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>
21 #include <sys/statfs.h>
28 #include <netinet/in.h>
32 #include <afs/voldefs.h>
35 #include <afs/vlserver.h>
37 #include <afs/cellconfig.h>
40 #include <afs/afsint.h>
44 #include <afs/com_err.h>
46 #include <afs/kautils.h>
49 #define ERRCODE_RANGE 8 /* from error_table.h */
50 #define CLOCKSKEW 2 /* not really skew, but resolution */
51 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
53 /* for UV_MoveVolume() recovery */
55 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
58 #include <volser_prototypes.h>
60 struct ubik_client *cstruct;
66 afs_int32 vldbEntryIndex;
69 /* Utility macros used by rest of this source file */
70 #define EPRINT(ec, es) \
72 fprintf(STDERR, "\n"); \
73 fprintf(STDERR, (es)); \
77 #define EPRINT1(ec, es, ep1) \
79 fprintf(STDERR, "\n"); \
80 fprintf(STDERR, (es), (ep1)); \
84 #define EPRINT2(ec, es, ep1, ep2) \
86 fprintf(STDERR, "\n"); \
87 fprintf(STDERR, (es), (ep1), (ep2)); \
91 #define EPRINT3(ec, es, ep1, ep2, ep3) \
93 fprintf(STDERR, "\n"); \
94 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
98 #define EGOTO(where, ec, es) \
107 #define EGOTO1(where, ec, es, ep1) \
110 EPRINT1((ec),(es),(ep1)); \
116 #define EGOTO2(where, ec, es, ep1, ep2) \
119 EPRINT2((ec),(es),(ep1),(ep2)); \
125 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
128 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
135 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
136 #define VPRINT1(es, p) \
137 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
138 #define VPRINT2(es, p1, p2) \
139 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
140 #define VPRINT3(es, p1, p2, p3) \
141 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
143 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
144 #define VEPRINT(es) \
145 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
146 #define VEPRINT1(es, p) \
147 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
148 #define VEPRINT2(es, p1, p2) \
149 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
150 #define VEPRINT3(es, p1, p2, p3) \
151 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
153 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
157 /* getting rid of this */
158 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
161 /* Protos for static routines */
162 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
163 afs_int32 apart, afs_int32 okvol,
165 static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
167 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
168 struct rx_connection **connPtr, afs_int32 * transPtr,
169 afs_int32 * crtimePtr, afs_int32 * uptimePtr);
170 static int SimulateForwardMultiple(struct rx_connection *fromconn,
171 afs_int32 fromtid, afs_int32 fromdate,
172 manyDests * tr, afs_int32 flags,
173 void *cookie, manyResults * results);
174 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
175 afs_int32 apart, afs_int32 * modentry,
176 afs_uint32 * maxvolid);
179 /*map the partition <partId> into partition name <partName>*/
181 MapPartIdIntoName(afs_int32 partId, char *partName)
183 if (partId < 26) { /* what if partId > = 26 ? */
184 strcpy(partName, "/vicep");
185 partName[6] = partId + 'a';
188 } else if (partId < VOLMAXPARTS) {
189 strcpy(partName, "/vicep");
191 partName[6] = 'a' + (partId / 26);
192 partName[7] = 'a' + (partId % 26);
204 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
205 response = c = getchar();
206 while (!(c == EOF || c == '\n'))
207 c = getchar(); /*skip to end of line */
208 code = (response == 'y' || response == 'Y');
214 PrintError(char *msg, afs_int32 errcode)
216 fprintf(STDERR, msg);
217 /*replace by a big switch statement */
222 fprintf(STDERR, "Possible communication failure\n");
225 fprintf(STDERR, "Volume needs to be salvaged\n");
228 fprintf(STDERR, "Bad vnode number quoted\n");
232 "Volume not attached, does not exist, or not on line\n");
235 fprintf(STDERR, "Volume already exists\n");
238 fprintf(STDERR, "Volume is not in service\n");
241 fprintf(STDERR, "Volume is off line\n");
244 fprintf(STDERR, "Volume is already on line\n");
247 fprintf(STDERR, "Partition is full\n");
250 fprintf(STDERR, "Volume max quota exceeded\n");
253 fprintf(STDERR, "Volume temporarily unavailable\n");
256 fprintf(STDERR, "Volume has moved to another server\n");
259 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
262 fprintf(STDERR, "VLDB: a read terminated too early\n");
265 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
268 fprintf(STDERR, "VLDB: internal creation failure\n");
271 fprintf(STDERR, "VLDB: no such entry\n");
274 fprintf(STDERR, "VLDB: vldb database is empty\n");
277 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
280 fprintf(STDERR, "VLDB: volume name is illegal\n");
283 fprintf(STDERR, "VLDB: index was out of range\n");
286 fprintf(STDERR, "VLDB: bad volume type\n");
289 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
291 case VL_BADPARTITION:
292 fprintf(STDERR, "VLDB: bad partition number\n");
295 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
298 fprintf(STDERR, "VLDB: no such repsite server exists\n");
300 case VL_DUPREPSERVER:
301 fprintf(STDERR, "VLDB: replication site server already exists\n");
304 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
307 fprintf(STDERR, "VLDB: illegal reference count number\n");
309 case VL_SIZEEXCEEDED:
310 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
313 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
315 case VL_BADVOLIDBUMP:
316 fprintf(STDERR, "VLDB: illegal max volid increment\n");
318 case VL_IDALREADYHASHED:
319 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
322 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
325 fprintf(STDERR, "VLDB: bad volume operation code\n");
327 case VL_BADRELLOCKTYPE:
328 fprintf(STDERR, "VLDB: bad release lock type\n");
331 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
333 case VL_BADSERVERFLAG:
334 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
337 fprintf(STDERR, "VLDB: no permission access for call\n");
339 case VOLSERREAD_DUMPERROR:
341 "VOLSER: Problems encountered in reading the dump file !\n");
343 case VOLSERDUMPERROR:
344 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
346 case VOLSERATTACH_ERROR:
347 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
349 case VOLSERDETACH_ERROR:
350 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
352 case VOLSERILLEGAL_PARTITION:
353 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
355 case VOLSERBAD_ACCESS:
356 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
358 case VOLSERVLDB_ERROR:
359 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
362 fprintf(STDERR, "VOLSER: error in volume name\n");
365 fprintf(STDERR, "VOLSER: volume has moved\n");
368 fprintf(STDERR, "VOLSER: illegal operation\n");
370 case VOLSERBADRELEASE:
371 fprintf(STDERR, "VOLSER: release could not be completed\n");
374 fprintf(STDERR, "VOLSER: volume is busy\n");
376 case VOLSERNO_MEMORY:
377 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
381 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
383 case VOLSERMULTIRWVOL:
385 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
389 "VOLSER: not all entries were successfully processed\n");
396 initialize_KA_error_table();
397 initialize_RXK_error_table();
398 initialize_KTC_error_table();
399 initialize_ACFG_error_table();
400 initialize_CMD_error_table();
401 initialize_VL_error_table();
403 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
404 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
405 afs_error_message(errcode));
412 void init_volintInfo(struct volintInfo *vinfo) {
413 memset(vinfo, 0, sizeof(struct volintInfo));
415 vinfo->maxquota = -1;
417 vinfo->creationDate = -1;
418 vinfo->updateDate = -1;
426 static struct rx_securityClass *uvclass = 0;
427 static int uvindex = -1;
428 /* called by VLDBClient_Init to set the security module to be used in the RPC */
430 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
437 /* bind to volser on <port> <aserver> */
438 /* takes server address in network order, port in host order. dumb */
439 struct rx_connection *
440 UV_Bind(afs_int32 aserver, afs_int32 port)
442 register struct rx_connection *tc;
444 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
449 /* if <okvol> is allright(indicated by beibg able to
450 * start a transaction, delete the <delvol> */
452 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
453 afs_int32 okvol, afs_int32 delvol)
455 afs_int32 error, code, tid, rcode;
461 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
464 code = AFSVolDeleteVolume(aconn, tid);
467 code = AFSVolEndTrans(aconn, tid, &rcode);
474 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
476 code = AFSVolEndTrans(aconn, tid, &rcode);
481 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
484 code = AFSVolDeleteVolume(aconn, tid);
487 code = AFSVolEndTrans(aconn, tid, &rcode);
498 /* called by EmuerateEntry, show vldb entry in a reasonable format */
500 SubEnumerateEntry(struct nvldbentry *entry)
507 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
508 if (entry->flags & RW_EXISTS)
509 fprintf(STDOUT, " valid \n");
511 fprintf(STDOUT, " invalid \n");
512 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
513 if (entry->flags & RO_EXISTS)
514 fprintf(STDOUT, " valid \n");
516 fprintf(STDOUT, " invalid \n");
517 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
518 if (entry->flags & BACK_EXISTS)
519 fprintf(STDOUT, " valid \n");
521 fprintf(STDOUT, " invalid \n");
522 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
523 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
525 if (entry->flags & RW_EXISTS)
526 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
527 if (entry->flags & RO_EXISTS)
528 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
529 if (entry->flags & BACK_EXISTS)
530 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
531 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
532 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
533 fprintf(STDOUT, "\n");
535 fprintf(STDOUT, " number of sites -> %lu\n",
536 (unsigned long)entry->nServers);
537 for (i = 0; i < entry->nServers; i++) {
538 if (entry->serverFlags[i] & NEW_REPSITE)
541 for (i = 0; i < entry->nServers; i++) {
542 MapPartIdIntoName(entry->serverPartition[i], pname);
543 fprintf(STDOUT, " server %s partition %s ",
544 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
545 if (entry->serverFlags[i] & ITSRWVOL)
546 fprintf(STDOUT, "RW Site ");
548 fprintf(STDOUT, "RO Site ");
550 if (entry->serverFlags[i] & NEW_REPSITE)
551 fprintf(STDOUT," -- New release");
553 if (!(entry->serverFlags[i] & ITSRWVOL))
554 fprintf(STDOUT," -- Old release");
556 if (entry->serverFlags[i] & RO_DONTUSE)
557 fprintf(STDOUT, " -- Not released");
559 fprintf(STDOUT, "\n");
566 /*enumerate the vldb entry corresponding to <entry> */
568 EnumerateEntry(struct nvldbentry *entry)
571 fprintf(STDOUT, "\n");
572 fprintf(STDOUT, "%s \n", entry->name);
573 SubEnumerateEntry(entry);
577 /* forcibly remove a volume. Very dangerous call */
579 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
581 register struct rx_connection *tconn;
582 register afs_int32 code;
584 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
586 code = AFSVolNukeVolume(tconn, partid, volid);
587 rx_DestroyConnection(tconn);
593 /* like df. Return usage of <pname> on <server> in <partition> */
595 UV_PartitionInfo64(afs_int32 server, char *pname,
596 struct diskPartition64 *partition)
598 register struct rx_connection *aconn;
601 aconn = (struct rx_connection *)0;
602 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
603 code = AFSVolPartitionInfo64(aconn, pname, partition);
604 if (code == RXGEN_OPCODE) {
605 struct diskPartition *dpp =
606 (struct diskPartition *)malloc(sizeof(struct diskPartition));
607 code = AFSVolPartitionInfo(aconn, pname, dpp);
609 strncpy(partition->name, dpp->name, 32);
610 strncpy(partition->devName, dpp->devName, 32);
611 partition->lock_fd = dpp->lock_fd;
612 partition->free = dpp->free;
613 partition->minFree = dpp->minFree;
618 fprintf(STDERR, "Could not get information on partition %s\n", pname);
619 PrintError("", code);
622 rx_DestroyConnection(aconn);
626 /* old interface to create volume */
628 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
632 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
636 /* create a volume, given a server, partition number, volume name --> sends
637 * back new vol id in <anewid>*/
639 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
640 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
641 afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
644 register struct rx_connection *aconn;
646 register afs_int32 code;
648 afs_int32 rcode, vcode;
649 struct nvldbentry entry, storeEntry; /*the new vldb entry */
650 struct volintInfo tstatus;
653 aconn = (struct rx_connection *)0;
656 init_volintInfo(&tstatus);
657 tstatus.maxquota = aquota;
659 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
660 /* next the next 3 available ids from the VLDB */
661 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 3, anewid);
662 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
665 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
666 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
669 code = AFSVolSetInfo(aconn, tid, &tstatus);
671 EPRINT(code, "Could not change quota, continuing...\n");
673 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
674 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
677 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
679 /* set up the vldb entry for this volume */
680 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
682 entry.serverNumber[0] = aserver; /* this should have another
683 * level of indirection later */
684 entry.serverPartition[0] = apart; /* this should also have
685 * another indirection level */
686 entry.flags = RW_EXISTS; /* this records that rw volume exists */
687 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
688 entry.volumeId[RWVOL] = *anewid;
689 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
690 entry.volumeId[BACKVOL] = *anewid + 2;
692 /*map into right byte order, before passing to xdr, the stuff has to be in host
693 * byte order. Xdr converts it into network order */
694 MapNetworkToHost(&entry, &storeEntry);
695 /* create the vldb entry */
696 vcode = VLDB_CreateEntry(&storeEntry);
699 "Could not create a VLDB entry for the volume %s %lu\n",
700 aname, (unsigned long)*anewid);
701 /*destroy the created volume */
702 VPRINT1("Deleting the newly created volume %u\n", *anewid);
703 AFSVolDeleteVolume(aconn, tid);
707 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
708 /* volume created, now terminate the transaction and release the connection */
709 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
710 * the volume will come online anyway when transaction timesout , so if
711 * vldb entry exists then the volume is guaranteed to exist too wrt create */
715 "Failed to end the transaction on the volume %s %lu\n", aname,
716 (unsigned long)*anewid);
723 code = AFSVolEndTrans(aconn, tid, &rcode);
725 fprintf(STDERR, "WARNING: could not end transaction\n");
728 rx_DestroyConnection(aconn);
729 PrintError("", error);
735 /* create a volume, given a server, partition number, volume name --> sends
736 * back new vol id in <anewid>*/
738 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
741 register struct rx_connection *aconn;
744 struct nvldbentry entry, storeEntry; /*the new vldb entry */
746 aconn = (struct rx_connection *)0;
749 /* set up the vldb entry for this volume */
750 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
752 entry.serverNumber[0] = aserver; /* this should have another
753 * level of indirection later */
754 entry.serverPartition[0] = apart; /* this should also have
755 * another indirection level */
756 entry.flags = RW_EXISTS; /* this records that rw volume exists */
757 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
758 entry.volumeId[RWVOL] = aid;
760 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
761 entry.volumeId[BACKVOL] = *anewid + 2;
763 entry.volumeId[ROVOL] = 0;
764 entry.volumeId[BACKVOL] = 0;
767 /*map into right byte order, before passing to xdr, the stuff has to be in host
768 * byte order. Xdr converts it into network order */
769 MapNetworkToHost(&entry, &storeEntry);
770 /* create the vldb entry */
771 vcode = VLDB_CreateEntry(&storeEntry);
774 "Could not create a VLDB entry for the volume %s %lu\n",
775 aname, (unsigned long)aid);
779 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
783 rx_DestroyConnection(aconn);
784 PrintError("", error);
788 /* Delete the volume <volid>on <aserver> <apart>
789 * the physical entry gets removed from the vldb only if the ref count
793 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
795 struct rx_connection *aconn = (struct rx_connection *)0;
797 afs_int32 code, rcode;
799 struct nvldbentry entry, storeEntry;
801 afs_int32 avoltype = -1, vtype;
802 int notondisk = 0, notinvldb = 0;
804 /* Find and read bhe VLDB entry for this volume */
805 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
807 if (code != VL_NOENT) {
808 EGOTO1(error_exit, code,
809 "Could not lock VLDB entry for the volume %u\n", avolid);
815 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
816 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
818 MapHostToNetwork(&entry);
821 EnumerateEntry(&entry);
824 /* Whether volume is in the VLDB or not. Delete the volume on disk */
825 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
826 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
828 if (code == VNOVOL) {
831 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
835 VPRINT1("Trying to delete the volume %u ...", avolid);
837 code = AFSVolDeleteVolume(aconn, ttid);
838 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
840 code = AFSVolEndTrans(aconn, ttid, &rcode);
841 code = (code ? code : rcode);
843 EGOTO1(error_exit, code,
844 "Could not end the transaction for the volume %u \n", avolid);
848 /* Now update the VLDB entry.
849 * But first, verify we have a VLDB entry.
850 * Whether volume is on disk or not. Delete the volume in VLDB.
855 if (avolid == entry.volumeId[BACKVOL]) {
856 /* Its a backup volume, modify the VLDB entry. Check that the
857 * backup volume is on the server/partition we asked to delete.
859 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
860 notinvldb = 2; /* Not on this server and partition */
864 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
866 entry.flags &= ~BACK_EXISTS;
870 else if (avolid == entry.volumeId[ROVOL]) {
871 /* Its a read-only volume, modify the VLDB entry. Check that the
872 * readonly volume is on the server/partition we asked to delete.
873 * If flags does not have RO_EIXSTS set, then this may mean the RO
874 * hasn't been released (and could exist in VLDB).
876 if (!Lp_ROMatch(aserver, apart, &entry)) {
877 notinvldb = 2; /* Not found on this server and partition */
883 "Marking the readonly volume %lu deleted in the VLDB\n",
884 (unsigned long)avolid);
886 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
888 if (!Lp_ROMatch(0, 0, &entry))
889 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
893 else if (avolid == entry.volumeId[RWVOL]) {
894 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
895 * Check that the readwrite volumes is on the server/partition we
898 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
899 notinvldb = 2; /* Not found on this server and partition */
903 /* Delete backup if it exists */
905 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
909 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
910 entry.volumeId[BACKVOL]);
913 code = AFSVolDeleteVolume(aconn, ttid);
914 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
915 entry.volumeId[BACKVOL]);
917 code = AFSVolEndTrans(aconn, ttid, &rcode);
919 code = (code ? code : rcode);
920 EGOTO1(error_exit, code,
921 "Could not end the transaction for the volume %u \n",
922 entry.volumeId[BACKVOL]);
924 fprintf(STDOUT, " done\n");
929 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
930 (unsigned long)avolid,
932 flags & BACK_EXISTS) ? ", and its backup volume," :
935 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
937 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
940 if (entry.flags & RO_EXISTS)
941 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
945 notinvldb = 2; /* Not found on this server and partition */
949 /* Either delete or replace the VLDB entry */
950 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
953 "Last reference to the VLDB entry for %lu - deleting entry\n",
954 (unsigned long)avolid);
955 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
956 EGOTO1(error_exit, code,
957 "Could not delete the VLDB entry for the volume %u \n",
960 MapNetworkToHost(&entry, &storeEntry);
962 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
963 (LOCKREL_OPCODE | LOCKREL_AFSID |
965 EGOTO1(error_exit, code,
966 "Could not update the VLDB entry for the volume %u \n",
975 if (notondisk && notinvldb) {
976 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
977 ((notinvldb == 2) ? "on server and partition" : ""));
980 } else if (notondisk) {
982 "WARNING: Volume %lu did not exist on the partition\n",
983 (unsigned long)avolid);
984 } else if (notinvldb) {
985 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
986 (unsigned long)avolid,
987 ((notinvldb == 2) ? "on server and partition" : ""));
991 code = AFSVolEndTrans(aconn, ttid, &rcode);
992 code = (code ? code : rcode);
994 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
995 (unsigned long)avolid);
996 PrintError("", code);
1004 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1005 (LOCKREL_OPCODE | LOCKREL_AFSID |
1006 LOCKREL_TIMESTAMP));
1009 "Could not release the lock on the VLDB entry for the volume %u \n",
1017 rx_DestroyConnection(aconn);
1021 /* add recovery to UV_MoveVolume */
1023 #define TESTC 0 /* set to test recovery code, clear for production */
1029 sigint_handler(int x)
1034 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1036 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1037 fprintf(STDOUT, "enter second control-c to exit\n");
1041 (void)signal(SIGINT, sigint_handler);
1046 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1047 * <atopart>. The operation is almost idempotent. The following
1048 * flags are recognized:
1050 * RV_NOCLONE - don't use a copy clone
1054 UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1055 afs_int32 atoserver, afs_int32 atopart, int flags)
1057 struct rx_connection *toconn, *fromconn;
1058 afs_int32 fromtid, totid, clonetid;
1061 char tmpName[VOLSER_MAXVOLNAME + 1];
1064 struct restoreCookie cookie;
1065 register afs_int32 vcode, code;
1066 afs_int32 newVol, volid, backupId;
1067 struct volser_status tstatus;
1068 struct destServer destination;
1070 struct nvldbentry entry, storeEntry;
1071 int i, islocked, pntg;
1073 char in, lf; /* for test code */
1076 #ifdef ENABLE_BUGFIX_1165
1077 volEntries volumeInfo;
1078 struct volintInfo *infop = 0;
1082 fromconn = (struct rx_connection *)0;
1083 toconn = (struct rx_connection *)0;
1093 /* support control-c processing */
1096 (void)signal(SIGINT, sigint_handler);
1100 "\nThere are three tests points - verifies all code paths through recovery.\n");
1101 fprintf(STDOUT, "First test point - operation not started.\n");
1102 fprintf(STDOUT, "...test here (y, n)? ");
1104 fscanf(stdin, "%c", &in);
1105 fscanf(stdin, "%c", &lf); /* toss away */
1107 fprintf(STDOUT, "type control-c\n");
1109 fprintf(stdout, ".");
1114 /* or drop through */
1117 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1118 EGOTO1(mfail, vcode,
1119 "Could not fetch the entry for the volume %u from the VLDB \n",
1122 if (entry.volumeId[RWVOL] != afromvol) {
1123 fprintf(STDERR, "Only RW volume can be moved\n");
1127 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1128 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1131 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1132 EGOTO1(mfail, vcode,
1133 "Could not fetch the entry for the volume %u from the VLDB \n",
1136 backupId = entry.volumeId[BACKVOL];
1137 MapHostToNetwork(&entry);
1139 if (!Lp_Match(afromserver, afrompart, &entry)) {
1140 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1141 if (!Lp_Match(atoserver, atopart, &entry)) {
1142 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1143 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1144 (unsigned long)afromvol);
1145 fprintf(STDERR, "The current site is :");
1146 for (i = 0; i < entry.nServers; i++) {
1147 if (entry.serverFlags[i] == ITSRWVOL) {
1149 MapPartIdIntoName(entry.serverPartition[i], pname);
1150 fprintf(STDERR, " server %s partition %s \n",
1151 hostutil_GetNameByINet(entry.serverNumber[i]),
1156 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1157 (LOCKREL_OPCODE | LOCKREL_AFSID |
1158 LOCKREL_TIMESTAMP));
1159 EGOTO1(mfail, vcode,
1160 " Could not release lock on the VLDB entry for the volume %u \n",
1163 return VOLSERVOLMOVED;
1166 /* delete the volume afromvol on src_server */
1167 /* from-info does not exist but to-info does =>
1168 * we have already done the move, but the volume
1169 * may still be existing physically on from fileserver
1171 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1176 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1178 if (!code) { /* volume exists - delete it */
1179 VPRINT1("Setting flags on leftover source volume %u ...",
1182 AFSVolSetFlags(fromconn, fromtid,
1183 VTDeleteOnSalvage | VTOutOfService);
1185 "Failed to set flags on the leftover source volume %u\n",
1189 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1190 code = AFSVolDeleteVolume(fromconn, fromtid);
1192 "Failed to delete the leftover source volume %u\n",
1196 VPRINT1("Ending transaction on leftover source volume %u ...",
1198 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1203 "Could not end the transaction for the leftover source volume %u \n",
1208 /*delete the backup volume now */
1211 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1213 if (!code) { /* backup volume exists - delete it */
1214 VPRINT1("Setting flags on leftover backup volume %u ...",
1217 AFSVolSetFlags(fromconn, fromtid,
1218 VTDeleteOnSalvage | VTOutOfService);
1220 "Failed to set flags on the backup volume %u\n", backupId);
1223 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1224 code = AFSVolDeleteVolume(fromconn, fromtid);
1226 "Could not delete the leftover backup volume %u\n",
1230 VPRINT1("Ending transaction on leftover backup volume %u ...",
1232 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1237 "Could not end the transaction for the leftover backup volume %u\n",
1247 /* From-info matches the vldb info about volid,
1248 * its ok start the move operation, the backup volume
1249 * on the old site is deleted in the process
1251 if (afrompart == atopart) {
1252 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1253 EGOTO2(mfail, error,
1254 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1255 afromserver, error);
1258 EGOTO1(mfail, VOLSERVOLMOVED,
1259 "Warning: Moving volume %u to its home partition ignored!\n",
1265 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1266 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1267 fromtid = totid = 0; /* initialize to uncreated */
1270 * clone the read/write volume locally.
1273 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1274 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1275 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1279 if (!(flags & RV_NOCLONE)) {
1280 /* Get a clone id */
1281 VPRINT1("Allocating new volume id for clone of volume %u ...",
1284 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1285 EGOTO1(mfail, vcode,
1286 "Could not get an ID for the clone of volume %u from the VLDB\n",
1290 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1291 VPRINT1("Cloning source volume %u ...", afromvol);
1292 strcpy(vname, "move-clone-temp");
1294 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1295 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1300 /* lookup the name of the volume we just cloned */
1302 code = AFSVolGetName(fromconn, fromtid, &volName);
1303 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1306 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1308 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1313 "Failed to end the transaction on the source volume %u\n",
1318 * Create the destination volume
1321 if (!(flags & RV_NOCLONE)) {
1322 /* All of this is to get the fromDate */
1323 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1325 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1328 "Failed to start a transaction on the cloned volume%u\n",
1332 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1334 AFSVolSetFlags(fromconn, clonetid,
1335 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1336 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1340 /* remember time from which we've dumped the volume */
1341 VPRINT1("Getting status of cloned volume %u ...", newVol);
1342 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1344 "Failed to get the status of the cloned volume %u\n",
1348 fromDate = CLOCKADJ(tstatus.creationDate);
1350 /* With RV_NOCLONE, just do a full copy from the source */
1355 #ifdef ENABLE_BUGFIX_1165
1357 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1358 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1359 * don't use this information...
1361 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1362 volumeInfo.volEntries_len = 0;
1363 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1365 "Failed to get the volint Info of the cloned volume %u\n",
1368 infop = (volintInfo *) volumeInfo.volEntries_val;
1369 infop->maxquota = -1; /* Else it will replace the default quota */
1370 infop->creationDate = -1; /* Else it will use the source creation date */
1371 infop->updateDate = -1; /* Else it will use the source update date */
1374 /* create a volume on the target machine */
1376 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1378 /* Delete the existing volume.
1379 * While we are deleting the volume in these steps, the transaction
1380 * we started against the cloned volume (clonetid above) will be
1381 * sitting idle. It will get cleaned up after 600 seconds
1383 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1384 code = AFSVolDeleteVolume(toconn, totid);
1386 "Could not delete the pre-existing volume %u on destination\n",
1391 ("Ending transaction on pre-existing volume %u on destination ...",
1393 code = AFSVolEndTrans(toconn, totid, &rcode);
1398 "Could not end the transaction on pre-existing volume %u on destination\n",
1403 VPRINT1("Creating the destination volume %u ...", volid);
1405 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1407 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1411 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1415 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1417 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1419 "Failed to set the flags on the destination volume %u\n", volid);
1423 * Now dump the clone to the new volume
1426 destination.destHost = ntohl(atoserver);
1427 destination.destPort = AFSCONF_VOLUMEPORT;
1428 destination.destSSID = 1;
1430 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1431 cookie.type = RWVOL;
1432 cookie.parent = entry.volumeId[RWVOL];
1435 if (!(flags & RV_NOCLONE)) {
1436 /* Copy the clone to the new volume */
1437 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1440 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1442 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1445 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1446 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1451 "Failed to end the transaction on the cloned volume %u\n",
1457 * reattach to the main-line volume, and incrementally dump it.
1460 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1461 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1463 "Failed to create a transaction on the source volume %u\n",
1467 /* now do the incremental */
1469 ("Doing the%s dump from source to destination for volume %u ... ",
1470 (flags & RV_NOCLONE) ? "" : " incremental",
1473 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1476 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1477 (flags & RV_NOCLONE) ? "" : " incremental");
1480 /* now adjust the flags so that the new volume becomes official */
1481 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1482 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1484 "Failed to set the flags to make old source volume offline\n");
1487 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1488 code = AFSVolSetFlags(toconn, totid, 0);
1490 "Failed to set the flags to make new source volume online\n");
1493 #ifdef ENABLE_BUGFIX_1165
1494 VPRINT1("Setting volume status on destination volume %u ...", volid);
1495 code = AFSVolSetInfo(toconn, totid, infop);
1497 "Failed to set volume status on the destination volume %u\n",
1502 /* put new volume online */
1503 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1504 code = AFSVolEndTrans(toconn, totid, &rcode);
1509 "Failed to end the transaction on the volume %u on the new site\n",
1513 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1514 MapNetworkToHost(&entry, &storeEntry);
1515 storeEntry.flags &= ~BACK_EXISTS;
1519 "Second test point - operation in progress but not complete.\n");
1520 fprintf(STDOUT, "...test here (y, n)? ");
1522 fscanf(stdin, "%c", &in);
1523 fscanf(stdin, "%c", &lf); /* toss away */
1525 fprintf(STDOUT, "type control-c\n");
1527 fprintf(stdout, ".");
1532 /* or drop through */
1535 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1537 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1538 (LOCKREL_OPCODE | LOCKREL_AFSID |
1539 LOCKREL_TIMESTAMP));
1542 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1543 storeEntry.name, (unsigned long)afromvol);
1552 "Third test point - operation complete but no cleanup.\n");
1553 fprintf(STDOUT, "...test here (y, n)? ");
1555 fscanf(stdin, "%c", &in);
1556 fscanf(stdin, "%c", &lf); /* toss away */
1558 fprintf(STDOUT, "type control-c\n");
1560 fprintf(stdout, ".");
1565 /* or drop through */
1568 /* This is tricky. File server is very stupid, and if you mark the volume
1569 * as VTOutOfService, it may mark the *good* instance (if you're moving
1570 * between partitions on the same machine) as out of service. Since
1571 * we're cleaning this code up in DEcorum, we're just going to kludge around
1572 * it for now by removing this call. */
1573 /* already out of service, just zap it now */
1575 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1578 "Failed to set the flags to make the old source volume offline\n");
1582 if (atoserver != afromserver) {
1583 /* set forwarding pointer for moved volumes */
1584 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1585 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1587 "Failed to set the forwarding pointer for the volume %u\n",
1592 VPRINT1("Deleting old volume %u on source ...", afromvol);
1593 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1594 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1598 VPRINT1("Ending transaction on old volume %u on the source ...",
1600 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1605 "Failed to end the transaction on the old volume %u on the source\n",
1609 /* Delete the backup volume on the original site */
1610 VPRINT1("Creating transaction for backup volume %u on source ...",
1613 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1616 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1618 AFSVolSetFlags(fromconn, fromtid,
1619 VTDeleteOnSalvage | VTOutOfService);
1621 "Failed to set the flags on the backup volume %u on the source\n",
1625 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1626 code = AFSVolDeleteVolume(fromconn, fromtid);
1628 "Failed to delete the backup volume %u on the source\n",
1632 VPRINT1("Ending transaction on backup volume %u on source ...",
1634 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1639 "Failed to end the transaction on the backup volume %u on the source\n",
1643 code = 0; /* no backup volume? that's okay */
1646 if (!(flags & RV_NOCLONE)) {
1647 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1649 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1652 "Failed to start a transaction on the cloned volume%u\n",
1656 /* now delete the clone */
1657 VPRINT1("Deleting the cloned volume %u ...", newVol);
1658 code = AFSVolDeleteVolume(fromconn, clonetid);
1659 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1663 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1664 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1669 "Failed to end the transaction on the cloned volume %u\n",
1678 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1679 fprintf(STDOUT, "...test here (y, n)? ");
1681 fscanf(stdin, "%c", &in);
1682 fscanf(stdin, "%c", &lf); /* toss away */
1684 fprintf(STDOUT, "type control-c\n");
1686 fprintf(stdout, ".");
1691 /* or drop through */
1694 /* normal cleanup code */
1696 if (entry.flags & RO_EXISTS)
1697 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1700 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1702 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1703 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1707 " Could not release the lock on the VLDB entry for the volume %lu \n",
1708 (unsigned long)afromvol);
1716 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1718 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1719 if (code || rcode) {
1722 "Could not end transaction on the source volume %lu\n",
1723 (unsigned long)afromvol);
1725 error = (code ? code : rcode);
1731 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1732 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1733 if (code || rcode) {
1736 "Could not end transaction on the source's clone volume %lu\n",
1737 (unsigned long)newVol);
1739 error = (code ? code : rcode);
1745 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1747 code = AFSVolEndTrans(toconn, totid, &rcode);
1751 "Could not end transaction on destination volume %lu\n",
1752 (unsigned long)afromvol);
1754 error = (code ? code : rcode);
1760 #ifdef ENABLE_BUGFIX_1165
1765 rx_DestroyConnection(fromconn);
1767 rx_DestroyConnection(toconn);
1768 PrintError("", error);
1771 /* come here only when the sky falls */
1776 "vos move: operation interrupted, cleanup in progress...\n");
1777 fprintf(STDOUT, "clear transaction contexts\n");
1781 /* unlock VLDB entry */
1783 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1784 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1785 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1790 VPRINT("Recovery: Ending transaction on clone volume ...");
1791 AFSVolEndTrans(fromconn, clonetid, &rcode);
1795 VPRINT("Recovery: Ending transaction on destination volume ...");
1796 AFSVolEndTrans(toconn, totid, &rcode);
1799 if (fromtid) { /* put it on-line */
1800 VPRINT("Recovery: Setting volume flags on source volume ...");
1801 AFSVolSetFlags(fromconn, fromtid, 0);
1804 VPRINT("Recovery: Ending transaction on source volume ...");
1805 AFSVolEndTrans(fromconn, fromtid, &rcode);
1809 VPRINT("Recovery: Accessing VLDB.\n");
1810 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1812 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1816 MapHostToNetwork(&entry);
1818 /* Delete either the volume on the source location or the target location.
1819 * If the vldb entry still points to the source location, then we know the
1820 * volume move didn't finish so we remove the volume from the target
1821 * location. Otherwise, we remove the volume from the source location.
1823 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1826 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1830 if (volid && toconn) {
1832 ("Recovery: Creating transaction for destination volume %u ...",
1835 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1841 ("Recovery: Setting flags on destination volume %u ...",
1843 AFSVolSetFlags(toconn, totid,
1844 VTDeleteOnSalvage | VTOutOfService);
1847 VPRINT1("Recovery: Deleting destination volume %u ...",
1849 AFSVolDeleteVolume(toconn, totid);
1853 ("Recovery: Ending transaction on destination volume %u ...",
1855 AFSVolEndTrans(toconn, totid, &rcode);
1859 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1864 /* put source volume on-line */
1866 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1869 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1874 VPRINT1("Recovery: Setting flags on source volume %u ...",
1876 AFSVolSetFlags(fromconn, fromtid, 0);
1880 ("Recovery: Ending transaction on source volume %u ...",
1882 AFSVolEndTrans(fromconn, fromtid, &rcode);
1886 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1890 } else { /* yep, move complete */
1893 "move complete - attempt cleanup of source partition - no guarantee\n");
1897 /* delete backup volume */
1899 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1902 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1907 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1909 AFSVolSetFlags(fromconn, fromtid,
1910 VTDeleteOnSalvage | VTOutOfService);
1913 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1914 AFSVolDeleteVolume(fromconn, fromtid);
1918 ("Recovery: Ending transaction on backup volume %u ...",
1920 AFSVolEndTrans(fromconn, fromtid, &rcode);
1924 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1928 /* delete source volume */
1929 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1932 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1937 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1939 AFSVolSetFlags(fromconn, fromtid,
1940 VTDeleteOnSalvage | VTOutOfService);
1943 if (atoserver != afromserver) {
1944 VPRINT("Recovery: Setting volume forwarding pointer ...");
1945 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1949 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1950 AFSVolDeleteVolume(fromconn, fromtid);
1954 ("Recovery: Ending transaction on source volume %u ...",
1956 AFSVolEndTrans(fromconn, fromtid, &rcode);
1960 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1966 /* common cleanup - delete local clone */
1968 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1971 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1976 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1977 AFSVolDeleteVolume(fromconn, clonetid);
1980 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1982 AFSVolEndTrans(fromconn, clonetid, &rcode);
1986 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1991 /* unlock VLDB entry */
1992 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
1994 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1995 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1998 done: /* routine cleanup */
2001 #ifdef ENABLE_BUGFIX_1165
2006 rx_DestroyConnection(fromconn);
2008 rx_DestroyConnection(toconn);
2011 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2019 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2020 afs_int32 atoserver, afs_int32 atopart)
2022 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2023 atoserver, atopart, 0);
2027 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2028 * <atopart>. The new volume is named by <atovolname>. The new volume
2029 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2030 * from the VLDB. the following flags are supported:
2032 * RV_RDONLY - target volume is RO
2033 * RV_OFFLINE - leave target volume offline
2034 * RV_CPINCR - do incremental dump if target exists
2035 * RV_NOVLDB - don't create/update VLDB entry
2036 * RV_NOCLONE - don't use a copy clone
2039 UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2040 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2041 afs_int32 atovolid, int flags)
2043 struct rx_connection *toconn, *fromconn;
2044 afs_int32 fromtid, totid, clonetid;
2047 afs_int32 fromDate, cloneFromDate;
2048 struct restoreCookie cookie;
2049 register afs_int32 vcode, code;
2050 afs_int32 cloneVol, newVol, volflag;
2051 struct volser_status tstatus;
2052 struct destServer destination;
2054 struct nvldbentry entry, newentry, storeEntry;
2060 fromconn = (struct rx_connection *)0;
2061 toconn = (struct rx_connection *)0;
2069 /* support control-c processing */
2072 (void)signal(SIGINT, sigint_handler);
2074 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2075 EGOTO1(mfail, vcode,
2076 "Could not fetch the entry for the volume %u from the VLDB \n",
2078 MapHostToNetwork(&entry);
2081 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2082 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2083 fromtid = totid = 0; /* initialize to uncreated */
2086 /* check if we can shortcut and use a local clone instead of a full copy */
2087 if (afromserver == atoserver && afrompart == atopart) {
2092 * clone the read/write volume locally.
2096 if (!(flags & RV_NOCLONE)) {
2097 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2098 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2100 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2104 /* Get a clone id */
2105 VPRINT1("Allocating new volume id for clone of volume %u ...",
2108 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2109 EGOTO1(mfail, vcode,
2110 "Could not get an ID for the clone of volume %u from the VLDB\n",
2118 /* Get a new volume id */
2119 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2121 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2122 EGOTO1(mfail, vcode,
2123 "Could not get an ID for the copy of volume %u from the VLDB\n",
2128 if (!(flags & RV_NOCLONE)) {
2129 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2130 VPRINT1("Cloning source volume %u ...", afromvol);
2131 strcpy(vname, "copy-clone-temp");
2133 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2135 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2139 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2141 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2146 "Failed to end the transaction on the source volume %u\n",
2152 * Create the destination volume
2155 if (!(flags & RV_NOCLONE)) {
2156 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2158 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2161 "Failed to start a transaction on the cloned volume%u\n",
2165 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2167 AFSVolSetFlags(fromconn, clonetid,
2168 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2169 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2173 /* remember time from which we've dumped the volume */
2174 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2175 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2177 "Failed to get the status of the cloned volume %u\n",
2181 fromDate = CLOCKADJ(tstatus.creationDate);
2186 /* create a volume on the target machine */
2188 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2190 if ((flags & RV_CPINCR)) {
2191 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2192 code = AFSVolGetStatus(toconn, totid, &tstatus);
2194 "Failed to get the status of the pre-existing volume %u\n",
2198 /* Using the update date should be OK here, but add some fudge */
2199 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2200 if ((flags & RV_NOCLONE))
2201 fromDate = cloneFromDate;
2203 /* XXX We should check that the source volume's creationDate is
2204 * XXX not newer than the existing target volume, and if not,
2205 * XXX throw away the existing target and do a full dump. */
2210 /* Delete the existing volume.
2211 * While we are deleting the volume in these steps, the transaction
2212 * we started against the cloned volume (clonetid above) will be
2213 * sitting idle. It will get cleaned up after 600 seconds
2215 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2216 code = AFSVolDeleteVolume(toconn, totid);
2218 "Could not delete the pre-existing volume %u on destination\n",
2223 ("Ending transaction on pre-existing volume %u on destination ...",
2225 code = AFSVolEndTrans(toconn, totid, &rcode);
2230 "Could not end the transaction on pre-existing volume %u on destination\n",
2235 VPRINT1("Creating the destination volume %u ...", newVol);
2237 AFSVolCreateVolume(toconn, atopart, atovolname,
2238 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2239 newVol, &newVol, &totid);
2240 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2244 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2246 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2248 "Failed to set the flags on the destination volume %u\n", newVol);
2253 destination.destHost = ntohl(atoserver);
2254 destination.destPort = AFSCONF_VOLUMEPORT;
2255 destination.destSSID = 1;
2257 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2258 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2263 * Now dump the clone to the new volume
2266 if (!(flags & RV_NOCLONE)) {
2267 /* XXX probably should have some code here that checks to see if
2268 * XXX we are copying to same server and partition - if so, just
2269 * XXX use a clone to save disk space */
2271 /* Copy the clone to the new volume */
2272 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2275 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2277 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2281 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2282 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2287 "Failed to end the transaction on the cloned volume %u\n",
2293 * reattach to the main-line volume, and incrementally dump it.
2296 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2297 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2299 "Failed to create a transaction on the source volume %u\n",
2303 /* now do the incremental */
2305 ("Doing the%s dump from source to destination for volume %u ... ",
2306 (flags & RV_NOCLONE) ? "" : " incremental",
2309 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2312 "Failed to do the%s dump from old site to new site\n",
2316 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2317 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2318 code = AFSVolSetFlags(toconn, totid, volflag);
2320 "Failed to set the flags to make destination volume online\n");
2323 /* put new volume online */
2324 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2325 code = AFSVolEndTrans(toconn, totid, &rcode);
2330 "Failed to end the transaction on the destination volume %u\n",
2334 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2335 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2340 "Failed to end the transaction on the source volume %u\n",
2346 if (!(flags & RV_NOCLONE)) {
2347 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2349 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2352 "Failed to start a transaction on the cloned volume%u\n",
2356 /* now delete the clone */
2357 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2358 code = AFSVolDeleteVolume(fromconn, clonetid);
2359 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2363 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2364 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2369 "Failed to end the transaction on the cloned volume %u\n",
2374 if (!(flags & RV_NOVLDB)) {
2375 /* create the vldb entry for the copied volume */
2376 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2377 newentry.nServers = 1;
2378 newentry.serverNumber[0] = atoserver;
2379 newentry.serverPartition[0] = atopart;
2380 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2381 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2382 newentry.volumeId[RWVOL] = newVol;
2383 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2384 newentry.volumeId[BACKVOL] = 0;
2385 newentry.cloneId = 0;
2386 /*map into right byte order, before passing to xdr, the stuff has to be in host
2387 * byte order. Xdr converts it into network order */
2388 MapNetworkToHost(&newentry, &storeEntry);
2389 /* create the vldb entry */
2390 vcode = VLDB_CreateEntry(&storeEntry);
2393 "Could not create a VLDB entry for the volume %s %lu\n",
2394 atovolname, (unsigned long)newVol);
2395 /*destroy the created volume */
2396 VPRINT1("Deleting the newly created volume %u\n", newVol);
2397 AFSVolDeleteVolume(toconn, totid);
2401 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2405 /* normal cleanup code */
2408 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2410 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2411 if (code || rcode) {
2414 "Could not end transaction on the source volume %lu\n",
2415 (unsigned long)afromvol);
2417 error = (code ? code : rcode);
2423 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2425 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2426 if (code || rcode) {
2429 "Could not end transaction on the source's clone volume %lu\n",
2430 (unsigned long)cloneVol);
2432 error = (code ? code : rcode);
2438 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2440 code = AFSVolEndTrans(toconn, totid, &rcode);
2444 "Could not end transaction on destination volume %lu\n",
2445 (unsigned long)newVol);
2447 error = (code ? code : rcode);
2452 rx_DestroyConnection(fromconn);
2454 rx_DestroyConnection(toconn);
2455 PrintError("", error);
2458 /* come here only when the sky falls */
2463 "vos copy: operation interrupted, cleanup in progress...\n");
2464 fprintf(STDOUT, "clear transaction contexts\n");
2469 VPRINT("Recovery: Ending transaction on clone volume ...");
2470 AFSVolEndTrans(fromconn, clonetid, &rcode);
2474 VPRINT("Recovery: Ending transaction on destination volume ...");
2475 AFSVolEndTrans(toconn, totid, &rcode);
2478 if (fromtid) { /* put it on-line */
2479 VPRINT("Recovery: Ending transaction on source volume ...");
2480 AFSVolEndTrans(fromconn, fromtid, &rcode);
2484 VPRINT("Recovery: Accessing VLDB.\n");
2485 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2487 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2491 MapHostToNetwork(&entry);
2493 /* common cleanup - delete local clone */
2495 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2498 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2503 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2504 AFSVolDeleteVolume(fromconn, clonetid);
2507 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2509 AFSVolEndTrans(fromconn, clonetid, &rcode);
2513 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2518 done: /* routine cleanup */
2520 rx_DestroyConnection(fromconn);
2522 rx_DestroyConnection(toconn);
2525 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2533 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2534 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2536 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2537 atovolname, atoserver, atopart, 0, 0);
2542 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2543 * if one already exists, update it
2547 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2549 struct rx_connection *aconn = (struct rx_connection *)0;
2550 afs_int32 ttid = 0, btid = 0;
2552 afs_int32 code = 0, rcode = 0;
2553 char vname[VOLSER_MAXVOLNAME + 1];
2554 struct nvldbentry entry, storeEntry;
2555 afs_int32 error = 0;
2556 int vldblocked = 0, vldbmod = 0, backexists = 1;
2558 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2560 /* the calls to VLDB will succeed only if avolid is a RW volume,
2561 * since we are following the RW hash chain for searching */
2562 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2565 "Could not fetch the entry for the volume %lu from the VLDB \n",
2566 (unsigned long)avolid);
2570 MapHostToNetwork(&entry);
2572 /* These operations require the VLDB be locked since it means the VLDB
2573 * will change or the vldb is already locked.
2575 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2576 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2577 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2579 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2582 "Could not lock the VLDB entry for the volume %lu\n",
2583 (unsigned long)avolid);
2589 /* Reread the vldb entry */
2590 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2593 "Could not fetch the entry for the volume %lu from the VLDB \n",
2594 (unsigned long)avolid);
2598 MapHostToNetwork(&entry);
2601 if (!ISNAMEVALID(entry.name)) {
2602 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2604 error = VOLSERBADNAME;
2608 backupID = entry.volumeId[BACKVOL];
2609 if (backupID == INVALID_BID) {
2610 /* Get a backup volume id from the VLDB and update the vldb
2613 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2616 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2617 (unsigned long)avolid);
2621 entry.volumeId[BACKVOL] = backupID;
2625 /* Test to see if the backup volume exists by trying to create
2626 * a transaction on the backup volume. We've assumed the backup exists.
2628 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2630 if (code != VNOVOL) {
2631 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2632 (unsigned long)backupID);
2636 backexists = 0; /* backup volume does not exist */
2639 code = AFSVolEndTrans(aconn, btid, &rcode);
2641 if (code || rcode) {
2643 "Could not end transaction on the previous backup volume %lu\n",
2644 (unsigned long)backupID);
2645 error = (code ? code : rcode);
2650 /* Now go ahead and try to clone the RW volume.
2651 * First start a transaction on the RW volume
2653 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2655 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2656 (unsigned long)avolid);
2661 /* Clone or reclone the volume, depending on whether the backup
2662 * volume exists or not
2665 VPRINT1("Re-cloning backup volume %u ...", backupID);
2667 code = AFSVolReClone(aconn, ttid, backupID);
2669 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2670 (unsigned long)backupID);
2675 VPRINT1("Creating a new backup clone %u ...", backupID);
2677 strcpy(vname, entry.name);
2678 strcat(vname, ".backup");
2680 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2682 fprintf(STDERR, "Failed to clone the volume %lu\n",
2683 (unsigned long)avolid);
2689 /* End the transaction on the RW volume */
2690 code = AFSVolEndTrans(aconn, ttid, &rcode);
2692 if (code || rcode) {
2694 "Failed to end the transaction on the rw volume %lu\n",
2695 (unsigned long)avolid);
2696 error = (code ? code : rcode);
2700 /* Mork vldb as backup exists */
2701 if (!(entry.flags & BACK_EXISTS)) {
2702 entry.flags |= BACK_EXISTS;
2706 /* Now go back to the backup volume and bring it on line */
2707 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2710 "Failed to start a transaction on the backup volume %lu\n",
2711 (unsigned long)backupID);
2716 code = AFSVolSetFlags(aconn, btid, 0);
2718 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2719 (unsigned long)backupID);
2724 code = AFSVolEndTrans(aconn, btid, &rcode);
2726 if (code || rcode) {
2728 "Failed to end the transaction on the backup volume %lu\n",
2729 (unsigned long)backupID);
2730 error = (code ? code : rcode);
2736 /* Will update the vldb below */
2740 code = AFSVolEndTrans(aconn, ttid, &rcode);
2741 if (code || rcode) {
2742 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2743 (unsigned long)avolid);
2745 error = (code ? code : rcode);
2750 code = AFSVolEndTrans(aconn, btid, &rcode);
2751 if (code || rcode) {
2753 "Could not end transaction the backup volume %lu\n",
2754 (unsigned long)backupID);
2756 error = (code ? code : rcode);
2760 /* Now update the vldb - if modified */
2763 MapNetworkToHost(&entry, &storeEntry);
2765 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2766 (LOCKREL_OPCODE | LOCKREL_AFSID |
2767 LOCKREL_TIMESTAMP));
2770 "Could not update the VLDB entry for the volume %lu \n",
2771 (unsigned long)avolid);
2777 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2778 (LOCKREL_OPCODE | LOCKREL_AFSID |
2779 LOCKREL_TIMESTAMP));
2782 "Could not unlock the VLDB entry for the volume %lu \n",
2783 (unsigned long)avolid);
2791 rx_DestroyConnection(aconn);
2793 PrintError("", error);
2797 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2798 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2799 * The new volume is named by <aname>, or by appending ".clone" to
2800 * the existing name if <aname> is NULL. The following flags are
2803 * RV_RDONLY - target volume is RO
2804 * RV_OFFLINE - leave target volume offline
2808 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
2809 afs_int32 acloneid, char *aname, int flags)
2811 struct rx_connection *aconn = (struct rx_connection *)0;
2812 afs_int32 ttid = 0, btid = 0;
2813 afs_int32 code = 0, rcode = 0;
2814 char vname[VOLSER_MAXVOLNAME + 1];
2815 afs_int32 error = 0;
2817 volEntries volumeInfo;
2819 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2822 volumeInfo.volEntries_val = (volintInfo *) 0;
2823 volumeInfo.volEntries_len = 0;
2824 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2826 fprintf(stderr, "Could not get info for volume %lu\n",
2827 (unsigned long)avolid);
2831 strncpy(vname, volumeInfo.volEntries_val[0].name,
2832 VOLSER_OLDMAXVOLNAME - 7);
2833 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2834 strcat(vname, ".clone");
2836 if (volumeInfo.volEntries_val)
2837 free(volumeInfo.volEntries_val);
2841 /* Get a clone id */
2842 VPRINT1("Allocating new volume id for clone of volume %u ...",
2844 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2846 "Could not get an ID for the clone of volume %u from the VLDB\n",
2851 /* Test to see if the clone volume exists by trying to create
2852 * a transaction on the clone volume. We've assumed the clone exists.
2854 /* XXX I wonder what happens if the clone has some other parent... */
2855 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2857 if (code != VNOVOL) {
2858 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2859 (unsigned long)acloneid);
2863 backexists = 0; /* backup volume does not exist */
2866 code = AFSVolEndTrans(aconn, btid, &rcode);
2868 if (code || rcode) {
2870 "Could not end transaction on the previous clone volume %lu\n",
2871 (unsigned long)acloneid);
2872 error = (code ? code : rcode);
2877 /* Now go ahead and try to clone the RW volume.
2878 * First start a transaction on the RW volume
2880 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2882 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2883 (unsigned long)avolid);
2888 /* Clone or reclone the volume, depending on whether the backup
2889 * volume exists or not
2892 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2894 code = AFSVolReClone(aconn, ttid, acloneid);
2896 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2897 (unsigned long)acloneid);
2902 VPRINT1("Creating a new clone %u ...", acloneid);
2904 code = AFSVolClone(aconn, ttid, 0,
2905 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2908 fprintf(STDERR, "Failed to clone the volume %lu\n",
2909 (unsigned long)avolid);
2915 /* End the transaction on the RW volume */
2916 code = AFSVolEndTrans(aconn, ttid, &rcode);
2918 if (code || rcode) {
2920 "Failed to end the transaction on the rw volume %lu\n",
2921 (unsigned long)avolid);
2922 error = (code ? code : rcode);
2926 /* Now go back to the backup volume and bring it on line */
2927 if (!(flags & RV_OFFLINE)) {
2928 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2931 "Failed to start a transaction on the clone volume %lu\n",
2932 (unsigned long)acloneid);
2937 code = AFSVolSetFlags(aconn, btid, 0);
2939 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2940 (unsigned long)acloneid);
2945 code = AFSVolEndTrans(aconn, btid, &rcode);
2947 if (code || rcode) {
2949 "Failed to end the transaction on the clone volume %lu\n",
2950 (unsigned long)acloneid);
2951 error = (code ? code : rcode);
2960 code = AFSVolEndTrans(aconn, ttid, &rcode);
2961 if (code || rcode) {
2962 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2963 (unsigned long)avolid);
2965 error = (code ? code : rcode);
2970 code = AFSVolEndTrans(aconn, btid, &rcode);
2971 if (code || rcode) {
2973 "Could not end transaction on the clone volume %lu\n",
2974 (unsigned long)acloneid);
2976 error = (code ? code : rcode);
2981 rx_DestroyConnection(aconn);
2983 PrintError("", error);
2988 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2991 afs_int32 acode, ccode, rcode, tid;
2992 ccode = rcode = tid = 0;
2994 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2995 if (!acode) { /* It really was there */
2996 acode = AFSVolDeleteVolume(conn, tid);
2998 fprintf(STDERR, "Failed to delete volume %lu.\n",
2999 (unsigned long)vid);
3000 PrintError("", acode);
3002 ccode = AFSVolEndTrans(conn, tid, &rcode);
3006 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3007 (unsigned long)vid);
3008 PrintError("", ccode);
3015 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3016 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3018 /* Get a "transaction" on this replica. Create the volume
3019 * if necessary. Return the time from which a dump should
3020 * be made (0 if it's a new volume)
3023 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3024 struct rx_connection **connPtr, afs_int32 * transPtr,
3025 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3028 struct volser_status tstatus;
3029 int code, rcode, tcode;
3031 *connPtr = (struct rx_connection *)0;
3036 /* get connection to the replication site */
3037 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3039 goto fail; /* server is down */
3041 volid = vldbEntryPtr->volumeId[ROVOL];
3044 AFSVolTransCreate(*connPtr, volid,
3045 vldbEntryPtr->serverPartition[index], ITOffline,
3048 /* If the volume does not exist, create it */
3049 if (!volid || code) {
3052 if (volid && (code != VNOVOL)) {
3053 PrintError("Failed to start a transaction on the RO volume.\n",
3058 strcpy(volname, vldbEntryPtr->name);
3059 strcat(volname, ".readonly");
3063 "Creating new volume %lu on replication site %s: ",
3064 (unsigned long)volid,
3065 hostutil_GetNameByINet(vldbEntryPtr->
3066 serverNumber[index]));
3071 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3073 vldbEntryPtr->volumeId[RWVOL], &volid,
3076 PrintError("Failed to create the ro volume: ", code);
3079 vldbEntryPtr->volumeId[ROVOL] = volid;
3083 /* The following is a bit redundant, since create sets these flags by default */
3085 AFSVolSetFlags(*connPtr, *transPtr,
3086 VTDeleteOnSalvage | VTOutOfService);
3088 PrintError("Failed to set flags on the ro volume: ", code);
3093 /* Otherwise, the transaction did succeed, so get the creation date of the
3094 * latest RO volume on the replication site
3097 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3098 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3100 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3102 PrintError("Failed to get status of volume on destination: ",
3106 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3107 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3114 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3119 PrintError("Could not end transaction on a ro volume: ", tcode);
3126 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3127 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3128 void *cookie, manyResults * results)
3132 for (i = 0; i < tr->manyDests_len; i++) {
3133 results->manyResults_val[i] =
3134 AFSVolForward(fromconn, fromtid, fromdate,
3135 &(tr->manyDests_val[i].server),
3136 tr->manyDests_val[i].trans, cookie);
3142 /* UV_ReleaseVolume()
3143 * Release volume <afromvol> on <afromserver> <afrompart> to all
3144 * its RO sites (full release). Unless the previous release was
3145 * incomplete: in which case we bring the remaining incomplete
3146 * volumes up to date with the volumes that were released
3148 * forceflag: Performs a full release.
3150 * Will create a clone from the RW, then dump the clone out to
3151 * the remaining replicas. If there is more than 1 RO sites,
3152 * ensure that the VLDB says at least one RO is available all
3153 * the time: Influences when we write back the VLDB entry.
3157 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
3158 afs_int32 afrompart, int forceflag)
3161 afs_int32 code, vcode, rcode, tcode;
3162 afs_int32 cloneVolId, roVolId;
3163 struct replica *replicas = 0;
3164 struct nvldbentry entry, storeEntry;
3165 int i, volcount, m, fullrelease, vldbindex;
3167 struct restoreCookie cookie;
3168 struct rx_connection **toconns = 0;
3169 struct release *times = 0;
3171 struct rx_connection *fromconn = (struct rx_connection *)0;
3172 afs_int32 error = 0;
3174 afs_int32 clonetid = 0, onlinetid;
3175 afs_int32 fromtid = 0;
3176 afs_uint32 fromdate, thisdate;
3180 manyResults results;
3181 int rwindex, roindex, roclone, roexists;
3182 afs_int32 rwcrdate, rwupdate, clcrdate;
3186 } remembertime[NMAXNSERVERS];
3187 int releasecount = 0;
3188 struct volser_status volstatus;
3190 memset((char *)remembertime, 0, sizeof(remembertime));
3191 memset((char *)&results, 0, sizeof(results));
3193 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3194 if (vcode != VL_RERELEASE)
3195 ONERROR(vcode, afromvol,
3196 "Could not lock the VLDB entry for the volume %u.\n");
3199 /* Get the vldb entry in readable format */
3200 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3201 ONERROR(vcode, afromvol,
3202 "Could not fetch the entry for the volume %u from the VLDB.\n");
3203 MapHostToNetwork(&entry);
3206 EnumerateEntry(&entry);
3208 if (!ISNAMEVALID(entry.name))
3209 ONERROR(VOLSERBADOP, entry.name,
3210 "Volume name %s is too long, rename before releasing.\n");
3211 if (entry.volumeId[RWVOL] != afromvol)
3212 ONERROR(VOLSERBADOP, afromvol,
3213 "The volume %u being released is not a read-write volume.\n");
3214 if (entry.nServers <= 1)
3215 ONERROR(VOLSERBADOP, afromvol,
3216 "Volume %u has no replicas - release operation is meaningless!\n");
3217 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3218 ONERROR(VOLSERBADOP, entry.name,
3219 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3221 /* roclone is true if one of the RO volumes is on the same
3222 * partition as the RW volume. In this case, we make the RO volume
3223 * on the same partition a clone instead of a complete copy.
3226 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3227 roclone = ((roindex == -1) ? 0 : 1);
3228 rwindex = Lp_GetRwIndex(&entry);
3230 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3232 /* Make sure we have a RO volume id to work with */
3233 if (entry.volumeId[ROVOL] == INVALID_BID) {
3234 /* need to get a new RO volume id */
3235 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3236 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3238 entry.volumeId[ROVOL] = roVolId;
3239 MapNetworkToHost(&entry, &storeEntry);
3240 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3241 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3244 /* Will we be completing a previously unfinished release. -force overrides */
3245 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3246 if (entry.serverFlags[i] & ITSROVOL) {
3248 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3251 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3254 /* Determine which volume id to use and see if it exists */
3257 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3258 code = VolumeExists(afromserver, afrompart, cloneVolId);
3259 roexists = ((code == ENODEV) ? 0 : 1);
3261 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3263 ONERROR(-1, afromserver,
3264 "Cannot establish connection with server 0x%x\n");
3268 fullrelease = 1; /* Do a full release if RO clone does not exist */
3270 /* Begin transaction on RW and mark it busy while we query it */
3271 code = AFSVolTransCreate(
3272 fromconn, afromvol, afrompart, ITBusy, &fromtid
3274 ONERROR(code, afromvol,
3275 "Failed to start transaction on RW volume %u\n");
3277 /* Query the creation date for the RW */
3278 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3279 ONERROR(code, afromvol,
3280 "Failed to get the status of RW volume %u\n");
3281 rwcrdate = volstatus.creationDate;
3282 rwupdate = volstatus.updateDate;
3284 /* End transaction on RW */
3285 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3287 ONERROR((code ? code : rcode), afromvol,
3288 "Failed to end transaction on RW volume %u\n");
3290 /* Begin transaction on clone and mark it busy while we query it */
3291 code = AFSVolTransCreate(
3292 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3294 ONERROR(code, cloneVolId,
3295 "Failed to start transaction on RW clone %u\n");
3297 /* Query the creation date for the clone */
3298 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3299 ONERROR(code, cloneVolId,
3300 "Failed to get the status of RW clone %u\n");
3301 clcrdate = volstatus.creationDate;
3303 /* End transaction on clone */
3304 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3306 ONERROR((code ? code : rcode), cloneVolId,
3307 "Failed to end transaction on RW clone %u\n");
3309 if (rwcrdate > clcrdate)
3310 fullrelease = 2;/* Do a full release if RO clone older than RW */
3315 switch (fullrelease) {
3317 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3318 (unsigned long)afromvol);
3321 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3322 (unsigned long)afromvol);
3325 fprintf(STDOUT, "This is a completion of a previous release\n");
3331 /* If the RO clone exists, then if the clone is a temporary
3332 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3333 * (it was recently added), then also delete it. We do not
3334 * want to "reclone" a temporary RO clone.
3337 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3338 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3339 if (code && (code != VNOVOL))
3344 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3345 * write this entry out to the vlserver until after the first
3346 * RO volume is released (temp RO clones don't count).
3348 for (i = 0; i < entry.nServers; i++) {
3349 entry.serverFlags[i] &= ~NEW_REPSITE;
3350 entry.serverFlags[i] |= RO_DONTUSE;
3352 entry.serverFlags[rwindex] |= NEW_REPSITE;
3353 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3355 /* Begin transaction on RW and mark it busy while we clone it */
3357 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3359 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3361 /* Clone or reclone the volume */
3363 VPRINT1("Recloning RW volume %u...", cloneVolId);
3364 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3365 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3369 strcpy(vname, entry.name);
3370 strcat(vname, ".readonly");
3371 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3373 strcpy(vname, "readonly-clone-temp");
3374 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3377 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3379 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3383 /* Get the time the RW was created for future information */
3384 VPRINT1("Getting status of RW volume %u...", afromvol);
3385 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3386 ONERROR(code, afromvol,
3387 "Failed to get the status of the RW volume %u\n");
3389 rwcrdate = volstatus.creationDate;
3390 rwupdate = volstatus.updateDate;
3392 /* End the transaction on the RW volume */
3393 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3394 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3396 ONERROR((code ? code : rcode), afromvol,
3397 "Failed to end cloning transaction on RW %u\n");
3400 /* Remember clone volume ID in case we fail or are interrupted */
3401 entry.cloneId = cloneVolId;
3404 /* Bring the RO clone online - though not if it's a temporary clone */
3405 VPRINT1("Starting transaction on RO clone volume %u...",
3408 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3410 ONERROR(code, cloneVolId,
3411 "Failed to start transaction on volume %u\n");
3414 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3415 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3418 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3419 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3420 ONERROR((code ? code : rcode), cloneVolId,
3421 "Failed to end transaction on RO clone %u\n");
3424 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3426 /* Sleep so that a client searching for an online volume won't
3427 * find the clone offline and then the next RO offline while the
3428 * release brings the clone online and the next RO offline (race).
3429 * There is a fix in the 3.4 client that does not need this sleep
3430 * anymore, but we don't know what clients we have.
3432 if (entry.nServers > 2)
3435 /* Mark the RO clone in the VLDB as a good site (already released) */
3436 entry.serverFlags[roindex] |= NEW_REPSITE;
3437 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3438 entry.flags |= RO_EXISTS;
3442 /* Write out the VLDB entry only if the clone is not a temporary
3443 * clone. If we did this to a temporary clone then we would end
3444 * up marking all the ROs as "old release" making the ROs
3445 * temporarily unavailable.
3447 MapNetworkToHost(&entry, &storeEntry);
3448 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3449 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3450 ONERROR(vcode, entry.name,
3451 "Could not update vldb entry for %s.\n");
3456 /* Now we will release from the clone to the remaining RO replicas.
3457 * The first 2 ROs (counting the non-temporary RO clone) are released
3458 * individually: releasecount. This is to reduce the race condition
3459 * of clients trying to find an on-line RO volume. The remaining ROs
3460 * are released in parallel but no more than half the number of ROs
3461 * (rounded up) at a time: nservers.
3464 strcpy(vname, entry.name);
3465 strcat(vname, ".readonly");
3466 memset(&cookie, 0, sizeof(cookie));
3467 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3468 cookie.type = ROVOL;
3469 cookie.parent = entry.volumeId[RWVOL];
3472 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3474 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3475 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3477 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3479 results.manyResults_val =
3480 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3481 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3483 "Failed to create transaction on the release clone\n");
3485 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3486 memset(times, 0, (sizeof(struct release) * nservers + 1));
3487 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3488 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3490 /* Create a transaction on the cloned volume */
3491 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3493 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3494 if (!fullrelease && code)
3495 ONERROR(VOLSERNOVOL, afromvol,
3496 "Old clone is inaccessible. Try vos release -f %u.\n");
3497 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3500 /* For each index in the VLDB */
3501 for (vldbindex = 0; vldbindex < entry.nServers;) {
3503 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3505 ((volcount < nservers) && (vldbindex < entry.nServers));
3507 /* The first two RO volumes will be released individually.
3508 * The rest are then released in parallel. This is a hack
3509 * for clients not recognizing right away when a RO volume
3510 * comes back on-line.
3512 if ((volcount == 1) && (releasecount < 2))
3515 if (vldbindex == roindex)
3516 continue; /* the clone */
3517 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3518 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3520 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3521 continue; /* not a RO vol */
3524 /* Get a Transaction on this replica. Get a new connection if
3525 * necessary. Create the volume if necessary. Return the
3526 * time from which the dump should be made (0 if it's a new
3527 * volume). Each volume might have a different time.
3529 replicas[volcount].server.destHost =
3530 ntohl(entry.serverNumber[vldbindex]);
3531 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3532 replicas[volcount].server.destSSID = 1;
3533 times[volcount].vldbEntryIndex = vldbindex;
3536 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3537 &(replicas[volcount].trans),
3538 &(times[volcount].crtime),
3539 &(times[volcount].uptime));
3543 /* Thisdate is the date from which we want to pick up all changes */
3544 if (forceflag || !fullrelease
3545 || (rwcrdate > times[volcount].crtime)) {
3546 /* If the forceflag is set, then we want to do a full dump.
3547 * If it's not a full release, we can't be sure that the creation
3548 * date is good (so we also do a full dump).
3549 * If the RW volume was replaced (its creation date is newer than
3550 * the last release), then we can't be sure what has changed (so
3551 * we do a full dump).
3554 } else if (remembertime[vldbindex].validtime) {
3555 /* Trans was prev ended. Use the time from the prev trans
3556 * because, prev trans may have created the volume. In which
3557 * case time[volcount].time would be now instead of 0.
3560 (remembertime[vldbindex].uptime < times[volcount].uptime)
3561 ? remembertime[vldbindex].uptime
3562 : times[volcount].uptime;
3564 thisdate = times[volcount].uptime;
3566 remembertime[vldbindex].validtime = 1;
3567 remembertime[vldbindex].uptime = thisdate;
3569 if (volcount == 0) {
3570 fromdate = thisdate;
3572 /* Include this volume if it is within 15 minutes of the earliest */
3574 thisdate) ? (fromdate - thisdate) : (thisdate -
3576 AFSVolEndTrans(toconns[volcount],
3577 replicas[volcount].trans, &rcode);
3578 replicas[volcount].trans = 0;
3581 if (thisdate < fromdate)
3582 fromdate = thisdate;
3590 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3591 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3592 hostutil_GetNameByINet(entry.
3593 serverNumber[times[0].
3596 for (s = 1; s < volcount; s++) {
3597 fprintf(STDOUT, " and %s",
3598 hostutil_GetNameByINet(entry.
3599 serverNumber[times[s].
3604 fprintf(STDOUT, " (full release)");
3607 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3609 fprintf(STDOUT, ".\n");
3613 /* Release the ones we have collected */
3614 tr.manyDests_val = &(replicas[0]);
3615 tr.manyDests_len = results.manyResults_len = volcount;
3617 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3618 0 /*spare */ , &cookie, &results);
3619 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3621 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3622 0 /*spare */ , &cookie, &results);
3627 PrintError("Release failed: ", code);
3629 for (m = 0; m < volcount; m++) {
3630 if (results.manyResults_val[m]) {
3631 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3632 /* we retry timed out transaction. When it is
3633 * not the first volume and the transaction wasn't found
3634 * (assume it timed out and was garbage collected by volser).
3637 ("Failed to dump volume from clone to a ro site: ",
3638 results.manyResults_val[m]);
3644 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3645 ROVOL, entry.volumeId[RWVOL], 0, 0);
3647 if ((m == 0) || (code != ENOENT)) {
3648 PrintError("Failed to set correct names and ids: ",
3654 /* have to clear dest. flags to ensure new vol goes online:
3655 * because the restore (forwarded) operation copied
3656 * the V_inService(=0) flag over to the destination.
3658 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3660 if ((m == 0) || (code != ENOENT)) {
3661 PrintError("Failed to set flags on ro volume: ",
3667 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3668 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3669 entry.flags |= RO_EXISTS;
3674 /* End the transactions and destroy the connections */
3675 for (s = 0; s < volcount; s++) {
3676 if (replicas[s].trans)
3677 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3678 replicas[s].trans = 0;
3682 if ((s == 0) || (code != ENOENT)) {
3683 PrintError("Could not end transaction on a ro volume: ",
3687 ("Transaction timed out on a ro volume. Will retry.\n",
3689 if (times[s].vldbEntryIndex < vldbindex)
3690 vldbindex = times[s].vldbEntryIndex;
3695 rx_DestroyConnection(toconns[s]);
3699 MapNetworkToHost(&entry, &storeEntry);
3700 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3701 ONERROR(vcode, afromvol,
3702 " Could not update VLDB entry for volume %u\n");
3703 } /* for each index in the vldb */
3705 /* End the transaction on the cloned volume */
3706 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3711 PrintError("Failed to end transaction on rw volume: ", code);
3713 /* Figure out if any volume were not released and say so */
3714 for (failure = 0, i = 0; i < entry.nServers; i++) {
3715 if (!(entry.serverFlags[i] & NEW_REPSITE))
3721 "The volume %lu could not be released to the following %d sites:\n",
3722 (unsigned long)afromvol, failure);
3723 for (i = 0; i < entry.nServers; i++) {
3724 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3725 MapPartIdIntoName(entry.serverPartition[i], pname);
3726 fprintf(STDERR, "\t%35s %s\n",
3727 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3731 MapNetworkToHost(&entry, &storeEntry);
3733 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3735 ONERROR(vcode, afromvol,
3736 " Could not update VLDB entry for volume %u\n");
3738 ERROREXIT(VOLSERBADRELEASE);
3741 /* All the ROs were release successfully. Remove the temporary clone */
3744 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3745 (unsigned long)cloneVolId);
3748 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3749 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3754 for (i = 0; i < entry.nServers; i++)
3755 entry.serverFlags[i] &= ~NEW_REPSITE;
3757 /* Update the VLDB */
3758 VPRINT("updating VLDB ...");
3760 MapNetworkToHost(&entry, &storeEntry);
3762 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3763 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3764 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3769 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3773 "Failed to end cloning transaction on the RW volume %lu\n",
3774 (unsigned long)afromvol);
3780 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3784 "Failed to end transaction on the release clone %lu\n",
3785 (unsigned long)cloneVolId);
3790 for (i = 0; i < nservers; i++) {
3791 if (replicas && replicas[i].trans) {
3792 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3793 replicas[i].trans = 0;
3796 "Failed to end transaction on ro volume %u at server %s\n",
3797 entry.volumeId[ROVOL],
3798 hostutil_GetNameByINet(htonl
3799 (replicas[i].server.
3805 if (toconns && toconns[i]) {
3806 rx_DestroyConnection(toconns[i]);
3812 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3813 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3816 "Could not release lock on the VLDB entry for volume %lu\n",
3817 (unsigned long)afromvol);
3823 PrintError("", error);
3826 rx_DestroyConnection(fromconn);
3827 if (results.manyResults_val)
3828 free(results.manyResults_val);
3840 dump_sig_handler(int x)
3842 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3846 /* Dump the volume <afromvol> on <afromserver> and
3847 * <afrompart> to <afilename> starting from <fromdate>.
3848 * DumpFunction does the real work behind the scenes after
3849 * extracting parameters from the rock
3852 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3853 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock,
3856 struct rx_connection *fromconn = (struct rx_connection *)0;
3857 struct rx_call *fromcall = (struct rx_call *)0;
3858 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3859 afs_int32 code, error = 0, retry = 0;
3860 time_t tmv = fromdate;
3864 #ifndef AFS_NT40_ENV
3865 (void)signal(SIGPIPE, dump_sig_handler);
3867 (void)signal(SIGINT, dump_sig_handler);
3870 VEPRINT("Full Dump ...\n");
3872 VEPRINT1("Incremental Dump (as of %.24s)...\n",
3876 /* get connections to the servers */
3877 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3879 VEPRINT1("Starting transaction on volume %u...", afromvol);
3880 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3881 EGOTO1(error_exit, code,
3882 "Could not start transaction on the volume %u to be dumped\n",
3886 fromcall = rx_NewCall(fromconn);
3888 VEPRINT1("Starting volume dump on volume %u...", afromvol);
3889 if (flags & VOLDUMPV2_OMITDIRS)
3890 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
3893 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3894 EGOTO(error_exit, code, "Could not start the dump process \n");
3897 VEPRINT1("Dumping volume %u...", afromvol);
3898 code = DumpFunction(fromcall, rock);
3899 if (code == RXGEN_OPCODE)
3901 EGOTO(error_exit, code, "Error while dumping volume \n");
3906 code = rx_EndCall(fromcall, rxError);
3907 if (code && code != RXGEN_OPCODE)
3908 fprintf(STDERR, "Error in rx_EndCall\n");
3913 VEPRINT1("Ending transaction on volume %u...", afromvol);
3914 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3915 if (code || rcode) {
3916 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3917 (unsigned long)afromvol);
3919 error = (code ? code : rcode);
3924 rx_DestroyConnection(fromconn);
3928 if (error != RXGEN_OPCODE)
3929 PrintError("", error);
3933 /* Clone the volume <afromvol> on <afromserver> and
3934 * <afrompart>, and then dump the clone volume to
3935 * <afilename> starting from <fromdate>.
3936 * DumpFunction does the real work behind the scenes after
3937 * extracting parameters from the rock
3940 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3941 afs_int32 afrompart, afs_int32 fromdate,
3942 afs_int32(*DumpFunction) (), char *rock, afs_int32 flags)
3944 struct rx_connection *fromconn = (struct rx_connection *)0;
3945 struct rx_call *fromcall = (struct rx_call *)0;
3946 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3947 afs_int32 clonetid = 0;
3948 afs_int32 code = 0, vcode = 0, error = 0;
3949 afs_int32 clonevol = 0;
3951 time_t tmv = fromdate;
3955 #ifndef AFS_NT40_ENV
3956 (void)signal(SIGPIPE, dump_sig_handler);
3958 (void)signal(SIGINT, dump_sig_handler);
3961 VEPRINT("Full Dump ...\n");
3963 VEPRINT1("Incremental Dump (as of %.24s)...\n",
3967 /* get connections to the servers */
3968 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3970 VEPRINT1("Starting transaction on volume %u...", afromvol);
3971 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3972 EGOTO1(error_exit, code,
3973 "Could not start transaction on the volume %u to be dumped\n",
3977 /* Get a clone id */
3978 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3979 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
3980 EGOTO1(error_exit, code,
3981 "Could not get an ID for the clone of volume %u from the VLDB\n",
3985 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3986 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3988 strcpy(vname, "dump-clone-temp");
3990 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3991 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3995 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
3997 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4001 EGOTO1(error_exit, code,
4002 "Failed to end the transaction on the volume %u\n", afromvol);
4006 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4008 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
4010 EGOTO1(error_exit, code,
4011 "Failed to start a transaction on the cloned volume%u\n",
4015 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4016 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4017 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4022 fromcall = rx_NewCall(fromconn);
4024 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4025 if (flags & VOLDUMPV2_OMITDIRS)
4026 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4028 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4029 EGOTO(error_exit, code, "Could not start the dump process \n");
4032 VEPRINT1("Dumping volume %u...", afromvol);
4033 code = DumpFunction(fromcall, rock);
4034 EGOTO(error_exit, code, "Error while dumping volume \n");
4038 /* now delete the clone */
4039 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4040 code = AFSVolDeleteVolume(fromconn, clonetid);
4042 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4043 (unsigned long)clonevol);
4049 code = rx_EndCall(fromcall, rxError);
4051 fprintf(STDERR, "Error in rx_EndCall\n");
4057 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4058 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4059 if (code || rcode) {
4061 "Could not end transaction on the cloned volume %lu\n",
4062 (unsigned long)clonevol);
4064 error = (code ? code : rcode);
4069 rx_DestroyConnection(fromconn);
4071 PrintError("", error);
4078 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4079 * the dump file <afilename>. WriteData does all the real work
4080 * after extracting params from the rock
4083 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4084 afs_int32 toparentid, char tovolname[], int flags,
4085 afs_int32(*WriteData) (), char *rock)
4087 struct rx_connection *toconn, *tempconn;
4088 struct rx_call *tocall;
4089 afs_int32 totid, code, rcode, vcode, terror = 0;
4090 afs_int32 rxError = 0;
4091 struct volser_status tstatus;
4092 struct volintInfo vinfo;
4094 char tovolreal[VOLSER_OLDMAXVOLNAME];
4095 afs_int32 pvolid, pparentid;
4098 struct nvldbentry entry, storeEntry;
4101 struct restoreCookie cookie;
4103 afs_int32 volflag, voltype, volsertype;
4104 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4105 int index, same, errcode;
4109 memset(&cookie, 0, sizeof(cookie));
4114 tocall = (struct rx_call *)0;
4115 toconn = (struct rx_connection *)0;
4116 tempconn = (struct rx_connection *)0;
4120 if (flags & RV_RDONLY) {
4122 volsertype = volser_RO;
4125 volsertype = volser_RW;
4129 pparentid = toparentid;
4130 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4131 if (pvolid == 0) { /*alot a new id if needed */
4132 vcode = VLDB_GetEntryByName(tovolname, &entry);
4133 if (vcode == VL_NOENT) {
4134 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4136 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4142 } else if (flags & RV_RDONLY) {
4143 if (entry.flags & RW_EXISTS) {
4145 "Entry for ReadWrite volume %s already exists!\n",
4147 error = VOLSERBADOP;
4150 if (!entry.volumeId[ROVOL]) {
4152 "Existing entry for volume %s has no ReadOnly ID\n",
4154 error = VOLSERBADOP;
4157 pvolid = entry.volumeId[ROVOL];
4158 pparentid = entry.volumeId[RWVOL];
4160 pvolid = entry.volumeId[RWVOL];
4161 pparentid = entry.volumeId[RWVOL];
4164 if (!pparentid) pparentid = pvolid;
4165 /* at this point we have a volume id to use/reuse for the volume to be restored */
4166 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4168 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4169 EGOTO1(refail, VOLSERBADOP,
4170 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4173 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4174 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4175 EGOTO1(refail, VOLSERBADOP,
4176 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4178 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4181 MapPartIdIntoName(topart, partName);
4182 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4183 tovolreal, (unsigned long)pvolid,
4184 hostutil_GetNameByINet(toserver), partName);
4187 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4190 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4191 VPRINT1("Deleting the previous volume %u ...", pvolid);
4194 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4195 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4198 code = AFSVolGetStatus(toconn, totid, &tstatus);
4199 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4202 oldCreateDate = tstatus.creationDate;
4203 oldUpdateDate = tstatus.updateDate;
4206 AFSVolSetFlags(toconn, totid,
4207 VTDeleteOnSalvage | VTOutOfService);
4208 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4211 code = AFSVolDeleteVolume(toconn, totid);
4212 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4214 code = AFSVolEndTrans(toconn, totid, &rcode);
4218 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4223 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4225 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4228 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4229 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4232 code = AFSVolGetStatus(toconn, totid, &tstatus);
4233 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4236 oldCreateDate = tstatus.creationDate;
4237 oldUpdateDate = tstatus.updateDate;
4244 cookie.parent = pparentid;
4245 cookie.type = voltype;
4247 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4249 tocall = rx_NewCall(toconn);
4250 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4252 fprintf(STDERR, "Volume restore Failed \n");
4256 code = WriteData(tocall, rock);
4258 fprintf(STDERR, "Could not transmit data\n");
4262 terror = rx_EndCall(tocall, rxError);
4263 tocall = (struct rx_call *)0;
4265 fprintf(STDERR, "rx_EndCall Failed \n");
4269 code = AFSVolGetStatus(toconn, totid, &tstatus);
4272 "Could not get status information about the volume %lu\n",
4273 (unsigned long)pvolid);
4277 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4279 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4280 (unsigned long)pvolid);
4285 if (flags & RV_CRDUMP)
4286 newCreateDate = tstatus.creationDate;
4287 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4288 newCreateDate = oldCreateDate;
4290 newCreateDate = time(0);
4291 if (flags & RV_LUDUMP)
4292 newUpdateDate = tstatus.updateDate;
4293 else if (flags & RV_LUKEEP)
4294 newUpdateDate = oldUpdateDate;
4296 newUpdateDate = time(0);
4297 code = AFSVolSetDate(toconn,totid, newCreateDate);
4299 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4304 init_volintInfo(&vinfo);
4305 vinfo.creationDate = newCreateDate;
4306 vinfo.updateDate = newUpdateDate;
4307 code = AFSVolSetInfo(toconn, totid, &vinfo);
4309 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4315 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4316 code = AFSVolSetFlags(toconn, totid, volflag);
4318 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4323 /* It isn't handled right in refail */
4324 code = AFSVolEndTrans(toconn, totid, &rcode);
4329 fprintf(STDERR, "Could not end transaction on %lu\n",
4330 (unsigned long)pvolid);
4336 fprintf(STDOUT, " done\n");
4338 if (success && (!reuseID || (flags & RV_FULLRST))) {
4339 /* Volume was restored on the file server, update the
4340 * VLDB to reflect the change.
4342 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4343 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4345 "Could not fetch the entry for volume number %lu from VLDB \n",
4346 (unsigned long)pvolid);
4351 MapHostToNetwork(&entry);
4352 if (vcode == VL_NOENT) { /* it doesnot exist already */
4353 /*make the vldb return this indication specifically */
4354 VPRINT("------- Creating a new VLDB entry ------- \n");
4355 strcpy(entry.name, tovolname);
4357 entry.serverNumber[0] = toserver; /*should be indirect */
4358 entry.serverPartition[0] = topart;
4359 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4360 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4361 if (flags & RV_RDONLY)
4362 entry.volumeId[ROVOL] = pvolid;
4363 else if (tstatus.cloneID != 0) {
4364 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4366 entry.volumeId[ROVOL] = INVALID_BID;
4367 entry.volumeId[RWVOL] = pparentid;
4369 if (tstatus.backupID != 0) {
4370 entry.volumeId[BACKVOL] = tstatus.backupID;
4371 /*this should come from status info on the volume if non zero */
4373 entry.volumeId[BACKVOL] = INVALID_BID;
4374 MapNetworkToHost(&entry, &storeEntry);
4375 vcode = VLDB_CreateEntry(&storeEntry);
4378 "Could not create the VLDB entry for volume number %lu \n",
4379 (unsigned long)pvolid);
4385 EnumerateEntry(&entry);
4386 } else { /*update the existing entry */
4388 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4389 fprintf(STDOUT, "------- Old entry -------\n");
4390 EnumerateEntry(&entry);
4391 fprintf(STDOUT, "------- New entry -------\n");
4394 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4398 "Could not lock the entry for volume number %lu \n",
4399 (unsigned long)pvolid);
4404 strcpy(entry.name, tovolname);
4406 /* Update the vlentry with the new information */
4407 if (flags & RV_RDONLY)
4408 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4410 index = Lp_GetRwIndex(&entry);
4412 /* Add the new site for the volume being restored */
4413 entry.serverNumber[entry.nServers] = toserver;
4414 entry.serverPartition[entry.nServers] = topart;
4415 entry.serverFlags[entry.nServers] =
4416 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4419 /* This volume should be deleted on the old site
4420 * if its different from new site.
4423 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4427 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4429 if ((!errcode && !same)
4430 || (entry.serverPartition[index] != topart)) {
4431 if (flags & RV_NODEL) {
4433 ("Not deleting the previous volume %u on server %s, ...",
4435 hostutil_GetNameByINet(entry.serverNumber[index]));
4438 UV_Bind(entry.serverNumber[index],
4439 AFSCONF_VOLUMEPORT);
4441 MapPartIdIntoName(entry.serverPartition[index],
4444 ("Deleting the previous volume %u on server %s, partition %s ...",
4446 hostutil_GetNameByINet(entry.serverNumber[index]),
4449 AFSVolTransCreate(tempconn, pvolid,
4450 entry.serverPartition[index],
4451 ITOffline, &temptid);
4454 AFSVolSetFlags(tempconn, temptid,
4459 "Could not set flags on volume %lu on the older site\n",
4460 (unsigned long)pvolid);
4464 code = AFSVolDeleteVolume(tempconn, temptid);
4467 "Could not delete volume %lu on the older site\n",
4468 (unsigned long)pvolid);
4472 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4478 "Could not end transaction on volume %lu on the older site\n",
4479 (unsigned long)pvolid);
4484 MapPartIdIntoName(entry.serverPartition[index],
4489 entry.serverNumber[index] = toserver;
4490 entry.serverPartition[index] = topart;
4493 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4494 MapNetworkToHost(&entry, &storeEntry);
4496 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4497 LOCKREL_OPCODE | LOCKREL_AFSID |
4501 "Could not update the entry for volume number %lu \n",
4502 (unsigned long)pvolid);
4508 EnumerateEntry(&entry);
4515 code = rx_EndCall(tocall, rxError);
4521 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4522 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4525 "Could not release lock on the VLDB entry for the volume %lu\n",
4526 (unsigned long)pvolid);
4532 code = AFSVolEndTrans(toconn, totid, &rcode);
4536 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4537 (unsigned long)pvolid);
4543 code = AFSVolEndTrans(toconn, temptid, &rcode);
4547 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4548 (unsigned long)pvolid);
4554 rx_DestroyConnection(tempconn);
4556 rx_DestroyConnection(toconn);
4557 PrintError("", error);
4562 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4563 char tovolname[], int flags, afs_int32(*WriteData) (),
4566 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4571 /*unlocks the vldb entry associated with <volid> */
4573 UV_LockRelease(afs_int32 volid)
4579 VPRINT("Binding to the VLDB server\n");
4581 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4582 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4585 "Could not unlock the entry for volume number %lu in VLDB \n",
4586 (unsigned long)volid);
4587 PrintError("", vcode);
4590 VPRINT("VLDB updated\n");
4595 /*adds <server> and <part> as a readonly replication site for <volid>
4598 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid, afs_int32 valid)
4600 int j, nro = 0, islocked = 0;
4601 struct nvldbentry entry, storeEntry;
4602 afs_int32 vcode, error = 0;
4605 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4608 " Could not lock the VLDB entry for the volume %lu \n",
4609 (unsigned long)volid);
4614 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4617 "Could not fetch the VLDB entry for volume number %lu \n",
4618 (unsigned long)volid);
4622 if (!ISNAMEVALID(entry.name)) {
4624 "Volume name %s is too long, rename before adding site\n",
4626 error = VOLSERBADOP;
4629 MapHostToNetwork(&entry);
4631 /* See if it's too many entries */
4632 if (entry.nServers >= NMAXNSERVERS) {
4633 fprintf(STDERR, "Total number of entries will exceed %u\n",
4635 error = VOLSERBADOP;
4639 /* See if it's on the same server */
4640 for (j = 0; j < entry.nServers; j++) {
4641 if (entry.serverFlags[j] & ITSROVOL) {
4643 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4646 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4649 MapPartIdIntoName(entry.serverPartition[j], apartName);
4651 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4653 error = VOLSERBADOP;
4660 /* See if it's too many RO sites - leave one for the RW */
4661 if (nro >= NMAXNSERVERS - 1) {
4662 fprintf(STDERR, "Total number of sites will exceed %u\n",
4664 error = VOLSERBADOP;
4668 VPRINT("Adding a new site ...");
4669 entry.serverNumber[entry.nServers] = server;
4670 entry.serverPartition[entry.nServers] = part;
4672 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4674 entry.serverFlags[entry.nServers] = (ITSROVOL);
4678 MapNetworkToHost(&entry, &storeEntry);
4680 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4681 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4683 fprintf(STDERR, "Could not update entry for volume %lu \n",
4684 (unsigned long)volid);
4693 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4694 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4697 "Could not release lock on volume entry for %lu \n",
4698 (unsigned long)volid);
4699 PrintError("", vcode);
4703 PrintError("", error);
4707 /*removes <server> <part> as read only site for <volid> from the vldb */
4709 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4712 struct nvldbentry entry, storeEntry;
4715 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4717 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4718 (unsigned long)volid);
4719 PrintError("", vcode);
4723 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4726 "Could not fetch the entry for volume number %lu from VLDB \n",
4727 (unsigned long)volid);
4728 PrintError("", vcode);
4731 MapHostToNetwork(&entry);
4732 if (!Lp_ROMatch(server, part, &entry)) {
4733 /*this site doesnot exist */
4734 fprintf(STDERR, "This site is not a replication site \n");
4736 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4737 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4739 fprintf(STDERR, "Could not update entry for volume %lu \n",
4740 (unsigned long)volid);
4741 PrintError("", vcode);
4742 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4743 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4747 } else { /*remove the rep site */
4748 Lp_SetROValue(&entry, server, part, 0, 0);
4750 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4751 entry.flags &= ~RO_EXISTS;
4752 if (entry.nServers < 1) { /*this is the last ref */
4753 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4755 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4758 "Could not delete VLDB entry for volume %lu \n",
4759 (unsigned long)volid);
4760 PrintError("", vcode);
4765 MapNetworkToHost(&entry, &storeEntry);
4766 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4767 (unsigned long)volid);
4770 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4771 LOCKREL_OPCODE | LOCKREL_AFSID |
4775 "Could not release lock on volume entry for %lu \n",
4776 (unsigned long)volid);
4777 PrintError("", vcode);
4778 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4779 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4787 /*sets <server> <part> as read/write site for <volid> in the vldb */
4789 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4792 struct nvldbentry entry, storeEntry;
4795 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4797 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4798 (unsigned long)volid);
4799 PrintError("", vcode);
4802 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4805 "Could not fetch the entry for volume number %lu from VLDB \n",
4806 (unsigned long)volid);
4807 PrintError("", vcode);
4810 MapHostToNetwork(&entry);
4811 index = Lp_GetRwIndex(&entry);
4813 /* no RW site exists */
4814 fprintf(STDERR, "No existing RW site for volume %lu",
4815 (unsigned long)volid);
4817 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4818 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4821 "Could not release lock on entry for volume %lu \n",
4822 (unsigned long)volid);
4823 PrintError("", vcode);
4827 } else { /* change the RW site */
4828 entry.serverNumber[index] = server;
4829 entry.serverPartition[index] = part;
4830 MapNetworkToHost(&entry, &storeEntry);
4832 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4833 LOCKREL_OPCODE | LOCKREL_AFSID |
4836 fprintf(STDERR, "Could not update entry for volume %lu \n",
4837 (unsigned long)volid);
4838 PrintError("", vcode);
4839 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4840 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4848 /*list all the partitions on <aserver> */
4850 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4853 struct rx_connection *aconn;
4854 struct pIDs partIds;
4855 struct partEntries partEnts;
4856 register int i, j = 0, code;
4859 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4861 partEnts.partEntries_len = 0;
4862 partEnts.partEntries_val = NULL;
4863 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4864 if (code == RXGEN_OPCODE) {
4865 for (i = 0; i < 26; i++) /* try old interface */
4866 partIds.partIds[i] = -1;
4867 code = AFSVolListPartitions(aconn, &partIds);
4869 for (i = 0; i < 26; i++) {
4870 if ((partIds.partIds[i]) != -1) {
4871 ptrPartList->partId[j] = partIds.partIds[i];
4872 ptrPartList->partFlags[j] = PARTVALID;
4875 ptrPartList->partFlags[i] = 0;
4880 *cntp = partEnts.partEntries_len;
4881 if (*cntp > VOLMAXPARTS) {
4883 "Warning: number of partitions on the server too high %d (process only %d)\n",
4884 *cntp, VOLMAXPARTS);
4885 *cntp = VOLMAXPARTS;
4887 for (i = 0; i < *cntp; i++) {
4888 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4889 ptrPartList->partFlags[i] = PARTVALID;
4891 free(partEnts.partEntries_val);
4897 "Could not fetch the list of partitions from the server\n");
4898 PrintError("", code);
4900 rx_DestroyConnection(aconn);
4905 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4906 This is used by the backup system */
4908 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4909 struct volDescription *volPtr, afs_int32 arraySize)
4911 struct rx_connection *aconn;
4912 struct volDescription *curPtr;
4915 afs_int32 rcode = 0;
4916 afs_int32 success = 1;
4919 aconn = (struct rx_connection *)0;
4920 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4922 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4923 if (curPtr->volFlags & CLONEVALID) {
4924 curPtr->volFlags &= ~CLONEZAPPED;
4927 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4932 code = AFSVolDeleteVolume(aconn, tid);
4935 code = AFSVolEndTrans(aconn, tid, &rcode);
4940 curPtr->volFlags |= CLONEZAPPED;
4942 fprintf(STDERR, "Could not zap volume %lu\n",
4943 (unsigned long)curPtr->volCloneId);
4945 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4946 curPtr->volCloneId);
4952 rx_DestroyConnection(aconn);
4956 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4959 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4960 struct volDescription *volPtr, afs_int32 arraySize)
4962 struct rx_connection *aconn;
4963 struct volDescription *curPtr;
4966 afs_int32 rcode = 0;
4968 int reuseCloneId = 0;
4969 afs_int32 curCloneId = 0;
4970 char cloneName[256]; /*max vol name */
4972 aconn = (struct rx_connection *)0;
4973 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4975 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4977 else { /*get a bunch of id's from vldb */
4979 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
4981 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4982 PrintError("", code);
4987 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4988 if (curPtr->volFlags & ENTRYVALID) {
4990 curPtr->volFlags |= CLONEVALID;
4991 /*make a clone of curParentId and record as curPtr->volCloneId */
4993 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4996 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4999 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5003 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5004 strcpy(cloneName, curPtr->volName);
5005 strcat(cloneName, "-tmpClone-");
5007 strcpy(cloneName, "-tmpClone");
5009 curPtr->volCloneId = curCloneId;
5014 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5015 &(curPtr->volCloneId));
5017 curPtr->volFlags &= ~CLONEVALID;
5019 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5020 curPtr->volName, (unsigned long)code);
5021 code = AFSVolEndTrans(aconn, tid, &rcode);
5023 fprintf(STDERR, "WARNING: could not end transaction\n");
5026 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5027 curPtr->volCloneId);
5028 code = AFSVolEndTrans(aconn, tid, &rcode);
5029 if (code || rcode) {
5030 curPtr->volFlags &= ~CLONEVALID;
5039 rx_DestroyConnection(aconn);
5044 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5045 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5047 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5048 struct volintInfo **resultPtr, afs_int32 * size)
5050 struct rx_connection *aconn;
5052 volEntries volumeInfo;
5056 *resultPtr = (volintInfo *) 0;
5057 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5058 volumeInfo.volEntries_len = 0;
5060 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5061 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5064 "Could not fetch the list of volumes from the server\n");
5066 *resultPtr = volumeInfo.volEntries_val;
5067 *size = volumeInfo.volEntries_len;
5071 rx_DestroyConnection(aconn);
5072 PrintError("", code);
5076 /*------------------------------------------------------------------------
5077 * EXPORTED UV_XListVolumes
5080 * List the extended information for all the volumes on a particular
5081 * File Server and partition. We may either return the volume's ID
5082 * or all of its extended information.
5085 * a_serverID : Address of the File Server for which we want
5086 * extended volume info.
5087 * a_partID : Partition for which we want the extended
5089 * a_all : If non-zero, fetch ALL the volume info,
5090 * otherwise just the volume ID.
5091 * a_resultPP : Ptr to the address of the area containing
5092 * the returned volume info.
5093 * a_numEntsInResultP : Ptr for the value we set for the number of
5098 * Otherise, the return value of AFSVolXListVolumes.
5101 * This routine is closely related to UV_ListVolumes, which returns
5102 * only the standard level of detail on AFS volumes. It is a
5103 * heavyweight operation, zipping through all the volume entries for
5104 * a given server/partition.
5108 *------------------------------------------------------------------------*/
5111 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5112 struct volintXInfo **a_resultPP,
5113 afs_int32 * a_numEntsInResultP)
5115 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5116 afs_int32 code; /*Error code to return */
5117 volXEntries volumeXInfo; /*Area for returned extended vol info */
5120 * Set up our error code and the area for returned extended volume info.
5121 * We set the val field to a null pointer as a hint for the stub to
5125 *a_numEntsInResultP = 0;
5126 *a_resultPP = (volintXInfo *) 0;
5127 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5128 volumeXInfo.volXEntries_len = 0;
5131 * Bind to the Volume Server port on the File Server machine in question,
5134 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5135 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5137 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5140 * We got the info; pull out the pointer to where the results lie
5141 * and how many entries are there.
5143 *a_resultPP = volumeXInfo.volXEntries_val;
5144 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5148 * If we got an Rx connection, throw it away.
5151 rx_DestroyConnection(rxConnP);
5153 PrintError("", code);
5155 } /*UV_XListVolumes */
5157 /* get all the information about volume <volid> on <aserver> and <apart> */
5159 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
5160 struct volintInfo **resultPtr)
5162 struct rx_connection *aconn;
5164 volEntries volumeInfo;
5168 *resultPtr = (volintInfo *) 0;
5169 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5170 volumeInfo.volEntries_len = 0;
5172 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5173 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5176 "Could not fetch the information about volume %lu from the server\n",
5177 (unsigned long)volid);
5179 *resultPtr = volumeInfo.volEntries_val;
5184 rx_DestroyConnection(aconn);
5185 PrintError("", code);
5189 /*------------------------------------------------------------------------
5190 * EXPORTED UV_XListOneVolume
5193 * List the extended information for a volume on a particular File
5194 * Server and partition.
5197 * a_serverID : Address of the File Server for which we want
5198 * extended volume info.
5199 * a_partID : Partition for which we want the extended
5201 * a_volID : Volume ID for which we want the info.
5202 * a_resultPP : Ptr to the address of the area containing
5203 * the returned volume info.
5207 * Otherise, the return value of AFSVolXListOneVolume.
5210 * This routine is closely related to UV_ListOneVolume, which returns
5211 * only the standard level of detail on the chosen AFS volume.
5215 *------------------------------------------------------------------------*/
5218 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
5219 struct volintXInfo **a_resultPP)
5221 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5222 afs_int32 code; /*Error code */
5223 volXEntries volumeXInfo; /*Area for returned info */
5226 * Set up our error code, and the area we're in which we are returning
5227 * the info. Setting the val field to a null pointer tells the stub
5228 * to allocate space for us.
5231 *a_resultPP = (volintXInfo *) 0;
5232 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5233 volumeXInfo.volXEntries_len = 0;
5236 * Bind to the Volume Server port on the File Server machine in question,
5239 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5240 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5243 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5246 * We got the info; pull out the pointer to where the results lie.
5248 *a_resultPP = volumeXInfo.volXEntries_val;
5251 * If we got an Rx connection, throw it away.
5254 rx_DestroyConnection(rxConnP);
5256 PrintError("", code);
5261 * Given a volume we read from a partition, check if it is
5262 * represented in the VLDB correctly.
5264 * The VLDB is looked up by the RW volume id (not its name).
5265 * The RW contains the true name of the volume (BK and RO set
5266 * the name in the VLDB only on creation of the VLDB entry).
5267 * We want rules strict enough that when we check all volumes
5268 * on one partition, it does not need to be done again. IE:
5269 * two volumes on different partitions won't constantly
5270 * change a VLDB entry away from what the other set.
5271 * For RW and BK volumes, we will always check the VLDB to see
5272 * if the two exist on the server/partition. May seem redundant,
5273 * but this is an easy check of the VLDB. IE: if the VLDB entry
5274 * says the BK exists but no BK volume is there, we will detect
5275 * this when we check the RW volume.
5276 * VLDB entries are locked only when a change needs to be done.
5277 * Output changed to look a lot like the "vos syncserv" otuput.
5280 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5281 afs_int32 * modentry, afs_uint32 * maxvolid)
5284 afs_int32 code, error = 0;
5285 struct nvldbentry entry, storeEntry;
5287 int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
5296 ((volumeinfo->type ==
5297 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5300 /* Check to see if the VLDB is ok without locking it (pass 1).
5301 * If it will change, then lock the VLDB entry, read it again,
5302 * then make the changes to it (pass 2).
5305 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5307 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5308 (unsigned long)rwvolid);
5314 createentry = 0; /* Do we need to create a VLDB entry */
5315 addvolume = 0; /* Add this volume to the VLDB entry */
5316 modified = 0; /* The VLDB entry was modified */
5318 /* Read the entry from VLDB by its RW volume id */
5319 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5321 if (code != VL_NOENT) {
5323 "Could not retreive the VLDB entry for volume %lu \n",
5324 (unsigned long)rwvolid);
5328 memset(&entry, 0, sizeof(entry));
5329 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5333 MapHostToNetwork(&entry);
5336 if (verbose && (pass == 1)) {
5337 fprintf(STDOUT, "_______________________________\n");
5338 fprintf(STDOUT, "\n-- status before -- \n");
5340 fprintf(STDOUT, "\n**does not exist**\n");
5342 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5343 || (entry.flags & BACK_EXISTS))
5344 EnumerateEntry(&entry);
5346 fprintf(STDOUT, "\n");
5349 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5355 /* Check existence of RW and BK volumes */
5356 code = CheckVldbRWBK(&entry, &mod);
5362 idx = Lp_GetRwIndex(&entry);
5363 if (idx == -1) { /* RW index not found in the VLDB entry */
5364 idx = entry.nServers; /* put it into next index */
5367 } else { /* RW index found in the VLDB entry. */
5368 /* Verify if this volume's location matches where the VLDB says it is */
5369 if (!Lp_Match(aserver, apart, &entry)) {
5370 if (entry.flags & RW_EXISTS) {
5371 /* The RW volume exists elsewhere - report this one a duplicate */
5373 MapPartIdIntoName(apart, pname);
5375 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5376 (unsigned long)rwvolid,
5377 hostutil_GetNameByINet(aserver), pname);
5378 MapPartIdIntoName(entry.serverPartition[idx],
5381 " VLDB reports RW volume %lu exists on %s %s\n",
5382 (unsigned long)rwvolid,
5383 hostutil_GetNameByINet(entry.
5388 /* The RW volume does not exist - have VLDB point to this one */
5391 /* Check for orphaned BK volume on old partition */
5392 if (entry.flags & BACK_EXISTS) {
5394 MapPartIdIntoName(entry.serverPartition[idx],
5397 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5398 entry.volumeId[BACKVOL],
5399 hostutil_GetNameByINet(entry.
5402 MapPartIdIntoName(apart, pname);
5404 " VLDB reports its RW volume %lu exists on %s %s\n",
5405 (unsigned long)rwvolid,
5406 hostutil_GetNameByINet(aserver),
5412 /* Volume location matches the VLDB location */
5413 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5414 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5417 (entry.name, volumeinfo->name,
5418 VOLSER_OLDMAXVOLNAME) != 0)) {
5426 entry.flags |= RW_EXISTS;
5427 entry.volumeId[RWVOL] = rwvolid;
5428 if (!entry.volumeId[BACKVOL])
5429 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5430 if (!entry.volumeId[ROVOL])
5431 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5433 entry.serverFlags[idx] = ITSRWVOL;
5434 entry.serverNumber[idx] = aserver;
5435 entry.serverPartition[idx] = apart;
5436 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5440 /* One last check - to update BK if need to */
5441 code = CheckVldbRWBK(&entry, &mod);
5449 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5455 /* Check existence of RW and BK volumes */
5456 code = CheckVldbRWBK(&entry, &mod);
5462 idx = Lp_GetRwIndex(&entry);
5463 if (idx == -1) { /* RW index not found in the VLDB entry */
5464 idx = entry.nServers; /* Put it into next index */
5467 } else { /* RW index found in the VLDB entry */
5468 /* Verify if this volume's location matches where the VLDB says it is */
5469 if (!Lp_Match(aserver, apart, &entry)) {
5470 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5472 MapPartIdIntoName(apart, pname);
5474 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5475 (unsigned long)volumeinfo->volid,
5476 hostutil_GetNameByINet(aserver), pname);
5477 MapPartIdIntoName(entry.serverPartition[idx], pname);
5479 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5480 (unsigned long)rwvolid,
5481 hostutil_GetNameByINet(entry.
5486 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5487 if (!(entry.flags & BACK_EXISTS)) {
5489 } else if (volumeinfo->volid >
5490 entry.volumeId[BACKVOL]) {
5494 MapPartIdIntoName(entry.serverPartition[idx],
5497 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5498 entry.volumeId[BACKVOL],
5499 hostutil_GetNameByINet(aserver),
5502 " VLDB reports its BK volume ID is %lu\n",
5503 (unsigned long)volumeinfo->volid);
5507 MapPartIdIntoName(entry.serverPartition[idx],
5510 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5511 (unsigned long)volumeinfo->volid,
5512 hostutil_GetNameByINet(aserver),
5515 " VLDB reports its BK volume ID is %u\n",
5516 entry.volumeId[BACKVOL]);
5519 } else if (!entry.volumeId[BACKVOL]) {
5526 entry.flags |= BACK_EXISTS;
5527 entry.volumeId[RWVOL] = rwvolid;
5528 entry.volumeId[BACKVOL] = volumeinfo->volid;
5530 entry.serverNumber[idx] = aserver;
5531 entry.serverPartition[idx] = apart;
5532 entry.serverFlags[idx] = ITSRWVOL;
5538 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5539 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5540 /* This is a quick check to see if the RO entry exists in the
5541 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5542 * RO volume listed in the VLDB exists).
5544 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5546 idx = entry.nServers;
5550 if (!(entry.flags & RO_EXISTS)) {
5555 /* Before we correct the VLDB entry, make sure all the
5556 * ROs listed in the VLDB exist.
5558 code = CheckVldbRO(&entry, &mod);
5564 if (!(entry.flags & RO_EXISTS)) {
5565 /* No RO exists in the VLDB entry - add this one */
5566 idx = entry.nServers;
5569 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5570 /* The volume headers's RO ID does not match that in the VLDB entry,
5571 * and the vol hdr's ID is greater (implies more recent). So delete
5572 * all the RO volumes listed in VLDB entry and add this volume.
5574 for (j = 0; j < entry.nServers; j++) {
5575 if (entry.serverFlags[j] & ITSROVOL) {
5576 /* Verify this volume exists and print message we are orphaning it */
5578 MapPartIdIntoName(apart, pname);
5580 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5581 entry.volumeId[ROVOL],
5582 hostutil_GetNameByINet(entry.
5586 " VLDB reports its RO volume ID is %lu\n",
5587 (unsigned long)volumeinfo->volid);
5590 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5591 entry.serverPartition[idx], 0L, 0L);
5598 idx = entry.nServers;
5601 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5602 /* The volume headers's RO ID does not match that in the VLDB entry,
5603 * and the vol hdr's ID is lower (implies its older). So orphan it.
5606 MapPartIdIntoName(apart, pname);
5608 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5609 (unsigned long)volumeinfo->volid,
5610 hostutil_GetNameByINet(aserver), pname);
5612 " VLDB reports its RO volume ID is %u\n",
5613 entry.volumeId[ROVOL]);
5616 /* The RO volume ID in the volume header match that in the VLDB entry,
5617 * and there exist RO volumes in the VLDB entry. See if any of them
5618 * are this one. If not, then we add it.
5620 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5622 idx = entry.nServers;
5630 entry.flags |= RO_EXISTS;
5631 entry.volumeId[RWVOL] = rwvolid;
5632 entry.volumeId[ROVOL] = volumeinfo->volid;
5634 entry.serverNumber[idx] = aserver;
5635 entry.serverPartition[idx] = apart;
5636 entry.serverFlags[idx] = ITSROVOL;
5642 /* Remember largest volume id */
5643 if (entry.volumeId[ROVOL] > *maxvolid)
5644 *maxvolid = entry.volumeId[ROVOL];
5645 if (entry.volumeId[BACKVOL] > *maxvolid)
5646 *maxvolid = entry.volumeId[BACKVOL];
5647 if (entry.volumeId[RWVOL] > *maxvolid)
5648 *maxvolid = entry.volumeId[RWVOL];
5650 if (modified && doit) {
5651 MapNetworkToHost(&entry, &storeEntry);
5654 code = VLDB_CreateEntry(&storeEntry);
5657 "Could not create a VLDB entry for the volume %lu\n",
5658 (unsigned long)rwvolid);
5665 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5666 LOCKREL_OPCODE | LOCKREL_AFSID |
5669 fprintf(STDERR, "Could not update entry for %lu\n",
5670 (unsigned long)rwvolid);
5675 *modentry = modified;
5676 } else if (pass == 2) {
5678 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5679 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5681 PrintError("Could not unlock VLDB entry ", code);
5685 if (verbose && doit) {
5686 fprintf(STDOUT, "-- status after --\n");
5688 EnumerateEntry(&entry);
5690 fprintf(STDOUT, "\n**no change**\n");
5694 VPRINT("\n_______________________________\n");
5699 sortVolumes(const void *a, const void *b)
5701 volintInfo *v1 = (volintInfo *) a;
5702 volintInfo *v2 = (volintInfo *) b;
5703 afs_int32 rwvolid1, rwvolid2;
5705 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5706 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5708 if (rwvolid1 > rwvolid2)
5709 return -1; /* lower RW id goes first */
5710 if (rwvolid1 < rwvolid2)
5713 if (v1->type == RWVOL)
5714 return -1; /* RW vols go first */
5715 if (v2->type == RWVOL)
5718 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5719 return -1; /* BK vols next */
5720 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5723 if (v1->volid < v2->volid)
5724 return 1; /* larger volids first */
5725 if (v1->volid > v2->volid)
5731 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5732 * Synchronize an individual volume against a sever and partition.
5733 * Checks the VLDB entry (similar to syncserv) as well as checks
5734 * if the volume exists on specified servers (similar to syncvldb).
5737 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5739 struct rx_connection *aconn = 0;
5740 afs_int32 j, k, code, vcode, error = 0;
5741 afs_int32 tverbose, mod, modified = 0;
5742 struct nvldbentry vldbentry;
5743 afs_int32 volumeid = 0;
5744 volEntries volumeInfo;
5745 struct partList PartList;
5747 afs_int32 maxvolid = 0;
5749 volumeInfo.volEntries_val = (volintInfo *) 0;
5750 volumeInfo.volEntries_len = 0;
5752 if (!aserver && (flags & 1)) {
5753 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5757 /* Turn verbose logging off and do our own verbose logging */
5763 /* Read the VLDB entry */
5764 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5765 if (vcode && (vcode != VL_NOENT)) {
5766 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5769 } else if (!vcode) {
5770 MapHostToNetwork(&vldbentry);
5774 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5775 fprintf(STDOUT, "_______________________________\n");
5776 fprintf(STDOUT, "\n-- status before -- \n");
5778 fprintf(STDOUT, "\n**does not exist**\n");
5780 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5781 || (vldbentry.flags & BACK_EXISTS))
5782 EnumerateEntry(&vldbentry);
5784 fprintf(STDOUT, "\n");
5787 /* Verify that all of the VLDB entries exist on the repective servers
5788 * and partitions (this does not require that avolname be a volume ID).
5789 * Equivalent to a syncserv.
5792 /* Tell CheckVldb not to update if appropriate */
5797 code = CheckVldb(&vldbentry, &mod);
5799 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5807 /* If aserver is given, we will search for the desired volume on it */
5809 /* Generate array of partitions on the server that we will check */
5811 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5814 "Could not fetch the list of partitions from the server\n");
5818 PartList.partId[0] = apart;
5822 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5824 /* If a volume ID were given, search for it on each partition */
5825 if ((volumeid = atol(avolname))) {
5826 for (j = 0; j < pcnt; j++) {
5828 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5831 if (code != ENODEV) {
5832 fprintf(STDERR, "Could not query server\n");
5840 /* Found one, sync it with VLDB entry */
5842 CheckVolume(volumeInfo.volEntries_val, aserver,
5843 PartList.partId[j], &mod, &maxvolid);
5850 if (volumeInfo.volEntries_val)
5851 free(volumeInfo.volEntries_val);
5852 volumeInfo.volEntries_val = (volintInfo *) 0;
5853 volumeInfo.volEntries_len = 0;
5857 /* Check to see if the RW, BK, and RO IDs exist on any
5858 * partitions. We get the volume IDs from the VLDB.
5860 rv = 1; /* Read the VLDB entry ? */
5861 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5863 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5865 if (vcode == VL_NOENT)
5868 "Could not access the VLDB for volume %s\n",
5875 if (vldbentry.volumeId[j] == 0)
5878 for (k = 0; k < pcnt; k++) { /* For each partition */
5879 volumeInfo.volEntries_val = (volintInfo *) 0;
5880 volumeInfo.volEntries_len = 0;
5882 AFSVolListOneVolume(aconn, PartList.partId[k],
5883 vldbentry.volumeId[j], &volumeInfo);
5885 if (code != ENODEV) {
5886 fprintf(STDERR, "Could not query server\n");
5894 /* Found one, sync it with VLDB entry */
5896 CheckVolume(volumeInfo.volEntries_val, aserver,
5897 PartList.partId[k], &mod, &maxvolid);
5904 if (volumeInfo.volEntries_val)
5905 free(volumeInfo.volEntries_val);
5906 volumeInfo.volEntries_val = (volintInfo *) 0;
5907 volumeInfo.volEntries_len = 0;
5913 /* If verbose output, print a summary of what changed */
5914 if (tverbose && !(flags & 2)) {
5915 fprintf(STDOUT, "-- status after --\n");
5916 code = VLDB_GetEntryByName(avolname, &vldbentry);
5917 if (code && (code != VL_NOENT)) {
5918 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5922 if (modified && (code == VL_NOENT)) {
5923 fprintf(STDOUT, "\n**entry deleted**\n");
5924 } else if (modified) {
5925 EnumerateEntry(&vldbentry);
5927 fprintf(STDOUT, "\n**no change**\n");
5929 fprintf(STDOUT, "\n_______________________________\n");
5933 /* Now check if the maxvolid is larger than that stored in the VLDB */
5935 afs_int32 maxvldbid = 0;
5936 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
5939 "Could not get the highest allocated volume id from the VLDB\n");
5942 } else if (maxvolid > maxvldbid) {
5944 id = maxvolid - maxvldbid + 1;
5945 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
5948 "Error in increasing highest allocated volume id in VLDB\n");
5958 fprintf(STDOUT, "...error encountered");
5960 fprintf(STDOUT, "...done entry\n");
5963 rx_DestroyConnection(aconn);
5964 if (volumeInfo.volEntries_val)
5965 free(volumeInfo.volEntries_val);
5967 PrintError("", error);
5972 * Synchronise vldb with the file server <aserver> and,
5973 * optionally, <apart>.
5976 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5978 struct rx_connection *aconn;
5979 afs_int32 code, error = 0;
5981 volEntries volumeInfo;
5982 struct partList PartList;
5986 afs_int32 failures = 0, modifications = 0, tentries = 0;
5988 afs_uint32 maxvolid = 0;
5990 volumeInfo.volEntries_val = (volintInfo *) 0;
5991 volumeInfo.volEntries_len = 0;
5993 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5995 /* Generate array of partitions to check */
5997 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6000 "Could not fetch the list of partitions from the server\n");
6004 PartList.partId[0] = apart;
6008 VPRINT("Processing volume entries ...\n");
6010 /* Step through the array of partitions */
6011 for (i = 0; i < pcnt; i++) {
6012 apart = PartList.partId[i];
6013 MapPartIdIntoName(apart, pname);
6015 volumeInfo.volEntries_val = (volintInfo *) 0;
6016 volumeInfo.volEntries_len = 0;
6017 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6020 "Could not fetch the list of volumes from the server\n");
6024 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6025 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6026 sizeof(volintInfo), sortVolumes);
6029 for (vi = volumeInfo.volEntries_val, j = 0;
6030 j < volumeInfo.volEntries_len; j++, vi++) {
6038 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6039 j + 1, vi->name, (unsigned long)vi->volid,
6040 hostutil_GetNameByINet(aserver), pname);
6048 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
6050 PrintError("", code);
6053 } else if (modified) {
6059 fprintf(STDOUT, "...error encountered\n\n");
6061 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6068 "Could not process entries on server %s partition %s\n",
6069 hostutil_GetNameByINet(aserver), pname);
6071 if (volumeInfo.volEntries_val) {
6072 free(volumeInfo.volEntries_val);
6073 volumeInfo.volEntries_val = 0;
6076 } /* thru all partitions */
6079 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6080 tentries, failures, modifications);
6082 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6083 tentries, failures, modifications);
6087 /* Now check if the maxvolid is larger than that stored in the VLDB */
6089 afs_int32 maxvldbid = 0;
6090 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6093 "Could not get the highest allocated volume id from the VLDB\n");
6096 } else if (maxvolid > maxvldbid) {
6098 id = maxvolid - maxvldbid + 1;
6099 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6102 "Error in increasing highest allocated volume id in VLDB\n");
6110 rx_DestroyConnection(aconn);
6111 if (volumeInfo.volEntries_val)
6112 free(volumeInfo.volEntries_val);
6113 PrintError("", error);
6118 * Determine if a volume exists on a server and partition.
6119 * Try creating a transaction on the volume. If we can,
6120 * the volume exists, if not, then return the error code.
6121 * Some error codes mean the volume is unavailable but
6122 * still exists - so we catch these error codes.
6125 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
6127 struct rx_connection *conn = (struct rx_connection *)0;
6128 afs_int32 code = -1;
6129 volEntries volumeInfo;
6131 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6133 volumeInfo.volEntries_val = (volintInfo *) 0;
6134 volumeInfo.volEntries_len = 0;
6135 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6136 if (volumeInfo.volEntries_val)
6137 free(volumeInfo.volEntries_val);
6138 if (code == VOLSERILLEGAL_PARTITION)
6140 rx_DestroyConnection(conn);
6149 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6153 afs_int32 code, error = 0;
6158 idx = Lp_GetRwIndex(entry);
6160 /* Check to see if the RW volume exists and set the RW_EXISTS
6163 if (idx == -1) { /* Did not find a RW entry */
6164 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6165 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6170 VolumeExists(entry->serverNumber[idx],
6171 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6172 if (code == 0) { /* RW volume exists */
6173 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6174 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6177 } else if (code == ENODEV) { /* RW volume does not exist */
6178 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6179 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6183 /* If VLDB says it didn't exist, then ignore error */
6184 if (entry->flags & RW_EXISTS) {
6185 MapPartIdIntoName(entry->serverPartition[idx], pname);
6187 "Transaction call failed for RW volume %u on server %s %s\n",
6188 entry->volumeId[RWVOL],
6189 hostutil_GetNameByINet(entry->serverNumber[idx]),
6196 /* Check to see if the BK volume exists and set the BACK_EXISTS
6197 * flag accordingly. idx already ponts to the RW entry.
6199 if (idx == -1) { /* Did not find a RW entry */
6200 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6201 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6204 } else { /* Found a RW entry */
6206 VolumeExists(entry->serverNumber[idx],
6207 entry->serverPartition[idx],
6208 entry->volumeId[BACKVOL]);
6209 if (code == 0) { /* BK volume exists */
6210 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6211 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6214 } else if (code == ENODEV) { /* BK volume does not exist */
6215 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6216 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6220 /* If VLDB says it didn't exist, then ignore error */
6221 if (entry->flags & BACK_EXISTS) {
6222 MapPartIdIntoName(entry->serverPartition[idx], pname);
6224 "Transaction call failed for BK volume %u on server %s %s\n",
6225 entry->volumeId[BACKVOL],
6226 hostutil_GetNameByINet(entry->serverNumber[idx]),
6233 /* If there is an idx but the BK and RW volumes no
6234 * longer exist, then remove the RW entry.
6236 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6237 && !(entry->flags & BACK_EXISTS)) {
6238 Lp_SetRWValue(entry, entry->serverNumber[idx],
6239 entry->serverPartition[idx], 0L, 0L);
6246 *modified = modentry;
6251 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6254 int foundro = 0, modentry = 0;
6255 afs_int32 code, error = 0;
6261 /* Check to see if the RO volumes exist and set the RO_EXISTS
6264 for (idx = 0; idx < entry->nServers; idx++) {
6265 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6266 continue; /* not a RO */
6270 VolumeExists(entry->serverNumber[idx],
6271 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6272 if (code == 0) { /* RO volume exists */
6274 } else if (code == ENODEV) { /* RW volume does not exist */
6275 Lp_SetROValue(entry, entry->serverNumber[idx],
6276 entry->serverPartition[idx], 0L, 0L);
6281 MapPartIdIntoName(entry->serverPartition[idx], pname);
6283 "Transaction call failed for RO %u on server %s %s\n",
6284 entry->volumeId[ROVOL],
6285 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6290 if (foundro) { /* A RO volume exists */
6291 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6292 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6295 } else { /* A RO volume does not exist */
6296 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6297 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6304 *modified = modentry;
6309 * Ensure that <entry> matches with the info on file servers
6312 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6314 afs_int32 code, error = 0;
6315 struct nvldbentry storeEntry;
6316 int islocked = 0, mod, modentry, delentry = 0;
6317 int pass = 0, doit=1;
6325 fprintf(STDOUT, "_______________________________\n");
6326 fprintf(STDOUT, "\n-- status before -- \n");
6327 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6328 || (entry->flags & BACK_EXISTS))
6329 EnumerateEntry(entry);
6330 fprintf(STDOUT, "\n");
6333 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6334 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6335 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6339 /* Check to see if the VLDB is ok without locking it (pass 1).
6340 * If it will change, then lock the VLDB entry, read it again,
6341 * then make the changes to it (pass 2).
6345 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6348 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6349 entry->volumeId[RWVOL]);
6354 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6356 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6360 MapHostToNetwork(entry);
6366 /* Check if the RW and BK entries are ok */
6367 code = CheckVldbRWBK(entry, &mod);
6370 if (mod && (pass == 1) && doit)
6375 /* Check if the RO volumes entries are ok */
6376 code = CheckVldbRO(entry, &mod);
6379 if (mod && (pass == 1) && doit)
6384 /* The VLDB entry has been updated. If it as been modified, then
6385 * write the entry back out the the VLDB.
6387 if (modentry && doit) {
6391 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6392 && !(entry->flags & RO_EXISTS) && doit) {
6393 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6395 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6399 "Could not delete VLDB entry for volume %u \n",
6400 entry->volumeId[RWVOL]);
6405 /* Replace old entry with our new one */
6406 MapNetworkToHost(entry, &storeEntry);
6408 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6409 (LOCKREL_OPCODE | LOCKREL_AFSID |
6410 LOCKREL_TIMESTAMP));
6412 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6413 entry->volumeId[RWVOL]);
6422 if (verbose && doit) {
6423 fprintf(STDOUT, "-- status after --\n");
6425 fprintf(STDOUT, "\n**entry deleted**\n");
6427 EnumerateEntry(entry);
6429 fprintf(STDOUT, "\n**no change**\n");
6433 VPRINT("\n_______________________________\n");
6437 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6439 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6442 "Could not release lock on VLDB entry for volume %u\n",
6443 entry->volumeId[RWVOL]);
6452 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6455 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6457 struct rx_connection *aconn;
6458 afs_int32 code, error = 0;
6459 afs_int32 nentries, tentries = 0;
6460 struct VldbListByAttributes attributes;
6461 nbulkentries arrayEntries;
6462 afs_int32 failures = 0, modified, modifications = 0;
6463 struct nvldbentry *vlentry;
6464 afs_int32 si, nsi, j;
6469 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6471 /* Set up attributes to search VLDB */
6472 attributes.server = ntohl(aserver);
6473 attributes.Mask = VLLIST_SERVER;
6475 attributes.partition = apart;
6476 attributes.Mask |= VLLIST_PARTITION;
6479 VPRINT("Processing VLDB entries ...\n");
6481 /* While we need to collect more VLDB entries */
6482 for (si = 0; si != -1; si = nsi) {
6483 memset(&arrayEntries, 0, sizeof(arrayEntries));
6485 /* Collect set of VLDB entries */
6487 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6488 &arrayEntries, &nsi);
6489 if (code == RXGEN_OPCODE) {
6490 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6494 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6497 tentries += nentries;
6499 for (j = 0; j < nentries; j++) {
6500 vlentry = &arrayEntries.nbulkentries_val[j];
6501 MapHostToNetwork(vlentry);
6503 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6505 /* Tell CheckVldb not to update if appropriate */
6510 code = CheckVldb(vlentry, &modified);
6512 PrintError("", code);
6514 "Could not process VLDB entry for volume %s\n",
6517 } else if (modified) {
6523 fprintf(STDOUT, "...error encountered\n\n");
6525 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6530 if (arrayEntries.nbulkentries_val) {
6531 free(arrayEntries.nbulkentries_val);
6532 arrayEntries.nbulkentries_val = 0;
6537 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6538 tentries, failures, modifications);
6540 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6541 tentries, failures, modifications);
6546 rx_DestroyConnection(aconn);
6547 if (arrayEntries.nbulkentries_val)
6548 free(arrayEntries.nbulkentries_val);
6551 error = VOLSERFAILEDOP;
6555 /*rename volume <oldname> to <newname>, changing the names of the related
6556 *readonly and backup volumes. This operation is also idempotent.
6557 *salvager is capable of recovering from rename operation stopping halfway.
6558 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6560 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6562 struct nvldbentry storeEntry;
6563 afs_int32 vcode, code, rcode, error;
6565 char nameBuffer[256];
6567 struct rx_connection *aconn;
6571 aconn = (struct rx_connection *)0;
6575 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6578 " Could not lock the VLDB entry for the volume %u \n",
6579 entry->volumeId[RWVOL]);
6584 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6585 MapNetworkToHost(entry, &storeEntry);
6586 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6588 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6589 entry->volumeId[RWVOL]);
6593 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6594 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6595 * is concerned, oldname is lost */
6596 if (entry->flags & RW_EXISTS) {
6597 index = Lp_GetRwIndex(entry);
6598 if (index == -1) { /* there is a serious discrepancy */
6600 "There is a serious discrepancy in VLDB entry for volume %u\n",
6601 entry->volumeId[RWVOL]);
6602 fprintf(STDERR, "try building VLDB from scratch\n");
6603 error = VOLSERVLDB_ERROR;
6606 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6608 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6609 entry->serverPartition[index], ITOffline, &tid);
6610 if (code) { /*volume doesnot exist */
6612 "Could not start transaction on the rw volume %u\n",
6613 entry->volumeId[RWVOL]);
6616 } else { /*volume exists, process it */
6619 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6620 entry->volumeId[RWVOL],
6621 entry->volumeId[ROVOL],
6622 entry->volumeId[BACKVOL]);
6624 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6625 code = AFSVolEndTrans(aconn, tid, &rcode);
6629 "Could not end transaction on volume %s %u\n",
6630 entry->name, entry->volumeId[RWVOL]);
6635 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6636 entry->name, entry->volumeId[RWVOL]);
6642 rx_DestroyConnection(aconn);
6643 aconn = (struct rx_connection *)0;
6645 /*end rw volume processing */
6646 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6647 index = Lp_GetRwIndex(entry);
6648 if (index == -1) { /* there is a serious discrepancy */
6650 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6651 entry->volumeId[BACKVOL]);
6652 fprintf(STDERR, "try building VLDB from scratch\n");
6653 error = VOLSERVLDB_ERROR;
6656 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6658 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6659 entry->serverPartition[index], ITOffline, &tid);
6660 if (code) { /*volume doesnot exist */
6662 "Could not start transaction on the backup volume %u\n",
6663 entry->volumeId[BACKVOL]);
6666 } else { /*volume exists, process it */
6667 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6669 "Volume name %s.backup exceeds the limit of %u characters\n",
6670 newname, VOLSER_OLDMAXVOLNAME);
6674 strcpy(nameBuffer, newname);
6675 strcat(nameBuffer, ".backup");
6678 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6679 entry->volumeId[RWVOL], 0, 0);
6681 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6682 code = AFSVolEndTrans(aconn, tid, &rcode);
6686 "Could not end transaction on the backup volume %u\n",
6687 entry->volumeId[BACKVOL]);
6693 "Could not set parameters on the backup volume %u\n",
6694 entry->volumeId[BACKVOL]);
6699 } /* end backup processing */
6701 rx_DestroyConnection(aconn);
6702 aconn = (struct rx_connection *)0;
6703 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6704 for (i = 0; i < entry->nServers; i++) {
6705 if (entry->serverFlags[i] & ITSROVOL) {
6706 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6708 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6709 entry->serverPartition[i], ITOffline,
6711 if (code) { /*volume doesnot exist */
6713 "Could not start transaction on the ro volume %u\n",
6714 entry->volumeId[ROVOL]);
6717 } else { /*volume exists, process it */
6718 strcpy(nameBuffer, newname);
6719 strcat(nameBuffer, ".readonly");
6720 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6722 "Volume name %s exceeds the limit of %u characters\n",
6723 nameBuffer, VOLSER_OLDMAXVOLNAME);
6728 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6729 entry->volumeId[RWVOL], 0, 0);
6731 VPRINT2("Renamed RO volume %s on host %s\n",
6733 hostutil_GetNameByINet(entry->
6735 code = AFSVolEndTrans(aconn, tid, &rcode);
6739 "Could not end transaction on volume %u\n",
6740 entry->volumeId[ROVOL]);
6746 "Could not set parameters on the ro volume %u\n",
6747 entry->volumeId[ROVOL]);
6753 rx_DestroyConnection(aconn);
6754 aconn = (struct rx_connection *)0;
6761 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6763 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6766 "Could not unlock the VLDB entry for the volume %s %u\n",
6767 entry->name, entry->volumeId[RWVOL]);
6773 code = AFSVolEndTrans(aconn, tid, &rcode);
6777 fprintf(STDERR, "Failed to end transaction on a volume \n");
6783 rx_DestroyConnection(aconn);
6784 PrintError("", error);
6789 /*report on all the active transactions on volser */
6791 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6793 struct rx_connection *aconn;
6794 transDebugEntries transInfo;
6797 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6798 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6799 transInfo.transDebugEntries_len = 0;
6800 code = AFSVolMonitor(aconn, &transInfo);
6803 "Could not access status information about the server\n");
6804 PrintError("", code);
6805 if (transInfo.transDebugEntries_val)
6806 free(transInfo.transDebugEntries_val);
6808 rx_DestroyConnection(aconn);
6811 *rcount = transInfo.transDebugEntries_len;
6812 *rpntr = transInfo.transDebugEntries_val;
6814 rx_DestroyConnection(aconn);
6821 /*delete the volume without interacting with the vldb */
6823 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6825 afs_int32 rcode, ttid, error, code;
6826 struct rx_connection *aconn;
6832 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6833 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6835 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6836 (unsigned long)volid);
6840 code = AFSVolDeleteVolume(aconn, ttid);
6842 fprintf(STDERR, "Could not delete volume %lu\n",
6843 (unsigned long)volid);
6847 code = AFSVolEndTrans(aconn, ttid, &rcode);
6852 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6853 (unsigned long)volid);
6859 code = AFSVolEndTrans(aconn, ttid, &rcode);
6865 PrintError("", error);
6867 rx_DestroyConnection(aconn);
6872 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6873 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6875 struct rx_connection *conn = 0;
6877 afs_int32 code, error = 0, rcode;
6879 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6881 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6885 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6887 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6891 code = AFSVolSetFlags(conn, tid, setflag);
6893 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6898 #ifdef AFS_PTHREAD_ENV
6901 IOMGR_Sleep(sleeptime);
6908 code = AFSVolEndTrans(conn, tid, &rcode);
6909 if (code || rcode) {
6910 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6912 error = (code ? code : rcode);
6917 rx_DestroyConnection(conn);
6922 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6925 struct rx_connection *conn = 0;
6927 afs_int32 code, error = 0, rcode;
6929 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6931 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6935 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6937 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6941 code = AFSVolSetInfo(conn, tid, infop);
6943 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6950 code = AFSVolEndTrans(conn, tid, &rcode);
6951 if (code || rcode) {
6952 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6954 error = (code ? code : rcode);
6959 rx_DestroyConnection(conn);
6964 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6965 afs_int32 fromdate, struct volintSize *vol_size)
6967 struct rx_connection *aconn = (struct rx_connection *)0;
6968 afs_int32 tid = 0, rcode = 0;
6969 afs_int32 code, error = 0;
6972 /* get connections to the servers */
6973 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6975 VPRINT1("Starting transaction on volume %u...", afromvol);
6976 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6977 EGOTO1(error_exit, code,
6978 "Could not start transaction on the volume %u to be measured\n",
6982 VPRINT1("Getting size of volume on volume %u...", afromvol);
6983 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6984 EGOTO(error_exit, code, "Could not start the measurement process \n");
6989 VPRINT1("Ending transaction on volume %u...", afromvol);
6990 code = AFSVolEndTrans(aconn, tid, &rcode);
6991 if (code || rcode) {
6992 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6994 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6996 error = (code ? code : rcode);
7001 rx_DestroyConnection(aconn);
7003 PrintError("", error);
7007 /*maps the host addresses in <old > (present in network byte order) to
7008 that in< new> (present in host byte order )*/
7010 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7014 /*copy all the fields */
7015 strcpy(new->name, old->name);
7016 /* new->volumeType = old->volumeType;*/
7017 new->nServers = old->nServers;
7018 count = old->nServers;
7019 if (count < NMAXNSERVERS)
7021 for (i = 0; i < count; i++) {
7022 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7023 new->serverPartition[i] = old->serverPartition[i];
7024 new->serverFlags[i] = old->serverFlags[i];
7026 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7027 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7028 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7029 new->cloneId = old->cloneId;
7030 new->flags = old->flags;
7033 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7035 MapHostToNetwork(struct nvldbentry *entry)
7039 count = entry->nServers;
7040 if (count < NMAXNSERVERS)
7042 for (i = 0; i < count; i++) {
7043 entry->serverNumber[i] = htonl(entry->serverNumber[i]);