2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Read a VLDB file and verify it for correctness */
12 #define VL 0x001 /* good volume entry */
13 #define FR 0x002 /* free volume entry */
14 #define MH 0x004 /* multi-homed entry */
16 #define RWH 0x010 /* on rw hash chain */
17 #define ROH 0x020 /* on ro hash chain */
18 #define BKH 0x040 /* on bk hash chain */
19 #define NH 0x080 /* on name hash chain */
21 #define MHC 0x100 /* on multihomed chain */
22 #define FRC 0x200 /* on free chain */
24 #define REFRW 0x1000 /* linked from something (RW) */
25 #define REFRO 0x2000 /* linked from something (RO) */
26 #define REFBK 0x4000 /* linked from something (BK) */
27 #define REFN 0x8000 /* linked from something (name) */
29 #define MULTRW 0x10000 /* multiply-chained (RW) */
30 #define MULTRO 0x20000 /* multiply-chained (RO) */
31 #define MULTBK 0x40000 /* multiply-chained (BK) */
32 #define MULTN 0x80000 /* multiply-chained (name) */
34 #define MISRWH 0x100000 /* mischained (RW) */
35 #define MISROH 0x200000 /* mischained (RO) */
36 #define MISBKH 0x400000 /* mischained (BK) */
37 #define MISNH 0x800000 /* mischained (name) */
39 #define VLDB_CHECK_NO_VLDB_CHECK_ERROR 0
40 #define VLDB_CHECK_WARNING 1
41 #define VLDB_CHECK_ERROR 2
42 #define VLDB_CHECK_FATAL 4
43 #define vldbread(x,y,z) vldbio(x,y,z,0)
44 #define vldbwrite(x,y,z) vldbio(x,y,z,1)
46 #include <afsconfig.h>
47 #include <afs/param.h>
51 #include <sys/types.h>
58 #include <WINNT/afsevent.h>
61 #include <sys/socket.h>
63 #include <netinet/in.h>
69 #include <afs/afsutil.h>
72 #define ADDR(x) (x/sizeof(struct nvlentry))
75 int listentries, listservers, listheader, listuheader, verbose, quiet;
79 /* if quiet, don't send anything to stdout */
81 /* error level. 0 = no error, 1 = warning, 2 = error, 4 = fatal */
89 int serveraddrs[MAXSERVERID + 2];
91 /* Used to control what goes to stdout based on quiet flag */
93 quiet_println(const char *fmt,...) {
97 vfprintf(stdout, fmt, args);
102 /* Used to set the error level and ship messages to stderr */
104 log_error(int eval, const char *fmt, ...)
107 if (error_level < eval) error_level = eval ; /* bump up the severity */
109 vfprintf(stderr, fmt, args);
112 if (error_level == VLDB_CHECK_FATAL) exit(VLDB_CHECK_FATAL);
120 /* Bump the version number?? We could cheat and push a new db... */
129 struct ubik_hdr uheader;
131 offset = lseek(fd, 0, 0);
133 log_error(VLDB_CHECK_FATAL,"error: lseek to 0 failed: %d %d\n", offset, errno);
134 return (VLDB_CHECK_FATAL);
137 /* now read the info */
138 r = read(fd, &uheader, sizeof(uheader));
139 if (r != sizeof(uheader)) {
140 log_error(VLDB_CHECK_FATAL,"error: read of %lu bytes failed: %d %d\n", sizeof(uheader), r,
142 return (VLDB_CHECK_FATAL);
145 uheader.magic = ntohl(uheader.magic);
146 uheader.size = ntohs(uheader.size);
147 uheader.version.epoch = ntohl(uheader.version.epoch);
148 uheader.version.counter = ntohl(uheader.version.counter);
151 quiet_println("Ubik Header\n");
152 quiet_println(" Magic = 0x%x\n", uheader.magic);
153 quiet_println(" Size = %u\n", uheader.size);
154 quiet_println(" Version.epoch = %u\n", uheader.version.epoch);
155 quiet_println(" Version.counter = %u\n", uheader.version.counter);
158 if (uheader.size != HDRSIZE)
159 log_error(VLDB_CHECK_WARNING,"VLDB_CHECK_WARNING: Ubik header size is %u (should be %u)\n", uheader.size,
161 if (uheader.magic != UBIK_MAGIC)
162 log_error(VLDB_CHECK_ERROR,"Ubik header magic is 0x%x (should be 0x%x)\n", uheader.magic,
169 vldbio(int position, void *buffer, int size, int rdwr)
173 /* seek to the correct spot. skip ubik stuff */
174 p = position + HDRSIZE;
175 offset = lseek(fd, p, 0);
177 log_error(VLDB_CHECK_FATAL,"error: lseek to %d failed: %d %d\n", p, offset, errno);
182 r = write(fd, buffer, size);
184 r = read(fd, buffer, size);
187 log_error(VLDB_CHECK_FATAL,"error: %s of %d bytes failed: %d %d\n", rdwr==1?"write":"read",
211 NameHash(char *volname)
217 for (vchar = volname + strlen(volname) - 1; vchar >= volname; vchar--)
218 hash = (hash * 63) + (*((unsigned char *)vchar) - 63);
219 return (hash % HASHSIZE);
223 IdHash(afs_uint32 volid)
225 return ((abs(volid)) % HASHSIZE);
228 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
230 InvalidVolname(char *volname)
236 slen = strlen(volname);
237 if (slen >= VL_MAXNAMELEN)
239 return (slen != strspn(volname, map));
243 validVolumeAddr(afs_uint32 fileOffset)
245 if (ADDR(fileOffset) >= maxentries) {
246 /* Are we in range */
250 * We cannot test whether the offset is aligned
251 * since the vl entries are not in a regular array
257 readheader(struct vlheader *headerp)
261 vldbread(0, (char *)headerp, sizeof(*headerp));
263 headerp->vital_header.vldbversion =
264 ntohl(headerp->vital_header.vldbversion);
265 headerp->vital_header.headersize =
266 ntohl(headerp->vital_header.headersize);
267 headerp->vital_header.freePtr = ntohl(headerp->vital_header.freePtr);
268 headerp->vital_header.eofPtr = ntohl(headerp->vital_header.eofPtr);
269 headerp->vital_header.allocs = ntohl(headerp->vital_header.allocs);
270 headerp->vital_header.frees = ntohl(headerp->vital_header.frees);
271 headerp->vital_header.MaxVolumeId =
272 ntohl(headerp->vital_header.MaxVolumeId);
273 headerp->vital_header.totalEntries[0] =
274 ntohl(headerp->vital_header.totalEntries[0]);
275 for (i = 0; i < MAXTYPES; i++)
276 headerp->vital_header.totalEntries[i] =
277 ntohl(headerp->vital_header.totalEntries[1]);
279 headerp->SIT = ntohl(headerp->SIT);
280 for (i = 0; i < MAXSERVERID; i++)
281 headerp->IpMappedAddr[i] = ntohl(headerp->IpMappedAddr[i]);
282 for (i = 0; i < HASHSIZE; i++)
283 headerp->VolnameHash[i] = ntohl(headerp->VolnameHash[i]);
284 for (i = 0; i < MAXTYPES; i++)
285 for (j = 0; j < HASHSIZE; j++)
286 headerp->VolidHash[i][j] = ntohl(headerp->VolidHash[i][j]);
289 quiet_println("vldb header\n");
290 quiet_println(" vldbversion = %u\n",
291 headerp->vital_header.vldbversion);
292 quiet_println(" headersize = %u [actual=%lu]\n",
293 headerp->vital_header.headersize, sizeof(*headerp));
294 quiet_println(" freePtr = 0x%x\n", headerp->vital_header.freePtr);
295 quiet_println(" eofPtr = %u\n", headerp->vital_header.eofPtr);
296 quiet_println(" allocblock calls = %10u\n", headerp->vital_header.allocs);
297 quiet_println(" freeblock calls = %10u\n", headerp->vital_header.frees);
298 quiet_println(" MaxVolumeId = %u\n",
299 headerp->vital_header.MaxVolumeId);
300 quiet_println(" rw vol entries = %u\n",
301 headerp->vital_header.totalEntries[0]);
302 quiet_println(" ro vol entries = %u\n",
303 headerp->vital_header.totalEntries[1]);
304 quiet_println(" bk vol entries = %u\n",
305 headerp->vital_header.totalEntries[2]);
306 quiet_println(" multihome info = 0x%x (%u)\n", headerp->SIT,
308 quiet_println(" server ip addr table: size = %d entries\n",
310 quiet_println(" volume name hash table: size = %d buckets\n", HASHSIZE);
311 quiet_println(" volume id hash table: %d tables with %d buckets each\n",
315 /* Check the header size */
316 if (headerp->vital_header.headersize != sizeof(*headerp))
317 log_error(VLDB_CHECK_WARNING,"Header reports its size as %d (should be %lu)\n",
318 headerp->vital_header.headersize, sizeof(*headerp));
323 writeheader(struct vlheader *headerp)
327 headerp->vital_header.vldbversion =
328 htonl(headerp->vital_header.vldbversion);
329 headerp->vital_header.headersize =
330 htonl(headerp->vital_header.headersize);
331 headerp->vital_header.freePtr = htonl(headerp->vital_header.freePtr);
332 headerp->vital_header.eofPtr = htonl(headerp->vital_header.eofPtr);
333 headerp->vital_header.allocs = htonl(headerp->vital_header.allocs);
334 headerp->vital_header.frees = htonl(headerp->vital_header.frees);
335 headerp->vital_header.MaxVolumeId =
336 htonl(headerp->vital_header.MaxVolumeId);
337 headerp->vital_header.totalEntries[0] =
338 htonl(headerp->vital_header.totalEntries[0]);
339 for (i = 0; i < MAXTYPES; i++)
340 headerp->vital_header.totalEntries[i] =
341 htonl(headerp->vital_header.totalEntries[1]);
343 headerp->SIT = htonl(headerp->SIT);
344 for (i = 0; i < MAXSERVERID; i++)
345 headerp->IpMappedAddr[i] = htonl(headerp->IpMappedAddr[i]);
346 for (i = 0; i < HASHSIZE; i++)
347 headerp->VolnameHash[i] = htonl(headerp->VolnameHash[i]);
348 for (i = 0; i < MAXTYPES; i++)
349 for (j = 0; j < HASHSIZE; j++)
350 headerp->VolidHash[i][j] = htonl(headerp->VolidHash[i][j]);
352 vldbwrite(0, (char *)headerp, sizeof(*headerp));
356 readMH(afs_int32 addr, struct extentaddr *mhblockP)
359 struct extentaddr *e;
361 vldbread(addr, (char *)mhblockP, VL_ADDREXTBLK_SIZE);
363 mhblockP->ex_count = ntohl(mhblockP->ex_count);
364 mhblockP->ex_flags = ntohl(mhblockP->ex_flags);
365 for (i = 0; i < VL_MAX_ADDREXTBLKS; i++)
366 mhblockP->ex_contaddrs[i] = ntohl(mhblockP->ex_contaddrs[i]);
368 for (i = 1; i < VL_MHSRV_PERBLK; i++) {
371 /* won't convert hostuuid */
372 e->ex_uniquifier = ntohl(e->ex_uniquifier);
373 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++)
374 e->ex_addrs[j] = ntohl(e->ex_addrs[j]);
380 readentry(afs_int32 addr, struct nvlentry *vlentryp, afs_int32 *type)
384 vldbread(addr, (char *)vlentryp, sizeof(*vlentryp));
386 for (i = 0; i < MAXTYPES; i++)
387 vlentryp->volumeId[i] = ntohl(vlentryp->volumeId[i]);
388 vlentryp->flags = ntohl(vlentryp->flags);
389 vlentryp->LockAfsId = ntohl(vlentryp->LockAfsId);
390 vlentryp->LockTimestamp = ntohl(vlentryp->LockTimestamp);
391 vlentryp->cloneId = ntohl(vlentryp->cloneId);
392 for (i = 0; i < MAXTYPES; i++)
393 vlentryp->nextIdHash[i] = ntohl(vlentryp->nextIdHash[i]);
394 vlentryp->nextNameHash = ntohl(vlentryp->nextNameHash);
395 for (i = 0; i < NMAXNSERVERS; i++) {
396 /* make sure not to ntohl these, as they're chars, not ints */
397 vlentryp->serverNumber[i] = vlentryp->serverNumber[i];
398 vlentryp->serverPartition[i] = vlentryp->serverPartition[i];
399 vlentryp->serverFlags[i] = vlentryp->serverFlags[i];
402 if (vlentryp->flags == VLCONTBLOCK) {
404 } else if (vlentryp->flags == VLFREE) {
411 quiet_println("address %u: ", addr);
412 if (vlentryp->flags == VLCONTBLOCK) {
413 quiet_println("mh extension block\n");
414 } else if (vlentryp->flags == VLFREE) {
415 quiet_println("free vlentry\n");
417 quiet_println("vlentry %s\n", vlentryp->name);
418 quiet_println(" rw id = %u ; ro id = %u ; bk id = %u\n",
419 vlentryp->volumeId[0], vlentryp->volumeId[1],
420 vlentryp->volumeId[2]);
421 quiet_println(" flags =");
422 if (vlentryp->flags & VLF_RWEXISTS)
423 quiet_println(" rw");
424 if (vlentryp->flags & VLF_ROEXISTS)
425 quiet_println(" ro");
426 if (vlentryp->flags & VLF_BACKEXISTS)
427 quiet_println(" bk");
428 if (vlentryp->flags & VLOP_MOVE)
429 quiet_println(" lock_move");
430 if (vlentryp->flags & VLOP_RELEASE)
431 quiet_println(" lock_release");
432 if (vlentryp->flags & VLOP_BACKUP)
433 quiet_println(" lock_backup");
434 if (vlentryp->flags & VLOP_DELETE)
435 quiet_println(" lock_delete");
436 if (vlentryp->flags & VLOP_DUMP)
437 quiet_println(" lock_dump");
439 /* all bits not covered by VLF_* and VLOP_* constants */
440 if (vlentryp->flags & 0xffff8e0f)
441 quiet_println(" errorflag(0x%x)", vlentryp->flags);
443 quiet_println(" LockAfsId = %d\n", vlentryp->LockAfsId);
444 quiet_println(" LockTimestamp = %d\n", vlentryp->LockTimestamp);
445 quiet_println(" cloneId = %u\n", vlentryp->cloneId);
447 (" next hash for rw = %u ; ro = %u ; bk = %u ; name = %u\n",
448 vlentryp->nextIdHash[0], vlentryp->nextIdHash[1],
449 vlentryp->nextIdHash[2], vlentryp->nextNameHash);
450 for (i = 0; i < NMAXNSERVERS; i++) {
451 if (vlentryp->serverNumber[i] != 255) {
452 quiet_println(" server %d ; partition %d ; flags =",
453 vlentryp->serverNumber[i],
454 vlentryp->serverPartition[i]);
455 if (vlentryp->serverFlags[i] & VLSF_RWVOL)
456 quiet_println(" rw");
457 if (vlentryp->serverFlags[i] & VLSF_ROVOL)
458 quiet_println(" ro");
459 if (vlentryp->serverFlags[i] & VLSF_BACKVOL)
460 quiet_println(" bk");
461 if (vlentryp->serverFlags[i] & VLSF_NEWREPSITE)
462 quiet_println(" newro");
472 writeentry(afs_int32 addr, struct nvlentry *vlentryp)
476 if (verbose) quiet_println("Writing back entry at addr %u\n", addr);
477 for (i = 0; i < MAXTYPES; i++)
478 vlentryp->volumeId[i] = htonl(vlentryp->volumeId[i]);
479 vlentryp->flags = htonl(vlentryp->flags);
480 vlentryp->LockAfsId = htonl(vlentryp->LockAfsId);
481 vlentryp->LockTimestamp = htonl(vlentryp->LockTimestamp);
482 vlentryp->cloneId = htonl(vlentryp->cloneId);
483 for (i = 0; i < MAXTYPES; i++)
484 vlentryp->nextIdHash[i] = htonl(vlentryp->nextIdHash[i]);
485 vlentryp->nextNameHash = htonl(vlentryp->nextNameHash);
486 for (i = 0; i < NMAXNSERVERS; i++) {
487 /* make sure not to htonl these, as they're chars, not ints */
488 vlentryp->serverNumber[i] = vlentryp->serverNumber[i] ;
489 vlentryp->serverPartition[i] = vlentryp->serverPartition[i] ;
490 vlentryp->serverFlags[i] = vlentryp->serverFlags[i] ;
492 vldbwrite(addr, (char *)vlentryp, sizeof(*vlentryp));
496 readSIT(int base, int addr)
499 char sitbuf[VL_ADDREXTBLK_SIZE];
500 struct extentaddr *extent;
504 vldbread(addr, sitbuf, VL_ADDREXTBLK_SIZE);
505 extent = (struct extentaddr *)sitbuf;
507 quiet_println("multihome info block: base %d\n", base);
509 quiet_println(" count = %u\n", ntohl(extent->ex_count));
510 quiet_println(" flags = %u\n", ntohl(extent->ex_flags));
511 for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
512 quiet_println(" contaddrs[%d] = %u\n", i,
513 ntohl(extent->ex_contaddrs[i]));
516 for (i = 1; i < VL_MHSRV_PERBLK; i++) {
517 /* should we skip this entry */
518 for (j = 0; j < VL_MAX_ADDREXTBLKS; j++) {
519 if (extent[i].ex_addrs[j])
522 if (j >= VL_MAX_ADDREXTBLKS)
525 quiet_println(" base %d index %d:\n", base, i);
527 quiet_println(" afsuuid = (%x %x %x /%d/%d/ /%x/%x/%x/%x/%x/%x/)\n",
528 ntohl(extent[i].ex_hostuuid.time_low),
529 ntohl(extent[i].ex_hostuuid.time_mid),
530 ntohl(extent[i].ex_hostuuid.time_hi_and_version),
531 ntohl(extent[i].ex_hostuuid.clock_seq_hi_and_reserved),
532 ntohl(extent[i].ex_hostuuid.clock_seq_low),
533 ntohl(extent[i].ex_hostuuid.node[0]),
534 ntohl(extent[i].ex_hostuuid.node[1]),
535 ntohl(extent[i].ex_hostuuid.node[2]),
536 ntohl(extent[i].ex_hostuuid.node[3]),
537 ntohl(extent[i].ex_hostuuid.node[4]),
538 ntohl(extent[i].ex_hostuuid.node[5]));
539 quiet_println(" uniquifier = %u\n", ntohl(extent[i].ex_uniquifier));
540 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
541 a = ntohl(extent[i].ex_addrs[j]);
543 quiet_println(" %d.%d.%d.%d\n", (a >> 24) & 0xff,
544 (a >> 16) & 0xff, (a >> 8) & 0xff, (a) & 0xff);
551 * Read each entry in the database:
552 * Record what type of entry it is and its address in the record array.
553 * Remember what the maximum volume id we found is and check against the header.
556 ReadAllEntries(struct vlheader *header)
558 afs_int32 type, rindex, i, j, e;
559 int freecount = 0, mhcount = 0, vlcount = 0;
560 int rwcount = 0, rocount = 0, bkcount = 0;
561 struct nvlentry vlentry;
563 afs_uint32 entrysize = 0;
564 afs_uint32 maxvolid = 0;
566 if (verbose) quiet_println("Read each entry in the database\n");
567 for (addr = header->vital_header.headersize;
568 addr < header->vital_header.eofPtr; addr += entrysize) {
570 /* Remember the highest volume id */
571 readentry(addr, &vlentry, &type);
573 if (!(vlentry.flags & VLF_RWEXISTS))
574 log_error(VLDB_CHECK_WARNING,"VLDB_CHECK_WARNING: VLDB entry '%s' has no RW volume\n",
577 for (i = 0; i < MAXTYPES; i++)
578 if (maxvolid < vlentry.volumeId[i])
579 maxvolid = vlentry.volumeId[i];
582 for (j = 0; j < NMAXNSERVERS; j++) {
583 if (vlentry.serverNumber[j] == 255)
585 if (vlentry.serverFlags[j] & (VLSF_ROVOL | VLSF_NEWREPSITE)) {
589 if (vlentry.serverFlags[j] & VLSF_RWVOL) {
591 if (vlentry.flags & VLF_BACKEXISTS)
595 if (!vlentry.serverFlags[j]) {
601 (VLDB_CHECK_ERROR,"VLDB entry '%s' contains an unknown RW/RO index serverFlag\n",
606 (" index %d : serverNumber %d : serverPartition %d : serverFlag %d\n",
607 j, vlentry.serverNumber[j], vlentry.serverPartition[j],
608 vlentry.serverFlags[j]);
612 rindex = addr / sizeof(vlentry);
613 if (record[rindex].type) {
614 log_error(VLDB_CHECK_ERROR,"INTERNAL VLDB_CHECK_ERROR: record holder %d already in use\n",
618 record[rindex].addr = addr;
619 record[rindex].type = type;
621 /* Determine entrysize and keep count */
623 entrysize = sizeof(vlentry);
625 } else if (type == FR) {
626 entrysize = sizeof(vlentry);
628 } else if (type == MH) {
629 entrysize = VL_ADDREXTBLK_SIZE;
632 log_error(VLDB_CHECK_ERROR, "Unknown entry at %u. Aborting\n", addr);
637 quiet_println("Found %d entries, %d free entries, %d multihomed blocks\n",
638 vlcount, freecount, mhcount);
639 quiet_println("Found %d RW volumes, %d BK volumes, %d RO volumes\n", rwcount,
643 /* Check the maxmimum volume id in the header */
644 if (maxvolid != header->vital_header.MaxVolumeId - 1)
646 ("Header's maximum volume id is %u and largest id found in VLDB is %u\n",
647 header->vital_header.MaxVolumeId, maxvolid);
651 * Follow each Name hash bucket marking it as read in the record array.
652 * Record we found it in the name hash within the record array.
653 * Check that the name is hashed correctly.
656 FollowNameHash(struct vlheader *header)
658 int count = 0, longest = 0, shortest = -1, chainlength;
659 struct nvlentry vlentry;
661 afs_int32 i, type, rindex;
663 /* Now follow the Name Hash Table */
664 if (verbose) quiet_println("Check Volume Name Hash\n");
665 for (i = 0; i < HASHSIZE; i++) {
668 if (!validVolumeAddr(header->VolnameHash[i])) {
669 log_error(VLDB_CHECK_ERROR,"Name Hash %d: Bad entry %u is out of range\n",
670 i, header->VolnameHash[i]);
674 for (addr = header->VolnameHash[i]; addr; addr = vlentry.nextNameHash) {
675 readentry(addr, &vlentry, &type);
677 log_error(VLDB_CHECK_ERROR,"Name Hash %d: Bad entry at %u: Not a valid vlentry\n",
685 * we know that the address is valid because we
686 * checked it either above or below
688 if (record[rindex].addr != addr && record[rindex].addr) {
690 (VLDB_CHECK_ERROR,"INTERNAL VLDB_CHECK_ERROR: addresses %ld and %u use same record slot %d\n",
691 record[rindex].addr, addr, rindex);
693 if (record[rindex].type & NH) {
695 (VLDB_CHECK_ERROR,"Name Hash %d: Bad entry '%s': Already in the name hash\n",
697 record[rindex].type |= MULTN;
701 if (!validVolumeAddr(vlentry.nextNameHash)) {
702 log_error(VLDB_CHECK_ERROR,"Name Hash forward link of '%s' is out of range\n",
704 record[rindex].type |= MULTN;
708 record[rindex].type |= NH;
709 record[rindex].type |= REFN;
714 /* Hash the name and check if in correct hash table */
715 if (NameHash(vlentry.name) != i) {
717 (VLDB_CHECK_ERROR,"Name Hash %d: Bad entry '%s': Incorrect name hash chain (should be in %d)\n",
718 i, vlentry.name, NameHash(vlentry.name));
719 record[rindex].type |= MULTN;
722 if (chainlength > longest)
723 longest = chainlength;
724 if ((shortest == -1) || (chainlength < shortest))
725 shortest = chainlength;
729 ("%d entries in name hash, longest is %d, shortest is %d, average length is %f\n",
730 count, longest, shortest, ((float)count / (float)HASHSIZE));
736 * Follow the ID hash chains for the RW, RO, and BK hash tables.
737 * Record we found it in the id hash within the record array.
738 * Check that the ID is hashed correctly.
741 FollowIdHash(struct vlheader *header)
743 int count = 0, longest = 0, shortest = -1, chainlength;
744 struct nvlentry vlentry;
746 afs_int32 i, j, hash, type, rindex, ref, badref, badhash;
748 /* Now follow the RW, RO, and BK Hash Tables */
749 if (verbose) quiet_println("Check RW, RO, and BK id Hashes\n");
750 for (i = 0; i < MAXTYPES; i++) {
751 hash = ((i == 0) ? RWH : ((i == 1) ? ROH : BKH));
752 ref = ((i == 0) ? REFRW : ((i == 1) ? REFRO : REFBK));
753 badref = ((i == 0) ? MULTRW : ((i == 1) ? MULTRO : MULTBK));
754 badhash = ((i == 0) ? MULTRW : ((i == 1) ? MULTRO : MULTBK));
758 for (j = 0; j < HASHSIZE; j++) {
760 if (!validVolumeAddr(header->VolidHash[i][j])) {
761 log_error(VLDB_CHECK_ERROR,"%s Hash %d: Bad entry %u is out of range\n",
762 vtype(i), j, header->VolidHash[i][j]);
766 for (addr = header->VolidHash[i][j]; addr;
767 addr = vlentry.nextIdHash[i]) {
768 readentry(addr, &vlentry, &type);
771 (VLDB_CHECK_ERROR,"%s Id Hash %d: Bad entry at %u: Not a valid vlentry\n",
777 if (record[rindex].addr != addr && record[rindex].addr) {
779 (VLDB_CHECK_ERROR,"INTERNAL VLDB_CHECK_ERROR: addresses %ld and %u use same record slot %d\n",
780 record[rindex].addr, addr, rindex);
782 if (record[rindex].type & hash) {
784 (VLDB_CHECK_ERROR,"%s Id Hash %d: Bad entry '%s': Already in the hash table\n",
785 vtype(i), j, vlentry.name);
786 record[rindex].type |= badref;
790 if (!validVolumeAddr(vlentry.nextIdHash[i])) {
791 log_error(VLDB_CHECK_ERROR,"%s Id Hash forward link of '%s' is out of range\n",
792 vtype(i), vlentry.name);
793 record[rindex].type |= badref;
797 record[rindex].type |= hash;
798 record[rindex].type |= ref;
803 /* Hash the id and check if in correct hash table */
804 if (IdHash(vlentry.volumeId[i]) != j) {
806 (VLDB_CHECK_ERROR,"%s Id Hash %d: Bad entry '%s': Incorrect Id hash chain (should be in %d)\n",
807 vtype(i), j, vlentry.name,
808 IdHash(vlentry.volumeId[i]));
809 record[rindex].type |= badhash;
813 if (chainlength > longest)
814 longest = chainlength;
815 if ((shortest == -1) || (chainlength < shortest))
816 shortest = chainlength;
820 ("%d entries in %s hash, longest is %d, shortest is %d, average length is %f\n",
821 count, vtype(i), longest, shortest,((float)count / (float)HASHSIZE));
828 * Follow the free chain.
829 * Record we found it in the free chain within the record array.
832 FollowFreeChain(struct vlheader *header)
835 struct nvlentry vlentry;
837 afs_int32 type, rindex;
839 /* Now follow the Free Chain */
840 if (verbose) quiet_println("Check Volume Free Chain\n");
841 for (addr = header->vital_header.freePtr; addr;
842 addr = vlentry.nextIdHash[0]) {
843 readentry(addr, &vlentry, &type);
846 (VLDB_CHECK_ERROR,"Free Chain %d: Bad entry at %u: Not a valid free vlentry (0x%x)\n",
851 rindex = addr / sizeof(vlentry);
852 if (record[rindex].addr != addr && record[rindex].addr) {
854 (VLDB_CHECK_ERROR,"INTERNAL VLDB_CHECK_ERROR: addresses %u and %ld use same record slot %d\n",
855 record[rindex].addr, addr, rindex);
857 if (record[rindex].type & FRC) {
858 log_error(VLDB_CHECK_ERROR,"Free Chain: Bad entry at %u: Already in the free chain\n",
862 record[rindex].type |= FRC;
867 quiet_println("%d entries on free chain\n", count);
872 * Read each multihomed block and mark it as found in the record.
873 * Read each entry in each multihomed block and mark the serveraddrs
874 * array with the number of ip addresses found for this entry.
876 * Then read the IpMappedAddr array in the header.
877 * Verify that multihomed entries base and index are valid and points to
878 * a good multhomed entry.
879 * Mark the serveraddrs array with 1 ip address for regular entries.
881 * By the end, the severaddrs array will have a 0 if the entry has no
882 * IP addresses in it or the count of the number of IP addresses.
884 * The code does not verify if there are duplicate IP addresses in the
885 * list. The vlserver does this when a fileserver registeres itself.
888 CheckIpAddrs(struct vlheader *header)
891 afs_int32 i, j, m, rindex;
892 afs_int32 mhentries, regentries;
893 afs_int32 caddrs[VL_MAX_ADDREXTBLKS];
894 char mhblock[VL_ADDREXTBLK_SIZE];
895 struct extentaddr *MHblock = (struct extentaddr *)mhblock;
896 struct extentaddr *e;
897 int ipindex, ipaddrs;
900 memset(&nulluuid, 0, sizeof(nulluuid));
903 quiet_println("Check Multihomed blocks\n");
906 /* Read the first MH block and from it, gather the
907 * addresses of all the mh blocks.
909 readMH(header->SIT, MHblock);
910 if (MHblock->ex_flags != VLCONTBLOCK) {
912 (VLDB_CHECK_ERROR,"Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n",
916 for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
917 caddrs[i] = MHblock->ex_contaddrs[i];
920 if (header->SIT != caddrs[0]) {
922 (VLDB_CHECK_ERROR,"MH block does not point to self %u in header, %u in block\n",
923 header->SIT, caddrs[0]);
926 /* Now read each MH block and record it in the record array */
927 for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
931 readMH(caddrs[i], MHblock);
932 if (MHblock->ex_flags != VLCONTBLOCK) {
934 (VLDB_CHECK_ERROR,"Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n",
938 rindex = caddrs[i] / sizeof(vlentry);
939 if (record[rindex].addr != caddrs[i] && record[rindex].addr) {
941 (VLDB_CHECK_ERROR,"INTERNAL VLDB_CHECK_ERROR: addresses %u and %u use same record slot %d\n",
942 record[rindex].addr, caddrs[i], rindex);
944 if (record[rindex].type & FRC) {
946 (VLDB_CHECK_ERROR,"MH Blocks Chain %d: Bad entry at %ld: Already a MH block\n",
947 i, record[rindex].addr);
950 record[rindex].type |= MHC;
954 /* Read each entry in a multihomed block.
955 * Find the pointer to the entry in the IpMappedAddr array and
956 * verify that the entry is good (has IP addresses in it).
959 for (j = 1; j < VL_MHSRV_PERBLK; j++) {
960 e = (struct extentaddr *)&(MHblock[j]);
962 /* Search the IpMappedAddr array for the reference to this entry */
963 for (ipindex = 0; ipindex < MAXSERVERID; ipindex++) {
964 if (((header->IpMappedAddr[ipindex] & 0xff000000) ==
968 IpMappedAddr[ipindex] & 0x00ff0000) >> 16) == i)
969 && ((header->IpMappedAddr[ipindex] & 0x0000ffff) ==
974 if (ipindex >= MAXSERVERID)
977 serveraddrs[ipindex] = -1;
979 if (memcmp(&e->ex_hostuuid, &nulluuid, sizeof(afsUUID)) == 0) {
982 (VLDB_CHECK_ERROR,"Server Addrs index %d references null MH block %d, index %d\n",
984 serveraddrs[ipindex] = 0; /* avoids printing 2nd error below */
989 /* Step through each ip address and count the good addresses */
991 for (m = 0; m < VL_MAXIPADDRS_PERMH; m++) {
996 /* If we found any good ip addresses, mark it in the serveraddrs record */
1001 (VLDB_CHECK_ERROR,"MH block %d, index %d: Not referenced by server addrs\n",
1004 serveraddrs[ipindex] = ipaddrs; /* It is good */
1008 if (listservers && ipaddrs) {
1009 quiet_println("MH block %d, index %d:", i, j);
1010 for (m = 0; m < VL_MAXIPADDRS_PERMH; m++) {
1011 if (!e->ex_addrs[m])
1013 quiet_println(" %d.%d.%d.%d",
1014 (e->ex_addrs[m] & 0xff000000) >> 24,
1015 (e->ex_addrs[m] & 0x00ff0000) >> 16,
1016 (e->ex_addrs[m] & 0x0000ff00) >> 8,
1017 (e->ex_addrs[m] & 0x000000ff));
1019 quiet_println("\n");
1023 * if (mhentries != MHblock->ex_count) {
1024 * quiet_println("MH blocks says it has %d entries (found %d)\n",
1025 * MHblock->ex_count, mhentries);
1031 quiet_println("%d multihomed blocks\n", mhblocks);
1033 /* Check the server addresses */
1035 quiet_println("Check server addresses\n");
1036 mhentries = regentries = 0;
1037 for (i = 0; i <= MAXSERVERID; i++) {
1038 if (header->IpMappedAddr[i]) {
1039 if ((header->IpMappedAddr[i] & 0xff000000) == 0xff000000) {
1041 if (((header->IpMappedAddr[i] & 0x00ff0000) >> 16) >
1044 (VLDB_CHECK_ERROR,"IP Addr for entry %d: Multihome block is bad (%d)\n",
1045 i, ((header->IpMappedAddr[i] & 0x00ff0000) >> 16));
1046 if (((header->IpMappedAddr[i] & 0x0000ffff) > VL_MHSRV_PERBLK)
1047 || ((header->IpMappedAddr[i] & 0x0000ffff) < 1))
1049 (VLDB_CHECK_ERROR,"IP Addr for entry %d: Multihome index is bad (%d)\n",
1050 i, (header->IpMappedAddr[i] & 0x0000ffff));
1051 if (serveraddrs[i] == -1) {
1053 (VLDB_CHECK_WARNING,"warning: IP Addr for entry %d: Multihome entry has no ip addresses\n",
1058 quiet_println(" Server ip addr %d = MH block %d, index %d\n",
1059 i, (header->IpMappedAddr[i] & 0x00ff0000) >> 16,
1060 (header->IpMappedAddr[i] & 0x0000ffff));
1064 serveraddrs[i] = 1; /* It is good */
1066 quiet_println(" Server ip addr %d = %d.%d.%d.%d\n", i,
1067 (header->IpMappedAddr[i] & 0xff000000) >> 24,
1068 (header->IpMappedAddr[i] & 0x00ff0000) >> 16,
1069 (header->IpMappedAddr[i] & 0x0000ff00) >> 8,
1070 (header->IpMappedAddr[i] & 0x000000ff));
1076 quiet_println("%d simple entries, %d multihomed entries, Total = %d\n",
1077 regentries, mhentries, mhentries + regentries);
1083 nameForAddr(afs_uint32 addr, int hashtype, afs_uint32 *hash, char *buffer)
1086 * We need to simplify the reporting, while retaining
1087 * legible messages. This is a helper function. The return address
1088 * is either a fixed char or the provided buffer - so don't use the
1089 * name after the valid lifetime of the buffer.
1092 struct nvlentry entry;
1094 /* Distinguished, invalid, hash */
1097 } else if (!validVolumeAddr(addr)) {
1098 /* Different, invalid, hash */
1102 readentry(addr, &entry, &type);
1107 if (hashtype >= MAXTYPES) {
1108 *hash = NameHash(entry.name);
1110 *hash = IdHash(entry.volumeId[hashtype]);
1112 sprintf(buffer, "for '%s'", entry.name);
1117 reportHashChanges(struct vlheader *header, afs_uint32 oldnamehash[HASHSIZE], afs_uint32 oldidhash[MAXTYPES][HASHSIZE])
1120 afs_uint32 oldhash, newhash;
1121 char oldNameBuffer[10 + VL_MAXNAMELEN];
1122 char newNameBuffer[10 + VL_MAXNAMELEN];
1123 char *oldname, *newname;
1125 * report hash changes
1128 for (i = 0; i < HASHSIZE; i++) {
1129 if (oldnamehash[i] != header->VolnameHash[i]) {
1131 oldname = nameForAddr(oldnamehash[i], MAXTYPES, &oldhash, oldNameBuffer);
1132 newname = nameForAddr(header->VolnameHash[i], MAXTYPES, &newhash, newNameBuffer);
1133 if (verbose || (oldhash != newhash)) {
1134 quiet_println("FIX: Name hash header at %d was %s, is now %s\n", i, oldname, newname);
1137 for (j = 0; j < MAXTYPES; j++) {
1138 if (oldidhash[j][i] != header->VolidHash[j][i]) {
1140 oldname = nameForAddr(oldidhash[j][i], j, &oldhash, oldNameBuffer);
1141 newname = nameForAddr(header->VolidHash[j][i], j, &newhash, newNameBuffer);
1142 if (verbose || (oldhash != newhash)) {
1143 quiet_println("FIX: %s hash header at %d was %s, is now %s\n", vtype(j), i, oldname, newname);
1151 WorkerBee(struct cmd_syndesc *as, void *arock)
1155 struct vlheader header;
1156 struct nvlentry vlentry, vlentry2;
1158 afs_uint32 oldnamehash[HASHSIZE];
1159 afs_uint32 oldidhash[MAXTYPES][HASHSIZE];
1161 error_level = 0; /* start clean with no error status */
1162 dbfile = as->parms[0].items->data; /* -database */
1163 listuheader = (as->parms[1].items ? 1 : 0); /* -uheader */
1164 listheader = (as->parms[2].items ? 1 : 0); /* -vheader */
1165 listservers = (as->parms[3].items ? 1 : 0); /* -servers */
1166 listentries = (as->parms[4].items ? 1 : 0); /* -entries */
1167 verbose = (as->parms[5].items ? 1 : 0); /* -verbose */
1168 quiet = (as->parms[6].items ? 1 : 0); /* -quiet */
1169 fix = (as->parms[7].items ? 1 : 0); /* -fix */
1172 if (quiet && (verbose || listuheader || listheader ||listservers \
1174 log_error(VLDB_CHECK_FATAL," -quiet cannot be used other display flags\n");
1175 return VLDB_CHECK_FATAL;
1179 /* open the vldb database file */
1180 fd = open(dbfile, (fix > 0)?O_RDWR:O_RDONLY, 0);
1182 log_error(VLDB_CHECK_FATAL,"can't open file '%s'. error = %d\n", dbfile, errno);
1186 /* read the ubik header and the vldb database header */
1188 readheader(&header);
1189 if (header.vital_header.vldbversion < 3) {
1190 log_error(VLDB_CHECK_FATAL,"does not support vldb with version less than 3\n");
1191 return VLDB_CHECK_FATAL;
1194 maxentries = (header.vital_header.eofPtr / sizeof(vlentry)) + 1;
1195 record = (struct er *)malloc(maxentries * sizeof(struct er));
1196 memset(record, 0, (maxentries * sizeof(struct er)));
1197 memset(serveraddrs, 0, sizeof(serveraddrs));
1199 /* Will fill in the record array of entries it found */
1200 ReadAllEntries(&header);
1201 listentries = 0; /* Listed all the entries */
1203 /* Check the multihomed blocks for valid entries as well as
1204 * the IpMappedAddrs array in the header for valid entries.
1206 CheckIpAddrs(&header);
1208 /* Follow the hash tables */
1209 FollowNameHash(&header);
1210 FollowIdHash(&header);
1212 /* Follow the chain of free entries */
1213 FollowFreeChain(&header);
1215 /* Now check the record we have been keeping for inconsistencies
1216 * For valid vlentries, also check that the server we point to is
1217 * valid (the serveraddrs array).
1220 quiet_println("Verify each volume entry\n");
1221 for (i = 0; i < maxentries; i++) {
1229 if (record[i].type == 0)
1232 /* If a vlentry, verify that its name is valid, its name and ids are
1233 * on the hash chains, and its server numbers are good.
1235 if (record[i].type & VL) {
1237 int foundbroken = 0;
1240 readentry(record[i].addr, &vlentry, &type);
1242 if (InvalidVolname(vlentry.name))
1243 log_error(VLDB_CHECK_ERROR,"Volume '%s' at addr %ld has an invalid name\n",
1244 vlentry.name, record[i].addr);
1246 if (!(record[i].type & NH)) {
1247 nextp = ADDR(vlentry.nextNameHash);
1249 hash = NameHash(vlentry.name);
1250 nextpp = &vlentry.nextNameHash;
1256 if (vlentry.volumeId[0] && !(record[i].type & RWH)) {
1257 nextp = ADDR(vlentry.nextIdHash[0]);
1259 hash = IdHash(vlentry.volumeId[0]);
1260 nextpp = &(vlentry.nextIdHash[0]);
1262 sprintf(volidbuf, "id %u ", vlentry.volumeId[0]);
1266 if (vlentry.volumeId[1] && !(record[i].type & ROH)) {
1267 nextp = ADDR(vlentry.nextIdHash[1]);
1269 hash = IdHash(vlentry.volumeId[1]);
1270 nextpp = &(vlentry.nextIdHash[1]);
1272 sprintf(volidbuf, "id %u ", vlentry.volumeId[1]);
1276 if (vlentry.volumeId[2] && !(record[i].type & BKH)) {
1277 nextp = ADDR(vlentry.nextIdHash[2]);
1279 hash = IdHash(vlentry.volumeId[2]);
1280 nextpp = &(vlentry.nextIdHash[2]);
1282 sprintf(volidbuf, "id %u ", vlentry.volumeId[2]);
1286 if (!validVolumeAddr(vlentry.nextNameHash) ||
1287 record[ADDR(vlentry.nextNameHash)].type & MULTN) {
1288 nextp = ADDR(vlentry.nextNameHash);
1290 hash = NameHash(vlentry.name);
1291 nextpp = &vlentry.nextNameHash;
1294 if (validVolumeAddr(vlentry.nextNameHash)) {
1295 readentry(vlentry.nextNameHash, &vlentry2, &type);
1296 nexthash = NameHash(vlentry2.name);
1298 nexthash = 0xFFFFFFFF;
1300 if (hash != nexthash)
1304 if (!validVolumeAddr(vlentry.nextIdHash[0]) ||
1305 record[ADDR(vlentry.nextIdHash[0])].type & MULTRW) {
1306 nextp = ADDR(vlentry.nextIdHash[0]);
1308 hash = IdHash(vlentry.volumeId[0]);
1309 nextpp = &(vlentry.nextIdHash[0]);
1311 sprintf(volidbuf, "id %u ", vlentry.volumeId[0]);
1312 if (validVolumeAddr(vlentry.nextIdHash[0])) {
1313 readentry(vlentry.nextIdHash[0], &vlentry2, &type);
1314 nexthash = IdHash(vlentry2.volumeId[0]);
1316 nexthash = 0xFFFFFFFF;
1318 if (hash != nexthash)
1322 if (!validVolumeAddr(vlentry.nextIdHash[1]) ||
1323 record[ADDR(vlentry.nextIdHash[1])].type & MULTRO) {
1324 nextp = ADDR(vlentry.nextIdHash[1]);
1326 hash = IdHash(vlentry.volumeId[1]);
1327 nextpp = &(vlentry.nextIdHash[1]);
1329 sprintf(volidbuf, "id %u ", vlentry.volumeId[1]);
1330 if (validVolumeAddr(vlentry.nextIdHash[1])) {
1331 readentry(vlentry.nextIdHash[1], &vlentry2, &type);
1332 nexthash = IdHash(vlentry2.volumeId[1]);
1334 nexthash = 0xFFFFFFFF;
1336 if (hash != nexthash)
1340 if (!validVolumeAddr(vlentry.nextIdHash[2]) ||
1341 record[ADDR(vlentry.nextIdHash[2])].type & MULTBK) {
1342 nextp = ADDR(vlentry.nextIdHash[2]);
1344 hash = IdHash(vlentry.volumeId[2]);
1345 nextpp = &(vlentry.nextIdHash[2]);
1347 sprintf(volidbuf, "id %u ", vlentry.volumeId[2]);
1348 if (validVolumeAddr(vlentry.nextIdHash[2])) {
1349 readentry(vlentry.nextIdHash[2], &vlentry2, &type);
1350 nexthash = IdHash(vlentry2.volumeId[2]);
1352 nexthash = 0xFFFFFFFF;
1354 if (hash != nexthash)
1359 log_error(VLDB_CHECK_ERROR, "%d: Volume '%s' %s forward link in %s hash chain is broken (hash %d != %d)\n", i,
1360 vlentry.name, volidbuf, which, hash, nexthash);
1361 } else if (foundbad) {
1362 log_error(VLDB_CHECK_ERROR, "%d: Volume '%s' %snot found in %s hash %d\n", i,
1363 vlentry.name, volidbuf, which, hash);
1366 for (j = 0; j < NMAXNSERVERS; j++) {
1367 if ((vlentry.serverNumber[j] != 255)
1368 && (serveraddrs[vlentry.serverNumber[j]] == 0)) {
1370 (VLDB_CHECK_ERROR,"Volume '%s', index %d points to empty server entry %d\n",
1371 vlentry.name, j, vlentry.serverNumber[j]);
1375 if (record[i].type & 0xffff0f00)
1377 (VLDB_CHECK_ERROR,"Volume '%s' id %u also found on other chains (0x%x)\n",
1378 vlentry.name, vlentry.volumeId[0], record[i].type);
1381 } else if (record[i].type & FR) {
1382 if (!(record[i].type & FRC))
1383 log_error(VLDB_CHECK_ERROR,"Free vlentry at %ld not on free chain\n",
1386 if (record[i].type & 0xfffffdf0)
1388 (VLDB_CHECK_ERROR,"Free vlentry at %ld also found on other chains (0x%x)\n",
1389 record[i].addr, record[i].type);
1391 /* A multihomed entry */
1392 } else if (record[i].type & MH) {
1393 if (!(record[i].type & MHC))
1394 log_error(VLDB_CHECK_ERROR,"Multihomed block at %ld is orphaned\n",
1397 if (record[i].type & 0xfffffef0)
1399 (VLDB_CHECK_ERROR,"Multihomed block at %ld also found on other chains (0x%x)\n",
1400 record[i].addr, record[i].type);
1403 log_error(VLDB_CHECK_ERROR,"Unknown entry type at %u (0x%x)\n", record[i].addr,
1410 * If we are fixing we will rebuild all the hash lists from the ground up
1412 memcpy(oldnamehash, header.VolnameHash, sizeof(oldnamehash));
1413 memset(header.VolnameHash, 0, sizeof(header.VolnameHash));
1415 memcpy(oldidhash, header.VolidHash, sizeof(oldidhash));
1416 memset(header.VolidHash, 0, sizeof(header.VolidHash));
1417 quiet_println("Rebuilding %u entries\n", maxentries);
1419 quiet_println("Scanning %u entries for possible repairs\n", maxentries);
1421 for (i = 0; i < maxentries; i++) {
1423 if (record[i].type & VL) {
1424 readentry(record[i].addr, &vlentry, &type);
1425 if (!(record[i].type & REFN)) {
1426 log_error(VLDB_CHECK_ERROR,"%d: Record %ld (type 0x%x) not in a name chain\n", i,
1427 record[i].addr, record[i].type);
1429 if (vlentry.volumeId[0] && !(record[i].type & REFRW)) {
1430 log_error(VLDB_CHECK_ERROR,"%d: Record %ld (type 0x%x) not in a RW chain\n", i,
1431 record[i].addr, record[i].type);
1433 if (vlentry.volumeId[1] && !(record[i].type & REFRO)) {
1434 log_error(VLDB_CHECK_ERROR,"%d: Record %ld (type 0x%x) not in a RO chain\n", i,
1435 record[i].addr, record[i].type);
1437 if (vlentry.volumeId[2] && !(record[i].type & REFBK)) {
1438 log_error(VLDB_CHECK_ERROR,"%d: Record %ld (type 0x%x) not in a BK chain\n", i,
1439 record[i].addr, record[i].type);
1442 afs_uint32 oldhash, newhash;
1443 char oldNameBuffer[10 + VL_MAXNAMELEN];
1444 char newNameBuffer[10 + VL_MAXNAMELEN];
1445 char *oldname, *newname;
1448 * Put the current hash table contexts into our 'next'
1449 * and our address into the hash table.
1451 hash = NameHash(vlentry.name);
1453 if (vlentry.nextNameHash != header.VolnameHash[hash]) {
1454 oldname = nameForAddr(vlentry.nextNameHash, MAXTYPES, &oldhash, oldNameBuffer);
1455 newname = nameForAddr(header.VolnameHash[hash], MAXTYPES, &newhash, newNameBuffer);
1456 if (verbose || ((oldhash != newhash) &&
1457 (0 != vlentry.nextNameHash) &&
1458 (0 != header.VolnameHash[hash]))) {
1460 * That is, only report if we are verbose
1461 * or the hash is changing (and one side wasn't NULL
1463 quiet_println("FIX: Name hash link for '%s' was %s, is now %s\n",
1464 vlentry.name, oldname, newname);
1468 vlentry.nextNameHash = header.VolnameHash[hash];
1469 header.VolnameHash[hash] = record[i].addr;
1471 for (j = 0; j < MAXTYPES; j++) {
1473 if (0 == vlentry.volumeId[j]) {
1475 * No volume of that type. Continue
1479 hash = IdHash(vlentry.volumeId[j]);
1481 if (vlentry.nextIdHash[j] != header.VolidHash[j][hash]) {
1482 oldname = nameForAddr(vlentry.nextIdHash[j], j, &oldhash, oldNameBuffer);
1483 newname = nameForAddr(header.VolidHash[j][hash], j, &newhash, newNameBuffer);
1484 if (verbose || ((oldhash != newhash) &&
1485 (0 != vlentry.nextIdHash[j]) &&
1486 (0 != header.VolidHash[j][hash]))) {
1487 quiet_println("FIX: %s hash link for '%s' was %s, is now %s\n",
1488 vtype(j), vlentry.name, oldname, newname);
1492 vlentry.nextIdHash[j] = header.VolidHash[j][hash];
1493 header.VolidHash[j][hash] = record[i].addr;
1495 writeentry(record[i].addr, &vlentry);
1500 reportHashChanges(&header, oldnamehash, oldidhash);
1501 writeheader(&header);
1510 main(int argc, char **argv)
1512 struct cmd_syndesc *ts;
1516 ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "vldb check");
1517 cmd_AddParm(ts, "-database", CMD_SINGLE, CMD_REQUIRED, "vldb_file");
1518 cmd_AddParm(ts, "-uheader", CMD_FLAG, CMD_OPTIONAL,
1519 "Display UBIK header");
1520 cmd_AddParm(ts, "-vheader", CMD_FLAG, CMD_OPTIONAL,
1521 "Display VLDB header");
1522 cmd_AddParm(ts, "-servers", CMD_FLAG, CMD_OPTIONAL,
1523 "Display server list");
1524 cmd_AddParm(ts, "-entries", CMD_FLAG, CMD_OPTIONAL, "Display entries");
1525 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");
1526 cmd_AddParm(ts, "-quiet", CMD_FLAG, CMD_OPTIONAL, "quiet");
1527 cmd_AddParm(ts, "-fix", CMD_FLAG, CMD_OPTIONAL, "attempt to patch the database (potentially dangerous)");
1529 return cmd_Dispatch(argc, argv);