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>
14 #include <sys/types.h>
18 #include <sys/statfs.h>
25 #include <netinet/in.h>
29 #include <afs/voldefs.h>
32 #include <afs/vlserver.h>
34 #include <afs/cellconfig.h>
37 #include <afs/afsint.h>
41 #include <afs/com_err.h>
43 #include <afs/kautils.h>
45 #include <afs/ihandle.h>
47 #include <afs/ntops.h>
49 #include <afs/vnode.h>
50 #include <afs/volume.h>
52 #define ERRCODE_RANGE 8 /* from error_table.h */
53 #define CLOCKSKEW 2 /* not really skew, but resolution */
54 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
56 /* for UV_MoveVolume() recovery */
58 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
61 #include "volser_internal.h"
62 #include "volser_prototypes.h"
63 #include "vsutils_prototypes.h"
64 #include "lockprocs_prototypes.h"
66 struct ubik_client *cstruct;
67 int verbose = 0, noresolve = 0;
72 afs_int32 vldbEntryIndex;
75 /* Utility macros used by rest of this source file */
76 #define EPRINT(ec, es) \
78 fprintf(STDERR, "\n"); \
79 fprintf(STDERR, (es)); \
83 #define EPRINT1(ec, es, ep1) \
85 fprintf(STDERR, "\n"); \
86 fprintf(STDERR, (es), (ep1)); \
90 #define EPRINT2(ec, es, ep1, ep2) \
92 fprintf(STDERR, "\n"); \
93 fprintf(STDERR, (es), (ep1), (ep2)); \
97 #define EPRINT3(ec, es, ep1, ep2, ep3) \
99 fprintf(STDERR, "\n"); \
100 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
101 PrintError(" ",ec); \
104 #define EGOTO(where, ec, es) \
113 #define EGOTO1(where, ec, es, ep1) \
116 EPRINT1((ec),(es),(ep1)); \
122 #define EGOTO2(where, ec, es, ep1, ep2) \
125 EPRINT2((ec),(es),(ep1),(ep2)); \
131 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
134 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
141 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
142 #define VPRINT1(es, p) \
143 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
144 #define VPRINT2(es, p1, p2) \
145 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
146 #define VPRINT3(es, p1, p2, p3) \
147 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
149 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
150 #define VEPRINT(es) \
151 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
152 #define VEPRINT1(es, p) \
153 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
154 #define VEPRINT2(es, p1, p2) \
155 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
156 #define VEPRINT3(es, p1, p2, p3) \
157 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
159 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
163 /* getting rid of this */
164 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
167 /* Protos for static routines */
169 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
170 afs_int32 apart, afs_uint32 okvol,
173 static int DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
175 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
176 struct rx_connection **connPtr, afs_int32 * transPtr,
177 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr);
178 static int SimulateForwardMultiple(struct rx_connection *fromconn,
179 afs_int32 fromtid, afs_int32 fromdate,
180 manyDests * tr, afs_int32 flags,
181 void *cookie, manyResults * results);
182 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
183 afs_int32 apart, afs_int32 * modentry,
184 afs_uint32 * maxvolid);
187 /*map the partition <partId> into partition name <partName>*/
189 MapPartIdIntoName(afs_int32 partId, char *partName)
191 if (partId < 26) { /* what if partId > = 26 ? */
192 strcpy(partName, "/vicep");
193 partName[6] = partId + 'a';
196 } else if (partId < VOLMAXPARTS) {
197 strcpy(partName, "/vicep");
199 partName[6] = 'a' + (partId / 26);
200 partName[7] = 'a' + (partId % 26);
212 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
213 response = c = getchar();
214 while (!(c == EOF || c == '\n'))
215 c = getchar(); /*skip to end of line */
216 code = (response == 'y' || response == 'Y');
222 PrintError(char *msg, afs_int32 errcode)
224 fprintf(STDERR, "%s", msg);
225 /*replace by a big switch statement */
230 fprintf(STDERR, "Possible communication failure\n");
233 fprintf(STDERR, "Volume needs to be salvaged\n");
236 fprintf(STDERR, "Bad vnode number quoted\n");
240 "Volume not attached, does not exist, or not on line\n");
243 fprintf(STDERR, "Volume already exists\n");
246 fprintf(STDERR, "Volume is not in service\n");
249 fprintf(STDERR, "Volume is off line\n");
252 fprintf(STDERR, "Volume is already on line\n");
255 fprintf(STDERR, "Partition is full\n");
258 fprintf(STDERR, "Volume max quota exceeded\n");
261 fprintf(STDERR, "Volume temporarily unavailable\n");
264 fprintf(STDERR, "Volume has moved to another server\n");
267 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
270 fprintf(STDERR, "VLDB: a read terminated too early\n");
273 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
276 fprintf(STDERR, "VLDB: internal creation failure\n");
279 fprintf(STDERR, "VLDB: no such entry\n");
282 fprintf(STDERR, "VLDB: vldb database is empty\n");
285 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
288 fprintf(STDERR, "VLDB: volume name is illegal\n");
291 fprintf(STDERR, "VLDB: index was out of range\n");
294 fprintf(STDERR, "VLDB: bad volume type\n");
297 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
299 case VL_BADPARTITION:
300 fprintf(STDERR, "VLDB: bad partition number\n");
303 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
306 fprintf(STDERR, "VLDB: no such repsite server exists\n");
308 case VL_DUPREPSERVER:
309 fprintf(STDERR, "VLDB: replication site server already exists\n");
312 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
315 fprintf(STDERR, "VLDB: illegal reference count number\n");
317 case VL_SIZEEXCEEDED:
318 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
321 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
323 case VL_BADVOLIDBUMP:
324 fprintf(STDERR, "VLDB: illegal max volid increment\n");
326 case VL_IDALREADYHASHED:
327 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
330 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
333 fprintf(STDERR, "VLDB: bad volume operation code\n");
335 case VL_BADRELLOCKTYPE:
336 fprintf(STDERR, "VLDB: bad release lock type\n");
339 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
341 case VL_BADSERVERFLAG:
342 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
345 fprintf(STDERR, "VLDB: no permission access for call\n");
347 case VOLSERREAD_DUMPERROR:
349 "VOLSER: Problems encountered in reading the dump file !\n");
351 case VOLSERDUMPERROR:
352 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
354 case VOLSERATTACH_ERROR:
355 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
357 case VOLSERDETACH_ERROR:
358 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
360 case VOLSERILLEGAL_PARTITION:
361 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
363 case VOLSERBAD_ACCESS:
364 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
366 case VOLSERVLDB_ERROR:
367 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
370 fprintf(STDERR, "VOLSER: error in volume name\n");
373 fprintf(STDERR, "VOLSER: volume has moved\n");
376 fprintf(STDERR, "VOLSER: illegal operation\n");
378 case VOLSERBADRELEASE:
379 fprintf(STDERR, "VOLSER: release could not be completed\n");
382 fprintf(STDERR, "VOLSER: volume is busy\n");
384 case VOLSERNO_MEMORY:
385 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
389 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
391 case VOLSERMULTIRWVOL:
393 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
397 "VOLSER: not all entries were successfully processed\n");
404 initialize_KA_error_table();
405 initialize_RXK_error_table();
406 initialize_KTC_error_table();
407 initialize_ACFG_error_table();
408 initialize_CMD_error_table();
409 initialize_VL_error_table();
411 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
412 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
413 afs_error_message(errcode));
420 void init_volintInfo(struct volintInfo *vinfo) {
421 memset(vinfo, 0, sizeof(struct volintInfo));
423 vinfo->maxquota = -1;
425 vinfo->creationDate = -1;
426 vinfo->updateDate = -1;
434 static struct rx_securityClass *uvclass = 0;
435 static int uvindex = -1;
436 /* called by VLDBClient_Init to set the security module to be used in the RPC */
438 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
445 /* bind to volser on <port> <aserver> */
446 /* takes server address in network order, port in host order. dumb */
447 struct rx_connection *
448 UV_Bind(afs_int32 aserver, afs_int32 port)
450 register struct rx_connection *tc;
452 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
458 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
459 afs_int32 partition, char *name, afs_int32 type,
460 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
465 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
467 if (code != VOLSERVOLBUSY)
470 #ifdef AFS_PTHREAD_ENV
473 IOMGR_Sleep(3-retries);
480 AFSVolTransCreate_retry(struct rx_connection *z_conn,
481 afs_int32 volume, afs_int32 partition,
482 afs_int32 flags, afs_int32 * trans)
487 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
488 if (code != VOLSERVOLBUSY)
491 #ifdef AFS_PTHREAD_ENV
494 IOMGR_Sleep(3-retries);
501 /* if <okvol> is allright(indicated by beibg able to
502 * start a transaction, delete the <delvol> */
504 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
505 afs_uint32 okvol, afs_uint32 delvol)
507 afs_int32 error, code, tid, rcode;
512 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
515 code = AFSVolDeleteVolume(aconn, tid);
518 code = AFSVolEndTrans(aconn, tid, &rcode);
525 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
527 code = AFSVolEndTrans(aconn, tid, &rcode);
532 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
535 code = AFSVolDeleteVolume(aconn, tid);
538 code = AFSVolEndTrans(aconn, tid, &rcode);
551 /* called by EmuerateEntry, show vldb entry in a reasonable format */
553 SubEnumerateEntry(struct nvldbentry *entry)
561 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
562 if (entry->flags & RW_EXISTS)
563 fprintf(STDOUT, " valid \n");
565 fprintf(STDOUT, " invalid \n");
566 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
567 if (entry->flags & RO_EXISTS)
568 fprintf(STDOUT, " valid \n");
570 fprintf(STDOUT, " invalid \n");
571 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
572 if (entry->flags & BACK_EXISTS)
573 fprintf(STDOUT, " valid \n");
575 fprintf(STDOUT, " invalid \n");
576 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
577 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
579 if (entry->flags & RW_EXISTS)
580 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
581 if (entry->flags & RO_EXISTS)
582 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
583 if (entry->flags & BACK_EXISTS)
584 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
585 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
586 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
587 fprintf(STDOUT, "\n");
589 fprintf(STDOUT, " number of sites -> %lu\n",
590 (unsigned long)entry->nServers);
591 for (i = 0; i < entry->nServers; i++) {
592 if (entry->serverFlags[i] & NEW_REPSITE)
595 for (i = 0; i < entry->nServers; i++) {
596 MapPartIdIntoName(entry->serverPartition[i], pname);
597 fprintf(STDOUT, " server %s partition %s ",
598 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
599 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
600 if (entry->serverFlags[i] & ITSRWVOL)
601 fprintf(STDOUT, "RW Site ");
603 fprintf(STDOUT, "RO Site ");
605 if (entry->serverFlags[i] & NEW_REPSITE)
606 fprintf(STDOUT," -- New release");
608 if (!(entry->serverFlags[i] & ITSRWVOL))
609 fprintf(STDOUT," -- Old release");
611 if (entry->serverFlags[i] & RO_DONTUSE)
612 fprintf(STDOUT, " -- Not released");
614 fprintf(STDOUT, "\n");
621 /*enumerate the vldb entry corresponding to <entry> */
623 EnumerateEntry(struct nvldbentry *entry)
626 fprintf(STDOUT, "\n");
627 fprintf(STDOUT, "%s \n", entry->name);
628 SubEnumerateEntry(entry);
632 /* forcibly remove a volume. Very dangerous call */
634 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_uint32 volid)
636 register struct rx_connection *tconn;
637 register afs_int32 code;
639 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
641 code = AFSVolNukeVolume(tconn, partid, volid);
642 rx_DestroyConnection(tconn);
648 /* like df. Return usage of <pname> on <server> in <partition> */
650 UV_PartitionInfo64(afs_int32 server, char *pname,
651 struct diskPartition64 *partition)
653 register struct rx_connection *aconn;
656 aconn = (struct rx_connection *)0;
657 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
658 code = AFSVolPartitionInfo64(aconn, pname, partition);
659 if (code == RXGEN_OPCODE) {
660 struct diskPartition *dpp =
661 (struct diskPartition *)malloc(sizeof(struct diskPartition));
662 code = AFSVolPartitionInfo(aconn, pname, dpp);
664 strncpy(partition->name, dpp->name, 32);
665 strncpy(partition->devName, dpp->devName, 32);
666 partition->lock_fd = dpp->lock_fd;
667 partition->free = dpp->free;
668 partition->minFree = dpp->minFree;
673 fprintf(STDERR, "Could not get information on partition %s\n", pname);
674 PrintError("", code);
677 rx_DestroyConnection(aconn);
681 /* old interface to create volumes */
683 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
688 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
692 /* less old interface to create volumes */
694 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
695 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
696 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
698 afs_uint32 roid = 0, bkid = 0;
699 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
700 aspare3, aspare4, anewid, &roid, &bkid);
704 * Create a volume on the given server and partition
706 * @param aserver server to create volume on
707 * @param spart partition to create volume on
708 * @param aname name of new volume
709 * @param aquota quota for new volume
710 * @param anewid contains the desired volume id for the new volume. If
711 * *anewid == 0, a new id will be chosen, and will be placed
712 * in *anewid when UV_CreateVolume3 returns.
713 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
714 * will be unset. If *aroid == 0, an id will be chosen, and
715 * will be placed in *anewid when UV_CreateVolume3 returns.
716 * @param abkid same as aroid, except for the BK volume id instead of the
718 * @return 0 on success, error code otherwise.
721 UV_CreateVolume3(afs_int32 aserver, afs_int32 apart, char *aname,
722 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
723 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
724 afs_uint32 * aroid, afs_uint32 * abkid)
726 register struct rx_connection *aconn;
728 register afs_int32 code;
730 afs_int32 rcode, vcode;
732 struct nvldbentry entry, storeEntry; /*the new vldb entry */
733 struct volintInfo tstatus;
736 aconn = (struct rx_connection *)0;
739 init_volintInfo(&tstatus);
740 tstatus.maxquota = aquota;
742 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
744 if (aroid && *aroid) {
745 VPRINT1("Using RO volume ID %d.\n", *aroid);
747 if (abkid && *abkid) {
748 VPRINT1("Using BK volume ID %d.\n", *abkid);
752 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
754 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
757 VPRINT1("Using volume ID %d.\n", *anewid);
759 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
760 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
762 if (aroid && *aroid == 0) {
763 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
764 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
767 if (abkid && *abkid == 0) {
768 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
769 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
773 /* rw,ro, bk id are related in the default case */
774 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
776 if (aroid && *aroid == 0) {
779 if (abkid && *abkid == 0) {
784 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
785 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
788 code = AFSVolSetInfo(aconn, tid, &tstatus);
790 EPRINT(code, "Could not change quota, continuing...\n");
792 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
793 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
796 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
798 /* set up the vldb entry for this volume */
799 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
801 entry.serverNumber[0] = aserver; /* this should have another
802 * level of indirection later */
803 entry.serverPartition[0] = apart; /* this should also have
804 * another indirection level */
805 entry.flags = RW_EXISTS; /* this records that rw volume exists */
806 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
807 entry.volumeId[RWVOL] = *anewid;
808 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
809 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
811 /*map into right byte order, before passing to xdr, the stuff has to be in host
812 * byte order. Xdr converts it into network order */
813 MapNetworkToHost(&entry, &storeEntry);
814 /* create the vldb entry */
815 vcode = VLDB_CreateEntry(&storeEntry);
818 "Could not create a VLDB entry for the volume %s %lu\n",
819 aname, (unsigned long)*anewid);
820 /*destroy the created volume */
821 VPRINT1("Deleting the newly created volume %u\n", *anewid);
822 AFSVolDeleteVolume(aconn, tid);
826 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
827 /* volume created, now terminate the transaction and release the connection */
828 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
829 * the volume will come online anyway when transaction timesout , so if
830 * vldb entry exists then the volume is guaranteed to exist too wrt create */
834 "Failed to end the transaction on the volume %s %lu\n", aname,
835 (unsigned long)*anewid);
842 code = AFSVolEndTrans(aconn, tid, &rcode);
844 fprintf(STDERR, "WARNING: could not end transaction\n");
847 rx_DestroyConnection(aconn);
848 PrintError("", error);
852 /* create a volume, given a server, partition number, volume name --> sends
853 * back new vol id in <anewid>*/
855 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
858 register struct rx_connection *aconn;
861 struct nvldbentry entry, storeEntry; /*the new vldb entry */
863 aconn = (struct rx_connection *)0;
866 /* set up the vldb entry for this volume */
867 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
869 entry.serverNumber[0] = aserver; /* this should have another
870 * level of indirection later */
871 entry.serverPartition[0] = apart; /* this should also have
872 * another indirection level */
873 entry.flags = RW_EXISTS; /* this records that rw volume exists */
874 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
875 entry.volumeId[RWVOL] = aid;
877 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
878 entry.volumeId[BACKVOL] = *anewid + 2;
880 entry.volumeId[ROVOL] = 0;
881 entry.volumeId[BACKVOL] = 0;
884 /*map into right byte order, before passing to xdr, the stuff has to be in host
885 * byte order. Xdr converts it into network order */
886 MapNetworkToHost(&entry, &storeEntry);
887 /* create the vldb entry */
888 vcode = VLDB_CreateEntry(&storeEntry);
891 "Could not create a VLDB entry for the volume %s %lu\n",
892 aname, (unsigned long)aid);
896 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
900 rx_DestroyConnection(aconn);
901 PrintError("", error);
905 /* Delete the volume <volid>on <aserver> <apart>
906 * the physical entry gets removed from the vldb only if the ref count
910 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
912 struct rx_connection *aconn = (struct rx_connection *)0;
914 afs_int32 code, rcode;
916 struct nvldbentry entry, storeEntry;
918 afs_int32 avoltype = -1, vtype;
919 int notondisk = 0, notinvldb = 0;
921 /* Find and read bhe VLDB entry for this volume */
922 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
924 if (code != VL_NOENT) {
925 EGOTO1(error_exit, code,
926 "Could not lock VLDB entry for the volume %u\n", avolid);
932 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
933 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
935 MapHostToNetwork(&entry);
938 EnumerateEntry(&entry);
941 /* Whether volume is in the VLDB or not. Delete the volume on disk */
942 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
943 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
945 if (code == VNOVOL) {
948 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
952 VPRINT1("Trying to delete the volume %u ...", avolid);
954 code = AFSVolDeleteVolume(aconn, ttid);
955 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
957 code = AFSVolEndTrans(aconn, ttid, &rcode);
958 code = (code ? code : rcode);
960 EGOTO1(error_exit, code,
961 "Could not end the transaction for the volume %u \n", avolid);
965 /* Now update the VLDB entry.
966 * But first, verify we have a VLDB entry.
967 * Whether volume is on disk or not. Delete the volume in VLDB.
972 if (avolid == entry.volumeId[BACKVOL]) {
973 /* Its a backup volume, modify the VLDB entry. Check that the
974 * backup volume is on the server/partition we asked to delete.
976 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
977 notinvldb = 2; /* Not on this server and partition */
981 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
983 entry.flags &= ~BACK_EXISTS;
987 else if (avolid == entry.volumeId[ROVOL]) {
988 /* Its a read-only volume, modify the VLDB entry. Check that the
989 * readonly volume is on the server/partition we asked to delete.
990 * If flags does not have RO_EIXSTS set, then this may mean the RO
991 * hasn't been released (and could exist in VLDB).
993 if (!Lp_ROMatch(aserver, apart, &entry)) {
994 notinvldb = 2; /* Not found on this server and partition */
1000 "Marking the readonly volume %lu deleted in the VLDB\n",
1001 (unsigned long)avolid);
1003 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
1005 if (!Lp_ROMatch(0, 0, &entry))
1006 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
1010 else if (avolid == entry.volumeId[RWVOL]) {
1011 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
1012 * Check that the readwrite volumes is on the server/partition we
1015 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
1016 notinvldb = 2; /* Not found on this server and partition */
1020 /* Delete backup if it exists */
1022 AFSVolTransCreate_retry(aconn, entry.volumeId[BACKVOL], apart,
1027 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
1028 entry.volumeId[BACKVOL]);
1031 code = AFSVolDeleteVolume(aconn, ttid);
1032 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
1033 entry.volumeId[BACKVOL]);
1035 code = AFSVolEndTrans(aconn, ttid, &rcode);
1037 code = (code ? code : rcode);
1038 EGOTO1(error_exit, code,
1039 "Could not end the transaction for the volume %u \n",
1040 entry.volumeId[BACKVOL]);
1042 fprintf(STDOUT, " done\n");
1047 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1048 (unsigned long)avolid,
1050 flags & BACK_EXISTS) ? ", and its backup volume," :
1053 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1055 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
1058 if (entry.flags & RO_EXISTS)
1059 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1063 notinvldb = 2; /* Not found on this server and partition */
1067 /* Either delete or replace the VLDB entry */
1068 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
1071 "Last reference to the VLDB entry for %lu - deleting entry\n",
1072 (unsigned long)avolid);
1073 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1074 EGOTO1(error_exit, code,
1075 "Could not delete the VLDB entry for the volume %u \n",
1078 MapNetworkToHost(&entry, &storeEntry);
1080 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1081 (LOCKREL_OPCODE | LOCKREL_AFSID |
1082 LOCKREL_TIMESTAMP));
1083 EGOTO1(error_exit, code,
1084 "Could not update the VLDB entry for the volume %u \n",
1091 EPRINT(error, "\n");
1093 if (notondisk && notinvldb) {
1094 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1095 ((notinvldb == 2) ? "on server and partition" : ""));
1097 error = VOLSERNOVOL;
1098 } else if (notondisk) {
1100 "WARNING: Volume %lu did not exist on the partition\n",
1101 (unsigned long)avolid);
1102 } else if (notinvldb) {
1103 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1104 (unsigned long)avolid,
1105 ((notinvldb == 2) ? "on server and partition" : ""));
1109 code = AFSVolEndTrans(aconn, ttid, &rcode);
1110 code = (code ? code : rcode);
1112 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1113 (unsigned long)avolid);
1114 PrintError("", code);
1122 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1123 (LOCKREL_OPCODE | LOCKREL_AFSID |
1124 LOCKREL_TIMESTAMP));
1127 "Could not release the lock on the VLDB entry for the volume %u \n",
1135 rx_DestroyConnection(aconn);
1139 /* add recovery to UV_MoveVolume */
1141 #define TESTC 0 /* set to test recovery code, clear for production */
1147 do_interrupt(void * unused)
1150 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1151 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1152 * changed. This will avoid some sanity checks, but until a better way
1153 * is found, the only alternative is always crashing and burning on at
1154 * least the stack-overflow check. */
1155 lwp_cpptr->stack = NULL;
1160 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1162 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1163 fprintf(STDOUT, "enter second control-c to exit\n");
1171 sigint_handler(int x)
1173 #ifdef AFS_PTHREAD_ENV
1176 IOMGR_SoftSig(do_interrupt, 0);
1178 (void)signal(SIGINT, sigint_handler);
1181 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1182 * <atopart>. The operation is almost idempotent. The following
1183 * flags are recognized:
1185 * RV_NOCLONE - don't use a copy clone
1189 UV_MoveVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1190 afs_int32 atoserver, afs_int32 atopart, int flags)
1192 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1193 * be changing during the move */
1194 struct rx_connection * volatile toconn;
1195 struct rx_connection * volatile fromconn;
1196 afs_int32 volatile fromtid;
1197 afs_int32 volatile totid;
1198 afs_int32 volatile clonetid;
1199 afs_uint32 volatile newVol;
1200 afs_uint32 volatile volid;
1201 afs_uint32 volatile backupId;
1202 int volatile islocked;
1207 char tmpName[VOLSER_MAXVOLNAME + 1];
1212 struct restoreCookie cookie;
1213 register afs_int32 vcode, code;
1214 struct volser_status tstatus;
1215 struct destServer destination;
1217 struct nvldbentry entry, storeEntry;
1220 char in, lf; /* for test code */
1224 #ifdef ENABLE_BUGFIX_1165
1225 volEntries volumeInfo;
1226 struct volintInfo *infop = 0;
1230 fromconn = (struct rx_connection *)0;
1231 toconn = (struct rx_connection *)0;
1241 /* support control-c processing */
1244 (void)signal(SIGINT, sigint_handler);
1248 "\nThere are three tests points - verifies all code paths through recovery.\n");
1249 fprintf(STDOUT, "First test point - operation not started.\n");
1250 fprintf(STDOUT, "...test here (y, n)? ");
1252 fscanf(stdin, "%c", &in);
1253 fscanf(stdin, "%c", &lf); /* toss away */
1255 fprintf(STDOUT, "type control-c\n");
1257 fprintf(stdout, ".");
1262 /* or drop through */
1265 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1266 EGOTO1(mfail, vcode,
1267 "Could not fetch the entry for the volume %u from the VLDB \n",
1270 if (entry.volumeId[RWVOL] != afromvol) {
1271 fprintf(STDERR, "Only RW volume can be moved\n");
1275 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1276 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1279 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1280 EGOTO1(mfail, vcode,
1281 "Could not fetch the entry for the volume %u from the VLDB \n",
1284 backupId = entry.volumeId[BACKVOL];
1285 MapHostToNetwork(&entry);
1287 if (!Lp_Match(afromserver, afrompart, &entry)) {
1288 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1289 if (!Lp_Match(atoserver, atopart, &entry)) {
1290 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1291 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1292 (unsigned long)afromvol);
1293 fprintf(STDERR, "The current site is :");
1294 for (i = 0; i < entry.nServers; i++) {
1295 if (entry.serverFlags[i] == ITSRWVOL) {
1297 MapPartIdIntoName(entry.serverPartition[i], pname);
1298 fprintf(STDERR, " server %s partition %s \n",
1299 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1300 hostutil_GetNameByINet(entry.serverNumber[i]),
1305 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1306 (LOCKREL_OPCODE | LOCKREL_AFSID |
1307 LOCKREL_TIMESTAMP));
1308 EGOTO1(mfail, vcode,
1309 " Could not release lock on the VLDB entry for the volume %u \n",
1312 return VOLSERVOLMOVED;
1315 /* delete the volume afromvol on src_server */
1316 /* from-info does not exist but to-info does =>
1317 * we have already done the move, but the volume
1318 * may still be existing physically on from fileserver
1320 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1326 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITOffline,
1330 if (!code) { /* volume exists - delete it */
1331 VPRINT1("Setting flags on leftover source volume %u ...",
1334 AFSVolSetFlags(fromconn, fromtid,
1335 VTDeleteOnSalvage | VTOutOfService);
1337 "Failed to set flags on the leftover source volume %u\n",
1341 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1342 code = AFSVolDeleteVolume(fromconn, fromtid);
1344 "Failed to delete the leftover source volume %u\n",
1348 VPRINT1("Ending transaction on leftover source volume %u ...",
1350 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1355 "Could not end the transaction for the leftover source volume %u \n",
1360 /*delete the backup volume now */
1363 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
1367 if (!code) { /* backup volume exists - delete it */
1368 VPRINT1("Setting flags on leftover backup volume %u ...",
1371 AFSVolSetFlags(fromconn, fromtid,
1372 VTDeleteOnSalvage | VTOutOfService);
1374 "Failed to set flags on the backup volume %u\n", backupId);
1377 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1378 code = AFSVolDeleteVolume(fromconn, fromtid);
1380 "Could not delete the leftover backup volume %u\n",
1384 VPRINT1("Ending transaction on leftover backup volume %u ...",
1386 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1391 "Could not end the transaction for the leftover backup volume %u\n",
1401 /* From-info matches the vldb info about volid,
1402 * its ok start the move operation, the backup volume
1403 * on the old site is deleted in the process
1405 if (afrompart == atopart) {
1406 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1407 EGOTO2(mfail, error,
1408 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1409 afromserver, error);
1412 EGOTO1(mfail, VOLSERVOLMOVED,
1413 "Warning: Moving volume %u to its home partition ignored!\n",
1419 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1420 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1421 fromtid = totid = 0; /* initialize to uncreated */
1424 * clone the read/write volume locally.
1427 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1428 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1430 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1434 if (!(flags & RV_NOCLONE)) {
1435 /* Get a clone id */
1436 VPRINT1("Allocating new volume id for clone of volume %u ...",
1438 newVol = tmpVol = 0;
1439 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1441 EGOTO1(mfail, vcode,
1442 "Could not get an ID for the clone of volume %u from the VLDB\n",
1446 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1447 VPRINT1("Cloning source volume %u ...", afromvol);
1448 strcpy(vname, "move-clone-temp");
1450 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1452 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1457 /* lookup the name of the volume we just cloned */
1459 code = AFSVolGetName(fromconn, fromtid, &volName);
1460 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1463 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1465 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1470 "Failed to end the transaction on the source volume %u\n",
1475 * Create the destination volume
1478 if (!(flags & RV_NOCLONE)) {
1479 /* All of this is to get the fromDate */
1480 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1483 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1487 "Failed to start a transaction on the cloned volume%u\n",
1491 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1493 AFSVolSetFlags(fromconn, clonetid,
1494 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1495 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1499 /* remember time from which we've dumped the volume */
1500 VPRINT1("Getting status of cloned volume %u ...", newVol);
1501 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1503 "Failed to get the status of the cloned volume %u\n",
1507 fromDate = CLOCKADJ(tstatus.creationDate);
1509 /* With RV_NOCLONE, just do a full copy from the source */
1514 #ifdef ENABLE_BUGFIX_1165
1516 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1517 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1518 * don't use this information...
1520 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1521 volumeInfo.volEntries_len = 0;
1522 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1524 "Failed to get the volint Info of the cloned volume %u\n",
1527 infop = (volintInfo *) volumeInfo.volEntries_val;
1528 infop->maxquota = -1; /* Else it will replace the default quota */
1529 infop->creationDate = -1; /* Else it will use the source creation date */
1530 infop->updateDate = -1; /* Else it will use the source update date */
1533 /* create a volume on the target machine */
1536 code = AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &tmp);
1539 /* Delete the existing volume.
1540 * While we are deleting the volume in these steps, the transaction
1541 * we started against the cloned volume (clonetid above) will be
1542 * sitting idle. It will get cleaned up after 600 seconds
1544 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1545 code = AFSVolDeleteVolume(toconn, totid);
1547 "Could not delete the pre-existing volume %u on destination\n",
1552 ("Ending transaction on pre-existing volume %u on destination ...",
1554 code = AFSVolEndTrans(toconn, totid, &rcode);
1559 "Could not end the transaction on pre-existing volume %u on destination\n",
1564 VPRINT1("Creating the destination volume %u ...", volid);
1568 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1572 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1576 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1580 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1582 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1584 "Failed to set the flags on the destination volume %u\n", volid);
1588 * Now dump the clone to the new volume
1591 destination.destHost = ntohl(atoserver);
1592 destination.destPort = AFSCONF_VOLUMEPORT;
1593 destination.destSSID = 1;
1595 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1596 cookie.type = RWVOL;
1597 cookie.parent = entry.volumeId[RWVOL];
1600 if (!(flags & RV_NOCLONE)) {
1601 /* Copy the clone to the new volume */
1602 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1605 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1607 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1610 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1611 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1616 "Failed to end the transaction on the cloned volume %u\n",
1622 * reattach to the main-line volume, and incrementally dump it.
1625 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1627 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1630 "Failed to create a transaction on the source volume %u\n",
1634 /* now do the incremental */
1636 ("Doing the%s dump from source to destination for volume %u ... ",
1637 (flags & RV_NOCLONE) ? "" : " incremental",
1640 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1643 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1644 (flags & RV_NOCLONE) ? "" : " incremental");
1647 /* now adjust the flags so that the new volume becomes official */
1648 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1649 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1651 "Failed to set the flags to make old source volume offline\n");
1654 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1655 code = AFSVolSetFlags(toconn, totid, 0);
1657 "Failed to set the flags to make new source volume online\n");
1660 #ifdef ENABLE_BUGFIX_1165
1661 VPRINT1("Setting volume status on destination volume %u ...", volid);
1662 code = AFSVolSetInfo(toconn, totid, infop);
1664 "Failed to set volume status on the destination volume %u\n",
1669 /* put new volume online */
1670 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1671 code = AFSVolEndTrans(toconn, totid, &rcode);
1676 "Failed to end the transaction on the volume %u on the new site\n",
1680 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1681 MapNetworkToHost(&entry, &storeEntry);
1682 storeEntry.flags &= ~BACK_EXISTS;
1686 "Second test point - operation in progress but not complete.\n");
1687 fprintf(STDOUT, "...test here (y, n)? ");
1689 fscanf(stdin, "%c", &in);
1690 fscanf(stdin, "%c", &lf); /* toss away */
1692 fprintf(STDOUT, "type control-c\n");
1694 fprintf(stdout, ".");
1699 /* or drop through */
1702 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1704 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1705 (LOCKREL_OPCODE | LOCKREL_AFSID |
1706 LOCKREL_TIMESTAMP));
1709 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1710 storeEntry.name, (unsigned long)afromvol);
1719 "Third test point - operation complete but no cleanup.\n");
1720 fprintf(STDOUT, "...test here (y, n)? ");
1722 fscanf(stdin, "%c", &in);
1723 fscanf(stdin, "%c", &lf); /* toss away */
1725 fprintf(STDOUT, "type control-c\n");
1727 fprintf(stdout, ".");
1732 /* or drop through */
1735 /* This is tricky. File server is very stupid, and if you mark the volume
1736 * as VTOutOfService, it may mark the *good* instance (if you're moving
1737 * between partitions on the same machine) as out of service. Since
1738 * we're cleaning this code up in DEcorum, we're just going to kludge around
1739 * it for now by removing this call. */
1740 /* already out of service, just zap it now */
1742 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1745 "Failed to set the flags to make the old source volume offline\n");
1749 if (atoserver != afromserver) {
1750 /* set forwarding pointer for moved volumes */
1751 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1752 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1754 "Failed to set the forwarding pointer for the volume %u\n",
1759 VPRINT1("Deleting old volume %u on source ...", afromvol);
1760 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1761 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1765 VPRINT1("Ending transaction on old volume %u on the source ...",
1767 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1772 "Failed to end the transaction on the old volume %u on the source\n",
1776 /* Delete the backup volume on the original site */
1777 VPRINT1("Creating transaction for backup volume %u on source ...",
1781 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline, &tmp);
1785 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1787 AFSVolSetFlags(fromconn, fromtid,
1788 VTDeleteOnSalvage | VTOutOfService);
1790 "Failed to set the flags on the backup volume %u on the source\n",
1794 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1795 code = AFSVolDeleteVolume(fromconn, fromtid);
1797 "Failed to delete the backup volume %u on the source\n",
1801 VPRINT1("Ending transaction on backup volume %u on source ...",
1803 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1808 "Failed to end the transaction on the backup volume %u on the source\n",
1812 code = 0; /* no backup volume? that's okay */
1815 if (!(flags & RV_NOCLONE)) {
1816 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1819 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1823 "Failed to start a transaction on the cloned volume%u\n",
1827 /* now delete the clone */
1828 VPRINT1("Deleting the cloned volume %u ...", newVol);
1829 code = AFSVolDeleteVolume(fromconn, clonetid);
1830 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1834 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1835 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1840 "Failed to end the transaction on the cloned volume %u\n",
1849 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1850 fprintf(STDOUT, "...test here (y, n)? ");
1852 fscanf(stdin, "%c", &in);
1853 fscanf(stdin, "%c", &lf); /* toss away */
1855 fprintf(STDOUT, "type control-c\n");
1857 fprintf(stdout, ".");
1862 /* or drop through */
1865 /* normal cleanup code */
1867 if (entry.flags & RO_EXISTS)
1868 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1871 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1873 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1874 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1878 " Could not release the lock on the VLDB entry for the volume %lu \n",
1879 (unsigned long)afromvol);
1887 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1889 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1890 if (code || rcode) {
1893 "Could not end transaction on the source volume %lu\n",
1894 (unsigned long)afromvol);
1896 error = (code ? code : rcode);
1902 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1903 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1904 if (code || rcode) {
1907 "Could not end transaction on the source's clone volume %lu\n",
1908 (unsigned long)newVol);
1910 error = (code ? code : rcode);
1916 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1918 code = AFSVolEndTrans(toconn, totid, &rcode);
1922 "Could not end transaction on destination volume %lu\n",
1923 (unsigned long)afromvol);
1925 error = (code ? code : rcode);
1931 #ifdef ENABLE_BUGFIX_1165
1936 rx_DestroyConnection(fromconn);
1938 rx_DestroyConnection(toconn);
1939 PrintError("", error);
1942 /* come here only when the sky falls */
1947 "vos move: operation interrupted, cleanup in progress...\n");
1948 fprintf(STDOUT, "clear transaction contexts\n");
1952 /* unlock VLDB entry */
1954 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1955 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1956 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1962 VPRINT("Recovery: Ending transaction on clone volume ...");
1963 AFSVolEndTrans(fromconn, clonetid, &rcode);
1967 VPRINT("Recovery: Ending transaction on destination volume ...");
1968 AFSVolEndTrans(toconn, totid, &rcode);
1971 if (fromtid) { /* put it on-line */
1972 VPRINT("Recovery: Setting volume flags on source volume ...");
1973 AFSVolSetFlags(fromconn, fromtid, 0);
1976 VPRINT("Recovery: Ending transaction on source volume ...");
1977 AFSVolEndTrans(fromconn, fromtid, &rcode);
1981 VPRINT("Recovery: Accessing VLDB.\n");
1982 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1984 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1988 MapHostToNetwork(&entry);
1990 /* Delete either the volume on the source location or the target location.
1991 * If the vldb entry still points to the source location, then we know the
1992 * volume move didn't finish so we remove the volume from the target
1993 * location. Otherwise, we remove the volume from the source location.
1995 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1998 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2002 if (volid && toconn) {
2004 ("Recovery: Creating transaction for destination volume %u ...",
2008 AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &tmp);
2015 ("Recovery: Setting flags on destination volume %u ...",
2017 AFSVolSetFlags(toconn, totid,
2018 VTDeleteOnSalvage | VTOutOfService);
2021 VPRINT1("Recovery: Deleting destination volume %u ...",
2023 AFSVolDeleteVolume(toconn, totid);
2027 ("Recovery: Ending transaction on destination volume %u ...",
2029 AFSVolEndTrans(toconn, totid, &rcode);
2033 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
2038 /* put source volume on-line */
2040 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2044 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2050 VPRINT1("Recovery: Setting flags on source volume %u ...",
2052 AFSVolSetFlags(fromconn, fromtid, 0);
2056 ("Recovery: Ending transaction on source volume %u ...",
2058 AFSVolEndTrans(fromconn, fromtid, &rcode);
2062 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2066 } else { /* yep, move complete */
2069 "move complete - attempt cleanup of source partition - no guarantee\n");
2073 /* delete backup volume */
2075 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
2079 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
2085 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2087 AFSVolSetFlags(fromconn, fromtid,
2088 VTDeleteOnSalvage | VTOutOfService);
2091 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
2092 AFSVolDeleteVolume(fromconn, fromtid);
2096 ("Recovery: Ending transaction on backup volume %u ...",
2098 AFSVolEndTrans(fromconn, fromtid, &rcode);
2102 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
2106 /* delete source volume */
2107 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2111 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2117 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2119 AFSVolSetFlags(fromconn, fromtid,
2120 VTDeleteOnSalvage | VTOutOfService);
2123 if (atoserver != afromserver) {
2124 VPRINT("Recovery: Setting volume forwarding pointer ...");
2125 AFSVolSetForwarding(fromconn, fromtid, atoserver);
2129 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
2130 AFSVolDeleteVolume(fromconn, fromtid);
2134 ("Recovery: Ending transaction on source volume %u ...",
2136 AFSVolEndTrans(fromconn, fromtid, &rcode);
2140 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2146 /* common cleanup - delete local clone */
2148 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2152 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
2158 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
2159 AFSVolDeleteVolume(fromconn, clonetid);
2162 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2164 AFSVolEndTrans(fromconn, clonetid, &rcode);
2168 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2173 /* unlock VLDB entry */
2175 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2177 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2178 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2182 done: /* routine cleanup */
2185 #ifdef ENABLE_BUGFIX_1165
2190 rx_DestroyConnection(fromconn);
2192 rx_DestroyConnection(toconn);
2195 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2203 UV_MoveVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2204 afs_int32 atoserver, afs_int32 atopart)
2206 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2207 atoserver, atopart, 0);
2211 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2212 * <atopart>. The new volume is named by <atovolname>. The new volume
2213 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2214 * from the VLDB. the following flags are supported:
2216 * RV_RDONLY - target volume is RO
2217 * RV_OFFLINE - leave target volume offline
2218 * RV_CPINCR - do incremental dump if target exists
2219 * RV_NOVLDB - don't create/update VLDB entry
2220 * RV_NOCLONE - don't use a copy clone
2223 UV_CopyVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2224 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2225 afs_uint32 atovolid, int flags)
2227 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2228 * be changing during the copy */
2230 afs_int32 volatile clonetid;
2231 afs_int32 volatile totid;
2232 afs_int32 volatile fromtid;
2233 struct rx_connection * volatile fromconn;
2234 struct rx_connection * volatile toconn;
2235 afs_uint32 volatile cloneVol;
2239 afs_int32 fromDate, cloneFromDate;
2240 struct restoreCookie cookie;
2241 register afs_int32 vcode, code;
2244 struct volser_status tstatus;
2245 struct destServer destination;
2246 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 /* check if we can shortcut and use a local clone instead of a full copy */
2281 if (afromserver == atoserver && afrompart == atopart) {
2286 * clone the read/write volume locally.
2290 if (!(flags & RV_NOCLONE)) {
2291 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2293 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2296 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2300 /* Get a clone id */
2301 VPRINT1("Allocating new volume id for clone of volume %u ...",
2305 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2307 EGOTO1(mfail, vcode,
2308 "Could not get an ID for the clone of volume %u from the VLDB\n",
2316 /* Get a new volume id */
2317 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2319 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2320 EGOTO1(mfail, vcode,
2321 "Could not get an ID for the copy of volume %u from the VLDB\n",
2326 if (!(flags & RV_NOCLONE)) {
2327 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2328 VPRINT1("Cloning source volume %u ...", afromvol);
2329 strcpy(vname, "copy-clone-temp");
2332 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2335 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2339 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2341 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2346 "Failed to end the transaction on the source volume %u\n",
2352 * Create the destination volume
2355 if (!(flags & RV_NOCLONE)) {
2356 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2359 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2363 "Failed to start a transaction on the cloned volume%u\n",
2367 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2369 AFSVolSetFlags(fromconn, clonetid,
2370 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2371 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2375 /* remember time from which we've dumped the volume */
2376 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2377 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2379 "Failed to get the status of the cloned volume %u\n",
2383 fromDate = CLOCKADJ(tstatus.creationDate);
2388 /* create a volume on the target machine */
2391 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2394 if ((flags & RV_CPINCR)) {
2395 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2396 code = AFSVolGetStatus(toconn, totid, &tstatus);
2398 "Failed to get the status of the pre-existing volume %u\n",
2402 /* Using the update date should be OK here, but add some fudge */
2403 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2404 if ((flags & RV_NOCLONE))
2405 fromDate = cloneFromDate;
2407 /* XXX We should check that the source volume's creationDate is
2408 * XXX not newer than the existing target volume, and if not,
2409 * XXX throw away the existing target and do a full dump. */
2414 /* Delete the existing volume.
2415 * While we are deleting the volume in these steps, the transaction
2416 * we started against the cloned volume (clonetid above) will be
2417 * sitting idle. It will get cleaned up after 600 seconds
2419 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2420 code = AFSVolDeleteVolume(toconn, totid);
2422 "Could not delete the pre-existing volume %u on destination\n",
2427 ("Ending transaction on pre-existing volume %u on destination ...",
2429 code = AFSVolEndTrans(toconn, totid, &rcode);
2434 "Could not end the transaction on pre-existing volume %u on destination\n",
2439 VPRINT1("Creating the destination volume %u ...", newVol);
2442 AFSVolCreateVolume(toconn, atopart, atovolname,
2443 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2444 newVol, &newVol, &tmp);
2446 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2450 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2452 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2454 "Failed to set the flags on the destination volume %u\n", newVol);
2459 destination.destHost = ntohl(atoserver);
2460 destination.destPort = AFSCONF_VOLUMEPORT;
2461 destination.destSSID = 1;
2463 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2464 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2469 * Now dump the clone to the new volume
2472 if (!(flags & RV_NOCLONE)) {
2473 /* XXX probably should have some code here that checks to see if
2474 * XXX we are copying to same server and partition - if so, just
2475 * XXX use a clone to save disk space */
2477 /* Copy the clone to the new volume */
2478 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2481 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2483 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2487 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2488 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2493 "Failed to end the transaction on the cloned volume %u\n",
2499 * reattach to the main-line volume, and incrementally dump it.
2502 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2504 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2507 "Failed to create a transaction on the source volume %u\n",
2511 /* now do the incremental */
2513 ("Doing the%s dump from source to destination for volume %u ... ",
2514 (flags & RV_NOCLONE) ? "" : " incremental",
2517 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2520 "Failed to do the%s dump from old site to new site\n",
2521 (flags & RV_NOCLONE) ? "" : " incremental");
2524 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2525 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2526 code = AFSVolSetFlags(toconn, totid, volflag);
2528 "Failed to set the flags to make destination volume online\n");
2531 /* put new volume online */
2532 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2533 code = AFSVolEndTrans(toconn, totid, &rcode);
2538 "Failed to end the transaction on the destination volume %u\n",
2542 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2543 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2548 "Failed to end the transaction on the source volume %u\n",
2554 if (!(flags & RV_NOCLONE)) {
2555 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2558 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2562 "Failed to start a transaction on the cloned volume%u\n",
2566 /* now delete the clone */
2567 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2568 code = AFSVolDeleteVolume(fromconn, clonetid);
2569 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2573 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2574 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2579 "Failed to end the transaction on the cloned volume %u\n",
2584 if (!(flags & RV_NOVLDB)) {
2585 /* create the vldb entry for the copied volume */
2586 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2587 newentry.nServers = 1;
2588 newentry.serverNumber[0] = atoserver;
2589 newentry.serverPartition[0] = atopart;
2590 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2591 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2592 newentry.volumeId[RWVOL] = newVol;
2593 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2594 newentry.volumeId[BACKVOL] = 0;
2595 newentry.cloneId = 0;
2596 /*map into right byte order, before passing to xdr, the stuff has to be in host
2597 * byte order. Xdr converts it into network order */
2598 MapNetworkToHost(&newentry, &storeEntry);
2599 /* create the vldb entry */
2600 vcode = VLDB_CreateEntry(&storeEntry);
2603 "Could not create a VLDB entry for the volume %s %lu\n",
2604 atovolname, (unsigned long)newVol);
2605 /*destroy the created volume */
2606 VPRINT1("Deleting the newly created volume %u\n", newVol);
2607 AFSVolDeleteVolume(toconn, totid);
2611 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2615 /* normal cleanup code */
2618 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2620 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2621 if (code || rcode) {
2624 "Could not end transaction on the source volume %lu\n",
2625 (unsigned long)afromvol);
2627 error = (code ? code : rcode);
2633 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2635 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2636 if (code || rcode) {
2639 "Could not end transaction on the source's clone volume %lu\n",
2640 (unsigned long)cloneVol);
2642 error = (code ? code : rcode);
2648 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2650 code = AFSVolEndTrans(toconn, totid, &rcode);
2654 "Could not end transaction on destination volume %lu\n",
2655 (unsigned long)newVol);
2657 error = (code ? code : rcode);
2662 rx_DestroyConnection(fromconn);
2664 rx_DestroyConnection(toconn);
2665 PrintError("", error);
2668 /* come here only when the sky falls */
2673 "vos copy: operation interrupted, cleanup in progress...\n");
2674 fprintf(STDOUT, "clear transaction contexts\n");
2679 VPRINT("Recovery: Ending transaction on clone volume ...");
2680 AFSVolEndTrans(fromconn, clonetid, &rcode);
2684 VPRINT("Recovery: Ending transaction on destination volume ...");
2685 AFSVolEndTrans(toconn, totid, &rcode);
2688 if (fromtid) { /* put it on-line */
2689 VPRINT("Recovery: Ending transaction on source volume ...");
2690 AFSVolEndTrans(fromconn, fromtid, &rcode);
2694 VPRINT("Recovery: Accessing VLDB.\n");
2695 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2697 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2701 MapHostToNetwork(&entry);
2703 /* common cleanup - delete local clone */
2705 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2709 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2715 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2716 AFSVolDeleteVolume(fromconn, clonetid);
2719 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2721 AFSVolEndTrans(fromconn, clonetid, &rcode);
2725 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2730 done: /* routine cleanup */
2732 rx_DestroyConnection(fromconn);
2734 rx_DestroyConnection(toconn);
2737 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2745 UV_CopyVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2746 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2748 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2749 atovolname, atoserver, atopart, 0, 0);
2754 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2755 * if one already exists, update it
2759 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
2761 struct rx_connection *aconn = (struct rx_connection *)0;
2762 afs_int32 ttid = 0, btid = 0;
2763 afs_uint32 backupID;
2764 afs_int32 code = 0, rcode = 0;
2765 char vname[VOLSER_MAXVOLNAME + 1];
2766 struct nvldbentry entry, storeEntry;
2767 afs_int32 error = 0;
2768 int vldblocked = 0, vldbmod = 0, backexists = 1;
2770 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2772 /* the calls to VLDB will succeed only if avolid is a RW volume,
2773 * since we are following the RW hash chain for searching */
2774 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2777 "Could not fetch the entry for the volume %lu from the VLDB \n",
2778 (unsigned long)avolid);
2782 MapHostToNetwork(&entry);
2784 /* These operations require the VLDB be locked since it means the VLDB
2785 * will change or the vldb is already locked.
2787 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2788 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2789 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2791 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2794 "Could not lock the VLDB entry for the volume %lu\n",
2795 (unsigned long)avolid);
2801 /* Reread the vldb entry */
2802 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2805 "Could not fetch the entry for the volume %lu from the VLDB \n",
2806 (unsigned long)avolid);
2810 MapHostToNetwork(&entry);
2813 if (!ISNAMEVALID(entry.name)) {
2814 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2816 error = VOLSERBADNAME;
2820 backupID = entry.volumeId[BACKVOL];
2821 if (backupID == INVALID_BID) {
2822 /* Get a backup volume id from the VLDB and update the vldb
2825 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2828 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2829 (unsigned long)avolid);
2833 entry.volumeId[BACKVOL] = backupID;
2837 /* Test to see if the backup volume exists by trying to create
2838 * a transaction on the backup volume. We've assumed the backup exists.
2840 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2842 if (code != VNOVOL) {
2843 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2844 (unsigned long)backupID);
2848 backexists = 0; /* backup volume does not exist */
2851 code = AFSVolEndTrans(aconn, btid, &rcode);
2853 if (code || rcode) {
2855 "Could not end transaction on the previous backup volume %lu\n",
2856 (unsigned long)backupID);
2857 error = (code ? code : rcode);
2862 /* Now go ahead and try to clone the RW volume.
2863 * First start a transaction on the RW volume
2865 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
2867 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2868 (unsigned long)avolid);
2873 /* Clone or reclone the volume, depending on whether the backup
2874 * volume exists or not
2877 VPRINT1("Re-cloning backup volume %u ...", backupID);
2879 code = AFSVolReClone(aconn, ttid, backupID);
2881 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2882 (unsigned long)backupID);
2887 VPRINT1("Creating a new backup clone %u ...", backupID);
2889 strcpy(vname, entry.name);
2890 strcat(vname, ".backup");
2892 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2894 fprintf(STDERR, "Failed to clone the volume %lu\n",
2895 (unsigned long)avolid);
2901 /* End the transaction on the RW volume */
2902 code = AFSVolEndTrans(aconn, ttid, &rcode);
2904 if (code || rcode) {
2906 "Failed to end the transaction on the rw volume %lu\n",
2907 (unsigned long)avolid);
2908 error = (code ? code : rcode);
2912 /* Mork vldb as backup exists */
2913 if (!(entry.flags & BACK_EXISTS)) {
2914 entry.flags |= BACK_EXISTS;
2918 /* Now go back to the backup volume and bring it on line */
2919 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2922 "Failed to start a transaction on the backup volume %lu\n",
2923 (unsigned long)backupID);
2928 code = AFSVolSetFlags(aconn, btid, 0);
2930 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2931 (unsigned long)backupID);
2936 code = AFSVolEndTrans(aconn, btid, &rcode);
2938 if (code || rcode) {
2940 "Failed to end the transaction on the backup volume %lu\n",
2941 (unsigned long)backupID);
2942 error = (code ? code : rcode);
2948 /* Will update the vldb below */
2952 code = AFSVolEndTrans(aconn, ttid, &rcode);
2953 if (code || rcode) {
2954 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2955 (unsigned long)avolid);
2957 error = (code ? code : rcode);
2962 code = AFSVolEndTrans(aconn, btid, &rcode);
2963 if (code || rcode) {
2965 "Could not end transaction the backup volume %lu\n",
2966 (unsigned long)backupID);
2968 error = (code ? code : rcode);
2972 /* Now update the vldb - if modified */
2975 MapNetworkToHost(&entry, &storeEntry);
2977 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2978 (LOCKREL_OPCODE | LOCKREL_AFSID |
2979 LOCKREL_TIMESTAMP));
2982 "Could not update the VLDB entry for the volume %lu \n",
2983 (unsigned long)avolid);
2989 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2990 (LOCKREL_OPCODE | LOCKREL_AFSID |
2991 LOCKREL_TIMESTAMP));
2994 "Could not unlock the VLDB entry for the volume %lu \n",
2995 (unsigned long)avolid);
3003 rx_DestroyConnection(aconn);
3005 PrintError("", error);
3009 /* Make a new clone of volume <avolid> on <aserver> and <apart>
3010 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
3011 * The new volume is named by <aname>, or by appending ".clone" to
3012 * the existing name if <aname> is NULL. The following flags are
3015 * RV_RDONLY - target volume is RO
3016 * RV_OFFLINE - leave target volume offline
3020 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid,
3021 afs_uint32 acloneid, char *aname, int flags)
3023 struct rx_connection *aconn = (struct rx_connection *)0;
3024 afs_int32 ttid = 0, btid = 0;
3025 afs_int32 code = 0, rcode = 0;
3026 char vname[VOLSER_MAXVOLNAME + 1];
3027 afs_int32 error = 0;
3029 volEntries volumeInfo;
3031 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
3034 volumeInfo.volEntries_val = (volintInfo *) 0;
3035 volumeInfo.volEntries_len = 0;
3036 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
3038 fprintf(stderr, "Could not get info for volume %lu\n",
3039 (unsigned long)avolid);
3043 strncpy(vname, volumeInfo.volEntries_val[0].name,
3044 VOLSER_OLDMAXVOLNAME - 7);
3045 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
3046 strcat(vname, ".clone");
3048 if (volumeInfo.volEntries_val)
3049 free(volumeInfo.volEntries_val);
3053 /* Get a clone id */
3054 VPRINT1("Allocating new volume id for clone of volume %u ...",
3056 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
3058 "Could not get an ID for the clone of volume %u from the VLDB\n",
3063 /* Test to see if the clone volume exists by trying to create
3064 * a transaction on the clone volume. We've assumed the clone exists.
3066 /* XXX I wonder what happens if the clone has some other parent... */
3067 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3069 if (code != VNOVOL) {
3070 fprintf(STDERR, "Could not reach the clone volume %lu\n",
3071 (unsigned long)acloneid);
3075 backexists = 0; /* backup volume does not exist */
3078 code = AFSVolEndTrans(aconn, btid, &rcode);
3080 if (code || rcode) {
3082 "Could not end transaction on the previous clone volume %lu\n",
3083 (unsigned long)acloneid);
3084 error = (code ? code : rcode);
3089 /* Now go ahead and try to clone the RW volume.
3090 * First start a transaction on the RW volume
3092 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
3094 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
3095 (unsigned long)avolid);
3100 /* Clone or reclone the volume, depending on whether the backup
3101 * volume exists or not
3104 VPRINT1("Re-cloning clone volume %u ...", acloneid);
3106 code = AFSVolReClone(aconn, ttid, acloneid);
3108 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
3109 (unsigned long)acloneid);
3114 VPRINT1("Creating a new clone %u ...", acloneid);
3116 code = AFSVolClone(aconn, ttid, 0,
3117 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
3120 fprintf(STDERR, "Failed to clone the volume %lu\n",
3121 (unsigned long)avolid);
3127 /* End the transaction on the RW volume */
3128 code = AFSVolEndTrans(aconn, ttid, &rcode);
3130 if (code || rcode) {
3132 "Failed to end the transaction on the rw volume %lu\n",
3133 (unsigned long)avolid);
3134 error = (code ? code : rcode);
3138 /* Now go back to the backup volume and bring it on line */
3139 if (!(flags & RV_OFFLINE)) {
3140 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3143 "Failed to start a transaction on the clone volume %lu\n",
3144 (unsigned long)acloneid);
3149 code = AFSVolSetFlags(aconn, btid, 0);
3151 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3152 (unsigned long)acloneid);
3157 code = AFSVolEndTrans(aconn, btid, &rcode);
3159 if (code || rcode) {
3161 "Failed to end the transaction on the clone volume %lu\n",
3162 (unsigned long)acloneid);
3163 error = (code ? code : rcode);
3172 code = AFSVolEndTrans(aconn, ttid, &rcode);
3173 if (code || rcode) {
3174 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3175 (unsigned long)avolid);
3177 error = (code ? code : rcode);
3182 code = AFSVolEndTrans(aconn, btid, &rcode);
3183 if (code || rcode) {
3185 "Could not end transaction on the clone volume %lu\n",
3186 (unsigned long)acloneid);
3188 error = (code ? code : rcode);
3193 rx_DestroyConnection(aconn);
3195 PrintError("", error);
3200 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
3203 afs_int32 acode, ccode, rcode, tid;
3204 ccode = rcode = tid = 0;
3206 acode = AFSVolTransCreate_retry(conn, vid, part, flags, &tid);
3207 if (!acode) { /* It really was there */
3208 acode = AFSVolDeleteVolume(conn, tid);
3210 fprintf(STDERR, "Failed to delete volume %lu.\n",
3211 (unsigned long)vid);
3212 PrintError("", acode);
3214 ccode = AFSVolEndTrans(conn, tid, &rcode);
3218 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3219 (unsigned long)vid);
3220 PrintError("", ccode);
3227 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3228 #define ONERROR0(ec, es) if (ec) { fprintf(STDERR, (es)); error = (ec); goto rfail; }
3229 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3231 /* Get a "transaction" on this replica. Create the volume
3232 * if necessary. Return the time from which a dump should
3233 * be made (0 if it's a new volume)
3236 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3237 struct rx_connection **connPtr, afs_int32 * transPtr,
3238 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr)
3241 struct volser_status tstatus;
3246 *connPtr = (struct rx_connection *)0;
3251 /* get connection to the replication site */
3252 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3254 goto fail; /* server is down */
3256 volid = vldbEntryPtr->volumeId[ROVOL];
3259 AFSVolTransCreate_retry(*connPtr, volid,
3260 vldbEntryPtr->serverPartition[index], ITOffline,
3263 /* If the volume does not exist, create it */
3264 if (!volid || code) {
3268 if (volid && (code != VNOVOL)) {
3269 PrintError("Failed to start a transaction on the RO volume.\n",
3274 strcpy(volname, vldbEntryPtr->name);
3275 strcat(volname, ".readonly");
3279 "Creating new volume %lu on replication site %s: ",
3280 (unsigned long)volid,
3281 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3282 serverNumber[index], hoststr) :
3283 hostutil_GetNameByINet(vldbEntryPtr->
3284 serverNumber[index]));
3289 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3291 vldbEntryPtr->volumeId[RWVOL], &volid,
3294 PrintError("Failed to create the ro volume: ", code);
3297 vldbEntryPtr->volumeId[ROVOL] = volid;
3301 /* The following is a bit redundant, since create sets these flags by default */
3303 AFSVolSetFlags(*connPtr, *transPtr,
3304 VTDeleteOnSalvage | VTOutOfService);
3306 PrintError("Failed to set flags on the ro volume: ", code);
3311 /* Otherwise, the transaction did succeed, so get the creation date of the
3312 * latest RO volume on the replication site
3315 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3316 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3317 serverNumber[index], hoststr) :
3318 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3320 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3322 PrintError("Failed to get status of volume on destination: ",
3326 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3327 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3334 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3339 PrintError("Could not end transaction on a ro volume: ", tcode);
3346 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3347 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3348 void *cookie, manyResults * results)
3352 for (i = 0; i < tr->manyDests_len; i++) {
3353 results->manyResults_val[i] =
3354 AFSVolForward(fromconn, fromtid, fromdate,
3355 &(tr->manyDests_val[i].server),
3356 tr->manyDests_val[i].trans, cookie);
3362 /* UV_ReleaseVolume()
3363 * Release volume <afromvol> on <afromserver> <afrompart> to all
3364 * its RO sites (full release). Unless the previous release was
3365 * incomplete: in which case we bring the remaining incomplete
3366 * volumes up to date with the volumes that were released
3368 * forceflag: Performs a full release.
3370 * Will create a clone from the RW, then dump the clone out to
3371 * the remaining replicas. If there is more than 1 RO sites,
3372 * ensure that the VLDB says at least one RO is available all
3373 * the time: Influences when we write back the VLDB entry.
3377 UV_ReleaseVolume(afs_uint32 afromvol, afs_int32 afromserver,
3378 afs_int32 afrompart, int forceflag)
3382 afs_int32 vcode, rcode, tcode;
3383 afs_uint32 cloneVolId, roVolId;
3384 struct replica *replicas = 0;
3385 struct nvldbentry entry, storeEntry;
3386 int i, volcount, m, fullrelease, vldbindex;
3388 struct restoreCookie cookie;
3389 struct rx_connection **toconns = 0;
3390 struct release *times = 0;
3392 struct rx_connection *fromconn = (struct rx_connection *)0;
3393 afs_int32 error = 0;
3395 afs_int32 clonetid = 0, onlinetid;
3396 afs_int32 fromtid = 0;
3397 afs_uint32 fromdate = 0;
3398 afs_uint32 thisdate;
3402 manyResults results;
3403 int rwindex, roindex, roclone, roexists;
3404 afs_uint32 rwcrdate = 0;
3405 afs_uint32 rwupdate, clcrdate;
3409 } remembertime[NMAXNSERVERS];
3410 int releasecount = 0;
3411 struct volser_status volstatus;
3414 memset(remembertime, 0, sizeof(remembertime));
3415 memset(&results, 0, sizeof(results));
3417 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3418 if (vcode != VL_RERELEASE)
3419 ONERROR(vcode, afromvol,
3420 "Could not lock the VLDB entry for the volume %u.\n");
3423 /* Get the vldb entry in readable format */
3424 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3425 ONERROR(vcode, afromvol,
3426 "Could not fetch the entry for the volume %u from the VLDB.\n");
3427 MapHostToNetwork(&entry);
3430 EnumerateEntry(&entry);
3432 if (!ISNAMEVALID(entry.name))
3433 ONERROR(VOLSERBADOP, entry.name,
3434 "Volume name %s is too long, rename before releasing.\n");
3435 if (entry.volumeId[RWVOL] != afromvol)
3436 ONERROR(VOLSERBADOP, afromvol,
3437 "The volume %u being released is not a read-write volume.\n");
3438 if (entry.nServers <= 1)
3439 ONERROR(VOLSERBADOP, afromvol,
3440 "Volume %u has no replicas - release operation is meaningless!\n");
3441 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3442 ONERROR(VOLSERBADOP, entry.name,
3443 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3445 /* roclone is true if one of the RO volumes is on the same
3446 * partition as the RW volume. In this case, we make the RO volume
3447 * on the same partition a clone instead of a complete copy.
3450 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3451 roclone = ((roindex == -1) ? 0 : 1);
3452 rwindex = Lp_GetRwIndex(&entry);
3454 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3456 /* Make sure we have a RO volume id to work with */
3457 if (entry.volumeId[ROVOL] == INVALID_BID) {
3458 /* need to get a new RO volume id */
3459 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3460 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3462 entry.volumeId[ROVOL] = roVolId;
3463 MapNetworkToHost(&entry, &storeEntry);
3464 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3465 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3468 /* Will we be completing a previously unfinished release. -force overrides */
3469 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3470 if (entry.serverFlags[i] & ITSROVOL) {
3472 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3475 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3478 /* Determine which volume id to use and see if it exists */
3481 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3482 code = VolumeExists(afromserver, afrompart, cloneVolId);
3483 roexists = ((code == ENODEV) ? 0 : 1);
3485 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3487 ONERROR(-1, afromserver,
3488 "Cannot establish connection with server 0x%x\n");
3492 fullrelease = 1; /* Do a full release if RO clone does not exist */
3494 /* Begin transaction on RW and mark it busy while we query it */
3495 code = AFSVolTransCreate_retry(
3496 fromconn, afromvol, afrompart, ITBusy, &fromtid
3498 ONERROR(code, afromvol,
3499 "Failed to start transaction on RW volume %u\n");
3501 /* Query the creation date for the RW */
3502 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3503 ONERROR(code, afromvol,
3504 "Failed to get the status of RW volume %u\n");
3505 rwcrdate = volstatus.creationDate;
3506 rwupdate = volstatus.updateDate;
3508 /* End transaction on RW */
3509 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3511 ONERROR((code ? code : rcode), afromvol,
3512 "Failed to end transaction on RW volume %u\n");
3514 /* Begin transaction on clone and mark it busy while we query it */
3515 code = AFSVolTransCreate_retry(
3516 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3518 ONERROR(code, cloneVolId,
3519 "Failed to start transaction on RW clone %u\n");
3521 /* Query the creation date for the clone */
3522 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3523 ONERROR(code, cloneVolId,
3524 "Failed to get the status of RW clone %u\n");
3525 clcrdate = volstatus.creationDate;
3527 /* End transaction on clone */
3528 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3530 ONERROR((code ? code : rcode), cloneVolId,
3531 "Failed to end transaction on RW clone %u\n");
3533 if (rwcrdate > clcrdate)
3534 fullrelease = 2;/* Do a full release if RO clone older than RW */
3539 switch (fullrelease) {
3541 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3542 (unsigned long)afromvol);
3545 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3546 (unsigned long)afromvol);
3549 fprintf(STDOUT, "This is a completion of a previous release\n");
3555 /* If the RO clone exists, then if the clone is a temporary
3556 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3557 * (it was recently added), then also delete it. We do not
3558 * want to "reclone" a temporary RO clone.
3561 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3562 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3563 if (code && (code != VNOVOL))
3568 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3569 * write this entry out to the vlserver until after the first
3570 * RO volume is released (temp RO clones don't count).
3572 for (i = 0; i < entry.nServers; i++) {
3573 entry.serverFlags[i] &= ~NEW_REPSITE;
3574 entry.serverFlags[i] |= RO_DONTUSE;
3576 entry.serverFlags[rwindex] |= NEW_REPSITE;
3577 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3579 /* Begin transaction on RW and mark it busy while we clone it */
3581 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
3583 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3585 /* Clone or reclone the volume */
3587 VPRINT1("Recloning RW volume %u...", cloneVolId);
3588 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3589 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3593 strcpy(vname, entry.name);
3594 strcat(vname, ".readonly");
3595 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3597 strcpy(vname, "readonly-clone-temp");
3598 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3601 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3603 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3607 /* Get the time the RW was created for future information */
3608 VPRINT1("Getting status of RW volume %u...", afromvol);
3609 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3610 ONERROR(code, afromvol,
3611 "Failed to get the status of the RW volume %u\n");
3613 rwcrdate = volstatus.creationDate;
3614 rwupdate = volstatus.updateDate;
3616 /* End the transaction on the RW volume */
3617 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3618 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3620 ONERROR((code ? code : rcode), afromvol,
3621 "Failed to end cloning transaction on RW %u\n");
3624 /* Remember clone volume ID in case we fail or are interrupted */
3625 entry.cloneId = cloneVolId;
3628 /* Bring the RO clone online - though not if it's a temporary clone */
3629 VPRINT1("Starting transaction on RO clone volume %u...",
3632 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3634 ONERROR(code, cloneVolId,
3635 "Failed to start transaction on volume %u\n");
3638 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3639 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3642 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3643 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3644 ONERROR((code ? code : rcode), cloneVolId,
3645 "Failed to end transaction on RO clone %u\n");
3648 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3650 /* Sleep so that a client searching for an online volume won't
3651 * find the clone offline and then the next RO offline while the
3652 * release brings the clone online and the next RO offline (race).
3653 * There is a fix in the 3.4 client that does not need this sleep
3654 * anymore, but we don't know what clients we have.
3656 if (entry.nServers > 2)
3659 /* Mark the RO clone in the VLDB as a good site (already released) */
3660 entry.serverFlags[roindex] |= NEW_REPSITE;
3661 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3662 entry.flags |= RO_EXISTS;
3666 /* Write out the VLDB entry only if the clone is not a temporary
3667 * clone. If we did this to a temporary clone then we would end
3668 * up marking all the ROs as "old release" making the ROs
3669 * temporarily unavailable.
3671 MapNetworkToHost(&entry, &storeEntry);
3672 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3673 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3674 ONERROR(vcode, entry.name,
3675 "Could not update vldb entry for %s.\n");
3680 /* Now we will release from the clone to the remaining RO replicas.
3681 * The first 2 ROs (counting the non-temporary RO clone) are released
3682 * individually: releasecount. This is to reduce the race condition
3683 * of clients trying to find an on-line RO volume. The remaining ROs
3684 * are released in parallel but no more than half the number of ROs
3685 * (rounded up) at a time: nservers.
3688 strcpy(vname, entry.name);
3689 strcat(vname, ".readonly");
3690 memset(&cookie, 0, sizeof(cookie));
3691 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3692 cookie.type = ROVOL;
3693 cookie.parent = entry.volumeId[RWVOL];
3696 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3698 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3699 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3701 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3703 results.manyResults_val =
3704 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3705 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3707 "Failed to create transaction on the release clone\n");
3709 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3710 memset(times, 0, (sizeof(struct release) * nservers + 1));
3711 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3712 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3714 /* Create a transaction on the cloned volume */
3715 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3717 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3718 if (!fullrelease && code)
3719 ONERROR(VOLSERNOVOL, afromvol,
3720 "Old clone is inaccessible. Try vos release -f %u.\n");
3721 ONERROR0(code, "Failed to create transaction on the release clone\n");
3724 /* For each index in the VLDB */
3725 for (vldbindex = 0; vldbindex < entry.nServers;) {
3727 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3729 ((volcount < nservers) && (vldbindex < entry.nServers));
3731 /* The first two RO volumes will be released individually.
3732 * The rest are then released in parallel. This is a hack
3733 * for clients not recognizing right away when a RO volume
3734 * comes back on-line.
3736 if ((volcount == 1) && (releasecount < 2))
3739 if (vldbindex == roindex)
3740 continue; /* the clone */
3741 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3742 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3744 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3745 continue; /* not a RO vol */
3748 /* Get a Transaction on this replica. Get a new connection if
3749 * necessary. Create the volume if necessary. Return the
3750 * time from which the dump should be made (0 if it's a new
3751 * volume). Each volume might have a different time.
3753 replicas[volcount].server.destHost =
3754 ntohl(entry.serverNumber[vldbindex]);
3755 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3756 replicas[volcount].server.destSSID = 1;
3757 times[volcount].vldbEntryIndex = vldbindex;
3760 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3761 &(replicas[volcount].trans),
3762 &(times[volcount].crtime),
3763 &(times[volcount].uptime));
3767 /* Thisdate is the date from which we want to pick up all changes */
3768 if (forceflag || !fullrelease
3769 || (rwcrdate > times[volcount].crtime)) {
3770 /* If the forceflag is set, then we want to do a full dump.
3771 * If it's not a full release, we can't be sure that the creation
3772 * date is good (so we also do a full dump).
3773 * If the RW volume was replaced (its creation date is newer than
3774 * the last release), then we can't be sure what has changed (so
3775 * we do a full dump).
3778 } else if (remembertime[vldbindex].validtime) {
3779 /* Trans was prev ended. Use the time from the prev trans
3780 * because, prev trans may have created the volume. In which
3781 * case time[volcount].time would be now instead of 0.
3784 (remembertime[vldbindex].uptime < times[volcount].uptime)
3785 ? remembertime[vldbindex].uptime
3786 : times[volcount].uptime;
3788 thisdate = times[volcount].uptime;
3790 remembertime[vldbindex].validtime = 1;
3791 remembertime[vldbindex].uptime = thisdate;
3793 if (volcount == 0) {
3794 fromdate = thisdate;
3796 /* Include this volume if it is within 15 minutes of the earliest */
3798 thisdate) ? (fromdate - thisdate) : (thisdate -
3800 AFSVolEndTrans(toconns[volcount],
3801 replicas[volcount].trans, &rcode);
3802 replicas[volcount].trans = 0;
3805 if (thisdate < fromdate)
3806 fromdate = thisdate;
3814 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3815 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3816 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3817 vldbEntryIndex], hoststr) :
3818 hostutil_GetNameByINet(entry.
3819 serverNumber[times[0].
3822 for (s = 1; s < volcount; s++) {
3823 fprintf(STDOUT, " and %s",
3824 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3825 vldbEntryIndex], hoststr) :
3826 hostutil_GetNameByINet(entry.
3827 serverNumber[times[s].
3832 fprintf(STDOUT, " (full release)");
3835 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3837 fprintf(STDOUT, ".\n");
3841 /* Release the ones we have collected */
3842 tr.manyDests_val = &(replicas[0]);
3843 tr.manyDests_len = results.manyResults_len = volcount;
3845 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3846 0 /*spare */ , &cookie, &results);
3847 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3849 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3850 0 /*spare */ , &cookie, &results);
3855 PrintError("Release failed: ", code);
3857 for (m = 0; m < volcount; m++) {
3858 if (results.manyResults_val[m]) {
3859 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3860 /* we retry timed out transaction. When it is
3861 * not the first volume and the transaction wasn't found
3862 * (assume it timed out and was garbage collected by volser).
3865 ("Failed to dump volume from clone to a ro site: ",
3866 results.manyResults_val[m]);
3872 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3873 ROVOL, entry.volumeId[RWVOL], 0, 0);
3875 if ((m == 0) || (code != ENOENT)) {
3876 PrintError("Failed to set correct names and ids: ",
3882 /* have to clear dest. flags to ensure new vol goes online:
3883 * because the restore (forwarded) operation copied
3884 * the V_inService(=0) flag over to the destination.
3886 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3888 if ((m == 0) || (code != ENOENT)) {
3889 PrintError("Failed to set flags on ro volume: ",
3895 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3896 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3897 entry.flags |= RO_EXISTS;
3902 /* End the transactions and destroy the connections */
3903 for (s = 0; s < volcount; s++) {
3904 if (replicas[s].trans)
3905 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3906 replicas[s].trans = 0;
3910 if ((s == 0) || (code != ENOENT)) {
3911 PrintError("Could not end transaction on a ro volume: ",
3915 ("Transaction timed out on a ro volume. Will retry.\n",
3917 if (times[s].vldbEntryIndex < vldbindex)
3918 vldbindex = times[s].vldbEntryIndex;
3923 rx_DestroyConnection(toconns[s]);
3927 MapNetworkToHost(&entry, &storeEntry);
3928 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3929 ONERROR(vcode, afromvol,
3930 " Could not update VLDB entry for volume %u\n");
3931 } /* for each index in the vldb */
3933 /* End the transaction on the cloned volume */
3934 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3939 PrintError("Failed to end transaction on rw volume: ", code);
3941 /* Figure out if any volume were not released and say so */
3942 for (failure = 0, i = 0; i < entry.nServers; i++) {
3943 if (!(entry.serverFlags[i] & NEW_REPSITE))
3949 "The volume %lu could not be released to the following %d sites:\n",
3950 (unsigned long)afromvol, failure);
3951 for (i = 0; i < entry.nServers; i++) {
3952 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3953 MapPartIdIntoName(entry.serverPartition[i], pname);
3954 fprintf(STDERR, "\t%35s %s\n",
3955 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
3956 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3960 MapNetworkToHost(&entry, &storeEntry);
3962 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3964 ONERROR(vcode, afromvol,
3965 " Could not update VLDB entry for volume %u\n");
3967 ERROREXIT(VOLSERBADRELEASE);
3970 /* All the ROs were release successfully. Remove the temporary clone */
3973 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3974 (unsigned long)cloneVolId);
3977 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3978 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3983 for (i = 0; i < entry.nServers; i++)
3984 entry.serverFlags[i] &= ~NEW_REPSITE;
3986 /* Update the VLDB */
3987 VPRINT("updating VLDB ...");
3989 MapNetworkToHost(&entry, &storeEntry);
3991 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3992 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3993 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3998 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4002 "Failed to end cloning transaction on the RW volume %lu\n",
4003 (unsigned long)afromvol);
4009 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4013 "Failed to end transaction on the release clone %lu\n",
4014 (unsigned long)cloneVolId);
4019 for (i = 0; i < nservers; i++) {
4020 if (replicas && replicas[i].trans) {
4021 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4022 replicas[i].trans = 0;
4025 "Failed to end transaction on ro volume %u at server %s\n",
4026 entry.volumeId[ROVOL],
4027 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4028 destHost), hoststr) :
4029 hostutil_GetNameByINet(htonl
4030 (replicas[i].server.destHost)));
4035 if (toconns && toconns[i]) {
4036 rx_DestroyConnection(toconns[i]);
4042 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4043 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4046 "Could not release lock on the VLDB entry for volume %lu\n",
4047 (unsigned long)afromvol);
4053 PrintError("", error);
4056 rx_DestroyConnection(fromconn);
4057 if (results.manyResults_val)
4058 free(results.manyResults_val);
4070 dump_sig_handler(int x)
4072 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4076 /* Dump the volume <afromvol> on <afromserver> and
4077 * <afrompart> to <afilename> starting from <fromdate>.
4078 * DumpFunction does the real work behind the scenes after
4079 * extracting parameters from the rock
4082 UV_DumpVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
4084 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4087 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4088 * be changing during the dump */
4089 struct rx_call * volatile fromcall = NULL;
4090 struct rx_connection * volatile fromconn = NULL;
4091 afs_int32 volatile fromtid = 0;
4093 afs_int32 rxError = 0, rcode = 0;
4094 afs_int32 code, error = 0;
4096 time_t tmv = fromdate;
4100 #ifndef AFS_NT40_ENV
4101 (void)signal(SIGPIPE, dump_sig_handler);
4103 (void)signal(SIGINT, dump_sig_handler);
4106 VEPRINT("Full Dump ...\n");
4108 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4112 /* get connections to the servers */
4113 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4115 VEPRINT1("Starting transaction on volume %u...", afromvol);
4117 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4119 EGOTO1(error_exit, code,
4120 "Could not start transaction on the volume %u to be dumped\n",
4124 fromcall = rx_NewCall(fromconn);
4126 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4127 if (flags & VOLDUMPV2_OMITDIRS)
4128 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4130 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4131 EGOTO(error_exit, code, "Could not start the dump process \n");
4134 VEPRINT1("Dumping volume %u...", afromvol);
4135 code = DumpFunction(fromcall, rock);