void threadmain(int argc, char *argv[]) { ArenaPart *ap; Part *part; char *file; u8int score[VtScoreSize]; int i, found; ventifmtinstall(); ARGBEGIN{ case 'v': verbose++; break; default: usage(); break; }ARGEND readonly = 1; if(argc != 2) usage(); file = argv[0]; if(strscore(argv[1], score) < 0) sysfatal("bad score %s", argv[1]); part = initpart(file, OREAD|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); ap = initarenapart(part); if(ap == nil) sysfatal("can't initialize arena partition in %s: %r", file); if(verbose > 1){ printarenapart(2, ap); fprint(2, "\n"); } initdcache(8 * MaxDiskBlock); found = 0; for(i = 0; i < ap->narenas; i++) found += findscore(ap->arenas[i], score); print("found %d occurrences of %V\n", found, score); if(verbose > 1) printstats(); threadexitsall(0); }
void threadmain(int argc, char *argv[]) { ArenaPart *ap; Part *part; char *file, *aname; int i; ventifmtinstall(); statsinit(); ARGBEGIN{ case 'q': quiet++; break; case 'v': verbose++; break; default: usage(); break; }ARGEND readonly = 1; if(argc != 2) usage(); file = argv[0]; aname = argv[1]; part = initpart(file, OREAD|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); ap = initarenapart(part); if(ap == nil) sysfatal("can't initialize arena partition in %s: %r", file); if(verbose) printarenapart(2, ap); initdcache(8 * MaxDiskBlock); for(i = 0; i < ap->narenas; i++){ if(strcmp(ap->arenas[i]->name, aname) == 0){ rdarena(ap->arenas[i]); threadexitsall(0); } } sysfatal("couldn't find arena %s", aname); }
void threadmain(int argc, char *argv[]) { int vers; ArenaPart *ap; Part *part; Arena *arena; uint64_t addr, limit, asize, apsize; char *file, *name, aname[ANameSize]; int i, n, blocksize, tabsize, zero; ventifmtinstall(); statsinit(); blocksize = 8 * 1024; asize = 512 * 1024 *1024; tabsize = 512 * 1024; /* BUG: should be determine from number of arenas */ zero = -1; vers = ArenaVersion5; ARGBEGIN{ case 'D': settrace(EARGF(usage())); break; case 'a': asize = unittoull(EARGF(usage())); if(asize == TWID64) usage(); break; case 'b': blocksize = unittoull(EARGF(usage())); if(blocksize == ~0) usage(); if(blocksize > MaxDiskBlock){ fprint(2, "block size too large, max %d\n", MaxDiskBlock); threadexitsall("usage"); } break; case '4': vers = ArenaVersion4; break; case 'Z': zero = 0; break; default: usage(); break; }ARGEND if(zero == -1){ if(vers == ArenaVersion4) zero = 1; else zero = 0; } if(argc != 2) usage(); name = argv[0]; file = argv[1]; if(nameok(name) < 0) sysfatal("illegal name template %s", name); part = initpart(file, ORDWR|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); if(zero) zeropart(part, blocksize); maxblocksize = blocksize; initdcache(20*blocksize); ap = newarenapart(part, blocksize, tabsize); if(ap == nil) sysfatal("can't initialize arena: %r"); apsize = ap->size - ap->arenabase; n = apsize / asize; if(apsize - (n * asize) >= MinArenaSize) n++; fprint(2, "fmtarenas %s: %,d arenas, %,lld bytes storage, %,d bytes for index map\n", file, n, apsize, ap->tabsize); ap->narenas = n; ap->map = MKNZ(AMap, n); ap->arenas = MKNZ(Arena*, n); addr = ap->arenabase; for(i = 0; i < n; i++){ limit = addr + asize; if(limit >= ap->size || ap->size - limit < MinArenaSize){ limit = ap->size; if(limit - addr < MinArenaSize) sysfatal("bad arena set math: runt arena at %lld,%lld %lld", addr, limit, ap->size); } snprint(aname, ANameSize, "%s%d", name, i); if(0) fprint(2, "adding arena %s at [%lld,%lld)\n", aname, addr, limit); arena = newarena(part, vers, aname, addr, limit - addr, blocksize); if(!arena) fprint(2, "can't make new arena %s: %r", aname); freearena(arena); ap->map[i].start = addr; ap->map[i].stop = limit; namecp(ap->map[i].name, aname); addr = limit; } if(wbarenapart(ap) < 0) fprint(2, "can't write back arena partition header for %s: %r\n", file); flushdcache(); threadexitsall(0); }
void threadmain(int argc, char *argv[]) { int i; char *file; Arena *arena; u64int offset, aoffset; Part *part; uchar buf[8192]; ArenaHead head; ZClump zerocl; ventifmtinstall(); qlock(&godot); aoffset = 0; ARGBEGIN{ case 'f': fast = 1; ventidoublechecksha1 = 0; break; case 'h': host = EARGF(usage()); break; case 'o': haveaoffset = 1; aoffset = strtoull(EARGF(usage()), 0, 0); break; case 'M': maxwrites = atoi(EARGF(usage())); break; case 'v': verbose = 1; break; default: usage(); break; }ARGEND offset = ~(u64int)0; switch(argc) { default: usage(); case 2: offset = strtoull(argv[1], 0, 0); /* fall through */ case 1: file = argv[0]; } fmtinstall('V', vtscorefmt); statsinit(); part = initpart(file, OREAD); if(part == nil) sysfatal("can't open file %s: %r", file); if(readpart(part, aoffset, buf, sizeof buf) < 0) sysfatal("can't read file %s: %r", file); if(unpackarenahead(&head, buf) < 0) sysfatal("corrupted arena header: %r"); if(aoffset+head.size > part->size) sysfatal("arena is truncated: want %llud bytes have %llud", head.size, part->size); partblocksize(part, head.blocksize); initdcache(8 * MaxDiskBlock); arena = initarena(part, aoffset, head.size, head.blocksize); if(arena == nil) sysfatal("initarena: %r"); z = nil; if(host==nil || strcmp(host, "/dev/null") != 0){ z = vtdial(host); if(z == nil) sysfatal("could not connect to server: %r"); if(vtconnect(z) < 0) sysfatal("vtconnect: %r"); } c = chancreate(sizeof(ZClump), 0); for(i=0; i<12; i++) vtproc(vtsendthread, nil); rdarena(arena, offset); if(vtsync(z) < 0) sysfatal("executing sync: %r"); memset(&zerocl, 0, sizeof zerocl); for(i=0; i<12; i++) send(c, &zerocl); if(z){ vthangup(z); } threadexitsall(0); }
void threadmain(int argc, char *argv[]) { char *haddr, *vaddr, *webroot, *file; traceinit(); threadsetname("main"); vaddr = nil; haddr = "tcp!*!9000"; webroot = nil; ARGBEGIN{ case 'a': vaddr = EARGF(usage()); break; case 'D': settrace(EARGF(usage())); break; case 'd': debug = 1; nofork = 1; break; case 'h': haddr = EARGF(usage()); break; case 'L': ventilogging = 1; break; case 'r': readonly = 1; break; case 's': nofork = 1; break; case 'W': webroot = EARGF(usage()); break; default: usage(); }ARGEND if(argc < 1) usage(); file = argv[0]; if(!nofork) rfork(RFNOTEG); #ifdef PLAN9PORT { /* sigh - needed to avoid signals when writing to hungup networks */ struct sigaction sa; memset(&sa, 0, sizeof sa); sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, nil); } #endif ventifmtinstall(); trace(TraceQuiet, "venti started"); fprint(2, "%T venti: "); statsinit(); mminit(file, readonly ? OREAD : ORDWR); /* * default other configuration-file parameters */ if(vaddr == nil) vaddr = "tcp!*!venti"; if(haddr){ fprint(2, "httpd %s...", haddr); if(httpdinit(haddr, webroot) < 0) fprint(2, "warning: can't start http server: %r"); } fprint(2, "init..."); fprint(2, "announce %s...", vaddr); ventisrv = vtlisten(vaddr); if(ventisrv == nil) sysfatal("can't announce %s: %r", vaddr); fprint(2, "serving.\n"); if(nofork) ventiserver(nil); else vtproc(ventiserver, nil); threadexits(nil); }
void threadmain(int argc, char **argv) { int i; int nofork; char *prog; Job *j; ventilogging = 1; ventifmtinstall(); #ifdef PLAN9PORT bin = unsharp("#9/bin/venti"); #else bin = "/bin/venti"; #endif nofork = 0; ARGBEGIN{ case 'b': bin = EARGF(usage()); break; case 's': nofork = 1; break; default: usage(); }ARGEND if(argc != 1) usage(); if(rdconf(argv[0], &conf) < 0) sysfatal("reading config: %r"); if(conf.httpaddr == nil) sysfatal("config has no httpaddr"); if(conf.smtp != nil && conf.mailfrom == nil) sysfatal("config has smtp but no mailfrom"); if(conf.smtp != nil && conf.mailto == nil) sysfatal("config has smtp but no mailto"); if((mirrorprog = regcomp(mirrorregexp)) == nil) sysfatal("mirrorregexp did not complete"); if((verifyprog = regcomp(verifyregexp)) == nil) sysfatal("verifyregexp did not complete"); if(conf.nverify > 0 && conf.verifyfreq == 0) sysfatal("config has no verifyfreq"); if(conf.nmirror > 0 && conf.mirrorfreq == 0) sysfatal("config has no mirrorfreq"); time0 = time(0); // sendmail("startup", "mgr is starting\n"); logbuf = vtmalloc(LogSize+1); // +1 for NUL errlog = vtlogopen("errors", LogSize); job = vtmalloc((conf.nmirror+conf.nverify)*sizeof job[0]); prog = smprint("%s/mirrorarenas", bin); for(i=0; i<conf.nmirror; i++) { // job: /bin/venti/mirrorarenas -v src dst // filter output j = &job[njob++]; mkjob(j, prog, "-v", conf.mirror[i].src, conf.mirror[i].dst, nil); j->name = smprint("mirror %s %s", conf.mirror[i].src, conf.mirror[i].dst); j->ok = mirrorok; j->freq = conf.mirrorfreq; // 4 hours // TODO: put in config j->offset = (double)i/conf.nmirror; } prog = smprint("%s/verifyarena", bin); for(i=0; i<conf.nverify; i++) { // job: /bin/venti/verifyarena -b 64M -s 1000 -v arena // filter output j = &job[njob++]; mkjob(j, prog, "-b64M", "-s1000", conf.verify[i], nil); j->name = smprint("verify %s", conf.verify[i]); j->ok = verifyok; j->freq = conf.verifyfreq; j->offset = (double)i/conf.nverify; } httpdobj("/mgr", hmanager); httpdobj("/log", xlog); vtproc(httpdproc, conf.httpaddr); vtproc(waitproc, threadwaitchan()); if(nofork) manager(nil); else vtproc(manager, nil); }
void threadmain(int argc, char *argv[]) { char *configfile, *haddr, *vaddr, *webroot; u32int mem, icmem, bcmem, minbcmem, mempcnt, stfree; Allocs allocs; Config config; traceinit(); threadsetname("main"); mempcnt = 0; vaddr = nil; haddr = nil; configfile = nil; webroot = nil; mem = Unspecified; icmem = 0; bcmem = 0; ARGBEGIN{ case 'a': vaddr = EARGF(usage()); break; case 'B': bcmem = unittoull(EARGF(usage())); break; case 'c': configfile = EARGF(usage()); break; case 'C': mem = unittoull(EARGF(usage())); break; case 'D': settrace(EARGF(usage())); break; case 'd': debug = 1; nofork = 1; break; case 'h': haddr = EARGF(usage()); break; case 'm': mempcnt = atoi(EARGF(usage())); if (mempcnt <= 0 || mempcnt >= 100) usage(); break; case 'I': icmem = unittoull(EARGF(usage())); break; case 'L': ventilogging = 1; break; case 'r': readonly = 1; break; case 's': nofork = 1; break; case 'w': /* compatibility with old venti */ queuewrites = 1; break; case 'W': webroot = EARGF(usage()); break; default: usage(); }ARGEND if(argc) usage(); if(!nofork) rfork(RFNOTEG); #ifdef PLAN9PORT { /* sigh - needed to avoid signals when writing to hungup networks */ struct sigaction sa; memset(&sa, 0, sizeof sa); sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, nil); } #endif ventifmtinstall(); trace(TraceQuiet, "venti started"); fprint(2, "%T venti: "); if(configfile == nil) configfile = "venti.conf"; /* remember free memory before initventi & loadbloom, for auto-sizing */ stfree = freemem(); fprint(2, "conf..."); if(initventi(configfile, &config) < 0) sysfatal("can't init server: %r"); /* * load bloom filter */ if(mainindex->bloom && loadbloom(mainindex->bloom) < 0) sysfatal("can't load bloom filter: %r"); /* * size memory allocations; assumes bloom filter is loaded */ allocs = sizeallocs((Allocs){mem, bcmem, icmem, stfree, mempcnt}, &config); mem = allocs.mem; bcmem = allocs.bcmem; icmem = allocs.icmem; fprint(2, "%s: mem %,ud bcmem %,ud icmem %,ud...", argv0, mem, bcmem, icmem); /* * default other configuration-file parameters */ if(haddr == nil) haddr = config.haddr; if(vaddr == nil) vaddr = config.vaddr; if(vaddr == nil) vaddr = "tcp!*!venti"; if(webroot == nil) webroot = config.webroot; if(queuewrites == 0) queuewrites = config.queuewrites; if(haddr){ fprint(2, "httpd %s...", haddr); if(httpdinit(haddr, webroot) < 0) fprint(2, "warning: can't start http server: %r"); } fprint(2, "init..."); /* * lump cache */ if(0) fprint(2, "initialize %d bytes of lump cache for %d lumps\n", mem, mem / (8 * 1024)); initlumpcache(mem, mem / (8 * 1024)); /* * index cache */ initicache(icmem); initicachewrite(); /* * block cache: need a block for every arena and every process */ minbcmem = maxblocksize * (mainindex->narenas + mainindex->nsects*4 + 16); if(bcmem < minbcmem) bcmem = minbcmem; if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem); initdcache(bcmem); if(mainindex->bloom) startbloomproc(mainindex->bloom); fprint(2, "sync..."); if(!readonly && syncindex(mainindex) < 0) sysfatal("can't sync server: %r"); if(!readonly && queuewrites){ fprint(2, "queue..."); if(initlumpqueues(mainindex->nsects) < 0){ fprint(2, "can't initialize lump queues," " disabling write queueing: %r"); queuewrites = 0; } } if(initarenasum() < 0) fprint(2, "warning: can't initialize arena summing process: %r"); fprint(2, "announce %s...", vaddr); ventisrv = vtlisten(vaddr); if(ventisrv == nil) sysfatal("can't announce %s: %r", vaddr); fprint(2, "serving.\n"); if(nofork) ventiserver(nil); else vtproc(ventiserver, nil); threadexits(nil); }
void threadmain(int argc, char *argv[]) { int i, nline; char *p, *q, *table, *table1, *f[10], line[256]; vlong start, stop; ArenaPart ap; ArenaPart ap1; ventifmtinstall(); blocksize = MaxIoSize; ARGBEGIN{ case 'b': blocksize = unittoull(EARGF(usage())); break; case 's': sleepms = atoi(EARGF(usage())); break; case 'v': verbose++; break; default: usage(); break; }ARGEND if(argc < 2) usage(); data = vtmalloc(blocksize); data1 = vtmalloc(blocksize); if((fd = open(argv[0], OREAD)) < 0) sysfatal("open %s: %r", argv[0]); if((fd1 = open(argv[1], OREAD)) < 0) sysfatal("open %s: %r", argv[0]); table = readap(fd, &ap); table1 = readap(fd1, &ap1); if(strcmp(table, table1) != 0) sysfatal("arena partitions do not have identical tables"); nline = atoi(table); p = strchr(table, '\n'); if(p) p++; for(i=0; i<nline; i++){ if(p == nil){ fprint(2, "warning: unexpected arena table end\n"); break; } q = strchr(p, '\n'); if(q) *q++ = 0; if(strlen(p) >= sizeof line){ fprint(2, "warning: long arena table line: %s\n", p); p = q; continue; } strcpy(line, p); memset(f, 0, sizeof f); if(tokenize(line, f, nelem(f)) < 3){ fprint(2, "warning: bad arena table line: %s\n", p); p = q; continue; } p = q; if(shouldcheck(f[0], argv+1, argc-1)){ start = strtoull(f[1], 0, 0); stop = strtoull(f[2], 0, 0); if(stop <= start){ fprint(2, "%s: bad start,stop %lld,%lld\n", f[0], stop, start); continue; } if(seek(fd, start, 0) < 0) fprint(2, "%s: seek to start: %r\n", f[0]); if(seek(fd1, start, 0) < 0) fprint(2, "%s: seek to start: %r\n", f[0]); cmparena(f[0], stop - start); } } for(i=2; i<argc; i++) if(argv[i] != 0) fprint(2, "%s: did not find arena\n", argv[i]); threadexitsall(nil); }
void threadmain(int argc, char *argv[]) { int vers; ISect *is; Part *part; char *file, *name; int blocksize, setsize, zero; ventifmtinstall(); statsinit(); blocksize = 8 * 1024; setsize = 512 * 1024; zero = -1; vers = ISectVersion2; ARGBEGIN{ case 'b': blocksize = unittoull(ARGF()); if(blocksize == ~0) usage(); if(blocksize > MaxDiskBlock){ fprint(2, "block size too large, max %d\n", MaxDiskBlock); threadexitsall("usage"); } break; case '1': vers = ISectVersion1; break; case 'Z': zero = 0; break; default: usage(); break; }ARGEND if(zero == -1){ if(vers == ISectVersion1) zero = 1; else zero = 0; } if(argc != 2) usage(); name = argv[0]; file = argv[1]; if(nameok(name) < 0) sysfatal("illegal name %s", name); part = initpart(file, ORDWR|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); if(zero) zeropart(part, blocksize); is = newisect(part, vers, name, blocksize, setsize); if(is == nil) sysfatal("can't initialize new index: %r"); fprint(2, "fmtisect %s: %,d buckets of %,d entries, %,d bytes for index map\n", file, is->blocks, is->buckmax, setsize); if(wbisect(is) < 0) fprint(2, "can't write back index section header for %s: %r\n", file); threadexitsall(0); }