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 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1342 * <atopart>. The operation is almost idempotent. The following
1343 * flags are recognized:
1345 * RV_NOCLONE - don't use a copy clone
1349 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1350 afs_uint32 atoserver, afs_int32 atopart, int flags)
1352 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1353 * be changing during the move */
1354 struct rx_connection * volatile toconn;
1355 struct rx_connection * volatile fromconn;
1356 afs_int32 volatile fromtid;
1357 afs_int32 volatile totid;
1358 afs_int32 volatile clonetid;
1359 afs_uint32 volatile newVol;
1360 afs_uint32 volatile volid;
1361 afs_uint32 volatile backupId;
1362 int volatile islocked;
1367 char tmpName[VOLSER_MAXVOLNAME + 1];
1372 struct restoreCookie cookie;
1373 afs_int32 vcode, code;
1374 struct volser_status tstatus;
1375 struct destServer destination;
1377 struct nvldbentry entry, storeEntry;
1380 char in, lf; /* for test code */
1384 #ifdef ENABLE_BUGFIX_1165
1385 volEntries volumeInfo;
1386 struct volintInfo *infop = 0;
1390 fromconn = (struct rx_connection *)0;
1391 toconn = (struct rx_connection *)0;
1401 /* support control-c processing */
1404 (void)signal(SIGINT, sigint_handler);
1408 "\nThere are three tests points - verifies all code paths through recovery.\n");
1409 fprintf(STDOUT, "First test point - operation not started.\n");
1410 fprintf(STDOUT, "...test here (y, n)? ");
1412 fscanf(stdin, "%c", &in);
1413 fscanf(stdin, "%c", &lf); /* toss away */
1415 fprintf(STDOUT, "type control-c\n");
1417 fprintf(stdout, ".");
1422 /* or drop through */
1425 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1426 EGOTO1(mfail, vcode,
1427 "Could not fetch the entry for the volume %u from the VLDB \n",
1430 if (entry.volumeId[RWVOL] != afromvol) {
1431 fprintf(STDERR, "Only RW volume can be moved\n");
1435 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1436 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1439 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1440 EGOTO1(mfail, vcode,
1441 "Could not fetch the entry for the volume %u from the VLDB \n",
1444 backupId = entry.volumeId[BACKVOL];
1445 MapHostToNetwork(&entry);
1447 if (!Lp_Match(afromserver, afrompart, &entry)) {
1448 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1449 if (!Lp_Match(atoserver, atopart, &entry)) {
1450 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1451 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1452 (unsigned long)afromvol);
1453 fprintf(STDERR, "The current site is :");
1454 for (i = 0; i < entry.nServers; i++) {
1455 if (entry.serverFlags[i] == ITSRWVOL) {
1457 MapPartIdIntoName(entry.serverPartition[i], pname);
1458 fprintf(STDERR, " server %s partition %s \n",
1459 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1460 hostutil_GetNameByINet(entry.serverNumber[i]),
1465 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1466 (LOCKREL_OPCODE | LOCKREL_AFSID |
1467 LOCKREL_TIMESTAMP));
1468 EGOTO1(mfail, vcode,
1469 " Could not release lock on the VLDB entry for the volume %u \n",
1472 return VOLSERVOLMOVED;
1475 /* delete the volume afromvol on src_server */
1476 /* from-info does not exist but to-info does =>
1477 * we have already done the move, but the volume
1478 * may still be existing physically on from fileserver
1480 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1483 code = DoVolDelete(fromconn, afromvol, afrompart,
1484 "leftover", 0, NULL, NULL);
1485 if (code && code != VNOVOL) {
1490 code = DoVolDelete(fromconn, backupId, afrompart,
1491 "leftover backup", 0, NULL, NULL);
1492 if (code && code != VNOVOL) {
1502 /* From-info matches the vldb info about volid,
1503 * its ok start the move operation, the backup volume
1504 * on the old site is deleted in the process
1506 if (afrompart == atopart) {
1507 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1508 EGOTO2(mfail, error,
1509 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1510 afromserver, error);
1513 EGOTO1(mfail, VOLSERVOLMOVED,
1514 "Warning: Moving volume %u to its home partition ignored!\n",
1520 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1521 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1522 totid = 0; /* initialize to uncreated */
1525 * clone the read/write volume locally.
1528 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1529 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1531 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1535 if (!(flags & RV_NOCLONE)) {
1536 /* Get a clone id */
1537 VPRINT1("Allocating new volume id for clone of volume %u ...",
1540 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1542 EGOTO1(mfail, vcode,
1543 "Could not get an ID for the clone of volume %u from the VLDB\n",
1547 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1548 VPRINT1("Cloning source volume %u ...", afromvol);
1549 strcpy(vname, "move-clone-temp");
1551 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1553 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1558 /* lookup the name of the volume we just cloned */
1560 code = AFSVolGetName(fromconn, fromtid, &volName);
1561 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1564 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1566 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1571 "Failed to end the transaction on the source volume %u\n",
1576 * Create the destination volume
1579 if (!(flags & RV_NOCLONE)) {
1580 /* All of this is to get the fromDate */
1581 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1584 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1588 "Failed to start a transaction on the cloned volume%u\n",
1592 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1594 AFSVolSetFlags(fromconn, clonetid,
1595 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1596 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1600 /* remember time from which we've dumped the volume */
1601 VPRINT1("Getting status of cloned volume %u ...", newVol);
1602 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1604 "Failed to get the status of the cloned volume %u\n",
1608 fromDate = CLOCKADJ(tstatus.creationDate);
1610 /* With RV_NOCLONE, just do a full copy from the source */
1615 #ifdef ENABLE_BUGFIX_1165
1617 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1618 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1619 * don't use this information...
1621 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1622 volumeInfo.volEntries_len = 0;
1623 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1625 "Failed to get the volint Info of the cloned volume %u\n",
1628 infop = (volintInfo *) volumeInfo.volEntries_val;
1629 infop->maxquota = -1; /* Else it will replace the default quota */
1630 infop->creationDate = -1; /* Else it will use the source creation date */
1631 infop->updateDate = -1; /* Else it will use the source update date */
1634 /* create a volume on the target machine */
1636 code = DoVolDelete(toconn, volid, atopart,
1637 "pre-existing destination", 0, NULL, NULL);
1638 if (code && code != VNOVOL) {
1643 VPRINT1("Creating the destination volume %u ...", volid);
1647 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1651 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1655 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1659 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1661 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1663 "Failed to set the flags on the destination volume %u\n", volid);
1667 * Now dump the clone to the new volume
1670 destination.destHost = ntohl(atoserver);
1671 destination.destPort = AFSCONF_VOLUMEPORT;
1672 destination.destSSID = 1;
1674 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1675 cookie.type = RWVOL;
1676 cookie.parent = entry.volumeId[RWVOL];
1679 if (!(flags & RV_NOCLONE)) {
1680 /* Copy the clone to the new volume */
1681 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1684 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1686 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1689 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1690 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1695 "Failed to end the transaction on the cloned volume %u\n",
1701 * reattach to the main-line volume, and incrementally dump it.
1704 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1706 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1709 "Failed to create a transaction on the source volume %u\n",
1713 /* now do the incremental */
1715 ("Doing the%s dump from source to destination for volume %u ... ",
1716 (flags & RV_NOCLONE) ? "" : " incremental",
1719 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1722 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1723 (flags & RV_NOCLONE) ? "" : " incremental");
1726 /* now adjust the flags so that the new volume becomes official */
1727 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1728 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1730 "Failed to set the flags to make old source volume offline\n");
1733 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1734 code = AFSVolSetFlags(toconn, totid, 0);
1736 "Failed to set the flags to make new source volume online\n");
1739 #ifdef ENABLE_BUGFIX_1165
1740 VPRINT1("Setting volume status on destination volume %u ...", volid);
1741 code = AFSVolSetInfo(toconn, totid, infop);
1743 "Failed to set volume status on the destination volume %u\n",
1748 /* put new volume online */
1749 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1750 code = AFSVolEndTrans(toconn, totid, &rcode);
1755 "Failed to end the transaction on the volume %u on the new site\n",
1759 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1760 MapNetworkToHost(&entry, &storeEntry);
1761 storeEntry.flags &= ~BACK_EXISTS;
1765 "Second test point - operation in progress but not complete.\n");
1766 fprintf(STDOUT, "...test here (y, n)? ");
1768 fscanf(stdin, "%c", &in);
1769 fscanf(stdin, "%c", &lf); /* toss away */
1771 fprintf(STDOUT, "type control-c\n");
1773 fprintf(stdout, ".");
1778 /* or drop through */
1781 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1783 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1784 (LOCKREL_OPCODE | LOCKREL_AFSID |
1785 LOCKREL_TIMESTAMP));
1788 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1789 storeEntry.name, (unsigned long)afromvol);
1798 "Third test point - operation complete but no cleanup.\n");
1799 fprintf(STDOUT, "...test here (y, n)? ");
1801 fscanf(stdin, "%c", &in);
1802 fscanf(stdin, "%c", &lf); /* toss away */
1804 fprintf(STDOUT, "type control-c\n");
1806 fprintf(stdout, ".");
1811 /* or drop through */
1814 /* This is tricky. File server is very stupid, and if you mark the volume
1815 * as VTOutOfService, it may mark the *good* instance (if you're moving
1816 * between partitions on the same machine) as out of service. Since
1817 * we're cleaning this code up in DEcorum, we're just going to kludge around
1818 * it for now by removing this call. */
1819 /* already out of service, just zap it now */
1821 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1824 "Failed to set the flags to make the old source volume offline\n");
1828 if (atoserver != afromserver) {
1829 /* set forwarding pointer for moved volumes */
1830 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1831 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1833 "Failed to set the forwarding pointer for the volume %u\n",
1838 VPRINT1("Deleting old volume %u on source ...", afromvol);
1839 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1840 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1844 VPRINT1("Ending transaction on old volume %u on the source ...",
1846 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1851 "Failed to end the transaction on the old volume %u on the source\n",
1855 code = DoVolDelete(fromconn, backupId, afrompart,
1856 "source backup", 0, NULL, NULL);
1857 if (code && code != VNOVOL) {
1862 code = 0; /* no backup volume? that's okay */
1865 if (!(flags & RV_NOCLONE)) {
1866 code = DoVolDelete(fromconn, newVol, afrompart,
1867 "cloned", 0, NULL, NULL);
1869 if (code == VNOVOL) {
1870 EPRINT1(code, "Failed to start transaction on %u\n", newVol);
1881 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1882 fprintf(STDOUT, "...test here (y, n)? ");
1884 fscanf(stdin, "%c", &in);
1885 fscanf(stdin, "%c", &lf); /* toss away */
1887 fprintf(STDOUT, "type control-c\n");
1889 fprintf(stdout, ".");
1894 /* or drop through */
1897 /* normal cleanup code */
1899 if (entry.flags & RO_EXISTS)
1900 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1903 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1905 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1906 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1910 " Could not release the lock on the VLDB entry for the volume %lu \n",
1911 (unsigned long)afromvol);
1919 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1921 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1922 if (code || rcode) {
1925 "Could not end transaction on the source volume %lu\n",
1926 (unsigned long)afromvol);
1928 error = (code ? code : rcode);
1934 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1935 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1936 if (code || rcode) {
1939 "Could not end transaction on the source's clone volume %lu\n",
1940 (unsigned long)newVol);
1942 error = (code ? code : rcode);
1948 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1950 code = AFSVolEndTrans(toconn, totid, &rcode);
1954 "Could not end transaction on destination volume %lu\n",
1955 (unsigned long)afromvol);
1957 error = (code ? code : rcode);
1963 #ifdef ENABLE_BUGFIX_1165
1968 rx_DestroyConnection(fromconn);
1970 rx_DestroyConnection(toconn);
1971 PrintError("", error);
1974 /* come here only when the sky falls */
1979 "vos move: operation interrupted, cleanup in progress...\n");
1980 fprintf(STDOUT, "clear transaction contexts\n");
1984 /* unlock VLDB entry */
1986 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1987 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1988 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1994 VPRINT("Recovery: Ending transaction on clone volume ...");
1995 AFSVolEndTrans(fromconn, clonetid, &rcode);
1999 VPRINT("Recovery: Ending transaction on destination volume ...");
2000 AFSVolEndTrans(toconn, totid, &rcode);
2003 if (fromtid) { /* put it on-line */
2004 VPRINT("Recovery: Setting volume flags on source volume ...");
2005 AFSVolSetFlags(fromconn, fromtid, 0);
2008 VPRINT("Recovery: Ending transaction on source volume ...");
2009 AFSVolEndTrans(fromconn, fromtid, &rcode);
2013 VPRINT("Recovery: Accessing VLDB.\n");
2014 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2016 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2020 MapHostToNetwork(&entry);
2022 /* Delete either the volume on the source location or the target location.
2023 * If the vldb entry still points to the source location, then we know the
2024 * volume move didn't finish so we remove the volume from the target
2025 * location. Otherwise, we remove the volume from the source location.
2027 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2030 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2034 if (volid && toconn) {
2035 code = DoVolDelete(toconn, volid, atopart,
2036 "destination", 0, NULL, "Recovery:");
2037 if (code == VNOVOL) {
2038 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2042 /* put source volume on-line */
2044 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2048 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2054 VPRINT1("Recovery: Setting flags on source volume %u ...",
2056 AFSVolSetFlags(fromconn, fromtid, 0);
2060 ("Recovery: Ending transaction on source volume %u ...",
2062 AFSVolEndTrans(fromconn, fromtid, &rcode);
2066 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2070 } else { /* yep, move complete */
2073 "move complete - attempt cleanup of source partition - no guarantee\n");
2077 /* delete backup volume */
2079 code = DoVolDelete(fromconn, backupId, afrompart,
2080 "backup", 0, NULL, "Recovery:");
2081 if (code == VNOVOL) {
2082 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2085 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2086 (atoserver != afromserver)?atoserver:0,
2088 if (code == VNOVOL) {
2089 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2094 /* common cleanup - delete local clone */
2096 code = DoVolDelete(fromconn, newVol, afrompart,
2097 "clone", 0, NULL, "Recovery:");
2098 if (code == VNOVOL) {
2099 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2103 /* unlock VLDB entry */
2105 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2107 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2108 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2111 done: /* routine cleanup */
2114 #ifdef ENABLE_BUGFIX_1165
2119 rx_DestroyConnection(fromconn);
2121 rx_DestroyConnection(toconn);
2124 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2132 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2133 afs_uint32 atoserver, afs_int32 atopart)
2135 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2136 atoserver, atopart, 0);
2140 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2141 * <atopart>. The new volume is named by <atovolname>. The new volume
2142 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2143 * from the VLDB. the following flags are supported:
2145 * RV_RDONLY - target volume is RO
2146 * RV_OFFLINE - leave target volume offline
2147 * RV_CPINCR - do incremental dump if target exists
2148 * RV_NOVLDB - don't create/update VLDB entry
2149 * RV_NOCLONE - don't use a copy clone
2152 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2153 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2154 afs_uint32 atovolid, int flags)
2156 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2157 * be changing during the copy */
2159 afs_int32 volatile clonetid;
2160 afs_int32 volatile totid;
2161 afs_int32 volatile fromtid;
2162 struct rx_connection * volatile fromconn;
2163 struct rx_connection * volatile toconn;
2164 afs_uint32 volatile cloneVol;
2168 afs_int32 fromDate, cloneFromDate;
2169 struct restoreCookie cookie;
2170 afs_int32 vcode, code;
2173 struct volser_status tstatus;
2174 struct destServer destination;
2175 struct nvldbentry entry, newentry, storeEntry;
2180 fromconn = (struct rx_connection *)0;
2181 toconn = (struct rx_connection *)0;
2189 /* support control-c processing */
2192 (void)signal(SIGINT, sigint_handler);
2194 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2195 EGOTO1(mfail, vcode,
2196 "Could not fetch the entry for the volume %u from the VLDB \n",
2198 MapHostToNetwork(&entry);
2201 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2202 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2203 fromtid = totid = 0; /* initialize to uncreated */
2206 * clone the read/write volume locally.
2210 if (!(flags & RV_NOCLONE)) {
2211 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2213 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2216 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2220 /* Get a clone id */
2221 VPRINT1("Allocating new volume id for clone of volume %u ...",
2225 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2227 EGOTO1(mfail, vcode,
2228 "Could not get an ID for the clone of volume %u from the VLDB\n",
2236 /* Get a new volume id */
2237 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2239 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2240 EGOTO1(mfail, vcode,
2241 "Could not get an ID for the copy of volume %u from the VLDB\n",
2246 if (!(flags & RV_NOCLONE)) {
2247 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2248 VPRINT1("Cloning source volume %u ...", afromvol);
2249 strcpy(vname, "copy-clone-temp");
2252 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2255 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2259 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2261 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2266 "Failed to end the transaction on the source volume %u\n",
2272 * Create the destination volume
2275 if (!(flags & RV_NOCLONE)) {
2276 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2279 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2283 "Failed to start a transaction on the cloned volume%u\n",
2287 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2289 AFSVolSetFlags(fromconn, clonetid,
2290 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2291 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2295 /* remember time from which we've dumped the volume */
2296 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2297 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2299 "Failed to get the status of the cloned volume %u\n",
2303 fromDate = CLOCKADJ(tstatus.creationDate);
2308 /* create a volume on the target machine */
2311 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2314 if ((flags & RV_CPINCR)) {
2315 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2316 code = AFSVolGetStatus(toconn, totid, &tstatus);
2318 "Failed to get the status of the pre-existing volume %u\n",
2322 /* Using the update date should be OK here, but add some fudge */
2323 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2324 if ((flags & RV_NOCLONE))
2325 fromDate = cloneFromDate;
2327 /* XXX We should check that the source volume's creationDate is
2328 * XXX not newer than the existing target volume, and if not,
2329 * XXX throw away the existing target and do a full dump. */
2334 /* Delete the existing volume.
2335 * While we are deleting the volume in these steps, the transaction
2336 * we started against the cloned volume (clonetid above) will be
2337 * sitting idle. It will get cleaned up after 600 seconds
2339 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2340 code = AFSVolDeleteVolume(toconn, totid);
2342 "Could not delete the pre-existing volume %u on destination\n",
2347 ("Ending transaction on pre-existing volume %u on destination ...",
2349 code = AFSVolEndTrans(toconn, totid, &rcode);
2354 "Could not end the transaction on pre-existing volume %u on destination\n",
2359 VPRINT1("Creating the destination volume %u ...", newVol);
2362 AFSVolCreateVolume(toconn, atopart, atovolname,
2363 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2364 newVol, &newVol, &tmp);
2366 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2370 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2372 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2374 "Failed to set the flags on the destination volume %u\n", newVol);
2379 destination.destHost = ntohl(atoserver);
2380 destination.destPort = AFSCONF_VOLUMEPORT;
2381 destination.destSSID = 1;
2383 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2384 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2389 * Now dump the clone to the new volume
2392 if (!(flags & RV_NOCLONE)) {
2393 /* XXX probably should have some code here that checks to see if
2394 * XXX we are copying to same server and partition - if so, just
2395 * XXX use a clone to save disk space */
2397 /* Copy the clone to the new volume */
2398 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2401 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2403 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2407 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2408 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2413 "Failed to end the transaction on the cloned volume %u\n",
2419 * reattach to the main-line volume, and incrementally dump it.
2422 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2424 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2427 "Failed to create a transaction on the source volume %u\n",
2431 /* now do the incremental */
2433 ("Doing the%s dump from source to destination for volume %u ... ",
2434 (flags & RV_NOCLONE) ? "" : " incremental",
2437 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2440 "Failed to do the%s dump from old site to new site\n",
2441 (flags & RV_NOCLONE) ? "" : " incremental");
2444 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2445 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2446 code = AFSVolSetFlags(toconn, totid, volflag);
2448 "Failed to set the flags to make destination volume online\n");
2451 /* put new volume online */
2452 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2453 code = AFSVolEndTrans(toconn, totid, &rcode);
2458 "Failed to end the transaction on the destination volume %u\n",
2462 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2463 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2468 "Failed to end the transaction on the source volume %u\n",
2474 if (!(flags & RV_NOCLONE)) {
2475 code = DoVolDelete(fromconn, cloneVol, afrompart,
2476 "cloned", 0, NULL, NULL);
2478 if (code == VNOVOL) {
2479 EPRINT1(code, "Failed to start transaction on %u\n", cloneVol);
2486 if (!(flags & RV_NOVLDB)) {
2487 /* create the vldb entry for the copied volume */
2488 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2489 newentry.nServers = 1;
2490 newentry.serverNumber[0] = atoserver;
2491 newentry.serverPartition[0] = atopart;
2492 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2493 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2494 newentry.volumeId[RWVOL] = newVol;
2495 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2496 newentry.volumeId[BACKVOL] = 0;
2497 newentry.cloneId = 0;
2498 /*map into right byte order, before passing to xdr, the stuff has to be in host
2499 * byte order. Xdr converts it into network order */
2500 MapNetworkToHost(&newentry, &storeEntry);
2501 /* create the vldb entry */
2502 vcode = VLDB_CreateEntry(&storeEntry);
2505 "Could not create a VLDB entry for the volume %s %lu\n",
2506 atovolname, (unsigned long)newVol);
2507 /*destroy the created volume */
2508 VPRINT1("Deleting the newly created volume %u\n", newVol);
2509 AFSVolDeleteVolume(toconn, totid);
2513 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2517 /* normal cleanup code */
2520 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2522 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2523 if (code || rcode) {
2526 "Could not end transaction on the source volume %lu\n",
2527 (unsigned long)afromvol);
2529 error = (code ? code : rcode);
2535 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2537 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2538 if (code || rcode) {
2541 "Could not end transaction on the source's clone volume %lu\n",
2542 (unsigned long)cloneVol);
2544 error = (code ? code : rcode);
2550 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2552 code = AFSVolEndTrans(toconn, totid, &rcode);
2556 "Could not end transaction on destination volume %lu\n",
2557 (unsigned long)newVol);
2559 error = (code ? code : rcode);
2564 rx_DestroyConnection(fromconn);
2566 rx_DestroyConnection(toconn);
2567 PrintError("", error);
2570 /* come here only when the sky falls */
2575 "vos copy: operation interrupted, cleanup in progress...\n");
2576 fprintf(STDOUT, "clear transaction contexts\n");
2581 VPRINT("Recovery: Ending transaction on clone volume ...");
2582 AFSVolEndTrans(fromconn, clonetid, &rcode);
2586 VPRINT("Recovery: Ending transaction on destination volume ...");
2587 AFSVolEndTrans(toconn, totid, &rcode);
2590 if (fromtid) { /* put it on-line */
2591 VPRINT("Recovery: Ending transaction on source volume ...");
2592 AFSVolEndTrans(fromconn, fromtid, &rcode);
2596 VPRINT("Recovery: Accessing VLDB.\n");
2597 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2599 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2603 MapHostToNetwork(&entry);
2605 /* common cleanup - delete local clone */
2607 code = DoVolDelete(fromconn, cloneVol, afrompart,
2608 "clone", 0, NULL, "Recovery:");
2609 if (code == VNOVOL) {
2610 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", cloneVol);
2614 done: /* routine cleanup */
2616 rx_DestroyConnection(fromconn);
2618 rx_DestroyConnection(toconn);
2621 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2629 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2630 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2632 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2633 atovolname, atoserver, atopart, 0, 0);
2638 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2639 * if one already exists, update it
2643 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2645 struct rx_connection *aconn = (struct rx_connection *)0;
2646 afs_int32 ttid = 0, btid = 0;
2647 afs_uint32 backupID;
2648 afs_int32 code = 0, rcode = 0;
2649 struct nvldbentry entry, storeEntry;
2650 afs_int32 error = 0;
2651 int vldblocked = 0, vldbmod = 0;
2653 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2655 /* the calls to VLDB will succeed only if avolid is a RW volume,
2656 * since we are following the RW hash chain for searching */
2657 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2660 "Could not fetch the entry for the volume %lu from the VLDB \n",
2661 (unsigned long)avolid);
2665 MapHostToNetwork(&entry);
2667 /* These operations require the VLDB be locked since it means the VLDB
2668 * will change or the vldb is already locked.
2670 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2671 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2672 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2674 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2677 "Could not lock the VLDB entry for the volume %lu\n",
2678 (unsigned long)avolid);
2684 /* Reread the vldb entry */
2685 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2688 "Could not fetch the entry for the volume %lu from the VLDB \n",
2689 (unsigned long)avolid);
2693 MapHostToNetwork(&entry);
2696 if (!ISNAMEVALID(entry.name)) {
2697 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2699 error = VOLSERBADNAME;
2703 backupID = entry.volumeId[BACKVOL];
2704 if (backupID == INVALID_BID) {
2705 /* Get a backup volume id from the VLDB and update the vldb
2708 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2711 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2712 (unsigned long)avolid);
2716 entry.volumeId[BACKVOL] = backupID;
2720 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2721 entry.name, NULL, ".backup", NULL, NULL);
2727 /* Mark vldb as backup exists */
2728 if (!(entry.flags & BACK_EXISTS)) {
2729 entry.flags |= BACK_EXISTS;
2733 /* Now go back to the backup volume and bring it on line */
2734 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2737 "Failed to start a transaction on the backup volume %lu\n",
2738 (unsigned long)backupID);
2743 code = AFSVolSetFlags(aconn, btid, 0);
2745 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2746 (unsigned long)backupID);
2751 code = AFSVolEndTrans(aconn, btid, &rcode);
2753 if (code || rcode) {
2755 "Failed to end the transaction on the backup volume %lu\n",
2756 (unsigned long)backupID);
2757 error = (code ? code : rcode);
2763 /* Will update the vldb below */
2767 code = AFSVolEndTrans(aconn, ttid, &rcode);
2768 if (code || rcode) {
2769 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2770 (unsigned long)avolid);
2772 error = (code ? code : rcode);
2777 code = AFSVolEndTrans(aconn, btid, &rcode);
2778 if (code || rcode) {
2780 "Could not end transaction the backup volume %lu\n",
2781 (unsigned long)backupID);
2783 error = (code ? code : rcode);
2787 /* Now update the vldb - if modified */
2790 MapNetworkToHost(&entry, &storeEntry);
2792 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2793 (LOCKREL_OPCODE | LOCKREL_AFSID |
2794 LOCKREL_TIMESTAMP));
2797 "Could not update the VLDB entry for the volume %lu \n",
2798 (unsigned long)avolid);
2804 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2805 (LOCKREL_OPCODE | LOCKREL_AFSID |
2806 LOCKREL_TIMESTAMP));
2809 "Could not unlock the VLDB entry for the volume %lu \n",
2810 (unsigned long)avolid);
2818 rx_DestroyConnection(aconn);
2820 PrintError("", error);
2824 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2825 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2826 * The new volume is named by <aname>, or by appending ".clone" to
2827 * the existing name if <aname> is NULL. The following flags are
2830 * RV_RDONLY - target volume is RO
2831 * RV_OFFLINE - leave target volume offline
2835 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2836 afs_uint32 acloneid, char *aname, int flags)
2838 struct rx_connection *aconn = (struct rx_connection *)0;
2839 afs_int32 ttid = 0, btid = 0;
2840 afs_int32 code = 0, rcode = 0;
2841 char vname[VOLSER_MAXVOLNAME + 1];
2842 afs_int32 error = 0;
2843 volEntries volumeInfo;
2846 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2849 volumeInfo.volEntries_val = (volintInfo *) 0;
2850 volumeInfo.volEntries_len = 0;
2851 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2853 fprintf(stderr, "Could not get info for volume %lu\n",
2854 (unsigned long)avolid);
2858 strncpy(vname, volumeInfo.volEntries_val[0].name,
2859 VOLSER_OLDMAXVOLNAME - 7);
2860 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2861 strcat(vname, ".clone");
2863 if (volumeInfo.volEntries_val)
2864 free(volumeInfo.volEntries_val);
2868 /* Get a clone id */
2869 VPRINT1("Allocating new volume id for clone of volume %u ...",
2871 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2873 "Could not get an ID for the clone of volume %u from the VLDB\n",
2878 if (flags & RV_RWONLY)
2879 type = readwriteVolume;
2880 else if (flags & RV_RDONLY)
2881 type = readonlyVolume;
2883 type = backupVolume;
2885 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
2886 NULL, ".clone", NULL, NULL, NULL);
2892 /* Now go back to the backup volume and bring it on line */
2893 if (!(flags & RV_OFFLINE)) {
2894 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2897 "Failed to start a transaction on the clone volume %lu\n",
2898 (unsigned long)acloneid);
2903 code = AFSVolSetFlags(aconn, btid, 0);
2905 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2906 (unsigned long)acloneid);
2911 code = AFSVolEndTrans(aconn, btid, &rcode);
2913 if (code || rcode) {
2915 "Failed to end the transaction on the clone volume %lu\n",
2916 (unsigned long)acloneid);
2917 error = (code ? code : rcode);
2926 code = AFSVolEndTrans(aconn, ttid, &rcode);
2927 if (code || rcode) {
2928 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2929 (unsigned long)avolid);
2931 error = (code ? code : rcode);
2936 code = AFSVolEndTrans(aconn, btid, &rcode);
2937 if (code || rcode) {
2939 "Could not end transaction on the clone volume %lu\n",
2940 (unsigned long)acloneid);
2942 error = (code ? code : rcode);
2947 rx_DestroyConnection(aconn);
2949 PrintError("", error);
2953 #define ONERROR(ec, ep, es) do { \
2955 fprintf(STDERR, (es), (ep)); \
2960 #define ONERROR0(ec, es) do { \
2962 fprintf(STDERR, (es)); \
2967 #define ERROREXIT(ec) do { \
2972 /* Get a "transaction" on this replica. Create the volume
2973 * if necessary. Return the time from which a dump should
2974 * be made (0 if it's a new volume)
2977 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
2978 struct rx_connection **connPtr, afs_int32 * transPtr,
2979 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
2980 afs_int32 *origflags, afs_uint32 tmpVolId)
2983 struct volser_status tstatus;
2988 *connPtr = (struct rx_connection *)0;
2993 /* get connection to the replication site */
2994 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
2996 goto fail; /* server is down */
2998 volid = vldbEntryPtr->volumeId[ROVOL];
3002 AFSVolTransCreate_retry(*connPtr, volid,
3003 vldbEntryPtr->serverPartition[index], ITOffline,
3006 if (!code && (origflags[index] & RO_DONTUSE)) {
3007 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3008 * site. Don't trust any data on it, since it is possible we
3009 * have encountered some temporary volume from some other
3010 * incomplete volume operation. It is difficult to detect if
3011 * that has happened vs if this is a legit volume, so just
3012 * delete it to be safe. */
3014 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3015 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3016 serverNumber[index], hoststr) :
3017 hostutil_GetNameByINet(vldbEntryPtr->
3018 serverNumber[index]));
3020 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3022 PrintError("Failed to delete RO_DONTUSE site: ", code);
3026 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3032 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3039 /* emulate what TransCreate would have returned, so we try to
3040 * create the volume below */
3045 /* If the volume does not exist, create it */
3046 if (!volid || code) {
3047 char volname[VL_MAXNAMELEN];
3050 if (volid && (code != VNOVOL)) {
3051 PrintError("Failed to start a transaction on the RO volume.\n",
3056 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3058 if (strlcat(volname,
3059 tmpVolId?".roclone":".readonly",
3060 sizeof(volname)) >= sizeof(volname)) {
3062 PrintError("Volume name is too long\n", code);
3067 strcat(volname, ".roclone");
3069 strcat(volname, ".readonly");
3073 "Creating new volume %lu on replication site %s: ",
3074 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3075 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3076 serverNumber[index], hoststr) :
3077 hostutil_GetNameByINet(vldbEntryPtr->
3078 serverNumber[index]));
3083 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3085 vldbEntryPtr->volumeId[RWVOL],
3086 tmpVolId?&tmpVolId:&volid,
3089 PrintError("Failed to create the ro volume: ", code);
3092 vldbEntryPtr->volumeId[ROVOL] = volid;
3096 /* The following is a bit redundant, since create sets these flags by default */
3098 AFSVolSetFlags(*connPtr, *transPtr,
3099 VTDeleteOnSalvage | VTOutOfService);
3101 PrintError("Failed to set flags on the ro volume: ", code);
3106 /* Otherwise, the transaction did succeed, so get the creation date of the
3107 * latest RO volume on the replication site
3110 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3111 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3112 serverNumber[index], hoststr) :
3113 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3115 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3117 PrintError("Failed to get status of volume on destination: ",
3122 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3127 code = DoVolClone(*connPtr, volid,
3128 vldbEntryPtr->serverPartition[index],
3129 readonlyVolume, tmpVolId, "temporary",
3130 vldbEntryPtr->name, NULL, ".roclone", NULL,
3135 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3136 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3143 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3147 if (tcode && tcode != ENOENT)
3148 PrintError("Could not end transaction on a ro volume: ", tcode);
3155 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3156 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3157 void *cookie, manyResults * results)
3161 for (i = 0; i < tr->manyDests_len; i++) {
3162 results->manyResults_val[i] =
3163 AFSVolForward(fromconn, fromtid, fromdate,
3164 &(tr->manyDests_val[i].server),
3165 tr->manyDests_val[i].trans, cookie);
3171 * Check if a trans has timed out, and recreate it if necessary.
3173 * @param[in] aconn RX connection to the relevant server
3174 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3175 * contains the new trans ID on success
3176 * @param[in] apart Partition for the transaction
3177 * @param[in] astat The status of the original transaction
3179 * @return operation status
3180 * @retval 0 existing transaction is still valid, or we managed to recreate
3181 * the trans successfully
3182 * @retval nonzero Fatal error; bail out
3185 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3186 struct volser_status *astat)
3188 struct volser_status new_status;
3191 memset(&new_status, 0, sizeof(new_status));
3192 code = AFSVolGetStatus(aconn, *atid, &new_status);
3194 if (code == ENOENT) {
3196 VPRINT1("Old transaction on cloned volume %lu timed out, "
3197 "restarting transaction\n", (long unsigned) astat->volID);
3198 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3201 PrintError("Failed to recreate cloned RO volume transaction\n",
3206 memset(&new_status, 0, sizeof(new_status));
3207 code = AFSVolGetStatus(aconn, *atid, &new_status);
3209 PrintError("Failed to get status on recreated transaction\n",
3214 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3215 PrintError("Recreated transaction on cloned RO volume, but "
3216 "the volume has changed!\n", 0);
3220 PrintError("Unable to get status of current cloned RO transaction\n",
3225 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3227 PrintError("Internal error: current GetStatus does not match "
3228 "original GetStatus?\n", 0);
3237 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3238 struct rx_connection **toconns, struct release *times,
3241 afs_int32 s, code = 0, rcode = 0;
3242 /* End the transactions and destroy the connections */
3243 for (s = 0; s < volcount; s++) {
3244 if (replicas[s].trans) {
3245 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3247 replicas[s].trans = 0;
3251 if ((s == 0) || (code != ENOENT)) {
3252 PrintError("Could not end transaction on a ro volume: ",
3256 ("Transaction timed out on a ro volume. Will retry.\n",
3258 if (times[s].vldbEntryIndex < *vldbindex)
3259 *vldbindex = times[s].vldbEntryIndex;
3264 rx_DestroyConnection(toconns[s]);
3270 DoVolOnline(struct nvldbentry *vldbEntryPtr, afs_uint32 avolid, int index,
3271 char *vname, struct rx_connection *connPtr)
3273 afs_int32 code = 0, rcode = 0, onlinetid = 0;
3276 AFSVolTransCreate_retry(connPtr, avolid,
3277 vldbEntryPtr->serverPartition[index],
3281 EPRINT(code, "Could not create transaction on readonly...\n");
3284 code = AFSVolSetFlags(connPtr, onlinetid, 0);
3286 EPRINT(code, "Could not set flags on readonly...\n");
3291 AFSVolSetIdsTypes(connPtr, onlinetid, vname,
3292 ROVOL, vldbEntryPtr->volumeId[RWVOL],
3295 EPRINT(code, "Could not set ids on readonly...\n");
3298 code = AFSVolEndTrans(connPtr, onlinetid, &rcode);
3304 /* UV_ReleaseVolume()
3305 * Release volume <afromvol> on <afromserver> <afrompart> to all
3306 * its RO sites (full release). Unless the previous release was
3307 * incomplete: in which case we bring the remaining incomplete
3308 * volumes up to date with the volumes that were released
3310 * forceflag: Performs a full release.
3312 * Will create a clone from the RW, then dump the clone out to
3313 * the remaining replicas. If there is more than 1 RO sites,
3314 * ensure that the VLDB says at least one RO is available all
3315 * the time: Influences when we write back the VLDB entry.
3319 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3320 afs_int32 afrompart, int forceflag, int stayUp)
3324 afs_int32 vcode, rcode, tcode;
3325 afs_uint32 cloneVolId = 0, roVolId;
3326 struct replica *replicas = 0;
3327 struct nvldbentry entry, storeEntry;
3328 int i, volcount = 0, m, fullrelease, vldbindex;
3330 struct restoreCookie cookie;
3331 struct rx_connection **toconns = 0;
3332 struct release *times = 0;
3334 struct rx_connection *fromconn = (struct rx_connection *)0;
3335 afs_int32 error = 0;
3337 afs_int32 clonetid = 0, onlinetid;
3338 afs_int32 fromtid = 0;
3339 afs_uint32 fromdate = 0;
3340 afs_uint32 thisdate;
3344 manyResults results;
3345 int rwindex, roindex, roclone, roexists;
3346 afs_uint32 rwcrdate = 0, rwupdate = 0;
3347 afs_uint32 clcrdate;
3351 } remembertime[NMAXNSERVERS];
3352 int releasecount = 0;
3353 struct volser_status volstatus;
3355 afs_int32 origflags[NMAXNSERVERS];
3356 struct volser_status orig_status;
3357 int notreleased = 0;
3358 int tried_justnewsites = 0;
3359 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3361 memset(remembertime, 0, sizeof(remembertime));
3362 memset(&results, 0, sizeof(results));
3363 memset(origflags, 0, sizeof(origflags));
3365 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3366 if (vcode != VL_RERELEASE)
3367 ONERROR(vcode, afromvol,
3368 "Could not lock the VLDB entry for the volume %u.\n");
3371 /* Get the vldb entry in readable format */
3372 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3373 ONERROR(vcode, afromvol,
3374 "Could not fetch the entry for the volume %u from the VLDB.\n");
3375 MapHostToNetwork(&entry);
3378 EnumerateEntry(&entry);
3380 if (!ISNAMEVALID(entry.name))
3381 ONERROR(VOLSERBADOP, entry.name,
3382 "Volume name %s is too long, rename before releasing.\n");
3383 if (entry.volumeId[RWVOL] != afromvol)
3384 ONERROR(VOLSERBADOP, afromvol,
3385 "The volume %u being released is not a read-write volume.\n");
3386 if (entry.nServers <= 1)
3387 ONERROR(VOLSERBADOP, afromvol,
3388 "Volume %u has no replicas - release operation is meaningless!\n");
3389 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3390 ONERROR(VOLSERBADOP, entry.name,
3391 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3393 /* roclone is true if one of the RO volumes is on the same
3394 * partition as the RW volume. In this case, we make the RO volume
3395 * on the same partition a clone instead of a complete copy.
3398 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3399 roclone = ((roindex == -1) ? 0 : 1);
3400 rwindex = Lp_GetRwIndex(&entry);
3402 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3404 /* Make sure we have a RO volume id to work with */
3405 if (entry.volumeId[ROVOL] == INVALID_BID) {
3406 /* need to get a new RO volume id */
3407 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3408 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3410 entry.volumeId[ROVOL] = roVolId;
3411 MapNetworkToHost(&entry, &storeEntry);
3412 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3413 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3416 /* Will we be completing a previously unfinished release. -force overrides */
3417 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3418 if (entry.serverFlags[i] & ITSROVOL) {
3420 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3421 if (entry.serverFlags[i] & RO_DONTUSE) notreleased++;
3423 origflags[i] = entry.serverFlags[i];
3425 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3428 if (!forceflag && (s == m || s == 0)) {
3429 if (notreleased && notreleased != m) {
3430 /* we have some new unreleased sites. try to just release to those,
3431 * if the RW has not changed */
3436 /* Determine which volume id to use and see if it exists */
3439 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3440 code = VolumeExists(afromserver, afrompart, cloneVolId);
3441 roexists = ((code == ENODEV) ? 0 : 1);
3443 /* For stayUp case, if roclone is the only site, bypass special handling */
3444 if (stayUp && roclone) {
3448 for (e = 0; (e < entry.nServers) && !error; e++) {
3449 if ((entry.serverFlags[e] & ITSROVOL)) {
3450 if (!(VLDB_IsSameAddrs(entry.serverNumber[e], afromserver,
3455 if (e >= entry.nServers)
3459 /* If we had a previous release to complete, do so, else: */
3460 if (stayUp && (cloneVolId == entry.volumeId[ROVOL])) {
3461 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVolId);
3462 ONERROR(code, afromvol,
3463 "Cannot get temporary clone id for volume %u\n");
3466 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3468 ONERROR(-1, afromserver,
3469 "Cannot establish connection with server 0x%x\n");
3473 fullrelease = 1; /* Do a full release if RO clone does not exist */
3475 /* Begin transaction on RW and mark it busy while we query it */
3476 code = AFSVolTransCreate_retry(
3477 fromconn, afromvol, afrompart, ITBusy, &fromtid
3479 ONERROR(code, afromvol,
3480 "Failed to start transaction on RW volume %u\n");
3482 /* Query the creation date for the RW */
3483 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3484 ONERROR(code, afromvol,
3485 "Failed to get the status of RW volume %u\n");
3486 rwcrdate = volstatus.creationDate;
3488 /* End transaction on RW */
3489 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3491 ONERROR((code ? code : rcode), afromvol,
3492 "Failed to end transaction on RW volume %u\n");
3494 /* Begin transaction on clone and mark it busy while we query it */
3495 code = AFSVolTransCreate_retry(
3496 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3498 ONERROR(code, cloneVolId,
3499 "Failed to start transaction on RW clone %u\n");
3501 /* Query the creation date for the clone */
3502 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3503 ONERROR(code, cloneVolId,
3504 "Failed to get the status of RW clone %u\n");
3505 clcrdate = volstatus.creationDate;
3507 /* End transaction on clone */
3508 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3510 ONERROR((code ? code : rcode), cloneVolId,
3511 "Failed to end transaction on RW clone %u\n");
3513 if (rwcrdate > clcrdate)
3514 fullrelease = 2;/* Do a full release if RO clone older than RW */
3518 if (fullrelease != 1) {
3519 /* in case the RW has changed, and just to be safe */
3524 switch (fullrelease) {
3526 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3527 (unsigned long)afromvol);
3530 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3531 (unsigned long)afromvol);
3533 tried_justnewsites = 1;
3534 fprintf(STDOUT, "There are new RO sites; we will try to "
3535 "only release to new sites\n");
3539 fprintf(STDOUT, "This is a completion of a previous release\n");
3545 afs_int32 oldest = 0;
3546 /* If the RO clone exists, then if the clone is a temporary
3547 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3548 * (it was recently added), then also delete it. We do not
3549 * want to "reclone" a temporary RO clone.
3552 code = VolumeExists(afromserver, afrompart, cloneVolId);
3554 code = DoVolDelete(fromconn, cloneVolId, afrompart, "previous clone", 0,
3556 if (code && (code != VNOVOL))
3561 /* clean up any previous tmp clone before starting if staying up */
3563 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3564 code = DoVolDelete(fromconn,
3565 stayUp ? entry.volumeId[ROVOL] : cloneVolId,
3566 afrompart, "the", 0, NULL, NULL);
3567 if (code && (code != VNOVOL))
3573 VPRINT("Querying old RO sites for update times...");
3574 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3575 volEntries volumeInfo;
3576 struct rx_connection *conn;
3579 if (!(entry.serverFlags[vldbindex] & ITSROVOL)) {
3582 if ((entry.serverFlags[vldbindex] & RO_DONTUSE)) {
3585 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3587 fprintf(STDERR, "Cannot establish connection to server %s\n",
3588 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3592 volumeInfo.volEntries_val = NULL;
3593 volumeInfo.volEntries_len = 0;
3594 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3595 entry.volumeId[ROVOL],
3598 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3599 (unsigned long)entry.volumeId[ROVOL],
3600 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3601 PrintError("", code);
3603 rx_DestroyConnection(conn);
3607 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3609 if (oldest == 0 || crdate < oldest) {
3613 rx_DestroyConnection(conn);
3614 free(volumeInfo.volEntries_val);
3615 volumeInfo.volEntries_val = NULL;
3616 volumeInfo.volEntries_len = 0;
3621 volEntries volumeInfo;
3622 volumeInfo.volEntries_val = NULL;
3623 volumeInfo.volEntries_len = 0;
3624 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3627 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3628 (unsigned long)afromvol,
3629 hostutil_GetNameByINet(afromserver));
3630 PrintError("", code);
3633 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3635 free(volumeInfo.volEntries_val);
3636 volumeInfo.volEntries_val = NULL;
3637 volumeInfo.volEntries_len = 0;
3640 if (justnewsites && oldest <= rwupdate) {
3641 /* RW has changed */
3645 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3646 * write this entry out to the vlserver until after the first
3647 * RO volume is released (temp RO clones don't count).
3649 * If 'justnewsites' is set, we're only updating sites that have
3650 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3652 for (i = 0; i < entry.nServers; i++) {
3654 if ((entry.serverFlags[i] & RO_DONTUSE)) {
3655 entry.serverFlags[i] &= ~NEW_REPSITE;
3657 entry.serverFlags[i] |= NEW_REPSITE;
3660 entry.serverFlags[i] &= ~NEW_REPSITE;
3661 entry.serverFlags[i] |= RO_DONTUSE;
3664 entry.serverFlags[rwindex] |= NEW_REPSITE;
3665 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3668 if (justnewsites && roexists) {
3669 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3670 * anything with the RO clone, so skip the reclone */
3673 } else if (fullrelease) {
3676 strcpy(vname, entry.name);
3678 strcat(vname, ".roclone");
3680 strcat(vname, ".readonly");
3682 strcpy(vname, "readonly-clone-temp");
3685 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3686 cloneVolId, (roclone && !stayUp)?"permanent RO":
3687 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3693 if (justnewsites && rwupdate != volstatus.updateDate) {
3695 /* reset the serverFlags as if 'justnewsites' had never been set */
3696 for (i = 0; i < entry.nServers; i++) {
3697 entry.serverFlags[i] &= ~NEW_REPSITE;
3698 entry.serverFlags[i] |= RO_DONTUSE;
3700 entry.serverFlags[rwindex] |= NEW_REPSITE;
3701 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3704 rwcrdate = volstatus.creationDate;
3706 /* Remember clone volume ID in case we fail or are interrupted */
3707 entry.cloneId = cloneVolId;
3709 if (roclone && !stayUp) {
3710 /* Bring the RO clone online - though not if it's a temporary clone */
3711 VPRINT1("Starting transaction on RO clone volume %u...",
3714 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3716 ONERROR(code, cloneVolId,
3717 "Failed to start transaction on volume %u\n");
3720 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3721 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3724 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3725 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3726 ONERROR((code ? code : rcode), cloneVolId,
3727 "Failed to end transaction on RO clone %u\n");
3730 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3732 /* Sleep so that a client searching for an online volume won't
3733 * find the clone offline and then the next RO offline while the
3734 * release brings the clone online and the next RO offline (race).
3735 * There is a fix in the 3.4 client that does not need this sleep
3736 * anymore, but we don't know what clients we have.
3738 if (entry.nServers > 2 && !justnewsites)
3741 /* Mark the RO clone in the VLDB as a good site (already released) */
3742 entry.serverFlags[roindex] |= NEW_REPSITE;
3743 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3744 entry.flags |= RO_EXISTS;
3748 /* Write out the VLDB entry only if the clone is not a temporary
3749 * clone. If we did this to a temporary clone then we would end
3750 * up marking all the ROs as "old release" making the ROs
3751 * temporarily unavailable.
3753 MapNetworkToHost(&entry, &storeEntry);
3754 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3755 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3756 ONERROR(vcode, entry.name,
3757 "Could not update vldb entry for %s.\n");
3763 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3764 /* act like this is a completion of a previous release */
3766 } else if (tried_justnewsites) {
3767 VPRINT("RW vol has changed; releasing to all sites\n");
3770 /* Now we will release from the clone to the remaining RO replicas.
3771 * The first 2 ROs (counting the non-temporary RO clone) are released
3772 * individually: releasecount. This is to reduce the race condition
3773 * of clients trying to find an on-line RO volume. The remaining ROs
3774 * are released in parallel but no more than half the number of ROs
3775 * (rounded up) at a time: nservers.
3778 strcpy(vname, entry.name);
3780 strcat(vname, ".roclone");
3782 strcat(vname, ".readonly");
3783 memset(&cookie, 0, sizeof(cookie));
3784 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3785 cookie.type = ROVOL;
3786 cookie.parent = entry.volumeId[RWVOL];
3789 /* how many to do at once, excluding clone */
3790 if (stayUp || justnewsites)
3791 nservers = entry.nServers; /* can do all, none offline */
3793 nservers = entry.nServers / 2;
3794 replicas = calloc(nservers + 1, sizeof(struct replica));
3795 times = calloc(nservers + 1, sizeof(struct release));
3796 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3797 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3798 if (!replicas || !times || !results.manyResults_val || !toconns)
3800 "Failed to create transaction on the release clone\n");
3802 /* Create a transaction on the cloned volume */
3803 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3805 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3807 memset(&orig_status, 0, sizeof(orig_status));
3808 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3810 if (!fullrelease && code)
3811 ONERROR(VOLSERNOVOL, afromvol,
3812 "Old clone is inaccessible. Try vos release -f %u.\n");
3813 ONERROR0(code, "Failed to create transaction on the release clone\n");
3816 /* if we have a clone, treat this as done, for now */
3817 if (stayUp && !fullrelease) {
3818 entry.serverFlags[roindex] |= NEW_REPSITE;
3819 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3820 entry.flags |= RO_EXISTS;
3825 /* For each index in the VLDB */
3826 for (vldbindex = 0; vldbindex < entry.nServers;) {
3827 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3829 ((volcount < nservers) && (vldbindex < entry.nServers));
3831 if (!stayUp && !justnewsites) {
3832 /* The first two RO volumes will be released individually.
3833 * The rest are then released in parallel. This is a hack
3834 * for clients not recognizing right away when a RO volume
3835 * comes back on-line.
3837 if ((volcount == 1) && (releasecount < 2))
3841 if (vldbindex == roindex)
3842 continue; /* the clone */
3843 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3844 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3846 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3847 continue; /* not a RO vol */
3850 /* Get a Transaction on this replica. Get a new connection if
3851 * necessary. Create the volume if necessary. Return the
3852 * time from which the dump should be made (0 if it's a new
3853 * volume). Each volume might have a different time.
3855 replicas[volcount].server.destHost =
3856 ntohl(entry.serverNumber[vldbindex]);
3857 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3858 replicas[volcount].server.destSSID = 1;
3859 times[volcount].vldbEntryIndex = vldbindex;
3862 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3863 &(replicas[volcount].trans),
3864 &(times[volcount].crtime),
3865 &(times[volcount].uptime),
3866 origflags, stayUp?cloneVolId:0);
3870 /* Thisdate is the date from which we want to pick up all changes */
3871 if (forceflag || !fullrelease
3872 || (rwcrdate > times[volcount].crtime)) {
3873 /* If the forceflag is set, then we want to do a full dump.
3874 * If it's not a full release, we can't be sure that the creation
3875 * date is good (so we also do a full dump).
3876 * If the RW volume was replaced (its creation date is newer than
3877 * the last release), then we can't be sure what has changed (so
3878 * we do a full dump).
3881 } else if (remembertime[vldbindex].validtime) {
3882 /* Trans was prev ended. Use the time from the prev trans
3883 * because, prev trans may have created the volume. In which
3884 * case time[volcount].time would be now instead of 0.
3887 (remembertime[vldbindex].uptime < times[volcount].uptime)
3888 ? remembertime[vldbindex].uptime
3889 : times[volcount].uptime;
3891 thisdate = times[volcount].uptime;
3893 remembertime[vldbindex].validtime = 1;
3894 remembertime[vldbindex].uptime = thisdate;
3896 if (volcount == 0) {
3897 fromdate = thisdate;
3899 /* Include this volume if it is within 15 minutes of the earliest */
3901 thisdate) ? (fromdate - thisdate) : (thisdate -
3903 AFSVolEndTrans(toconns[volcount],
3904 replicas[volcount].trans, &rcode);
3905 replicas[volcount].trans = 0;
3908 if (thisdate < fromdate)
3909 fromdate = thisdate;
3916 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
3923 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3924 (unsigned long)cloneVolId, stayUp?
3925 cloneVolId:entry.volumeId[ROVOL],
3926 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3927 vldbEntryIndex], hoststr) :
3928 hostutil_GetNameByINet(entry.
3929 serverNumber[times[0].
3932 for (s = 1; s < volcount; s++) {
3933 fprintf(STDOUT, " and %s",
3934 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3935 vldbEntryIndex], hoststr) :
3936 hostutil_GetNameByINet(entry.
3937 serverNumber[times[s].
3942 fprintf(STDOUT, " (full release)");
3945 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3947 fprintf(STDOUT, ".\n");
3951 /* Release the ones we have collected */
3952 tr.manyDests_val = &(replicas[0]);
3953 tr.manyDests_len = results.manyResults_len = volcount;
3955 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3956 0 /*spare */ , &cookie, &results);
3957 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3959 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3960 0 /*spare */ , &cookie, &results);
3965 PrintError("Release failed: ", code);
3967 for (m = 0; m < volcount; m++) {
3968 if (results.manyResults_val[m]) {
3969 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3970 /* we retry timed out transaction. When it is
3971 * not the first volume and the transaction wasn't found
3972 * (assume it timed out and was garbage collected by volser).
3975 ("Failed to dump volume from clone to a ro site: ",
3976 results.manyResults_val[m]);
3982 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3983 ROVOL, entry.volumeId[RWVOL], 0, 0);
3985 if ((m == 0) || (code != ENOENT)) {
3986 PrintError("Failed to set correct names and ids: ",
3992 /* have to clear dest. flags to ensure new vol goes online:
3993 * because the restore (forwarded) operation copied
3994 * the V_inService(=0) flag over to the destination.
3996 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3998 if ((m == 0) || (code != ENOENT)) {
3999 PrintError("Failed to set flags on ro volume: ",
4005 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
4006 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
4007 entry.flags |= RO_EXISTS;
4013 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4014 MapNetworkToHost(&entry, &storeEntry);
4015 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4016 ONERROR(vcode, afromvol,
4017 " Could not update VLDB entry for volume %u\n");
4019 } /* for each index in the vldb */
4021 /* for the stayup case, put back at the end */
4023 afs_uint32 tmpVol = entry.volumeId[ROVOL];
4024 strcpy(vname, entry.name);
4025 strcat(vname, ".readonly");
4028 /* have to clear flags to ensure new vol goes online
4030 code = AFSVolSetFlags(fromconn, fromtid, 0);
4031 if (code && (code != ENOENT)) {
4032 PrintError("Failed to set flags on ro volume: ",
4036 VPRINT3("%sloning to permanent RO %u on %s...", roexists?"Re-c":"C", tmpVol,
4038 afs_inet_ntoa_r(entry.serverNumber[roindex],
4040 hostutil_GetNameByINet(entry.serverNumber[roindex]));
4042 code = AFSVolClone(fromconn, fromtid, roexists?tmpVol:0,
4043 readonlyVolume, vname, &tmpVol);
4047 VPRINT("Bringing readonly online...");
4048 code = DoVolOnline(&entry, tmpVol, roindex, vname,
4052 EPRINT(code, "Failed: ");
4053 entry.serverFlags[roindex] &= ~NEW_REPSITE;
4054 entry.serverFlags[roindex] |= RO_DONTUSE;
4056 entry.serverFlags[roindex] |= NEW_REPSITE;
4057 entry.serverFlags[roindex] &= ~RO_DONTUSE;
4058 entry.flags |= RO_EXISTS;
4063 for (s = 0; s < volcount; s++) {
4064 if (replicas[s].trans) {
4065 vldbindex = times[s].vldbEntryIndex;
4067 /* ok, so now we have to end the previous transaction */
4068 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4073 code = AFSVolTransCreate_retry(toconns[s],
4075 entry.serverPartition[vldbindex],
4077 &(replicas[s].trans));
4079 PrintError("Unable to begin transaction on temporary clone: ", code);
4082 PrintError("Unable to end transaction on temporary clone: ", code);
4085 VPRINT3("%sloning to permanent RO %u on %s...", times[s].crtime?"Re-c":"C",
4087 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4089 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4090 if (times[s].crtime)
4091 code = AFSVolClone(toconns[s], replicas[s].trans, tmpVol,
4092 readonlyVolume, vname, &tmpVol);
4094 code = AFSVolClone(toconns[s], replicas[s].trans, 0,
4095 readonlyVolume, vname, &tmpVol);
4098 if (!times[s].crtime) {
4099 entry.serverFlags[vldbindex] |= RO_DONTUSE;
4101 entry.serverFlags[vldbindex] &= ~NEW_REPSITE;
4102 PrintError("Failed: ",
4107 if (entry.serverFlags[vldbindex] != RO_DONTUSE) {
4108 /* bring it online (mark it InService) */
4109 VPRINT1("Bringing readonly online on %s...",
4112 htonl(replicas[s].server.destHost),
4114 hostutil_GetNameByINet(
4115 htonl(replicas[s].server.destHost)));
4117 code = DoVolOnline(&entry, tmpVol, vldbindex, vname,
4119 /* needed to come online for cloning */
4121 /* technically it's still new, just not online */
4122 entry.serverFlags[s] &= ~NEW_REPSITE;
4123 entry.serverFlags[s] |= RO_DONTUSE;
4124 if (code != ENOENT) {
4125 PrintError("Failed to set correct names and ids: ",
4132 VPRINT("Marking temporary clone for deletion...\n");
4133 code = AFSVolSetFlags(toconns[s],
4138 EPRINT(code, "Failed: ");
4142 VPRINT("Ending transaction on temporary clone...\n");
4143 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4147 PrintError("Failed: ", code);
4150 /* ended successfully */
4151 replicas[s].trans = 0;
4153 VPRINT2("Deleting temporary clone %u on %s...", cloneVolId,
4155 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4157 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4158 code = DoVolDelete(toconns[s], cloneVolId,
4159 entry.serverPartition[vldbindex],
4160 NULL, 0, NULL, NULL);
4162 EPRINT(code, "Failed: ");
4169 /* done. put the vldb entry in the success tail case*/
4170 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4173 /* End the transaction on the cloned volume */
4174 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4179 PrintError("Failed to end transaction on rw volume: ", code);
4181 /* Figure out if any volume were not released and say so */
4182 for (failure = 0, i = 0; i < entry.nServers; i++) {
4183 if (!(entry.serverFlags[i] & NEW_REPSITE))
4189 "The volume %lu could not be released to the following %d sites:\n",
4190 (unsigned long)afromvol, failure);
4191 for (i = 0; i < entry.nServers; i++) {
4192 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
4193 MapPartIdIntoName(entry.serverPartition[i], pname);
4194 fprintf(STDERR, "\t%35s %s\n",
4195 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4196 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4199 MapNetworkToHost(&entry, &storeEntry);
4201 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4203 ONERROR(vcode, afromvol,
4204 " Could not update VLDB entry for volume %u\n");
4206 ERROREXIT(VOLSERBADRELEASE);
4210 /* All the ROs were release successfully. Remove the temporary clone */
4211 if (!roclone || stayUp) {
4213 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4214 (unsigned long)cloneVolId);
4217 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4219 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4223 for (i = 0; i < entry.nServers; i++)
4224 entry.serverFlags[i] &= ~NEW_REPSITE;
4226 /* Update the VLDB */
4227 VPRINT("updating VLDB ...");
4229 MapNetworkToHost(&entry, &storeEntry);
4231 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4232 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4233 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4238 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4242 "Failed to end cloning transaction on the RW volume %lu\n",
4243 (unsigned long)afromvol);
4249 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4253 "Failed to end transaction on the release clone %lu\n",
4254 (unsigned long)cloneVolId);
4259 for (i = 0; i < nservers; i++) {
4260 if (replicas && replicas[i].trans) {
4261 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4262 replicas[i].trans = 0;
4265 "Failed to end transaction on ro volume %u at server %s\n",
4266 entry.volumeId[ROVOL],
4267 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4268 destHost), hoststr) :
4269 hostutil_GetNameByINet(htonl
4270 (replicas[i].server.destHost)));
4275 if (toconns && toconns[i]) {
4276 rx_DestroyConnection(toconns[i]);
4282 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4283 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4286 "Could not release lock on the VLDB entry for volume %lu\n",
4287 (unsigned long)afromvol);
4293 PrintError("", error);
4296 rx_DestroyConnection(fromconn);
4297 if (results.manyResults_val)
4298 free(results.manyResults_val);
4310 dump_sig_handler(int x)
4312 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4316 /* Dump the volume <afromvol> on <afromserver> and
4317 * <afrompart> to <afilename> starting from <fromdate>.
4318 * DumpFunction does the real work behind the scenes after
4319 * extracting parameters from the rock
4322 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4324 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4327 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4328 * be changing during the dump */
4329 struct rx_call * volatile fromcall = NULL;
4330 struct rx_connection * volatile fromconn = NULL;
4331 afs_int32 volatile fromtid = 0;
4333 afs_int32 rxError = 0, rcode = 0;
4334 afs_int32 code, error = 0;
4336 time_t tmv = fromdate;
4340 #ifndef AFS_NT40_ENV
4341 (void)signal(SIGPIPE, dump_sig_handler);
4343 (void)signal(SIGINT, dump_sig_handler);
4346 VEPRINT("Full Dump ...\n");
4348 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4352 /* get connections to the servers */
4353 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4355 VEPRINT1("Starting transaction on volume %u...", afromvol);
4357 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4359 EGOTO1(error_exit, code,
4360 "Could not start transaction on the volume %u to be dumped\n",
4364 fromcall = rx_NewCall(fromconn);
4366 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4367 if (flags & VOLDUMPV2_OMITDIRS)
4368 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4370 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4371 EGOTO(error_exit, code, "Could not start the dump process \n");
4374 VEPRINT1("Dumping volume %u...", afromvol);
4375 code = DumpFunction(fromcall, rock);
4376 if (code == RXGEN_OPCODE)
4378 EGOTO(error_exit, code, "Error while dumping volume \n");
4383 code = rx_EndCall(fromcall, rxError);
4384 if (code && code != RXGEN_OPCODE)
4385 fprintf(STDERR, "Error in rx_EndCall\n");
4390 VEPRINT1("Ending transaction on volume %u...", afromvol);
4391 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4392 if (code || rcode) {
4393 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4394 (unsigned long)afromvol);
4396 error = (code ? code : rcode);
4401 rx_DestroyConnection(fromconn);
4403 if (error != RXGEN_OPCODE)
4404 PrintError("", error);
4408 /* Clone the volume <afromvol> on <afromserver> and
4409 * <afrompart>, and then dump the clone volume to
4410 * <afilename> starting from <fromdate>.
4411 * DumpFunction does the real work behind the scenes after
4412 * extracting parameters from the rock
4415 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4416 afs_int32 afrompart, afs_int32 fromdate,
4417 afs_int32(*DumpFunction) (struct rx_call *, void *),
4418 void *rock, afs_int32 flags)
4420 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4421 * be changing during the dump */
4422 struct rx_connection * volatile fromconn = NULL;
4423 struct rx_call * volatile fromcall = NULL;
4424 afs_int32 volatile clonetid = 0;
4425 afs_uint32 volatile clonevol = 0;
4428 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4429 afs_int32 code = 0, error = 0;
4432 time_t tmv = fromdate;
4436 #ifndef AFS_NT40_ENV
4437 (void)signal(SIGPIPE, dump_sig_handler);
4439 (void)signal(SIGINT, dump_sig_handler);
4442 VEPRINT("Full Dump ...\n");
4444 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4448 /* get connections to the servers */
4449 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4451 VEPRINT1("Starting transaction on volume %u...", afromvol);
4452 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4453 EGOTO1(error_exit, code,
4454 "Could not start transaction on the volume %u to be dumped\n",
4458 /* Get a clone id */
4459 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4461 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4463 EGOTO1(error_exit, code,
4464 "Could not get an ID for the clone of volume %u from the VLDB\n",
4468 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4469 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4471 strcpy(vname, "dump-clone-temp");
4474 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
4476 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4480 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4482 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4486 EGOTO1(error_exit, code,
4487 "Failed to end the transaction on the volume %u\n", afromvol);
4491 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4494 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4497 EGOTO1(error_exit, code,
4498 "Failed to start a transaction on the cloned volume%u\n",
4502 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4503 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4504 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4509 fromcall = rx_NewCall(fromconn);
4511 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4512 if (flags & VOLDUMPV2_OMITDIRS)
4513 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4515 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4516 EGOTO(error_exit, code, "Could not start the dump process \n");
4519 VEPRINT1("Dumping volume %u...", afromvol);
4520 code = DumpFunction(fromcall, rock);
4521 EGOTO(error_exit, code, "Error while dumping volume \n");
4525 /* now delete the clone */
4526 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4527 code = AFSVolDeleteVolume(fromconn, clonetid);
4529 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4530 (unsigned long)clonevol);
4536 code = rx_EndCall(fromcall, rxError);
4538 fprintf(STDERR, "Error in rx_EndCall\n");
4544 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4545 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4546 if (code || rcode) {
4548 "Could not end transaction on the cloned volume %lu\n",
4549 (unsigned long)clonevol);
4551 error = (code ? code : rcode);
4556 rx_DestroyConnection(fromconn);
4558 PrintError("", error);
4565 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4566 * the dump file <afilename>. WriteData does all the real work
4567 * after extracting params from the rock
4570 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4571 afs_uint32 toparentid, char tovolname[], int flags,
4572 afs_int32(*WriteData) (struct rx_call *, void *),
4575 struct rx_connection *toconn, *tempconn;
4576 struct rx_call *tocall;
4577 afs_int32 totid, code, rcode, vcode, terror = 0;
4578 afs_int32 rxError = 0;
4579 struct volser_status tstatus;
4580 struct volintInfo vinfo;
4582 char tovolreal[VOLSER_OLDMAXVOLNAME];
4584 afs_int32 temptid, pparentid;
4585 struct nvldbentry entry, storeEntry;
4588 struct restoreCookie cookie;
4590 afs_int32 volflag, voltype, volsertype;
4591 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4592 int index, same, errcode;
4596 memset(&cookie, 0, sizeof(cookie));
4600 tocall = (struct rx_call *)0;
4601 tempconn = (struct rx_connection *)0;
4605 if (flags & RV_RDONLY) {
4607 volsertype = volser_RO;
4610 volsertype = volser_RW;
4614 pparentid = toparentid;
4615 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4616 if (pvolid == 0) { /*alot a new id if needed */
4617 vcode = VLDB_GetEntryByName(tovolname, &entry);
4618 if (vcode == VL_NOENT) {
4619 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4621 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4627 } else if (flags & RV_RDONLY) {
4628 if (entry.flags & RW_EXISTS) {
4630 "Entry for ReadWrite volume %s already exists!\n",
4632 error = VOLSERBADOP;
4635 if (!entry.volumeId[ROVOL]) {
4637 "Existing entry for volume %s has no ReadOnly ID\n",
4639 error = VOLSERBADOP;
4642 pvolid = entry.volumeId[ROVOL];
4643 pparentid = entry.volumeId[RWVOL];
4645 pvolid = entry.volumeId[RWVOL];
4646 pparentid = entry.volumeId[RWVOL];
4649 if (!pparentid) pparentid = pvolid;
4650 /* at this point we have a volume id to use/reuse for the volume to be restored */
4651 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4653 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4654 EGOTO1(refail, VOLSERBADOP,
4655 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4658 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4659 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4660 EGOTO1(refail, VOLSERBADOP,
4661 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4663 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4666 MapPartIdIntoName(topart, partName);
4667 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4668 tovolreal, (unsigned long)pvolid,
4669 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4670 hostutil_GetNameByINet(toserver), partName);
4673 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4676 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4677 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4679 if (code && code != VNOVOL) {
4685 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4687 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4690 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4691 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4694 code = AFSVolGetStatus(toconn, totid, &tstatus);
4695 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4699 oldCreateDate = tstatus.creationDate;
4700 oldUpdateDate = tstatus.updateDate;
4706 cookie.parent = pparentid;
4707 cookie.type = voltype;
4709 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4711 tocall = rx_NewCall(toconn);
4712 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4714 fprintf(STDERR, "Volume restore Failed \n");
4718 code = WriteData(tocall, rock);
4720 fprintf(STDERR, "Could not transmit data\n");
4724 terror = rx_EndCall(tocall, rxError);
4725 tocall = (struct rx_call *)0;
4727 fprintf(STDERR, "rx_EndCall Failed \n");
4731 code = AFSVolGetStatus(toconn, totid, &tstatus);
4734 "Could not get status information about the volume %lu\n",
4735 (unsigned long)pvolid);
4739 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4741 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4742 (unsigned long)pvolid);
4747 if (flags & RV_CRDUMP)
4748 newCreateDate = tstatus.creationDate;
4749 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4750 newCreateDate = oldCreateDate;
4752 newCreateDate = time(0);
4753 if (flags & RV_LUDUMP)
4754 newUpdateDate = tstatus.updateDate;
4755 else if (flags & RV_LUKEEP)
4756 newUpdateDate = oldUpdateDate;
4758 newUpdateDate = time(0);
4759 code = AFSVolSetDate(toconn,totid, newCreateDate);
4761 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4766 init_volintInfo(&vinfo);
4767 vinfo.creationDate = newCreateDate;
4768 vinfo.updateDate = newUpdateDate;
4769 code = AFSVolSetInfo(toconn, totid, &vinfo);
4771 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4777 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4778 code = AFSVolSetFlags(toconn, totid, volflag);
4780 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4785 /* It isn't handled right in refail */
4786 code = AFSVolEndTrans(toconn, totid, &rcode);
4791 fprintf(STDERR, "Could not end transaction on %lu\n",
4792 (unsigned long)pvolid);
4797 fprintf(STDOUT, " done\n");
4799 if (!reuseID || (flags & RV_FULLRST)) {
4800 /* Volume was restored on the file server, update the
4801 * VLDB to reflect the change.
4803 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4804 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4806 "Could not fetch the entry for volume number %lu from VLDB \n",
4807 (unsigned long)pvolid);
4812 MapHostToNetwork(&entry);
4813 if (vcode == VL_NOENT) { /* it doesnot exist already */
4814 /*make the vldb return this indication specifically */
4815 VPRINT("------- Creating a new VLDB entry ------- \n");
4816 strcpy(entry.name, tovolname);
4818 entry.serverNumber[0] = toserver; /*should be indirect */
4819 entry.serverPartition[0] = topart;
4820 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4821 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4822 if (flags & RV_RDONLY)
4823 entry.volumeId[ROVOL] = pvolid;
4824 else if (tstatus.cloneID != 0) {
4825 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4827 entry.volumeId[ROVOL] = INVALID_BID;
4828 entry.volumeId[RWVOL] = pparentid;
4830 if (tstatus.backupID != 0) {
4831 entry.volumeId[BACKVOL] = tstatus.backupID;
4832 /*this should come from status info on the volume if non zero */
4834 entry.volumeId[BACKVOL] = INVALID_BID;
4835 MapNetworkToHost(&entry, &storeEntry);
4836 vcode = VLDB_CreateEntry(&storeEntry);
4839 "Could not create the VLDB entry for volume number %lu \n",
4840 (unsigned long)pvolid);
4846 EnumerateEntry(&entry);
4847 } else { /*update the existing entry */
4849 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4850 fprintf(STDOUT, "------- Old entry -------\n");
4851 EnumerateEntry(&entry);
4852 fprintf(STDOUT, "------- New entry -------\n");
4855 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4859 "Could not lock the entry for volume number %lu \n",
4860 (unsigned long)pvolid);
4865 strcpy(entry.name, tovolname);
4867 /* Update the vlentry with the new information */
4868 if (flags & RV_RDONLY)
4869 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4871 index = Lp_GetRwIndex(&entry);
4873 /* Add the new site for the volume being restored */
4874 entry.serverNumber[entry.nServers] = toserver;
4875 entry.serverPartition[entry.nServers] = topart;
4876 entry.serverFlags[entry.nServers] =
4877 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4880 /* This volume should be deleted on the old site
4881 * if its different from new site.
4884 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4888 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4890 if ((!errcode && !same)
4891 || (entry.serverPartition[index] != topart)) {
4892 if (flags & RV_NODEL) {
4894 ("Not deleting the previous volume %u on server %s, ...",
4896 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4897 hostutil_GetNameByINet(entry.serverNumber[index]));
4900 UV_Bind(entry.serverNumber[index],
4901 AFSCONF_VOLUMEPORT);
4903 MapPartIdIntoName(entry.serverPartition[index],
4906 ("Deleting the previous volume %u on server %s, partition %s ...",
4908 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4909 hostutil_GetNameByINet(entry.serverNumber[index]),
4911 code = DoVolDelete(tempconn, pvolid,
4912 entry.serverPartition[index],
4913 "the", 0, NULL, NULL);
4914 if (code && code != VNOVOL) {
4918 MapPartIdIntoName(entry.serverPartition[index],
4922 entry.serverNumber[index] = toserver;
4923 entry.serverPartition[index] = topart;
4926 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4927 MapNetworkToHost(&entry, &storeEntry);
4929 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4930 LOCKREL_OPCODE | LOCKREL_AFSID |
4934 "Could not update the entry for volume number %lu \n",
4935 (unsigned long)pvolid);
4941 EnumerateEntry(&entry);
4948 code = rx_EndCall(tocall, rxError);
4954 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4955 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4958 "Could not release lock on the VLDB entry for the volume %lu\n",
4959 (unsigned long)pvolid);
4965 code = AFSVolEndTrans(toconn, totid, &rcode);
4969 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4970 (unsigned long)pvolid);
4976 code = AFSVolEndTrans(toconn, temptid, &rcode);
4980 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4981 (unsigned long)pvolid);
4987 rx_DestroyConnection(tempconn);
4989 rx_DestroyConnection(toconn);
4990 PrintError("", error);
4995 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4996 char tovolname[], int flags,
4997 afs_int32(*WriteData) (struct rx_call *, void *),
5000 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
5005 /*unlocks the vldb entry associated with <volid> */
5007 UV_LockRelease(afs_uint32 volid)
5011 VPRINT("Binding to the VLDB server\n");
5013 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5014 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5017 "Could not unlock the entry for volume number %lu in VLDB \n",
5018 (unsigned long)volid);
5019 PrintError("", vcode);
5022 VPRINT("VLDB updated\n");
5027 /* old interface to add rosites */
5029 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5032 return UV_AddSite2(server, part, volid, 0, valid);
5035 /*adds <server> and <part> as a readonly replication site for <volid>
5038 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5039 afs_uint32 rovolid, afs_int32 valid)
5041 int j, nro = 0, islocked = 0;
5042 struct nvldbentry entry, storeEntry, entry2;
5043 afs_int32 vcode, error = 0;
5046 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5049 " Could not lock the VLDB entry for the volume %lu \n",
5050 (unsigned long)volid);
5055 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
5058 "Could not fetch the VLDB entry for volume number %lu \n",
5059 (unsigned long)volid);
5063 if (!ISNAMEVALID(entry.name)) {
5065 "Volume name %s is too long, rename before adding site\n",
5067 error = VOLSERBADOP;
5070 MapHostToNetwork(&entry);
5072 /* See if it's too many entries */
5073 if (entry.nServers >= NMAXNSERVERS) {
5074 fprintf(STDERR, "Total number of entries will exceed %u\n",
5076 error = VOLSERBADOP;
5080 /* See if it's on the same server */
5081 for (j = 0; j < entry.nServers; j++) {
5082 if (entry.serverFlags[j] & ITSROVOL) {
5084 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5087 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5090 MapPartIdIntoName(entry.serverPartition[j], apartName);
5092 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5094 error = VOLSERBADOP;
5101 /* See if it's too many RO sites - leave one for the RW */
5102 if (nro >= NMAXNSERVERS - 1) {
5103 fprintf(STDERR, "Total number of sites will exceed %u\n",
5105 error = VOLSERBADOP;
5109 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5110 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5111 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5114 if (entry.volumeId[ROVOL] == INVALID_BID) {
5115 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5117 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5120 VPRINT1("Using RO volume id %d.\n", rovolid);
5121 entry.volumeId[ROVOL] = rovolid;
5123 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5124 rovolid, entry.volumeId[ROVOL]);
5128 VPRINT("Adding a new site ...");
5129 entry.serverNumber[entry.nServers] = server;
5130 entry.serverPartition[entry.nServers] = part;
5132 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
5134 entry.serverFlags[entry.nServers] = (ITSROVOL);
5138 MapNetworkToHost(&entry, &storeEntry);
5140 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5141 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5143 fprintf(STDERR, "Could not update entry for volume %lu \n",
5144 (unsigned long)volid);
5153 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5154 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5157 "Could not release lock on volume entry for %lu \n",
5158 (unsigned long)volid);
5159 PrintError("", vcode);
5163 PrintError("", error);
5167 /*removes <server> <part> as read only site for <volid> from the vldb */
5169 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5172 struct nvldbentry entry, storeEntry;
5174 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5176 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5177 (unsigned long)volid);
5178 PrintError("", vcode);
5181 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5184 "Could not fetch the entry for volume number %lu from VLDB \n",
5185 (unsigned long)volid);
5186 PrintError("", vcode);
5189 MapHostToNetwork(&entry);
5190 if (!Lp_ROMatch(server, part, &entry)) {
5191 /*this site doesnot exist */
5192 fprintf(STDERR, "This site is not a replication site \n");
5194 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5195 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5197 fprintf(STDERR, "Could not update entry for volume %lu \n",
5198 (unsigned long)volid);
5199 PrintError("", vcode);
5200 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5201 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5205 } else { /*remove the rep site */
5206 Lp_SetROValue(&entry, server, part, 0, 0);
5208 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
5209 entry.flags &= ~RO_EXISTS;
5210 if (entry.nServers < 1) { /*this is the last ref */
5211 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5213 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5216 "Could not delete VLDB entry for volume %lu \n",
5217 (unsigned long)volid);
5218 PrintError("", vcode);
5223 MapNetworkToHost(&entry, &storeEntry);
5224 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5225 (unsigned long)volid);
5228 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5229 LOCKREL_OPCODE | LOCKREL_AFSID |
5233 "Could not release lock on volume entry for %lu \n",
5234 (unsigned long)volid);
5235 PrintError("", vcode);
5236 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5237 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5245 /*sets <server> <part> as read/write site for <volid> in the vldb */
5247 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5250 struct nvldbentry entry, storeEntry;
5253 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5255 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5256 (unsigned long)volid);
5257 PrintError("", vcode);
5260 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5263 "Could not fetch the entry for volume number %lu from VLDB \n",
5264 (unsigned long)volid);
5265 PrintError("", vcode);
5268 MapHostToNetwork(&entry);
5269 index = Lp_GetRwIndex(&entry);
5271 /* no RW site exists */
5272 fprintf(STDERR, "No existing RW site for volume %lu",
5273 (unsigned long)volid);
5275 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5276 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5279 "Could not release lock on entry for volume %lu \n",
5280 (unsigned long)volid);
5281 PrintError("", vcode);
5285 } else { /* change the RW site */
5286 entry.serverNumber[index] = server;
5287 entry.serverPartition[index] = part;
5288 MapNetworkToHost(&entry, &storeEntry);
5290 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5291 LOCKREL_OPCODE | LOCKREL_AFSID |
5294 fprintf(STDERR, "Could not update entry for volume %lu \n",
5295 (unsigned long)volid);
5296 PrintError("", vcode);
5297 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5298 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5306 /*list all the partitions on <aserver> */
5308 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5311 struct rx_connection *aconn;
5312 struct pIDs partIds;
5313 struct partEntries partEnts;
5317 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5319 partEnts.partEntries_len = 0;
5320 partEnts.partEntries_val = NULL;
5321 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5322 if (code == RXGEN_OPCODE) {
5323 for (i = 0; i < 26; i++) /* try old interface */
5324 partIds.partIds[i] = -1;
5325 code = AFSVolListPartitions(aconn, &partIds);
5327 for (i = 0; i < 26; i++) {
5328 if ((partIds.partIds[i]) != -1) {
5329 ptrPartList->partId[j] = partIds.partIds[i];
5330 ptrPartList->partFlags[j] = PARTVALID;
5333 ptrPartList->partFlags[i] = 0;
5338 *cntp = partEnts.partEntries_len;
5339 if (*cntp > VOLMAXPARTS) {
5341 "Warning: number of partitions on the server too high %d (process only %d)\n",
5342 *cntp, VOLMAXPARTS);
5343 *cntp = VOLMAXPARTS;
5345 for (i = 0; i < *cntp; i++) {
5346 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5347 ptrPartList->partFlags[i] = PARTVALID;
5349 free(partEnts.partEntries_val);
5355 "Could not fetch the list of partitions from the server\n");
5356 PrintError("", code);
5358 rx_DestroyConnection(aconn);
5363 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5364 This is used by the backup system */
5366 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5367 struct volDescription *volPtr, afs_int32 arraySize)
5369 struct rx_connection *aconn;
5370 struct volDescription *curPtr;
5373 afs_int32 success = 1;
5375 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5377 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5378 if (curPtr->volFlags & CLONEVALID) {
5379 curPtr->volFlags &= ~CLONEZAPPED;
5382 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5383 "clone", 0, NULL, NULL);
5388 curPtr->volFlags |= CLONEZAPPED;
5390 fprintf(STDERR, "Could not zap volume %lu\n",
5391 (unsigned long)curPtr->volCloneId);
5393 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5394 curPtr->volCloneId);
5399 rx_DestroyConnection(aconn);
5403 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5406 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5407 struct volDescription *volPtr, afs_int32 arraySize)
5409 struct rx_connection *aconn;
5410 struct volDescription *curPtr;
5413 afs_int32 rcode = 0;
5415 int reuseCloneId = 0;
5416 afs_uint32 curCloneId = 0;
5417 char cloneName[256]; /*max vol name */
5419 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5421 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5423 else { /*get a bunch of id's from vldb */
5425 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5427 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5428 PrintError("", code);
5433 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5434 if (curPtr->volFlags & ENTRYVALID) {
5436 curPtr->volFlags |= CLONEVALID;
5437 /*make a clone of curParentId and record as curPtr->volCloneId */
5439 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5442 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5445 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5449 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5450 strcpy(cloneName, curPtr->volName);
5451 strcat(cloneName, "-tmpClone-");
5453 strcpy(cloneName, "-tmpClone");
5455 curPtr->volCloneId = curCloneId;
5460 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5461 &(curPtr->volCloneId));
5463 curPtr->volFlags &= ~CLONEVALID;
5465 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5466 curPtr->volName, (unsigned long)code);
5467 code = AFSVolEndTrans(aconn, tid, &rcode);
5469 fprintf(STDERR, "WARNING: could not end transaction\n");
5472 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5473 curPtr->volCloneId);
5474 code = AFSVolEndTrans(aconn, tid, &rcode);
5475 if (code || rcode) {
5476 curPtr->volFlags &= ~CLONEVALID;
5485 rx_DestroyConnection(aconn);
5490 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5491 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5493 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5494 struct volintInfo **resultPtr, afs_int32 * size)
5496 struct rx_connection *aconn;
5498 volEntries volumeInfo;
5502 *resultPtr = (volintInfo *) 0;
5503 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5504 volumeInfo.volEntries_len = 0;
5506 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5507 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5510 "Could not fetch the list of volumes from the server\n");
5512 *resultPtr = volumeInfo.volEntries_val;
5513 *size = volumeInfo.volEntries_len;
5517 rx_DestroyConnection(aconn);
5518 PrintError("", code);
5522 /*------------------------------------------------------------------------
5523 * EXPORTED UV_XListVolumes
5526 * List the extended information for all the volumes on a particular
5527 * File Server and partition. We may either return the volume's ID
5528 * or all of its extended information.
5531 * a_serverID : Address of the File Server for which we want
5532 * extended volume info.
5533 * a_partID : Partition for which we want the extended
5535 * a_all : If non-zero, fetch ALL the volume info,
5536 * otherwise just the volume ID.
5537 * a_resultPP : Ptr to the address of the area containing
5538 * the returned volume info.
5539 * a_numEntsInResultP : Ptr for the value we set for the number of
5544 * Otherise, the return value of AFSVolXListVolumes.
5547 * This routine is closely related to UV_ListVolumes, which returns
5548 * only the standard level of detail on AFS volumes. It is a
5549 * heavyweight operation, zipping through all the volume entries for
5550 * a given server/partition.
5554 *------------------------------------------------------------------------*/
5557 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5558 struct volintXInfo **a_resultPP,
5559 afs_int32 * a_numEntsInResultP)
5561 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5562 afs_int32 code; /*Error code to return */
5563 volXEntries volumeXInfo; /*Area for returned extended vol info */
5566 * Set up our error code and the area for returned extended volume info.
5567 * We set the val field to a null pointer as a hint for the stub to
5570 *a_numEntsInResultP = 0;
5571 *a_resultPP = (volintXInfo *) 0;
5572 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5573 volumeXInfo.volXEntries_len = 0;
5576 * Bind to the Volume Server port on the File Server machine in question,
5579 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5580 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5582 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5585 * We got the info; pull out the pointer to where the results lie
5586 * and how many entries are there.
5588 *a_resultPP = volumeXInfo.volXEntries_val;
5589 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5593 * If we got an Rx connection, throw it away.
5596 rx_DestroyConnection(rxConnP);
5598 PrintError("", code);
5600 } /*UV_XListVolumes */
5602 /* get all the information about volume <volid> on <aserver> and <apart> */
5604 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5605 struct volintInfo **resultPtr)
5607 struct rx_connection *aconn;
5609 volEntries volumeInfo;
5611 *resultPtr = (volintInfo *) 0;
5612 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5613 volumeInfo.volEntries_len = 0;
5615 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5616 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5619 "Could not fetch the information about volume %lu from the server\n",
5620 (unsigned long)volid);
5622 *resultPtr = volumeInfo.volEntries_val;
5627 rx_DestroyConnection(aconn);
5628 PrintError("", code);
5632 /*------------------------------------------------------------------------
5633 * EXPORTED UV_XListOneVolume
5636 * List the extended information for a volume on a particular File
5637 * Server and partition.
5640 * a_serverID : Address of the File Server for which we want
5641 * extended volume info.
5642 * a_partID : Partition for which we want the extended
5644 * a_volID : Volume ID for which we want the info.
5645 * a_resultPP : Ptr to the address of the area containing
5646 * the returned volume info.
5650 * Otherise, the return value of AFSVolXListOneVolume.
5653 * This routine is closely related to UV_ListOneVolume, which returns
5654 * only the standard level of detail on the chosen AFS volume.
5658 *------------------------------------------------------------------------*/
5661 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5662 struct volintXInfo **a_resultPP)
5664 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5665 afs_int32 code; /*Error code */
5666 volXEntries volumeXInfo; /*Area for returned info */
5669 * Set up our error code, and the area we're in which we are returning
5670 * the info. Setting the val field to a null pointer tells the stub
5671 * to allocate space for us.
5673 *a_resultPP = (volintXInfo *) 0;
5674 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5675 volumeXInfo.volXEntries_len = 0;
5678 * Bind to the Volume Server port on the File Server machine in question,
5681 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5682 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5685 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5688 * We got the info; pull out the pointer to where the results lie.
5690 *a_resultPP = volumeXInfo.volXEntries_val;
5693 * If we got an Rx connection, throw it away.
5696 rx_DestroyConnection(rxConnP);
5698 PrintError("", code);
5703 * Given a volume we read from a partition, check if it is
5704 * represented in the VLDB correctly.
5706 * The VLDB is looked up by the RW volume id (not its name).
5707 * The RW contains the true name of the volume (BK and RO set
5708 * the name in the VLDB only on creation of the VLDB entry).
5709 * We want rules strict enough that when we check all volumes
5710 * on one partition, it does not need to be done again. IE:
5711 * two volumes on different partitions won't constantly
5712 * change a VLDB entry away from what the other set.
5713 * For RW and BK volumes, we will always check the VLDB to see
5714 * if the two exist on the server/partition. May seem redundant,
5715 * but this is an easy check of the VLDB. IE: if the VLDB entry
5716 * says the BK exists but no BK volume is there, we will detect
5717 * this when we check the RW volume.
5718 * VLDB entries are locked only when a change needs to be done.
5719 * Output changed to look a lot like the "vos syncserv" otuput.
5722 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5723 afs_int32 * modentry, afs_uint32 * maxvolid,
5724 struct nvldbentry *aentry)
5728 afs_int32 code, error = 0;
5729 struct nvldbentry entry, storeEntry;
5731 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5741 ((volumeinfo->type ==
5742 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5745 /* Check to see if the VLDB is ok without locking it (pass 1).
5746 * If it will change, then lock the VLDB entry, read it again,
5747 * then make the changes to it (pass 2).
5750 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5752 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5753 (unsigned long)rwvolid);
5758 createentry = 0; /* Do we need to create a VLDB entry */
5759 addvolume = 0; /* Add this volume to the VLDB entry */
5760 modified = 0; /* The VLDB entry was modified */
5763 memcpy(&entry, aentry, sizeof(entry));
5765 /* Read the entry from VLDB by its RW volume id */
5766 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5768 if (code != VL_NOENT) {
5770 "Could not retrieve the VLDB entry for volume %lu \n",
5771 (unsigned long)rwvolid);
5775 memset(&entry, 0, sizeof(entry));
5776 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5780 MapHostToNetwork(&entry);
5784 if (verbose && (pass == 1)) {
5785 fprintf(STDOUT, "_______________________________\n");
5786 fprintf(STDOUT, "\n-- status before -- \n");
5788 fprintf(STDOUT, "\n**does not exist**\n");
5790 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5791 || (entry.flags & BACK_EXISTS))
5792 EnumerateEntry(&entry);
5794 fprintf(STDOUT, "\n");
5797 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5803 /* Check existence of RW and BK volumes */
5804 code = CheckVldbRWBK(&entry, &mod);
5810 idx = Lp_GetRwIndex(&entry);
5811 if (idx == -1) { /* RW index not found in the VLDB entry */
5812 idx = entry.nServers; /* put it into next index */
5815 } else { /* RW index found in the VLDB entry. */
5816 /* Verify if this volume's location matches where the VLDB says it is */
5817 if (!Lp_Match(aserver, apart, &entry)) {
5818 if (entry.flags & RW_EXISTS) {
5819 /* The RW volume exists elsewhere - report this one a duplicate */
5821 MapPartIdIntoName(apart, pname);
5823 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5824 (unsigned long)rwvolid,
5826 afs_inet_ntoa_r(aserver, hoststr) :
5827 hostutil_GetNameByINet(aserver), pname);
5828 MapPartIdIntoName(entry.serverPartition[idx],
5831 " VLDB reports RW volume %lu exists on %s %s\n",
5832 (unsigned long)rwvolid,
5834 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5835 hostutil_GetNameByINet(entry.
5840 /* The RW volume does not exist - have VLDB point to this one */
5843 /* Check for orphaned BK volume on old partition */
5844 if (entry.flags & BACK_EXISTS) {
5846 MapPartIdIntoName(entry.serverPartition[idx],
5849 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5850 entry.volumeId[BACKVOL],
5852 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5853 hostutil_GetNameByINet(entry.
5856 MapPartIdIntoName(apart, pname);
5858 " VLDB reports its RW volume %lu exists on %s %s\n",
5859 (unsigned long)rwvolid,
5861 afs_inet_ntoa_r(aserver, hoststr) :
5862 hostutil_GetNameByINet(aserver),
5868 /* Volume location matches the VLDB location */
5869 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5870 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5873 (entry.name, volumeinfo->name,
5874 VOLSER_OLDMAXVOLNAME) != 0)) {
5882 entry.flags |= RW_EXISTS;
5883 entry.volumeId[RWVOL] = rwvolid;
5884 if (!entry.volumeId[BACKVOL])
5885 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5886 if (!entry.volumeId[ROVOL])
5887 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5889 entry.serverFlags[idx] = ITSRWVOL;
5890 entry.serverNumber[idx] = aserver;
5891 entry.serverPartition[idx] = apart;
5892 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5896 /* One last check - to update BK if need to */
5897 code = CheckVldbRWBK(&entry, &mod);
5905 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5911 /* Check existence of RW and BK volumes */
5912 code = CheckVldbRWBK(&entry, &mod);
5918 idx = Lp_GetRwIndex(&entry);
5919 if (idx == -1) { /* RW index not found in the VLDB entry */
5920 idx = entry.nServers; /* Put it into next index */
5923 } else { /* RW index found in the VLDB entry */
5924 /* Verify if this volume's location matches where the VLDB says it is */
5925 if (!Lp_Match(aserver, apart, &entry)) {
5926 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5928 MapPartIdIntoName(apart, pname);
5930 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5931 (unsigned long)volumeinfo->volid,
5933 afs_inet_ntoa_r(aserver, hoststr) :
5934 hostutil_GetNameByINet(aserver), pname);
5935 MapPartIdIntoName(entry.serverPartition[idx], pname);
5937 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5938 (unsigned long)rwvolid,
5940 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5941 hostutil_GetNameByINet(entry.
5946 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5947 if (!(entry.flags & BACK_EXISTS)) {
5949 } else if (volumeinfo->volid >
5950 entry.volumeId[BACKVOL]) {
5954 MapPartIdIntoName(entry.serverPartition[idx],
5957 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5958 entry.volumeId[BACKVOL],
5960 afs_inet_ntoa_r(aserver, hoststr) :
5961 hostutil_GetNameByINet(aserver),
5964 " VLDB reports its BK volume ID is %lu\n",
5965 (unsigned long)volumeinfo->volid);
5969 MapPartIdIntoName(entry.serverPartition[idx],
5972 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5973 (unsigned long)volumeinfo->volid,
5975 afs_inet_ntoa_r(aserver, hoststr) :
5976 hostutil_GetNameByINet(aserver),
5979 " VLDB reports its BK volume ID is %u\n",
5980 entry.volumeId[BACKVOL]);
5983 } else if (!entry.volumeId[BACKVOL]) {
5990 entry.flags |= BACK_EXISTS;
5991 entry.volumeId[RWVOL] = rwvolid;
5992 entry.volumeId[BACKVOL] = volumeinfo->volid;
5994 entry.serverNumber[idx] = aserver;
5995 entry.serverPartition[idx] = apart;
5996 entry.serverFlags[idx] = ITSBACKVOL;
6002 else if (volumeinfo->type == ROVOL) { /* A RO volume */
6003 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
6004 /* This is a quick check to see if the RO entry exists in the
6005 * VLDB so we avoid the CheckVldbRO() call (which checks if each
6006 * RO volume listed in the VLDB exists).
6008 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6010 idx = entry.nServers;
6014 if (!(entry.flags & RO_EXISTS)) {
6019 /* Before we correct the VLDB entry, make sure all the
6020 * ROs listed in the VLDB exist.
6022 code = CheckVldbRO(&entry, &mod);
6028 if (!(entry.flags & RO_EXISTS)) {
6029 /* No RO exists in the VLDB entry - add this one */
6030 idx = entry.nServers;
6033 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
6034 /* The volume headers's RO ID does not match that in the VLDB entry,
6035 * and the vol hdr's ID is greater (implies more recent). So delete
6036 * all the RO volumes listed in VLDB entry and add this volume.
6038 for (j = 0; j < entry.nServers; j++) {
6039 if (entry.serverFlags[j] & ITSROVOL) {
6040 /* Verify this volume exists and print message we are orphaning it */
6042 MapPartIdIntoName(apart, pname);
6044 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
6045 entry.volumeId[ROVOL],
6047 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
6048 hostutil_GetNameByINet(entry.
6052 " VLDB reports its RO volume ID is %lu\n",
6053 (unsigned long)volumeinfo->volid);
6056 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6057 entry.serverPartition[idx], 0L, 0L);
6064 idx = entry.nServers;
6067 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6068 /* The volume headers's RO ID does not match that in the VLDB entry,
6069 * and the vol hdr's ID is lower (implies its older). So orphan it.
6072 MapPartIdIntoName(apart, pname);
6074 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6075 (unsigned long)volumeinfo->volid,
6077 afs_inet_ntoa_r(aserver, hoststr) :
6078 hostutil_GetNameByINet(aserver), pname);
6080 " VLDB reports its RO volume ID is %u\n",
6081 entry.volumeId[ROVOL]);
6084 /* The RO volume ID in the volume header match that in the VLDB entry,
6085 * and there exist RO volumes in the VLDB entry. See if any of them
6086 * are this one. If not, then we add it.
6088 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6090 idx = entry.nServers;
6098 entry.flags |= RO_EXISTS;
6099 entry.volumeId[RWVOL] = rwvolid;
6100 entry.volumeId[ROVOL] = volumeinfo->volid;
6102 entry.serverNumber[idx] = aserver;
6103 entry.serverPartition[idx] = apart;
6104 entry.serverFlags[idx] = ITSROVOL;
6110 /* Remember largest volume id */
6111 if (entry.volumeId[ROVOL] > *maxvolid)
6112 *maxvolid = entry.volumeId[ROVOL];
6113 if (entry.volumeId[BACKVOL] > *maxvolid)
6114 *maxvolid = entry.volumeId[BACKVOL];
6115 if (entry.volumeId[RWVOL] > *maxvolid)
6116 *maxvolid = entry.volumeId[RWVOL];
6118 if (modified && doit) {
6119 MapNetworkToHost(&entry, &storeEntry);
6122 code = VLDB_CreateEntry(&storeEntry);
6125 "Could not create a VLDB entry for the volume %lu\n",
6126 (unsigned long)rwvolid);
6133 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6134 LOCKREL_OPCODE | LOCKREL_AFSID |
6137 fprintf(STDERR, "Could not update entry for %lu\n",
6138 (unsigned long)rwvolid);
6142 } else if (pass == 2) {
6144 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6145 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6147 PrintError("Could not unlock VLDB entry ", code);
6151 if (modified && modentry) {
6156 memcpy(aentry, &entry, sizeof(entry));
6160 fprintf(STDOUT, "-- status after --\n");
6162 EnumerateEntry(&entry);
6164 fprintf(STDOUT, "\n**no change**\n");
6168 VPRINT("\n_______________________________\n");
6173 sortVolumes(const void *a, const void *b)
6175 volintInfo *v1 = (volintInfo *) a;
6176 volintInfo *v2 = (volintInfo *) b;
6177 afs_uint32 rwvolid1, rwvolid2;
6179 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6180 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6182 if (rwvolid1 > rwvolid2)
6183 return -1; /* lower RW id goes first */
6184 if (rwvolid1 < rwvolid2)
6187 if (v1->type == RWVOL)
6188 return -1; /* RW vols go first */
6189 if (v2->type == RWVOL)
6192 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6193 return -1; /* BK vols next */
6194 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6197 if (v1->volid < v2->volid)
6198 return 1; /* larger volids first */
6199 if (v1->volid > v2->volid)
6205 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6206 * Synchronize an individual volume against a sever and partition.
6207 * Checks the VLDB entry (similar to syncserv) as well as checks
6208 * if the volume exists on specified servers (similar to syncvldb).
6211 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6213 struct rx_connection *aconn = 0;
6214 afs_int32 j, k, code, vcode, error = 0;
6216 afs_int32 mod, modified = 0, deleted = 0;
6217 struct nvldbentry vldbentry;
6218 afs_uint32 volumeid = 0;
6219 volEntries volumeInfo;
6220 struct partList PartList;
6222 afs_uint32 maxvolid = 0;
6224 volumeInfo.volEntries_val = (volintInfo *) 0;
6225 volumeInfo.volEntries_len = 0;
6227 /* Turn verbose logging off and do our own verbose logging */
6228 /* tverbose must be set before we call ERROR_EXIT() */
6235 if (!aserver && (flags & 1)) {
6236 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6240 /* Read the VLDB entry */
6241 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6242 if (vcode && (vcode != VL_NOENT)) {
6243 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6246 } else if (!vcode) {
6247 MapHostToNetwork(&vldbentry);
6251 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6252 fprintf(STDOUT, "_______________________________\n");
6253 fprintf(STDOUT, "\n-- status before -- \n");
6255 fprintf(STDOUT, "\n**does not exist**\n");
6257 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
6258 || (vldbentry.flags & BACK_EXISTS))
6259 EnumerateEntry(&vldbentry);
6261 fprintf(STDOUT, "\n");
6264 /* Verify that all of the VLDB entries exist on the repective servers
6265 * and partitions (this does not require that avolname be a volume ID).
6266 * Equivalent to a syncserv.
6269 /* Tell CheckVldb not to update if appropriate */
6274 code = CheckVldb(&vldbentry, &mod, &deleted);
6276 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6284 /* If aserver is given, we will search for the desired volume on it */
6286 /* Generate array of partitions on the server that we will check */
6288 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6291 "Could not fetch the list of partitions from the server\n");
6295 PartList.partId[0] = apart;
6299 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6301 /* If a volume ID were given, search for it on each partition */
6302 if ((volumeid = atol(avolname))) {
6303 for (j = 0; j < pcnt; j++) {
6305 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6308 if (code != ENODEV) {
6309 fprintf(STDERR, "Could not query server\n");
6317 /* Found one, sync it with VLDB entry */
6319 CheckVolume(volumeInfo.volEntries_val, aserver,
6320 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6327 if (volumeInfo.volEntries_val)
6328 free(volumeInfo.volEntries_val);
6329 volumeInfo.volEntries_val = (volintInfo *) 0;
6330 volumeInfo.volEntries_len = 0;
6334 /* Check to see if the RW, BK, and RO IDs exist on any
6335 * partitions. We get the volume IDs from the VLDB.
6337 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6338 if (vldbentry.volumeId[j] == 0)
6341 for (k = 0; k < pcnt; k++) { /* For each partition */
6342 volumeInfo.volEntries_val = (volintInfo *) 0;
6343 volumeInfo.volEntries_len = 0;
6345 AFSVolListOneVolume(aconn, PartList.partId[k],
6346 vldbentry.volumeId[j], &volumeInfo);
6348 if (code != ENODEV) {
6349 fprintf(STDERR, "Could not query server\n");
6357 /* Found one, sync it with VLDB entry */
6359 CheckVolume(volumeInfo.volEntries_val, aserver,
6360 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6367 if (volumeInfo.volEntries_val)
6368 free(volumeInfo.volEntries_val);
6369 volumeInfo.volEntries_val = (volintInfo *) 0;
6370 volumeInfo.volEntries_len = 0;
6376 /* If verbose output, print a summary of what changed */
6378 fprintf(STDOUT, "-- status after --\n");
6380 fprintf(STDOUT, "\n**entry deleted**\n");
6381 } else if (modified) {
6382 EnumerateEntry(&vldbentry);
6384 fprintf(STDOUT, "\n**no change**\n");
6386 fprintf(STDOUT, "\n_______________________________\n");
6390 /* Now check if the maxvolid is larger than that stored in the VLDB */
6392 afs_uint32 maxvldbid = 0;
6393 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6396 "Could not get the highest allocated volume id from the VLDB\n");
6399 } else if (maxvolid > maxvldbid) {
6401 id = maxvolid - maxvldbid + 1;
6402 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6405 "Error in increasing highest allocated volume id in VLDB\n");
6415 fprintf(STDOUT, "...error encountered");
6417 fprintf(STDOUT, "...done entry\n");
6420 rx_DestroyConnection(aconn);
6421 if (volumeInfo.volEntries_val)
6422 free(volumeInfo.volEntries_val);
6424 PrintError("", error);
6429 * Synchronise vldb with the file server <aserver> and,
6430 * optionally, <apart>.
6433 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6435 struct rx_connection *aconn;
6436 afs_int32 code, error = 0;
6439 volEntries volumeInfo;
6440 struct partList PartList;
6444 afs_int32 failures = 0, modifications = 0, tentries = 0;
6446 afs_uint32 maxvolid = 0;
6449 volumeInfo.volEntries_val = (volintInfo *) 0;
6450 volumeInfo.volEntries_len = 0;
6452 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6454 /* Generate array of partitions to check */
6456 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6459 "Could not fetch the list of partitions from the server\n");
6463 PartList.partId[0] = apart;
6467 VPRINT("Processing volume entries ...\n");
6469 /* Step through the array of partitions */
6470 for (i = 0; i < pcnt; i++) {
6471 apart = PartList.partId[i];
6472 MapPartIdIntoName(apart, pname);
6474 volumeInfo.volEntries_val = (volintInfo *) 0;
6475 volumeInfo.volEntries_len = 0;
6476 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6479 "Could not fetch the list of volumes from the server\n");
6483 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6484 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6485 sizeof(volintInfo), sortVolumes);
6488 for (vi = volumeInfo.volEntries_val, j = 0;
6489 j < volumeInfo.volEntries_len; j++, vi++) {
6497 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6498 j + 1, vi->name, (unsigned long)vi->volid,
6500 afs_inet_ntoa_r(aserver, hoststr) :
6501 hostutil_GetNameByINet(aserver), pname);
6509 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6511 PrintError("", code);
6514 } else if (modified) {
6520 fprintf(STDOUT, "...error encountered\n\n");
6522 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6529 "Could not process entries on server %s partition %s\n",
6531 afs_inet_ntoa_r(aserver, hoststr) :
6532 hostutil_GetNameByINet(aserver), pname);
6534 if (volumeInfo.volEntries_val) {
6535 free(volumeInfo.volEntries_val);
6536 volumeInfo.volEntries_val = 0;
6539 } /* thru all partitions */
6542 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6543 tentries, failures, modifications);
6545 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6546 tentries, failures, modifications);
6550 /* Now check if the maxvolid is larger than that stored in the VLDB */
6552 afs_uint32 maxvldbid = 0;
6553 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6556 "Could not get the highest allocated volume id from the VLDB\n");
6559 } else if (maxvolid > maxvldbid) {
6561 id = maxvolid - maxvldbid + 1;
6562 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6565 "Error in increasing highest allocated volume id in VLDB\n");
6573 rx_DestroyConnection(aconn);
6574 if (volumeInfo.volEntries_val)
6575 free(volumeInfo.volEntries_val);
6576 PrintError("", error);
6581 * Determine if a volume exists on a server and partition.
6582 * Try creating a transaction on the volume. If we can,
6583 * the volume exists, if not, then return the error code.
6584 * Some error codes mean the volume is unavailable but
6585 * still exists - so we catch these error codes.
6588 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6590 struct rx_connection *conn = (struct rx_connection *)0;
6591 afs_int32 code = -1;
6592 volEntries volumeInfo;
6594 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6596 volumeInfo.volEntries_val = (volintInfo *) 0;
6597 volumeInfo.volEntries_len = 0;
6598 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6599 if (volumeInfo.volEntries_val)
6600 free(volumeInfo.volEntries_val);
6601 if (code == VOLSERILLEGAL_PARTITION)
6603 rx_DestroyConnection(conn);
6612 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6616 afs_int32 code, error = 0;
6622 idx = Lp_GetRwIndex(entry);
6624 /* Check to see if the RW volume exists and set the RW_EXISTS
6627 if (idx == -1) { /* Did not find a RW entry */
6628 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6629 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6634 VolumeExists(entry->serverNumber[idx],
6635 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6636 if (code == 0) { /* RW volume exists */
6637 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6638 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6641 } else if (code == ENODEV) { /* RW volume does not exist */
6642 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6643 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6647 /* If VLDB says it didn't exist, then ignore error */
6648 if (entry->flags & RW_EXISTS) {
6649 MapPartIdIntoName(entry->serverPartition[idx], pname);
6651 "Transaction call failed for RW volume %u on server %s %s\n",
6652 entry->volumeId[RWVOL],
6654 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6655 hostutil_GetNameByINet(entry->serverNumber[idx]),
6662 /* Check to see if the BK volume exists and set the BACK_EXISTS
6663 * flag accordingly. idx already ponts to the RW entry.
6665 if (idx == -1) { /* Did not find a RW entry */
6666 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6667 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6670 } else { /* Found a RW entry */
6672 VolumeExists(entry->serverNumber[idx],
6673 entry->serverPartition[idx],
6674 entry->volumeId[BACKVOL]);
6675 if (code == 0) { /* BK volume exists */
6676 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6677 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6680 } else if (code == ENODEV) { /* BK volume does not exist */
6681 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6682 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6686 /* If VLDB says it didn't exist, then ignore error */
6687 if (entry->flags & BACK_EXISTS) {
6688 MapPartIdIntoName(entry->serverPartition[idx], pname);
6690 "Transaction call failed for BK volume %u on server %s %s\n",
6691 entry->volumeId[BACKVOL],
6693 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6694 hostutil_GetNameByINet(entry->serverNumber[idx]),
6701 /* If there is an idx but the BK and RW volumes no
6702 * longer exist, then remove the RW entry.
6704 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6705 && !(entry->flags & BACK_EXISTS)) {
6706 Lp_SetRWValue(entry, entry->serverNumber[idx],
6707 entry->serverPartition[idx], 0L, 0L);
6714 *modified = modentry;
6719 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6722 int foundro = 0, modentry = 0;
6723 afs_int32 code, error = 0;
6730 /* Check to see if the RO volumes exist and set the RO_EXISTS
6733 for (idx = 0; idx < entry->nServers; idx++) {
6734 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6735 continue; /* not a RO */
6739 VolumeExists(entry->serverNumber[idx],
6740 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6741 if (code == 0) { /* RO volume exists */
6743 } else if (code == ENODEV) { /* RW volume does not exist */
6744 Lp_SetROValue(entry, entry->serverNumber[idx],
6745 entry->serverPartition[idx], 0L, 0L);
6750 MapPartIdIntoName(entry->serverPartition[idx], pname);
6752 "Transaction call failed for RO %u on server %s %s\n",
6753 entry->volumeId[ROVOL],
6755 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6756 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6761 if (foundro) { /* A RO volume exists */
6762 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6763 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6766 } else { /* A RO volume does not exist */
6767 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6768 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6775 *modified = modentry;
6780 * Ensure that <entry> matches with the info on file servers
6783 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6785 afs_int32 code, error = 0;
6786 struct nvldbentry storeEntry;
6787 int islocked = 0, mod, modentry, delentry = 0;
6788 int pass = 0, doit=1;
6796 fprintf(STDOUT, "_______________________________\n");
6797 fprintf(STDOUT, "\n-- status before -- \n");
6798 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6799 || (entry->flags & BACK_EXISTS))
6800 EnumerateEntry(entry);
6801 fprintf(STDOUT, "\n");
6804 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6805 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6806 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6810 /* Check to see if the VLDB is ok without locking it (pass 1).
6811 * If it will change, then lock the VLDB entry, read it again,
6812 * then make the changes to it (pass 2).
6816 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6819 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6820 entry->volumeId[RWVOL]);
6825 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6827 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6831 MapHostToNetwork(entry);
6837 /* Check if the RW and BK entries are ok */
6838 code = CheckVldbRWBK(entry, &mod);
6841 if (mod && (pass == 1) && doit)
6846 /* Check if the RO volumes entries are ok */
6847 code = CheckVldbRO(entry, &mod);
6850 if (mod && (pass == 1) && doit)
6855 /* The VLDB entry has been updated. If it as been modified, then
6856 * write the entry back out the the VLDB.
6858 if (modentry && doit) {
6862 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6863 && !(entry->flags & RO_EXISTS) && doit) {
6864 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6866 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6870 "Could not delete VLDB entry for volume %u \n",
6871 entry->volumeId[RWVOL]);
6876 /* Replace old entry with our new one */
6877 MapNetworkToHost(entry, &storeEntry);
6879 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6880 (LOCKREL_OPCODE | LOCKREL_AFSID |
6881 LOCKREL_TIMESTAMP));
6883 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6884 entry->volumeId[RWVOL]);
6891 if (modified && modentry) {
6894 if (deleted && delentry) {
6899 fprintf(STDOUT, "-- status after --\n");
6901 fprintf(STDOUT, "\n**entry deleted**\n");
6903 EnumerateEntry(entry);
6905 fprintf(STDOUT, "\n**no change**\n");
6909 VPRINT("\n_______________________________\n");
6913 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6915 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6918 "Could not release lock on VLDB entry for volume %u\n",
6919 entry->volumeId[RWVOL]);
6928 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6931 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6933 struct rx_connection *aconn;
6934 afs_int32 code, error = 0;
6935 afs_int32 nentries, tentries = 0;
6936 struct VldbListByAttributes attributes;
6937 nbulkentries arrayEntries;
6938 afs_int32 failures = 0, modified, modifications = 0;
6939 struct nvldbentry *vlentry;
6940 afs_int32 si, nsi, j;
6945 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6947 /* Set up attributes to search VLDB */
6948 attributes.server = ntohl(aserver);
6949 attributes.Mask = VLLIST_SERVER;
6951 attributes.partition = apart;
6952 attributes.Mask |= VLLIST_PARTITION;
6955 VPRINT("Processing VLDB entries ...\n");
6957 /* While we need to collect more VLDB entries */
6958 for (si = 0; si != -1; si = nsi) {
6959 memset(&arrayEntries, 0, sizeof(arrayEntries));
6961 /* Collect set of VLDB entries */
6963 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6964 &arrayEntries, &nsi);
6965 if (code == RXGEN_OPCODE) {
6966 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6970 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6973 tentries += nentries;
6975 for (j = 0; j < nentries; j++) {
6976 vlentry = &arrayEntries.nbulkentries_val[j];
6977 MapHostToNetwork(vlentry);
6979 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6981 /* Tell CheckVldb not to update if appropriate */
6986 code = CheckVldb(vlentry, &modified, NULL);
6988 PrintError("", code);
6990 "Could not process VLDB entry for volume %s\n",
6993 } else if (modified) {
6999 fprintf(STDOUT, "...error encountered\n\n");
7001 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
7006 if (arrayEntries.nbulkentries_val) {
7007 free(arrayEntries.nbulkentries_val);
7008 arrayEntries.nbulkentries_val = 0;
7013 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
7014 tentries, failures, modifications);
7016 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
7017 tentries, failures, modifications);
7022 rx_DestroyConnection(aconn);
7023 if (arrayEntries.nbulkentries_val)
7024 free(arrayEntries.nbulkentries_val);
7027 error = VOLSERFAILEDOP;
7031 /*rename volume <oldname> to <newname>, changing the names of the related
7032 *readonly and backup volumes. This operation is also idempotent.
7033 *salvager is capable of recovering from rename operation stopping halfway.
7034 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
7036 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
7038 struct nvldbentry storeEntry;
7039 afs_int32 vcode, code, rcode, error;
7041 char nameBuffer[256];
7043 struct rx_connection *aconn;
7048 aconn = (struct rx_connection *)0;
7052 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7055 " Could not lock the VLDB entry for the volume %u \n",
7056 entry->volumeId[RWVOL]);
7061 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7062 MapNetworkToHost(entry, &storeEntry);
7063 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7065 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7066 entry->volumeId[RWVOL]);
7070 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7071 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7072 * is concerned, oldname is lost */
7073 if (entry->flags & RW_EXISTS) {
7074 index = Lp_GetRwIndex(entry);
7075 if (index == -1) { /* there is a serious discrepancy */
7077 "There is a serious discrepancy in VLDB entry for volume %u\n",
7078 entry->volumeId[RWVOL]);
7079 fprintf(STDERR, "try building VLDB from scratch\n");
7080 error = VOLSERVLDB_ERROR;
7083 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7085 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7086 entry->serverPartition[index], ITOffline, &tid);
7087 if (code) { /*volume doesnot exist */
7089 "Could not start transaction on the rw volume %u\n",
7090 entry->volumeId[RWVOL]);
7093 } else { /*volume exists, process it */
7096 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7097 entry->volumeId[RWVOL],
7098 entry->volumeId[ROVOL],
7099 entry->volumeId[BACKVOL]);
7101 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7102 code = AFSVolEndTrans(aconn, tid, &rcode);
7106 "Could not end transaction on volume %s %u\n",
7107 entry->name, entry->volumeId[RWVOL]);
7112 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7113 entry->name, entry->volumeId[RWVOL]);
7119 rx_DestroyConnection(aconn);
7120 aconn = (struct rx_connection *)0;
7122 /*end rw volume processing */
7123 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
7124 index = Lp_GetRwIndex(entry);
7125 if (index == -1) { /* there is a serious discrepancy */
7127 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7128 entry->volumeId[BACKVOL]);
7129 fprintf(STDERR, "try building VLDB from scratch\n");
7130 error = VOLSERVLDB_ERROR;
7133 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7135 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7136 entry->serverPartition[index], ITOffline, &tid);
7137 if (code) { /*volume doesnot exist */
7139 "Could not start transaction on the backup volume %u\n",
7140 entry->volumeId[BACKVOL]);
7143 } else { /*volume exists, process it */
7144 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7146 "Volume name %s.backup exceeds the limit of %u characters\n",
7147 newname, VOLSER_OLDMAXVOLNAME);
7151 strcpy(nameBuffer, newname);
7152 strcat(nameBuffer, ".backup");
7155 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7156 entry->volumeId[RWVOL], 0, 0);
7158 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7159 code = AFSVolEndTrans(aconn, tid, &rcode);
7163 "Could not end transaction on the backup volume %u\n",
7164 entry->volumeId[BACKVOL]);
7170 "Could not set parameters on the backup volume %u\n",
7171 entry->volumeId[BACKVOL]);
7176 } /* end backup processing */
7178 rx_DestroyConnection(aconn);
7179 aconn = (struct rx_connection *)0;
7180 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
7181 for (i = 0; i < entry->nServers; i++) {
7182 if (entry->serverFlags[i] & ITSROVOL) {
7183 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7185 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7186 entry->serverPartition[i], ITOffline,
7188 if (code) { /*volume doesnot exist */
7190 "Could not start transaction on the ro volume %u\n",
7191 entry->volumeId[ROVOL]);
7194 } else { /*volume exists, process it */
7195 strcpy(nameBuffer, newname);
7196 strcat(nameBuffer, ".readonly");
7197 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7199 "Volume name %s exceeds the limit of %u characters\n",
7200 nameBuffer, VOLSER_OLDMAXVOLNAME);
7205 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7206 entry->volumeId[RWVOL], 0, 0);
7208 VPRINT2("Renamed RO volume %s on host %s\n",
7211 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7212 hostutil_GetNameByINet(entry->
7214 code = AFSVolEndTrans(aconn, tid, &rcode);
7218 "Could not end transaction on volume %u\n",
7219 entry->volumeId[ROVOL]);
7225 "Could not set parameters on the ro volume %u\n",
7226 entry->volumeId[ROVOL]);
7232 rx_DestroyConnection(aconn);
7233 aconn = (struct rx_connection *)0;
7240 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7242 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7245 "Could not unlock the VLDB entry for the volume %s %u\n",
7246 entry->name, entry->volumeId[RWVOL]);
7252 code = AFSVolEndTrans(aconn, tid, &rcode);
7256 fprintf(STDERR, "Failed to end transaction on a volume \n");
7262 rx_DestroyConnection(aconn);
7263 PrintError("", error);
7268 /*report on all the active transactions on volser */
7270 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7272 struct rx_connection *aconn;
7273 transDebugEntries transInfo;
7276 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7277 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7278 transInfo.transDebugEntries_len = 0;
7279 code = AFSVolMonitor(aconn, &transInfo);
7282 "Could not access status information about the server\n");
7283 PrintError("", code);
7284 if (transInfo.transDebugEntries_val)
7285 free(transInfo.transDebugEntries_val);
7287 rx_DestroyConnection(aconn);
7290 *rcount = transInfo.transDebugEntries_len;
7291 *rpntr = transInfo.transDebugEntries_val;
7293 rx_DestroyConnection(aconn);
7300 /*delete the volume without interacting with the vldb */
7302 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7305 struct rx_connection *aconn;
7307 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7308 error = DoVolDelete(aconn, volid, part,
7309 "the", 0, NULL, NULL);
7310 if (error == VNOVOL) {
7311 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7314 PrintError("", error);
7316 rx_DestroyConnection(aconn);
7321 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7322 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7324 struct rx_connection *conn = 0;
7326 afs_int32 code, error = 0, rcode;
7328 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7330 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7334 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7336 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7340 code = AFSVolSetFlags(conn, tid, setflag);
7342 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7347 #ifdef AFS_PTHREAD_ENV
7350 IOMGR_Sleep(sleeptime);
7357 code = AFSVolEndTrans(conn, tid, &rcode);
7358 if (code || rcode) {
7359 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7361 error = (code ? code : rcode);
7366 rx_DestroyConnection(conn);
7371 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7374 struct rx_connection *conn = 0;
7376 afs_int32 code, error = 0, rcode;
7378 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7380 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7384 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7386 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7390 code = AFSVolSetInfo(conn, tid, infop);
7392 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7399 code = AFSVolEndTrans(conn, tid, &rcode);
7400 if (code || rcode) {
7401 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7403 error = (code ? code : rcode);
7408 rx_DestroyConnection(conn);
7413 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7414 afs_int32 fromdate, struct volintSize *vol_size)
7416 struct rx_connection *aconn = (struct rx_connection *)0;
7417 afs_int32 tid = 0, rcode = 0;
7418 afs_int32 code, error = 0;
7421 /* get connections to the servers */
7422 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7424 VPRINT1("Starting transaction on volume %u...", afromvol);
7425 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7426 EGOTO1(error_exit, code,
7427 "Could not start transaction on the volume %u to be measured\n",
7431 VPRINT1("Getting size of volume on volume %u...", afromvol);
7432 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7433 EGOTO(error_exit, code, "Could not start the measurement process \n");
7438 VPRINT1("Ending transaction on volume %u...", afromvol);
7439 code = AFSVolEndTrans(aconn, tid, &rcode);
7440 if (code || rcode) {
7441 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7443 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7445 error = (code ? code : rcode);
7450 rx_DestroyConnection(aconn);
7452 PrintError("", error);
7456 /*maps the host addresses in <old > (present in network byte order) to
7457 that in< new> (present in host byte order )*/
7459 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7463 /*copy all the fields */
7464 strcpy(new->name, old->name);
7465 /* new->volumeType = old->volumeType;*/
7466 new->nServers = old->nServers;
7467 count = old->nServers;
7468 if (count < NMAXNSERVERS)
7470 for (i = 0; i < count; i++) {
7471 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7472 new->serverPartition[i] = old->serverPartition[i];
7473 new->serverFlags[i] = old->serverFlags[i];
7475 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7476 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7477 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7478 new->cloneId = old->cloneId;
7479 new->flags = old->flags;
7482 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7484 MapHostToNetwork(struct nvldbentry *entry)
7488 count = entry->nServers;
7489 if (count < NMAXNSERVERS)
7491 for (i = 0; i < count; i++) {
7492 entry->serverNumber[i] = htonl(entry->serverNumber[i]);