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 #include <afsconfig.h>
25 #include <afs/param.h>
29 #include <sys/types.h>
35 #include <WINNT/afsevent.h>
38 #include <sys/socket.h>
40 #include <netinet/in.h>
45 #include <afs/afsutil.h>
49 int listentries, listservers, listheader, listuheader, verbose;
55 int serveraddrs[MAXSERVERID+2];
62 struct ubik_hdr uheader;
64 offset = lseek(fd, 0, 0);
66 printf("error: lseek to 0 failed: %d %d\n", offset, errno);
70 /* now read the info */
71 r = read(fd, &uheader, sizeof(uheader));
72 if (r != sizeof(uheader)) {
73 printf("error: read of %d bytes failed: %d %d\n", sizeof(uheader), r, errno);
77 uheader.magic = ntohl(uheader.magic);
78 uheader.size = ntohl(uheader.size);
79 uheader.version.epoch = ntohl(uheader.version.epoch);
80 uheader.version.counter = ntohl(uheader.version.counter);
83 printf("Ubik Header\n");
84 printf(" Magic = 0x%x\n", uheader.magic);
85 printf(" Size = %u\n", uheader.size);
86 printf(" Version.epoch = %u\n", uheader.version.epoch);
87 printf(" Version.counter = %u\n", uheader.version.counter);
90 if (uheader.size != HDRSIZE)
91 printf("Ubik header size is %u (should be %u)\n", uheader.size, HDRSIZE);
92 if (uheader.magic != UBIK_MAGIC)
93 printf("Ubik header magic is 0x%x (should be 0x%x)\n", uheader.magic, UBIK_MAGIC);
98 int vldbread(position,buffer,size)
105 /* seek to the correct spot. skip ubik stuff */
106 p = position + HDRSIZE;
107 offset = lseek(fd, p, 0);
109 printf("error: lseek to %d failed: %d %d\n", p, offset, errno);
113 /* now read the info */
114 r = read(fd, buffer, size);
116 printf("error: read of %d bytes failed: %d %d\n", size, r, errno);
127 if (type == 0) strcpy(Type,"rw");
128 else if (type == 1) strcpy(Type,"ro");
129 else if (type == 2) strcpy(Type,"bk");
130 else strcpy(Type,"??");
134 afs_int32 NameHash(volname)
142 for (vchar=volname+strlen(volname)-1; vchar >= volname; vchar--)
143 hash = (hash*63) + (*((unsigned char *)vchar) - 63);
144 return(hash % HASHSIZE);
147 afs_int32 IdHash(volid)
150 return((abs(volid)) % HASHSIZE);
153 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
154 int InvalidVolname(volname)
161 slen = strlen(volname);
162 if (slen >= VL_MAXNAMELEN) return 1;
163 return (slen != strspn(volname, map));
167 struct vlheader *headerp;
171 vldbread(0, headerp, sizeof(*headerp));
173 headerp->vital_header.vldbversion = ntohl(headerp->vital_header.vldbversion);
174 headerp->vital_header.headersize = ntohl(headerp->vital_header.headersize);
175 headerp->vital_header.freePtr = ntohl(headerp->vital_header.freePtr);
176 headerp->vital_header.eofPtr = ntohl(headerp->vital_header.eofPtr);
177 headerp->vital_header.allocs = ntohl(headerp->vital_header.allocs);
178 headerp->vital_header.frees = ntohl(headerp->vital_header.frees);
179 headerp->vital_header.MaxVolumeId = ntohl(headerp->vital_header.MaxVolumeId);
180 headerp->vital_header.totalEntries[0] = ntohl(headerp->vital_header.totalEntries[0]);
181 for (i=0; i<MAXTYPES; i++)
182 headerp->vital_header.totalEntries[i] = ntohl(headerp->vital_header.totalEntries[1]);
184 headerp->SIT = ntohl(headerp->SIT);
185 for (i=0; i<MAXSERVERID; i++)
186 headerp->IpMappedAddr[i] = ntohl(headerp->IpMappedAddr[i]);
187 for (i=0; i<HASHSIZE; i++)
188 headerp->VolnameHash[i] = ntohl(headerp->VolnameHash[i]);
189 for (i=0; i<MAXTYPES; i++)
190 for (j=0; j<HASHSIZE; j++)
191 headerp->VolidHash[i][j] = ntohl(headerp->VolidHash[i][j]);
194 printf("vldb header\n");
195 printf(" vldbversion = %u\n", headerp->vital_header.vldbversion);
196 printf(" headersize = %u [actual=%u]\n",
197 headerp->vital_header.headersize, sizeof(*headerp));
198 printf(" freePtr = 0x%x\n", headerp->vital_header.freePtr);
199 printf(" eofPtr = %u\n", headerp->vital_header.eofPtr);
200 printf(" allocblock calls = %10u\n", headerp->vital_header.allocs);
201 printf(" freeblock calls = %10u\n", headerp->vital_header.frees);
202 printf(" MaxVolumeId = %u\n", headerp->vital_header.MaxVolumeId);
203 printf(" rw vol entries = %u\n", headerp->vital_header.totalEntries[0]);
204 printf(" ro vol entries = %u\n", headerp->vital_header.totalEntries[1]);
205 printf(" bk vol entries = %u\n", headerp->vital_header.totalEntries[2]);
206 printf(" multihome info = 0x%x (%u)\n", headerp->SIT, headerp->SIT);
207 printf(" server ip addr table: size = %d entries\n", MAXSERVERID+1);
208 printf(" volume name hash table: size = %d buckets\n", HASHSIZE);
209 printf(" volume id hash table: %d tables with %d buckets each\n",
213 /* Check the header size */
214 if (headerp->vital_header.headersize != sizeof(*headerp))
215 printf("Header reports its size as %d (should be %d)\n",
216 headerp->vital_header.headersize, sizeof(*headerp));
219 readMH(addr, mhblockP)
221 struct extentaddr *mhblockP;
224 struct extentaddr *e;
226 vldbread(addr, mhblockP, VL_ADDREXTBLK_SIZE);
228 mhblockP->ex_count = ntohl(mhblockP->ex_count);
229 mhblockP->ex_flags = ntohl(mhblockP->ex_flags);
230 for (i=0; i<VL_MAX_ADDREXTBLKS; i++)
231 mhblockP->ex_contaddrs[i] = ntohl(mhblockP->ex_contaddrs[i]);
233 for (i=1; i<VL_MHSRV_PERBLK; i++) {
236 /* won't convert hostuuid */
237 e->ex_uniquifier = ntohl(e->ex_uniquifier);
238 for (j=0; j<VL_MAXIPADDRS_PERMH; j++)
239 e->ex_addrs[j] = ntohl(e->ex_addrs[j]);
243 readentry(addr, vlentryp, type)
245 struct nvlentry *vlentryp;
250 vldbread(addr, vlentryp, sizeof(*vlentryp));
252 for (i=0; i<MAXTYPES; i++)
253 vlentryp->volumeId[i] = ntohl(vlentryp->volumeId[i]);
254 vlentryp->flags = ntohl(vlentryp->flags);
255 vlentryp->LockAfsId = ntohl(vlentryp->LockAfsId);
256 vlentryp->LockTimestamp = ntohl(vlentryp->LockTimestamp);
257 vlentryp->cloneId = ntohl(vlentryp->cloneId);
258 for (i=0; i<MAXTYPES; i++)
259 vlentryp->nextIdHash[i] = ntohl(vlentryp->nextIdHash[i]);
260 vlentryp->nextNameHash = ntohl(vlentryp->nextNameHash);
261 for (i=0; i<NMAXNSERVERS; i++) {
262 vlentryp->serverNumber[i] = ntohl(vlentryp->serverNumber[i]);
263 vlentryp->serverPartition[i] = ntohl(vlentryp->serverPartition[i]);
264 vlentryp->serverFlags[i] = ntohl(vlentryp->serverFlags[i]);
267 if (vlentryp->flags == VLCONTBLOCK) {
269 } else if (vlentryp->flags == VLFREE) {
276 printf("address %u: ", addr);
277 if (vlentryp->flags == VLCONTBLOCK) {
278 printf("mh extension block\n");
279 } else if (vlentryp->flags == VLFREE) {
280 printf("free vlentry\n");
282 printf("vlentry %s\n", vlentryp->name);
283 printf(" rw id = %u ; ro id = %u ; bk id = %u\n",
284 vlentryp->volumeId[0], vlentryp->volumeId[1], vlentryp->volumeId[2]);
286 if (vlentryp->flags & VLF_RWEXISTS) printf(" rw");
287 if (vlentryp->flags & VLF_ROEXISTS) printf(" ro");
288 if (vlentryp->flags & VLF_BACKEXISTS) printf(" bk");
289 if (vlentryp->flags & 0xffff8fff)
290 printf(" errorflag(0x%x)", vlentryp->flags);
292 printf(" LockAfsId = %d\n", vlentryp->LockAfsId);
293 printf(" LockTimestamp = %d\n", vlentryp->LockTimestamp);
294 printf(" cloneId = %u\n", vlentryp->cloneId);
295 printf(" next hash for rw = %u ; ro = %u ; bk = %u ; name = %u\n",
296 vlentryp->nextIdHash[0], vlentryp->nextIdHash[1],
297 vlentryp->nextIdHash[2], vlentryp->nextNameHash);
298 for (i=0; i<NMAXNSERVERS; i++) {
299 if (vlentryp->serverNumber[i] != 255) {
300 printf(" server %d ; partition %d ; flags =",
301 vlentryp->serverNumber[i], vlentryp->serverPartition[i]);
302 if (vlentryp->serverFlags[i] & VLSF_RWVOL) printf(" rw");
303 if (vlentryp->serverFlags[i] & VLSF_ROVOL) printf(" ro");
304 if (vlentryp->serverFlags[i] & VLSF_BACKVOL) printf(" bk");
305 if (vlentryp->serverFlags[i] & VLSF_NEWREPSITE) printf(" newro");
318 char sitbuf[VL_ADDREXTBLK_SIZE];
319 struct extentaddr *extent;
323 vldbread(addr, sitbuf, VL_ADDREXTBLK_SIZE);
324 extent = (struct extentaddr *)sitbuf;
326 printf("multihome info block: base %d\n", base);
328 printf(" count = %u\n", ntohl(extent->ex_count));
329 printf(" flags = %u\n", ntohl(extent->ex_flags));
330 for (i=0; i<VL_MAX_ADDREXTBLKS; i++) {
331 printf(" contaddrs[%d] = %u\n", i, ntohl(extent->ex_contaddrs[i]));
334 for (i=1; i<VL_MHSRV_PERBLK; i++) {
335 /* should we skip this entry */
336 for (j=0; j<VL_MAX_ADDREXTBLKS; j++) {
337 if (extent[i].ex_addrs[j]) break;
339 if (j >= VL_MAX_ADDREXTBLKS) continue;
341 printf(" base %d index %d:\n", base, i);
343 printf(" afsuuid = (%x %x %x /%d/%d/ /%x/%x/%x/%x/%x/%x/)\n",
344 ntohl(extent[i].ex_hostuuid.time_low),
345 ntohl(extent[i].ex_hostuuid.time_mid),
346 ntohl(extent[i].ex_hostuuid.time_hi_and_version),
347 ntohl(extent[i].ex_hostuuid.clock_seq_hi_and_reserved),
348 ntohl(extent[i].ex_hostuuid.clock_seq_low),
349 ntohl(extent[i].ex_hostuuid.node[0]), ntohl(extent[i].ex_hostuuid.node[1]),
350 ntohl(extent[i].ex_hostuuid.node[2]), ntohl(extent[i].ex_hostuuid.node[3]),
351 ntohl(extent[i].ex_hostuuid.node[4]), ntohl(extent[i].ex_hostuuid.node[5]));
352 printf(" uniquifier = %u\n", ntohl(extent[i].ex_uniquifier));
353 for (j=0; j<VL_MAXIPADDRS_PERMH; j++) {
354 a = ntohl(extent[i].ex_addrs[j]);
356 printf(" %d.%d.%d.%d\n",
357 (a>>24)&0xff, (a>>16)&0xff,
358 (a>>8) &0xff, (a )&0xff);
365 * Read each entry in the database:
366 * Record what type of entry it is and its address in the record array.
367 * Remember what the maximum volume id we found is and check against the header.
369 ReadAllEntries(header)
370 struct vlheader *header;
372 afs_int32 type, rindex, i, j, e;
373 int freecount=0, mhcount=0, vlcount=0;
374 int rwcount=0, rocount=0, bkcount=0;
375 struct nvlentry vlentry;
376 afs_uint32 addr, entrysize, maxvolid=0;
379 printf("Read each entry in the database\n");
380 for (addr = header->vital_header.headersize;
381 addr < header->vital_header.eofPtr; addr += entrysize) {
383 /* Remember the highest volume id */
384 readentry(addr, &vlentry, &type);
386 if (!(vlentry.flags & VLF_RWEXISTS))
387 printf("WARNING: VLDB entry '%s' has no RW volume\n", vlentry.name);
389 for (i=0; i<MAXTYPES; i++)
390 if (maxvolid < vlentry.volumeId[i]) maxvolid = vlentry.volumeId[i];
393 for (j=0; j<NMAXNSERVERS; j++) {
394 if (vlentry.serverNumber[j] == 255) continue;
395 if (vlentry.serverFlags[j] & (VLSF_ROVOL|VLSF_NEWREPSITE)) {
399 if (vlentry.serverFlags[j] & VLSF_RWVOL) {
401 if (vlentry.flags & VLF_BACKEXISTS) bkcount++;
405 printf("VLDB entry '%s' contains an unknown RW/RO index serverFlag\n",
409 printf(" index %d : serverNumber %d : serverPartition %d : serverFlag %d\n",
410 j, vlentry.serverNumber[j], vlentry.serverPartition[j], vlentry.serverFlags[j]);
414 rindex = addr/sizeof(vlentry);
415 if (record[rindex].type) {
416 printf("INTERNAL ERROR: record holder %d already in use\n", rindex);
419 record[rindex].addr = addr;
420 record[rindex].type = type;
422 /* Determine entrysize and keep count */
424 entrysize = sizeof(vlentry);
426 } else if (type == FR) {
427 entrysize = sizeof(vlentry);
429 } else if (type == MH) {
430 entrysize = VL_ADDREXTBLK_SIZE;
433 printf("Unknown entry at %u\n", addr);
437 printf("Found %d entries, %d free entries, %d multihomed blocks\n",
438 vlcount, freecount, mhcount);
439 printf("Found %d RW volumes, %d BK volumes, %d RO volumes\n",
440 rwcount, bkcount, rocount);
443 /* Check the maxmimum volume id in the header */
444 if (maxvolid != header->vital_header.MaxVolumeId-1)
445 printf("Header's maximum volume id is %u and largest id found in VLDB is %u\n",
446 header->vital_header.MaxVolumeId, maxvolid);
451 * Follow each Name hash bucket marking it as read in the record array.
452 * Record we found it in the name hash within the record array.
453 * Check that the name is hashed correctly.
455 FollowNameHash(header)
456 struct vlheader *header;
458 int count=0, longest=0, shortest=-1, chainlength;
459 struct nvlentry vlentry;
461 afs_int32 i, type, rindex;
463 /* Now follow the Name Hash Table */
465 printf("Check Volume Name Hash\n");
466 for (i=0; i<HASHSIZE; i++) {
468 for (addr = header->VolnameHash[i]; addr; addr=vlentry.nextNameHash) {
469 readentry(addr, &vlentry, &type);
471 printf("Name Hash %d: Bad entry at %u: Not a valid vlentry\n", i, addr);
475 rindex = addr/sizeof(vlentry);
477 if (record[rindex].addr != addr && record[rindex].addr) {
478 printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n",
479 record[rindex].addr, addr, rindex);
481 if (record[rindex].type & NH) {
482 printf("Name Hash %d: Bad entry '%s': Already in the name hash\n",
486 record[rindex].type |= NH;
491 /* Hash the name and check if in correct hash table */
492 if (NameHash(vlentry.name) != i) {
493 printf("Name Hash %d: Bad entry '%s': Incorrect name hash chain (should be in %d)\n",
494 i, vlentry.name, NameHash(vlentry.name));
497 if (chainlength > longest) longest = chainlength;
498 if ((shortest == -1) || (chainlength < shortest)) shortest = chainlength;
501 printf("%d entries in name hash, longest is %d, shortest is %d, average length is %f\n",
502 count, longest, shortest, ((float)count/(float)HASHSIZE));
507 * Follow the ID hash chains for the RW, RO, and BK hash tables.
508 * Record we found it in the id hash within the record array.
509 * Check that the ID is hashed correctly.
512 struct vlheader *header;
514 int count=0, longest=0, shortest=-1, chainlength;
515 struct nvlentry vlentry;
517 afs_int32 i, j, hash, type, rindex;
519 /* Now follow the RW, RO, and BK Hash Tables */
521 printf("Check RW, RO, and BK id Hashes\n");
522 for (i=0; i<MAXTYPES; i++) {
523 hash = ((i==0)?RWH : ((i==1)?ROH : BKH));
524 count = longest = 0; shortest = -1;
526 for (j=0; j<HASHSIZE; j++) {
528 for (addr=header->VolidHash[i][j]; addr; addr=vlentry.nextIdHash[i]) {
529 readentry(addr, &vlentry, &type);
531 printf("%s Id Hash %d: Bad entry at %u: Not a valid vlentry\n",
536 rindex = addr/sizeof(vlentry);
537 if (record[rindex].addr != addr && record[rindex].addr) {
538 printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n",
539 record[rindex].addr, addr, rindex);
541 if (record[rindex].type & hash) {
542 printf("%s Id Hash %d: Bad entry '%s': Already in the the hash table\n",
543 vtype(i), j, vlentry.name);
546 record[rindex].type |= hash;
551 /* Hash the id and check if in correct hash table */
552 if (IdHash(vlentry.volumeId[i]) != j) {
553 printf("%s Id Hash %d: Bad entry '%s': Incorrect Id hash chain (should be in %d)\n",
554 vtype(i), j, vlentry.name, IdHash(vlentry.volumeId[i]));
558 if (chainlength > longest) longest = chainlength;
559 if ((shortest == -1) || (chainlength < shortest)) shortest = chainlength;
562 printf("%d entries in %s hash, longest is %d, shortest is %d, average length is %f\n",
563 count, vtype(i), longest, shortest, ((float)count/(float)HASHSIZE));
569 * Follow the free chain.
570 * Record we found it in the free chain within the record array.
572 FollowFreeChain(header)
573 struct vlheader *header;
576 struct nvlentry vlentry;
578 afs_int32 i, type, rindex;
580 /* Now follow the Free Chain */
582 printf("Check Volume Free Chain\n");
583 for (addr=header->vital_header.freePtr; addr; addr=vlentry.nextIdHash[0]) {
584 readentry(addr, &vlentry, &type);
586 printf("Free Chain %d: Bad entry at %u: Not a valid free vlentry (0x%x)\n",
591 rindex = addr/sizeof(vlentry);
592 if (record[rindex].addr != addr && record[rindex].addr) {
593 printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n",
594 record[rindex].addr, addr, rindex);
596 if (record[rindex].type & FRC) {
597 printf("Free Chain: Bad entry at %u: Already in the free chain\n", addr);
600 record[rindex].type |= FRC;
605 printf("%d entries on free chain\n", count);
609 * Read each multihomed block and mark it as found in the record.
610 * Read each entry in each multihomed block and mark the serveraddrs
611 * array with the number of ip addresses found for this entry.
613 * Then read the IpMappedAddr array in the header.
614 * Verify that multihomed entries base and index are valid and points to
615 * a good multhomed entry.
616 * Mark the serveraddrs array with 1 ip address for regular entries.
618 * By the end, the severaddrs array will have a 0 if the entry has no
619 * IP addresses in it or the count of the number of IP addresses.
621 * The code does not verify if there are duplicate IP addresses in the
622 * list. The vlserver does this when a fileserver registeres itself.
625 struct vlheader *header;
628 struct nvlentry vlentry;
630 afs_int32 i, j, m, rindex;
631 afs_int32 mhentries, regentries;
632 afs_int32 caddrs[VL_MAX_ADDREXTBLKS];
633 char mhblock[VL_ADDREXTBLK_SIZE];
634 struct extentaddr *MHblock = (struct extentaddr *)mhblock;
635 struct extentaddr *e;
636 int ipindex, ipaddrs;
639 bzero(&nulluuid, sizeof(nulluuid));
642 printf("Check Multihomed blocks\n");
645 /* Read the first MH block and from it, gather the
646 * addresses of all the mh blocks.
648 readMH(header->SIT, MHblock);
649 if (MHblock->ex_flags != VLCONTBLOCK) {
650 printf("Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n",
654 for (i=0; i<VL_MAX_ADDREXTBLKS; i++) {
655 caddrs[i] = MHblock->ex_contaddrs[i];
658 if (header->SIT != caddrs[0]) {
659 printf("MH block does not point to self %u in header, %u in block\n",
660 header->SIT, caddrs[0]);
663 /* Now read each MH block and record it in the record array */
664 for (i=0; i<VL_MAX_ADDREXTBLKS; i++) {
665 if (!caddrs[i]) continue;
667 readMH(caddrs[i], MHblock);
668 if (MHblock->ex_flags != VLCONTBLOCK) {
669 printf("Multihomed Block 0: Bad entry at %u: Not a valid multihomed block\n",
673 rindex = caddrs[i]/sizeof(vlentry);
674 if (record[rindex].addr != caddrs[i] && record[rindex].addr) {
675 printf("INTERNAL ERROR: addresses %u and %u use same record slot %d\n",
676 record[rindex].addr, caddrs[i], rindex);
678 if (record[rindex].type & FRC) {
679 printf("MH Blocks Chain %d: Bad entry at %u: Already a MH block\n", i, addr);
682 record[rindex].type |= MHC;
686 /* Read each entry in a multihomed block.
687 * Find the pointer to the entry in the IpMappedAddr array and
688 * verify that the entry is good (has IP addresses in it).
691 for (j=1; j<VL_MHSRV_PERBLK; j++) {
692 e = (struct extentaddr *)&(MHblock[j]);
694 /* Search the IpMappedAddr array for the reference to this entry */
695 for (ipindex=0; ipindex<MAXSERVERID; ipindex++) {
696 if ( ((header->IpMappedAddr[ipindex] & 0xff000000) == 0xff000000) &&
697 (((header->IpMappedAddr[ipindex] & 0x00ff0000)>>16) == i) &&
698 ((header->IpMappedAddr[ipindex] & 0x0000ffff) == j) ) {
702 if (ipindex >= MAXSERVERID) ipindex = -1;
703 else serveraddrs[ipindex] = -1;
705 if (memcmp(&e->ex_hostuuid, &nulluuid, sizeof(afsUUID)) == 0) {
707 printf("Server Addrs index %d references null MH block %d, index %d\n", i, j);
708 serveraddrs[ipindex] = 0; /* avoids printing 2nd error below */
713 /* Step through each ip address and count the good addresses */
715 for (m=0; m<VL_MAXIPADDRS_PERMH; m++) {
716 if (e->ex_addrs[m]) ipaddrs++;
719 /* If we found any good ip addresses, mark it in the serveraddrs record */
723 printf("MH block %d, index %d: Not referenced by server addrs\n", i, j);
725 serveraddrs[ipindex] = ipaddrs; /* It is good */
729 if (listservers && ipaddrs) {
730 printf("MH block %d, index %d:", i, j);
731 for (m=0; m<VL_MAXIPADDRS_PERMH; m++) {
732 if (!e->ex_addrs[m]) continue;
733 printf(" %d.%d.%d.%d",
734 (e->ex_addrs[m]&0xff000000)>>24,
735 (e->ex_addrs[m]&0x00ff0000)>>16,
736 (e->ex_addrs[m]&0x0000ff00)>>8,
737 (e->ex_addrs[m]&0x000000ff));
743 * if (mhentries != MHblock->ex_count) {
744 * printf("MH blocks says it has %d entries (found %d)\n",
745 * MHblock->ex_count, mhentries);
751 printf("%d multihomed blocks\n", mhblocks);
753 /* Check the server addresses */
755 printf("Check server addresses\n");
756 mhentries = regentries = 0;
757 for (i=0; i<=MAXSERVERID; i++) {
758 if (header->IpMappedAddr[i]) {
759 if ((header->IpMappedAddr[i] & 0xff000000) == 0xff000000) {
761 if (((header->IpMappedAddr[i] & 0x00ff0000)>>16) > VL_MAX_ADDREXTBLKS)
762 printf("IP Addr for entry %d: Multihome block is bad (%d)\n",
763 i, ((header->IpMappedAddr[i] & 0x00ff0000)>>16));
764 if ( ((header->IpMappedAddr[i] & 0x0000ffff) > VL_MHSRV_PERBLK) ||
765 ((header->IpMappedAddr[i] & 0x0000ffff) < 1) )
766 printf("IP Addr for entry %d: Multihome index is bad (%d)\n",
767 i, (header->IpMappedAddr[i] & 0x0000ffff));
768 if (serveraddrs[i] == -1) {
769 printf("warning: IP Addr for entry %d: Multihome entry has no ip addresses\n", i);
773 printf(" Server ip addr %d = MH block %d, index %d\n", i,
774 (header->IpMappedAddr[i] & 0x00ff0000)>>16,
775 (header->IpMappedAddr[i] & 0x0000ffff));
779 serveraddrs[i] = 1; /* It is good */
781 printf(" Server ip addr %d = %d.%d.%d.%d\n", i,
782 (header->IpMappedAddr[i]&0xff000000)>>24,
783 (header->IpMappedAddr[i]&0x00ff0000)>>16,
784 (header->IpMappedAddr[i]&0x0000ff00)>>8,
785 (header->IpMappedAddr[i]&0x000000ff));
791 printf("%d simple entries, %d multihomed entries, Total = %d\n",
792 regentries, mhentries, mhentries+regentries);
798 struct cmd_syndesc *as;
802 afs_int32 maxentries, type;
803 struct vlheader header;
804 struct nvlentry vlentry;
807 dbfile = as->parms[0].items->data; /* -database */
808 listuheader = (as->parms[1].items ? 1 : 0); /* -uheader */
809 listheader = (as->parms[2].items ? 1 : 0); /* -vheader */
810 listservers = (as->parms[3].items ? 1 : 0); /* -servers */
811 listentries = (as->parms[4].items ? 1 : 0); /* -entries */
812 verbose = (as->parms[5].items ? 1 : 0); /* -verbose */
814 /* open the vldb database file */
815 fd = open(dbfile, O_RDONLY, 0);
817 printf("can't open file '%s'. error = %d\n", dbfile, errno);
821 /* read the ubik header and the vldb database header*/
824 if (header.vital_header.vldbversion < 3) {
825 printf("does not support vldb with version less than 3\n");
829 maxentries = (header.vital_header.eofPtr / sizeof(vlentry)) + 1;
830 record = (struct er *)malloc(maxentries * sizeof(struct er));
831 bzero((char *)record, (maxentries * sizeof(struct er)));
832 bzero((char *)serveraddrs, sizeof(serveraddrs));
834 /* Will fill in the record array of entries it found */
835 ReadAllEntries(&header);
836 listentries = 0; /* Listed all the entries */
838 /* Check the multihomed blocks for valid entries as well as
839 * the IpMappedAddrs array in the header for valid entries.
841 CheckIpAddrs(&header);
843 /* Follow the hash tables */
844 FollowNameHash(&header);
845 FollowIdHash(&header);
847 /* Follow the chain of free entries */
848 FollowFreeChain(&header);
850 /* Now check the record we have been keeping for inconsistancies
851 * For valid vlentries, also check that the server we point to is
852 * valid (the serveraddrs array).
855 printf("Verify each volume entry\n");
856 for (i=0; i<maxentries; i++) {
857 if (record[i].type == 0) continue;
859 /* If a vlentry, verify that its name is valid, its name and ids are
860 * on the hash chains, and its server numbers are good.
862 if (record[i].type & VL) {
863 readentry(record[i].addr, &vlentry, &type);
865 if (InvalidVolname(vlentry.name))
866 printf("Volume '%s' at addr has an invalid name\n", vlentry.name, record[i].addr);
868 if (!(record[i].type & NH))
869 printf("Volume '%s' not found in name hash\n", vlentry.name);
871 if (vlentry.volumeId[0] && !(record[i].type & RWH))
872 printf("Volume '%s' id %u not found in RW hash chain\n",
873 vlentry.name, vlentry.volumeId[0]);
875 if (vlentry.volumeId[1] && !(record[i].type & ROH))
876 printf("Volume '%s' id %u not found in RO hash chain\n",
877 vlentry.name, vlentry.volumeId[1]);
879 if (vlentry.volumeId[2] && !(record[i].type & BKH))
880 printf("Volume '%s' id %u not found in BK hash chain\n",
881 vlentry.name, vlentry.volumeId[2]);
883 for (j=0; j<NMAXNSERVERS; j++) {
884 if ( (vlentry.serverNumber[j] != 255) &&
885 (serveraddrs[vlentry.serverNumber[j]] == 0) ) {
886 printf("Volume '%s', index %d points to empty server entry %d\n",
887 vlentry.name, j, vlentry.serverNumber[j]);
891 if (record[i].type & 0xffffff00)
892 printf("Volume '%s' id %u also found on other chains (0x%x)\n",
893 vlentry.name, vlentry.volumeId[0], record[i].type);
896 } else if (record[i].type & FR) {
897 if (!(record[i].type & FRC))
898 printf("Free vlentry at %u not on free chain\n", record[i].addr);
900 if (record[i].type & 0xfffffdf0)
901 printf("Free vlentry at %u also found on other chains (0x%x)\n",
902 record[i].addr, record[i].type);
904 /* A multihomed entry */
905 } else if (record[i].type & MH) {
906 if (!(record[i].type & MHC))
907 printf("Multihomed block at %u is orphaned\n", record[i].addr);
909 if (record[i].type & 0xfffffef0)
910 printf("Multihomed block at %u also found on other chains (0x%x)\n",
911 record[i].addr, record[i].type);
914 printf("Unknown entry type at %u (0x%x)\n", record[i].addr, record[i].type);
923 struct cmd_syndesc *ts;
928 ts=cmd_CreateSyntax((char *)0, WorkerBee, (char *) 0, "vldb check");
929 cmd_AddParm(ts, "-database", CMD_SINGLE, CMD_REQUIRED, "vldb_file");
930 cmd_AddParm(ts, "-uheader", CMD_FLAG, CMD_OPTIONAL, "Display UBIK header");
931 cmd_AddParm(ts, "-vheader", CMD_FLAG, CMD_OPTIONAL, "Display VLDB header");
932 cmd_AddParm(ts, "-servers", CMD_FLAG, CMD_OPTIONAL, "Display server list");
933 cmd_AddParm(ts, "-entries", CMD_FLAG, CMD_OPTIONAL, "Display entries");
934 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");
936 return cmd_Dispatch(argc, argv);