"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/server/protocol2/bsparse.c" between
burp-2.3.14.tar.bz2 and burp-2.3.20.tar.bz2

About: Burp is a backup and restore program using librsync and also VSS (for Windows clients). Latest version.

bsparse.c  (burp-2.3.14.tar.bz2):bsparse.c  (burp-2.3.20.tar.bz2)
skipping to change at line 19 skipping to change at line 19
#include "../../hexmap.h" #include "../../hexmap.h"
#include "../../iobuf.h" #include "../../iobuf.h"
#include "../../lock.h" #include "../../lock.h"
#include "../../log.h" #include "../../log.h"
#include "../../strlist.h" #include "../../strlist.h"
#include "../../protocol2/blk.h" #include "../../protocol2/blk.h"
#include "../bu_get.h" #include "../bu_get.h"
#include "../protocol2/backup_phase4.h" #include "../protocol2/backup_phase4.h"
#include "../sdirs.h" #include "../sdirs.h"
#include "bsigs.h" #include "bsigs.h"
#include "clist.h"
#include "champ_chooser/champ_chooser.h" #include "champ_chooser/champ_chooser.h"
#include "sparse_min.h"
static struct cstat *clist=NULL;
static struct lock *sparse_lock=NULL; static struct lock *sparse_lock=NULL;
static struct cstat *clist=NULL;
static int usage(void) static int usage(void)
{ {
logfmt("\nUsage: %s [options] <path to dedup_group>\n", prog); logfmt("\nUsage: %s [options] <path to dedup_group>\n", prog);
logfmt("\n"); logfmt("\n");
logfmt(" Options:\n"); logfmt(" Options:\n");
logfmt(" -c <path> Path to config file (default: %s).\n", logfmt(" -c <path> Path to config file (default: %s).\n",
config_default_path()); config_default_path());
logfmt("\n"); logfmt("\n");
return 1; return 1;
} }
static void release_locks(void) static void release_locks(struct cstat *clist)
{ {
struct cstat *c; struct cstat *c;
struct sdirs *s; struct sdirs *s;
for(c=clist; c; c=c->next) for(c=clist; c; c=c->next)
{ {
s=(struct sdirs *)c->sdirs; s=(struct sdirs *)c->sdirs;
if(!s) continue; if(!s) continue;
lock_release(s->lock_storage_for_write); lock_release(s->lock_storage_for_write);
logp("released: %s\n", c->name); logp("released: %s\n", c->name);
} }
lock_release(sparse_lock); lock_release(sparse_lock);
lock_free(&sparse_lock); lock_free(&sparse_lock);
logp("released: sparse index\n"); logp("released: sparse index\n");
} }
static void sighandler(__attribute__ ((unused)) int signum) static void sighandler(__attribute__ ((unused)) int signum)
{ {
release_locks(); release_locks(clist);
exit(1); exit(1);
} }
static struct sdirs *get_sdirs(struct conf **globalcs) static struct sdirs *get_sdirs(struct conf **conf)
{ {
struct sdirs *sdirs=NULL; struct sdirs *sdirs=NULL;
if(!(sdirs=sdirs_alloc()) if(!(sdirs=sdirs_alloc())
|| sdirs_init_from_confs(sdirs, globalcs)) || sdirs_init_from_confs(sdirs, conf))
sdirs_free(&sdirs); sdirs_free(&sdirs);
return sdirs; return sdirs;
} }
static int parse_directory(const char *arg, static int parse_directory(const char *arg,
char **directory, char **dedup_group) char **directory, char **dedup_group)
{ {
char *cp; char *cp;
if(!(*directory=strdup_w(arg, __func__))) if(!(*directory=strdup_w(arg, __func__)))
goto error; goto error;
skipping to change at line 93 skipping to change at line 95
return 0; return 0;
error: error:
free_w(directory); free_w(directory);
free_w(dedup_group); free_w(dedup_group);
return -1; return -1;
} }
static struct conf **load_conf(const char *configfile, static struct conf **load_conf(const char *configfile,
const char *directory, const char *dedup_group) const char *directory, const char *dedup_group)
{ {
struct conf **globalcs=NULL; struct conf **conf=NULL;
if(!(globalcs=confs_alloc()) if(!(conf=confs_alloc())
|| confs_init(globalcs) || confs_init(conf)
|| conf_load_global_only(configfile, globalcs) || conf_load_global_only(configfile, conf)
|| set_string(globalcs[OPT_CNAME], "fake") || set_string(conf[OPT_CNAME], "fake")
|| set_string(globalcs[OPT_DIRECTORY], directory) || set_string(conf[OPT_DIRECTORY], directory)
|| set_string(globalcs[OPT_DEDUP_GROUP], dedup_group) || set_string(conf[OPT_DEDUP_GROUP], dedup_group)
|| set_protocol(globalcs, PROTO_2)) || set_protocol(conf, PROTO_2))
confs_free(&globalcs); confs_free(&conf);
return globalcs; return conf;
} }
static void setup_sighandler(void) static void setup_sighandler(void)
{ {
signal(SIGABRT, &sighandler); signal(SIGABRT, &sighandler);
signal(SIGTERM, &sighandler); signal(SIGTERM, &sighandler);
signal(SIGINT, &sighandler); signal(SIGINT, &sighandler);
} }
static int get_sparse_lock(const char *sparse) static int get_sparse_lock(const char *sparse)
{ {
if(!(sparse_lock=try_to_get_sparse_lock(sparse))) if(!(sparse_lock=try_to_get_sparse_lock(sparse)))
{ {
logp("Could not get sparse lock\n"); logp("Could not get sparse lock\n");
return -1; return -1;
} }
return 0; return 0;
} }
static int get_client_locks(void) static int get_client_locks(struct cstat *clist)
{ {
struct cstat *c; struct cstat *c;
struct sdirs *s; struct sdirs *s;
for(c=clist; c; c=c->next) for(c=clist; c; c=c->next)
{ {
s=(struct sdirs *)c->sdirs; s=(struct sdirs *)c->sdirs;
if(mkpath(&s->lock_storage_for_write->path, s->lockdir)) if(mkpath(&s->lock_storage_for_write->path, s->lockdir))
{ {
logp("problem with lock directory: %s\n", s->lockdir); logp("problem with lock directory: %s\n", s->lockdir);
return -1; return -1;
skipping to change at line 155 skipping to change at line 157
case GET_LOCK_ERROR: case GET_LOCK_ERROR:
default: default:
logp("Problem with lock file: %s\n", logp("Problem with lock file: %s\n",
s->lock_storage_for_write->path); s->lock_storage_for_write->path);
return -1; return -1;
} }
} }
return 0; return 0;
} }
static struct cstat *get_client_list(const char *cdir, struct conf **globalcs)
{
int i=0;
int count=0;
char *fullpath=NULL;
char **clients=NULL;
struct cstat *cnew=NULL;
const char *clientconfdir=get_string(globalcs[OPT_CLIENTCONFDIR]);
if(entries_in_directory_alphasort(cdir, &clients, &count, 1/*atime*/, 1/*
follow_symlinks*/))
goto error;
for(i=0; i<count; i++)
{
free_w(&fullpath);
if(!(fullpath=prepend_s(cdir, clients[i])))
goto end;
switch(is_dir_lstat(fullpath))
{
case 0: continue;
case 1: break;
default: logp("is_dir(%s): %s\n",
fullpath, strerror(errno));
goto error;
}
if(set_string(globalcs[OPT_CNAME], clients[i]))
goto error;
// Have a good entry. Add it to the list.
if(!(cnew=cstat_alloc())
|| !(cnew->sdirs=sdirs_alloc())
|| (sdirs_init_from_confs((struct sdirs *)cnew->sdirs,
globalcs))
|| cstat_init(cnew, clients[i], clientconfdir))
goto error;
cstat_add_to_list(&clist, cnew);
cnew=NULL;
}
goto end;
error:
cstat_list_free(&clist);
end:
for(i=0; i<count; i++)
free_w(&(clients[i]));
free_v((void **)&clients);
free_w(&fullpath);
if(cnew)
{
sdirs_free((struct sdirs **)&cnew->sdirs);
cstat_free(&cnew);
}
return clist;
}
static void clist_free(void)
{
struct cstat *c;
if(!clist)
return;
for(c=clist; c; c=c->next)
sdirs_free((struct sdirs **)&c->sdirs);
cstat_list_free(&clist);
}
static int merge_in_client_sparse_indexes(struct cstat *c, static int merge_in_client_sparse_indexes(struct cstat *c,
const char *global_sparse) const char *global_sparse)
{ {
int ret=-1; int ret=-1;
char *sparse=NULL; char *sparse=NULL;
struct bu *b=NULL; struct bu *b=NULL;
struct bu *bu_list=NULL; struct bu *bu_list=NULL;
struct sdirs *s=(struct sdirs *)c->sdirs; struct sdirs *s=(struct sdirs *)c->sdirs;
if(bu_get_list(s, &bu_list)) if(bu_get_list(s, &bu_list))
skipping to change at line 272 skipping to change at line 211
} }
int run_bsparse(int argc, char *argv[]) int run_bsparse(int argc, char *argv[])
{ {
int ret=1; int ret=1;
int option; int option;
char *directory=NULL; char *directory=NULL;
char *dedup_group=NULL; char *dedup_group=NULL;
const char *configfile=NULL; const char *configfile=NULL;
struct sdirs *sdirs=NULL; struct sdirs *sdirs=NULL;
struct conf **globalcs=NULL; struct conf **conf=NULL;
base64_init(); base64_init();
configfile=config_default_path(); configfile=config_default_path();
while((option=getopt(argc, argv, "c:Vh?"))!=-1) while((option=getopt(argc, argv, "c:Vh?"))!=-1)
{ {
switch(option) switch(option)
{ {
case 'c': case 'c':
configfile=optarg; configfile=optarg;
skipping to change at line 303 skipping to change at line 242
if(optind>=argc || optind<argc-1) if(optind>=argc || optind<argc-1)
return usage(); return usage();
if(parse_directory(argv[optind], &directory, &dedup_group)) if(parse_directory(argv[optind], &directory, &dedup_group))
goto end; goto end;
logp("config file: %s\n", configfile); logp("config file: %s\n", configfile);
logp("directory: %s\n", directory); logp("directory: %s\n", directory);
logp("dedup_group: %s\n", dedup_group); logp("dedup_group: %s\n", dedup_group);
if(!(globalcs=load_conf(configfile, directory, dedup_group)) if(!(conf=load_conf(configfile, directory, dedup_group))
|| !(sdirs=get_sdirs(globalcs))) || !(sdirs=get_sdirs(conf)))
goto end; goto end;
logp("clients: %s\n", sdirs->clients); logp("clients: %s\n", sdirs->clients);
logp("sparse file: %s\n", sdirs->global_sparse); logp("sparse file: %s\n", sdirs->global_sparse);
setup_sighandler(); setup_sighandler();
if(get_sparse_lock(sdirs->global_sparse)) if(get_sparse_lock(sdirs->global_sparse))
goto end; goto end;
if(!get_client_list(sdirs->clients, globalcs)) if(get_client_list(&clist, sdirs->clients, conf))
{ {
logp("Did not find any client directories\n"); logp("Did not find any client directories\n");
goto end; goto end;
} }
if(get_client_locks()) if(get_client_locks(clist))
goto end; goto end;
if(merge_in_all_sparse_indexes(sdirs->global_sparse)) if(merge_in_all_sparse_indexes(sdirs->global_sparse))
goto end; goto end;
if(sparse_minimise(conf, sdirs->global_sparse, sparse_lock, clist))
goto end;
ret=0; ret=0;
end: end:
release_locks(); release_locks(clist);
sdirs_free(&sdirs); sdirs_free(&sdirs);
free_w(&directory); free_w(&directory);
free_w(&dedup_group); free_w(&dedup_group);
confs_free(&globalcs); confs_free(&conf);
clist_free(); clist_free(&clist);
return ret; return ret;
} }
 End of changes. 18 change blocks. 
88 lines changed or deleted 29 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)