7 int readonly = 1; /* for part.c */
8 int mainstacksize = 256*1024;
11 int fast; /* and a bit unsafe; only for benchmarking */
16 typedef struct ZClump ZClump;
27 fprint(2, "usage: wrarena [-o fileoffset] [-h host] arenafile [clumpoffset]\n");
28 threadexitsall("usage");
37 while(recv(c, &zcl) == 1){
40 if(vtwrite(z, zcl.cl.info.score, zcl.cl.info.type, zcl.lump->data, zcl.cl.info.uncsize) < 0)
41 sysfatal("failed writing clump %llud: %r", zcl.aa);
43 print("%V\n", zcl.cl.info.score);
47 * All the send threads try to exit right when
48 * threadmain is calling threadexitsall.
49 * Either libthread or the Linux NPTL pthreads library
50 * can't handle this condition (I suspect NPTL but have
51 * not confirmed this) and we get a seg fault in exit.
52 * I spent a day tracking this down with no success,
53 * so we're going to work around it instead by just
54 * sitting here and waiting for the threadexitsall to
61 rdarena(Arena *arena, u64int offset)
65 uchar score[VtScoreSize];
71 fprint(2, "wrarena: copying %s to venti\n", arena->name);
75 e = arena->base + arena->size;
76 if(offset != ~(u64int)0) {
78 sysfatal("bad offset %#llx >= %#llx", offset, e - a);
84 for(a = 0; maxwrites != 0 && i < arena->memstats.clumps;
85 a += ClumpSize + ci.size){
86 if(readclumpinfo(arena, i++, &ci) < 0)
88 if(a < aa || ci.type == VtCorruptType){
89 if(ci.type == VtCorruptType)
90 fprint(2, "%s: corrupt clump read at %#llx: +%d\n",
91 argv0, a, ClumpSize+ci.size);
94 lump = loadclump(arena, a, 0, &cl, score, 0);
96 fprint(2, "clump %#llx failed to read: %r\n", a);
99 if(!fast && cl.info.type != VtCorruptType) {
100 scoremem(score, lump->data, cl.info.uncsize);
101 if(scorecmp(cl.info.score, score) != 0) {
102 fprint(2, "clump %#llx has mismatched score\n",
106 if(vttypevalid(cl.info.type) < 0) {
107 fprint(2, "clump %#llx has bad type %d\n",
112 if(z && cl.info.type != VtCorruptType){
125 print("end offset %#llx\n", aa);
129 threadmain(int argc, char *argv[])
135 u64int offset, aoffset;
146 ventidoublechecksha1 = 0;
149 host = EARGF(usage());
153 aoffset = strtoull(EARGF(usage()), 0, 0);
156 maxwrites = atoi(EARGF(usage()));
171 offset = strtoull(argv[1], 0, 0);
181 part = initpart(file, OREAD);
183 sysfatal("can't open file %s: %r", file);
185 // Try as arena partition.
187 ap = initarenapart(part);
191 if(readpart(part, aoffset, buf, sizeof buf) < 0)
192 sysfatal("can't read file %s: %r", file);
194 if(unpackarenahead(&head, buf) < 0)
195 sysfatal("corrupted arena header: %r");
197 if(aoffset+head.size > part->size)
198 sysfatal("arena is truncated: want %llud bytes have %llud",
199 head.size, part->size);
201 partblocksize(part, head.blocksize);
203 arena = initarena(part, aoffset, head.size, head.blocksize);
205 sysfatal("initarena: %r");
209 if(host==nil || strcmp(host, "/dev/null") != 0){
212 sysfatal("could not connect to server: %r");
214 sysfatal("vtconnect: %r");
217 print("%T starting to send data\n");
218 c = chancreate(sizeof(ZClump), 0);
220 vtproc(vtsendthread, nil);
222 initdcache(8 * MaxDiskBlock);
225 for(i=0; i<ap->narenas; i++)
226 rdarena(ap->arenas[i], 0);
228 rdarena(arena, offset);
230 memset(&zerocl, 0, sizeof zerocl);
234 sysfatal("executing sync: %r");
238 print("%T sent all data\n");