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 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
21 #include <netinet/in.h>
22 #include <afs/venus.h>
24 #include <afs/afsutil.h>
25 #include <afs/fileutil.h>
28 #include "cnvldb.h" /* CHANGEME! */
30 #define MAXSIZE 2048 /* most I'll get back from PIOCTL */
31 #define BADSERVERID 255 /* XXX */
34 static char pn[] = "cnvldb";
35 static char tempname[] = "XXnewvldb";
36 static int MaxServers[3] = { 30, 254, 254 }; /* max server # permitted in this version */
38 static afs_int32 Conv4to3(afs_int32 addr);
40 static void convert_vlentry(int, int, int, struct vlheader_1 *,
41 struct vlheader_1 *, struct vlentry_1 *);
42 static void rewrite_header(int, int, void *);
43 static void readheader(int fd, int version, void *addr);
44 static int readentry(int fd, int version, void *addr);
45 static void printentry(int version, void *addr);
47 static char tspace[1024]; /* chdir can't handle anything bigger, anyway */
49 void read_mhentries(afs_uint32 mh_addr, int oldfd);
50 void convert_mhentries(int oldfd, int newfd, struct vlheader_2 *header, int fromver, int tover);
52 static int convert_header(int ofd, int fd, int fromv, int tov, void *fromaddr,
55 /* return a static pointer to a buffer */
57 Parent(const char *apath)
60 strcpy(tspace, apath);
61 tp = strrchr(tspace, '/');
70 int fromvers = 0, tovers = 0, showversion = 0;
73 const char *pathname = NULL;
77 handleit(struct cmd_syndesc *as, void *arock)
79 int w, old, new, rc, dump = 0, fromv = 0;
80 char ubik[80]; /* space for some ubik header */
82 struct vlheader_1 header1;
83 struct vlheader_2 header2;
84 struct vlheader_3 header3;
85 } oldheader, newheader; /* large enough for either */
88 struct vlentry_1 entry1;
89 struct vlentry_2 entry2;
90 struct vlentry_3 entry3;
91 char mhinfo_block[VL_ADDREXTBLK_SIZE];
94 pathname = (as->parms[2].items ? as->parms[2].items->data : dbPath); /* -name */
95 showversion = (as->parms[3].items ? 1 : 0); /* -showversion */
96 dump = (as->parms[4].items ? 1 : 0); /* -dumpvldb */
97 fromvers = (as->parms[1].items ? atoi(as->parms[1].items->data) : 0); /* -fromversion */
98 tovers = (as->parms[0].items ? atoi(as->parms[0].items->data) : 0); /* -toversion */
100 /* should stat() the old vldb, get its size, and see if there's */
101 /* room for another. It might be in AFS, so check the quota, too */
102 old = open(pathname, O_RDONLY);
108 /* Read the version */
109 lseek(old, 64, L_SET);
110 read(old, &fromv, sizeof(int));
111 fromv = ntohl(fromv);
112 if ((fromv < 1) || (fromv > 4)) {
113 fprintf(stderr, "%s", pn);
114 fprintf(stderr, ": Unrecognized VLDB version %d.\n", fromv);
118 /* Sequentially read the database converting the entries as we go */
119 lseek(old, 0, L_SET);
121 readheader(old, fromv, &oldheader);
123 dbsize = ntohl(oldheader.header1.vital_header.eofPtr);
124 fromv = ntohl(oldheader.header1.vital_header.vldbversion);
126 } else if (fromv == 2) {
127 dbsize = ntohl(oldheader.header2.vital_header.eofPtr);
128 fromv = ntohl(oldheader.header2.vital_header.vldbversion);
133 dbsize = ntohl(oldheader.header3.vital_header.eofPtr);
134 fromv = ntohl(oldheader.header3.vital_header.vldbversion);
135 mhaddr = ntohl(oldheader.header3.SIT);
137 /* Read the multihomed extent blocks in */
139 read_mhentries(mhaddr, old);
141 /* Position back to this after header */
142 lseek(old, pos + 64, L_SET);
146 if (showversion || dump) {
148 fprintf(stdout, "%s has a version of %d\n", pathname, fromv);
150 while (oldpos < dbsize) {
151 rc = readentry(old, fromv, &xvlentry);
152 if ((rc == 0) || (rc == EOF))
154 printentry(fromv, &xvlentry);
160 if (!fromvers) { /* not set */
162 } else if (fromvers != fromv) {
164 "%s has a version of %d while the -fromversion specified was %d - aborting\n",
165 pathname, fromv, fromvers);
169 if ((fromvers < 1) || (fromvers > 4)) {
170 fprintf(stderr, "%s", pn);
171 fprintf(stderr, ": VLDB version %d is not supported.\n", fromvers);
172 fprintf(stderr, "%s", pn);
173 fprintf(stderr, ": Only versions 1-4 are currently supported.\n");
178 tovers = fromvers + 1;
180 if (tovers < 1 || tovers > 4) {
181 fprintf(stderr, "%s", pn);
182 fprintf(stderr, ": VLDB version %d is not supported.\n", tovers);
183 fprintf(stderr, "%s", pn);
184 fprintf(stderr, ": Only versions 1 - 4 are currently supported.\n");
188 if (mhaddr && (tovers < 3)) {
189 fprintf(stderr, "%s", pn);
190 fprintf(stderr, ": Cannot convert. VLDB contains multihome info.\n");
194 /* OK! let's get down to business... */
196 if (chdir(Parent(pathname))) {
201 new = open(tempname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
207 /* Write the UBIK data */
208 w = write(new, ubik, 64);
210 printf("Write of ubik header failed %d; error %u\n", w, errno);
214 /* Because we know that all the vldb entries are the same size and type we
215 * can just read them sequentially, fiddle with the fields, and write
216 * them out again. If we invent a vldb format that has different
217 * types of entries, then we're going to have to invent new logic for
218 * converting the vldb-- we'll probably have to chase down the various
219 * linked lists in turn, doing lseeks and the like.
222 convert_header(old, new, fromvers, tovers, &oldheader, &newheader);
223 while (oldpos < dbsize) {
224 rc = readentry(old, fromvers, &xvlentry);
225 if ((rc == 0) || (rc == EOF))
227 convert_vlentry(new, fromvers, tovers,
228 (struct vlheader_1 *)&oldheader,
229 (struct vlheader_1 *)&newheader,
230 (struct vlentry_1 *)&xvlentry);
233 /* We have now finished sequentially reading and writing the database.
234 * Now randomly offset into database and update multihome entries.
236 convert_mhentries(old, new, (struct vlheader_2 *)&newheader,
238 rewrite_header(new, tovers, &newheader);
247 renamefile(tempname, pathname);
254 readheader(int fd, int version, void *addr)
256 int hdrsize, size = 0;
260 hdrsize = sizeof(struct vlheader_1);
262 hdrsize = sizeof(struct vlheader_2);
264 size = read(fd, addr, hdrsize);
272 readentry(int fd, int version, void *addr)
275 struct vlentry_3 *vl3p = (struct vlentry_3 *)addr;
277 char *caddr = (char *)addr;
281 1) ? sizeof(struct vlentry_1) : sizeof(struct vlentry_2));
282 rc = read(fd, addr, toread);
284 printf("Partial read of vlentry at pos %u: %d\n", oldpos, rc);
288 /* Read a mhblock entry if there is one */
289 if ((rc > 0) && (vl3p->flags == VLCONTBLOCK)) {
290 if (!mhaddr) /* Remember first mh block */
291 mhaddr = oldpos - rc;
293 rc1 = read(fd, &caddr[rc], VL_ADDREXTBLK_SIZE - rc);
294 if (rc1 != VL_ADDREXTBLK_SIZE - rc)
295 printf("Partial read of mhblock at pos %u: %d\n", oldpos + rc,
307 printentry(int version, void *addr)
309 struct vlentry_2 *vl2p = (struct vlentry_2 *)addr;
310 struct vlentry_3 *vl3p = (struct vlentry_3 *)addr;
313 /* Don't print anything if the entry is a mh info block */
314 if (vl3p->flags == VLCONTBLOCK) {
318 if (version == 1 || version == 2) {
319 printf("%s\t%5d [%10d:%10d:%10d]%8X%8d\n", vl2p->name, vl2p->spares3,
320 vl2p->volumeId[0], vl2p->volumeId[1], vl2p->volumeId[2],
321 vl2p->flags, vl2p->LockAfsId);
322 printf("\t%8d%8d%8d [%7d%7d%7d]%7d [%4d%4d%4d%4d][%4d%4d%4d%4d]\n",
323 vl2p->LockTimestamp, vl2p->cloneId, vl2p->spares0,
324 vl2p->nextIdHash[0], vl2p->nextIdHash[1], vl2p->nextIdHash[2],
325 vl2p->nextNameHash, vl2p->serverNumber[0],
326 vl2p->serverNumber[1], vl2p->serverNumber[2],
327 vl2p->serverNumber[3], vl2p->serverPartition[0],
328 vl2p->serverPartition[1], vl2p->serverPartition[2],
329 vl2p->serverPartition[3]);
330 printf("\t[%4d%4d%4d%4d]\n", vl2p->serverFlags[0],
331 vl2p->serverFlags[1], vl2p->serverFlags[2],
332 vl2p->serverFlags[3]);
333 } else { /* if (version >= 3) */
335 if (vl3p->flags == VLFREE)
337 printf("%s\tPos=%" AFS_SIZET_FMT " NextIdHash=[%d:%d:%d] NextNameHash=%d\n",
338 vl3p->name, (oldpos - sizeof(struct vlentry_3)),
339 vl3p->nextIdHash[0], vl3p->nextIdHash[1], vl3p->nextIdHash[2],
341 printf("\tRW=%u RO=%u BK=%u CL=%u flags=0x%X lockBy=%d lockTime=%u\n",
342 vl3p->volumeId[0], vl3p->volumeId[1], vl3p->volumeId[2],
343 vl3p->cloneId, vl3p->flags, vl3p->LockAfsId,
344 vl3p->LockTimestamp);
345 for (i = 0; i < OMAXNSERVERS; i++) {
346 if ((vl3p->serverNumber[i] & 0xff) != 0xff) {
347 printf("\tServer=%d Partition=%d flags=%X\n",
348 vl3p->serverNumber[i], vl3p->serverPartition[i],
349 vl3p->serverFlags[i]);
356 int readmhentries = 0;
357 struct extentaddr *base[VL_MAX_ADDREXTBLKS];
359 /* Read the multihome extent blocks in. Check if they are good by
360 * verifying their address is not pass the EOF and the flags are good.
361 * If it's not good, then don't read the block in.
364 read_mhentries(afs_uint32 mh_addr, int oldfd)
374 /* Initialize base pointers */
375 for (j = 0; j < VL_MAX_ADDREXTBLKS; j++)
381 /* Check if the first extent block is beyond eof. If
382 * it is, it's not real.
384 if (mh_addr > dbsize - VL_ADDREXTBLK_SIZE)
387 /* Now read the first mh extent block */
388 code = lseek(oldfd, mh_addr + 64, L_SET);
390 perror("seek MH block");
393 base[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE);
398 code = read(oldfd, (char *)base[0], VL_ADDREXTBLK_SIZE);
399 if (code != VL_ADDREXTBLK_SIZE) {
400 perror("read MH block");
406 /* Verify that this block is the right one */
407 if (ntohl(base[0]->ex_flags) != VLCONTBLOCK) { /* check if flag is correct */
413 /* The first block contains pointers to the other extent blocks.
414 * Check to see if the pointers are good and read them in if they are.
417 for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) {
418 if (!base[0]->ex_contaddrs[j])
421 sit = ntohl(base[0]->ex_contaddrs[j]);
423 /* Every time we allocate a new extent block, it is allocated after
424 * the previous ones. But it must be before the EOF.
426 if ((sit < (a + VL_ADDREXTBLK_SIZE))
427 || (sit > dbsize - VL_ADDREXTBLK_SIZE)) {
431 /* Read the extent block in */
433 code = lseek(oldfd, sit, L_SET);
435 perror("seek MH block");
438 base[j] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE);
443 code = read(oldfd, (char *)base[j], VL_ADDREXTBLK_SIZE);
444 if (code != VL_ADDREXTBLK_SIZE) {
445 perror("read MH block");
449 /* Verify that this block knows its an extent block */
450 if (ntohl(base[j]->ex_flags) != VLCONTBLOCK) {
456 /* The extent block passed our tests */
457 a = ntohl(base[0]->ex_contaddrs[j]);
461 /* Follow the SIT pointer in the header (mhaddr) to the multihomed
462 * extent blocks and verify that the pointers are good. And fix.
463 * Then convert the multihomed addresses to single address if we
464 * are converting back from version 4.
466 * Before this can be called, the routine read_mhentries must be called.
469 convert_mhentries(int oldfd, int newfd, struct vlheader_2 *header,
470 int fromver, int tover)
473 int i, j, modified = 0, w;
474 afs_uint32 raddr, addr;
475 struct extentaddr *exp;
478 /* Check if the header says the extent block exists. If
479 * it does, then read_mhentries should have read it in.
481 if (mhaddr && !base[0]) {
482 printf("Fix Bad base extent block pointer\n");
483 header->SIT = mhaddr = 0;
484 } else if (mhaddr && base[0]) {
486 if ((ntohl(header->SIT) != mhaddr) && (tover == 4)) {
488 ("Fix pointer to first base extent block. Was 0x%x, now 0x%x\n",
489 ntohl(header->SIT), mhaddr);
490 header->SIT = htonl(mhaddr);
493 /* Check if the first block points to itself. If not, then fix it */
494 if (ntohl(base[0]->ex_contaddrs[0]) != mhaddr) {
495 printf("Fix bad pointer in base extent block: Base 0\n");
496 base[0]->ex_contaddrs[0] = htonl(mhaddr);
500 /* The first block contains pointers to the other extent blocks.
501 * Check to see if the pointers are good.
503 for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) {
504 /* Check if the base extent block says the extent blocks exist.
505 * If it does, then read_mhentries should have read it in.
507 if (base[0]->ex_contaddrs[j] && !base[j]) {
508 printf("Fix bad pointer in base extent block: Base %d\n", j);
509 base[0]->ex_contaddrs[j] = 0;
514 /* Now write out the base extent blocks if it changed */
516 code = lseek(newfd, mhaddr + 64, L_SET);
518 perror("seek MH Block");
521 w = write(newfd, (char *)base[0], VL_ADDREXTBLK_SIZE);
522 if (w != VL_ADDREXTBLK_SIZE) {
523 perror("write MH Block");
529 /* If we are converting from version 4 to version 3, then
530 * translate any multihome ptrs in the IpMappedAddr array
531 * to true IP addresses.
533 if ((fromver == 4) && (tover == 3)) {
534 /* Step through the fileserver addresses in the VLDB header
535 * and convert the pointers back to IP addresses.
537 for (i = 0; i < 254; i++) {
538 addr = ntohl(header->IpMappedAddr[i]);
539 if (addr && ((addr & 0xff000000) == 0xff000000)) {
540 basei = (addr >> 16) & 0xff;
541 index = addr & 0xffff;
543 if ((basei >= VL_ADDREXTBLK_SIZE) || !base[basei]) {
545 "Warning: mh entry %d has no IP address; ignored!!\n",
547 header->IpMappedAddr[i] = 0;
550 exp = &base[basei][index];
552 /* For now return the first ip address back */
553 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
554 if (exp->ex_addrs[j]) {
555 raddr = ntohl(exp->ex_addrs[j]);
559 if (j >= VL_MAXIPADDRS_PERMH) {
561 "Warning: mh entry %d has no ip address; ignored!!\n",
566 ("Multi-homed addr: converting to single ip address %d.%d.%d.%d\n",
567 (raddr >> 24 & 0xff), (raddr >> 16 & 0xff),
568 (raddr >> 8 & 0xff), (raddr & 0xff));
570 header->IpMappedAddr[i] = htonl(raddr);
573 header->SIT = mhaddr = 0; /* mhinfo block has been removed */
575 /* Now step through the hash tables in header updating them.
576 * Because we removed the mh info blocks and some entries they
577 * point to may have changed position.
580 for (i = 0; i < 8191; i++) {
581 header->VolnameHash[i] = Conv4to3(header->VolnameHash[i]);
584 for (i = 0; i < 3; i++) {
585 for (j = 0; j < 8191; j++) {
586 header->VolidHash[i][j] = Conv4to3(header->VolidHash[i][j]);
590 /* Update eofptr to take into account the removal of the mhinfo blocks */
591 header->vital_header.eofPtr = htonl(Conv4to3(dbsize));
597 convert_header(int ofd, int fd, int fromv, int tov, void *fromaddr,
600 struct vlheader_1 *tvp1;
601 struct vlheader_2 *tvp2;
606 memcpy(toaddr, fromaddr, sizeof(struct vlheader_1));
607 tvp1 = (struct vlheader_1 *)toaddr;
609 w = write(fd, tvp1, sizeof(struct vlheader_1));
610 if (w != sizeof(struct vlheader_1)) {
611 printf("Write of header failed %d; error %u\n", w, errno);
615 /* for garbage-collecting... */
616 for (i = 0; i < 31; i++)
617 tvp1->IpMappedAddr[i] = 0;
619 } else if (tov == 2 || tov == 3) {
620 tvp1 = (struct vlheader_1 *)fromaddr;
621 tvp2 = (struct vlheader_2 *)toaddr;
622 memset(tvp2, 0, sizeof(struct vlheader_2));
623 tvp2->vital_header.vldbversion = htonl(tov);
624 tvp2->vital_header.headersize = htonl(sizeof(struct vlheader_2));
626 ntohl(tvp2->vital_header.headersize) -
627 ntohl(tvp1->vital_header.headersize);
628 if (ntohl(tvp1->vital_header.freePtr))
629 tvp2->vital_header.freePtr =
630 htonl(ntohl(tvp1->vital_header.freePtr) + diff);
631 if (ntohl(tvp1->vital_header.eofPtr))
632 tvp2->vital_header.eofPtr =
633 htonl(ntohl(tvp1->vital_header.eofPtr) + diff);
634 tvp2->vital_header.allocs = tvp1->vital_header.allocs;
635 tvp2->vital_header.frees = tvp1->vital_header.frees;
636 tvp2->vital_header.MaxVolumeId = tvp1->vital_header.MaxVolumeId;
637 for (i = 0; i < 3; i++)
638 tvp2->vital_header.totalEntries[i] =
639 tvp1->vital_header.totalEntries[i];
641 for (i = 0; i < 31; i++)
642 tvp2->IpMappedAddr[i] = tvp1->IpMappedAddr[i];
644 for (i = 0; i < 8191; i++) {
645 if (ntohl(tvp1->VolnameHash[i]))
646 tvp2->VolnameHash[i] =
647 htonl(ntohl(tvp1->VolnameHash[i]) + diff);
650 for (i = 0; i < 3; i++) {
651 for (j = 0; j < 8191; j++) {
652 if (ntohl(tvp1->VolidHash[i][j]))
653 tvp2->VolidHash[i][j] =
654 htonl(ntohl(tvp1->VolidHash[i][j]) + diff);
658 w = write(fd, tvp2, sizeof(struct vlheader_2));
659 if (w != sizeof(struct vlheader_2)) {
660 printf("Write of header failed %d; error %u\n", w, errno);
664 /* for garbage-collecting... */
665 for (i = 0; i < 31; i++)
666 tvp2->IpMappedAddr[i] = 0;
669 } else if (fromv == 2 || fromv == 3 || fromv == 4) {
670 if (tov == 2 || tov == 3 || tov == 4) {
671 memcpy(toaddr, fromaddr, sizeof(struct vlheader_2));
672 tvp2 = (struct vlheader_2 *)toaddr;
673 tvp2->vital_header.vldbversion = htonl(tov);
674 w = write(fd, tvp2, sizeof(struct vlheader_2));
675 if (w != sizeof(struct vlheader_2)) {
676 printf("Write of header failed %d; error %u\n", w, errno);
680 } else if (tov == 1) {
681 tvp2 = (struct vlheader_2 *)fromaddr;
682 tvp1 = (struct vlheader_1 *)toaddr;
683 memset(tvp1, 0, sizeof(struct vlheader_1));
684 tvp1->vital_header.vldbversion = htonl(1);
685 tvp1->vital_header.headersize = htonl(sizeof(struct vlheader_1));
687 ntohl(tvp1->vital_header.headersize) -
688 ntohl(tvp2->vital_header.headersize);
689 if (ntohl(tvp2->vital_header.freePtr))
690 tvp1->vital_header.freePtr =
691 htonl(ntohl(tvp2->vital_header.freePtr) + diff);
692 if (ntohl(tvp2->vital_header.eofPtr))
693 tvp1->vital_header.eofPtr =
694 htonl(ntohl(tvp2->vital_header.eofPtr) + diff);
695 tvp1->vital_header.allocs = tvp2->vital_header.allocs;
696 tvp1->vital_header.frees = tvp2->vital_header.frees;
697 tvp1->vital_header.MaxVolumeId = tvp2->vital_header.MaxVolumeId;
698 for (i = 0; i < 3; i++)
699 tvp1->vital_header.totalEntries[i] =
700 tvp2->vital_header.totalEntries[i];
702 for (i = 0; i < 31; i++)
703 tvp1->IpMappedAddr[i] = tvp2->IpMappedAddr[i];
705 for (i = 0; i < 8191; i++) {
706 if (ntohl(tvp2->VolnameHash[i]))
707 tvp1->VolnameHash[i] =
708 htonl(ntohl(tvp2->VolnameHash[i]) + diff);
711 for (i = 0; i < 3; i++) {
712 for (j = 0; j < 8191; j++) {
713 if (ntohl(tvp2->VolidHash[i][j]))
714 tvp1->VolidHash[i][j] =
715 htonl(ntohl(tvp2->VolidHash[i][j]) + diff);
719 w = write(fd, tvp1, sizeof(struct vlheader_1));
720 if (w != sizeof(struct vlheader_2)) {
721 printf("Write of header failed %d; error %u\n", w, errno);
725 /* for garbage-collecting... */
726 for (i = 0; i < 31; i++)
727 tvp1->IpMappedAddr[i] = 0;
736 /* Convert an address pointer to a vlentry from version 4 to version 3.
737 * This involves checking if the address is after any of the four
738 * MH block and if it is, subtract the size of the MH block.
740 * In going from version 4 to 3, the mh blocks go away and all entries
741 * move up in their place. The adresses then need to be updated.
743 * Before this can be called, the routine read_mhentries must be called.
746 Conv4to3(afs_int32 addr)
751 if (!base[0] || !addr)
755 for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
756 if (base[i] && base[0]->ex_contaddrs[i]
757 && (addr > base[0]->ex_contaddrs[i]))
758 raddr -= VL_ADDREXTBLK_SIZE;
764 /* this only works because the vlheader struct is essentially the same
765 * from version 1 to version 2 -- that is, the first bunch of fields
766 * aren't any more or any larger, so they match up pretty well.
770 convert_vlentry(int new, int fromvers, int tovers,
771 struct vlheader_1 *oldheader, struct vlheader_1 *newheader,
772 struct vlentry_1 *vlentryp)
775 struct vlentry_3 *vl3p = (struct vlentry_3 *)vlentryp;
777 /* For mh information blocks,
778 * If going to version 4 or greater, keep the mh info block.
779 * Otherwise, don't keep it (version 3 and earlier don't have them).
781 if (vl3p->flags == VLCONTBLOCK) {
783 w = write(new, vlentryp, VL_ADDREXTBLK_SIZE);
784 if (w != VL_ADDREXTBLK_SIZE) {
785 printf("Write of mh info block failed %d; error %u\n", w,
793 if (fromvers == 2 && tovers == 3) {
796 vl.volumeId[0] = vlentryp->volumeId[0];
797 vl.volumeId[1] = vlentryp->volumeId[1];
798 vl.volumeId[2] = vlentryp->volumeId[2];
799 vl.flags = vlentryp->flags;
800 vl.LockAfsId = vlentryp->LockAfsId;
801 vl.LockTimestamp = vlentryp->LockTimestamp;
802 vl.cloneId = vlentryp->cloneId;
803 vl.nextIdHash[0] = vlentryp->nextIdHash[0];
804 vl.nextIdHash[1] = vlentryp->nextIdHash[1];
805 vl.nextIdHash[2] = vlentryp->nextIdHash[2];
806 vl.nextNameHash = vlentryp->nextNameHash;
807 memcpy(vl.name, vlentryp->name, 65);
808 for (i = 0; i < 8; i++) {
809 vl.serverNumber[i] = vlentryp->serverNumber[i];
810 vl.serverPartition[i] = vlentryp->serverPartition[i];
811 vl.serverFlags[i] = vlentryp->serverFlags[i];
814 vl.serverNumber[i] = vl.serverPartition[i] = vl.serverFlags[i] =
816 w = write(new, &vl, sizeof(struct vlentry_3));
817 if (w != sizeof(struct vlentry_3)) {
818 printf("Write of entry failed %d; error %u\n", w, errno);
823 } else if (fromvers == 3 && tovers == 2) {
825 struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp;
827 memset((char *)&vl, 0, sizeof(struct vlentry_2));
828 vl.volumeId[0] = xnvlentry->volumeId[0];
829 vl.volumeId[1] = xnvlentry->volumeId[1];
830 vl.volumeId[2] = xnvlentry->volumeId[2];
831 vl.flags = xnvlentry->flags;
832 vl.LockAfsId = xnvlentry->LockAfsId;
833 vl.LockTimestamp = xnvlentry->LockTimestamp;
834 vl.cloneId = xnvlentry->cloneId;
835 for (i = 0; i < 3; i++) {
836 if (ntohl(xnvlentry->nextIdHash[i]))
837 vl.nextIdHash[i] = xnvlentry->nextIdHash[i];
839 if (ntohl(xnvlentry->nextNameHash))
840 vl.nextNameHash = xnvlentry->nextNameHash;
841 memcpy(vl.name, xnvlentry->name, 65);
842 for (i = 0; i < 8; i++) {
843 vl.serverNumber[i] = xnvlentry->serverNumber[i];
844 vl.serverPartition[i] = xnvlentry->serverPartition[i];
845 vl.serverFlags[i] = xnvlentry->serverFlags[i];
847 w = write(new, &vl, sizeof(struct vlentry_2));
848 if (w != sizeof(struct vlentry_2)) {
849 printf("Write of entry failed %d; error %u\n", w, errno);
853 } else if (fromvers == 3 && tovers == 1) {
855 struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp;
859 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2))
861 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2));
862 memset((char *)&vl, 0, sizeof(struct vlentry_1));
863 vl.volumeId[0] = xnvlentry->volumeId[0];
864 vl.volumeId[1] = xnvlentry->volumeId[1];
865 vl.volumeId[2] = xnvlentry->volumeId[2];
866 vl.flags = xnvlentry->flags;
867 vl.LockAfsId = xnvlentry->LockAfsId;
868 vl.LockTimestamp = xnvlentry->LockTimestamp;
869 vl.cloneId = xnvlentry->cloneId;
870 for (i = 0; i < 3; i++) {
871 if (ntohl(xnvlentry->nextIdHash[i]))
873 htonl(ntohl(xnvlentry->nextIdHash[i]) + diff);
875 if (ntohl(xnvlentry->nextNameHash))
876 vl.nextNameHash = htonl(ntohl(xnvlentry->nextNameHash) + diff);
878 memcpy(vl.name, xnvlentry->name, 65);
879 for (i = 0; i < 8; i++) {
880 vl.serverNumber[i] = xnvlentry->serverNumber[i];
881 vl.serverPartition[i] = xnvlentry->serverPartition[i];
882 vl.serverFlags[i] = xnvlentry->serverFlags[i];
884 for (i = 0; i < 8; i++) {
885 s = xnvlentry->serverNumber[i];
887 if (s > MaxServers[tovers - 1]) {
889 "%s: Too Many Servers (%d) for this version!\n",
893 newheader->IpMappedAddr[s] = oldheader->IpMappedAddr[s];
896 w = write(new, &vl, sizeof(struct vlentry_1));
897 if (w != sizeof(struct vlentry_1)) {
898 printf("Write of entry failed %d; error %u\n", w, errno);
902 } else if (fromvers == 4 && tovers == 3) {
904 /* We are converting from version 4 to 3. In this conversion, mh info
905 * blocks go away and all vlentries after them move up in the vldb file.
906 * When this happens, the linked list pointers need to be updated.
908 memcpy(&vl, vlentryp, sizeof(vl));
909 for (i = 0; i < 3; i++) {
910 vl.nextIdHash[i] = Conv4to3(vl.nextIdHash[i]);
912 vl.nextNameHash = Conv4to3(vl.nextNameHash);
914 w = write(new, &vl, sizeof(vl));
915 if (w != sizeof(vl)) {
916 printf("Write of entry failed %d; error %u\n", w, errno);
923 w = write(new, vlentryp, sizeof(struct vlentry_1));
924 if (w != sizeof(struct vlentry_1)) {
925 printf("Write of entry failed %d; error %u\n", w, errno);
928 } else if (tovers == 2) {
929 w = write(new, vlentryp, sizeof(struct vlentry_2));
930 if (w != sizeof(struct vlentry_2)) {
931 printf("Write of entry failed %d; error %u\n", w, errno);
934 } else if (tovers == 3 || tovers == 4) {
935 w = write(new, vlentryp, sizeof(struct vlentry_3));
936 if (w != sizeof(struct vlentry_3)) {
937 printf("Write of entry failed %d; error %u\n", w, errno);
943 "Skipping vlentry write - db corrupted - bad toversion %d\n",
951 rewrite_header(int new, int tovers, void *newheader)
955 pos = lseek(new, 64, L_SET); /* leave room for ubik */
958 fprintf(stderr, "%s: no garbage colection\n", pn);
960 } else if (pos != 64) {
961 fprintf(stderr, "%s: Can't rewind: no garbage collection\n", pn);
967 1) ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2));
968 w = write(new, newheader, towrite);
970 printf("Write of entry failed %d; error %u\n", w, errno);
978 #include "AFS_component_version_number.c"
981 main(int argc, char **argv)
983 register struct cmd_syndesc *ts;
986 ts = cmd_CreateSyntax("initcmd", handleit, NULL, "optional");
987 cmd_AddParm(ts, "-to", CMD_SINGLE, CMD_OPTIONAL, "goal version");
988 cmd_AddParm(ts, "-from", CMD_SINGLE, CMD_OPTIONAL, "current version");
989 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "pathname");
990 cmd_AddParm(ts, "-showversion", CMD_FLAG, CMD_OPTIONAL,
991 "Just display version of current vldb");
992 cmd_AddParm(ts, "-dumpvldb", CMD_FLAG, CMD_OPTIONAL,
993 "display all vldb entries");
996 cmd_AddParm(ts, "-noGC", CMD_FLAG, CMD_OPTIONAL,
997 "Don't do garbage collection");
1000 dbPath = AFSDIR_SERVER_VLDB_FILEPATH;
1002 code = cmd_Dispatch(argc, argv);