2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
17 #include <sys/statfs.h>
21 #include <afs/voldefs.h>
24 #include <rx/rx_queue.h>
25 #include <afs/vlserver.h>
27 #include <afs/cellconfig.h>
30 #include <afs/afsint.h>
34 #include <afs/com_err.h>
36 #include <afs/kautils.h>
38 #include <afs/ihandle.h>
40 #include <afs/ntops.h>
42 #include <afs/vnode.h>
43 #include <afs/volume.h>
44 #define ERRCODE_RANGE 8 /* from error_table.h */
45 #define CLOCKSKEW 2 /* not really skew, but resolution */
46 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
48 /* for UV_MoveVolume() recovery */
52 #include "volser_internal.h"
53 #include "volser_prototypes.h"
54 #include "vsutils_prototypes.h"
55 #include "lockprocs_prototypes.h"
57 extern struct ubik_client *cstruct;
58 int verbose = 0, noresolve = 0;
63 afs_int32 vldbEntryIndex;
66 /* Utility macros used by rest of this source file */
67 #define EPRINT(ec, es) \
69 fprintf(STDERR, "\n"); \
70 fprintf(STDERR, (es)); \
74 #define EPRINT1(ec, es, ep1) \
76 fprintf(STDERR, "\n"); \
77 fprintf(STDERR, (es), (ep1)); \
81 #define EPRINT2(ec, es, ep1, ep2) \
83 fprintf(STDERR, "\n"); \
84 fprintf(STDERR, (es), (ep1), (ep2)); \
88 #define EPRINT3(ec, es, ep1, ep2, ep3) \
90 fprintf(STDERR, "\n"); \
91 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
95 #define EGOTO(where, ec, es) \
104 #define EGOTO1(where, ec, es, ep1) \
107 EPRINT1((ec),(es),(ep1)); \
113 #define EGOTO2(where, ec, es, ep1, ep2) \
116 EPRINT2((ec),(es),(ep1),(ep2)); \
122 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
125 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
132 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
133 #define VPRINT1(es, p) \
134 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
135 #define VPRINT2(es, p1, p2) \
136 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
137 #define VPRINT3(es, p1, p2, p3) \
138 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
140 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
141 #define VEPRINT(es) \
142 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
143 #define VEPRINT1(es, p) \
144 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
145 #define VEPRINT2(es, p1, p2) \
146 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
147 #define VEPRINT3(es, p1, p2, p3) \
148 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
150 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
154 /* getting rid of this */
155 #define ERROR_EXIT(code) do { \
161 /* Protos for static routines */
163 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
164 afs_int32 apart, afs_uint32 okvol,
167 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
168 struct rx_connection **connPtr, afs_int32 * transPtr,
169 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
170 afs_int32 *origflags, afs_uint32 tmpVolId);
171 static int SimulateForwardMultiple(struct rx_connection *fromconn,
172 afs_int32 fromtid, afs_int32 fromdate,
173 manyDests * tr, afs_int32 flags,
174 void *cookie, manyResults * results);
175 static int DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
176 afs_int32 apart, int type, afs_uint32 cloneid,
177 char *typestring, char *pname, char *vname, char *suffix,
178 struct volser_status *volstatus, afs_int32 *transPtr);
179 static int DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
180 afs_int32 apart, char *typestring, afs_uint32 atoserver,
181 struct volser_status *volstatus, char *pprefix);
182 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
183 afs_int32 apart, afs_int32 * modentry,
184 afs_uint32 * maxvolid, struct nvldbentry *aentry);
185 static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition,
186 afs_uint32 volumeid);
187 static afs_int32 CheckVldbRWBK(struct nvldbentry * entry,
188 afs_int32 * modified);
189 static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified);
190 static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified,
192 static void dump_sig_handler(int x);
193 static int sortVolumes(const void *a, const void *b);
196 /*map the partition <partId> into partition name <partName>*/
198 MapPartIdIntoName(afs_int32 partId, char *partName)
200 if (partId < 26) { /* what if partId > = 26 ? */
201 strcpy(partName, "/vicep");
202 partName[6] = partId + 'a';
205 } else if (partId < VOLMAXPARTS) {
206 strcpy(partName, "/vicep");
208 partName[6] = 'a' + (partId / 26);
209 partName[7] = 'a' + (partId % 26);
216 PrintError(char *msg, afs_int32 errcode)
218 fprintf(STDERR, "%s", 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");
395 initialize_RXK_error_table();
396 initialize_KTC_error_table();
397 initialize_ACFG_error_table();
398 initialize_VL_error_table();
400 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
401 afs_error_message(errcode));
408 void init_volintInfo(struct volintInfo *vinfo) {
409 memset(vinfo, 0, sizeof(struct volintInfo));
411 vinfo->maxquota = -1;
413 vinfo->creationDate = -1;
414 vinfo->updateDate = -1;
422 static struct rx_securityClass *uvclass = 0;
423 static int uvindex = -1;
424 /* called by VLDBClient_Init to set the security module to be used in the RPC */
426 UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
433 /* bind to volser on <port> <aserver> */
434 /* takes server address in network order, port in host order. dumb */
435 struct rx_connection *
436 UV_Bind(afs_uint32 aserver, afs_int32 port)
438 struct rx_connection *tc;
440 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
446 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
447 afs_int32 partition, char *name, afs_int32 type,
448 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
453 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
455 if (code != VOLSERVOLBUSY)
458 #ifdef AFS_PTHREAD_ENV
461 IOMGR_Sleep(3-retries);
468 AFSVolTransCreate_retry(struct rx_connection *z_conn,
469 afs_int32 volume, afs_int32 partition,
470 afs_int32 flags, afs_int32 * trans)
475 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
476 if (code != VOLSERVOLBUSY)
479 #ifdef AFS_PTHREAD_ENV
482 IOMGR_Sleep(3-retries);
489 /* if <okvol> is allright(indicated by beibg able to
490 * start a transaction, delete the <delvol> */
492 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
493 afs_uint32 okvol, afs_uint32 delvol)
495 afs_int32 error, code, tid, rcode;
500 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
503 code = AFSVolDeleteVolume(aconn, tid);
506 code = AFSVolEndTrans(aconn, tid, &rcode);
513 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
515 code = AFSVolEndTrans(aconn, tid, &rcode);
520 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
523 code = AFSVolDeleteVolume(aconn, tid);
526 code = AFSVolEndTrans(aconn, tid, &rcode);
539 /* called by EmuerateEntry, show vldb entry in a reasonable format */
541 SubEnumerateEntry(struct nvldbentry *entry)
549 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
550 if (entry->flags & VLF_RWEXISTS)
551 fprintf(STDOUT, " valid \n");
553 fprintf(STDOUT, " invalid \n");
554 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
555 if (entry->flags & VLF_ROEXISTS)
556 fprintf(STDOUT, " valid \n");
558 fprintf(STDOUT, " invalid \n");
559 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
560 if (entry->flags & VLF_BACKEXISTS)
561 fprintf(STDOUT, " valid \n");
563 fprintf(STDOUT, " invalid \n");
564 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
565 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
567 if (entry->flags & VLF_RWEXISTS)
568 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
569 if (entry->flags & VLF_ROEXISTS)
570 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
571 if (entry->flags & VLF_BACKEXISTS)
572 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
573 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
574 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
575 fprintf(STDOUT, "\n");
577 fprintf(STDOUT, " number of sites -> %lu\n",
578 (unsigned long)entry->nServers);
579 for (i = 0; i < entry->nServers; i++) {
580 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
583 for (i = 0; i < entry->nServers; i++) {
584 MapPartIdIntoName(entry->serverPartition[i], pname);
585 fprintf(STDOUT, " server %s partition %s ",
586 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
587 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
588 if (entry->serverFlags[i] & VLSF_RWVOL)
589 fprintf(STDOUT, "RW Site ");
591 fprintf(STDOUT, "RO Site ");
593 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
594 fprintf(STDOUT," -- New release");
596 if (!(entry->serverFlags[i] & VLSF_RWVOL))
597 fprintf(STDOUT," -- Old release");
599 if (entry->serverFlags[i] & VLSF_DONTUSE)
600 fprintf(STDOUT, " -- Not released");
602 fprintf(STDOUT, "\n");
609 /*enumerate the vldb entry corresponding to <entry> */
611 EnumerateEntry(struct nvldbentry *entry)
614 fprintf(STDOUT, "\n");
615 fprintf(STDOUT, "%s \n", entry->name);
616 SubEnumerateEntry(entry);
620 /* forcibly remove a volume. Very dangerous call */
622 UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
624 struct rx_connection *tconn;
627 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
629 code = AFSVolNukeVolume(tconn, partid, volid);
630 rx_DestroyConnection(tconn);
636 /* like df. Return usage of <pname> on <server> in <partition> */
638 UV_PartitionInfo64(afs_uint32 server, char *pname,
639 struct diskPartition64 *partition)
641 struct rx_connection *aconn;
644 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
645 code = AFSVolPartitionInfo64(aconn, pname, partition);
646 if (code == RXGEN_OPCODE) {
647 struct diskPartition *dpp = malloc(sizeof(struct diskPartition));
648 code = AFSVolPartitionInfo(aconn, pname, dpp);
650 strncpy(partition->name, dpp->name, 32);
651 strncpy(partition->devName, dpp->devName, 32);
652 partition->lock_fd = dpp->lock_fd;
653 partition->free = dpp->free;
654 partition->minFree = dpp->minFree;
659 fprintf(STDERR, "Could not get information on partition %s\n", pname);
660 PrintError("", code);
663 rx_DestroyConnection(aconn);
667 /* old interface to create volumes */
669 UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
674 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
678 /* less old interface to create volumes */
680 UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
681 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
682 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
684 afs_uint32 roid = 0, bkid = 0;
685 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
686 aspare3, aspare4, anewid, &roid, &bkid);
690 * Create a volume on the given server and partition
692 * @param aserver server to create volume on
693 * @param spart partition to create volume on
694 * @param aname name of new volume
695 * @param aquota quota for new volume
696 * @param anewid contains the desired volume id for the new volume. If
697 * *anewid == 0, a new id will be chosen, and will be placed
698 * in *anewid when UV_CreateVolume3 returns.
699 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
700 * will be unset. If *aroid == 0, an id will be chosen, and
701 * will be placed in *anewid when UV_CreateVolume3 returns.
702 * @param abkid same as aroid, except for the BK volume id instead of the
704 * @return 0 on success, error code otherwise.
707 UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
708 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
709 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
710 afs_uint32 * aroid, afs_uint32 * abkid)
712 struct rx_connection *aconn;
716 afs_int32 rcode, vcode;
718 struct nvldbentry entry, storeEntry; /*the new vldb entry */
719 struct volintInfo tstatus;
724 memset(&storeEntry, 0, sizeof(struct nvldbentry));
726 init_volintInfo(&tstatus);
727 tstatus.maxquota = aquota;
729 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
731 if (aroid && *aroid) {
732 VPRINT1("Using RO volume ID %d.\n", *aroid);
734 if (abkid && *abkid) {
735 VPRINT1("Using BK volume ID %d.\n", *abkid);
739 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
741 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
744 VPRINT1("Using volume ID %d.\n", *anewid);
746 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
747 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
749 if (aroid && *aroid == 0) {
750 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
751 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
754 if (abkid && *abkid == 0) {
755 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
756 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
760 /* rw,ro, bk id are related in the default case */
761 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
763 if (aroid && *aroid != 0) {
764 lastid = max(lastid, *aroid);
766 if (abkid && *abkid != 0) {
767 lastid = max(lastid, *abkid);
769 if (aroid && *aroid == 0) {
772 if (abkid && *abkid == 0) {
777 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
778 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
781 code = AFSVolSetInfo(aconn, tid, &tstatus);
783 EPRINT(code, "Could not change quota, continuing...\n");
785 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
786 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
789 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
791 /* set up the vldb entry for this volume */
792 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
794 entry.serverNumber[0] = aserver; /* this should have another
795 * level of indirection later */
796 entry.serverPartition[0] = apart; /* this should also have
797 * another indirection level */
798 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
799 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
800 entry.volumeId[RWVOL] = *anewid;
801 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
802 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
804 /*map into right byte order, before passing to xdr, the stuff has to be in host
805 * byte order. Xdr converts it into network order */
806 MapNetworkToHost(&entry, &storeEntry);
807 /* create the vldb entry */
808 vcode = VLDB_CreateEntry(&storeEntry);
811 "Could not create a VLDB entry for the volume %s %lu\n",
812 aname, (unsigned long)*anewid);
813 /*destroy the created volume */
814 VPRINT1("Deleting the newly created volume %u\n", *anewid);
815 AFSVolDeleteVolume(aconn, tid);
819 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
820 /* volume created, now terminate the transaction and release the connection */
821 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
822 * the volume will come online anyway when transaction timesout , so if
823 * vldb entry exists then the volume is guaranteed to exist too wrt create */
827 "Failed to end the transaction on the volume %s %lu\n", aname,
828 (unsigned long)*anewid);
835 code = AFSVolEndTrans(aconn, tid, &rcode);
837 fprintf(STDERR, "WARNING: could not end transaction\n");
840 rx_DestroyConnection(aconn);
841 PrintError("", error);
845 /* create a volume, given a server, partition number, volume name --> sends
846 * back new vol id in <anewid>*/
848 UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
851 struct rx_connection *aconn;
854 struct nvldbentry entry, storeEntry; /*the new vldb entry */
856 memset(&storeEntry, 0, sizeof(struct nvldbentry));
858 aconn = (struct rx_connection *)0;
861 /* set up the vldb entry for this volume */
862 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
864 entry.serverNumber[0] = aserver; /* this should have another
865 * level of indirection later */
866 entry.serverPartition[0] = apart; /* this should also have
867 * another indirection level */
868 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
869 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
870 entry.volumeId[RWVOL] = aid;
872 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
873 entry.volumeId[BACKVOL] = *anewid + 2;
875 entry.volumeId[ROVOL] = 0;
876 entry.volumeId[BACKVOL] = 0;
879 /*map into right byte order, before passing to xdr, the stuff has to be in host
880 * byte order. Xdr converts it into network order */
881 MapNetworkToHost(&entry, &storeEntry);
882 /* create the vldb entry */
883 vcode = VLDB_CreateEntry(&storeEntry);
886 "Could not create a VLDB entry for the volume %s %lu\n",
887 aname, (unsigned long)aid);
891 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
895 rx_DestroyConnection(aconn);
896 PrintError("", error);
900 /* Delete the volume <volid>on <aserver> <apart>
901 * the physical entry gets removed from the vldb only if the ref count
905 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
907 struct rx_connection *aconn = (struct rx_connection *)0;
909 afs_int32 code, rcode;
911 struct nvldbentry entry, storeEntry;
913 afs_int32 avoltype = -1, vtype;
914 int notondisk = 0, notinvldb = 0;
916 memset(&storeEntry, 0, sizeof(struct nvldbentry));
918 /* Find and read bhe VLDB entry for this volume */
919 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
921 if (code != VL_NOENT) {
922 EGOTO1(error_exit, code,
923 "Could not lock VLDB entry for the volume %u\n", avolid);
929 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
930 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
932 MapHostToNetwork(&entry);
935 EnumerateEntry(&entry);
938 /* Whether volume is in the VLDB or not. Delete the volume on disk */
939 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
941 code = DoVolDelete(aconn, avolid, apart, "the", 0, NULL, NULL);
951 /* Now update the VLDB entry.
952 * But first, verify we have a VLDB entry.
953 * Whether volume is on disk or not. Delete the volume in VLDB.
958 if (avolid == entry.volumeId[BACKVOL]) {
959 /* Its a backup volume, modify the VLDB entry. Check that the
960 * backup volume is on the server/partition we asked to delete.
962 if (!(entry.flags & VLF_BACKEXISTS) || !Lp_Match(aserver, apart, &entry)) {
963 notinvldb = 2; /* Not on this server and partition */
967 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
969 entry.flags &= ~VLF_BACKEXISTS;
973 else if (avolid == entry.volumeId[ROVOL]) {
974 /* Its a read-only volume, modify the VLDB entry. Check that the
975 * readonly volume is on the server/partition we asked to delete.
976 * If flags does not have RO_EIXSTS set, then this may mean the RO
977 * hasn't been released (and could exist in VLDB).
979 if (!Lp_ROMatch(aserver, apart, &entry)) {
980 notinvldb = 2; /* Not found on this server and partition */
986 "Marking the readonly volume %lu deleted in the VLDB\n",
987 (unsigned long)avolid);
989 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
991 if (!Lp_ROMatch(0, 0, &entry))
992 entry.flags &= ~VLF_ROEXISTS; /* This was the last ro volume */
996 else if (avolid == entry.volumeId[RWVOL]) {
997 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
998 * Check that the readwrite volumes is on the server/partition we
1001 if (!(entry.flags & VLF_RWEXISTS) || !Lp_Match(aserver, apart, &entry)) {
1002 notinvldb = 2; /* Not found on this server and partition */
1006 if (entry.volumeId[BACKVOL]) {
1007 /* Delete backup if it exists */
1008 code = DoVolDelete(aconn, entry.volumeId[BACKVOL], apart,
1009 "the backup", 0, NULL, NULL);
1010 if (code && code != VNOVOL) {
1018 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1019 (unsigned long)avolid,
1021 flags & VLF_BACKEXISTS) ? ", and its backup volume," :
1024 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1026 entry.flags &= ~(VLF_BACKEXISTS | VLF_RWEXISTS);
1029 if (entry.flags & VLF_ROEXISTS)
1030 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1034 notinvldb = 2; /* Not found on this server and partition */
1038 /* Either delete or replace the VLDB entry */
1039 if ((entry.nServers <= 0) || !(entry.flags & (VLF_ROEXISTS | VLF_RWEXISTS))) {
1042 "Last reference to the VLDB entry for %lu - deleting entry\n",
1043 (unsigned long)avolid);
1044 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1045 EGOTO1(error_exit, code,
1046 "Could not delete the VLDB entry for the volume %u \n",
1049 MapNetworkToHost(&entry, &storeEntry);
1051 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1052 (LOCKREL_OPCODE | LOCKREL_AFSID |
1053 LOCKREL_TIMESTAMP));
1054 EGOTO1(error_exit, code,
1055 "Could not update the VLDB entry for the volume %u \n",
1062 EPRINT(error, "\n");
1064 if (notondisk && notinvldb) {
1065 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1066 ((notinvldb == 2) ? "on server and partition" : ""));
1068 error = VOLSERNOVOL;
1069 } else if (notondisk) {
1071 "WARNING: Volume %lu did not exist on the partition\n",
1072 (unsigned long)avolid);
1073 } else if (notinvldb) {
1074 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1075 (unsigned long)avolid,
1076 ((notinvldb == 2) ? "on server and partition" : ""));
1080 code = AFSVolEndTrans(aconn, ttid, &rcode);
1081 code = (code ? code : rcode);
1083 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1084 (unsigned long)avolid);
1085 PrintError("", code);
1093 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1094 (LOCKREL_OPCODE | LOCKREL_AFSID |
1095 LOCKREL_TIMESTAMP));
1098 "Could not release the lock on the VLDB entry for the volume %u \n",
1106 rx_DestroyConnection(aconn);
1110 /* add recovery to UV_MoveVolume */
1112 #define TESTC 0 /* set to test recovery code, clear for production */
1118 do_interrupt(void * unused)
1121 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1122 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1123 * changed. This will avoid some sanity checks, but until a better way
1124 * is found, the only alternative is always crashing and burning on at
1125 * least the stack-overflow check. */
1126 lwp_cpptr->stack = NULL;
1131 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1133 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1134 fprintf(STDOUT, "enter second control-c to exit\n");
1142 sigint_handler(int x)
1144 #ifdef AFS_PTHREAD_ENV
1147 IOMGR_SoftSig(do_interrupt, 0);
1149 (void)signal(SIGINT, sigint_handler);
1153 DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
1154 afs_int32 apart, char *ptypestring, afs_uint32 atoserver,
1155 struct volser_status *volstatus, char *pprefix)
1157 afs_int32 ttid = 0, code, rcode, error = 0;
1158 char *prefix, *typestring;
1167 typestring = ptypestring;
1173 VPRINT3("%sDeleting %s volume %u ...", prefix, typestring, avolid);
1176 AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
1178 /* return early and quietly for VNOVOL; don't continue the attempt to delete. */
1179 if (code == VNOVOL) {
1184 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1188 code = AFSVolGetStatus(aconn, ttid, volstatus);
1189 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1194 AFSVolSetFlags(aconn, ttid,
1195 VTDeleteOnSalvage | VTOutOfService);
1197 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1201 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1202 AFSVolSetForwarding(aconn, ttid, atoserver);
1206 code = AFSVolDeleteVolume(aconn, ttid);
1207 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1211 code = AFSVolEndTrans(aconn, ttid, &rcode);
1216 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1217 prefix, typestring, (unsigned long)avolid);
1223 if (beverbose && !error)
1229 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1230 afs_int32 apart, int type, afs_uint32 cloneid,
1231 char *typestring, char *pname, char *vname, char *suffix,
1232 struct volser_status *volstatus, afs_int32 *transPtr)
1235 afs_int32 ttid = 0, btid = 0;
1236 afs_int32 code = 0, rcode = 0;
1237 afs_int32 error = 0;
1238 int cloneexists = 1;
1240 /* Test to see if the clone volume exists by trying to create
1241 * a transaction on the clone volume. We've assumed the clone exists.
1243 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1245 if (code != VNOVOL) {
1246 EPRINT2(code, "Could not reach the %s volume %lu\n",
1247 typestring, (unsigned long)cloneid);
1251 cloneexists = 0; /* clone volume does not exist */
1254 code = AFSVolEndTrans(aconn, btid, &rcode);
1256 if (code || rcode) {
1258 "Could not end transaction on the previous %s volume %lu\n",
1259 typestring, (unsigned long)cloneid);
1260 error = (code ? code : rcode);
1265 /* Now go ahead and try to clone the RW volume.
1266 * First start a transaction on the RW volume
1268 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1270 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1271 (unsigned long)avolid);
1276 /* Clone or reclone the volume, depending on whether the clone
1277 * volume exists or not
1280 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1282 code = AFSVolReClone(aconn, ttid, cloneid);
1284 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1285 typestring, (unsigned long)cloneid);
1290 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1293 strcpy(cname, pname);
1294 strcat(cname, suffix);
1297 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1300 fprintf(STDERR, "Failed to clone the volume %lu\n",
1301 (unsigned long)avolid);
1310 VPRINT1("Getting status of parent volume %u...", avolid);
1311 code = AFSVolGetStatus(aconn, ttid, volstatus);
1313 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1314 (unsigned long)avolid);
1323 code = AFSVolEndTrans(aconn, ttid, &rcode);
1324 if (code || rcode) {
1325 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1326 (unsigned long)avolid);
1328 error = (code ? code : rcode);
1333 code = AFSVolEndTrans(aconn, btid, &rcode);
1334 if (code || rcode) {
1336 "Could not end transaction on the %s volume %lu\n",
1337 typestring, (unsigned long)cloneid);
1339 error = (code ? code : rcode);
1345 /* Convert volume from RO to RW; adjust the VLDB entry to match.
1346 * The nvldbentry passed to us has already been MapHostToNetwork'd
1351 UV_ConvertRO(afs_uint32 server, afs_uint32 partition, afs_uint32 volid,
1352 struct nvldbentry *entry)
1354 afs_int32 code, i, same;
1355 struct nvldbentry checkEntry, storeEntry;
1357 afs_int32 rwindex = 0;
1358 afs_uint32 rwserver = 0;
1359 afs_int32 roindex = 0;
1360 afs_uint32 roserver = 0;
1361 struct rx_connection *aconn;
1363 memset(&storeEntry, 0, sizeof(struct nvldbentry));
1366 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1370 "Unable to lock volume %lu, code %d\n",
1371 (unsigned long)entry->volumeId[RWVOL],vcode);
1372 PrintError("", vcode);
1376 /* make sure the VLDB entry hasn't changed since we started */
1377 memset(&checkEntry, 0, sizeof(checkEntry));
1378 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1381 "Could not fetch the entry for volume %lu from VLDB\n",
1382 (unsigned long)volid);
1383 PrintError("convertROtoRW ", vcode);
1388 MapHostToNetwork(&checkEntry);
1389 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1390 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1391 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1393 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1394 (unsigned long)volid);
1399 /* extract information from the original entry */
1400 for (i = 0; i < entry->nServers; i++) {
1401 if (entry->serverFlags[i] & VLSF_RWVOL) {
1403 rwserver = entry->serverNumber[i];
1404 /* rwpartition = entry->serverPartition[i]; */
1407 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1408 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1411 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1418 roserver = entry->serverNumber[i];
1419 /* ropartition = entry->serverPartition[i]; */
1426 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1427 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1430 "Converting RO volume %lu to RW volume failed with code %d\n",
1431 (unsigned long)volid, code);
1432 PrintError("convertROtoRW ", code);
1435 /* Update the VLDB to match what we did on disk as much as possible. */
1436 /* If the converted RO was in the VLDB, make it look like the new RW. */
1438 entry->serverFlags[roindex] = VLSF_RWVOL;
1440 /* Add a new site entry for the newly created RW. It's possible
1441 * (but unlikely) that we are already at MAXNSERVERS and that this
1442 * new site will invalidate the whole VLDB entry; however,
1443 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1444 * so we need no extra guard logic here.
1446 afs_int32 newrwindex = entry->nServers;
1447 (entry->nServers)++;
1448 entry->serverNumber[newrwindex] = server;
1449 entry->serverPartition[newrwindex] = partition;
1450 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1452 entry->flags |= VLF_RWEXISTS;
1453 entry->flags &= ~VLF_BACKEXISTS;
1455 /* if the old RW was in the VLDB, remove it by decrementing the number */
1456 /* of servers, replacing the RW entry with the last entry, and zeroing */
1457 /* out the last entry. */
1459 (entry->nServers)--;
1460 if (rwindex != entry->nServers) {
1461 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1462 entry->serverPartition[rwindex] =
1463 entry->serverPartition[entry->nServers];
1464 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1465 entry->serverNumber[entry->nServers] = 0;
1466 entry->serverPartition[entry->nServers] = 0;
1467 entry->serverFlags[entry->nServers] = 0;
1470 entry->flags &= ~VLF_ROEXISTS;
1471 for (i = 0; i < entry->nServers; i++) {
1472 if (entry->serverFlags[i] & VLSF_ROVOL) {
1473 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1474 entry->flags |= VLF_ROEXISTS;
1477 MapNetworkToHost(entry, &storeEntry);
1479 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1480 (LOCKREL_OPCODE | LOCKREL_AFSID |
1481 LOCKREL_TIMESTAMP));
1484 "Warning: volume converted, but vldb update failed with code %d!\n",
1489 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1492 "Unable to unlock volume %lu, code %d\n",
1493 (unsigned long)entry->volumeId[RWVOL],vcode);
1494 PrintError("", vcode);
1500 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1501 * <atopart>. The operation is almost idempotent. The following
1502 * flags are recognized:
1504 * RV_NOCLONE - don't use a copy clone
1508 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1509 afs_uint32 atoserver, afs_int32 atopart, int flags)
1511 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1512 * be changing during the move */
1513 struct rx_connection * volatile toconn;
1514 struct rx_connection * volatile fromconn;
1515 afs_int32 volatile fromtid;
1516 afs_int32 volatile totid;
1517 afs_int32 volatile clonetid;
1518 afs_uint32 volatile newVol;
1519 afs_uint32 volatile volid;
1520 afs_uint32 volatile backupId;
1521 int volatile islocked;
1526 char tmpName[VOLSER_MAXVOLNAME + 1];
1531 struct restoreCookie cookie;
1532 afs_int32 vcode, code;
1533 struct volser_status tstatus;
1534 struct destServer destination;
1536 struct nvldbentry entry, storeEntry;
1539 char in, lf; /* for test code */
1543 #ifdef ENABLE_BUGFIX_1165
1544 volEntries volumeInfo;
1545 struct volintInfo *infop = 0;
1549 fromconn = (struct rx_connection *)0;
1550 toconn = (struct rx_connection *)0;
1560 /* support control-c processing */
1563 (void)signal(SIGINT, sigint_handler);
1567 "\nThere are three tests points - verifies all code paths through recovery.\n");
1568 fprintf(STDOUT, "First test point - operation not started.\n");
1569 fprintf(STDOUT, "...test here (y, n)? ");
1571 if (fscanf(stdin, "%c", &in) < 1)
1573 if (fscanf(stdin, "%c", &lf) < 0) {
1574 /* toss away; don't care */
1577 fprintf(STDOUT, "type control-c\n");
1579 fprintf(stdout, ".");
1584 /* or drop through */
1587 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1588 EGOTO1(mfail, vcode,
1589 "Could not fetch the entry for the volume %u from the VLDB \n",
1592 if (entry.volumeId[RWVOL] != afromvol) {
1593 fprintf(STDERR, "Only RW volume can be moved\n");
1597 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1598 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1601 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1602 EGOTO1(mfail, vcode,
1603 "Could not fetch the entry for the volume %u from the VLDB \n",
1606 backupId = entry.volumeId[BACKVOL];
1607 MapHostToNetwork(&entry);
1609 if (!Lp_Match(afromserver, afrompart, &entry)) {
1610 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1611 if (!Lp_Match(atoserver, atopart, &entry)) {
1612 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1613 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1614 (unsigned long)afromvol);
1615 fprintf(STDERR, "The current site is :");
1616 for (i = 0; i < entry.nServers; i++) {
1617 if (entry.serverFlags[i] == VLSF_RWVOL) {
1619 MapPartIdIntoName(entry.serverPartition[i], pname);
1620 fprintf(STDERR, " server %s partition %s \n",
1621 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1622 hostutil_GetNameByINet(entry.serverNumber[i]),
1627 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1628 (LOCKREL_OPCODE | LOCKREL_AFSID |
1629 LOCKREL_TIMESTAMP));
1630 EGOTO1(mfail, vcode,
1631 " Could not release lock on the VLDB entry for the volume %u \n",
1634 return VOLSERVOLMOVED;
1637 /* delete the volume afromvol on src_server */
1638 /* from-info does not exist but to-info does =>
1639 * we have already done the move, but the volume
1640 * may still be existing physically on from fileserver
1642 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1645 code = DoVolDelete(fromconn, afromvol, afrompart,
1646 "leftover", 0, NULL, NULL);
1647 if (code && code != VNOVOL) {
1652 code = DoVolDelete(fromconn, backupId, afrompart,
1653 "leftover backup", 0, NULL, NULL);
1654 if (code && code != VNOVOL) {
1664 /* From-info matches the vldb info about volid,
1665 * its ok start the move operation, the backup volume
1666 * on the old site is deleted in the process
1668 if (afrompart == atopart) {
1669 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1670 EGOTO2(mfail, error,
1671 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1672 afromserver, error);
1675 EGOTO1(mfail, VOLSERVOLMOVED,
1676 "Warning: Moving volume %u to its home partition ignored!\n",
1682 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1683 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1684 totid = 0; /* initialize to uncreated */
1687 * clone the read/write volume locally.
1690 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1691 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1693 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1697 if (!(flags & RV_NOCLONE)) {
1698 /* Get a clone id */
1699 VPRINT1("Allocating new volume id for clone of volume %u ...",
1702 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1704 EGOTO1(mfail, vcode,
1705 "Could not get an ID for the clone of volume %u from the VLDB\n",
1709 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1710 VPRINT1("Cloning source volume %u ...", afromvol);
1711 strcpy(vname, "move-clone-temp");
1713 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1715 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1720 /* lookup the name of the volume we just cloned */
1722 code = AFSVolGetName(fromconn, fromtid, &volName);
1723 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1726 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1728 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1733 "Failed to end the transaction on the source volume %u\n",
1738 * Create the destination volume
1741 if (!(flags & RV_NOCLONE)) {
1742 /* All of this is to get the fromDate */
1743 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1746 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1750 "Failed to start a transaction on the cloned volume%u\n",
1754 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1756 AFSVolSetFlags(fromconn, clonetid,
1757 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1758 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1762 /* remember time from which we've dumped the volume */
1763 VPRINT1("Getting status of cloned volume %u ...", newVol);
1764 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1766 "Failed to get the status of the cloned volume %u\n",
1770 fromDate = CLOCKADJ(tstatus.creationDate);
1772 /* With RV_NOCLONE, just do a full copy from the source */
1777 #ifdef ENABLE_BUGFIX_1165
1779 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1780 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1781 * don't use this information...
1783 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1784 volumeInfo.volEntries_len = 0;
1785 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1787 "Failed to get the volint Info of the cloned volume %u\n",
1790 infop = (volintInfo *) volumeInfo.volEntries_val;
1791 infop->maxquota = -1; /* Else it will replace the default quota */
1792 infop->creationDate = -1; /* Else it will use the source creation date */
1793 infop->updateDate = -1; /* Else it will use the source update date */
1796 /* create a volume on the target machine */
1798 code = DoVolDelete(toconn, volid, atopart,
1799 "pre-existing destination", 0, NULL, NULL);
1800 if (code && code != VNOVOL) {
1805 VPRINT1("Creating the destination volume %u ...", volid);
1809 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1813 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1817 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1821 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1823 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1825 "Failed to set the flags on the destination volume %u\n", volid);
1829 * Now dump the clone to the new volume
1832 destination.destHost = ntohl(atoserver);
1833 destination.destPort = AFSCONF_VOLUMEPORT;
1834 destination.destSSID = 1;
1836 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1837 cookie.type = RWVOL;
1838 cookie.parent = entry.volumeId[RWVOL];
1841 if (!(flags & RV_NOCLONE)) {
1842 /* Copy the clone to the new volume */
1843 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1846 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1848 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1851 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1852 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1857 "Failed to end the transaction on the cloned volume %u\n",
1863 * reattach to the main-line volume, and incrementally dump it.
1866 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1868 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1871 "Failed to create a transaction on the source volume %u\n",
1875 /* now do the incremental */
1877 ("Doing the%s dump from source to destination for volume %u ... ",
1878 (flags & RV_NOCLONE) ? "" : " incremental",
1881 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1884 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1885 (flags & RV_NOCLONE) ? "" : " incremental");
1888 /* now adjust the flags so that the new volume becomes official */
1889 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1890 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1892 "Failed to set the flags to make old source volume offline\n");
1895 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1896 code = AFSVolSetFlags(toconn, totid, 0);
1898 "Failed to set the flags to make new source volume online\n");
1901 #ifdef ENABLE_BUGFIX_1165
1902 VPRINT1("Setting volume status on destination volume %u ...", volid);
1903 code = AFSVolSetInfo(toconn, totid, infop);
1905 "Failed to set volume status on the destination volume %u\n",
1910 /* put new volume online */
1911 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1912 code = AFSVolEndTrans(toconn, totid, &rcode);
1917 "Failed to end the transaction on the volume %u on the new site\n",
1921 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1922 MapNetworkToHost(&entry, &storeEntry);
1923 storeEntry.flags &= ~VLF_BACKEXISTS;
1927 "Second test point - operation in progress but not complete.\n");
1928 fprintf(STDOUT, "...test here (y, n)? ");
1930 if (fscanf(stdin, "%c", &in) < 1)
1932 if (fscanf(stdin, "%c", &lf) < 0) {
1933 /* toss away, don't care */
1936 fprintf(STDOUT, "type control-c\n");
1938 fprintf(stdout, ".");
1943 /* or drop through */
1946 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1948 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1949 (LOCKREL_OPCODE | LOCKREL_AFSID |
1950 LOCKREL_TIMESTAMP));
1953 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1954 storeEntry.name, (unsigned long)afromvol);
1963 "Third test point - operation complete but no cleanup.\n");
1964 fprintf(STDOUT, "...test here (y, n)? ");
1966 if (fscanf(stdin, "%c", &in) < 1)
1968 if (fscanf(stdin, "%c", &lf) < 0) {
1969 /* toss away; don't care */
1972 fprintf(STDOUT, "type control-c\n");
1974 fprintf(stdout, ".");
1979 /* or drop through */
1982 /* This is tricky. File server is very stupid, and if you mark the volume
1983 * as VTOutOfService, it may mark the *good* instance (if you're moving
1984 * between partitions on the same machine) as out of service. Since
1985 * we're cleaning this code up in DEcorum, we're just going to kludge around
1986 * it for now by removing this call. */
1987 /* already out of service, just zap it now */
1989 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1992 "Failed to set the flags to make the old source volume offline\n");
1996 if (atoserver != afromserver) {
1997 /* set forwarding pointer for moved volumes */
1998 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1999 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
2001 "Failed to set the forwarding pointer for the volume %u\n",
2006 VPRINT1("Deleting old volume %u on source ...", afromvol);
2007 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
2008 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
2012 VPRINT1("Ending transaction on old volume %u on the source ...",
2014 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2019 "Failed to end the transaction on the old volume %u on the source\n",
2023 code = DoVolDelete(fromconn, backupId, afrompart,
2024 "source backup", 0, NULL, NULL);
2025 if (code && code != VNOVOL) {
2030 code = 0; /* no backup volume? that's okay */
2033 if (!(flags & RV_NOCLONE)) {
2034 code = DoVolDelete(fromconn, newVol, afrompart,
2035 "cloned", 0, NULL, NULL);
2037 if (code == VNOVOL) {
2038 EPRINT1(code, "Failed to start transaction on %u\n", newVol);
2049 fprintf(STDOUT, "Fourth test point - operation complete.\n");
2050 fprintf(STDOUT, "...test here (y, n)? ");
2052 if (fscanf(stdin, "%c", &in) < 1)
2054 if (fscanf(stdin, "%c", &lf) < 0) { /* toss away */
2058 fprintf(STDOUT, "type control-c\n");
2060 fprintf(stdout, ".");
2065 /* or drop through */
2068 /* normal cleanup code */
2070 if (entry.flags & VLF_ROEXISTS)
2071 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
2074 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
2076 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2077 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2081 " Could not release the lock on the VLDB entry for the volume %lu \n",
2082 (unsigned long)afromvol);
2090 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2092 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2093 if (code || rcode) {
2096 "Could not end transaction on the source volume %lu\n",
2097 (unsigned long)afromvol);
2099 error = (code ? code : rcode);
2105 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2106 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2107 if (code || rcode) {
2110 "Could not end transaction on the source's clone volume %lu\n",
2111 (unsigned long)newVol);
2113 error = (code ? code : rcode);
2119 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2121 code = AFSVolEndTrans(toconn, totid, &rcode);
2125 "Could not end transaction on destination volume %lu\n",
2126 (unsigned long)afromvol);
2128 error = (code ? code : rcode);
2134 #ifdef ENABLE_BUGFIX_1165
2139 rx_DestroyConnection(fromconn);
2141 rx_DestroyConnection(toconn);
2142 PrintError("", error);
2145 /* come here only when the sky falls */
2150 "vos move: operation interrupted, cleanup in progress...\n");
2151 fprintf(STDOUT, "clear transaction contexts\n");
2155 /* unlock VLDB entry */
2157 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2158 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2159 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2165 VPRINT("Recovery: Ending transaction on clone volume ...");
2166 AFSVolEndTrans(fromconn, clonetid, &rcode);
2170 VPRINT("Recovery: Ending transaction on destination volume ...");
2171 AFSVolEndTrans(toconn, totid, &rcode);
2174 if (fromtid) { /* put it on-line */
2175 VPRINT("Recovery: Setting volume flags on source volume ...");
2176 AFSVolSetFlags(fromconn, fromtid, 0);
2179 VPRINT("Recovery: Ending transaction on source volume ...");
2180 AFSVolEndTrans(fromconn, fromtid, &rcode);
2184 VPRINT("Recovery: Accessing VLDB.\n");
2185 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2187 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2191 MapHostToNetwork(&entry);
2193 /* Delete either the volume on the source location or the target location.
2194 * If the vldb entry still points to the source location, then we know the
2195 * volume move didn't finish so we remove the volume from the target
2196 * location. Otherwise, we remove the volume from the source location.
2198 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2201 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2205 if (volid && toconn) {
2206 code = DoVolDelete(toconn, volid, atopart,
2207 "destination", 0, NULL, "Recovery:");
2208 if (code == VNOVOL) {
2209 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2213 /* put source volume on-line */
2215 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2219 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2225 VPRINT1("Recovery: Setting flags on source volume %u ...",
2227 AFSVolSetFlags(fromconn, fromtid, 0);
2231 ("Recovery: Ending transaction on source volume %u ...",
2233 AFSVolEndTrans(fromconn, fromtid, &rcode);
2237 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2241 } else { /* yep, move complete */
2244 "move complete - attempt cleanup of source partition - no guarantee\n");
2248 /* delete backup volume */
2250 code = DoVolDelete(fromconn, backupId, afrompart,
2251 "backup", 0, NULL, "Recovery:");
2252 if (code == VNOVOL) {
2253 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2256 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2257 (atoserver != afromserver)?atoserver:0,
2259 if (code == VNOVOL) {
2260 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2265 /* common cleanup - delete local clone */
2267 code = DoVolDelete(fromconn, newVol, afrompart,
2268 "clone", 0, NULL, "Recovery:");
2269 if (code == VNOVOL) {
2270 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2274 /* unlock VLDB entry */
2276 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2278 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2279 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2282 done: /* routine cleanup */
2285 #ifdef ENABLE_BUGFIX_1165
2290 rx_DestroyConnection(fromconn);
2292 rx_DestroyConnection(toconn);
2295 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2303 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2304 afs_uint32 atoserver, afs_int32 atopart)
2306 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2307 atoserver, atopart, 0);
2311 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2312 * <atopart>. The new volume is named by <atovolname>. The new volume
2313 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2314 * from the VLDB. the following flags are supported:
2316 * RV_RDONLY - target volume is RO
2317 * RV_OFFLINE - leave target volume offline
2318 * RV_CPINCR - do incremental dump if target exists
2319 * RV_NOVLDB - don't create/update VLDB entry
2320 * RV_NOCLONE - don't use a copy clone
2323 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2324 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2325 afs_uint32 atovolid, int flags)
2327 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2328 * be changing during the copy */
2330 afs_int32 volatile clonetid;
2331 afs_int32 volatile totid;
2332 afs_int32 volatile fromtid;
2333 struct rx_connection * volatile fromconn;
2334 struct rx_connection * volatile toconn;
2335 afs_uint32 volatile cloneVol;
2339 afs_int32 fromDate, cloneFromDate;
2340 struct restoreCookie cookie;
2341 afs_int32 vcode, code;
2344 struct volser_status tstatus;
2345 struct destServer destination;
2346 struct nvldbentry entry, newentry, storeEntry;
2351 fromconn = (struct rx_connection *)0;
2352 toconn = (struct rx_connection *)0;
2360 /* support control-c processing */
2363 (void)signal(SIGINT, sigint_handler);
2365 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2366 EGOTO1(mfail, vcode,
2367 "Could not fetch the entry for the volume %u from the VLDB \n",
2369 MapHostToNetwork(&entry);
2372 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2373 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2374 fromtid = totid = 0; /* initialize to uncreated */
2377 * clone the read/write volume locally.
2381 if (!(flags & RV_NOCLONE)) {
2382 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2384 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2387 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2391 /* Get a clone id */
2392 VPRINT1("Allocating new volume id for clone of volume %u ...",
2396 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2398 EGOTO1(mfail, vcode,
2399 "Could not get an ID for the clone of volume %u from the VLDB\n",
2407 /* Get a new volume id */
2408 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2410 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2411 EGOTO1(mfail, vcode,
2412 "Could not get an ID for the copy of volume %u from the VLDB\n",
2417 if (!(flags & RV_NOCLONE)) {
2418 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2419 VPRINT1("Cloning source volume %u ...", afromvol);
2420 strcpy(vname, "copy-clone-temp");
2423 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2426 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2430 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2432 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2437 "Failed to end the transaction on the source volume %u\n",
2443 * Create the destination volume
2446 if (!(flags & RV_NOCLONE)) {
2447 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2450 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2454 "Failed to start a transaction on the cloned volume%u\n",
2458 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2460 AFSVolSetFlags(fromconn, clonetid,
2461 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2462 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2466 /* remember time from which we've dumped the volume */
2467 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2468 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2470 "Failed to get the status of the cloned volume %u\n",
2474 fromDate = CLOCKADJ(tstatus.creationDate);
2479 /* create a volume on the target machine */
2482 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2485 if ((flags & RV_CPINCR)) {
2486 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2487 code = AFSVolGetStatus(toconn, totid, &tstatus);
2489 "Failed to get the status of the pre-existing volume %u\n",
2493 /* Using the update date should be OK here, but add some fudge */
2494 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2495 if ((flags & RV_NOCLONE))
2496 fromDate = cloneFromDate;
2498 /* XXX We should check that the source volume's creationDate is
2499 * XXX not newer than the existing target volume, and if not,
2500 * XXX throw away the existing target and do a full dump. */
2505 /* Delete the existing volume.
2506 * While we are deleting the volume in these steps, the transaction
2507 * we started against the cloned volume (clonetid above) will be
2508 * sitting idle. It will get cleaned up after 600 seconds
2510 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2511 code = AFSVolDeleteVolume(toconn, totid);
2513 "Could not delete the pre-existing volume %u on destination\n",
2518 ("Ending transaction on pre-existing volume %u on destination ...",
2520 code = AFSVolEndTrans(toconn, totid, &rcode);
2525 "Could not end the transaction on pre-existing volume %u on destination\n",
2530 VPRINT1("Creating the destination volume %u ...", newVol);
2533 AFSVolCreateVolume(toconn, atopart, atovolname,
2534 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2535 newVol, &newVol, &tmp);
2537 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2541 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2543 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2545 "Failed to set the flags on the destination volume %u\n", newVol);
2550 destination.destHost = ntohl(atoserver);
2551 destination.destPort = AFSCONF_VOLUMEPORT;
2552 destination.destSSID = 1;
2554 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2555 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2560 * Now dump the clone to the new volume
2563 if (!(flags & RV_NOCLONE)) {
2564 /* XXX probably should have some code here that checks to see if
2565 * XXX we are copying to same server and partition - if so, just
2566 * XXX use a clone to save disk space */
2568 /* Copy the clone to the new volume */
2569 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2572 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2574 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2578 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2579 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2584 "Failed to end the transaction on the cloned volume %u\n",
2590 * reattach to the main-line volume, and incrementally dump it.
2593 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2595 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2598 "Failed to create a transaction on the source volume %u\n",
2602 /* now do the incremental */
2604 ("Doing the%s dump from source to destination for volume %u ... ",
2605 (flags & RV_NOCLONE) ? "" : " incremental",
2608 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2611 "Failed to do the%s dump from old site to new site\n",
2612 (flags & RV_NOCLONE) ? "" : " incremental");
2615 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2616 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2617 code = AFSVolSetFlags(toconn, totid, volflag);
2619 "Failed to set the flags to make destination volume online\n");
2622 /* put new volume online */
2623 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2624 code = AFSVolEndTrans(toconn, totid, &rcode);
2629 "Failed to end the transaction on the destination volume %u\n",
2633 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2634 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2639 "Failed to end the transaction on the source volume %u\n",
2645 if (!(flags & RV_NOCLONE)) {
2646 code = DoVolDelete(fromconn, cloneVol, afrompart,
2647 "cloned", 0, NULL, NULL);
2649 if (code == VNOVOL) {
2650 EPRINT1(code, "Failed to start transaction on %u\n", cloneVol);
2657 if (!(flags & RV_NOVLDB)) {
2658 /* create the vldb entry for the copied volume */
2659 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2660 newentry.nServers = 1;
2661 newentry.serverNumber[0] = atoserver;
2662 newentry.serverPartition[0] = atopart;
2663 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2664 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2665 newentry.volumeId[RWVOL] = newVol;
2666 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2667 newentry.volumeId[BACKVOL] = 0;
2668 newentry.cloneId = 0;
2669 /*map into right byte order, before passing to xdr, the stuff has to be in host
2670 * byte order. Xdr converts it into network order */
2671 MapNetworkToHost(&newentry, &storeEntry);
2672 /* create the vldb entry */
2673 vcode = VLDB_CreateEntry(&storeEntry);
2676 "Could not create a VLDB entry for the volume %s %lu\n",
2677 atovolname, (unsigned long)newVol);
2678 /*destroy the created volume */
2679 VPRINT1("Deleting the newly created volume %u\n", newVol);
2680 AFSVolDeleteVolume(toconn, totid);
2684 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2688 /* normal cleanup code */
2691 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2693 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2694 if (code || rcode) {
2697 "Could not end transaction on the source volume %lu\n",
2698 (unsigned long)afromvol);
2700 error = (code ? code : rcode);
2706 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2708 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2709 if (code || rcode) {
2712 "Could not end transaction on the source's clone volume %lu\n",
2713 (unsigned long)cloneVol);
2715 error = (code ? code : rcode);
2721 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2723 code = AFSVolEndTrans(toconn, totid, &rcode);
2727 "Could not end transaction on destination volume %lu\n",
2728 (unsigned long)newVol);
2730 error = (code ? code : rcode);
2735 rx_DestroyConnection(fromconn);
2737 rx_DestroyConnection(toconn);
2738 PrintError("", error);
2741 /* come here only when the sky falls */
2746 "vos copy: operation interrupted, cleanup in progress...\n");
2747 fprintf(STDOUT, "clear transaction contexts\n");
2752 VPRINT("Recovery: Ending transaction on clone volume ...");
2753 AFSVolEndTrans(fromconn, clonetid, &rcode);
2757 VPRINT("Recovery: Ending transaction on destination volume ...");
2758 AFSVolEndTrans(toconn, totid, &rcode);
2761 if (fromtid) { /* put it on-line */
2762 VPRINT("Recovery: Ending transaction on source volume ...");
2763 AFSVolEndTrans(fromconn, fromtid, &rcode);
2767 VPRINT("Recovery: Accessing VLDB.\n");
2768 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2770 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2774 MapHostToNetwork(&entry);
2776 /* common cleanup - delete local clone */
2778 code = DoVolDelete(fromconn, cloneVol, afrompart,
2779 "clone", 0, NULL, "Recovery:");
2780 if (code == VNOVOL) {
2781 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", cloneVol);
2785 done: /* routine cleanup */
2787 rx_DestroyConnection(fromconn);
2789 rx_DestroyConnection(toconn);
2792 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2800 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2801 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2803 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2804 atovolname, atoserver, atopart, 0, 0);
2809 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2810 * if one already exists, update it
2814 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2816 struct rx_connection *aconn = (struct rx_connection *)0;
2817 afs_int32 ttid = 0, btid = 0;
2818 afs_uint32 backupID;
2819 afs_int32 code = 0, rcode = 0;
2820 struct nvldbentry entry, storeEntry;
2821 afs_int32 error = 0;
2822 int vldblocked = 0, vldbmod = 0;
2824 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2826 /* the calls to VLDB will succeed only if avolid is a RW volume,
2827 * since we are following the RW hash chain for searching */
2828 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2831 "Could not fetch the entry for the volume %lu from the VLDB \n",
2832 (unsigned long)avolid);
2836 MapHostToNetwork(&entry);
2838 /* These operations require the VLDB be locked since it means the VLDB
2839 * will change or the vldb is already locked.
2841 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2842 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2843 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2845 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2848 "Could not lock the VLDB entry for the volume %lu\n",
2849 (unsigned long)avolid);
2855 /* Reread the vldb entry */
2856 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2859 "Could not fetch the entry for the volume %lu from the VLDB \n",
2860 (unsigned long)avolid);
2864 MapHostToNetwork(&entry);
2867 if (!ISNAMEVALID(entry.name)) {
2868 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2870 error = VOLSERBADNAME;
2874 backupID = entry.volumeId[BACKVOL];
2875 if (backupID == INVALID_BID) {
2876 /* Get a backup volume id from the VLDB and update the vldb
2879 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2882 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2883 (unsigned long)avolid);
2887 entry.volumeId[BACKVOL] = backupID;
2891 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2892 entry.name, NULL, ".backup", NULL, NULL);
2898 /* Mark vldb as backup exists */
2899 if (!(entry.flags & VLF_BACKEXISTS)) {
2900 entry.flags |= VLF_BACKEXISTS;
2904 /* Now go back to the backup volume and bring it on line */
2905 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2908 "Failed to start a transaction on the backup volume %lu\n",
2909 (unsigned long)backupID);
2914 code = AFSVolSetFlags(aconn, btid, 0);
2916 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2917 (unsigned long)backupID);
2922 code = AFSVolEndTrans(aconn, btid, &rcode);
2924 if (code || rcode) {
2926 "Failed to end the transaction on the backup volume %lu\n",
2927 (unsigned long)backupID);
2928 error = (code ? code : rcode);
2932 /* Will update the vldb below */
2936 code = AFSVolEndTrans(aconn, ttid, &rcode);
2937 if (code || rcode) {
2938 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2939 (unsigned long)avolid);
2941 error = (code ? code : rcode);
2946 code = AFSVolEndTrans(aconn, btid, &rcode);
2947 if (code || rcode) {
2949 "Could not end transaction the backup volume %lu\n",
2950 (unsigned long)backupID);
2952 error = (code ? code : rcode);
2956 /* Now update the vldb - if modified */
2959 MapNetworkToHost(&entry, &storeEntry);
2961 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2962 (LOCKREL_OPCODE | LOCKREL_AFSID |
2963 LOCKREL_TIMESTAMP));
2966 "Could not update the VLDB entry for the volume %lu \n",
2967 (unsigned long)avolid);
2973 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2974 (LOCKREL_OPCODE | LOCKREL_AFSID |
2975 LOCKREL_TIMESTAMP));
2978 "Could not unlock the VLDB entry for the volume %lu \n",
2979 (unsigned long)avolid);
2987 rx_DestroyConnection(aconn);
2989 PrintError("", error);
2993 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2994 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2995 * The new volume is named by <aname>, or by appending ".clone" to
2996 * the existing name if <aname> is NULL. The following flags are
2999 * RV_RDONLY - target volume is RO
3000 * RV_OFFLINE - leave target volume offline
3004 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
3005 afs_uint32 acloneid, char *aname, int flags)
3007 struct rx_connection *aconn = (struct rx_connection *)0;
3008 afs_int32 ttid = 0, btid = 0;
3009 afs_int32 code = 0, rcode = 0;
3010 char vname[VOLSER_MAXVOLNAME + 1];
3011 afs_int32 error = 0;
3012 volEntries volumeInfo;
3015 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
3018 volumeInfo.volEntries_val = (volintInfo *) 0;
3019 volumeInfo.volEntries_len = 0;
3020 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
3022 fprintf(stderr, "Could not get info for volume %lu\n",
3023 (unsigned long)avolid);
3027 strncpy(vname, volumeInfo.volEntries_val[0].name,
3028 VOLSER_OLDMAXVOLNAME - 7);
3029 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
3030 strcat(vname, ".clone");
3032 if (volumeInfo.volEntries_val)
3033 free(volumeInfo.volEntries_val);
3037 /* Get a clone id */
3038 VPRINT1("Allocating new volume id for clone of volume %u ...",
3040 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
3042 "Could not get an ID for the clone of volume %u from the VLDB\n",
3047 if (flags & RV_RWONLY)
3048 type = readwriteVolume;
3049 else if (flags & RV_RDONLY)
3050 type = readonlyVolume;
3052 type = backupVolume;
3054 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
3055 NULL, aname, NULL, NULL, NULL);
3061 /* Now go back to the backup volume and bring it on line */
3062 if (!(flags & RV_OFFLINE)) {
3063 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3066 "Failed to start a transaction on the clone volume %lu\n",
3067 (unsigned long)acloneid);
3072 code = AFSVolSetFlags(aconn, btid, 0);
3074 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3075 (unsigned long)acloneid);
3080 code = AFSVolEndTrans(aconn, btid, &rcode);
3082 if (code || rcode) {
3084 "Failed to end the transaction on the clone volume %lu\n",
3085 (unsigned long)acloneid);
3086 error = (code ? code : rcode);
3093 code = AFSVolEndTrans(aconn, ttid, &rcode);
3094 if (code || rcode) {
3095 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3096 (unsigned long)avolid);
3098 error = (code ? code : rcode);
3103 code = AFSVolEndTrans(aconn, btid, &rcode);
3104 if (code || rcode) {
3106 "Could not end transaction on the clone volume %lu\n",
3107 (unsigned long)acloneid);
3109 error = (code ? code : rcode);
3114 rx_DestroyConnection(aconn);
3116 PrintError("", error);
3120 #define ONERROR(ec, ep, es) do { \
3122 fprintf(STDERR, (es), (ep)); \
3127 #define ONERROR0(ec, es) do { \
3129 fprintf(STDERR, (es)); \
3134 #define ERROREXIT(ec) do { \
3139 /* Get a "transaction" on this replica. Create the volume
3140 * if necessary. Return the time from which a dump should
3141 * be made (0 if it's a new volume)
3144 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3145 struct rx_connection **connPtr, afs_int32 * transPtr,
3146 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3147 afs_int32 *origflags, afs_uint32 tmpVolId)
3150 struct volser_status tstatus;
3155 *connPtr = (struct rx_connection *)0;
3160 /* get connection to the replication site */
3161 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3163 goto fail; /* server is down */
3165 volid = vldbEntryPtr->volumeId[ROVOL];
3169 AFSVolTransCreate_retry(*connPtr, volid,
3170 vldbEntryPtr->serverPartition[index], ITOffline,
3173 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3174 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3175 * site. Don't trust any data on it, since it is possible we
3176 * have encountered some temporary volume from some other
3177 * incomplete volume operation. It is difficult to detect if
3178 * that has happened vs if this is a legit volume, so just
3179 * delete it to be safe. */
3181 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3182 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3183 serverNumber[index], hoststr) :
3184 hostutil_GetNameByINet(vldbEntryPtr->
3185 serverNumber[index]));
3187 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3189 PrintError("Failed to delete RO_DONTUSE site: ", code);
3193 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3199 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3206 /* emulate what TransCreate would have returned, so we try to
3207 * create the volume below */
3212 /* If the volume does not exist, create it */
3213 if (!volid || code) {
3214 char volname[VL_MAXNAMELEN];
3217 if (volid && (code != VNOVOL)) {
3218 PrintError("Failed to start a transaction on the RO volume.\n",
3223 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3225 if (strlcat(volname,
3226 tmpVolId?".roclone":".readonly",
3227 sizeof(volname)) >= sizeof(volname)) {
3229 PrintError("Volume name is too long\n", code);
3235 "Creating new volume %lu on replication site %s: ",
3236 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3237 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3238 serverNumber[index], hoststr) :
3239 hostutil_GetNameByINet(vldbEntryPtr->
3240 serverNumber[index]));
3245 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3247 vldbEntryPtr->volumeId[RWVOL],
3248 tmpVolId?&tmpVolId:&volid,
3251 PrintError("Failed to create the ro volume: ", code);
3254 vldbEntryPtr->volumeId[ROVOL] = volid;
3258 /* The following is a bit redundant, since create sets these flags by default */
3260 AFSVolSetFlags(*connPtr, *transPtr,
3261 VTDeleteOnSalvage | VTOutOfService);
3263 PrintError("Failed to set flags on the ro volume: ", code);
3268 /* Otherwise, the transaction did succeed, so get the creation date of the
3269 * latest RO volume on the replication site
3272 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3273 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3274 serverNumber[index], hoststr) :
3275 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3277 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3279 PrintError("Failed to get status of volume on destination: ",
3284 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3289 code = DoVolClone(*connPtr, volid,
3290 vldbEntryPtr->serverPartition[index],
3291 readonlyVolume, tmpVolId, "temporary",
3292 vldbEntryPtr->name, NULL, ".roclone", NULL,
3297 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3298 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3305 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3309 if (tcode && tcode != ENOENT)
3310 PrintError("Could not end transaction on a ro volume: ", tcode);
3317 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3318 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3319 void *cookie, manyResults * results)
3323 for (i = 0; i < tr->manyDests_len; i++) {
3324 results->manyResults_val[i] =
3325 AFSVolForward(fromconn, fromtid, fromdate,
3326 &(tr->manyDests_val[i].server),
3327 tr->manyDests_val[i].trans, cookie);
3333 * Check if a trans has timed out, and recreate it if necessary.
3335 * @param[in] aconn RX connection to the relevant server
3336 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3337 * contains the new trans ID on success
3338 * @param[in] apart Partition for the transaction
3339 * @param[in] astat The status of the original transaction
3341 * @return operation status
3342 * @retval 0 existing transaction is still valid, or we managed to recreate
3343 * the trans successfully
3344 * @retval nonzero Fatal error; bail out
3347 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3348 struct volser_status *astat)
3350 struct volser_status new_status;
3353 memset(&new_status, 0, sizeof(new_status));
3354 code = AFSVolGetStatus(aconn, *atid, &new_status);
3356 if (code == ENOENT) {
3358 VPRINT1("Old transaction on cloned volume %lu timed out, "
3359 "restarting transaction\n", (long unsigned) astat->volID);
3360 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3363 PrintError("Failed to recreate cloned RO volume transaction\n",
3368 memset(&new_status, 0, sizeof(new_status));
3369 code = AFSVolGetStatus(aconn, *atid, &new_status);
3371 PrintError("Failed to get status on recreated transaction\n",
3376 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3377 PrintError("Recreated transaction on cloned RO volume, but "
3378 "the volume has changed!\n", 0);
3382 PrintError("Unable to get status of current cloned RO transaction\n",
3387 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3389 PrintError("Internal error: current GetStatus does not match "
3390 "original GetStatus?\n", 0);
3399 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3400 struct rx_connection **toconns, struct release *times,
3403 afs_int32 s, code = 0, rcode = 0;
3404 /* End the transactions and destroy the connections */
3405 for (s = 0; s < volcount; s++) {
3406 if (replicas[s].trans) {
3407 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3409 replicas[s].trans = 0;
3413 if ((s == 0) || (code != ENOENT)) {
3414 PrintError("Could not end transaction on a ro volume: ",
3418 ("Transaction timed out on a ro volume. Will retry.\n",
3420 if (times[s].vldbEntryIndex < *vldbindex)
3421 *vldbindex = times[s].vldbEntryIndex;
3426 rx_DestroyConnection(toconns[s]);
3432 * Release a volume to read-only sites
3434 * Release volume <afromvol> on <afromserver> <afrompart> to all its RO
3435 * sites (complete release), unless the previous release was incomplete
3436 * or new sites were added without changes to the read-write volume, in
3437 * which case we bring the remaining volumes up to date with the volumes
3438 * that were previously released successfully.
3440 * Will create a clone from the RW, then dump the clone out to
3441 * the remaining replicas. If there is more than 1 RO sites,
3442 * ensure that the VLDB says at least one RO is available all
3443 * the time: Influences when we write back the VLDB entry.
3445 * @param[in] afromvol volume to be released
3446 * @param[in] afromserver server containing afromvol
3447 * @param[in] afrompart partition containing afromvol
3448 * @param[in] flags bitmap of options
3449 * REL_COMPLETE - force a complete release
3450 * REL_FULLDUMPS - force full dumps
3453 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3454 afs_int32 afrompart, int flags)
3458 afs_int32 vcode, rcode, tcode;
3459 afs_uint32 cloneVolId = 0, roVolId;
3460 struct replica *replicas = 0;
3461 struct nvldbentry entry, storeEntry;
3462 int i, volcount = 0, m, vldbindex;
3464 struct restoreCookie cookie;
3465 struct rx_connection **toconns = 0;
3466 struct release *times = 0;
3468 struct rx_connection *fromconn = (struct rx_connection *)0;
3469 afs_int32 error = 0;
3471 afs_int32 clonetid = 0, onlinetid;
3472 afs_int32 fromtid = 0;
3473 afs_uint32 fromdate = 0;
3474 afs_uint32 thisdate;
3478 manyResults results;
3479 int rwindex, roindex, roclone, roexists;
3480 afs_uint32 rwcrdate = 0, rwupdate = 0;
3481 afs_uint32 clcrdate;
3485 } remembertime[NMAXNSERVERS];
3486 int releasecount = 0;
3487 struct volser_status volstatus;
3489 afs_int32 origflags[NMAXNSERVERS];
3490 struct volser_status orig_status;
3491 int notreleased = 0;
3492 int tried_justnewsites = 0;
3493 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3494 int sites = 0; /* number of ro sites */
3495 int new_sites = 0; /* number of ro sites markes as new */
3498 CR_PARTIAL = 0x0000, /**< just new sites added or recover from a previous failed release */
3499 CR_FORCED = 0x0001, /**< complete: forced by caller */
3500 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3501 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3502 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3503 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3504 } complete_release_t;
3506 complete_release_t complete_release = CR_PARTIAL;
3508 memset(remembertime, 0, sizeof(remembertime));
3509 memset(&results, 0, sizeof(results));
3510 memset(origflags, 0, sizeof(origflags));
3512 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3513 if (vcode != VL_RERELEASE)
3514 ONERROR(vcode, afromvol,
3515 "Could not lock the VLDB entry for the volume %u.\n");
3518 /* Get the vldb entry in readable format */
3519 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3520 ONERROR(vcode, afromvol,
3521 "Could not fetch the entry for the volume %u from the VLDB.\n");
3522 MapHostToNetwork(&entry);
3525 EnumerateEntry(&entry);
3527 if (!ISNAMEVALID(entry.name))
3528 ONERROR(VOLSERBADOP, entry.name,
3529 "Volume name %s is too long, rename before releasing.\n");
3530 if (entry.volumeId[RWVOL] != afromvol)
3531 ONERROR(VOLSERBADOP, afromvol,
3532 "The volume %u being released is not a read-write volume.\n");
3533 if (entry.nServers <= 1)
3534 ONERROR(VOLSERBADOP, afromvol,
3535 "Volume %u has no replicas - release operation is meaningless!\n");
3536 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3537 ONERROR(VOLSERBADOP, entry.name,
3538 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3540 /* roclone is true if one of the RO volumes is on the same
3541 * partition as the RW volume. In this case, we make the RO volume
3542 * on the same partition a clone instead of a complete copy.
3545 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3546 roclone = ((roindex == -1) ? 0 : 1);
3547 rwindex = Lp_GetRwIndex(&entry);
3549 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3551 /* Make sure we have a RO volume id to work with */
3552 if (entry.volumeId[ROVOL] == INVALID_BID) {
3553 /* need to get a new RO volume id */
3554 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3555 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3557 entry.volumeId[ROVOL] = roVolId;
3558 MapNetworkToHost(&entry, &storeEntry);
3559 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3560 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3564 * Determine if this is to be a complete release or a recovery of a
3565 * previous unfinished release. The previous release is considered to be
3566 * unfinished when the clone was successfully distributed to at least one
3567 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3570 * The caller can override the vldb flags check using the -force
3571 * or -force-reclone flag, to force this to be a complete release.
3573 for (i = 0; i < entry.nServers; i++) {
3574 if (entry.serverFlags[i] & VLSF_ROVOL) {
3576 if (entry.serverFlags[i] & VLSF_NEWREPSITE)