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 & RW_EXISTS)
553 fprintf(STDOUT, " valid \n");
555 fprintf(STDOUT, " invalid \n");
556 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
557 if (entry->flags & RO_EXISTS)
558 fprintf(STDOUT, " valid \n");
560 fprintf(STDOUT, " invalid \n");
561 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
562 if (entry->flags & BACK_EXISTS)
563 fprintf(STDOUT, " valid \n");
565 fprintf(STDOUT, " invalid \n");
566 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
567 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
569 if (entry->flags & RW_EXISTS)
570 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
571 if (entry->flags & RO_EXISTS)
572 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
573 if (entry->flags & BACK_EXISTS)
574 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
575 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
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] & NEW_REPSITE)
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] & ITSRWVOL)
591 fprintf(STDOUT, "RW Site ");
593 fprintf(STDOUT, "RO Site ");
595 if (entry->serverFlags[i] & NEW_REPSITE)
596 fprintf(STDOUT," -- New release");
598 if (!(entry->serverFlags[i] & ITSRWVOL))
599 fprintf(STDOUT," -- Old release");
601 if (entry->serverFlags[i] & RO_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 = RW_EXISTS; /* this records that rw volume exists */
799 entry.serverFlags[0] = ITSRWVOL; /*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 = RW_EXISTS; /* this records that rw volume exists */
867 entry.serverFlags[0] = ITSRWVOL; /*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 & BACK_EXISTS) || !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 &= ~BACK_EXISTS;
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 &= ~RO_EXISTS; /* 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 & RW_EXISTS) || !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 & BACK_EXISTS) ? ", and its backup volume," :
1020 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1022 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
1025 if (entry.flags & RO_EXISTS)
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 & (RO_EXISTS | RW_EXISTS))) {
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] & ITSRWVOL) {
1397 rwserver = entry->serverNumber[i];
1398 /* rwpartition = entry->serverPartition[i]; */
1401 } else if ((entry->serverFlags[i] & ITSROVOL) && !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] = ITSRWVOL;
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] = ITSRWVOL;
1446 entry->flags |= RW_EXISTS;
1447 entry->flags &= ~BACK_EXISTS;
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 &= ~RO_EXISTS;
1465 for (i = 0; i < entry->nServers; i++) {
1466 if (entry->serverFlags[i] & ITSROVOL) {
1467 if (!(entry->serverFlags[i] & (RO_DONTUSE | NEW_REPSITE)))
1468 entry->flags |= RO_EXISTS;
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 fscanf(stdin, "%c", &in);
1566 fscanf(stdin, "%c", &lf); /* toss away */
1568 fprintf(STDOUT, "type control-c\n");
1570 fprintf(stdout, ".");
1575 /* or drop through */
1578 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1579 EGOTO1(mfail, vcode,
1580 "Could not fetch the entry for the volume %u from the VLDB \n",
1583 if (entry.volumeId[RWVOL] != afromvol) {
1584 fprintf(STDERR, "Only RW volume can be moved\n");
1588 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1589 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1592 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1593 EGOTO1(mfail, vcode,
1594 "Could not fetch the entry for the volume %u from the VLDB \n",
1597 backupId = entry.volumeId[BACKVOL];
1598 MapHostToNetwork(&entry);
1600 if (!Lp_Match(afromserver, afrompart, &entry)) {
1601 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1602 if (!Lp_Match(atoserver, atopart, &entry)) {
1603 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1604 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1605 (unsigned long)afromvol);
1606 fprintf(STDERR, "The current site is :");
1607 for (i = 0; i < entry.nServers; i++) {
1608 if (entry.serverFlags[i] == ITSRWVOL) {
1610 MapPartIdIntoName(entry.serverPartition[i], pname);
1611 fprintf(STDERR, " server %s partition %s \n",
1612 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1613 hostutil_GetNameByINet(entry.serverNumber[i]),
1618 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1619 (LOCKREL_OPCODE | LOCKREL_AFSID |
1620 LOCKREL_TIMESTAMP));
1621 EGOTO1(mfail, vcode,
1622 " Could not release lock on the VLDB entry for the volume %u \n",
1625 return VOLSERVOLMOVED;
1628 /* delete the volume afromvol on src_server */
1629 /* from-info does not exist but to-info does =>
1630 * we have already done the move, but the volume
1631 * may still be existing physically on from fileserver
1633 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1636 code = DoVolDelete(fromconn, afromvol, afrompart,
1637 "leftover", 0, NULL, NULL);
1638 if (code && code != VNOVOL) {
1643 code = DoVolDelete(fromconn, backupId, afrompart,
1644 "leftover backup", 0, NULL, NULL);
1645 if (code && code != VNOVOL) {
1655 /* From-info matches the vldb info about volid,
1656 * its ok start the move operation, the backup volume
1657 * on the old site is deleted in the process
1659 if (afrompart == atopart) {
1660 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1661 EGOTO2(mfail, error,
1662 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1663 afromserver, error);
1666 EGOTO1(mfail, VOLSERVOLMOVED,
1667 "Warning: Moving volume %u to its home partition ignored!\n",
1673 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1674 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1675 totid = 0; /* initialize to uncreated */
1678 * clone the read/write volume locally.
1681 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1682 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1684 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1688 if (!(flags & RV_NOCLONE)) {
1689 /* Get a clone id */
1690 VPRINT1("Allocating new volume id for clone of volume %u ...",
1693 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1695 EGOTO1(mfail, vcode,
1696 "Could not get an ID for the clone of volume %u from the VLDB\n",
1700 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1701 VPRINT1("Cloning source volume %u ...", afromvol);
1702 strcpy(vname, "move-clone-temp");
1704 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1706 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1711 /* lookup the name of the volume we just cloned */
1713 code = AFSVolGetName(fromconn, fromtid, &volName);
1714 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1717 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1719 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1724 "Failed to end the transaction on the source volume %u\n",
1729 * Create the destination volume
1732 if (!(flags & RV_NOCLONE)) {
1733 /* All of this is to get the fromDate */
1734 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1737 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1741 "Failed to start a transaction on the cloned volume%u\n",
1745 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1747 AFSVolSetFlags(fromconn, clonetid,
1748 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1749 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1753 /* remember time from which we've dumped the volume */
1754 VPRINT1("Getting status of cloned volume %u ...", newVol);
1755 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1757 "Failed to get the status of the cloned volume %u\n",
1761 fromDate = CLOCKADJ(tstatus.creationDate);
1763 /* With RV_NOCLONE, just do a full copy from the source */
1768 #ifdef ENABLE_BUGFIX_1165
1770 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1771 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1772 * don't use this information...
1774 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1775 volumeInfo.volEntries_len = 0;
1776 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1778 "Failed to get the volint Info of the cloned volume %u\n",
1781 infop = (volintInfo *) volumeInfo.volEntries_val;
1782 infop->maxquota = -1; /* Else it will replace the default quota */
1783 infop->creationDate = -1; /* Else it will use the source creation date */
1784 infop->updateDate = -1; /* Else it will use the source update date */
1787 /* create a volume on the target machine */
1789 code = DoVolDelete(toconn, volid, atopart,
1790 "pre-existing destination", 0, NULL, NULL);
1791 if (code && code != VNOVOL) {
1796 VPRINT1("Creating the destination volume %u ...", volid);
1800 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1804 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1808 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1812 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1814 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1816 "Failed to set the flags on the destination volume %u\n", volid);
1820 * Now dump the clone to the new volume
1823 destination.destHost = ntohl(atoserver);
1824 destination.destPort = AFSCONF_VOLUMEPORT;
1825 destination.destSSID = 1;
1827 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1828 cookie.type = RWVOL;
1829 cookie.parent = entry.volumeId[RWVOL];
1832 if (!(flags & RV_NOCLONE)) {
1833 /* Copy the clone to the new volume */
1834 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1837 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1839 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1842 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1843 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1848 "Failed to end the transaction on the cloned volume %u\n",
1854 * reattach to the main-line volume, and incrementally dump it.
1857 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1859 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1862 "Failed to create a transaction on the source volume %u\n",
1866 /* now do the incremental */
1868 ("Doing the%s dump from source to destination for volume %u ... ",
1869 (flags & RV_NOCLONE) ? "" : " incremental",
1872 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1875 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1876 (flags & RV_NOCLONE) ? "" : " incremental");
1879 /* now adjust the flags so that the new volume becomes official */
1880 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1881 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1883 "Failed to set the flags to make old source volume offline\n");
1886 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1887 code = AFSVolSetFlags(toconn, totid, 0);
1889 "Failed to set the flags to make new source volume online\n");
1892 #ifdef ENABLE_BUGFIX_1165
1893 VPRINT1("Setting volume status on destination volume %u ...", volid);
1894 code = AFSVolSetInfo(toconn, totid, infop);
1896 "Failed to set volume status on the destination volume %u\n",
1901 /* put new volume online */
1902 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1903 code = AFSVolEndTrans(toconn, totid, &rcode);
1908 "Failed to end the transaction on the volume %u on the new site\n",
1912 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1913 MapNetworkToHost(&entry, &storeEntry);
1914 storeEntry.flags &= ~BACK_EXISTS;
1918 "Second test point - operation in progress but not complete.\n");
1919 fprintf(STDOUT, "...test here (y, n)? ");
1921 fscanf(stdin, "%c", &in);
1922 fscanf(stdin, "%c", &lf); /* toss away */
1924 fprintf(STDOUT, "type control-c\n");
1926 fprintf(stdout, ".");
1931 /* or drop through */
1934 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1936 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1937 (LOCKREL_OPCODE | LOCKREL_AFSID |
1938 LOCKREL_TIMESTAMP));
1941 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1942 storeEntry.name, (unsigned long)afromvol);
1951 "Third test point - operation complete but no cleanup.\n");
1952 fprintf(STDOUT, "...test here (y, n)? ");
1954 fscanf(stdin, "%c", &in);
1955 fscanf(stdin, "%c", &lf); /* toss away */
1957 fprintf(STDOUT, "type control-c\n");
1959 fprintf(stdout, ".");
1964 /* or drop through */
1967 /* This is tricky. File server is very stupid, and if you mark the volume
1968 * as VTOutOfService, it may mark the *good* instance (if you're moving
1969 * between partitions on the same machine) as out of service. Since
1970 * we're cleaning this code up in DEcorum, we're just going to kludge around
1971 * it for now by removing this call. */
1972 /* already out of service, just zap it now */
1974 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1977 "Failed to set the flags to make the old source volume offline\n");
1981 if (atoserver != afromserver) {
1982 /* set forwarding pointer for moved volumes */
1983 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1984 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1986 "Failed to set the forwarding pointer for the volume %u\n",
1991 VPRINT1("Deleting old volume %u on source ...", afromvol);
1992 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1993 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1997 VPRINT1("Ending transaction on old volume %u on the source ...",
1999 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2004 "Failed to end the transaction on the old volume %u on the source\n",
2008 code = DoVolDelete(fromconn, backupId, afrompart,
2009 "source backup", 0, NULL, NULL);
2010 if (code && code != VNOVOL) {
2015 code = 0; /* no backup volume? that's okay */
2018 if (!(flags & RV_NOCLONE)) {
2019 code = DoVolDelete(fromconn, newVol, afrompart,
2020 "cloned", 0, NULL, NULL);
2022 if (code == VNOVOL) {
2023 EPRINT1(code, "Failed to start transaction on %u\n", newVol);
2034 fprintf(STDOUT, "Fourth test point - operation complete.\n");
2035 fprintf(STDOUT, "...test here (y, n)? ");
2037 fscanf(stdin, "%c", &in);
2038 fscanf(stdin, "%c", &lf); /* toss away */
2040 fprintf(STDOUT, "type control-c\n");
2042 fprintf(stdout, ".");
2047 /* or drop through */
2050 /* normal cleanup code */
2052 if (entry.flags & RO_EXISTS)
2053 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
2056 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
2058 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2059 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2063 " Could not release the lock on the VLDB entry for the volume %lu \n",
2064 (unsigned long)afromvol);
2072 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2074 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2075 if (code || rcode) {
2078 "Could not end transaction on the source volume %lu\n",
2079 (unsigned long)afromvol);
2081 error = (code ? code : rcode);
2087 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2088 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2089 if (code || rcode) {
2092 "Could not end transaction on the source's clone volume %lu\n",
2093 (unsigned long)newVol);
2095 error = (code ? code : rcode);
2101 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2103 code = AFSVolEndTrans(toconn, totid, &rcode);
2107 "Could not end transaction on destination volume %lu\n",
2108 (unsigned long)afromvol);
2110 error = (code ? code : rcode);
2116 #ifdef ENABLE_BUGFIX_1165
2121 rx_DestroyConnection(fromconn);
2123 rx_DestroyConnection(toconn);
2124 PrintError("", error);
2127 /* come here only when the sky falls */
2132 "vos move: operation interrupted, cleanup in progress...\n");
2133 fprintf(STDOUT, "clear transaction contexts\n");
2137 /* unlock VLDB entry */
2139 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2140 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2141 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2147 VPRINT("Recovery: Ending transaction on clone volume ...");
2148 AFSVolEndTrans(fromconn, clonetid, &rcode);
2152 VPRINT("Recovery: Ending transaction on destination volume ...");
2153 AFSVolEndTrans(toconn, totid, &rcode);
2156 if (fromtid) { /* put it on-line */
2157 VPRINT("Recovery: Setting volume flags on source volume ...");
2158 AFSVolSetFlags(fromconn, fromtid, 0);
2161 VPRINT("Recovery: Ending transaction on source volume ...");
2162 AFSVolEndTrans(fromconn, fromtid, &rcode);
2166 VPRINT("Recovery: Accessing VLDB.\n");
2167 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2169 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2173 MapHostToNetwork(&entry);
2175 /* Delete either the volume on the source location or the target location.
2176 * If the vldb entry still points to the source location, then we know the
2177 * volume move didn't finish so we remove the volume from the target
2178 * location. Otherwise, we remove the volume from the source location.
2180 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2183 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2187 if (volid && toconn) {
2188 code = DoVolDelete(toconn, volid, atopart,
2189 "destination", 0, NULL, "Recovery:");
2190 if (code == VNOVOL) {
2191 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2195 /* put source volume on-line */
2197 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2201 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2207 VPRINT1("Recovery: Setting flags on source volume %u ...",
2209 AFSVolSetFlags(fromconn, fromtid, 0);
2213 ("Recovery: Ending transaction on source volume %u ...",
2215 AFSVolEndTrans(fromconn, fromtid, &rcode);
2219 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2223 } else { /* yep, move complete */
2226 "move complete - attempt cleanup of source partition - no guarantee\n");
2230 /* delete backup volume */
2232 code = DoVolDelete(fromconn, backupId, afrompart,
2233 "backup", 0, NULL, "Recovery:");
2234 if (code == VNOVOL) {
2235 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2238 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2239 (atoserver != afromserver)?atoserver:0,
2241 if (code == VNOVOL) {
2242 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2247 /* common cleanup - delete local clone */
2249 code = DoVolDelete(fromconn, newVol, afrompart,
2250 "clone", 0, NULL, "Recovery:");
2251 if (code == VNOVOL) {
2252 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2256 /* unlock VLDB entry */
2258 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2260 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2261 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2264 done: /* routine cleanup */
2267 #ifdef ENABLE_BUGFIX_1165
2272 rx_DestroyConnection(fromconn);
2274 rx_DestroyConnection(toconn);
2277 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2285 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2286 afs_uint32 atoserver, afs_int32 atopart)
2288 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2289 atoserver, atopart, 0);
2293 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2294 * <atopart>. The new volume is named by <atovolname>. The new volume
2295 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2296 * from the VLDB. the following flags are supported:
2298 * RV_RDONLY - target volume is RO
2299 * RV_OFFLINE - leave target volume offline
2300 * RV_CPINCR - do incremental dump if target exists
2301 * RV_NOVLDB - don't create/update VLDB entry
2302 * RV_NOCLONE - don't use a copy clone
2305 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2306 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2307 afs_uint32 atovolid, int flags)
2309 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2310 * be changing during the copy */
2312 afs_int32 volatile clonetid;
2313 afs_int32 volatile totid;
2314 afs_int32 volatile fromtid;
2315 struct rx_connection * volatile fromconn;
2316 struct rx_connection * volatile toconn;
2317 afs_uint32 volatile cloneVol;
2321 afs_int32 fromDate, cloneFromDate;
2322 struct restoreCookie cookie;
2323 afs_int32 vcode, code;
2326 struct volser_status tstatus;
2327 struct destServer destination;
2328 struct nvldbentry entry, newentry, storeEntry;
2333 fromconn = (struct rx_connection *)0;
2334 toconn = (struct rx_connection *)0;
2342 /* support control-c processing */
2345 (void)signal(SIGINT, sigint_handler);
2347 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2348 EGOTO1(mfail, vcode,
2349 "Could not fetch the entry for the volume %u from the VLDB \n",
2351 MapHostToNetwork(&entry);
2354 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2355 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2356 fromtid = totid = 0; /* initialize to uncreated */
2359 * clone the read/write volume locally.
2363 if (!(flags & RV_NOCLONE)) {
2364 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2366 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2369 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2373 /* Get a clone id */
2374 VPRINT1("Allocating new volume id for clone of volume %u ...",
2378 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2380 EGOTO1(mfail, vcode,
2381 "Could not get an ID for the clone of volume %u from the VLDB\n",
2389 /* Get a new volume id */
2390 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2392 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2393 EGOTO1(mfail, vcode,
2394 "Could not get an ID for the copy of volume %u from the VLDB\n",
2399 if (!(flags & RV_NOCLONE)) {
2400 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2401 VPRINT1("Cloning source volume %u ...", afromvol);
2402 strcpy(vname, "copy-clone-temp");
2405 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2408 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2412 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2414 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2419 "Failed to end the transaction on the source volume %u\n",
2425 * Create the destination volume
2428 if (!(flags & RV_NOCLONE)) {
2429 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2432 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2436 "Failed to start a transaction on the cloned volume%u\n",
2440 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2442 AFSVolSetFlags(fromconn, clonetid,
2443 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2444 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2448 /* remember time from which we've dumped the volume */
2449 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2450 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2452 "Failed to get the status of the cloned volume %u\n",
2456 fromDate = CLOCKADJ(tstatus.creationDate);
2461 /* create a volume on the target machine */
2464 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2467 if ((flags & RV_CPINCR)) {
2468 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2469 code = AFSVolGetStatus(toconn, totid, &tstatus);
2471 "Failed to get the status of the pre-existing volume %u\n",
2475 /* Using the update date should be OK here, but add some fudge */
2476 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2477 if ((flags & RV_NOCLONE))
2478 fromDate = cloneFromDate;
2480 /* XXX We should check that the source volume's creationDate is
2481 * XXX not newer than the existing target volume, and if not,
2482 * XXX throw away the existing target and do a full dump. */
2487 /* Delete the existing volume.
2488 * While we are deleting the volume in these steps, the transaction
2489 * we started against the cloned volume (clonetid above) will be
2490 * sitting idle. It will get cleaned up after 600 seconds
2492 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2493 code = AFSVolDeleteVolume(toconn, totid);
2495 "Could not delete the pre-existing volume %u on destination\n",
2500 ("Ending transaction on pre-existing volume %u on destination ...",
2502 code = AFSVolEndTrans(toconn, totid, &rcode);
2507 "Could not end the transaction on pre-existing volume %u on destination\n",
2512 VPRINT1("Creating the destination volume %u ...", newVol);
2515 AFSVolCreateVolume(toconn, atopart, atovolname,
2516 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2517 newVol, &newVol, &tmp);
2519 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2523 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2525 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2527 "Failed to set the flags on the destination volume %u\n", newVol);
2532 destination.destHost = ntohl(atoserver);
2533 destination.destPort = AFSCONF_VOLUMEPORT;
2534 destination.destSSID = 1;
2536 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2537 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2542 * Now dump the clone to the new volume
2545 if (!(flags & RV_NOCLONE)) {
2546 /* XXX probably should have some code here that checks to see if
2547 * XXX we are copying to same server and partition - if so, just
2548 * XXX use a clone to save disk space */
2550 /* Copy the clone to the new volume */
2551 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2554 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2556 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2560 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2561 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2566 "Failed to end the transaction on the cloned volume %u\n",
2572 * reattach to the main-line volume, and incrementally dump it.
2575 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2577 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2580 "Failed to create a transaction on the source volume %u\n",
2584 /* now do the incremental */
2586 ("Doing the%s dump from source to destination for volume %u ... ",
2587 (flags & RV_NOCLONE) ? "" : " incremental",
2590 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2593 "Failed to do the%s dump from old site to new site\n",
2594 (flags & RV_NOCLONE) ? "" : " incremental");
2597 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2598 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2599 code = AFSVolSetFlags(toconn, totid, volflag);
2601 "Failed to set the flags to make destination volume online\n");
2604 /* put new volume online */
2605 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2606 code = AFSVolEndTrans(toconn, totid, &rcode);
2611 "Failed to end the transaction on the destination volume %u\n",
2615 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2616 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2621 "Failed to end the transaction on the source volume %u\n",
2627 if (!(flags & RV_NOCLONE)) {
2628 code = DoVolDelete(fromconn, cloneVol, afrompart,
2629 "cloned", 0, NULL, NULL);
2631 if (code == VNOVOL) {
2632 EPRINT1(code, "Failed to start transaction on %u\n", cloneVol);
2639 if (!(flags & RV_NOVLDB)) {
2640 /* create the vldb entry for the copied volume */
2641 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2642 newentry.nServers = 1;
2643 newentry.serverNumber[0] = atoserver;
2644 newentry.serverPartition[0] = atopart;
2645 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2646 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2647 newentry.volumeId[RWVOL] = newVol;
2648 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2649 newentry.volumeId[BACKVOL] = 0;
2650 newentry.cloneId = 0;
2651 /*map into right byte order, before passing to xdr, the stuff has to be in host
2652 * byte order. Xdr converts it into network order */
2653 MapNetworkToHost(&newentry, &storeEntry);
2654 /* create the vldb entry */
2655 vcode = VLDB_CreateEntry(&storeEntry);
2658 "Could not create a VLDB entry for the volume %s %lu\n",
2659 atovolname, (unsigned long)newVol);
2660 /*destroy the created volume */
2661 VPRINT1("Deleting the newly created volume %u\n", newVol);
2662 AFSVolDeleteVolume(toconn, totid);
2666 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2670 /* normal cleanup code */
2673 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2675 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2676 if (code || rcode) {
2679 "Could not end transaction on the source volume %lu\n",
2680 (unsigned long)afromvol);
2682 error = (code ? code : rcode);
2688 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2690 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2691 if (code || rcode) {
2694 "Could not end transaction on the source's clone volume %lu\n",
2695 (unsigned long)cloneVol);
2697 error = (code ? code : rcode);
2703 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2705 code = AFSVolEndTrans(toconn, totid, &rcode);
2709 "Could not end transaction on destination volume %lu\n",
2710 (unsigned long)newVol);
2712 error = (code ? code : rcode);
2717 rx_DestroyConnection(fromconn);
2719 rx_DestroyConnection(toconn);
2720 PrintError("", error);
2723 /* come here only when the sky falls */
2728 "vos copy: operation interrupted, cleanup in progress...\n");
2729 fprintf(STDOUT, "clear transaction contexts\n");
2734 VPRINT("Recovery: Ending transaction on clone volume ...");
2735 AFSVolEndTrans(fromconn, clonetid, &rcode);
2739 VPRINT("Recovery: Ending transaction on destination volume ...");
2740 AFSVolEndTrans(toconn, totid, &rcode);
2743 if (fromtid) { /* put it on-line */
2744 VPRINT("Recovery: Ending transaction on source volume ...");
2745 AFSVolEndTrans(fromconn, fromtid, &rcode);
2749 VPRINT("Recovery: Accessing VLDB.\n");
2750 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2752 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2756 MapHostToNetwork(&entry);
2758 /* common cleanup - delete local clone */
2760 code = DoVolDelete(fromconn, cloneVol, afrompart,
2761 "clone", 0, NULL, "Recovery:");
2762 if (code == VNOVOL) {
2763 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", cloneVol);
2767 done: /* routine cleanup */
2769 rx_DestroyConnection(fromconn);
2771 rx_DestroyConnection(toconn);
2774 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2782 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2783 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2785 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2786 atovolname, atoserver, atopart, 0, 0);
2791 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2792 * if one already exists, update it
2796 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2798 struct rx_connection *aconn = (struct rx_connection *)0;
2799 afs_int32 ttid = 0, btid = 0;
2800 afs_uint32 backupID;
2801 afs_int32 code = 0, rcode = 0;
2802 struct nvldbentry entry, storeEntry;
2803 afs_int32 error = 0;
2804 int vldblocked = 0, vldbmod = 0;
2806 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2808 /* the calls to VLDB will succeed only if avolid is a RW volume,
2809 * since we are following the RW hash chain for searching */
2810 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2813 "Could not fetch the entry for the volume %lu from the VLDB \n",
2814 (unsigned long)avolid);
2818 MapHostToNetwork(&entry);
2820 /* These operations require the VLDB be locked since it means the VLDB
2821 * will change or the vldb is already locked.
2823 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2824 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2825 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2827 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2830 "Could not lock the VLDB entry for the volume %lu\n",
2831 (unsigned long)avolid);
2837 /* Reread the vldb entry */
2838 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2841 "Could not fetch the entry for the volume %lu from the VLDB \n",
2842 (unsigned long)avolid);
2846 MapHostToNetwork(&entry);
2849 if (!ISNAMEVALID(entry.name)) {
2850 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2852 error = VOLSERBADNAME;
2856 backupID = entry.volumeId[BACKVOL];
2857 if (backupID == INVALID_BID) {
2858 /* Get a backup volume id from the VLDB and update the vldb
2861 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2864 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2865 (unsigned long)avolid);
2869 entry.volumeId[BACKVOL] = backupID;
2873 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2874 entry.name, NULL, ".backup", NULL, NULL);
2880 /* Mark vldb as backup exists */
2881 if (!(entry.flags & BACK_EXISTS)) {
2882 entry.flags |= BACK_EXISTS;
2886 /* Now go back to the backup volume and bring it on line */
2887 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2890 "Failed to start a transaction on the backup volume %lu\n",
2891 (unsigned long)backupID);
2896 code = AFSVolSetFlags(aconn, btid, 0);
2898 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2899 (unsigned long)backupID);
2904 code = AFSVolEndTrans(aconn, btid, &rcode);
2906 if (code || rcode) {
2908 "Failed to end the transaction on the backup volume %lu\n",
2909 (unsigned long)backupID);
2910 error = (code ? code : rcode);
2916 /* Will update the vldb below */
2920 code = AFSVolEndTrans(aconn, ttid, &rcode);
2921 if (code || rcode) {
2922 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2923 (unsigned long)avolid);
2925 error = (code ? code : rcode);
2930 code = AFSVolEndTrans(aconn, btid, &rcode);
2931 if (code || rcode) {
2933 "Could not end transaction the backup volume %lu\n",
2934 (unsigned long)backupID);
2936 error = (code ? code : rcode);
2940 /* Now update the vldb - if modified */
2943 MapNetworkToHost(&entry, &storeEntry);
2945 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2946 (LOCKREL_OPCODE | LOCKREL_AFSID |
2947 LOCKREL_TIMESTAMP));
2950 "Could not update the VLDB entry for the volume %lu \n",
2951 (unsigned long)avolid);
2957 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2958 (LOCKREL_OPCODE | LOCKREL_AFSID |
2959 LOCKREL_TIMESTAMP));
2962 "Could not unlock the VLDB entry for the volume %lu \n",
2963 (unsigned long)avolid);
2971 rx_DestroyConnection(aconn);
2973 PrintError("", error);
2977 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2978 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2979 * The new volume is named by <aname>, or by appending ".clone" to
2980 * the existing name if <aname> is NULL. The following flags are
2983 * RV_RDONLY - target volume is RO
2984 * RV_OFFLINE - leave target volume offline
2988 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2989 afs_uint32 acloneid, char *aname, int flags)
2991 struct rx_connection *aconn = (struct rx_connection *)0;
2992 afs_int32 ttid = 0, btid = 0;
2993 afs_int32 code = 0, rcode = 0;
2994 char vname[VOLSER_MAXVOLNAME + 1];
2995 afs_int32 error = 0;
2996 volEntries volumeInfo;
2999 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
3002 volumeInfo.volEntries_val = (volintInfo *) 0;
3003 volumeInfo.volEntries_len = 0;
3004 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
3006 fprintf(stderr, "Could not get info for volume %lu\n",
3007 (unsigned long)avolid);
3011 strncpy(vname, volumeInfo.volEntries_val[0].name,
3012 VOLSER_OLDMAXVOLNAME - 7);
3013 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
3014 strcat(vname, ".clone");
3016 if (volumeInfo.volEntries_val)
3017 free(volumeInfo.volEntries_val);
3021 /* Get a clone id */
3022 VPRINT1("Allocating new volume id for clone of volume %u ...",
3024 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
3026 "Could not get an ID for the clone of volume %u from the VLDB\n",
3031 if (flags & RV_RWONLY)
3032 type = readwriteVolume;
3033 else if (flags & RV_RDONLY)
3034 type = readonlyVolume;
3036 type = backupVolume;
3038 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
3039 NULL, aname, NULL, NULL, NULL);
3045 /* Now go back to the backup volume and bring it on line */
3046 if (!(flags & RV_OFFLINE)) {
3047 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3050 "Failed to start a transaction on the clone volume %lu\n",
3051 (unsigned long)acloneid);
3056 code = AFSVolSetFlags(aconn, btid, 0);
3058 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3059 (unsigned long)acloneid);
3064 code = AFSVolEndTrans(aconn, btid, &rcode);
3066 if (code || rcode) {
3068 "Failed to end the transaction on the clone volume %lu\n",
3069 (unsigned long)acloneid);
3070 error = (code ? code : rcode);
3079 code = AFSVolEndTrans(aconn, ttid, &rcode);
3080 if (code || rcode) {
3081 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3082 (unsigned long)avolid);
3084 error = (code ? code : rcode);
3089 code = AFSVolEndTrans(aconn, btid, &rcode);
3090 if (code || rcode) {
3092 "Could not end transaction on the clone volume %lu\n",
3093 (unsigned long)acloneid);
3095 error = (code ? code : rcode);
3100 rx_DestroyConnection(aconn);
3102 PrintError("", error);
3106 #define ONERROR(ec, ep, es) do { \
3108 fprintf(STDERR, (es), (ep)); \
3113 #define ONERROR0(ec, es) do { \
3115 fprintf(STDERR, (es)); \
3120 #define ERROREXIT(ec) do { \
3125 /* Get a "transaction" on this replica. Create the volume
3126 * if necessary. Return the time from which a dump should
3127 * be made (0 if it's a new volume)
3130 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3131 struct rx_connection **connPtr, afs_int32 * transPtr,
3132 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3133 afs_int32 *origflags, afs_uint32 tmpVolId)
3136 struct volser_status tstatus;
3141 *connPtr = (struct rx_connection *)0;
3146 /* get connection to the replication site */
3147 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3149 goto fail; /* server is down */
3151 volid = vldbEntryPtr->volumeId[ROVOL];
3155 AFSVolTransCreate_retry(*connPtr, volid,
3156 vldbEntryPtr->serverPartition[index], ITOffline,
3159 if (!code && (origflags[index] & RO_DONTUSE)) {
3160 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3161 * site. Don't trust any data on it, since it is possible we
3162 * have encountered some temporary volume from some other
3163 * incomplete volume operation. It is difficult to detect if
3164 * that has happened vs if this is a legit volume, so just
3165 * delete it to be safe. */
3167 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3168 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3169 serverNumber[index], hoststr) :
3170 hostutil_GetNameByINet(vldbEntryPtr->
3171 serverNumber[index]));
3173 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3175 PrintError("Failed to delete RO_DONTUSE site: ", code);
3179 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3185 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3192 /* emulate what TransCreate would have returned, so we try to
3193 * create the volume below */
3198 /* If the volume does not exist, create it */
3199 if (!volid || code) {
3200 char volname[VL_MAXNAMELEN];
3203 if (volid && (code != VNOVOL)) {
3204 PrintError("Failed to start a transaction on the RO volume.\n",
3209 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3211 if (strlcat(volname,
3212 tmpVolId?".roclone":".readonly",
3213 sizeof(volname)) >= sizeof(volname)) {
3215 PrintError("Volume name is too long\n", code);
3221 "Creating new volume %lu on replication site %s: ",
3222 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3223 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3224 serverNumber[index], hoststr) :
3225 hostutil_GetNameByINet(vldbEntryPtr->
3226 serverNumber[index]));
3231 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3233 vldbEntryPtr->volumeId[RWVOL],
3234 tmpVolId?&tmpVolId:&volid,
3237 PrintError("Failed to create the ro volume: ", code);
3240 vldbEntryPtr->volumeId[ROVOL] = volid;
3244 /* The following is a bit redundant, since create sets these flags by default */
3246 AFSVolSetFlags(*connPtr, *transPtr,
3247 VTDeleteOnSalvage | VTOutOfService);
3249 PrintError("Failed to set flags on the ro volume: ", code);
3254 /* Otherwise, the transaction did succeed, so get the creation date of the
3255 * latest RO volume on the replication site
3258 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3259 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3260 serverNumber[index], hoststr) :
3261 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3263 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3265 PrintError("Failed to get status of volume on destination: ",
3270 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3275 code = DoVolClone(*connPtr, volid,
3276 vldbEntryPtr->serverPartition[index],
3277 readonlyVolume, tmpVolId, "temporary",
3278 vldbEntryPtr->name, NULL, ".roclone", NULL,
3283 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3284 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3291 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3295 if (tcode && tcode != ENOENT)
3296 PrintError("Could not end transaction on a ro volume: ", tcode);
3303 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3304 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3305 void *cookie, manyResults * results)
3309 for (i = 0; i < tr->manyDests_len; i++) {
3310 results->manyResults_val[i] =
3311 AFSVolForward(fromconn, fromtid, fromdate,
3312 &(tr->manyDests_val[i].server),
3313 tr->manyDests_val[i].trans, cookie);
3319 * Check if a trans has timed out, and recreate it if necessary.
3321 * @param[in] aconn RX connection to the relevant server
3322 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3323 * contains the new trans ID on success
3324 * @param[in] apart Partition for the transaction
3325 * @param[in] astat The status of the original transaction
3327 * @return operation status
3328 * @retval 0 existing transaction is still valid, or we managed to recreate
3329 * the trans successfully
3330 * @retval nonzero Fatal error; bail out
3333 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3334 struct volser_status *astat)
3336 struct volser_status new_status;
3339 memset(&new_status, 0, sizeof(new_status));
3340 code = AFSVolGetStatus(aconn, *atid, &new_status);
3342 if (code == ENOENT) {
3344 VPRINT1("Old transaction on cloned volume %lu timed out, "
3345 "restarting transaction\n", (long unsigned) astat->volID);
3346 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3349 PrintError("Failed to recreate cloned RO volume transaction\n",
3354 memset(&new_status, 0, sizeof(new_status));
3355 code = AFSVolGetStatus(aconn, *atid, &new_status);
3357 PrintError("Failed to get status on recreated transaction\n",
3362 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3363 PrintError("Recreated transaction on cloned RO volume, but "
3364 "the volume has changed!\n", 0);
3368 PrintError("Unable to get status of current cloned RO transaction\n",
3373 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3375 PrintError("Internal error: current GetStatus does not match "
3376 "original GetStatus?\n", 0);
3385 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3386 struct rx_connection **toconns, struct release *times,
3389 afs_int32 s, code = 0, rcode = 0;
3390 /* End the transactions and destroy the connections */
3391 for (s = 0; s < volcount; s++) {
3392 if (replicas[s].trans) {
3393 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3395 replicas[s].trans = 0;
3399 if ((s == 0) || (code != ENOENT)) {
3400 PrintError("Could not end transaction on a ro volume: ",
3404 ("Transaction timed out on a ro volume. Will retry.\n",
3406 if (times[s].vldbEntryIndex < *vldbindex)
3407 *vldbindex = times[s].vldbEntryIndex;
3412 rx_DestroyConnection(toconns[s]);
3418 DoVolOnline(struct nvldbentry *vldbEntryPtr, afs_uint32 avolid, int index,
3419 char *vname, struct rx_connection *connPtr)
3421 afs_int32 code = 0, rcode = 0, onlinetid = 0;
3424 AFSVolTransCreate_retry(connPtr, avolid,
3425 vldbEntryPtr->serverPartition[index],
3429 EPRINT(code, "Could not create transaction on readonly...\n");
3432 code = AFSVolSetFlags(connPtr, onlinetid, 0);
3434 EPRINT(code, "Could not set flags on readonly...\n");
3439 AFSVolSetIdsTypes(connPtr, onlinetid, vname,
3440 ROVOL, vldbEntryPtr->volumeId[RWVOL],
3443 EPRINT(code, "Could not set ids on readonly...\n");
3446 code = AFSVolEndTrans(connPtr, onlinetid, &rcode);
3453 * Release a volume to read-only sites
3455 * Release volume <afromvol> on <afromserver> <afrompart> to all
3456 * its RO sites (full release). Unless the previous release was
3457 * incomplete: in which case we bring the remaining incomplete
3458 * volumes up to date with the volumes that were released
3461 * Will create a clone from the RW, then dump the clone out to
3462 * the remaining replicas. If there is more than 1 RO sites,
3463 * ensure that the VLDB says at least one RO is available all
3464 * the time: Influences when we write back the VLDB entry.
3466 * @param[in] afromvol volume to be released
3467 * @param[in] afromserver server containing afromvol
3468 * @param[in] afrompart partition containing afromvol
3469 * @param[in] flags bitmap of options
3470 * REL_COMPLETE - force a complete release
3471 * REL_FULLDUMPS - force full dumps
3472 * REL_STAYUP - dump to clones to avoid offline time
3475 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3476 afs_int32 afrompart, int flags)
3480 afs_int32 vcode, rcode, tcode;
3481 afs_uint32 cloneVolId = 0, roVolId;
3482 struct replica *replicas = 0;
3483 struct nvldbentry entry, storeEntry;
3484 int i, volcount = 0, m, vldbindex;
3486 struct restoreCookie cookie;
3487 struct rx_connection **toconns = 0;
3488 struct release *times = 0;
3490 struct rx_connection *fromconn = (struct rx_connection *)0;
3491 afs_int32 error = 0;
3493 afs_int32 clonetid = 0, onlinetid;
3494 afs_int32 fromtid = 0;
3495 afs_uint32 fromdate = 0;
3496 afs_uint32 thisdate;
3500 manyResults results;
3501 int rwindex, roindex, roclone, roexists;
3502 afs_uint32 rwcrdate = 0, rwupdate = 0;
3503 afs_uint32 clcrdate;
3507 } remembertime[NMAXNSERVERS];
3508 int releasecount = 0;
3509 struct volser_status volstatus;
3511 afs_int32 origflags[NMAXNSERVERS];
3512 struct volser_status orig_status;
3513 int notreleased = 0;
3514 int tried_justnewsites = 0;
3515 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3516 int sites = 0; /* number of ro sites */
3517 int new_sites = 0; /* number of ro sites markes as new */
3518 int stayUp = (flags & REL_STAYUP);
3521 CR_RECOVER = 0x0000, /**< not complete: a recovery from a previous failed release */
3522 CR_FORCED = 0x0001, /**< complete: forced by caller */
3523 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3524 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3525 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3526 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3527 } complete_release_t;
3529 complete_release_t complete_release = CR_RECOVER;
3531 memset(remembertime, 0, sizeof(remembertime));
3532 memset(&results, 0, sizeof(results));
3533 memset(origflags, 0, sizeof(origflags));
3535 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3536 if (vcode != VL_RERELEASE)
3537 ONERROR(vcode, afromvol,
3538 "Could not lock the VLDB entry for the volume %u.\n");
3541 /* Get the vldb entry in readable format */
3542 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3543 ONERROR(vcode, afromvol,
3544 "Could not fetch the entry for the volume %u from the VLDB.\n");
3545 MapHostToNetwork(&entry);
3548 EnumerateEntry(&entry);
3550 if (!ISNAMEVALID(entry.name))
3551 ONERROR(VOLSERBADOP, entry.name,
3552 "Volume name %s is too long, rename before releasing.\n");
3553 if (entry.volumeId[RWVOL] != afromvol)
3554 ONERROR(VOLSERBADOP, afromvol,
3555 "The volume %u being released is not a read-write volume.\n");
3556 if (entry.nServers <= 1)
3557 ONERROR(VOLSERBADOP, afromvol,
3558 "Volume %u has no replicas - release operation is meaningless!\n");
3559 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3560 ONERROR(VOLSERBADOP, entry.name,
3561 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3563 /* roclone is true if one of the RO volumes is on the same
3564 * partition as the RW volume. In this case, we make the RO volume
3565 * on the same partition a clone instead of a complete copy.
3568 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3569 roclone = ((roindex == -1) ? 0 : 1);
3570 rwindex = Lp_GetRwIndex(&entry);
3572 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3574 /* Make sure we have a RO volume id to work with */
3575 if (entry.volumeId[ROVOL] == INVALID_BID) {
3576 /* need to get a new RO volume id */
3577 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3578 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3580 entry.volumeId[ROVOL] = roVolId;
3581 MapNetworkToHost(&entry, &storeEntry);
3582 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3583 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3587 * Determine if this is to be a complete release or a recovery of a
3588 * previous unfinished release. The previous release is considered to be
3589 * unfinished when the clone was successfully distributed to at least one
3590 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3593 * The caller can override the vldb flags check using the -force
3594 * or -force-reclone flag, to force this to be a complete release.
3596 for (i = 0; i < entry.nServers; i++) {
3597 if (entry.serverFlags[i] & ITSROVOL) {
3599 if (entry.serverFlags[i] & NEW_REPSITE)
3601 if (entry.serverFlags[i] & RO_DONTUSE)
3604 origflags[i] = entry.serverFlags[i];
3607 if (flags & REL_COMPLETE) {
3608 complete_release |= CR_FORCED;
3611 if (new_sites == 0) {
3612 complete_release |= CR_LAST_OK;
3613 } else if (new_sites == sites) {
3614 complete_release |= CR_ALL_NEW;
3617 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3618 && !(complete_release & CR_FORCED)) {
3619 if (notreleased && notreleased != sites) {
3620 /* we have some new unreleased sites. try to just release to those,
3621 * if the RW has not changed. The caller can override with -force
3622 * or with -force-reclone. */
3627 /* Determine which volume id to use and see if it exists */
3628 cloneVolId = (complete_release || entry.cloneId == 0)
3629 ? entry.volumeId[ROVOL] : entry.cloneId;
3631 code = VolumeExists(afromserver, afrompart, cloneVolId);
3632 roexists = ((code == ENODEV) ? 0 : 1);
3634 /* For stayUp case, if roclone is the only site, bypass special handling */
3635 if (stayUp && roclone) {
3639 for (e = 0; (e < entry.nServers) && !error; e++) {
3640 if ((entry.serverFlags[e] & ITSROVOL)) {
3641 if (!(VLDB_IsSameAddrs(entry.serverNumber[e], afromserver,
3646 if (e >= entry.nServers)
3650 /* If we had a previous release to complete, do so, else: */
3651 if (stayUp && (cloneVolId == entry.volumeId[ROVOL])) {
3652 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVolId);
3653 ONERROR(code, afromvol,
3654 "Cannot get temporary clone id for volume %u\n");
3657 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3659 ONERROR(-1, afromserver,
3660 "Cannot establish connection with server 0x%x\n");
3662 if (!complete_release) {
3664 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3666 /* Begin transaction on RW and mark it busy while we query it */
3667 code = AFSVolTransCreate_retry(
3668 fromconn, afromvol, afrompart, ITBusy, &fromtid
3670 ONERROR(code, afromvol,
3671 "Failed to start transaction on RW volume %u\n");
3673 /* Query the creation date for the RW */
3674 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3675 ONERROR(code, afromvol,
3676 "Failed to get the status of RW volume %u\n");
3677 rwcrdate = volstatus.creationDate;
3679 /* End transaction on RW */
3680 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3682 ONERROR((code ? code : rcode), afromvol,
3683 "Failed to end transaction on RW volume %u\n");
3685 /* Begin transaction on clone and mark it busy while we query it */
3686 code = AFSVolTransCreate_retry(
3687 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3689 ONERROR(code, cloneVolId,
3690 "Failed to start transaction on RW clone %u\n");
3692 /* Query the creation date for the clone */
3693 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3694 ONERROR(code, cloneVolId,
3695 "Failed to get the status of RW clone %u\n");
3696 clcrdate = volstatus.creationDate;
3698 /* End transaction on clone */
3699 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3701 ONERROR((code ? code : rcode), cloneVolId,
3702 "Failed to end transaction on RW clone %u\n");
3704 if (rwcrdate > clcrdate)
3705 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3709 if (!complete_release || (complete_release & CR_NEW_RW)) {
3710 /* in case the RW has changed, and just to be safe */
3715 if (!complete_release) {
3717 "This is a recovery of previously failed release\n");
3719 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3720 /* Give the reasons for a complete release, except if only CR_LAST_OK. */
3721 if (complete_release != CR_LAST_OK) {
3723 if (complete_release & CR_FORCED) {
3724 fprintf(STDOUT, "%sforced", sep);
3727 if (complete_release & CR_LAST_OK) {
3728 fprintf(STDOUT, "%slast ok", sep);
3731 if (complete_release & CR_ALL_NEW) {
3732 fprintf(STDOUT, "%sall sites are new", sep);
3735 if (complete_release & CR_NEW_RW) {
3736 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3739 if (complete_release & CR_RO_MISSING) {
3740 fprintf(STDOUT, "%sro clone missing", sep);
3742 fprintf(STDOUT, ")");
3744 fprintf(STDOUT, "\n");
3746 tried_justnewsites = 1;
3747 fprintf(STDOUT, "There are new RO sites; we will try to "
3748 "only release to new sites\n");
3753 if (complete_release) {
3754 afs_int32 oldest = 0;
3755 /* If the RO clone exists, then if the clone is a temporary
3756 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3757 * (it was recently added), then also delete it. We do not
3758 * want to "reclone" a temporary RO clone.
3761 code = VolumeExists(afromserver, afrompart, cloneVolId);
3763 code = DoVolDelete(fromconn, cloneVolId, afrompart, "previous clone", 0,
3765 if (code && (code != VNOVOL))
3770 /* clean up any previous tmp clone before starting if staying up */
3772 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3773 code = DoVolDelete(fromconn,
3774 stayUp ? entry.volumeId[ROVOL] : cloneVolId,
3775 afrompart, "the", 0, NULL, NULL);
3776 if (code && (code != VNOVOL))
3782 VPRINT("Querying old RO sites for update times...");
3783 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3784 volEntries volumeInfo;
3785 struct rx_connection *conn;
3788 if (!(entry.serverFlags[vldbindex] & ITSROVOL)) {
3791 if ((entry.serverFlags[vldbindex] & RO_DONTUSE)) {
3794 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3796 fprintf(STDERR, "Cannot establish connection to server %s\n",
3797 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3801 volumeInfo.volEntries_val = NULL;
3802 volumeInfo.volEntries_len = 0;
3803 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3804 entry.volumeId[ROVOL],
3807 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3808 (unsigned long)entry.volumeId[ROVOL],
3809 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3810 PrintError("", code);
3812 rx_DestroyConnection(conn);
3816 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3818 if (oldest == 0 || crdate < oldest) {
3822 rx_DestroyConnection(conn);
3823 free(volumeInfo.volEntries_val);
3824 volumeInfo.volEntries_val = NULL;
3825 volumeInfo.volEntries_len = 0;
3830 volEntries volumeInfo;
3831 volumeInfo.volEntries_val = NULL;
3832 volumeInfo.volEntries_len = 0;
3833 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3836 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3837 (unsigned long)afromvol,
3838 hostutil_GetNameByINet(afromserver));
3839 PrintError("", code);
3842 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3844 free(volumeInfo.volEntries_val);
3845 volumeInfo.volEntries_val = NULL;
3846 volumeInfo.volEntries_len = 0;
3849 if (justnewsites && oldest <= rwupdate) {
3850 /* RW has changed */
3854 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3855 * write this entry out to the vlserver until after the first
3856 * RO volume is released (temp RO clones don't count).
3858 * If 'justnewsites' is set, we're only updating sites that have
3859 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3861 for (i = 0; i < entry.nServers; i++) {
3863 if ((entry.serverFlags[i] & RO_DONTUSE)) {
3864 entry.serverFlags[i] &= ~NEW_REPSITE;
3866 entry.serverFlags[i] |= NEW_REPSITE;
3869 entry.serverFlags[i] &= ~NEW_REPSITE;
3870 entry.serverFlags[i] |= RO_DONTUSE;
3873 entry.serverFlags[rwindex] |= NEW_REPSITE;
3874 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3877 if (justnewsites && roexists) {
3878 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3879 * anything with the RO clone, so skip the reclone */
3882 } else if (complete_release) {
3885 strcpy(vname, entry.name);
3887 strcat(vname, ".roclone");
3889 strcat(vname, ".readonly");
3891 strcpy(vname, "readonly-clone-temp");
3894 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3895 cloneVolId, (roclone && !stayUp)?"permanent RO":
3896 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3902 if (justnewsites && rwupdate != volstatus.updateDate) {
3904 /* reset the serverFlags as if 'justnewsites' had never been set */
3905 for (i = 0; i < entry.nServers; i++) {
3906 entry.serverFlags[i] &= ~NEW_REPSITE;
3907 entry.serverFlags[i] |= RO_DONTUSE;
3909 entry.serverFlags[rwindex] |= NEW_REPSITE;
3910 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3913 rwcrdate = volstatus.creationDate;
3915 /* Remember clone volume ID in case we fail or are interrupted */
3916 entry.cloneId = cloneVolId;
3918 if (roclone && !stayUp) {
3919 /* Bring the RO clone online - though not if it's a temporary clone */
3920 VPRINT1("Starting transaction on RO clone volume %u...",
3923 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3925 ONERROR(code, cloneVolId,
3926 "Failed to start transaction on volume %u\n");
3929 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3930 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3933 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3934 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3935 ONERROR((code ? code : rcode), cloneVolId,
3936 "Failed to end transaction on RO clone %u\n");
3939 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3941 /* Sleep so that a client searching for an online volume won't
3942 * find the clone offline and then the next RO offline while the
3943 * release brings the clone online and the next RO offline (race).
3944 * There is a fix in the 3.4 client that does not need this sleep
3945 * anymore, but we don't know what clients we have.
3947 if (entry.nServers > 2 && !justnewsites)
3950 /* Mark the RO clone in the VLDB as a good site (already released) */
3951 entry.serverFlags[roindex] |= NEW_REPSITE;
3952 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3953 entry.flags |= RO_EXISTS;
3957 /* Write out the VLDB entry only if the clone is not a temporary
3958 * clone. If we did this to a temporary clone then we would end
3959 * up marking all the ROs as "old release" making the ROs
3960 * temporarily unavailable.
3962 MapNetworkToHost(&entry, &storeEntry);
3963 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3964 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3965 ONERROR(vcode, entry.name,
3966 "Could not update vldb entry for %s.\n");
3972 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3973 /* act like this is a completion of a previous release */
3974 complete_release = CR_RECOVER;
3975 } else if (tried_justnewsites) {
3976 VPRINT("RW vol has changed; releasing to all sites\n");
3979 /* Now we will release from the clone to the remaining RO replicas.
3980 * The first 2 ROs (counting the non-temporary RO clone) are released
3981 * individually: releasecount. This is to reduce the race condition
3982 * of clients trying to find an on-line RO volume. The remaining ROs
3983 * are released in parallel but no more than half the number of ROs
3984 * (rounded up) at a time: nservers.
3987 strcpy(vname, entry.name);
3989 strcat(vname, ".roclone");
3991 strcat(vname, ".readonly");
3992 memset(&cookie, 0, sizeof(cookie));
3993 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3994 cookie.type = ROVOL;
3995 cookie.parent = entry.volumeId[RWVOL];
3998 /* how many to do at once, excluding clone */
3999 if (stayUp || justnewsites)
4000 nservers = entry.nServers; /* can do all, none offline */
4002 nservers = entry.nServers / 2;
4003 replicas = calloc(nservers + 1, sizeof(struct replica));
4004 times = calloc(nservers + 1, sizeof(struct release));
4005 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
4006 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
4007 if (!replicas || !times || !results.manyResults_val || !toconns)
4009 "Failed to create transaction on the release clone\n");
4011 /* Create a transaction on the cloned volume */
4012 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
4014 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
4016 memset(&orig_status, 0, sizeof(orig_status));
4017 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
4019 if (!complete_release && code)
4020 ONERROR(VOLSERNOVOL, afromvol,
4021 "Old clone is inaccessible. Try vos release -f %u.\n");
4022 ONERROR0(code, "Failed to create transaction on the release clone\n");
4025 /* if we have a clone, treat this as done, for now */
4026 if (stayUp && !complete_release) {
4027 entry.serverFlags[roindex] |= NEW_REPSITE;
4028 entry.serverFlags[roindex] &= ~RO_DONTUSE;
4029 entry.flags |= RO_EXISTS;
4034 /* For each index in the VLDB */
4035 for (vldbindex = 0; vldbindex < entry.nServers;) {
4036 /* Get a transaction on the replicas. Pick replicas which have an old release. */
4038 ((volcount < nservers) && (vldbindex < entry.nServers));
4040 if (!stayUp && !justnewsites) {
4041 /* The first two RO volumes will be released individually.
4042 * The rest are then released in parallel. This is a hack
4043 * for clients not recognizing right away when a RO volume
4044 * comes back on-line.
4046 if ((volcount == 1) && (releasecount < 2))
4050 if (vldbindex == roindex)
4051 continue; /* the clone */
4052 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
4053 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
4055 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
4056 continue; /* not a RO vol */
4059 /* Get a Transaction on this replica. Get a new connection if
4060 * necessary. Create the volume if necessary. Return the
4061 * time from which the dump should be made (0 if it's a new
4062 * volume). Each volume might have a different time.
4064 replicas[volcount].server.destHost =
4065 ntohl(entry.serverNumber[vldbindex]);
4066 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
4067 replicas[volcount].server.destSSID = 1;
4068 times[volcount].vldbEntryIndex = vldbindex;
4071 GetTrans(&entry, vldbindex, &(toconns[volcount]),
4072 &(replicas[volcount].trans),
4073 &(times[volcount].crtime),
4074 &(times[volcount].uptime),
4075 origflags, stayUp?cloneVolId:0);
4079 /* Thisdate is the date from which we want to pick up all changes */
4080 if (flags & REL_FULLDUMPS) {
4081 /* Do a full dump when forced by the caller. */
4082 VPRINT("This will be a full dump: forced\n");
4084 } else if (!complete_release) {
4085 /* If this release is a recovery of a failed release, we can't be
4086 * sure the creation date is good, so do a full dump.
4088 VPRINT("This will be a full dump: previous release failed\n");
4090 } else if (times[volcount].crtime == 0) {
4091 /* A full dump is needed for a new read-only volume. */
4093 ("This will be a full dump: read-only volume needs to be created\n");
4095 } else if ((rwcrdate > times[volcount].crtime)) {
4096 /* If the RW volume was replaced (its creation date is newer than
4097 * the last release), then we can't be sure what has changed (so
4098 * we do a full dump).
4101 ("This will be a full dump: read-write volume was replaced\n");
4103 } else if (remembertime[vldbindex].validtime) {
4104 /* Trans was prev ended. Use the time from the prev trans
4105 * because, prev trans may have created the volume. In which
4106 * case time[volcount].time would be now instead of 0.
4109 (remembertime[vldbindex].uptime < times[volcount].uptime)
4110 ? remembertime[vldbindex].uptime
4111 : times[volcount].uptime;
4113 thisdate = times[volcount].uptime;
4115 remembertime[vldbindex].validtime = 1;
4116 remembertime[vldbindex].uptime = thisdate;
4118 if (volcount == 0) {
4119 fromdate = thisdate;
4121 /* Include this volume if it is within 15 minutes of the earliest */
4123 thisdate) ? (fromdate - thisdate) : (thisdate -
4125 AFSVolEndTrans(toconns[volcount],
4126 replicas[volcount].trans, &rcode);
4127 replicas[volcount].trans = 0;
4130 if (thisdate < fromdate)
4131 fromdate = thisdate;
4138 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
4145 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
4146 (unsigned long)cloneVolId, stayUp?
4147 cloneVolId:entry.volumeId[ROVOL],
4148 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
4149 vldbEntryIndex], hoststr) :
4150 hostutil_GetNameByINet(entry.
4151 serverNumber[times[0].
4154 for (s = 1; s < volcount; s++) {
4155 fprintf(STDOUT, " and %s",
4156 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
4157 vldbEntryIndex], hoststr) :
4158 hostutil_GetNameByINet(entry.
4159 serverNumber[times[s].
4164 fprintf(STDOUT, " (entire volume)");
4167 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4169 fprintf(STDOUT, ".\n");
4173 /* Release the ones we have collected */
4174 tr.manyDests_val = &(replicas[0]);
4175 tr.manyDests_len = results.manyResults_len = volcount;
4177 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4178 0 /*spare */ , &cookie, &results);
4179 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4181 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4182 0 /*spare */ , &cookie, &results);
4187 PrintError("Release failed: ", code);
4189 for (m = 0; m < volcount; m++) {
4190 if (results.manyResults_val[m]) {
4191 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4192 /* we retry timed out transaction. When it is
4193 * not the first volume and the transaction wasn't found
4194 * (assume it timed out and was garbage collected by volser).
4197 ("Failed to dump volume from clone to a ro site: ",
4198 results.manyResults_val[m]);
4204 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4205 ROVOL, entry.volumeId[RWVOL], 0, 0);
4207 if ((m == 0) || (code != ENOENT)) {
4208 PrintError("Failed to set correct names and ids: ",
4214 /* have to clear dest. flags to ensure new vol goes online:
4215 * because the restore (forwarded) operation copied
4216 * the V_inService(=0) flag over to the destination.
4218 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4220 if ((m == 0) || (code != ENOENT)) {
4221 PrintError("Failed to set flags on ro volume: ",
4227 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
4228 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
4229 entry.flags |= RO_EXISTS;
4235 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4236 MapNetworkToHost(&entry, &storeEntry);
4237 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4238 ONERROR(vcode, afromvol,
4239 " Could not update VLDB entry for volume %u\n");
4241 } /* for each index in the vldb */
4243 /* for the stayup case, put back at the end */
4245 afs_uint32 tmpVol = entry.volumeId[ROVOL];
4246 strcpy(vname, entry.name);
4247 strcat(vname, ".readonly");
4250 /* have to clear flags to ensure new vol goes online
4252 code = AFSVolSetFlags(fromconn, fromtid, 0);
4253 if (code && (code != ENOENT)) {
4254 PrintError("Failed to set flags on ro volume: ",
4258 VPRINT3("%sloning to permanent RO %u on %s...", roexists?"Re-c":"C", tmpVol,
4260 afs_inet_ntoa_r(entry.serverNumber[roindex],
4262 hostutil_GetNameByINet(entry.serverNumber[roindex]));
4264 code = AFSVolClone(fromconn, fromtid, roexists?tmpVol:0,
4265 readonlyVolume, vname, &tmpVol);
4269 VPRINT("Bringing readonly online...");
4270 code = DoVolOnline(&entry, tmpVol, roindex, vname,
4274 EPRINT(code, "Failed: ");
4275 entry.serverFlags[roindex] &= ~NEW_REPSITE;
4276 entry.serverFlags[roindex] |= RO_DONTUSE;
4278 entry.serverFlags[roindex] |= NEW_REPSITE;
4279 entry.serverFlags[roindex] &= ~RO_DONTUSE;
4280 entry.flags |= RO_EXISTS;
4285 for (s = 0; s < volcount; s++) {
4286 if (replicas[s].trans) {
4287 vldbindex = times[s].vldbEntryIndex;
4289 /* ok, so now we have to end the previous transaction */
4290 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4295 code = AFSVolTransCreate_retry(toconns[s],
4297 entry.serverPartition[vldbindex],
4299 &(replicas[s].trans));
4301 PrintError("Unable to begin transaction on temporary clone: ", code);
4304 PrintError("Unable to end transaction on temporary clone: ", code);
4307 VPRINT3("%sloning to permanent RO %u on %s...", times[s].crtime?"Re-c":"C",
4309 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4311 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4312 if (times[s].crtime)
4313 code = AFSVolClone(toconns[s], replicas[s].trans, tmpVol,
4314 readonlyVolume, vname, &tmpVol);
4316 code = AFSVolClone(toconns[s], replicas[s].trans, 0,
4317 readonlyVolume, vname, &tmpVol);
4320 if (!times[s].crtime) {
4321 entry.serverFlags[vldbindex] |= RO_DONTUSE;
4323 entry.serverFlags[vldbindex] &= ~NEW_REPSITE;
4324 PrintError("Failed: ",
4329 if (entry.serverFlags[vldbindex] != RO_DONTUSE) {
4330 /* bring it online (mark it InService) */
4331 VPRINT1("Bringing readonly online on %s...",
4334 htonl(replicas[s].server.destHost),
4336 hostutil_GetNameByINet(
4337 htonl(replicas[s].server.destHost)));
4339 code = DoVolOnline(&entry, tmpVol, vldbindex, vname,
4341 /* needed to come online for cloning */
4343 /* technically it's still new, just not online */
4344 entry.serverFlags[s] &= ~NEW_REPSITE;
4345 entry.serverFlags[s] |= RO_DONTUSE;
4346 if (code != ENOENT) {
4347 PrintError("Failed to set correct names and ids: ",
4354 VPRINT("Marking temporary clone for deletion...\n");
4355 code = AFSVolSetFlags(toconns[s],
4360 EPRINT(code, "Failed: ");
4364 VPRINT("Ending transaction on temporary clone...\n");
4365 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4369 PrintError("Failed: ", code);
4372 /* ended successfully */
4373 replicas[s].trans = 0;
4375 VPRINT2("Deleting temporary clone %u on %s...", cloneVolId,
4377 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4379 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4380 code = DoVolDelete(toconns[s], cloneVolId,
4381 entry.serverPartition[vldbindex],
4382 NULL, 0, NULL, NULL);
4384 EPRINT(code, "Failed: ");
4391 /* done. put the vldb entry in the success tail case*/
4392 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4395 /* End the transaction on the cloned volume */
4396 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4401 PrintError("Failed to end transaction on rw volume: ", code);
4403 /* Figure out if any volume were not released and say so */
4404 for (failure = 0, i = 0; i < entry.nServers; i++) {
4405 if (!(entry.serverFlags[i] & NEW_REPSITE))
4411 "The volume %lu could not be released to the following %d sites:\n",
4412 (unsigned long)afromvol, failure);
4413 for (i = 0; i < entry.nServers; i++) {
4414 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
4415 MapPartIdIntoName(entry.serverPartition[i], pname);
4416 fprintf(STDERR, "\t%35s %s\n",
4417 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4418 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4421 MapNetworkToHost(&entry, &storeEntry);
4423 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4425 ONERROR(vcode, afromvol,
4426 " Could not update VLDB entry for volume %u\n");
4428 ERROREXIT(VOLSERBADRELEASE);
4432 /* All the ROs were release successfully. Remove the temporary clone */
4433 if (!roclone || stayUp) {
4435 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4436 (unsigned long)cloneVolId);
4439 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4441 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4445 for (i = 0; i < entry.nServers; i++)
4446 entry.serverFlags[i] &= ~NEW_REPSITE;
4448 /* Update the VLDB */
4449 VPRINT("updating VLDB ...");
4451 MapNetworkToHost(&entry, &storeEntry);
4453 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4454 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4455 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4460 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4464 "Failed to end cloning transaction on the RW volume %lu\n",
4465 (unsigned long)afromvol);
4471 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4475 "Failed to end transaction on the release clone %lu\n",
4476 (unsigned long)cloneVolId);
4481 for (i = 0; i < nservers; i++) {
4482 if (replicas && replicas[i].trans) {
4483 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4484 replicas[i].trans = 0;
4487 "Failed to end transaction on ro volume %u at server %s\n",
4488 entry.volumeId[ROVOL],
4489 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4490 destHost), hoststr) :
4491 hostutil_GetNameByINet(htonl
4492 (replicas[i].server.destHost)));
4497 if (toconns && toconns[i]) {
4498 rx_DestroyConnection(toconns[i]);
4504 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4505 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4508 "Could not release lock on the VLDB entry for volume %lu\n",
4509 (unsigned long)afromvol);
4515 PrintError("", error);
4518 rx_DestroyConnection(fromconn);
4519 if (results.manyResults_val)
4520 free(results.manyResults_val);
4532 dump_sig_handler(int x)
4534 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4538 /* Dump the volume <afromvol> on <afromserver> and
4539 * <afrompart> to <afilename> starting from <fromdate>.
4540 * DumpFunction does the real work behind the scenes after
4541 * extracting parameters from the rock
4544 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4546 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4549 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4550 * be changing during the dump */
4551 struct rx_call * volatile fromcall = NULL;
4552 struct rx_connection * volatile fromconn = NULL;
4553 afs_int32 volatile fromtid = 0;
4555 afs_int32 rcode = 0;
4556 afs_int32 code, error = 0;
4558 time_t tmv = fromdate;
4562 #ifndef AFS_NT40_ENV
4563 (void)signal(SIGPIPE, dump_sig_handler);
4565 (void)signal(SIGINT, dump_sig_handler);
4568 VEPRINT("Full Dump ...\n");
4570 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4574 /* get connections to the servers */
4575 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4577 VEPRINT1("Starting transaction on volume %u...", afromvol);
4579 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4581 EGOTO1(error_exit, code,
4582 "Could not start transaction on the volume %u to be dumped\n",
4586 fromcall = rx_NewCall(fromconn);
4588 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4589 if (flags & VOLDUMPV2_OMITDIRS)
4590 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4592 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4593 EGOTO(error_exit, code, "Could not start the dump process \n");
4596 VEPRINT1("Dumping volume %u...", afromvol);
4597 code = DumpFunction(fromcall, rock);
4598 if (code == RXGEN_OPCODE)
4600 EGOTO(error_exit, code, "Error while dumping volume \n");
4605 code = rx_EndCall(fromcall, 0);
4606 if (code && code != RXGEN_OPCODE)
4607 fprintf(STDERR, "Error in rx_EndCall\n");
4612 VEPRINT1("Ending transaction on volume %u...", afromvol);
4613 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4614 if (code || rcode) {
4615 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4616 (unsigned long)afromvol);
4618 error = (code ? code : rcode);
4623 rx_DestroyConnection(fromconn);
4625 if (error != RXGEN_OPCODE)
4626 PrintError("", error);
4630 /* Clone the volume <afromvol> on <afromserver> and
4631 * <afrompart>, and then dump the clone volume to
4632 * <afilename> starting from <fromdate>.
4633 * DumpFunction does the real work behind the scenes after
4634 * extracting parameters from the rock
4637 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4638 afs_int32 afrompart, afs_int32 fromdate,
4639 afs_int32(*DumpFunction) (struct rx_call *, void *),
4640 void *rock, afs_int32 flags)
4642 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4643 * be changing during the dump */
4644 struct rx_connection * volatile fromconn = NULL;
4645 struct rx_call * volatile fromcall = NULL;
4646 afs_int32 volatile clonetid = 0;
4647 afs_uint32 volatile clonevol = 0;
4650 afs_int32 fromtid = 0, rcode = 0;
4651 afs_int32 code = 0, error = 0;
4654 time_t tmv = fromdate;
4658 #ifndef AFS_NT40_ENV
4659 (void)signal(SIGPIPE, dump_sig_handler);
4661 (void)signal(SIGINT, dump_sig_handler);
4664 VEPRINT("Full Dump ...\n");
4666 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4670 /* get connections to the servers */
4671 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4673 VEPRINT1("Starting transaction on volume %u...", afromvol);
4674 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4675 EGOTO1(error_exit, code,
4676 "Could not start transaction on the volume %u to be dumped\n",
4680 /* Get a clone id */
4681 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4683 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4685 EGOTO1(error_exit, code,
4686 "Could not get an ID for the clone of volume %u from the VLDB\n",
4690 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4691 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4693 strcpy(vname, "dump-clone-temp");
4696 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
4698 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4702 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4704 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4708 EGOTO1(error_exit, code,
4709 "Failed to end the transaction on the volume %u\n", afromvol);
4713 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4716 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4719 EGOTO1(error_exit, code,
4720 "Failed to start a transaction on the cloned volume%u\n",
4724 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4725 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4726 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4731 fromcall = rx_NewCall(fromconn);
4733 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4734 if (flags & VOLDUMPV2_OMITDIRS)
4735 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4737 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4738 EGOTO(error_exit, code, "Could not start the dump process \n");
4741 VEPRINT1("Dumping volume %u...", afromvol);
4742 code = DumpFunction(fromcall, rock);
4743 EGOTO(error_exit, code, "Error while dumping volume \n");
4747 /* now delete the clone */
4748 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4749 code = AFSVolDeleteVolume(fromconn, clonetid);
4751 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4752 (unsigned long)clonevol);
4758 code = rx_EndCall(fromcall, 0);
4760 fprintf(STDERR, "Error in rx_EndCall\n");
4766 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4767 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4768 if (code || rcode) {
4770 "Could not end transaction on the cloned volume %lu\n",
4771 (unsigned long)clonevol);
4773 error = (code ? code : rcode);
4778 rx_DestroyConnection(fromconn);
4780 PrintError("", error);
4787 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4788 * the dump file <afilename>. WriteData does all the real work
4789 * after extracting params from the rock
4792 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4793 afs_uint32 toparentid, char tovolname[], int flags,
4794 afs_int32(*WriteData) (struct rx_call *, void *),
4797 struct rx_connection *toconn, *tempconn;
4798 struct rx_call *tocall;
4799 afs_int32 totid, code, rcode, vcode, terror = 0;
4800 struct volser_status tstatus;
4801 struct volintInfo vinfo;
4803 char tovolreal[VOLSER_OLDMAXVOLNAME];
4805 afs_int32 temptid, pparentid;
4806 struct nvldbentry entry, storeEntry;
4809 struct restoreCookie cookie;
4811 afs_int32 volflag, voltype, volsertype;
4812 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4813 int index, same, errcode;
4817 memset(&cookie, 0, sizeof(cookie));
4821 tocall = (struct rx_call *)0;
4822 tempconn = (struct rx_connection *)0;
4826 if (flags & RV_RDONLY) {
4828 volsertype = volser_RO;
4831 volsertype = volser_RW;
4835 pparentid = toparentid;
4836 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4837 if (pvolid == 0) { /*alot a new id if needed */
4838 vcode = VLDB_GetEntryByName(tovolname, &entry);
4839 if (vcode == VL_NOENT) {
4840 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4842 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4848 } else if (flags & RV_RDONLY) {
4849 if (entry.flags & RW_EXISTS) {
4851 "Entry for ReadWrite volume %s already exists!\n",
4853 error = VOLSERBADOP;
4856 if (!entry.volumeId[ROVOL]) {
4858 "Existing entry for volume %s has no ReadOnly ID\n",
4860 error = VOLSERBADOP;
4863 pvolid = entry.volumeId[ROVOL];
4864 pparentid = entry.volumeId[RWVOL];
4866 pvolid = entry.volumeId[RWVOL];
4867 pparentid = entry.volumeId[RWVOL];
4870 if (!pparentid) pparentid = pvolid;
4871 /* at this point we have a volume id to use/reuse for the volume to be restored */
4872 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4874 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4875 EGOTO1(refail, VOLSERBADOP,
4876 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4879 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4880 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4881 EGOTO1(refail, VOLSERBADOP,
4882 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4884 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4887 MapPartIdIntoName(topart, partName);
4888 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4889 tovolreal, (unsigned long)pvolid,
4890 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4891 hostutil_GetNameByINet(toserver), partName);
4894 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4897 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4898 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4900 if (code && code != VNOVOL) {
4906 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4908 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4911 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4912 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4915 code = AFSVolGetStatus(toconn, totid, &tstatus);
4916 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4920 oldCreateDate = tstatus.creationDate;
4921 oldUpdateDate = tstatus.updateDate;
4927 cookie.parent = pparentid;
4928 cookie.type = voltype;
4930 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4932 tocall = rx_NewCall(toconn);
4933 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4935 fprintf(STDERR, "Volume restore Failed \n");
4939 code = WriteData(tocall, rock);
4941 fprintf(STDERR, "Could not transmit data\n");
4945 terror = rx_EndCall(tocall, 0);
4946 tocall = (struct rx_call *)0;
4948 fprintf(STDERR, "rx_EndCall Failed \n");
4952 code = AFSVolGetStatus(toconn, totid, &tstatus);
4955 "Could not get status information about the volume %lu\n",
4956 (unsigned long)pvolid);
4960 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4962 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4963 (unsigned long)pvolid);
4968 if (flags & RV_CRDUMP)
4969 newCreateDate = tstatus.creationDate;
4970 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4971 newCreateDate = oldCreateDate;
4973 newCreateDate = time(0);
4974 if (flags & RV_LUDUMP)
4975 newUpdateDate = tstatus.updateDate;
4976 else if (flags & RV_LUKEEP)
4977 newUpdateDate = oldUpdateDate;
4979 newUpdateDate = time(0);
4980 code = AFSVolSetDate(toconn,totid, newCreateDate);
4982 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4987 init_volintInfo(&vinfo);
4988 vinfo.creationDate = newCreateDate;
4989 vinfo.updateDate = newUpdateDate;
4990 code = AFSVolSetInfo(toconn, totid, &vinfo);
4992 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4998 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4999 code = AFSVolSetFlags(toconn, totid, volflag);
5001 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
5006 /* It isn't handled right in refail */
5007 code = AFSVolEndTrans(toconn, totid, &rcode);
5012 fprintf(STDERR, "Could not end transaction on %lu\n",
5013 (unsigned long)pvolid);
5018 fprintf(STDOUT, " done\n");
5020 if (!reuseID || (flags & RV_FULLRST)) {
5021 /* Volume was restored on the file server, update the
5022 * VLDB to reflect the change.
5024 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
5025 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
5027 "Could not fetch the entry for volume number %lu from VLDB \n",
5028 (unsigned long)pvolid);
5033 MapHostToNetwork(&entry);
5034 if (vcode == VL_NOENT) { /* it doesnot exist already */
5035 /*make the vldb return this indication specifically */
5036 VPRINT("------- Creating a new VLDB entry ------- \n");
5037 strcpy(entry.name, tovolname);
5039 entry.serverNumber[0] = toserver; /*should be indirect */
5040 entry.serverPartition[0] = topart;
5041 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
5042 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
5043 if (flags & RV_RDONLY)
5044 entry.volumeId[ROVOL] = pvolid;
5045 else if (tstatus.cloneID != 0) {
5046 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
5048 entry.volumeId[ROVOL] = INVALID_BID;
5049 entry.volumeId[RWVOL] = pparentid;
5051 if (tstatus.backupID != 0) {
5052 entry.volumeId[BACKVOL] = tstatus.backupID;
5053 /*this should come from status info on the volume if non zero */
5055 entry.volumeId[BACKVOL] = INVALID_BID;
5056 MapNetworkToHost(&entry, &storeEntry);
5057 vcode = VLDB_CreateEntry(&storeEntry);
5060 "Could not create the VLDB entry for volume number %lu \n",
5061 (unsigned long)pvolid);
5067 EnumerateEntry(&entry);
5068 } else { /*update the existing entry */
5070 fprintf(STDOUT, "Updating the existing VLDB entry\n");
5071 fprintf(STDOUT, "------- Old entry -------\n");
5072 EnumerateEntry(&entry);
5073 fprintf(STDOUT, "------- New entry -------\n");
5076 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
5080 "Could not lock the entry for volume number %lu \n",
5081 (unsigned long)pvolid);
5086 strcpy(entry.name, tovolname);
5088 /* Update the vlentry with the new information */
5089 if (flags & RV_RDONLY)
5090 index = Lp_ROMatch(toserver, topart, &entry) - 1;
5092 index = Lp_GetRwIndex(&entry);
5094 /* Add the new site for the volume being restored */
5095 entry.serverNumber[entry.nServers] = toserver;
5096 entry.serverPartition[entry.nServers] = topart;
5097 entry.serverFlags[entry.nServers] =
5098 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
5101 /* This volume should be deleted on the old site
5102 * if its different from new site.
5105 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
5109 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
5111 if ((!errcode && !same)
5112 || (entry.serverPartition[index] != topart)) {
5113 if (flags & RV_NODEL) {
5115 ("Not deleting the previous volume %u on server %s, ...",
5117 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
5118 hostutil_GetNameByINet(entry.serverNumber[index]));
5121 UV_Bind(entry.serverNumber[index],
5122 AFSCONF_VOLUMEPORT);
5124 MapPartIdIntoName(entry.serverPartition[index],
5127 ("Deleting the previous volume %u on server %s, partition %s ...",
5129 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
5130 hostutil_GetNameByINet(entry.serverNumber[index]),
5132 code = DoVolDelete(tempconn, pvolid,
5133 entry.serverPartition[index],
5134 "the", 0, NULL, NULL);
5135 if (code && code != VNOVOL) {
5139 MapPartIdIntoName(entry.serverPartition[index],
5143 entry.serverNumber[index] = toserver;
5144 entry.serverPartition[index] = topart;
5147 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
5148 MapNetworkToHost(&entry, &storeEntry);
5150 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
5151 LOCKREL_OPCODE | LOCKREL_AFSID |
5155 "Could not update the entry for volume number %lu \n",
5156 (unsigned long)pvolid);
5162 EnumerateEntry(&entry);
5169 code = rx_EndCall(tocall, 0);
5175 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
5176 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5179 "Could not release lock on the VLDB entry for the volume %lu\n",
5180 (unsigned long)pvolid);
5186 code = AFSVolEndTrans(toconn, totid, &rcode);
5190 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
5191 (unsigned long)pvolid);
5197 code = AFSVolEndTrans(toconn, temptid, &rcode);
5201 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
5202 (unsigned long)pvolid);
5208 rx_DestroyConnection(tempconn);
5210 rx_DestroyConnection(toconn);
5211 PrintError("", error);
5216 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
5217 char tovolname[], int flags,
5218 afs_int32(*WriteData) (struct rx_call *, void *),
5221 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
5226 /*unlocks the vldb entry associated with <volid> */
5228 UV_LockRelease(afs_uint32 volid)
5232 VPRINT("Binding to the VLDB server\n");
5234 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5235 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5238 "Could not unlock the entry for volume number %lu in VLDB \n",
5239 (unsigned long)volid);
5240 PrintError("", vcode);
5243 VPRINT("VLDB updated\n");
5248 /* old interface to add rosites */
5250 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5253 return UV_AddSite2(server, part, volid, 0, valid);
5256 /*adds <server> and <part> as a readonly replication site for <volid>
5259 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5260 afs_uint32 rovolid, afs_int32 valid)
5262 int j, nro = 0, islocked = 0;
5263 struct nvldbentry entry, storeEntry, entry2;
5264 afs_int32 vcode, error = 0;
5267 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5270 " Could not lock the VLDB entry for the volume %lu \n",
5271 (unsigned long)volid);
5276 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
5279 "Could not fetch the VLDB entry for volume number %lu \n",
5280 (unsigned long)volid);
5284 if (!ISNAMEVALID(entry.name)) {
5286 "Volume name %s is too long, rename before adding site\n",
5288 error = VOLSERBADOP;
5291 MapHostToNetwork(&entry);
5293 /* See if it's too many entries */
5294 if (entry.nServers >= NMAXNSERVERS) {
5295 fprintf(STDERR, "Total number of entries will exceed %u\n",
5297 error = VOLSERBADOP;
5301 /* See if it's on the same server */
5302 for (j = 0; j < entry.nServers; j++) {
5303 if (entry.serverFlags[j] & ITSROVOL) {
5305 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5308 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5311 MapPartIdIntoName(entry.serverPartition[j], apartName);
5313 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5315 error = VOLSERBADOP;
5322 /* See if it's too many RO sites - leave one for the RW */
5323 if (nro >= NMAXNSERVERS - 1) {
5324 fprintf(STDERR, "Total number of sites will exceed %u\n",
5326 error = VOLSERBADOP;
5330 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5331 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5332 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5335 if (entry.volumeId[ROVOL] == INVALID_BID) {
5336 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5338 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5341 VPRINT1("Using RO volume id %d.\n", rovolid);
5342 entry.volumeId[ROVOL] = rovolid;
5344 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5345 rovolid, entry.volumeId[ROVOL]);
5349 VPRINT("Adding a new site ...");
5350 entry.serverNumber[entry.nServers] = server;
5351 entry.serverPartition[entry.nServers] = part;
5353 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
5355 entry.serverFlags[entry.nServers] = (ITSROVOL);
5359 MapNetworkToHost(&entry, &storeEntry);
5361 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5362 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5364 fprintf(STDERR, "Could not update entry for volume %lu \n",
5365 (unsigned long)volid);
5374 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5375 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5378 "Could not release lock on volume entry for %lu \n",
5379 (unsigned long)volid);
5380 PrintError("", vcode);
5384 PrintError("", error);
5388 /*removes <server> <part> as read only site for <volid> from the vldb */
5390 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5393 struct nvldbentry entry, storeEntry;
5395 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5397 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5398 (unsigned long)volid);
5399 PrintError("", vcode);
5402 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5405 "Could not fetch the entry for volume number %lu from VLDB \n",
5406 (unsigned long)volid);
5407 PrintError("", vcode);
5410 MapHostToNetwork(&entry);
5411 if (!Lp_ROMatch(server, part, &entry)) {
5412 /*this site doesnot exist */
5413 fprintf(STDERR, "This site is not a replication site \n");
5415 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5416 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5418 fprintf(STDERR, "Could not update entry for volume %lu \n",
5419 (unsigned long)volid);
5420 PrintError("", vcode);
5421 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5422 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5426 } else { /*remove the rep site */
5427 Lp_SetROValue(&entry, server, part, 0, 0);
5429 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
5430 entry.flags &= ~RO_EXISTS;
5431 if (entry.nServers < 1) { /*this is the last ref */
5432 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5434 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5437 "Could not delete VLDB entry for volume %lu \n",
5438 (unsigned long)volid);
5439 PrintError("", vcode);
5444 MapNetworkToHost(&entry, &storeEntry);
5445 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5446 (unsigned long)volid);
5449 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5450 LOCKREL_OPCODE | LOCKREL_AFSID |
5454 "Could not release lock on volume entry for %lu \n",
5455 (unsigned long)volid);
5456 PrintError("", vcode);
5457 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5458 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5466 /*sets <server> <part> as read/write site for <volid> in the vldb */
5468 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5471 struct nvldbentry entry, storeEntry;
5474 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5476 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5477 (unsigned long)volid);
5478 PrintError("", vcode);
5481 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5484 "Could not fetch the entry for volume number %lu from VLDB \n",
5485 (unsigned long)volid);
5486 PrintError("", vcode);
5489 MapHostToNetwork(&entry);
5490 index = Lp_GetRwIndex(&entry);
5492 /* no RW site exists */
5493 fprintf(STDERR, "No existing RW site for volume %lu",
5494 (unsigned long)volid);
5496 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5497 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5500 "Could not release lock on entry for volume %lu \n",
5501 (unsigned long)volid);
5502 PrintError("", vcode);
5506 } else { /* change the RW site */
5507 entry.serverNumber[index] = server;
5508 entry.serverPartition[index] = part;
5509 MapNetworkToHost(&entry, &storeEntry);
5511 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5512 LOCKREL_OPCODE | LOCKREL_AFSID |
5515 fprintf(STDERR, "Could not update entry for volume %lu \n",
5516 (unsigned long)volid);
5517 PrintError("", vcode);
5518 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5519 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5527 /*list all the partitions on <aserver> */
5529 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5532 struct rx_connection *aconn;
5533 struct pIDs partIds;
5534 struct partEntries partEnts;
5538 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5540 partEnts.partEntries_len = 0;
5541 partEnts.partEntries_val = NULL;
5542 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5543 if (code == RXGEN_OPCODE) {
5544 for (i = 0; i < 26; i++) /* try old interface */
5545 partIds.partIds[i] = -1;
5546 code = AFSVolListPartitions(aconn, &partIds);
5548 for (i = 0; i < 26; i++) {
5549 if ((partIds.partIds[i]) != -1) {
5550 ptrPartList->partId[j] = partIds.partIds[i];
5551 ptrPartList->partFlags[j] = PARTVALID;
5554 ptrPartList->partFlags[i] = 0;
5559 *cntp = partEnts.partEntries_len;
5560 if (*cntp > VOLMAXPARTS) {
5562 "Warning: number of partitions on the server too high %d (process only %d)\n",
5563 *cntp, VOLMAXPARTS);
5564 *cntp = VOLMAXPARTS;
5566 for (i = 0; i < *cntp; i++) {
5567 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5568 ptrPartList->partFlags[i] = PARTVALID;
5570 free(partEnts.partEntries_val);
5576 "Could not fetch the list of partitions from the server\n");
5577 PrintError("", code);
5579 rx_DestroyConnection(aconn);
5584 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5585 This is used by the backup system */
5587 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5588 struct volDescription *volPtr, afs_int32 arraySize)
5590 struct rx_connection *aconn;
5591 struct volDescription *curPtr;
5594 afs_int32 success = 1;
5596 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5598 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5599 if (curPtr->volFlags & CLONEVALID) {
5600 curPtr->volFlags &= ~CLONEZAPPED;
5603 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5604 "clone", 0, NULL, NULL);
5609 curPtr->volFlags |= CLONEZAPPED;
5611 fprintf(STDERR, "Could not zap volume %lu\n",
5612 (unsigned long)curPtr->volCloneId);
5614 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5615 curPtr->volCloneId);
5620 rx_DestroyConnection(aconn);
5624 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5627 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5628 struct volDescription *volPtr, afs_int32 arraySize)
5630 struct rx_connection *aconn;
5631 struct volDescription *curPtr;
5634 afs_int32 rcode = 0;
5636 int reuseCloneId = 0;
5637 afs_uint32 curCloneId = 0;
5638 char cloneName[256]; /*max vol name */
5640 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5642 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5644 else { /*get a bunch of id's from vldb */
5646 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5648 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5649 PrintError("", code);
5654 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5655 if (curPtr->volFlags & ENTRYVALID) {
5657 curPtr->volFlags |= CLONEVALID;
5658 /*make a clone of curParentId and record as curPtr->volCloneId */
5660 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5663 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5666 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5670 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5671 strcpy(cloneName, curPtr->volName);
5672 strcat(cloneName, "-tmpClone-");
5674 strcpy(cloneName, "-tmpClone");
5676 curPtr->volCloneId = curCloneId;
5681 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5682 &(curPtr->volCloneId));
5684 curPtr->volFlags &= ~CLONEVALID;
5686 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5687 curPtr->volName, (unsigned long)code);
5688 code = AFSVolEndTrans(aconn, tid, &rcode);
5690 fprintf(STDERR, "WARNING: could not end transaction\n");
5693 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5694 curPtr->volCloneId);
5695 code = AFSVolEndTrans(aconn, tid, &rcode);
5696 if (code || rcode) {
5697 curPtr->volFlags &= ~CLONEVALID;
5706 rx_DestroyConnection(aconn);
5711 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5712 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5714 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5715 struct volintInfo **resultPtr, afs_int32 * size)
5717 struct rx_connection *aconn;
5719 volEntries volumeInfo;
5723 *resultPtr = (volintInfo *) 0;
5724 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5725 volumeInfo.volEntries_len = 0;
5727 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5728 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5731 "Could not fetch the list of volumes from the server\n");
5733 *resultPtr = volumeInfo.volEntries_val;
5734 *size = volumeInfo.volEntries_len;
5738 rx_DestroyConnection(aconn);
5739 PrintError("", code);
5743 /*------------------------------------------------------------------------
5744 * EXPORTED UV_XListVolumes
5747 * List the extended information for all the volumes on a particular
5748 * File Server and partition. We may either return the volume's ID
5749 * or all of its extended information.
5752 * a_serverID : Address of the File Server for which we want
5753 * extended volume info.
5754 * a_partID : Partition for which we want the extended
5756 * a_all : If non-zero, fetch ALL the volume info,
5757 * otherwise just the volume ID.
5758 * a_resultPP : Ptr to the address of the area containing
5759 * the returned volume info.
5760 * a_numEntsInResultP : Ptr for the value we set for the number of
5765 * Otherise, the return value of AFSVolXListVolumes.
5768 * This routine is closely related to UV_ListVolumes, which returns
5769 * only the standard level of detail on AFS volumes. It is a
5770 * heavyweight operation, zipping through all the volume entries for
5771 * a given server/partition.
5775 *------------------------------------------------------------------------*/
5778 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5779 struct volintXInfo **a_resultPP,
5780 afs_int32 * a_numEntsInResultP)
5782 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5783 afs_int32 code; /*Error code to return */
5784 volXEntries volumeXInfo; /*Area for returned extended vol info */
5787 * Set up our error code and the area for returned extended volume info.
5788 * We set the val field to a null pointer as a hint for the stub to
5791 *a_numEntsInResultP = 0;
5792 *a_resultPP = (volintXInfo *) 0;
5793 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5794 volumeXInfo.volXEntries_len = 0;
5797 * Bind to the Volume Server port on the File Server machine in question,
5800 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5801 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5803 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5806 * We got the info; pull out the pointer to where the results lie
5807 * and how many entries are there.
5809 *a_resultPP = volumeXInfo.volXEntries_val;
5810 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5814 * If we got an Rx connection, throw it away.
5817 rx_DestroyConnection(rxConnP);
5819 PrintError("", code);
5821 } /*UV_XListVolumes */
5823 /* get all the information about volume <volid> on <aserver> and <apart> */
5825 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5826 struct volintInfo **resultPtr)
5828 struct rx_connection *aconn;
5830 volEntries volumeInfo;
5832 *resultPtr = (volintInfo *) 0;
5833 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5834 volumeInfo.volEntries_len = 0;
5836 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5837 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5840 "Could not fetch the information about volume %lu from the server\n",
5841 (unsigned long)volid);
5843 *resultPtr = volumeInfo.volEntries_val;
5848 rx_DestroyConnection(aconn);
5849 PrintError("", code);
5853 /*------------------------------------------------------------------------
5854 * EXPORTED UV_XListOneVolume
5857 * List the extended information for a volume on a particular File
5858 * Server and partition.
5861 * a_serverID : Address of the File Server for which we want
5862 * extended volume info.
5863 * a_partID : Partition for which we want the extended
5865 * a_volID : Volume ID for which we want the info.
5866 * a_resultPP : Ptr to the address of the area containing
5867 * the returned volume info.
5871 * Otherise, the return value of AFSVolXListOneVolume.
5874 * This routine is closely related to UV_ListOneVolume, which returns
5875 * only the standard level of detail on the chosen AFS volume.
5879 *------------------------------------------------------------------------*/
5882 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5883 struct volintXInfo **a_resultPP)
5885 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5886 afs_int32 code; /*Error code */
5887 volXEntries volumeXInfo; /*Area for returned info */
5890 * Set up our error code, and the area we're in which we are returning
5891 * the info. Setting the val field to a null pointer tells the stub
5892 * to allocate space for us.
5894 *a_resultPP = (volintXInfo *) 0;
5895 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5896 volumeXInfo.volXEntries_len = 0;
5899 * Bind to the Volume Server port on the File Server machine in question,
5902 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5903 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5906 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5909 * We got the info; pull out the pointer to where the results lie.
5911 *a_resultPP = volumeXInfo.volXEntries_val;
5914 * If we got an Rx connection, throw it away.
5917 rx_DestroyConnection(rxConnP);
5919 PrintError("", code);
5924 * Given a volume we read from a partition, check if it is
5925 * represented in the VLDB correctly.
5927 * The VLDB is looked up by the RW volume id (not its name).
5928 * The RW contains the true name of the volume (BK and RO set
5929 * the name in the VLDB only on creation of the VLDB entry).
5930 * We want rules strict enough that when we check all volumes
5931 * on one partition, it does not need to be done again. IE:
5932 * two volumes on different partitions won't constantly
5933 * change a VLDB entry away from what the other set.
5934 * For RW and BK volumes, we will always check the VLDB to see
5935 * if the two exist on the server/partition. May seem redundant,
5936 * but this is an easy check of the VLDB. IE: if the VLDB entry
5937 * says the BK exists but no BK volume is there, we will detect
5938 * this when we check the RW volume.
5939 * VLDB entries are locked only when a change needs to be done.
5940 * Output changed to look a lot like the "vos syncserv" otuput.
5943 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5944 afs_int32 * modentry, afs_uint32 * maxvolid,
5945 struct nvldbentry *aentry)
5949 afs_int32 code, error = 0;
5950 struct nvldbentry entry, storeEntry;
5952 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5962 ((volumeinfo->type ==
5963 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5966 /* Check to see if the VLDB is ok without locking it (pass 1).
5967 * If it will change, then lock the VLDB entry, read it again,
5968 * then make the changes to it (pass 2).
5971 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5973 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5974 (unsigned long)rwvolid);
5979 createentry = 0; /* Do we need to create a VLDB entry */
5980 addvolume = 0; /* Add this volume to the VLDB entry */
5981 modified = 0; /* The VLDB entry was modified */
5984 memcpy(&entry, aentry, sizeof(entry));
5986 /* Read the entry from VLDB by its RW volume id */
5987 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5989 if (code != VL_NOENT) {
5991 "Could not retrieve the VLDB entry for volume %lu \n",
5992 (unsigned long)rwvolid);
5996 memset(&entry, 0, sizeof(entry));
5997 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
6001 MapHostToNetwork(&entry);
6005 if (verbose && (pass == 1)) {
6006 fprintf(STDOUT, "_______________________________\n");
6007 fprintf(STDOUT, "\n-- status before -- \n");
6009 fprintf(STDOUT, "\n**does not exist**\n");
6011 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
6012 || (entry.flags & BACK_EXISTS))
6013 EnumerateEntry(&entry);
6015 fprintf(STDOUT, "\n");
6018 if (volumeinfo->type == RWVOL) { /* RW volume exists */
6024 /* Check existence of RW and BK volumes */
6025 code = CheckVldbRWBK(&entry, &mod);
6031 idx = Lp_GetRwIndex(&entry);
6032 if (idx == -1) { /* RW index not found in the VLDB entry */
6033 idx = entry.nServers; /* put it into next index */
6036 } else { /* RW index found in the VLDB entry. */
6037 /* Verify if this volume's location matches where the VLDB says it is */
6038 if (!Lp_Match(aserver, apart, &entry)) {
6039 if (entry.flags & RW_EXISTS) {
6040 /* The RW volume exists elsewhere - report this one a duplicate */
6042 MapPartIdIntoName(apart, pname);
6044 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
6045 (unsigned long)rwvolid,
6047 afs_inet_ntoa_r(aserver, hoststr) :
6048 hostutil_GetNameByINet(aserver), pname);
6049 MapPartIdIntoName(entry.serverPartition[idx],
6052 " VLDB reports RW volume %lu exists on %s %s\n",
6053 (unsigned long)rwvolid,
6055 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
6056 hostutil_GetNameByINet(entry.
6061 /* The RW volume does not exist - have VLDB point to this one */
6064 /* Check for orphaned BK volume on old partition */
6065 if (entry.flags & BACK_EXISTS) {
6067 MapPartIdIntoName(entry.serverPartition[idx],
6070 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
6071 entry.volumeId[BACKVOL],
6073 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
6074 hostutil_GetNameByINet(entry.
6077 MapPartIdIntoName(apart, pname);
6079 " VLDB reports its RW volume %lu exists on %s %s\n",
6080 (unsigned long)rwvolid,
6082 afs_inet_ntoa_r(aserver, hoststr) :
6083 hostutil_GetNameByINet(aserver),
6089 /* Volume location matches the VLDB location */
6090 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
6091 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
6094 (entry.name, volumeinfo->name,
6095 VOLSER_OLDMAXVOLNAME) != 0)) {
6103 entry.flags |= RW_EXISTS;
6104 entry.volumeId[RWVOL] = rwvolid;
6105 if (!entry.volumeId[BACKVOL])
6106 entry.volumeId[BACKVOL] = volumeinfo->backupID;
6107 if (!entry.volumeId[ROVOL])
6108 entry.volumeId[ROVOL] = volumeinfo->cloneID;
6110 entry.serverFlags[idx] = ITSRWVOL;
6111 entry.serverNumber[idx] = aserver;
6112 entry.serverPartition[idx] = apart;
6113 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
6117 /* One last check - to update BK if need to */
6118 code = CheckVldbRWBK(&entry, &mod);
6126 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
6132 /* Check existence of RW and BK volumes */
6133 code = CheckVldbRWBK(&entry, &mod);
6139 idx = Lp_GetRwIndex(&entry);
6140 if (idx == -1) { /* RW index not found in the VLDB entry */
6141 idx = entry.nServers; /* Put it into next index */
6144 } else { /* RW index found in the VLDB entry */
6145 /* Verify if this volume's location matches where the VLDB says it is */
6146 if (!Lp_Match(aserver, apart, &entry)) {
6147 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
6149 MapPartIdIntoName(apart, pname);
6151 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
6152 (unsigned long)volumeinfo->volid,
6154 afs_inet_ntoa_r(aserver, hoststr) :
6155 hostutil_GetNameByINet(aserver), pname);
6156 MapPartIdIntoName(entry.serverPartition[idx], pname);
6158 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
6159 (unsigned long)rwvolid,
6161 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
6162 hostutil_GetNameByINet(entry.
6167 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
6168 if (!(entry.flags & BACK_EXISTS)) {
6170 } else if (volumeinfo->volid >
6171 entry.volumeId[BACKVOL]) {
6175 MapPartIdIntoName(entry.serverPartition[idx],
6178 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
6179 entry.volumeId[BACKVOL],
6181 afs_inet_ntoa_r(aserver, hoststr) :
6182 hostutil_GetNameByINet(aserver),
6185 " VLDB reports its BK volume ID is %lu\n",
6186 (unsigned long)volumeinfo->volid);
6190 MapPartIdIntoName(entry.serverPartition[idx],
6193 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
6194 (unsigned long)volumeinfo->volid,
6196 afs_inet_ntoa_r(aserver, hoststr) :
6197 hostutil_GetNameByINet(aserver),
6200 " VLDB reports its BK volume ID is %u\n",
6201 entry.volumeId[BACKVOL]);
6204 } else if (!entry.volumeId[BACKVOL]) {
6211 entry.flags |= BACK_EXISTS;
6212 entry.volumeId[RWVOL] = rwvolid;
6213 entry.volumeId[BACKVOL] = volumeinfo->volid;
6215 entry.serverNumber[idx] = aserver;
6216 entry.serverPartition[idx] = apart;
6217 entry.serverFlags[idx] = ITSBACKVOL;
6223 else if (volumeinfo->type == ROVOL) { /* A RO volume */
6224 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
6225 /* This is a quick check to see if the RO entry exists in the
6226 * VLDB so we avoid the CheckVldbRO() call (which checks if each
6227 * RO volume listed in the VLDB exists).
6229 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6231 idx = entry.nServers;
6235 if (!(entry.flags & RO_EXISTS)) {
6240 /* Before we correct the VLDB entry, make sure all the
6241 * ROs listed in the VLDB exist.
6243 code = CheckVldbRO(&entry, &mod);
6249 if (!(entry.flags & RO_EXISTS)) {
6250 /* No RO exists in the VLDB entry - add this one */
6251 idx = entry.nServers;
6254 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
6255 /* The volume headers's RO ID does not match that in the VLDB entry,
6256 * and the vol hdr's ID is greater (implies more recent). So delete
6257 * all the RO volumes listed in VLDB entry and add this volume.
6259 for (j = 0; j < entry.nServers; j++) {
6260 if (entry.serverFlags[j] & ITSROVOL) {
6261 /* Verify this volume exists and print message we are orphaning it */
6263 MapPartIdIntoName(apart, pname);
6265 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
6266 entry.volumeId[ROVOL],
6268 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
6269 hostutil_GetNameByINet(entry.
6273 " VLDB reports its RO volume ID is %lu\n",
6274 (unsigned long)volumeinfo->volid);
6277 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6278 entry.serverPartition[idx], 0L, 0L);
6285 idx = entry.nServers;
6288 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6289 /* The volume headers's RO ID does not match that in the VLDB entry,
6290 * and the vol hdr's ID is lower (implies its older). So orphan it.
6293 MapPartIdIntoName(apart, pname);
6295 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6296 (unsigned long)volumeinfo->volid,
6298 afs_inet_ntoa_r(aserver, hoststr) :
6299 hostutil_GetNameByINet(aserver), pname);
6301 " VLDB reports its RO volume ID is %u\n",
6302 entry.volumeId[ROVOL]);
6305 /* The RO volume ID in the volume header match that in the VLDB entry,
6306 * and there exist RO volumes in the VLDB entry. See if any of them
6307 * are this one. If not, then we add it.
6309 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6311 idx = entry.nServers;
6319 entry.flags |= RO_EXISTS;
6320 entry.volumeId[RWVOL] = rwvolid;
6321 entry.volumeId[ROVOL] = volumeinfo->volid;
6323 entry.serverNumber[idx] = aserver;
6324 entry.serverPartition[idx] = apart;
6325 entry.serverFlags[idx] = ITSROVOL;
6331 /* Remember largest volume id */
6332 if (entry.volumeId[ROVOL] > *maxvolid)
6333 *maxvolid = entry.volumeId[ROVOL];
6334 if (entry.volumeId[BACKVOL] > *maxvolid)
6335 *maxvolid = entry.volumeId[BACKVOL];
6336 if (entry.volumeId[RWVOL] > *maxvolid)
6337 *maxvolid = entry.volumeId[RWVOL];
6339 if (modified && doit) {
6340 MapNetworkToHost(&entry, &storeEntry);
6343 code = VLDB_CreateEntry(&storeEntry);
6346 "Could not create a VLDB entry for the volume %lu\n",
6347 (unsigned long)rwvolid);
6354 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6355 LOCKREL_OPCODE | LOCKREL_AFSID |
6358 fprintf(STDERR, "Could not update entry for %lu\n",
6359 (unsigned long)rwvolid);
6363 } else if (pass == 2) {
6365 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6366 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6368 PrintError("Could not unlock VLDB entry ", code);
6372 if (modified && modentry) {
6377 memcpy(aentry, &entry, sizeof(entry));
6381 fprintf(STDOUT, "-- status after --\n");
6383 EnumerateEntry(&entry);
6385 fprintf(STDOUT, "\n**no change**\n");
6389 VPRINT("\n_______________________________\n");
6394 sortVolumes(const void *a, const void *b)
6396 volintInfo *v1 = (volintInfo *) a;
6397 volintInfo *v2 = (volintInfo *) b;
6398 afs_uint32 rwvolid1, rwvolid2;
6400 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6401 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6403 if (rwvolid1 > rwvolid2)
6404 return -1; /* lower RW id goes first */
6405 if (rwvolid1 < rwvolid2)
6408 if (v1->type == RWVOL)
6409 return -1; /* RW vols go first */
6410 if (v2->type == RWVOL)
6413 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6414 return -1; /* BK vols next */
6415 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6418 if (v1->volid < v2->volid)
6419 return 1; /* larger volids first */
6420 if (v1->volid > v2->volid)
6426 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6427 * Synchronize an individual volume against a sever and partition.
6428 * Checks the VLDB entry (similar to syncserv) as well as checks
6429 * if the volume exists on specified servers (similar to syncvldb).
6432 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6434 struct rx_connection *aconn = 0;
6435 afs_int32 j, k, code, vcode, error = 0;
6437 afs_int32 mod, modified = 0, deleted = 0;
6438 struct nvldbentry vldbentry;
6439 afs_uint32 volumeid = 0;
6440 volEntries volumeInfo;
6441 struct partList PartList;
6443 afs_uint32 maxvolid = 0;
6445 volumeInfo.volEntries_val = (volintInfo *) 0;
6446 volumeInfo.volEntries_len = 0;
6448 /* Turn verbose logging off and do our own verbose logging */
6449 /* tverbose must be set before we call ERROR_EXIT() */
6456 if (!aserver && (flags & 1)) {
6457 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6461 /* Read the VLDB entry */
6462 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6463 if (vcode && (vcode != VL_NOENT)) {
6464 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6467 } else if (!vcode) {
6468 MapHostToNetwork(&vldbentry);
6472 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6473 fprintf(STDOUT, "_______________________________\n");
6474 fprintf(STDOUT, "\n-- status before -- \n");
6476 fprintf(STDOUT, "\n**does not exist**\n");
6478 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
6479 || (vldbentry.flags & BACK_EXISTS))
6480 EnumerateEntry(&vldbentry);
6482 fprintf(STDOUT, "\n");
6485 /* Verify that all of the VLDB entries exist on the repective servers
6486 * and partitions (this does not require that avolname be a volume ID).
6487 * Equivalent to a syncserv.
6490 /* Tell CheckVldb not to update if appropriate */
6495 code = CheckVldb(&vldbentry, &mod, &deleted);
6497 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6505 /* If aserver is given, we will search for the desired volume on it */
6507 /* Generate array of partitions on the server that we will check */
6509 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6512 "Could not fetch the list of partitions from the server\n");
6516 PartList.partId[0] = apart;
6520 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6522 /* If a volume ID were given, search for it on each partition */
6523 if ((volumeid = atol(avolname))) {
6524 for (j = 0; j < pcnt; j++) {
6526 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6529 if (code != ENODEV) {
6530 fprintf(STDERR, "Could not query server\n");
6538 /* Found one, sync it with VLDB entry */
6540 CheckVolume(volumeInfo.volEntries_val, aserver,
6541 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6548 if (volumeInfo.volEntries_val)
6549 free(volumeInfo.volEntries_val);
6550 volumeInfo.volEntries_val = (volintInfo *) 0;
6551 volumeInfo.volEntries_len = 0;
6555 /* Check to see if the RW, BK, and RO IDs exist on any
6556 * partitions. We get the volume IDs from the VLDB.
6558 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6559 if (vldbentry.volumeId[j] == 0)
6562 for (k = 0; k < pcnt; k++) { /* For each partition */
6563 volumeInfo.volEntries_val = (volintInfo *) 0;
6564 volumeInfo.volEntries_len = 0;
6566 AFSVolListOneVolume(aconn, PartList.partId[k],
6567 vldbentry.volumeId[j], &volumeInfo);
6569 if (code != ENODEV) {
6570 fprintf(STDERR, "Could not query server\n");
6578 /* Found one, sync it with VLDB entry */
6580 CheckVolume(volumeInfo.volEntries_val, aserver,
6581 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6588 if (volumeInfo.volEntries_val)
6589 free(volumeInfo.volEntries_val);
6590 volumeInfo.volEntries_val = (volintInfo *) 0;
6591 volumeInfo.volEntries_len = 0;
6597 /* If verbose output, print a summary of what changed */
6599 fprintf(STDOUT, "-- status after --\n");
6601 fprintf(STDOUT, "\n**entry deleted**\n");
6602 } else if (modified) {
6603 EnumerateEntry(&vldbentry);
6605 fprintf(STDOUT, "\n**no change**\n");
6607 fprintf(STDOUT, "\n_______________________________\n");
6611 /* Now check if the maxvolid is larger than that stored in the VLDB */
6613 afs_uint32 maxvldbid = 0;
6614 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6617 "Could not get the highest allocated volume id from the VLDB\n");
6620 } else if (maxvolid > maxvldbid) {
6622 id = maxvolid - maxvldbid + 1;
6623 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6626 "Error in increasing highest allocated volume id in VLDB\n");
6636 fprintf(STDOUT, "...error encountered");
6638 fprintf(STDOUT, "...done entry\n");
6641 rx_DestroyConnection(aconn);
6642 if (volumeInfo.volEntries_val)
6643 free(volumeInfo.volEntries_val);
6645 PrintError("", error);
6650 * Synchronise vldb with the file server <aserver> and,
6651 * optionally, <apart>.
6654 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6656 struct rx_connection *aconn;
6657 afs_int32 code, error = 0;
6660 volEntries volumeInfo;
6661 struct partList PartList;
6665 afs_int32 failures = 0, modifications = 0, tentries = 0;
6667 afs_uint32 maxvolid = 0;
6670 volumeInfo.volEntries_val = (volintInfo *) 0;
6671 volumeInfo.volEntries_len = 0;
6673 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6675 /* Generate array of partitions to check */
6677 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6680 "Could not fetch the list of partitions from the server\n");
6684 PartList.partId[0] = apart;
6688 VPRINT("Processing volume entries ...\n");
6690 /* Step through the array of partitions */
6691 for (i = 0; i < pcnt; i++) {
6692 apart = PartList.partId[i];
6693 MapPartIdIntoName(apart, pname);
6695 volumeInfo.volEntries_val = (volintInfo *) 0;
6696 volumeInfo.volEntries_len = 0;
6697 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6700 "Could not fetch the list of volumes from the server\n");
6704 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6705 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6706 sizeof(volintInfo), sortVolumes);
6709 for (vi = volumeInfo.volEntries_val, j = 0;
6710 j < volumeInfo.volEntries_len; j++, vi++) {
6718 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6719 j + 1, vi->name, (unsigned long)vi->volid,
6721 afs_inet_ntoa_r(aserver, hoststr) :
6722 hostutil_GetNameByINet(aserver), pname);
6730 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6732 PrintError("", code);
6735 } else if (modified) {
6741 fprintf(STDOUT, "...error encountered\n\n");
6743 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6750 "Could not process entries on server %s partition %s\n",
6752 afs_inet_ntoa_r(aserver, hoststr) :
6753 hostutil_GetNameByINet(aserver), pname);
6755 if (volumeInfo.volEntries_val) {
6756 free(volumeInfo.volEntries_val);
6757 volumeInfo.volEntries_val = 0;
6760 } /* thru all partitions */
6763 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6764 tentries, failures, modifications);
6766 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6767 tentries, failures, modifications);
6771 /* Now check if the maxvolid is larger than that stored in the VLDB */
6773 afs_uint32 maxvldbid = 0;
6774 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6777 "Could not get the highest allocated volume id from the VLDB\n");
6780 } else if (maxvolid > maxvldbid) {
6782 id = maxvolid - maxvldbid + 1;
6783 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6786 "Error in increasing highest allocated volume id in VLDB\n");
6794 rx_DestroyConnection(aconn);
6795 if (volumeInfo.volEntries_val)
6796 free(volumeInfo.volEntries_val);
6797 PrintError("", error);
6802 * Determine if a volume exists on a server and partition.
6803 * Try creating a transaction on the volume. If we can,
6804 * the volume exists, if not, then return the error code.
6805 * Some error codes mean the volume is unavailable but
6806 * still exists - so we catch these error codes.
6809 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6811 struct rx_connection *conn = (struct rx_connection *)0;
6812 afs_int32 code = -1;
6813 volEntries volumeInfo;
6815 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6817 volumeInfo.volEntries_val = (volintInfo *) 0;
6818 volumeInfo.volEntries_len = 0;
6819 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6820 if (volumeInfo.volEntries_val)
6821 free(volumeInfo.volEntries_val);
6822 if (code == VOLSERILLEGAL_PARTITION)
6824 rx_DestroyConnection(conn);
6833 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6837 afs_int32 code, error = 0;
6843 idx = Lp_GetRwIndex(entry);
6845 /* Check to see if the RW volume exists and set the RW_EXISTS
6848 if (idx == -1) { /* Did not find a RW entry */
6849 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6850 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6855 VolumeExists(entry->serverNumber[idx],
6856 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6857 if (code == 0) { /* RW volume exists */
6858 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6859 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6862 } else if (code == ENODEV) { /* RW volume does not exist */
6863 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6864 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6868 /* If VLDB says it didn't exist, then ignore error */
6869 if (entry->flags & RW_EXISTS) {
6870 MapPartIdIntoName(entry->serverPartition[idx], pname);
6872 "Transaction call failed for RW volume %u on server %s %s\n",
6873 entry->volumeId[RWVOL],
6875 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6876 hostutil_GetNameByINet(entry->serverNumber[idx]),
6883 /* Check to see if the BK volume exists and set the BACK_EXISTS
6884 * flag accordingly. idx already ponts to the RW entry.
6886 if (idx == -1) { /* Did not find a RW entry */
6887 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6888 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6891 } else { /* Found a RW entry */
6893 VolumeExists(entry->serverNumber[idx],
6894 entry->serverPartition[idx],
6895 entry->volumeId[BACKVOL]);
6896 if (code == 0) { /* BK volume exists */
6897 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6898 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6901 } else if (code == ENODEV) { /* BK volume does not exist */
6902 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6903 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6907 /* If VLDB says it didn't exist, then ignore error */
6908 if (entry->flags & BACK_EXISTS) {
6909 MapPartIdIntoName(entry->serverPartition[idx], pname);
6911 "Transaction call failed for BK volume %u on server %s %s\n",
6912 entry->volumeId[BACKVOL],
6914 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6915 hostutil_GetNameByINet(entry->serverNumber[idx]),
6922 /* If there is an idx but the BK and RW volumes no
6923 * longer exist, then remove the RW entry.
6925 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6926 && !(entry->flags & BACK_EXISTS)) {
6927 Lp_SetRWValue(entry, entry->serverNumber[idx],
6928 entry->serverPartition[idx], 0L, 0L);
6935 *modified = modentry;
6940 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6943 int foundro = 0, modentry = 0;
6944 afs_int32 code, error = 0;
6951 /* Check to see if the RO volumes exist and set the RO_EXISTS
6954 for (idx = 0; idx < entry->nServers; idx++) {
6955 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6956 continue; /* not a RO */
6960 VolumeExists(entry->serverNumber[idx],
6961 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6962 if (code == 0) { /* RO volume exists */
6964 } else if (code == ENODEV) { /* RW volume does not exist */
6965 Lp_SetROValue(entry, entry->serverNumber[idx],
6966 entry->serverPartition[idx], 0L, 0L);
6971 MapPartIdIntoName(entry->serverPartition[idx], pname);
6973 "Transaction call failed for RO %u on server %s %s\n",
6974 entry->volumeId[ROVOL],
6976 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6977 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6982 if (foundro) { /* A RO volume exists */
6983 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6984 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6987 } else { /* A RO volume does not exist */
6988 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6989 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6996 *modified = modentry;
7001 * Ensure that <entry> matches with the info on file servers
7004 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
7006 afs_int32 code, error = 0;
7007 struct nvldbentry storeEntry;
7008 int islocked = 0, mod, modentry, delentry = 0;
7009 int pass = 0, doit=1;
7017 fprintf(STDOUT, "_______________________________\n");
7018 fprintf(STDOUT, "\n-- status before -- \n");
7019 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
7020 || (entry->flags & BACK_EXISTS))
7021 EnumerateEntry(entry);
7022 fprintf(STDOUT, "\n");
7025 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
7026 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
7027 entry->name, VOLSER_OLDMAXVOLNAME - 10);
7031 /* Check to see if the VLDB is ok without locking it (pass 1).
7032 * If it will change, then lock the VLDB entry, read it again,
7033 * then make the changes to it (pass 2).
7037 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
7040 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
7041 entry->volumeId[RWVOL]);
7046 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
7048 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
7052 MapHostToNetwork(entry);
7058 /* Check if the RW and BK entries are ok */
7059 code = CheckVldbRWBK(entry, &mod);
7062 if (mod && (pass == 1) && doit)
7067 /* Check if the RO volumes entries are ok */
7068 code = CheckVldbRO(entry, &mod);
7071 if (mod && (pass == 1) && doit)
7076 /* The VLDB entry has been updated. If it as been modified, then
7077 * write the entry back out the the VLDB.
7079 if (modentry && doit) {
7083 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
7084 && !(entry->flags & RO_EXISTS) && doit) {
7085 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
7087 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
7091 "Could not delete VLDB entry for volume %u \n",
7092 entry->volumeId[RWVOL]);
7097 /* Replace old entry with our new one */
7098 MapNetworkToHost(entry, &storeEntry);
7100 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
7101 (LOCKREL_OPCODE | LOCKREL_AFSID |
7102 LOCKREL_TIMESTAMP));
7104 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
7105 entry->volumeId[RWVOL]);
7112 if (modified && modentry) {
7115 if (deleted && delentry) {
7120 fprintf(STDOUT, "-- status after --\n");
7122 fprintf(STDOUT, "\n**entry deleted**\n");
7124 EnumerateEntry(entry);
7126 fprintf(STDOUT, "\n**no change**\n");
7130 VPRINT("\n_______________________________\n");
7134 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7136 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
7139 "Could not release lock on VLDB entry for volume %u\n",
7140 entry->volumeId[RWVOL]);
7149 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
7152 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
7154 struct rx_connection *aconn;
7155 afs_int32 code, error = 0;
7156 afs_int32 nentries, tentries = 0;
7157 struct VldbListByAttributes attributes;
7158 nbulkentries arrayEntries;
7159 afs_int32 failures = 0, modified, modifications = 0;
7160 struct nvldbentry *vlentry;
7161 afs_int32 si, nsi, j;
7166 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
7168 /* Set up attributes to search VLDB */
7169 attributes.server = ntohl(aserver);
7170 attributes.Mask = VLLIST_SERVER;
7172 attributes.partition = apart;
7173 attributes.Mask |= VLLIST_PARTITION;
7176 VPRINT("Processing VLDB entries ...\n");
7178 /* While we need to collect more VLDB entries */
7179 for (si = 0; si != -1; si = nsi) {
7180 memset(&arrayEntries, 0, sizeof(arrayEntries));
7182 /* Collect set of VLDB entries */
7184 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
7185 &arrayEntries, &nsi);
7186 if (code == RXGEN_OPCODE) {
7187 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
7191 fprintf(STDERR, "Could not access the VLDB for attributes\n");
7194 tentries += nentries;
7196 for (j = 0; j < nentries; j++) {
7197 vlentry = &arrayEntries.nbulkentries_val[j];
7198 MapHostToNetwork(vlentry);
7200 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
7202 /* Tell CheckVldb not to update if appropriate */
7207 code = CheckVldb(vlentry, &modified, NULL);
7209 PrintError("", code);
7211 "Could not process VLDB entry for volume %s\n",
7214 } else if (modified) {
7220 fprintf(STDOUT, "...error encountered\n\n");
7222 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
7227 if (arrayEntries.nbulkentries_val) {
7228 free(arrayEntries.nbulkentries_val);
7229 arrayEntries.nbulkentries_val = 0;
7234 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
7235 tentries, failures, modifications);
7237 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
7238 tentries, failures, modifications);
7243 rx_DestroyConnection(aconn);
7244 if (arrayEntries.nbulkentries_val)
7245 free(arrayEntries.nbulkentries_val);
7248 error = VOLSERFAILEDOP;
7252 /*rename volume <oldname> to <newname>, changing the names of the related
7253 *readonly and backup volumes. This operation is also idempotent.
7254 *salvager is capable of recovering from rename operation stopping halfway.
7255 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
7257 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
7259 struct nvldbentry storeEntry;
7260 afs_int32 vcode, code, rcode, error;
7262 char nameBuffer[256];
7264 struct rx_connection *aconn;
7269 aconn = (struct rx_connection *)0;
7273 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7276 " Could not lock the VLDB entry for the volume %u \n",
7277 entry->volumeId[RWVOL]);
7282 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7283 MapNetworkToHost(entry, &storeEntry);
7284 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7286 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7287 entry->volumeId[RWVOL]);
7291 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7292 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7293 * is concerned, oldname is lost */
7294 if (entry->flags & RW_EXISTS) {
7295 index = Lp_GetRwIndex(entry);
7296 if (index == -1) { /* there is a serious discrepancy */
7298 "There is a serious discrepancy in VLDB entry for volume %u\n",
7299 entry->volumeId[RWVOL]);
7300 fprintf(STDERR, "try building VLDB from scratch\n");
7301 error = VOLSERVLDB_ERROR;
7304 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7306 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7307 entry->serverPartition[index], ITOffline, &tid);
7308 if (code) { /*volume doesnot exist */
7310 "Could not start transaction on the rw volume %u\n",
7311 entry->volumeId[RWVOL]);
7314 } else { /*volume exists, process it */
7317 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7318 entry->volumeId[RWVOL],
7319 entry->volumeId[ROVOL],
7320 entry->volumeId[BACKVOL]);
7322 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7323 code = AFSVolEndTrans(aconn, tid, &rcode);
7327 "Could not end transaction on volume %s %u\n",
7328 entry->name, entry->volumeId[RWVOL]);
7333 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7334 entry->name, entry->volumeId[RWVOL]);
7340 rx_DestroyConnection(aconn);
7341 aconn = (struct rx_connection *)0;
7343 /*end rw volume processing */
7344 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
7345 index = Lp_GetRwIndex(entry);
7346 if (index == -1) { /* there is a serious discrepancy */
7348 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7349 entry->volumeId[BACKVOL]);
7350 fprintf(STDERR, "try building VLDB from scratch\n");
7351 error = VOLSERVLDB_ERROR;
7354 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7356 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7357 entry->serverPartition[index], ITOffline, &tid);
7358 if (code) { /*volume doesnot exist */
7360 "Could not start transaction on the backup volume %u\n",
7361 entry->volumeId[BACKVOL]);
7364 } else { /*volume exists, process it */
7365 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7367 "Volume name %s.backup exceeds the limit of %u characters\n",
7368 newname, VOLSER_OLDMAXVOLNAME);
7372 strcpy(nameBuffer, newname);
7373 strcat(nameBuffer, ".backup");
7376 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7377 entry->volumeId[RWVOL], 0, 0);
7379 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7380 code = AFSVolEndTrans(aconn, tid, &rcode);
7384 "Could not end transaction on the backup volume %u\n",
7385 entry->volumeId[BACKVOL]);
7391 "Could not set parameters on the backup volume %u\n",
7392 entry->volumeId[BACKVOL]);
7397 } /* end backup processing */
7399 rx_DestroyConnection(aconn);
7400 aconn = (struct rx_connection *)0;
7401 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
7402 for (i = 0; i < entry->nServers; i++) {
7403 if (entry->serverFlags[i] & ITSROVOL) {
7404 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7406 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7407 entry->serverPartition[i], ITOffline,
7409 if (code) { /*volume doesnot exist */
7411 "Could not start transaction on the ro volume %u\n",
7412 entry->volumeId[ROVOL]);
7415 } else { /*volume exists, process it */
7416 strcpy(nameBuffer, newname);
7417 strcat(nameBuffer, ".readonly");
7418 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7420 "Volume name %s exceeds the limit of %u characters\n",
7421 nameBuffer, VOLSER_OLDMAXVOLNAME);
7426 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7427 entry->volumeId[RWVOL], 0, 0);
7429 VPRINT2("Renamed RO volume %s on host %s\n",
7432 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7433 hostutil_GetNameByINet(entry->
7435 code = AFSVolEndTrans(aconn, tid, &rcode);
7439 "Could not end transaction on volume %u\n",
7440 entry->volumeId[ROVOL]);
7446 "Could not set parameters on the ro volume %u\n",
7447 entry->volumeId[ROVOL]);
7453 rx_DestroyConnection(aconn);
7454 aconn = (struct rx_connection *)0;
7461 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7463 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7466 "Could not unlock the VLDB entry for the volume %s %u\n",
7467 entry->name, entry->volumeId[RWVOL]);
7473 code = AFSVolEndTrans(aconn, tid, &rcode);
7477 fprintf(STDERR, "Failed to end transaction on a volume \n");
7483 rx_DestroyConnection(aconn);
7484 PrintError("", error);
7489 /*report on all the active transactions on volser */
7491 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7493 struct rx_connection *aconn;
7494 transDebugEntries transInfo;
7497 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7498 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7499 transInfo.transDebugEntries_len = 0;
7500 code = AFSVolMonitor(aconn, &transInfo);
7503 "Could not access status information about the server\n");
7504 PrintError("", code);
7505 if (transInfo.transDebugEntries_val)
7506 free(transInfo.transDebugEntries_val);
7508 rx_DestroyConnection(aconn);
7511 *rcount = transInfo.transDebugEntries_len;
7512 *rpntr = transInfo.transDebugEntries_val;
7514 rx_DestroyConnection(aconn);
7521 /*delete the volume without interacting with the vldb */
7523 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7526 struct rx_connection *aconn;
7528 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7529 error = DoVolDelete(aconn, volid, part,
7530 "the", 0, NULL, NULL);
7531 if (error == VNOVOL) {
7532 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7535 PrintError("", error);
7537 rx_DestroyConnection(aconn);
7542 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7543 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7545 struct rx_connection *conn = 0;
7547 afs_int32 code, error = 0, rcode;
7549 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7551 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7555 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7557 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7561 code = AFSVolSetFlags(conn, tid, setflag);
7563 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7568 #ifdef AFS_PTHREAD_ENV
7571 IOMGR_Sleep(sleeptime);
7578 code = AFSVolEndTrans(conn, tid, &rcode);
7579 if (code || rcode) {
7580 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7582 error = (code ? code : rcode);
7587 rx_DestroyConnection(conn);
7592 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7595 struct rx_connection *conn = 0;
7597 afs_int32 code, error = 0, rcode;
7599 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7601 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7605 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7607 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7611 code = AFSVolSetInfo(conn, tid, infop);
7613 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7620 code = AFSVolEndTrans(conn, tid, &rcode);
7621 if (code || rcode) {
7622 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7624 error = (code ? code : rcode);
7629 rx_DestroyConnection(conn);
7634 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7635 afs_int32 fromdate, struct volintSize *vol_size)
7637 struct rx_connection *aconn = (struct rx_connection *)0;
7638 afs_int32 tid = 0, rcode = 0;
7639 afs_int32 code, error = 0;
7642 /* get connections to the servers */
7643 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7645 VPRINT1("Starting transaction on volume %u...", afromvol);
7646 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7647 EGOTO1(error_exit, code,
7648 "Could not start transaction on the volume %u to be measured\n",
7652 VPRINT1("Getting size of volume on volume %u...", afromvol);
7653 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7654 EGOTO(error_exit, code, "Could not start the measurement process \n");
7659 VPRINT1("Ending transaction on volume %u...", afromvol);
7660 code = AFSVolEndTrans(aconn, tid, &rcode);
7661 if (code || rcode) {
7662 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7664 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7666 error = (code ? code : rcode);
7671 rx_DestroyConnection(aconn);
7673 PrintError("", error);
7677 /*maps the host addresses in <old > (present in network byte order) to
7678 that in< new> (present in host byte order )*/
7680 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7684 /*copy all the fields */
7685 strcpy(new->name, old->name);
7686 /* new->volumeType = old->volumeType;*/
7687 new->nServers = old->nServers;
7688 count = old->nServers;
7689 if (count < NMAXNSERVERS)
7691 for (i = 0; i < count; i++) {
7692 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7693 new->serverPartition[i] = old->serverPartition[i];
7694 new->serverFlags[i] = old->serverFlags[i];
7696 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7697 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7698 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7699 new->cloneId = old->cloneId;
7700 new->flags = old->flags;
7703 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7705 MapHostToNetwork(struct nvldbentry *entry)
7709 count = entry->nServers;
7710 if (count < NMAXNSERVERS)
7712 for (i = 0; i < count; i++) {
7713 entry->serverNumber[i] = htonl(entry->serverNumber[i]);