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 [-h host] arenafile [offset]\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\n", 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, "corrupt at %#llx: +%d\n",
91 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[])
134 u64int offset, aoffset;
145 ventidoublechecksha1 = 0;
148 host = EARGF(usage());
152 aoffset = strtoull(EARGF(usage()), 0, 0);
155 maxwrites = atoi(EARGF(usage()));
170 offset = strtoull(argv[1], 0, 0);
180 part = initpart(file, OREAD);
182 sysfatal("can't open file %s: %r", file);
183 if(readpart(part, aoffset, buf, sizeof buf) < 0)
184 sysfatal("can't read file %s: %r", file);
186 if(unpackarenahead(&head, buf) < 0)
187 sysfatal("corrupted arena header: %r");
189 if(aoffset+head.size > part->size)
190 sysfatal("arena is truncated: want %llud bytes have %llud\n",
191 head.size, part->size);
193 partblocksize(part, head.blocksize);
194 initdcache(8 * MaxDiskBlock);
196 arena = initarena(part, aoffset, head.size, head.blocksize);
198 sysfatal("initarena: %r");
201 if(host==nil || strcmp(host, "/dev/null") != 0){
204 sysfatal("could not connect to server: %r");
206 sysfatal("vtconnect: %r");
209 print("%T starting to send data\n");
210 c = chancreate(sizeof(ZClump), 0);
212 vtproc(vtsendthread, nil);
214 rdarena(arena, offset);
215 memset(&zerocl, 0, sizeof zerocl);
219 sysfatal("executing sync: %r");
223 print("%T sent all data\n");