8 int mainstacksize = 256*1024;
10 static void ventiserver(char *vaddr);
13 threadmain(int argc, char *argv[])
15 char *config, *haddr, *vaddr;
16 u32int mem, icmem, bcmem, minbcmem;
18 vaddr = "tcp!*!venti";
31 bcmem = unittoull(ARGF());
39 mem = unittoull(ARGF());
50 icmem = unittoull(ARGF());
59 print("whack %d\n", sizeof(Whack));
63 fprint(2, "usage: venti [-dw] [-a ventiaddress] [-h httpaddress] [-c config] [-C cachesize] [-I icachesize] [-B blockcachesize]\n");
64 threadexitsall("usage");
67 fmtinstall('V', vtscorefmt);
68 fmtinstall('H', encodefmt);
69 fmtinstall('F', vtfcallfmt);
72 config = "venti.conf";
75 if(initarenasum() < 0)
76 fprint(2, "warning: can't initialize arena summing process: %r");
78 if(initventi(config) < 0)
79 sysfatal("can't init server: %r");
81 if(mem == 0xffffffffUL)
82 mem = 1 * 1024 * 1024;
83 fprint(2, "initialize %d bytes of lump cache for %d lumps\n",
84 mem, mem / (8 * 1024));
85 initlumpcache(mem, mem / (8 * 1024));
87 icmem = u64log2(icmem / (sizeof(IEntry)+sizeof(IEntry*)) / ICacheDepth);
90 fprint(2, "initialize %d bytes of index cache for %d index entries\n",
91 (sizeof(IEntry)+sizeof(IEntry*)) * (1 << icmem) * ICacheDepth,
92 (1 << icmem) * ICacheDepth);
93 initicache(icmem, ICacheDepth);
96 * need a block for every arena and every process
98 minbcmem = maxblocksize *
99 (mainindex->narenas + mainindex->nsects*4 + 16);
103 fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
106 fprint(2, "sync arenas and index...\n");
107 if(syncindex(mainindex, 1) < 0)
108 sysfatal("can't sync server: %r");
111 fprint(2, "initialize write queue...\n");
112 if(initlumpqueues(mainindex->nsects) < 0){
113 fprint(2, "can't initialize lump queues,"
114 " disabling write queueing: %r");
120 fprint(2, "starting http server at %s\n", haddr);
121 if(httpdinit(haddr) < 0)
122 fprint(2, "warning: can't start http server: %r");
130 vtrerror(VtReq *r, char *error)
132 r->rx.type = VtRerror;
133 r->rx.error = estrdup(error);
137 ventiserver(char *addr)
146 sysfatal("can't announce %s: %r", addr);
148 while((r = vtgetreq(s)) != nil){
149 r->rx.type = r->tx.type+1;
150 // print("req (arenas[0]=%p sects[0]=%p) %F\n",
151 // mainindex->arenas[0], mainindex->sects[0], &r->tx);
154 vtrerror(r, "unknown request");
157 if((r->rx.data = readlump(r->tx.score, r->tx.dtype, r->tx.count)) == nil){
158 rerrstr(err, sizeof err);
165 if(writelump(p, r->rx.score, r->tx.dtype, 0) < 0){
166 rerrstr(err, sizeof err);