/* * always called with mainlock locked */ void syncall(void) { for(;;) if(!syncblock()) return; }
/* * process to synch blocks * it puts out a block/line every second * it waits 10 seconds if catches up. * in both cases, it takes about 10 seconds * to get up-to-date. * * it also updates the filter stats * and executes commands */ void syncproc(void) { char buf[4*1024]; Filter *ft; uint32_t c0, c1; int32_t t, n, d; int i, p[2]; /* * make a pipe for commands */ if(pipe(p) < 0) panic("command pipe"); sprint(buf, "#s/%s.cmd", service); srvfd(buf, cmdmode, p[0]); close(p[0]); cmdfd = p[1]; notify(catchalarm); t = time(nil); for(;;){ i = syncblock(); alarmed = 0; alarm(i ? 1000: 10000); n = read(cmdfd, buf, sizeof buf - 1); if(n <= 0 && !alarmed) sleep(i ? 1000: 10000); alarm(0); if(n > 0){ buf[n] = '\0'; if(cmd_exec(buf)) fprint(cmdfd, "done"); else fprint(cmdfd, "unknown command"); } n = time(nil); d = n - t; if(d < 0 || d > 5*60) d = 0; while(d >= 1) { d -= 1; for(i=0; i<f.nfilter; i++) { ft = f.filters[i]; c0 = ft->count; c1 = c0 - ft->oldcount; ft->oldcount = c0; ft->filter[0] = famd(ft->filter[0], c1, 59, 60); ft->filter[1] = famd(ft->filter[1], c1, 599, 600); ft->filter[2] = famd(ft->filter[2], c1, 5999, 6000); } } t = n; } }
void sync(char *reason) { int32_t i; print("sync: %s\n", reason); for(i=10*nhiob; i>0; i--) if(!syncblock()) return; print("sync shorted\n"); }
void sync(char *reason) { long i; if(chatty) fprint(2, "sync: %s\n", reason); for(i=10*nhiob; i>0; i--) if(!syncblock()) return; }
/* * process to synch blocks * it puts out a block/cache-line every second * it waits 10 seconds if caught up. * in both cases, it takes about 10 seconds * to get up-to-date. */ void synccopy(void) { int f; for (;;) { rlock(&mainlock); f = syncblock(); runlock(&mainlock); if(!f) delay(10000); else delay(1000); } }