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>
17 #include <sys/types.h>
23 #include "cnvldb.h" /* CHANGEME! */
24 #include <netinet/in.h>
25 #include <afs/venus.h>
27 #include <afs/afsutil.h>
28 #include <afs/fileutil.h>
32 #define MAXSIZE 2048 /* most I'll get back from PIOCTL */
33 #define BADSERVERID 255 /* XXX */
36 static char pn[] = "cnvldb";
37 static char tempname[] = "XXnewvldb";
38 static char space[MAXSIZE];
39 static int MaxServers[3] = { 30, 254, 254 }; /* max server # permitted in this version */
41 static afs_int32 Conv4to3();
43 static int convert_vlentry();
44 static int rewrite_header();
46 static char tspace[1024]; /* chdir can't handle anything bigger, anyway */
48 void read_mhentries(afs_uint32 mh_addr, int oldfd);
49 void convert_mhentries(int oldfd, int newfd, struct vlheader_2 *header, int fromver, int tover);
51 /* return a static pointer to a buffer */
57 strcpy(tspace, apath);
58 tp = strrchr(tspace, '/');
67 int fromvers = 0, tovers = 0, showversion = 0;
70 char *pathname = NULL;
74 handleit(struct cmd_syndesc *as, void *arock)
76 register struct cmd_item *ti;
77 register afs_int32 code;
78 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, oldheader1, 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)) {
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)) {
171 fprintf(stderr, ": VLDB version %d is not supported.\n", fromvers);
173 fprintf(stderr, ": Only versions 1-4 are currently supported.\n");
178 tovers = fromvers + 1;
180 if (tovers < 1 || tovers > 4) {
182 fprintf(stderr, ": VLDB version %d is not supported.\n", tovers);
184 fprintf(stderr, ": Only versions 1 - 4 are currently supported.\n");
188 if (mhaddr && (tovers < 3)) {
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, &oldheader, &newheader,
231 /* We have now finished sequentially reading and writing the database.
232 * Now randomly offset into database and update multihome entries.
234 convert_mhentries(old, new, &newheader, fromvers, tovers);
235 rewrite_header(new, tovers, &newheader);
244 renamefile(tempname, pathname);
250 readheader(fd, version, addr)
255 int hdrsize, size = 0;
259 hdrsize = sizeof(struct vlheader_1);
261 hdrsize = sizeof(struct vlheader_2);
263 size = read(fd, addr, hdrsize);
270 readentry(fd, version, addr)
276 struct vlentry_3 *vl3p = (struct vlentry_3 *)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, &addr[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,
306 printentry(version, addr)
310 struct vlentry_2 *vl2p = (struct vlentry_2 *)addr;
311 struct vlentry_3 *vl3p = (struct vlentry_3 *)addr;
314 /* Don't print anything if the entry is a mh info block */
315 if (vl3p->flags == VLCONTBLOCK) {
319 if (version == 1 || version == 2) {
320 printf("%s\t%5d [%10d:%10d:%10d]%8X%8d\n", vl2p->name, vl2p->spares3,
321 vl2p->volumeId[0], vl2p->volumeId[1], vl2p->volumeId[2],
322 vl2p->flags, vl2p->LockAfsId);
323 printf("\t%8d%8d%8d [%7d%7d%7d]%7d% [%4d%4d%4d%4d][%4d%4d%4d%4d]\n",
324 vl2p->LockTimestamp, vl2p->cloneId, vl2p->spares0,
325 vl2p->nextIdHash[0], vl2p->nextIdHash[1], vl2p->nextIdHash[2],
326 vl2p->nextNameHash, vl2p->serverNumber[0],
327 vl2p->serverNumber[1], vl2p->serverNumber[2],
328 vl2p->serverNumber[3], vl2p->serverPartition[0],
329 vl2p->serverPartition[1], vl2p->serverPartition[2],
330 vl2p->serverPartition[3]);
331 printf("\t[%4d%4d%4d%4d]\n", vl2p->serverFlags[0],
332 vl2p->serverFlags[1], vl2p->serverFlags[2],
333 vl2p->serverFlags[3]);
334 } else { /* if (version >= 3) */
336 if (vl3p->flags == VLFREE)
338 printf("%s\tPos=%lu NextIdHash=[%d:%d:%d] NextNameHash=%d\n",
339 vl3p->name, (oldpos - sizeof(struct vlentry_3)),
340 vl3p->nextIdHash[0], vl3p->nextIdHash[1], vl3p->nextIdHash[2],
342 printf("\tRW=%u RO=%u BK=%u CL=%u flags=0x%X lockBy=%d lockTime=%u\n",
343 vl3p->volumeId[0], vl3p->volumeId[1], vl3p->volumeId[2],
344 vl3p->cloneId, vl3p->flags, vl3p->LockAfsId,
345 vl3p->LockTimestamp);
346 for (i = 0; i < OMAXNSERVERS; i++) {
347 if ((vl3p->serverNumber[i] & 0xff) != 0xff) {
348 printf("\tServer=%d Partition=%d flags=%X\n",
349 vl3p->serverNumber[i], vl3p->serverPartition[i],
350 vl3p->serverFlags[i]);
357 int readmhentries = 0;
358 struct extentaddr *base[VL_MAX_ADDREXTBLKS];
360 /* Read the multihome extent blocks in. Check if they are good by
361 * verifying their address is not pass the EOF and the flags are good.
362 * If it's not good, then don't read the block in.
365 read_mhentries(mh_addr, oldfd)
377 /* Initialize base pointers */
378 for (j = 0; j < VL_MAX_ADDREXTBLKS; j++)
384 /* Check if the first extent block is beyond eof. If
385 * it is, it's not real.
387 if (mh_addr > dbsize - VL_ADDREXTBLK_SIZE)
390 /* Now read the first mh extent block */
391 code = lseek(oldfd, mh_addr + 64, L_SET);
393 perror("seek MH block");
396 base[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE);
401 code = read(oldfd, (char *)base[0], VL_ADDREXTBLK_SIZE);
402 if (code != VL_ADDREXTBLK_SIZE) {
403 perror("read MH block");
409 /* Verify that this block is the right one */
410 if (ntohl(base[0]->ex_flags) != VLCONTBLOCK) { /* check if flag is correct */
416 /* The first block contains pointers to the other extent blocks.
417 * Check to see if the pointers are good and read them in if they are.
420 for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) {
421 if (!base[0]->ex_contaddrs[j])
424 sit = ntohl(base[0]->ex_contaddrs[j]);
426 /* Every time we allocate a new extent block, it is allocated after
427 * the previous ones. But it must be before the EOF.
429 if ((sit < (a + VL_ADDREXTBLK_SIZE))
430 || (sit > dbsize - VL_ADDREXTBLK_SIZE)) {
434 /* Read the extent block in */
436 code = lseek(oldfd, sit, L_SET);
438 perror("seek MH block");
441 base[j] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE);
446 code = read(oldfd, (char *)base[j], VL_ADDREXTBLK_SIZE);
447 if (code != VL_ADDREXTBLK_SIZE) {
448 perror("read MH block");
452 /* Verify that this block knows its an extent block */
453 if (ntohl(base[j]->ex_flags) != VLCONTBLOCK) {
459 /* The extent block passed our tests */
460 a = ntohl(base[0]->ex_contaddrs[j]);
464 /* Follow the SIT pointer in the header (mhaddr) to the multihomed
465 * extent blocks and verify that the pointers are good. And fix.
466 * Then convert the multihomed addresses to single address if we
467 * are converting back from version 4.
469 * Before this can be called, the routine read_mhentries must be called.
472 convert_mhentries(oldfd, newfd, header, fromver, tover)
474 struct vlheader_2 *header;
479 int i, j, modified = 0, w;
480 afs_uint32 raddr, addr;
481 struct extentaddr *exp;
484 /* Check if the header says the extent block exists. If
485 * it does, then read_mhentries should have read it in.
487 if (mhaddr && !base[0]) {
488 printf("Fix Bad base extent block pointer\n");
489 header->SIT = mhaddr = 0;
490 } else if (mhaddr && base[0]) {
492 if ((ntohl(header->SIT) != mhaddr) && (tover == 4)) {
494 ("Fix pointer to first base extent block. Was 0x%x, now 0x%x\n",
495 ntohl(header->SIT), mhaddr);
496 header->SIT = htonl(mhaddr);
499 /* Check if the first block points to itself. If not, then fix it */
500 if (ntohl(base[0]->ex_contaddrs[0]) != mhaddr) {
501 printf("Fix bad pointer in base extent block: Base 0\n");
502 base[0]->ex_contaddrs[0] = htonl(mhaddr);
506 /* The first block contains pointers to the other extent blocks.
507 * Check to see if the pointers are good.
509 for (j = 1; j < VL_MAX_ADDREXTBLKS; j++) {
510 /* Check if the base extent block says the extent blocks exist.
511 * If it does, then read_mhentries should have read it in.
513 if (base[0]->ex_contaddrs[j] && !base[j]) {
514 printf("Fix bad pointer in base extent block: Base %d\n", j);
515 base[0]->ex_contaddrs[j] = 0;
520 /* Now write out the base extent blocks if it changed */
522 code = lseek(newfd, mhaddr + 64, L_SET);
524 perror("seek MH Block");
527 w = write(newfd, (char *)base[0], VL_ADDREXTBLK_SIZE);
528 if (w != VL_ADDREXTBLK_SIZE) {
529 perror("write MH Block");
535 /* If we are converting from version 4 to version 3, then
536 * translate any multihome ptrs in the IpMappedAddr array
537 * to true IP addresses.
539 if ((fromver == 4) && (tover == 3)) {
540 /* Step through the fileserver addresses in the VLDB header
541 * and convert the pointers back to IP addresses.
543 for (i = 0; i < 254; i++) {
544 addr = ntohl(header->IpMappedAddr[i]);
545 if (addr && ((addr & 0xff000000) == 0xff000000)) {
546 basei = (addr >> 16) & 0xff;
547 index = addr & 0xffff;
549 if ((basei >= VL_ADDREXTBLK_SIZE) || !base[basei]) {
551 "Warning: mh entry %d has no IP address; ignored!!\n",
553 header->IpMappedAddr[i] = 0;
556 exp = &base[basei][index];
558 /* For now return the first ip address back */
559 for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
560 if (exp->ex_addrs[j]) {
561 raddr = ntohl(exp->ex_addrs[j]);
565 if (j >= VL_MAXIPADDRS_PERMH) {
567 "Warning: mh entry %d has no ip address; ignored!!\n",
572 ("Multi-homed addr: converting to single ip address %d.%d.%d.%d\n",
573 (raddr >> 24 & 0xff), (raddr >> 16 & 0xff),
574 (raddr >> 8 & 0xff), (raddr & 0xff));
576 header->IpMappedAddr[i] = htonl(raddr);
579 header->SIT = mhaddr = 0; /* mhinfo block has been removed */
581 /* Now step through the hash tables in header updating them.
582 * Because we removed the mh info blocks and some entries they
583 * point to may have changed position.
586 for (i = 0; i < 8191; i++) {
587 header->VolnameHash[i] = Conv4to3(header->VolnameHash[i]);
590 for (i = 0; i < 3; i++) {
591 for (j = 0; j < 8191; j++) {
592 header->VolidHash[i][j] = Conv4to3(header->VolidHash[i][j]);
596 /* Update eofptr to take into account the removal of the mhinfo blocks */
597 header->vital_header.eofPtr = htonl(Conv4to3(dbsize));
602 convert_header(ofd, fd, fromv, tov, fromaddr, toaddr)
603 int ofd, fd, fromv, tov;
604 char *fromaddr, *toaddr;
606 struct vlheader_1 *tvp1;
607 struct vlheader_2 *tvp2;
612 memcpy(toaddr, fromaddr, sizeof(struct vlheader_1));
613 tvp1 = (struct vlheader_1 *)toaddr;
615 w = write(fd, tvp1, sizeof(struct vlheader_1));
616 if (w != sizeof(struct vlheader_1)) {
617 printf("Write of header failed %d; error %u\n", w, errno);
621 /* for garbage-collecting... */
622 for (i = 0; i < 31; i++)
623 tvp1->IpMappedAddr[i] = 0;
625 } else if (tov == 2 || tov == 3) {
626 tvp1 = (struct vlheader_1 *)fromaddr;
627 tvp2 = (struct vlheader_2 *)toaddr;
628 memset(tvp2, 0, sizeof(struct vlheader_2));
629 tvp2->vital_header.vldbversion = htonl(tov);
630 tvp2->vital_header.headersize = htonl(sizeof(struct vlheader_2));
632 ntohl(tvp2->vital_header.headersize) -
633 ntohl(tvp1->vital_header.headersize);
634 if (ntohl(tvp1->vital_header.freePtr))
635 tvp2->vital_header.freePtr =
636 htonl(ntohl(tvp1->vital_header.freePtr) + diff);
637 if (ntohl(tvp1->vital_header.eofPtr))
638 tvp2->vital_header.eofPtr =
639 htonl(ntohl(tvp1->vital_header.eofPtr) + diff);
640 tvp2->vital_header.allocs = tvp1->vital_header.allocs;
641 tvp2->vital_header.frees = tvp1->vital_header.frees;
642 tvp2->vital_header.MaxVolumeId = tvp1->vital_header.MaxVolumeId;
643 for (i = 0; i < 3; i++)
644 tvp2->vital_header.totalEntries[i] =
645 tvp1->vital_header.totalEntries[i];
647 for (i = 0; i < 31; i++)
648 tvp2->IpMappedAddr[i] = tvp1->IpMappedAddr[i];
650 for (i = 0; i < 8191; i++) {
651 if (ntohl(tvp1->VolnameHash[i]))
652 tvp2->VolnameHash[i] =
653 htonl(ntohl(tvp1->VolnameHash[i]) + diff);
656 for (i = 0; i < 3; i++) {
657 for (j = 0; j < 8191; j++) {
658 if (ntohl(tvp1->VolidHash[i][j]))
659 tvp2->VolidHash[i][j] =
660 htonl(ntohl(tvp1->VolidHash[i][j]) + diff);
664 w = write(fd, tvp2, sizeof(struct vlheader_2));
665 if (w != sizeof(struct vlheader_2)) {
666 printf("Write of header failed %d; error %u\n", w, errno);
670 /* for garbage-collecting... */
671 for (i = 0; i < 31; i++)
672 tvp2->IpMappedAddr[i] = 0;
675 } else if (fromv == 2 || fromv == 3 || fromv == 4) {
676 if (tov == 2 || tov == 3 || tov == 4) {
677 memcpy(toaddr, fromaddr, sizeof(struct vlheader_2));
678 tvp2 = (struct vlheader_2 *)toaddr;
679 tvp2->vital_header.vldbversion = htonl(tov);
680 w = write(fd, tvp2, sizeof(struct vlheader_2));
681 if (w != sizeof(struct vlheader_2)) {
682 printf("Write of header failed %d; error %u\n", w, errno);
686 } else if (tov == 1) {
687 tvp2 = (struct vlheader_2 *)fromaddr;
688 tvp1 = (struct vlheader_1 *)toaddr;
689 memset(tvp1, 0, sizeof(struct vlheader_1));
690 tvp1->vital_header.vldbversion = htonl(1);
691 tvp1->vital_header.headersize = htonl(sizeof(struct vlheader_1));
693 ntohl(tvp1->vital_header.headersize) -
694 ntohl(tvp2->vital_header.headersize);
695 if (ntohl(tvp2->vital_header.freePtr))
696 tvp1->vital_header.freePtr =
697 htonl(ntohl(tvp2->vital_header.freePtr) + diff);
698 if (ntohl(tvp2->vital_header.eofPtr))
699 tvp1->vital_header.eofPtr =
700 htonl(ntohl(tvp2->vital_header.eofPtr) + diff);
701 tvp1->vital_header.allocs = tvp2->vital_header.allocs;
702 tvp1->vital_header.frees = tvp2->vital_header.frees;
703 tvp1->vital_header.MaxVolumeId = tvp2->vital_header.MaxVolumeId;
704 for (i = 0; i < 3; i++)
705 tvp1->vital_header.totalEntries[i] =
706 tvp2->vital_header.totalEntries[i];
708 for (i = 0; i < 31; i++)
709 tvp1->IpMappedAddr[i] = tvp2->IpMappedAddr[i];
711 for (i = 0; i < 8191; i++) {
712 if (ntohl(tvp2->VolnameHash[i]))
713 tvp1->VolnameHash[i] =
714 htonl(ntohl(tvp2->VolnameHash[i]) + diff);
717 for (i = 0; i < 3; i++) {
718 for (j = 0; j < 8191; j++) {
719 if (ntohl(tvp2->VolidHash[i][j]))
720 tvp1->VolidHash[i][j] =
721 htonl(ntohl(tvp2->VolidHash[i][j]) + diff);
725 w = write(fd, tvp1, sizeof(struct vlheader_1));
726 if (w != sizeof(struct vlheader_2)) {
727 printf("Write of header failed %d; error %u\n", w, errno);
731 /* for garbage-collecting... */
732 for (i = 0; i < 31; i++)
733 tvp1->IpMappedAddr[i] = 0;
742 /* Convert an address pointer to a vlentry from version 4 to version 3.
743 * This involves checking if the address is after any of the four
744 * MH block and if it is, subtract the size of the MH block.
746 * In going from version 4 to 3, the mh blocks go away and all entries
747 * move up in their place. The adresses then need to be updated.
749 * Before this can be called, the routine read_mhentries must be called.
758 if (!base[0] || !addr)
762 for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
763 if (base[i] && base[0]->ex_contaddrs[i]
764 && (addr > base[0]->ex_contaddrs[i]))
765 raddr -= VL_ADDREXTBLK_SIZE;
771 /* this only works because the vlheader struct is essentially the same
772 * from version 1 to version 2 -- that is, the first bunch of fields
773 * aren't any more or any larger, so they match up pretty well.
777 convert_vlentry(new, fromvers, tovers, oldheader, newheader, vlentryp)
778 int new, fromvers, tovers;
779 struct vlheader_1 *oldheader, *newheader; /* close enough */
780 struct vlentry_1 *vlentryp; /* 1 and 2 are identical */
783 struct vlentry_3 *vl3p = (struct vlentry_3 *)vlentryp;
785 /* For mh information blocks,
786 * If going to version 4 or greater, keep the mh info block.
787 * Otherwise, don't keep it (version 3 and earlier don't have them).
789 if (vl3p->flags == VLCONTBLOCK) {
791 w = write(new, vlentryp, VL_ADDREXTBLK_SIZE);
792 if (w != VL_ADDREXTBLK_SIZE) {
793 printf("Write of mh info block failed %d; error %u\n", w,
801 if (fromvers == 2 && tovers == 3) {
804 vl.volumeId[0] = vlentryp->volumeId[0];
805 vl.volumeId[1] = vlentryp->volumeId[1];
806 vl.volumeId[2] = vlentryp->volumeId[2];
807 vl.flags = vlentryp->flags;
808 vl.LockAfsId = vlentryp->LockAfsId;
809 vl.LockTimestamp = vlentryp->LockTimestamp;
810 vl.cloneId = vlentryp->cloneId;
811 vl.nextIdHash[0] = vlentryp->nextIdHash[0];
812 vl.nextIdHash[1] = vlentryp->nextIdHash[1];
813 vl.nextIdHash[2] = vlentryp->nextIdHash[2];
814 vl.nextNameHash = vlentryp->nextNameHash;
815 memcpy(vl.name, vlentryp->name, 65);
816 for (i = 0; i < 8; i++) {
817 vl.serverNumber[i] = vlentryp->serverNumber[i];
818 vl.serverPartition[i] = vlentryp->serverPartition[i];
819 vl.serverFlags[i] = vlentryp->serverFlags[i];
822 vl.serverNumber[i] = vl.serverPartition[i] = vl.serverFlags[i] =
824 w = write(new, &vl, sizeof(struct vlentry_3));
825 if (w != sizeof(struct vlentry_3)) {
826 printf("Write of entry failed %d; error %u\n", w, errno);
831 } else if (fromvers == 3 && tovers == 2) {
833 struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp;
835 memset((char *)&vl, 0, sizeof(struct vlentry_2));
836 vl.volumeId[0] = xnvlentry->volumeId[0];
837 vl.volumeId[1] = xnvlentry->volumeId[1];
838 vl.volumeId[2] = xnvlentry->volumeId[2];
839 vl.flags = xnvlentry->flags;
840 vl.LockAfsId = xnvlentry->LockAfsId;
841 vl.LockTimestamp = xnvlentry->LockTimestamp;
842 vl.cloneId = xnvlentry->cloneId;
843 for (i = 0; i < 3; i++) {
844 if (ntohl(xnvlentry->nextIdHash[i]))
845 vl.nextIdHash[i] = xnvlentry->nextIdHash[i];
847 if (ntohl(xnvlentry->nextNameHash))
848 vl.nextNameHash = xnvlentry->nextNameHash;
849 memcpy(vl.name, xnvlentry->name, 65);
850 for (i = 0; i < 8; i++) {
851 vl.serverNumber[i] = xnvlentry->serverNumber[i];
852 vl.serverPartition[i] = xnvlentry->serverPartition[i];
853 vl.serverFlags[i] = xnvlentry->serverFlags[i];
855 w = write(new, &vl, sizeof(struct vlentry_2));
856 if (w != sizeof(struct vlentry_2)) {
857 printf("Write of entry failed %d; error %u\n", w, errno);
861 } else if (fromvers == 3 && tovers == 1) {
863 struct vlentry_3 *xnvlentry = (struct vlentry_3 *)vlentryp;
867 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2))
869 1 ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2));
870 memset((char *)&vl, 0, sizeof(struct vlentry_1));
871 vl.volumeId[0] = xnvlentry->volumeId[0];
872 vl.volumeId[1] = xnvlentry->volumeId[1];
873 vl.volumeId[2] = xnvlentry->volumeId[2];
874 vl.flags = xnvlentry->flags;
875 vl.LockAfsId = xnvlentry->LockAfsId;
876 vl.LockTimestamp = xnvlentry->LockTimestamp;
877 vl.cloneId = xnvlentry->cloneId;
878 for (i = 0; i < 3; i++) {
879 if (ntohl(xnvlentry->nextIdHash[i]))
881 htonl(ntohl(xnvlentry->nextIdHash[i]) + diff);
883 if (ntohl(xnvlentry->nextNameHash))
884 vl.nextNameHash = htonl(ntohl(xnvlentry->nextNameHash) + diff);
886 memcpy(vl.name, xnvlentry->name, 65);
887 for (i = 0; i < 8; i++) {
888 vl.serverNumber[i] = xnvlentry->serverNumber[i];
889 vl.serverPartition[i] = xnvlentry->serverPartition[i];
890 vl.serverFlags[i] = xnvlentry->serverFlags[i];
892 for (i = 0; i < 8; i++) {
893 s = xnvlentry->serverNumber[i];
895 if (s > MaxServers[tovers - 1]) {
897 "%s: Too Many Servers (%d) for this version!\n",
901 newheader->IpMappedAddr[s] = oldheader->IpMappedAddr[s];
904 w = write(new, &vl, sizeof(struct vlentry_1));
905 if (w != sizeof(struct vlentry_1)) {
906 printf("Write of entry failed %d; error %u\n", w, errno);
910 } else if (fromvers == 4 && tovers == 3) {
912 /* We are converting from version 4 to 3. In this conversion, mh info
913 * blocks go away and all vlentries after them move up in the vldb file.
914 * When this happens, the linked list pointers need to be updated.
916 memcpy(&vl, vlentryp, sizeof(vl));
917 for (i = 0; i < 3; i++) {
918 vl.nextIdHash[i] = Conv4to3(vl.nextIdHash[i]);
920 vl.nextNameHash = Conv4to3(vl.nextNameHash);
922 w = write(new, &vl, sizeof(vl));
923 if (w != sizeof(vl)) {
924 printf("Write of entry failed %d; error %u\n", w, errno);
931 w = write(new, vlentryp, sizeof(struct vlentry_1));
932 if (w != sizeof(struct vlentry_1)) {
933 printf("Write of entry failed %d; error %u\n", w, errno);
936 } else if (tovers == 2) {
937 w = write(new, vlentryp, sizeof(struct vlentry_2));
938 if (w != sizeof(struct vlentry_2)) {
939 printf("Write of entry failed %d; error %u\n", w, errno);
942 } else if (tovers == 3 || tovers == 4) {
943 w = write(new, vlentryp, sizeof(struct vlentry_3));
944 if (w != sizeof(struct vlentry_3)) {
945 printf("Write of entry failed %d; error %u\n", w, errno);
951 "Skipping vlentry write - db corrupted - bad toversion %d\n",
959 rewrite_header(new, tovers, newheader)
965 pos = lseek(new, 64, L_SET); /* leave room for ubik */
968 fprintf(stderr, "%s: no garbage colection\n", pn);
970 } else if (pos != 64) {
971 fprintf(stderr, "%s: Can't rewind: no garbage collection\n", pn);
977 1) ? sizeof(struct vlheader_1) : sizeof(struct vlheader_2));
978 w = write(new, newheader, towrite);
980 printf("Write of entry failed %d; error %u\n", w, errno);
988 #include "AFS_component_version_number.c"
994 register struct cmd_syndesc *ts;
997 ts = cmd_CreateSyntax("initcmd", handleit, NULL, "optional");
998 cmd_AddParm(ts, "-to", CMD_SINGLE, CMD_OPTIONAL, "goal version");
999 cmd_AddParm(ts, "-from", CMD_SINGLE, CMD_OPTIONAL, "current version");
1000 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "pathname");
1001 cmd_AddParm(ts, "-showversion", CMD_FLAG, CMD_OPTIONAL,
1002 "Just display version of current vldb");
1003 cmd_AddParm(ts, "-dumpvldb", CMD_FLAG, CMD_OPTIONAL,
1004 "display all vldb entries");
1007 cmd_AddParm(ts, "-noGC", CMD_FLAG, CMD_OPTIONAL,
1008 "Don't do garbage collection");
1011 dbPath = AFSDIR_SERVER_VLDB_FILEPATH;
1013 code = cmd_Dispatch(argc, argv);