2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
21 #include <sys/statfs.h>
28 #include <netinet/in.h>
32 #include <afs/voldefs.h>
35 #include <afs/vlserver.h>
37 #include <afs/cellconfig.h>
40 #include <afs/afsint.h>
44 #include <afs/com_err.h>
46 #include <afs/kautils.h>
49 #define ERRCODE_RANGE 8 /* from error_table.h */
50 #define CLOCKSKEW 2 /* not really skew, but resolution */
51 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
53 /* for UV_MoveVolume() recovery */
55 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
58 #include "volser_prototypes.h"
59 #include "vsutils_prototypes.h"
60 #include "lockprocs_prototypes.h"
62 struct ubik_client *cstruct;
63 int verbose = 0, noresolve = 0;
68 afs_int32 vldbEntryIndex;
71 /* Utility macros used by rest of this source file */
72 #define EPRINT(ec, es) \
74 fprintf(STDERR, "\n"); \
75 fprintf(STDERR, (es)); \
79 #define EPRINT1(ec, es, ep1) \
81 fprintf(STDERR, "\n"); \
82 fprintf(STDERR, (es), (ep1)); \
86 #define EPRINT2(ec, es, ep1, ep2) \
88 fprintf(STDERR, "\n"); \
89 fprintf(STDERR, (es), (ep1), (ep2)); \
93 #define EPRINT3(ec, es, ep1, ep2, ep3) \
95 fprintf(STDERR, "\n"); \
96 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
100 #define EGOTO(where, ec, es) \
109 #define EGOTO1(where, ec, es, ep1) \
112 EPRINT1((ec),(es),(ep1)); \
118 #define EGOTO2(where, ec, es, ep1, ep2) \
121 EPRINT2((ec),(es),(ep1),(ep2)); \
127 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
130 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
137 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
138 #define VPRINT1(es, p) \
139 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
140 #define VPRINT2(es, p1, p2) \
141 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
142 #define VPRINT3(es, p1, p2, p3) \
143 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
145 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
146 #define VEPRINT(es) \
147 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
148 #define VEPRINT1(es, p) \
149 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
150 #define VEPRINT2(es, p1, p2) \
151 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
152 #define VEPRINT3(es, p1, p2, p3) \
153 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
155 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
159 /* getting rid of this */
160 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
163 /* Protos for static routines */
164 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
165 afs_int32 apart, afs_uint32 okvol,
167 static int DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
169 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
170 struct rx_connection **connPtr, afs_int32 * transPtr,
171 afs_int32 * crtimePtr, afs_int32 * uptimePtr);
172 static int SimulateForwardMultiple(struct rx_connection *fromconn,
173 afs_int32 fromtid, afs_int32 fromdate,
174 manyDests * tr, afs_int32 flags,
175 void *cookie, manyResults * results);
176 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
177 afs_int32 apart, afs_int32 * modentry,
178 afs_uint32 * maxvolid);
181 /*map the partition <partId> into partition name <partName>*/
183 MapPartIdIntoName(afs_int32 partId, char *partName)
185 if (partId < 26) { /* what if partId > = 26 ? */
186 strcpy(partName, "/vicep");
187 partName[6] = partId + 'a';
190 } else if (partId < VOLMAXPARTS) {
191 strcpy(partName, "/vicep");
193 partName[6] = 'a' + (partId / 26);
194 partName[7] = 'a' + (partId % 26);
206 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
207 response = c = getchar();
208 while (!(c == EOF || c == '\n'))
209 c = getchar(); /*skip to end of line */
210 code = (response == 'y' || response == 'Y');
216 PrintError(char *msg, afs_int32 errcode)
218 fprintf(STDERR, msg);
219 /*replace by a big switch statement */
224 fprintf(STDERR, "Possible communication failure\n");
227 fprintf(STDERR, "Volume needs to be salvaged\n");
230 fprintf(STDERR, "Bad vnode number quoted\n");
234 "Volume not attached, does not exist, or not on line\n");
237 fprintf(STDERR, "Volume already exists\n");
240 fprintf(STDERR, "Volume is not in service\n");
243 fprintf(STDERR, "Volume is off line\n");
246 fprintf(STDERR, "Volume is already on line\n");
249 fprintf(STDERR, "Partition is full\n");
252 fprintf(STDERR, "Volume max quota exceeded\n");
255 fprintf(STDERR, "Volume temporarily unavailable\n");
258 fprintf(STDERR, "Volume has moved to another server\n");
261 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
264 fprintf(STDERR, "VLDB: a read terminated too early\n");
267 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
270 fprintf(STDERR, "VLDB: internal creation failure\n");
273 fprintf(STDERR, "VLDB: no such entry\n");
276 fprintf(STDERR, "VLDB: vldb database is empty\n");
279 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
282 fprintf(STDERR, "VLDB: volume name is illegal\n");
285 fprintf(STDERR, "VLDB: index was out of range\n");
288 fprintf(STDERR, "VLDB: bad volume type\n");
291 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
293 case VL_BADPARTITION:
294 fprintf(STDERR, "VLDB: bad partition number\n");
297 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
300 fprintf(STDERR, "VLDB: no such repsite server exists\n");
302 case VL_DUPREPSERVER:
303 fprintf(STDERR, "VLDB: replication site server already exists\n");
306 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
309 fprintf(STDERR, "VLDB: illegal reference count number\n");
311 case VL_SIZEEXCEEDED:
312 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
315 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
317 case VL_BADVOLIDBUMP:
318 fprintf(STDERR, "VLDB: illegal max volid increment\n");
320 case VL_IDALREADYHASHED:
321 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
324 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
327 fprintf(STDERR, "VLDB: bad volume operation code\n");
329 case VL_BADRELLOCKTYPE:
330 fprintf(STDERR, "VLDB: bad release lock type\n");
333 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
335 case VL_BADSERVERFLAG:
336 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
339 fprintf(STDERR, "VLDB: no permission access for call\n");
341 case VOLSERREAD_DUMPERROR:
343 "VOLSER: Problems encountered in reading the dump file !\n");
345 case VOLSERDUMPERROR:
346 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
348 case VOLSERATTACH_ERROR:
349 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
351 case VOLSERDETACH_ERROR:
352 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
354 case VOLSERILLEGAL_PARTITION:
355 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
357 case VOLSERBAD_ACCESS:
358 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
360 case VOLSERVLDB_ERROR:
361 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
364 fprintf(STDERR, "VOLSER: error in volume name\n");
367 fprintf(STDERR, "VOLSER: volume has moved\n");
370 fprintf(STDERR, "VOLSER: illegal operation\n");
372 case VOLSERBADRELEASE:
373 fprintf(STDERR, "VOLSER: release could not be completed\n");
376 fprintf(STDERR, "VOLSER: volume is busy\n");
378 case VOLSERNO_MEMORY:
379 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
383 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
385 case VOLSERMULTIRWVOL:
387 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
391 "VOLSER: not all entries were successfully processed\n");
398 initialize_KA_error_table();
399 initialize_RXK_error_table();
400 initialize_KTC_error_table();
401 initialize_ACFG_error_table();
402 initialize_CMD_error_table();
403 initialize_VL_error_table();
405 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
406 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
407 afs_error_message(errcode));
414 void init_volintInfo(struct volintInfo *vinfo) {
415 memset(vinfo, 0, sizeof(struct volintInfo));
417 vinfo->maxquota = -1;
419 vinfo->creationDate = -1;
420 vinfo->updateDate = -1;
428 static struct rx_securityClass *uvclass = 0;
429 static int uvindex = -1;
430 /* called by VLDBClient_Init to set the security module to be used in the RPC */
432 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
439 /* bind to volser on <port> <aserver> */
440 /* takes server address in network order, port in host order. dumb */
441 struct rx_connection *
442 UV_Bind(afs_int32 aserver, afs_int32 port)
444 register struct rx_connection *tc;
446 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
451 /* if <okvol> is allright(indicated by beibg able to
452 * start a transaction, delete the <delvol> */
454 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
455 afs_uint32 okvol, afs_uint32 delvol)
457 afs_int32 error, code, tid, rcode;
463 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
466 code = AFSVolDeleteVolume(aconn, tid);
469 code = AFSVolEndTrans(aconn, tid, &rcode);
476 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
478 code = AFSVolEndTrans(aconn, tid, &rcode);
483 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
486 code = AFSVolDeleteVolume(aconn, tid);
489 code = AFSVolEndTrans(aconn, tid, &rcode);
500 /* called by EmuerateEntry, show vldb entry in a reasonable format */
502 SubEnumerateEntry(struct nvldbentry *entry)
510 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
511 if (entry->flags & RW_EXISTS)
512 fprintf(STDOUT, " valid \n");
514 fprintf(STDOUT, " invalid \n");
515 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
516 if (entry->flags & RO_EXISTS)
517 fprintf(STDOUT, " valid \n");
519 fprintf(STDOUT, " invalid \n");
520 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
521 if (entry->flags & BACK_EXISTS)
522 fprintf(STDOUT, " valid \n");
524 fprintf(STDOUT, " invalid \n");
525 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
526 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
528 if (entry->flags & RW_EXISTS)
529 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
530 if (entry->flags & RO_EXISTS)
531 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
532 if (entry->flags & BACK_EXISTS)
533 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
534 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
535 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
536 fprintf(STDOUT, "\n");
538 fprintf(STDOUT, " number of sites -> %lu\n",
539 (unsigned long)entry->nServers);
540 for (i = 0; i < entry->nServers; i++) {
541 if (entry->serverFlags[i] & NEW_REPSITE)
544 for (i = 0; i < entry->nServers; i++) {
545 MapPartIdIntoName(entry->serverPartition[i], pname);
546 fprintf(STDOUT, " server %s partition %s ",
547 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
548 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
549 if (entry->serverFlags[i] & ITSRWVOL)
550 fprintf(STDOUT, "RW Site ");
552 fprintf(STDOUT, "RO Site ");
554 if (entry->serverFlags[i] & NEW_REPSITE)
555 fprintf(STDOUT," -- New release");
557 if (!(entry->serverFlags[i] & ITSRWVOL))
558 fprintf(STDOUT," -- Old release");
560 if (entry->serverFlags[i] & RO_DONTUSE)
561 fprintf(STDOUT, " -- Not released");
563 fprintf(STDOUT, "\n");
570 /*enumerate the vldb entry corresponding to <entry> */
572 EnumerateEntry(struct nvldbentry *entry)
575 fprintf(STDOUT, "\n");
576 fprintf(STDOUT, "%s \n", entry->name);
577 SubEnumerateEntry(entry);
581 /* forcibly remove a volume. Very dangerous call */
583 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_uint32 volid)
585 register struct rx_connection *tconn;
586 register afs_int32 code;
588 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
590 code = AFSVolNukeVolume(tconn, partid, volid);
591 rx_DestroyConnection(tconn);
597 /* like df. Return usage of <pname> on <server> in <partition> */
599 UV_PartitionInfo64(afs_int32 server, char *pname,
600 struct diskPartition64 *partition)
602 register struct rx_connection *aconn;
605 aconn = (struct rx_connection *)0;
606 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
607 code = AFSVolPartitionInfo64(aconn, pname, partition);
608 if (code == RXGEN_OPCODE) {
609 struct diskPartition *dpp =
610 (struct diskPartition *)malloc(sizeof(struct diskPartition));
611 code = AFSVolPartitionInfo(aconn, pname, dpp);
613 strncpy(partition->name, dpp->name, 32);
614 strncpy(partition->devName, dpp->devName, 32);
615 partition->lock_fd = dpp->lock_fd;
616 partition->free = dpp->free;
617 partition->minFree = dpp->minFree;
622 fprintf(STDERR, "Could not get information on partition %s\n", pname);
623 PrintError("", code);
626 rx_DestroyConnection(aconn);
630 /* old interface to create volume */
632 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
636 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
640 /* create a volume, given a server, partition number, volume name --> sends
641 * back new vol id in <anewid>*/
643 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
644 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
645 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
648 register struct rx_connection *aconn;
650 register afs_int32 code;
652 afs_int32 rcode, vcode;
653 struct nvldbentry entry, storeEntry; /*the new vldb entry */
654 struct volintInfo tstatus;
657 aconn = (struct rx_connection *)0;
660 init_volintInfo(&tstatus);
661 tstatus.maxquota = aquota;
663 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
664 /* next the next 3 available ids from the VLDB */
665 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 3, anewid);
666 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
669 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
670 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
673 code = AFSVolSetInfo(aconn, tid, &tstatus);
675 EPRINT(code, "Could not change quota, continuing...\n");
677 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
678 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
681 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
683 /* set up the vldb entry for this volume */
684 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
686 entry.serverNumber[0] = aserver; /* this should have another
687 * level of indirection later */
688 entry.serverPartition[0] = apart; /* this should also have
689 * another indirection level */
690 entry.flags = RW_EXISTS; /* this records that rw volume exists */
691 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
692 entry.volumeId[RWVOL] = *anewid;
693 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
694 entry.volumeId[BACKVOL] = *anewid + 2;
696 /*map into right byte order, before passing to xdr, the stuff has to be in host
697 * byte order. Xdr converts it into network order */
698 MapNetworkToHost(&entry, &storeEntry);
699 /* create the vldb entry */
700 vcode = VLDB_CreateEntry(&storeEntry);
703 "Could not create a VLDB entry for the volume %s %lu\n",
704 aname, (unsigned long)*anewid);
705 /*destroy the created volume */
706 VPRINT1("Deleting the newly created volume %u\n", *anewid);
707 AFSVolDeleteVolume(aconn, tid);
711 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
712 /* volume created, now terminate the transaction and release the connection */
713 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
714 * the volume will come online anyway when transaction timesout , so if
715 * vldb entry exists then the volume is guaranteed to exist too wrt create */
719 "Failed to end the transaction on the volume %s %lu\n", aname,
720 (unsigned long)*anewid);
727 code = AFSVolEndTrans(aconn, tid, &rcode);
729 fprintf(STDERR, "WARNING: could not end transaction\n");
732 rx_DestroyConnection(aconn);
733 PrintError("", error);
739 /* create a volume, given a server, partition number, volume name --> sends
740 * back new vol id in <anewid>*/
742 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
745 register struct rx_connection *aconn;
748 struct nvldbentry entry, storeEntry; /*the new vldb entry */
750 aconn = (struct rx_connection *)0;
753 /* set up the vldb entry for this volume */
754 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
756 entry.serverNumber[0] = aserver; /* this should have another
757 * level of indirection later */
758 entry.serverPartition[0] = apart; /* this should also have
759 * another indirection level */
760 entry.flags = RW_EXISTS; /* this records that rw volume exists */
761 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
762 entry.volumeId[RWVOL] = aid;
764 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
765 entry.volumeId[BACKVOL] = *anewid + 2;
767 entry.volumeId[ROVOL] = 0;
768 entry.volumeId[BACKVOL] = 0;
771 /*map into right byte order, before passing to xdr, the stuff has to be in host
772 * byte order. Xdr converts it into network order */
773 MapNetworkToHost(&entry, &storeEntry);
774 /* create the vldb entry */
775 vcode = VLDB_CreateEntry(&storeEntry);
778 "Could not create a VLDB entry for the volume %s %lu\n",
779 aname, (unsigned long)aid);
783 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
787 rx_DestroyConnection(aconn);
788 PrintError("", error);
792 /* Delete the volume <volid>on <aserver> <apart>
793 * the physical entry gets removed from the vldb only if the ref count
797 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
799 struct rx_connection *aconn = (struct rx_connection *)0;
801 afs_int32 code, rcode;
803 struct nvldbentry entry, storeEntry;
805 afs_int32 avoltype = -1, vtype;
806 int notondisk = 0, notinvldb = 0;
808 /* Find and read bhe VLDB entry for this volume */
809 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
811 if (code != VL_NOENT) {
812 EGOTO1(error_exit, code,
813 "Could not lock VLDB entry for the volume %u\n", avolid);
819 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
820 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
822 MapHostToNetwork(&entry);
825 EnumerateEntry(&entry);
828 /* Whether volume is in the VLDB or not. Delete the volume on disk */
829 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
830 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
832 if (code == VNOVOL) {
835 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
839 VPRINT1("Trying to delete the volume %u ...", avolid);
841 code = AFSVolDeleteVolume(aconn, ttid);
842 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
844 code = AFSVolEndTrans(aconn, ttid, &rcode);
845 code = (code ? code : rcode);
847 EGOTO1(error_exit, code,
848 "Could not end the transaction for the volume %u \n", avolid);
852 /* Now update the VLDB entry.
853 * But first, verify we have a VLDB entry.
854 * Whether volume is on disk or not. Delete the volume in VLDB.
859 if (avolid == entry.volumeId[BACKVOL]) {
860 /* Its a backup volume, modify the VLDB entry. Check that the
861 * backup volume is on the server/partition we asked to delete.
863 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
864 notinvldb = 2; /* Not on this server and partition */
868 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
870 entry.flags &= ~BACK_EXISTS;
874 else if (avolid == entry.volumeId[ROVOL]) {
875 /* Its a read-only volume, modify the VLDB entry. Check that the
876 * readonly volume is on the server/partition we asked to delete.
877 * If flags does not have RO_EIXSTS set, then this may mean the RO
878 * hasn't been released (and could exist in VLDB).
880 if (!Lp_ROMatch(aserver, apart, &entry)) {
881 notinvldb = 2; /* Not found on this server and partition */
887 "Marking the readonly volume %lu deleted in the VLDB\n",
888 (unsigned long)avolid);
890 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
892 if (!Lp_ROMatch(0, 0, &entry))
893 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
897 else if (avolid == entry.volumeId[RWVOL]) {
898 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
899 * Check that the readwrite volumes is on the server/partition we
902 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
903 notinvldb = 2; /* Not found on this server and partition */
907 /* Delete backup if it exists */
909 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
913 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
914 entry.volumeId[BACKVOL]);
917 code = AFSVolDeleteVolume(aconn, ttid);
918 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
919 entry.volumeId[BACKVOL]);
921 code = AFSVolEndTrans(aconn, ttid, &rcode);
923 code = (code ? code : rcode);
924 EGOTO1(error_exit, code,
925 "Could not end the transaction for the volume %u \n",
926 entry.volumeId[BACKVOL]);
928 fprintf(STDOUT, " done\n");
933 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
934 (unsigned long)avolid,
936 flags & BACK_EXISTS) ? ", and its backup volume," :
939 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
941 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
944 if (entry.flags & RO_EXISTS)
945 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
949 notinvldb = 2; /* Not found on this server and partition */
953 /* Either delete or replace the VLDB entry */
954 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
957 "Last reference to the VLDB entry for %lu - deleting entry\n",
958 (unsigned long)avolid);
959 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
960 EGOTO1(error_exit, code,
961 "Could not delete the VLDB entry for the volume %u \n",
964 MapNetworkToHost(&entry, &storeEntry);
966 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
967 (LOCKREL_OPCODE | LOCKREL_AFSID |
969 EGOTO1(error_exit, code,
970 "Could not update the VLDB entry for the volume %u \n",
979 if (notondisk && notinvldb) {
980 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
981 ((notinvldb == 2) ? "on server and partition" : ""));
984 } else if (notondisk) {
986 "WARNING: Volume %lu did not exist on the partition\n",
987 (unsigned long)avolid);
988 } else if (notinvldb) {
989 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
990 (unsigned long)avolid,
991 ((notinvldb == 2) ? "on server and partition" : ""));
995 code = AFSVolEndTrans(aconn, ttid, &rcode);
996 code = (code ? code : rcode);
998 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
999 (unsigned long)avolid);
1000 PrintError("", code);
1008 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1009 (LOCKREL_OPCODE | LOCKREL_AFSID |
1010 LOCKREL_TIMESTAMP));
1013 "Could not release the lock on the VLDB entry for the volume %u \n",
1021 rx_DestroyConnection(aconn);
1025 /* add recovery to UV_MoveVolume */
1027 #define TESTC 0 /* set to test recovery code, clear for production */
1033 sigint_handler(int x)
1038 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1040 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1041 fprintf(STDOUT, "enter second control-c to exit\n");
1045 (void)signal(SIGINT, sigint_handler);
1050 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1051 * <atopart>. The operation is almost idempotent. The following
1052 * flags are recognized:
1054 * RV_NOCLONE - don't use a copy clone
1058 UV_MoveVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1059 afs_int32 atoserver, afs_int32 atopart, int flags)
1061 struct rx_connection *toconn, *fromconn;
1062 afs_int32 fromtid, totid, clonetid;
1065 char tmpName[VOLSER_MAXVOLNAME + 1];
1068 struct restoreCookie cookie;
1069 register afs_int32 vcode, code;
1070 afs_uint32 newVol, volid, backupId;
1071 struct volser_status tstatus;
1072 struct destServer destination;
1074 struct nvldbentry entry, storeEntry;
1075 int i, islocked, pntg;
1077 char in, lf; /* for test code */
1081 #ifdef ENABLE_BUGFIX_1165
1082 volEntries volumeInfo;
1083 struct volintInfo *infop = 0;
1087 fromconn = (struct rx_connection *)0;
1088 toconn = (struct rx_connection *)0;
1098 /* support control-c processing */
1101 (void)signal(SIGINT, sigint_handler);
1105 "\nThere are three tests points - verifies all code paths through recovery.\n");
1106 fprintf(STDOUT, "First test point - operation not started.\n");
1107 fprintf(STDOUT, "...test here (y, n)? ");
1109 fscanf(stdin, "%c", &in);
1110 fscanf(stdin, "%c", &lf); /* toss away */
1112 fprintf(STDOUT, "type control-c\n");
1114 fprintf(stdout, ".");
1119 /* or drop through */
1122 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1123 EGOTO1(mfail, vcode,
1124 "Could not fetch the entry for the volume %u from the VLDB \n",
1127 if (entry.volumeId[RWVOL] != afromvol) {
1128 fprintf(STDERR, "Only RW volume can be moved\n");
1132 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1133 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1136 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1137 EGOTO1(mfail, vcode,
1138 "Could not fetch the entry for the volume %u from the VLDB \n",
1141 backupId = entry.volumeId[BACKVOL];
1142 MapHostToNetwork(&entry);
1144 if (!Lp_Match(afromserver, afrompart, &entry)) {
1145 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1146 if (!Lp_Match(atoserver, atopart, &entry)) {
1147 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1148 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1149 (unsigned long)afromvol);
1150 fprintf(STDERR, "The current site is :");
1151 for (i = 0; i < entry.nServers; i++) {
1152 if (entry.serverFlags[i] == ITSRWVOL) {
1154 MapPartIdIntoName(entry.serverPartition[i], pname);
1155 fprintf(STDERR, " server %s partition %s \n",
1156 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1157 hostutil_GetNameByINet(entry.serverNumber[i]),
1162 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1163 (LOCKREL_OPCODE | LOCKREL_AFSID |
1164 LOCKREL_TIMESTAMP));
1165 EGOTO1(mfail, vcode,
1166 " Could not release lock on the VLDB entry for the volume %u \n",
1169 return VOLSERVOLMOVED;
1172 /* delete the volume afromvol on src_server */
1173 /* from-info does not exist but to-info does =>
1174 * we have already done the move, but the volume
1175 * may still be existing physically on from fileserver
1177 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1182 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1184 if (!code) { /* volume exists - delete it */
1185 VPRINT1("Setting flags on leftover source volume %u ...",
1188 AFSVolSetFlags(fromconn, fromtid,
1189 VTDeleteOnSalvage | VTOutOfService);
1191 "Failed to set flags on the leftover source volume %u\n",
1195 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1196 code = AFSVolDeleteVolume(fromconn, fromtid);
1198 "Failed to delete the leftover source volume %u\n",
1202 VPRINT1("Ending transaction on leftover source volume %u ...",
1204 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1209 "Could not end the transaction for the leftover source volume %u \n",
1214 /*delete the backup volume now */
1217 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1219 if (!code) { /* backup volume exists - delete it */
1220 VPRINT1("Setting flags on leftover backup volume %u ...",
1223 AFSVolSetFlags(fromconn, fromtid,
1224 VTDeleteOnSalvage | VTOutOfService);
1226 "Failed to set flags on the backup volume %u\n", backupId);
1229 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1230 code = AFSVolDeleteVolume(fromconn, fromtid);
1232 "Could not delete the leftover backup volume %u\n",
1236 VPRINT1("Ending transaction on leftover backup volume %u ...",
1238 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1243 "Could not end the transaction for the leftover backup volume %u\n",
1253 /* From-info matches the vldb info about volid,
1254 * its ok start the move operation, the backup volume
1255 * on the old site is deleted in the process
1257 if (afrompart == atopart) {
1258 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1259 EGOTO2(mfail, error,
1260 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1261 afromserver, error);
1264 EGOTO1(mfail, VOLSERVOLMOVED,
1265 "Warning: Moving volume %u to its home partition ignored!\n",
1271 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1272 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1273 fromtid = totid = 0; /* initialize to uncreated */
1276 * clone the read/write volume locally.
1279 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1280 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1281 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1285 if (!(flags & RV_NOCLONE)) {
1286 /* Get a clone id */
1287 VPRINT1("Allocating new volume id for clone of volume %u ...",
1290 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1291 EGOTO1(mfail, vcode,
1292 "Could not get an ID for the clone of volume %u from the VLDB\n",
1296 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1297 VPRINT1("Cloning source volume %u ...", afromvol);
1298 strcpy(vname, "move-clone-temp");
1300 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1301 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1306 /* lookup the name of the volume we just cloned */
1308 code = AFSVolGetName(fromconn, fromtid, &volName);
1309 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1312 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1314 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1319 "Failed to end the transaction on the source volume %u\n",
1324 * Create the destination volume
1327 if (!(flags & RV_NOCLONE)) {
1328 /* All of this is to get the fromDate */
1329 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1331 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1334 "Failed to start a transaction on the cloned volume%u\n",
1338 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1340 AFSVolSetFlags(fromconn, clonetid,
1341 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1342 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1346 /* remember time from which we've dumped the volume */
1347 VPRINT1("Getting status of cloned volume %u ...", newVol);
1348 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1350 "Failed to get the status of the cloned volume %u\n",
1354 fromDate = CLOCKADJ(tstatus.creationDate);
1356 /* With RV_NOCLONE, just do a full copy from the source */
1361 #ifdef ENABLE_BUGFIX_1165
1363 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1364 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1365 * don't use this information...
1367 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1368 volumeInfo.volEntries_len = 0;
1369 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1371 "Failed to get the volint Info of the cloned volume %u\n",
1374 infop = (volintInfo *) volumeInfo.volEntries_val;
1375 infop->maxquota = -1; /* Else it will replace the default quota */
1376 infop->creationDate = -1; /* Else it will use the source creation date */
1377 infop->updateDate = -1; /* Else it will use the source update date */
1380 /* create a volume on the target machine */
1382 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1384 /* Delete the existing volume.
1385 * While we are deleting the volume in these steps, the transaction
1386 * we started against the cloned volume (clonetid above) will be
1387 * sitting idle. It will get cleaned up after 600 seconds
1389 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1390 code = AFSVolDeleteVolume(toconn, totid);
1392 "Could not delete the pre-existing volume %u on destination\n",
1397 ("Ending transaction on pre-existing volume %u on destination ...",
1399 code = AFSVolEndTrans(toconn, totid, &rcode);
1404 "Could not end the transaction on pre-existing volume %u on destination\n",
1409 VPRINT1("Creating the destination volume %u ...", volid);
1411 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1413 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1417 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1421 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1423 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1425 "Failed to set the flags on the destination volume %u\n", volid);
1429 * Now dump the clone to the new volume
1432 destination.destHost = ntohl(atoserver);
1433 destination.destPort = AFSCONF_VOLUMEPORT;
1434 destination.destSSID = 1;
1436 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1437 cookie.type = RWVOL;
1438 cookie.parent = entry.volumeId[RWVOL];
1441 if (!(flags & RV_NOCLONE)) {
1442 /* Copy the clone to the new volume */
1443 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1446 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1448 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1451 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1452 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1457 "Failed to end the transaction on the cloned volume %u\n",
1463 * reattach to the main-line volume, and incrementally dump it.
1466 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1467 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1469 "Failed to create a transaction on the source volume %u\n",
1473 /* now do the incremental */
1475 ("Doing the%s dump from source to destination for volume %u ... ",
1476 (flags & RV_NOCLONE) ? "" : " incremental",
1479 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1482 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1483 (flags & RV_NOCLONE) ? "" : " incremental");
1486 /* now adjust the flags so that the new volume becomes official */
1487 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1488 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1490 "Failed to set the flags to make old source volume offline\n");
1493 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1494 code = AFSVolSetFlags(toconn, totid, 0);
1496 "Failed to set the flags to make new source volume online\n");
1499 #ifdef ENABLE_BUGFIX_1165
1500 VPRINT1("Setting volume status on destination volume %u ...", volid);
1501 code = AFSVolSetInfo(toconn, totid, infop);
1503 "Failed to set volume status on the destination volume %u\n",
1508 /* put new volume online */
1509 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1510 code = AFSVolEndTrans(toconn, totid, &rcode);
1515 "Failed to end the transaction on the volume %u on the new site\n",
1519 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1520 MapNetworkToHost(&entry, &storeEntry);
1521 storeEntry.flags &= ~BACK_EXISTS;
1525 "Second test point - operation in progress but not complete.\n");
1526 fprintf(STDOUT, "...test here (y, n)? ");
1528 fscanf(stdin, "%c", &in);
1529 fscanf(stdin, "%c", &lf); /* toss away */
1531 fprintf(STDOUT, "type control-c\n");
1533 fprintf(stdout, ".");
1538 /* or drop through */
1541 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1543 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1544 (LOCKREL_OPCODE | LOCKREL_AFSID |
1545 LOCKREL_TIMESTAMP));
1548 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1549 storeEntry.name, (unsigned long)afromvol);
1558 "Third test point - operation complete but no cleanup.\n");
1559 fprintf(STDOUT, "...test here (y, n)? ");
1561 fscanf(stdin, "%c", &in);
1562 fscanf(stdin, "%c", &lf); /* toss away */
1564 fprintf(STDOUT, "type control-c\n");
1566 fprintf(stdout, ".");
1571 /* or drop through */
1574 /* This is tricky. File server is very stupid, and if you mark the volume
1575 * as VTOutOfService, it may mark the *good* instance (if you're moving
1576 * between partitions on the same machine) as out of service. Since
1577 * we're cleaning this code up in DEcorum, we're just going to kludge around
1578 * it for now by removing this call. */
1579 /* already out of service, just zap it now */
1581 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1584 "Failed to set the flags to make the old source volume offline\n");
1588 if (atoserver != afromserver) {
1589 /* set forwarding pointer for moved volumes */
1590 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1591 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1593 "Failed to set the forwarding pointer for the volume %u\n",
1598 VPRINT1("Deleting old volume %u on source ...", afromvol);
1599 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1600 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1604 VPRINT1("Ending transaction on old volume %u on the source ...",
1606 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1611 "Failed to end the transaction on the old volume %u on the source\n",
1615 /* Delete the backup volume on the original site */
1616 VPRINT1("Creating transaction for backup volume %u on source ...",
1619 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1622 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1624 AFSVolSetFlags(fromconn, fromtid,
1625 VTDeleteOnSalvage | VTOutOfService);
1627 "Failed to set the flags on the backup volume %u on the source\n",
1631 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1632 code = AFSVolDeleteVolume(fromconn, fromtid);
1634 "Failed to delete the backup volume %u on the source\n",
1638 VPRINT1("Ending transaction on backup volume %u on source ...",
1640 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1645 "Failed to end the transaction on the backup volume %u on the source\n",
1649 code = 0; /* no backup volume? that's okay */
1652 if (!(flags & RV_NOCLONE)) {
1653 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1655 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1658 "Failed to start a transaction on the cloned volume%u\n",
1662 /* now delete the clone */
1663 VPRINT1("Deleting the cloned volume %u ...", newVol);
1664 code = AFSVolDeleteVolume(fromconn, clonetid);
1665 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1669 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1670 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1675 "Failed to end the transaction on the cloned volume %u\n",
1684 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1685 fprintf(STDOUT, "...test here (y, n)? ");
1687 fscanf(stdin, "%c", &in);
1688 fscanf(stdin, "%c", &lf); /* toss away */
1690 fprintf(STDOUT, "type control-c\n");
1692 fprintf(stdout, ".");
1697 /* or drop through */
1700 /* normal cleanup code */
1702 if (entry.flags & RO_EXISTS)
1703 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1706 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1708 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1709 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1713 " Could not release the lock on the VLDB entry for the volume %lu \n",
1714 (unsigned long)afromvol);
1722 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1724 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1725 if (code || rcode) {
1728 "Could not end transaction on the source volume %lu\n",
1729 (unsigned long)afromvol);
1731 error = (code ? code : rcode);
1737 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1738 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1739 if (code || rcode) {
1742 "Could not end transaction on the source's clone volume %lu\n",
1743 (unsigned long)newVol);
1745 error = (code ? code : rcode);
1751 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1753 code = AFSVolEndTrans(toconn, totid, &rcode);
1757 "Could not end transaction on destination volume %lu\n",
1758 (unsigned long)afromvol);
1760 error = (code ? code : rcode);
1766 #ifdef ENABLE_BUGFIX_1165
1771 rx_DestroyConnection(fromconn);
1773 rx_DestroyConnection(toconn);
1774 PrintError("", error);
1777 /* come here only when the sky falls */
1782 "vos move: operation interrupted, cleanup in progress...\n");
1783 fprintf(STDOUT, "clear transaction contexts\n");
1787 /* unlock VLDB entry */
1789 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1790 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1791 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1797 VPRINT("Recovery: Ending transaction on clone volume ...");
1798 AFSVolEndTrans(fromconn, clonetid, &rcode);
1802 VPRINT("Recovery: Ending transaction on destination volume ...");
1803 AFSVolEndTrans(toconn, totid, &rcode);
1806 if (fromtid) { /* put it on-line */
1807 VPRINT("Recovery: Setting volume flags on source volume ...");
1808 AFSVolSetFlags(fromconn, fromtid, 0);
1811 VPRINT("Recovery: Ending transaction on source volume ...");
1812 AFSVolEndTrans(fromconn, fromtid, &rcode);
1816 VPRINT("Recovery: Accessing VLDB.\n");
1817 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1819 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1823 MapHostToNetwork(&entry);
1825 /* Delete either the volume on the source location or the target location.
1826 * If the vldb entry still points to the source location, then we know the
1827 * volume move didn't finish so we remove the volume from the target
1828 * location. Otherwise, we remove the volume from the source location.
1830 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1833 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1837 if (volid && toconn) {
1839 ("Recovery: Creating transaction for destination volume %u ...",
1842 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1848 ("Recovery: Setting flags on destination volume %u ...",
1850 AFSVolSetFlags(toconn, totid,
1851 VTDeleteOnSalvage | VTOutOfService);
1854 VPRINT1("Recovery: Deleting destination volume %u ...",
1856 AFSVolDeleteVolume(toconn, totid);
1860 ("Recovery: Ending transaction on destination volume %u ...",
1862 AFSVolEndTrans(toconn, totid, &rcode);
1866 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1871 /* put source volume on-line */
1873 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1876 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1881 VPRINT1("Recovery: Setting flags on source volume %u ...",
1883 AFSVolSetFlags(fromconn, fromtid, 0);
1887 ("Recovery: Ending transaction on source volume %u ...",
1889 AFSVolEndTrans(fromconn, fromtid, &rcode);
1893 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1897 } else { /* yep, move complete */
1900 "move complete - attempt cleanup of source partition - no guarantee\n");
1904 /* delete backup volume */
1906 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1909 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1914 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1916 AFSVolSetFlags(fromconn, fromtid,
1917 VTDeleteOnSalvage | VTOutOfService);
1920 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1921 AFSVolDeleteVolume(fromconn, fromtid);
1925 ("Recovery: Ending transaction on backup volume %u ...",
1927 AFSVolEndTrans(fromconn, fromtid, &rcode);
1931 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1935 /* delete source volume */
1936 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1939 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1944 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1946 AFSVolSetFlags(fromconn, fromtid,
1947 VTDeleteOnSalvage | VTOutOfService);
1950 if (atoserver != afromserver) {
1951 VPRINT("Recovery: Setting volume forwarding pointer ...");
1952 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1956 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1957 AFSVolDeleteVolume(fromconn, fromtid);
1961 ("Recovery: Ending transaction on source volume %u ...",
1963 AFSVolEndTrans(fromconn, fromtid, &rcode);
1967 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1973 /* common cleanup - delete local clone */
1975 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1978 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1983 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1984 AFSVolDeleteVolume(fromconn, clonetid);
1987 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1989 AFSVolEndTrans(fromconn, clonetid, &rcode);
1993 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1998 /* unlock VLDB entry */
2000 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2002 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2003 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2007 done: /* routine cleanup */
2010 #ifdef ENABLE_BUGFIX_1165
2015 rx_DestroyConnection(fromconn);
2017 rx_DestroyConnection(toconn);
2020 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2028 UV_MoveVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2029 afs_int32 atoserver, afs_int32 atopart)
2031 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2032 atoserver, atopart, 0);
2036 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2037 * <atopart>. The new volume is named by <atovolname>. The new volume
2038 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2039 * from the VLDB. the following flags are supported:
2041 * RV_RDONLY - target volume is RO
2042 * RV_OFFLINE - leave target volume offline
2043 * RV_CPINCR - do incremental dump if target exists
2044 * RV_NOVLDB - don't create/update VLDB entry
2045 * RV_NOCLONE - don't use a copy clone
2048 UV_CopyVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2049 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2050 afs_uint32 atovolid, int flags)
2052 struct rx_connection *toconn, *fromconn;
2053 afs_int32 fromtid, totid, clonetid;
2056 afs_int32 fromDate, cloneFromDate;
2057 struct restoreCookie cookie;
2058 register afs_int32 vcode, code;
2059 afs_uint32 cloneVol, newVol;
2061 struct volser_status tstatus;
2062 struct destServer destination;
2064 struct nvldbentry entry, newentry, storeEntry;
2070 fromconn = (struct rx_connection *)0;
2071 toconn = (struct rx_connection *)0;
2079 /* support control-c processing */
2082 (void)signal(SIGINT, sigint_handler);
2084 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2085 EGOTO1(mfail, vcode,
2086 "Could not fetch the entry for the volume %u from the VLDB \n",
2088 MapHostToNetwork(&entry);
2091 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2092 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2093 fromtid = totid = 0; /* initialize to uncreated */
2096 /* check if we can shortcut and use a local clone instead of a full copy */
2097 if (afromserver == atoserver && afrompart == atopart) {
2102 * clone the read/write volume locally.
2106 if (!(flags & RV_NOCLONE)) {
2107 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2108 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2110 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2114 /* Get a clone id */
2115 VPRINT1("Allocating new volume id for clone of volume %u ...",
2118 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2119 EGOTO1(mfail, vcode,
2120 "Could not get an ID for the clone of volume %u from the VLDB\n",
2128 /* Get a new volume id */
2129 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2131 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2132 EGOTO1(mfail, vcode,
2133 "Could not get an ID for the copy of volume %u from the VLDB\n",
2138 if (!(flags & RV_NOCLONE)) {
2139 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2140 VPRINT1("Cloning source volume %u ...", afromvol);
2141 strcpy(vname, "copy-clone-temp");
2143 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2145 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2149 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2151 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2156 "Failed to end the transaction on the source volume %u\n",
2162 * Create the destination volume
2165 if (!(flags & RV_NOCLONE)) {
2166 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2168 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2171 "Failed to start a transaction on the cloned volume%u\n",
2175 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2177 AFSVolSetFlags(fromconn, clonetid,
2178 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2179 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2183 /* remember time from which we've dumped the volume */
2184 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2185 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2187 "Failed to get the status of the cloned volume %u\n",
2191 fromDate = CLOCKADJ(tstatus.creationDate);
2196 /* create a volume on the target machine */
2198 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2200 if ((flags & RV_CPINCR)) {
2201 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2202 code = AFSVolGetStatus(toconn, totid, &tstatus);
2204 "Failed to get the status of the pre-existing volume %u\n",
2208 /* Using the update date should be OK here, but add some fudge */
2209 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2210 if ((flags & RV_NOCLONE))
2211 fromDate = cloneFromDate;
2213 /* XXX We should check that the source volume's creationDate is
2214 * XXX not newer than the existing target volume, and if not,
2215 * XXX throw away the existing target and do a full dump. */
2220 /* Delete the existing volume.
2221 * While we are deleting the volume in these steps, the transaction
2222 * we started against the cloned volume (clonetid above) will be
2223 * sitting idle. It will get cleaned up after 600 seconds
2225 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2226 code = AFSVolDeleteVolume(toconn, totid);
2228 "Could not delete the pre-existing volume %u on destination\n",
2233 ("Ending transaction on pre-existing volume %u on destination ...",
2235 code = AFSVolEndTrans(toconn, totid, &rcode);
2240 "Could not end the transaction on pre-existing volume %u on destination\n",
2245 VPRINT1("Creating the destination volume %u ...", newVol);
2247 AFSVolCreateVolume(toconn, atopart, atovolname,
2248 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2249 newVol, &newVol, &totid);
2250 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2254 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2256 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2258 "Failed to set the flags on the destination volume %u\n", newVol);
2263 destination.destHost = ntohl(atoserver);
2264 destination.destPort = AFSCONF_VOLUMEPORT;
2265 destination.destSSID = 1;
2267 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2268 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2273 * Now dump the clone to the new volume
2276 if (!(flags & RV_NOCLONE)) {
2277 /* XXX probably should have some code here that checks to see if
2278 * XXX we are copying to same server and partition - if so, just
2279 * XXX use a clone to save disk space */
2281 /* Copy the clone to the new volume */
2282 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2285 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2287 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2291 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2292 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2297 "Failed to end the transaction on the cloned volume %u\n",
2303 * reattach to the main-line volume, and incrementally dump it.
2306 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2307 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2309 "Failed to create a transaction on the source volume %u\n",
2313 /* now do the incremental */
2315 ("Doing the%s dump from source to destination for volume %u ... ",
2316 (flags & RV_NOCLONE) ? "" : " incremental",
2319 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2322 "Failed to do the%s dump from old site to new site\n",
2326 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2327 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2328 code = AFSVolSetFlags(toconn, totid, volflag);
2330 "Failed to set the flags to make destination volume online\n");
2333 /* put new volume online */
2334 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2335 code = AFSVolEndTrans(toconn, totid, &rcode);
2340 "Failed to end the transaction on the destination volume %u\n",
2344 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2345 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2350 "Failed to end the transaction on the source volume %u\n",
2356 if (!(flags & RV_NOCLONE)) {
2357 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2359 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2362 "Failed to start a transaction on the cloned volume%u\n",
2366 /* now delete the clone */
2367 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2368 code = AFSVolDeleteVolume(fromconn, clonetid);
2369 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2373 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2374 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2379 "Failed to end the transaction on the cloned volume %u\n",
2384 if (!(flags & RV_NOVLDB)) {
2385 /* create the vldb entry for the copied volume */
2386 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2387 newentry.nServers = 1;
2388 newentry.serverNumber[0] = atoserver;
2389 newentry.serverPartition[0] = atopart;
2390 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2391 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2392 newentry.volumeId[RWVOL] = newVol;
2393 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2394 newentry.volumeId[BACKVOL] = 0;
2395 newentry.cloneId = 0;
2396 /*map into right byte order, before passing to xdr, the stuff has to be in host
2397 * byte order. Xdr converts it into network order */
2398 MapNetworkToHost(&newentry, &storeEntry);
2399 /* create the vldb entry */
2400 vcode = VLDB_CreateEntry(&storeEntry);
2403 "Could not create a VLDB entry for the volume %s %lu\n",
2404 atovolname, (unsigned long)newVol);
2405 /*destroy the created volume */
2406 VPRINT1("Deleting the newly created volume %u\n", newVol);
2407 AFSVolDeleteVolume(toconn, totid);
2411 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2415 /* normal cleanup code */
2418 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2420 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2421 if (code || rcode) {
2424 "Could not end transaction on the source volume %lu\n",
2425 (unsigned long)afromvol);
2427 error = (code ? code : rcode);
2433 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2435 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2436 if (code || rcode) {
2439 "Could not end transaction on the source's clone volume %lu\n",
2440 (unsigned long)cloneVol);
2442 error = (code ? code : rcode);
2448 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2450 code = AFSVolEndTrans(toconn, totid, &rcode);
2454 "Could not end transaction on destination volume %lu\n",
2455 (unsigned long)newVol);
2457 error = (code ? code : rcode);
2462 rx_DestroyConnection(fromconn);
2464 rx_DestroyConnection(toconn);
2465 PrintError("", error);
2468 /* come here only when the sky falls */
2473 "vos copy: operation interrupted, cleanup in progress...\n");
2474 fprintf(STDOUT, "clear transaction contexts\n");
2479 VPRINT("Recovery: Ending transaction on clone volume ...");
2480 AFSVolEndTrans(fromconn, clonetid, &rcode);
2484 VPRINT("Recovery: Ending transaction on destination volume ...");
2485 AFSVolEndTrans(toconn, totid, &rcode);
2488 if (fromtid) { /* put it on-line */
2489 VPRINT("Recovery: Ending transaction on source volume ...");
2490 AFSVolEndTrans(fromconn, fromtid, &rcode);
2494 VPRINT("Recovery: Accessing VLDB.\n");
2495 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2497 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2501 MapHostToNetwork(&entry);
2503 /* common cleanup - delete local clone */
2505 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2508 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2513 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2514 AFSVolDeleteVolume(fromconn, clonetid);
2517 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2519 AFSVolEndTrans(fromconn, clonetid, &rcode);
2523 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2528 done: /* routine cleanup */
2530 rx_DestroyConnection(fromconn);
2532 rx_DestroyConnection(toconn);
2535 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2543 UV_CopyVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2544 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2546 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2547 atovolname, atoserver, atopart, 0, 0);
2552 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2553 * if one already exists, update it
2557 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
2559 struct rx_connection *aconn = (struct rx_connection *)0;
2560 afs_int32 ttid = 0, btid = 0;
2561 afs_uint32 backupID;
2562 afs_int32 code = 0, rcode = 0;
2563 char vname[VOLSER_MAXVOLNAME + 1];
2564 struct nvldbentry entry, storeEntry;
2565 afs_int32 error = 0;
2566 int vldblocked = 0, vldbmod = 0, backexists = 1;
2568 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2570 /* the calls to VLDB will succeed only if avolid is a RW volume,
2571 * since we are following the RW hash chain for searching */
2572 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2575 "Could not fetch the entry for the volume %lu from the VLDB \n",
2576 (unsigned long)avolid);
2580 MapHostToNetwork(&entry);
2582 /* These operations require the VLDB be locked since it means the VLDB
2583 * will change or the vldb is already locked.
2585 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2586 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2587 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2589 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2592 "Could not lock the VLDB entry for the volume %lu\n",
2593 (unsigned long)avolid);
2599 /* Reread the vldb entry */
2600 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2603 "Could not fetch the entry for the volume %lu from the VLDB \n",
2604 (unsigned long)avolid);
2608 MapHostToNetwork(&entry);
2611 if (!ISNAMEVALID(entry.name)) {
2612 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2614 error = VOLSERBADNAME;
2618 backupID = entry.volumeId[BACKVOL];
2619 if (backupID == INVALID_BID) {
2620 /* Get a backup volume id from the VLDB and update the vldb
2623 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2626 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2627 (unsigned long)avolid);
2631 entry.volumeId[BACKVOL] = backupID;
2635 /* Test to see if the backup volume exists by trying to create
2636 * a transaction on the backup volume. We've assumed the backup exists.
2638 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2640 if (code != VNOVOL) {
2641 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2642 (unsigned long)backupID);
2646 backexists = 0; /* backup volume does not exist */
2649 code = AFSVolEndTrans(aconn, btid, &rcode);
2651 if (code || rcode) {
2653 "Could not end transaction on the previous backup volume %lu\n",
2654 (unsigned long)backupID);
2655 error = (code ? code : rcode);
2660 /* Now go ahead and try to clone the RW volume.
2661 * First start a transaction on the RW volume
2663 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2665 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2666 (unsigned long)avolid);
2671 /* Clone or reclone the volume, depending on whether the backup
2672 * volume exists or not
2675 VPRINT1("Re-cloning backup volume %u ...", backupID);
2677 code = AFSVolReClone(aconn, ttid, backupID);
2679 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2680 (unsigned long)backupID);
2685 VPRINT1("Creating a new backup clone %u ...", backupID);
2687 strcpy(vname, entry.name);
2688 strcat(vname, ".backup");
2690 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2692 fprintf(STDERR, "Failed to clone the volume %lu\n",
2693 (unsigned long)avolid);
2699 /* End the transaction on the RW volume */
2700 code = AFSVolEndTrans(aconn, ttid, &rcode);
2702 if (code || rcode) {
2704 "Failed to end the transaction on the rw volume %lu\n",
2705 (unsigned long)avolid);
2706 error = (code ? code : rcode);
2710 /* Mork vldb as backup exists */
2711 if (!(entry.flags & BACK_EXISTS)) {
2712 entry.flags |= BACK_EXISTS;
2716 /* Now go back to the backup volume and bring it on line */
2717 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2720 "Failed to start a transaction on the backup volume %lu\n",
2721 (unsigned long)backupID);
2726 code = AFSVolSetFlags(aconn, btid, 0);
2728 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2729 (unsigned long)backupID);
2734 code = AFSVolEndTrans(aconn, btid, &rcode);
2736 if (code || rcode) {
2738 "Failed to end the transaction on the backup volume %lu\n",
2739 (unsigned long)backupID);
2740 error = (code ? code : rcode);
2746 /* Will update the vldb below */
2750 code = AFSVolEndTrans(aconn, ttid, &rcode);
2751 if (code || rcode) {
2752 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2753 (unsigned long)avolid);
2755 error = (code ? code : rcode);
2760 code = AFSVolEndTrans(aconn, btid, &rcode);
2761 if (code || rcode) {
2763 "Could not end transaction the backup volume %lu\n",
2764 (unsigned long)backupID);
2766 error = (code ? code : rcode);
2770 /* Now update the vldb - if modified */
2773 MapNetworkToHost(&entry, &storeEntry);
2775 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2776 (LOCKREL_OPCODE | LOCKREL_AFSID |
2777 LOCKREL_TIMESTAMP));
2780 "Could not update the VLDB entry for the volume %lu \n",
2781 (unsigned long)avolid);
2787 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2788 (LOCKREL_OPCODE | LOCKREL_AFSID |
2789 LOCKREL_TIMESTAMP));
2792 "Could not unlock the VLDB entry for the volume %lu \n",
2793 (unsigned long)avolid);
2801 rx_DestroyConnection(aconn);
2803 PrintError("", error);
2807 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2808 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2809 * The new volume is named by <aname>, or by appending ".clone" to
2810 * the existing name if <aname> is NULL. The following flags are
2813 * RV_RDONLY - target volume is RO
2814 * RV_OFFLINE - leave target volume offline
2818 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid,
2819 afs_uint32 acloneid, char *aname, int flags)
2821 struct rx_connection *aconn = (struct rx_connection *)0;
2822 afs_int32 ttid = 0, btid = 0;
2823 afs_int32 code = 0, rcode = 0;
2824 char vname[VOLSER_MAXVOLNAME + 1];
2825 afs_int32 error = 0;
2827 volEntries volumeInfo;
2829 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2832 volumeInfo.volEntries_val = (volintInfo *) 0;
2833 volumeInfo.volEntries_len = 0;
2834 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2836 fprintf(stderr, "Could not get info for volume %lu\n",
2837 (unsigned long)avolid);
2841 strncpy(vname, volumeInfo.volEntries_val[0].name,
2842 VOLSER_OLDMAXVOLNAME - 7);
2843 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2844 strcat(vname, ".clone");
2846 if (volumeInfo.volEntries_val)
2847 free(volumeInfo.volEntries_val);
2851 /* Get a clone id */
2852 VPRINT1("Allocating new volume id for clone of volume %u ...",
2854 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2856 "Could not get an ID for the clone of volume %u from the VLDB\n",
2861 /* Test to see if the clone volume exists by trying to create
2862 * a transaction on the clone volume. We've assumed the clone exists.
2864 /* XXX I wonder what happens if the clone has some other parent... */
2865 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2867 if (code != VNOVOL) {
2868 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2869 (unsigned long)acloneid);
2873 backexists = 0; /* backup volume does not exist */
2876 code = AFSVolEndTrans(aconn, btid, &rcode);
2878 if (code || rcode) {
2880 "Could not end transaction on the previous clone volume %lu\n",
2881 (unsigned long)acloneid);
2882 error = (code ? code : rcode);
2887 /* Now go ahead and try to clone the RW volume.
2888 * First start a transaction on the RW volume
2890 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2892 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2893 (unsigned long)avolid);
2898 /* Clone or reclone the volume, depending on whether the backup
2899 * volume exists or not
2902 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2904 code = AFSVolReClone(aconn, ttid, acloneid);
2906 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2907 (unsigned long)acloneid);
2912 VPRINT1("Creating a new clone %u ...", acloneid);
2914 code = AFSVolClone(aconn, ttid, 0,
2915 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2918 fprintf(STDERR, "Failed to clone the volume %lu\n",
2919 (unsigned long)avolid);
2925 /* End the transaction on the RW volume */
2926 code = AFSVolEndTrans(aconn, ttid, &rcode);
2928 if (code || rcode) {
2930 "Failed to end the transaction on the rw volume %lu\n",
2931 (unsigned long)avolid);
2932 error = (code ? code : rcode);
2936 /* Now go back to the backup volume and bring it on line */
2937 if (!(flags & RV_OFFLINE)) {
2938 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2941 "Failed to start a transaction on the clone volume %lu\n",
2942 (unsigned long)acloneid);
2947 code = AFSVolSetFlags(aconn, btid, 0);
2949 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2950 (unsigned long)acloneid);
2955 code = AFSVolEndTrans(aconn, btid, &rcode);
2957 if (code || rcode) {
2959 "Failed to end the transaction on the clone volume %lu\n",
2960 (unsigned long)acloneid);
2961 error = (code ? code : rcode);
2970 code = AFSVolEndTrans(aconn, ttid, &rcode);
2971 if (code || rcode) {
2972 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2973 (unsigned long)avolid);
2975 error = (code ? code : rcode);
2980 code = AFSVolEndTrans(aconn, btid, &rcode);
2981 if (code || rcode) {
2983 "Could not end transaction on the clone volume %lu\n",
2984 (unsigned long)acloneid);
2986 error = (code ? code : rcode);
2991 rx_DestroyConnection(aconn);
2993 PrintError("", error);
2998 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
3001 afs_int32 acode, ccode, rcode, tid;
3002 ccode = rcode = tid = 0;
3004 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
3005 if (!acode) { /* It really was there */
3006 acode = AFSVolDeleteVolume(conn, tid);
3008 fprintf(STDERR, "Failed to delete volume %lu.\n",
3009 (unsigned long)vid);
3010 PrintError("", acode);
3012 ccode = AFSVolEndTrans(conn, tid, &rcode);
3016 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3017 (unsigned long)vid);
3018 PrintError("", ccode);
3025 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3026 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3028 /* Get a "transaction" on this replica. Create the volume
3029 * if necessary. Return the time from which a dump should
3030 * be made (0 if it's a new volume)
3033 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3034 struct rx_connection **connPtr, afs_int32 * transPtr,
3035 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3038 struct volser_status tstatus;
3043 *connPtr = (struct rx_connection *)0;
3048 /* get connection to the replication site */
3049 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3051 goto fail; /* server is down */
3053 volid = vldbEntryPtr->volumeId[ROVOL];
3056 AFSVolTransCreate(*connPtr, volid,
3057 vldbEntryPtr->serverPartition[index], ITOffline,
3060 /* If the volume does not exist, create it */
3061 if (!volid || code) {
3065 if (volid && (code != VNOVOL)) {
3066 PrintError("Failed to start a transaction on the RO volume.\n",
3071 strcpy(volname, vldbEntryPtr->name);
3072 strcat(volname, ".readonly");
3076 "Creating new volume %lu on replication site %s: ",
3077 (unsigned long)volid,
3078 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3079 serverNumber[index], hoststr) :
3080 hostutil_GetNameByINet(vldbEntryPtr->
3081 serverNumber[index]));
3086 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3088 vldbEntryPtr->volumeId[RWVOL], &volid,
3091 PrintError("Failed to create the ro volume: ", code);
3094 vldbEntryPtr->volumeId[ROVOL] = volid;
3098 /* The following is a bit redundant, since create sets these flags by default */
3100 AFSVolSetFlags(*connPtr, *transPtr,
3101 VTDeleteOnSalvage | VTOutOfService);
3103 PrintError("Failed to set flags on the ro volume: ", code);
3108 /* Otherwise, the transaction did succeed, so get the creation date of the
3109 * latest RO volume on the replication site
3112 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3113 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3114 serverNumber[index], hoststr) :
3115 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3117 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3119 PrintError("Failed to get status of volume on destination: ",
3123 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3124 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3131 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3136 PrintError("Could not end transaction on a ro volume: ", tcode);
3143 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3144 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3145 void *cookie, manyResults * results)
3149 for (i = 0; i < tr->manyDests_len; i++) {
3150 results->manyResults_val[i] =
3151 AFSVolForward(fromconn, fromtid, fromdate,
3152 &(tr->manyDests_val[i].server),
3153 tr->manyDests_val[i].trans, cookie);
3159 /* UV_ReleaseVolume()
3160 * Release volume <afromvol> on <afromserver> <afrompart> to all
3161 * its RO sites (full release). Unless the previous release was
3162 * incomplete: in which case we bring the remaining incomplete
3163 * volumes up to date with the volumes that were released
3165 * forceflag: Performs a full release.
3167 * Will create a clone from the RW, then dump the clone out to
3168 * the remaining replicas. If there is more than 1 RO sites,
3169 * ensure that the VLDB says at least one RO is available all
3170 * the time: Influences when we write back the VLDB entry.
3174 UV_ReleaseVolume(afs_uint32 afromvol, afs_int32 afromserver,
3175 afs_int32 afrompart, int forceflag)
3179 afs_int32 vcode, rcode, tcode;
3180 afs_uint32 cloneVolId, roVolId;
3181 struct replica *replicas = 0;
3182 struct nvldbentry entry, storeEntry;
3183 int i, volcount, m, fullrelease, vldbindex;
3185 struct restoreCookie cookie;
3186 struct rx_connection **toconns = 0;
3187 struct release *times = 0;
3189 struct rx_connection *fromconn = (struct rx_connection *)0;
3190 afs_int32 error = 0;
3192 afs_int32 clonetid = 0, onlinetid;
3193 afs_int32 fromtid = 0;
3194 afs_uint32 fromdate = 0;
3195 afs_uint32 thisdate;
3199 manyResults results;
3200 int rwindex, roindex, roclone, roexists;
3201 afs_uint32 rwcrdate = 0;
3202 afs_uint32 rwupdate, clcrdate;
3206 } remembertime[NMAXNSERVERS];
3207 int releasecount = 0;
3208 struct volser_status volstatus;
3211 memset((char *)remembertime, 0, sizeof(remembertime));
3212 memset((char *)&results, 0, sizeof(results));
3214 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3215 if (vcode != VL_RERELEASE)
3216 ONERROR(vcode, afromvol,
3217 "Could not lock the VLDB entry for the volume %u.\n");
3220 /* Get the vldb entry in readable format */
3221 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3222 ONERROR(vcode, afromvol,
3223 "Could not fetch the entry for the volume %u from the VLDB.\n");
3224 MapHostToNetwork(&entry);
3227 EnumerateEntry(&entry);
3229 if (!ISNAMEVALID(entry.name))
3230 ONERROR(VOLSERBADOP, entry.name,
3231 "Volume name %s is too long, rename before releasing.\n");
3232 if (entry.volumeId[RWVOL] != afromvol)
3233 ONERROR(VOLSERBADOP, afromvol,
3234 "The volume %u being released is not a read-write volume.\n");
3235 if (entry.nServers <= 1)
3236 ONERROR(VOLSERBADOP, afromvol,
3237 "Volume %u has no replicas - release operation is meaningless!\n");
3238 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3239 ONERROR(VOLSERBADOP, entry.name,
3240 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3242 /* roclone is true if one of the RO volumes is on the same
3243 * partition as the RW volume. In this case, we make the RO volume
3244 * on the same partition a clone instead of a complete copy.
3247 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3248 roclone = ((roindex == -1) ? 0 : 1);
3249 rwindex = Lp_GetRwIndex(&entry);
3251 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3253 /* Make sure we have a RO volume id to work with */
3254 if (entry.volumeId[ROVOL] == INVALID_BID) {
3255 /* need to get a new RO volume id */
3256 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3257 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3259 entry.volumeId[ROVOL] = roVolId;
3260 MapNetworkToHost(&entry, &storeEntry);
3261 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3262 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3265 /* Will we be completing a previously unfinished release. -force overrides */
3266 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3267 if (entry.serverFlags[i] & ITSROVOL) {
3269 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3272 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3275 /* Determine which volume id to use and see if it exists */
3278 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3279 code = VolumeExists(afromserver, afrompart, cloneVolId);
3280 roexists = ((code == ENODEV) ? 0 : 1);
3282 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3284 ONERROR(-1, afromserver,
3285 "Cannot establish connection with server 0x%x\n");
3289 fullrelease = 1; /* Do a full release if RO clone does not exist */
3291 /* Begin transaction on RW and mark it busy while we query it */
3292 code = AFSVolTransCreate(
3293 fromconn, afromvol, afrompart, ITBusy, &fromtid
3295 ONERROR(code, afromvol,
3296 "Failed to start transaction on RW volume %u\n");
3298 /* Query the creation date for the RW */
3299 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3300 ONERROR(code, afromvol,
3301 "Failed to get the status of RW volume %u\n");
3302 rwcrdate = volstatus.creationDate;
3303 rwupdate = volstatus.updateDate;
3305 /* End transaction on RW */
3306 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3308 ONERROR((code ? code : rcode), afromvol,
3309 "Failed to end transaction on RW volume %u\n");
3311 /* Begin transaction on clone and mark it busy while we query it */
3312 code = AFSVolTransCreate(
3313 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3315 ONERROR(code, cloneVolId,
3316 "Failed to start transaction on RW clone %u\n");
3318 /* Query the creation date for the clone */
3319 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3320 ONERROR(code, cloneVolId,
3321 "Failed to get the status of RW clone %u\n");
3322 clcrdate = volstatus.creationDate;
3324 /* End transaction on clone */
3325 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3327 ONERROR((code ? code : rcode), cloneVolId,
3328 "Failed to end transaction on RW clone %u\n");
3330 if (rwcrdate > clcrdate)
3331 fullrelease = 2;/* Do a full release if RO clone older than RW */
3336 switch (fullrelease) {
3338 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3339 (unsigned long)afromvol);
3342 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3343 (unsigned long)afromvol);
3346 fprintf(STDOUT, "This is a completion of a previous release\n");
3352 /* If the RO clone exists, then if the clone is a temporary
3353 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3354 * (it was recently added), then also delete it. We do not
3355 * want to "reclone" a temporary RO clone.
3358 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3359 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3360 if (code && (code != VNOVOL))
3365 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3366 * write this entry out to the vlserver until after the first
3367 * RO volume is released (temp RO clones don't count).
3369 for (i = 0; i < entry.nServers; i++) {
3370 entry.serverFlags[i] &= ~NEW_REPSITE;
3371 entry.serverFlags[i] |= RO_DONTUSE;
3373 entry.serverFlags[rwindex] |= NEW_REPSITE;
3374 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3376 /* Begin transaction on RW and mark it busy while we clone it */
3378 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3380 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3382 /* Clone or reclone the volume */
3384 VPRINT1("Recloning RW volume %u...", cloneVolId);
3385 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3386 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3390 strcpy(vname, entry.name);
3391 strcat(vname, ".readonly");
3392 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3394 strcpy(vname, "readonly-clone-temp");
3395 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3398 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3400 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3404 /* Get the time the RW was created for future information */
3405 VPRINT1("Getting status of RW volume %u...", afromvol);
3406 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3407 ONERROR(code, afromvol,
3408 "Failed to get the status of the RW volume %u\n");
3410 rwcrdate = volstatus.creationDate;
3411 rwupdate = volstatus.updateDate;
3413 /* End the transaction on the RW volume */
3414 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3415 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3417 ONERROR((code ? code : rcode), afromvol,
3418 "Failed to end cloning transaction on RW %u\n");
3421 /* Remember clone volume ID in case we fail or are interrupted */
3422 entry.cloneId = cloneVolId;
3425 /* Bring the RO clone online - though not if it's a temporary clone */
3426 VPRINT1("Starting transaction on RO clone volume %u...",
3429 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3431 ONERROR(code, cloneVolId,
3432 "Failed to start transaction on volume %u\n");
3435 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3436 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3439 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3440 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3441 ONERROR((code ? code : rcode), cloneVolId,
3442 "Failed to end transaction on RO clone %u\n");
3445 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3447 /* Sleep so that a client searching for an online volume won't
3448 * find the clone offline and then the next RO offline while the
3449 * release brings the clone online and the next RO offline (race).
3450 * There is a fix in the 3.4 client that does not need this sleep
3451 * anymore, but we don't know what clients we have.
3453 if (entry.nServers > 2)
3456 /* Mark the RO clone in the VLDB as a good site (already released) */
3457 entry.serverFlags[roindex] |= NEW_REPSITE;
3458 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3459 entry.flags |= RO_EXISTS;
3463 /* Write out the VLDB entry only if the clone is not a temporary
3464 * clone. If we did this to a temporary clone then we would end
3465 * up marking all the ROs as "old release" making the ROs
3466 * temporarily unavailable.
3468 MapNetworkToHost(&entry, &storeEntry);
3469 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3470 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3471 ONERROR(vcode, entry.name,
3472 "Could not update vldb entry for %s.\n");
3477 /* Now we will release from the clone to the remaining RO replicas.
3478 * The first 2 ROs (counting the non-temporary RO clone) are released
3479 * individually: releasecount. This is to reduce the race condition
3480 * of clients trying to find an on-line RO volume. The remaining ROs
3481 * are released in parallel but no more than half the number of ROs
3482 * (rounded up) at a time: nservers.
3485 strcpy(vname, entry.name);
3486 strcat(vname, ".readonly");
3487 memset(&cookie, 0, sizeof(cookie));
3488 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3489 cookie.type = ROVOL;
3490 cookie.parent = entry.volumeId[RWVOL];
3493 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3495 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3496 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3498 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3500 results.manyResults_val =
3501 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3502 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3504 "Failed to create transaction on the release clone\n");
3506 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3507 memset(times, 0, (sizeof(struct release) * nservers + 1));
3508 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3509 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3511 /* Create a transaction on the cloned volume */
3512 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3514 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3515 if (!fullrelease && code)
3516 ONERROR(VOLSERNOVOL, afromvol,
3517 "Old clone is inaccessible. Try vos release -f %u.\n");
3518 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3521 /* For each index in the VLDB */
3522 for (vldbindex = 0; vldbindex < entry.nServers;) {
3524 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3526 ((volcount < nservers) && (vldbindex < entry.nServers));
3528 /* The first two RO volumes will be released individually.
3529 * The rest are then released in parallel. This is a hack
3530 * for clients not recognizing right away when a RO volume
3531 * comes back on-line.
3533 if ((volcount == 1) && (releasecount < 2))
3536 if (vldbindex == roindex)
3537 continue; /* the clone */
3538 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3539 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))