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 DoVolOnline(struct nvldbentry *vldbEntryPtr, afs_uint32 avolid,
176 int index, char *vname, struct rx_connection *connPtr);
177 static int DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
178 afs_int32 apart, int type, afs_uint32 cloneid,
179 char *typestring, char *pname, char *vname, char *suffix,
180 struct volser_status *volstatus, afs_int32 *transPtr);
181 static int DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
182 afs_int32 apart, char *typestring, afs_uint32 atoserver,
183 struct volser_status *volstatus, char *pprefix);
184 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
185 afs_int32 apart, afs_int32 * modentry,
186 afs_uint32 * maxvolid, struct nvldbentry *aentry);
187 static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition,
188 afs_uint32 volumeid);
189 static afs_int32 CheckVldbRWBK(struct nvldbentry * entry,
190 afs_int32 * modified);
191 static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified);
192 static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified,
194 static void dump_sig_handler(int x);
195 static int sortVolumes(const void *a, const void *b);
198 /*map the partition <partId> into partition name <partName>*/
200 MapPartIdIntoName(afs_int32 partId, char *partName)
202 if (partId < 26) { /* what if partId > = 26 ? */
203 strcpy(partName, "/vicep");
204 partName[6] = partId + 'a';
207 } else if (partId < VOLMAXPARTS) {
208 strcpy(partName, "/vicep");
210 partName[6] = 'a' + (partId / 26);
211 partName[7] = 'a' + (partId % 26);
218 PrintError(char *msg, afs_int32 errcode)
220 fprintf(STDERR, "%s", msg);
221 /*replace by a big switch statement */
226 fprintf(STDERR, "Possible communication failure\n");
229 fprintf(STDERR, "Volume needs to be salvaged\n");
232 fprintf(STDERR, "Bad vnode number quoted\n");
236 "Volume not attached, does not exist, or not on line\n");
239 fprintf(STDERR, "Volume already exists\n");
242 fprintf(STDERR, "Volume is not in service\n");
245 fprintf(STDERR, "Volume is off line\n");
248 fprintf(STDERR, "Volume is already on line\n");
251 fprintf(STDERR, "Partition is full\n");
254 fprintf(STDERR, "Volume max quota exceeded\n");
257 fprintf(STDERR, "Volume temporarily unavailable\n");
260 fprintf(STDERR, "Volume has moved to another server\n");
263 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
266 fprintf(STDERR, "VLDB: a read terminated too early\n");
269 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
272 fprintf(STDERR, "VLDB: internal creation failure\n");
275 fprintf(STDERR, "VLDB: no such entry\n");
278 fprintf(STDERR, "VLDB: vldb database is empty\n");
281 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
284 fprintf(STDERR, "VLDB: volume name is illegal\n");
287 fprintf(STDERR, "VLDB: index was out of range\n");
290 fprintf(STDERR, "VLDB: bad volume type\n");
293 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
295 case VL_BADPARTITION:
296 fprintf(STDERR, "VLDB: bad partition number\n");
299 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
302 fprintf(STDERR, "VLDB: no such repsite server exists\n");
304 case VL_DUPREPSERVER:
305 fprintf(STDERR, "VLDB: replication site server already exists\n");
308 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
311 fprintf(STDERR, "VLDB: illegal reference count number\n");
313 case VL_SIZEEXCEEDED:
314 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
317 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
319 case VL_BADVOLIDBUMP:
320 fprintf(STDERR, "VLDB: illegal max volid increment\n");
322 case VL_IDALREADYHASHED:
323 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
326 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
329 fprintf(STDERR, "VLDB: bad volume operation code\n");
331 case VL_BADRELLOCKTYPE:
332 fprintf(STDERR, "VLDB: bad release lock type\n");
335 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
337 case VL_BADSERVERFLAG:
338 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
341 fprintf(STDERR, "VLDB: no permission access for call\n");
343 case VOLSERREAD_DUMPERROR:
345 "VOLSER: Problems encountered in reading the dump file !\n");
347 case VOLSERDUMPERROR:
348 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
350 case VOLSERATTACH_ERROR:
351 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
353 case VOLSERDETACH_ERROR:
354 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
356 case VOLSERILLEGAL_PARTITION:
357 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
359 case VOLSERBAD_ACCESS:
360 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
362 case VOLSERVLDB_ERROR:
363 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
366 fprintf(STDERR, "VOLSER: error in volume name\n");
369 fprintf(STDERR, "VOLSER: volume has moved\n");
372 fprintf(STDERR, "VOLSER: illegal operation\n");
374 case VOLSERBADRELEASE:
375 fprintf(STDERR, "VOLSER: release could not be completed\n");
378 fprintf(STDERR, "VOLSER: volume is busy\n");
380 case VOLSERNO_MEMORY:
381 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
385 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
387 case VOLSERMULTIRWVOL:
389 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
393 "VOLSER: not all entries were successfully processed\n");
397 initialize_RXK_error_table();
398 initialize_KTC_error_table();
399 initialize_ACFG_error_table();
400 initialize_VL_error_table();
402 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
403 afs_error_message(errcode));
410 void init_volintInfo(struct volintInfo *vinfo) {
411 memset(vinfo, 0, sizeof(struct volintInfo));
413 vinfo->maxquota = -1;
415 vinfo->creationDate = -1;
416 vinfo->updateDate = -1;
424 static struct rx_securityClass *uvclass = 0;
425 static int uvindex = -1;
426 /* called by VLDBClient_Init to set the security module to be used in the RPC */
428 UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
435 /* bind to volser on <port> <aserver> */
436 /* takes server address in network order, port in host order. dumb */
437 struct rx_connection *
438 UV_Bind(afs_uint32 aserver, afs_int32 port)
440 struct rx_connection *tc;
442 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
448 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
449 afs_int32 partition, char *name, afs_int32 type,
450 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
455 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
457 if (code != VOLSERVOLBUSY)
460 #ifdef AFS_PTHREAD_ENV
463 IOMGR_Sleep(3-retries);
470 AFSVolTransCreate_retry(struct rx_connection *z_conn,
471 afs_int32 volume, afs_int32 partition,
472 afs_int32 flags, afs_int32 * trans)
477 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
478 if (code != VOLSERVOLBUSY)
481 #ifdef AFS_PTHREAD_ENV
484 IOMGR_Sleep(3-retries);
491 /* if <okvol> is allright(indicated by beibg able to
492 * start a transaction, delete the <delvol> */
494 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
495 afs_uint32 okvol, afs_uint32 delvol)
497 afs_int32 error, code, tid, rcode;
502 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
505 code = AFSVolDeleteVolume(aconn, tid);
508 code = AFSVolEndTrans(aconn, tid, &rcode);
515 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
517 code = AFSVolEndTrans(aconn, tid, &rcode);
522 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
525 code = AFSVolDeleteVolume(aconn, tid);
528 code = AFSVolEndTrans(aconn, tid, &rcode);
541 /* called by EmuerateEntry, show vldb entry in a reasonable format */
543 SubEnumerateEntry(struct nvldbentry *entry)
551 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
552 if (entry->flags & VLF_RWEXISTS)
553 fprintf(STDOUT, " valid \n");
555 fprintf(STDOUT, " invalid \n");
556 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
557 if (entry->flags & VLF_ROEXISTS)
558 fprintf(STDOUT, " valid \n");
560 fprintf(STDOUT, " invalid \n");
561 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
562 if (entry->flags & VLF_BACKEXISTS)
563 fprintf(STDOUT, " valid \n");
565 fprintf(STDOUT, " invalid \n");
566 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
567 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
569 if (entry->flags & VLF_RWEXISTS)
570 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
571 if (entry->flags & VLF_ROEXISTS)
572 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
573 if (entry->flags & VLF_BACKEXISTS)
574 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
575 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
576 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
577 fprintf(STDOUT, "\n");
579 fprintf(STDOUT, " number of sites -> %lu\n",
580 (unsigned long)entry->nServers);
581 for (i = 0; i < entry->nServers; i++) {
582 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
585 for (i = 0; i < entry->nServers; i++) {
586 MapPartIdIntoName(entry->serverPartition[i], pname);
587 fprintf(STDOUT, " server %s partition %s ",
588 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
589 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
590 if (entry->serverFlags[i] & VLSF_RWVOL)
591 fprintf(STDOUT, "RW Site ");
593 fprintf(STDOUT, "RO Site ");
595 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
596 fprintf(STDOUT," -- New release");
598 if (!(entry->serverFlags[i] & VLSF_RWVOL))
599 fprintf(STDOUT," -- Old release");
601 if (entry->serverFlags[i] & VLSF_DONTUSE)
602 fprintf(STDOUT, " -- Not released");
604 fprintf(STDOUT, "\n");
611 /*enumerate the vldb entry corresponding to <entry> */
613 EnumerateEntry(struct nvldbentry *entry)
616 fprintf(STDOUT, "\n");
617 fprintf(STDOUT, "%s \n", entry->name);
618 SubEnumerateEntry(entry);
622 /* forcibly remove a volume. Very dangerous call */
624 UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
626 struct rx_connection *tconn;
629 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
631 code = AFSVolNukeVolume(tconn, partid, volid);
632 rx_DestroyConnection(tconn);
638 /* like df. Return usage of <pname> on <server> in <partition> */
640 UV_PartitionInfo64(afs_uint32 server, char *pname,
641 struct diskPartition64 *partition)
643 struct rx_connection *aconn;
646 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
647 code = AFSVolPartitionInfo64(aconn, pname, partition);
648 if (code == RXGEN_OPCODE) {
649 struct diskPartition *dpp = malloc(sizeof(struct diskPartition));
650 code = AFSVolPartitionInfo(aconn, pname, dpp);
652 strncpy(partition->name, dpp->name, 32);
653 strncpy(partition->devName, dpp->devName, 32);
654 partition->lock_fd = dpp->lock_fd;
655 partition->free = dpp->free;
656 partition->minFree = dpp->minFree;
661 fprintf(STDERR, "Could not get information on partition %s\n", pname);
662 PrintError("", code);
665 rx_DestroyConnection(aconn);
669 /* old interface to create volumes */
671 UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
676 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
680 /* less old interface to create volumes */
682 UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
683 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
684 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
686 afs_uint32 roid = 0, bkid = 0;
687 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
688 aspare3, aspare4, anewid, &roid, &bkid);
692 * Create a volume on the given server and partition
694 * @param aserver server to create volume on
695 * @param spart partition to create volume on
696 * @param aname name of new volume
697 * @param aquota quota for new volume
698 * @param anewid contains the desired volume id for the new volume. If
699 * *anewid == 0, a new id will be chosen, and will be placed
700 * in *anewid when UV_CreateVolume3 returns.
701 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
702 * will be unset. If *aroid == 0, an id will be chosen, and
703 * will be placed in *anewid when UV_CreateVolume3 returns.
704 * @param abkid same as aroid, except for the BK volume id instead of the
706 * @return 0 on success, error code otherwise.
709 UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
710 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
711 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
712 afs_uint32 * aroid, afs_uint32 * abkid)
714 struct rx_connection *aconn;
718 afs_int32 rcode, vcode;
720 struct nvldbentry entry, storeEntry; /*the new vldb entry */
721 struct volintInfo tstatus;
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 aconn = (struct rx_connection *)0;
859 /* set up the vldb entry for this volume */
860 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
862 entry.serverNumber[0] = aserver; /* this should have another
863 * level of indirection later */
864 entry.serverPartition[0] = apart; /* this should also have
865 * another indirection level */
866 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
867 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
868 entry.volumeId[RWVOL] = aid;
870 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
871 entry.volumeId[BACKVOL] = *anewid + 2;
873 entry.volumeId[ROVOL] = 0;
874 entry.volumeId[BACKVOL] = 0;
877 /*map into right byte order, before passing to xdr, the stuff has to be in host
878 * byte order. Xdr converts it into network order */
879 MapNetworkToHost(&entry, &storeEntry);
880 /* create the vldb entry */
881 vcode = VLDB_CreateEntry(&storeEntry);
884 "Could not create a VLDB entry for the volume %s %lu\n",
885 aname, (unsigned long)aid);
889 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
893 rx_DestroyConnection(aconn);
894 PrintError("", error);
898 /* Delete the volume <volid>on <aserver> <apart>
899 * the physical entry gets removed from the vldb only if the ref count
903 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
905 struct rx_connection *aconn = (struct rx_connection *)0;
907 afs_int32 code, rcode;
909 struct nvldbentry entry, storeEntry;
911 afs_int32 avoltype = -1, vtype;
912 int notondisk = 0, notinvldb = 0;
914 /* Find and read bhe VLDB entry for this volume */
915 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
917 if (code != VL_NOENT) {
918 EGOTO1(error_exit, code,
919 "Could not lock VLDB entry for the volume %u\n", avolid);
925 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
926 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
928 MapHostToNetwork(&entry);
931 EnumerateEntry(&entry);
934 /* Whether volume is in the VLDB or not. Delete the volume on disk */
935 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
937 code = DoVolDelete(aconn, avolid, apart, "the", 0, NULL, NULL);
947 /* Now update the VLDB entry.
948 * But first, verify we have a VLDB entry.
949 * Whether volume is on disk or not. Delete the volume in VLDB.
954 if (avolid == entry.volumeId[BACKVOL]) {
955 /* Its a backup volume, modify the VLDB entry. Check that the
956 * backup volume is on the server/partition we asked to delete.
958 if (!(entry.flags & VLF_BACKEXISTS) || !Lp_Match(aserver, apart, &entry)) {
959 notinvldb = 2; /* Not on this server and partition */
963 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
965 entry.flags &= ~VLF_BACKEXISTS;
969 else if (avolid == entry.volumeId[ROVOL]) {
970 /* Its a read-only volume, modify the VLDB entry. Check that the
971 * readonly volume is on the server/partition we asked to delete.
972 * If flags does not have RO_EIXSTS set, then this may mean the RO
973 * hasn't been released (and could exist in VLDB).
975 if (!Lp_ROMatch(aserver, apart, &entry)) {
976 notinvldb = 2; /* Not found on this server and partition */
982 "Marking the readonly volume %lu deleted in the VLDB\n",
983 (unsigned long)avolid);
985 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
987 if (!Lp_ROMatch(0, 0, &entry))
988 entry.flags &= ~VLF_ROEXISTS; /* This was the last ro volume */
992 else if (avolid == entry.volumeId[RWVOL]) {
993 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
994 * Check that the readwrite volumes is on the server/partition we
997 if (!(entry.flags & VLF_RWEXISTS) || !Lp_Match(aserver, apart, &entry)) {
998 notinvldb = 2; /* Not found on this server and partition */
1002 if (entry.volumeId[BACKVOL]) {
1003 /* Delete backup if it exists */
1004 code = DoVolDelete(aconn, entry.volumeId[BACKVOL], apart,
1005 "the backup", 0, NULL, NULL);
1006 if (code && code != VNOVOL) {
1014 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1015 (unsigned long)avolid,
1017 flags & VLF_BACKEXISTS) ? ", and its backup volume," :
1020 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1022 entry.flags &= ~(VLF_BACKEXISTS | VLF_RWEXISTS);
1025 if (entry.flags & VLF_ROEXISTS)
1026 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1030 notinvldb = 2; /* Not found on this server and partition */
1034 /* Either delete or replace the VLDB entry */
1035 if ((entry.nServers <= 0) || !(entry.flags & (VLF_ROEXISTS | VLF_RWEXISTS))) {
1038 "Last reference to the VLDB entry for %lu - deleting entry\n",
1039 (unsigned long)avolid);
1040 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1041 EGOTO1(error_exit, code,
1042 "Could not delete the VLDB entry for the volume %u \n",
1045 MapNetworkToHost(&entry, &storeEntry);
1047 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1048 (LOCKREL_OPCODE | LOCKREL_AFSID |
1049 LOCKREL_TIMESTAMP));
1050 EGOTO1(error_exit, code,
1051 "Could not update the VLDB entry for the volume %u \n",
1058 EPRINT(error, "\n");
1060 if (notondisk && notinvldb) {
1061 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1062 ((notinvldb == 2) ? "on server and partition" : ""));
1064 error = VOLSERNOVOL;
1065 } else if (notondisk) {
1067 "WARNING: Volume %lu did not exist on the partition\n",
1068 (unsigned long)avolid);
1069 } else if (notinvldb) {
1070 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1071 (unsigned long)avolid,
1072 ((notinvldb == 2) ? "on server and partition" : ""));
1076 code = AFSVolEndTrans(aconn, ttid, &rcode);
1077 code = (code ? code : rcode);
1079 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1080 (unsigned long)avolid);
1081 PrintError("", code);
1089 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1090 (LOCKREL_OPCODE | LOCKREL_AFSID |
1091 LOCKREL_TIMESTAMP));
1094 "Could not release the lock on the VLDB entry for the volume %u \n",
1102 rx_DestroyConnection(aconn);
1106 /* add recovery to UV_MoveVolume */
1108 #define TESTC 0 /* set to test recovery code, clear for production */
1114 do_interrupt(void * unused)
1117 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1118 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1119 * changed. This will avoid some sanity checks, but until a better way
1120 * is found, the only alternative is always crashing and burning on at
1121 * least the stack-overflow check. */
1122 lwp_cpptr->stack = NULL;
1127 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1129 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1130 fprintf(STDOUT, "enter second control-c to exit\n");
1138 sigint_handler(int x)
1140 #ifdef AFS_PTHREAD_ENV
1143 IOMGR_SoftSig(do_interrupt, 0);
1145 (void)signal(SIGINT, sigint_handler);
1149 DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
1150 afs_int32 apart, char *ptypestring, afs_uint32 atoserver,
1151 struct volser_status *volstatus, char *pprefix)
1153 afs_int32 ttid = 0, code, rcode, error = 0;
1154 char *prefix, *typestring;
1163 typestring = ptypestring;
1169 VPRINT3("%sDeleting %s volume %u ...", prefix, typestring, avolid);
1172 AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
1174 /* return early and quietly for VNOVOL; don't continue the attempt to delete. */
1175 if (code == VNOVOL) {
1180 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1184 code = AFSVolGetStatus(aconn, ttid, volstatus);
1185 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1190 AFSVolSetFlags(aconn, ttid,
1191 VTDeleteOnSalvage | VTOutOfService);
1193 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1197 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1198 AFSVolSetForwarding(aconn, ttid, atoserver);
1202 code = AFSVolDeleteVolume(aconn, ttid);
1203 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1207 code = AFSVolEndTrans(aconn, ttid, &rcode);
1212 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1213 prefix, typestring, (unsigned long)avolid);
1219 if (beverbose && !error)
1225 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1226 afs_int32 apart, int type, afs_uint32 cloneid,
1227 char *typestring, char *pname, char *vname, char *suffix,
1228 struct volser_status *volstatus, afs_int32 *transPtr)
1231 afs_int32 ttid = 0, btid = 0;
1232 afs_int32 code = 0, rcode = 0;
1233 afs_int32 error = 0;
1234 int cloneexists = 1;
1236 /* Test to see if the clone volume exists by trying to create
1237 * a transaction on the clone volume. We've assumed the clone exists.
1239 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1241 if (code != VNOVOL) {
1242 EPRINT2(code, "Could not reach the %s volume %lu\n",
1243 typestring, (unsigned long)cloneid);
1247 cloneexists = 0; /* clone volume does not exist */
1250 code = AFSVolEndTrans(aconn, btid, &rcode);
1252 if (code || rcode) {
1254 "Could not end transaction on the previous %s volume %lu\n",
1255 typestring, (unsigned long)cloneid);
1256 error = (code ? code : rcode);
1261 /* Now go ahead and try to clone the RW volume.
1262 * First start a transaction on the RW volume
1264 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1266 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1267 (unsigned long)avolid);
1272 /* Clone or reclone the volume, depending on whether the clone
1273 * volume exists or not
1276 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1278 code = AFSVolReClone(aconn, ttid, cloneid);
1280 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1281 typestring, (unsigned long)cloneid);
1286 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1289 strcpy(cname, pname);
1290 strcat(cname, suffix);
1293 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1296 fprintf(STDERR, "Failed to clone the volume %lu\n",
1297 (unsigned long)avolid);
1306 VPRINT1("Getting status of parent volume %u...", avolid);
1307 code = AFSVolGetStatus(aconn, ttid, volstatus);
1309 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1310 (unsigned long)avolid);
1319 code = AFSVolEndTrans(aconn, ttid, &rcode);
1320 if (code || rcode) {
1321 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1322 (unsigned long)avolid);
1324 error = (code ? code : rcode);
1329 code = AFSVolEndTrans(aconn, btid, &rcode);
1330 if (code || rcode) {
1332 "Could not end transaction on the %s volume %lu\n",
1333 typestring, (unsigned long)cloneid);
1335 error = (code ? code : rcode);
1341 /* Convert volume from RO to RW; adjust the VLDB entry to match.
1342 * The nvldbentry passed to us has already been MapHostToNetwork'd
1347 UV_ConvertRO(afs_uint32 server, afs_uint32 partition, afs_uint32 volid,
1348 struct nvldbentry *entry)
1350 afs_int32 code, i, same;
1351 struct nvldbentry checkEntry, storeEntry;
1353 afs_int32 rwindex = 0;
1354 afs_uint32 rwserver = 0;
1355 afs_int32 roindex = 0;
1356 afs_uint32 roserver = 0;
1357 struct rx_connection *aconn;
1360 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1364 "Unable to lock volume %lu, code %d\n",
1365 (unsigned long)entry->volumeId[RWVOL],vcode);
1366 PrintError("", vcode);
1370 /* make sure the VLDB entry hasn't changed since we started */
1371 memset(&checkEntry, 0, sizeof(checkEntry));
1372 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1375 "Could not fetch the entry for volume %lu from VLDB\n",
1376 (unsigned long)volid);
1377 PrintError("convertROtoRW ", vcode);
1382 MapHostToNetwork(&checkEntry);
1383 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1384 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1385 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1387 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1388 (unsigned long)volid);
1393 /* extract information from the original entry */
1394 for (i = 0; i < entry->nServers; i++) {
1395 if (entry->serverFlags[i] & VLSF_RWVOL) {
1397 rwserver = entry->serverNumber[i];
1398 /* rwpartition = entry->serverPartition[i]; */
1401 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1402 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1405 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1412 roserver = entry->serverNumber[i];
1413 /* ropartition = entry->serverPartition[i]; */
1420 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1421 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1424 "Converting RO volume %lu to RW volume failed with code %d\n",
1425 (unsigned long)volid, code);
1426 PrintError("convertROtoRW ", code);
1429 /* Update the VLDB to match what we did on disk as much as possible. */
1430 /* If the converted RO was in the VLDB, make it look like the new RW. */
1432 entry->serverFlags[roindex] = VLSF_RWVOL;
1434 /* Add a new site entry for the newly created RW. It's possible
1435 * (but unlikely) that we are already at MAXNSERVERS and that this
1436 * new site will invalidate the whole VLDB entry; however,
1437 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1438 * so we need no extra guard logic here.
1440 afs_int32 newrwindex = entry->nServers;
1441 (entry->nServers)++;
1442 entry->serverNumber[newrwindex] = server;
1443 entry->serverPartition[newrwindex] = partition;
1444 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1446 entry->flags |= VLF_RWEXISTS;
1447 entry->flags &= ~VLF_BACKEXISTS;
1449 /* if the old RW was in the VLDB, remove it by decrementing the number */
1450 /* of servers, replacing the RW entry with the last entry, and zeroing */
1451 /* out the last entry. */
1453 (entry->nServers)--;
1454 if (rwindex != entry->nServers) {
1455 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1456 entry->serverPartition[rwindex] =
1457 entry->serverPartition[entry->nServers];
1458 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1459 entry->serverNumber[entry->nServers] = 0;
1460 entry->serverPartition[entry->nServers] = 0;
1461 entry->serverFlags[entry->nServers] = 0;
1464 entry->flags &= ~VLF_ROEXISTS;
1465 for (i = 0; i < entry->nServers; i++) {
1466 if (entry->serverFlags[i] & VLSF_ROVOL) {
1467 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1468 entry->flags |= VLF_ROEXISTS;
1471 MapNetworkToHost(entry, &storeEntry);
1473 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1474 (LOCKREL_OPCODE | LOCKREL_AFSID |
1475 LOCKREL_TIMESTAMP));
1478 "Warning: volume converted, but vldb update failed with code %d!\n",
1483 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1486 "Unable to unlock volume %lu, code %d\n",
1487 (unsigned long)entry->volumeId[RWVOL],vcode);
1488 PrintError("", vcode);
1494 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1495 * <atopart>. The operation is almost idempotent. The following
1496 * flags are recognized:
1498 * RV_NOCLONE - don't use a copy clone
1502 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1503 afs_uint32 atoserver, afs_int32 atopart, int flags)
1505 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1506 * be changing during the move */
1507 struct rx_connection * volatile toconn;
1508 struct rx_connection * volatile fromconn;
1509 afs_int32 volatile fromtid;
1510 afs_int32 volatile totid;
1511 afs_int32 volatile clonetid;
1512 afs_uint32 volatile newVol;
1513 afs_uint32 volatile volid;
1514 afs_uint32 volatile backupId;
1515 int volatile islocked;
1520 char tmpName[VOLSER_MAXVOLNAME + 1];
1525 struct restoreCookie cookie;
1526 afs_int32 vcode, code;
1527 struct volser_status tstatus;
1528 struct destServer destination;
1530 struct nvldbentry entry, storeEntry;
1533 char in, lf; /* for test code */
1537 #ifdef ENABLE_BUGFIX_1165
1538 volEntries volumeInfo;
1539 struct volintInfo *infop = 0;
1543 fromconn = (struct rx_connection *)0;
1544 toconn = (struct rx_connection *)0;
1554 /* support control-c processing */
1557 (void)signal(SIGINT, sigint_handler);
1561 "\nThere are three tests points - verifies all code paths through recovery.\n");
1562 fprintf(STDOUT, "First test point - operation not started.\n");
1563 fprintf(STDOUT, "...test here (y, n)? ");
1565 if (fscanf(stdin, "%c", &in) < 1)
1567 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1570 fprintf(STDOUT, "type control-c\n");
1572 fprintf(stdout, ".");
1577 /* or drop through */
1580 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1581 EGOTO1(mfail, vcode,
1582 "Could not fetch the entry for the volume %u from the VLDB \n",
1585 if (entry.volumeId[RWVOL] != afromvol) {
1586 fprintf(STDERR, "Only RW volume can be moved\n");
1590 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1591 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1594 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1595 EGOTO1(mfail, vcode,
1596 "Could not fetch the entry for the volume %u from the VLDB \n",
1599 backupId = entry.volumeId[BACKVOL];
1600 MapHostToNetwork(&entry);
1602 if (!Lp_Match(afromserver, afrompart, &entry)) {
1603 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1604 if (!Lp_Match(atoserver, atopart, &entry)) {
1605 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1606 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1607 (unsigned long)afromvol);
1608 fprintf(STDERR, "The current site is :");
1609 for (i = 0; i < entry.nServers; i++) {
1610 if (entry.serverFlags[i] == VLSF_RWVOL) {
1612 MapPartIdIntoName(entry.serverPartition[i], pname);
1613 fprintf(STDERR, " server %s partition %s \n",
1614 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1615 hostutil_GetNameByINet(entry.serverNumber[i]),
1620 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1621 (LOCKREL_OPCODE | LOCKREL_AFSID |
1622 LOCKREL_TIMESTAMP));
1623 EGOTO1(mfail, vcode,
1624 " Could not release lock on the VLDB entry for the volume %u \n",
1627 return VOLSERVOLMOVED;
1630 /* delete the volume afromvol on src_server */
1631 /* from-info does not exist but to-info does =>
1632 * we have already done the move, but the volume
1633 * may still be existing physically on from fileserver
1635 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1638 code = DoVolDelete(fromconn, afromvol, afrompart,
1639 "leftover", 0, NULL, NULL);
1640 if (code && code != VNOVOL) {
1645 code = DoVolDelete(fromconn, backupId, afrompart,
1646 "leftover backup", 0, NULL, NULL);
1647 if (code && code != VNOVOL) {
1657 /* From-info matches the vldb info about volid,
1658 * its ok start the move operation, the backup volume
1659 * on the old site is deleted in the process
1661 if (afrompart == atopart) {
1662 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1663 EGOTO2(mfail, error,
1664 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1665 afromserver, error);
1668 EGOTO1(mfail, VOLSERVOLMOVED,
1669 "Warning: Moving volume %u to its home partition ignored!\n",
1675 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1676 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1677 totid = 0; /* initialize to uncreated */
1680 * clone the read/write volume locally.
1683 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1684 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1686 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1690 if (!(flags & RV_NOCLONE)) {
1691 /* Get a clone id */
1692 VPRINT1("Allocating new volume id for clone of volume %u ...",
1695 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1697 EGOTO1(mfail, vcode,
1698 "Could not get an ID for the clone of volume %u from the VLDB\n",
1702 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1703 VPRINT1("Cloning source volume %u ...", afromvol);
1704 strcpy(vname, "move-clone-temp");
1706 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1708 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1713 /* lookup the name of the volume we just cloned */
1715 code = AFSVolGetName(fromconn, fromtid, &volName);
1716 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1719 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1721 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1726 "Failed to end the transaction on the source volume %u\n",
1731 * Create the destination volume
1734 if (!(flags & RV_NOCLONE)) {
1735 /* All of this is to get the fromDate */
1736 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1739 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1743 "Failed to start a transaction on the cloned volume%u\n",
1747 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1749 AFSVolSetFlags(fromconn, clonetid,
1750 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1751 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1755 /* remember time from which we've dumped the volume */
1756 VPRINT1("Getting status of cloned volume %u ...", newVol);
1757 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1759 "Failed to get the status of the cloned volume %u\n",
1763 fromDate = CLOCKADJ(tstatus.creationDate);
1765 /* With RV_NOCLONE, just do a full copy from the source */
1770 #ifdef ENABLE_BUGFIX_1165
1772 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1773 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1774 * don't use this information...
1776 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1777 volumeInfo.volEntries_len = 0;
1778 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1780 "Failed to get the volint Info of the cloned volume %u\n",
1783 infop = (volintInfo *) volumeInfo.volEntries_val;
1784 infop->maxquota = -1; /* Else it will replace the default quota */
1785 infop->creationDate = -1; /* Else it will use the source creation date */
1786 infop->updateDate = -1; /* Else it will use the source update date */
1789 /* create a volume on the target machine */
1791 code = DoVolDelete(toconn, volid, atopart,
1792 "pre-existing destination", 0, NULL, NULL);
1793 if (code && code != VNOVOL) {
1798 VPRINT1("Creating the destination volume %u ...", volid);
1802 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1806 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1810 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1814 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1816 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1818 "Failed to set the flags on the destination volume %u\n", volid);
1822 * Now dump the clone to the new volume
1825 destination.destHost = ntohl(atoserver);
1826 destination.destPort = AFSCONF_VOLUMEPORT;
1827 destination.destSSID = 1;
1829 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1830 cookie.type = RWVOL;
1831 cookie.parent = entry.volumeId[RWVOL];
1834 if (!(flags & RV_NOCLONE)) {
1835 /* Copy the clone to the new volume */
1836 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1839 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1841 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1844 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1845 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1850 "Failed to end the transaction on the cloned volume %u\n",
1856 * reattach to the main-line volume, and incrementally dump it.
1859 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1861 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1864 "Failed to create a transaction on the source volume %u\n",
1868 /* now do the incremental */
1870 ("Doing the%s dump from source to destination for volume %u ... ",
1871 (flags & RV_NOCLONE) ? "" : " incremental",
1874 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1877 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1878 (flags & RV_NOCLONE) ? "" : " incremental");
1881 /* now adjust the flags so that the new volume becomes official */
1882 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1883 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1885 "Failed to set the flags to make old source volume offline\n");
1888 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1889 code = AFSVolSetFlags(toconn, totid, 0);
1891 "Failed to set the flags to make new source volume online\n");
1894 #ifdef ENABLE_BUGFIX_1165
1895 VPRINT1("Setting volume status on destination volume %u ...", volid);
1896 code = AFSVolSetInfo(toconn, totid, infop);
1898 "Failed to set volume status on the destination volume %u\n",
1903 /* put new volume online */
1904 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1905 code = AFSVolEndTrans(toconn, totid, &rcode);
1910 "Failed to end the transaction on the volume %u on the new site\n",
1914 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1915 MapNetworkToHost(&entry, &storeEntry);
1916 storeEntry.flags &= ~VLF_BACKEXISTS;
1920 "Second test point - operation in progress but not complete.\n");
1921 fprintf(STDOUT, "...test here (y, n)? ");
1923 if (fscanf(stdin, "%c", &in) < 1)
1925 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1928 fprintf(STDOUT, "type control-c\n");
1930 fprintf(stdout, ".");
1935 /* or drop through */
1938 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1940 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1941 (LOCKREL_OPCODE | LOCKREL_AFSID |
1942 LOCKREL_TIMESTAMP));
1945 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1946 storeEntry.name, (unsigned long)afromvol);
1955 "Third test point - operation complete but no cleanup.\n");
1956 fprintf(STDOUT, "...test here (y, n)? ");
1958 if (fscanf(stdin, "%c", &in) < 1)
1960 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1963 fprintf(STDOUT, "type control-c\n");
1965 fprintf(stdout, ".");
1970 /* or drop through */
1973 /* This is tricky. File server is very stupid, and if you mark the volume
1974 * as VTOutOfService, it may mark the *good* instance (if you're moving
1975 * between partitions on the same machine) as out of service. Since
1976 * we're cleaning this code up in DEcorum, we're just going to kludge around
1977 * it for now by removing this call. */
1978 /* already out of service, just zap it now */
1980 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1983 "Failed to set the flags to make the old source volume offline\n");
1987 if (atoserver != afromserver) {
1988 /* set forwarding pointer for moved volumes */
1989 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1990 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1992 "Failed to set the forwarding pointer for the volume %u\n",
1997 VPRINT1("Deleting old volume %u on source ...", afromvol);
1998 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1999 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
2003 VPRINT1("Ending transaction on old volume %u on the source ...",
2005 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2010 "Failed to end the transaction on the old volume %u on the source\n",
2014 code = DoVolDelete(fromconn, backupId, afrompart,
2015 "source backup", 0, NULL, NULL);
2016 if (code && code != VNOVOL) {
2021 code = 0; /* no backup volume? that's okay */
2024 if (!(flags & RV_NOCLONE)) {
2025 code = DoVolDelete(fromconn, newVol, afrompart,
2026 "cloned", 0, NULL, NULL);
2028 if (code == VNOVOL) {
2029 EPRINT1(code, "Failed to start transaction on %u\n", newVol);
2040 fprintf(STDOUT, "Fourth test point - operation complete.\n");
2041 fprintf(STDOUT, "...test here (y, n)? ");
2043 if (fscanf(stdin, "%c", &in) < 1)
2045 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
2048 fprintf(STDOUT, "type control-c\n");
2050 fprintf(stdout, ".");
2055 /* or drop through */
2058 /* normal cleanup code */
2060 if (entry.flags & VLF_ROEXISTS)
2061 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
2064 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
2066 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2067 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2071 " Could not release the lock on the VLDB entry for the volume %lu \n",
2072 (unsigned long)afromvol);
2080 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2082 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2083 if (code || rcode) {
2086 "Could not end transaction on the source volume %lu\n",
2087 (unsigned long)afromvol);
2089 error = (code ? code : rcode);
2095 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2096 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2097 if (code || rcode) {
2100 "Could not end transaction on the source's clone volume %lu\n",
2101 (unsigned long)newVol);
2103 error = (code ? code : rcode);
2109 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2111 code = AFSVolEndTrans(toconn, totid, &rcode);
2115 "Could not end transaction on destination volume %lu\n",
2116 (unsigned long)afromvol);
2118 error = (code ? code : rcode);
2124 #ifdef ENABLE_BUGFIX_1165
2129 rx_DestroyConnection(fromconn);
2131 rx_DestroyConnection(toconn);
2132 PrintError("", error);
2135 /* come here only when the sky falls */
2140 "vos move: operation interrupted, cleanup in progress...\n");
2141 fprintf(STDOUT, "clear transaction contexts\n");
2145 /* unlock VLDB entry */
2147 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2148 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2149 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2155 VPRINT("Recovery: Ending transaction on clone volume ...");
2156 AFSVolEndTrans(fromconn, clonetid, &rcode);
2160 VPRINT("Recovery: Ending transaction on destination volume ...");
2161 AFSVolEndTrans(toconn, totid, &rcode);
2164 if (fromtid) { /* put it on-line */
2165 VPRINT("Recovery: Setting volume flags on source volume ...");
2166 AFSVolSetFlags(fromconn, fromtid, 0);
2169 VPRINT("Recovery: Ending transaction on source volume ...");
2170 AFSVolEndTrans(fromconn, fromtid, &rcode);
2174 VPRINT("Recovery: Accessing VLDB.\n");
2175 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2177 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2181 MapHostToNetwork(&entry);
2183 /* Delete either the volume on the source location or the target location.
2184 * If the vldb entry still points to the source location, then we know the
2185 * volume move didn't finish so we remove the volume from the target
2186 * location. Otherwise, we remove the volume from the source location.
2188 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2191 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2195 if (volid && toconn) {
2196 code = DoVolDelete(toconn, volid, atopart,
2197 "destination", 0, NULL, "Recovery:");
2198 if (code == VNOVOL) {
2199 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2203 /* put source volume on-line */
2205 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2209 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2215 VPRINT1("Recovery: Setting flags on source volume %u ...",
2217 AFSVolSetFlags(fromconn, fromtid, 0);
2221 ("Recovery: Ending transaction on source volume %u ...",
2223 AFSVolEndTrans(fromconn, fromtid, &rcode);
2227 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2231 } else { /* yep, move complete */
2234 "move complete - attempt cleanup of source partition - no guarantee\n");
2238 /* delete backup volume */
2240 code = DoVolDelete(fromconn, backupId, afrompart,
2241 "backup", 0, NULL, "Recovery:");
2242 if (code == VNOVOL) {
2243 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2246 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2247 (atoserver != afromserver)?atoserver:0,
2249 if (code == VNOVOL) {
2250 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2255 /* common cleanup - delete local clone */
2257 code = DoVolDelete(fromconn, newVol, afrompart,
2258 "clone", 0, NULL, "Recovery:");
2259 if (code == VNOVOL) {
2260 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2264 /* unlock VLDB entry */
2266 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2268 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2269 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2272 done: /* routine cleanup */
2275 #ifdef ENABLE_BUGFIX_1165
2280 rx_DestroyConnection(fromconn);
2282 rx_DestroyConnection(toconn);
2285 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2293 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2294 afs_uint32 atoserver, afs_int32 atopart)
2296 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2297 atoserver, atopart, 0);
2301 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2302 * <atopart>. The new volume is named by <atovolname>. The new volume
2303 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2304 * from the VLDB. the following flags are supported:
2306 * RV_RDONLY - target volume is RO
2307 * RV_OFFLINE - leave target volume offline
2308 * RV_CPINCR - do incremental dump if target exists
2309 * RV_NOVLDB - don't create/update VLDB entry
2310 * RV_NOCLONE - don't use a copy clone
2313 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2314 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2315 afs_uint32 atovolid, int flags)
2317 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2318 * be changing during the copy */
2320 afs_int32 volatile clonetid;
2321 afs_int32 volatile totid;
2322 afs_int32 volatile fromtid;
2323 struct rx_connection * volatile fromconn;
2324 struct rx_connection * volatile toconn;
2325 afs_uint32 volatile cloneVol;
2329 afs_int32 fromDate, cloneFromDate;
2330 struct restoreCookie cookie;
2331 afs_int32 vcode, code;
2334 struct volser_status tstatus;
2335 struct destServer destination;
2336 struct nvldbentry entry, newentry, storeEntry;
2341 fromconn = (struct rx_connection *)0;
2342 toconn = (struct rx_connection *)0;
2350 /* support control-c processing */
2353 (void)signal(SIGINT, sigint_handler);
2355 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2356 EGOTO1(mfail, vcode,
2357 "Could not fetch the entry for the volume %u from the VLDB \n",
2359 MapHostToNetwork(&entry);
2362 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2363 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2364 fromtid = totid = 0; /* initialize to uncreated */
2367 * clone the read/write volume locally.
2371 if (!(flags & RV_NOCLONE)) {
2372 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2374 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2377 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2381 /* Get a clone id */
2382 VPRINT1("Allocating new volume id for clone of volume %u ...",
2386 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2388 EGOTO1(mfail, vcode,
2389 "Could not get an ID for the clone of volume %u from the VLDB\n",
2397 /* Get a new volume id */
2398 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2400 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2401 EGOTO1(mfail, vcode,
2402 "Could not get an ID for the copy of volume %u from the VLDB\n",
2407 if (!(flags & RV_NOCLONE)) {
2408 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2409 VPRINT1("Cloning source volume %u ...", afromvol);
2410 strcpy(vname, "copy-clone-temp");
2413 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2416 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2420 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2422 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2427 "Failed to end the transaction on the source volume %u\n",
2433 * Create the destination volume
2436 if (!(flags & RV_NOCLONE)) {
2437 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2440 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2444 "Failed to start a transaction on the cloned volume%u\n",
2448 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2450 AFSVolSetFlags(fromconn, clonetid,
2451 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2452 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2456 /* remember time from which we've dumped the volume */
2457 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2458 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2460 "Failed to get the status of the cloned volume %u\n",
2464 fromDate = CLOCKADJ(tstatus.creationDate);
2469 /* create a volume on the target machine */
2472 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2475 if ((flags & RV_CPINCR)) {
2476 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2477 code = AFSVolGetStatus(toconn, totid, &tstatus);
2479 "Failed to get the status of the pre-existing volume %u\n",
2483 /* Using the update date should be OK here, but add some fudge */
2484 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2485 if ((flags & RV_NOCLONE))
2486 fromDate = cloneFromDate;
2488 /* XXX We should check that the source volume's creationDate is
2489 * XXX not newer than the existing target volume, and if not,
2490 * XXX throw away the existing target and do a full dump. */
2495 /* Delete the existing volume.
2496 * While we are deleting the volume in these steps, the transaction
2497 * we started against the cloned volume (clonetid above) will be
2498 * sitting idle. It will get cleaned up after 600 seconds
2500 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2501 code = AFSVolDeleteVolume(toconn, totid);
2503 "Could not delete the pre-existing volume %u on destination\n",
2508 ("Ending transaction on pre-existing volume %u on destination ...",
2510 code = AFSVolEndTrans(toconn, totid, &rcode);
2515 "Could not end the transaction on pre-existing volume %u on destination\n",
2520 VPRINT1("Creating the destination volume %u ...", newVol);
2523 AFSVolCreateVolume(toconn, atopart, atovolname,
2524 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2525 newVol, &newVol, &tmp);
2527 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2531 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2533 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2535 "Failed to set the flags on the destination volume %u\n", newVol);
2540 destination.destHost = ntohl(atoserver);
2541 destination.destPort = AFSCONF_VOLUMEPORT;
2542 destination.destSSID = 1;
2544 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2545 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2550 * Now dump the clone to the new volume
2553 if (!(flags & RV_NOCLONE)) {
2554 /* XXX probably should have some code here that checks to see if
2555 * XXX we are copying to same server and partition - if so, just
2556 * XXX use a clone to save disk space */
2558 /* Copy the clone to the new volume */
2559 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2562 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2564 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2568 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2569 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2574 "Failed to end the transaction on the cloned volume %u\n",
2580 * reattach to the main-line volume, and incrementally dump it.
2583 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2585 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2588 "Failed to create a transaction on the source volume %u\n",
2592 /* now do the incremental */
2594 ("Doing the%s dump from source to destination for volume %u ... ",
2595 (flags & RV_NOCLONE) ? "" : " incremental",
2598 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2601 "Failed to do the%s dump from old site to new site\n",
2602 (flags & RV_NOCLONE) ? "" : " incremental");
2605 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2606 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2607 code = AFSVolSetFlags(toconn, totid, volflag);
2609 "Failed to set the flags to make destination volume online\n");
2612 /* put new volume online */
2613 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2614 code = AFSVolEndTrans(toconn, totid, &rcode);
2619 "Failed to end the transaction on the destination volume %u\n",
2623 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2624 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2629 "Failed to end the transaction on the source volume %u\n",
2635 if (!(flags & RV_NOCLONE)) {
2636 code = DoVolDelete(fromconn, cloneVol, afrompart,
2637 "cloned", 0, NULL, NULL);
2639 if (code == VNOVOL) {
2640 EPRINT1(code, "Failed to start transaction on %u\n", cloneVol);
2647 if (!(flags & RV_NOVLDB)) {
2648 /* create the vldb entry for the copied volume */
2649 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2650 newentry.nServers = 1;
2651 newentry.serverNumber[0] = atoserver;
2652 newentry.serverPartition[0] = atopart;
2653 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2654 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2655 newentry.volumeId[RWVOL] = newVol;
2656 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2657 newentry.volumeId[BACKVOL] = 0;
2658 newentry.cloneId = 0;
2659 /*map into right byte order, before passing to xdr, the stuff has to be in host
2660 * byte order. Xdr converts it into network order */
2661 MapNetworkToHost(&newentry, &storeEntry);
2662 /* create the vldb entry */
2663 vcode = VLDB_CreateEntry(&storeEntry);
2666 "Could not create a VLDB entry for the volume %s %lu\n",
2667 atovolname, (unsigned long)newVol);
2668 /*destroy the created volume */
2669 VPRINT1("Deleting the newly created volume %u\n", newVol);
2670 AFSVolDeleteVolume(toconn, totid);
2674 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2678 /* normal cleanup code */
2681 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2683 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2684 if (code || rcode) {
2687 "Could not end transaction on the source volume %lu\n",
2688 (unsigned long)afromvol);
2690 error = (code ? code : rcode);
2696 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2698 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2699 if (code || rcode) {
2702 "Could not end transaction on the source's clone volume %lu\n",
2703 (unsigned long)cloneVol);
2705 error = (code ? code : rcode);
2711 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2713 code = AFSVolEndTrans(toconn, totid, &rcode);
2717 "Could not end transaction on destination volume %lu\n",
2718 (unsigned long)newVol);
2720 error = (code ? code : rcode);
2725 rx_DestroyConnection(fromconn);
2727 rx_DestroyConnection(toconn);
2728 PrintError("", error);
2731 /* come here only when the sky falls */
2736 "vos copy: operation interrupted, cleanup in progress...\n");
2737 fprintf(STDOUT, "clear transaction contexts\n");
2742 VPRINT("Recovery: Ending transaction on clone volume ...");
2743 AFSVolEndTrans(fromconn, clonetid, &rcode);
2747 VPRINT("Recovery: Ending transaction on destination volume ...");
2748 AFSVolEndTrans(toconn, totid, &rcode);
2751 if (fromtid) { /* put it on-line */
2752 VPRINT("Recovery: Ending transaction on source volume ...");
2753 AFSVolEndTrans(fromconn, fromtid, &rcode);
2757 VPRINT("Recovery: Accessing VLDB.\n");
2758 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2760 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2764 MapHostToNetwork(&entry);
2766 /* common cleanup - delete local clone */
2768 code = DoVolDelete(fromconn, cloneVol, afrompart,
2769 "clone", 0, NULL, "Recovery:");
2770 if (code == VNOVOL) {
2771 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", cloneVol);
2775 done: /* routine cleanup */
2777 rx_DestroyConnection(fromconn);
2779 rx_DestroyConnection(toconn);
2782 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2790 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2791 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2793 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2794 atovolname, atoserver, atopart, 0, 0);
2799 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2800 * if one already exists, update it
2804 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2806 struct rx_connection *aconn = (struct rx_connection *)0;
2807 afs_int32 ttid = 0, btid = 0;
2808 afs_uint32 backupID;
2809 afs_int32 code = 0, rcode = 0;
2810 struct nvldbentry entry, storeEntry;
2811 afs_int32 error = 0;
2812 int vldblocked = 0, vldbmod = 0;
2814 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2816 /* the calls to VLDB will succeed only if avolid is a RW volume,
2817 * since we are following the RW hash chain for searching */
2818 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2821 "Could not fetch the entry for the volume %lu from the VLDB \n",
2822 (unsigned long)avolid);
2826 MapHostToNetwork(&entry);
2828 /* These operations require the VLDB be locked since it means the VLDB
2829 * will change or the vldb is already locked.
2831 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2832 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2833 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2835 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2838 "Could not lock the VLDB entry for the volume %lu\n",
2839 (unsigned long)avolid);
2845 /* Reread the vldb entry */
2846 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2849 "Could not fetch the entry for the volume %lu from the VLDB \n",
2850 (unsigned long)avolid);
2854 MapHostToNetwork(&entry);
2857 if (!ISNAMEVALID(entry.name)) {
2858 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2860 error = VOLSERBADNAME;
2864 backupID = entry.volumeId[BACKVOL];
2865 if (backupID == INVALID_BID) {
2866 /* Get a backup volume id from the VLDB and update the vldb
2869 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2872 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2873 (unsigned long)avolid);
2877 entry.volumeId[BACKVOL] = backupID;
2881 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2882 entry.name, NULL, ".backup", NULL, NULL);
2888 /* Mark vldb as backup exists */
2889 if (!(entry.flags & VLF_BACKEXISTS)) {
2890 entry.flags |= VLF_BACKEXISTS;
2894 /* Now go back to the backup volume and bring it on line */
2895 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2898 "Failed to start a transaction on the backup volume %lu\n",
2899 (unsigned long)backupID);
2904 code = AFSVolSetFlags(aconn, btid, 0);
2906 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2907 (unsigned long)backupID);
2912 code = AFSVolEndTrans(aconn, btid, &rcode);
2914 if (code || rcode) {
2916 "Failed to end the transaction on the backup volume %lu\n",
2917 (unsigned long)backupID);
2918 error = (code ? code : rcode);
2924 /* Will update the vldb below */
2928 code = AFSVolEndTrans(aconn, ttid, &rcode);
2929 if (code || rcode) {
2930 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2931 (unsigned long)avolid);
2933 error = (code ? code : rcode);
2938 code = AFSVolEndTrans(aconn, btid, &rcode);
2939 if (code || rcode) {
2941 "Could not end transaction the backup volume %lu\n",
2942 (unsigned long)backupID);
2944 error = (code ? code : rcode);
2948 /* Now update the vldb - if modified */
2951 MapNetworkToHost(&entry, &storeEntry);
2953 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2954 (LOCKREL_OPCODE | LOCKREL_AFSID |
2955 LOCKREL_TIMESTAMP));
2958 "Could not update the VLDB entry for the volume %lu \n",
2959 (unsigned long)avolid);
2965 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2966 (LOCKREL_OPCODE | LOCKREL_AFSID |
2967 LOCKREL_TIMESTAMP));
2970 "Could not unlock the VLDB entry for the volume %lu \n",
2971 (unsigned long)avolid);
2979 rx_DestroyConnection(aconn);
2981 PrintError("", error);
2985 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2986 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2987 * The new volume is named by <aname>, or by appending ".clone" to
2988 * the existing name if <aname> is NULL. The following flags are
2991 * RV_RDONLY - target volume is RO
2992 * RV_OFFLINE - leave target volume offline
2996 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2997 afs_uint32 acloneid, char *aname, int flags)
2999 struct rx_connection *aconn = (struct rx_connection *)0;
3000 afs_int32 ttid = 0, btid = 0;
3001 afs_int32 code = 0, rcode = 0;
3002 char vname[VOLSER_MAXVOLNAME + 1];
3003 afs_int32 error = 0;
3004 volEntries volumeInfo;
3007 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
3010 volumeInfo.volEntries_val = (volintInfo *) 0;
3011 volumeInfo.volEntries_len = 0;
3012 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
3014 fprintf(stderr, "Could not get info for volume %lu\n",
3015 (unsigned long)avolid);
3019 strncpy(vname, volumeInfo.volEntries_val[0].name,
3020 VOLSER_OLDMAXVOLNAME - 7);
3021 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
3022 strcat(vname, ".clone");
3024 if (volumeInfo.volEntries_val)
3025 free(volumeInfo.volEntries_val);
3029 /* Get a clone id */
3030 VPRINT1("Allocating new volume id for clone of volume %u ...",
3032 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
3034 "Could not get an ID for the clone of volume %u from the VLDB\n",
3039 if (flags & RV_RWONLY)
3040 type = readwriteVolume;
3041 else if (flags & RV_RDONLY)
3042 type = readonlyVolume;
3044 type = backupVolume;
3046 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
3047 NULL, aname, NULL, NULL, NULL);
3053 /* Now go back to the backup volume and bring it on line */
3054 if (!(flags & RV_OFFLINE)) {
3055 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3058 "Failed to start a transaction on the clone volume %lu\n",
3059 (unsigned long)acloneid);
3064 code = AFSVolSetFlags(aconn, btid, 0);
3066 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3067 (unsigned long)acloneid);
3072 code = AFSVolEndTrans(aconn, btid, &rcode);
3074 if (code || rcode) {
3076 "Failed to end the transaction on the clone volume %lu\n",
3077 (unsigned long)acloneid);
3078 error = (code ? code : rcode);
3087 code = AFSVolEndTrans(aconn, ttid, &rcode);
3088 if (code || rcode) {
3089 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3090 (unsigned long)avolid);
3092 error = (code ? code : rcode);
3097 code = AFSVolEndTrans(aconn, btid, &rcode);
3098 if (code || rcode) {
3100 "Could not end transaction on the clone volume %lu\n",
3101 (unsigned long)acloneid);
3103 error = (code ? code : rcode);
3108 rx_DestroyConnection(aconn);
3110 PrintError("", error);
3114 #define ONERROR(ec, ep, es) do { \
3116 fprintf(STDERR, (es), (ep)); \
3121 #define ONERROR0(ec, es) do { \
3123 fprintf(STDERR, (es)); \
3128 #define ERROREXIT(ec) do { \
3133 /* Get a "transaction" on this replica. Create the volume
3134 * if necessary. Return the time from which a dump should
3135 * be made (0 if it's a new volume)
3138 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3139 struct rx_connection **connPtr, afs_int32 * transPtr,
3140 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3141 afs_int32 *origflags, afs_uint32 tmpVolId)
3144 struct volser_status tstatus;
3149 *connPtr = (struct rx_connection *)0;
3154 /* get connection to the replication site */
3155 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3157 goto fail; /* server is down */
3159 volid = vldbEntryPtr->volumeId[ROVOL];
3163 AFSVolTransCreate_retry(*connPtr, volid,
3164 vldbEntryPtr->serverPartition[index], ITOffline,
3167 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3168 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3169 * site. Don't trust any data on it, since it is possible we
3170 * have encountered some temporary volume from some other
3171 * incomplete volume operation. It is difficult to detect if
3172 * that has happened vs if this is a legit volume, so just
3173 * delete it to be safe. */
3175 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3176 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3177 serverNumber[index], hoststr) :
3178 hostutil_GetNameByINet(vldbEntryPtr->
3179 serverNumber[index]));
3181 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3183 PrintError("Failed to delete RO_DONTUSE site: ", code);
3187 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3193 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3200 /* emulate what TransCreate would have returned, so we try to
3201 * create the volume below */
3206 /* If the volume does not exist, create it */
3207 if (!volid || code) {
3208 char volname[VL_MAXNAMELEN];
3211 if (volid && (code != VNOVOL)) {
3212 PrintError("Failed to start a transaction on the RO volume.\n",
3217 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3219 if (strlcat(volname,
3220 tmpVolId?".roclone":".readonly",
3221 sizeof(volname)) >= sizeof(volname)) {
3223 PrintError("Volume name is too long\n", code);
3229 "Creating new volume %lu on replication site %s: ",
3230 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3231 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3232 serverNumber[index], hoststr) :
3233 hostutil_GetNameByINet(vldbEntryPtr->
3234 serverNumber[index]));
3239 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3241 vldbEntryPtr->volumeId[RWVOL],
3242 tmpVolId?&tmpVolId:&volid,
3245 PrintError("Failed to create the ro volume: ", code);
3248 vldbEntryPtr->volumeId[ROVOL] = volid;
3252 /* The following is a bit redundant, since create sets these flags by default */
3254 AFSVolSetFlags(*connPtr, *transPtr,
3255 VTDeleteOnSalvage | VTOutOfService);
3257 PrintError("Failed to set flags on the ro volume: ", code);
3262 /* Otherwise, the transaction did succeed, so get the creation date of the
3263 * latest RO volume on the replication site
3266 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3267 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3268 serverNumber[index], hoststr) :
3269 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3271 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3273 PrintError("Failed to get status of volume on destination: ",
3278 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3283 code = DoVolClone(*connPtr, volid,
3284 vldbEntryPtr->serverPartition[index],
3285 readonlyVolume, tmpVolId, "temporary",
3286 vldbEntryPtr->name, NULL, ".roclone", NULL,
3291 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3292 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3299 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3303 if (tcode && tcode != ENOENT)
3304 PrintError("Could not end transaction on a ro volume: ", tcode);
3311 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3312 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3313 void *cookie, manyResults * results)
3317 for (i = 0; i < tr->manyDests_len; i++) {
3318 results->manyResults_val[i] =
3319 AFSVolForward(fromconn, fromtid, fromdate,
3320 &(tr->manyDests_val[i].server),
3321 tr->manyDests_val[i].trans, cookie);
3327 * Check if a trans has timed out, and recreate it if necessary.
3329 * @param[in] aconn RX connection to the relevant server
3330 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3331 * contains the new trans ID on success
3332 * @param[in] apart Partition for the transaction
3333 * @param[in] astat The status of the original transaction
3335 * @return operation status
3336 * @retval 0 existing transaction is still valid, or we managed to recreate
3337 * the trans successfully
3338 * @retval nonzero Fatal error; bail out
3341 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3342 struct volser_status *astat)
3344 struct volser_status new_status;
3347 memset(&new_status, 0, sizeof(new_status));
3348 code = AFSVolGetStatus(aconn, *atid, &new_status);
3350 if (code == ENOENT) {
3352 VPRINT1("Old transaction on cloned volume %lu timed out, "
3353 "restarting transaction\n", (long unsigned) astat->volID);
3354 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3357 PrintError("Failed to recreate cloned RO volume transaction\n",
3362 memset(&new_status, 0, sizeof(new_status));
3363 code = AFSVolGetStatus(aconn, *atid, &new_status);
3365 PrintError("Failed to get status on recreated transaction\n",
3370 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3371 PrintError("Recreated transaction on cloned RO volume, but "
3372 "the volume has changed!\n", 0);
3376 PrintError("Unable to get status of current cloned RO transaction\n",
3381 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3383 PrintError("Internal error: current GetStatus does not match "
3384 "original GetStatus?\n", 0);
3393 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3394 struct rx_connection **toconns, struct release *times,
3397 afs_int32 s, code = 0, rcode = 0;
3398 /* End the transactions and destroy the connections */
3399 for (s = 0; s < volcount; s++) {
3400 if (replicas[s].trans) {
3401 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3403 replicas[s].trans = 0;
3407 if ((s == 0) || (code != ENOENT)) {
3408 PrintError("Could not end transaction on a ro volume: ",
3412 ("Transaction timed out on a ro volume. Will retry.\n",
3414 if (times[s].vldbEntryIndex < *vldbindex)
3415 *vldbindex = times[s].vldbEntryIndex;
3420 rx_DestroyConnection(toconns[s]);
3426 DoVolOnline(struct nvldbentry *vldbEntryPtr, afs_uint32 avolid, int index,
3427 char *vname, struct rx_connection *connPtr)
3429 afs_int32 code = 0, rcode = 0, onlinetid = 0;
3432 AFSVolTransCreate_retry(connPtr, avolid,
3433 vldbEntryPtr->serverPartition[index],
3437 EPRINT(code, "Could not create transaction on readonly...\n");
3440 code = AFSVolSetFlags(connPtr, onlinetid, 0);
3442 EPRINT(code, "Could not set flags on readonly...\n");
3447 AFSVolSetIdsTypes(connPtr, onlinetid, vname,
3448 ROVOL, vldbEntryPtr->volumeId[RWVOL],
3451 EPRINT(code, "Could not set ids on readonly...\n");
3454 code = AFSVolEndTrans(connPtr, onlinetid, &rcode);
3461 * Release a volume to read-only sites
3463 * Release volume <afromvol> on <afromserver> <afrompart> to all
3464 * its RO sites (full release). Unless the previous release was
3465 * incomplete: in which case we bring the remaining incomplete
3466 * volumes up to date with the volumes that were released
3469 * Will create a clone from the RW, then dump the clone out to
3470 * the remaining replicas. If there is more than 1 RO sites,
3471 * ensure that the VLDB says at least one RO is available all
3472 * the time: Influences when we write back the VLDB entry.
3474 * @param[in] afromvol volume to be released
3475 * @param[in] afromserver server containing afromvol
3476 * @param[in] afrompart partition containing afromvol
3477 * @param[in] flags bitmap of options
3478 * REL_COMPLETE - force a complete release
3479 * REL_FULLDUMPS - force full dumps
3480 * REL_STAYUP - dump to clones to avoid offline time
3483 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3484 afs_int32 afrompart, int flags)
3488 afs_int32 vcode, rcode, tcode;
3489 afs_uint32 cloneVolId = 0, roVolId;
3490 struct replica *replicas = 0;
3491 struct nvldbentry entry, storeEntry;
3492 int i, volcount = 0, m, vldbindex;
3494 struct restoreCookie cookie;
3495 struct rx_connection **toconns = 0;
3496 struct release *times = 0;
3498 struct rx_connection *fromconn = (struct rx_connection *)0;
3499 afs_int32 error = 0;
3501 afs_int32 clonetid = 0, onlinetid;
3502 afs_int32 fromtid = 0;
3503 afs_uint32 fromdate = 0;
3504 afs_uint32 thisdate;
3508 manyResults results;
3509 int rwindex, roindex, roclone, roexists;
3510 afs_uint32 rwcrdate = 0, rwupdate = 0;
3511 afs_uint32 clcrdate;
3515 } remembertime[NMAXNSERVERS];
3516 int releasecount = 0;
3517 struct volser_status volstatus;
3519 afs_int32 origflags[NMAXNSERVERS];
3520 struct volser_status orig_status;
3521 int notreleased = 0;
3522 int tried_justnewsites = 0;
3523 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3524 int sites = 0; /* number of ro sites */
3525 int new_sites = 0; /* number of ro sites markes as new */
3526 int stayUp = (flags & REL_STAYUP);
3529 CR_RECOVER = 0x0000, /**< not complete: a recovery from a previous failed release */
3530 CR_FORCED = 0x0001, /**< complete: forced by caller */
3531 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3532 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3533 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3534 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3535 } complete_release_t;
3537 complete_release_t complete_release = CR_RECOVER;
3539 memset(remembertime, 0, sizeof(remembertime));
3540 memset(&results, 0, sizeof(results));
3541 memset(origflags, 0, sizeof(origflags));
3543 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3544 if (vcode != VL_RERELEASE)
3545 ONERROR(vcode, afromvol,
3546 "Could not lock the VLDB entry for the volume %u.\n");
3549 /* Get the vldb entry in readable format */
3550 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3551 ONERROR(vcode, afromvol,
3552 "Could not fetch the entry for the volume %u from the VLDB.\n");
3553 MapHostToNetwork(&entry);
3556 EnumerateEntry(&entry);
3558 if (!ISNAMEVALID(entry.name))
3559 ONERROR(VOLSERBADOP, entry.name,
3560 "Volume name %s is too long, rename before releasing.\n");
3561 if (entry.volumeId[RWVOL] != afromvol)
3562 ONERROR(VOLSERBADOP, afromvol,
3563 "The volume %u being released is not a read-write volume.\n");
3564 if (entry.nServers <= 1)
3565 ONERROR(VOLSERBADOP, afromvol,
3566 "Volume %u has no replicas - release operation is meaningless!\n");
3567 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3568 ONERROR(VOLSERBADOP, entry.name,
3569 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3571 /* roclone is true if one of the RO volumes is on the same
3572 * partition as the RW volume. In this case, we make the RO volume
3573 * on the same partition a clone instead of a complete copy.
3576 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3577 roclone = ((roindex == -1) ? 0 : 1);
3578 rwindex = Lp_GetRwIndex(&entry);
3580 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3582 /* Make sure we have a RO volume id to work with */
3583 if (entry.volumeId[ROVOL] == INVALID_BID) {
3584 /* need to get a new RO volume id */
3585 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3586 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3588 entry.volumeId[ROVOL] = roVolId;
3589 MapNetworkToHost(&entry, &storeEntry);
3590 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3591 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3595 * Determine if this is to be a complete release or a recovery of a
3596 * previous unfinished release. The previous release is considered to be
3597 * unfinished when the clone was successfully distributed to at least one
3598 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3601 * The caller can override the vldb flags check using the -force
3602 * or -force-reclone flag, to force this to be a complete release.
3604 for (i = 0; i < entry.nServers; i++) {
3605 if (entry.serverFlags[i] & VLSF_ROVOL) {
3607 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3609 if (entry.serverFlags[i] & VLSF_DONTUSE)
3612 origflags[i] = entry.serverFlags[i];
3615 if (flags & REL_COMPLETE) {
3616 complete_release |= CR_FORCED;
3619 if (new_sites == 0) {
3620 complete_release |= CR_LAST_OK;
3621 } else if (new_sites == sites) {
3622 complete_release |= CR_ALL_NEW;
3625 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3626 && !(complete_release & CR_FORCED)) {
3627 if (notreleased && notreleased != sites) {
3628 /* we have some new unreleased sites. try to just release to those,
3629 * if the RW has not changed. The caller can override with -force
3630 * or with -force-reclone. */
3635 /* Determine which volume id to use and see if it exists */
3636 cloneVolId = (complete_release || entry.cloneId == 0)
3637 ? entry.volumeId[ROVOL] : entry.cloneId;
3639 code = VolumeExists(afromserver, afrompart, cloneVolId);
3640 roexists = ((code == ENODEV) ? 0 : 1);
3642 /* For stayUp case, if roclone is the only site, bypass special handling */
3643 if (stayUp && roclone) {
3647 for (e = 0; (e < entry.nServers) && !error; e++) {
3648 if ((entry.serverFlags[e] & VLSF_ROVOL)) {
3649 if (!(VLDB_IsSameAddrs(entry.serverNumber[e], afromserver,
3654 if (e >= entry.nServers)
3658 /* If we had a previous release to complete, do so, else: */
3659 if (stayUp && (cloneVolId == entry.volumeId[ROVOL])) {
3660 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVolId);
3661 ONERROR(code, afromvol,
3662 "Cannot get temporary clone id for volume %u\n");
3665 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3667 ONERROR(-1, afromserver,
3668 "Cannot establish connection with server 0x%x\n");
3670 if (!complete_release) {
3672 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3674 /* Begin transaction on RW and mark it busy while we query it */
3675 code = AFSVolTransCreate_retry(
3676 fromconn, afromvol, afrompart, ITBusy, &fromtid
3678 ONERROR(code, afromvol,
3679 "Failed to start transaction on RW volume %u\n");
3681 /* Query the creation date for the RW */
3682 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3683 ONERROR(code, afromvol,
3684 "Failed to get the status of RW volume %u\n");
3685 rwcrdate = volstatus.creationDate;
3687 /* End transaction on RW */
3688 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3690 ONERROR((code ? code : rcode), afromvol,
3691 "Failed to end transaction on RW volume %u\n");
3693 /* Begin transaction on clone and mark it busy while we query it */
3694 code = AFSVolTransCreate_retry(
3695 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3697 ONERROR(code, cloneVolId,
3698 "Failed to start transaction on RW clone %u\n");
3700 /* Query the creation date for the clone */
3701 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3702 ONERROR(code, cloneVolId,
3703 "Failed to get the status of RW clone %u\n");
3704 clcrdate = volstatus.creationDate;
3706 /* End transaction on clone */
3707 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3709 ONERROR((code ? code : rcode), cloneVolId,
3710 "Failed to end transaction on RW clone %u\n");
3712 if (rwcrdate > clcrdate)
3713 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3717 if (!complete_release || (complete_release & CR_NEW_RW)) {
3718 /* in case the RW has changed, and just to be safe */
3723 if (!complete_release) {
3725 "This is a recovery of previously failed release\n");
3727 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3728 /* Give the reasons for a complete release, except if only CR_LAST_OK. */
3729 if (complete_release != CR_LAST_OK) {
3731 if (complete_release & CR_FORCED) {
3732 fprintf(STDOUT, "%sforced", sep);
3735 if (complete_release & CR_LAST_OK) {
3736 fprintf(STDOUT, "%slast ok", sep);
3739 if (complete_release & CR_ALL_NEW) {
3740 fprintf(STDOUT, "%sall sites are new", sep);
3743 if (complete_release & CR_NEW_RW) {
3744 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3747 if (complete_release & CR_RO_MISSING) {
3748 fprintf(STDOUT, "%sro clone missing", sep);
3750 fprintf(STDOUT, ")");
3752 fprintf(STDOUT, "\n");
3754 tried_justnewsites = 1;
3755 fprintf(STDOUT, "There are new RO sites; we will try to "
3756 "only release to new sites\n");
3761 if (complete_release) {
3762 afs_int32 oldest = 0;
3763 /* If the RO clone exists, then if the clone is a temporary
3764 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3765 * (it was recently added), then also delete it. We do not
3766 * want to "reclone" a temporary RO clone.
3769 code = VolumeExists(afromserver, afrompart, cloneVolId);
3771 code = DoVolDelete(fromconn, cloneVolId, afrompart, "previous clone", 0,
3773 if (code && (code != VNOVOL))
3778 /* clean up any previous tmp clone before starting if staying up */
3780 && (!roclone || (entry.serverFlags[roindex] & VLSF_DONTUSE))) {
3781 code = DoVolDelete(fromconn,
3782 stayUp ? entry.volumeId[ROVOL] : cloneVolId,
3783 afrompart, "the", 0, NULL, NULL);
3784 if (code && (code != VNOVOL))
3790 VPRINT("Querying old RO sites for update times...");
3791 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3792 volEntries volumeInfo;
3793 struct rx_connection *conn;
3796 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL)) {
3799 if ((entry.serverFlags[vldbindex] & VLSF_DONTUSE)) {
3802 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3804 fprintf(STDERR, "Cannot establish connection to server %s\n",
3805 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3809 volumeInfo.volEntries_val = NULL;
3810 volumeInfo.volEntries_len = 0;
3811 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3812 entry.volumeId[ROVOL],
3815 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3816 (unsigned long)entry.volumeId[ROVOL],
3817 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3818 PrintError("", code);
3820 rx_DestroyConnection(conn);
3824 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3826 if (oldest == 0 || crdate < oldest) {
3830 rx_DestroyConnection(conn);
3831 free(volumeInfo.volEntries_val);
3832 volumeInfo.volEntries_val = NULL;
3833 volumeInfo.volEntries_len = 0;
3838 volEntries volumeInfo;
3839 volumeInfo.volEntries_val = NULL;
3840 volumeInfo.volEntries_len = 0;
3841 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3844 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3845 (unsigned long)afromvol,
3846 hostutil_GetNameByINet(afromserver));
3847 PrintError("", code);
3850 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3852 free(volumeInfo.volEntries_val);
3853 volumeInfo.volEntries_val = NULL;
3854 volumeInfo.volEntries_len = 0;
3857 if (justnewsites && oldest <= rwupdate) {
3858 /* RW has changed */
3862 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3863 * write this entry out to the vlserver until after the first
3864 * RO volume is released (temp RO clones don't count).
3866 * If 'justnewsites' is set, we're only updating sites that have
3867 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3869 for (i = 0; i < entry.nServers; i++) {
3871 if ((entry.serverFlags[i] & VLSF_DONTUSE)) {
3872 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3874 entry.serverFlags[i] |= VLSF_NEWREPSITE;
3877 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3878 entry.serverFlags[i] |= VLSF_DONTUSE;
3881 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3882 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3885 if (justnewsites && roexists) {
3886 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3887 * anything with the RO clone, so skip the reclone */
3890 } else if (complete_release) {
3893 strcpy(vname, entry.name);
3895 strcat(vname, ".roclone");
3897 strcat(vname, ".readonly");
3899 strcpy(vname, "readonly-clone-temp");
3902 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3903 cloneVolId, (roclone && !stayUp)?"permanent RO":
3904 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3910 if (justnewsites && rwupdate != volstatus.updateDate) {
3912 /* reset the serverFlags as if 'justnewsites' had never been set */
3913 for (i = 0; i < entry.nServers; i++) {
3914 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3915 entry.serverFlags[i] |= VLSF_DONTUSE;
3917 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3918 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3921 rwcrdate = volstatus.creationDate;
3923 /* Remember clone volume ID in case we fail or are interrupted */
3924 entry.cloneId = cloneVolId;
3926 if (roclone && !stayUp) {
3927 /* Bring the RO clone online - though not if it's a temporary clone */
3928 VPRINT1("Starting transaction on RO clone volume %u...",
3931 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3933 ONERROR(code, cloneVolId,
3934 "Failed to start transaction on volume %u\n");
3937 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3938 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3941 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3942 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3943 ONERROR((code ? code : rcode), cloneVolId,
3944 "Failed to end transaction on RO clone %u\n");
3947 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3949 /* Sleep so that a client searching for an online volume won't
3950 * find the clone offline and then the next RO offline while the
3951 * release brings the clone online and the next RO offline (race).
3952 * There is a fix in the 3.4 client that does not need this sleep
3953 * anymore, but we don't know what clients we have.
3955 if (entry.nServers > 2 && !justnewsites)
3958 /* Mark the RO clone in the VLDB as a good site (already released) */
3959 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
3960 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
3961 entry.flags |= VLF_ROEXISTS;
3965 /* Write out the VLDB entry only if the clone is not a temporary
3966 * clone. If we did this to a temporary clone then we would end
3967 * up marking all the ROs as "old release" making the ROs
3968 * temporarily unavailable.
3970 MapNetworkToHost(&entry, &storeEntry);
3971 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3972 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3973 ONERROR(vcode, entry.name,
3974 "Could not update vldb entry for %s.\n");
3980 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3981 /* act like this is a completion of a previous release */
3982 complete_release = CR_RECOVER;
3983 } else if (tried_justnewsites) {
3984 VPRINT("RW vol has changed; releasing to all sites\n");
3987 /* Now we will release from the clone to the remaining RO replicas.
3988 * The first 2 ROs (counting the non-temporary RO clone) are released
3989 * individually: releasecount. This is to reduce the race condition
3990 * of clients trying to find an on-line RO volume. The remaining ROs
3991 * are released in parallel but no more than half the number of ROs
3992 * (rounded up) at a time: nservers.
3995 strcpy(vname, entry.name);
3997 strcat(vname, ".roclone");
3999 strcat(vname, ".readonly");
4000 memset(&cookie, 0, sizeof(cookie));
4001 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
4002 cookie.type = ROVOL;
4003 cookie.parent = entry.volumeId[RWVOL];
4006 /* how many to do at once, excluding clone */
4007 if (stayUp || justnewsites)
4008 nservers = entry.nServers; /* can do all, none offline */
4010 nservers = entry.nServers / 2;
4011 replicas = calloc(nservers + 1, sizeof(struct replica));
4012 times = calloc(nservers + 1, sizeof(struct release));
4013 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
4014 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
4015 if (!replicas || !times || !results.manyResults_val || !toconns)
4017 "Failed to create transaction on the release clone\n");
4019 /* Create a transaction on the cloned volume */
4020 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
4022 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
4024 memset(&orig_status, 0, sizeof(orig_status));
4025 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
4027 if (!complete_release && code)
4028 ONERROR(VOLSERNOVOL, afromvol,
4029 "Old clone is inaccessible. Try vos release -f %u.\n");
4030 ONERROR0(code, "Failed to create transaction on the release clone\n");
4033 /* if we have a clone, treat this as done, for now */
4034 if (stayUp && !complete_release) {
4035 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
4036 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
4037 entry.flags |= VLF_ROEXISTS;
4042 /* For each index in the VLDB */
4043 for (vldbindex = 0; vldbindex < entry.nServers;) {
4044 /* Get a transaction on the replicas. Pick replicas which have an old release. */
4046 ((volcount < nservers) && (vldbindex < entry.nServers));
4048 if (!stayUp && !justnewsites) {
4049 /* The first two RO volumes will be released individually.
4050 * The rest are then released in parallel. This is a hack
4051 * for clients not recognizing right away when a RO volume
4052 * comes back on-line.
4054 if ((volcount == 1) && (releasecount < 2))
4058 if (vldbindex == roindex)
4059 continue; /* the clone */
4060 if ((entry.serverFlags[vldbindex] & VLSF_NEWREPSITE)
4061 && !(entry.serverFlags[vldbindex] & VLSF_DONTUSE))
4063 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL))
4064 continue; /* not a RO vol */
4067 /* Get a Transaction on this replica. Get a new connection if
4068 * necessary. Create the volume if necessary. Return the
4069 * time from which the dump should be made (0 if it's a new
4070 * volume). Each volume might have a different time.
4072 replicas[volcount].server.destHost =
4073 ntohl(entry.serverNumber[vldbindex]);
4074 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
4075 replicas[volcount].server.destSSID = 1;
4076 times[volcount].vldbEntryIndex = vldbindex;
4079 GetTrans(&entry, vldbindex, &(toconns[volcount]),
4080 &(replicas[volcount].trans),
4081 &(times[volcount].crtime),
4082 &(times[volcount].uptime),
4083 origflags, stayUp?cloneVolId:0);
4087 /* Thisdate is the date from which we want to pick up all changes */
4088 if (flags & REL_FULLDUMPS) {
4089 /* Do a full dump when forced by the caller. */
4090 VPRINT("This will be a full dump: forced\n");
4092 } else if (!complete_release) {
4093 /* If this release is a recovery of a failed release, we can't be
4094 * sure the creation date is good, so do a full dump.
4096 VPRINT("This will be a full dump: previous release failed\n");
4098 } else if (times[volcount].crtime == 0) {
4099 /* A full dump is needed for a new read-only volume. */
4101 ("This will be a full dump: read-only volume needs to be created\n");
4103 } else if ((rwcrdate > times[volcount].crtime)) {
4104 /* If the RW volume was replaced (its creation date is newer than
4105 * the last release), then we can't be sure what has changed (so
4106 * we do a full dump).
4109 ("This will be a full dump: read-write volume was replaced\n");
4111 } else if (remembertime[vldbindex].validtime) {
4112 /* Trans was prev ended. Use the time from the prev trans
4113 * because, prev trans may have created the volume. In which
4114 * case time[volcount].time would be now instead of 0.
4117 (remembertime[vldbindex].uptime < times[volcount].uptime)
4118 ? remembertime[vldbindex].uptime
4119 : times[volcount].uptime;
4121 thisdate = times[volcount].uptime;
4123 remembertime[vldbindex].validtime = 1;
4124 remembertime[vldbindex].uptime = thisdate;
4126 if (volcount == 0) {
4127 fromdate = thisdate;
4129 /* Include this volume if it is within 15 minutes of the earliest */
4131 thisdate) ? (fromdate - thisdate) : (thisdate -
4133 AFSVolEndTrans(toconns[volcount],
4134 replicas[volcount].trans, &rcode);
4135 replicas[volcount].trans = 0;
4138 if (thisdate < fromdate)
4139 fromdate = thisdate;
4146 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
4153 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
4154 (unsigned long)cloneVolId, stayUp?
4155 cloneVolId:entry.volumeId[ROVOL],
4156 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
4157 vldbEntryIndex], hoststr) :
4158 hostutil_GetNameByINet(entry.
4159 serverNumber[times[0].
4162 for (s = 1; s < volcount; s++) {
4163 fprintf(STDOUT, " and %s",
4164 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
4165 vldbEntryIndex], hoststr) :
4166 hostutil_GetNameByINet(entry.
4167 serverNumber[times[s].
4172 fprintf(STDOUT, " (entire volume)");
4175 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4177 fprintf(STDOUT, ".\n");
4181 /* Release the ones we have collected */
4182 tr.manyDests_val = &(replicas[0]);
4183 tr.manyDests_len = results.manyResults_len = volcount;
4185 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4186 0 /*spare */ , &cookie, &results);
4187 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4189 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4190 0 /*spare */ , &cookie, &results);
4195 PrintError("Release failed: ", code);
4197 for (m = 0; m < volcount; m++) {
4198 if (results.manyResults_val[m]) {
4199 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4200 /* we retry timed out transaction. When it is
4201 * not the first volume and the transaction wasn't found
4202 * (assume it timed out and was garbage collected by volser).
4205 ("Failed to dump volume from clone to a ro site: ",
4206 results.manyResults_val[m]);
4212 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4213 ROVOL, entry.volumeId[RWVOL], 0, 0);
4215 if ((m == 0) || (code != ENOENT)) {
4216 PrintError("Failed to set correct names and ids: ",
4222 /* have to clear dest. flags to ensure new vol goes online:
4223 * because the restore (forwarded) operation copied
4224 * the V_inService(=0) flag over to the destination.
4226 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4228 if ((m == 0) || (code != ENOENT)) {
4229 PrintError("Failed to set flags on ro volume: ",
4235 entry.serverFlags[times[m].vldbEntryIndex] |= VLSF_NEWREPSITE;
4236 entry.serverFlags[times[m].vldbEntryIndex] &= ~VLSF_DONTUSE;
4237 entry.flags |= VLF_ROEXISTS;
4243 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4244 MapNetworkToHost(&entry, &storeEntry);
4245 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4246 ONERROR(vcode, afromvol,
4247 " Could not update VLDB entry for volume %u\n");
4249 } /* for each index in the vldb */
4251 /* for the stayup case, put back at the end */
4253 afs_uint32 tmpVol = entry.volumeId[ROVOL];
4254 strcpy(vname, entry.name);
4255 strcat(vname, ".readonly");
4258 /* have to clear flags to ensure new vol goes online
4260 code = AFSVolSetFlags(fromconn, fromtid, 0);
4261 if (code && (code != ENOENT)) {
4262 PrintError("Failed to set flags on ro volume: ",
4266 VPRINT3("%sloning to permanent RO %u on %s...", roexists?"Re-c":"C", tmpVol,
4268 afs_inet_ntoa_r(entry.serverNumber[roindex],
4270 hostutil_GetNameByINet(entry.serverNumber[roindex]));
4272 code = AFSVolClone(fromconn, fromtid, roexists?tmpVol:0,
4273 readonlyVolume, vname, &tmpVol);
4277 VPRINT("Bringing readonly online...");
4278 code = DoVolOnline(&entry, tmpVol, roindex, vname,
4282 EPRINT(code, "Failed: ");
4283 entry.serverFlags[roindex] &= ~VLSF_NEWREPSITE;
4284 entry.serverFlags[roindex] |= VLSF_DONTUSE;
4286 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
4287 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
4288 entry.flags |= VLF_ROEXISTS;
4293 for (s = 0; s < volcount; s++) {
4294 if (replicas[s].trans) {
4295 vldbindex = times[s].vldbEntryIndex;
4297 /* ok, so now we have to end the previous transaction */
4298 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4303 code = AFSVolTransCreate_retry(toconns[s],
4305 entry.serverPartition[vldbindex],
4307 &(replicas[s].trans));
4309 PrintError("Unable to begin transaction on temporary clone: ", code);
4312 PrintError("Unable to end transaction on temporary clone: ", code);
4315 VPRINT3("%sloning to permanent RO %u on %s...", times[s].crtime?"Re-c":"C",
4317 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4319 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4320 if (times[s].crtime)
4321 code = AFSVolClone(toconns[s], replicas[s].trans, tmpVol,
4322 readonlyVolume, vname, &tmpVol);
4324 code = AFSVolClone(toconns[s], replicas[s].trans, 0,
4325 readonlyVolume, vname, &tmpVol);
4328 if (!times[s].crtime) {
4329 entry.serverFlags[vldbindex] |= VLSF_DONTUSE;
4331 entry.serverFlags[vldbindex] &= ~VLSF_NEWREPSITE;
4332 PrintError("Failed: ",
4337 if (entry.serverFlags[vldbindex] != VLSF_DONTUSE) {
4338 /* bring it online (mark it InService) */
4339 VPRINT1("Bringing readonly online on %s...",
4342 htonl(replicas[s].server.destHost),
4344 hostutil_GetNameByINet(
4345 htonl(replicas[s].server.destHost)));
4347 code = DoVolOnline(&entry, tmpVol, vldbindex, vname,
4349 /* needed to come online for cloning */
4351 /* technically it's still new, just not online */
4352 entry.serverFlags[s] &= ~VLSF_NEWREPSITE;
4353 entry.serverFlags[s] |= VLSF_DONTUSE;
4354 if (code != ENOENT) {
4355 PrintError("Failed to set correct names and ids: ",
4362 VPRINT("Marking temporary clone for deletion...\n");
4363 code = AFSVolSetFlags(toconns[s],
4368 EPRINT(code, "Failed: ");
4372 VPRINT("Ending transaction on temporary clone...\n");
4373 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4377 PrintError("Failed: ", code);
4380 /* ended successfully */
4381 replicas[s].trans = 0;
4383 VPRINT2("Deleting temporary clone %u on %s...", cloneVolId,
4385 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4387 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4388 code = DoVolDelete(toconns[s], cloneVolId,
4389 entry.serverPartition[vldbindex],
4390 NULL, 0, NULL, NULL);
4392 EPRINT(code, "Failed: ");
4399 /* done. put the vldb entry in the success tail case*/
4400 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4403 /* End the transaction on the cloned volume */
4404 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4409 PrintError("Failed to end transaction on rw volume: ", code);
4411 /* Figure out if any volume were not released and say so */
4412 for (failure = 0, i = 0; i < entry.nServers; i++) {
4413 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE))
4419 "The volume %lu could not be released to the following %d sites:\n",
4420 (unsigned long)afromvol, failure);
4421 for (i = 0; i < entry.nServers; i++) {
4422 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE)) {
4423 MapPartIdIntoName(entry.serverPartition[i], pname);
4424 fprintf(STDERR, "\t%35s %s\n",
4425 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4426 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4429 MapNetworkToHost(&entry, &storeEntry);
4431 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4433 ONERROR(vcode, afromvol,
4434 " Could not update VLDB entry for volume %u\n");
4436 ERROREXIT(VOLSERBADRELEASE);
4440 /* All the ROs were release successfully. Remove the temporary clone */
4441 if (!roclone || stayUp) {
4443 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4444 (unsigned long)cloneVolId);
4447 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4449 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4453 for (i = 0; i < entry.nServers; i++)
4454 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
4456 /* Update the VLDB */
4457 VPRINT("updating VLDB ...");
4459 MapNetworkToHost(&entry, &storeEntry);
4461 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4462 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4463 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4468 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4472 "Failed to end cloning transaction on the RW volume %lu\n",
4473 (unsigned long)afromvol);
4479 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4483 "Failed to end transaction on the release clone %lu\n",
4484 (unsigned long)cloneVolId);
4489 for (i = 0; i < nservers; i++) {
4490 if (replicas && replicas[i].trans) {
4491 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4492 replicas[i].trans = 0;
4495 "Failed to end transaction on ro volume %u at server %s\n",
4496 entry.volumeId[ROVOL],
4497 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4498 destHost), hoststr) :
4499 hostutil_GetNameByINet(htonl
4500 (replicas[i].server.destHost)));
4505 if (toconns && toconns[i]) {
4506 rx_DestroyConnection(toconns[i]);
4512 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4513 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4516 "Could not release lock on the VLDB entry for volume %lu\n",
4517 (unsigned long)afromvol);
4523 PrintError("", error);
4526 rx_DestroyConnection(fromconn);
4527 if (results.manyResults_val)
4528 free(results.manyResults_val);
4540 dump_sig_handler(int x)
4542 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4546 /* Dump the volume <afromvol> on <afromserver> and
4547 * <afrompart> to <afilename> starting from <fromdate>.
4548 * DumpFunction does the real work behind the scenes after
4549 * extracting parameters from the rock
4552 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4554 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4557 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4558 * be changing during the dump */
4559 struct rx_call * volatile fromcall = NULL;
4560 struct rx_connection * volatile fromconn = NULL;
4561 afs_int32 volatile fromtid = 0;
4563 afs_int32 rcode = 0;
4564 afs_int32 code, error = 0;
4566 time_t tmv = fromdate;
4570 #ifndef AFS_NT40_ENV
4571 (void)signal(SIGPIPE, dump_sig_handler);
4573 (void)signal(SIGINT, dump_sig_handler);
4576 VEPRINT("Full Dump ...\n");
4578 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4582 /* get connections to the servers */
4583 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4585 VEPRINT1("Starting transaction on volume %u...", afromvol);
4587 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4589 EGOTO1(error_exit, code,
4590 "Could not start transaction on the volume %u to be dumped\n",
4594 fromcall = rx_NewCall(fromconn);
4596 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4597 if (flags & VOLDUMPV2_OMITDIRS)
4598 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4600 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4601 EGOTO(error_exit, code, "Could not start the dump process \n");
4604 VEPRINT1("Dumping volume %u...", afromvol);
4605 code = DumpFunction(fromcall, rock);
4606 if (code == RXGEN_OPCODE)
4608 EGOTO(error_exit, code, "Error while dumping volume \n");
4613 code = rx_EndCall(fromcall, 0);
4614 if (code && code != RXGEN_OPCODE)
4615 fprintf(STDERR, "Error in rx_EndCall\n");
4620 VEPRINT1("Ending transaction on volume %u...", afromvol);
4621 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4622 if (code || rcode) {
4623 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4624 (unsigned long)afromvol);
4626 error = (code ? code : rcode);
4631 rx_DestroyConnection(fromconn);
4633 if (error != RXGEN_OPCODE)
4634 PrintError("", error);
4638 /* Clone the volume <afromvol> on <afromserver> and
4639 * <afrompart>, and then dump the clone volume to
4640 * <afilename> starting from <fromdate>.
4641 * DumpFunction does the real work behind the scenes after
4642 * extracting parameters from the rock
4645 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4646 afs_int32 afrompart, afs_int32 fromdate,
4647 afs_int32(*DumpFunction) (struct rx_call *, void *),
4648 void *rock, afs_int32 flags)
4650 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4651 * be changing during the dump */
4652 struct rx_connection * volatile fromconn = NULL;
4653 struct rx_call * volatile fromcall = NULL;
4654 afs_int32 volatile clonetid = 0;
4655 afs_uint32 volatile clonevol = 0;
4658 afs_int32 fromtid = 0, rcode = 0;
4659 afs_int32 code = 0, error = 0;
4662 time_t tmv = fromdate;
4666 #ifndef AFS_NT40_ENV
4667 (void)signal(SIGPIPE, dump_sig_handler);
4669 (void)signal(SIGINT, dump_sig_handler);
4672 VEPRINT("Full Dump ...\n");
4674 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4678 /* get connections to the servers */
4679 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4681 VEPRINT1("Starting transaction on volume %u...", afromvol);
4682 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4683 EGOTO1(error_exit, code,
4684 "Could not start transaction on the volume %u to be dumped\n",
4688 /* Get a clone id */
4689 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4691 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4693 EGOTO1(error_exit, code,
4694 "Could not get an ID for the clone of volume %u from the VLDB\n",
4698 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4699 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4701 strcpy(vname, "dump-clone-temp");
4704 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
4706 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4710 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4712 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4716 EGOTO1(error_exit, code,
4717 "Failed to end the transaction on the volume %u\n", afromvol);
4721 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4724 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4727 EGOTO1(error_exit, code,
4728 "Failed to start a transaction on the cloned volume%u\n",
4732 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4733 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4734 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4739 fromcall = rx_NewCall(fromconn);
4741 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4742 if (flags & VOLDUMPV2_OMITDIRS)
4743 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4745 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4746 EGOTO(error_exit, code, "Could not start the dump process \n");
4749 VEPRINT1("Dumping volume %u...", afromvol);
4750 code = DumpFunction(fromcall, rock);
4751 EGOTO(error_exit, code, "Error while dumping volume \n");
4755 /* now delete the clone */
4756 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4757 code = AFSVolDeleteVolume(fromconn, clonetid);
4759 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4760 (unsigned long)clonevol);
4766 code = rx_EndCall(fromcall, 0);
4768 fprintf(STDERR, "Error in rx_EndCall\n");
4774 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4775 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4776 if (code || rcode) {
4778 "Could not end transaction on the cloned volume %lu\n",
4779 (unsigned long)clonevol);
4781 error = (code ? code : rcode);
4786 rx_DestroyConnection(fromconn);
4788 PrintError("", error);
4795 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4796 * the dump file <afilename>. WriteData does all the real work
4797 * after extracting params from the rock
4800 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4801 afs_uint32 toparentid, char tovolname[], int flags,
4802 afs_int32(*WriteData) (struct rx_call *, void *),
4805 struct rx_connection *toconn, *tempconn;
4806 struct rx_call *tocall;
4807 afs_int32 totid, code, rcode, vcode, terror = 0;
4808 struct volser_status tstatus;
4809 struct volintInfo vinfo;
4811 char tovolreal[VOLSER_OLDMAXVOLNAME];
4813 afs_int32 temptid, pparentid;
4814 struct nvldbentry entry, storeEntry;
4817 struct restoreCookie cookie;
4819 afs_int32 volflag, voltype, volsertype;
4820 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4821 int index, same, errcode;
4825 memset(&cookie, 0, sizeof(cookie));
4829 tocall = (struct rx_call *)0;
4830 tempconn = (struct rx_connection *)0;
4834 if (flags & RV_RDONLY) {
4836 volsertype = volser_RO;
4839 volsertype = volser_RW;
4843 pparentid = toparentid;
4844 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4845 if (pvolid == 0) { /*alot a new id if needed */
4846 vcode = VLDB_GetEntryByName(tovolname, &entry);
4847 if (vcode == VL_NOENT) {
4848 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4850 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4856 } else if (flags & RV_RDONLY) {
4857 if (entry.flags & VLF_RWEXISTS) {
4859 "Entry for ReadWrite volume %s already exists!\n",
4861 error = VOLSERBADOP;
4864 if (!entry.volumeId[ROVOL]) {
4866 "Existing entry for volume %s has no ReadOnly ID\n",
4868 error = VOLSERBADOP;
4871 pvolid = entry.volumeId[ROVOL];
4872 pparentid = entry.volumeId[RWVOL];
4874 pvolid = entry.volumeId[RWVOL];
4875 pparentid = entry.volumeId[RWVOL];
4878 if (!pparentid) pparentid = pvolid;
4879 /* at this point we have a volume id to use/reuse for the volume to be restored */
4880 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4882 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4883 EGOTO1(refail, VOLSERBADOP,
4884 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4887 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4888 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4889 EGOTO1(refail, VOLSERBADOP,
4890 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4892 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4895 MapPartIdIntoName(topart, partName);
4896 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4897 tovolreal, (unsigned long)pvolid,
4898 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4899 hostutil_GetNameByINet(toserver), partName);
4902 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4905 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4906 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4908 if (code && code != VNOVOL) {
4914 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4916 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4919 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4920 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4923 code = AFSVolGetStatus(toconn, totid, &tstatus);
4924 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4928 oldCreateDate = tstatus.creationDate;
4929 oldUpdateDate = tstatus.updateDate;
4935 cookie.parent = pparentid;
4936 cookie.type = voltype;
4938 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4940 tocall = rx_NewCall(toconn);
4941 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4943 fprintf(STDERR, "Volume restore Failed \n");
4947 code = WriteData(tocall, rock);
4949 fprintf(STDERR, "Could not transmit data\n");
4953 terror = rx_EndCall(tocall, 0);
4954 tocall = (struct rx_call *)0;
4956 fprintf(STDERR, "rx_EndCall Failed \n");
4960 code = AFSVolGetStatus(toconn, totid, &tstatus);
4963 "Could not get status information about the volume %lu\n",
4964 (unsigned long)pvolid);
4968 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4970 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4971 (unsigned long)pvolid);
4976 if (flags & RV_CRDUMP)
4977 newCreateDate = tstatus.creationDate;
4978 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4979 newCreateDate = oldCreateDate;
4981 newCreateDate = time(0);
4982 if (flags & RV_LUDUMP)
4983 newUpdateDate = tstatus.updateDate;
4984 else if (flags & RV_LUKEEP)
4985 newUpdateDate = oldUpdateDate;
4987 newUpdateDate = time(0);
4988 code = AFSVolSetDate(toconn,totid, newCreateDate);
4990 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4995 init_volintInfo(&vinfo);
4996 vinfo.creationDate = newCreateDate;
4997 vinfo.updateDate = newUpdateDate;
4998 code = AFSVolSetInfo(toconn, totid, &vinfo);
5000 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
5006 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
5007 code = AFSVolSetFlags(toconn, totid, volflag);
5009 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
5014 /* It isn't handled right in refail */
5015 code = AFSVolEndTrans(toconn, totid, &rcode);
5020 fprintf(STDERR, "Could not end transaction on %lu\n",
5021 (unsigned long)pvolid);
5026 fprintf(STDOUT, " done\n");
5028 if (!reuseID || (flags & RV_FULLRST)) {
5029 /* Volume was restored on the file server, update the
5030 * VLDB to reflect the change.
5032 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
5033 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
5035 "Could not fetch the entry for volume number %lu from VLDB \n",
5036 (unsigned long)pvolid);
5041 MapHostToNetwork(&entry);
5042 if (vcode == VL_NOENT) { /* it doesnot exist already */
5043 /*make the vldb return this indication specifically */
5044 VPRINT("------- Creating a new VLDB entry ------- \n");
5045 strcpy(entry.name, tovolname);
5047 entry.serverNumber[0] = toserver; /*should be indirect */
5048 entry.serverPartition[0] = topart;
5049 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
5050 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
5051 if (flags & RV_RDONLY)
5052 entry.volumeId[ROVOL] = pvolid;
5053 else if (tstatus.cloneID != 0) {
5054 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
5056 entry.volumeId[ROVOL] = INVALID_BID;
5057 entry.volumeId[RWVOL] = pparentid;
5059 if (tstatus.backupID != 0) {
5060 entry.volumeId[BACKVOL] = tstatus.backupID;
5061 /*this should come from status info on the volume if non zero */
5063 entry.volumeId[BACKVOL] = INVALID_BID;
5064 MapNetworkToHost(&entry, &storeEntry);
5065 vcode = VLDB_CreateEntry(&storeEntry);
5068 "Could not create the VLDB entry for volume number %lu \n",
5069 (unsigned long)pvolid);
5075 EnumerateEntry(&entry);
5076 } else { /*update the existing entry */
5078 fprintf(STDOUT, "Updating the existing VLDB entry\n");
5079 fprintf(STDOUT, "------- Old entry -------\n");
5080 EnumerateEntry(&entry);
5081 fprintf(STDOUT, "------- New entry -------\n");
5084 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
5088 "Could not lock the entry for volume number %lu \n",
5089 (unsigned long)pvolid);
5094 strcpy(entry.name, tovolname);
5096 /* Update the vlentry with the new information */
5097 if (flags & RV_RDONLY)
5098 index = Lp_ROMatch(toserver, topart, &entry) - 1;
5100 index = Lp_GetRwIndex(&entry);
5102 /* Add the new site for the volume being restored */
5103 entry.serverNumber[entry.nServers] = toserver;
5104 entry.serverPartition[entry.nServers] = topart;
5105 entry.serverFlags[entry.nServers] =
5106 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
5109 /* This volume should be deleted on the old site
5110 * if its different from new site.
5113 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
5117 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
5119 if ((!errcode && !same)
5120 || (entry.serverPartition[index] != topart)) {
5121 if (flags & RV_NODEL) {
5123 ("Not deleting the previous volume %u on server %s, ...",
5125 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
5126 hostutil_GetNameByINet(entry.serverNumber[index]));
5129 UV_Bind(entry.serverNumber[index],
5130 AFSCONF_VOLUMEPORT);
5132 MapPartIdIntoName(entry.serverPartition[index],
5135 ("Deleting the previous volume %u on server %s, partition %s ...",
5137 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
5138 hostutil_GetNameByINet(entry.serverNumber[index]),
5140 code = DoVolDelete(tempconn, pvolid,
5141 entry.serverPartition[index],
5142 "the", 0, NULL, NULL);
5143 if (code && code != VNOVOL) {
5147 MapPartIdIntoName(entry.serverPartition[index],
5151 entry.serverNumber[index] = toserver;
5152 entry.serverPartition[index] = topart;
5155 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
5156 MapNetworkToHost(&entry, &storeEntry);
5158 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
5159 LOCKREL_OPCODE | LOCKREL_AFSID |
5163 "Could not update the entry for volume number %lu \n",
5164 (unsigned long)pvolid);
5170 EnumerateEntry(&entry);
5177 code = rx_EndCall(tocall, 0);
5183 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
5184 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5187 "Could not release lock on the VLDB entry for the volume %lu\n",
5188 (unsigned long)pvolid);
5194 code = AFSVolEndTrans(toconn, totid, &rcode);
5198 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
5199 (unsigned long)pvolid);
5205 code = AFSVolEndTrans(toconn, temptid, &rcode);
5209 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
5210 (unsigned long)pvolid);
5216 rx_DestroyConnection(tempconn);
5218 rx_DestroyConnection(toconn);
5219 PrintError("", error);
5224 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
5225 char tovolname[], int flags,
5226 afs_int32(*WriteData) (struct rx_call *, void *),
5229 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
5234 /*unlocks the vldb entry associated with <volid> */
5236 UV_LockRelease(afs_uint32 volid)
5240 VPRINT("Binding to the VLDB server\n");
5242 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5243 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5246 "Could not unlock the entry for volume number %lu in VLDB \n",
5247 (unsigned long)volid);
5248 PrintError("", vcode);
5251 VPRINT("VLDB updated\n");
5256 /* old interface to add rosites */
5258 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5261 return UV_AddSite2(server, part, volid, 0, valid);
5264 /*adds <server> and <part> as a readonly replication site for <volid>
5267 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5268 afs_uint32 rovolid, afs_int32 valid)
5270 int j, nro = 0, islocked = 0;
5271 struct nvldbentry entry, storeEntry, entry2;
5272 afs_int32 vcode, error = 0;
5275 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5278 " Could not lock the VLDB entry for the volume %lu \n",
5279 (unsigned long)volid);
5284 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
5287 "Could not fetch the VLDB entry for volume number %lu \n",
5288 (unsigned long)volid);
5292 if (!ISNAMEVALID(entry.name)) {
5294 "Volume name %s is too long, rename before adding site\n",
5296 error = VOLSERBADOP;
5299 MapHostToNetwork(&entry);
5301 /* See if it's too many entries */
5302 if (entry.nServers >= NMAXNSERVERS) {
5303 fprintf(STDERR, "Total number of entries will exceed %u\n",
5305 error = VOLSERBADOP;
5309 /* See if it's on the same server */
5310 for (j = 0; j < entry.nServers; j++) {
5311 if (entry.serverFlags[j] & VLSF_ROVOL) {
5313 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5316 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5319 MapPartIdIntoName(entry.serverPartition[j], apartName);
5321 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5323 error = VOLSERBADOP;
5330 /* See if it's too many RO sites - leave one for the RW */
5331 if (nro >= NMAXNSERVERS - 1) {
5332 fprintf(STDERR, "Total number of sites will exceed %u\n",
5334 error = VOLSERBADOP;
5338 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5339 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5340 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5343 if (entry.volumeId[ROVOL] == INVALID_BID) {
5344 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5346 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5349 VPRINT1("Using RO volume id %d.\n", rovolid);
5350 entry.volumeId[ROVOL] = rovolid;
5352 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5353 rovolid, entry.volumeId[ROVOL]);
5357 VPRINT("Adding a new site ...");
5358 entry.serverNumber[entry.nServers] = server;
5359 entry.serverPartition[entry.nServers] = part;
5361 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5363 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5367 MapNetworkToHost(&entry, &storeEntry);
5369 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5370 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5372 fprintf(STDERR, "Could not update entry for volume %lu \n",
5373 (unsigned long)volid);
5382 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5383 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5386 "Could not release lock on volume entry for %lu \n",
5387 (unsigned long)volid);
5388 PrintError("", vcode);
5392 PrintError("", error);
5396 /*removes <server> <part> as read only site for <volid> from the vldb */
5398 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5401 struct nvldbentry entry, storeEntry;
5403 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5405 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5406 (unsigned long)volid);
5407 PrintError("", vcode);
5410 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5413 "Could not fetch the entry for volume number %lu from VLDB \n",
5414 (unsigned long)volid);
5415 PrintError("", vcode);
5418 MapHostToNetwork(&entry);
5419 if (!Lp_ROMatch(server, part, &entry)) {
5420 /*this site doesnot exist */
5421 fprintf(STDERR, "This site is not a replication site \n");
5423 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5424 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5426 fprintf(STDERR, "Could not update entry for volume %lu \n",
5427 (unsigned long)volid);
5428 PrintError("", vcode);
5429 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5430 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5434 } else { /*remove the rep site */
5435 Lp_SetROValue(&entry, server, part, 0, 0);
5437 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5438 entry.flags &= ~VLF_ROEXISTS;
5439 if (entry.nServers < 1) { /*this is the last ref */
5440 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5442 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5445 "Could not delete VLDB entry for volume %lu \n",
5446 (unsigned long)volid);
5447 PrintError("", vcode);
5452 MapNetworkToHost(&entry, &storeEntry);
5453 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5454 (unsigned long)volid);
5457 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5458 LOCKREL_OPCODE | LOCKREL_AFSID |
5462 "Could not release lock on volume entry for %lu \n",
5463 (unsigned long)volid);
5464 PrintError("", vcode);
5465 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5466 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5474 /*sets <server> <part> as read/write site for <volid> in the vldb */
5476 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5479 struct nvldbentry entry, storeEntry;
5482 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5484 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5485 (unsigned long)volid);
5486 PrintError("", vcode);
5489 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5492 "Could not fetch the entry for volume number %lu from VLDB \n",
5493 (unsigned long)volid);
5494 PrintError("", vcode);
5497 MapHostToNetwork(&entry);
5498 index = Lp_GetRwIndex(&entry);
5500 /* no RW site exists */
5501 fprintf(STDERR, "No existing RW site for volume %lu",
5502 (unsigned long)volid);
5504 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5505 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5508 "Could not release lock on entry for volume %lu \n",
5509 (unsigned long)volid);
5510 PrintError("", vcode);
5514 } else { /* change the RW site */
5515 entry.serverNumber[index] = server;
5516 entry.serverPartition[index] = part;
5517 MapNetworkToHost(&entry, &storeEntry);
5519 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5520 LOCKREL_OPCODE | LOCKREL_AFSID |
5523 fprintf(STDERR, "Could not update entry for volume %lu \n",
5524 (unsigned long)volid);
5525 PrintError("", vcode);
5526 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5527 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5535 /*list all the partitions on <aserver> */
5537 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5540 struct rx_connection *aconn;
5541 struct pIDs partIds;
5542 struct partEntries partEnts;
5546 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5548 partEnts.partEntries_len = 0;
5549 partEnts.partEntries_val = NULL;
5550 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5551 if (code == RXGEN_OPCODE) {
5552 for (i = 0; i < 26; i++) /* try old interface */
5553 partIds.partIds[i] = -1;
5554 code = AFSVolListPartitions(aconn, &partIds);
5556 for (i = 0; i < 26; i++) {
5557 if ((partIds.partIds[i]) != -1) {
5558 ptrPartList->partId[j] = partIds.partIds[i];
5559 ptrPartList->partFlags[j] = PARTVALID;
5562 ptrPartList->partFlags[i] = 0;
5567 *cntp = partEnts.partEntries_len;
5568 if (*cntp > VOLMAXPARTS) {
5570 "Warning: number of partitions on the server too high %d (process only %d)\n",
5571 *cntp, VOLMAXPARTS);
5572 *cntp = VOLMAXPARTS;
5574 for (i = 0; i < *cntp; i++) {
5575 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5576 ptrPartList->partFlags[i] = PARTVALID;
5578 free(partEnts.partEntries_val);
5584 "Could not fetch the list of partitions from the server\n");
5585 PrintError("", code);
5587 rx_DestroyConnection(aconn);
5592 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5593 This is used by the backup system */
5595 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5596 struct volDescription *volPtr, afs_int32 arraySize)
5598 struct rx_connection *aconn;
5599 struct volDescription *curPtr;
5602 afs_int32 success = 1;
5604 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5606 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5607 if (curPtr->volFlags & CLONEVALID) {
5608 curPtr->volFlags &= ~CLONEZAPPED;
5611 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5612 "clone", 0, NULL, NULL);
5617 curPtr->volFlags |= CLONEZAPPED;
5619 fprintf(STDERR, "Could not zap volume %lu\n",
5620 (unsigned long)curPtr->volCloneId);
5622 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5623 curPtr->volCloneId);
5628 rx_DestroyConnection(aconn);
5632 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5635 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5636 struct volDescription *volPtr, afs_int32 arraySize)
5638 struct rx_connection *aconn;
5639 struct volDescription *curPtr;
5642 afs_int32 rcode = 0;
5644 int reuseCloneId = 0;
5645 afs_uint32 curCloneId = 0;
5646 char cloneName[256]; /*max vol name */
5648 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5650 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5652 else { /*get a bunch of id's from vldb */
5654 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5656 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5657 PrintError("", code);
5662 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5663 if (curPtr->volFlags & ENTRYVALID) {
5665 curPtr->volFlags |= CLONEVALID;
5666 /*make a clone of curParentId and record as curPtr->volCloneId */
5668 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5671 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5674 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5678 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5679 strcpy(cloneName, curPtr->volName);
5680 strcat(cloneName, "-tmpClone-");
5682 strcpy(cloneName, "-tmpClone");
5684 curPtr->volCloneId = curCloneId;
5689 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5690 &(curPtr->volCloneId));
5692 curPtr->volFlags &= ~CLONEVALID;
5694 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5695 curPtr->volName, (unsigned long)code);
5696 code = AFSVolEndTrans(aconn, tid, &rcode);
5698 fprintf(STDERR, "WARNING: could not end transaction\n");
5701 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5702 curPtr->volCloneId);
5703 code = AFSVolEndTrans(aconn, tid, &rcode);
5704 if (code || rcode) {
5705 curPtr->volFlags &= ~CLONEVALID;
5714 rx_DestroyConnection(aconn);
5719 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5720 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5722 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5723 struct volintInfo **resultPtr, afs_int32 * size)
5725 struct rx_connection *aconn;
5727 volEntries volumeInfo;
5731 *resultPtr = (volintInfo *) 0;
5732 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5733 volumeInfo.volEntries_len = 0;
5735 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5736 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5739 "Could not fetch the list of volumes from the server\n");
5741 *resultPtr = volumeInfo.volEntries_val;
5742 *size = volumeInfo.volEntries_len;
5746 rx_DestroyConnection(aconn);
5747 PrintError("", code);
5751 /*------------------------------------------------------------------------
5752 * EXPORTED UV_XListVolumes
5755 * List the extended information for all the volumes on a particular
5756 * File Server and partition. We may either return the volume's ID
5757 * or all of its extended information.
5760 * a_serverID : Address of the File Server for which we want
5761 * extended volume info.
5762 * a_partID : Partition for which we want the extended
5764 * a_all : If non-zero, fetch ALL the volume info,
5765 * otherwise just the volume ID.
5766 * a_resultPP : Ptr to the address of the area containing
5767 * the returned volume info.
5768 * a_numEntsInResultP : Ptr for the value we set for the number of
5773 * Otherise, the return value of AFSVolXListVolumes.
5776 * This routine is closely related to UV_ListVolumes, which returns
5777 * only the standard level of detail on AFS volumes. It is a
5778 * heavyweight operation, zipping through all the volume entries for
5779 * a given server/partition.
5783 *------------------------------------------------------------------------*/
5786 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5787 struct volintXInfo **a_resultPP,
5788 afs_int32 * a_numEntsInResultP)
5790 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5791 afs_int32 code; /*Error code to return */
5792 volXEntries volumeXInfo; /*Area for returned extended vol info */
5795 * Set up our error code and the area for returned extended volume info.
5796 * We set the val field to a null pointer as a hint for the stub to
5799 *a_numEntsInResultP = 0;
5800 *a_resultPP = (volintXInfo *) 0;
5801 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5802 volumeXInfo.volXEntries_len = 0;
5805 * Bind to the Volume Server port on the File Server machine in question,
5808 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5809 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5811 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5814 * We got the info; pull out the pointer to where the results lie
5815 * and how many entries are there.
5817 *a_resultPP = volumeXInfo.volXEntries_val;
5818 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5822 * If we got an Rx connection, throw it away.
5825 rx_DestroyConnection(rxConnP);
5827 PrintError("", code);
5829 } /*UV_XListVolumes */
5831 /* get all the information about volume <volid> on <aserver> and <apart> */
5833 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5834 struct volintInfo **resultPtr)
5836 struct rx_connection *aconn;
5838 volEntries volumeInfo;
5840 *resultPtr = (volintInfo *) 0;
5841 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5842 volumeInfo.volEntries_len = 0;
5844 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5845 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5848 "Could not fetch the information about volume %lu from the server\n",
5849 (unsigned long)volid);
5851 *resultPtr = volumeInfo.volEntries_val;
5856 rx_DestroyConnection(aconn);
5857 PrintError("", code);
5861 /*------------------------------------------------------------------------
5862 * EXPORTED UV_XListOneVolume
5865 * List the extended information for a volume on a particular File
5866 * Server and partition.
5869 * a_serverID : Address of the File Server for which we want
5870 * extended volume info.
5871 * a_partID : Partition for which we want the extended
5873 * a_volID : Volume ID for which we want the info.
5874 * a_resultPP : Ptr to the address of the area containing
5875 * the returned volume info.
5879 * Otherise, the return value of AFSVolXListOneVolume.
5882 * This routine is closely related to UV_ListOneVolume, which returns
5883 * only the standard level of detail on the chosen AFS volume.
5887 *------------------------------------------------------------------------*/
5890 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5891 struct volintXInfo **a_resultPP)
5893 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5894 afs_int32 code; /*Error code */
5895 volXEntries volumeXInfo; /*Area for returned info */
5898 * Set up our error code, and the area we're in which we are returning
5899 * the info. Setting the val field to a null pointer tells the stub
5900 * to allocate space for us.
5902 *a_resultPP = (volintXInfo *) 0;
5903 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5904 volumeXInfo.volXEntries_len = 0;
5907 * Bind to the Volume Server port on the File Server machine in question,
5910 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5911 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5914 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5917 * We got the info; pull out the pointer to where the results lie.
5919 *a_resultPP = volumeXInfo.volXEntries_val;
5922 * If we got an Rx connection, throw it away.
5925 rx_DestroyConnection(rxConnP);
5927 PrintError("", code);
5932 * Given a volume we read from a partition, check if it is
5933 * represented in the VLDB correctly.
5935 * The VLDB is looked up by the RW volume id (not its name).
5936 * The RW contains the true name of the volume (BK and RO set
5937 * the name in the VLDB only on creation of the VLDB entry).
5938 * We want rules strict enough that when we check all volumes
5939 * on one partition, it does not need to be done again. IE:
5940 * two volumes on different partitions won't constantly
5941 * change a VLDB entry away from what the other set.
5942 * For RW and BK volumes, we will always check the VLDB to see
5943 * if the two exist on the server/partition. May seem redundant,
5944 * but this is an easy check of the VLDB. IE: if the VLDB entry
5945 * says the BK exists but no BK volume is there, we will detect
5946 * this when we check the RW volume.
5947 * VLDB entries are locked only when a change needs to be done.
5948 * Output changed to look a lot like the "vos syncserv" otuput.
5951 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5952 afs_int32 * modentry, afs_uint32 * maxvolid,
5953 struct nvldbentry *aentry)
5957 afs_int32 code, error = 0;
5958 struct nvldbentry entry, storeEntry;
5960 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5970 ((volumeinfo->type ==
5971 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5974 /* Check to see if the VLDB is ok without locking it (pass 1).
5975 * If it will change, then lock the VLDB entry, read it again,
5976 * then make the changes to it (pass 2).
5979 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5981 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5982 (unsigned long)rwvolid);
5987 createentry = 0; /* Do we need to create a VLDB entry */
5988 addvolume = 0; /* Add this volume to the VLDB entry */
5989 modified = 0; /* The VLDB entry was modified */
5992 memcpy(&entry, aentry, sizeof(entry));
5994 /* Read the entry from VLDB by its RW volume id */
5995 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5997 if (code != VL_NOENT) {
5999 "Could not retrieve the VLDB entry for volume %lu \n",
6000 (unsigned long)rwvolid);
6004 memset(&entry, 0, sizeof(entry));
6005 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
6009 MapHostToNetwork(&entry);
6013 if (verbose && (pass == 1)) {
6014 fprintf(STDOUT, "_______________________________\n");
6015 fprintf(STDOUT, "\n-- status before -- \n");
6017 fprintf(STDOUT, "\n**does not exist**\n");
6019 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
6020 || (entry.flags & VLF_BACKEXISTS))
6021 EnumerateEntry(&entry);
6023 fprintf(STDOUT, "\n");
6026 if (volumeinfo->type == RWVOL) { /* RW volume exists */
6032 /* Check existence of RW and BK volumes */
6033 code = CheckVldbRWBK(&entry, &mod);
6039 idx = Lp_GetRwIndex(&entry);
6040 if (idx == -1) { /* RW index not found in the VLDB entry */
6041 idx = entry.nServers; /* put it into next index */
6044 } else { /* RW index found in the VLDB entry. */
6045 /* Verify if this volume's location matches where the VLDB says it is */
6046 if (!Lp_Match(aserver, apart, &entry)) {
6047 if (entry.flags & VLF_RWEXISTS) {
6048 /* The RW volume exists elsewhere - report this one a duplicate */
6050 MapPartIdIntoName(apart, pname);
6052 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
6053 (unsigned long)rwvolid,
6055 afs_inet_ntoa_r(aserver, hoststr) :
6056 hostutil_GetNameByINet(aserver), pname);
6057 MapPartIdIntoName(entry.serverPartition[idx],
6060 " VLDB reports RW volume %lu exists on %s %s\n",
6061 (unsigned long)rwvolid,
6063 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
6064 hostutil_GetNameByINet(entry.
6069 /* The RW volume does not exist - have VLDB point to this one */
6072 /* Check for orphaned BK volume on old partition */
6073 if (entry.flags & VLF_BACKEXISTS) {
6075 MapPartIdIntoName(entry.serverPartition[idx],
6078 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
6079 entry.volumeId[BACKVOL],
6081 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
6082 hostutil_GetNameByINet(entry.
6085 MapPartIdIntoName(apart, pname);
6087 " VLDB reports its RW volume %lu exists on %s %s\n",
6088 (unsigned long)rwvolid,
6090 afs_inet_ntoa_r(aserver, hoststr) :
6091 hostutil_GetNameByINet(aserver),
6097 /* Volume location matches the VLDB location */
6098 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
6099 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
6102 (entry.name, volumeinfo->name,
6103 VOLSER_OLDMAXVOLNAME) != 0)) {
6111 entry.flags |= VLF_RWEXISTS;
6112 entry.volumeId[RWVOL] = rwvolid;
6113 if (!entry.volumeId[BACKVOL])
6114 entry.volumeId[BACKVOL] = volumeinfo->backupID;
6115 if (!entry.volumeId[ROVOL])
6116 entry.volumeId[ROVOL] = volumeinfo->cloneID;
6118 entry.serverFlags[idx] = VLSF_RWVOL;
6119 entry.serverNumber[idx] = aserver;
6120 entry.serverPartition[idx] = apart;
6121 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
6125 /* One last check - to update BK if need to */
6126 code = CheckVldbRWBK(&entry, &mod);
6134 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
6140 /* Check existence of RW and BK volumes */
6141 code = CheckVldbRWBK(&entry, &mod);
6147 idx = Lp_GetRwIndex(&entry);
6148 if (idx == -1) { /* RW index not found in the VLDB entry */
6149 idx = entry.nServers; /* Put it into next index */
6152 } else { /* RW index found in the VLDB entry */
6153 /* Verify if this volume's location matches where the VLDB says it is */
6154 if (!Lp_Match(aserver, apart, &entry)) {
6155 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
6157 MapPartIdIntoName(apart, pname);
6159 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
6160 (unsigned long)volumeinfo->volid,
6162 afs_inet_ntoa_r(aserver, hoststr) :
6163 hostutil_GetNameByINet(aserver), pname);
6164 MapPartIdIntoName(entry.serverPartition[idx], pname);
6166 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
6167 (unsigned long)rwvolid,
6169 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
6170 hostutil_GetNameByINet(entry.
6175 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
6176 if (!(entry.flags & VLF_BACKEXISTS)) {
6178 } else if (volumeinfo->volid >
6179 entry.volumeId[BACKVOL]) {
6183 MapPartIdIntoName(entry.serverPartition[idx],
6186 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
6187 entry.volumeId[BACKVOL],
6189 afs_inet_ntoa_r(aserver, hoststr) :
6190 hostutil_GetNameByINet(aserver),
6193 " VLDB reports its BK volume ID is %lu\n",
6194 (unsigned long)volumeinfo->volid);
6198 MapPartIdIntoName(entry.serverPartition[idx],
6201 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
6202 (unsigned long)volumeinfo->volid,
6204 afs_inet_ntoa_r(aserver, hoststr) :
6205 hostutil_GetNameByINet(aserver),
6208 " VLDB reports its BK volume ID is %u\n",
6209 entry.volumeId[BACKVOL]);
6212 } else if (!entry.volumeId[BACKVOL]) {
6219 entry.flags |= VLF_BACKEXISTS;
6220 entry.volumeId[RWVOL] = rwvolid;
6221 entry.volumeId[BACKVOL] = volumeinfo->volid;
6223 entry.serverNumber[idx] = aserver;
6224 entry.serverPartition[idx] = apart;
6225 entry.serverFlags[idx] = VLSF_RWVOL;
6231 else if (volumeinfo->type == ROVOL) { /* A RO volume */
6232 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
6233 /* This is a quick check to see if the RO entry exists in the
6234 * VLDB so we avoid the CheckVldbRO() call (which checks if each
6235 * RO volume listed in the VLDB exists).
6237 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6239 idx = entry.nServers;
6243 if (!(entry.flags & VLF_ROEXISTS)) {
6248 /* Before we correct the VLDB entry, make sure all the
6249 * ROs listed in the VLDB exist.
6251 code = CheckVldbRO(&entry, &mod);
6257 if (!(entry.flags & VLF_ROEXISTS)) {
6258 /* No RO exists in the VLDB entry - add this one */
6259 idx = entry.nServers;
6262 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
6263 /* The volume headers's RO ID does not match that in the VLDB entry,
6264 * and the vol hdr's ID is greater (implies more recent). So delete
6265 * all the RO volumes listed in VLDB entry and add this volume.
6267 for (j = 0; j < entry.nServers; j++) {
6268 if (entry.serverFlags[j] & VLSF_ROVOL) {
6269 /* Verify this volume exists and print message we are orphaning it */
6271 MapPartIdIntoName(apart, pname);
6273 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
6274 entry.volumeId[ROVOL],
6276 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
6277 hostutil_GetNameByINet(entry.
6281 " VLDB reports its RO volume ID is %lu\n",
6282 (unsigned long)volumeinfo->volid);
6285 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6286 entry.serverPartition[idx], 0L, 0L);
6293 idx = entry.nServers;
6296 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6297 /* The volume headers's RO ID does not match that in the VLDB entry,
6298 * and the vol hdr's ID is lower (implies its older). So orphan it.
6301 MapPartIdIntoName(apart, pname);
6303 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6304 (unsigned long)volumeinfo->volid,
6306 afs_inet_ntoa_r(aserver, hoststr) :
6307 hostutil_GetNameByINet(aserver), pname);
6309 " VLDB reports its RO volume ID is %u\n",
6310 entry.volumeId[ROVOL]);
6313 /* The RO volume ID in the volume header match that in the VLDB entry,
6314 * and there exist RO volumes in the VLDB entry. See if any of them
6315 * are this one. If not, then we add it.
6317 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6319 idx = entry.nServers;
6327 entry.flags |= VLF_ROEXISTS;
6328 entry.volumeId[RWVOL] = rwvolid;
6329 entry.volumeId[ROVOL] = volumeinfo->volid;
6331 entry.serverNumber[idx] = aserver;
6332 entry.serverPartition[idx] = apart;
6333 entry.serverFlags[idx] = VLSF_ROVOL;
6339 /* Remember largest volume id */
6340 if (entry.volumeId[ROVOL] > *maxvolid)
6341 *maxvolid = entry.volumeId[ROVOL];
6342 if (entry.volumeId[BACKVOL] > *maxvolid)
6343 *maxvolid = entry.volumeId[BACKVOL];
6344 if (entry.volumeId[RWVOL] > *maxvolid)
6345 *maxvolid = entry.volumeId[RWVOL];
6347 if (modified && doit) {
6348 MapNetworkToHost(&entry, &storeEntry);
6351 code = VLDB_CreateEntry(&storeEntry);
6354 "Could not create a VLDB entry for the volume %lu\n",
6355 (unsigned long)rwvolid);
6362 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6363 LOCKREL_OPCODE | LOCKREL_AFSID |
6366 fprintf(STDERR, "Could not update entry for %lu\n",
6367 (unsigned long)rwvolid);
6371 } else if (pass == 2) {
6373 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6374 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6376 PrintError("Could not unlock VLDB entry ", code);
6380 if (modified && modentry) {
6385 memcpy(aentry, &entry, sizeof(entry));
6389 fprintf(STDOUT, "-- status after --\n");
6391 EnumerateEntry(&entry);
6393 fprintf(STDOUT, "\n**no change**\n");
6397 VPRINT("\n_______________________________\n");
6402 sortVolumes(const void *a, const void *b)
6404 volintInfo *v1 = (volintInfo *) a;
6405 volintInfo *v2 = (volintInfo *) b;
6406 afs_uint32 rwvolid1, rwvolid2;
6408 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6409 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6411 if (rwvolid1 > rwvolid2)
6412 return -1; /* lower RW id goes first */
6413 if (rwvolid1 < rwvolid2)
6416 if (v1->type == RWVOL)
6417 return -1; /* RW vols go first */
6418 if (v2->type == RWVOL)
6421 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6422 return -1; /* BK vols next */
6423 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6426 if (v1->volid < v2->volid)
6427 return 1; /* larger volids first */
6428 if (v1->volid > v2->volid)
6434 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6435 * Synchronize an individual volume against a sever and partition.
6436 * Checks the VLDB entry (similar to syncserv) as well as checks
6437 * if the volume exists on specified servers (similar to syncvldb).
6440 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6442 struct rx_connection *aconn = 0;
6443 afs_int32 j, k, code, vcode, error = 0;
6445 afs_int32 mod, modified = 0, deleted = 0;
6446 struct nvldbentry vldbentry;
6447 afs_uint32 volumeid = 0;
6448 volEntries volumeInfo;
6449 struct partList PartList;
6451 afs_uint32 maxvolid = 0;
6453 volumeInfo.volEntries_val = (volintInfo *) 0;
6454 volumeInfo.volEntries_len = 0;
6456 /* Turn verbose logging off and do our own verbose logging */
6457 /* tverbose must be set before we call ERROR_EXIT() */
6464 if (!aserver && (flags & 1)) {
6465 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6469 /* Read the VLDB entry */
6470 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6471 if (vcode && (vcode != VL_NOENT)) {
6472 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6475 } else if (!vcode) {
6476 MapHostToNetwork(&vldbentry);
6480 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6481 fprintf(STDOUT, "_______________________________\n");
6482 fprintf(STDOUT, "\n-- status before -- \n");
6484 fprintf(STDOUT, "\n**does not exist**\n");
6486 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6487 || (vldbentry.flags & VLF_BACKEXISTS))
6488 EnumerateEntry(&vldbentry);
6490 fprintf(STDOUT, "\n");
6493 /* Verify that all of the VLDB entries exist on the repective servers
6494 * and partitions (this does not require that avolname be a volume ID).
6495 * Equivalent to a syncserv.
6498 /* Tell CheckVldb not to update if appropriate */
6503 code = CheckVldb(&vldbentry, &mod, &deleted);
6505 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6513 /* If aserver is given, we will search for the desired volume on it */
6515 /* Generate array of partitions on the server that we will check */
6517 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6520 "Could not fetch the list of partitions from the server\n");
6524 PartList.partId[0] = apart;
6528 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6530 /* If a volume ID were given, search for it on each partition */
6531 if ((volumeid = atol(avolname))) {
6532 for (j = 0; j < pcnt; j++) {
6534 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6537 if (code != ENODEV) {
6538 fprintf(STDERR, "Could not query server\n");
6546 /* Found one, sync it with VLDB entry */
6548 CheckVolume(volumeInfo.volEntries_val, aserver,
6549 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6556 if (volumeInfo.volEntries_val)
6557 free(volumeInfo.volEntries_val);
6558 volumeInfo.volEntries_val = (volintInfo *) 0;
6559 volumeInfo.volEntries_len = 0;
6563 /* Check to see if the RW, BK, and RO IDs exist on any
6564 * partitions. We get the volume IDs from the VLDB.
6566 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6567 if (vldbentry.volumeId[j] == 0)
6570 for (k = 0; k < pcnt; k++) { /* For each partition */
6571 volumeInfo.volEntries_val = (volintInfo *) 0;
6572 volumeInfo.volEntries_len = 0;
6574 AFSVolListOneVolume(aconn, PartList.partId[k],
6575 vldbentry.volumeId[j], &volumeInfo);
6577 if (code != ENODEV) {
6578 fprintf(STDERR, "Could not query server\n");
6586 /* Found one, sync it with VLDB entry */
6588 CheckVolume(volumeInfo.volEntries_val, aserver,
6589 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6596 if (volumeInfo.volEntries_val)
6597 free(volumeInfo.volEntries_val);
6598 volumeInfo.volEntries_val = (volintInfo *) 0;
6599 volumeInfo.volEntries_len = 0;
6605 /* If verbose output, print a summary of what changed */
6607 fprintf(STDOUT, "-- status after --\n");
6609 fprintf(STDOUT, "\n**entry deleted**\n");
6610 } else if (modified) {
6611 EnumerateEntry(&vldbentry);
6613 fprintf(STDOUT, "\n**no change**\n");
6615 fprintf(STDOUT, "\n_______________________________\n");
6619 /* Now check if the maxvolid is larger than that stored in the VLDB */
6621 afs_uint32 maxvldbid = 0;
6622 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6625 "Could not get the highest allocated volume id from the VLDB\n");
6628 } else if (maxvolid > maxvldbid) {
6630 id = maxvolid - maxvldbid + 1;
6631 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6634 "Error in increasing highest allocated volume id in VLDB\n");
6644 fprintf(STDOUT, "...error encountered");
6646 fprintf(STDOUT, "...done entry\n");
6649 rx_DestroyConnection(aconn);
6650 if (volumeInfo.volEntries_val)
6651 free(volumeInfo.volEntries_val);
6653 PrintError("", error);
6658 * Synchronise vldb with the file server <aserver> and,
6659 * optionally, <apart>.
6662 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6664 struct rx_connection *aconn;
6665 afs_int32 code, error = 0;
6668 volEntries volumeInfo;
6669 struct partList PartList;
6673 afs_int32 failures = 0, modifications = 0, tentries = 0;
6675 afs_uint32 maxvolid = 0;
6678 volumeInfo.volEntries_val = (volintInfo *) 0;
6679 volumeInfo.volEntries_len = 0;
6681 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6683 /* Generate array of partitions to check */
6685 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6688 "Could not fetch the list of partitions from the server\n");
6692 PartList.partId[0] = apart;
6696 VPRINT("Processing volume entries ...\n");
6698 /* Step through the array of partitions */
6699 for (i = 0; i < pcnt; i++) {
6700 apart = PartList.partId[i];
6701 MapPartIdIntoName(apart, pname);
6703 volumeInfo.volEntries_val = (volintInfo *) 0;
6704 volumeInfo.volEntries_len = 0;
6705 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6708 "Could not fetch the list of volumes from the server\n");
6712 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6713 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6714 sizeof(volintInfo), sortVolumes);
6717 for (vi = volumeInfo.volEntries_val, j = 0;
6718 j < volumeInfo.volEntries_len; j++, vi++) {
6726 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6727 j + 1, vi->name, (unsigned long)vi->volid,
6729 afs_inet_ntoa_r(aserver, hoststr) :
6730 hostutil_GetNameByINet(aserver), pname);
6738 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6740 PrintError("", code);
6743 } else if (modified) {
6749 fprintf(STDOUT, "...error encountered\n\n");
6751 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6758 "Could not process entries on server %s partition %s\n",
6760 afs_inet_ntoa_r(aserver, hoststr) :
6761 hostutil_GetNameByINet(aserver), pname);
6763 if (volumeInfo.volEntries_val) {
6764 free(volumeInfo.volEntries_val);
6765 volumeInfo.volEntries_val = 0;
6768 } /* thru all partitions */
6771 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6772 tentries, failures, modifications);
6774 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6775 tentries, failures, modifications);
6779 /* Now check if the maxvolid is larger than that stored in the VLDB */
6781 afs_uint32 maxvldbid = 0;
6782 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6785 "Could not get the highest allocated volume id from the VLDB\n");
6788 } else if (maxvolid > maxvldbid) {
6790 id = maxvolid - maxvldbid + 1;
6791 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6794 "Error in increasing highest allocated volume id in VLDB\n");
6802 rx_DestroyConnection(aconn);
6803 if (volumeInfo.volEntries_val)
6804 free(volumeInfo.volEntries_val);
6805 PrintError("", error);
6810 * Determine if a volume exists on a server and partition.
6811 * Try creating a transaction on the volume. If we can,
6812 * the volume exists, if not, then return the error code.
6813 * Some error codes mean the volume is unavailable but
6814 * still exists - so we catch these error codes.
6817 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6819 struct rx_connection *conn = (struct rx_connection *)0;
6820 afs_int32 code = -1;
6821 volEntries volumeInfo;
6823 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6825 volumeInfo.volEntries_val = (volintInfo *) 0;
6826 volumeInfo.volEntries_len = 0;
6827 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6828 if (volumeInfo.volEntries_val)
6829 free(volumeInfo.volEntries_val);
6830 if (code == VOLSERILLEGAL_PARTITION)
6832 rx_DestroyConnection(conn);
6841 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6845 afs_int32 code, error = 0;
6851 idx = Lp_GetRwIndex(entry);
6853 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6856 if (idx == -1) { /* Did not find a RW entry */
6857 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6858 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6863 VolumeExists(entry->serverNumber[idx],
6864 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6865 if (code == 0) { /* RW volume exists */
6866 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6867 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6870 } else if (code == ENODEV) { /* RW volume does not exist */
6871 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6872 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6876 /* If VLDB says it didn't exist, then ignore error */
6877 if (entry->flags & VLF_RWEXISTS) {
6878 MapPartIdIntoName(entry->serverPartition[idx], pname);
6880 "Transaction call failed for RW volume %u on server %s %s\n",
6881 entry->volumeId[RWVOL],
6883 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6884 hostutil_GetNameByINet(entry->serverNumber[idx]),
6891 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6892 * flag accordingly. idx already ponts to the RW entry.
6894 if (idx == -1) { /* Did not find a RW entry */
6895 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6896 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6899 } else { /* Found a RW entry */
6901 VolumeExists(entry->serverNumber[idx],
6902 entry->serverPartition[idx],
6903 entry->volumeId[BACKVOL]);
6904 if (code == 0) { /* BK volume exists */
6905 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6906 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6909 } else if (code == ENODEV) { /* BK volume does not exist */
6910 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6911 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6915 /* If VLDB says it didn't exist, then ignore error */
6916 if (entry->flags & VLF_BACKEXISTS) {
6917 MapPartIdIntoName(entry->serverPartition[idx], pname);
6919 "Transaction call failed for BK volume %u on server %s %s\n",
6920 entry->volumeId[BACKVOL],
6922 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6923 hostutil_GetNameByINet(entry->serverNumber[idx]),
6930 /* If there is an idx but the BK and RW volumes no
6931 * longer exist, then remove the RW entry.
6933 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6934 && !(entry->flags & VLF_BACKEXISTS)) {
6935 Lp_SetRWValue(entry, entry->serverNumber[idx],
6936 entry->serverPartition[idx], 0L, 0L);
6943 *modified = modentry;
6948 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6951 int foundro = 0, modentry = 0;
6952 afs_int32 code, error = 0;
6959 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6962 for (idx = 0; idx < entry->nServers; idx++) {
6963 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6964 continue; /* not a RO */
6968 VolumeExists(entry->serverNumber[idx],
6969 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6970 if (code == 0) { /* RO volume exists */
6972 } else if (code == ENODEV) { /* RW volume does not exist */
6973 Lp_SetROValue(entry, entry->serverNumber[idx],
6974 entry->serverPartition[idx], 0L, 0L);
6979 MapPartIdIntoName(entry->serverPartition[idx], pname);
6981 "Transaction call failed for RO %u on server %s %s\n",
6982 entry->volumeId[ROVOL],
6984 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6985 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6990 if (foundro) { /* A RO volume exists */
6991 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6992 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6995 } else { /* A RO volume does not exist */
6996 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6997 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
7004 *modified = modentry;
7009 * Ensure that <entry> matches with the info on file servers
7012 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
7014 afs_int32 code, error = 0;
7015 struct nvldbentry storeEntry;
7016 int islocked = 0, mod, modentry, delentry = 0;
7017 int pass = 0, doit=1;
7025 fprintf(STDOUT, "_______________________________\n");
7026 fprintf(STDOUT, "\n-- status before -- \n");
7027 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
7028 || (entry->flags & VLF_BACKEXISTS))
7029 EnumerateEntry(entry);
7030 fprintf(STDOUT, "\n");
7033 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
7034 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
7035 entry->name, VOLSER_OLDMAXVOLNAME - 10);
7039 /* Check to see if the VLDB is ok without locking it (pass 1).
7040 * If it will change, then lock the VLDB entry, read it again,
7041 * then make the changes to it (pass 2).
7045 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
7048 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
7049 entry->volumeId[RWVOL]);
7054 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
7056 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
7060 MapHostToNetwork(entry);
7066 /* Check if the RW and BK entries are ok */
7067 code = CheckVldbRWBK(entry, &mod);
7070 if (mod && (pass == 1) && doit)
7075 /* Check if the RO volumes entries are ok */
7076 code = CheckVldbRO(entry, &mod);
7079 if (mod && (pass == 1) && doit)
7084 /* The VLDB entry has been updated. If it as been modified, then
7085 * write the entry back out the the VLDB.
7087 if (modentry && doit) {
7091 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
7092 && !(entry->flags & VLF_ROEXISTS) && doit) {
7093 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
7095 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
7099 "Could not delete VLDB entry for volume %u \n",
7100 entry->volumeId[RWVOL]);
7105 /* Replace old entry with our new one */
7106 MapNetworkToHost(entry, &storeEntry);
7108 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
7109 (LOCKREL_OPCODE | LOCKREL_AFSID |
7110 LOCKREL_TIMESTAMP));
7112 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
7113 entry->volumeId[RWVOL]);
7120 if (modified && modentry) {
7123 if (deleted && delentry) {
7128 fprintf(STDOUT, "-- status after --\n");
7130 fprintf(STDOUT, "\n**entry deleted**\n");
7132 EnumerateEntry(entry);
7134 fprintf(STDOUT, "\n**no change**\n");
7138 VPRINT("\n_______________________________\n");
7142 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7144 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
7147 "Could not release lock on VLDB entry for volume %u\n",
7148 entry->volumeId[RWVOL]);
7157 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
7160 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
7162 struct rx_connection *aconn;
7163 afs_int32 code, error = 0;
7164 afs_int32 nentries, tentries = 0;
7165 struct VldbListByAttributes attributes;
7166 nbulkentries arrayEntries;
7167 afs_int32 failures = 0, modified, modifications = 0;
7168 struct nvldbentry *vlentry;
7169 afs_int32 si, nsi, j;
7174 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
7176 /* Set up attributes to search VLDB */
7177 attributes.server = ntohl(aserver);
7178 attributes.Mask = VLLIST_SERVER;
7180 attributes.partition = apart;
7181 attributes.Mask |= VLLIST_PARTITION;
7184 VPRINT("Processing VLDB entries ...\n");
7186 /* While we need to collect more VLDB entries */
7187 for (si = 0; si != -1; si = nsi) {
7188 memset(&arrayEntries, 0, sizeof(arrayEntries));
7190 /* Collect set of VLDB entries */
7192 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
7193 &arrayEntries, &nsi);
7194 if (code == RXGEN_OPCODE) {
7195 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
7199 fprintf(STDERR, "Could not access the VLDB for attributes\n");
7202 tentries += nentries;
7204 for (j = 0; j < nentries; j++) {
7205 vlentry = &arrayEntries.nbulkentries_val[j];
7206 MapHostToNetwork(vlentry);
7208 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
7210 /* Tell CheckVldb not to update if appropriate */
7215 code = CheckVldb(vlentry, &modified, NULL);
7217 PrintError("", code);
7219 "Could not process VLDB entry for volume %s\n",
7222 } else if (modified) {
7228 fprintf(STDOUT, "...error encountered\n\n");
7230 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
7235 if (arrayEntries.nbulkentries_val) {
7236 free(arrayEntries.nbulkentries_val);
7237 arrayEntries.nbulkentries_val = 0;
7242 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
7243 tentries, failures, modifications);
7245 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
7246 tentries, failures, modifications);
7251 rx_DestroyConnection(aconn);
7252 if (arrayEntries.nbulkentries_val)
7253 free(arrayEntries.nbulkentries_val);
7256 error = VOLSERFAILEDOP;
7260 /*rename volume <oldname> to <newname>, changing the names of the related
7261 *readonly and backup volumes. This operation is also idempotent.
7262 *salvager is capable of recovering from rename operation stopping halfway.
7263 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
7265 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
7267 struct nvldbentry storeEntry;
7268 afs_int32 vcode, code, rcode, error;
7270 char nameBuffer[256];
7272 struct rx_connection *aconn;
7277 aconn = (struct rx_connection *)0;
7281 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7284 " Could not lock the VLDB entry for the volume %u \n",
7285 entry->volumeId[RWVOL]);
7290 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7291 MapNetworkToHost(entry, &storeEntry);
7292 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7294 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7295 entry->volumeId[RWVOL]);
7299 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7300 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7301 * is concerned, oldname is lost */
7302 if (entry->flags & VLF_RWEXISTS) {
7303 index = Lp_GetRwIndex(entry);
7304 if (index == -1) { /* there is a serious discrepancy */
7306 "There is a serious discrepancy in VLDB entry for volume %u\n",
7307 entry->volumeId[RWVOL]);
7308 fprintf(STDERR, "try building VLDB from scratch\n");
7309 error = VOLSERVLDB_ERROR;
7312 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7314 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7315 entry->serverPartition[index], ITOffline, &tid);
7316 if (code) { /*volume doesnot exist */
7318 "Could not start transaction on the rw volume %u\n",
7319 entry->volumeId[RWVOL]);
7322 } else { /*volume exists, process it */
7325 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7326 entry->volumeId[RWVOL],
7327 entry->volumeId[ROVOL],
7328 entry->volumeId[BACKVOL]);
7330 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7331 code = AFSVolEndTrans(aconn, tid, &rcode);
7335 "Could not end transaction on volume %s %u\n",
7336 entry->name, entry->volumeId[RWVOL]);
7341 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7342 entry->name, entry->volumeId[RWVOL]);
7348 rx_DestroyConnection(aconn);
7349 aconn = (struct rx_connection *)0;
7351 /*end rw volume processing */
7352 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7353 index = Lp_GetRwIndex(entry);
7354 if (index == -1) { /* there is a serious discrepancy */
7356 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7357 entry->volumeId[BACKVOL]);
7358 fprintf(STDERR, "try building VLDB from scratch\n");
7359 error = VOLSERVLDB_ERROR;
7362 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7364 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7365 entry->serverPartition[index], ITOffline, &tid);
7366 if (code) { /*volume doesnot exist */
7368 "Could not start transaction on the backup volume %u\n",
7369 entry->volumeId[BACKVOL]);
7372 } else { /*volume exists, process it */
7373 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7375 "Volume name %s.backup exceeds the limit of %u characters\n",
7376 newname, VOLSER_OLDMAXVOLNAME);
7380 strcpy(nameBuffer, newname);
7381 strcat(nameBuffer, ".backup");
7384 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7385 entry->volumeId[RWVOL], 0, 0);
7387 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7388 code = AFSVolEndTrans(aconn, tid, &rcode);
7392 "Could not end transaction on the backup volume %u\n",
7393 entry->volumeId[BACKVOL]);
7399 "Could not set parameters on the backup volume %u\n",
7400 entry->volumeId[BACKVOL]);
7405 } /* end backup processing */
7407 rx_DestroyConnection(aconn);
7408 aconn = (struct rx_connection *)0;
7409 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7410 for (i = 0; i < entry->nServers; i++) {
7411 if (entry->serverFlags[i] & VLSF_ROVOL) {
7412 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7414 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7415 entry->serverPartition[i], ITOffline,
7417 if (code) { /*volume doesnot exist */
7419 "Could not start transaction on the ro volume %u\n",
7420 entry->volumeId[ROVOL]);
7423 } else { /*volume exists, process it */
7424 strcpy(nameBuffer, newname);
7425 strcat(nameBuffer, ".readonly");
7426 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7428 "Volume name %s exceeds the limit of %u characters\n",
7429 nameBuffer, VOLSER_OLDMAXVOLNAME);
7434 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7435 entry->volumeId[RWVOL], 0, 0);
7437 VPRINT2("Renamed RO volume %s on host %s\n",
7440 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7441 hostutil_GetNameByINet(entry->
7443 code = AFSVolEndTrans(aconn, tid, &rcode);
7447 "Could not end transaction on volume %u\n",
7448 entry->volumeId[ROVOL]);
7454 "Could not set parameters on the ro volume %u\n",
7455 entry->volumeId[ROVOL]);
7461 rx_DestroyConnection(aconn);
7462 aconn = (struct rx_connection *)0;
7469 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7471 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7474 "Could not unlock the VLDB entry for the volume %s %u\n",
7475 entry->name, entry->volumeId[RWVOL]);
7481 code = AFSVolEndTrans(aconn, tid, &rcode);
7485 fprintf(STDERR, "Failed to end transaction on a volume \n");
7491 rx_DestroyConnection(aconn);
7492 PrintError("", error);
7497 /*report on all the active transactions on volser */
7499 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7501 struct rx_connection *aconn;
7502 transDebugEntries transInfo;
7505 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7506 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7507 transInfo.transDebugEntries_len = 0;
7508 code = AFSVolMonitor(aconn, &transInfo);
7511 "Could not access status information about the server\n");
7512 PrintError("", code);
7513 if (transInfo.transDebugEntries_val)
7514 free(transInfo.transDebugEntries_val);
7516 rx_DestroyConnection(aconn);
7519 *rcount = transInfo.transDebugEntries_len;
7520 *rpntr = transInfo.transDebugEntries_val;
7522 rx_DestroyConnection(aconn);
7529 /*delete the volume without interacting with the vldb */
7531 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7534 struct rx_connection *aconn;
7536 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7537 error = DoVolDelete(aconn, volid, part,
7538 "the", 0, NULL, NULL);
7539 if (error == VNOVOL) {
7540 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7543 PrintError("", error);
7545 rx_DestroyConnection(aconn);
7550 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7551 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7553 struct rx_connection *conn = 0;
7555 afs_int32 code, error = 0, rcode;
7557 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7559 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7563 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7565 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7569 code = AFSVolSetFlags(conn, tid, setflag);
7571 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7576 #ifdef AFS_PTHREAD_ENV
7579 IOMGR_Sleep(sleeptime);
7586 code = AFSVolEndTrans(conn, tid, &rcode);
7587 if (code || rcode) {
7588 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7590 error = (code ? code : rcode);
7595 rx_DestroyConnection(conn);
7600 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7603 struct rx_connection *conn = 0;
7605 afs_int32 code, error = 0, rcode;
7607 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7609 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7613 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7615 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7619 code = AFSVolSetInfo(conn, tid, infop);
7621 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7628 code = AFSVolEndTrans(conn, tid, &rcode);
7629 if (code || rcode) {
7630 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7632 error = (code ? code : rcode);
7637 rx_DestroyConnection(conn);
7642 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7643 afs_int32 fromdate, struct volintSize *vol_size)
7645 struct rx_connection *aconn = (struct rx_connection *)0;
7646 afs_int32 tid = 0, rcode = 0;
7647 afs_int32 code, error = 0;
7650 /* get connections to the servers */
7651 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7653 VPRINT1("Starting transaction on volume %u...", afromvol);
7654 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7655 EGOTO1(error_exit, code,
7656 "Could not start transaction on the volume %u to be measured\n",
7660 VPRINT1("Getting size of volume on volume %u...", afromvol);
7661 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7662 EGOTO(error_exit, code, "Could not start the measurement process \n");
7667 VPRINT1("Ending transaction on volume %u...", afromvol);
7668 code = AFSVolEndTrans(aconn, tid, &rcode);
7669 if (code || rcode) {
7670 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7672 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7674 error = (code ? code : rcode);
7679 rx_DestroyConnection(aconn);
7681 PrintError("", error);
7685 /*maps the host addresses in <old > (present in network byte order) to
7686 that in< new> (present in host byte order )*/
7688 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7692 /*copy all the fields */
7693 strcpy(new->name, old->name);
7694 /* new->volumeType = old->volumeType;*/
7695 new->nServers = old->nServers;
7696 count = old->nServers;
7697 if (count < NMAXNSERVERS)
7699 for (i = 0; i < count; i++) {
7700 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7701 new->serverPartition[i] = old->serverPartition[i];
7702 new->serverFlags[i] = old->serverFlags[i];
7704 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7705 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7706 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7707 new->cloneId = old->cloneId;
7708 new->flags = old->flags;
7711 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7713 MapHostToNetwork(struct nvldbentry *entry)
7717 count = entry->nServers;
7718 if (count < NMAXNSERVERS)
7720 for (i = 0; i < count; i++) {
7721 entry->serverNumber[i] = htonl(entry->serverNumber[i]);