Skip to content

Commit

Permalink
Merge bndmp_fhdb_[mem/lmdb]_add_file function
Browse files Browse the repository at this point in the history
We had two almost identical functions for each backend.

They were merged into the new function
"bndmp_fhdb_add_file()"
which is located in the new file ndmp_fhdb_common.c
  • Loading branch information
pstorz committed Nov 16, 2016
1 parent 5f9891e commit a5c1550
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 118 deletions.
3 changes: 2 additions & 1 deletion src/dird/Makefile.in
Expand Up @@ -34,7 +34,8 @@ SVRSRCS = admin.c archive.c authenticate.c autoprune.c backup.c bsr.c catreq.c \
consolidate.c dir_plugins.c dird_conf.c dird.c expand.c fd_cmds.c \
getmsg.c inc_conf.c job.c jobq.c migrate.c mountreq.c msgchan.c \
ndmp_dma_backup.c ndmp_dma_generic.c ndmp_dma_restore.c \
ndmp_dma_storage.c ndmp_fhdb_helpers.c ndmp_fhdb_mem.c ndmp_fhdb_lmdb.c \
ndmp_dma_storage.c ndmp_fhdb_common.c ndmp_fhdb_helpers.c \
ndmp_fhdb_mem.c ndmp_fhdb_lmdb.c \
newvol.c next_vol.c quota.c socket_server.c recycle.c restore.c \
run_conf.c sd_cmds.c scheduler.c stats.c storage.c ua_acl.c ua_audit.c \
ua_cmds.c ua_configure.c ua_db.c ua_dotcmds.c ua_input.c ua_impexp.c \
Expand Down
4 changes: 4 additions & 0 deletions src/dird/ndmp_dma_priv.h
Expand Up @@ -140,4 +140,8 @@ void ndmp_fhdb_mem_register(struct ndmlog *ixlog);
void ndmp_fhdb_mem_unregister(struct ndmlog *ixlog);
void ndmp_fhdb_mem_process_db(struct ndmlog *ixlog);


extern "C" int bndmp_fhdb_add_file(struct ndmlog *ixlog, int tagc, char *raw_name, ndmp9_file_stat *fstat);


#endif
96 changes: 96 additions & 0 deletions src/dird/ndmp_fhdb_common.c
@@ -0,0 +1,96 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2015-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* Functions common to mem and lmdb backends of fhdb handling
*
* Philipp Storz, Nov 2016
*/

#include "bareos.h"
#include "dird.h"

#if defined(HAVE_NDMP)

#include "ndmp/ndmagents.h"
#include "ndmp_dma_priv.h"

extern "C" int bndmp_fhdb_add_file(struct ndmlog *ixlog, int tagc, char *raw_name,
ndmp9_file_stat *fstat)
{
NIS *nis = (NIS *)ixlog->ctx;

nis->jcr->lock();
nis->jcr->JobFiles++;
nis->jcr->unlock();

if (nis->save_filehist) {
int8_t FileType = 0;
POOL_MEM attribs(PM_FNAME),
pathname(PM_FNAME);

/*
* Every file entry is relative from the filesystem currently being backed up.
*/
Dmsg2(100, "bndmp_fhdb_add_file: New filename ==> %s%s\n", nis->filesystem, raw_name);

if (nis->jcr->ar) {
/*
* See if this is the top level entry of the tree e.g. len == 0
*/
if (strlen(raw_name) == 0) {
ndmp_convert_fstat(fstat, nis->FileIndex, &FileType, attribs);

pm_strcpy(pathname, nis->filesystem);
pm_strcat(pathname, "/");
return 0;
} else {
ndmp_convert_fstat(fstat, nis->FileIndex, &FileType, attribs);

pm_strcpy(pathname, nis->filesystem);

/*
* skip leading slash to avoid double slashes
*/
if (raw_name == (char*)'/') {
pm_strcat(pathname, raw_name + 1);
} else {
pm_strcat(pathname, raw_name);
}

if (FileType == FT_DIREND) {
/*
* A directory needs to end with a '/'
* so append it if it is missing
*/
if ( pathname.c_str()[strlen(pathname.c_str()) - 1] != '/' ) {
pm_strcat(pathname, "/");
}
}
}

ndmp_store_attribute_record(nis->jcr, pathname.c_str(), nis->virtual_filename, attribs.c_str(), FileType,
0, (fstat->fh_info.valid == NDMP9_VALIDITY_VALID) ? fstat->fh_info.value : 0);
}
}

return 0;
}
#endif
64 changes: 1 addition & 63 deletions src/dird/ndmp_fhdb_lmdb.c
Expand Up @@ -63,68 +63,6 @@ static int dbglvl = 100;
#define AVG_NR_BYTES_PER_ENTRY 256
#define B_PAGE_SIZE 4096

extern "C" int bndmp_fhdb_lmdb_add_file(struct ndmlog *ixlog, int tagc, char *raw_name,
ndmp9_file_stat *fstat)
{
NIS *nis = (NIS *)ixlog->ctx;

nis->jcr->lock();
nis->jcr->JobFiles++;
nis->jcr->unlock();

if (nis->save_filehist) {
int8_t FileType = 0;
POOL_MEM attribs(PM_FNAME),
pathname(PM_FNAME);

/*
* Every file entry is relative from the filesystem currently being backed up.
*/
Dmsg2(100, "bndmp_fhdb_lmdb_add_file: New filename ==> %s%s\n", nis->filesystem, raw_name);

if (nis->jcr->ar) {
/*
* See if this is the top level entry of the tree e.g. len == 0
*/
if (strlen(raw_name) == 0) {
ndmp_convert_fstat(fstat, nis->FileIndex, &FileType, attribs);

pm_strcpy(pathname, nis->filesystem);
pm_strcat(pathname, "/");
return 0;
} else {
ndmp_convert_fstat(fstat, nis->FileIndex, &FileType, attribs);

pm_strcpy(pathname, nis->filesystem);

/*
* skip leading slash to avoid double slashes
*/
if (raw_name == (char*)'/') {
pm_strcat(pathname, raw_name + 1);
} else {
pm_strcat(pathname, raw_name);
}

if (FileType == FT_DIREND) {
/*
* A directory needs to end with a '/'
* so append it if it is missing
*/
if ( pathname.c_str()[strlen(pathname.c_str()) - 1] != '/' ) {
pm_strcat(pathname, "/");
}
}
}

ndmp_store_attribute_record(nis->jcr, pathname.c_str(), nis->virtual_filename, attribs.c_str(), FileType,
0, (fstat->fh_info.valid == NDMP9_VALIDITY_VALID) ? fstat->fh_info.value : 0);
}
}

return 0;
}

extern "C" int bndmp_fhdb_lmdb_add_dir(struct ndmlog *ixlog, int tagc, char *raw_name,
ndmp9_u_quad dir_node, ndmp9_u_quad node)
{
Expand Down Expand Up @@ -438,7 +376,7 @@ void ndmp_fhdb_lmdb_register(struct ndmlog *ixlog)
/*
* Register the FileHandleDB callbacks.
*/
fhdb_callbacks.add_file = bndmp_fhdb_lmdb_add_file;
fhdb_callbacks.add_file = bndmp_fhdb_add_file;
fhdb_callbacks.add_dir = bndmp_fhdb_lmdb_add_dir;
fhdb_callbacks.add_node = bndmp_fhdb_lmdb_add_node;
fhdb_callbacks.add_dirnode_root = bndmp_fhdb_lmdb_add_dirnode_root;
Expand Down
53 changes: 1 addition & 52 deletions src/dird/ndmp_fhdb_mem.c
Expand Up @@ -432,57 +432,6 @@ static N_TREE_NODE *find_tree_node(N_TREE_ROOT *root, uint64_t inode)
return (N_TREE_NODE *)NULL;
}

extern "C" int bndmp_fhdb_mem_add_file(struct ndmlog *ixlog, int tagc, char *raw_name,
ndmp9_file_stat *fstat)
{
NIS *nis = (NIS *)ixlog->ctx;

nis->jcr->lock();
nis->jcr->JobFiles++;
nis->jcr->unlock();

if (nis->save_filehist) {
int8_t FileType = 0;
POOL_MEM attribs(PM_FNAME),
pathname(PM_FNAME);

/*
* Every file entry is releative from the filesystem currently being backuped.
*/
Dmsg2(100, "bndmp_fhdb_mem_add_file: New filename ==> %s/%s\n", nis->filesystem, raw_name);

if (nis->jcr->ar) {
/*
* See if this is the top level entry of the tree e.g. len == 0
*/
if (strlen(raw_name) == 0) {
ndmp_convert_fstat(fstat, nis->FileIndex, &FileType, attribs);

pm_strcpy(pathname, nis->filesystem);
pm_strcat(pathname, "/");
return 0;
} else {
ndmp_convert_fstat(fstat, nis->FileIndex, &FileType, attribs);

pm_strcpy(pathname, nis->filesystem);
pm_strcat(pathname, "/");
pm_strcat(pathname, raw_name);

if (FileType == FT_DIREND) {
/*
* A directory needs to end with a slash.
*/
pm_strcat(pathname, "/");
}
}

ndmp_store_attribute_record(nis->jcr, pathname.c_str(), nis->virtual_filename, attribs.c_str(), FileType,
0, (fstat->fh_info.valid == NDMP9_VALIDITY_VALID) ? fstat->fh_info.value : 0);
}
}

return 0;
}

/*
* This inserts a piece of meta data we receive out or order in a hash table
Expand Down Expand Up @@ -800,7 +749,7 @@ void ndmp_fhdb_mem_register(struct ndmlog *ixlog)
/*
* Register the FileHandleDB callbacks.
*/
fhdb_callbacks.add_file = bndmp_fhdb_mem_add_file;
fhdb_callbacks.add_file = bndmp_fhdb_add_file;
fhdb_callbacks.add_dir = bndmp_fhdb_mem_add_dir;
fhdb_callbacks.add_node = bndmp_fhdb_mem_add_node;
fhdb_callbacks.add_dirnode_root = bndmp_fhdb_mem_add_dirnode_root;
Expand Down
7 changes: 5 additions & 2 deletions src/dird/unittests/protos.h
Expand Up @@ -23,12 +23,15 @@
#include "ndmp/ndmlib.h"

extern "C" {
int bndmp_fhdb_mem_add_file(struct ndmlog *ixlog, int tagc, char *raw_name, ndmp9_file_stat *fstat);
/*
* common for both back ends
*/
int bndmp_fhdb_add_file(struct ndmlog *ixlog, int tagc, char *raw_name, ndmp9_file_stat *fstat);

int bndmp_fhdb_mem_add_dir(struct ndmlog *ixlog, int tagc, char *raw_name, ndmp9_u_quad dir_node, ndmp9_u_quad node);
int bndmp_fhdb_mem_add_dirnode_root(struct ndmlog *ixlog, int tagc, ndmp9_u_quad root_node);
int bndmp_fhdb_mem_add_node(struct ndmlog *ixlog, int tagc, ndmp9_u_quad node, ndmp9_file_stat *fstat);

int bndmp_fhdb_lmdb_add_file(struct ndmlog *ixlog, int tagc, char *raw_name, ndmp9_file_stat *fstat);
int bndmp_fhdb_lmdb_add_dir(struct ndmlog *ixlog, int tagc, char *raw_name, ndmp9_u_quad dir_node, ndmp9_u_quad node);
int bndmp_fhdb_lmdb_add_dirnode_root(struct ndmlog *ixlog, int tagc, ndmp9_u_quad root_node);
int bndmp_fhdb_lmdb_add_node(struct ndmlog *ixlog, int tagc, ndmp9_u_quad node, ndmp9_file_stat *fstat);
Expand Down

0 comments on commit a5c1550

Please sign in to comment.