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 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1178 code = AFSVolGetStatus(aconn, ttid, volstatus);
1179 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1184 AFSVolSetFlags(aconn, ttid,
1185 VTDeleteOnSalvage | VTOutOfService);
1187 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1191 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1192 AFSVolSetForwarding(aconn, ttid, atoserver);
1196 code = AFSVolDeleteVolume(aconn, ttid);
1197 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1201 code = AFSVolEndTrans(aconn, ttid, &rcode);
1206 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1207 prefix, typestring, (unsigned long)avolid);
1213 if (beverbose && !error)
1219 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1220 afs_int32 apart, int type, afs_uint32 cloneid,
1221 char *typestring, char *pname, char *vname, char *suffix,
1222 struct volser_status *volstatus, afs_int32 *transPtr)
1225 afs_int32 ttid = 0, btid = 0;
1226 afs_int32 code = 0, rcode = 0;
1227 afs_int32 error = 0;
1228 int cloneexists = 1;
1230 /* Test to see if the clone volume exists by trying to create
1231 * a transaction on the clone volume. We've assumed the clone exists.
1233 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1235 if (code != VNOVOL) {
1236 EPRINT2(code, "Could not reach the %s volume %lu\n",
1237 typestring, (unsigned long)cloneid);
1241 cloneexists = 0; /* clone volume does not exist */
1244 code = AFSVolEndTrans(aconn, btid, &rcode);
1246 if (code || rcode) {
1248 "Could not end transaction on the previous %s volume %lu\n",
1249 typestring, (unsigned long)cloneid);
1250 error = (code ? code : rcode);
1255 /* Now go ahead and try to clone the RW volume.
1256 * First start a transaction on the RW volume
1258 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1260 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1261 (unsigned long)avolid);
1266 /* Clone or reclone the volume, depending on whether the clone
1267 * volume exists or not
1270 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1272 code = AFSVolReClone(aconn, ttid, cloneid);
1274 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1275 typestring, (unsigned long)cloneid);
1280 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1283 strcpy(cname, pname);
1284 strcat(cname, suffix);
1287 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1290 fprintf(STDERR, "Failed to clone the volume %lu\n",
1291 (unsigned long)avolid);
1300 VPRINT1("Getting status of parent volume %u...", avolid);
1301 code = AFSVolGetStatus(aconn, ttid, volstatus);
1303 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1304 (unsigned long)avolid);
1313 code = AFSVolEndTrans(aconn, ttid, &rcode);
1314 if (code || rcode) {
1315 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1316 (unsigned long)avolid);
1318 error = (code ? code : rcode);
1323 code = AFSVolEndTrans(aconn, btid, &rcode);
1324 if (code || rcode) {
1326 "Could not end transaction on the %s volume %lu\n",
1327 typestring, (unsigned long)cloneid);
1329 error = (code ? code : rcode);
1335 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1336 * <atopart>. The operation is almost idempotent. The following
1337 * flags are recognized:
1339 * RV_NOCLONE - don't use a copy clone
1343 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1344 afs_uint32 atoserver, afs_int32 atopart, int flags)
1346 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1347 * be changing during the move */
1348 struct rx_connection * volatile toconn;
1349 struct rx_connection * volatile fromconn;
1350 afs_int32 volatile fromtid;
1351 afs_int32 volatile totid;
1352 afs_int32 volatile clonetid;
1353 afs_uint32 volatile newVol;
1354 afs_uint32 volatile volid;
1355 afs_uint32 volatile backupId;
1356 int volatile islocked;
1361 char tmpName[VOLSER_MAXVOLNAME + 1];
1366 struct restoreCookie cookie;
1367 afs_int32 vcode, code;
1368 struct volser_status tstatus;
1369 struct destServer destination;
1371 struct nvldbentry entry, storeEntry;
1374 char in, lf; /* for test code */
1378 #ifdef ENABLE_BUGFIX_1165
1379 volEntries volumeInfo;
1380 struct volintInfo *infop = 0;
1384 fromconn = (struct rx_connection *)0;
1385 toconn = (struct rx_connection *)0;
1395 /* support control-c processing */
1398 (void)signal(SIGINT, sigint_handler);
1402 "\nThere are three tests points - verifies all code paths through recovery.\n");
1403 fprintf(STDOUT, "First test point - operation not started.\n");
1404 fprintf(STDOUT, "...test here (y, n)? ");
1406 fscanf(stdin, "%c", &in);
1407 fscanf(stdin, "%c", &lf); /* toss away */
1409 fprintf(STDOUT, "type control-c\n");
1411 fprintf(stdout, ".");
1416 /* or drop through */
1419 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1420 EGOTO1(mfail, vcode,
1421 "Could not fetch the entry for the volume %u from the VLDB \n",
1424 if (entry.volumeId[RWVOL] != afromvol) {
1425 fprintf(STDERR, "Only RW volume can be moved\n");
1429 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1430 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1433 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1434 EGOTO1(mfail, vcode,
1435 "Could not fetch the entry for the volume %u from the VLDB \n",
1438 backupId = entry.volumeId[BACKVOL];
1439 MapHostToNetwork(&entry);
1441 if (!Lp_Match(afromserver, afrompart, &entry)) {
1442 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1443 if (!Lp_Match(atoserver, atopart, &entry)) {
1444 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1445 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1446 (unsigned long)afromvol);
1447 fprintf(STDERR, "The current site is :");
1448 for (i = 0; i < entry.nServers; i++) {
1449 if (entry.serverFlags[i] == ITSRWVOL) {
1451 MapPartIdIntoName(entry.serverPartition[i], pname);
1452 fprintf(STDERR, " server %s partition %s \n",
1453 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1454 hostutil_GetNameByINet(entry.serverNumber[i]),
1459 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1460 (LOCKREL_OPCODE | LOCKREL_AFSID |
1461 LOCKREL_TIMESTAMP));
1462 EGOTO1(mfail, vcode,
1463 " Could not release lock on the VLDB entry for the volume %u \n",
1466 return VOLSERVOLMOVED;
1469 /* delete the volume afromvol on src_server */
1470 /* from-info does not exist but to-info does =>
1471 * we have already done the move, but the volume
1472 * may still be existing physically on from fileserver
1474 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1477 code = DoVolDelete(fromconn, afromvol, afrompart,
1478 "leftover", 0, NULL, NULL);
1479 if (code && code != VNOVOL) {
1484 code = DoVolDelete(fromconn, backupId, afrompart,
1485 "leftover backup", 0, NULL, NULL);
1486 if (code && code != VNOVOL) {
1496 /* From-info matches the vldb info about volid,
1497 * its ok start the move operation, the backup volume
1498 * on the old site is deleted in the process
1500 if (afrompart == atopart) {
1501 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1502 EGOTO2(mfail, error,
1503 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1504 afromserver, error);
1507 EGOTO1(mfail, VOLSERVOLMOVED,
1508 "Warning: Moving volume %u to its home partition ignored!\n",
1514 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1515 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1516 fromtid = totid = 0; /* initialize to uncreated */
1519 * clone the read/write volume locally.
1522 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1523 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1525 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1529 if (!(flags & RV_NOCLONE)) {
1530 /* Get a clone id */
1531 VPRINT1("Allocating new volume id for clone of volume %u ...",
1534 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1536 EGOTO1(mfail, vcode,
1537 "Could not get an ID for the clone of volume %u from the VLDB\n",
1541 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1542 VPRINT1("Cloning source volume %u ...", afromvol);
1543 strcpy(vname, "move-clone-temp");
1545 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1547 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1552 /* lookup the name of the volume we just cloned */
1554 code = AFSVolGetName(fromconn, fromtid, &volName);
1555 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1558 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1560 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1565 "Failed to end the transaction on the source volume %u\n",
1570 * Create the destination volume
1573 if (!(flags & RV_NOCLONE)) {
1574 /* All of this is to get the fromDate */
1575 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1578 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1582 "Failed to start a transaction on the cloned volume%u\n",
1586 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1588 AFSVolSetFlags(fromconn, clonetid,
1589 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1590 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1594 /* remember time from which we've dumped the volume */
1595 VPRINT1("Getting status of cloned volume %u ...", newVol);
1596 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1598 "Failed to get the status of the cloned volume %u\n",
1602 fromDate = CLOCKADJ(tstatus.creationDate);
1604 /* With RV_NOCLONE, just do a full copy from the source */
1609 #ifdef ENABLE_BUGFIX_1165
1611 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1612 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1613 * don't use this information...
1615 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1616 volumeInfo.volEntries_len = 0;
1617 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1619 "Failed to get the volint Info of the cloned volume %u\n",
1622 infop = (volintInfo *) volumeInfo.volEntries_val;
1623 infop->maxquota = -1; /* Else it will replace the default quota */
1624 infop->creationDate = -1; /* Else it will use the source creation date */
1625 infop->updateDate = -1; /* Else it will use the source update date */
1628 /* create a volume on the target machine */
1630 code = DoVolDelete(toconn, volid, atopart,
1631 "pre-existing destination", 0, NULL, NULL);
1632 if (code && code != VNOVOL) {
1637 VPRINT1("Creating the destination volume %u ...", volid);
1641 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1645 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1649 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1653 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1655 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1657 "Failed to set the flags on the destination volume %u\n", volid);
1661 * Now dump the clone to the new volume
1664 destination.destHost = ntohl(atoserver);
1665 destination.destPort = AFSCONF_VOLUMEPORT;
1666 destination.destSSID = 1;
1668 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1669 cookie.type = RWVOL;
1670 cookie.parent = entry.volumeId[RWVOL];
1673 if (!(flags & RV_NOCLONE)) {
1674 /* Copy the clone to the new volume */
1675 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1678 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1680 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1683 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1684 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1689 "Failed to end the transaction on the cloned volume %u\n",
1695 * reattach to the main-line volume, and incrementally dump it.
1698 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1700 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1703 "Failed to create a transaction on the source volume %u\n",
1707 /* now do the incremental */
1709 ("Doing the%s dump from source to destination for volume %u ... ",
1710 (flags & RV_NOCLONE) ? "" : " incremental",
1713 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1716 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1717 (flags & RV_NOCLONE) ? "" : " incremental");
1720 /* now adjust the flags so that the new volume becomes official */
1721 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1722 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1724 "Failed to set the flags to make old source volume offline\n");
1727 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1728 code = AFSVolSetFlags(toconn, totid, 0);
1730 "Failed to set the flags to make new source volume online\n");
1733 #ifdef ENABLE_BUGFIX_1165
1734 VPRINT1("Setting volume status on destination volume %u ...", volid);
1735 code = AFSVolSetInfo(toconn, totid, infop);
1737 "Failed to set volume status on the destination volume %u\n",
1742 /* put new volume online */
1743 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1744 code = AFSVolEndTrans(toconn, totid, &rcode);
1749 "Failed to end the transaction on the volume %u on the new site\n",
1753 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1754 MapNetworkToHost(&entry, &storeEntry);
1755 storeEntry.flags &= ~BACK_EXISTS;
1759 "Second test point - operation in progress but not complete.\n");
1760 fprintf(STDOUT, "...test here (y, n)? ");
1762 fscanf(stdin, "%c", &in);
1763 fscanf(stdin, "%c", &lf); /* toss away */
1765 fprintf(STDOUT, "type control-c\n");
1767 fprintf(stdout, ".");
1772 /* or drop through */
1775 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1777 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1778 (LOCKREL_OPCODE | LOCKREL_AFSID |
1779 LOCKREL_TIMESTAMP));
1782 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1783 storeEntry.name, (unsigned long)afromvol);
1792 "Third test point - operation complete but no cleanup.\n");
1793 fprintf(STDOUT, "...test here (y, n)? ");
1795 fscanf(stdin, "%c", &in);
1796 fscanf(stdin, "%c", &lf); /* toss away */
1798 fprintf(STDOUT, "type control-c\n");
1800 fprintf(stdout, ".");
1805 /* or drop through */
1808 /* This is tricky. File server is very stupid, and if you mark the volume
1809 * as VTOutOfService, it may mark the *good* instance (if you're moving
1810 * between partitions on the same machine) as out of service. Since
1811 * we're cleaning this code up in DEcorum, we're just going to kludge around
1812 * it for now by removing this call. */
1813 /* already out of service, just zap it now */
1815 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1818 "Failed to set the flags to make the old source volume offline\n");
1822 if (atoserver != afromserver) {
1823 /* set forwarding pointer for moved volumes */
1824 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1825 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1827 "Failed to set the forwarding pointer for the volume %u\n",
1832 VPRINT1("Deleting old volume %u on source ...", afromvol);
1833 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1834 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1838 VPRINT1("Ending transaction on old volume %u on the source ...",
1840 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1845 "Failed to end the transaction on the old volume %u on the source\n",
1849 code = DoVolDelete(fromconn, backupId, afrompart,
1850 "source backup", 0, NULL, NULL);
1851 if (code && code != VNOVOL) {
1856 code = 0; /* no backup volume? that's okay */
1859 if (!(flags & RV_NOCLONE)) {
1860 code = DoVolDelete(fromconn, newVol, afrompart,
1861 "cloned", 0, NULL, NULL);
1872 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1873 fprintf(STDOUT, "...test here (y, n)? ");
1875 fscanf(stdin, "%c", &in);
1876 fscanf(stdin, "%c", &lf); /* toss away */
1878 fprintf(STDOUT, "type control-c\n");
1880 fprintf(stdout, ".");
1885 /* or drop through */
1888 /* normal cleanup code */
1890 if (entry.flags & RO_EXISTS)
1891 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1894 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1896 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1897 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1901 " Could not release the lock on the VLDB entry for the volume %lu \n",
1902 (unsigned long)afromvol);
1910 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1912 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1913 if (code || rcode) {
1916 "Could not end transaction on the source volume %lu\n",
1917 (unsigned long)afromvol);
1919 error = (code ? code : rcode);
1925 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1926 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1927 if (code || rcode) {
1930 "Could not end transaction on the source's clone volume %lu\n",
1931 (unsigned long)newVol);
1933 error = (code ? code : rcode);
1939 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1941 code = AFSVolEndTrans(toconn, totid, &rcode);
1945 "Could not end transaction on destination volume %lu\n",
1946 (unsigned long)afromvol);
1948 error = (code ? code : rcode);
1954 #ifdef ENABLE_BUGFIX_1165
1959 rx_DestroyConnection(fromconn);
1961 rx_DestroyConnection(toconn);
1962 PrintError("", error);
1965 /* come here only when the sky falls */
1970 "vos move: operation interrupted, cleanup in progress...\n");
1971 fprintf(STDOUT, "clear transaction contexts\n");
1975 /* unlock VLDB entry */
1977 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1978 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1979 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1985 VPRINT("Recovery: Ending transaction on clone volume ...");
1986 AFSVolEndTrans(fromconn, clonetid, &rcode);
1990 VPRINT("Recovery: Ending transaction on destination volume ...");
1991 AFSVolEndTrans(toconn, totid, &rcode);
1994 if (fromtid) { /* put it on-line */
1995 VPRINT("Recovery: Setting volume flags on source volume ...");
1996 AFSVolSetFlags(fromconn, fromtid, 0);
1999 VPRINT("Recovery: Ending transaction on source volume ...");
2000 AFSVolEndTrans(fromconn, fromtid, &rcode);
2004 VPRINT("Recovery: Accessing VLDB.\n");
2005 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2007 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2011 MapHostToNetwork(&entry);
2013 /* Delete either the volume on the source location or the target location.
2014 * If the vldb entry still points to the source location, then we know the
2015 * volume move didn't finish so we remove the volume from the target
2016 * location. Otherwise, we remove the volume from the source location.
2018 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2021 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2025 if (volid && toconn)
2026 code = DoVolDelete(toconn, volid, atopart,
2027 "destination", 0, NULL, "Recovery:");
2029 /* put source volume on-line */
2031 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2035 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2041 VPRINT1("Recovery: Setting flags on source volume %u ...",
2043 AFSVolSetFlags(fromconn, fromtid, 0);
2047 ("Recovery: Ending transaction on source volume %u ...",
2049 AFSVolEndTrans(fromconn, fromtid, &rcode);
2053 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2057 } else { /* yep, move complete */
2060 "move complete - attempt cleanup of source partition - no guarantee\n");
2064 /* delete backup volume */
2066 code = DoVolDelete(fromconn, backupId, afrompart,
2067 "backup", 0, NULL, "Recovery:");
2069 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2070 (atoserver != afromserver)?atoserver:0,
2075 /* common cleanup - delete local clone */
2077 code = DoVolDelete(fromconn, newVol, afrompart,
2078 "clone", 0, NULL, "Recovery:");
2081 /* unlock VLDB entry */
2083 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2085 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2086 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2090 done: /* routine cleanup */
2093 #ifdef ENABLE_BUGFIX_1165
2098 rx_DestroyConnection(fromconn);
2100 rx_DestroyConnection(toconn);
2103 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2111 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2112 afs_uint32 atoserver, afs_int32 atopart)
2114 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2115 atoserver, atopart, 0);
2119 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2120 * <atopart>. The new volume is named by <atovolname>. The new volume
2121 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2122 * from the VLDB. the following flags are supported:
2124 * RV_RDONLY - target volume is RO
2125 * RV_OFFLINE - leave target volume offline
2126 * RV_CPINCR - do incremental dump if target exists
2127 * RV_NOVLDB - don't create/update VLDB entry
2128 * RV_NOCLONE - don't use a copy clone
2131 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2132 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2133 afs_uint32 atovolid, int flags)
2135 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2136 * be changing during the copy */
2138 afs_int32 volatile clonetid;
2139 afs_int32 volatile totid;
2140 afs_int32 volatile fromtid;
2141 struct rx_connection * volatile fromconn;
2142 struct rx_connection * volatile toconn;
2143 afs_uint32 volatile cloneVol;
2147 afs_int32 fromDate, cloneFromDate;
2148 struct restoreCookie cookie;
2149 afs_int32 vcode, code;
2152 struct volser_status tstatus;
2153 struct destServer destination;
2154 struct nvldbentry entry, newentry, storeEntry;
2159 fromconn = (struct rx_connection *)0;
2160 toconn = (struct rx_connection *)0;
2168 /* support control-c processing */
2171 (void)signal(SIGINT, sigint_handler);
2173 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2174 EGOTO1(mfail, vcode,
2175 "Could not fetch the entry for the volume %u from the VLDB \n",
2177 MapHostToNetwork(&entry);
2180 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2181 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2182 fromtid = totid = 0; /* initialize to uncreated */
2185 * clone the read/write volume locally.
2189 if (!(flags & RV_NOCLONE)) {
2190 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2192 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2195 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2199 /* Get a clone id */
2200 VPRINT1("Allocating new volume id for clone of volume %u ...",
2204 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2206 EGOTO1(mfail, vcode,
2207 "Could not get an ID for the clone of volume %u from the VLDB\n",
2215 /* Get a new volume id */
2216 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2218 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2219 EGOTO1(mfail, vcode,
2220 "Could not get an ID for the copy of volume %u from the VLDB\n",
2225 if (!(flags & RV_NOCLONE)) {
2226 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2227 VPRINT1("Cloning source volume %u ...", afromvol);
2228 strcpy(vname, "copy-clone-temp");
2231 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2234 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2238 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2240 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2245 "Failed to end the transaction on the source volume %u\n",
2251 * Create the destination volume
2254 if (!(flags & RV_NOCLONE)) {
2255 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2258 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2262 "Failed to start a transaction on the cloned volume%u\n",
2266 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2268 AFSVolSetFlags(fromconn, clonetid,
2269 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2270 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2274 /* remember time from which we've dumped the volume */
2275 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2276 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2278 "Failed to get the status of the cloned volume %u\n",
2282 fromDate = CLOCKADJ(tstatus.creationDate);
2287 /* create a volume on the target machine */
2290 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2293 if ((flags & RV_CPINCR)) {
2294 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2295 code = AFSVolGetStatus(toconn, totid, &tstatus);
2297 "Failed to get the status of the pre-existing volume %u\n",
2301 /* Using the update date should be OK here, but add some fudge */
2302 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2303 if ((flags & RV_NOCLONE))
2304 fromDate = cloneFromDate;
2306 /* XXX We should check that the source volume's creationDate is
2307 * XXX not newer than the existing target volume, and if not,
2308 * XXX throw away the existing target and do a full dump. */
2313 /* Delete the existing volume.
2314 * While we are deleting the volume in these steps, the transaction
2315 * we started against the cloned volume (clonetid above) will be
2316 * sitting idle. It will get cleaned up after 600 seconds
2318 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2319 code = AFSVolDeleteVolume(toconn, totid);
2321 "Could not delete the pre-existing volume %u on destination\n",
2326 ("Ending transaction on pre-existing volume %u on destination ...",
2328 code = AFSVolEndTrans(toconn, totid, &rcode);
2333 "Could not end the transaction on pre-existing volume %u on destination\n",
2338 VPRINT1("Creating the destination volume %u ...", newVol);
2341 AFSVolCreateVolume(toconn, atopart, atovolname,
2342 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2343 newVol, &newVol, &tmp);
2345 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2349 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2351 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2353 "Failed to set the flags on the destination volume %u\n", newVol);
2358 destination.destHost = ntohl(atoserver);
2359 destination.destPort = AFSCONF_VOLUMEPORT;
2360 destination.destSSID = 1;
2362 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2363 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2368 * Now dump the clone to the new volume
2371 if (!(flags & RV_NOCLONE)) {
2372 /* XXX probably should have some code here that checks to see if
2373 * XXX we are copying to same server and partition - if so, just
2374 * XXX use a clone to save disk space */
2376 /* Copy the clone to the new volume */
2377 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2380 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2382 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2386 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2387 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2392 "Failed to end the transaction on the cloned volume %u\n",
2398 * reattach to the main-line volume, and incrementally dump it.
2401 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2403 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2406 "Failed to create a transaction on the source volume %u\n",
2410 /* now do the incremental */
2412 ("Doing the%s dump from source to destination for volume %u ... ",
2413 (flags & RV_NOCLONE) ? "" : " incremental",
2416 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2419 "Failed to do the%s dump from old site to new site\n",
2420 (flags & RV_NOCLONE) ? "" : " incremental");
2423 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2424 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2425 code = AFSVolSetFlags(toconn, totid, volflag);
2427 "Failed to set the flags to make destination volume online\n");
2430 /* put new volume online */
2431 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2432 code = AFSVolEndTrans(toconn, totid, &rcode);
2437 "Failed to end the transaction on the destination volume %u\n",
2441 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2442 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2447 "Failed to end the transaction on the source volume %u\n",
2453 if (!(flags & RV_NOCLONE)) {
2454 code = DoVolDelete(fromconn, cloneVol, afrompart,
2455 "cloned", 0, NULL, NULL);
2462 if (!(flags & RV_NOVLDB)) {
2463 /* create the vldb entry for the copied volume */
2464 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2465 newentry.nServers = 1;
2466 newentry.serverNumber[0] = atoserver;
2467 newentry.serverPartition[0] = atopart;
2468 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2469 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2470 newentry.volumeId[RWVOL] = newVol;
2471 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2472 newentry.volumeId[BACKVOL] = 0;
2473 newentry.cloneId = 0;
2474 /*map into right byte order, before passing to xdr, the stuff has to be in host
2475 * byte order. Xdr converts it into network order */
2476 MapNetworkToHost(&newentry, &storeEntry);
2477 /* create the vldb entry */
2478 vcode = VLDB_CreateEntry(&storeEntry);
2481 "Could not create a VLDB entry for the volume %s %lu\n",
2482 atovolname, (unsigned long)newVol);
2483 /*destroy the created volume */
2484 VPRINT1("Deleting the newly created volume %u\n", newVol);
2485 AFSVolDeleteVolume(toconn, totid);
2489 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2493 /* normal cleanup code */
2496 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2498 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2499 if (code || rcode) {
2502 "Could not end transaction on the source volume %lu\n",
2503 (unsigned long)afromvol);
2505 error = (code ? code : rcode);
2511 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2513 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2514 if (code || rcode) {
2517 "Could not end transaction on the source's clone volume %lu\n",
2518 (unsigned long)cloneVol);
2520 error = (code ? code : rcode);
2526 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2528 code = AFSVolEndTrans(toconn, totid, &rcode);
2532 "Could not end transaction on destination volume %lu\n",
2533 (unsigned long)newVol);
2535 error = (code ? code : rcode);
2540 rx_DestroyConnection(fromconn);
2542 rx_DestroyConnection(toconn);
2543 PrintError("", error);
2546 /* come here only when the sky falls */
2551 "vos copy: operation interrupted, cleanup in progress...\n");
2552 fprintf(STDOUT, "clear transaction contexts\n");
2557 VPRINT("Recovery: Ending transaction on clone volume ...");
2558 AFSVolEndTrans(fromconn, clonetid, &rcode);
2562 VPRINT("Recovery: Ending transaction on destination volume ...");
2563 AFSVolEndTrans(toconn, totid, &rcode);
2566 if (fromtid) { /* put it on-line */
2567 VPRINT("Recovery: Ending transaction on source volume ...");
2568 AFSVolEndTrans(fromconn, fromtid, &rcode);
2572 VPRINT("Recovery: Accessing VLDB.\n");
2573 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2575 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2579 MapHostToNetwork(&entry);
2581 /* common cleanup - delete local clone */
2583 code = DoVolDelete(fromconn, cloneVol, afrompart,
2584 "clone", 0, NULL, "Recovery:");
2586 done: /* routine cleanup */
2588 rx_DestroyConnection(fromconn);
2590 rx_DestroyConnection(toconn);
2593 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2601 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2602 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2604 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2605 atovolname, atoserver, atopart, 0, 0);
2610 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2611 * if one already exists, update it
2615 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2617 struct rx_connection *aconn = (struct rx_connection *)0;
2618 afs_int32 ttid = 0, btid = 0;
2619 afs_uint32 backupID;
2620 afs_int32 code = 0, rcode = 0;
2621 struct nvldbentry entry, storeEntry;
2622 afs_int32 error = 0;
2623 int vldblocked = 0, vldbmod = 0;
2625 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2627 /* the calls to VLDB will succeed only if avolid is a RW volume,
2628 * since we are following the RW hash chain for searching */
2629 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2632 "Could not fetch the entry for the volume %lu from the VLDB \n",
2633 (unsigned long)avolid);
2637 MapHostToNetwork(&entry);
2639 /* These operations require the VLDB be locked since it means the VLDB
2640 * will change or the vldb is already locked.
2642 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2643 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2644 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2646 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2649 "Could not lock the VLDB entry for the volume %lu\n",
2650 (unsigned long)avolid);
2656 /* Reread the vldb entry */
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);
2668 if (!ISNAMEVALID(entry.name)) {
2669 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2671 error = VOLSERBADNAME;
2675 backupID = entry.volumeId[BACKVOL];
2676 if (backupID == INVALID_BID) {
2677 /* Get a backup volume id from the VLDB and update the vldb
2680 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2683 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2684 (unsigned long)avolid);
2688 entry.volumeId[BACKVOL] = backupID;
2692 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2693 entry.name, NULL, ".backup", NULL, NULL);
2699 /* Mark vldb as backup exists */
2700 if (!(entry.flags & BACK_EXISTS)) {
2701 entry.flags |= BACK_EXISTS;
2705 /* Now go back to the backup volume and bring it on line */
2706 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2709 "Failed to start a transaction on the backup volume %lu\n",
2710 (unsigned long)backupID);
2715 code = AFSVolSetFlags(aconn, btid, 0);
2717 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2718 (unsigned long)backupID);
2723 code = AFSVolEndTrans(aconn, btid, &rcode);
2725 if (code || rcode) {
2727 "Failed to end the transaction on the backup volume %lu\n",
2728 (unsigned long)backupID);
2729 error = (code ? code : rcode);
2735 /* Will update the vldb below */
2739 code = AFSVolEndTrans(aconn, ttid, &rcode);
2740 if (code || rcode) {
2741 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2742 (unsigned long)avolid);
2744 error = (code ? code : rcode);
2749 code = AFSVolEndTrans(aconn, btid, &rcode);
2750 if (code || rcode) {
2752 "Could not end transaction the backup volume %lu\n",
2753 (unsigned long)backupID);
2755 error = (code ? code : rcode);
2759 /* Now update the vldb - if modified */
2762 MapNetworkToHost(&entry, &storeEntry);
2764 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2765 (LOCKREL_OPCODE | LOCKREL_AFSID |
2766 LOCKREL_TIMESTAMP));
2769 "Could not update the VLDB entry for the volume %lu \n",
2770 (unsigned long)avolid);
2776 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2777 (LOCKREL_OPCODE | LOCKREL_AFSID |
2778 LOCKREL_TIMESTAMP));
2781 "Could not unlock the VLDB entry for the volume %lu \n",
2782 (unsigned long)avolid);
2790 rx_DestroyConnection(aconn);
2792 PrintError("", error);
2796 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2797 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2798 * The new volume is named by <aname>, or by appending ".clone" to
2799 * the existing name if <aname> is NULL. The following flags are
2802 * RV_RDONLY - target volume is RO
2803 * RV_OFFLINE - leave target volume offline
2807 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2808 afs_uint32 acloneid, char *aname, int flags)
2810 struct rx_connection *aconn = (struct rx_connection *)0;
2811 afs_int32 ttid = 0, btid = 0;
2812 afs_int32 code = 0, rcode = 0;
2813 char vname[VOLSER_MAXVOLNAME + 1];
2814 afs_int32 error = 0;
2815 volEntries volumeInfo;
2818 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2821 volumeInfo.volEntries_val = (volintInfo *) 0;
2822 volumeInfo.volEntries_len = 0;
2823 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2825 fprintf(stderr, "Could not get info for volume %lu\n",
2826 (unsigned long)avolid);
2830 strncpy(vname, volumeInfo.volEntries_val[0].name,
2831 VOLSER_OLDMAXVOLNAME - 7);
2832 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2833 strcat(vname, ".clone");
2835 if (volumeInfo.volEntries_val)
2836 free(volumeInfo.volEntries_val);
2840 /* Get a clone id */
2841 VPRINT1("Allocating new volume id for clone of volume %u ...",
2843 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2845 "Could not get an ID for the clone of volume %u from the VLDB\n",
2850 if (flags & RV_RWONLY)
2851 type = readwriteVolume;
2852 else if (flags & RV_RDONLY)
2853 type = readonlyVolume;
2855 type = backupVolume;
2857 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
2858 NULL, ".clone", NULL, NULL, NULL);
2864 /* Now go back to the backup volume and bring it on line */
2865 if (!(flags & RV_OFFLINE)) {
2866 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2869 "Failed to start a transaction on the clone volume %lu\n",
2870 (unsigned long)acloneid);
2875 code = AFSVolSetFlags(aconn, btid, 0);
2877 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2878 (unsigned long)acloneid);
2883 code = AFSVolEndTrans(aconn, btid, &rcode);
2885 if (code || rcode) {
2887 "Failed to end the transaction on the clone volume %lu\n",
2888 (unsigned long)acloneid);
2889 error = (code ? code : rcode);
2898 code = AFSVolEndTrans(aconn, ttid, &rcode);
2899 if (code || rcode) {
2900 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2901 (unsigned long)avolid);
2903 error = (code ? code : rcode);
2908 code = AFSVolEndTrans(aconn, btid, &rcode);
2909 if (code || rcode) {
2911 "Could not end transaction on the clone volume %lu\n",
2912 (unsigned long)acloneid);
2914 error = (code ? code : rcode);
2919 rx_DestroyConnection(aconn);
2921 PrintError("", error);
2925 #define ONERROR(ec, ep, es) do { \
2927 fprintf(STDERR, (es), (ep)); \
2932 #define ONERROR0(ec, es) do { \
2934 fprintf(STDERR, (es)); \
2939 #define ERROREXIT(ec) do { \
2944 /* Get a "transaction" on this replica. Create the volume
2945 * if necessary. Return the time from which a dump should
2946 * be made (0 if it's a new volume)
2949 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
2950 struct rx_connection **connPtr, afs_int32 * transPtr,
2951 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
2952 afs_int32 *origflags, afs_uint32 tmpVolId)
2955 struct volser_status tstatus;
2960 *connPtr = (struct rx_connection *)0;
2965 /* get connection to the replication site */
2966 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
2968 goto fail; /* server is down */
2970 volid = vldbEntryPtr->volumeId[ROVOL];
2974 AFSVolTransCreate_retry(*connPtr, volid,
2975 vldbEntryPtr->serverPartition[index], ITOffline,
2978 if (!code && (origflags[index] & RO_DONTUSE)) {
2979 /* If RO_DONTUSE is set, this is supposed to be an entirely new
2980 * site. Don't trust any data on it, since it is possible we
2981 * have encountered some temporary volume from some other
2982 * incomplete volume operation. It is difficult to detect if
2983 * that has happened vs if this is a legit volume, so just
2984 * delete it to be safe. */
2986 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
2987 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
2988 serverNumber[index], hoststr) :
2989 hostutil_GetNameByINet(vldbEntryPtr->
2990 serverNumber[index]));
2992 code = AFSVolDeleteVolume(*connPtr, *transPtr);
2994 PrintError("Failed to delete RO_DONTUSE site: ", code);
2998 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3004 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3011 /* emulate what TransCreate would have returned, so we try to
3012 * create the volume below */
3017 /* If the volume does not exist, create it */
3018 if (!volid || code) {
3022 if (volid && (code != VNOVOL)) {
3023 PrintError("Failed to start a transaction on the RO volume.\n",
3028 strcpy(volname, vldbEntryPtr->name);
3030 strcat(volname, ".roclone");
3032 strcat(volname, ".readonly");
3036 "Creating new volume %lu on replication site %s: ",
3037 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3038 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3039 serverNumber[index], hoststr) :
3040 hostutil_GetNameByINet(vldbEntryPtr->
3041 serverNumber[index]));
3046 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3048 vldbEntryPtr->volumeId[RWVOL],
3049 tmpVolId?&tmpVolId:&volid,
3052 PrintError("Failed to create the ro volume: ", code);
3055 vldbEntryPtr->volumeId[ROVOL] = volid;
3059 /* The following is a bit redundant, since create sets these flags by default */
3061 AFSVolSetFlags(*connPtr, *transPtr,
3062 VTDeleteOnSalvage | VTOutOfService);
3064 PrintError("Failed to set flags on the ro volume: ", code);
3069 /* Otherwise, the transaction did succeed, so get the creation date of the
3070 * latest RO volume on the replication site
3073 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3074 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3075 serverNumber[index], hoststr) :
3076 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3078 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3080 PrintError("Failed to get status of volume on destination: ",
3085 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3090 code = DoVolClone(*connPtr, volid,
3091 vldbEntryPtr->serverPartition[index],
3092 readonlyVolume, tmpVolId, "temporary",
3093 vldbEntryPtr->name, NULL, ".roclone", NULL,
3098 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3099 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3106 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3110 if (tcode && tcode != ENOENT)
3111 PrintError("Could not end transaction on a ro volume: ", tcode);
3118 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3119 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3120 void *cookie, manyResults * results)
3124 for (i = 0; i < tr->manyDests_len; i++) {
3125 results->manyResults_val[i] =
3126 AFSVolForward(fromconn, fromtid, fromdate,
3127 &(tr->manyDests_val[i].server),
3128 tr->manyDests_val[i].trans, cookie);
3134 * Check if a trans has timed out, and recreate it if necessary.
3136 * @param[in] aconn RX connection to the relevant server
3137 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3138 * contains the new trans ID on success
3139 * @param[in] apart Partition for the transaction
3140 * @param[in] astat The status of the original transaction
3142 * @return operation status
3143 * @retval 0 existing transaction is still valid, or we managed to recreate
3144 * the trans successfully
3145 * @retval nonzero Fatal error; bail out
3148 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3149 struct volser_status *astat)
3151 struct volser_status new_status;
3154 memset(&new_status, 0, sizeof(new_status));
3155 code = AFSVolGetStatus(aconn, *atid, &new_status);
3157 if (code == ENOENT) {
3159 VPRINT1("Old transaction on cloned volume %lu timed out, "
3160 "restarting transaction\n", (long unsigned) astat->volID);
3161 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3164 PrintError("Failed to recreate cloned RO volume transaction\n",
3169 memset(&new_status, 0, sizeof(new_status));
3170 code = AFSVolGetStatus(aconn, *atid, &new_status);
3172 PrintError("Failed to get status on recreated transaction\n",
3177 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3178 PrintError("Recreated transaction on cloned RO volume, but "
3179 "the volume has changed!\n", 0);
3183 PrintError("Unable to get status of current cloned RO transaction\n",
3188 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3190 PrintError("Internal error: current GetStatus does not match "
3191 "original GetStatus?\n", 0);
3200 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3201 struct rx_connection **toconns, struct release *times,
3204 afs_int32 s, code = 0, rcode = 0;
3205 /* End the transactions and destroy the connections */
3206 for (s = 0; s < volcount; s++) {
3207 if (replicas[s].trans) {
3208 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3210 replicas[s].trans = 0;
3214 if ((s == 0) || (code != ENOENT)) {
3215 PrintError("Could not end transaction on a ro volume: ",
3219 ("Transaction timed out on a ro volume. Will retry.\n",
3221 if (times[s].vldbEntryIndex < *vldbindex)
3222 *vldbindex = times[s].vldbEntryIndex;
3227 rx_DestroyConnection(toconns[s]);
3233 DoVolOnline(struct nvldbentry *vldbEntryPtr, afs_uint32 avolid, int index,
3234 char *vname, struct rx_connection *connPtr)
3236 afs_int32 code = 0, rcode = 0, onlinetid = 0;
3239 AFSVolTransCreate_retry(connPtr, avolid,
3240 vldbEntryPtr->serverPartition[index],
3244 EPRINT(code, "Could not create transaction on readonly...\n");
3247 code = AFSVolSetFlags(connPtr, onlinetid, 0);
3249 EPRINT(code, "Could not set flags on readonly...\n");
3254 AFSVolSetIdsTypes(connPtr, onlinetid, vname,
3255 ROVOL, vldbEntryPtr->volumeId[RWVOL],
3258 EPRINT(code, "Could not set ids on readonly...\n");
3261 code = AFSVolEndTrans(connPtr, onlinetid, &rcode);
3267 /* UV_ReleaseVolume()
3268 * Release volume <afromvol> on <afromserver> <afrompart> to all
3269 * its RO sites (full release). Unless the previous release was
3270 * incomplete: in which case we bring the remaining incomplete
3271 * volumes up to date with the volumes that were released
3273 * forceflag: Performs a full release.
3275 * Will create a clone from the RW, then dump the clone out to
3276 * the remaining replicas. If there is more than 1 RO sites,
3277 * ensure that the VLDB says at least one RO is available all
3278 * the time: Influences when we write back the VLDB entry.
3282 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3283 afs_int32 afrompart, int forceflag, int stayUp)
3287 afs_int32 vcode, rcode, tcode;
3288 afs_uint32 cloneVolId = 0, roVolId;
3289 struct replica *replicas = 0;
3290 struct nvldbentry entry, storeEntry;
3291 int i, volcount = 0, m, fullrelease, vldbindex;
3293 struct restoreCookie cookie;
3294 struct rx_connection **toconns = 0;
3295 struct release *times = 0;
3297 struct rx_connection *fromconn = (struct rx_connection *)0;
3298 afs_int32 error = 0;
3300 afs_int32 clonetid = 0, onlinetid;
3301 afs_int32 fromtid = 0;
3302 afs_uint32 fromdate = 0;
3303 afs_uint32 thisdate;
3307 manyResults results;
3308 int rwindex, roindex, roclone, roexists;
3309 afs_uint32 rwcrdate = 0, rwupdate = 0;
3310 afs_uint32 clcrdate;
3314 } remembertime[NMAXNSERVERS];
3315 int releasecount = 0;
3316 struct volser_status volstatus;
3318 afs_int32 origflags[NMAXNSERVERS];
3319 struct volser_status orig_status;
3320 int notreleased = 0;
3321 int tried_justnewsites = 0;
3322 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3324 memset(remembertime, 0, sizeof(remembertime));
3325 memset(&results, 0, sizeof(results));
3326 memset(origflags, 0, sizeof(origflags));
3328 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3329 if (vcode != VL_RERELEASE)
3330 ONERROR(vcode, afromvol,
3331 "Could not lock the VLDB entry for the volume %u.\n");
3334 /* Get the vldb entry in readable format */
3335 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3336 ONERROR(vcode, afromvol,
3337 "Could not fetch the entry for the volume %u from the VLDB.\n");
3338 MapHostToNetwork(&entry);
3341 EnumerateEntry(&entry);
3343 if (!ISNAMEVALID(entry.name))
3344 ONERROR(VOLSERBADOP, entry.name,
3345 "Volume name %s is too long, rename before releasing.\n");
3346 if (entry.volumeId[RWVOL] != afromvol)
3347 ONERROR(VOLSERBADOP, afromvol,
3348 "The volume %u being released is not a read-write volume.\n");
3349 if (entry.nServers <= 1)
3350 ONERROR(VOLSERBADOP, afromvol,
3351 "Volume %u has no replicas - release operation is meaningless!\n");
3352 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3353 ONERROR(VOLSERBADOP, entry.name,
3354 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3356 /* roclone is true if one of the RO volumes is on the same
3357 * partition as the RW volume. In this case, we make the RO volume
3358 * on the same partition a clone instead of a complete copy.
3361 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3362 roclone = ((roindex == -1) ? 0 : 1);
3363 rwindex = Lp_GetRwIndex(&entry);
3365 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3367 /* Make sure we have a RO volume id to work with */
3368 if (entry.volumeId[ROVOL] == INVALID_BID) {
3369 /* need to get a new RO volume id */
3370 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3371 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3373 entry.volumeId[ROVOL] = roVolId;
3374 MapNetworkToHost(&entry, &storeEntry);
3375 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3376 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3379 /* Will we be completing a previously unfinished release. -force overrides */
3380 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3381 if (entry.serverFlags[i] & ITSROVOL) {
3383 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3384 if (entry.serverFlags[i] & RO_DONTUSE) notreleased++;
3386 origflags[i] = entry.serverFlags[i];
3388 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3391 if (!forceflag && (s == m || s == 0)) {
3392 if (notreleased && notreleased != m) {
3393 /* we have some new unreleased sites. try to just release to those,
3394 * if the RW has not changed */
3399 /* Determine which volume id to use and see if it exists */
3402 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3403 code = VolumeExists(afromserver, afrompart, cloneVolId);
3404 roexists = ((code == ENODEV) ? 0 : 1);
3406 /* For stayUp case, if roclone is the only site, bypass special handling */
3407 if (stayUp && roclone) {
3411 for (e = 0; (e < entry.nServers) && !error; e++) {
3412 if ((entry.serverFlags[e] & ITSROVOL)) {
3413 if (!(VLDB_IsSameAddrs(entry.serverNumber[e], afromserver,
3418 if (e >= entry.nServers)
3422 /* If we had a previous release to complete, do so, else: */
3423 if (stayUp && (cloneVolId == entry.volumeId[ROVOL])) {
3424 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVolId);
3425 ONERROR(code, afromvol,
3426 "Cannot get temporary clone id for volume %u\n");
3429 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3431 ONERROR(-1, afromserver,
3432 "Cannot establish connection with server 0x%x\n");
3436 fullrelease = 1; /* Do a full release if RO clone does not exist */
3438 /* Begin transaction on RW and mark it busy while we query it */
3439 code = AFSVolTransCreate_retry(
3440 fromconn, afromvol, afrompart, ITBusy, &fromtid
3442 ONERROR(code, afromvol,
3443 "Failed to start transaction on RW volume %u\n");
3445 /* Query the creation date for the RW */
3446 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3447 ONERROR(code, afromvol,
3448 "Failed to get the status of RW volume %u\n");
3449 rwcrdate = volstatus.creationDate;
3451 /* End transaction on RW */
3452 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3454 ONERROR((code ? code : rcode), afromvol,
3455 "Failed to end transaction on RW volume %u\n");
3457 /* Begin transaction on clone and mark it busy while we query it */
3458 code = AFSVolTransCreate_retry(
3459 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3461 ONERROR(code, cloneVolId,
3462 "Failed to start transaction on RW clone %u\n");
3464 /* Query the creation date for the clone */
3465 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3466 ONERROR(code, cloneVolId,
3467 "Failed to get the status of RW clone %u\n");
3468 clcrdate = volstatus.creationDate;
3470 /* End transaction on clone */
3471 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3473 ONERROR((code ? code : rcode), cloneVolId,
3474 "Failed to end transaction on RW clone %u\n");
3476 if (rwcrdate > clcrdate)
3477 fullrelease = 2;/* Do a full release if RO clone older than RW */
3481 if (fullrelease != 1) {
3482 /* in case the RW has changed, and just to be safe */
3487 switch (fullrelease) {
3489 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3490 (unsigned long)afromvol);
3493 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3494 (unsigned long)afromvol);
3496 tried_justnewsites = 1;
3497 fprintf(STDOUT, "There are new RO sites; we will try to "
3498 "only release to new sites\n");
3502 fprintf(STDOUT, "This is a completion of a previous release\n");
3508 afs_int32 oldest = 0;
3509 /* If the RO clone exists, then if the clone is a temporary
3510 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3511 * (it was recently added), then also delete it. We do not
3512 * want to "reclone" a temporary RO clone.
3515 code = VolumeExists(afromserver, afrompart, cloneVolId);
3517 code = DoVolDelete(fromconn, cloneVolId, afrompart, "previous clone", 0,
3519 if (code && (code != VNOVOL))
3524 /* clean up any previous tmp clone before starting if staying up */
3526 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3527 code = DoVolDelete(fromconn,
3528 stayUp ? entry.volumeId[ROVOL] : cloneVolId,
3529 afrompart, "the", 0, NULL, NULL);
3530 if (code && (code != VNOVOL))
3536 VPRINT("Querying old RO sites for update times...");
3537 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3538 volEntries volumeInfo;
3539 struct rx_connection *conn;
3542 if (!(entry.serverFlags[vldbindex] & ITSROVOL)) {
3545 if ((entry.serverFlags[vldbindex] & RO_DONTUSE)) {
3548 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3550 fprintf(STDERR, "Cannot establish connection to server %s\n",
3551 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3555 volumeInfo.volEntries_val = NULL;
3556 volumeInfo.volEntries_len = 0;
3557 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3558 entry.volumeId[ROVOL],
3561 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3562 (unsigned long)entry.volumeId[ROVOL],
3563 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3564 PrintError("", code);
3566 rx_DestroyConnection(conn);
3570 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3572 if (oldest == 0 || crdate < oldest) {
3576 rx_DestroyConnection(conn);
3577 free(volumeInfo.volEntries_val);
3578 volumeInfo.volEntries_val = NULL;
3579 volumeInfo.volEntries_len = 0;
3584 volEntries volumeInfo;
3585 volumeInfo.volEntries_val = NULL;
3586 volumeInfo.volEntries_len = 0;
3587 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3590 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3591 (unsigned long)afromvol,
3592 hostutil_GetNameByINet(afromserver));
3593 PrintError("", code);
3596 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3598 free(volumeInfo.volEntries_val);
3599 volumeInfo.volEntries_val = NULL;
3600 volumeInfo.volEntries_len = 0;
3603 if (justnewsites && oldest <= rwupdate) {
3604 /* RW has changed */
3608 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3609 * write this entry out to the vlserver until after the first
3610 * RO volume is released (temp RO clones don't count).
3612 * If 'justnewsites' is set, we're only updating sites that have
3613 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3615 for (i = 0; i < entry.nServers; i++) {
3617 if ((entry.serverFlags[i] & RO_DONTUSE)) {
3618 entry.serverFlags[i] &= ~NEW_REPSITE;
3620 entry.serverFlags[i] |= NEW_REPSITE;
3623 entry.serverFlags[i] &= ~NEW_REPSITE;
3624 entry.serverFlags[i] |= RO_DONTUSE;
3627 entry.serverFlags[rwindex] |= NEW_REPSITE;
3628 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3631 if (justnewsites && roexists) {
3632 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3633 * anything with the RO clone, so skip the reclone */
3636 } else if (fullrelease) {
3639 strcpy(vname, entry.name);
3641 strcat(vname, ".roclone");
3643 strcat(vname, ".readonly");
3645 strcpy(vname, "readonly-clone-temp");
3648 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3649 cloneVolId, (roclone && !stayUp)?"permanent RO":
3650 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3656 if (justnewsites && rwupdate != volstatus.updateDate) {
3658 /* reset the serverFlags as if 'justnewsites' had never been set */
3659 for (i = 0; i < entry.nServers; i++) {
3660 entry.serverFlags[i] &= ~NEW_REPSITE;
3661 entry.serverFlags[i] |= RO_DONTUSE;
3663 entry.serverFlags[rwindex] |= NEW_REPSITE;
3664 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3667 rwcrdate = volstatus.creationDate;
3669 /* Remember clone volume ID in case we fail or are interrupted */
3670 entry.cloneId = cloneVolId;
3672 if (roclone && !stayUp) {
3673 /* Bring the RO clone online - though not if it's a temporary clone */
3674 VPRINT1("Starting transaction on RO clone volume %u...",
3677 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3679 ONERROR(code, cloneVolId,
3680 "Failed to start transaction on volume %u\n");
3683 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3684 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3687 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3688 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3689 ONERROR((code ? code : rcode), cloneVolId,
3690 "Failed to end transaction on RO clone %u\n");
3693 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3695 /* Sleep so that a client searching for an online volume won't
3696 * find the clone offline and then the next RO offline while the
3697 * release brings the clone online and the next RO offline (race).
3698 * There is a fix in the 3.4 client that does not need this sleep
3699 * anymore, but we don't know what clients we have.
3701 if (entry.nServers > 2 && !justnewsites)
3704 /* Mark the RO clone in the VLDB as a good site (already released) */
3705 entry.serverFlags[roindex] |= NEW_REPSITE;
3706 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3707 entry.flags |= RO_EXISTS;
3711 /* Write out the VLDB entry only if the clone is not a temporary
3712 * clone. If we did this to a temporary clone then we would end
3713 * up marking all the ROs as "old release" making the ROs
3714 * temporarily unavailable.
3716 MapNetworkToHost(&entry, &storeEntry);
3717 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3718 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3719 ONERROR(vcode, entry.name,
3720 "Could not update vldb entry for %s.\n");
3726 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3727 /* act like this is a completion of a previous release */
3729 } else if (tried_justnewsites) {
3730 VPRINT("RW vol has changed; releasing to all sites\n");
3733 /* Now we will release from the clone to the remaining RO replicas.
3734 * The first 2 ROs (counting the non-temporary RO clone) are released
3735 * individually: releasecount. This is to reduce the race condition
3736 * of clients trying to find an on-line RO volume. The remaining ROs
3737 * are released in parallel but no more than half the number of ROs
3738 * (rounded up) at a time: nservers.
3741 strcpy(vname, entry.name);
3743 strcat(vname, ".roclone");
3745 strcat(vname, ".readonly");
3746 memset(&cookie, 0, sizeof(cookie));
3747 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3748 cookie.type = ROVOL;
3749 cookie.parent = entry.volumeId[RWVOL];
3752 /* how many to do at once, excluding clone */
3753 if (stayUp || justnewsites)
3754 nservers = entry.nServers; /* can do all, none offline */
3756 nservers = entry.nServers / 2;
3757 replicas = calloc(nservers + 1, sizeof(struct replica));
3758 times = calloc(nservers + 1, sizeof(struct release));
3759 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3760 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3761 if (!replicas || !times || !results.manyResults_val || !toconns)
3763 "Failed to create transaction on the release clone\n");
3765 /* Create a transaction on the cloned volume */
3766 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3768 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3770 memset(&orig_status, 0, sizeof(orig_status));
3771 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3773 if (!fullrelease && code)
3774 ONERROR(VOLSERNOVOL, afromvol,
3775 "Old clone is inaccessible. Try vos release -f %u.\n");
3776 ONERROR0(code, "Failed to create transaction on the release clone\n");
3779 /* if we have a clone, treat this as done, for now */
3780 if (stayUp && !fullrelease) {
3781 entry.serverFlags[roindex] |= NEW_REPSITE;
3782 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3783 entry.flags |= RO_EXISTS;
3788 /* For each index in the VLDB */
3789 for (vldbindex = 0; vldbindex < entry.nServers;) {
3790 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3792 ((volcount < nservers) && (vldbindex < entry.nServers));
3794 if (!stayUp && !justnewsites) {
3795 /* The first two RO volumes will be released individually.
3796 * The rest are then released in parallel. This is a hack
3797 * for clients not recognizing right away when a RO volume
3798 * comes back on-line.
3800 if ((volcount == 1) && (releasecount < 2))
3804 if (vldbindex == roindex)
3805 continue; /* the clone */
3806 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3807 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3809 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3810 continue; /* not a RO vol */
3813 /* Get a Transaction on this replica. Get a new connection if
3814 * necessary. Create the volume if necessary. Return the
3815 * time from which the dump should be made (0 if it's a new
3816 * volume). Each volume might have a different time.
3818 replicas[volcount].server.destHost =
3819 ntohl(entry.serverNumber[vldbindex]);
3820 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3821 replicas[volcount].server.destSSID = 1;
3822 times[volcount].vldbEntryIndex = vldbindex;
3825 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3826 &(replicas[volcount].trans),
3827 &(times[volcount].crtime),
3828 &(times[volcount].uptime),
3829 origflags, stayUp?cloneVolId:0);
3833 /* Thisdate is the date from which we want to pick up all changes */
3834 if (forceflag || !fullrelease
3835 || (rwcrdate > times[volcount].crtime)) {
3836 /* If the forceflag is set, then we want to do a full dump.
3837 * If it's not a full release, we can't be sure that the creation
3838 * date is good (so we also do a full dump).
3839 * If the RW volume was replaced (its creation date is newer than
3840 * the last release), then we can't be sure what has changed (so
3841 * we do a full dump).
3844 } else if (remembertime[vldbindex].validtime) {
3845 /* Trans was prev ended. Use the time from the prev trans
3846 * because, prev trans may have created the volume. In which
3847 * case time[volcount].time would be now instead of 0.
3850 (remembertime[vldbindex].uptime < times[volcount].uptime)
3851 ? remembertime[vldbindex].uptime
3852 : times[volcount].uptime;
3854 thisdate = times[volcount].uptime;
3856 remembertime[vldbindex].validtime = 1;
3857 remembertime[vldbindex].uptime = thisdate;
3859 if (volcount == 0) {
3860 fromdate = thisdate;
3862 /* Include this volume if it is within 15 minutes of the earliest */
3864 thisdate) ? (fromdate - thisdate) : (thisdate -
3866 AFSVolEndTrans(toconns[volcount],
3867 replicas[volcount].trans, &rcode);
3868 replicas[volcount].trans = 0;
3871 if (thisdate < fromdate)
3872 fromdate = thisdate;
3879 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
3886 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3887 (unsigned long)cloneVolId, stayUp?
3888 cloneVolId:entry.volumeId[ROVOL],
3889 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3890 vldbEntryIndex], hoststr) :
3891 hostutil_GetNameByINet(entry.
3892 serverNumber[times[0].
3895 for (s = 1; s < volcount; s++) {
3896 fprintf(STDOUT, " and %s",
3897 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3898 vldbEntryIndex], hoststr) :
3899 hostutil_GetNameByINet(entry.
3900 serverNumber[times[s].
3905 fprintf(STDOUT, " (full release)");
3908 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3910 fprintf(STDOUT, ".\n");
3914 /* Release the ones we have collected */
3915 tr.manyDests_val = &(replicas[0]);
3916 tr.manyDests_len = results.manyResults_len = volcount;
3918 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3919 0 /*spare */ , &cookie, &results);
3920 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3922 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3923 0 /*spare */ , &cookie, &results);
3928 PrintError("Release failed: ", code);
3930 for (m = 0; m < volcount; m++) {
3931 if (results.manyResults_val[m]) {
3932 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3933 /* we retry timed out transaction. When it is
3934 * not the first volume and the transaction wasn't found
3935 * (assume it timed out and was garbage collected by volser).
3938 ("Failed to dump volume from clone to a ro site: ",
3939 results.manyResults_val[m]);
3945 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3946 ROVOL, entry.volumeId[RWVOL], 0, 0);
3948 if ((m == 0) || (code != ENOENT)) {
3949 PrintError("Failed to set correct names and ids: ",
3955 /* have to clear dest. flags to ensure new vol goes online:
3956 * because the restore (forwarded) operation copied
3957 * the V_inService(=0) flag over to the destination.
3959 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3961 if ((m == 0) || (code != ENOENT)) {
3962 PrintError("Failed to set flags on ro volume: ",
3968 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3969 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3970 entry.flags |= RO_EXISTS;
3976 PutTrans(&vldbindex, replicas, toconns, times, volcount);
3977 MapNetworkToHost(&entry, &storeEntry);
3978 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3979 ONERROR(vcode, afromvol,
3980 " Could not update VLDB entry for volume %u\n");
3982 } /* for each index in the vldb */
3984 /* for the stayup case, put back at the end */
3986 afs_uint32 tmpVol = entry.volumeId[ROVOL];
3987 strcpy(vname, entry.name);
3988 strcat(vname, ".readonly");
3991 /* have to clear flags to ensure new vol goes online
3993 code = AFSVolSetFlags(fromconn, fromtid, 0);
3994 if (code && (code != ENOENT)) {
3995 PrintError("Failed to set flags on ro volume: ",
3999 VPRINT3("%sloning to permanent RO %u on %s...", roexists?"Re-c":"C", tmpVol,
4001 afs_inet_ntoa_r(entry.serverNumber[roindex],
4003 hostutil_GetNameByINet(entry.serverNumber[roindex]));
4005 code = AFSVolClone(fromconn, fromtid, roexists?tmpVol:0,
4006 readonlyVolume, vname, &tmpVol);
4010 VPRINT("Bringing readonly online...");
4011 code = DoVolOnline(&entry, tmpVol, roindex, vname,
4015 EPRINT(code, "Failed: ");
4016 entry.serverFlags[roindex] &= ~NEW_REPSITE;
4017 entry.serverFlags[roindex] |= RO_DONTUSE;
4019 entry.serverFlags[roindex] |= NEW_REPSITE;
4020 entry.serverFlags[roindex] &= ~RO_DONTUSE;
4021 entry.flags |= RO_EXISTS;
4026 for (s = 0; s < volcount; s++) {
4027 if (replicas[s].trans) {
4028 vldbindex = times[s].vldbEntryIndex;
4030 /* ok, so now we have to end the previous transaction */
4031 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4036 code = AFSVolTransCreate_retry(toconns[s],
4038 entry.serverPartition[vldbindex],
4040 &(replicas[s].trans));
4042 PrintError("Unable to begin transaction on temporary clone: ", code);
4045 PrintError("Unable to end transaction on temporary clone: ", code);
4048 VPRINT3("%sloning to permanent RO %u on %s...", times[s].crtime?"Re-c":"C",
4050 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4052 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4053 if (times[s].crtime)
4054 code = AFSVolClone(toconns[s], replicas[s].trans, tmpVol,
4055 readonlyVolume, vname, &tmpVol);
4057 code = AFSVolClone(toconns[s], replicas[s].trans, 0,
4058 readonlyVolume, vname, &tmpVol);
4061 if (!times[s].crtime) {
4062 entry.serverFlags[vldbindex] |= RO_DONTUSE;
4064 entry.serverFlags[vldbindex] &= ~NEW_REPSITE;
4065 PrintError("Failed: ",
4070 if (entry.serverFlags[vldbindex] != RO_DONTUSE) {
4071 /* bring it online (mark it InService) */
4072 VPRINT1("Bringing readonly online on %s...",
4075 htonl(replicas[s].server.destHost),
4077 hostutil_GetNameByINet(
4078 htonl(replicas[s].server.destHost)));
4080 code = DoVolOnline(&entry, tmpVol, vldbindex, vname,
4082 /* needed to come online for cloning */
4084 /* technically it's still new, just not online */
4085 entry.serverFlags[s] &= ~NEW_REPSITE;
4086 entry.serverFlags[s] |= RO_DONTUSE;
4087 if (code != ENOENT) {
4088 PrintError("Failed to set correct names and ids: ",
4095 VPRINT("Marking temporary clone for deletion...\n");
4096 code = AFSVolSetFlags(toconns[s],
4101 EPRINT(code, "Failed: ");
4105 VPRINT("Ending transaction on temporary clone...\n");
4106 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4110 PrintError("Failed: ", code);
4113 /* ended successfully */
4114 replicas[s].trans = 0;
4116 VPRINT2("Deleting temporary clone %u on %s...", cloneVolId,
4118 afs_inet_ntoa_r(htonl(replicas[s].server.destHost),
4120 hostutil_GetNameByINet(htonl(replicas[s].server.destHost)));
4121 code = DoVolDelete(toconns[s], cloneVolId,
4122 entry.serverPartition[vldbindex],
4123 NULL, 0, NULL, NULL);
4125 EPRINT(code, "Failed: ");
4132 /* done. put the vldb entry in the success tail case*/
4133 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4136 /* End the transaction on the cloned volume */
4137 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4142 PrintError("Failed to end transaction on rw volume: ", code);
4144 /* Figure out if any volume were not released and say so */
4145 for (failure = 0, i = 0; i < entry.nServers; i++) {
4146 if (!(entry.serverFlags[i] & NEW_REPSITE))
4152 "The volume %lu could not be released to the following %d sites:\n",
4153 (unsigned long)afromvol, failure);
4154 for (i = 0; i < entry.nServers; i++) {
4155 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
4156 MapPartIdIntoName(entry.serverPartition[i], pname);
4157 fprintf(STDERR, "\t%35s %s\n",
4158 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4159 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4162 MapNetworkToHost(&entry, &storeEntry);
4164 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4166 ONERROR(vcode, afromvol,
4167 " Could not update VLDB entry for volume %u\n");
4169 ERROREXIT(VOLSERBADRELEASE);
4173 /* All the ROs were release successfully. Remove the temporary clone */
4174 if (!roclone || stayUp) {
4176 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4177 (unsigned long)cloneVolId);
4180 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4182 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4186 for (i = 0; i < entry.nServers; i++)
4187 entry.serverFlags[i] &= ~NEW_REPSITE;
4189 /* Update the VLDB */
4190 VPRINT("updating VLDB ...");
4192 MapNetworkToHost(&entry, &storeEntry);
4194 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4195 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4196 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4201 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4205 "Failed to end cloning transaction on the RW volume %lu\n",
4206 (unsigned long)afromvol);
4212 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4216 "Failed to end transaction on the release clone %lu\n",
4217 (unsigned long)cloneVolId);
4222 for (i = 0; i < nservers; i++) {
4223 if (replicas && replicas[i].trans) {
4224 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4225 replicas[i].trans = 0;
4228 "Failed to end transaction on ro volume %u at server %s\n",
4229 entry.volumeId[ROVOL],
4230 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4231 destHost), hoststr) :
4232 hostutil_GetNameByINet(htonl
4233 (replicas[i].server.destHost)));
4238 if (toconns && toconns[i]) {
4239 rx_DestroyConnection(toconns[i]);
4245 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4246 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4249 "Could not release lock on the VLDB entry for volume %lu\n",
4250 (unsigned long)afromvol);
4256 PrintError("", error);
4259 rx_DestroyConnection(fromconn);
4260 if (results.manyResults_val)
4261 free(results.manyResults_val);
4273 dump_sig_handler(int x)
4275 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4279 /* Dump the volume <afromvol> on <afromserver> and
4280 * <afrompart> to <afilename> starting from <fromdate>.
4281 * DumpFunction does the real work behind the scenes after
4282 * extracting parameters from the rock
4285 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4287 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4290 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4291 * be changing during the dump */
4292 struct rx_call * volatile fromcall = NULL;
4293 struct rx_connection * volatile fromconn = NULL;
4294 afs_int32 volatile fromtid = 0;
4296 afs_int32 rxError = 0, rcode = 0;
4297 afs_int32 code, error = 0;
4299 time_t tmv = fromdate;
4303 #ifndef AFS_NT40_ENV
4304 (void)signal(SIGPIPE, dump_sig_handler);
4306 (void)signal(SIGINT, dump_sig_handler);
4309 VEPRINT("Full Dump ...\n");
4311 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4315 /* get connections to the servers */
4316 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4318 VEPRINT1("Starting transaction on volume %u...", afromvol);
4320 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4322 EGOTO1(error_exit, code,
4323 "Could not start transaction on the volume %u to be dumped\n",
4327 fromcall = rx_NewCall(fromconn);
4329 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4330 if (flags & VOLDUMPV2_OMITDIRS)
4331 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4333 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4334 EGOTO(error_exit, code, "Could not start the dump process \n");
4337 VEPRINT1("Dumping volume %u...", afromvol);
4338 code = DumpFunction(fromcall, rock);
4339 if (code == RXGEN_OPCODE)
4341 EGOTO(error_exit, code, "Error while dumping volume \n");
4346 code = rx_EndCall(fromcall, rxError);
4347 if (code && code != RXGEN_OPCODE)
4348 fprintf(STDERR, "Error in rx_EndCall\n");
4353 VEPRINT1("Ending transaction on volume %u...", afromvol);
4354 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4355 if (code || rcode) {
4356 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4357 (unsigned long)afromvol);
4359 error = (code ? code : rcode);
4364 rx_DestroyConnection(fromconn);
4366 if (error != RXGEN_OPCODE)
4367 PrintError("", error);
4371 /* Clone the volume <afromvol> on <afromserver> and
4372 * <afrompart>, and then dump the clone volume to
4373 * <afilename> starting from <fromdate>.
4374 * DumpFunction does the real work behind the scenes after
4375 * extracting parameters from the rock
4378 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4379 afs_int32 afrompart, afs_int32 fromdate,
4380 afs_int32(*DumpFunction) (struct rx_call *, void *),
4381 void *rock, afs_int32 flags)
4383 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4384 * be changing during the dump */
4385 struct rx_connection * volatile fromconn = NULL;
4386 struct rx_call * volatile fromcall = NULL;
4387 afs_int32 volatile clonetid = 0;
4388 afs_uint32 volatile clonevol = 0;
4391 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4392 afs_int32 code = 0, error = 0;
4395 time_t tmv = fromdate;
4399 #ifndef AFS_NT40_ENV
4400 (void)signal(SIGPIPE, dump_sig_handler);
4402 (void)signal(SIGINT, dump_sig_handler);
4405 VEPRINT("Full Dump ...\n");
4407 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4411 /* get connections to the servers */
4412 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4414 VEPRINT1("Starting transaction on volume %u...", afromvol);
4415 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4416 EGOTO1(error_exit, code,
4417 "Could not start transaction on the volume %u to be dumped\n",
4421 /* Get a clone id */
4422 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4424 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4426 EGOTO1(error_exit, code,
4427 "Could not get an ID for the clone of volume %u from the VLDB\n",
4431 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4432 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4434 strcpy(vname, "dump-clone-temp");
4437 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
4439 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4443 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4445 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4449 EGOTO1(error_exit, code,
4450 "Failed to end the transaction on the volume %u\n", afromvol);
4454 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4457 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4460 EGOTO1(error_exit, code,
4461 "Failed to start a transaction on the cloned volume%u\n",
4465 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4466 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4467 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4472 fromcall = rx_NewCall(fromconn);
4474 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4475 if (flags & VOLDUMPV2_OMITDIRS)
4476 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4478 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4479 EGOTO(error_exit, code, "Could not start the dump process \n");
4482 VEPRINT1("Dumping volume %u...", afromvol);
4483 code = DumpFunction(fromcall, rock);
4484 EGOTO(error_exit, code, "Error while dumping volume \n");
4488 /* now delete the clone */
4489 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4490 code = AFSVolDeleteVolume(fromconn, clonetid);
4492 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4493 (unsigned long)clonevol);
4499 code = rx_EndCall(fromcall, rxError);
4501 fprintf(STDERR, "Error in rx_EndCall\n");
4507 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4508 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4509 if (code || rcode) {
4511 "Could not end transaction on the cloned volume %lu\n",
4512 (unsigned long)clonevol);
4514 error = (code ? code : rcode);
4519 rx_DestroyConnection(fromconn);
4521 PrintError("", error);
4528 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4529 * the dump file <afilename>. WriteData does all the real work
4530 * after extracting params from the rock
4533 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4534 afs_uint32 toparentid, char tovolname[], int flags,
4535 afs_int32(*WriteData) (struct rx_call *, void *),
4538 struct rx_connection *toconn, *tempconn;
4539 struct rx_call *tocall;
4540 afs_int32 totid, code, rcode, vcode, terror = 0;
4541 afs_int32 rxError = 0;
4542 struct volser_status tstatus;
4543 struct volintInfo vinfo;
4545 char tovolreal[VOLSER_OLDMAXVOLNAME];
4547 afs_int32 temptid, pparentid;
4549 struct nvldbentry entry, storeEntry;
4552 struct restoreCookie cookie;
4554 afs_int32 volflag, voltype, volsertype;
4555 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4556 int index, same, errcode;
4560 memset(&cookie, 0, sizeof(cookie));
4565 tocall = (struct rx_call *)0;
4566 tempconn = (struct rx_connection *)0;
4570 if (flags & RV_RDONLY) {
4572 volsertype = volser_RO;
4575 volsertype = volser_RW;
4579 pparentid = toparentid;
4580 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4581 if (pvolid == 0) { /*alot a new id if needed */
4582 vcode = VLDB_GetEntryByName(tovolname, &entry);
4583 if (vcode == VL_NOENT) {
4584 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4586 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4592 } else if (flags & RV_RDONLY) {
4593 if (entry.flags & RW_EXISTS) {
4595 "Entry for ReadWrite volume %s already exists!\n",
4597 error = VOLSERBADOP;
4600 if (!entry.volumeId[ROVOL]) {
4602 "Existing entry for volume %s has no ReadOnly ID\n",
4604 error = VOLSERBADOP;
4607 pvolid = entry.volumeId[ROVOL];
4608 pparentid = entry.volumeId[RWVOL];
4610 pvolid = entry.volumeId[RWVOL];
4611 pparentid = entry.volumeId[RWVOL];
4614 if (!pparentid) pparentid = pvolid;
4615 /* at this point we have a volume id to use/reuse for the volume to be restored */
4616 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4618 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4619 EGOTO1(refail, VOLSERBADOP,
4620 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4623 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4624 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4625 EGOTO1(refail, VOLSERBADOP,
4626 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4628 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4631 MapPartIdIntoName(topart, partName);
4632 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4633 tovolreal, (unsigned long)pvolid,
4634 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4635 hostutil_GetNameByINet(toserver), partName);
4638 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4641 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4642 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4644 if (code && code != VNOVOL) {
4650 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4652 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4655 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4656 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4659 code = AFSVolGetStatus(toconn, totid, &tstatus);
4660 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4664 oldCreateDate = tstatus.creationDate;
4665 oldUpdateDate = tstatus.updateDate;
4671 cookie.parent = pparentid;
4672 cookie.type = voltype;
4674 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4676 tocall = rx_NewCall(toconn);
4677 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4679 fprintf(STDERR, "Volume restore Failed \n");
4683 code = WriteData(tocall, rock);
4685 fprintf(STDERR, "Could not transmit data\n");
4689 terror = rx_EndCall(tocall, rxError);
4690 tocall = (struct rx_call *)0;
4692 fprintf(STDERR, "rx_EndCall Failed \n");
4696 code = AFSVolGetStatus(toconn, totid, &tstatus);
4699 "Could not get status information about the volume %lu\n",
4700 (unsigned long)pvolid);
4704 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4706 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4707 (unsigned long)pvolid);
4712 if (flags & RV_CRDUMP)
4713 newCreateDate = tstatus.creationDate;
4714 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4715 newCreateDate = oldCreateDate;
4717 newCreateDate = time(0);
4718 if (flags & RV_LUDUMP)
4719 newUpdateDate = tstatus.updateDate;
4720 else if (flags & RV_LUKEEP)
4721 newUpdateDate = oldUpdateDate;
4723 newUpdateDate = time(0);
4724 code = AFSVolSetDate(toconn,totid, newCreateDate);
4726 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4731 init_volintInfo(&vinfo);
4732 vinfo.creationDate = newCreateDate;
4733 vinfo.updateDate = newUpdateDate;
4734 code = AFSVolSetInfo(toconn, totid, &vinfo);
4736 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4742 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4743 code = AFSVolSetFlags(toconn, totid, volflag);
4745 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4750 /* It isn't handled right in refail */
4751 code = AFSVolEndTrans(toconn, totid, &rcode);
4756 fprintf(STDERR, "Could not end transaction on %lu\n",
4757 (unsigned long)pvolid);
4763 fprintf(STDOUT, " done\n");
4765 if (success && (!reuseID || (flags & RV_FULLRST))) {
4766 /* Volume was restored on the file server, update the
4767 * VLDB to reflect the change.
4769 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4770 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4772 "Could not fetch the entry for volume number %lu from VLDB \n",
4773 (unsigned long)pvolid);
4778 MapHostToNetwork(&entry);
4779 if (vcode == VL_NOENT) { /* it doesnot exist already */
4780 /*make the vldb return this indication specifically */
4781 VPRINT("------- Creating a new VLDB entry ------- \n");
4782 strcpy(entry.name, tovolname);
4784 entry.serverNumber[0] = toserver; /*should be indirect */
4785 entry.serverPartition[0] = topart;
4786 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4787 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4788 if (flags & RV_RDONLY)
4789 entry.volumeId[ROVOL] = pvolid;
4790 else if (tstatus.cloneID != 0) {
4791 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4793 entry.volumeId[ROVOL] = INVALID_BID;
4794 entry.volumeId[RWVOL] = pparentid;
4796 if (tstatus.backupID != 0) {
4797 entry.volumeId[BACKVOL] = tstatus.backupID;
4798 /*this should come from status info on the volume if non zero */
4800 entry.volumeId[BACKVOL] = INVALID_BID;
4801 MapNetworkToHost(&entry, &storeEntry);
4802 vcode = VLDB_CreateEntry(&storeEntry);
4805 "Could not create the VLDB entry for volume number %lu \n",
4806 (unsigned long)pvolid);
4812 EnumerateEntry(&entry);
4813 } else { /*update the existing entry */
4815 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4816 fprintf(STDOUT, "------- Old entry -------\n");
4817 EnumerateEntry(&entry);
4818 fprintf(STDOUT, "------- New entry -------\n");
4821 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4825 "Could not lock the entry for volume number %lu \n",
4826 (unsigned long)pvolid);
4831 strcpy(entry.name, tovolname);
4833 /* Update the vlentry with the new information */
4834 if (flags & RV_RDONLY)
4835 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4837 index = Lp_GetRwIndex(&entry);
4839 /* Add the new site for the volume being restored */
4840 entry.serverNumber[entry.nServers] = toserver;
4841 entry.serverPartition[entry.nServers] = topart;
4842 entry.serverFlags[entry.nServers] =
4843 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4846 /* This volume should be deleted on the old site
4847 * if its different from new site.
4850 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4854 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4856 if ((!errcode && !same)
4857 || (entry.serverPartition[index] != topart)) {
4858 if (flags & RV_NODEL) {
4860 ("Not deleting the previous volume %u on server %s, ...",
4862 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4863 hostutil_GetNameByINet(entry.serverNumber[index]));
4866 UV_Bind(entry.serverNumber[index],
4867 AFSCONF_VOLUMEPORT);
4869 MapPartIdIntoName(entry.serverPartition[index],
4872 ("Deleting the previous volume %u on server %s, partition %s ...",
4874 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4875 hostutil_GetNameByINet(entry.serverNumber[index]),
4877 code = DoVolDelete(tempconn, pvolid,
4878 entry.serverPartition[index],
4879 "the", 0, NULL, NULL);
4880 if (code && code != VNOVOL) {
4884 MapPartIdIntoName(entry.serverPartition[index],
4888 entry.serverNumber[index] = toserver;
4889 entry.serverPartition[index] = topart;
4892 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4893 MapNetworkToHost(&entry, &storeEntry);
4895 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4896 LOCKREL_OPCODE | LOCKREL_AFSID |
4900 "Could not update the entry for volume number %lu \n",
4901 (unsigned long)pvolid);
4907 EnumerateEntry(&entry);
4914 code = rx_EndCall(tocall, rxError);
4920 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4921 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4924 "Could not release lock on the VLDB entry for the volume %lu\n",
4925 (unsigned long)pvolid);
4931 code = AFSVolEndTrans(toconn, totid, &rcode);
4935 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4936 (unsigned long)pvolid);
4942 code = AFSVolEndTrans(toconn, temptid, &rcode);
4946 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4947 (unsigned long)pvolid);
4953 rx_DestroyConnection(tempconn);
4955 rx_DestroyConnection(toconn);
4956 PrintError("", error);
4961 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4962 char tovolname[], int flags,
4963 afs_int32(*WriteData) (struct rx_call *, void *),
4966 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4971 /*unlocks the vldb entry associated with <volid> */
4973 UV_LockRelease(afs_uint32 volid)
4977 VPRINT("Binding to the VLDB server\n");
4979 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4980 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4983 "Could not unlock the entry for volume number %lu in VLDB \n",
4984 (unsigned long)volid);
4985 PrintError("", vcode);
4988 VPRINT("VLDB updated\n");
4993 /* old interface to add rosites */
4995 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4998 return UV_AddSite2(server, part, volid, 0, valid);
5001 /*adds <server> and <part> as a readonly replication site for <volid>
5004 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5005 afs_uint32 rovolid, afs_int32 valid)
5007 int j, nro = 0, islocked = 0;
5008 struct nvldbentry entry, storeEntry, entry2;
5009 afs_int32 vcode, error = 0;
5012 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5015 " Could not lock the VLDB entry for the volume %lu \n",
5016 (unsigned long)volid);
5021 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
5024 "Could not fetch the VLDB entry for volume number %lu \n",
5025 (unsigned long)volid);
5029 if (!ISNAMEVALID(entry.name)) {
5031 "Volume name %s is too long, rename before adding site\n",
5033 error = VOLSERBADOP;
5036 MapHostToNetwork(&entry);
5038 /* See if it's too many entries */
5039 if (entry.nServers >= NMAXNSERVERS) {
5040 fprintf(STDERR, "Total number of entries will exceed %u\n",
5042 error = VOLSERBADOP;
5046 /* See if it's on the same server */
5047 for (j = 0; j < entry.nServers; j++) {
5048 if (entry.serverFlags[j] & ITSROVOL) {
5050 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5053 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5056 MapPartIdIntoName(entry.serverPartition[j], apartName);
5058 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5060 error = VOLSERBADOP;
5067 /* See if it's too many RO sites - leave one for the RW */
5068 if (nro >= NMAXNSERVERS - 1) {
5069 fprintf(STDERR, "Total number of sites will exceed %u\n",
5071 error = VOLSERBADOP;
5075 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5076 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5077 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5080 if (entry.volumeId[ROVOL] == INVALID_BID) {
5081 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5083 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5086 VPRINT1("Using RO volume id %d.\n", rovolid);
5087 entry.volumeId[ROVOL] = rovolid;
5089 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5090 rovolid, entry.volumeId[ROVOL]);
5094 VPRINT("Adding a new site ...");
5095 entry.serverNumber[entry.nServers] = server;
5096 entry.serverPartition[entry.nServers] = part;
5098 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
5100 entry.serverFlags[entry.nServers] = (ITSROVOL);
5104 MapNetworkToHost(&entry, &storeEntry);
5106 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5107 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5109 fprintf(STDERR, "Could not update entry for volume %lu \n",
5110 (unsigned long)volid);
5119 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5120 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5123 "Could not release lock on volume entry for %lu \n",
5124 (unsigned long)volid);
5125 PrintError("", vcode);
5129 PrintError("", error);
5133 /*removes <server> <part> as read only site for <volid> from the vldb */
5135 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5138 struct nvldbentry entry, storeEntry;
5140 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5142 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5143 (unsigned long)volid);
5144 PrintError("", vcode);
5147 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5150 "Could not fetch the entry for volume number %lu from VLDB \n",
5151 (unsigned long)volid);
5152 PrintError("", vcode);
5155 MapHostToNetwork(&entry);
5156 if (!Lp_ROMatch(server, part, &entry)) {
5157 /*this site doesnot exist */
5158 fprintf(STDERR, "This site is not a replication site \n");
5160 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5161 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5163 fprintf(STDERR, "Could not update entry for volume %lu \n",
5164 (unsigned long)volid);
5165 PrintError("", vcode);
5166 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5167 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5171 } else { /*remove the rep site */
5172 Lp_SetROValue(&entry, server, part, 0, 0);
5174 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
5175 entry.flags &= ~RO_EXISTS;
5176 if (entry.nServers < 1) { /*this is the last ref */
5177 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5179 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5182 "Could not delete VLDB entry for volume %lu \n",
5183 (unsigned long)volid);
5184 PrintError("", vcode);
5189 MapNetworkToHost(&entry, &storeEntry);
5190 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5191 (unsigned long)volid);
5194 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5195 LOCKREL_OPCODE | LOCKREL_AFSID |
5199 "Could not release lock on volume entry for %lu \n",
5200 (unsigned long)volid);
5201 PrintError("", vcode);
5202 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5203 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5211 /*sets <server> <part> as read/write site for <volid> in the vldb */
5213 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5216 struct nvldbentry entry, storeEntry;
5219 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5221 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5222 (unsigned long)volid);
5223 PrintError("", vcode);
5226 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5229 "Could not fetch the entry for volume number %lu from VLDB \n",
5230 (unsigned long)volid);
5231 PrintError("", vcode);
5234 MapHostToNetwork(&entry);
5235 index = Lp_GetRwIndex(&entry);
5237 /* no RW site exists */
5238 fprintf(STDERR, "No existing RW site for volume %lu",
5239 (unsigned long)volid);
5241 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5242 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5245 "Could not release lock on entry for volume %lu \n",
5246 (unsigned long)volid);
5247 PrintError("", vcode);
5251 } else { /* change the RW site */
5252 entry.serverNumber[index] = server;
5253 entry.serverPartition[index] = part;
5254 MapNetworkToHost(&entry, &storeEntry);
5256 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5257 LOCKREL_OPCODE | LOCKREL_AFSID |
5260 fprintf(STDERR, "Could not update entry for volume %lu \n",
5261 (unsigned long)volid);
5262 PrintError("", vcode);
5263 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5264 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5272 /*list all the partitions on <aserver> */
5274 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5277 struct rx_connection *aconn;
5278 struct pIDs partIds;
5279 struct partEntries partEnts;
5283 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5285 partEnts.partEntries_len = 0;
5286 partEnts.partEntries_val = NULL;
5287 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5288 if (code == RXGEN_OPCODE) {
5289 for (i = 0; i < 26; i++) /* try old interface */
5290 partIds.partIds[i] = -1;
5291 code = AFSVolListPartitions(aconn, &partIds);
5293 for (i = 0; i < 26; i++) {
5294 if ((partIds.partIds[i]) != -1) {
5295 ptrPartList->partId[j] = partIds.partIds[i];
5296 ptrPartList->partFlags[j] = PARTVALID;
5299 ptrPartList->partFlags[i] = 0;
5304 *cntp = partEnts.partEntries_len;
5305 if (*cntp > VOLMAXPARTS) {
5307 "Warning: number of partitions on the server too high %d (process only %d)\n",
5308 *cntp, VOLMAXPARTS);
5309 *cntp = VOLMAXPARTS;
5311 for (i = 0; i < *cntp; i++) {
5312 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5313 ptrPartList->partFlags[i] = PARTVALID;
5315 free(partEnts.partEntries_val);
5321 "Could not fetch the list of partitions from the server\n");
5322 PrintError("", code);
5324 rx_DestroyConnection(aconn);
5329 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5330 This is used by the backup system */
5332 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5333 struct volDescription *volPtr, afs_int32 arraySize)
5335 struct rx_connection *aconn;
5336 struct volDescription *curPtr;
5339 afs_int32 success = 1;
5341 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5343 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5344 if (curPtr->volFlags & CLONEVALID) {
5345 curPtr->volFlags &= ~CLONEZAPPED;
5348 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5349 "clone", 0, NULL, NULL);
5354 curPtr->volFlags |= CLONEZAPPED;
5356 fprintf(STDERR, "Could not zap volume %lu\n",
5357 (unsigned long)curPtr->volCloneId);
5359 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5360 curPtr->volCloneId);
5365 rx_DestroyConnection(aconn);
5369 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5372 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5373 struct volDescription *volPtr, afs_int32 arraySize)
5375 struct rx_connection *aconn;
5376 struct volDescription *curPtr;
5379 afs_int32 rcode = 0;
5381 int reuseCloneId = 0;
5382 afs_uint32 curCloneId = 0;
5383 char cloneName[256]; /*max vol name */
5385 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5387 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5389 else { /*get a bunch of id's from vldb */
5391 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5393 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5394 PrintError("", code);
5399 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5400 if (curPtr->volFlags & ENTRYVALID) {
5402 curPtr->volFlags |= CLONEVALID;
5403 /*make a clone of curParentId and record as curPtr->volCloneId */
5405 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5408 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5411 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5415 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5416 strcpy(cloneName, curPtr->volName);
5417 strcat(cloneName, "-tmpClone-");
5419 strcpy(cloneName, "-tmpClone");
5421 curPtr->volCloneId = curCloneId;
5426 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5427 &(curPtr->volCloneId));
5429 curPtr->volFlags &= ~CLONEVALID;
5431 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5432 curPtr->volName, (unsigned long)code);
5433 code = AFSVolEndTrans(aconn, tid, &rcode);
5435 fprintf(STDERR, "WARNING: could not end transaction\n");
5438 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5439 curPtr->volCloneId);
5440 code = AFSVolEndTrans(aconn, tid, &rcode);
5441 if (code || rcode) {
5442 curPtr->volFlags &= ~CLONEVALID;
5451 rx_DestroyConnection(aconn);
5456 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5457 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5459 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5460 struct volintInfo **resultPtr, afs_int32 * size)
5462 struct rx_connection *aconn;
5464 volEntries volumeInfo;
5468 *resultPtr = (volintInfo *) 0;
5469 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5470 volumeInfo.volEntries_len = 0;
5472 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5473 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5476 "Could not fetch the list of volumes from the server\n");
5478 *resultPtr = volumeInfo.volEntries_val;
5479 *size = volumeInfo.volEntries_len;
5483 rx_DestroyConnection(aconn);
5484 PrintError("", code);
5488 /*------------------------------------------------------------------------
5489 * EXPORTED UV_XListVolumes
5492 * List the extended information for all the volumes on a particular
5493 * File Server and partition. We may either return the volume's ID
5494 * or all of its extended information.
5497 * a_serverID : Address of the File Server for which we want
5498 * extended volume info.
5499 * a_partID : Partition for which we want the extended
5501 * a_all : If non-zero, fetch ALL the volume info,
5502 * otherwise just the volume ID.
5503 * a_resultPP : Ptr to the address of the area containing
5504 * the returned volume info.
5505 * a_numEntsInResultP : Ptr for the value we set for the number of
5510 * Otherise, the return value of AFSVolXListVolumes.
5513 * This routine is closely related to UV_ListVolumes, which returns
5514 * only the standard level of detail on AFS volumes. It is a
5515 * heavyweight operation, zipping through all the volume entries for
5516 * a given server/partition.
5520 *------------------------------------------------------------------------*/
5523 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5524 struct volintXInfo **a_resultPP,
5525 afs_int32 * a_numEntsInResultP)
5527 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5528 afs_int32 code; /*Error code to return */
5529 volXEntries volumeXInfo; /*Area for returned extended vol info */
5532 * Set up our error code and the area for returned extended volume info.
5533 * We set the val field to a null pointer as a hint for the stub to
5537 *a_numEntsInResultP = 0;
5538 *a_resultPP = (volintXInfo *) 0;
5539 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5540 volumeXInfo.volXEntries_len = 0;
5543 * Bind to the Volume Server port on the File Server machine in question,
5546 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5547 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5549 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5552 * We got the info; pull out the pointer to where the results lie
5553 * and how many entries are there.
5555 *a_resultPP = volumeXInfo.volXEntries_val;
5556 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5560 * If we got an Rx connection, throw it away.
5563 rx_DestroyConnection(rxConnP);
5565 PrintError("", code);
5567 } /*UV_XListVolumes */
5569 /* get all the information about volume <volid> on <aserver> and <apart> */
5571 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5572 struct volintInfo **resultPtr)
5574 struct rx_connection *aconn;
5576 volEntries volumeInfo;
5580 *resultPtr = (volintInfo *) 0;
5581 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5582 volumeInfo.volEntries_len = 0;
5584 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5585 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5588 "Could not fetch the information about volume %lu from the server\n",
5589 (unsigned long)volid);
5591 *resultPtr = volumeInfo.volEntries_val;
5596 rx_DestroyConnection(aconn);
5597 PrintError("", code);
5601 /*------------------------------------------------------------------------
5602 * EXPORTED UV_XListOneVolume
5605 * List the extended information for a volume on a particular File
5606 * Server and partition.
5609 * a_serverID : Address of the File Server for which we want
5610 * extended volume info.
5611 * a_partID : Partition for which we want the extended
5613 * a_volID : Volume ID for which we want the info.
5614 * a_resultPP : Ptr to the address of the area containing
5615 * the returned volume info.
5619 * Otherise, the return value of AFSVolXListOneVolume.
5622 * This routine is closely related to UV_ListOneVolume, which returns
5623 * only the standard level of detail on the chosen AFS volume.
5627 *------------------------------------------------------------------------*/
5630 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5631 struct volintXInfo **a_resultPP)
5633 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5634 afs_int32 code; /*Error code */
5635 volXEntries volumeXInfo; /*Area for returned info */
5638 * Set up our error code, and the area we're in which we are returning
5639 * the info. Setting the val field to a null pointer tells the stub
5640 * to allocate space for us.
5643 *a_resultPP = (volintXInfo *) 0;
5644 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5645 volumeXInfo.volXEntries_len = 0;
5648 * Bind to the Volume Server port on the File Server machine in question,
5651 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5652 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5655 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5658 * We got the info; pull out the pointer to where the results lie.
5660 *a_resultPP = volumeXInfo.volXEntries_val;
5663 * If we got an Rx connection, throw it away.
5666 rx_DestroyConnection(rxConnP);
5668 PrintError("", code);
5673 * Given a volume we read from a partition, check if it is
5674 * represented in the VLDB correctly.
5676 * The VLDB is looked up by the RW volume id (not its name).
5677 * The RW contains the true name of the volume (BK and RO set
5678 * the name in the VLDB only on creation of the VLDB entry).
5679 * We want rules strict enough that when we check all volumes
5680 * on one partition, it does not need to be done again. IE:
5681 * two volumes on different partitions won't constantly
5682 * change a VLDB entry away from what the other set.
5683 * For RW and BK volumes, we will always check the VLDB to see
5684 * if the two exist on the server/partition. May seem redundant,
5685 * but this is an easy check of the VLDB. IE: if the VLDB entry
5686 * says the BK exists but no BK volume is there, we will detect
5687 * this when we check the RW volume.
5688 * VLDB entries are locked only when a change needs to be done.
5689 * Output changed to look a lot like the "vos syncserv" otuput.
5692 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5693 afs_int32 * modentry, afs_uint32 * maxvolid,
5694 struct nvldbentry *aentry)
5698 afs_int32 code, error = 0;
5699 struct nvldbentry entry, storeEntry;
5701 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5711 ((volumeinfo->type ==
5712 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5715 /* Check to see if the VLDB is ok without locking it (pass 1).
5716 * If it will change, then lock the VLDB entry, read it again,
5717 * then make the changes to it (pass 2).
5720 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5722 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5723 (unsigned long)rwvolid);
5728 createentry = 0; /* Do we need to create a VLDB entry */
5729 addvolume = 0; /* Add this volume to the VLDB entry */
5730 modified = 0; /* The VLDB entry was modified */
5733 memcpy(&entry, aentry, sizeof(entry));
5735 /* Read the entry from VLDB by its RW volume id */
5736 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5738 if (code != VL_NOENT) {
5740 "Could not retrieve the VLDB entry for volume %lu \n",
5741 (unsigned long)rwvolid);
5745 memset(&entry, 0, sizeof(entry));
5746 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5750 MapHostToNetwork(&entry);
5754 if (verbose && (pass == 1)) {
5755 fprintf(STDOUT, "_______________________________\n");
5756 fprintf(STDOUT, "\n-- status before -- \n");
5758 fprintf(STDOUT, "\n**does not exist**\n");
5760 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5761 || (entry.flags & BACK_EXISTS))
5762 EnumerateEntry(&entry);
5764 fprintf(STDOUT, "\n");
5767 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5773 /* Check existence of RW and BK volumes */
5774 code = CheckVldbRWBK(&entry, &mod);
5780 idx = Lp_GetRwIndex(&entry);
5781 if (idx == -1) { /* RW index not found in the VLDB entry */
5782 idx = entry.nServers; /* put it into next index */
5785 } else { /* RW index found in the VLDB entry. */
5786 /* Verify if this volume's location matches where the VLDB says it is */
5787 if (!Lp_Match(aserver, apart, &entry)) {
5788 if (entry.flags & RW_EXISTS) {
5789 /* The RW volume exists elsewhere - report this one a duplicate */
5791 MapPartIdIntoName(apart, pname);
5793 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5794 (unsigned long)rwvolid,
5796 afs_inet_ntoa_r(aserver, hoststr) :
5797 hostutil_GetNameByINet(aserver), pname);
5798 MapPartIdIntoName(entry.serverPartition[idx],
5801 " VLDB reports RW volume %lu exists on %s %s\n",
5802 (unsigned long)rwvolid,
5804 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5805 hostutil_GetNameByINet(entry.
5810 /* The RW volume does not exist - have VLDB point to this one */
5813 /* Check for orphaned BK volume on old partition */
5814 if (entry.flags & BACK_EXISTS) {
5816 MapPartIdIntoName(entry.serverPartition[idx],
5819 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5820 entry.volumeId[BACKVOL],
5822 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5823 hostutil_GetNameByINet(entry.
5826 MapPartIdIntoName(apart, pname);
5828 " VLDB reports its RW volume %lu exists on %s %s\n",
5829 (unsigned long)rwvolid,
5831 afs_inet_ntoa_r(aserver, hoststr) :
5832 hostutil_GetNameByINet(aserver),
5838 /* Volume location matches the VLDB location */
5839 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5840 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5843 (entry.name, volumeinfo->name,
5844 VOLSER_OLDMAXVOLNAME) != 0)) {
5852 entry.flags |= RW_EXISTS;
5853 entry.volumeId[RWVOL] = rwvolid;
5854 if (!entry.volumeId[BACKVOL])
5855 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5856 if (!entry.volumeId[ROVOL])
5857 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5859 entry.serverFlags[idx] = ITSRWVOL;
5860 entry.serverNumber[idx] = aserver;
5861 entry.serverPartition[idx] = apart;
5862 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5866 /* One last check - to update BK if need to */
5867 code = CheckVldbRWBK(&entry, &mod);
5875 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5881 /* Check existence of RW and BK volumes */
5882 code = CheckVldbRWBK(&entry, &mod);
5888 idx = Lp_GetRwIndex(&entry);
5889 if (idx == -1) { /* RW index not found in the VLDB entry */
5890 idx = entry.nServers; /* Put it into next index */
5893 } else { /* RW index found in the VLDB entry */
5894 /* Verify if this volume's location matches where the VLDB says it is */
5895 if (!Lp_Match(aserver, apart, &entry)) {
5896 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5898 MapPartIdIntoName(apart, pname);
5900 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5901 (unsigned long)volumeinfo->volid,
5903 afs_inet_ntoa_r(aserver, hoststr) :
5904 hostutil_GetNameByINet(aserver), pname);
5905 MapPartIdIntoName(entry.serverPartition[idx], pname);
5907 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5908 (unsigned long)rwvolid,
5910 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5911 hostutil_GetNameByINet(entry.
5916 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5917 if (!(entry.flags & BACK_EXISTS)) {
5919 } else if (volumeinfo->volid >
5920 entry.volumeId[BACKVOL]) {
5924 MapPartIdIntoName(entry.serverPartition[idx],
5927 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5928 entry.volumeId[BACKVOL],
5930 afs_inet_ntoa_r(aserver, hoststr) :
5931 hostutil_GetNameByINet(aserver),
5934 " VLDB reports its BK volume ID is %lu\n",
5935 (unsigned long)volumeinfo->volid);
5939 MapPartIdIntoName(entry.serverPartition[idx],
5942 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5943 (unsigned long)volumeinfo->volid,
5945 afs_inet_ntoa_r(aserver, hoststr) :
5946 hostutil_GetNameByINet(aserver),
5949 " VLDB reports its BK volume ID is %u\n",
5950 entry.volumeId[BACKVOL]);
5953 } else if (!entry.volumeId[BACKVOL]) {
5960 entry.flags |= BACK_EXISTS;
5961 entry.volumeId[RWVOL] = rwvolid;
5962 entry.volumeId[BACKVOL] = volumeinfo->volid;
5964 entry.serverNumber[idx] = aserver;
5965 entry.serverPartition[idx] = apart;
5966 entry.serverFlags[idx] = ITSBACKVOL;
5972 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5973 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5974 /* This is a quick check to see if the RO entry exists in the
5975 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5976 * RO volume listed in the VLDB exists).
5978 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5980 idx = entry.nServers;
5984 if (!(entry.flags & RO_EXISTS)) {
5989 /* Before we correct the VLDB entry, make sure all the
5990 * ROs listed in the VLDB exist.
5992 code = CheckVldbRO(&entry, &mod);
5998 if (!(entry.flags & RO_EXISTS)) {
5999 /* No RO exists in the VLDB entry - add this one */
6000 idx = entry.nServers;
6003 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
6004 /* The volume headers's RO ID does not match that in the VLDB entry,
6005 * and the vol hdr's ID is greater (implies more recent). So delete
6006 * all the RO volumes listed in VLDB entry and add this volume.
6008 for (j = 0; j < entry.nServers; j++) {
6009 if (entry.serverFlags[j] & ITSROVOL) {
6010 /* Verify this volume exists and print message we are orphaning it */
6012 MapPartIdIntoName(apart, pname);
6014 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
6015 entry.volumeId[ROVOL],
6017 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
6018 hostutil_GetNameByINet(entry.
6022 " VLDB reports its RO volume ID is %lu\n",
6023 (unsigned long)volumeinfo->volid);
6026 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6027 entry.serverPartition[idx], 0L, 0L);
6034 idx = entry.nServers;
6037 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6038 /* The volume headers's RO ID does not match that in the VLDB entry,
6039 * and the vol hdr's ID is lower (implies its older). So orphan it.
6042 MapPartIdIntoName(apart, pname);
6044 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6045 (unsigned long)volumeinfo->volid,
6047 afs_inet_ntoa_r(aserver, hoststr) :
6048 hostutil_GetNameByINet(aserver), pname);
6050 " VLDB reports its RO volume ID is %u\n",
6051 entry.volumeId[ROVOL]);
6054 /* The RO volume ID in the volume header match that in the VLDB entry,
6055 * and there exist RO volumes in the VLDB entry. See if any of them
6056 * are this one. If not, then we add it.
6058 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6060 idx = entry.nServers;
6068 entry.flags |= RO_EXISTS;
6069 entry.volumeId[RWVOL] = rwvolid;
6070 entry.volumeId[ROVOL] = volumeinfo->volid;
6072 entry.serverNumber[idx] = aserver;
6073 entry.serverPartition[idx] = apart;
6074 entry.serverFlags[idx] = ITSROVOL;
6080 /* Remember largest volume id */
6081 if (entry.volumeId[ROVOL] > *maxvolid)
6082 *maxvolid = entry.volumeId[ROVOL];
6083 if (entry.volumeId[BACKVOL] > *maxvolid)
6084 *maxvolid = entry.volumeId[BACKVOL];
6085 if (entry.volumeId[RWVOL] > *maxvolid)
6086 *maxvolid = entry.volumeId[RWVOL];
6088 if (modified && doit) {
6089 MapNetworkToHost(&entry, &storeEntry);
6092 code = VLDB_CreateEntry(&storeEntry);
6095 "Could not create a VLDB entry for the volume %lu\n",
6096 (unsigned long)rwvolid);
6103 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6104 LOCKREL_OPCODE | LOCKREL_AFSID |
6107 fprintf(STDERR, "Could not update entry for %lu\n",
6108 (unsigned long)rwvolid);
6112 } else if (pass == 2) {
6114 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6115 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6117 PrintError("Could not unlock VLDB entry ", code);
6121 if (modified && modentry) {
6126 memcpy(aentry, &entry, sizeof(entry));
6130 fprintf(STDOUT, "-- status after --\n");
6132 EnumerateEntry(&entry);
6134 fprintf(STDOUT, "\n**no change**\n");
6138 VPRINT("\n_______________________________\n");
6143 sortVolumes(const void *a, const void *b)
6145 volintInfo *v1 = (volintInfo *) a;
6146 volintInfo *v2 = (volintInfo *) b;
6147 afs_uint32 rwvolid1, rwvolid2;
6149 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6150 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6152 if (rwvolid1 > rwvolid2)
6153 return -1; /* lower RW id goes first */
6154 if (rwvolid1 < rwvolid2)
6157 if (v1->type == RWVOL)
6158 return -1; /* RW vols go first */
6159 if (v2->type == RWVOL)
6162 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6163 return -1; /* BK vols next */
6164 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6167 if (v1->volid < v2->volid)
6168 return 1; /* larger volids first */
6169 if (v1->volid > v2->volid)
6175 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6176 * Synchronize an individual volume against a sever and partition.
6177 * Checks the VLDB entry (similar to syncserv) as well as checks
6178 * if the volume exists on specified servers (similar to syncvldb).
6181 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6183 struct rx_connection *aconn = 0;
6184 afs_int32 j, k, code, vcode, error = 0;
6186 afs_int32 mod, modified = 0, deleted = 0;
6187 struct nvldbentry vldbentry;
6188 afs_uint32 volumeid = 0;
6189 volEntries volumeInfo;
6190 struct partList PartList;
6192 afs_uint32 maxvolid = 0;
6194 volumeInfo.volEntries_val = (volintInfo *) 0;
6195 volumeInfo.volEntries_len = 0;
6197 /* Turn verbose logging off and do our own verbose logging */
6198 /* tverbose must be set before we call ERROR_EXIT() */
6205 if (!aserver && (flags & 1)) {
6206 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6210 /* Read the VLDB entry */
6211 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6212 if (vcode && (vcode != VL_NOENT)) {
6213 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6216 } else if (!vcode) {
6217 MapHostToNetwork(&vldbentry);
6221 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6222 fprintf(STDOUT, "_______________________________\n");
6223 fprintf(STDOUT, "\n-- status before -- \n");
6225 fprintf(STDOUT, "\n**does not exist**\n");
6227 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
6228 || (vldbentry.flags & BACK_EXISTS))
6229 EnumerateEntry(&vldbentry);
6231 fprintf(STDOUT, "\n");
6234 /* Verify that all of the VLDB entries exist on the repective servers
6235 * and partitions (this does not require that avolname be a volume ID).
6236 * Equivalent to a syncserv.
6239 /* Tell CheckVldb not to update if appropriate */
6244 code = CheckVldb(&vldbentry, &mod, &deleted);
6246 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6254 /* If aserver is given, we will search for the desired volume on it */
6256 /* Generate array of partitions on the server that we will check */
6258 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6261 "Could not fetch the list of partitions from the server\n");
6265 PartList.partId[0] = apart;
6269 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6271 /* If a volume ID were given, search for it on each partition */
6272 if ((volumeid = atol(avolname))) {
6273 for (j = 0; j < pcnt; j++) {
6275 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6278 if (code != ENODEV) {
6279 fprintf(STDERR, "Could not query server\n");
6287 /* Found one, sync it with VLDB entry */
6289 CheckVolume(volumeInfo.volEntries_val, aserver,
6290 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6297 if (volumeInfo.volEntries_val)
6298 free(volumeInfo.volEntries_val);
6299 volumeInfo.volEntries_val = (volintInfo *) 0;
6300 volumeInfo.volEntries_len = 0;
6304 /* Check to see if the RW, BK, and RO IDs exist on any
6305 * partitions. We get the volume IDs from the VLDB.
6307 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6308 if (vldbentry.volumeId[j] == 0)
6311 for (k = 0; k < pcnt; k++) { /* For each partition */
6312 volumeInfo.volEntries_val = (volintInfo *) 0;
6313 volumeInfo.volEntries_len = 0;
6315 AFSVolListOneVolume(aconn, PartList.partId[k],
6316 vldbentry.volumeId[j], &volumeInfo);
6318 if (code != ENODEV) {
6319 fprintf(STDERR, "Could not query server\n");
6327 /* Found one, sync it with VLDB entry */
6329 CheckVolume(volumeInfo.volEntries_val, aserver,
6330 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6337 if (volumeInfo.volEntries_val)
6338 free(volumeInfo.volEntries_val);
6339 volumeInfo.volEntries_val = (volintInfo *) 0;
6340 volumeInfo.volEntries_len = 0;
6346 /* If verbose output, print a summary of what changed */
6348 fprintf(STDOUT, "-- status after --\n");
6350 fprintf(STDOUT, "\n**entry deleted**\n");
6351 } else if (modified) {
6352 EnumerateEntry(&vldbentry);
6354 fprintf(STDOUT, "\n**no change**\n");
6356 fprintf(STDOUT, "\n_______________________________\n");
6360 /* Now check if the maxvolid is larger than that stored in the VLDB */
6362 afs_uint32 maxvldbid = 0;
6363 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6366 "Could not get the highest allocated volume id from the VLDB\n");
6369 } else if (maxvolid > maxvldbid) {
6371 id = maxvolid - maxvldbid + 1;
6372 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6375 "Error in increasing highest allocated volume id in VLDB\n");
6385 fprintf(STDOUT, "...error encountered");
6387 fprintf(STDOUT, "...done entry\n");
6390 rx_DestroyConnection(aconn);
6391 if (volumeInfo.volEntries_val)
6392 free(volumeInfo.volEntries_val);
6394 PrintError("", error);
6399 * Synchronise vldb with the file server <aserver> and,
6400 * optionally, <apart>.
6403 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6405 struct rx_connection *aconn;
6406 afs_int32 code, error = 0;
6409 volEntries volumeInfo;
6410 struct partList PartList;
6414 afs_int32 failures = 0, modifications = 0, tentries = 0;
6416 afs_uint32 maxvolid = 0;
6419 volumeInfo.volEntries_val = (volintInfo *) 0;
6420 volumeInfo.volEntries_len = 0;
6422 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6424 /* Generate array of partitions to check */
6426 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6429 "Could not fetch the list of partitions from the server\n");
6433 PartList.partId[0] = apart;
6437 VPRINT("Processing volume entries ...\n");
6439 /* Step through the array of partitions */
6440 for (i = 0; i < pcnt; i++) {
6441 apart = PartList.partId[i];
6442 MapPartIdIntoName(apart, pname);
6444 volumeInfo.volEntries_val = (volintInfo *) 0;
6445 volumeInfo.volEntries_len = 0;
6446 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6449 "Could not fetch the list of volumes from the server\n");
6453 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6454 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6455 sizeof(volintInfo), sortVolumes);
6458 for (vi = volumeInfo.volEntries_val, j = 0;
6459 j < volumeInfo.volEntries_len; j++, vi++) {
6467 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6468 j + 1, vi->name, (unsigned long)vi->volid,
6470 afs_inet_ntoa_r(aserver, hoststr) :
6471 hostutil_GetNameByINet(aserver), pname);
6479 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6481 PrintError("", code);
6484 } else if (modified) {
6490 fprintf(STDOUT, "...error encountered\n\n");
6492 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6499 "Could not process entries on server %s partition %s\n",
6501 afs_inet_ntoa_r(aserver, hoststr) :
6502 hostutil_GetNameByINet(aserver), pname);
6504 if (volumeInfo.volEntries_val) {
6505 free(volumeInfo.volEntries_val);
6506 volumeInfo.volEntries_val = 0;
6509 } /* thru all partitions */
6512 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6513 tentries, failures, modifications);
6515 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6516 tentries, failures, modifications);
6520 /* Now check if the maxvolid is larger than that stored in the VLDB */
6522 afs_uint32 maxvldbid = 0;
6523 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6526 "Could not get the highest allocated volume id from the VLDB\n");
6529 } else if (maxvolid > maxvldbid) {
6531 id = maxvolid - maxvldbid + 1;
6532 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6535 "Error in increasing highest allocated volume id in VLDB\n");
6543 rx_DestroyConnection(aconn);
6544 if (volumeInfo.volEntries_val)
6545 free(volumeInfo.volEntries_val);
6546 PrintError("", error);
6551 * Determine if a volume exists on a server and partition.
6552 * Try creating a transaction on the volume. If we can,
6553 * the volume exists, if not, then return the error code.
6554 * Some error codes mean the volume is unavailable but
6555 * still exists - so we catch these error codes.
6558 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6560 struct rx_connection *conn = (struct rx_connection *)0;
6561 afs_int32 code = -1;
6562 volEntries volumeInfo;
6564 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6566 volumeInfo.volEntries_val = (volintInfo *) 0;
6567 volumeInfo.volEntries_len = 0;
6568 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6569 if (volumeInfo.volEntries_val)
6570 free(volumeInfo.volEntries_val);
6571 if (code == VOLSERILLEGAL_PARTITION)
6573 rx_DestroyConnection(conn);
6582 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6586 afs_int32 code, error = 0;
6592 idx = Lp_GetRwIndex(entry);
6594 /* Check to see if the RW volume exists and set the RW_EXISTS
6597 if (idx == -1) { /* Did not find a RW entry */
6598 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6599 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6604 VolumeExists(entry->serverNumber[idx],
6605 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6606 if (code == 0) { /* RW volume exists */
6607 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6608 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6611 } else if (code == ENODEV) { /* RW volume does not exist */
6612 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6613 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6617 /* If VLDB says it didn't exist, then ignore error */
6618 if (entry->flags & RW_EXISTS) {
6619 MapPartIdIntoName(entry->serverPartition[idx], pname);
6621 "Transaction call failed for RW volume %u on server %s %s\n",
6622 entry->volumeId[RWVOL],
6624 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6625 hostutil_GetNameByINet(entry->serverNumber[idx]),
6632 /* Check to see if the BK volume exists and set the BACK_EXISTS
6633 * flag accordingly. idx already ponts to the RW entry.
6635 if (idx == -1) { /* Did not find a RW entry */
6636 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6637 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6640 } else { /* Found a RW entry */
6642 VolumeExists(entry->serverNumber[idx],
6643 entry->serverPartition[idx],
6644 entry->volumeId[BACKVOL]);
6645 if (code == 0) { /* BK volume exists */
6646 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6647 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6650 } else if (code == ENODEV) { /* BK volume does not exist */
6651 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6652 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6656 /* If VLDB says it didn't exist, then ignore error */
6657 if (entry->flags & BACK_EXISTS) {
6658 MapPartIdIntoName(entry->serverPartition[idx], pname);
6660 "Transaction call failed for BK volume %u on server %s %s\n",
6661 entry->volumeId[BACKVOL],
6663 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6664 hostutil_GetNameByINet(entry->serverNumber[idx]),
6671 /* If there is an idx but the BK and RW volumes no
6672 * longer exist, then remove the RW entry.
6674 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6675 && !(entry->flags & BACK_EXISTS)) {
6676 Lp_SetRWValue(entry, entry->serverNumber[idx],
6677 entry->serverPartition[idx], 0L, 0L);
6684 *modified = modentry;
6689 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6692 int foundro = 0, modentry = 0;
6693 afs_int32 code, error = 0;
6700 /* Check to see if the RO volumes exist and set the RO_EXISTS
6703 for (idx = 0; idx < entry->nServers; idx++) {
6704 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6705 continue; /* not a RO */
6709 VolumeExists(entry->serverNumber[idx],
6710 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6711 if (code == 0) { /* RO volume exists */
6713 } else if (code == ENODEV) { /* RW volume does not exist */
6714 Lp_SetROValue(entry, entry->serverNumber[idx],
6715 entry->serverPartition[idx], 0L, 0L);
6720 MapPartIdIntoName(entry->serverPartition[idx], pname);
6722 "Transaction call failed for RO %u on server %s %s\n",
6723 entry->volumeId[ROVOL],
6725 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6726 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6731 if (foundro) { /* A RO volume exists */
6732 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6733 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6736 } else { /* A RO volume does not exist */
6737 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6738 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6745 *modified = modentry;
6750 * Ensure that <entry> matches with the info on file servers
6753 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6755 afs_int32 code, error = 0;
6756 struct nvldbentry storeEntry;
6757 int islocked = 0, mod, modentry, delentry = 0;
6758 int pass = 0, doit=1;
6766 fprintf(STDOUT, "_______________________________\n");
6767 fprintf(STDOUT, "\n-- status before -- \n");
6768 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6769 || (entry->flags & BACK_EXISTS))
6770 EnumerateEntry(entry);
6771 fprintf(STDOUT, "\n");
6774 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6775 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6776 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6780 /* Check to see if the VLDB is ok without locking it (pass 1).
6781 * If it will change, then lock the VLDB entry, read it again,
6782 * then make the changes to it (pass 2).
6786 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6789 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6790 entry->volumeId[RWVOL]);
6795 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6797 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6801 MapHostToNetwork(entry);
6807 /* Check if the RW and BK entries are ok */
6808 code = CheckVldbRWBK(entry, &mod);
6811 if (mod && (pass == 1) && doit)
6816 /* Check if the RO volumes entries are ok */
6817 code = CheckVldbRO(entry, &mod);
6820 if (mod && (pass == 1) && doit)
6825 /* The VLDB entry has been updated. If it as been modified, then
6826 * write the entry back out the the VLDB.
6828 if (modentry && doit) {
6832 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6833 && !(entry->flags & RO_EXISTS) && doit) {
6834 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6836 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6840 "Could not delete VLDB entry for volume %u \n",
6841 entry->volumeId[RWVOL]);
6846 /* Replace old entry with our new one */
6847 MapNetworkToHost(entry, &storeEntry);
6849 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6850 (LOCKREL_OPCODE | LOCKREL_AFSID |
6851 LOCKREL_TIMESTAMP));
6853 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6854 entry->volumeId[RWVOL]);
6861 if (modified && modentry) {
6864 if (deleted && delentry) {
6869 fprintf(STDOUT, "-- status after --\n");
6871 fprintf(STDOUT, "\n**entry deleted**\n");
6873 EnumerateEntry(entry);
6875 fprintf(STDOUT, "\n**no change**\n");
6879 VPRINT("\n_______________________________\n");
6883 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6885 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6888 "Could not release lock on VLDB entry for volume %u\n",
6889 entry->volumeId[RWVOL]);
6898 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6901 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6903 struct rx_connection *aconn;
6904 afs_int32 code, error = 0;
6905 afs_int32 nentries, tentries = 0;
6906 struct VldbListByAttributes attributes;
6907 nbulkentries arrayEntries;
6908 afs_int32 failures = 0, modified, modifications = 0;
6909 struct nvldbentry *vlentry;
6910 afs_int32 si, nsi, j;
6915 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6917 /* Set up attributes to search VLDB */
6918 attributes.server = ntohl(aserver);
6919 attributes.Mask = VLLIST_SERVER;
6921 attributes.partition = apart;
6922 attributes.Mask |= VLLIST_PARTITION;
6925 VPRINT("Processing VLDB entries ...\n");
6927 /* While we need to collect more VLDB entries */
6928 for (si = 0; si != -1; si = nsi) {
6929 memset(&arrayEntries, 0, sizeof(arrayEntries));
6931 /* Collect set of VLDB entries */
6933 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6934 &arrayEntries, &nsi);
6935 if (code == RXGEN_OPCODE) {
6936 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6940 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6943 tentries += nentries;
6945 for (j = 0; j < nentries; j++) {
6946 vlentry = &arrayEntries.nbulkentries_val[j];
6947 MapHostToNetwork(vlentry);
6949 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6951 /* Tell CheckVldb not to update if appropriate */
6956 code = CheckVldb(vlentry, &modified, NULL);
6958 PrintError("", code);
6960 "Could not process VLDB entry for volume %s\n",
6963 } else if (modified) {
6969 fprintf(STDOUT, "...error encountered\n\n");
6971 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6976 if (arrayEntries.nbulkentries_val) {
6977 free(arrayEntries.nbulkentries_val);
6978 arrayEntries.nbulkentries_val = 0;
6983 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6984 tentries, failures, modifications);
6986 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6987 tentries, failures, modifications);
6992 rx_DestroyConnection(aconn);
6993 if (arrayEntries.nbulkentries_val)
6994 free(arrayEntries.nbulkentries_val);
6997 error = VOLSERFAILEDOP;
7001 /*rename volume <oldname> to <newname>, changing the names of the related
7002 *readonly and backup volumes. This operation is also idempotent.
7003 *salvager is capable of recovering from rename operation stopping halfway.
7004 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
7006 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
7008 struct nvldbentry storeEntry;
7009 afs_int32 vcode, code, rcode, error;
7011 char nameBuffer[256];
7013 struct rx_connection *aconn;
7018 aconn = (struct rx_connection *)0;
7022 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7025 " Could not lock the VLDB entry for the volume %u \n",
7026 entry->volumeId[RWVOL]);
7031 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7032 MapNetworkToHost(entry, &storeEntry);
7033 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7035 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7036 entry->volumeId[RWVOL]);
7040 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7041 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7042 * is concerned, oldname is lost */
7043 if (entry->flags & RW_EXISTS) {
7044 index = Lp_GetRwIndex(entry);
7045 if (index == -1) { /* there is a serious discrepancy */
7047 "There is a serious discrepancy in VLDB entry for volume %u\n",
7048 entry->volumeId[RWVOL]);
7049 fprintf(STDERR, "try building VLDB from scratch\n");
7050 error = VOLSERVLDB_ERROR;
7053 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7055 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7056 entry->serverPartition[index], ITOffline, &tid);
7057 if (code) { /*volume doesnot exist */
7059 "Could not start transaction on the rw volume %u\n",
7060 entry->volumeId[RWVOL]);
7063 } else { /*volume exists, process it */
7066 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7067 entry->volumeId[RWVOL],
7068 entry->volumeId[ROVOL],
7069 entry->volumeId[BACKVOL]);
7071 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7072 code = AFSVolEndTrans(aconn, tid, &rcode);
7076 "Could not end transaction on volume %s %u\n",
7077 entry->name, entry->volumeId[RWVOL]);
7082 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7083 entry->name, entry->volumeId[RWVOL]);
7089 rx_DestroyConnection(aconn);
7090 aconn = (struct rx_connection *)0;
7092 /*end rw volume processing */
7093 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
7094 index = Lp_GetRwIndex(entry);
7095 if (index == -1) { /* there is a serious discrepancy */
7097 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7098 entry->volumeId[BACKVOL]);
7099 fprintf(STDERR, "try building VLDB from scratch\n");
7100 error = VOLSERVLDB_ERROR;
7103 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7105 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7106 entry->serverPartition[index], ITOffline, &tid);
7107 if (code) { /*volume doesnot exist */
7109 "Could not start transaction on the backup volume %u\n",
7110 entry->volumeId[BACKVOL]);
7113 } else { /*volume exists, process it */
7114 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7116 "Volume name %s.backup exceeds the limit of %u characters\n",
7117 newname, VOLSER_OLDMAXVOLNAME);
7121 strcpy(nameBuffer, newname);
7122 strcat(nameBuffer, ".backup");
7125 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7126 entry->volumeId[RWVOL], 0, 0);
7128 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7129 code = AFSVolEndTrans(aconn, tid, &rcode);
7133 "Could not end transaction on the backup volume %u\n",
7134 entry->volumeId[BACKVOL]);
7140 "Could not set parameters on the backup volume %u\n",
7141 entry->volumeId[BACKVOL]);
7146 } /* end backup processing */
7148 rx_DestroyConnection(aconn);
7149 aconn = (struct rx_connection *)0;
7150 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
7151 for (i = 0; i < entry->nServers; i++) {
7152 if (entry->serverFlags[i] & ITSROVOL) {
7153 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7155 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7156 entry->serverPartition[i], ITOffline,
7158 if (code) { /*volume doesnot exist */
7160 "Could not start transaction on the ro volume %u\n",
7161 entry->volumeId[ROVOL]);
7164 } else { /*volume exists, process it */
7165 strcpy(nameBuffer, newname);
7166 strcat(nameBuffer, ".readonly");
7167 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7169 "Volume name %s exceeds the limit of %u characters\n",
7170 nameBuffer, VOLSER_OLDMAXVOLNAME);
7175 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7176 entry->volumeId[RWVOL], 0, 0);
7178 VPRINT2("Renamed RO volume %s on host %s\n",
7181 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7182 hostutil_GetNameByINet(entry->
7184 code = AFSVolEndTrans(aconn, tid, &rcode);
7188 "Could not end transaction on volume %u\n",
7189 entry->volumeId[ROVOL]);
7195 "Could not set parameters on the ro volume %u\n",
7196 entry->volumeId[ROVOL]);
7202 rx_DestroyConnection(aconn);
7203 aconn = (struct rx_connection *)0;
7210 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7212 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7215 "Could not unlock the VLDB entry for the volume %s %u\n",
7216 entry->name, entry->volumeId[RWVOL]);
7222 code = AFSVolEndTrans(aconn, tid, &rcode);
7226 fprintf(STDERR, "Failed to end transaction on a volume \n");
7232 rx_DestroyConnection(aconn);
7233 PrintError("", error);
7238 /*report on all the active transactions on volser */
7240 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7242 struct rx_connection *aconn;
7243 transDebugEntries transInfo;
7246 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7247 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7248 transInfo.transDebugEntries_len = 0;
7249 code = AFSVolMonitor(aconn, &transInfo);
7252 "Could not access status information about the server\n");
7253 PrintError("", code);
7254 if (transInfo.transDebugEntries_val)
7255 free(transInfo.transDebugEntries_val);
7257 rx_DestroyConnection(aconn);
7260 *rcount = transInfo.transDebugEntries_len;
7261 *rpntr = transInfo.transDebugEntries_val;
7263 rx_DestroyConnection(aconn);
7270 /*delete the volume without interacting with the vldb */
7272 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7275 struct rx_connection *aconn;
7277 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7278 error = DoVolDelete(aconn, volid, part,
7279 "the", 0, NULL, NULL);
7281 PrintError("", error);
7283 rx_DestroyConnection(aconn);
7288 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7289 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7291 struct rx_connection *conn = 0;
7293 afs_int32 code, error = 0, rcode;
7295 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7297 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7301 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7303 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7307 code = AFSVolSetFlags(conn, tid, setflag);
7309 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7314 #ifdef AFS_PTHREAD_ENV
7317 IOMGR_Sleep(sleeptime);
7324 code = AFSVolEndTrans(conn, tid, &rcode);
7325 if (code || rcode) {
7326 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7328 error = (code ? code : rcode);
7333 rx_DestroyConnection(conn);
7338 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7341 struct rx_connection *conn = 0;
7343 afs_int32 code, error = 0, rcode;
7345 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7347 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7351 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7353 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7357 code = AFSVolSetInfo(conn, tid, infop);
7359 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7366 code = AFSVolEndTrans(conn, tid, &rcode);
7367 if (code || rcode) {
7368 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7370 error = (code ? code : rcode);
7375 rx_DestroyConnection(conn);
7380 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7381 afs_int32 fromdate, struct volintSize *vol_size)
7383 struct rx_connection *aconn = (struct rx_connection *)0;
7384 afs_int32 tid = 0, rcode = 0;
7385 afs_int32 code, error = 0;
7388 /* get connections to the servers */
7389 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7391 VPRINT1("Starting transaction on volume %u...", afromvol);
7392 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7393 EGOTO1(error_exit, code,
7394 "Could not start transaction on the volume %u to be measured\n",
7398 VPRINT1("Getting size of volume on volume %u...", afromvol);
7399 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7400 EGOTO(error_exit, code, "Could not start the measurement process \n");
7405 VPRINT1("Ending transaction on volume %u...", afromvol);
7406 code = AFSVolEndTrans(aconn, tid, &rcode);
7407 if (code || rcode) {
7408 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7410 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7412 error = (code ? code : rcode);
7417 rx_DestroyConnection(aconn);
7419 PrintError("", error);
7423 /*maps the host addresses in <old > (present in network byte order) to
7424 that in< new> (present in host byte order )*/
7426 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7430 /*copy all the fields */
7431 strcpy(new->name, old->name);
7432 /* new->volumeType = old->volumeType;*/
7433 new->nServers = old->nServers;
7434 count = old->nServers;
7435 if (count < NMAXNSERVERS)
7437 for (i = 0; i < count; i++) {
7438 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7439 new->serverPartition[i] = old->serverPartition[i];
7440 new->serverFlags[i] = old->serverFlags[i];
7442 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7443 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7444 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7445 new->cloneId = old->cloneId;
7446 new->flags = old->flags;
7449 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7451 MapHostToNetwork(struct nvldbentry *entry)
7455 count = entry->nServers;
7456 if (count < NMAXNSERVERS)
7458 for (i = 0; i < count; i++) {
7459 entry->serverNumber[i] = htonl(entry->serverNumber[i]);