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>
13 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
17 #include <sys/statfs.h>
21 #include <afs/voldefs.h>
24 #include <rx/rx_queue.h>
25 #include <afs/vlserver.h>
27 #include <afs/cellconfig.h>
30 #include <afs/afsint.h>
34 #include <afs/com_err.h>
36 #include <afs/kautils.h>
38 #include <afs/ihandle.h>
40 #include <afs/ntops.h>
42 #include <afs/vnode.h>
43 #include <afs/volume.h>
44 #define ERRCODE_RANGE 8 /* from error_table.h */
45 #define CLOCKSKEW 2 /* not really skew, but resolution */
46 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
48 /* for UV_MoveVolume() recovery */
52 #include "volser_internal.h"
53 #include "volser_prototypes.h"
54 #include "vsutils_prototypes.h"
55 #include "lockprocs_prototypes.h"
57 extern struct ubik_client *cstruct;
58 int verbose = 0, noresolve = 0;
63 afs_int32 vldbEntryIndex;
66 /* Utility macros used by rest of this source file */
67 #define EPRINT(ec, es) \
69 fprintf(STDERR, "\n"); \
70 fprintf(STDERR, (es)); \
74 #define EPRINT1(ec, es, ep1) \
76 fprintf(STDERR, "\n"); \
77 fprintf(STDERR, (es), (ep1)); \
81 #define EPRINT2(ec, es, ep1, ep2) \
83 fprintf(STDERR, "\n"); \
84 fprintf(STDERR, (es), (ep1), (ep2)); \
88 #define EPRINT3(ec, es, ep1, ep2, ep3) \
90 fprintf(STDERR, "\n"); \
91 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
95 #define EGOTO(where, ec, es) \
104 #define EGOTO1(where, ec, es, ep1) \
107 EPRINT1((ec),(es),(ep1)); \
113 #define EGOTO2(where, ec, es, ep1, ep2) \
116 EPRINT2((ec),(es),(ep1),(ep2)); \
122 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
125 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
132 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
133 #define VPRINT1(es, p) \
134 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
135 #define VPRINT2(es, p1, p2) \
136 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
137 #define VPRINT3(es, p1, p2, p3) \
138 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
140 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
141 #define VEPRINT(es) \
142 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
143 #define VEPRINT1(es, p) \
144 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
145 #define VEPRINT2(es, p1, p2) \
146 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
147 #define VEPRINT3(es, p1, p2, p3) \
148 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
150 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
154 /* getting rid of this */
155 #define ERROR_EXIT(code) do { \
161 /* Protos for static routines */
162 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
163 struct rx_connection **connPtr, afs_int32 * transPtr,
164 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
165 afs_int32 *origflags, afs_uint32 tmpVolId);
166 static int SimulateForwardMultiple(struct rx_connection *fromconn,
167 afs_int32 fromtid, afs_int32 fromdate,
168 manyDests * tr, afs_int32 flags,
169 void *cookie, manyResults * results);
170 static int DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
171 afs_int32 apart, int type, afs_uint32 cloneid,
172 char *typestring, char *pname, char *vname, char *suffix,
173 struct volser_status *volstatus, afs_int32 *transPtr);
174 static int DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
175 afs_int32 apart, char *typestring, afs_uint32 atoserver,
176 struct volser_status *volstatus, char *pprefix);
177 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
178 afs_int32 apart, afs_int32 * modentry,
179 afs_uint32 * maxvolid, struct nvldbentry *aentry);
180 static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition,
181 afs_uint32 volumeid);
182 static afs_int32 CheckVldbRWBK(struct nvldbentry * entry,
183 afs_int32 * modified);
184 static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified);
185 static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified,
187 static void dump_sig_handler(int x);
188 static int sortVolumes(const void *a, const void *b);
191 /*map the partition <partId> into partition name <partName>*/
193 MapPartIdIntoName(afs_int32 partId, char *partName)
195 if (partId < 26) { /* what if partId > = 26 ? */
196 strcpy(partName, "/vicep");
197 partName[6] = partId + 'a';
200 } else if (partId < VOLMAXPARTS) {
201 strcpy(partName, "/vicep");
203 partName[6] = 'a' + (partId / 26);
204 partName[7] = 'a' + (partId % 26);
211 PrintError(char *msg, afs_int32 errcode)
213 fprintf(STDERR, "%s", msg);
214 /*replace by a big switch statement */
219 fprintf(STDERR, "Possible communication failure\n");
222 fprintf(STDERR, "Volume needs to be salvaged\n");
225 fprintf(STDERR, "Bad vnode number quoted\n");
229 "Volume not attached, does not exist, or not on line\n");
232 fprintf(STDERR, "Volume already exists\n");
235 fprintf(STDERR, "Volume is not in service\n");
238 fprintf(STDERR, "Volume is off line\n");
241 fprintf(STDERR, "Volume is already on line\n");
244 fprintf(STDERR, "Partition is full\n");
247 fprintf(STDERR, "Volume max quota exceeded\n");
250 fprintf(STDERR, "Volume temporarily unavailable\n");
253 fprintf(STDERR, "Volume has moved to another server\n");
256 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
259 fprintf(STDERR, "VLDB: a read terminated too early\n");
262 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
265 fprintf(STDERR, "VLDB: internal creation failure\n");
268 fprintf(STDERR, "VLDB: no such entry\n");
271 fprintf(STDERR, "VLDB: vldb database is empty\n");
274 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
277 fprintf(STDERR, "VLDB: volume name is illegal\n");
280 fprintf(STDERR, "VLDB: index was out of range\n");
283 fprintf(STDERR, "VLDB: bad volume type\n");
286 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
288 case VL_BADPARTITION:
289 fprintf(STDERR, "VLDB: bad partition number\n");
292 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
295 fprintf(STDERR, "VLDB: no such repsite server exists\n");
297 case VL_DUPREPSERVER:
298 fprintf(STDERR, "VLDB: replication site server already exists\n");
301 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
304 fprintf(STDERR, "VLDB: illegal reference count number\n");
306 case VL_SIZEEXCEEDED:
307 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
310 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
312 case VL_BADVOLIDBUMP:
313 fprintf(STDERR, "VLDB: illegal max volid increment\n");
315 case VL_IDALREADYHASHED:
316 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
319 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
322 fprintf(STDERR, "VLDB: bad volume operation code\n");
324 case VL_BADRELLOCKTYPE:
325 fprintf(STDERR, "VLDB: bad release lock type\n");
328 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
330 case VL_BADSERVERFLAG:
331 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
334 fprintf(STDERR, "VLDB: no permission access for call\n");
336 case VOLSERREAD_DUMPERROR:
338 "VOLSER: Problems encountered in reading the dump file !\n");
340 case VOLSERDUMPERROR:
341 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
343 case VOLSERATTACH_ERROR:
344 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
346 case VOLSERDETACH_ERROR:
347 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
349 case VOLSERILLEGAL_PARTITION:
350 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
352 case VOLSERBAD_ACCESS:
353 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
355 case VOLSERVLDB_ERROR:
356 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
359 fprintf(STDERR, "VOLSER: error in volume name\n");
362 fprintf(STDERR, "VOLSER: volume has moved\n");
365 fprintf(STDERR, "VOLSER: illegal operation\n");
367 case VOLSERBADRELEASE:
368 fprintf(STDERR, "VOLSER: release could not be completed\n");
371 fprintf(STDERR, "VOLSER: volume is busy\n");
373 case VOLSERNO_MEMORY:
374 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
378 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
380 case VOLSERMULTIRWVOL:
382 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
386 "VOLSER: not all entries were successfully processed\n");
390 initialize_RXK_error_table();
391 initialize_KTC_error_table();
392 initialize_ACFG_error_table();
393 initialize_VL_error_table();
395 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
396 afs_error_message(errcode));
403 void init_volintInfo(struct volintInfo *vinfo) {
404 memset(vinfo, 0, sizeof(struct volintInfo));
406 vinfo->maxquota = -1;
408 vinfo->creationDate = -1;
409 vinfo->updateDate = -1;
417 static struct rx_securityClass *uvclass = 0;
418 static int uvindex = -1;
419 /* called by VLDBClient_Init to set the security module to be used in the RPC */
421 UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
428 /* bind to volser on <port> <aserver> */
429 /* takes server address in network order, port in host order. dumb */
430 struct rx_connection *
431 UV_Bind(afs_uint32 aserver, afs_int32 port)
433 struct rx_connection *tc;
435 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
441 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
442 afs_int32 partition, char *name, afs_int32 type,
443 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
448 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
450 if (code != VOLSERVOLBUSY)
453 #ifdef AFS_PTHREAD_ENV
456 IOMGR_Sleep(3-retries);
463 AFSVolTransCreate_retry(struct rx_connection *z_conn,
464 afs_int32 volume, afs_int32 partition,
465 afs_int32 flags, afs_int32 * trans)
470 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
471 if (code != VOLSERVOLBUSY)
474 #ifdef AFS_PTHREAD_ENV
477 IOMGR_Sleep(3-retries);
483 /* called by EmuerateEntry, show vldb entry in a reasonable format */
485 SubEnumerateEntry(struct nvldbentry *entry)
492 if (entry->flags & VLF_RWEXISTS)
493 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
494 if (entry->flags & VLF_ROEXISTS)
495 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
496 if (entry->flags & VLF_BACKEXISTS)
497 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
498 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
499 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
500 fprintf(STDOUT, "\n");
501 fprintf(STDOUT, " number of sites -> %lu\n",
502 (unsigned long)entry->nServers);
503 for (i = 0; i < entry->nServers; i++) {
504 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
507 for (i = 0; i < entry->nServers; i++) {
508 MapPartIdIntoName(entry->serverPartition[i], pname);
509 fprintf(STDOUT, " server %s partition %s ",
510 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
511 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
512 if (entry->serverFlags[i] & VLSF_RWVOL)
513 fprintf(STDOUT, "RW Site ");
515 fprintf(STDOUT, "RO Site ");
517 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
518 fprintf(STDOUT," -- New release");
520 if (!(entry->serverFlags[i] & VLSF_RWVOL))
521 fprintf(STDOUT," -- Old release");
523 if (entry->serverFlags[i] & VLSF_DONTUSE)
524 fprintf(STDOUT, " -- Not released");
526 fprintf(STDOUT, "\n");
533 /*enumerate the vldb entry corresponding to <entry> */
535 EnumerateEntry(struct nvldbentry *entry)
538 fprintf(STDOUT, "\n");
539 fprintf(STDOUT, "%s \n", entry->name);
540 SubEnumerateEntry(entry);
544 /* forcibly remove a volume. Very dangerous call */
546 UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
548 struct rx_connection *tconn;
551 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
553 code = AFSVolNukeVolume(tconn, partid, volid);
554 rx_DestroyConnection(tconn);
560 /* like df. Return usage of <pname> on <server> in <partition> */
562 UV_PartitionInfo64(afs_uint32 server, char *pname,
563 struct diskPartition64 *partition)
565 struct rx_connection *aconn;
568 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
569 code = AFSVolPartitionInfo64(aconn, pname, partition);
570 if (code == RXGEN_OPCODE) {
571 struct diskPartition *dpp = malloc(sizeof(struct diskPartition));
572 code = AFSVolPartitionInfo(aconn, pname, dpp);
574 strncpy(partition->name, dpp->name, 32);
575 strncpy(partition->devName, dpp->devName, 32);
576 partition->lock_fd = dpp->lock_fd;
577 partition->free = dpp->free;
578 partition->minFree = dpp->minFree;
583 fprintf(STDERR, "Could not get information on partition %s\n", pname);
584 PrintError("", code);
587 rx_DestroyConnection(aconn);
591 /* old interface to create volumes */
593 UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
598 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
602 /* less old interface to create volumes */
604 UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
605 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
606 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
608 afs_uint32 roid = 0, bkid = 0;
609 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
610 aspare3, aspare4, anewid, &roid, &bkid);
614 * Create a volume on the given server and partition
616 * @param aserver server to create volume on
617 * @param spart partition to create volume on
618 * @param aname name of new volume
619 * @param aquota quota for new volume
620 * @param anewid contains the desired volume id for the new volume. If
621 * *anewid == 0, a new id will be chosen, and will be placed
622 * in *anewid when UV_CreateVolume3 returns.
623 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
624 * will be unset. If *aroid == 0, an id will be chosen, and
625 * will be placed in *anewid when UV_CreateVolume3 returns.
626 * @param abkid same as aroid, except for the BK volume id instead of the
628 * @return 0 on success, error code otherwise.
631 UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
632 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
633 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
634 afs_uint32 * aroid, afs_uint32 * abkid)
636 struct rx_connection *aconn;
640 afs_int32 rcode, vcode;
642 struct nvldbentry entry, storeEntry; /*the new vldb entry */
643 struct volintInfo tstatus;
648 memset(&storeEntry, 0, sizeof(struct nvldbentry));
650 init_volintInfo(&tstatus);
651 tstatus.maxquota = aquota;
653 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
655 if (aroid && *aroid) {
656 VPRINT1("Using RO volume ID %d.\n", *aroid);
658 if (abkid && *abkid) {
659 VPRINT1("Using BK volume ID %d.\n", *abkid);
663 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
665 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
668 VPRINT1("Using volume ID %d.\n", *anewid);
670 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
671 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
673 if (aroid && *aroid == 0) {
674 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
675 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
678 if (abkid && *abkid == 0) {
679 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
680 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
684 /* rw,ro, bk id are related in the default case */
685 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
687 if (aroid && *aroid != 0) {
688 lastid = max(lastid, *aroid);
690 if (abkid && *abkid != 0) {
691 lastid = max(lastid, *abkid);
693 if (aroid && *aroid == 0) {
696 if (abkid && *abkid == 0) {
701 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
702 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
705 code = AFSVolSetInfo(aconn, tid, &tstatus);
707 EPRINT(code, "Could not change quota, continuing...\n");
709 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
710 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
713 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
715 /* set up the vldb entry for this volume */
716 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
718 entry.serverNumber[0] = aserver; /* this should have another
719 * level of indirection later */
720 entry.serverPartition[0] = apart; /* this should also have
721 * another indirection level */
722 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
723 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
724 entry.volumeId[RWVOL] = *anewid;
725 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
726 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
728 /*map into right byte order, before passing to xdr, the stuff has to be in host
729 * byte order. Xdr converts it into network order */
730 MapNetworkToHost(&entry, &storeEntry);
731 /* create the vldb entry */
732 vcode = VLDB_CreateEntry(&storeEntry);
735 "Could not create a VLDB entry for the volume %s %lu\n",
736 aname, (unsigned long)*anewid);
737 /*destroy the created volume */
738 VPRINT1("Deleting the newly created volume %u\n", *anewid);
739 AFSVolDeleteVolume(aconn, tid);
743 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
744 /* volume created, now terminate the transaction and release the connection */
745 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
746 * the volume will come online anyway when transaction timesout , so if
747 * vldb entry exists then the volume is guaranteed to exist too wrt create */
751 "Failed to end the transaction on the volume %s %lu\n", aname,
752 (unsigned long)*anewid);
759 code = AFSVolEndTrans(aconn, tid, &rcode);
761 fprintf(STDERR, "WARNING: could not end transaction\n");
764 rx_DestroyConnection(aconn);
765 PrintError("", error);
769 /* create a volume, given a server, partition number, volume name --> sends
770 * back new vol id in <anewid>*/
772 UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
775 struct rx_connection *aconn;
778 struct nvldbentry entry, storeEntry; /*the new vldb entry */
780 memset(&storeEntry, 0, sizeof(struct nvldbentry));
782 aconn = (struct rx_connection *)0;
785 /* set up the vldb entry for this volume */
786 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
788 entry.serverNumber[0] = aserver; /* this should have another
789 * level of indirection later */
790 entry.serverPartition[0] = apart; /* this should also have
791 * another indirection level */
792 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
793 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
794 entry.volumeId[RWVOL] = aid;
795 entry.volumeId[ROVOL] = 0;
796 entry.volumeId[BACKVOL] = 0;
798 /*map into right byte order, before passing to xdr, the stuff has to be in host
799 * byte order. Xdr converts it into network order */
800 MapNetworkToHost(&entry, &storeEntry);
801 /* create the vldb entry */
802 vcode = VLDB_CreateEntry(&storeEntry);
805 "Could not create a VLDB entry for the volume %s %lu\n",
806 aname, (unsigned long)aid);
810 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
814 rx_DestroyConnection(aconn);
815 PrintError("", error);
819 /* Delete the volume <volid>on <aserver> <apart>
820 * the physical entry gets removed from the vldb only if the ref count
824 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
826 struct rx_connection *aconn = (struct rx_connection *)0;
828 afs_int32 code, rcode;
830 struct nvldbentry entry, storeEntry;
832 afs_int32 avoltype = -1, vtype;
833 int notondisk = 0, notinvldb = 0;
835 memset(&storeEntry, 0, sizeof(struct nvldbentry));
837 /* Find and read bhe VLDB entry for this volume */
838 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
840 if (code != VL_NOENT) {
841 EGOTO1(error_exit, code,
842 "Could not lock VLDB entry for the volume %u\n", avolid);
848 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
849 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
851 MapHostToNetwork(&entry);
854 EnumerateEntry(&entry);
857 /* Whether volume is in the VLDB or not. Delete the volume on disk */
858 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
860 code = DoVolDelete(aconn, avolid, apart, "the", 0, NULL, NULL);
870 /* Now update the VLDB entry.
871 * But first, verify we have a VLDB entry.
872 * Whether volume is on disk or not. Delete the volume in VLDB.
877 if (avolid == entry.volumeId[BACKVOL]) {
878 /* Its a backup volume, modify the VLDB entry. Check that the
879 * backup volume is on the server/partition we asked to delete.
881 if (!(entry.flags & VLF_BACKEXISTS) || !Lp_Match(aserver, apart, &entry)) {
882 notinvldb = 2; /* Not on this server and partition */
886 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
888 entry.flags &= ~VLF_BACKEXISTS;
892 else if (avolid == entry.volumeId[ROVOL]) {
893 /* Its a read-only volume, modify the VLDB entry. Check that the
894 * readonly volume is on the server/partition we asked to delete.
895 * If flags does not have RO_EIXSTS set, then this may mean the RO
896 * hasn't been released (and could exist in VLDB).
898 if (!Lp_ROMatch(aserver, apart, &entry)) {
899 notinvldb = 2; /* Not found on this server and partition */
905 "Marking the readonly volume %lu deleted in the VLDB\n",
906 (unsigned long)avolid);
908 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
910 if (!Lp_ROMatch(0, 0, &entry))
911 entry.flags &= ~VLF_ROEXISTS; /* This was the last ro volume */
915 else if (avolid == entry.volumeId[RWVOL]) {
916 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
917 * Check that the readwrite volumes is on the server/partition we
920 if (!(entry.flags & VLF_RWEXISTS) || !Lp_Match(aserver, apart, &entry)) {
921 notinvldb = 2; /* Not found on this server and partition */
925 if (entry.volumeId[BACKVOL]) {
926 /* Delete backup if it exists */
927 code = DoVolDelete(aconn, entry.volumeId[BACKVOL], apart,
928 "the backup", 0, NULL, NULL);
929 if (code && code != VNOVOL) {
937 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
938 (unsigned long)avolid,
940 flags & VLF_BACKEXISTS) ? ", and its backup volume," :
943 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
945 entry.flags &= ~(VLF_BACKEXISTS | VLF_RWEXISTS);
948 if (entry.flags & VLF_ROEXISTS)
949 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
953 notinvldb = 2; /* Not found on this server and partition */
957 /* Either delete or replace the VLDB entry */
958 if ((entry.nServers <= 0) || !(entry.flags & (VLF_ROEXISTS | VLF_RWEXISTS))) {
961 "Last reference to the VLDB entry for %lu - deleting entry\n",
962 (unsigned long)avolid);
963 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
964 EGOTO1(error_exit, code,
965 "Could not delete the VLDB entry for the volume %u \n",
968 MapNetworkToHost(&entry, &storeEntry);
970 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
971 (LOCKREL_OPCODE | LOCKREL_AFSID |
973 EGOTO1(error_exit, code,
974 "Could not update the VLDB entry for the volume %u \n",
983 if (notondisk && notinvldb) {
984 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
985 ((notinvldb == 2) ? "on server and partition" : ""));
988 } else if (notondisk) {
990 "WARNING: Volume %lu did not exist on the partition\n",
991 (unsigned long)avolid);
992 } else if (notinvldb) {
993 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
994 (unsigned long)avolid,
995 ((notinvldb == 2) ? "on server and partition" : ""));
999 code = AFSVolEndTrans(aconn, ttid, &rcode);
1000 code = (code ? code : rcode);
1002 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1003 (unsigned long)avolid);
1004 PrintError("", code);
1012 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1013 (LOCKREL_OPCODE | LOCKREL_AFSID |
1014 LOCKREL_TIMESTAMP));
1017 "Could not release the lock on the VLDB entry for the volume %u \n",
1025 rx_DestroyConnection(aconn);
1029 /* add recovery to UV_MoveVolume */
1031 #define TESTC 0 /* set to test recovery code, clear for production */
1037 do_interrupt(void * unused)
1040 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1041 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1042 * changed. This will avoid some sanity checks, but until a better way
1043 * is found, the only alternative is always crashing and burning on at
1044 * least the stack-overflow check. */
1045 lwp_cpptr->stack = NULL;
1050 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1052 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1053 fprintf(STDOUT, "enter second control-c to exit\n");
1061 sigint_handler(int x)
1063 #ifdef AFS_PTHREAD_ENV
1066 IOMGR_SoftSig(do_interrupt, 0);
1068 (void)signal(SIGINT, sigint_handler);
1072 DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
1073 afs_int32 apart, char *ptypestring, afs_uint32 atoserver,
1074 struct volser_status *volstatus, char *pprefix)
1076 afs_int32 ttid = 0, code, rcode, error = 0;
1077 char *prefix, *typestring;
1086 typestring = ptypestring;
1092 VPRINT3("%sDeleting %s volume %u ...", prefix, typestring, avolid);
1095 AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
1097 /* return early and quietly for VNOVOL; don't continue the attempt to delete. */
1098 if (code == VNOVOL) {
1103 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1107 code = AFSVolGetStatus(aconn, ttid, volstatus);
1108 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1113 AFSVolSetFlags(aconn, ttid,
1114 VTDeleteOnSalvage | VTOutOfService);
1116 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1120 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1121 AFSVolSetForwarding(aconn, ttid, atoserver);
1125 code = AFSVolDeleteVolume(aconn, ttid);
1126 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1130 code = AFSVolEndTrans(aconn, ttid, &rcode);
1135 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1136 prefix, typestring, (unsigned long)avolid);
1142 if (beverbose && !error)
1148 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1149 afs_int32 apart, int type, afs_uint32 cloneid,
1150 char *typestring, char *pname, char *vname, char *suffix,
1151 struct volser_status *volstatus, afs_int32 *transPtr)
1154 afs_int32 ttid = 0, btid = 0;
1155 afs_int32 code = 0, rcode = 0;
1156 afs_int32 error = 0;
1157 int cloneexists = 1;
1159 /* Test to see if the clone volume exists by trying to create
1160 * a transaction on the clone volume. We've assumed the clone exists.
1162 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1164 if (code != VNOVOL) {
1165 EPRINT2(code, "Could not reach the %s volume %lu\n",
1166 typestring, (unsigned long)cloneid);
1170 cloneexists = 0; /* clone volume does not exist */
1173 code = AFSVolEndTrans(aconn, btid, &rcode);
1175 if (code || rcode) {
1177 "Could not end transaction on the previous %s volume %lu\n",
1178 typestring, (unsigned long)cloneid);
1179 error = (code ? code : rcode);
1184 /* Now go ahead and try to clone the RW volume.
1185 * First start a transaction on the RW volume
1187 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1189 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1190 (unsigned long)avolid);
1195 /* Clone or reclone the volume, depending on whether the clone
1196 * volume exists or not
1199 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1201 code = AFSVolReClone(aconn, ttid, cloneid);
1203 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1204 typestring, (unsigned long)cloneid);
1209 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1212 strcpy(cname, pname);
1213 strcat(cname, suffix);
1216 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1219 fprintf(STDERR, "Failed to clone the volume %lu\n",
1220 (unsigned long)avolid);
1229 VPRINT1("Getting status of parent volume %u...", avolid);
1230 code = AFSVolGetStatus(aconn, ttid, volstatus);
1232 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1233 (unsigned long)avolid);
1242 code = AFSVolEndTrans(aconn, ttid, &rcode);
1243 if (code || rcode) {
1244 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1245 (unsigned long)avolid);
1247 error = (code ? code : rcode);
1252 code = AFSVolEndTrans(aconn, btid, &rcode);
1253 if (code || rcode) {
1255 "Could not end transaction on the %s volume %lu\n",
1256 typestring, (unsigned long)cloneid);
1258 error = (code ? code : rcode);
1264 /* Convert volume from RO to RW; adjust the VLDB entry to match.
1265 * The nvldbentry passed to us has already been MapHostToNetwork'd
1270 UV_ConvertRO(afs_uint32 server, afs_uint32 partition, afs_uint32 volid,
1271 struct nvldbentry *entry)
1273 afs_int32 code, i, same;
1274 struct nvldbentry checkEntry, storeEntry;
1276 afs_int32 rwindex = 0;
1277 afs_uint32 rwserver = 0;
1278 afs_int32 roindex = 0;
1279 afs_uint32 roserver = 0;
1280 struct rx_connection *aconn;
1282 memset(&storeEntry, 0, sizeof(struct nvldbentry));
1285 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1289 "Unable to lock volume %lu, code %d\n",
1290 (unsigned long)entry->volumeId[RWVOL],vcode);
1291 PrintError("", vcode);
1295 /* make sure the VLDB entry hasn't changed since we started */
1296 memset(&checkEntry, 0, sizeof(checkEntry));
1297 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1300 "Could not fetch the entry for volume %lu from VLDB\n",
1301 (unsigned long)volid);
1302 PrintError("convertROtoRW ", vcode);
1307 MapHostToNetwork(&checkEntry);
1308 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1309 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1310 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1312 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1313 (unsigned long)volid);
1318 /* extract information from the original entry */
1319 for (i = 0; i < entry->nServers; i++) {
1320 if (entry->serverFlags[i] & VLSF_RWVOL) {
1322 rwserver = entry->serverNumber[i];
1323 /* rwpartition = entry->serverPartition[i]; */
1326 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1327 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1330 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1337 roserver = entry->serverNumber[i];
1338 /* ropartition = entry->serverPartition[i]; */
1345 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1346 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1349 "Converting RO volume %lu to RW volume failed with code %d\n",
1350 (unsigned long)volid, code);
1351 PrintError("convertROtoRW ", code);
1354 /* Update the VLDB to match what we did on disk as much as possible. */
1355 /* If the converted RO was in the VLDB, make it look like the new RW. */
1357 entry->serverFlags[roindex] = VLSF_RWVOL;
1359 /* Add a new site entry for the newly created RW. It's possible
1360 * (but unlikely) that we are already at MAXNSERVERS and that this
1361 * new site will invalidate the whole VLDB entry; however,
1362 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1363 * so we need no extra guard logic here.
1365 afs_int32 newrwindex = entry->nServers;
1366 (entry->nServers)++;
1367 entry->serverNumber[newrwindex] = server;
1368 entry->serverPartition[newrwindex] = partition;
1369 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1371 entry->flags |= VLF_RWEXISTS;
1372 entry->flags &= ~VLF_BACKEXISTS;
1374 /* if the old RW was in the VLDB, remove it by decrementing the number */
1375 /* of servers, replacing the RW entry with the last entry, and zeroing */
1376 /* out the last entry. */
1378 (entry->nServers)--;
1379 if (rwindex != entry->nServers) {
1380 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1381 entry->serverPartition[rwindex] =
1382 entry->serverPartition[entry->nServers];
1383 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1384 entry->serverNumber[entry->nServers] = 0;
1385 entry->serverPartition[entry->nServers] = 0;
1386 entry->serverFlags[entry->nServers] = 0;
1389 entry->flags &= ~VLF_ROEXISTS;
1390 for (i = 0; i < entry->nServers; i++) {
1391 if (entry->serverFlags[i] & VLSF_ROVOL) {
1392 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1393 entry->flags |= VLF_ROEXISTS;
1396 MapNetworkToHost(entry, &storeEntry);
1398 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1399 (LOCKREL_OPCODE | LOCKREL_AFSID |
1400 LOCKREL_TIMESTAMP));
1403 "Warning: volume converted, but vldb update failed with code %d!\n",
1408 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1411 "Unable to unlock volume %lu, code %d\n",
1412 (unsigned long)entry->volumeId[RWVOL],vcode);
1413 PrintError("", vcode);
1419 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1420 * <atopart>. The operation is almost idempotent. The following
1421 * flags are recognized:
1423 * RV_NOCLONE - don't use a copy clone
1427 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1428 afs_uint32 atoserver, afs_int32 atopart, int flags)
1430 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1431 * be changing during the move */
1432 struct rx_connection * volatile toconn;
1433 struct rx_connection * volatile fromconn;
1434 afs_int32 volatile fromtid;
1435 afs_int32 volatile totid;
1436 afs_int32 volatile clonetid;
1437 afs_uint32 volatile newVol;
1438 afs_uint32 volatile volid;
1439 afs_uint32 volatile backupId;
1440 int volatile islocked;
1445 char tmpName[VOLSER_MAXVOLNAME + 1];
1450 struct restoreCookie cookie;
1451 afs_int32 vcode, code;
1452 struct volser_status tstatus;
1453 struct destServer destination;
1455 struct nvldbentry entry, storeEntry;
1458 char in, lf; /* for test code */
1462 #ifdef ENABLE_BUGFIX_1165
1463 volEntries volumeInfo;
1464 struct volintInfo *infop = 0;
1468 fromconn = (struct rx_connection *)0;
1469 toconn = (struct rx_connection *)0;
1479 /* support control-c processing */
1482 (void)signal(SIGINT, sigint_handler);
1486 "\nThere are three tests points - verifies all code paths through recovery.\n");
1487 fprintf(STDOUT, "First test point - operation not started.\n");
1488 fprintf(STDOUT, "...test here (y, n)? ");
1490 if (fscanf(stdin, "%c", &in) < 1)
1492 if (fscanf(stdin, "%c", &lf) < 0) {
1493 /* toss away; don't care */
1496 fprintf(STDOUT, "type control-c\n");
1498 fprintf(stdout, ".");
1503 /* or drop through */
1506 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1507 EGOTO1(mfail, vcode,
1508 "Could not fetch the entry for the volume %u from the VLDB \n",
1511 if (entry.volumeId[RWVOL] != afromvol) {
1512 fprintf(STDERR, "Only RW volume can be moved\n");
1516 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1517 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1520 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1521 EGOTO1(mfail, vcode,
1522 "Could not fetch the entry for the volume %u from the VLDB \n",
1525 backupId = entry.volumeId[BACKVOL];
1526 MapHostToNetwork(&entry);
1528 if (!Lp_Match(afromserver, afrompart, &entry)) {
1529 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1530 if (!Lp_Match(atoserver, atopart, &entry)) {
1531 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1532 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1533 (unsigned long)afromvol);
1534 fprintf(STDERR, "The current site is :");
1535 for (i = 0; i < entry.nServers; i++) {
1536 if (entry.serverFlags[i] == VLSF_RWVOL) {
1538 MapPartIdIntoName(entry.serverPartition[i], pname);
1539 fprintf(STDERR, " server %s partition %s \n",
1540 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1541 hostutil_GetNameByINet(entry.serverNumber[i]),
1546 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1547 (LOCKREL_OPCODE | LOCKREL_AFSID |
1548 LOCKREL_TIMESTAMP));
1549 EGOTO1(mfail, vcode,
1550 " Could not release lock on the VLDB entry for the volume %u \n",
1553 return VOLSERVOLMOVED;
1556 /* delete the volume afromvol on src_server */
1557 /* from-info does not exist but to-info does =>
1558 * we have already done the move, but the volume
1559 * may still be existing physically on from fileserver
1561 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1564 code = DoVolDelete(fromconn, afromvol, afrompart,
1565 "leftover", 0, NULL, NULL);
1566 if (code && code != VNOVOL) {
1571 code = DoVolDelete(fromconn, backupId, afrompart,
1572 "leftover backup", 0, NULL, NULL);
1573 if (code && code != VNOVOL) {
1583 /* From-info matches the vldb info about volid,
1584 * its ok start the move operation, the backup volume
1585 * on the old site is deleted in the process
1587 if (afrompart == atopart) {
1588 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1589 EGOTO2(mfail, error,
1590 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1591 afromserver, error);
1594 EGOTO1(mfail, VOLSERVOLMOVED,
1595 "Warning: Moving volume %u to its home partition ignored!\n",
1601 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1602 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1603 totid = 0; /* initialize to uncreated */
1606 * clone the read/write volume locally.
1609 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1610 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1612 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1616 if (!(flags & RV_NOCLONE)) {
1617 /* Get a clone id */
1618 VPRINT1("Allocating new volume id for clone of volume %u ...",
1621 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1623 EGOTO1(mfail, vcode,
1624 "Could not get an ID for the clone of volume %u from the VLDB\n",
1628 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1629 VPRINT1("Cloning source volume %u ...", afromvol);
1630 strcpy(vname, "move-clone-temp");
1632 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1634 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1639 /* lookup the name of the volume we just cloned */
1641 code = AFSVolGetName(fromconn, fromtid, &volName);
1642 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1645 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1647 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1652 "Failed to end the transaction on the source volume %u\n",
1657 * Create the destination volume
1660 if (!(flags & RV_NOCLONE)) {
1661 /* All of this is to get the fromDate */
1662 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1665 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1669 "Failed to start a transaction on the cloned volume%u\n",
1673 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1675 AFSVolSetFlags(fromconn, clonetid,
1676 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1677 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1681 /* remember time from which we've dumped the volume */
1682 VPRINT1("Getting status of cloned volume %u ...", newVol);
1683 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1685 "Failed to get the status of the cloned volume %u\n",
1689 fromDate = CLOCKADJ(tstatus.creationDate);
1691 /* With RV_NOCLONE, just do a full copy from the source */
1696 #ifdef ENABLE_BUGFIX_1165
1698 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1699 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1700 * don't use this information...
1702 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1703 volumeInfo.volEntries_len = 0;
1704 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1706 "Failed to get the volint Info of the cloned volume %u\n",
1709 infop = (volintInfo *) volumeInfo.volEntries_val;
1710 infop->maxquota = -1; /* Else it will replace the default quota */
1711 infop->creationDate = -1; /* Else it will use the source creation date */
1712 infop->updateDate = -1; /* Else it will use the source update date */
1715 /* create a volume on the target machine */
1717 code = DoVolDelete(toconn, volid, atopart,
1718 "pre-existing destination", 0, NULL, NULL);
1719 if (code && code != VNOVOL) {
1724 VPRINT1("Creating the destination volume %u ...", volid);
1728 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1732 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1736 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1740 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1742 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1744 "Failed to set the flags on the destination volume %u\n", volid);
1748 * Now dump the clone to the new volume
1751 destination.destHost = ntohl(atoserver);
1752 destination.destPort = AFSCONF_VOLUMEPORT;
1753 destination.destSSID = 1;
1755 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1756 cookie.type = RWVOL;
1757 cookie.parent = entry.volumeId[RWVOL];
1760 if (!(flags & RV_NOCLONE)) {
1761 /* Copy the clone to the new volume */
1762 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1765 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1767 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1770 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1771 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1776 "Failed to end the transaction on the cloned volume %u\n",
1782 * reattach to the main-line volume, and incrementally dump it.
1785 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1787 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1790 "Failed to create a transaction on the source volume %u\n",
1794 /* now do the incremental */
1796 ("Doing the%s dump from source to destination for volume %u ... ",
1797 (flags & RV_NOCLONE) ? "" : " incremental",
1800 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1803 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1804 (flags & RV_NOCLONE) ? "" : " incremental");
1807 /* now adjust the flags so that the new volume becomes official */
1808 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1809 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1811 "Failed to set the flags to make old source volume offline\n");
1814 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1815 code = AFSVolSetFlags(toconn, totid, 0);
1817 "Failed to set the flags to make new source volume online\n");
1820 #ifdef ENABLE_BUGFIX_1165
1821 VPRINT1("Setting volume status on destination volume %u ...", volid);
1822 code = AFSVolSetInfo(toconn, totid, infop);
1824 "Failed to set volume status on the destination volume %u\n",
1829 /* put new volume online */
1830 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1831 code = AFSVolEndTrans(toconn, totid, &rcode);
1836 "Failed to end the transaction on the volume %u on the new site\n",
1840 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1841 MapNetworkToHost(&entry, &storeEntry);
1842 storeEntry.flags &= ~VLF_BACKEXISTS;
1846 "Second test point - operation in progress but not complete.\n");
1847 fprintf(STDOUT, "...test here (y, n)? ");
1849 if (fscanf(stdin, "%c", &in) < 1)
1851 if (fscanf(stdin, "%c", &lf) < 0) {
1852 /* toss away, don't care */
1855 fprintf(STDOUT, "type control-c\n");
1857 fprintf(stdout, ".");
1862 /* or drop through */
1865 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1867 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1868 (LOCKREL_OPCODE | LOCKREL_AFSID |
1869 LOCKREL_TIMESTAMP));
1872 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1873 storeEntry.name, (unsigned long)afromvol);
1882 "Third test point - operation complete but no cleanup.\n");
1883 fprintf(STDOUT, "...test here (y, n)? ");
1885 if (fscanf(stdin, "%c", &in) < 1)
1887 if (fscanf(stdin, "%c", &lf) < 0) {
1888 /* toss away; don't care */
1891 fprintf(STDOUT, "type control-c\n");
1893 fprintf(stdout, ".");
1898 /* or drop through */
1900 if (atoserver != afromserver) {
1901 /* set forwarding pointer for moved volumes */
1902 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1903 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1905 "Failed to set the forwarding pointer for the volume %u\n",
1910 VPRINT1("Deleting old volume %u on source ...", afromvol);
1911 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1912 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1916 VPRINT1("Ending transaction on old volume %u on the source ...",
1918 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1923 "Failed to end the transaction on the old volume %u on the source\n",
1927 code = DoVolDelete(fromconn, backupId, afrompart,
1928 "source backup", 0, NULL, NULL);
1929 if (code && code != VNOVOL) {
1934 code = 0; /* no backup volume? that's okay */
1937 if (!(flags & RV_NOCLONE)) {
1938 code = DoVolDelete(fromconn, newVol, afrompart,
1939 "cloned", 0, NULL, NULL);
1940 if (code && code != VNOVOL) {
1945 code = 0; /* clone missing? that's okay */
1952 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1953 fprintf(STDOUT, "...test here (y, n)? ");
1955 if (fscanf(stdin, "%c", &in) < 1)
1957 if (fscanf(stdin, "%c", &lf) < 0) { /* toss away */
1961 fprintf(STDOUT, "type control-c\n");
1963 fprintf(stdout, ".");
1968 /* or drop through */
1971 /* normal cleanup code */
1973 if (entry.flags & VLF_ROEXISTS)
1974 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1977 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1979 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1980 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1984 " Could not release the lock on the VLDB entry for the volume %lu \n",
1985 (unsigned long)afromvol);
1993 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1995 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1996 if (code || rcode) {
1999 "Could not end transaction on the source volume %lu\n",
2000 (unsigned long)afromvol);
2002 error = (code ? code : rcode);
2008 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2009 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2010 if (code || rcode) {
2013 "Could not end transaction on the source's clone volume %lu\n",
2014 (unsigned long)newVol);
2016 error = (code ? code : rcode);
2022 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2024 code = AFSVolEndTrans(toconn, totid, &rcode);
2028 "Could not end transaction on destination volume %lu\n",
2029 (unsigned long)afromvol);
2031 error = (code ? code : rcode);
2037 #ifdef ENABLE_BUGFIX_1165
2042 rx_DestroyConnection(fromconn);
2044 rx_DestroyConnection(toconn);
2045 PrintError("", error);
2048 /* come here only when the sky falls */
2053 "vos move: operation interrupted, cleanup in progress...\n");
2054 fprintf(STDOUT, "clear transaction contexts\n");
2058 /* unlock VLDB entry */
2060 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2061 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2062 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2068 VPRINT("Recovery: Ending transaction on clone volume ...");
2069 AFSVolEndTrans(fromconn, clonetid, &rcode);
2073 VPRINT("Recovery: Ending transaction on destination volume ...");
2074 AFSVolEndTrans(toconn, totid, &rcode);
2077 if (fromtid) { /* put it on-line */
2078 VPRINT("Recovery: Setting volume flags on source volume ...");
2079 AFSVolSetFlags(fromconn, fromtid, 0);
2082 VPRINT("Recovery: Ending transaction on source volume ...");
2083 AFSVolEndTrans(fromconn, fromtid, &rcode);
2087 VPRINT("Recovery: Accessing VLDB.\n");
2088 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2090 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2094 MapHostToNetwork(&entry);
2096 /* Delete either the volume on the source location or the target location.
2097 * If the vldb entry still points to the source location, then we know the
2098 * volume move didn't finish so we remove the volume from the target
2099 * location. Otherwise, we remove the volume from the source location.
2101 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2104 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2108 if (volid && toconn) {
2109 code = DoVolDelete(toconn, volid, atopart,
2110 "destination", 0, NULL, "Recovery:");
2111 if (code == VNOVOL) {
2112 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2116 /* put source volume on-line */
2118 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2122 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2128 VPRINT1("Recovery: Setting flags on source volume %u ...",
2130 AFSVolSetFlags(fromconn, fromtid, 0);
2134 ("Recovery: Ending transaction on source volume %u ...",
2136 AFSVolEndTrans(fromconn, fromtid, &rcode);
2140 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2144 } else { /* yep, move complete */
2147 "move complete - attempt cleanup of source partition - no guarantee\n");
2151 /* delete backup volume */
2153 code = DoVolDelete(fromconn, backupId, afrompart,
2154 "backup", 0, NULL, "Recovery:");
2155 if (code == VNOVOL) {
2156 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2159 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2160 (atoserver != afromserver)?atoserver:0,
2162 if (code == VNOVOL) {
2163 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2168 /* common cleanup - delete local clone */
2170 code = DoVolDelete(fromconn, newVol, afrompart,
2171 "clone", 0, NULL, "Recovery:");
2172 if (code == VNOVOL) {
2173 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2177 /* unlock VLDB entry */
2179 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2181 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2182 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2185 done: /* routine cleanup */
2188 #ifdef ENABLE_BUGFIX_1165
2193 rx_DestroyConnection(fromconn);
2195 rx_DestroyConnection(toconn);
2198 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2206 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2207 afs_uint32 atoserver, afs_int32 atopart)
2209 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2210 atoserver, atopart, 0);
2214 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2215 * <atopart>. The new volume is named by <atovolname>. The new volume
2216 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2217 * from the VLDB. the following flags are supported:
2219 * RV_RDONLY - target volume is RO
2220 * RV_OFFLINE - leave target volume offline
2221 * RV_CPINCR - do incremental dump if target exists
2222 * RV_NOVLDB - don't create/update VLDB entry
2223 * RV_NOCLONE - don't use a copy clone
2226 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2227 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2228 afs_uint32 atovolid, int flags)
2230 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2231 * be changing during the copy */
2233 afs_int32 volatile clonetid;
2234 afs_int32 volatile totid;
2235 afs_int32 volatile fromtid;
2236 struct rx_connection * volatile fromconn;
2237 struct rx_connection * volatile toconn;
2238 afs_uint32 volatile cloneVol;
2242 afs_int32 fromDate, cloneFromDate;
2243 struct restoreCookie cookie;
2244 afs_int32 vcode, code;
2247 struct volser_status tstatus;
2248 struct destServer destination;
2249 struct nvldbentry entry, newentry, storeEntry;
2254 fromconn = (struct rx_connection *)0;
2255 toconn = (struct rx_connection *)0;
2263 /* support control-c processing */
2266 (void)signal(SIGINT, sigint_handler);
2268 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2269 EGOTO1(mfail, vcode,
2270 "Could not fetch the entry for the volume %u from the VLDB \n",
2272 MapHostToNetwork(&entry);
2275 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2276 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2277 fromtid = totid = 0; /* initialize to uncreated */
2280 * clone the read/write volume locally.
2284 if (!(flags & RV_NOCLONE)) {
2285 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2287 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2290 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2294 /* Get a clone id */
2295 VPRINT1("Allocating new volume id for clone of volume %u ...",
2299 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2301 EGOTO1(mfail, vcode,
2302 "Could not get an ID for the clone of volume %u from the VLDB\n",
2310 /* Get a new volume id */
2311 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2313 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2314 EGOTO1(mfail, vcode,
2315 "Could not get an ID for the copy of volume %u from the VLDB\n",
2320 if (!(flags & RV_NOCLONE)) {
2321 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2322 VPRINT1("Cloning source volume %u ...", afromvol);
2323 strcpy(vname, "copy-clone-temp");
2326 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2329 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2333 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2335 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2340 "Failed to end the transaction on the source volume %u\n",
2346 * Create the destination volume
2349 if (!(flags & RV_NOCLONE)) {
2350 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2353 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2357 "Failed to start a transaction on the cloned volume%u\n",
2361 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2363 AFSVolSetFlags(fromconn, clonetid,
2364 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2365 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2369 /* remember time from which we've dumped the volume */
2370 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2371 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2373 "Failed to get the status of the cloned volume %u\n",
2377 fromDate = CLOCKADJ(tstatus.creationDate);
2382 /* create a volume on the target machine */
2385 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2388 if ((flags & RV_CPINCR)) {
2389 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2390 code = AFSVolGetStatus(toconn, totid, &tstatus);
2392 "Failed to get the status of the pre-existing volume %u\n",
2396 /* Using the update date should be OK here, but add some fudge */
2397 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2398 if ((flags & RV_NOCLONE))
2399 fromDate = cloneFromDate;
2401 /* XXX We should check that the source volume's creationDate is
2402 * XXX not newer than the existing target volume, and if not,
2403 * XXX throw away the existing target and do a full dump. */
2408 /* Delete the existing volume.
2409 * While we are deleting the volume in these steps, the transaction
2410 * we started against the cloned volume (clonetid above) will be
2411 * sitting idle. It will get cleaned up after 600 seconds
2413 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2414 code = AFSVolDeleteVolume(toconn, totid);
2416 "Could not delete the pre-existing volume %u on destination\n",
2421 ("Ending transaction on pre-existing volume %u on destination ...",
2423 code = AFSVolEndTrans(toconn, totid, &rcode);
2428 "Could not end the transaction on pre-existing volume %u on destination\n",
2433 VPRINT1("Creating the destination volume %u ...", newVol);
2436 AFSVolCreateVolume(toconn, atopart, atovolname,
2437 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2438 newVol, &newVol, &tmp);
2440 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2444 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2446 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2448 "Failed to set the flags on the destination volume %u\n", newVol);
2453 destination.destHost = ntohl(atoserver);
2454 destination.destPort = AFSCONF_VOLUMEPORT;
2455 destination.destSSID = 1;
2457 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2458 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2463 * Now dump the clone to the new volume
2466 if (!(flags & RV_NOCLONE)) {
2467 /* XXX probably should have some code here that checks to see if
2468 * XXX we are copying to same server and partition - if so, just
2469 * XXX use a clone to save disk space */
2471 /* Copy the clone to the new volume */
2472 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2475 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2477 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2481 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2482 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2487 "Failed to end the transaction on the cloned volume %u\n",
2493 * reattach to the main-line volume, and incrementally dump it.
2496 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2498 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2501 "Failed to create a transaction on the source volume %u\n",
2505 /* now do the incremental */
2507 ("Doing the%s dump from source to destination for volume %u ... ",
2508 (flags & RV_NOCLONE) ? "" : " incremental",
2511 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2514 "Failed to do the%s dump from old site to new site\n",
2515 (flags & RV_NOCLONE) ? "" : " incremental");
2518 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2519 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2520 code = AFSVolSetFlags(toconn, totid, volflag);
2522 "Failed to set the flags to make destination volume online\n");
2525 /* put new volume online */
2526 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2527 code = AFSVolEndTrans(toconn, totid, &rcode);
2532 "Failed to end the transaction on the destination volume %u\n",
2536 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2537 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2542 "Failed to end the transaction on the source volume %u\n",
2548 if (!(flags & RV_NOCLONE)) {
2549 code = DoVolDelete(fromconn, cloneVol, afrompart,
2550 "cloned", 0, NULL, NULL);
2551 if (code && code != VNOVOL) {
2556 code = 0; /* clone missing? that's ok */
2559 if (!(flags & RV_NOVLDB)) {
2560 /* create the vldb entry for the copied volume */
2561 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2562 newentry.nServers = 1;
2563 newentry.serverNumber[0] = atoserver;
2564 newentry.serverPartition[0] = atopart;
2565 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2566 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2567 newentry.volumeId[RWVOL] = newVol;
2568 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2569 newentry.volumeId[BACKVOL] = 0;
2570 newentry.cloneId = 0;
2571 /*map into right byte order, before passing to xdr, the stuff has to be in host
2572 * byte order. Xdr converts it into network order */
2573 MapNetworkToHost(&newentry, &storeEntry);
2574 /* create the vldb entry */
2575 vcode = VLDB_CreateEntry(&storeEntry);
2578 "Could not create a VLDB entry for the volume %s %lu\n",
2579 atovolname, (unsigned long)newVol);
2580 /*destroy the created volume */
2581 VPRINT1("Deleting the newly created volume %u\n", newVol);
2582 AFSVolDeleteVolume(toconn, totid);
2586 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2590 /* normal cleanup code */
2593 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2595 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2596 if (code || rcode) {
2599 "Could not end transaction on the source volume %lu\n",
2600 (unsigned long)afromvol);
2602 error = (code ? code : rcode);
2608 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2610 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2611 if (code || rcode) {
2614 "Could not end transaction on the source's clone volume %lu\n",
2615 (unsigned long)cloneVol);
2617 error = (code ? code : rcode);
2623 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2625 code = AFSVolEndTrans(toconn, totid, &rcode);
2629 "Could not end transaction on destination volume %lu\n",
2630 (unsigned long)newVol);
2632 error = (code ? code : rcode);
2637 rx_DestroyConnection(fromconn);
2639 rx_DestroyConnection(toconn);
2640 PrintError("", error);
2643 /* come here only when the sky falls */
2648 "vos copy: operation interrupted, cleanup in progress...\n");
2649 fprintf(STDOUT, "clear transaction contexts\n");
2654 VPRINT("Recovery: Ending transaction on clone volume ...");
2655 AFSVolEndTrans(fromconn, clonetid, &rcode);
2659 VPRINT("Recovery: Ending transaction on destination volume ...");
2660 AFSVolEndTrans(toconn, totid, &rcode);
2663 if (fromtid) { /* put it on-line */
2664 VPRINT("Recovery: Ending transaction on source volume ...");
2665 AFSVolEndTrans(fromconn, fromtid, &rcode);
2669 VPRINT("Recovery: Accessing VLDB.\n");
2670 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2672 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2676 MapHostToNetwork(&entry);
2678 /* common cleanup - delete local clone */
2680 DoVolDelete(fromconn, cloneVol, afrompart, "clone", 0, NULL,
2684 done: /* routine cleanup */
2686 rx_DestroyConnection(fromconn);
2688 rx_DestroyConnection(toconn);
2691 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2699 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2700 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2702 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2703 atovolname, atoserver, atopart, 0, 0);
2708 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2709 * if one already exists, update it
2713 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2715 struct rx_connection *aconn = (struct rx_connection *)0;
2716 afs_int32 ttid = 0, btid = 0;
2717 afs_uint32 backupID;
2718 afs_int32 code = 0, rcode = 0;
2719 struct nvldbentry entry, storeEntry;
2720 afs_int32 error = 0;
2721 int vldblocked = 0, vldbmod = 0;
2723 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2725 /* the calls to VLDB will succeed only if avolid is a RW volume,
2726 * since we are following the RW hash chain for searching */
2727 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2730 "Could not fetch the entry for the volume %lu from the VLDB \n",
2731 (unsigned long)avolid);
2735 MapHostToNetwork(&entry);
2737 /* These operations require the VLDB be locked since it means the VLDB
2738 * will change or the vldb is already locked.
2740 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2741 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2742 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2744 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2747 "Could not lock the VLDB entry for the volume %lu\n",
2748 (unsigned long)avolid);
2754 /* Reread the vldb entry */
2755 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2758 "Could not fetch the entry for the volume %lu from the VLDB \n",
2759 (unsigned long)avolid);
2763 MapHostToNetwork(&entry);
2766 if (!ISNAMEVALID(entry.name)) {
2767 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2769 error = VOLSERBADNAME;
2773 backupID = entry.volumeId[BACKVOL];
2774 if (backupID == INVALID_BID) {
2775 /* Get a backup volume id from the VLDB and update the vldb
2778 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2781 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2782 (unsigned long)avolid);
2786 entry.volumeId[BACKVOL] = backupID;
2790 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2791 entry.name, NULL, ".backup", NULL, NULL);
2797 /* Mark vldb as backup exists */
2798 if (!(entry.flags & VLF_BACKEXISTS)) {
2799 entry.flags |= VLF_BACKEXISTS;
2803 /* Now go back to the backup volume and bring it on line */
2804 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2807 "Failed to start a transaction on the backup volume %lu\n",
2808 (unsigned long)backupID);
2813 code = AFSVolSetFlags(aconn, btid, 0);
2815 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2816 (unsigned long)backupID);
2821 code = AFSVolEndTrans(aconn, btid, &rcode);
2823 if (code || rcode) {
2825 "Failed to end the transaction on the backup volume %lu\n",
2826 (unsigned long)backupID);
2827 error = (code ? code : rcode);
2831 /* Will update the vldb below */
2835 code = AFSVolEndTrans(aconn, ttid, &rcode);
2836 if (code || rcode) {
2837 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2838 (unsigned long)avolid);
2840 error = (code ? code : rcode);
2845 code = AFSVolEndTrans(aconn, btid, &rcode);
2846 if (code || rcode) {
2848 "Could not end transaction the backup volume %lu\n",
2849 (unsigned long)backupID);
2851 error = (code ? code : rcode);
2855 /* Now update the vldb - if modified */
2858 MapNetworkToHost(&entry, &storeEntry);
2860 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2861 (LOCKREL_OPCODE | LOCKREL_AFSID |
2862 LOCKREL_TIMESTAMP));
2865 "Could not update the VLDB entry for the volume %lu \n",
2866 (unsigned long)avolid);
2872 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2873 (LOCKREL_OPCODE | LOCKREL_AFSID |
2874 LOCKREL_TIMESTAMP));
2877 "Could not unlock the VLDB entry for the volume %lu \n",
2878 (unsigned long)avolid);
2886 rx_DestroyConnection(aconn);
2888 PrintError("", error);
2892 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2893 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2894 * The new volume is named by <aname>, or by appending ".clone" to
2895 * the existing name if <aname> is NULL. The following flags are
2898 * RV_RDONLY - target volume is RO
2899 * RV_OFFLINE - leave target volume offline
2903 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2904 afs_uint32 acloneid, char *aname, int flags)
2906 struct rx_connection *aconn = (struct rx_connection *)0;
2907 afs_int32 ttid = 0, btid = 0;
2908 afs_int32 code = 0, rcode = 0;
2909 char vname[VOLSER_MAXVOLNAME + 1];
2910 afs_int32 error = 0;
2911 volEntries volumeInfo;
2914 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2917 volumeInfo.volEntries_val = (volintInfo *) 0;
2918 volumeInfo.volEntries_len = 0;
2919 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2921 fprintf(stderr, "Could not get info for volume %lu\n",
2922 (unsigned long)avolid);
2926 strncpy(vname, volumeInfo.volEntries_val[0].name,
2927 VOLSER_OLDMAXVOLNAME - 7);
2928 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2929 strcat(vname, ".clone");
2931 if (volumeInfo.volEntries_val)
2932 free(volumeInfo.volEntries_val);
2936 /* Get a clone id */
2937 VPRINT1("Allocating new volume id for clone of volume %u ...",
2939 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2941 "Could not get an ID for the clone of volume %u from the VLDB\n",
2946 if (flags & RV_RWONLY)
2947 type = readwriteVolume;
2948 else if (flags & RV_RDONLY)
2949 type = readonlyVolume;
2951 type = backupVolume;
2953 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
2954 NULL, aname, NULL, NULL, NULL);
2960 /* Now go back to the backup volume and bring it on line */
2961 if (!(flags & RV_OFFLINE)) {
2962 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2965 "Failed to start a transaction on the clone volume %lu\n",
2966 (unsigned long)acloneid);
2971 code = AFSVolSetFlags(aconn, btid, 0);
2973 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2974 (unsigned long)acloneid);
2979 code = AFSVolEndTrans(aconn, btid, &rcode);
2981 if (code || rcode) {
2983 "Failed to end the transaction on the clone volume %lu\n",
2984 (unsigned long)acloneid);
2985 error = (code ? code : rcode);
2992 code = AFSVolEndTrans(aconn, ttid, &rcode);
2993 if (code || rcode) {
2994 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2995 (unsigned long)avolid);
2997 error = (code ? code : rcode);
3002 code = AFSVolEndTrans(aconn, btid, &rcode);
3003 if (code || rcode) {
3005 "Could not end transaction on the clone volume %lu\n",
3006 (unsigned long)acloneid);
3008 error = (code ? code : rcode);
3013 rx_DestroyConnection(aconn);
3015 PrintError("", error);
3019 #define ONERROR(ec, ep, es) do { \
3021 fprintf(STDERR, (es), (ep)); \
3026 #define ONERROR0(ec, es) do { \
3028 fprintf(STDERR, (es)); \
3033 #define ERROREXIT(ec) do { \
3038 /* Get a "transaction" on this replica. Create the volume
3039 * if necessary. Return the time from which a dump should
3040 * be made (0 if it's a new volume)
3043 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3044 struct rx_connection **connPtr, afs_int32 * transPtr,
3045 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3046 afs_int32 *origflags, afs_uint32 tmpVolId)
3049 struct volser_status tstatus;
3054 *connPtr = (struct rx_connection *)0;
3059 /* get connection to the replication site */
3060 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3062 goto fail; /* server is down */
3064 volid = vldbEntryPtr->volumeId[ROVOL];
3068 AFSVolTransCreate_retry(*connPtr, volid,
3069 vldbEntryPtr->serverPartition[index], ITOffline,
3072 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3073 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3074 * site. Don't trust any data on it, since it is possible we
3075 * have encountered some temporary volume from some other
3076 * incomplete volume operation. It is difficult to detect if
3077 * that has happened vs if this is a legit volume, so just
3078 * delete it to be safe. */
3080 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3081 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3082 serverNumber[index], hoststr) :
3083 hostutil_GetNameByINet(vldbEntryPtr->
3084 serverNumber[index]));
3086 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3088 PrintError("Failed to delete RO_DONTUSE site: ", code);
3092 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3098 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3105 /* emulate what TransCreate would have returned, so we try to
3106 * create the volume below */
3111 /* If the volume does not exist, create it */
3112 if (!volid || code) {
3113 char volname[VL_MAXNAMELEN];
3116 if (volid && (code != VNOVOL)) {
3117 PrintError("Failed to start a transaction on the RO volume.\n",
3122 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3124 if (strlcat(volname,
3125 tmpVolId?".roclone":".readonly",
3126 sizeof(volname)) >= sizeof(volname)) {
3128 PrintError("Volume name is too long\n", code);
3134 "Creating new volume %lu on replication site %s: ",
3135 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3136 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3137 serverNumber[index], hoststr) :
3138 hostutil_GetNameByINet(vldbEntryPtr->
3139 serverNumber[index]));
3144 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3146 vldbEntryPtr->volumeId[RWVOL],
3147 tmpVolId?&tmpVolId:&volid,
3150 PrintError("Failed to create the ro volume: ", code);
3153 vldbEntryPtr->volumeId[ROVOL] = volid;
3157 /* The following is a bit redundant, since create sets these flags by default */
3159 AFSVolSetFlags(*connPtr, *transPtr,
3160 VTDeleteOnSalvage | VTOutOfService);
3162 PrintError("Failed to set flags on the ro volume: ", code);
3167 /* Otherwise, the transaction did succeed, so get the creation date of the
3168 * latest RO volume on the replication site
3171 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3172 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3173 serverNumber[index], hoststr) :
3174 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3176 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3178 PrintError("Failed to get status of volume on destination: ",
3183 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3188 code = DoVolClone(*connPtr, volid,
3189 vldbEntryPtr->serverPartition[index],
3190 readonlyVolume, tmpVolId, "temporary",
3191 vldbEntryPtr->name, NULL, ".roclone", NULL,
3196 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3197 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3204 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3208 if (tcode && tcode != ENOENT)
3209 PrintError("Could not end transaction on a ro volume: ", tcode);
3216 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3217 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3218 void *cookie, manyResults * results)
3222 for (i = 0; i < tr->manyDests_len; i++) {
3223 results->manyResults_val[i] =
3224 AFSVolForward(fromconn, fromtid, fromdate,
3225 &(tr->manyDests_val[i].server),
3226 tr->manyDests_val[i].trans, cookie);
3232 * Check if a trans has timed out, and recreate it if necessary.
3234 * @param[in] aconn RX connection to the relevant server
3235 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3236 * contains the new trans ID on success
3237 * @param[in] apart Partition for the transaction
3238 * @param[in] astat The status of the original transaction
3240 * @return operation status
3241 * @retval 0 existing transaction is still valid, or we managed to recreate
3242 * the trans successfully
3243 * @retval nonzero Fatal error; bail out
3246 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3247 struct volser_status *astat)
3249 struct volser_status new_status;
3252 memset(&new_status, 0, sizeof(new_status));
3253 code = AFSVolGetStatus(aconn, *atid, &new_status);
3255 if (code == ENOENT) {
3257 VPRINT1("Old transaction on cloned volume %lu timed out, "
3258 "restarting transaction\n", (long unsigned) astat->volID);
3259 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3262 PrintError("Failed to recreate cloned RO volume transaction\n",
3267 memset(&new_status, 0, sizeof(new_status));
3268 code = AFSVolGetStatus(aconn, *atid, &new_status);
3270 PrintError("Failed to get status on recreated transaction\n",
3275 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3276 PrintError("Recreated transaction on cloned RO volume, but "
3277 "the volume has changed!\n", 0);
3281 PrintError("Unable to get status of current cloned RO transaction\n",
3286 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3288 PrintError("Internal error: current GetStatus does not match "
3289 "original GetStatus?\n", 0);
3298 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3299 struct rx_connection **toconns, struct release *times,
3302 afs_int32 s, code = 0, rcode = 0;
3303 /* End the transactions and destroy the connections */
3304 for (s = 0; s < volcount; s++) {
3305 if (replicas[s].trans) {
3306 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3308 replicas[s].trans = 0;
3312 if ((s == 0) || (code != ENOENT)) {
3313 PrintError("Could not end transaction on a ro volume: ",
3317 ("Transaction timed out on a ro volume. Will retry.\n",
3319 if (times[s].vldbEntryIndex < *vldbindex)
3320 *vldbindex = times[s].vldbEntryIndex;
3325 rx_DestroyConnection(toconns[s]);
3331 * Release a volume to read-only sites
3333 * Release volume <afromvol> on <afromserver> <afrompart> to all its RO
3334 * sites (complete release), unless the previous release was incomplete
3335 * or new sites were added without changes to the read-write volume, in
3336 * which case we bring the remaining volumes up to date with the volumes
3337 * that were previously released successfully.
3339 * Will create a clone from the RW, then dump the clone out to
3340 * the remaining replicas. If there is more than 1 RO sites,
3341 * ensure that the VLDB says at least one RO is available all
3342 * the time: Influences when we write back the VLDB entry.
3344 * @param[in] afromvol volume to be released
3345 * @param[in] afromserver server containing afromvol
3346 * @param[in] afrompart partition containing afromvol
3347 * @param[in] flags bitmap of options
3348 * REL_COMPLETE - force a complete release
3349 * REL_FULLDUMPS - force full dumps
3352 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3353 afs_int32 afrompart, int flags)
3357 afs_int32 vcode, rcode, tcode;
3358 afs_uint32 cloneVolId = 0, roVolId;
3359 struct replica *replicas = 0;
3360 struct nvldbentry entry, storeEntry;
3361 int i, volcount = 0, m, vldbindex;
3363 struct restoreCookie cookie;
3364 struct rx_connection **toconns = 0;
3365 struct release *times = 0;
3367 struct rx_connection *fromconn = (struct rx_connection *)0;
3368 afs_int32 error = 0;
3370 afs_int32 clonetid = 0, onlinetid;
3371 afs_int32 fromtid = 0;
3372 afs_uint32 fromdate = 0;
3373 afs_uint32 thisdate;
3377 manyResults results;
3378 int rwindex, roindex, roclone, roexists;
3379 afs_uint32 rwcrdate = 0, rwupdate = 0;
3380 afs_uint32 clcrdate;
3384 } remembertime[NMAXNSERVERS];
3385 int releasecount = 0;
3386 struct volser_status volstatus;
3388 afs_int32 origflags[NMAXNSERVERS];
3389 struct volser_status orig_status;
3390 int notreleased = 0;
3391 int tried_justnewsites = 0;
3392 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3393 int sites = 0; /* number of ro sites */
3394 int new_sites = 0; /* number of ro sites markes as new */
3397 CR_PARTIAL = 0x0000, /**< just new sites added or recover from a previous failed release */
3398 CR_FORCED = 0x0001, /**< complete: forced by caller */
3399 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3400 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3401 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3402 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3403 } complete_release_t;
3405 complete_release_t complete_release = CR_PARTIAL;
3407 memset(remembertime, 0, sizeof(remembertime));
3408 memset(&results, 0, sizeof(results));
3409 memset(origflags, 0, sizeof(origflags));
3411 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3412 if (vcode != VL_RERELEASE)
3413 ONERROR(vcode, afromvol,
3414 "Could not lock the VLDB entry for the volume %u.\n");
3417 /* Get the vldb entry in readable format */
3418 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3419 ONERROR(vcode, afromvol,
3420 "Could not fetch the entry for the volume %u from the VLDB.\n");
3421 MapHostToNetwork(&entry);
3424 EnumerateEntry(&entry);
3426 if (!ISNAMEVALID(entry.name))
3427 ONERROR(VOLSERBADOP, entry.name,
3428 "Volume name %s is too long, rename before releasing.\n");
3429 if (entry.volumeId[RWVOL] != afromvol)
3430 ONERROR(VOLSERBADOP, afromvol,
3431 "The volume %u being released is not a read-write volume.\n");
3432 if (entry.nServers <= 1)
3433 ONERROR(VOLSERBADOP, afromvol,
3434 "Volume %u has no replicas - release operation is meaningless!\n");
3435 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3436 ONERROR(VOLSERBADOP, entry.name,
3437 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3439 /* roclone is true if one of the RO volumes is on the same
3440 * partition as the RW volume. In this case, we make the RO volume
3441 * on the same partition a clone instead of a complete copy.
3444 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3445 roclone = ((roindex == -1) ? 0 : 1);
3446 rwindex = Lp_GetRwIndex(&entry);
3448 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3450 /* Make sure we have a RO volume id to work with */
3451 if (entry.volumeId[ROVOL] == INVALID_BID) {
3452 /* need to get a new RO volume id */
3453 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3454 ONERROR(vcode, entry.name, "Can't allocate ID for RO volume of %s\n");
3456 entry.volumeId[ROVOL] = roVolId;
3457 MapNetworkToHost(&entry, &storeEntry);
3458 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3459 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3463 * Determine if this is to be a complete release or a recovery of a
3464 * previous unfinished release. The previous release is considered to be
3465 * unfinished when the clone was successfully distributed to at least one
3466 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3469 * The caller can override the vldb flags check using the -force
3470 * or -force-reclone flag, to force this to be a complete release.
3472 for (i = 0; i < entry.nServers; i++) {
3473 if (entry.serverFlags[i] & VLSF_ROVOL) {
3475 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3477 if (entry.serverFlags[i] & VLSF_DONTUSE)
3480 origflags[i] = entry.serverFlags[i];
3483 if (flags & REL_COMPLETE) {
3484 complete_release |= CR_FORCED;
3487 if (new_sites == 0) {
3488 complete_release |= CR_LAST_OK;
3489 } else if (new_sites == sites) {
3490 complete_release |= CR_ALL_NEW;
3493 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3494 && !(complete_release & CR_FORCED)) {
3495 if (notreleased && notreleased != sites) {
3496 /* we have some new unreleased sites. try to just release to those,
3497 * if the RW has not changed. The caller can override with -force
3498 * or with -force-reclone. */
3503 /* Determine which volume id to use and see if it exists */
3504 cloneVolId = (complete_release || entry.cloneId == 0)
3505 ? entry.volumeId[ROVOL] : entry.cloneId;
3507 code = VolumeExists(afromserver, afrompart, cloneVolId);
3508 roexists = ((code == ENODEV) ? 0 : 1);
3510 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3512 ONERROR(-1, afromserver,
3513 "Cannot establish connection with server 0x%x\n");
3515 if (!complete_release) {
3517 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3519 /* Begin transaction on RW and mark it busy while we query it */
3520 code = AFSVolTransCreate_retry(
3521 fromconn, afromvol, afrompart, ITBusy, &fromtid
3523 ONERROR(code, afromvol,
3524 "Failed to start transaction on RW volume %u\n");
3526 /* Query the creation date for the RW */
3527 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3528 ONERROR(code, afromvol,
3529 "Failed to get the status of RW volume %u\n");
3530 rwcrdate = volstatus.creationDate;
3532 /* End transaction on RW */
3533 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3535 ONERROR((code ? code : rcode), afromvol,
3536 "Failed to end transaction on RW volume %u\n");
3538 /* Begin transaction on clone and mark it busy while we query it */
3539 code = AFSVolTransCreate_retry(
3540 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3542 ONERROR(code, cloneVolId,
3543 "Failed to start transaction on RW clone %u\n");
3545 /* Query the creation date for the clone */
3546 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3547 ONERROR(code, cloneVolId,
3548 "Failed to get the status of RW clone %u\n");
3549 clcrdate = volstatus.creationDate;
3551 /* End transaction on clone */
3552 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3554 ONERROR((code ? code : rcode), cloneVolId,
3555 "Failed to end transaction on RW clone %u\n");
3557 if (rwcrdate > clcrdate)
3558 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3562 if (!complete_release || (complete_release & CR_NEW_RW)) {
3563 /* in case the RW has changed, and just to be safe */
3568 if (!complete_release) {
3570 "This is a recovery of previously failed release\n");
3572 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3573 if (complete_release == CR_LAST_OK) {