6 static int disksummary(HConnect*);
7 static int diskarenapart(HConnect*, char*, Part*);
8 static int diskbloom(HConnect*, char*, Part*);
9 static int diskisect(HConnect*, char*, Part*);
21 disk = hargstr(c, "disk", "");
23 return disksummary(c);
24 if((p = initpart(disk, OREAD)) == nil){
25 hprint(&c->hout, "open %s: %r", disk);
29 type = hargstr(c, "type", "");
32 ret = diskarenapart(c, disk, p);
35 ret = diskbloom(c, disk, p);
38 ret = diskisect(c, disk, p);
41 hprint(&c->hout, "unknown disk type %s", type);
49 disksummary(HConnect *c)
55 hprint(&c->hout, "<h1>venti disks</h1>\n");
56 hprint(&c->hout, "<pre>\n");
59 for(i=0; i<ix->narenas; i++){
60 if(ix->arenas[i]->part == p)
62 p = ix->arenas[i]->part;
63 hprint(&c->hout, "<a href=\"/disk?disk=%s&type=a\">%s</a> %s\n", p->name, p->name, ix->arenas[i]->name);
65 hprint(&c->hout, "\n");
67 for(i=0; i<ix->nsects; i++){
68 if(ix->sects[i]->part == p)
70 p = ix->sects[i]->part;
71 hprint(&c->hout, "<a href=\"/disk?disk=%s&type=i\">%s</a> %s\n", p->name, p->name, ix->sects[i]->name);
73 hprint(&c->hout, "\n");
76 hprint(&c->hout, "<a href=\"/disk?disk=%s&type=b\">%s</a> %s\n", p->name, p->name, "bloom filter");
82 readap(Part *p, ArenaPart *ap)
88 if(readpart(p, PartBlank, blk, 8192) != 8192)
90 if(unpackarenapart(ap, blk) < 0){
91 werrstr("corrupt arena part header: %r");
95 ap->tabbase = (PartBlank+HeadSize+ap->blocksize-1)&~(ap->blocksize-1);
96 ap->tabsize = ap->arenabase - ap->tabbase;
97 table = vtmalloc(ap->tabsize+1);
98 if(readpart(p, ap->tabbase, (uchar*)table, ap->tabsize) != ap->tabsize){
99 werrstr("reading arena part directory: %r");
102 table[ap->tabsize] = 0;
107 xfindarena(char *table, char *name, vlong *start, vlong *end)
110 char *p, *q, *f[4], line[256];
113 p = strchr(table, '\n');
116 for(i=0; i<nline; i++){
122 if(strlen(p) >= sizeof line){
127 memset(f, 0, sizeof f);
128 if(tokenize(line, f, nelem(f)) < 3){
132 if(strcmp(f[0], name) == 0){
133 *start = strtoull(f[1], 0, 0);
134 *end = strtoull(f[2], 0, 0);
143 diskarenatable(HConnect *c, char *disk, char *table)
147 char *f[4], line[256], base[256];
149 hprint(&c->hout, "<h2>table</h2>\n");
150 hprint(&c->hout, "<pre>\n");
152 snprint(base, sizeof base, "/disk?disk=%s&type=a", disk);
153 p = strchr(table, '\n');
156 for(i=0; i<nline; i++){
158 hprint(&c->hout, "<b><i>unexpected end of table</i></b>\n");
164 if(strlen(p) >= sizeof line){
165 hprint(&c->hout, "%s\n", p);
170 memset(f, 0, sizeof f);
171 if(tokenize(line, f, 3) < 3){
172 hprint(&c->hout, "%s\n", p);
177 hprint(&c->hout, "<a href=\"%s&arena=%s\">%s</a> %s %s\n",
178 base, f[0], f[0], f[1], f[2]);
180 hprint(&c->hout, "</pre>\n");
184 fmttime(char *buf, ulong time)
186 strcpy(buf, ctime(time));
192 static int diskarenaclump(HConnect*, Arena*, vlong, char*);
193 static int diskarenatoc(HConnect*, Arena*);
196 diskarenapart(HConnect *c, char *disk, Part *p)
206 vlong start, end, off;
209 hprint(&c->hout, "<h1>arena partition %s</h1>\n", disk);
211 if((table = readap(p, &ap)) == nil){
212 hprint(&c->hout, "%r\n");
216 hprint(&c->hout, "<pre>\n");
217 hprint(&c->hout, "version=%d blocksize=%d base=%d\n",
218 ap.version, ap.blocksize, ap.arenabase);
219 hprint(&c->hout, "</pre>\n");
221 arenaname = hargstr(c, "arena", "");
222 if(arenaname[0] == 0){
223 diskarenatable(c, disk, table);
227 if(xfindarena(table, arenaname, &start, &end) < 0){
228 hprint(&c->hout, "no such arena %s\n", arenaname);
232 hprint(&c->hout, "<h2>arena %s</h2>\n", arenaname);
233 hprint(&c->hout, "<pre>start=%#llx end=%#llx<pre>\n", start, end);
234 if(end < start || end - start < HeadSize){
235 hprint(&c->hout, "bad size %#llx\n", end - start);
239 // read arena header, tail
240 blk = vtmalloc(HeadSize);
241 if(readpart(p, start, blk, HeadSize) != HeadSize){
242 hprint(&c->hout, "reading header: %r\n");
246 if(unpackarenahead(&head, blk) < 0){
247 hprint(&c->hout, "corrupt arena header: %r\n");
248 // hhex(blk, HeadSize);
254 hprint(&c->hout, "head:\n<pre>\n");
255 hprint(&c->hout, "version=%d name=%s blocksize=%d size=%#llx clumpmagic=%#ux\n",
256 head.version, head.name, head.blocksize, head.size,
258 hprint(&c->hout, "</pre><br><br>\n");
260 if(head.blocksize > MaxIoSize || head.blocksize >= end - start){
261 hprint(&c->hout, "corrupt block size %d\n", head.blocksize);
265 blk = vtmalloc(head.blocksize);
266 if(readpart(p, end - head.blocksize, blk, head.blocksize) < 0){
267 hprint(&c->hout, "reading tail: %r\n");
271 memset(&arena, 0, sizeof arena);
273 arena.blocksize = head.blocksize;
274 arena.clumpmax = head.blocksize / ClumpInfoSize;
275 arena.base = start + head.blocksize;
276 arena.size = end - start - 2 * head.blocksize;
277 if(unpackarena(&arena, blk) < 0){
281 scorecp(arena.score, blk+head.blocksize - VtScoreSize);
285 hprint(&c->hout, "tail:\n<pre>\n");
286 hprint(&c->hout, "version=%d name=%s\n", arena.version, arena.name);
287 hprint(&c->hout, "ctime=%d %s\n", arena.ctime, fmttime(tbuf, arena.ctime));
288 hprint(&c->hout, "wtime=%d %s\n", arena.wtime, fmttime(tbuf, arena.wtime));
289 hprint(&c->hout, "clumpmagic=%#ux\n", arena.clumpmagic);
290 hprint(&c->hout, "score %V\n", arena.score);
291 hprint(&c->hout, "diskstats:\n");
292 hprint(&c->hout, "\tclumps=%,d cclumps=%,d used=%,lld uncsize=%,lld sealed=%d\n",
293 arena.diskstats.clumps, arena.diskstats.cclumps,
294 arena.diskstats.used, arena.diskstats.uncsize,
295 arena.diskstats.sealed);
296 hprint(&c->hout, "memstats:\n");
297 hprint(&c->hout, "\tclumps=%,d cclumps=%,d used=%,lld uncsize=%,lld sealed=%d\n",
298 arena.memstats.clumps, arena.memstats.cclumps,
299 arena.memstats.used, arena.memstats.uncsize,
300 arena.memstats.sealed);
301 if(arena.clumpmax == 0){
302 hprint(&c->hout, "bad clumpmax\n");
306 score = hargstr(c, "score", "");
307 clump = hargstr(c, "clump", "");
310 off = strtoull(clump, 0, 0);
311 diskarenaclump(c, &arena, off, score[0] ? score : nil);
313 diskarenaclump(c, &arena, -1, score);
315 diskarenatoc(c, &arena);
324 findintoc(HConnect *c, Arena *arena, uchar *score)
332 blk = vtmalloc(arena->blocksize);
333 off = arena->base + arena->size;
335 for(i=0; i<arena->memstats.clumps; i++){
336 if(i%arena->clumpmax == 0){
337 off -= arena->blocksize;
338 if(readpart(arena->part, off, blk, arena->blocksize) != arena->blocksize){
340 hprint(&c->hout, "<i>clump info directory at %#llx: %r</i>\n<br>\n",
345 unpackclumpinfo(&ci, blk+(i%arena->clumpmax)*ClumpInfoSize);
346 if(scorecmp(ci.score, score) == 0){
350 coff += ClumpSize + ci.size;
358 diskarenatoc(HConnect *c, Arena *arena)
368 snprint(base, sizeof base, "/disk?disk=%s&type=a&arena=%s",
369 arena->part->name, arena->name);
371 blk = vtmalloc(arena->blocksize);
372 off = arena->base + arena->size;
373 hprint(&c->hout, "<h2>table of contents</h2>\n");
374 hprint(&c->hout, "<pre>\n");
375 hprint(&c->hout, "%5s %6s %7s %s\n", "type", "size", "uncsize", "score");
377 cib = hargint(c, "cib", 0);
379 for(i=0; i<arena->memstats.clumps; i++){
380 if(i%arena->clumpmax == 0){
381 off -= arena->blocksize;
382 if(readpart(arena->part, off, blk, arena->blocksize) != arena->blocksize){
383 hprint(&c->hout, "<i>clump info directory at %#llx: %r</i>\n<br>\n",
385 i += arena->clumpmax-1;
390 unpackclumpinfo(&ci, blk+(i%arena->clumpmax)*ClumpInfoSize);
391 if(i/arena->clumpmax == cib || i%arena->clumpmax == 0){
392 hprint(&c->hout, "%5d %6d %7d %V",
393 ci.type, ci.size, ci.uncsize, ci.score);
395 hprint(&c->hout, " at <a href=\"%s&clump=%#llx&score=%V\">%#llx</a>",
396 base, coff, ci.score, coff);
397 if(i/arena->clumpmax != cib)
398 hprint(&c->hout, " <font size=-1><a href=\"%s&cib=%d\">more</a></font>", base, i/arena->clumpmax);
399 hprint(&c->hout, "\n");
402 coff += ClumpSize + ci.size;
404 hprint(&c->hout, "</pre>\n");
408 #define U32GET(p) ((u32int)(((p)[0]<<24)|((p)[1]<<16)|((p)[2]<<8)|(p)[3]))
410 diskarenaclump(HConnect *c, Arena *arena, vlong off, char *scorestr)
415 uchar xscore[VtScoreSize], score[VtScoreSize];
420 if(vtparsescore(scorestr, nil, score) < 0){
421 hprint(&c->hout, "bad score %s: %r\n", scorestr);
425 off = findintoc(c, arena, score);
427 hprint(&c->hout, "score %V not found in arena %s\n", score, arena->name);
430 hprint(&c->hout, "score %V at %#llx\n", score, off);
433 memset(score, 0, sizeof score);
436 hprint(&c->hout, "bad offset %#llx\n", off);
442 blk = vtmalloc(ClumpSize + VtMaxLumpSize);
443 if(readpart(arena->part, off, blk, ClumpSize + VtMaxLumpSize) != ClumpSize + VtMaxLumpSize){
444 hprint(&c->hout, "reading at %#llx: %r\n", off);
449 if(unpackclump(&cl, blk, arena->clumpmagic) < 0){
450 hprint(&c->hout, "unpackclump: %r\n<br>");
451 rerrstr(err, sizeof err);
452 if(strstr(err, "magic")){
453 hprint(&c->hout, "trying again with magic=%#ux<br>\n", U32GET(blk));
454 if(unpackclump(&cl, blk, U32GET(blk)) < 0){
455 hprint(&c->hout, "unpackclump: %r\n<br>\n");
462 hprint(&c->hout, "<pre>type=%d size=%d uncsize=%d score=%V\n", cl.info.type, cl.info.size, cl.info.uncsize, cl.info.score);
463 hprint(&c->hout, "encoding=%d creator=%d time=%d %s</pre>\n", cl.encoding, cl.creator, cl.time, fmttime(err, cl.time));
465 if(cl.info.type == VtCorruptType)
466 hprint(&c->hout, "clump is marked corrupt<br>\n");
468 if(cl.info.size >= VtMaxLumpSize){
469 hprint(&c->hout, "clump too big\n");
475 blk2 = vtmalloc(VtMaxLumpSize);
477 n = unwhack(&uw, blk2, cl.info.uncsize, blk+ClumpSize, cl.info.size);
479 hprint(&c->hout, "decompression failed\n");
483 if(n != cl.info.uncsize){
484 hprint(&c->hout, "got wrong amount: %d wanted %d\n", n, cl.info.uncsize);
489 scoremem(xscore, blk2, cl.info.uncsize);
493 scoremem(xscore, blk+ClumpSize, cl.info.size);
497 hprint(&c->hout, "score=%V<br>\n", xscore);
498 if(scorestr && scorecmp(score, xscore) != 0)
499 hprint(&c->hout, "score does NOT match expected %V\n", score);
505 // hhex(blk, ClumpSize + VtMaxLumpSize);
511 diskbloom(HConnect *c, char *disk, Part *p)
520 diskisect(HConnect *c, char *disk, Part *p)
529 debugamap(HConnect *c)
534 hprint(&c->hout, "<h2>arena map</h2>\n");
535 hprint(&c->hout, "<pre>\n");
537 amap = mainindex->amap;
538 for(i=0; i<mainindex->narenas; i++)
539 hprint(&c->hout, "%s %#llx %#llx\n",
540 amap[i].name, amap[i].start, amap[i].stop);
544 debugread(HConnect *c, u8int *score)
556 u8int sc[VtScoreSize];
558 if(scorecmp(score, zeroscore) == 0){
559 hprint(&c->hout, "zero score\n");
563 hprint(&c->hout, "<h2>index search %V</h2><pre>\n", score);
564 if(icachelookup(score, -1, &ia) < 0)
565 hprint(&c->hout, " icache: not found\n");
567 hprint(&c->hout, " icache: addr=%#llx size=%d type=%d blocks=%d\n",
568 ia.addr, ia.size, ia.type, ia.blocks);
570 if(loadientry(mainindex, score, -1, &ie) < 0)
571 hprint(&c->hout, " idisk: not found\n");
573 hprint(&c->hout, " idisk: addr=%#llx size=%d type=%d blocks=%d\n",
574 ie.ia.addr, ie.ia.size, ie.ia.type, ie.ia.blocks);
576 hprint(&c->hout, "</pre><h2>lookup %V</h2>\n", score);
577 hprint(&c->hout, "<pre>\n");
579 for(type=0; type < VtMaxType; type++){
580 hprint(&c->hout, "%V type %d:", score, type);
581 u = lookuplump(score, type);
583 hprint(&c->hout, " +cache");
585 hprint(&c->hout, " -cache");
588 if(lookupscore(score, type, &ia) < 0){
589 hprint(&c->hout, " -lookup\n");
592 hprint(&c->hout, "\n lookupscore: addr=%#llx size=%d blocks=%d\n",
593 ia.addr, ia.size, ia.blocks);
595 arena = amapitoa(mainindex, ia.addr, &aa);
597 hprint(&c->hout, " amapitoa failed: %r\n");
601 hprint(&c->hout, " amapitoa: aa=%#llx arena="
602 "<a href=\"/disk?disk=%s&type=a&arena=%s&score=%V\">%s</a>\n",
603 aa, arena->part->name, arena->name, score, arena->name);
604 zb = loadclump(arena, aa, ia.blocks, &cl, sc, 1);
606 hprint(&c->hout, " loadclump failed: %r\n");
610 hprint(&c->hout, " loadclump: uncsize=%d type=%d score=%V\n",
611 cl.info.uncsize, cl.info.type, sc);
612 if(ia.size != cl.info.uncsize || ia.type != cl.info.type || scorecmp(score, sc) != 0){
613 hprint(&c->hout, " clump info mismatch\n");
618 if(hargstr(c, "brute", "")[0] == 'y'){
619 hprint(&c->hout, "</pre>\n");
620 hprint(&c->hout, "<h2>brute force arena search %V</h2>\n", score);
621 hprint(&c->hout, "<pre>\n");
623 for(i=0; i<mainindex->narenas; i++){
624 arena = mainindex->arenas[i];
625 hprint(&c->hout, "%s...\n", arena->name);
627 off = findintoc(nil, arena, score);
629 hprint(&c->hout, "%s %#llx (%#llx)\n", arena->name, off, mainindex->amap[i].start + off);
633 hprint(&c->hout, "</pre>\n");
637 debugmem(HConnect *c)
642 hprint(&c->hout, "<h2>memory</h2>\n");
644 hprint(&c->hout, "<pre>\n");
645 hprint(&c->hout, "ix=%p\n", ix);
646 hprint(&c->hout, "\tarenas=%p\n", ix->arenas);
648 hprint(&c->hout, "\tarenas[...] = %p...%p\n", ix->arenas[0], ix->arenas[ix->narenas-1]);
649 hprint(&c->hout, "\tsmap=%p\n", ix->smap);
650 hprint(&c->hout, "\tamap=%p\n", ix->amap);
651 hprint(&c->hout, "\tbloom=%p\n", ix->bloom);
652 hprint(&c->hout, "\tbloom->data=%p\n", ix->bloom ? ix->bloom->data : nil);
653 hprint(&c->hout, "\tisects=%p\n", ix->sects);
655 hprint(&c->hout, "\tsects[...] = %p...%p\n", ix->sects[0], ix->sects[ix->nsects-1]);
662 u8int score[VtScoreSize];
666 hprint(&c->hout, "<h1>venti debug</h1>\n");
668 op = hargstr(c, "op", "");
670 hprint(&c->hout, "no op\n");
674 if(strcmp(op, "amap") == 0){
679 if(strcmp(op, "mem") == 0){
684 if(strcmp(op, "read") == 0){
685 scorestr = hargstr(c, "score", "");
686 if(vtparsescore(scorestr, nil, score) < 0){
687 hprint(&c->hout, "bad score %s: %r\n", scorestr);
694 hprint(&c->hout, "unknown op %s", op);