X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Fclient.c;h=e6075dccb66274bfd78a599dfa8b41979c28d9c7;hb=e03e1e7c23b2f527d43ec72b01c93185ebc63008;hp=6aa1887b91817382badd43ad0a23c6503bb5ec71;hpb=7a2dee1d890df9fe5888ae8b8c80c41d3ae02f05;p=doldaconnect.git diff --git a/daemon/client.c b/daemon/client.c index 6aa1887..e6075dc 100644 --- a/daemon/client.c +++ b/daemon/client.c @@ -74,6 +74,15 @@ static struct configvar myvars[] = /** The filename to use for the hash cache (see the FILES section * for more information). */ {CONF_VAR_STRING, "hashcache", {.str = L"dc-hashcache"}}, + /** Writes of the hash cache and file lists are delayed for an + * amount of time, in order to minimize the time spent on I/O wait + * while hashing many small files. This variable sets the amount + * of time, in seconds. */ + {CONF_VAR_INT, "hashwritedelay", {.num = 300}}, + /** The amount of time, in seconds, to wait before automatically + * rescanning the shared directories for changes. Set to zero (the + * default) to disable automatic rescanning. */ + {CONF_VAR_INT, "rescandelay", {.num = 0}}, {CONF_VAR_END} }; @@ -94,6 +103,7 @@ static struct timer *hashwritetimer = NULL; * job. */ static pid_t hashjob = -1; struct sharecache *shareroot = NULL; +static struct timer *scantimer = NULL; unsigned long long sharesize = 0; GCBCHAIN(sharechangecb, unsigned long long); @@ -347,7 +357,7 @@ static void writehashcache(int now) if(!now) { if(hashwritetimer == NULL) - hashwritetimer = timercallback(ntime() + 300, (void (*)(int, void *))hashtimercb, NULL); + hashwritetimer = timercallback(ntime() + confgetint("cli", "hashwritedelay"), (void (*)(int, void *))hashtimercb, NULL); return; } if(hashwritetimer != NULL) @@ -963,6 +973,18 @@ int doscan(int quantum) return(1); } +static void rescancb(int cancelled, void *uudata) +{ + scantimer = NULL; + if(!cancelled) + { + if(scanqueue == NULL) + scanshares(); + else if(confgetint("cli", "rescandelay") > 0) + scantimer = timercallback(ntime() + confgetint("cli", "rescandelay"), (void (*)(int, void *))rescancb, NULL); + } +} + void scanshares(void) { struct sharepoint *cur; @@ -993,6 +1015,10 @@ void scanshares(void) } queuescan(node); } + if(scantimer != NULL) + canceltimer(scantimer); + if(confgetint("cli", "rescandelay") > 0) + scantimer = timercallback(ntime() + confgetint("cli", "rescandelay"), (void (*)(int, void *))rescancb, NULL); } static void preinit(int hup) @@ -1010,6 +1036,15 @@ static void preinit(int hup) } } +static int rsdelayupdate(struct configvar *var, void *uudata) +{ + if(scantimer != NULL) + canceltimer(scantimer); + if(confgetint("cli", "rescandelay") > 0) + scantimer = timercallback(ntime() + var->val.num, (void (*)(int, void *))rescancb, NULL); + return(0); +} + static int init(int hup) { struct sharepoint *cur, *next; @@ -1023,7 +1058,10 @@ static int init(int hup) } scanshares(); if(!hup) + { while(doscan(100)); + CBREG(confgetvar("cli", "rescandelay"), conf_update, rsdelayupdate, NULL, NULL); + } return(0); }