static void sort(void) { unsigned long sortedsum; int i, j; /* Step 1. Toss into bins. */ doforkall("Tossing", bin); checksize_bins(); complainx("Done tossing into bins."); /* Step 2: Sort the bins. */ doforkall("Sorting", sortbins); checksize_bins(); complainx("Done sorting the bins."); /* Step 3: Merge corresponding bins. */ doforkall("Merging", mergebins); checksize_merge(); complainx("Done merging the bins."); /* Step 3a: delete the bins */ for (i=0; i<numprocs; i++) { for (j=0; j<numprocs; j++) { doremove(binname(i, j)); } } /* Step 4: assemble output file */ docreate(PATH_SORTED); doforkall("Final assembly", assemble); if (getsize(PATH_SORTED) != correctsize) { complainx("%s: file is wrong size", PATH_SORTED); exit(1); } /* Step 4a: delete the merged bins */ for (i=0; i<numprocs; i++) { doremove(mergedname(i)); } /* Step 5: Checksum the result. */ sortedsum = checksum_file(PATH_SORTED); complainx("Checksum of sorted keys: %ld", sortedsum); if (sortedsum != checksum) { complainx("Sums do not match"); exit(1); } }
static void unsetdir(void) { doremove(PATH_KEYS); doremove(PATH_SORTED); #if 0 /* let's not require subdirs */ dochdir(".."); if (rmdir(PATH_TESTDIR) < 0) { complain("%s: rmdir", PATH_TESTDIR); /* but don't exit */ } #endif /* 0 */ }
void fileinit(Chan *cp) { File *f; Tlock *t; loop: lock(&cp->flock); f = cp->flist; if(!f) { unlock(&cp->flock); return; } cp->flist = f->next; unlock(&cp->flock); qlock(f); if(t = f->tlock) { t->time = 0; f->tlock = 0; } if(f->open & FREMOV) doremove(f, 0); freewp(f->wpath); f->open = 0; f->cp = 0; qunlock(f); goto loop; }
static void validate(void) { int smallest, largest, prev_largest; int i, fd; const char *name; doforkall("Validation", dovalidate); checksize_valid(); prev_largest = 1; for (i=0; i<numprocs; i++) { name = validname(i); fd = doopen(name, O_RDONLY, 0); doexactread(name, fd, &smallest, sizeof(int)); doexactread(name, fd, &largest, sizeof(int)); if (smallest < 1) { complainx("Validation: block %d: bad SMALLEST", i); exit(1); } if (largest >= RANDOM_MAX) { complainx("Validation: block %d: bad LARGEST", i); exit(1); } if (smallest > largest) { complainx("Validation: block %d: SMALLEST > LARGEST", i); exit(1); } if (smallest < prev_largest) { complain("Validation: block %d smallest key %d", i, smallest); complain("Validation: previous block largest key %d", prev_largest); complain("Validation failed"); exit(1); } } for (i=0; i<numprocs; i++) { doremove(validname(i)); } }
void fileinit(Chan *cp) { File *f, *prev; Tlock *t; int h; loop: lock(&flock); for (h=0; h < nelem(flist); h++) for (prev=0, f = flist[h]; f; prev=f, f=f->next) { if(f->cp != cp) continue; if(prev) { prev->next = f->next; f->next = flist[h]; flist[h] = f; } flist[h] = f->next; unlock(&flock); qlock(f); if(t = f->tlock) { if(t->file == f) t->time = 0; /* free the lock */ f->tlock = 0; } if(f->open & FREMOV) doremove(f, 0); freewp(f->wpath); f->open = 0; authfree(f->auth); f->auth = 0; f->cp = 0; qunlock(f); goto loop; } unlock(&flock); }
void f_remove(Chan *cp, Oldfcall *in, Oldfcall *ou) { File *f; if(CHAT(cp)) { print("c_remove %d\n", cp->chan); print(" fid = %d\n", in->fid); } f = filep(cp, in->fid, 0); if(!f) { ou->err = Efid; goto out; } ou->err = doremove(f, cp==cons.chan); out: ou->fid = in->fid; if(f) qunlock(f); }
void f_clunk(Chan *cp, Oldfcall *in, Oldfcall *ou) { File *f; Tlock *t; int32_t tim; if(CHAT(cp)) { print("c_clunk %d\n", cp->chan); print(" fid = %d\n", in->fid); } f = filep(cp, in->fid, 0); if(!f) { print("%p\n", f); ou->err = Efid; goto out; } if(t = f->tlock) { tim = time(0); if(t->time < tim || t->file != f) ou->err = Ebroken; t->time = 0; /* free the lock */ f->tlock = 0; } if(f->open & FREMOV) ou->err = doremove(f, 0); f->open = 0; freewp(f->wpath); freefp(f); out: if(f) qunlock(f); ou->fid = in->fid; }