2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
19 #include <sys/statfs.h>
26 #include <netinet/in.h>
30 #include <afs/voldefs.h>
33 #include <afs/vlserver.h>
35 #include <afs/cellconfig.h>
38 #include <afs/afsint.h>
42 #include <afs/com_err.h>
44 #include <afs/kautils.h>
47 #define ERRCODE_RANGE 8 /* from error_table.h */
48 #define CLOCKSKEW 2 /* not really skew, but resolution */
49 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
51 /* for UV_MoveVolume() recovery */
53 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
56 #include "volser_prototypes.h"
57 #include "vsutils_prototypes.h"
58 #include "lockprocs_prototypes.h"
60 struct ubik_client *cstruct;
61 int verbose = 0, noresolve = 0;
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_uint32 okvol,
165 static int DelVol(struct rx_connection *conn, afs_uint32 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,
450 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
451 afs_int32 partition, char *name, afs_int32 type,
452 afs_int32 parent, afs_int32 *volid, afs_int32 *trans)
457 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
459 if (code != VOLSERVOLBUSY)
462 #ifdef AFS_PTHREAD_ENV
465 IOMGR_Sleep(3-retries);
472 AFSVolTransCreate_retry(struct rx_connection *z_conn,
473 afs_int32 volume, afs_int32 partition,
474 afs_int32 flags, afs_int32 * trans)
479 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
480 if (code != VOLSERVOLBUSY)
483 #ifdef AFS_PTHREAD_ENV
486 IOMGR_Sleep(3-retries);
492 /* if <okvol> is allright(indicated by beibg able to
493 * start a transaction, delete the <delvol> */
495 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
496 afs_uint32 okvol, afs_uint32 delvol)
498 afs_int32 error, code, tid, rcode;
503 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
506 code = AFSVolDeleteVolume(aconn, tid);
509 code = AFSVolEndTrans(aconn, tid, &rcode);
516 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
518 code = AFSVolEndTrans(aconn, tid, &rcode);
523 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
526 code = AFSVolDeleteVolume(aconn, tid);
529 code = AFSVolEndTrans(aconn, tid, &rcode);
540 /* called by EmuerateEntry, show vldb entry in a reasonable format */
542 SubEnumerateEntry(struct nvldbentry *entry)
550 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
551 if (entry->flags & RW_EXISTS)
552 fprintf(STDOUT, " valid \n");
554 fprintf(STDOUT, " invalid \n");
555 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
556 if (entry->flags & RO_EXISTS)
557 fprintf(STDOUT, " valid \n");
559 fprintf(STDOUT, " invalid \n");
560 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
561 if (entry->flags & BACK_EXISTS)
562 fprintf(STDOUT, " valid \n");
564 fprintf(STDOUT, " invalid \n");
565 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
566 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
568 if (entry->flags & RW_EXISTS)
569 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
570 if (entry->flags & RO_EXISTS)
571 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
572 if (entry->flags & BACK_EXISTS)
573 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
574 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
575 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
576 fprintf(STDOUT, "\n");
578 fprintf(STDOUT, " number of sites -> %lu\n",
579 (unsigned long)entry->nServers);
580 for (i = 0; i < entry->nServers; i++) {
581 if (entry->serverFlags[i] & NEW_REPSITE)
584 for (i = 0; i < entry->nServers; i++) {
585 MapPartIdIntoName(entry->serverPartition[i], pname);
586 fprintf(STDOUT, " server %s partition %s ",
587 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
588 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
589 if (entry->serverFlags[i] & ITSRWVOL)
590 fprintf(STDOUT, "RW Site ");
592 fprintf(STDOUT, "RO Site ");
594 if (entry->serverFlags[i] & NEW_REPSITE)
595 fprintf(STDOUT," -- New release");
597 if (!(entry->serverFlags[i] & ITSRWVOL))
598 fprintf(STDOUT," -- Old release");
600 if (entry->serverFlags[i] & RO_DONTUSE)
601 fprintf(STDOUT, " -- Not released");
603 fprintf(STDOUT, "\n");
610 /*enumerate the vldb entry corresponding to <entry> */
612 EnumerateEntry(struct nvldbentry *entry)
615 fprintf(STDOUT, "\n");
616 fprintf(STDOUT, "%s \n", entry->name);
617 SubEnumerateEntry(entry);
621 /* forcibly remove a volume. Very dangerous call */
623 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_uint32 volid)
625 register struct rx_connection *tconn;
626 register afs_int32 code;
628 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
630 code = AFSVolNukeVolume(tconn, partid, volid);
631 rx_DestroyConnection(tconn);
637 /* like df. Return usage of <pname> on <server> in <partition> */
639 UV_PartitionInfo64(afs_int32 server, char *pname,
640 struct diskPartition64 *partition)
642 register struct rx_connection *aconn;
645 aconn = (struct rx_connection *)0;
646 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
647 code = AFSVolPartitionInfo64(aconn, pname, partition);
648 if (code == RXGEN_OPCODE) {
649 struct diskPartition *dpp =
650 (struct diskPartition *)malloc(sizeof(struct diskPartition));
651 code = AFSVolPartitionInfo(aconn, pname, dpp);
653 strncpy(partition->name, dpp->name, 32);
654 strncpy(partition->devName, dpp->devName, 32);
655 partition->lock_fd = dpp->lock_fd;
656 partition->free = dpp->free;
657 partition->minFree = dpp->minFree;
662 fprintf(STDERR, "Could not get information on partition %s\n", pname);
663 PrintError("", code);
666 rx_DestroyConnection(aconn);
670 /* old interface to create volume */
672 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
676 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
680 /* create a volume, given a server, partition number, volume name --> sends
681 * back new vol id in <anewid>*/
683 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
684 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
685 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
687 register struct rx_connection *aconn;
689 register afs_int32 code;
691 afs_int32 rcode, vcode;
692 struct nvldbentry entry, storeEntry; /*the new vldb entry */
693 struct volintInfo tstatus;
696 aconn = (struct rx_connection *)0;
699 init_volintInfo(&tstatus);
700 tstatus.maxquota = aquota;
702 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
703 /* next the next 3 available ids from the VLDB */
704 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 3, anewid);
705 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
707 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
708 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
711 code = AFSVolSetInfo(aconn, tid, &tstatus);
713 EPRINT(code, "Could not change quota, continuing...\n");
715 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
716 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
719 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
721 /* set up the vldb entry for this volume */
722 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
724 entry.serverNumber[0] = aserver; /* this should have another
725 * level of indirection later */
726 entry.serverPartition[0] = apart; /* this should also have
727 * another indirection level */
728 entry.flags = RW_EXISTS; /* this records that rw volume exists */
729 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
730 entry.volumeId[RWVOL] = *anewid;
731 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
732 entry.volumeId[BACKVOL] = *anewid + 2;
734 /*map into right byte order, before passing to xdr, the stuff has to be in host
735 * byte order. Xdr converts it into network order */
736 MapNetworkToHost(&entry, &storeEntry);
737 /* create the vldb entry */
738 vcode = VLDB_CreateEntry(&storeEntry);
741 "Could not create a VLDB entry for the volume %s %lu\n",
742 aname, (unsigned long)*anewid);
743 /*destroy the created volume */
744 VPRINT1("Deleting the newly created volume %u\n", *anewid);
745 AFSVolDeleteVolume(aconn, tid);
749 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
750 /* volume created, now terminate the transaction and release the connection */
751 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
752 * the volume will come online anyway when transaction timesout , so if
753 * vldb entry exists then the volume is guaranteed to exist too wrt create */
757 "Failed to end the transaction on the volume %s %lu\n", aname,
758 (unsigned long)*anewid);
765 code = AFSVolEndTrans(aconn, tid, &rcode);
767 fprintf(STDERR, "WARNING: could not end transaction\n");
770 rx_DestroyConnection(aconn);
771 PrintError("", error);
775 /* create a volume, given a server, partition number, volume name --> sends
776 * back new vol id in <anewid>*/
778 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
781 register struct rx_connection *aconn;
784 struct nvldbentry entry, storeEntry; /*the new vldb entry */
786 aconn = (struct rx_connection *)0;
789 /* set up the vldb entry for this volume */
790 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
792 entry.serverNumber[0] = aserver; /* this should have another
793 * level of indirection later */
794 entry.serverPartition[0] = apart; /* this should also have
795 * another indirection level */
796 entry.flags = RW_EXISTS; /* this records that rw volume exists */
797 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
798 entry.volumeId[RWVOL] = aid;
800 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
801 entry.volumeId[BACKVOL] = *anewid + 2;
803 entry.volumeId[ROVOL] = 0;
804 entry.volumeId[BACKVOL] = 0;
807 /*map into right byte order, before passing to xdr, the stuff has to be in host
808 * byte order. Xdr converts it into network order */
809 MapNetworkToHost(&entry, &storeEntry);
810 /* create the vldb entry */
811 vcode = VLDB_CreateEntry(&storeEntry);
814 "Could not create a VLDB entry for the volume %s %lu\n",
815 aname, (unsigned long)aid);
819 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
823 rx_DestroyConnection(aconn);
824 PrintError("", error);
828 /* Delete the volume <volid>on <aserver> <apart>
829 * the physical entry gets removed from the vldb only if the ref count
833 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
835 struct rx_connection *aconn = (struct rx_connection *)0;
837 afs_int32 code, rcode;
839 struct nvldbentry entry, storeEntry;
841 afs_int32 avoltype = -1, vtype;
842 int notondisk = 0, notinvldb = 0;
844 /* Find and read bhe VLDB entry for this volume */
845 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
847 if (code != VL_NOENT) {
848 EGOTO1(error_exit, code,
849 "Could not lock VLDB entry for the volume %u\n", avolid);
855 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
856 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
858 MapHostToNetwork(&entry);
861 EnumerateEntry(&entry);
864 /* Whether volume is in the VLDB or not. Delete the volume on disk */
865 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
866 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
868 if (code == VNOVOL) {
871 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
875 VPRINT1("Trying to delete the volume %u ...", avolid);
877 code = AFSVolDeleteVolume(aconn, ttid);
878 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
880 code = AFSVolEndTrans(aconn, ttid, &rcode);
881 code = (code ? code : rcode);
883 EGOTO1(error_exit, code,
884 "Could not end the transaction for the volume %u \n", avolid);
888 /* Now update the VLDB entry.
889 * But first, verify we have a VLDB entry.
890 * Whether volume is on disk or not. Delete the volume in VLDB.
895 if (avolid == entry.volumeId[BACKVOL]) {
896 /* Its a backup volume, modify the VLDB entry. Check that the
897 * backup volume is on the server/partition we asked to delete.
899 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
900 notinvldb = 2; /* Not on this server and partition */
904 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
906 entry.flags &= ~BACK_EXISTS;
910 else if (avolid == entry.volumeId[ROVOL]) {
911 /* Its a read-only volume, modify the VLDB entry. Check that the
912 * readonly volume is on the server/partition we asked to delete.
913 * If flags does not have RO_EIXSTS set, then this may mean the RO
914 * hasn't been released (and could exist in VLDB).
916 if (!Lp_ROMatch(aserver, apart, &entry)) {
917 notinvldb = 2; /* Not found on this server and partition */
923 "Marking the readonly volume %lu deleted in the VLDB\n",
924 (unsigned long)avolid);
926 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
928 if (!Lp_ROMatch(0, 0, &entry))
929 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
933 else if (avolid == entry.volumeId[RWVOL]) {
934 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
935 * Check that the readwrite volumes is on the server/partition we
938 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
939 notinvldb = 2; /* Not found on this server and partition */
943 /* Delete backup if it exists */
945 AFSVolTransCreate_retry(aconn, entry.volumeId[BACKVOL], apart,
950 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
951 entry.volumeId[BACKVOL]);
954 code = AFSVolDeleteVolume(aconn, ttid);
955 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
956 entry.volumeId[BACKVOL]);
958 code = AFSVolEndTrans(aconn, ttid, &rcode);
960 code = (code ? code : rcode);
961 EGOTO1(error_exit, code,
962 "Could not end the transaction for the volume %u \n",
963 entry.volumeId[BACKVOL]);
965 fprintf(STDOUT, " done\n");
970 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
971 (unsigned long)avolid,
973 flags & BACK_EXISTS) ? ", and its backup volume," :
976 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
978 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
981 if (entry.flags & RO_EXISTS)
982 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
986 notinvldb = 2; /* Not found on this server and partition */
990 /* Either delete or replace the VLDB entry */
991 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
994 "Last reference to the VLDB entry for %lu - deleting entry\n",
995 (unsigned long)avolid);
996 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
997 EGOTO1(error_exit, code,
998 "Could not delete the VLDB entry for the volume %u \n",
1001 MapNetworkToHost(&entry, &storeEntry);
1003 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1004 (LOCKREL_OPCODE | LOCKREL_AFSID |
1005 LOCKREL_TIMESTAMP));
1006 EGOTO1(error_exit, code,
1007 "Could not update the VLDB entry for the volume %u \n",
1014 EPRINT(error, "\n");
1016 if (notondisk && notinvldb) {
1017 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1018 ((notinvldb == 2) ? "on server and partition" : ""));
1020 error = VOLSERNOVOL;
1021 } else if (notondisk) {
1023 "WARNING: Volume %lu did not exist on the partition\n",
1024 (unsigned long)avolid);
1025 } else if (notinvldb) {
1026 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1027 (unsigned long)avolid,
1028 ((notinvldb == 2) ? "on server and partition" : ""));
1032 code = AFSVolEndTrans(aconn, ttid, &rcode);
1033 code = (code ? code : rcode);
1035 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1036 (unsigned long)avolid);
1037 PrintError("", code);
1045 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1046 (LOCKREL_OPCODE | LOCKREL_AFSID |
1047 LOCKREL_TIMESTAMP));
1050 "Could not release the lock on the VLDB entry for the volume %u \n",
1058 rx_DestroyConnection(aconn);
1062 /* add recovery to UV_MoveVolume */
1064 #define TESTC 0 /* set to test recovery code, clear for production */
1070 sigint_handler(int x)
1075 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1077 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1078 fprintf(STDOUT, "enter second control-c to exit\n");
1082 (void)signal(SIGINT, sigint_handler);
1087 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1088 * <atopart>. The operation is almost idempotent. The following
1089 * flags are recognized:
1091 * RV_NOCLONE - don't use a copy clone
1095 UV_MoveVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1096 afs_int32 atoserver, afs_int32 atopart, int flags)
1098 struct rx_connection *toconn, *fromconn;
1099 afs_int32 fromtid, totid, clonetid;
1102 char tmpName[VOLSER_MAXVOLNAME + 1];
1105 struct restoreCookie cookie;
1106 register afs_int32 vcode, code;
1107 afs_uint32 newVol, volid, backupId;
1108 struct volser_status tstatus;
1109 struct destServer destination;
1111 struct nvldbentry entry, storeEntry;
1112 int i, islocked, pntg;
1114 char in, lf; /* for test code */
1118 #ifdef ENABLE_BUGFIX_1165
1119 volEntries volumeInfo;
1120 struct volintInfo *infop = 0;
1124 fromconn = (struct rx_connection *)0;
1125 toconn = (struct rx_connection *)0;
1135 /* support control-c processing */
1138 (void)signal(SIGINT, sigint_handler);
1142 "\nThere are three tests points - verifies all code paths through recovery.\n");
1143 fprintf(STDOUT, "First test point - operation not started.\n");
1144 fprintf(STDOUT, "...test here (y, n)? ");
1146 fscanf(stdin, "%c", &in);
1147 fscanf(stdin, "%c", &lf); /* toss away */
1149 fprintf(STDOUT, "type control-c\n");
1151 fprintf(stdout, ".");
1156 /* or drop through */
1159 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1160 EGOTO1(mfail, vcode,
1161 "Could not fetch the entry for the volume %u from the VLDB \n",
1164 if (entry.volumeId[RWVOL] != afromvol) {
1165 fprintf(STDERR, "Only RW volume can be moved\n");
1169 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1170 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1173 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1174 EGOTO1(mfail, vcode,
1175 "Could not fetch the entry for the volume %u from the VLDB \n",
1178 backupId = entry.volumeId[BACKVOL];
1179 MapHostToNetwork(&entry);
1181 if (!Lp_Match(afromserver, afrompart, &entry)) {
1182 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1183 if (!Lp_Match(atoserver, atopart, &entry)) {
1184 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1185 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1186 (unsigned long)afromvol);
1187 fprintf(STDERR, "The current site is :");
1188 for (i = 0; i < entry.nServers; i++) {
1189 if (entry.serverFlags[i] == ITSRWVOL) {
1191 MapPartIdIntoName(entry.serverPartition[i], pname);
1192 fprintf(STDERR, " server %s partition %s \n",
1193 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1194 hostutil_GetNameByINet(entry.serverNumber[i]),
1199 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1200 (LOCKREL_OPCODE | LOCKREL_AFSID |
1201 LOCKREL_TIMESTAMP));
1202 EGOTO1(mfail, vcode,
1203 " Could not release lock on the VLDB entry for the volume %u \n",
1206 return VOLSERVOLMOVED;
1209 /* delete the volume afromvol on src_server */
1210 /* from-info does not exist but to-info does =>
1211 * we have already done the move, but the volume
1212 * may still be existing physically on from fileserver
1214 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1219 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITOffline,
1222 if (!code) { /* volume exists - delete it */
1223 VPRINT1("Setting flags on leftover source volume %u ...",
1226 AFSVolSetFlags(fromconn, fromtid,
1227 VTDeleteOnSalvage | VTOutOfService);
1229 "Failed to set flags on the leftover source volume %u\n",
1233 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1234 code = AFSVolDeleteVolume(fromconn, fromtid);
1236 "Failed to delete the leftover source volume %u\n",
1240 VPRINT1("Ending transaction on leftover source volume %u ...",
1242 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1247 "Could not end the transaction for the leftover source volume %u \n",
1252 /*delete the backup volume now */
1255 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
1258 if (!code) { /* backup volume exists - delete it */
1259 VPRINT1("Setting flags on leftover backup volume %u ...",
1262 AFSVolSetFlags(fromconn, fromtid,
1263 VTDeleteOnSalvage | VTOutOfService);
1265 "Failed to set flags on the backup volume %u\n", backupId);
1268 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1269 code = AFSVolDeleteVolume(fromconn, fromtid);
1271 "Could not delete the leftover backup volume %u\n",
1275 VPRINT1("Ending transaction on leftover backup volume %u ...",
1277 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1282 "Could not end the transaction for the leftover backup volume %u\n",
1292 /* From-info matches the vldb info about volid,
1293 * its ok start the move operation, the backup volume
1294 * on the old site is deleted in the process
1296 if (afrompart == atopart) {
1297 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1298 EGOTO2(mfail, error,
1299 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1300 afromserver, error);
1303 EGOTO1(mfail, VOLSERVOLMOVED,
1304 "Warning: Moving volume %u to its home partition ignored!\n",
1310 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1311 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1312 fromtid = totid = 0; /* initialize to uncreated */
1315 * clone the read/write volume locally.
1318 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1319 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1320 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1324 if (!(flags & RV_NOCLONE)) {
1325 /* Get a clone id */
1326 VPRINT1("Allocating new volume id for clone of volume %u ...",
1329 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1330 EGOTO1(mfail, vcode,
1331 "Could not get an ID for the clone of volume %u from the VLDB\n",
1335 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1336 VPRINT1("Cloning source volume %u ...", afromvol);
1337 strcpy(vname, "move-clone-temp");
1339 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1340 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1345 /* lookup the name of the volume we just cloned */
1347 code = AFSVolGetName(fromconn, fromtid, &volName);
1348 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1351 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1353 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1358 "Failed to end the transaction on the source volume %u\n",
1363 * Create the destination volume
1366 if (!(flags & RV_NOCLONE)) {
1367 /* All of this is to get the fromDate */
1368 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1370 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1373 "Failed to start a transaction on the cloned volume%u\n",
1377 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1379 AFSVolSetFlags(fromconn, clonetid,
1380 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1381 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1385 /* remember time from which we've dumped the volume */
1386 VPRINT1("Getting status of cloned volume %u ...", newVol);
1387 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1389 "Failed to get the status of the cloned volume %u\n",
1393 fromDate = CLOCKADJ(tstatus.creationDate);
1395 /* With RV_NOCLONE, just do a full copy from the source */
1400 #ifdef ENABLE_BUGFIX_1165
1402 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1403 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1404 * don't use this information...
1406 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1407 volumeInfo.volEntries_len = 0;
1408 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1410 "Failed to get the volint Info of the cloned volume %u\n",
1413 infop = (volintInfo *) volumeInfo.volEntries_val;
1414 infop->maxquota = -1; /* Else it will replace the default quota */
1415 infop->creationDate = -1; /* Else it will use the source creation date */
1416 infop->updateDate = -1; /* Else it will use the source update date */
1419 /* create a volume on the target machine */
1421 code = AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &totid);
1423 /* Delete the existing volume.
1424 * While we are deleting the volume in these steps, the transaction
1425 * we started against the cloned volume (clonetid above) will be
1426 * sitting idle. It will get cleaned up after 600 seconds
1428 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1429 code = AFSVolDeleteVolume(toconn, totid);
1431 "Could not delete the pre-existing volume %u on destination\n",
1436 ("Ending transaction on pre-existing volume %u on destination ...",
1438 code = AFSVolEndTrans(toconn, totid, &rcode);
1443 "Could not end the transaction on pre-existing volume %u on destination\n",
1448 VPRINT1("Creating the destination volume %u ...", volid);
1450 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1452 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1456 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1460 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1462 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1464 "Failed to set the flags on the destination volume %u\n", volid);
1468 * Now dump the clone to the new volume
1471 destination.destHost = ntohl(atoserver);
1472 destination.destPort = AFSCONF_VOLUMEPORT;
1473 destination.destSSID = 1;
1475 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1476 cookie.type = RWVOL;
1477 cookie.parent = entry.volumeId[RWVOL];
1480 if (!(flags & RV_NOCLONE)) {
1481 /* Copy the clone to the new volume */
1482 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1485 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1487 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1490 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1491 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1496 "Failed to end the transaction on the cloned volume %u\n",
1502 * reattach to the main-line volume, and incrementally dump it.
1505 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1506 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1508 "Failed to create a transaction on the source volume %u\n",
1512 /* now do the incremental */
1514 ("Doing the%s dump from source to destination for volume %u ... ",
1515 (flags & RV_NOCLONE) ? "" : " incremental",
1518 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1521 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1522 (flags & RV_NOCLONE) ? "" : " incremental");
1525 /* now adjust the flags so that the new volume becomes official */
1526 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1527 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1529 "Failed to set the flags to make old source volume offline\n");
1532 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1533 code = AFSVolSetFlags(toconn, totid, 0);
1535 "Failed to set the flags to make new source volume online\n");
1538 #ifdef ENABLE_BUGFIX_1165
1539 VPRINT1("Setting volume status on destination volume %u ...", volid);
1540 code = AFSVolSetInfo(toconn, totid, infop);
1542 "Failed to set volume status on the destination volume %u\n",
1547 /* put new volume online */
1548 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1549 code = AFSVolEndTrans(toconn, totid, &rcode);
1554 "Failed to end the transaction on the volume %u on the new site\n",
1558 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1559 MapNetworkToHost(&entry, &storeEntry);
1560 storeEntry.flags &= ~BACK_EXISTS;
1564 "Second test point - operation in progress but not complete.\n");
1565 fprintf(STDOUT, "...test here (y, n)? ");
1567 fscanf(stdin, "%c", &in);
1568 fscanf(stdin, "%c", &lf); /* toss away */
1570 fprintf(STDOUT, "type control-c\n");
1572 fprintf(stdout, ".");
1577 /* or drop through */
1580 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1582 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1583 (LOCKREL_OPCODE | LOCKREL_AFSID |
1584 LOCKREL_TIMESTAMP));
1587 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1588 storeEntry.name, (unsigned long)afromvol);
1597 "Third test point - operation complete but no cleanup.\n");
1598 fprintf(STDOUT, "...test here (y, n)? ");
1600 fscanf(stdin, "%c", &in);
1601 fscanf(stdin, "%c", &lf); /* toss away */
1603 fprintf(STDOUT, "type control-c\n");
1605 fprintf(stdout, ".");
1610 /* or drop through */
1613 /* This is tricky. File server is very stupid, and if you mark the volume
1614 * as VTOutOfService, it may mark the *good* instance (if you're moving
1615 * between partitions on the same machine) as out of service. Since
1616 * we're cleaning this code up in DEcorum, we're just going to kludge around
1617 * it for now by removing this call. */
1618 /* already out of service, just zap it now */
1620 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1623 "Failed to set the flags to make the old source volume offline\n");
1627 if (atoserver != afromserver) {
1628 /* set forwarding pointer for moved volumes */
1629 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1630 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1632 "Failed to set the forwarding pointer for the volume %u\n",
1637 VPRINT1("Deleting old volume %u on source ...", afromvol);
1638 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1639 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1643 VPRINT1("Ending transaction on old volume %u on the source ...",
1645 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1650 "Failed to end the transaction on the old volume %u on the source\n",
1654 /* Delete the backup volume on the original site */
1655 VPRINT1("Creating transaction for backup volume %u on source ...",
1658 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline, &fromtid);
1661 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1663 AFSVolSetFlags(fromconn, fromtid,
1664 VTDeleteOnSalvage | VTOutOfService);
1666 "Failed to set the flags on the backup volume %u on the source\n",
1670 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1671 code = AFSVolDeleteVolume(fromconn, fromtid);
1673 "Failed to delete the backup volume %u on the source\n",
1677 VPRINT1("Ending transaction on backup volume %u on source ...",
1679 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1684 "Failed to end the transaction on the backup volume %u on the source\n",
1688 code = 0; /* no backup volume? that's okay */
1691 if (!(flags & RV_NOCLONE)) {
1692 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1694 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1697 "Failed to start a transaction on the cloned volume%u\n",
1701 /* now delete the clone */
1702 VPRINT1("Deleting the cloned volume %u ...", newVol);
1703 code = AFSVolDeleteVolume(fromconn, clonetid);
1704 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1708 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1709 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1714 "Failed to end the transaction on the cloned volume %u\n",
1723 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1724 fprintf(STDOUT, "...test here (y, n)? ");
1726 fscanf(stdin, "%c", &in);
1727 fscanf(stdin, "%c", &lf); /* toss away */
1729 fprintf(STDOUT, "type control-c\n");
1731 fprintf(stdout, ".");
1736 /* or drop through */
1739 /* normal cleanup code */
1741 if (entry.flags & RO_EXISTS)
1742 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1745 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1747 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1748 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1752 " Could not release the lock on the VLDB entry for the volume %lu \n",
1753 (unsigned long)afromvol);
1761 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1763 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1764 if (code || rcode) {
1767 "Could not end transaction on the source volume %lu\n",
1768 (unsigned long)afromvol);
1770 error = (code ? code : rcode);
1776 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1777 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1778 if (code || rcode) {
1781 "Could not end transaction on the source's clone volume %lu\n",
1782 (unsigned long)newVol);
1784 error = (code ? code : rcode);
1790 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1792 code = AFSVolEndTrans(toconn, totid, &rcode);
1796 "Could not end transaction on destination volume %lu\n",
1797 (unsigned long)afromvol);
1799 error = (code ? code : rcode);
1805 #ifdef ENABLE_BUGFIX_1165
1810 rx_DestroyConnection(fromconn);
1812 rx_DestroyConnection(toconn);
1813 PrintError("", error);
1816 /* come here only when the sky falls */
1821 "vos move: operation interrupted, cleanup in progress...\n");
1822 fprintf(STDOUT, "clear transaction contexts\n");
1826 /* unlock VLDB entry */
1828 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1829 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1830 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1836 VPRINT("Recovery: Ending transaction on clone volume ...");
1837 AFSVolEndTrans(fromconn, clonetid, &rcode);
1841 VPRINT("Recovery: Ending transaction on destination volume ...");
1842 AFSVolEndTrans(toconn, totid, &rcode);
1845 if (fromtid) { /* put it on-line */
1846 VPRINT("Recovery: Setting volume flags on source volume ...");
1847 AFSVolSetFlags(fromconn, fromtid, 0);
1850 VPRINT("Recovery: Ending transaction on source volume ...");
1851 AFSVolEndTrans(fromconn, fromtid, &rcode);
1855 VPRINT("Recovery: Accessing VLDB.\n");
1856 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1858 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1862 MapHostToNetwork(&entry);
1864 /* Delete either the volume on the source location or the target location.
1865 * If the vldb entry still points to the source location, then we know the
1866 * volume move didn't finish so we remove the volume from the target
1867 * location. Otherwise, we remove the volume from the source location.
1869 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1872 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1876 if (volid && toconn) {
1878 ("Recovery: Creating transaction for destination volume %u ...",
1881 AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &totid);
1887 ("Recovery: Setting flags on destination volume %u ...",
1889 AFSVolSetFlags(toconn, totid,
1890 VTDeleteOnSalvage | VTOutOfService);
1893 VPRINT1("Recovery: Deleting destination volume %u ...",
1895 AFSVolDeleteVolume(toconn, totid);
1899 ("Recovery: Ending transaction on destination volume %u ...",
1901 AFSVolEndTrans(toconn, totid, &rcode);
1905 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1910 /* put source volume on-line */
1912 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1915 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
1920 VPRINT1("Recovery: Setting flags on source volume %u ...",
1922 AFSVolSetFlags(fromconn, fromtid, 0);
1926 ("Recovery: Ending transaction on source volume %u ...",
1928 AFSVolEndTrans(fromconn, fromtid, &rcode);
1932 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1936 } else { /* yep, move complete */
1939 "move complete - attempt cleanup of source partition - no guarantee\n");
1943 /* delete backup volume */
1945 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1948 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
1953 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1955 AFSVolSetFlags(fromconn, fromtid,
1956 VTDeleteOnSalvage | VTOutOfService);
1959 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1960 AFSVolDeleteVolume(fromconn, fromtid);
1964 ("Recovery: Ending transaction on backup volume %u ...",
1966 AFSVolEndTrans(fromconn, fromtid, &rcode);
1970 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1974 /* delete source volume */
1975 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1978 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
1983 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1985 AFSVolSetFlags(fromconn, fromtid,
1986 VTDeleteOnSalvage | VTOutOfService);
1989 if (atoserver != afromserver) {
1990 VPRINT("Recovery: Setting volume forwarding pointer ...");
1991 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1995 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1996 AFSVolDeleteVolume(fromconn, fromtid);
2000 ("Recovery: Ending transaction on source volume %u ...",
2002 AFSVolEndTrans(fromconn, fromtid, &rcode);
2006 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2012 /* common cleanup - delete local clone */
2014 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2017 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
2022 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
2023 AFSVolDeleteVolume(fromconn, clonetid);
2026 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2028 AFSVolEndTrans(fromconn, clonetid, &rcode);
2032 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2037 /* unlock VLDB entry */
2039 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2041 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2042 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2046 done: /* routine cleanup */
2049 #ifdef ENABLE_BUGFIX_1165
2054 rx_DestroyConnection(fromconn);
2056 rx_DestroyConnection(toconn);
2059 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2067 UV_MoveVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2068 afs_int32 atoserver, afs_int32 atopart)
2070 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2071 atoserver, atopart, 0);
2075 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2076 * <atopart>. The new volume is named by <atovolname>. The new volume
2077 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2078 * from the VLDB. the following flags are supported:
2080 * RV_RDONLY - target volume is RO
2081 * RV_OFFLINE - leave target volume offline
2082 * RV_CPINCR - do incremental dump if target exists
2083 * RV_NOVLDB - don't create/update VLDB entry
2084 * RV_NOCLONE - don't use a copy clone
2087 UV_CopyVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2088 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2089 afs_uint32 atovolid, int flags)
2091 struct rx_connection *toconn, *fromconn;
2092 afs_int32 fromtid, totid, clonetid;
2095 afs_int32 fromDate, cloneFromDate;
2096 struct restoreCookie cookie;
2097 register afs_int32 vcode, code;
2098 afs_uint32 cloneVol, newVol;
2100 struct volser_status tstatus;
2101 struct destServer destination;
2103 struct nvldbentry entry, newentry, storeEntry;
2109 fromconn = (struct rx_connection *)0;
2110 toconn = (struct rx_connection *)0;
2118 /* support control-c processing */
2121 (void)signal(SIGINT, sigint_handler);
2123 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2124 EGOTO1(mfail, vcode,
2125 "Could not fetch the entry for the volume %u from the VLDB \n",
2127 MapHostToNetwork(&entry);
2130 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2131 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2132 fromtid = totid = 0; /* initialize to uncreated */
2135 /* check if we can shortcut and use a local clone instead of a full copy */
2136 if (afromserver == atoserver && afrompart == atopart) {
2141 * clone the read/write volume locally.
2145 if (!(flags & RV_NOCLONE)) {
2146 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2147 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2149 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2153 /* Get a clone id */
2154 VPRINT1("Allocating new volume id for clone of volume %u ...",
2157 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2158 EGOTO1(mfail, vcode,
2159 "Could not get an ID for the clone of volume %u from the VLDB\n",
2167 /* Get a new volume id */
2168 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2170 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2171 EGOTO1(mfail, vcode,
2172 "Could not get an ID for the copy of volume %u from the VLDB\n",
2177 if (!(flags & RV_NOCLONE)) {
2178 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2179 VPRINT1("Cloning source volume %u ...", afromvol);
2180 strcpy(vname, "copy-clone-temp");
2182 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2184 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2188 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2190 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2195 "Failed to end the transaction on the source volume %u\n",
2201 * Create the destination volume
2204 if (!(flags & RV_NOCLONE)) {
2205 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2207 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2210 "Failed to start a transaction on the cloned volume%u\n",
2214 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2216 AFSVolSetFlags(fromconn, clonetid,
2217 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2218 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2222 /* remember time from which we've dumped the volume */
2223 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2224 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2226 "Failed to get the status of the cloned volume %u\n",
2230 fromDate = CLOCKADJ(tstatus.creationDate);
2235 /* create a volume on the target machine */
2237 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &totid);
2239 if ((flags & RV_CPINCR)) {
2240 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2241 code = AFSVolGetStatus(toconn, totid, &tstatus);
2243 "Failed to get the status of the pre-existing volume %u\n",
2247 /* Using the update date should be OK here, but add some fudge */
2248 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2249 if ((flags & RV_NOCLONE))
2250 fromDate = cloneFromDate;
2252 /* XXX We should check that the source volume's creationDate is
2253 * XXX not newer than the existing target volume, and if not,
2254 * XXX throw away the existing target and do a full dump. */
2259 /* Delete the existing volume.
2260 * While we are deleting the volume in these steps, the transaction
2261 * we started against the cloned volume (clonetid above) will be
2262 * sitting idle. It will get cleaned up after 600 seconds
2264 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2265 code = AFSVolDeleteVolume(toconn, totid);
2267 "Could not delete the pre-existing volume %u on destination\n",
2272 ("Ending transaction on pre-existing volume %u on destination ...",
2274 code = AFSVolEndTrans(toconn, totid, &rcode);
2279 "Could not end the transaction on pre-existing volume %u on destination\n",
2284 VPRINT1("Creating the destination volume %u ...", newVol);
2286 AFSVolCreateVolume(toconn, atopart, atovolname,
2287 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2288 newVol, &newVol, &totid);
2289 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2293 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2295 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2297 "Failed to set the flags on the destination volume %u\n", newVol);
2302 destination.destHost = ntohl(atoserver);
2303 destination.destPort = AFSCONF_VOLUMEPORT;
2304 destination.destSSID = 1;
2306 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2307 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2312 * Now dump the clone to the new volume
2315 if (!(flags & RV_NOCLONE)) {
2316 /* XXX probably should have some code here that checks to see if
2317 * XXX we are copying to same server and partition - if so, just
2318 * XXX use a clone to save disk space */
2320 /* Copy the clone to the new volume */
2321 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2324 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2326 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2330 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2331 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2336 "Failed to end the transaction on the cloned volume %u\n",
2342 * reattach to the main-line volume, and incrementally dump it.
2345 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2346 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2348 "Failed to create a transaction on the source volume %u\n",
2352 /* now do the incremental */
2354 ("Doing the%s dump from source to destination for volume %u ... ",
2355 (flags & RV_NOCLONE) ? "" : " incremental",
2358 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2361 "Failed to do the%s dump from old site to new site\n",
2362 (flags & RV_NOCLONE) ? "" : " incremental");
2365 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2366 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2367 code = AFSVolSetFlags(toconn, totid, volflag);
2369 "Failed to set the flags to make destination volume online\n");
2372 /* put new volume online */
2373 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2374 code = AFSVolEndTrans(toconn, totid, &rcode);
2379 "Failed to end the transaction on the destination volume %u\n",
2383 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2384 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2389 "Failed to end the transaction on the source volume %u\n",
2395 if (!(flags & RV_NOCLONE)) {
2396 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2398 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2401 "Failed to start a transaction on the cloned volume%u\n",
2405 /* now delete the clone */
2406 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2407 code = AFSVolDeleteVolume(fromconn, clonetid);
2408 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2412 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2413 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2418 "Failed to end the transaction on the cloned volume %u\n",
2423 if (!(flags & RV_NOVLDB)) {
2424 /* create the vldb entry for the copied volume */
2425 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2426 newentry.nServers = 1;
2427 newentry.serverNumber[0] = atoserver;
2428 newentry.serverPartition[0] = atopart;
2429 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2430 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2431 newentry.volumeId[RWVOL] = newVol;
2432 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2433 newentry.volumeId[BACKVOL] = 0;
2434 newentry.cloneId = 0;
2435 /*map into right byte order, before passing to xdr, the stuff has to be in host
2436 * byte order. Xdr converts it into network order */
2437 MapNetworkToHost(&newentry, &storeEntry);
2438 /* create the vldb entry */
2439 vcode = VLDB_CreateEntry(&storeEntry);
2442 "Could not create a VLDB entry for the volume %s %lu\n",
2443 atovolname, (unsigned long)newVol);
2444 /*destroy the created volume */
2445 VPRINT1("Deleting the newly created volume %u\n", newVol);
2446 AFSVolDeleteVolume(toconn, totid);
2450 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2454 /* normal cleanup code */
2457 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2459 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2460 if (code || rcode) {
2463 "Could not end transaction on the source volume %lu\n",
2464 (unsigned long)afromvol);
2466 error = (code ? code : rcode);
2472 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2474 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2475 if (code || rcode) {
2478 "Could not end transaction on the source's clone volume %lu\n",
2479 (unsigned long)cloneVol);
2481 error = (code ? code : rcode);
2487 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2489 code = AFSVolEndTrans(toconn, totid, &rcode);
2493 "Could not end transaction on destination volume %lu\n",
2494 (unsigned long)newVol);
2496 error = (code ? code : rcode);
2501 rx_DestroyConnection(fromconn);
2503 rx_DestroyConnection(toconn);
2504 PrintError("", error);
2507 /* come here only when the sky falls */
2512 "vos copy: operation interrupted, cleanup in progress...\n");
2513 fprintf(STDOUT, "clear transaction contexts\n");
2518 VPRINT("Recovery: Ending transaction on clone volume ...");
2519 AFSVolEndTrans(fromconn, clonetid, &rcode);
2523 VPRINT("Recovery: Ending transaction on destination volume ...");
2524 AFSVolEndTrans(toconn, totid, &rcode);
2527 if (fromtid) { /* put it on-line */
2528 VPRINT("Recovery: Ending transaction on source volume ...");
2529 AFSVolEndTrans(fromconn, fromtid, &rcode);
2533 VPRINT("Recovery: Accessing VLDB.\n");
2534 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2536 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2540 MapHostToNetwork(&entry);
2542 /* common cleanup - delete local clone */
2544 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2547 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2552 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2553 AFSVolDeleteVolume(fromconn, clonetid);
2556 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2558 AFSVolEndTrans(fromconn, clonetid, &rcode);
2562 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2567 done: /* routine cleanup */
2569 rx_DestroyConnection(fromconn);
2571 rx_DestroyConnection(toconn);
2574 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2582 UV_CopyVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2583 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2585 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2586 atovolname, atoserver, atopart, 0, 0);
2591 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2592 * if one already exists, update it
2596 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
2598 struct rx_connection *aconn = (struct rx_connection *)0;
2599 afs_int32 ttid = 0, btid = 0;
2600 afs_uint32 backupID;
2601 afs_int32 code = 0, rcode = 0;
2602 char vname[VOLSER_MAXVOLNAME + 1];
2603 struct nvldbentry entry, storeEntry;
2604 afs_int32 error = 0;
2605 int vldblocked = 0, vldbmod = 0, backexists = 1;
2607 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2609 /* the calls to VLDB will succeed only if avolid is a RW volume,
2610 * since we are following the RW hash chain for searching */
2611 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2614 "Could not fetch the entry for the volume %lu from the VLDB \n",
2615 (unsigned long)avolid);
2619 MapHostToNetwork(&entry);
2621 /* These operations require the VLDB be locked since it means the VLDB
2622 * will change or the vldb is already locked.
2624 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2625 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2626 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2628 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2631 "Could not lock the VLDB entry for the volume %lu\n",
2632 (unsigned long)avolid);
2638 /* Reread the vldb entry */
2639 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2642 "Could not fetch the entry for the volume %lu from the VLDB \n",
2643 (unsigned long)avolid);
2647 MapHostToNetwork(&entry);
2650 if (!ISNAMEVALID(entry.name)) {
2651 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2653 error = VOLSERBADNAME;
2657 backupID = entry.volumeId[BACKVOL];
2658 if (backupID == INVALID_BID) {
2659 /* Get a backup volume id from the VLDB and update the vldb
2662 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2665 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2666 (unsigned long)avolid);
2670 entry.volumeId[BACKVOL] = backupID;
2674 /* Test to see if the backup volume exists by trying to create
2675 * a transaction on the backup volume. We've assumed the backup exists.
2677 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2679 if (code != VNOVOL) {
2680 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2681 (unsigned long)backupID);
2685 backexists = 0; /* backup volume does not exist */
2688 code = AFSVolEndTrans(aconn, btid, &rcode);
2690 if (code || rcode) {
2692 "Could not end transaction on the previous backup volume %lu\n",
2693 (unsigned long)backupID);
2694 error = (code ? code : rcode);
2699 /* Now go ahead and try to clone the RW volume.
2700 * First start a transaction on the RW volume
2702 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
2704 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2705 (unsigned long)avolid);
2710 /* Clone or reclone the volume, depending on whether the backup
2711 * volume exists or not
2714 VPRINT1("Re-cloning backup volume %u ...", backupID);
2716 code = AFSVolReClone(aconn, ttid, backupID);
2718 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2719 (unsigned long)backupID);
2724 VPRINT1("Creating a new backup clone %u ...", backupID);
2726 strcpy(vname, entry.name);
2727 strcat(vname, ".backup");
2729 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2731 fprintf(STDERR, "Failed to clone the volume %lu\n",
2732 (unsigned long)avolid);
2738 /* End the transaction on the RW volume */
2739 code = AFSVolEndTrans(aconn, ttid, &rcode);
2741 if (code || rcode) {
2743 "Failed to end the transaction on the rw volume %lu\n",
2744 (unsigned long)avolid);
2745 error = (code ? code : rcode);
2749 /* Mork vldb as backup exists */
2750 if (!(entry.flags & BACK_EXISTS)) {
2751 entry.flags |= BACK_EXISTS;
2755 /* Now go back to the backup volume and bring it on line */
2756 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2759 "Failed to start a transaction on the backup volume %lu\n",
2760 (unsigned long)backupID);
2765 code = AFSVolSetFlags(aconn, btid, 0);
2767 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2768 (unsigned long)backupID);
2773 code = AFSVolEndTrans(aconn, btid, &rcode);
2775 if (code || rcode) {
2777 "Failed to end the transaction on the backup volume %lu\n",
2778 (unsigned long)backupID);
2779 error = (code ? code : rcode);
2785 /* Will update the vldb below */
2789 code = AFSVolEndTrans(aconn, ttid, &rcode);
2790 if (code || rcode) {
2791 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2792 (unsigned long)avolid);
2794 error = (code ? code : rcode);
2799 code = AFSVolEndTrans(aconn, btid, &rcode);
2800 if (code || rcode) {
2802 "Could not end transaction the backup volume %lu\n",
2803 (unsigned long)backupID);
2805 error = (code ? code : rcode);
2809 /* Now update the vldb - if modified */
2812 MapNetworkToHost(&entry, &storeEntry);
2814 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2815 (LOCKREL_OPCODE | LOCKREL_AFSID |
2816 LOCKREL_TIMESTAMP));
2819 "Could not update the VLDB entry for the volume %lu \n",
2820 (unsigned long)avolid);
2826 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2827 (LOCKREL_OPCODE | LOCKREL_AFSID |
2828 LOCKREL_TIMESTAMP));
2831 "Could not unlock the VLDB entry for the volume %lu \n",
2832 (unsigned long)avolid);
2840 rx_DestroyConnection(aconn);
2842 PrintError("", error);
2846 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2847 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2848 * The new volume is named by <aname>, or by appending ".clone" to
2849 * the existing name if <aname> is NULL. The following flags are
2852 * RV_RDONLY - target volume is RO
2853 * RV_OFFLINE - leave target volume offline
2857 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid,
2858 afs_uint32 acloneid, char *aname, int flags)
2860 struct rx_connection *aconn = (struct rx_connection *)0;
2861 afs_int32 ttid = 0, btid = 0;
2862 afs_int32 code = 0, rcode = 0;
2863 char vname[VOLSER_MAXVOLNAME + 1];
2864 afs_int32 error = 0;
2866 volEntries volumeInfo;
2868 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2871 volumeInfo.volEntries_val = (volintInfo *) 0;
2872 volumeInfo.volEntries_len = 0;
2873 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2875 fprintf(stderr, "Could not get info for volume %lu\n",
2876 (unsigned long)avolid);
2880 strncpy(vname, volumeInfo.volEntries_val[0].name,
2881 VOLSER_OLDMAXVOLNAME - 7);
2882 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2883 strcat(vname, ".clone");
2885 if (volumeInfo.volEntries_val)
2886 free(volumeInfo.volEntries_val);
2890 /* Get a clone id */
2891 VPRINT1("Allocating new volume id for clone of volume %u ...",
2893 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2895 "Could not get an ID for the clone of volume %u from the VLDB\n",
2900 /* Test to see if the clone volume exists by trying to create
2901 * a transaction on the clone volume. We've assumed the clone exists.
2903 /* XXX I wonder what happens if the clone has some other parent... */
2904 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2906 if (code != VNOVOL) {
2907 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2908 (unsigned long)acloneid);
2912 backexists = 0; /* backup volume does not exist */
2915 code = AFSVolEndTrans(aconn, btid, &rcode);
2917 if (code || rcode) {
2919 "Could not end transaction on the previous clone volume %lu\n",
2920 (unsigned long)acloneid);
2921 error = (code ? code : rcode);
2926 /* Now go ahead and try to clone the RW volume.
2927 * First start a transaction on the RW volume
2929 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
2931 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2932 (unsigned long)avolid);
2937 /* Clone or reclone the volume, depending on whether the backup
2938 * volume exists or not
2941 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2943 code = AFSVolReClone(aconn, ttid, acloneid);
2945 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2946 (unsigned long)acloneid);
2951 VPRINT1("Creating a new clone %u ...", acloneid);
2953 code = AFSVolClone(aconn, ttid, 0,
2954 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2957 fprintf(STDERR, "Failed to clone the volume %lu\n",
2958 (unsigned long)avolid);
2964 /* End the transaction on the RW volume */
2965 code = AFSVolEndTrans(aconn, ttid, &rcode);
2967 if (code || rcode) {
2969 "Failed to end the transaction on the rw volume %lu\n",
2970 (unsigned long)avolid);
2971 error = (code ? code : rcode);
2975 /* Now go back to the backup volume and bring it on line */
2976 if (!(flags & RV_OFFLINE)) {
2977 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2980 "Failed to start a transaction on the clone volume %lu\n",
2981 (unsigned long)acloneid);
2986 code = AFSVolSetFlags(aconn, btid, 0);
2988 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2989 (unsigned long)acloneid);
2994 code = AFSVolEndTrans(aconn, btid, &rcode);
2996 if (code || rcode) {
2998 "Failed to end the transaction on the clone volume %lu\n",
2999 (unsigned long)acloneid);
3000 error = (code ? code : rcode);
3009 code = AFSVolEndTrans(aconn, ttid, &rcode);
3010 if (code || rcode) {
3011 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3012 (unsigned long)avolid);
3014 error = (code ? code : rcode);
3019 code = AFSVolEndTrans(aconn, btid, &rcode);
3020 if (code || rcode) {
3022 "Could not end transaction on the clone volume %lu\n",
3023 (unsigned long)acloneid);
3025 error = (code ? code : rcode);
3030 rx_DestroyConnection(aconn);
3032 PrintError("", error);
3037 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
3040 afs_int32 acode, ccode, rcode, tid;
3041 ccode = rcode = tid = 0;
3043 acode = AFSVolTransCreate_retry(conn, vid, part, flags, &tid);
3044 if (!acode) { /* It really was there */
3045 acode = AFSVolDeleteVolume(conn, tid);
3047 fprintf(STDERR, "Failed to delete volume %lu.\n",
3048 (unsigned long)vid);
3049 PrintError("", acode);
3051 ccode = AFSVolEndTrans(conn, tid, &rcode);
3055 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3056 (unsigned long)vid);
3057 PrintError("", ccode);
3064 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3065 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3067 /* Get a "transaction" on this replica. Create the volume
3068 * if necessary. Return the time from which a dump should
3069 * be made (0 if it's a new volume)
3072 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3073 struct rx_connection **connPtr, afs_int32 * transPtr,
3074 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3077 struct volser_status tstatus;
3082 *connPtr = (struct rx_connection *)0;
3087 /* get connection to the replication site */
3088 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3090 goto fail; /* server is down */
3092 volid = vldbEntryPtr->volumeId[ROVOL];
3095 AFSVolTransCreate_retry(*connPtr, volid,
3096 vldbEntryPtr->serverPartition[index], ITOffline,
3099 /* If the volume does not exist, create it */
3100 if (!volid || code) {
3104 if (volid && (code != VNOVOL)) {
3105 PrintError("Failed to start a transaction on the RO volume.\n",
3110 strcpy(volname, vldbEntryPtr->name);
3111 strcat(volname, ".readonly");
3115 "Creating new volume %lu on replication site %s: ",
3116 (unsigned long)volid,
3117 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3118 serverNumber[index], hoststr) :
3119 hostutil_GetNameByINet(vldbEntryPtr->
3120 serverNumber[index]));
3125 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3127 vldbEntryPtr->volumeId[RWVOL], &volid,
3130 PrintError("Failed to create the ro volume: ", code);
3133 vldbEntryPtr->volumeId[ROVOL] = volid;
3137 /* The following is a bit redundant, since create sets these flags by default */
3139 AFSVolSetFlags(*connPtr, *transPtr,
3140 VTDeleteOnSalvage | VTOutOfService);
3142 PrintError("Failed to set flags on the ro volume: ", code);
3147 /* Otherwise, the transaction did succeed, so get the creation date of the
3148 * latest RO volume on the replication site
3151 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3152 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3153 serverNumber[index], hoststr) :
3154 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3156 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3158 PrintError("Failed to get status of volume on destination: ",
3162 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3163 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3170 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3175 PrintError("Could not end transaction on a ro volume: ", tcode);
3182 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3183 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3184 void *cookie, manyResults * results)
3188 for (i = 0; i < tr->manyDests_len; i++) {
3189 results->manyResults_val[i] =
3190 AFSVolForward(fromconn, fromtid, fromdate,
3191 &(tr->manyDests_val[i].server),
3192 tr->manyDests_val[i].trans, cookie);
3198 /* UV_ReleaseVolume()
3199 * Release volume <afromvol> on <afromserver> <afrompart> to all
3200 * its RO sites (full release). Unless the previous release was
3201 * incomplete: in which case we bring the remaining incomplete
3202 * volumes up to date with the volumes that were released
3204 * forceflag: Performs a full release.
3206 * Will create a clone from the RW, then dump the clone out to
3207 * the remaining replicas. If there is more than 1 RO sites,
3208 * ensure that the VLDB says at least one RO is available all
3209 * the time: Influences when we write back the VLDB entry.
3213 UV_ReleaseVolume(afs_uint32 afromvol, afs_int32 afromserver,
3214 afs_int32 afrompart, int forceflag)
3218 afs_int32 vcode, rcode, tcode;
3219 afs_uint32 cloneVolId, roVolId;
3220 struct replica *replicas = 0;
3221 struct nvldbentry entry, storeEntry;
3222 int i, volcount, m, fullrelease, vldbindex;
3224 struct restoreCookie cookie;
3225 struct rx_connection **toconns = 0;
3226 struct release *times = 0;
3228 struct rx_connection *fromconn = (struct rx_connection *)0;
3229 afs_int32 error = 0;
3231 afs_int32 clonetid = 0, onlinetid;
3232 afs_int32 fromtid = 0;
3233 afs_uint32 fromdate = 0;
3234 afs_uint32 thisdate;
3238 manyResults results;
3239 int rwindex, roindex, roclone, roexists;
3240 afs_uint32 rwcrdate = 0;
3241 afs_uint32 rwupdate, clcrdate;
3245 } remembertime[NMAXNSERVERS];
3246 int releasecount = 0;
3247 struct volser_status volstatus;
3250 memset((char *)remembertime, 0, sizeof(remembertime));
3251 memset((char *)&results, 0, sizeof(results));
3253 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3254 if (vcode != VL_RERELEASE)
3255 ONERROR(vcode, afromvol,
3256 "Could not lock the VLDB entry for the volume %u.\n");
3259 /* Get the vldb entry in readable format */
3260 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3261 ONERROR(vcode, afromvol,
3262 "Could not fetch the entry for the volume %u from the VLDB.\n");
3263 MapHostToNetwork(&entry);
3266 EnumerateEntry(&entry);
3268 if (!ISNAMEVALID(entry.name))
3269 ONERROR(VOLSERBADOP, entry.name,
3270 "Volume name %s is too long, rename before releasing.\n");
3271 if (entry.volumeId[RWVOL] != afromvol)
3272 ONERROR(VOLSERBADOP, afromvol,
3273 "The volume %u being released is not a read-write volume.\n");
3274 if (entry.nServers <= 1)
3275 ONERROR(VOLSERBADOP, afromvol,
3276 "Volume %u has no replicas - release operation is meaningless!\n");
3277 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3278 ONERROR(VOLSERBADOP, entry.name,
3279 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3281 /* roclone is true if one of the RO volumes is on the same
3282 * partition as the RW volume. In this case, we make the RO volume
3283 * on the same partition a clone instead of a complete copy.
3286 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3287 roclone = ((roindex == -1) ? 0 : 1);
3288 rwindex = Lp_GetRwIndex(&entry);
3290 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3292 /* Make sure we have a RO volume id to work with */
3293 if (entry.volumeId[ROVOL] == INVALID_BID) {
3294 /* need to get a new RO volume id */
3295 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3296 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3298 entry.volumeId[ROVOL] = roVolId;
3299 MapNetworkToHost(&entry, &storeEntry);
3300 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3301 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3304 /* Will we be completing a previously unfinished release. -force overrides */
3305 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3306 if (entry.serverFlags[i] & ITSROVOL) {
3308 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3311 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3314 /* Determine which volume id to use and see if it exists */
3317 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3318 code = VolumeExists(afromserver, afrompart, cloneVolId);
3319 roexists = ((code == ENODEV) ? 0 : 1);
3321 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3323 ONERROR(-1, afromserver,
3324 "Cannot establish connection with server 0x%x\n");
3328 fullrelease = 1; /* Do a full release if RO clone does not exist */
3330 /* Begin transaction on RW and mark it busy while we query it */
3331 code = AFSVolTransCreate_retry(
3332 fromconn, afromvol, afrompart, ITBusy, &fromtid
3334 ONERROR(code, afromvol,
3335 "Failed to start transaction on RW volume %u\n");
3337 /* Query the creation date for the RW */
3338 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3339 ONERROR(code, afromvol,
3340 "Failed to get the status of RW volume %u\n");
3341 rwcrdate = volstatus.creationDate;
3342 rwupdate = volstatus.updateDate;
3344 /* End transaction on RW */
3345 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3347 ONERROR((code ? code : rcode), afromvol,
3348 "Failed to end transaction on RW volume %u\n");
3350 /* Begin transaction on clone and mark it busy while we query it */
3351 code = AFSVolTransCreate_retry(
3352 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3354 ONERROR(code, cloneVolId,
3355 "Failed to start transaction on RW clone %u\n");
3357 /* Query the creation date for the clone */
3358 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3359 ONERROR(code, cloneVolId,
3360 "Failed to get the status of RW clone %u\n");
3361 clcrdate = volstatus.creationDate;
3363 /* End transaction on clone */
3364 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3366 ONERROR((code ? code : rcode), cloneVolId,
3367 "Failed to end transaction on RW clone %u\n");
3369 if (rwcrdate > clcrdate)
3370 fullrelease = 2;/* Do a full release if RO clone older than RW */
3375 switch (fullrelease) {
3377 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3378 (unsigned long)afromvol);
3381 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3382 (unsigned long)afromvol);
3385 fprintf(STDOUT, "This is a completion of a previous release\n");
3391 /* If the RO clone exists, then if the clone is a temporary
3392 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3393 * (it was recently added), then also delete it. We do not
3394 * want to "reclone" a temporary RO clone.
3397 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3398 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3399 if (code && (code != VNOVOL))
3404 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3405 * write this entry out to the vlserver until after the first
3406 * RO volume is released (temp RO clones don't count).
3408 for (i = 0; i < entry.nServers; i++) {
3409 entry.serverFlags[i] &= ~NEW_REPSITE;
3410 entry.serverFlags[i] |= RO_DONTUSE;
3412 entry.serverFlags[rwindex] |= NEW_REPSITE;
3413 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3415 /* Begin transaction on RW and mark it busy while we clone it */
3417 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
3419 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3421 /* Clone or reclone the volume */
3423 VPRINT1("Recloning RW volume %u...", cloneVolId);
3424 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3425 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3429 strcpy(vname, entry.name);
3430 strcat(vname, ".readonly");
3431 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3433 strcpy(vname, "readonly-clone-temp");
3434 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3437 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3439 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3443 /* Get the time the RW was created for future information */
3444 VPRINT1("Getting status of RW volume %u...", afromvol);
3445 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3446 ONERROR(code, afromvol,
3447 "Failed to get the status of the RW volume %u\n");
3449 rwcrdate = volstatus.creationDate;
3450 rwupdate = volstatus.updateDate;
3452 /* End the transaction on the RW volume */
3453 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3454 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3456 ONERROR((code ? code : rcode), afromvol,
3457 "Failed to end cloning transaction on RW %u\n");
3460 /* Remember clone volume ID in case we fail or are interrupted */
3461 entry.cloneId = cloneVolId;
3464 /* Bring the RO clone online - though not if it's a temporary clone */
3465 VPRINT1("Starting transaction on RO clone volume %u...",
3468 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3470 ONERROR(code, cloneVolId,
3471 "Failed to start transaction on volume %u\n");
3474 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3475 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3478 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3479 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3480 ONERROR((code ? code : rcode), cloneVolId,
3481 "Failed to end transaction on RO clone %u\n");
3484 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3486 /* Sleep so that a client searching for an online volume won't
3487 * find the clone offline and then the next RO offline while the
3488 * release brings the clone online and the next RO offline (race).
3489 * There is a fix in the 3.4 client that does not need this sleep
3490 * anymore, but we don't know what clients we have.
3492 if (entry.nServers > 2)
3495 /* Mark the RO clone in the VLDB as a good site (already released) */
3496 entry.serverFlags[roindex] |= NEW_REPSITE;
3497 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3498 entry.flags |= RO_EXISTS;
3502 /* Write out the VLDB entry only if the clone is not a temporary
3503 * clone. If we did this to a temporary clone then we would end
3504 * up marking all the ROs as "old release" making the ROs
3505 * temporarily unavailable.
3507 MapNetworkToHost(&entry, &storeEntry);
3508 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3509 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3510 ONERROR(vcode, entry.name,
3511 "Could not update vldb entry for %s.\n");
3516 /* Now we will release from the clone to the remaining RO replicas.
3517 * The first 2 ROs (counting the non-temporary RO clone) are released
3518 * individually: releasecount. This is to reduce the race condition
3519 * of clients trying to find an on-line RO volume. The remaining ROs
3520 * are released in parallel but no more than half the number of ROs
3521 * (rounded up) at a time: nservers.
3524 strcpy(vname, entry.name);
3525 strcat(vname, ".readonly");
3526 memset(&cookie, 0, sizeof(cookie));
3527 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3528 cookie.type = ROVOL;
3529 cookie.parent = entry.volumeId[RWVOL];
3532 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3534 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3535 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3537 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3539 results.manyResults_val =
3540 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3541 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3543 "Failed to create transaction on the release clone\n");
3545 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3546 memset(times, 0, (sizeof(struct release) * nservers + 1));
3547 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3548 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3550 /* Create a transaction on the cloned volume */
3551 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3553 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3554 if (!fullrelease && code)
3555 ONERROR(VOLSERNOVOL, afromvol,
3556 "Old clone is inaccessible. Try vos release -f %u.\n");
3557 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3560 /* For each index in the VLDB */
3561 for (vldbindex = 0; vldbindex < entry.nServers;) {
3563 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3565 ((volcount < nservers) && (vldbindex < entry.nServers));
3567 /* The first two RO volumes will be released individually.
3568 * The rest are then released in parallel. This is a hack
3569 * for clients not recognizing right away when a RO volume
3570 * comes back on-line.
3572 if ((volcount == 1) && (releasecount < 2))
3575 if (vldbindex == roindex)
3576 continue; /* the clone */
3577 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3578 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3580 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3581 continue; /* not a RO vol */
3584 /* Get a Transaction on this replica. Get a new connection if
3585 * necessary. Create the volume if necessary. Return the
3586 * time from which the dump should be made (0 if it's a new
3587 * volume). Each volume might have a different time.
3589 replicas[volcount].server.destHost =
3590 ntohl(entry.serverNumber[vldbindex]);
3591 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3592 replicas[volcount].server.destSSID = 1;
3593 times[volcount].vldbEntryIndex = vldbindex;
3596 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3597 &(replicas[volcount].trans),
3598 &(times[volcount].crtime),
3599 &(times[volcount].uptime));
3603 /* Thisdate is the date from which we want to pick up all changes */
3604 if (forceflag || !fullrelease
3605 || (rwcrdate > times[volcount].crtime)) {
3606 /* If the forceflag is set, then we want to do a full dump.
3607 * If it's not a full release, we can't be sure that the creation
3608 * date is good (so we also do a full dump).
3609 * If the RW volume was replaced (its creation date is newer than
3610 * the last release), then we can't be sure what has changed (so
3611 * we do a full dump).
3614 } else if (remembertime[vldbindex].validtime) {
3615 /* Trans was prev ended. Use the time from the prev trans
3616 * because, prev trans may have created the volume. In which
3617 * case time[volcount].time would be now instead of 0.
3620 (remembertime[vldbindex].uptime < times[volcount].uptime)
3621 ? remembertime[vldbindex].uptime
3622 : times[volcount].uptime;
3624 thisdate = times[volcount].uptime;
3626 remembertime[vldbindex].validtime = 1;
3627 remembertime[vldbindex].uptime = thisdate;
3629 if (volcount == 0) {
3630 fromdate = thisdate;
3632 /* Include this volume if it is within 15 minutes of the earliest */
3634 thisdate) ? (fromdate - thisdate) : (thisdate -
3636 AFSVolEndTrans(toconns[volcount],
3637 replicas[volcount].trans, &rcode);
3638 replicas[volcount].trans = 0;
3641 if (thisdate < fromdate)
3642 fromdate = thisdate;
3650 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3651 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3652 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3653 vldbEntryIndex], hoststr) :
3654 hostutil_GetNameByINet(entry.
3655 serverNumber[times[0].
3658 for (s = 1; s < volcount; s++) {
3659 fprintf(STDOUT, " and %s",
3660 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3661 vldbEntryIndex], hoststr) :
3662 hostutil_GetNameByINet(entry.
3663 serverNumber[times[s].
3668 fprintf(STDOUT, " (full release)");
3671 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3673 fprintf(STDOUT, ".\n");
3677 /* Release the ones we have collected */
3678 tr.manyDests_val = &(replicas[0]);
3679 tr.manyDests_len = results.manyResults_len = volcount;
3681 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3682 0 /*spare */ , &cookie, &results);
3683 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3685 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3686 0 /*spare */ , &cookie, &results);
3691 PrintError("Release failed: ", code);
3693 for (m = 0; m < volcount; m++) {
3694 if (results.manyResults_val[m]) {
3695 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3696 /* we retry timed out transaction. When it is
3697 * not the first volume and the transaction wasn't found
3698 * (assume it timed out and was garbage collected by volser).
3701 ("Failed to dump volume from clone to a ro site: ",
3702 results.manyResults_val[m]);
3708 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3709 ROVOL, entry.volumeId[RWVOL], 0, 0);
3711 if ((m == 0) || (code != ENOENT)) {
3712 PrintError("Failed to set correct names and ids: ",
3718 /* have to clear dest. flags to ensure new vol goes online:
3719 * because the restore (forwarded) operation copied
3720 * the V_inService(=0) flag over to the destination.
3722 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3724 if ((m == 0) || (code != ENOENT)) {
3725 PrintError("Failed to set flags on ro volume: ",
3731 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3732 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3733 entry.flags |= RO_EXISTS;
3738 /* End the transactions and destroy the connections */
3739 for (s = 0; s < volcount; s++) {
3740 if (replicas[s].trans)
3741 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3742 replicas[s].trans = 0;
3746 if ((s == 0) || (code != ENOENT)) {
3747 PrintError("Could not end transaction on a ro volume: ",
3751 ("Transaction timed out on a ro volume. Will retry.\n",
3753 if (times[s].vldbEntryIndex < vldbindex)
3754 vldbindex = times[s].vldbEntryIndex;
3759 rx_DestroyConnection(toconns[s]);
3763 MapNetworkToHost(&entry, &storeEntry);
3764 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3765 ONERROR(vcode, afromvol,
3766 " Could not update VLDB entry for volume %u\n");
3767 } /* for each index in the vldb */
3769 /* End the transaction on the cloned volume */
3770 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3775 PrintError("Failed to end transaction on rw volume: ", code);
3777 /* Figure out if any volume were not released and say so */
3778 for (failure = 0, i = 0; i < entry.nServers; i++) {
3779 if (!(entry.serverFlags[i] & NEW_REPSITE))
3785 "The volume %lu could not be released to the following %d sites:\n",
3786 (unsigned long)afromvol, failure);
3787 for (i = 0; i < entry.nServers; i++) {
3788 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3789 MapPartIdIntoName(entry.serverPartition[i], pname);
3790 fprintf(STDERR, "\t%35s %s\n",
3791 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
3792 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3796 MapNetworkToHost(&entry, &storeEntry);
3798 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3800 ONERROR(vcode, afromvol,
3801 " Could not update VLDB entry for volume %u\n");
3803 ERROREXIT(VOLSERBADRELEASE);
3806 /* All the ROs were release successfully. Remove the temporary clone */
3809 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3810 (unsigned long)cloneVolId);
3813 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3814 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3819 for (i = 0; i < entry.nServers; i++)
3820 entry.serverFlags[i] &= ~NEW_REPSITE;
3822 /* Update the VLDB */
3823 VPRINT("updating VLDB ...");
3825 MapNetworkToHost(&entry, &storeEntry);
3827 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3828 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3829 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3834 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3838 "Failed to end cloning transaction on the RW volume %lu\n",
3839 (unsigned long)afromvol);
3845 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3849 "Failed to end transaction on the release clone %lu\n",
3850 (unsigned long)cloneVolId);
3855 for (i = 0; i < nservers; i++) {
3856 if (replicas && replicas[i].trans) {
3857 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3858 replicas[i].trans = 0;
3861 "Failed to end transaction on ro volume %u at server %s\n",
3862 entry.volumeId[ROVOL],
3863 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
3864 destHost), hoststr) :
3865 hostutil_GetNameByINet(htonl
3866 (replicas[i].server.destHost)));
3871 if (toconns && toconns[i]) {
3872 rx_DestroyConnection(toconns[i]);
3878 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3879 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3882 "Could not release lock on the VLDB entry for volume %lu\n",
3883 (unsigned long)afromvol);
3889 PrintError("", error);
3892 rx_DestroyConnection(fromconn);
3893 if (results.manyResults_val)
3894 free(results.manyResults_val);
3906 dump_sig_handler(int x)
3908 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3912 /* Dump the volume <afromvol> on <afromserver> and
3913 * <afrompart> to <afilename> starting from <fromdate>.
3914 * DumpFunction does the real work behind the scenes after
3915 * extracting parameters from the rock
3918 UV_DumpVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3919 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock,
3922 struct rx_connection *fromconn = (struct rx_connection *)0;
3923 struct rx_call *fromcall = (struct rx_call *)0;
3924 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3925 afs_int32 code, error = 0, retry = 0;
3926 time_t tmv = fromdate;
3930 #ifndef AFS_NT40_ENV
3931 (void)signal(SIGPIPE, dump_sig_handler);
3933 (void)signal(SIGINT, dump_sig_handler);
3936 VEPRINT("Full Dump ...\n");
3938 VEPRINT1("Incremental Dump (as of %.24s)...\n",
3942 /* get connections to the servers */
3943 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3945 VEPRINT1("Starting transaction on volume %u...", afromvol);
3946 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3947 EGOTO1(error_exit, code,
3948 "Could not start transaction on the volume %u to be dumped\n",
3952 fromcall = rx_NewCall(fromconn);
3954 VEPRINT1("Starting volume dump on volume %u...", afromvol);
3955 if (flags & VOLDUMPV2_OMITDIRS)
3956 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
3959 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3960 EGOTO(error_exit, code, "Could not start the dump process \n");
3963 VEPRINT1("Dumping volume %u...", afromvol);
3964 code = DumpFunction(fromcall, rock);
3965 if (code == RXGEN_OPCODE)
3967 EGOTO(error_exit, code, "Error while dumping volume \n");
3972 code = rx_EndCall(fromcall, rxError);
3973 if (code && code != RXGEN_OPCODE)
3974 fprintf(STDERR, "Error in rx_EndCall\n");
3979 VEPRINT1("Ending transaction on volume %u...", afromvol);
3980 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3981 if (code || rcode) {
3982 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3983 (unsigned long)afromvol);
3985 error = (code ? code : rcode);
3990 rx_DestroyConnection(fromconn);
3994 if (error != RXGEN_OPCODE)
3995 PrintError("", error);
3999 /* Clone the volume <afromvol> on <afromserver> and
4000 * <afrompart>, and then dump the clone volume to
4001 * <afilename> starting from <fromdate>.
4002 * DumpFunction does the real work behind the scenes after
4003 * extracting parameters from the rock
4006 UV_DumpClonedVolume(afs_uint32 afromvol, afs_int32 afromserver,
4007 afs_int32 afrompart, afs_int32 fromdate,
4008 afs_int32(*DumpFunction) (), char *rock, afs_int32 flags)
4010 struct rx_connection *fromconn = (struct rx_connection *)0;
4011 struct rx_call *fromcall = (struct rx_call *)0;
4012 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4013 afs_int32 clonetid = 0;
4014 afs_int32 code = 0, vcode = 0, error = 0;
4015 afs_uint32 clonevol = 0;
4017 time_t tmv = fromdate;
4021 #ifndef AFS_NT40_ENV
4022 (void)signal(SIGPIPE, dump_sig_handler);
4024 (void)signal(SIGINT, dump_sig_handler);
4027 VEPRINT("Full Dump ...\n");
4029 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4033 /* get connections to the servers */
4034 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4036 VEPRINT1("Starting transaction on volume %u...", afromvol);
4037 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4038 EGOTO1(error_exit, code,
4039 "Could not start transaction on the volume %u to be dumped\n",
4043 /* Get a clone id */
4044 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4045 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
4046 EGOTO1(error_exit, code,
4047 "Could not get an ID for the clone of volume %u from the VLDB\n",
4051 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4052 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4054 strcpy(vname, "dump-clone-temp");
4056 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
4057 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4061 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4063 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4067 EGOTO1(error_exit, code,
4068 "Failed to end the transaction on the volume %u\n", afromvol);
4072 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4074 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4076 EGOTO1(error_exit, code,
4077 "Failed to start a transaction on the cloned volume%u\n",
4081 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4082 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4083 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4088 fromcall = rx_NewCall(fromconn);
4090 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4091 if (flags & VOLDUMPV2_OMITDIRS)
4092 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4094 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4095 EGOTO(error_exit, code, "Could not start the dump process \n");
4098 VEPRINT1("Dumping volume %u...", afromvol);
4099 code = DumpFunction(fromcall, rock);
4100 EGOTO(error_exit, code, "Error while dumping volume \n");
4104 /* now delete the clone */
4105 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4106 code = AFSVolDeleteVolume(fromconn, clonetid);
4108 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4109 (unsigned long)clonevol);
4115 code = rx_EndCall(fromcall, rxError);
4117 fprintf(STDERR, "Error in rx_EndCall\n");
4123 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4124 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4125 if (code || rcode) {
4127 "Could not end transaction on the cloned volume %lu\n",
4128 (unsigned long)clonevol);
4130 error = (code ? code : rcode);
4135 rx_DestroyConnection(fromconn);
4137 PrintError("", error);
4144 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4145 * the dump file <afilename>. WriteData does all the real work
4146 * after extracting params from the rock
4149 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_uint32 tovolid,
4150 afs_int32 toparentid, char tovolname[], int flags,
4151 afs_int32(*WriteData) (), char *rock)
4153 struct rx_connection *toconn, *tempconn;
4154 struct rx_call *tocall;
4155 afs_int32 totid, code, rcode, vcode, terror = 0;
4156 afs_int32 rxError = 0;
4157 struct volser_status tstatus;
4158 struct volintInfo vinfo;
4160 char tovolreal[VOLSER_OLDMAXVOLNAME];
4162 afs_int32 temptid, pparentid;
4164 struct nvldbentry entry, storeEntry;
4167 struct restoreCookie cookie;
4169 afs_int32 volflag, voltype, volsertype;
4170 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4171 int index, same, errcode;
4175 memset(&cookie, 0, sizeof(cookie));
4180 tocall = (struct rx_call *)0;
4181 toconn = (struct rx_connection *)0;
4182 tempconn = (struct rx_connection *)0;
4186 if (flags & RV_RDONLY) {
4188 volsertype = volser_RO;
4191 volsertype = volser_RW;
4195 pparentid = toparentid;
4196 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4197 if (pvolid == 0) { /*alot a new id if needed */
4198 vcode = VLDB_GetEntryByName(tovolname, &entry);
4199 if (vcode == VL_NOENT) {
4200 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4202 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4208 } else if (flags & RV_RDONLY) {
4209 if (entry.flags & RW_EXISTS) {
4211 "Entry for ReadWrite volume %s already exists!\n",
4213 error = VOLSERBADOP;
4216 if (!entry.volumeId[ROVOL]) {
4218 "Existing entry for volume %s has no ReadOnly ID\n",
4220 error = VOLSERBADOP;
4223 pvolid = entry.volumeId[ROVOL];
4224 pparentid = entry.volumeId[RWVOL];
4226 pvolid = entry.volumeId[RWVOL];
4227 pparentid = entry.volumeId[RWVOL];
4230 if (!pparentid) pparentid = pvolid;
4231 /* at this point we have a volume id to use/reuse for the volume to be restored */
4232 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4234 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4235 EGOTO1(refail, VOLSERBADOP,
4236 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4239 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4240 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4241 EGOTO1(refail, VOLSERBADOP,
4242 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4244 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4247 MapPartIdIntoName(topart, partName);
4248 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4249 tovolreal, (unsigned long)pvolid,
4250 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4251 hostutil_GetNameByINet(toserver), partName);
4254 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4257 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4258 VPRINT1("Deleting the previous volume %u ...", pvolid);
4261 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4262 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4265 code = AFSVolGetStatus(toconn, totid, &tstatus);
4266 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4269 oldCreateDate = tstatus.creationDate;
4270 oldUpdateDate = tstatus.updateDate;
4273 AFSVolSetFlags(toconn, totid,
4274 VTDeleteOnSalvage | VTOutOfService);
4275 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4278 code = AFSVolDeleteVolume(toconn, totid);
4279 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4281 code = AFSVolEndTrans(toconn, totid, &rcode);
4285 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4290 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4292 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4295 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4296 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4299 code = AFSVolGetStatus(toconn, totid, &tstatus);
4300 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4303 oldCreateDate = tstatus.creationDate;
4304 oldUpdateDate = tstatus.updateDate;
4311 cookie.parent = pparentid;
4312 cookie.type = voltype;
4314 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4316 tocall = rx_NewCall(toconn);
4317 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4319 fprintf(STDERR, "Volume restore Failed \n");
4323 code = WriteData(tocall, rock);
4325 fprintf(STDERR, "Could not transmit data\n");
4329 terror = rx_EndCall(tocall, rxError);
4330 tocall = (struct rx_call *)0;
4332 fprintf(STDERR, "rx_EndCall Failed \n");
4336 code = AFSVolGetStatus(toconn, totid, &tstatus);
4339 "Could not get status information about the volume %lu\n",
4340 (unsigned long)pvolid);
4344 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4346 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4347 (unsigned long)pvolid);
4352 if (flags & RV_CRDUMP)
4353 newCreateDate = tstatus.creationDate;
4354 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4355 newCreateDate = oldCreateDate;
4357 newCreateDate = time(0);
4358 if (flags & RV_LUDUMP)
4359 newUpdateDate = tstatus.updateDate;
4360 else if (flags & RV_LUKEEP)
4361 newUpdateDate = oldUpdateDate;
4363 newUpdateDate = time(0);
4364 code = AFSVolSetDate(toconn,totid, newCreateDate);
4366 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4371 init_volintInfo(&vinfo);
4372 vinfo.creationDate = newCreateDate;
4373 vinfo.updateDate = newUpdateDate;
4374 code = AFSVolSetInfo(toconn, totid, &vinfo);
4376 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4382 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4383 code = AFSVolSetFlags(toconn, totid, volflag);
4385 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4390 /* It isn't handled right in refail */
4391 code = AFSVolEndTrans(toconn, totid, &rcode);
4396 fprintf(STDERR, "Could not end transaction on %lu\n",
4397 (unsigned long)pvolid);
4403 fprintf(STDOUT, " done\n");
4405 if (success && (!reuseID || (flags & RV_FULLRST))) {
4406 /* Volume was restored on the file server, update the
4407 * VLDB to reflect the change.
4409 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4410 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4412 "Could not fetch the entry for volume number %lu from VLDB \n",
4413 (unsigned long)pvolid);
4418 MapHostToNetwork(&entry);
4419 if (vcode == VL_NOENT) { /* it doesnot exist already */
4420 /*make the vldb return this indication specifically */
4421 VPRINT("------- Creating a new VLDB entry ------- \n");
4422 strcpy(entry.name, tovolname);
4424 entry.serverNumber[0] = toserver; /*should be indirect */
4425 entry.serverPartition[0] = topart;
4426 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4427 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4428 if (flags & RV_RDONLY)
4429 entry.volumeId[ROVOL] = pvolid;
4430 else if (tstatus.cloneID != 0) {
4431 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4433 entry.volumeId[ROVOL] = INVALID_BID;
4434 entry.volumeId[RWVOL] = pparentid;
4436 if (tstatus.backupID != 0) {
4437 entry.volumeId[BACKVOL] = tstatus.backupID;
4438 /*this should come from status info on the volume if non zero */
4440 entry.volumeId[BACKVOL] = INVALID_BID;
4441 MapNetworkToHost(&entry, &storeEntry);
4442 vcode = VLDB_CreateEntry(&storeEntry);
4445 "Could not create the VLDB entry for volume number %lu \n",
4446 (unsigned long)pvolid);
4452 EnumerateEntry(&entry);
4453 } else { /*update the existing entry */
4455 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4456 fprintf(STDOUT, "------- Old entry -------\n");
4457 EnumerateEntry(&entry);
4458 fprintf(STDOUT, "------- New entry -------\n");
4461 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4465 "Could not lock the entry for volume number %lu \n",
4466 (unsigned long)pvolid);
4471 strcpy(entry.name, tovolname);
4473 /* Update the vlentry with the new information */
4474 if (flags & RV_RDONLY)
4475 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4477 index = Lp_GetRwIndex(&entry);
4479 /* Add the new site for the volume being restored */
4480 entry.serverNumber[entry.nServers] = toserver;
4481 entry.serverPartition[entry.nServers] = topart;
4482 entry.serverFlags[entry.nServers] =
4483 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4486 /* This volume should be deleted on the old site
4487 * if its different from new site.
4490 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4494 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4496 if ((!errcode && !same)
4497 || (entry.serverPartition[index] != topart)) {
4498 if (flags & RV_NODEL) {
4500 ("Not deleting the previous volume %u on server %s, ...",
4502 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4503 hostutil_GetNameByINet(entry.serverNumber[index]));
4506 UV_Bind(entry.serverNumber[index],
4507 AFSCONF_VOLUMEPORT);
4509 MapPartIdIntoName(entry.serverPartition[index],
4512 ("Deleting the previous volume %u on server %s, partition %s ...",
4514 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4515 hostutil_GetNameByINet(entry.serverNumber[index]),
4518 AFSVolTransCreate_retry(tempconn, pvolid,
4519 entry.serverPartition[index],
4520 ITOffline, &temptid);
4523 AFSVolSetFlags(tempconn, temptid,
4528 "Could not set flags on volume %lu on the older site\n",
4529 (unsigned long)pvolid);
4533 code = AFSVolDeleteVolume(tempconn, temptid);
4536 "Could not delete volume %lu on the older site\n",
4537 (unsigned long)pvolid);
4541 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4547 "Could not end transaction on volume %lu on the older site\n",
4548 (unsigned long)pvolid);
4553 MapPartIdIntoName(entry.serverPartition[index],
4558 entry.serverNumber[index] = toserver;
4559 entry.serverPartition[index] = topart;
4562 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4563 MapNetworkToHost(&entry, &storeEntry);
4565 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4566 LOCKREL_OPCODE | LOCKREL_AFSID |
4570 "Could not update the entry for volume number %lu \n",
4571 (unsigned long)pvolid);
4577 EnumerateEntry(&entry);
4584 code = rx_EndCall(tocall, rxError);
4590 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4591 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4594 "Could not release lock on the VLDB entry for the volume %lu\n",
4595 (unsigned long)pvolid);
4601 code = AFSVolEndTrans(toconn, totid, &rcode);
4605 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4606 (unsigned long)pvolid);
4612 code = AFSVolEndTrans(toconn, temptid, &rcode);
4616 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4617 (unsigned long)pvolid);
4623 rx_DestroyConnection(tempconn);
4625 rx_DestroyConnection(toconn);
4626 PrintError("", error);
4631 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_uint32 tovolid,
4632 char tovolname[], int flags, afs_int32(*WriteData) (),
4635 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4640 /*unlocks the vldb entry associated with <volid> */
4642 UV_LockRelease(afs_uint32 volid)
4646 VPRINT("Binding to the VLDB server\n");
4648 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4649 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4652 "Could not unlock the entry for volume number %lu in VLDB \n",
4653 (unsigned long)volid);
4654 PrintError("", vcode);
4657 VPRINT("VLDB updated\n");
4662 /*adds <server> and <part> as a readonly replication site for <volid>
4665 UV_AddSite(afs_int32 server, afs_int32 part, afs_uint32 volid, afs_int32 valid)
4667 int j, nro = 0, islocked = 0;
4668 struct nvldbentry entry, storeEntry;
4669 afs_int32 vcode, error = 0;
4672 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4675 " Could not lock the VLDB entry for the volume %lu \n",
4676 (unsigned long)volid);
4681 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4684 "Could not fetch the VLDB entry for volume number %lu \n",
4685 (unsigned long)volid);
4689 if (!ISNAMEVALID(entry.name)) {
4691 "Volume name %s is too long, rename before adding site\n",
4693 error = VOLSERBADOP;
4696 MapHostToNetwork(&entry);
4698 /* See if it's too many entries */
4699 if (entry.nServers >= NMAXNSERVERS) {
4700 fprintf(STDERR, "Total number of entries will exceed %u\n",
4702 error = VOLSERBADOP;
4706 /* See if it's on the same server */
4707 for (j = 0; j < entry.nServers; j++) {
4708 if (entry.serverFlags[j] & ITSROVOL) {
4710 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4713 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4716 MapPartIdIntoName(entry.serverPartition[j], apartName);
4718 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4720 error = VOLSERBADOP;
4727 /* See if it's too many RO sites - leave one for the RW */
4728 if (nro >= NMAXNSERVERS - 1) {
4729 fprintf(STDERR, "Total number of sites will exceed %u\n",
4731 error = VOLSERBADOP;
4735 VPRINT("Adding a new site ...");
4736 entry.serverNumber[entry.nServers] = server;
4737 entry.serverPartition[entry.nServers] = part;
4739 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4741 entry.serverFlags[entry.nServers] = (ITSROVOL);
4745 MapNetworkToHost(&entry, &storeEntry);
4747 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4748 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4750 fprintf(STDERR, "Could not update entry for volume %lu \n",
4751 (unsigned long)volid);
4760 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4761 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4764 "Could not release lock on volume entry for %lu \n",
4765 (unsigned long)volid);
4766 PrintError("", vcode);
4770 PrintError("", error);
4774 /*removes <server> <part> as read only site for <volid> from the vldb */
4776 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_uint32 volid)
4779 struct nvldbentry entry, storeEntry;
4782 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4784 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4785 (unsigned long)volid);
4786 PrintError("", vcode);
4790 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4793 "Could not fetch the entry for volume number %lu from VLDB \n",
4794 (unsigned long)volid);
4795 PrintError("", vcode);
4798 MapHostToNetwork(&entry);
4799 if (!Lp_ROMatch(server, part, &entry)) {
4800 /*this site doesnot exist */
4801 fprintf(STDERR, "This site is not a replication site \n");
4803 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4804 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4806 fprintf(STDERR, "Could not update entry for volume %lu \n",
4807 (unsigned long)volid);
4808 PrintError("", vcode);
4809 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4810 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4814 } else { /*remove the rep site */
4815 Lp_SetROValue(&entry, server, part, 0, 0);
4817 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4818 entry.flags &= ~RO_EXISTS;
4819 if (entry.nServers < 1) { /*this is the last ref */
4820 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4822 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4825 "Could not delete VLDB entry for volume %lu \n",
4826 (unsigned long)volid);
4827 PrintError("", vcode);
4832 MapNetworkToHost(&entry, &storeEntry);
4833 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4834 (unsigned long)volid);
4837 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4838 LOCKREL_OPCODE | LOCKREL_AFSID |
4842 "Could not release lock on volume entry for %lu \n",
4843 (unsigned long)volid);
4844 PrintError("", vcode);
4845 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4846 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4854 /*sets <server> <part> as read/write site for <volid> in the vldb */
4856 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_uint32 volid)
4859 struct nvldbentry entry, storeEntry;
4862 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4864 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4865 (unsigned long)volid);
4866 PrintError("", vcode);
4869 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4872 "Could not fetch the entry for volume number %lu from VLDB \n",
4873 (unsigned long)volid);
4874 PrintError("", vcode);
4877 MapHostToNetwork(&entry);
4878 index = Lp_GetRwIndex(&entry);
4880 /* no RW site exists */
4881 fprintf(STDERR, "No existing RW site for volume %lu",
4882 (unsigned long)volid);
4884 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4885 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4888 "Could not release lock on entry for volume %lu \n",
4889 (unsigned long)volid);
4890 PrintError("", vcode);
4894 } else { /* change the RW site */
4895 entry.serverNumber[index] = server;
4896 entry.serverPartition[index] = part;
4897 MapNetworkToHost(&entry, &storeEntry);
4899 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4900 LOCKREL_OPCODE | LOCKREL_AFSID |
4903 fprintf(STDERR, "Could not update entry for volume %lu \n",
4904 (unsigned long)volid);
4905 PrintError("", vcode);
4906 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4907 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4915 /*list all the partitions on <aserver> */
4917 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4920 struct rx_connection *aconn;
4921 struct pIDs partIds;
4922 struct partEntries partEnts;
4923 register int i, j = 0, code;
4926 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4928 partEnts.partEntries_len = 0;
4929 partEnts.partEntries_val = NULL;
4930 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4931 if (code == RXGEN_OPCODE) {
4932 for (i = 0; i < 26; i++) /* try old interface */
4933 partIds.partIds[i] = -1;
4934 code = AFSVolListPartitions(aconn, &partIds);
4936 for (i = 0; i < 26; i++) {
4937 if ((partIds.partIds[i]) != -1) {
4938 ptrPartList->partId[j] = partIds.partIds[i];
4939 ptrPartList->partFlags[j] = PARTVALID;
4942 ptrPartList->partFlags[i] = 0;
4947 *cntp = partEnts.partEntries_len;
4948 if (*cntp > VOLMAXPARTS) {
4950 "Warning: number of partitions on the server too high %d (process only %d)\n",
4951 *cntp, VOLMAXPARTS);
4952 *cntp = VOLMAXPARTS;
4954 for (i = 0; i < *cntp; i++) {
4955 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4956 ptrPartList->partFlags[i] = PARTVALID;
4958 free(partEnts.partEntries_val);
4964 "Could not fetch the list of partitions from the server\n");
4965 PrintError("", code);
4967 rx_DestroyConnection(aconn);
4972 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4973 This is used by the backup system */
4975 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4976 struct volDescription *volPtr, afs_int32 arraySize)
4978 struct rx_connection *aconn;
4979 struct volDescription *curPtr;
4982 afs_int32 rcode = 0;
4983 afs_int32 success = 1;
4986 aconn = (struct rx_connection *)0;
4987 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4989 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4990 if (curPtr->volFlags & CLONEVALID) {
4991 curPtr->volFlags &= ~CLONEZAPPED;
4994 AFSVolTransCreate_retry(aconn, curPtr->volCloneId, apart, ITOffline,
4999 code = AFSVolDeleteVolume(aconn, tid);
5002 code = AFSVolEndTrans(aconn, tid, &rcode);
5007 curPtr->volFlags |= CLONEZAPPED;
5009 fprintf(STDERR, "Could not zap volume %lu\n",
5010 (unsigned long)curPtr->volCloneId);
5012 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5013 curPtr->volCloneId);
5019 rx_DestroyConnection(aconn);
5023 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5026 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
5027 struct volDescription *volPtr, afs_int32 arraySize)
5029 struct rx_connection *aconn;
5030 struct volDescription *curPtr;
5033 afs_int32 rcode = 0;
5035 int reuseCloneId = 0;
5036 afs_uint32 curCloneId = 0;
5037 char cloneName[256]; /*max vol name */
5039 aconn = (struct rx_connection *)0;
5040 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5042 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5044 else { /*get a bunch of id's from vldb */
5046 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5048 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5049 PrintError("", code);
5054 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5055 if (curPtr->volFlags & ENTRYVALID) {
5057 curPtr->volFlags |= CLONEVALID;
5058 /*make a clone of curParentId and record as curPtr->volCloneId */
5060 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5063 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5066 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5070 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5071 strcpy(cloneName, curPtr->volName);
5072 strcat(cloneName, "-tmpClone-");
5074 strcpy(cloneName, "-tmpClone");
5076 curPtr->volCloneId = curCloneId;
5081 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5082 &(curPtr->volCloneId));
5084 curPtr->volFlags &= ~CLONEVALID;
5086 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5087 curPtr->volName, (unsigned long)code);
5088 code = AFSVolEndTrans(aconn, tid, &rcode);
5090 fprintf(STDERR, "WARNING: could not end transaction\n");
5093 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5094 curPtr->volCloneId);
5095 code = AFSVolEndTrans(aconn, tid, &rcode);
5096 if (code || rcode) {
5097 curPtr->volFlags &= ~CLONEVALID;
5106 rx_DestroyConnection(aconn);
5111 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5112 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5114 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5115 struct volintInfo **resultPtr, afs_int32 * size)
5117 struct rx_connection *aconn;
5119 volEntries volumeInfo;
5123 *resultPtr = (volintInfo *) 0;
5124 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5125 volumeInfo.volEntries_len = 0;
5127 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5128 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5131 "Could not fetch the list of volumes from the server\n");
5133 *resultPtr = volumeInfo.volEntries_val;
5134 *size = volumeInfo.volEntries_len;
5138 rx_DestroyConnection(aconn);
5139 PrintError("", code);
5143 /*------------------------------------------------------------------------
5144 * EXPORTED UV_XListVolumes
5147 * List the extended information for all the volumes on a particular
5148 * File Server and partition. We may either return the volume's ID
5149 * or all of its extended information.
5152 * a_serverID : Address of the File Server for which we want
5153 * extended volume info.
5154 * a_partID : Partition for which we want the extended
5156 * a_all : If non-zero, fetch ALL the volume info,
5157 * otherwise just the volume ID.
5158 * a_resultPP : Ptr to the address of the area containing
5159 * the returned volume info.
5160 * a_numEntsInResultP : Ptr for the value we set for the number of
5165 * Otherise, the return value of AFSVolXListVolumes.
5168 * This routine is closely related to UV_ListVolumes, which returns
5169 * only the standard level of detail on AFS volumes. It is a
5170 * heavyweight operation, zipping through all the volume entries for
5171 * a given server/partition.
5175 *------------------------------------------------------------------------*/
5178 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5179 struct volintXInfo **a_resultPP,
5180 afs_int32 * a_numEntsInResultP)
5182 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5183 afs_int32 code; /*Error code to return */
5184 volXEntries volumeXInfo; /*Area for returned extended vol info */
5187 * Set up our error code and the area for returned extended volume info.
5188 * We set the val field to a null pointer as a hint for the stub to
5192 *a_numEntsInResultP = 0;
5193 *a_resultPP = (volintXInfo *) 0;
5194 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5195 volumeXInfo.volXEntries_len = 0;
5198 * Bind to the Volume Server port on the File Server machine in question,
5201 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5202 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5204 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5207 * We got the info; pull out the pointer to where the results lie
5208 * and how many entries are there.
5210 *a_resultPP = volumeXInfo.volXEntries_val;
5211 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5215 * If we got an Rx connection, throw it away.
5218 rx_DestroyConnection(rxConnP);
5220 PrintError("", code);
5222 } /*UV_XListVolumes */
5224 /* get all the information about volume <volid> on <aserver> and <apart> */
5226 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 volid,
5227 struct volintInfo **resultPtr)
5229 struct rx_connection *aconn;
5231 volEntries volumeInfo;
5235 *resultPtr = (volintInfo *) 0;
5236 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5237 volumeInfo.volEntries_len = 0;
5239 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5240 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5243 "Could not fetch the information about volume %lu from the server\n",
5244 (unsigned long)volid);
5246 *resultPtr = volumeInfo.volEntries_val;
5251 rx_DestroyConnection(aconn);
5252 PrintError("", code);
5256 /*------------------------------------------------------------------------
5257 * EXPORTED UV_XListOneVolume
5260 * List the extended information for a volume on a particular File
5261 * Server and partition.
5264 * a_serverID : Address of the File Server for which we want
5265 * extended volume info.
5266 * a_partID : Partition for which we want the extended
5268 * a_volID : Volume ID for which we want the info.
5269 * a_resultPP : Ptr to the address of the area containing
5270 * the returned volume info.
5274 * Otherise, the return value of AFSVolXListOneVolume.
5277 * This routine is closely related to UV_ListOneVolume, which returns
5278 * only the standard level of detail on the chosen AFS volume.
5282 *------------------------------------------------------------------------*/
5285 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5286 struct volintXInfo **a_resultPP)
5288 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5289 afs_int32 code; /*Error code */
5290 volXEntries volumeXInfo; /*Area for returned info */
5293 * Set up our error code, and the area we're in which we are returning
5294 * the info. Setting the val field to a null pointer tells the stub
5295 * to allocate space for us.
5298 *a_resultPP = (volintXInfo *) 0;
5299 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5300 volumeXInfo.volXEntries_len = 0;
5303 * Bind to the Volume Server port on the File Server machine in question,
5306 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5307 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5310 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5313 * We got the info; pull out the pointer to where the results lie.
5315 *a_resultPP = volumeXInfo.volXEntries_val;
5318 * If we got an Rx connection, throw it away.
5321 rx_DestroyConnection(rxConnP);
5323 PrintError("", code);
5328 * Given a volume we read from a partition, check if it is
5329 * represented in the VLDB correctly.
5331 * The VLDB is looked up by the RW volume id (not its name).
5332 * The RW contains the true name of the volume (BK and RO set
5333 * the name in the VLDB only on creation of the VLDB entry).
5334 * We want rules strict enough that when we check all volumes
5335 * on one partition, it does not need to be done again. IE:
5336 * two volumes on different partitions won't constantly
5337 * change a VLDB entry away from what the other set.
5338 * For RW and BK volumes, we will always check the VLDB to see
5339 * if the two exist on the server/partition. May seem redundant,
5340 * but this is an easy check of the VLDB. IE: if the VLDB entry
5341 * says the BK exists but no BK volume is there, we will detect
5342 * this when we check the RW volume.
5343 * VLDB entries are locked only when a change needs to be done.
5344 * Output changed to look a lot like the "vos syncserv" otuput.
5347 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5348 afs_int32 * modentry, afs_uint32 * maxvolid)
5352 afs_int32 code, error = 0;
5353 struct nvldbentry entry, storeEntry;
5355 int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
5365 ((volumeinfo->type ==
5366 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5369 /* Check to see if the VLDB is ok without locking it (pass 1).
5370 * If it will change, then lock the VLDB entry, read it again,
5371 * then make the changes to it (pass 2).
5374 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5376 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5377 (unsigned long)rwvolid);
5383 createentry = 0; /* Do we need to create a VLDB entry */
5384 addvolume = 0; /* Add this volume to the VLDB entry */
5385 modified = 0; /* The VLDB entry was modified */
5387 /* Read the entry from VLDB by its RW volume id */
5388 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5390 if (code != VL_NOENT) {
5392 "Could not retreive the VLDB entry for volume %lu \n",
5393 (unsigned long)rwvolid);
5397 memset(&entry, 0, sizeof(entry));
5398 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5402 MapHostToNetwork(&entry);
5405 if (verbose && (pass == 1)) {
5406 fprintf(STDOUT, "_______________________________\n");
5407 fprintf(STDOUT, "\n-- status before -- \n");
5409 fprintf(STDOUT, "\n**does not exist**\n");
5411 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5412 || (entry.flags & BACK_EXISTS))
5413 EnumerateEntry(&entry);
5415 fprintf(STDOUT, "\n");
5418 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5424 /* Check existence of RW and BK volumes */
5425 code = CheckVldbRWBK(&entry, &mod);
5431 idx = Lp_GetRwIndex(&entry);
5432 if (idx == -1) { /* RW index not found in the VLDB entry */
5433 idx = entry.nServers; /* put it into next index */
5436 } else { /* RW index found in the VLDB entry. */
5437 /* Verify if this volume's location matches where the VLDB says it is */
5438 if (!Lp_Match(aserver, apart, &entry)) {
5439 if (entry.flags & RW_EXISTS) {
5440 /* The RW volume exists elsewhere - report this one a duplicate */
5442 MapPartIdIntoName(apart, pname);
5444 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5445 (unsigned long)rwvolid,
5447 afs_inet_ntoa_r(aserver, hoststr) :
5448 hostutil_GetNameByINet(aserver), pname);
5449 MapPartIdIntoName(entry.serverPartition[idx],
5452 " VLDB reports RW volume %lu exists on %s %s\n",
5453 (unsigned long)rwvolid,
5455 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5456 hostutil_GetNameByINet(entry.
5461 /* The RW volume does not exist - have VLDB point to this one */
5464 /* Check for orphaned BK volume on old partition */
5465 if (entry.flags & BACK_EXISTS) {
5467 MapPartIdIntoName(entry.serverPartition[idx],
5470 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5471 entry.volumeId[BACKVOL],
5473 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5474 hostutil_GetNameByINet(entry.
5477 MapPartIdIntoName(apart, pname);
5479 " VLDB reports its RW volume %lu exists on %s %s\n",
5480 (unsigned long)rwvolid,
5482 afs_inet_ntoa_r(aserver, hoststr) :
5483 hostutil_GetNameByINet(aserver),
5489 /* Volume location matches the VLDB location */
5490 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5491 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5494 (entry.name, volumeinfo->name,
5495 VOLSER_OLDMAXVOLNAME) != 0)) {
5503 entry.flags |= RW_EXISTS;
5504 entry.volumeId[RWVOL] = rwvolid;
5505 if (!entry.volumeId[BACKVOL])
5506 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5507 if (!entry.volumeId[ROVOL])
5508 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5510 entry.serverFlags[idx] = ITSRWVOL;
5511 entry.serverNumber[idx] = aserver;
5512 entry.serverPartition[idx] = apart;
5513 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5517 /* One last check - to update BK if need to */
5518 code = CheckVldbRWBK(&entry, &mod);
5526 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5532 /* Check existence of RW and BK volumes */
5533 code = CheckVldbRWBK(&entry, &mod);
5539 idx = Lp_GetRwIndex(&entry);
5540 if (idx == -1) { /* RW index not found in the VLDB entry */
5541 idx = entry.nServers; /* Put it into next index */
5544 } else { /* RW index found in the VLDB entry */
5545 /* Verify if this volume's location matches where the VLDB says it is */
5546 if (!Lp_Match(aserver, apart, &entry)) {
5547 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5549 MapPartIdIntoName(apart, pname);
5551 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5552 (unsigned long)volumeinfo->volid,
5554 afs_inet_ntoa_r(aserver, hoststr) :
5555 hostutil_GetNameByINet(aserver), pname);
5556 MapPartIdIntoName(entry.serverPartition[idx], pname);
5558 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5559 (unsigned long)rwvolid,
5561 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5562 hostutil_GetNameByINet(entry.
5567 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5568 if (!(entry.flags & BACK_EXISTS)) {
5570 } else if (volumeinfo->volid >
5571 entry.volumeId[BACKVOL]) {
5575 MapPartIdIntoName(entry.serverPartition[idx],
5578 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5579 entry.volumeId[BACKVOL],
5581 afs_inet_ntoa_r(aserver, hoststr) :
5582 hostutil_GetNameByINet(aserver),
5585 " VLDB reports its BK volume ID is %lu\n",
5586 (unsigned long)volumeinfo->volid);
5590 MapPartIdIntoName(entry.serverPartition[idx],
5593 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5594 (unsigned long)volumeinfo->volid,
5596 afs_inet_ntoa_r(aserver, hoststr) :
5597 hostutil_GetNameByINet(aserver),
5600 " VLDB reports its BK volume ID is %u\n",
5601 entry.volumeId[BACKVOL]);
5604 } else if (!entry.volumeId[BACKVOL]) {
5611 entry.flags |= BACK_EXISTS;
5612 entry.volumeId[RWVOL] = rwvolid;
5613 entry.volumeId[BACKVOL] = volumeinfo->volid;
5615 entry.serverNumber[idx] = aserver;
5616 entry.serverPartition[idx] = apart;
5617 entry.serverFlags[idx] = ITSBACKVOL;
5623 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5624 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5625 /* This is a quick check to see if the RO entry exists in the
5626 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5627 * RO volume listed in the VLDB exists).
5629 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5631 idx = entry.nServers;
5635 if (!(entry.flags & RO_EXISTS)) {
5640 /* Before we correct the VLDB entry, make sure all the
5641 * ROs listed in the VLDB exist.
5643 code = CheckVldbRO(&entry, &mod);
5649 if (!(entry.flags & RO_EXISTS)) {
5650 /* No RO exists in the VLDB entry - add this one */
5651 idx = entry.nServers;
5654 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5655 /* The volume headers's RO ID does not match that in the VLDB entry,
5656 * and the vol hdr's ID is greater (implies more recent). So delete
5657 * all the RO volumes listed in VLDB entry and add this volume.
5659 for (j = 0; j < entry.nServers; j++) {
5660 if (entry.serverFlags[j] & ITSROVOL) {
5661 /* Verify this volume exists and print message we are orphaning it */
5663 MapPartIdIntoName(apart, pname);
5665 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5666 entry.volumeId[ROVOL],
5668 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5669 hostutil_GetNameByINet(entry.
5673 " VLDB reports its RO volume ID is %lu\n",
5674 (unsigned long)volumeinfo->volid);
5677 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5678 entry.serverPartition[idx], 0L, 0L);
5685 idx = entry.nServers;
5688 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5689 /* The volume headers's RO ID does not match that in the VLDB entry,
5690 * and the vol hdr's ID is lower (implies its older). So orphan it.
5693 MapPartIdIntoName(apart, pname);
5695 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5696 (unsigned long)volumeinfo->volid,
5698 afs_inet_ntoa_r(aserver, hoststr) :
5699 hostutil_GetNameByINet(aserver), pname);
5701 " VLDB reports its RO volume ID is %u\n",
5702 entry.volumeId[ROVOL]);
5705 /* The RO volume ID in the volume header match that in the VLDB entry,
5706 * and there exist RO volumes in the VLDB entry. See if any of them
5707 * are this one. If not, then we add it.
5709 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5711 idx = entry.nServers;
5719 entry.flags |= RO_EXISTS;
5720 entry.volumeId[RWVOL] = rwvolid;
5721 entry.volumeId[ROVOL] = volumeinfo->volid;
5723 entry.serverNumber[idx] = aserver;
5724 entry.serverPartition[idx] = apart;
5725 entry.serverFlags[idx] = ITSROVOL;
5731 /* Remember largest volume id */
5732 if (entry.volumeId[ROVOL] > *maxvolid)
5733 *maxvolid = entry.volumeId[ROVOL];
5734 if (entry.volumeId[BACKVOL] > *maxvolid)
5735 *maxvolid = entry.volumeId[BACKVOL];
5736 if (entry.volumeId[RWVOL] > *maxvolid)
5737 *maxvolid = entry.volumeId[RWVOL];
5739 if (modified && doit) {
5740 MapNetworkToHost(&entry, &storeEntry);
5743 code = VLDB_CreateEntry(&storeEntry);
5746 "Could not create a VLDB entry for the volume %lu\n",
5747 (unsigned long)rwvolid);
5754 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5755 LOCKREL_OPCODE | LOCKREL_AFSID |
5758 fprintf(STDERR, "Could not update entry for %lu\n",
5759 (unsigned long)rwvolid);
5764 *modentry = modified;
5765 } else if (pass == 2) {
5767 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5768 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5770 PrintError("Could not unlock VLDB entry ", code);
5774 if (verbose && doit) {
5775 fprintf(STDOUT, "-- status after --\n");
5777 EnumerateEntry(&entry);
5779 fprintf(STDOUT, "\n**no change**\n");
5783 VPRINT("\n_______________________________\n");
5788 sortVolumes(const void *a, const void *b)
5790 volintInfo *v1 = (volintInfo *) a;
5791 volintInfo *v2 = (volintInfo *) b;
5792 afs_uint32 rwvolid1, rwvolid2;
5794 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5795 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5797 if (rwvolid1 > rwvolid2)
5798 return -1; /* lower RW id goes first */
5799 if (rwvolid1 < rwvolid2)
5802 if (v1->type == RWVOL)
5803 return -1; /* RW vols go first */
5804 if (v2->type == RWVOL)
5807 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5808 return -1; /* BK vols next */
5809 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5812 if (v1->volid < v2->volid)
5813 return 1; /* larger volids first */
5814 if (v1->volid > v2->volid)
5820 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5821 * Synchronize an individual volume against a sever and partition.
5822 * Checks the VLDB entry (similar to syncserv) as well as checks
5823 * if the volume exists on specified servers (similar to syncvldb).
5826 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5828 struct rx_connection *aconn = 0;
5829 afs_int32 j, k, code, vcode, error = 0;
5831 afs_int32 mod, modified = 0;
5832 struct nvldbentry vldbentry;
5833 afs_uint32 volumeid = 0;
5834 volEntries volumeInfo;
5835 struct partList PartList;
5837 afs_uint32 maxvolid = 0;
5839 volumeInfo.volEntries_val = (volintInfo *) 0;
5840 volumeInfo.volEntries_len = 0;
5842 /* Turn verbose logging off and do our own verbose logging */
5843 /* tverbose must be set before we call ERROR_EXIT() */
5850 if (!aserver && (flags & 1)) {
5851 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5855 /* Read the VLDB entry */
5856 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5857 if (vcode && (vcode != VL_NOENT)) {
5858 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5861 } else if (!vcode) {
5862 MapHostToNetwork(&vldbentry);
5866 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5867 fprintf(STDOUT, "_______________________________\n");
5868 fprintf(STDOUT, "\n-- status before -- \n");
5870 fprintf(STDOUT, "\n**does not exist**\n");
5872 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5873 || (vldbentry.flags & BACK_EXISTS))
5874 EnumerateEntry(&vldbentry);
5876 fprintf(STDOUT, "\n");
5879 /* Verify that all of the VLDB entries exist on the repective servers
5880 * and partitions (this does not require that avolname be a volume ID).
5881 * Equivalent to a syncserv.
5884 /* Tell CheckVldb not to update if appropriate */
5889 code = CheckVldb(&vldbentry, &mod);
5891 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5899 /* If aserver is given, we will search for the desired volume on it */
5901 /* Generate array of partitions on the server that we will check */
5903 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5906 "Could not fetch the list of partitions from the server\n");
5910 PartList.partId[0] = apart;
5914 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5916 /* If a volume ID were given, search for it on each partition */
5917 if ((volumeid = atol(avolname))) {
5918 for (j = 0; j < pcnt; j++) {
5920 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5923 if (code != ENODEV) {
5924 fprintf(STDERR, "Could not query server\n");
5932 /* Found one, sync it with VLDB entry */
5934 CheckVolume(volumeInfo.volEntries_val, aserver,
5935 PartList.partId[j], &mod, &maxvolid);
5942 if (volumeInfo.volEntries_val)
5943 free(volumeInfo.volEntries_val);
5944 volumeInfo.volEntries_val = (volintInfo *) 0;
5945 volumeInfo.volEntries_len = 0;
5949 /* Check to see if the RW, BK, and RO IDs exist on any
5950 * partitions. We get the volume IDs from the VLDB.
5952 rv = 1; /* Read the VLDB entry ? */
5953 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5955 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5957 if (vcode == VL_NOENT)
5960 "Could not access the VLDB for volume %s\n",
5967 if (vldbentry.volumeId[j] == 0)
5970 for (k = 0; k < pcnt; k++) { /* For each partition */
5971 volumeInfo.volEntries_val = (volintInfo *) 0;
5972 volumeInfo.volEntries_len = 0;
5974 AFSVolListOneVolume(aconn, PartList.partId[k],
5975 vldbentry.volumeId[j], &volumeInfo);
5977 if (code != ENODEV) {
5978 fprintf(STDERR, "Could not query server\n");
5986 /* Found one, sync it with VLDB entry */
5988 CheckVolume(volumeInfo.volEntries_val, aserver,
5989 PartList.partId[k], &mod, &maxvolid);
5996 if (volumeInfo.volEntries_val)
5997 free(volumeInfo.volEntries_val);
5998 volumeInfo.volEntries_val = (volintInfo *) 0;
5999 volumeInfo.volEntries_len = 0;
6005 /* If verbose output, print a summary of what changed */
6006 if (tverbose && !(flags & 2)) {
6007 fprintf(STDOUT, "-- status after --\n");
6008 code = VLDB_GetEntryByName(avolname, &vldbentry);
6009 if (code && (code != VL_NOENT)) {
6010 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6014 if (modified && (code == VL_NOENT)) {
6015 fprintf(STDOUT, "\n**entry deleted**\n");
6016 } else if (modified) {
6017 EnumerateEntry(&vldbentry);
6019 fprintf(STDOUT, "\n**no change**\n");
6021 fprintf(STDOUT, "\n_______________________________\n");
6025 /* Now check if the maxvolid is larger than that stored in the VLDB */
6027 afs_uint32 maxvldbid = 0;
6028 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6031 "Could not get the highest allocated volume id from the VLDB\n");
6034 } else if (maxvolid > maxvldbid) {
6036 id = maxvolid - maxvldbid + 1;
6037 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6040 "Error in increasing highest allocated volume id in VLDB\n");
6050 fprintf(STDOUT, "...error encountered");
6052 fprintf(STDOUT, "...done entry\n");
6055 rx_DestroyConnection(aconn);
6056 if (volumeInfo.volEntries_val)
6057 free(volumeInfo.volEntries_val);
6059 PrintError("", error);
6064 * Synchronise vldb with the file server <aserver> and,
6065 * optionally, <apart>.
6068 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
6070 struct rx_connection *aconn;
6071 afs_int32 code, error = 0;
6074 volEntries volumeInfo;
6075 struct partList PartList;
6079 afs_int32 failures = 0, modifications = 0, tentries = 0;
6081 afs_uint32 maxvolid = 0;
6084 volumeInfo.volEntries_val = (volintInfo *) 0;
6085 volumeInfo.volEntries_len = 0;
6087 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6089 /* Generate array of partitions to check */
6091 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6094 "Could not fetch the list of partitions from the server\n");
6098 PartList.partId[0] = apart;
6102 VPRINT("Processing volume entries ...\n");
6104 /* Step through the array of partitions */
6105 for (i = 0; i < pcnt; i++) {
6106 apart = PartList.partId[i];
6107 MapPartIdIntoName(apart, pname);
6109 volumeInfo.volEntries_val = (volintInfo *) 0;
6110 volumeInfo.volEntries_len = 0;
6111 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6114 "Could not fetch the list of volumes from the server\n");
6118 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6119 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6120 sizeof(volintInfo), sortVolumes);
6123 for (vi = volumeInfo.volEntries_val, j = 0;
6124 j < volumeInfo.volEntries_len; j++, vi++) {
6132 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6133 j + 1, vi->name, (unsigned long)vi->volid,
6135 afs_inet_ntoa_r(aserver, hoststr) :
6136 hostutil_GetNameByINet(aserver), pname);
6144 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
6146 PrintError("", code);
6149 } else if (modified) {
6155 fprintf(STDOUT, "...error encountered\n\n");
6157 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6164 "Could not process entries on server %s partition %s\n",
6166 afs_inet_ntoa_r(aserver, hoststr) :
6167 hostutil_GetNameByINet(aserver), pname);
6169 if (volumeInfo.volEntries_val) {
6170 free(volumeInfo.volEntries_val);
6171 volumeInfo.volEntries_val = 0;
6174 } /* thru all partitions */
6177 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6178 tentries, failures, modifications);
6180 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6181 tentries, failures, modifications);
6185 /* Now check if the maxvolid is larger than that stored in the VLDB */
6187 afs_uint32 maxvldbid = 0;
6188 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6191 "Could not get the highest allocated volume id from the VLDB\n");
6194 } else if (maxvolid > maxvldbid) {
6196 id = maxvolid - maxvldbid + 1;
6197 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6200 "Error in increasing highest allocated volume id in VLDB\n");
6208 rx_DestroyConnection(aconn);
6209 if (volumeInfo.volEntries_val)
6210 free(volumeInfo.volEntries_val);
6211 PrintError("", error);
6216 * Determine if a volume exists on a server and partition.
6217 * Try creating a transaction on the volume. If we can,
6218 * the volume exists, if not, then return the error code.
6219 * Some error codes mean the volume is unavailable but
6220 * still exists - so we catch these error codes.
6223 VolumeExists(afs_int32 server, afs_int32 partition, afs_uint32 volumeid)
6225 struct rx_connection *conn = (struct rx_connection *)0;
6226 afs_int32 code = -1;
6227 volEntries volumeInfo;
6229 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6231 volumeInfo.volEntries_val = (volintInfo *) 0;
6232 volumeInfo.volEntries_len = 0;
6233 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6234 if (volumeInfo.volEntries_val)
6235 free(volumeInfo.volEntries_val);
6236 if (code == VOLSERILLEGAL_PARTITION)
6238 rx_DestroyConnection(conn);
6247 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6251 afs_int32 code, error = 0;
6257 idx = Lp_GetRwIndex(entry);
6259 /* Check to see if the RW volume exists and set the RW_EXISTS
6262 if (idx == -1) { /* Did not find a RW entry */
6263 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6264 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6269 VolumeExists(entry->serverNumber[idx],
6270 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6271 if (code == 0) { /* RW volume exists */
6272 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6273 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6276 } else if (code == ENODEV) { /* RW volume does not exist */
6277 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6278 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6282 /* If VLDB says it didn't exist, then ignore error */
6283 if (entry->flags & RW_EXISTS) {
6284 MapPartIdIntoName(entry->serverPartition[idx], pname);
6286 "Transaction call failed for RW volume %u on server %s %s\n",
6287 entry->volumeId[RWVOL],
6289 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6290 hostutil_GetNameByINet(entry->serverNumber[idx]),
6297 /* Check to see if the BK volume exists and set the BACK_EXISTS
6298 * flag accordingly. idx already ponts to the RW entry.
6300 if (idx == -1) { /* Did not find a RW entry */
6301 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6302 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6305 } else { /* Found a RW entry */
6307 VolumeExists(entry->serverNumber[idx],
6308 entry->serverPartition[idx],
6309 entry->volumeId[BACKVOL]);
6310 if (code == 0) { /* BK volume exists */
6311 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6312 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6315 } else if (code == ENODEV) { /* BK volume does not exist */
6316 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6317 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6321 /* If VLDB says it didn't exist, then ignore error */
6322 if (entry->flags & BACK_EXISTS) {
6323 MapPartIdIntoName(entry->serverPartition[idx], pname);
6325 "Transaction call failed for BK volume %u on server %s %s\n",
6326 entry->volumeId[BACKVOL],
6328 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6329 hostutil_GetNameByINet(entry->serverNumber[idx]),
6336 /* If there is an idx but the BK and RW volumes no
6337 * longer exist, then remove the RW entry.
6339 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6340 && !(entry->flags & BACK_EXISTS)) {
6341 Lp_SetRWValue(entry, entry->serverNumber[idx],
6342 entry->serverPartition[idx], 0L, 0L);
6349 *modified = modentry;
6354 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6357 int foundro = 0, modentry = 0;
6358 afs_int32 code, error = 0;
6365 /* Check to see if the RO volumes exist and set the RO_EXISTS
6368 for (idx = 0; idx < entry->nServers; idx++) {
6369 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6370 continue; /* not a RO */
6374 VolumeExists(entry->serverNumber[idx],
6375 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6376 if (code == 0) { /* RO volume exists */
6378 } else if (code == ENODEV) { /* RW volume does not exist */
6379 Lp_SetROValue(entry, entry->serverNumber[idx],
6380 entry->serverPartition[idx], 0L, 0L);
6385 MapPartIdIntoName(entry->serverPartition[idx], pname);
6387 "Transaction call failed for RO %u on server %s %s\n",
6388 entry->volumeId[ROVOL],
6390 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6391 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6396 if (foundro) { /* A RO volume exists */
6397 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6398 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6401 } else { /* A RO volume does not exist */
6402 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6403 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6410 *modified = modentry;
6415 * Ensure that <entry> matches with the info on file servers
6418 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6420 afs_int32 code, error = 0;
6421 struct nvldbentry storeEntry;
6422 int islocked = 0, mod, modentry, delentry = 0;
6423 int pass = 0, doit=1;
6431 fprintf(STDOUT, "_______________________________\n");
6432 fprintf(STDOUT, "\n-- status before -- \n");
6433 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6434 || (entry->flags & BACK_EXISTS))
6435 EnumerateEntry(entry);
6436 fprintf(STDOUT, "\n");
6439 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6440 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6441 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6445 /* Check to see if the VLDB is ok without locking it (pass 1).
6446 * If it will change, then lock the VLDB entry, read it again,
6447 * then make the changes to it (pass 2).
6451 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6454 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6455 entry->volumeId[RWVOL]);
6460 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6462 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6466 MapHostToNetwork(entry);
6472 /* Check if the RW and BK entries are ok */
6473 code = CheckVldbRWBK(entry, &mod);
6476 if (mod && (pass == 1) && doit)
6481 /* Check if the RO volumes entries are ok */
6482 code = CheckVldbRO(entry, &mod);
6485 if (mod && (pass == 1) && doit)
6490 /* The VLDB entry has been updated. If it as been modified, then
6491 * write the entry back out the the VLDB.
6493 if (modentry && doit) {
6497 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6498 && !(entry->flags & RO_EXISTS) && doit) {
6499 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6501 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6505 "Could not delete VLDB entry for volume %u \n",
6506 entry->volumeId[RWVOL]);
6511 /* Replace old entry with our new one */
6512 MapNetworkToHost(entry, &storeEntry);
6514 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6515 (LOCKREL_OPCODE | LOCKREL_AFSID |
6516 LOCKREL_TIMESTAMP));
6518 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6519 entry->volumeId[RWVOL]);
6528 if (verbose && doit) {
6529 fprintf(STDOUT, "-- status after --\n");
6531 fprintf(STDOUT, "\n**entry deleted**\n");
6533 EnumerateEntry(entry);
6535 fprintf(STDOUT, "\n**no change**\n");
6539 VPRINT("\n_______________________________\n");
6543 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6545 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6548 "Could not release lock on VLDB entry for volume %u\n",
6549 entry->volumeId[RWVOL]);
6558 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6561 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6563 struct rx_connection *aconn;
6564 afs_int32 code, error = 0;
6565 afs_int32 nentries, tentries = 0;
6566 struct VldbListByAttributes attributes;
6567 nbulkentries arrayEntries;
6568 afs_int32 failures = 0, modified, modifications = 0;
6569 struct nvldbentry *vlentry;
6570 afs_int32 si, nsi, j;
6575 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6577 /* Set up attributes to search VLDB */
6578 attributes.server = ntohl(aserver);
6579 attributes.Mask = VLLIST_SERVER;
6581 attributes.partition = apart;
6582 attributes.Mask |= VLLIST_PARTITION;
6585 VPRINT("Processing VLDB entries ...\n");
6587 /* While we need to collect more VLDB entries */
6588 for (si = 0; si != -1; si = nsi) {
6589 memset(&arrayEntries, 0, sizeof(arrayEntries));
6591 /* Collect set of VLDB entries */
6593 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6594 &arrayEntries, &nsi);
6595 if (code == RXGEN_OPCODE) {
6596 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6600 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6603 tentries += nentries;
6605 for (j = 0; j < nentries; j++) {
6606 vlentry = &arrayEntries.nbulkentries_val[j];
6607 MapHostToNetwork(vlentry);
6609 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6611 /* Tell CheckVldb not to update if appropriate */
6616 code = CheckVldb(vlentry, &modified);
6618 PrintError("", code);
6620 "Could not process VLDB entry for volume %s\n",
6623 } else if (modified) {
6629 fprintf(STDOUT, "...error encountered\n\n");
6631 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6636 if (arrayEntries.nbulkentries_val) {
6637 free(arrayEntries.nbulkentries_val);
6638 arrayEntries.nbulkentries_val = 0;
6643 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6644 tentries, failures, modifications);
6646 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6647 tentries, failures, modifications);
6652 rx_DestroyConnection(aconn);
6653 if (arrayEntries.nbulkentries_val)
6654 free(arrayEntries.nbulkentries_val);
6657 error = VOLSERFAILEDOP;
6661 /*rename volume <oldname> to <newname>, changing the names of the related
6662 *readonly and backup volumes. This operation is also idempotent.
6663 *salvager is capable of recovering from rename operation stopping halfway.
6664 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6666 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6668 struct nvldbentry storeEntry;
6669 afs_int32 vcode, code, rcode, error;
6671 char nameBuffer[256];
6673 struct rx_connection *aconn;
6678 aconn = (struct rx_connection *)0;
6682 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6685 " Could not lock the VLDB entry for the volume %u \n",
6686 entry->volumeId[RWVOL]);
6691 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6692 MapNetworkToHost(entry, &storeEntry);
6693 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6695 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6696 entry->volumeId[RWVOL]);
6700 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6701 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6702 * is concerned, oldname is lost */
6703 if (entry->flags & RW_EXISTS) {
6704 index = Lp_GetRwIndex(entry);
6705 if (index == -1) { /* there is a serious discrepancy */
6707 "There is a serious discrepancy in VLDB entry for volume %u\n",
6708 entry->volumeId[RWVOL]);
6709 fprintf(STDERR, "try building VLDB from scratch\n");
6710 error = VOLSERVLDB_ERROR;
6713 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6715 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
6716 entry->serverPartition[index], ITOffline, &tid);
6717 if (code) { /*volume doesnot exist */
6719 "Could not start transaction on the rw volume %u\n",
6720 entry->volumeId[RWVOL]);
6723 } else { /*volume exists, process it */
6726 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6727 entry->volumeId[RWVOL],
6728 entry->volumeId[ROVOL],
6729 entry->volumeId[BACKVOL]);
6731 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6732 code = AFSVolEndTrans(aconn, tid, &rcode);
6736 "Could not end transaction on volume %s %u\n",
6737 entry->name, entry->volumeId[RWVOL]);
6742 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6743 entry->name, entry->volumeId[RWVOL]);
6749 rx_DestroyConnection(aconn);
6750 aconn = (struct rx_connection *)0;
6752 /*end rw volume processing */
6753 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6754 index = Lp_GetRwIndex(entry);
6755 if (index == -1) { /* there is a serious discrepancy */
6757 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6758 entry->volumeId[BACKVOL]);
6759 fprintf(STDERR, "try building VLDB from scratch\n");
6760 error = VOLSERVLDB_ERROR;
6763 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6765 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
6766 entry->serverPartition[index], ITOffline, &tid);
6767 if (code) { /*volume doesnot exist */
6769 "Could not start transaction on the backup volume %u\n",
6770 entry->volumeId[BACKVOL]);
6773 } else { /*volume exists, process it */
6774 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6776 "Volume name %s.backup exceeds the limit of %u characters\n",
6777 newname, VOLSER_OLDMAXVOLNAME);
6781 strcpy(nameBuffer, newname);
6782 strcat(nameBuffer, ".backup");
6785 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6786 entry->volumeId[RWVOL], 0, 0);
6788 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6789 code = AFSVolEndTrans(aconn, tid, &rcode);
6793 "Could not end transaction on the backup volume %u\n",
6794 entry->volumeId[BACKVOL]);
6800 "Could not set parameters on the backup volume %u\n",
6801 entry->volumeId[BACKVOL]);
6806 } /* end backup processing */
6808 rx_DestroyConnection(aconn);
6809 aconn = (struct rx_connection *)0;
6810 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6811 for (i = 0; i < entry->nServers; i++) {
6812 if (entry->serverFlags[i] & ITSROVOL) {
6813 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6815 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
6816 entry->serverPartition[i], ITOffline,
6818 if (code) { /*volume doesnot exist */
6820 "Could not start transaction on the ro volume %u\n",
6821 entry->volumeId[ROVOL]);
6824 } else { /*volume exists, process it */
6825 strcpy(nameBuffer, newname);
6826 strcat(nameBuffer, ".readonly");
6827 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6829 "Volume name %s exceeds the limit of %u characters\n",
6830 nameBuffer, VOLSER_OLDMAXVOLNAME);
6835 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6836 entry->volumeId[RWVOL], 0, 0);
6838 VPRINT2("Renamed RO volume %s on host %s\n",
6841 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
6842 hostutil_GetNameByINet(entry->
6844 code = AFSVolEndTrans(aconn, tid, &rcode);
6848 "Could not end transaction on volume %u\n",
6849 entry->volumeId[ROVOL]);
6855 "Could not set parameters on the ro volume %u\n",
6856 entry->volumeId[ROVOL]);
6862 rx_DestroyConnection(aconn);
6863 aconn = (struct rx_connection *)0;
6870 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6872 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6875 "Could not unlock the VLDB entry for the volume %s %u\n",
6876 entry->name, entry->volumeId[RWVOL]);
6882 code = AFSVolEndTrans(aconn, tid, &rcode);
6886 fprintf(STDERR, "Failed to end transaction on a volume \n");
6892 rx_DestroyConnection(aconn);
6893 PrintError("", error);
6898 /*report on all the active transactions on volser */
6900 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6902 struct rx_connection *aconn;
6903 transDebugEntries transInfo;
6906 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6907 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6908 transInfo.transDebugEntries_len = 0;
6909 code = AFSVolMonitor(aconn, &transInfo);
6912 "Could not access status information about the server\n");
6913 PrintError("", code);
6914 if (transInfo.transDebugEntries_val)
6915 free(transInfo.transDebugEntries_val);
6917 rx_DestroyConnection(aconn);
6920 *rcount = transInfo.transDebugEntries_len;
6921 *rpntr = transInfo.transDebugEntries_val;
6923 rx_DestroyConnection(aconn);
6930 /*delete the volume without interacting with the vldb */
6932 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_uint32 volid)
6934 afs_int32 rcode, ttid, error, code;
6935 struct rx_connection *aconn;
6941 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6942 code = AFSVolTransCreate_retry(aconn, volid, part, ITOffline, &ttid);
6944 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6945 (unsigned long)volid);
6949 code = AFSVolDeleteVolume(aconn, ttid);
6951 fprintf(STDERR, "Could not delete volume %lu\n",
6952 (unsigned long)volid);
6956 code = AFSVolEndTrans(aconn, ttid, &rcode);
6961 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6962 (unsigned long)volid);
6968 code = AFSVolEndTrans(aconn, ttid, &rcode);
6974 PrintError("", error);
6976 rx_DestroyConnection(aconn);
6981 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_uint32 volid,
6982 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6984 struct rx_connection *conn = 0;
6986 afs_int32 code, error = 0, rcode;
6988 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6990 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6994 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
6996 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7000 code = AFSVolSetFlags(conn, tid, setflag);
7002 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7007 #ifdef AFS_PTHREAD_ENV
7010 IOMGR_Sleep(sleeptime);
7017 code = AFSVolEndTrans(conn, tid, &rcode);
7018 if (code || rcode) {
7019 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7021 error = (code ? code : rcode);
7026 rx_DestroyConnection(conn);
7031 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_uint32 volid,
7034 struct rx_connection *conn = 0;
7036 afs_int32 code, error = 0, rcode;
7038 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7040 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7044 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7046 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7050 code = AFSVolSetInfo(conn, tid, infop);
7052 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7059 code = AFSVolEndTrans(conn, tid, &rcode);
7060 if (code || rcode) {
7061 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7063 error = (code ? code : rcode);
7068 rx_DestroyConnection(conn);
7073 UV_GetSize(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
7074 afs_int32 fromdate, struct volintSize *vol_size)
7076 struct rx_connection *aconn = (struct rx_connection *)0;
7077 afs_int32 tid = 0, rcode = 0;
7078 afs_int32 code, error = 0;
7081 /* get connections to the servers */
7082 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7084 VPRINT1("Starting transaction on volume %u...", afromvol);
7085 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7086 EGOTO1(error_exit, code,
7087 "Could not start transaction on the volume %u to be measured\n",
7091 VPRINT1("Getting size of volume on volume %u...", afromvol);
7092 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7093 EGOTO(error_exit, code, "Could not start the measurement process \n");
7098 VPRINT1("Ending transaction on volume %u...", afromvol);
7099 code = AFSVolEndTrans(aconn, tid, &rcode);
7100 if (code || rcode) {
7101 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7103 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7105 error = (code ? code : rcode);
7110 rx_DestroyConnection(aconn);
7112 PrintError("", error);
7116 /*maps the host addresses in <old > (present in network byte order) to
7117 that in< new> (present in host byte order )*/
7119 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7123 /*copy all the fields */
7124 strcpy(new->name, old->name);
7125 /* new->volumeType = old->volumeType;*/
7126 new->nServers = old->nServers;
7127 count = old->nServers;
7128 if (count < NMAXNSERVERS)
7130 for (i = 0; i < count; i++) {
7131 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7132 new->serverPartition[i] = old->serverPartition[i];
7133 new->serverFlags[i] = old->serverFlags[i];
7135 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7136 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7137 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7138 new->cloneId = old->cloneId;
7139 new->flags = old->flags;
7142 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7144 MapHostToNetwork(struct nvldbentry *entry)
7148 count = entry->nServers;
7149 if (count < NMAXNSERVERS)
7151 for (i = 0; i < count; i++) {
7152 entry->serverNumber[i] = htonl(entry->serverNumber[i]);