7 int readonly = 1; /* for part.c */
8 int mainstacksize = 256*1024;
11 int fast; /* and a bit unsafe; only for benchmarking */
15 typedef struct ZClump ZClump;
26 fprint(2, "usage: wrarena [-h host] arenafile [offset]\n");
27 threadexitsall("usage");
36 while(recv(c, &zcl) == 1){
39 if(vtwrite(z, zcl.cl.info.score, zcl.cl.info.type, zcl.lump->data, zcl.cl.info.uncsize) < 0)
40 sysfatal("failed writing clump %llud: %r", zcl.aa);
44 * All the send threads try to exit right when
45 * threadmain is calling threadexitsall.
46 * Either libthread or the Linux NPTL pthreads library
47 * can't handle this condition (I suspect NPTL but have
48 * not confirmed this) and we get a seg fault in exit.
49 * I spent a day tracking this down with no success,
50 * so we're going to work around it instead by just
51 * sitting here and waiting for the threadexitsall to
58 rdarena(Arena *arena, u64int offset)
63 uchar score[VtScoreSize];
67 fprint(2, "wrarena: copying %s to venti\n", arena->name);
71 e = arena->base + arena->size;
72 if(offset != ~(u64int)0) {
74 sysfatal("bad offset %llud >= %llud\n",
81 for(; aa < e; aa += ClumpSize+cl.info.size) {
82 magic = clumpmagic(arena, aa);
83 if(magic == ClumpFreeMagic)
85 if(magic != arena->clumpmagic) {
86 // fprint(2, "illegal clump magic number %#8.8ux offset %llud\n",
90 lump = loadclump(arena, aa, 0, &cl, score, 0);
92 fprint(2, "clump %llud failed to read: %r\n", aa);
95 if(!fast && cl.info.type != VtCorruptType) {
96 scoremem(score, lump->data, cl.info.uncsize);
97 if(scorecmp(cl.info.score, score) != 0) {
98 fprint(2, "clump %llud has mismatched score\n", aa);
101 if(vttypevalid(cl.info.type) < 0) {
102 fprint(2, "clump %llud has bad type %d\n", aa, cl.info.type);
106 if(z && cl.info.type != VtCorruptType){
113 if(maxwrites>0 && --maxwrites == 0)
117 print("end offset %llud\n", aa);
121 threadmain(int argc, char *argv[])
126 u64int offset, aoffset;
138 ventidoublechecksha1 = 0;
141 host = EARGF(usage());
145 aoffset = strtoull(EARGF(usage()), 0, 0);
148 maxwrites = atoi(EARGF(usage()));
160 offset = strtoull(argv[1], 0, 0);
166 fmtinstall('V', vtscorefmt);
170 if((d = dirstat(file)) == nil)
171 sysfatal("can't stat file %s: %r", file);
173 part = initpart(file, OREAD);
175 sysfatal("can't open file %s: %r", file);
176 if(readpart(part, aoffset, buf, sizeof buf) < 0)
177 sysfatal("can't read file %s: %r", file);
179 if(unpackarenahead(&head, buf) < 0)
180 sysfatal("corrupted arena header: %r");
182 if(aoffset+head.size > d->length)
183 sysfatal("arena is truncated: want %llud bytes have %llud\n",
184 head.size, d->length);
186 partblocksize(part, head.blocksize);
187 initdcache(8 * MaxDiskBlock);
189 arena = initarena(part, aoffset, head.size, head.blocksize);
191 sysfatal("initarena: %r");
194 if(host==nil || strcmp(host, "/dev/null") != 0){
197 sysfatal("could not connect to server: %r");
199 sysfatal("vtconnect: %r");
202 c = chancreate(sizeof(ZClump), 0);
204 vtproc(vtsendthread, nil);
206 rdarena(arena, offset);
208 sysfatal("executing sync: %r");
210 memset(&zerocl, 0, sizeof zerocl);