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 */
162 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
163 struct rx_connection **connPtr, afs_int32 * transPtr,
164 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
165 afs_int32 *origflags, afs_uint32 tmpVolId);
166 static int SimulateForwardMultiple(struct rx_connection *fromconn,
167 afs_int32 fromtid, afs_int32 fromdate,
168 manyDests * tr, afs_int32 flags,
169 void *cookie, manyResults * results);
170 static int DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
171 afs_int32 apart, int type, afs_uint32 cloneid,
172 char *typestring, char *pname, char *vname, char *suffix,
173 struct volser_status *volstatus, afs_int32 *transPtr);
174 static int DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
175 afs_int32 apart, char *typestring, afs_uint32 atoserver,
176 struct volser_status *volstatus, char *pprefix);
177 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
178 afs_int32 apart, afs_int32 * modentry,
179 afs_uint32 * maxvolid, struct nvldbentry *aentry);
180 static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition,
181 afs_uint32 volumeid);
182 static afs_int32 CheckVldbRWBK(struct nvldbentry * entry,
183 afs_int32 * modified);
184 static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified);
185 static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified,
187 static void dump_sig_handler(int x);
188 static int sortVolumes(const void *a, const void *b);
191 /*map the partition <partId> into partition name <partName>*/
193 MapPartIdIntoName(afs_int32 partId, char *partName)
195 if (partId < 26) { /* what if partId > = 26 ? */
196 strcpy(partName, "/vicep");
197 partName[6] = partId + 'a';
200 } else if (partId < VOLMAXPARTS) {
201 strcpy(partName, "/vicep");
203 partName[6] = 'a' + (partId / 26);
204 partName[7] = 'a' + (partId % 26);
211 PrintError(char *msg, afs_int32 errcode)
213 fprintf(STDERR, "%s", msg);
214 /*replace by a big switch statement */
219 fprintf(STDERR, "Possible communication failure\n");
222 fprintf(STDERR, "Volume needs to be salvaged\n");
225 fprintf(STDERR, "Bad vnode number quoted\n");
229 "Volume not attached, does not exist, or not on line\n");
232 fprintf(STDERR, "Volume already exists\n");
235 fprintf(STDERR, "Volume is not in service\n");
238 fprintf(STDERR, "Volume is off line\n");
241 fprintf(STDERR, "Volume is already on line\n");
244 fprintf(STDERR, "Partition is full\n");
247 fprintf(STDERR, "Volume max quota exceeded\n");
250 fprintf(STDERR, "Volume temporarily unavailable\n");
253 fprintf(STDERR, "Volume has moved to another server\n");
256 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
259 fprintf(STDERR, "VLDB: a read terminated too early\n");
262 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
265 fprintf(STDERR, "VLDB: internal creation failure\n");
268 fprintf(STDERR, "VLDB: no such entry\n");
271 fprintf(STDERR, "VLDB: vldb database is empty\n");
274 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
277 fprintf(STDERR, "VLDB: volume name is illegal\n");
280 fprintf(STDERR, "VLDB: index was out of range\n");
283 fprintf(STDERR, "VLDB: bad volume type\n");
286 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
288 case VL_BADPARTITION:
289 fprintf(STDERR, "VLDB: bad partition number\n");
292 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
295 fprintf(STDERR, "VLDB: no such repsite server exists\n");
297 case VL_DUPREPSERVER:
298 fprintf(STDERR, "VLDB: replication site server already exists\n");
301 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
304 fprintf(STDERR, "VLDB: illegal reference count number\n");
306 case VL_SIZEEXCEEDED:
307 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
310 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
312 case VL_BADVOLIDBUMP:
313 fprintf(STDERR, "VLDB: illegal max volid increment\n");
315 case VL_IDALREADYHASHED:
316 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
319 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
322 fprintf(STDERR, "VLDB: bad volume operation code\n");
324 case VL_BADRELLOCKTYPE:
325 fprintf(STDERR, "VLDB: bad release lock type\n");
328 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
330 case VL_BADSERVERFLAG:
331 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
334 fprintf(STDERR, "VLDB: no permission access for call\n");
336 case VOLSERREAD_DUMPERROR:
338 "VOLSER: Problems encountered in reading the dump file !\n");
340 case VOLSERDUMPERROR:
341 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
343 case VOLSERATTACH_ERROR:
344 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
346 case VOLSERDETACH_ERROR:
347 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
349 case VOLSERILLEGAL_PARTITION:
350 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
352 case VOLSERBAD_ACCESS:
353 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
355 case VOLSERVLDB_ERROR:
356 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
359 fprintf(STDERR, "VOLSER: error in volume name\n");
362 fprintf(STDERR, "VOLSER: volume has moved\n");
365 fprintf(STDERR, "VOLSER: illegal operation\n");
367 case VOLSERBADRELEASE:
368 fprintf(STDERR, "VOLSER: release could not be completed\n");
371 fprintf(STDERR, "VOLSER: volume is busy\n");
373 case VOLSERNO_MEMORY:
374 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
378 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
380 case VOLSERMULTIRWVOL:
382 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
386 "VOLSER: not all entries were successfully processed\n");
390 initialize_RXK_error_table();
391 initialize_KTC_error_table();
392 initialize_ACFG_error_table();
393 initialize_VL_error_table();
395 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
396 afs_error_message(errcode));
403 void init_volintInfo(struct volintInfo *vinfo) {
404 memset(vinfo, 0, sizeof(struct volintInfo));
406 vinfo->maxquota = -1;
408 vinfo->creationDate = -1;
409 vinfo->updateDate = -1;
417 static struct rx_securityClass *uvclass = 0;
418 static int uvindex = -1;
419 /* called by VLDBClient_Init to set the security module to be used in the RPC */
421 UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
428 /* bind to volser on <port> <aserver> */
429 /* takes server address in network order, port in host order. dumb */
430 struct rx_connection *
431 UV_Bind(afs_uint32 aserver, afs_int32 port)
433 struct rx_connection *tc;
435 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
441 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
442 afs_int32 partition, char *name, afs_int32 type,
443 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
448 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
450 if (code != VOLSERVOLBUSY)
453 #ifdef AFS_PTHREAD_ENV
456 IOMGR_Sleep(3-retries);
463 AFSVolTransCreate_retry(struct rx_connection *z_conn,
464 afs_int32 volume, afs_int32 partition,
465 afs_int32 flags, afs_int32 * trans)
470 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
471 if (code != VOLSERVOLBUSY)
474 #ifdef AFS_PTHREAD_ENV
477 IOMGR_Sleep(3-retries);
483 /* called by EmuerateEntry, show vldb entry in a reasonable format */
485 SubEnumerateEntry(struct nvldbentry *entry)
492 if (entry->flags & VLF_RWEXISTS)
493 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
494 if (entry->flags & VLF_ROEXISTS)
495 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
496 if (entry->flags & VLF_BACKEXISTS)
497 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
498 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
499 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
500 fprintf(STDOUT, "\n");
501 fprintf(STDOUT, " number of sites -> %lu\n",
502 (unsigned long)entry->nServers);
503 for (i = 0; i < entry->nServers; i++) {
504 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
507 for (i = 0; i < entry->nServers; i++) {
508 MapPartIdIntoName(entry->serverPartition[i], pname);
509 fprintf(STDOUT, " server %s partition %s ",
510 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
511 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
512 if (entry->serverFlags[i] & VLSF_RWVOL)
513 fprintf(STDOUT, "RW Site ");
515 fprintf(STDOUT, "RO Site ");
517 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
518 fprintf(STDOUT," -- New release");
520 if (!(entry->serverFlags[i] & VLSF_RWVOL))
521 fprintf(STDOUT," -- Old release");
523 if (entry->serverFlags[i] & VLSF_DONTUSE)
524 fprintf(STDOUT, " -- Not released");
526 fprintf(STDOUT, "\n");
533 /*enumerate the vldb entry corresponding to <entry> */
535 EnumerateEntry(struct nvldbentry *entry)
538 fprintf(STDOUT, "\n");
539 fprintf(STDOUT, "%s \n", entry->name);
540 SubEnumerateEntry(entry);
544 /* forcibly remove a volume. Very dangerous call */
546 UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
548 struct rx_connection *tconn;
551 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
553 code = AFSVolNukeVolume(tconn, partid, volid);
554 rx_DestroyConnection(tconn);
560 /* like df. Return usage of <pname> on <server> in <partition> */
562 UV_PartitionInfo64(afs_uint32 server, char *pname,
563 struct diskPartition64 *partition)
565 struct rx_connection *aconn;
568 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
569 code = AFSVolPartitionInfo64(aconn, pname, partition);
570 if (code == RXGEN_OPCODE) {
571 struct diskPartition *dpp = malloc(sizeof(struct diskPartition));
572 code = AFSVolPartitionInfo(aconn, pname, dpp);
574 strncpy(partition->name, dpp->name, 32);
575 strncpy(partition->devName, dpp->devName, 32);
576 partition->lock_fd = dpp->lock_fd;
577 partition->free = dpp->free;
578 partition->minFree = dpp->minFree;
583 fprintf(STDERR, "Could not get information on partition %s\n", pname);
584 PrintError("", code);
587 rx_DestroyConnection(aconn);
591 /* old interface to create volumes */
593 UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
598 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
602 /* less old interface to create volumes */
604 UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
605 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
606 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
608 afs_uint32 roid = 0, bkid = 0;
609 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
610 aspare3, aspare4, anewid, &roid, &bkid);
614 * Create a volume on the given server and partition
616 * @param aserver server to create volume on
617 * @param spart partition to create volume on
618 * @param aname name of new volume
619 * @param aquota quota for new volume
620 * @param anewid contains the desired volume id for the new volume. If
621 * *anewid == 0, a new id will be chosen, and will be placed
622 * in *anewid when UV_CreateVolume3 returns.
623 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
624 * will be unset. If *aroid == 0, an id will be chosen, and
625 * will be placed in *anewid when UV_CreateVolume3 returns.
626 * @param abkid same as aroid, except for the BK volume id instead of the
628 * @return 0 on success, error code otherwise.
631 UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
632 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
633 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
634 afs_uint32 * aroid, afs_uint32 * abkid)
636 struct rx_connection *aconn;
640 afs_int32 rcode, vcode;
642 struct nvldbentry entry, storeEntry; /*the new vldb entry */
643 struct volintInfo tstatus;
648 memset(&storeEntry, 0, sizeof(struct nvldbentry));
650 init_volintInfo(&tstatus);
651 tstatus.maxquota = aquota;
653 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
655 if (aroid && *aroid) {
656 VPRINT1("Using RO volume ID %d.\n", *aroid);
658 if (abkid && *abkid) {
659 VPRINT1("Using BK volume ID %d.\n", *abkid);
663 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
665 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
668 VPRINT1("Using volume ID %d.\n", *anewid);
670 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
671 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
673 if (aroid && *aroid == 0) {
674 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
675 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
678 if (abkid && *abkid == 0) {
679 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
680 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
684 /* rw,ro, bk id are related in the default case */
685 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
687 if (aroid && *aroid != 0) {
688 lastid = max(lastid, *aroid);
690 if (abkid && *abkid != 0) {
691 lastid = max(lastid, *abkid);
693 if (aroid && *aroid == 0) {
696 if (abkid && *abkid == 0) {
701 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
702 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
705 code = AFSVolSetInfo(aconn, tid, &tstatus);
707 EPRINT(code, "Could not change quota, continuing...\n");
709 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
710 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
713 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
715 /* set up the vldb entry for this volume */
716 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
718 entry.serverNumber[0] = aserver; /* this should have another
719 * level of indirection later */
720 entry.serverPartition[0] = apart; /* this should also have
721 * another indirection level */
722 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
723 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
724 entry.volumeId[RWVOL] = *anewid;
725 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
726 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
728 /*map into right byte order, before passing to xdr, the stuff has to be in host
729 * byte order. Xdr converts it into network order */
730 MapNetworkToHost(&entry, &storeEntry);
731 /* create the vldb entry */
732 vcode = VLDB_CreateEntry(&storeEntry);
735 "Could not create a VLDB entry for the volume %s %lu\n",
736 aname, (unsigned long)*anewid);
737 /*destroy the created volume */
738 VPRINT1("Deleting the newly created volume %u\n", *anewid);
739 AFSVolDeleteVolume(aconn, tid);
743 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
744 /* volume created, now terminate the transaction and release the connection */
745 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
746 * the volume will come online anyway when transaction timesout , so if
747 * vldb entry exists then the volume is guaranteed to exist too wrt create */
751 "Failed to end the transaction on the volume %s %lu\n", aname,
752 (unsigned long)*anewid);
759 code = AFSVolEndTrans(aconn, tid, &rcode);
761 fprintf(STDERR, "WARNING: could not end transaction\n");
764 rx_DestroyConnection(aconn);
765 PrintError("", error);
769 /* create a volume, given a server, partition number, volume name --> sends
770 * back new vol id in <anewid>*/
772 UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
775 struct rx_connection *aconn;
778 struct nvldbentry entry, storeEntry; /*the new vldb entry */
780 memset(&storeEntry, 0, sizeof(struct nvldbentry));
782 aconn = (struct rx_connection *)0;
785 /* set up the vldb entry for this volume */
786 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
788 entry.serverNumber[0] = aserver; /* this should have another
789 * level of indirection later */
790 entry.serverPartition[0] = apart; /* this should also have
791 * another indirection level */
792 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
793 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
794 entry.volumeId[RWVOL] = aid;
795 entry.volumeId[ROVOL] = 0;
796 entry.volumeId[BACKVOL] = 0;
798 /*map into right byte order, before passing to xdr, the stuff has to be in host
799 * byte order. Xdr converts it into network order */
800 MapNetworkToHost(&entry, &storeEntry);
801 /* create the vldb entry */
802 vcode = VLDB_CreateEntry(&storeEntry);
805 "Could not create a VLDB entry for the volume %s %lu\n",
806 aname, (unsigned long)aid);
810 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
814 rx_DestroyConnection(aconn);
815 PrintError("", error);
819 /* Delete the volume <volid>on <aserver> <apart>
820 * the physical entry gets removed from the vldb only if the ref count
824 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
826 struct rx_connection *aconn = (struct rx_connection *)0;
828 afs_int32 code, rcode;
830 struct nvldbentry entry, storeEntry;
832 afs_int32 avoltype = -1, vtype;
833 int notondisk = 0, notinvldb = 0;
835 memset(&storeEntry, 0, sizeof(struct nvldbentry));
837 /* Find and read bhe VLDB entry for this volume */
838 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
840 if (code != VL_NOENT) {
841 EGOTO1(error_exit, code,
842 "Could not lock VLDB entry for the volume %u\n", avolid);
848 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
849 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
851 MapHostToNetwork(&entry);
854 EnumerateEntry(&entry);
857 /* Whether volume is in the VLDB or not. Delete the volume on disk */
858 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
860 code = DoVolDelete(aconn, avolid, apart, "the", 0, NULL, NULL);
870 /* Now update the VLDB entry.
871 * But first, verify we have a VLDB entry.
872 * Whether volume is on disk or not. Delete the volume in VLDB.
877 if (avolid == entry.volumeId[BACKVOL]) {
878 /* Its a backup volume, modify the VLDB entry. Check that the
879 * backup volume is on the server/partition we asked to delete.
881 if (!(entry.flags & VLF_BACKEXISTS) || !Lp_Match(aserver, apart, &entry)) {
882 notinvldb = 2; /* Not on this server and partition */
886 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
888 entry.flags &= ~VLF_BACKEXISTS;
892 else if (avolid == entry.volumeId[ROVOL]) {
893 /* Its a read-only volume, modify the VLDB entry. Check that the
894 * readonly volume is on the server/partition we asked to delete.
895 * If flags does not have RO_EIXSTS set, then this may mean the RO
896 * hasn't been released (and could exist in VLDB).
898 if (!Lp_ROMatch(aserver, apart, &entry)) {
899 notinvldb = 2; /* Not found on this server and partition */
905 "Marking the readonly volume %lu deleted in the VLDB\n",
906 (unsigned long)avolid);
908 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
910 if (!Lp_ROMatch(0, 0, &entry))
911 entry.flags &= ~VLF_ROEXISTS; /* This was the last ro volume */
915 else if (avolid == entry.volumeId[RWVOL]) {
916 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
917 * Check that the readwrite volumes is on the server/partition we
920 if (!(entry.flags & VLF_RWEXISTS) || !Lp_Match(aserver, apart, &entry)) {
921 notinvldb = 2; /* Not found on this server and partition */
925 if (entry.volumeId[BACKVOL]) {
926 /* Delete backup if it exists */
927 code = DoVolDelete(aconn, entry.volumeId[BACKVOL], apart,
928 "the backup", 0, NULL, NULL);
929 if (code && code != VNOVOL) {
937 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
938 (unsigned long)avolid,
940 flags & VLF_BACKEXISTS) ? ", and its backup volume," :
943 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
945 entry.flags &= ~(VLF_BACKEXISTS | VLF_RWEXISTS);
948 if (entry.flags & VLF_ROEXISTS)
949 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
953 notinvldb = 2; /* Not found on this server and partition */
957 /* Either delete or replace the VLDB entry */
958 if ((entry.nServers <= 0) || !(entry.flags & (VLF_ROEXISTS | VLF_RWEXISTS))) {
961 "Last reference to the VLDB entry for %lu - deleting entry\n",
962 (unsigned long)avolid);
963 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
964 EGOTO1(error_exit, code,
965 "Could not delete the VLDB entry for the volume %u \n",
968 MapNetworkToHost(&entry, &storeEntry);
970 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
971 (LOCKREL_OPCODE | LOCKREL_AFSID |
973 EGOTO1(error_exit, code,
974 "Could not update the VLDB entry for the volume %u \n",
983 if (notondisk && notinvldb) {
984 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
985 ((notinvldb == 2) ? "on server and partition" : ""));
988 } else if (notondisk) {
990 "WARNING: Volume %lu did not exist on the partition\n",
991 (unsigned long)avolid);
992 } else if (notinvldb) {
993 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
994 (unsigned long)avolid,
995 ((notinvldb == 2) ? "on server and partition" : ""));
999 code = AFSVolEndTrans(aconn, ttid, &rcode);
1000 code = (code ? code : rcode);
1002 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1003 (unsigned long)avolid);
1004 PrintError("", code);
1012 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1013 (LOCKREL_OPCODE | LOCKREL_AFSID |
1014 LOCKREL_TIMESTAMP));
1017 "Could not release the lock on the VLDB entry for the volume %u \n",
1025 rx_DestroyConnection(aconn);
1029 /* add recovery to UV_MoveVolume */
1031 #define TESTC 0 /* set to test recovery code, clear for production */
1037 do_interrupt(void * unused)
1040 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1041 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1042 * changed. This will avoid some sanity checks, but until a better way
1043 * is found, the only alternative is always crashing and burning on at
1044 * least the stack-overflow check. */
1045 lwp_cpptr->stack = NULL;
1050 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1052 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1053 fprintf(STDOUT, "enter second control-c to exit\n");
1061 sigint_handler(int x)
1063 #ifdef AFS_PTHREAD_ENV
1066 IOMGR_SoftSig(do_interrupt, 0);
1068 (void)signal(SIGINT, sigint_handler);
1072 DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
1073 afs_int32 apart, char *ptypestring, afs_uint32 atoserver,
1074 struct volser_status *volstatus, char *pprefix)
1076 afs_int32 ttid = 0, code, rcode, error = 0;
1077 char *prefix, *typestring;
1086 typestring = ptypestring;
1092 VPRINT3("%sDeleting %s volume %u ...", prefix, typestring, avolid);
1095 AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
1097 /* return early and quietly for VNOVOL; don't continue the attempt to delete. */
1098 if (code == VNOVOL) {
1103 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1107 code = AFSVolGetStatus(aconn, ttid, volstatus);
1108 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1113 AFSVolSetFlags(aconn, ttid,
1114 VTDeleteOnSalvage | VTOutOfService);
1116 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1120 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1121 AFSVolSetForwarding(aconn, ttid, atoserver);
1125 code = AFSVolDeleteVolume(aconn, ttid);
1126 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1130 code = AFSVolEndTrans(aconn, ttid, &rcode);
1135 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1136 prefix, typestring, (unsigned long)avolid);
1142 if (beverbose && !error)
1148 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1149 afs_int32 apart, int type, afs_uint32 cloneid,
1150 char *typestring, char *pname, char *vname, char *suffix,
1151 struct volser_status *volstatus, afs_int32 *transPtr)
1154 afs_int32 ttid = 0, btid = 0;
1155 afs_int32 code = 0, rcode = 0;
1156 afs_int32 error = 0;
1157 int cloneexists = 1;
1159 /* Test to see if the clone volume exists by trying to create
1160 * a transaction on the clone volume. We've assumed the clone exists.
1162 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1164 if (code != VNOVOL) {
1165 EPRINT2(code, "Could not reach the %s volume %lu\n",
1166 typestring, (unsigned long)cloneid);
1170 cloneexists = 0; /* clone volume does not exist */
1173 code = AFSVolEndTrans(aconn, btid, &rcode);
1175 if (code || rcode) {
1177 "Could not end transaction on the previous %s volume %lu\n",
1178 typestring, (unsigned long)cloneid);
1179 error = (code ? code : rcode);
1184 /* Now go ahead and try to clone the RW volume.
1185 * First start a transaction on the RW volume
1187 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1189 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1190 (unsigned long)avolid);
1195 /* Clone or reclone the volume, depending on whether the clone
1196 * volume exists or not
1199 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1201 code = AFSVolReClone(aconn, ttid, cloneid);
1203 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1204 typestring, (unsigned long)cloneid);
1209 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1212 strcpy(cname, pname);
1213 strcat(cname, suffix);
1216 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1219 fprintf(STDERR, "Failed to clone the volume %lu\n",
1220 (unsigned long)avolid);
1229 VPRINT1("Getting status of parent volume %u...", avolid);
1230 code = AFSVolGetStatus(aconn, ttid, volstatus);
1232 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1233 (unsigned long)avolid);
1242 code = AFSVolEndTrans(aconn, ttid, &rcode);
1243 if (code || rcode) {
1244 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1245 (unsigned long)avolid);
1247 error = (code ? code : rcode);
1252 code = AFSVolEndTrans(aconn, btid, &rcode);
1253 if (code || rcode) {
1255 "Could not end transaction on the %s volume %lu\n",
1256 typestring, (unsigned long)cloneid);
1258 error = (code ? code : rcode);
1264 /* Convert volume from RO to RW; adjust the VLDB entry to match.
1265 * The nvldbentry passed to us has already been MapHostToNetwork'd
1270 UV_ConvertRO(afs_uint32 server, afs_uint32 partition, afs_uint32 volid,
1271 struct nvldbentry *entry)
1273 afs_int32 code, i, same;
1274 struct nvldbentry checkEntry, storeEntry;
1276 afs_int32 rwindex = 0;
1277 afs_uint32 rwserver = 0;
1278 afs_int32 roindex = 0;
1279 afs_uint32 roserver = 0;
1280 struct rx_connection *aconn;
1282 memset(&storeEntry, 0, sizeof(struct nvldbentry));
1285 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1289 "Unable to lock volume %lu, code %d\n",
1290 (unsigned long)entry->volumeId[RWVOL],vcode);
1291 PrintError("", vcode);
1295 /* make sure the VLDB entry hasn't changed since we started */
1296 memset(&checkEntry, 0, sizeof(checkEntry));
1297 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1300 "Could not fetch the entry for volume %lu from VLDB\n",
1301 (unsigned long)volid);
1302 PrintError("convertROtoRW ", vcode);
1307 MapHostToNetwork(&checkEntry);
1308 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1309 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1310 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1312 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1313 (unsigned long)volid);
1318 /* extract information from the original entry */
1319 for (i = 0; i < entry->nServers; i++) {
1320 if (entry->serverFlags[i] & VLSF_RWVOL) {
1322 rwserver = entry->serverNumber[i];
1323 /* rwpartition = entry->serverPartition[i]; */
1326 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1327 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1330 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1337 roserver = entry->serverNumber[i];
1338 /* ropartition = entry->serverPartition[i]; */
1345 /* volume must be inaccessible during this process */
1346 code = UV_SetVolume(server, partition, volid, ITOffline, VTOutOfService, 0);
1348 fprintf(STDERR, "Taking RO volume %u offline failed with code %d.\n",
1353 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1354 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1357 "Converting RO volume %lu to RW volume failed with code %d\n",
1358 (unsigned long)volid, code);
1359 PrintError("convertROtoRW ", code);
1364 * Since the inService flag is copied from the RO volume, the new RW copy is
1365 * offline. Change the status of this RW volume to online.
1367 code = UV_SetVolume(server, partition, entry->volumeId[RWVOL], ITOffline,
1370 fprintf(STDERR, "Warning: Attempt to set RW volume %u as online failed "
1371 "with code %d.\n", entry->volumeId[RWVOL], code);
1374 /* Update the VLDB to match what we did on disk as much as possible. */
1375 /* If the converted RO was in the VLDB, make it look like the new RW. */
1377 entry->serverFlags[roindex] = VLSF_RWVOL;
1379 /* Add a new site entry for the newly created RW. It's possible
1380 * (but unlikely) that we are already at MAXNSERVERS and that this
1381 * new site will invalidate the whole VLDB entry; however,
1382 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1383 * so we need no extra guard logic here.
1385 afs_int32 newrwindex = entry->nServers;
1386 (entry->nServers)++;
1387 entry->serverNumber[newrwindex] = server;
1388 entry->serverPartition[newrwindex] = partition;
1389 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1391 entry->flags |= VLF_RWEXISTS;
1392 entry->flags &= ~VLF_BACKEXISTS;
1394 /* if the old RW was in the VLDB, remove it by decrementing the number */
1395 /* of servers, replacing the RW entry with the last entry, and zeroing */
1396 /* out the last entry. */
1398 (entry->nServers)--;
1399 if (rwindex != entry->nServers) {
1400 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1401 entry->serverPartition[rwindex] =
1402 entry->serverPartition[entry->nServers];
1403 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1404 entry->serverNumber[entry->nServers] = 0;
1405 entry->serverPartition[entry->nServers] = 0;
1406 entry->serverFlags[entry->nServers] = 0;
1409 entry->flags &= ~VLF_ROEXISTS;
1410 for (i = 0; i < entry->nServers; i++) {
1411 if (entry->serverFlags[i] & VLSF_ROVOL) {
1412 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1413 entry->flags |= VLF_ROEXISTS;
1416 MapNetworkToHost(entry, &storeEntry);
1418 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1419 (LOCKREL_OPCODE | LOCKREL_AFSID |
1420 LOCKREL_TIMESTAMP));
1423 "Warning: volume converted, but vldb update failed with code %d!\n",
1428 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1431 "Unable to unlock volume %lu, code %d\n",
1432 (unsigned long)entry->volumeId[RWVOL],vcode);
1433 PrintError("", vcode);
1439 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1440 * <atopart>. The operation is almost idempotent. The following
1441 * flags are recognized:
1443 * RV_NOCLONE - don't use a copy clone
1447 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1448 afs_uint32 atoserver, afs_int32 atopart, int flags)
1450 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1451 * be changing during the move */
1452 struct rx_connection * volatile toconn;
1453 struct rx_connection * volatile fromconn;
1454 afs_int32 volatile fromtid;
1455 afs_int32 volatile totid;
1456 afs_int32 volatile clonetid;
1457 afs_uint32 volatile newVol;
1458 afs_uint32 volatile volid;
1459 afs_uint32 volatile backupId;
1460 int volatile islocked;
1465 char tmpName[VOLSER_MAXVOLNAME + 1];
1470 struct restoreCookie cookie;
1471 afs_int32 vcode, code;
1472 struct volser_status tstatus;
1473 struct destServer destination;
1475 struct nvldbentry entry, storeEntry;
1478 char in, lf; /* for test code */
1482 #ifdef ENABLE_BUGFIX_1165
1483 volEntries volumeInfo;
1484 struct volintInfo *infop = 0;
1488 fromconn = (struct rx_connection *)0;
1489 toconn = (struct rx_connection *)0;
1499 /* support control-c processing */
1502 (void)signal(SIGINT, sigint_handler);
1506 "\nThere are three tests points - verifies all code paths through recovery.\n");
1507 fprintf(STDOUT, "First test point - operation not started.\n");
1508 fprintf(STDOUT, "...test here (y, n)? ");
1510 if (fscanf(stdin, "%c", &in) < 1)
1512 if (fscanf(stdin, "%c", &lf) < 0) {
1513 /* toss away; don't care */
1516 fprintf(STDOUT, "type control-c\n");
1518 fprintf(stdout, ".");
1523 /* or drop through */
1526 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1527 EGOTO1(mfail, vcode,
1528 "Could not fetch the entry for the volume %u from the VLDB \n",
1531 if (entry.volumeId[RWVOL] != afromvol) {
1532 fprintf(STDERR, "Only RW volume can be moved\n");
1536 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1537 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1540 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1541 EGOTO1(mfail, vcode,
1542 "Could not fetch the entry for the volume %u from the VLDB \n",
1545 backupId = entry.volumeId[BACKVOL];
1546 MapHostToNetwork(&entry);
1548 if (!Lp_Match(afromserver, afrompart, &entry)) {
1549 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1550 if (!Lp_Match(atoserver, atopart, &entry)) {
1551 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1552 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1553 (unsigned long)afromvol);
1554 fprintf(STDERR, "The current site is :");
1555 for (i = 0; i < entry.nServers; i++) {
1556 if (entry.serverFlags[i] == VLSF_RWVOL) {
1558 MapPartIdIntoName(entry.serverPartition[i], pname);
1559 fprintf(STDERR, " server %s partition %s \n",
1560 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1561 hostutil_GetNameByINet(entry.serverNumber[i]),
1566 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1567 (LOCKREL_OPCODE | LOCKREL_AFSID |
1568 LOCKREL_TIMESTAMP));
1569 EGOTO1(mfail, vcode,
1570 " Could not release lock on the VLDB entry for the volume %u \n",
1573 return VOLSERVOLMOVED;
1576 /* delete the volume afromvol on src_server */
1577 /* from-info does not exist but to-info does =>
1578 * we have already done the move, but the volume
1579 * may still be existing physically on from fileserver
1581 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1584 code = DoVolDelete(fromconn, afromvol, afrompart,
1585 "leftover", 0, NULL, NULL);
1586 if (code && code != VNOVOL) {
1591 code = DoVolDelete(fromconn, backupId, afrompart,
1592 "leftover backup", 0, NULL, NULL);
1593 if (code && code != VNOVOL) {
1603 /* From-info matches the vldb info about volid,
1604 * its ok start the move operation, the backup volume
1605 * on the old site is deleted in the process
1607 if (afrompart == atopart) {
1608 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1609 EGOTO2(mfail, error,
1610 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1611 afromserver, error);
1614 EGOTO1(mfail, VOLSERVOLMOVED,
1615 "Warning: Moving volume %u to its home partition ignored!\n",
1621 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1622 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1623 totid = 0; /* initialize to uncreated */
1626 * clone the read/write volume locally.
1629 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1630 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1632 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1636 if (!(flags & RV_NOCLONE)) {
1637 /* Get a clone id */
1638 VPRINT1("Allocating new volume id for clone of volume %u ...",
1641 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1643 EGOTO1(mfail, vcode,
1644 "Could not get an ID for the clone of volume %u from the VLDB\n",
1648 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1649 VPRINT1("Cloning source volume %u ...", afromvol);
1650 strcpy(vname, "move-clone-temp");
1652 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1654 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1659 /* lookup the name of the volume we just cloned */
1661 code = AFSVolGetName(fromconn, fromtid, &volName);
1662 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1665 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1667 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1672 "Failed to end the transaction on the source volume %u\n",
1677 * Create the destination volume
1680 if (!(flags & RV_NOCLONE)) {
1681 /* All of this is to get the fromDate */
1682 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1685 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1689 "Failed to start a transaction on the cloned volume%u\n",
1693 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1695 AFSVolSetFlags(fromconn, clonetid,
1696 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1697 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1701 /* remember time from which we've dumped the volume */
1702 VPRINT1("Getting status of cloned volume %u ...", newVol);
1703 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1705 "Failed to get the status of the cloned volume %u\n",
1709 fromDate = CLOCKADJ(tstatus.creationDate);
1711 /* With RV_NOCLONE, just do a full copy from the source */
1716 #ifdef ENABLE_BUGFIX_1165
1718 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1719 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1720 * don't use this information...
1722 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1723 volumeInfo.volEntries_len = 0;
1724 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1726 "Failed to get the volint Info of the cloned volume %u\n",
1729 infop = (volintInfo *) volumeInfo.volEntries_val;
1730 infop->maxquota = -1; /* Else it will replace the default quota */
1731 infop->creationDate = -1; /* Else it will use the source creation date */
1732 infop->updateDate = -1; /* Else it will use the source update date */
1735 /* create a volume on the target machine */
1737 code = DoVolDelete(toconn, volid, atopart,
1738 "pre-existing destination", 0, NULL, NULL);
1739 if (code && code != VNOVOL) {
1744 VPRINT1("Creating the destination volume %u ...", volid);
1748 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1752 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1756 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1760 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1762 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1764 "Failed to set the flags on the destination volume %u\n", volid);
1768 * Now dump the clone to the new volume
1771 destination.destHost = ntohl(atoserver);
1772 destination.destPort = AFSCONF_VOLUMEPORT;
1773 destination.destSSID = 1;
1775 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1776 cookie.type = RWVOL;
1777 cookie.parent = entry.volumeId[RWVOL];
1780 if (!(flags & RV_NOCLONE)) {
1781 /* Copy the clone to the new volume */
1782 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1785 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1787 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1790 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1791 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1796 "Failed to end the transaction on the cloned volume %u\n",
1802 * reattach to the main-line volume, and incrementally dump it.
1805 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1807 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1810 "Failed to create a transaction on the source volume %u\n",
1814 /* now do the incremental */
1816 ("Doing the%s dump from source to destination for volume %u ... ",
1817 (flags & RV_NOCLONE) ? "" : " incremental",
1820 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1823 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1824 (flags & RV_NOCLONE) ? "" : " incremental");
1827 /* now adjust the flags so that the new volume becomes official */
1828 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1829 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1831 "Failed to set the flags to make old source volume offline\n");
1834 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1835 code = AFSVolSetFlags(toconn, totid, 0);
1837 "Failed to set the flags to make new source volume online\n");
1840 #ifdef ENABLE_BUGFIX_1165
1841 VPRINT1("Setting volume status on destination volume %u ...", volid);
1842 code = AFSVolSetInfo(toconn, totid, infop);
1844 "Failed to set volume status on the destination volume %u\n",
1849 /* put new volume online */
1850 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1851 code = AFSVolEndTrans(toconn, totid, &rcode);
1856 "Failed to end the transaction on the volume %u on the new site\n",
1860 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1861 MapNetworkToHost(&entry, &storeEntry);
1862 storeEntry.flags &= ~VLF_BACKEXISTS;
1866 "Second test point - operation in progress but not complete.\n");
1867 fprintf(STDOUT, "...test here (y, n)? ");
1869 if (fscanf(stdin, "%c", &in) < 1)
1871 if (fscanf(stdin, "%c", &lf) < 0) {
1872 /* toss away, don't care */
1875 fprintf(STDOUT, "type control-c\n");
1877 fprintf(stdout, ".");
1882 /* or drop through */
1885 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1887 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1888 (LOCKREL_OPCODE | LOCKREL_AFSID |
1889 LOCKREL_TIMESTAMP));
1892 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1893 storeEntry.name, (unsigned long)afromvol);
1902 "Third test point - operation complete but no cleanup.\n");
1903 fprintf(STDOUT, "...test here (y, n)? ");
1905 if (fscanf(stdin, "%c", &in) < 1)
1907 if (fscanf(stdin, "%c", &lf) < 0) {
1908 /* toss away; don't care */
1911 fprintf(STDOUT, "type control-c\n");
1913 fprintf(stdout, ".");
1918 /* or drop through */
1920 if (atoserver != afromserver) {
1921 /* set forwarding pointer for moved volumes */
1922 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1923 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1925 "Failed to set the forwarding pointer for the volume %u\n",
1930 VPRINT1("Deleting old volume %u on source ...", afromvol);
1931 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1932 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1936 VPRINT1("Ending transaction on old volume %u on the source ...",
1938 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1943 "Failed to end the transaction on the old volume %u on the source\n",
1947 code = DoVolDelete(fromconn, backupId, afrompart,
1948 "source backup", 0, NULL, NULL);
1949 if (code && code != VNOVOL) {
1954 code = 0; /* no backup volume? that's okay */
1957 if (!(flags & RV_NOCLONE)) {
1958 code = DoVolDelete(fromconn, newVol, afrompart,
1959 "cloned", 0, NULL, NULL);
1960 if (code && code != VNOVOL) {
1965 code = 0; /* clone missing? that's okay */
1972 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1973 fprintf(STDOUT, "...test here (y, n)? ");
1975 if (fscanf(stdin, "%c", &in) < 1)
1977 if (fscanf(stdin, "%c", &lf) < 0) { /* toss away */
1981 fprintf(STDOUT, "type control-c\n");
1983 fprintf(stdout, ".");
1988 /* or drop through */
1991 /* normal cleanup code */
1993 if (entry.flags & VLF_ROEXISTS)
1994 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1997 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1999 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2000 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2004 " Could not release the lock on the VLDB entry for the volume %lu \n",
2005 (unsigned long)afromvol);
2013 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2015 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2016 if (code || rcode) {
2019 "Could not end transaction on the source volume %lu\n",
2020 (unsigned long)afromvol);
2022 error = (code ? code : rcode);
2028 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2029 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2030 if (code || rcode) {
2033 "Could not end transaction on the source's clone volume %lu\n",
2034 (unsigned long)newVol);
2036 error = (code ? code : rcode);
2042 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2044 code = AFSVolEndTrans(toconn, totid, &rcode);
2048 "Could not end transaction on destination volume %lu\n",
2049 (unsigned long)afromvol);
2051 error = (code ? code : rcode);
2057 #ifdef ENABLE_BUGFIX_1165
2062 rx_DestroyConnection(fromconn);
2064 rx_DestroyConnection(toconn);
2065 PrintError("", error);
2068 /* come here only when the sky falls */
2073 "vos move: operation interrupted, cleanup in progress...\n");
2074 fprintf(STDOUT, "clear transaction contexts\n");
2078 /* unlock VLDB entry */
2080 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2081 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2082 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2088 VPRINT("Recovery: Ending transaction on clone volume ...");
2089 AFSVolEndTrans(fromconn, clonetid, &rcode);
2093 VPRINT("Recovery: Ending transaction on destination volume ...");
2094 AFSVolEndTrans(toconn, totid, &rcode);
2097 if (fromtid) { /* put it on-line */
2098 VPRINT("Recovery: Setting volume flags on source volume ...");
2099 AFSVolSetFlags(fromconn, fromtid, 0);
2102 VPRINT("Recovery: Ending transaction on source volume ...");
2103 AFSVolEndTrans(fromconn, fromtid, &rcode);
2107 VPRINT("Recovery: Accessing VLDB.\n");
2108 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2110 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2114 MapHostToNetwork(&entry);
2116 /* Delete either the volume on the source location or the target location.
2117 * If the vldb entry still points to the source location, then we know the
2118 * volume move didn't finish so we remove the volume from the target
2119 * location. Otherwise, we remove the volume from the source location.
2121 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2124 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2128 if (volid && toconn) {
2129 code = DoVolDelete(toconn, volid, atopart,
2130 "destination", 0, NULL, "Recovery:");
2131 if (code == VNOVOL) {
2132 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2136 /* put source volume on-line */
2138 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2142 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2148 VPRINT1("Recovery: Setting flags on source volume %u ...",
2150 AFSVolSetFlags(fromconn, fromtid, 0);
2154 ("Recovery: Ending transaction on source volume %u ...",
2156 AFSVolEndTrans(fromconn, fromtid, &rcode);
2160 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2164 } else { /* yep, move complete */
2167 "move complete - attempt cleanup of source partition - no guarantee\n");
2171 /* delete backup volume */
2173 code = DoVolDelete(fromconn, backupId, afrompart,
2174 "backup", 0, NULL, "Recovery:");
2175 if (code == VNOVOL) {
2176 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2179 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2180 (atoserver != afromserver)?atoserver:0,
2182 if (code == VNOVOL) {
2183 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2188 /* common cleanup - delete local clone */
2190 code = DoVolDelete(fromconn, newVol, afrompart,
2191 "clone", 0, NULL, "Recovery:");
2192 if (code == VNOVOL) {
2193 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2197 /* unlock VLDB entry */
2199 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2201 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2202 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2205 done: /* routine cleanup */
2208 #ifdef ENABLE_BUGFIX_1165
2213 rx_DestroyConnection(fromconn);
2215 rx_DestroyConnection(toconn);
2218 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2226 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2227 afs_uint32 atoserver, afs_int32 atopart)
2229 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2230 atoserver, atopart, 0);
2234 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2235 * <atopart>. The new volume is named by <atovolname>. The new volume
2236 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2237 * from the VLDB. the following flags are supported:
2239 * RV_RDONLY - target volume is RO
2240 * RV_OFFLINE - leave target volume offline
2241 * RV_CPINCR - do incremental dump if target exists
2242 * RV_NOVLDB - don't create/update VLDB entry
2243 * RV_NOCLONE - don't use a copy clone
2246 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2247 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2248 afs_uint32 atovolid, int flags)
2250 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2251 * be changing during the copy */
2253 afs_int32 volatile clonetid;
2254 afs_int32 volatile totid;
2255 afs_int32 volatile fromtid;
2256 struct rx_connection * volatile fromconn;
2257 struct rx_connection * volatile toconn;
2258 afs_uint32 volatile cloneVol;
2262 afs_int32 fromDate, cloneFromDate;
2263 struct restoreCookie cookie;
2264 afs_int32 vcode, code;
2267 struct volser_status tstatus;
2268 struct destServer destination;
2269 struct nvldbentry entry, newentry, storeEntry;
2274 fromconn = (struct rx_connection *)0;
2275 toconn = (struct rx_connection *)0;
2283 /* support control-c processing */
2286 (void)signal(SIGINT, sigint_handler);
2288 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2289 EGOTO1(mfail, vcode,
2290 "Could not fetch the entry for the volume %u from the VLDB \n",
2292 MapHostToNetwork(&entry);
2295 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2296 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2297 fromtid = totid = 0; /* initialize to uncreated */
2300 * clone the read/write volume locally.
2304 if (!(flags & RV_NOCLONE)) {
2305 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2307 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2310 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2314 /* Get a clone id */
2315 VPRINT1("Allocating new volume id for clone of volume %u ...",
2319 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2321 EGOTO1(mfail, vcode,
2322 "Could not get an ID for the clone of volume %u from the VLDB\n",
2330 /* Get a new volume id */
2331 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2333 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2334 EGOTO1(mfail, vcode,
2335 "Could not get an ID for the copy of volume %u from the VLDB\n",
2340 if (!(flags & RV_NOCLONE)) {
2341 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2342 VPRINT1("Cloning source volume %u ...", afromvol);
2343 strcpy(vname, "copy-clone-temp");
2346 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2349 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2353 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2355 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2360 "Failed to end the transaction on the source volume %u\n",
2366 * Create the destination volume
2369 if (!(flags & RV_NOCLONE)) {
2370 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2373 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2377 "Failed to start a transaction on the cloned volume%u\n",
2381 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2383 AFSVolSetFlags(fromconn, clonetid,
2384 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2385 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2389 /* remember time from which we've dumped the volume */
2390 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2391 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2393 "Failed to get the status of the cloned volume %u\n",
2397 fromDate = CLOCKADJ(tstatus.creationDate);
2402 /* create a volume on the target machine */
2405 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2408 if ((flags & RV_CPINCR)) {
2409 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2410 code = AFSVolGetStatus(toconn, totid, &tstatus);
2412 "Failed to get the status of the pre-existing volume %u\n",
2416 /* Using the update date should be OK here, but add some fudge */
2417 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2418 if ((flags & RV_NOCLONE))
2419 fromDate = cloneFromDate;
2421 /* XXX We should check that the source volume's creationDate is
2422 * XXX not newer than the existing target volume, and if not,
2423 * XXX throw away the existing target and do a full dump. */
2428 /* Delete the existing volume.
2429 * While we are deleting the volume in these steps, the transaction
2430 * we started against the cloned volume (clonetid above) will be
2431 * sitting idle. It will get cleaned up after 600 seconds
2433 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2434 code = AFSVolDeleteVolume(toconn, totid);
2436 "Could not delete the pre-existing volume %u on destination\n",
2441 ("Ending transaction on pre-existing volume %u on destination ...",
2443 code = AFSVolEndTrans(toconn, totid, &rcode);
2448 "Could not end the transaction on pre-existing volume %u on destination\n",
2453 VPRINT1("Creating the destination volume %u ...", newVol);
2456 AFSVolCreateVolume(toconn, atopart, atovolname,
2457 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2458 newVol, &newVol, &tmp);
2460 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2464 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2466 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2468 "Failed to set the flags on the destination volume %u\n", newVol);
2473 destination.destHost = ntohl(atoserver);
2474 destination.destPort = AFSCONF_VOLUMEPORT;
2475 destination.destSSID = 1;
2477 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2478 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2483 * Now dump the clone to the new volume
2486 if (!(flags & RV_NOCLONE)) {
2487 /* XXX probably should have some code here that checks to see if
2488 * XXX we are copying to same server and partition - if so, just
2489 * XXX use a clone to save disk space */
2491 /* Copy the clone to the new volume */
2492 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2495 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2497 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2501 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2502 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2507 "Failed to end the transaction on the cloned volume %u\n",
2513 * reattach to the main-line volume, and incrementally dump it.
2516 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2518 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2521 "Failed to create a transaction on the source volume %u\n",
2525 /* now do the incremental */
2527 ("Doing the%s dump from source to destination for volume %u ... ",
2528 (flags & RV_NOCLONE) ? "" : " incremental",
2531 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2534 "Failed to do the%s dump from old site to new site\n",
2535 (flags & RV_NOCLONE) ? "" : " incremental");
2538 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2539 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2540 code = AFSVolSetFlags(toconn, totid, volflag);
2542 "Failed to set the flags to make destination volume online\n");
2545 /* put new volume online */
2546 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2547 code = AFSVolEndTrans(toconn, totid, &rcode);
2552 "Failed to end the transaction on the destination volume %u\n",
2556 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2557 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2562 "Failed to end the transaction on the source volume %u\n",
2568 if (!(flags & RV_NOCLONE)) {
2569 code = DoVolDelete(fromconn, cloneVol, afrompart,
2570 "cloned", 0, NULL, NULL);
2571 if (code && code != VNOVOL) {
2576 code = 0; /* clone missing? that's ok */
2579 if (!(flags & RV_NOVLDB)) {
2580 /* create the vldb entry for the copied volume */
2581 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2582 newentry.nServers = 1;
2583 newentry.serverNumber[0] = atoserver;
2584 newentry.serverPartition[0] = atopart;
2585 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2586 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2587 newentry.volumeId[RWVOL] = newVol;
2588 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2589 newentry.volumeId[BACKVOL] = 0;
2590 newentry.cloneId = 0;
2591 /*map into right byte order, before passing to xdr, the stuff has to be in host
2592 * byte order. Xdr converts it into network order */
2593 MapNetworkToHost(&newentry, &storeEntry);
2594 /* create the vldb entry */
2595 vcode = VLDB_CreateEntry(&storeEntry);
2598 "Could not create a VLDB entry for the volume %s %lu\n",
2599 atovolname, (unsigned long)newVol);
2600 /*destroy the created volume */
2601 VPRINT1("Deleting the newly created volume %u\n", newVol);
2602 AFSVolDeleteVolume(toconn, totid);
2606 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2610 /* normal cleanup code */
2613 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2615 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2616 if (code || rcode) {
2619 "Could not end transaction on the source volume %lu\n",
2620 (unsigned long)afromvol);
2622 error = (code ? code : rcode);
2628 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2630 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2631 if (code || rcode) {
2634 "Could not end transaction on the source's clone volume %lu\n",
2635 (unsigned long)cloneVol);
2637 error = (code ? code : rcode);
2643 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2645 code = AFSVolEndTrans(toconn, totid, &rcode);
2649 "Could not end transaction on destination volume %lu\n",
2650 (unsigned long)newVol);
2652 error = (code ? code : rcode);
2657 rx_DestroyConnection(fromconn);
2659 rx_DestroyConnection(toconn);
2660 PrintError("", error);
2663 /* come here only when the sky falls */
2668 "vos copy: operation interrupted, cleanup in progress...\n");
2669 fprintf(STDOUT, "clear transaction contexts\n");
2674 VPRINT("Recovery: Ending transaction on clone volume ...");
2675 AFSVolEndTrans(fromconn, clonetid, &rcode);
2679 VPRINT("Recovery: Ending transaction on destination volume ...");
2680 AFSVolEndTrans(toconn, totid, &rcode);
2683 if (fromtid) { /* put it on-line */
2684 VPRINT("Recovery: Ending transaction on source volume ...");
2685 AFSVolEndTrans(fromconn, fromtid, &rcode);
2689 VPRINT("Recovery: Accessing VLDB.\n");
2690 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2692 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2696 MapHostToNetwork(&entry);
2698 /* common cleanup - delete local clone */
2700 DoVolDelete(fromconn, cloneVol, afrompart, "clone", 0, NULL,
2704 done: /* routine cleanup */
2706 rx_DestroyConnection(fromconn);
2708 rx_DestroyConnection(toconn);
2711 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2719 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2720 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2722 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2723 atovolname, atoserver, atopart, 0, 0);
2728 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2729 * if one already exists, update it
2733 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2735 struct rx_connection *aconn = (struct rx_connection *)0;
2736 afs_int32 ttid = 0, btid = 0;
2737 afs_uint32 backupID;
2738 afs_int32 code = 0, rcode = 0;
2739 struct nvldbentry entry, storeEntry;
2740 afs_int32 error = 0;
2741 int vldblocked = 0, vldbmod = 0;
2743 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2745 /* the calls to VLDB will succeed only if avolid is a RW volume,
2746 * since we are following the RW hash chain for searching */
2747 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2750 "Could not fetch the entry for the volume %lu from the VLDB \n",
2751 (unsigned long)avolid);
2755 MapHostToNetwork(&entry);
2757 /* These operations require the VLDB be locked since it means the VLDB
2758 * will change or the vldb is already locked.
2760 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2761 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2762 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2764 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2767 "Could not lock the VLDB entry for the volume %lu\n",
2768 (unsigned long)avolid);
2774 /* Reread the vldb entry */
2775 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2778 "Could not fetch the entry for the volume %lu from the VLDB \n",
2779 (unsigned long)avolid);
2783 MapHostToNetwork(&entry);
2786 if (!ISNAMEVALID(entry.name)) {
2787 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2789 error = VOLSERBADNAME;
2793 backupID = entry.volumeId[BACKVOL];
2794 if (backupID == INVALID_BID) {
2795 /* Get a backup volume id from the VLDB and update the vldb
2798 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2801 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2802 (unsigned long)avolid);
2806 entry.volumeId[BACKVOL] = backupID;
2810 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2811 entry.name, NULL, ".backup", NULL, NULL);
2817 /* Mark vldb as backup exists */
2818 if (!(entry.flags & VLF_BACKEXISTS)) {
2819 entry.flags |= VLF_BACKEXISTS;
2823 /* Now go back to the backup volume and bring it on line */
2824 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2827 "Failed to start a transaction on the backup volume %lu\n",
2828 (unsigned long)backupID);
2833 code = AFSVolSetFlags(aconn, btid, 0);
2835 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2836 (unsigned long)backupID);
2841 code = AFSVolEndTrans(aconn, btid, &rcode);
2843 if (code || rcode) {
2845 "Failed to end the transaction on the backup volume %lu\n",
2846 (unsigned long)backupID);
2847 error = (code ? code : rcode);
2851 /* Will update the vldb below */
2855 code = AFSVolEndTrans(aconn, ttid, &rcode);
2856 if (code || rcode) {
2857 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2858 (unsigned long)avolid);
2860 error = (code ? code : rcode);
2865 code = AFSVolEndTrans(aconn, btid, &rcode);
2866 if (code || rcode) {
2868 "Could not end transaction the backup volume %lu\n",
2869 (unsigned long)backupID);
2871 error = (code ? code : rcode);
2875 /* Now update the vldb - if modified */
2878 MapNetworkToHost(&entry, &storeEntry);
2880 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2881 (LOCKREL_OPCODE | LOCKREL_AFSID |
2882 LOCKREL_TIMESTAMP));
2885 "Could not update the VLDB entry for the volume %lu \n",
2886 (unsigned long)avolid);
2892 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2893 (LOCKREL_OPCODE | LOCKREL_AFSID |
2894 LOCKREL_TIMESTAMP));
2897 "Could not unlock the VLDB entry for the volume %lu \n",
2898 (unsigned long)avolid);
2906 rx_DestroyConnection(aconn);
2908 PrintError("", error);
2912 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2913 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2914 * The new volume is named by <aname>, or by appending ".clone" to
2915 * the existing name if <aname> is NULL. The following flags are
2918 * RV_RDONLY - target volume is RO
2919 * RV_OFFLINE - leave target volume offline
2923 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2924 afs_uint32 acloneid, char *aname, int flags)
2926 struct rx_connection *aconn = (struct rx_connection *)0;
2927 afs_int32 ttid = 0, btid = 0;
2928 afs_int32 code = 0, rcode = 0;
2929 char vname[VOLSER_MAXVOLNAME + 1];
2930 afs_int32 error = 0;
2931 volEntries volumeInfo;
2934 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2937 volumeInfo.volEntries_val = (volintInfo *) 0;
2938 volumeInfo.volEntries_len = 0;
2939 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2941 fprintf(stderr, "Could not get info for volume %lu\n",
2942 (unsigned long)avolid);
2946 strncpy(vname, volumeInfo.volEntries_val[0].name,
2947 VOLSER_OLDMAXVOLNAME - 7);
2948 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2949 strcat(vname, ".clone");
2951 if (volumeInfo.volEntries_val)
2952 free(volumeInfo.volEntries_val);
2956 /* Get a clone id */
2957 VPRINT1("Allocating new volume id for clone of volume %u ...",
2959 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2961 "Could not get an ID for the clone of volume %u from the VLDB\n",
2966 if (flags & RV_RWONLY)
2967 type = readwriteVolume;
2968 else if (flags & RV_RDONLY)
2969 type = readonlyVolume;
2971 type = backupVolume;
2973 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
2974 NULL, aname, NULL, NULL, NULL);
2980 /* Now go back to the backup volume and bring it on line */
2981 if (!(flags & RV_OFFLINE)) {
2982 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2985 "Failed to start a transaction on the clone volume %lu\n",
2986 (unsigned long)acloneid);
2991 code = AFSVolSetFlags(aconn, btid, 0);
2993 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2994 (unsigned long)acloneid);
2999 code = AFSVolEndTrans(aconn, btid, &rcode);
3001 if (code || rcode) {
3003 "Failed to end the transaction on the clone volume %lu\n",
3004 (unsigned long)acloneid);
3005 error = (code ? code : rcode);
3012 code = AFSVolEndTrans(aconn, ttid, &rcode);
3013 if (code || rcode) {
3014 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3015 (unsigned long)avolid);
3017 error = (code ? code : rcode);
3022 code = AFSVolEndTrans(aconn, btid, &rcode);
3023 if (code || rcode) {
3025 "Could not end transaction on the clone volume %lu\n",
3026 (unsigned long)acloneid);
3028 error = (code ? code : rcode);
3033 rx_DestroyConnection(aconn);
3035 PrintError("", error);
3039 #define ONERROR(ec, ep, es) do { \
3041 fprintf(STDERR, (es), (ep)); \
3046 #define ONERROR0(ec, es) do { \
3048 fprintf(STDERR, (es)); \
3053 #define ERROREXIT(ec) do { \
3058 /* Get a "transaction" on this replica. Create the volume
3059 * if necessary. Return the time from which a dump should
3060 * be made (0 if it's a new volume)
3063 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3064 struct rx_connection **connPtr, afs_int32 * transPtr,
3065 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3066 afs_int32 *origflags, afs_uint32 tmpVolId)
3069 struct volser_status tstatus;
3074 *connPtr = (struct rx_connection *)0;
3079 /* get connection to the replication site */
3080 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3082 goto fail; /* server is down */
3084 volid = vldbEntryPtr->volumeId[ROVOL];
3088 AFSVolTransCreate_retry(*connPtr, volid,
3089 vldbEntryPtr->serverPartition[index], ITOffline,
3092 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3093 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3094 * site. Don't trust any data on it, since it is possible we
3095 * have encountered some temporary volume from some other
3096 * incomplete volume operation. It is difficult to detect if
3097 * that has happened vs if this is a legit volume, so just
3098 * delete it to be safe. */
3100 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3101 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3102 serverNumber[index], hoststr) :
3103 hostutil_GetNameByINet(vldbEntryPtr->
3104 serverNumber[index]));
3106 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3108 PrintError("Failed to delete RO_DONTUSE site: ", code);
3112 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3118 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3125 /* emulate what TransCreate would have returned, so we try to
3126 * create the volume below */
3131 /* If the volume does not exist, create it */
3132 if (!volid || code) {
3133 char volname[VL_MAXNAMELEN];
3136 if (volid && (code != VNOVOL)) {
3137 PrintError("Failed to start a transaction on the RO volume.\n",
3142 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3144 if (strlcat(volname,
3145 tmpVolId?".roclone":".readonly",
3146 sizeof(volname)) >= sizeof(volname)) {
3148 PrintError("Volume name is too long\n", code);
3154 "Creating new volume %lu on replication site %s: ",
3155 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3156 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3157 serverNumber[index], hoststr) :
3158 hostutil_GetNameByINet(vldbEntryPtr->
3159 serverNumber[index]));
3164 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3166 vldbEntryPtr->volumeId[RWVOL],
3167 tmpVolId?&tmpVolId:&volid,
3170 PrintError("Failed to create the ro volume: ", code);
3173 vldbEntryPtr->volumeId[ROVOL] = volid;
3177 /* The following is a bit redundant, since create sets these flags by default */
3179 AFSVolSetFlags(*connPtr, *transPtr,
3180 VTDeleteOnSalvage | VTOutOfService);
3182 PrintError("Failed to set flags on the ro volume: ", code);
3187 /* Otherwise, the transaction did succeed, so get the creation date of the
3188 * latest RO volume on the replication site
3191 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3192 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3193 serverNumber[index], hoststr) :
3194 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3196 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3198 PrintError("Failed to get status of volume on destination: ",
3203 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3208 code = DoVolClone(*connPtr, volid,
3209 vldbEntryPtr->serverPartition[index],
3210 readonlyVolume, tmpVolId, "temporary",
3211 vldbEntryPtr->name, NULL, ".roclone", NULL,
3216 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3217 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3224 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3228 if (tcode && tcode != ENOENT)
3229 PrintError("Could not end transaction on a ro volume: ", tcode);
3236 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3237 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3238 void *cookie, manyResults * results)
3242 for (i = 0; i < tr->manyDests_len; i++) {
3243 results->manyResults_val[i] =
3244 AFSVolForward(fromconn, fromtid, fromdate,
3245 &(tr->manyDests_val[i].server),
3246 tr->manyDests_val[i].trans, cookie);
3252 * Check if a trans has timed out, and recreate it if necessary.
3254 * @param[in] aconn RX connection to the relevant server
3255 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3256 * contains the new trans ID on success
3257 * @param[in] apart Partition for the transaction
3258 * @param[in] astat The status of the original transaction
3260 * @return operation status
3261 * @retval 0 existing transaction is still valid, or we managed to recreate
3262 * the trans successfully
3263 * @retval nonzero Fatal error; bail out
3266 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3267 struct volser_status *astat)
3269 struct volser_status new_status;
3272 memset(&new_status, 0, sizeof(new_status));
3273 code = AFSVolGetStatus(aconn, *atid, &new_status);
3275 if (code == ENOENT) {
3277 VPRINT1("Old transaction on cloned volume %lu timed out, "
3278 "restarting transaction\n", (long unsigned) astat->volID);
3279 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3282 PrintError("Failed to recreate cloned RO volume transaction\n",
3287 memset(&new_status, 0, sizeof(new_status));
3288 code = AFSVolGetStatus(aconn, *atid, &new_status);
3290 PrintError("Failed to get status on recreated transaction\n",
3295 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3296 PrintError("Recreated transaction on cloned RO volume, but "
3297 "the volume has changed!\n", 0);
3301 PrintError("Unable to get status of current cloned RO transaction\n",
3306 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3308 PrintError("Internal error: current GetStatus does not match "
3309 "original GetStatus?\n", 0);
3318 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3319 struct rx_connection **toconns, struct release *times,
3322 afs_int32 s, code = 0, rcode = 0;
3323 /* End the transactions and destroy the connections */
3324 for (s = 0; s < volcount; s++) {
3325 if (replicas[s].trans) {
3326 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3328 replicas[s].trans = 0;
3332 if ((s == 0) || (code != ENOENT)) {
3333 PrintError("Could not end transaction on a ro volume: ",
3337 ("Transaction timed out on a ro volume. Will retry.\n",
3339 if (times[s].vldbEntryIndex < *vldbindex)
3340 *vldbindex = times[s].vldbEntryIndex;
3345 rx_DestroyConnection(toconns[s]);
3351 * Release a volume to read-only sites
3353 * Release volume <afromvol> on <afromserver> <afrompart> to all its RO
3354 * sites (complete release), unless the previous release was incomplete
3355 * or new sites were added without changes to the read-write volume, in
3356 * which case we bring the remaining volumes up to date with the volumes
3357 * that were previously released successfully.
3359 * Will create a clone from the RW, then dump the clone out to
3360 * the remaining replicas. If there is more than 1 RO sites,
3361 * ensure that the VLDB says at least one RO is available all
3362 * the time: Influences when we write back the VLDB entry.
3364 * @param[in] afromvol volume to be released
3365 * @param[in] afromserver server containing afromvol
3366 * @param[in] afrompart partition containing afromvol
3367 * @param[in] flags bitmap of options
3368 * REL_COMPLETE - force a complete release
3369 * REL_FULLDUMPS - force full dumps
3372 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3373 afs_int32 afrompart, int flags)
3377 afs_int32 vcode, rcode, tcode;
3378 afs_uint32 cloneVolId = 0, roVolId;
3379 struct replica *replicas = 0;
3380 struct nvldbentry entry, storeEntry;
3381 int i, volcount = 0, m, vldbindex;
3383 struct restoreCookie cookie;
3384 struct rx_connection **toconns = 0;
3385 struct release *times = 0;
3387 struct rx_connection *fromconn = (struct rx_connection *)0;
3388 afs_int32 error = 0;
3390 afs_int32 clonetid = 0, onlinetid;
3391 afs_int32 fromtid = 0;
3392 afs_uint32 fromdate = 0;
3393 afs_uint32 thisdate;
3397 manyResults results;
3398 int rwindex, roindex, roclone, roexists;
3399 afs_uint32 rwcrdate = 0, rwupdate = 0;
3400 afs_uint32 clcrdate;
3404 } remembertime[NMAXNSERVERS];
3405 int releasecount = 0;
3406 struct volser_status volstatus;
3408 afs_int32 origflags[NMAXNSERVERS];
3409 struct volser_status orig_status;
3410 int notreleased = 0;
3411 int tried_justnewsites = 0;
3412 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3413 int sites = 0; /* number of ro sites */
3414 int new_sites = 0; /* number of ro sites markes as new */
3417 CR_PARTIAL = 0x0000, /**< just new sites added or recover from a previous failed release */
3418 CR_FORCED = 0x0001, /**< complete: forced by caller */
3419 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3420 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3421 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3422 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3423 } complete_release_t;
3425 complete_release_t complete_release = CR_PARTIAL;
3427 memset(remembertime, 0, sizeof(remembertime));
3428 memset(&results, 0, sizeof(results));
3429 memset(origflags, 0, sizeof(origflags));
3431 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3432 if (vcode != VL_RERELEASE)
3433 ONERROR(vcode, afromvol,
3434 "Could not lock the VLDB entry for the volume %u.\n");
3437 /* Get the vldb entry in readable format */
3438 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3439 ONERROR(vcode, afromvol,
3440 "Could not fetch the entry for the volume %u from the VLDB.\n");
3441 MapHostToNetwork(&entry);
3444 EnumerateEntry(&entry);
3446 if (!ISNAMEVALID(entry.name))
3447 ONERROR(VOLSERBADOP, entry.name,
3448 "Volume name %s is too long, rename before releasing.\n");
3449 if (entry.volumeId[RWVOL] != afromvol)
3450 ONERROR(VOLSERBADOP, afromvol,
3451 "The volume %u being released is not a read-write volume.\n");
3452 if (entry.nServers <= 1)
3453 ONERROR(VOLSERBADOP, afromvol,
3454 "Volume %u has no replicas - release operation is meaningless!\n");
3455 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3456 ONERROR(VOLSERBADOP, entry.name,
3457 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3459 /* roclone is true if one of the RO volumes is on the same
3460 * partition as the RW volume. In this case, we make the RO volume
3461 * on the same partition a clone instead of a complete copy.
3464 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3465 roclone = ((roindex == -1) ? 0 : 1);
3466 rwindex = Lp_GetRwIndex(&entry);
3468 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3470 /* Make sure we have a RO volume id to work with */
3471 if (entry.volumeId[ROVOL] == INVALID_BID) {
3472 /* need to get a new RO volume id */
3473 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3474 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3476 entry.volumeId[ROVOL] = roVolId;
3477 MapNetworkToHost(&entry, &storeEntry);
3478 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3479 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3483 * Determine if this is to be a complete release or a recovery of a
3484 * previous unfinished release. The previous release is considered to be
3485 * unfinished when the clone was successfully distributed to at least one
3486 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3489 * The caller can override the vldb flags check using the -force
3490 * or -force-reclone flag, to force this to be a complete release.
3492 for (i = 0; i < entry.nServers; i++) {
3493 if (entry.serverFlags[i] & VLSF_ROVOL) {
3495 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3497 if (entry.serverFlags[i] & VLSF_DONTUSE)
3500 origflags[i] = entry.serverFlags[i];
3503 if (flags & REL_COMPLETE) {
3504 complete_release |= CR_FORCED;
3507 if (new_sites == 0) {
3508 complete_release |= CR_LAST_OK;
3509 } else if (new_sites == sites) {
3510 complete_release |= CR_ALL_NEW;
3513 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3514 && !(complete_release & CR_FORCED)) {
3515 if (notreleased && notreleased != sites) {
3516 /* we have some new unreleased sites. try to just release to those,
3517 * if the RW has not changed. The caller can override with -force
3518 * or with -force-reclone. */
3523 /* Determine which volume id to use and see if it exists */
3524 cloneVolId = (complete_release || entry.cloneId == 0)
3525 ? entry.volumeId[ROVOL] : entry.cloneId;
3527 code = VolumeExists(afromserver, afrompart, cloneVolId);
3528 roexists = ((code == ENODEV) ? 0 : 1);
3530 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3532 ONERROR(-1, afromserver,
3533 "Cannot establish connection with server 0x%x\n");
3535 if (!complete_release) {
3537 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3539 /* Begin transaction on RW and mark it busy while we query it */
3540 code = AFSVolTransCreate_retry(
3541 fromconn, afromvol, afrompart, ITBusy, &fromtid
3543 ONERROR(code, afromvol,
3544 "Failed to start transaction on RW volume %u\n");
3546 /* Query the creation date for the RW */
3547 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3548 ONERROR(code, afromvol,
3549 "Failed to get the status of RW volume %u\n");
3550 rwcrdate = volstatus.creationDate;
3552 /* End transaction on RW */
3553 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3555 ONERROR((code ? code : rcode), afromvol,
3556 "Failed to end transaction on RW volume %u\n");
3558 /* Begin transaction on clone and mark it busy while we query it */
3559 code = AFSVolTransCreate_retry(
3560 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3562 ONERROR(code, cloneVolId,
3563 "Failed to start transaction on RW clone %u\n");
3565 /* Query the creation date for the clone */
3566 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3567 ONERROR(code, cloneVolId,
3568 "Failed to get the status of RW clone %u\n");
3569 clcrdate = volstatus.creationDate;
3571 /* End transaction on clone */
3572 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3574 ONERROR((code ? code : rcode), cloneVolId,
3575 "Failed to end transaction on RW clone %u\n");
3577 if (rwcrdate > clcrdate)
3578 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3582 if (!complete_release || (complete_release & CR_NEW_RW)) {
3583 /* in case the RW has changed, and just to be safe */
3588 if (!complete_release) {
3590 "This is a recovery of previously failed release\n");
3592 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3593 if (complete_release == CR_LAST_OK) {
3595 tried_justnewsites = 1;
3596 fprintf(STDOUT, "\nThere are new RO sites; we will try to "
3597 "only release to new sites");
3601 if (complete_release & CR_FORCED) {
3602 fprintf(STDOUT, "%sforced", sep);
3605 if (complete_release & CR_LAST_OK) {
3606 fprintf(STDOUT, "%slast ok", sep);
3609 if (complete_release & CR_ALL_NEW) {
3610 fprintf(STDOUT, "%sall sites are new", sep);
3613 if (complete_release & CR_NEW_RW) {
3614 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3617 if (complete_release & CR_RO_MISSING) {
3618 fprintf(STDOUT, "%sro clone missing", sep);
3620 fprintf(STDOUT, ")");
3622 fprintf(STDOUT, "\n");
3626 if (complete_release) {
3627 afs_int32 oldest = 0;
3628 /* If the RO clone exists, then if the clone is a temporary
3629 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3630 * (it was recently added), then also delete it. We do not
3631 * want to "reclone" a temporary RO clone.
3634 /* clean up any previous tmp clone before starting if staying up */
3636 && (!roclone || (entry.serverFlags[roindex] & VLSF_DONTUSE))) {
3637 code = DoVolDelete(fromconn,
3639 afrompart, "the", 0, NULL, NULL);
3640 if (code && (code != VNOVOL))
3646 VPRINT("Querying old RO sites for update times...");
3647 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3648 volEntries volumeInfo;
3649 struct rx_connection *conn;
3652 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL)) {
3655 if ((entry.serverFlags[vldbindex] & VLSF_DONTUSE)) {
3658 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3660 fprintf(STDERR, "Cannot establish connection to server %s\n",
3661 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3665 volumeInfo.volEntries_val = NULL;
3666 volumeInfo.volEntries_len = 0;
3667 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3668 entry.volumeId[ROVOL],
3671 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3672 (unsigned long)entry.volumeId[ROVOL],
3673 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3674 PrintError("", code);
3676 rx_DestroyConnection(conn);
3680 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3682 if (oldest == 0 || crdate < oldest) {
3686 rx_DestroyConnection(conn);
3687 free(volumeInfo.volEntries_val);
3688 volumeInfo.volEntries_val = NULL;
3689 volumeInfo.volEntries_len = 0;
3694 volEntries volumeInfo;
3695 volumeInfo.volEntries_val = NULL;
3696 volumeInfo.volEntries_len = 0;
3697 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3700 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3701 (unsigned long)afromvol,
3702 hostutil_GetNameByINet(afromserver));
3703 PrintError("", code);
3706 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3708 free(volumeInfo.volEntries_val);
3709 volumeInfo.volEntries_val = NULL;
3710 volumeInfo.volEntries_len = 0;
3713 if (justnewsites && oldest <= rwupdate) {
3714 /* RW has changed */
3718 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3719 * write this entry out to the vlserver until after the first
3720 * RO volume is released (temp RO clones don't count).
3722 * If 'justnewsites' is set, we're only updating sites that have
3723 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3725 for (i = 0; i < entry.nServers; i++) {
3727 if ((entry.serverFlags[i] & VLSF_DONTUSE)) {
3728 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3730 entry.serverFlags[i] |= VLSF_NEWREPSITE;
3733 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3734 entry.serverFlags[i] |= VLSF_DONTUSE;
3737 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3738 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3741 if (justnewsites && roexists) {
3742 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3743 * anything with the RO clone, so skip the reclone */
3746 } else if (complete_release) {
3749 strcpy(vname, entry.name);
3750 strcat(vname, ".readonly");
3752 strcpy(vname, "readonly-clone-temp");
3755 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3756 cloneVolId, roclone?"permanent RO":
3757 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3763 if (justnewsites && rwupdate != volstatus.updateDate) {
3765 /* reset the serverFlags as if 'justnewsites' had never been set */
3766 for (i = 0; i < entry.nServers; i++) {
3767 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3768 entry.serverFlags[i] |= VLSF_DONTUSE;
3770 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3771 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3774 rwcrdate = volstatus.creationDate;
3776 /* Remember clone volume ID in case we fail or are interrupted */
3777 entry.cloneId = cloneVolId;
3780 /* Bring the RO clone online - though not if it's a temporary clone */
3781 VPRINT1("Starting transaction on RO clone volume %u...",
3784 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3786 ONERROR(code, cloneVolId,
3787 "Failed to start transaction on volume %u\n");
3790 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3791 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3794 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3795 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3796 ONERROR((code ? code : rcode), cloneVolId,
3797 "Failed to end transaction on RO clone %u\n");
3800 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3802 /* Sleep so that a client searching for an online volume won't
3803 * find the clone offline and then the next RO offline while the
3804 * release brings the clone online and the next RO offline (race).
3805 * There is a fix in the 3.4 client that does not need this sleep
3806 * anymore, but we don't know what clients we have.
3808 if (entry.nServers > 2 && !justnewsites)
3811 /* Mark the RO clone in the VLDB as a good site (already released) */
3812 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
3813 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
3814 entry.flags |= VLF_ROEXISTS;
3818 /* Write out the VLDB entry only if the clone is not a temporary
3819 * clone. If we did this to a temporary clone then we would end
3820 * up marking all the ROs as "old release" making the ROs
3821 * temporarily unavailable.
3823 MapNetworkToHost(&entry, &storeEntry);
3824 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3825 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3826 ONERROR(vcode, entry.name,
3827 "Could not update vldb entry for %s.\n");
3833 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3834 /* act like this is a completion of a previous release */
3835 complete_release = CR_PARTIAL;
3836 } else if (tried_justnewsites) {
3837 VPRINT("RW vol has changed; releasing to all sites\n");
3840 /* Now we will release from the clone to the remaining RO replicas.
3841 * The first 2 ROs (counting the non-temporary RO clone) are released
3842 * individually: releasecount. This is to reduce the race condition
3843 * of clients trying to find an on-line RO volume. The remaining ROs
3844 * are released in parallel but no more than half the number of ROs
3845 * (rounded up) at a time: nservers.
3848 strcpy(vname, entry.name);
3849 strcat(vname, ".readonly");
3850 memset(&cookie, 0, sizeof(cookie));
3851 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3852 cookie.type = ROVOL;
3853 cookie.parent = entry.volumeId[RWVOL];
3856 /* how many to do at once, excluding clone */
3858 nservers = entry.nServers; /* can do all, none offline */
3860 nservers = entry.nServers / 2;
3861 replicas = calloc(nservers + 1, sizeof(struct replica));
3862 times = calloc(nservers + 1, sizeof(struct release));
3863 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3864 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3865 if (!replicas || !times || !results.manyResults_val || !toconns)
3867 "Failed to create transaction on the release clone\n");
3869 /* Create a transaction on the cloned volume */
3870 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3872 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3874 memset(&orig_status, 0, sizeof(orig_status));
3875 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3877 if (!complete_release && code)
3878 ONERROR(VOLSERNOVOL, afromvol,
3879 "Old clone is inaccessible. Try vos release -f %u.\n");
3880 ONERROR0(code, "Failed to create transaction on the release clone\n");
3883 /* For each index in the VLDB */
3884 for (vldbindex = 0; vldbindex < entry.nServers;) {
3885 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3887 ((volcount < nservers) && (vldbindex < entry.nServers));
3889 if (!justnewsites) {
3890 /* The first two RO volumes will be released individually.
3891 * The rest are then released in parallel. This is a hack
3892 * for clients not recognizing right away when a RO volume
3893 * comes back on-line.
3895 if ((volcount == 1) && (releasecount < 2))
3899 if (vldbindex == roindex)
3900 continue; /* the clone */
3901 if ((entry.serverFlags[vldbindex] & VLSF_NEWREPSITE)
3902 && !(entry.serverFlags[vldbindex] & VLSF_DONTUSE))
3904 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL))
3905 continue; /* not a RO vol */
3908 /* Get a Transaction on this replica. Get a new connection if
3909 * necessary. Create the volume if necessary. Return the
3910 * time from which the dump should be made (0 if it's a new
3911 * volume). Each volume might have a different time.
3913 replicas[volcount].server.destHost =
3914 ntohl(entry.serverNumber[vldbindex]);
3915 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3916 replicas[volcount].server.destSSID = 1;
3917 times[volcount].vldbEntryIndex = vldbindex;
3920 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3921 &(replicas[volcount].trans),
3922 &(times[volcount].crtime),
3923 &(times[volcount].uptime),
3928 /* Thisdate is the date from which we want to pick up all changes */
3929 if (flags & REL_FULLDUMPS) {
3930 /* Do a full dump when forced by the caller. */
3931 VPRINT("This will be a full dump: forced\n");
3933 } else if (complete_release == CR_PARTIAL) {
3935 VPRINT("This will be a full dump: read-only volume needs be created for new site\n");
3938 * We cannot be sure the creation date is good since the previous
3939 * release failed, so do a full dump.
3941 VPRINT("This will be a full dump: previous release failed\n");
3944 } else if (times[volcount].crtime == 0) {
3945 /* A full dump is needed for a new read-only volume. */
3947 ("This will be a full dump: read-only volume needs to be created\n");
3949 } else if ((rwcrdate > times[volcount].crtime)) {
3950 /* If the RW volume was replaced (its creation date is newer than
3951 * the last release), then we can't be sure what has changed (so
3952 * we do a full dump).
3955 ("This will be a full dump: read-write volume was replaced\n");
3957 } else if (remembertime[vldbindex].validtime) {
3958 /* Trans was prev ended. Use the time from the prev trans
3959 * because, prev trans may have created the volume. In which
3960 * case time[volcount].time would be now instead of 0.
3963 (remembertime[vldbindex].uptime < times[volcount].uptime)
3964 ? remembertime[vldbindex].uptime
3965 : times[volcount].uptime;
3967 thisdate = times[volcount].uptime;
3969 remembertime[vldbindex].validtime = 1;
3970 remembertime[vldbindex].uptime = thisdate;
3972 if (volcount == 0) {
3973 fromdate = thisdate;
3975 /* Include this volume if it is within 15 minutes of the earliest */
3977 thisdate) ? (fromdate - thisdate) : (thisdate -
3979 AFSVolEndTrans(toconns[volcount],
3980 replicas[volcount].trans, &rcode);
3981 replicas[volcount].trans = 0;
3984 if (thisdate < fromdate)
3985 fromdate = thisdate;
3992 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
3999 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
4000 (unsigned long)cloneVolId,
4001 entry.volumeId[ROVOL],
4002 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
4003 vldbEntryIndex], hoststr) :
4004 hostutil_GetNameByINet(entry.
4005 serverNumber[times[0].
4008 for (s = 1; s < volcount; s++) {
4009 fprintf(STDOUT, " and %s",
4010 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
4011 vldbEntryIndex], hoststr) :
4012 hostutil_GetNameByINet(entry.
4013 serverNumber[times[s].
4018 fprintf(STDOUT, " (entire volume)");
4021 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4023 fprintf(STDOUT, ".\n");
4027 /* Release the ones we have collected */
4028 tr.manyDests_val = &(replicas[0]);
4029 tr.manyDests_len = results.manyResults_len = volcount;
4031 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4032 0 /*spare */ , &cookie, &results);
4033 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4035 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4036 0 /*spare */ , &cookie, &results);
4041 PrintError("Release failed: ", code);
4043 for (m = 0; m < volcount; m++) {
4044 if (results.manyResults_val[m]) {
4045 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4046 /* we retry timed out transaction. When it is
4047 * not the first volume and the transaction wasn't found
4048 * (assume it timed out and was garbage collected by volser).
4051 ("Failed to dump volume from clone to a ro site: ",
4052 results.manyResults_val[m]);
4058 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4059 ROVOL, entry.volumeId[RWVOL], 0, 0);
4061 if ((m == 0) || (code != ENOENT)) {
4062 PrintError("Failed to set correct names and ids: ",
4068 /* have to clear dest. flags to ensure new vol goes online:
4069 * because the restore (forwarded) operation copied
4070 * the V_inService(=0) flag over to the destination.
4072 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4074 if ((m == 0) || (code != ENOENT)) {
4075 PrintError("Failed to set flags on ro volume: ",
4081 entry.serverFlags[times[m].vldbEntryIndex] |= VLSF_NEWREPSITE;
4082 entry.serverFlags[times[m].vldbEntryIndex] &= ~VLSF_DONTUSE;
4083 entry.flags |= VLF_ROEXISTS;
4088 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4089 MapNetworkToHost(&entry, &storeEntry);
4090 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4091 ONERROR(vcode, afromvol,
4092 " Could not update VLDB entry for volume %u\n");
4093 } /* for each index in the vldb */
4095 /* End the transaction on the cloned volume */
4096 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4101 PrintError("Failed to end transaction on rw volume: ", code);
4103 /* Figure out if any volume were not released and say so */
4104 for (failure = 0, i = 0; i < entry.nServers; i++) {
4105 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE))
4111 "The volume %lu could not be released to the following %d sites:\n",
4112 (unsigned long)afromvol, failure);
4113 for (i = 0; i < entry.nServers; i++) {
4114 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE)) {
4115 MapPartIdIntoName(entry.serverPartition[i], pname);
4116 fprintf(STDERR, "\t%35s %s\n",
4117 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4118 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4121 MapNetworkToHost(&entry, &storeEntry);
4123 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4125 ONERROR(vcode, afromvol,
4126 " Could not update VLDB entry for volume %u\n");
4128 ERROREXIT(VOLSERBADRELEASE);
4132 /* All the ROs were release successfully. Remove the temporary clone */
4135 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4136 (unsigned long)cloneVolId);
4139 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4141 if (code && code != VNOVOL)
4142 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4146 for (i = 0; i < entry.nServers; i++)
4147 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
4149 /* Update the VLDB */
4150 VPRINT("updating VLDB ...");
4152 MapNetworkToHost(&entry, &storeEntry);
4154 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4155 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4156 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4161 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4165 "Failed to end cloning transaction on the RW volume %lu\n",
4166 (unsigned long)afromvol);
4172 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4176 "Failed to end transaction on the release clone %lu\n",
4177 (unsigned long)cloneVolId);
4182 for (i = 0; i < nservers; i++) {
4183 if (replicas && replicas[i].trans) {
4184 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4185 replicas[i].trans = 0;
4188 "Failed to end transaction on ro volume %u at server %s\n",
4189 entry.volumeId[ROVOL],
4190 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4191 destHost), hoststr) :
4192 hostutil_GetNameByINet(htonl
4193 (replicas[i].server.destHost)));
4198 if (toconns && toconns[i]) {
4199 rx_DestroyConnection(toconns[i]);
4205 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4206 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4209 "Could not release lock on the VLDB entry for volume %lu\n",
4210 (unsigned long)afromvol);
4216 PrintError("", error);
4219 rx_DestroyConnection(fromconn);
4220 if (results.manyResults_val)
4221 free(results.manyResults_val);
4233 dump_sig_handler(int x)
4235 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4239 /* Dump the volume <afromvol> on <afromserver> and
4240 * <afrompart> to <afilename> starting from <fromdate>.
4241 * DumpFunction does the real work behind the scenes after
4242 * extracting parameters from the rock
4245 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4247 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4250 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4251 * be changing during the dump */
4252 struct rx_call * volatile fromcall = NULL;
4253 struct rx_connection * volatile fromconn = NULL;
4254 afs_int32 volatile fromtid = 0;
4256 afs_int32 rcode = 0;
4257 afs_int32 code, error = 0;
4259 time_t tmv = fromdate;
4263 #ifndef AFS_NT40_ENV
4264 (void)signal(SIGPIPE, dump_sig_handler);
4266 (void)signal(SIGINT, dump_sig_handler);
4269 VEPRINT("Full Dump ...\n");
4271 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4275 /* get connections to the servers */
4276 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4278 VEPRINT1("Starting transaction on volume %u...", afromvol);
4280 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4282 EGOTO1(error_exit, code,
4283 "Could not start transaction on the volume %u to be dumped\n",
4287 fromcall = rx_NewCall(fromconn);
4289 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4290 if (flags & VOLDUMPV2_OMITDIRS)
4291 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4293 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4294 EGOTO(error_exit, code, "Could not start the dump process \n");
4297 VEPRINT1("Dumping volume %u...", afromvol);
4298 code = DumpFunction(fromcall, rock);
4299 if (code == RXGEN_OPCODE)
4301 EGOTO(error_exit, code, "Error while dumping volume \n");
4306 code = rx_EndCall(fromcall, 0);
4307 if (code && code != RXGEN_OPCODE)
4308 fprintf(STDERR, "Error in rx_EndCall\n");
4313 VEPRINT1("Ending transaction on volume %u...", afromvol);
4314 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4315 if (code || rcode) {
4316 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4317 (unsigned long)afromvol);
4319 error = (code ? code : rcode);
4324 rx_DestroyConnection(fromconn);
4326 if (error != RXGEN_OPCODE)
4327 PrintError("", error);
4331 /* Clone the volume <afromvol> on <afromserver> and
4332 * <afrompart>, and then dump the clone volume to
4333 * <afilename> starting from <fromdate>.
4334 * DumpFunction does the real work behind the scenes after
4335 * extracting parameters from the rock
4338 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4339 afs_int32 afrompart, afs_int32 fromdate,
4340 afs_int32(*DumpFunction) (struct rx_call *, void *),
4341 void *rock, afs_int32 flags)
4343 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4344 * be changing during the dump */
4345 struct rx_connection * volatile fromconn = NULL;
4346 struct rx_call * volatile fromcall = NULL;
4347 afs_int32 volatile clonetid = 0;
4348 afs_uint32 volatile clonevol = 0;
4351 afs_int32 fromtid = 0, rcode = 0;
4352 afs_int32 code = 0, error = 0;
4354 time_t tmv = fromdate;
4355 char *volName = NULL;
4359 #ifndef AFS_NT40_ENV
4360 (void)signal(SIGPIPE, dump_sig_handler);
4362 (void)signal(SIGINT, dump_sig_handler);
4365 VEPRINT("Full Dump ...\n");
4367 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4371 /* get connections to the servers */
4372 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4374 VEPRINT1("Starting transaction on volume %u...", afromvol);
4375 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4376 EGOTO1(error_exit, code,
4377 "Could not start transaction on the volume %u to be dumped\n",
4381 VEPRINT1("Getting the name for volume %u ...", afromvol);
4382 code = AFSVolGetName(fromconn, fromtid, &volName);
4383 EGOTO1(error_exit, code,
4384 "Failed to get the name of the volume %u\n",afromvol);
4387 /* Get a clone id */
4388 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4390 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4392 EGOTO1(error_exit, code,
4393 "Could not get an ID for the clone of volume %u from the VLDB\n",
4397 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4398 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4402 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, volName, &tmpVol);
4404 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4408 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4410 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4414 EGOTO1(error_exit, code,
4415 "Failed to end the transaction on the volume %u\n", afromvol);
4419 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4422 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4425 EGOTO1(error_exit, code,
4426 "Failed to start a transaction on the cloned volume%u\n",
4430 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4431 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4432 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4437 fromcall = rx_NewCall(fromconn);
4439 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4440 if (flags & VOLDUMPV2_OMITDIRS)
4441 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4443 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4444 EGOTO(error_exit, code, "Could not start the dump process \n");
4447 VEPRINT1("Dumping volume %u...", afromvol);
4448 code = DumpFunction(fromcall, rock);
4449 EGOTO(error_exit, code, "Error while dumping volume \n");
4456 /* now delete the clone */
4457 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4458 code = AFSVolDeleteVolume(fromconn, clonetid);
4460 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4461 (unsigned long)clonevol);
4467 code = rx_EndCall(fromcall, 0);
4469 fprintf(STDERR, "Error in rx_EndCall\n");
4475 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4476 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4477 if (code || rcode) {
4479 "Could not end transaction on the cloned volume %lu\n",
4480 (unsigned long)clonevol);
4482 error = (code ? code : rcode);
4487 rx_DestroyConnection(fromconn);
4489 PrintError("", error);
4496 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4497 * the dump file <afilename>. WriteData does all the real work
4498 * after extracting params from the rock
4501 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4502 afs_uint32 toparentid, char tovolname[], int flags,
4503 afs_int32(*WriteData) (struct rx_call *, void *),
4506 struct rx_connection *toconn, *tempconn;
4507 struct rx_call *tocall;
4508 afs_int32 totid, code, rcode, vcode, terror = 0;
4509 struct volser_status tstatus;
4510 struct volintInfo vinfo;
4512 char tovolreal[VOLSER_OLDMAXVOLNAME];
4514 afs_int32 temptid, pparentid;
4515 struct nvldbentry entry, storeEntry;
4518 struct restoreCookie cookie;
4520 afs_int32 volflag, voltype, volsertype;
4521 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4522 VolumeId oldCloneId = 0;
4523 VolumeId oldBackupId = 0;
4524 int index, same, errcode;
4528 memset(&cookie, 0, sizeof(cookie));
4532 tocall = (struct rx_call *)0;
4533 tempconn = (struct rx_connection *)0;
4537 if (flags & RV_RDONLY) {
4539 volsertype = volser_RO;
4542 volsertype = volser_RW;
4546 pparentid = toparentid;
4547 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4548 if (pvolid == 0) { /*alot a new id if needed */
4549 vcode = VLDB_GetEntryByName(tovolname, &entry);
4550 if (vcode == VL_NOENT) {
4551 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4553 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4559 } else if (flags & RV_RDONLY) {
4560 if (entry.flags & VLF_RWEXISTS) {
4562 "Entry for ReadWrite volume %s already exists!\n",
4564 error = VOLSERBADOP;
4567 if (!entry.volumeId[ROVOL]) {
4569 "Existing entry for volume %s has no ReadOnly ID\n",
4571 error = VOLSERBADOP;
4574 pvolid = entry.volumeId[ROVOL];
4575 pparentid = entry.volumeId[RWVOL];
4577 pvolid = entry.volumeId[RWVOL];
4578 pparentid = entry.volumeId[RWVOL];
4581 if (!pparentid) pparentid = pvolid;
4582 /* at this point we have a volume id to use/reuse for the volume to be restored */
4583 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4585 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4586 EGOTO1(refail, VOLSERBADOP,
4587 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4590 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4591 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4592 EGOTO1(refail, VOLSERBADOP,
4593 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4595 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4598 MapPartIdIntoName(topart, partName);
4599 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4600 tovolreal, (unsigned long)pvolid,
4601 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4602 hostutil_GetNameByINet(toserver), partName);
4605 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4608 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4609 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4611 if (code && code != VNOVOL) {
4617 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4619 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4622 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4623 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4626 code = AFSVolGetStatus(toconn, totid, &tstatus);
4627 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4631 oldCreateDate = tstatus.creationDate;
4632 oldUpdateDate = tstatus.updateDate;
4633 oldCloneId = tstatus.cloneID;
4634 oldBackupId = tstatus.backupID;
4640 cookie.parent = pparentid;
4641 cookie.type = voltype;
4643 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4645 tocall = rx_NewCall(toconn);
4646 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4648 fprintf(STDERR, "Volume restore Failed \n");
4652 code = WriteData(tocall, rock);
4654 fprintf(STDERR, "Could not transmit data\n");
4658 terror = rx_EndCall(tocall, 0);
4659 tocall = (struct rx_call *)0;
4661 fprintf(STDERR, "rx_EndCall Failed \n");
4665 code = AFSVolGetStatus(toconn, totid, &tstatus);
4668 "Could not get status information about the volume %lu\n",
4669 (unsigned long)pvolid);
4673 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid,
4674 oldCloneId, oldBackupId);
4676 fprintf(STDERR, "Could not set the right type and IDs on %lu\n",
4677 (unsigned long)pvolid);
4682 if (flags & RV_CRDUMP)
4683 newCreateDate = tstatus.creationDate;
4684 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4685 newCreateDate = oldCreateDate;
4687 newCreateDate = time(0);
4688 if (flags & RV_LUDUMP)
4689 newUpdateDate = tstatus.updateDate;
4690 else if (flags & RV_LUKEEP)
4691 newUpdateDate = oldUpdateDate;
4693 newUpdateDate = time(0);
4694 code = AFSVolSetDate(toconn,totid, newCreateDate);
4696 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4701 init_volintInfo(&vinfo);
4702 vinfo.creationDate = newCreateDate;
4703 vinfo.updateDate = newUpdateDate;
4704 code = AFSVolSetInfo(toconn, totid, &vinfo);
4706 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4712 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4713 code = AFSVolSetFlags(toconn, totid, volflag);
4715 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4720 /* It isn't handled right in refail */
4721 code = AFSVolEndTrans(toconn, totid, &rcode);
4726 fprintf(STDERR, "Could not end transaction on %lu\n",
4727 (unsigned long)pvolid);
4732 fprintf(STDOUT, " done\n");
4734 if (!reuseID || (flags & RV_FULLRST)) {
4735 /* Volume was restored on the file server, update the
4736 * VLDB to reflect the change.
4738 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4739 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4741 "Could not fetch the entry for volume number %lu from VLDB \n",
4742 (unsigned long)pvolid);
4747 MapHostToNetwork(&entry);
4748 if (vcode == VL_NOENT) { /* it doesnot exist already */
4749 /*make the vldb return this indication specifically */
4750 VPRINT("------- Creating a new VLDB entry ------- \n");
4751 strcpy(entry.name, tovolname);
4753 entry.serverNumber[0] = toserver; /*should be indirect */
4754 entry.serverPartition[0] = topart;
4755 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4756 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4757 if (flags & RV_RDONLY)
4758 entry.volumeId[ROVOL] = pvolid;
4759 else if (tstatus.cloneID != 0) {
4760 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4762 entry.volumeId[ROVOL] = INVALID_BID;
4763 entry.volumeId[RWVOL] = pparentid;
4765 if (tstatus.backupID != 0) {
4766 entry.volumeId[BACKVOL] = tstatus.backupID;
4767 /*this should come from status info on the volume if non zero */
4769 entry.volumeId[BACKVOL] = INVALID_BID;
4770 MapNetworkToHost(&entry, &storeEntry);
4771 vcode = VLDB_CreateEntry(&storeEntry);
4774 "Could not create the VLDB entry for volume number %lu \n",
4775 (unsigned long)pvolid);
4781 EnumerateEntry(&entry);
4782 } else { /*update the existing entry */
4784 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4785 fprintf(STDOUT, "------- Old entry -------\n");
4786 EnumerateEntry(&entry);
4787 fprintf(STDOUT, "------- New entry -------\n");
4790 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4794 "Could not lock the entry for volume number %lu \n",
4795 (unsigned long)pvolid);
4800 strcpy(entry.name, tovolname);
4802 /* Update the vlentry with the new information */
4803 if (flags & RV_RDONLY)
4804 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4806 index = Lp_GetRwIndex(&entry);
4808 /* Add the new site for the volume being restored */
4809 entry.serverNumber[entry.nServers] = toserver;
4810 entry.serverPartition[entry.nServers] = topart;
4811 entry.serverFlags[entry.nServers] =
4812 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4815 /* This volume should be deleted on the old site
4816 * if its different from new site.
4819 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4823 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4825 if ((!errcode && !same)
4826 || (entry.serverPartition[index] != topart)) {
4827 if (flags & RV_NODEL) {
4829 ("Not deleting the previous volume %u on server %s, ...",
4831 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4832 hostutil_GetNameByINet(entry.serverNumber[index]));
4835 UV_Bind(entry.serverNumber[index],
4836 AFSCONF_VOLUMEPORT);
4838 MapPartIdIntoName(entry.serverPartition[index],
4841 ("Deleting the previous volume %u on server %s, partition %s ...",
4843 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4844 hostutil_GetNameByINet(entry.serverNumber[index]),
4846 code = DoVolDelete(tempconn, pvolid,
4847 entry.serverPartition[index],
4848 "the", 0, NULL, NULL);
4849 if (code && code != VNOVOL) {
4853 MapPartIdIntoName(entry.serverPartition[index],
4857 entry.serverNumber[index] = toserver;
4858 entry.serverPartition[index] = topart;
4861 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4862 MapNetworkToHost(&entry, &storeEntry);
4864 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4865 LOCKREL_OPCODE | LOCKREL_AFSID |
4869 "Could not update the entry for volume number %lu \n",
4870 (unsigned long)pvolid);
4876 EnumerateEntry(&entry);
4883 code = rx_EndCall(tocall, 0);
4889 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4890 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4893 "Could not release lock on the VLDB entry for the volume %lu\n",
4894 (unsigned long)pvolid);
4900 code = AFSVolEndTrans(toconn, totid, &rcode);
4904 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4905 (unsigned long)pvolid);
4911 code = AFSVolEndTrans(toconn, temptid, &rcode);
4915 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4916 (unsigned long)pvolid);
4922 rx_DestroyConnection(tempconn);
4924 rx_DestroyConnection(toconn);
4925 PrintError("", error);
4930 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4931 char tovolname[], int flags,
4932 afs_int32(*WriteData) (struct rx_call *, void *),
4935 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4940 /*unlocks the vldb entry associated with <volid> */
4942 UV_LockRelease(afs_uint32 volid)
4946 VPRINT("Binding to the VLDB server\n");
4948 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4949 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4952 "Could not unlock the entry for volume number %lu in VLDB \n",
4953 (unsigned long)volid);
4954 PrintError("", vcode);
4957 VPRINT("VLDB updated\n");
4962 /* old interface to add rosites */
4964 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4967 return UV_AddSite2(server, part, volid, 0, valid);
4970 /*adds <server> and <part> as a readonly replication site for <volid>
4973 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4974 afs_uint32 rovolid, afs_int32 valid)
4976 int j, nro = 0, islocked = 0;
4977 struct nvldbentry entry, storeEntry, entry2;
4978 afs_int32 vcode, error = 0;
4981 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4984 " Could not lock the VLDB entry for the volume %lu \n",
4985 (unsigned long)volid);
4990 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4993 "Could not fetch the VLDB entry for volume number %lu \n",
4994 (unsigned long)volid);
4998 if (!ISNAMEVALID(entry.name)) {
5000 "Volume name %s is too long, rename before adding site\n",
5002 error = VOLSERBADOP;
5005 MapHostToNetwork(&entry);
5007 /* See if it's too many entries */
5008 if (entry.nServers >= NMAXNSERVERS) {
5009 fprintf(STDERR, "Total number of entries will exceed %u\n",
5011 error = VOLSERBADOP;
5015 /* See if it's on the same server */
5016 for (j = 0; j < entry.nServers; j++) {
5017 if (entry.serverFlags[j] & VLSF_ROVOL) {
5019 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5022 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5025 MapPartIdIntoName(entry.serverPartition[j], apartName);
5027 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5029 error = VOLSERBADOP;
5036 /* See if it's too many RO sites - leave one for the RW */
5037 if (nro >= NMAXNSERVERS - 1) {
5038 fprintf(STDERR, "Total number of sites will exceed %u\n",
5040 error = VOLSERBADOP;
5044 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5045 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5046 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5049 if (entry.volumeId[ROVOL] == INVALID_BID) {
5050 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5052 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5055 VPRINT1("Using RO volume id %d.\n", rovolid);
5056 entry.volumeId[ROVOL] = rovolid;
5058 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5059 rovolid, entry.volumeId[ROVOL]);
5063 VPRINT("Adding a new site ...");
5064 entry.serverNumber[entry.nServers] = server;
5065 entry.serverPartition[entry.nServers] = part;
5067 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5069 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5073 MapNetworkToHost(&entry, &storeEntry);
5075 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5076 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5078 fprintf(STDERR, "Could not update entry for volume %lu \n",
5079 (unsigned long)volid);
5088 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5089 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5092 "Could not release lock on volume entry for %lu \n",
5093 (unsigned long)volid);
5094 PrintError("", vcode);
5098 PrintError("", error);
5102 /*removes <server> <part> as read only site for <volid> from the vldb */
5104 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5107 struct nvldbentry entry, storeEntry;
5109 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5111 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5112 (unsigned long)volid);
5113 PrintError("", vcode);
5116 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5119 "Could not fetch the entry for volume number %lu from VLDB \n",
5120 (unsigned long)volid);
5121 PrintError("", vcode);
5124 MapHostToNetwork(&entry);
5125 if (!Lp_ROMatch(server, part, &entry)) {
5126 /*this site doesnot exist */
5127 fprintf(STDERR, "This site is not a replication site \n");
5129 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5130 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5132 fprintf(STDERR, "Could not update entry for volume %lu \n",
5133 (unsigned long)volid);
5134 PrintError("", vcode);
5135 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5136 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5140 } else { /*remove the rep site */
5141 Lp_SetROValue(&entry, server, part, 0, 0);
5143 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5144 entry.flags &= ~VLF_ROEXISTS;
5145 if (entry.nServers < 1) { /*this is the last ref */
5146 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5148 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5151 "Could not delete VLDB entry for volume %lu \n",
5152 (unsigned long)volid);
5153 PrintError("", vcode);
5158 MapNetworkToHost(&entry, &storeEntry);
5159 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5160 (unsigned long)volid);
5163 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5164 LOCKREL_OPCODE | LOCKREL_AFSID |
5168 "Could not release lock on volume entry for %lu \n",
5169 (unsigned long)volid);
5170 PrintError("", vcode);
5171 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5172 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5175 fprintf(STDOUT, " done\n");
5181 /*sets <server> <part> as read/write site for <volid> in the vldb */
5183 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5186 struct nvldbentry entry, storeEntry;
5189 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5191 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5192 (unsigned long)volid);
5193 PrintError("", vcode);
5196 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5199 "Could not fetch the entry for volume number %lu from VLDB \n",
5200 (unsigned long)volid);
5201 PrintError("", vcode);
5204 MapHostToNetwork(&entry);
5205 index = Lp_GetRwIndex(&entry);
5207 /* no RW site exists */
5208 fprintf(STDERR, "No existing RW site for volume %lu",
5209 (unsigned long)volid);
5211 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5212 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5215 "Could not release lock on entry for volume %lu \n",
5216 (unsigned long)volid);
5217 PrintError("", vcode);
5221 } else { /* change the RW site */
5222 entry.serverNumber[index] = server;
5223 entry.serverPartition[index] = part;
5224 MapNetworkToHost(&entry, &storeEntry);
5226 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5227 LOCKREL_OPCODE | LOCKREL_AFSID |
5230 fprintf(STDERR, "Could not update entry for volume %lu \n",
5231 (unsigned long)volid);
5232 PrintError("", vcode);
5233 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5234 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5242 /*list all the partitions on <aserver> */
5244 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5247 struct rx_connection *aconn;
5248 struct pIDs partIds;
5249 struct partEntries partEnts;
5253 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5255 partEnts.partEntries_len = 0;
5256 partEnts.partEntries_val = NULL;
5257 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5258 if (code == RXGEN_OPCODE) {
5259 for (i = 0; i < 26; i++) /* try old interface */
5260 partIds.partIds[i] = -1;
5261 code = AFSVolListPartitions(aconn, &partIds);
5263 for (i = 0; i < 26; i++) {
5264 if ((partIds.partIds[i]) != -1) {
5265 ptrPartList->partId[j] = partIds.partIds[i];
5266 ptrPartList->partFlags[j] = PARTVALID;
5269 ptrPartList->partFlags[i] = 0;
5274 *cntp = partEnts.partEntries_len;
5275 if (*cntp > VOLMAXPARTS) {
5277 "Warning: number of partitions on the server too high %d (process only %d)\n",
5278 *cntp, VOLMAXPARTS);
5279 *cntp = VOLMAXPARTS;
5281 for (i = 0; i < *cntp; i++) {
5282 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5283 ptrPartList->partFlags[i] = PARTVALID;
5285 free(partEnts.partEntries_val);
5291 "Could not fetch the list of partitions from the server\n");
5292 PrintError("", code);
5294 rx_DestroyConnection(aconn);
5299 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5300 This is used by the backup system */
5302 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5303 struct volDescription *volPtr, afs_int32 arraySize)
5305 struct rx_connection *aconn;
5306 struct volDescription *curPtr;
5309 afs_int32 success = 1;
5311 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5313 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5314 if (curPtr->volFlags & CLONEVALID) {
5315 curPtr->volFlags &= ~CLONEZAPPED;
5318 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5319 "clone", 0, NULL, NULL);
5324 curPtr->volFlags |= CLONEZAPPED;
5326 fprintf(STDERR, "Could not zap volume %lu\n",
5327 (unsigned long)curPtr->volCloneId);
5329 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5330 curPtr->volCloneId);
5335 rx_DestroyConnection(aconn);
5339 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5342 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5343 struct volDescription *volPtr, afs_int32 arraySize)
5345 struct rx_connection *aconn;
5346 struct volDescription *curPtr;
5349 afs_int32 rcode = 0;
5351 int reuseCloneId = 0;
5352 afs_uint32 curCloneId = 0;
5353 char cloneName[256]; /*max vol name */
5355 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5357 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5359 else { /*get a bunch of id's from vldb */
5361 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5363 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5364 PrintError("", code);
5369 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5370 if (curPtr->volFlags & ENTRYVALID) {
5372 curPtr->volFlags |= CLONEVALID;
5373 /*make a clone of curParentId and record as curPtr->volCloneId */
5375 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5378 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5381 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5385 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5386 strcpy(cloneName, curPtr->volName);
5387 strcat(cloneName, "-tmpClone-");
5389 strcpy(cloneName, "-tmpClone");
5391 curPtr->volCloneId = curCloneId;
5396 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5397 &(curPtr->volCloneId));
5399 curPtr->volFlags &= ~CLONEVALID;
5401 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5402 curPtr->volName, (unsigned long)code);
5403 code = AFSVolEndTrans(aconn, tid, &rcode);
5405 fprintf(STDERR, "WARNING: could not end transaction\n");
5408 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5409 curPtr->volCloneId);
5410 code = AFSVolEndTrans(aconn, tid, &rcode);
5411 if (code || rcode) {
5412 curPtr->volFlags &= ~CLONEVALID;
5421 rx_DestroyConnection(aconn);
5426 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5427 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5429 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5430 struct volintInfo **resultPtr, afs_int32 * size)
5432 struct rx_connection *aconn;
5434 volEntries volumeInfo;
5437 *resultPtr = (volintInfo *) 0;
5438 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5439 volumeInfo.volEntries_len = 0;
5441 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5442 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5445 "Could not fetch the list of volumes from the server\n");
5447 *resultPtr = volumeInfo.volEntries_val;
5448 *size = volumeInfo.volEntries_len;
5452 rx_DestroyConnection(aconn);
5453 PrintError("", code);
5457 /*------------------------------------------------------------------------
5458 * EXPORTED UV_XListVolumes
5461 * List the extended information for all the volumes on a particular
5462 * File Server and partition. We may either return the volume's ID
5463 * or all of its extended information.
5466 * a_serverID : Address of the File Server for which we want
5467 * extended volume info.
5468 * a_partID : Partition for which we want the extended
5470 * a_all : If non-zero, fetch ALL the volume info,
5471 * otherwise just the volume ID.
5472 * a_resultPP : Ptr to the address of the area containing
5473 * the returned volume info.
5474 * a_numEntsInResultP : Ptr for the value we set for the number of
5479 * Otherise, the return value of AFSVolXListVolumes.
5482 * This routine is closely related to UV_ListVolumes, which returns
5483 * only the standard level of detail on AFS volumes. It is a
5484 * heavyweight operation, zipping through all the volume entries for
5485 * a given server/partition.
5489 *------------------------------------------------------------------------*/
5492 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5493 struct volintXInfo **a_resultPP,
5494 afs_int32 * a_numEntsInResultP)
5496 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5497 afs_int32 code; /*Error code to return */
5498 volXEntries volumeXInfo; /*Area for returned extended vol info */
5501 * Set up our error code and the area for returned extended volume info.
5502 * We set the val field to a null pointer as a hint for the stub to
5505 *a_numEntsInResultP = 0;
5506 *a_resultPP = (volintXInfo *) 0;
5507 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5508 volumeXInfo.volXEntries_len = 0;
5511 * Bind to the Volume Server port on the File Server machine in question,
5514 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5515 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5517 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5520 * We got the info; pull out the pointer to where the results lie
5521 * and how many entries are there.
5523 *a_resultPP = volumeXInfo.volXEntries_val;
5524 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5528 * If we got an Rx connection, throw it away.
5531 rx_DestroyConnection(rxConnP);
5533 PrintError("", code);
5535 } /*UV_XListVolumes */
5537 /* get all the information about volume <volid> on <aserver> and <apart> */
5539 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5540 struct volintInfo **resultPtr)
5542 struct rx_connection *aconn;
5544 volEntries volumeInfo;
5546 *resultPtr = (volintInfo *) 0;
5547 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5548 volumeInfo.volEntries_len = 0;
5550 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5551 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5554 "Could not fetch the information about volume %lu from the server\n",
5555 (unsigned long)volid);
5557 *resultPtr = volumeInfo.volEntries_val;
5562 rx_DestroyConnection(aconn);
5563 PrintError("", code);
5567 /*------------------------------------------------------------------------
5568 * EXPORTED UV_XListOneVolume
5571 * List the extended information for a volume on a particular File
5572 * Server and partition.
5575 * a_serverID : Address of the File Server for which we want
5576 * extended volume info.
5577 * a_partID : Partition for which we want the extended
5579 * a_volID : Volume ID for which we want the info.
5580 * a_resultPP : Ptr to the address of the area containing
5581 * the returned volume info.
5585 * Otherise, the return value of AFSVolXListOneVolume.
5588 * This routine is closely related to UV_ListOneVolume, which returns
5589 * only the standard level of detail on the chosen AFS volume.
5593 *------------------------------------------------------------------------*/
5596 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5597 struct volintXInfo **a_resultPP)
5599 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5600 afs_int32 code; /*Error code */
5601 volXEntries volumeXInfo; /*Area for returned info */
5604 * Set up our error code, and the area we're in which we are returning
5605 * the info. Setting the val field to a null pointer tells the stub
5606 * to allocate space for us.
5608 *a_resultPP = (volintXInfo *) 0;
5609 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5610 volumeXInfo.volXEntries_len = 0;
5613 * Bind to the Volume Server port on the File Server machine in question,
5616 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5617 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5620 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5623 * We got the info; pull out the pointer to where the results lie.
5625 *a_resultPP = volumeXInfo.volXEntries_val;
5628 * If we got an Rx connection, throw it away.
5631 rx_DestroyConnection(rxConnP);
5633 PrintError("", code);
5638 * Given a volume we read from a partition, check if it is
5639 * represented in the VLDB correctly.
5641 * The VLDB is looked up by the RW volume id (not its name).
5642 * The RW contains the true name of the volume (BK and RO set
5643 * the name in the VLDB only on creation of the VLDB entry).
5644 * We want rules strict enough that when we check all volumes
5645 * on one partition, it does not need to be done again. IE:
5646 * two volumes on different partitions won't constantly
5647 * change a VLDB entry away from what the other set.
5648 * For RW and BK volumes, we will always check the VLDB to see
5649 * if the two exist on the server/partition. May seem redundant,
5650 * but this is an easy check of the VLDB. IE: if the VLDB entry
5651 * says the BK exists but no BK volume is there, we will detect
5652 * this when we check the RW volume.
5653 * VLDB entries are locked only when a change needs to be done.
5654 * Output changed to look a lot like the "vos syncserv" otuput.
5657 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5658 afs_int32 * modentry, afs_uint32 * maxvolid,
5659 struct nvldbentry *aentry)
5663 afs_int32 code, error = 0;
5664 struct nvldbentry entry, storeEntry;
5666 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5676 ((volumeinfo->type ==
5677 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5680 /* Check to see if the VLDB is ok without locking it (pass 1).
5681 * If it will change, then lock the VLDB entry, read it again,
5682 * then make the changes to it (pass 2).
5685 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5687 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5688 (unsigned long)rwvolid);
5693 createentry = 0; /* Do we need to create a VLDB entry */
5694 addvolume = 0; /* Add this volume to the VLDB entry */
5695 modified = 0; /* The VLDB entry was modified */
5698 memcpy(&entry, aentry, sizeof(entry));
5700 /* Read the entry from VLDB by its RW volume id */
5701 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5703 if (code != VL_NOENT) {
5705 "Could not retrieve the VLDB entry for volume %lu \n",
5706 (unsigned long)rwvolid);
5710 memset(&entry, 0, sizeof(entry));
5711 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5715 MapHostToNetwork(&entry);
5719 if (verbose && (pass == 1)) {
5720 fprintf(STDOUT, "_______________________________\n");
5721 fprintf(STDOUT, "\n-- status before -- \n");
5723 fprintf(STDOUT, "\n**does not exist**\n");
5725 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
5726 || (entry.flags & VLF_BACKEXISTS))
5727 EnumerateEntry(&entry);
5729 fprintf(STDOUT, "\n");
5732 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5738 /* Check existence of RW and BK volumes */
5739 code = CheckVldbRWBK(&entry, &mod);
5745 idx = Lp_GetRwIndex(&entry);
5746 if (idx == -1) { /* RW index not found in the VLDB entry */
5747 idx = entry.nServers; /* put it into next index */
5750 } else { /* RW index found in the VLDB entry. */
5751 /* Verify if this volume's location matches where the VLDB says it is */
5752 if (!Lp_Match(aserver, apart, &entry)) {
5753 if (entry.flags & VLF_RWEXISTS) {
5754 /* The RW volume exists elsewhere - report this one a duplicate */
5756 MapPartIdIntoName(apart, pname);
5758 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5759 (unsigned long)rwvolid,
5761 afs_inet_ntoa_r(aserver, hoststr) :
5762 hostutil_GetNameByINet(aserver), pname);
5763 MapPartIdIntoName(entry.serverPartition[idx],
5766 " VLDB reports RW volume %lu exists on %s %s\n",
5767 (unsigned long)rwvolid,
5769 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5770 hostutil_GetNameByINet(entry.
5775 /* The RW volume does not exist - have VLDB point to this one */
5778 /* Check for orphaned BK volume on old partition */
5779 if (entry.flags & VLF_BACKEXISTS) {
5781 MapPartIdIntoName(entry.serverPartition[idx],
5784 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5785 entry.volumeId[BACKVOL],
5787 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5788 hostutil_GetNameByINet(entry.
5791 MapPartIdIntoName(apart, pname);
5793 " VLDB reports its RW volume %lu exists on %s %s\n",
5794 (unsigned long)rwvolid,
5796 afs_inet_ntoa_r(aserver, hoststr) :
5797 hostutil_GetNameByINet(aserver),
5803 /* Volume location matches the VLDB location */
5804 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5805 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5808 (entry.name, volumeinfo->name,
5809 VOLSER_OLDMAXVOLNAME) != 0)) {
5817 entry.flags |= VLF_RWEXISTS;
5818 entry.volumeId[RWVOL] = rwvolid;
5819 if (!entry.volumeId[BACKVOL])
5820 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5821 if (!entry.volumeId[ROVOL])
5822 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5824 entry.serverFlags[idx] = VLSF_RWVOL;
5825 entry.serverNumber[idx] = aserver;
5826 entry.serverPartition[idx] = apart;
5827 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5831 /* One last check - to update BK if need to */
5832 code = CheckVldbRWBK(&entry, &mod);
5840 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5846 /* Check existence of RW and BK volumes */
5847 code = CheckVldbRWBK(&entry, &mod);
5853 idx = Lp_GetRwIndex(&entry);
5854 if (idx == -1) { /* RW index not found in the VLDB entry */
5855 idx = entry.nServers; /* Put it into next index */
5858 } else { /* RW index found in the VLDB entry */
5859 /* Verify if this volume's location matches where the VLDB says it is */
5860 if (!Lp_Match(aserver, apart, &entry)) {
5861 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5863 MapPartIdIntoName(apart, pname);
5865 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5866 (unsigned long)volumeinfo->volid,
5868 afs_inet_ntoa_r(aserver, hoststr) :
5869 hostutil_GetNameByINet(aserver), pname);
5870 MapPartIdIntoName(entry.serverPartition[idx], pname);
5872 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5873 (unsigned long)rwvolid,
5875 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5876 hostutil_GetNameByINet(entry.
5881 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5882 if (!(entry.flags & VLF_BACKEXISTS)) {
5884 } else if (volumeinfo->volid >
5885 entry.volumeId[BACKVOL]) {
5889 MapPartIdIntoName(entry.serverPartition[idx],
5892 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5893 entry.volumeId[BACKVOL],
5895 afs_inet_ntoa_r(aserver, hoststr) :
5896 hostutil_GetNameByINet(aserver),
5899 " VLDB reports its BK volume ID is %lu\n",
5900 (unsigned long)volumeinfo->volid);
5904 MapPartIdIntoName(entry.serverPartition[idx],
5907 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5908 (unsigned long)volumeinfo->volid,
5910 afs_inet_ntoa_r(aserver, hoststr) :
5911 hostutil_GetNameByINet(aserver),
5914 " VLDB reports its BK volume ID is %u\n",
5915 entry.volumeId[BACKVOL]);
5918 } else if (!entry.volumeId[BACKVOL]) {
5925 entry.flags |= VLF_BACKEXISTS;
5926 entry.volumeId[RWVOL] = rwvolid;
5927 entry.volumeId[BACKVOL] = volumeinfo->volid;
5929 entry.serverNumber[idx] = aserver;
5930 entry.serverPartition[idx] = apart;
5931 entry.serverFlags[idx] = VLSF_RWVOL;
5937 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5938 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5939 /* This is a quick check to see if the RO entry exists in the
5940 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5941 * RO volume listed in the VLDB exists).
5943 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5945 idx = entry.nServers;
5949 if (!(entry.flags & VLF_ROEXISTS)) {
5954 /* Before we correct the VLDB entry, make sure all the
5955 * ROs listed in the VLDB exist.
5957 code = CheckVldbRO(&entry, &mod);
5963 if (!(entry.flags & VLF_ROEXISTS)) {
5964 /* No RO exists in the VLDB entry - add this one */
5965 idx = entry.nServers;
5968 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5969 /* The volume headers's RO ID does not match that in the VLDB entry,
5970 * and the vol hdr's ID is greater (implies more recent). So delete
5971 * all the RO volumes listed in VLDB entry and add this volume.
5973 for (j = 0; j < entry.nServers; j++) {
5974 if (entry.serverFlags[j] & VLSF_ROVOL) {
5975 /* Verify this volume exists and print message we are orphaning it */
5977 MapPartIdIntoName(apart, pname);
5979 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5980 entry.volumeId[ROVOL],
5982 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5983 hostutil_GetNameByINet(entry.
5987 " VLDB reports its RO volume ID is %lu\n",
5988 (unsigned long)volumeinfo->volid);
5991 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5992 entry.serverPartition[idx], 0L, 0L);
5999 idx = entry.nServers;
6002 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6003 /* The volume headers's RO ID does not match that in the VLDB entry,
6004 * and the vol hdr's ID is lower (implies its older). So orphan it.
6007 MapPartIdIntoName(apart, pname);
6009 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6010 (unsigned long)volumeinfo->volid,
6012 afs_inet_ntoa_r(aserver, hoststr) :
6013 hostutil_GetNameByINet(aserver), pname);
6015 " VLDB reports its RO volume ID is %u\n",
6016 entry.volumeId[ROVOL]);
6019 /* The RO volume ID in the volume header match that in the VLDB entry,
6020 * and there exist RO volumes in the VLDB entry. See if any of them
6021 * are this one. If not, then we add it.
6023 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6025 idx = entry.nServers;
6033 entry.flags |= VLF_ROEXISTS;
6034 entry.volumeId[RWVOL] = rwvolid;
6035 entry.volumeId[ROVOL] = volumeinfo->volid;
6037 entry.serverNumber[idx] = aserver;
6038 entry.serverPartition[idx] = apart;
6039 entry.serverFlags[idx] = VLSF_ROVOL;
6045 /* Remember largest volume id */
6046 if (entry.volumeId[ROVOL] > *maxvolid)
6047 *maxvolid = entry.volumeId[ROVOL];
6048 if (entry.volumeId[BACKVOL] > *maxvolid)
6049 *maxvolid = entry.volumeId[BACKVOL];
6050 if (entry.volumeId[RWVOL] > *maxvolid)
6051 *maxvolid = entry.volumeId[RWVOL];
6053 if (modified && doit) {
6054 MapNetworkToHost(&entry, &storeEntry);
6057 code = VLDB_CreateEntry(&storeEntry);
6060 "Could not create a VLDB entry for the volume %lu\n",
6061 (unsigned long)rwvolid);
6068 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6069 LOCKREL_OPCODE | LOCKREL_AFSID |
6072 fprintf(STDERR, "Could not update entry for %lu\n",
6073 (unsigned long)rwvolid);
6077 } else if (pass == 2) {
6079 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6080 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6082 PrintError("Could not unlock VLDB entry ", code);
6086 if (modified && modentry) {
6091 memcpy(aentry, &entry, sizeof(entry));
6095 fprintf(STDOUT, "-- status after --\n");
6097 EnumerateEntry(&entry);
6099 fprintf(STDOUT, "\n**no change**\n");
6103 VPRINT("\n_______________________________\n");
6108 sortVolumes(const void *a, const void *b)
6110 volintInfo *v1 = (volintInfo *) a;
6111 volintInfo *v2 = (volintInfo *) b;
6112 afs_uint32 rwvolid1, rwvolid2;
6114 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6115 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6117 if (rwvolid1 > rwvolid2)
6118 return -1; /* lower RW id goes first */
6119 if (rwvolid1 < rwvolid2)
6122 if (v1->type == RWVOL)
6123 return -1; /* RW vols go first */
6124 if (v2->type == RWVOL)
6127 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6128 return -1; /* BK vols next */
6129 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6132 if (v1->volid < v2->volid)
6133 return 1; /* larger volids first */
6134 if (v1->volid > v2->volid)
6140 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6141 * Synchronize an individual volume against a sever and partition.
6142 * Checks the VLDB entry (similar to syncserv) as well as checks
6143 * if the volume exists on specified servers (similar to syncvldb).
6146 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6148 struct rx_connection *aconn = 0;
6149 afs_int32 j, k, code, vcode, error = 0;
6151 afs_int32 mod, modified = 0, deleted = 0;
6152 struct nvldbentry vldbentry;
6153 afs_uint32 volumeid = 0;
6154 volEntries volumeInfo;
6155 struct partList PartList;
6157 afs_uint32 maxvolid = 0;
6159 volumeInfo.volEntries_val = (volintInfo *) 0;
6160 volumeInfo.volEntries_len = 0;
6162 /* Turn verbose logging off and do our own verbose logging */
6163 /* tverbose must be set before we call ERROR_EXIT() */
6170 if (!aserver && (flags & 1)) {
6171 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6175 /* Read the VLDB entry */
6176 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6177 if (vcode && (vcode != VL_NOENT)) {
6178 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6181 } else if (!vcode) {
6182 MapHostToNetwork(&vldbentry);
6186 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6187 fprintf(STDOUT, "_______________________________\n");
6188 fprintf(STDOUT, "\n-- status before -- \n");
6190 fprintf(STDOUT, "\n**does not exist**\n");
6192 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6193 || (vldbentry.flags & VLF_BACKEXISTS))
6194 EnumerateEntry(&vldbentry);
6196 fprintf(STDOUT, "\n");
6199 /* Verify that all of the VLDB entries exist on the repective servers
6200 * and partitions (this does not require that avolname be a volume ID).
6201 * Equivalent to a syncserv.
6204 /* Tell CheckVldb not to update if appropriate */
6209 code = CheckVldb(&vldbentry, &mod, &deleted);
6211 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6219 /* If aserver is given, we will search for the desired volume on it */
6221 /* Generate array of partitions on the server that we will check */
6223 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6226 "Could not fetch the list of partitions from the server\n");
6230 PartList.partId[0] = apart;
6234 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6236 /* If a volume ID were given, search for it on each partition */
6237 if ((volumeid = atol(avolname))) {
6238 for (j = 0; j < pcnt; j++) {
6240 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6243 if (code != ENODEV) {
6244 fprintf(STDERR, "Could not query server\n");
6252 /* Found one, sync it with VLDB entry */
6254 CheckVolume(volumeInfo.volEntries_val, aserver,
6255 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6262 if (volumeInfo.volEntries_val)
6263 free(volumeInfo.volEntries_val);
6264 volumeInfo.volEntries_val = (volintInfo *) 0;
6265 volumeInfo.volEntries_len = 0;
6269 /* Check to see if the RW, BK, and RO IDs exist on any
6270 * partitions. We get the volume IDs from the VLDB.
6272 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6273 if (vldbentry.volumeId[j] == 0)
6276 for (k = 0; k < pcnt; k++) { /* For each partition */
6277 volumeInfo.volEntries_val = (volintInfo *) 0;
6278 volumeInfo.volEntries_len = 0;
6280 AFSVolListOneVolume(aconn, PartList.partId[k],
6281 vldbentry.volumeId[j], &volumeInfo);
6283 if (code != ENODEV) {
6284 fprintf(STDERR, "Could not query server\n");
6292 /* Found one, sync it with VLDB entry */
6294 CheckVolume(volumeInfo.volEntries_val, aserver,
6295 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6302 if (volumeInfo.volEntries_val)
6303 free(volumeInfo.volEntries_val);
6304 volumeInfo.volEntries_val = (volintInfo *) 0;
6305 volumeInfo.volEntries_len = 0;
6311 /* If verbose output, print a summary of what changed */
6313 fprintf(STDOUT, "-- status after --\n");
6315 fprintf(STDOUT, "\n**entry deleted**\n");
6316 } else if (modified) {
6317 EnumerateEntry(&vldbentry);
6319 fprintf(STDOUT, "\n**no change**\n");
6321 fprintf(STDOUT, "\n_______________________________\n");
6325 /* Now check if the maxvolid is larger than that stored in the VLDB */
6327 afs_uint32 maxvldbid = 0;
6328 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6331 "Could not get the highest allocated volume id from the VLDB\n");
6334 } else if (maxvolid > maxvldbid) {
6336 id = maxvolid - maxvldbid + 1;
6337 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6340 "Error in increasing highest allocated volume id in VLDB\n");
6350 fprintf(STDOUT, "...error encountered");
6352 fprintf(STDOUT, "...done entry\n");
6355 rx_DestroyConnection(aconn);
6356 if (volumeInfo.volEntries_val)
6357 free(volumeInfo.volEntries_val);
6359 PrintError("", error);
6364 * Synchronise vldb with the file server <aserver> and,
6365 * optionally, <apart>.
6368 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6370 struct rx_connection *aconn;
6371 afs_int32 code, error = 0;
6374 volEntries volumeInfo;
6375 struct partList PartList;
6379 afs_int32 failures = 0, modifications = 0, tentries = 0;
6381 afs_uint32 maxvolid = 0;
6384 volumeInfo.volEntries_val = (volintInfo *) 0;
6385 volumeInfo.volEntries_len = 0;
6387 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6389 /* Generate array of partitions to check */
6391 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6394 "Could not fetch the list of partitions from the server\n");
6398 PartList.partId[0] = apart;
6402 VPRINT("Processing volume entries ...\n");
6404 /* Step through the array of partitions */
6405 for (i = 0; i < pcnt; i++) {
6406 apart = PartList.partId[i];
6407 MapPartIdIntoName(apart, pname);
6409 volumeInfo.volEntries_val = (volintInfo *) 0;
6410 volumeInfo.volEntries_len = 0;
6411 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6414 "Could not fetch the list of volumes from the server\n");
6418 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6419 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6420 sizeof(volintInfo), sortVolumes);
6423 for (vi = volumeInfo.volEntries_val, j = 0;
6424 j < volumeInfo.volEntries_len; j++, vi++) {
6432 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6433 j + 1, vi->name, (unsigned long)vi->volid,
6435 afs_inet_ntoa_r(aserver, hoststr) :
6436 hostutil_GetNameByINet(aserver), pname);
6444 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6446 PrintError("", code);
6449 } else if (modified) {
6455 fprintf(STDOUT, "...error encountered\n\n");
6457 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6464 "Could not process entries on server %s partition %s\n",
6466 afs_inet_ntoa_r(aserver, hoststr) :
6467 hostutil_GetNameByINet(aserver), pname);
6469 if (volumeInfo.volEntries_val) {
6470 free(volumeInfo.volEntries_val);
6471 volumeInfo.volEntries_val = 0;
6474 } /* thru all partitions */
6477 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6478 tentries, failures, modifications);
6480 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6481 tentries, failures, modifications);
6485 /* Now check if the maxvolid is larger than that stored in the VLDB */
6487 afs_uint32 maxvldbid = 0;
6488 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6491 "Could not get the highest allocated volume id from the VLDB\n");
6494 } else if (maxvolid > maxvldbid) {
6496 id = maxvolid - maxvldbid + 1;
6497 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6500 "Error in increasing highest allocated volume id in VLDB\n");
6508 rx_DestroyConnection(aconn);
6509 if (volumeInfo.volEntries_val)
6510 free(volumeInfo.volEntries_val);
6511 PrintError("", error);
6516 * Determine if a volume exists on a server and partition.
6517 * Try creating a transaction on the volume. If we can,
6518 * the volume exists, if not, then return the error code.
6519 * Some error codes mean the volume is unavailable but
6520 * still exists - so we catch these error codes.
6523 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6525 struct rx_connection *conn = (struct rx_connection *)0;
6526 afs_int32 code = -1;
6527 volEntries volumeInfo;
6529 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6531 volumeInfo.volEntries_val = (volintInfo *) 0;
6532 volumeInfo.volEntries_len = 0;
6533 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6534 if (volumeInfo.volEntries_val)
6535 free(volumeInfo.volEntries_val);
6536 if (code == VOLSERILLEGAL_PARTITION)
6538 rx_DestroyConnection(conn);
6547 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6551 afs_int32 code, error = 0;
6557 idx = Lp_GetRwIndex(entry);
6559 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6562 if (idx == -1) { /* Did not find a RW entry */
6563 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6564 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6569 VolumeExists(entry->serverNumber[idx],
6570 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6571 if (code == 0) { /* RW volume exists */
6572 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6573 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6576 } else if (code == ENODEV) { /* RW volume does not exist */
6577 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6578 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6582 /* If VLDB says it didn't exist, then ignore error */
6583 if (entry->flags & VLF_RWEXISTS) {
6584 MapPartIdIntoName(entry->serverPartition[idx], pname);
6586 "Transaction call failed for RW volume %u on server %s %s\n",
6587 entry->volumeId[RWVOL],
6589 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6590 hostutil_GetNameByINet(entry->serverNumber[idx]),
6597 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6598 * flag accordingly. idx already ponts to the RW entry.
6600 if (idx == -1) { /* Did not find a RW entry */
6601 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6602 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6605 } else { /* Found a RW entry */
6607 VolumeExists(entry->serverNumber[idx],
6608 entry->serverPartition[idx],
6609 entry->volumeId[BACKVOL]);
6610 if (code == 0) { /* BK volume exists */
6611 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6612 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6615 } else if (code == ENODEV) { /* BK volume does not exist */
6616 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6617 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6621 /* If VLDB says it didn't exist, then ignore error */
6622 if (entry->flags & VLF_BACKEXISTS) {
6623 MapPartIdIntoName(entry->serverPartition[idx], pname);
6625 "Transaction call failed for BK volume %u on server %s %s\n",
6626 entry->volumeId[BACKVOL],
6628 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6629 hostutil_GetNameByINet(entry->serverNumber[idx]),
6636 /* If there is an idx but the BK and RW volumes no
6637 * longer exist, then remove the RW entry.
6639 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6640 && !(entry->flags & VLF_BACKEXISTS)) {
6641 Lp_SetRWValue(entry, entry->serverNumber[idx],
6642 entry->serverPartition[idx], 0L, 0L);
6649 *modified = modentry;
6654 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6657 int foundro = 0, modentry = 0;
6658 afs_int32 code, error = 0;
6665 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6668 for (idx = 0; idx < entry->nServers; idx++) {
6669 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6670 continue; /* not a RO */
6674 VolumeExists(entry->serverNumber[idx],
6675 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6676 if (code == 0) { /* RO volume exists */
6678 } else if (code == ENODEV) { /* RW volume does not exist */
6679 Lp_SetROValue(entry, entry->serverNumber[idx],
6680 entry->serverPartition[idx], 0L, 0L);
6685 MapPartIdIntoName(entry->serverPartition[idx], pname);
6687 "Transaction call failed for RO %u on server %s %s\n",
6688 entry->volumeId[ROVOL],
6690 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6691 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6696 if (foundro) { /* A RO volume exists */
6697 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6698 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6701 } else { /* A RO volume does not exist */
6702 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6703 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
6710 *modified = modentry;
6715 * Ensure that <entry> matches with the info on file servers
6718 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6720 afs_int32 code, error = 0;
6721 struct nvldbentry storeEntry;
6722 int islocked = 0, mod, modentry, delentry = 0;
6723 int pass = 0, doit=1;
6731 fprintf(STDOUT, "_______________________________\n");
6732 fprintf(STDOUT, "\n-- status before -- \n");
6733 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
6734 || (entry->flags & VLF_BACKEXISTS))
6735 EnumerateEntry(entry);
6736 fprintf(STDOUT, "\n");
6739 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6740 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6741 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6745 /* Check to see if the VLDB is ok without locking it (pass 1).
6746 * If it will change, then lock the VLDB entry, read it again,
6747 * then make the changes to it (pass 2).
6751 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6754 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6755 entry->volumeId[RWVOL]);
6760 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6762 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6766 MapHostToNetwork(entry);
6772 /* Check if the RW and BK entries are ok */
6773 code = CheckVldbRWBK(entry, &mod);
6776 if (mod && (pass == 1) && doit)
6781 /* Check if the RO volumes entries are ok */
6782 code = CheckVldbRO(entry, &mod);
6785 if (mod && (pass == 1) && doit)
6790 /* The VLDB entry has been updated. If it as been modified, then
6791 * write the entry back out the the VLDB.
6793 if (modentry && doit) {
6797 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
6798 && !(entry->flags & VLF_ROEXISTS) && doit) {
6799 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6801 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6805 "Could not delete VLDB entry for volume %u \n",
6806 entry->volumeId[RWVOL]);
6811 /* Replace old entry with our new one */
6812 MapNetworkToHost(entry, &storeEntry);
6814 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6815 (LOCKREL_OPCODE | LOCKREL_AFSID |
6816 LOCKREL_TIMESTAMP));
6818 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6819 entry->volumeId[RWVOL]);
6826 if (modified && modentry) {
6829 if (deleted && delentry) {
6834 fprintf(STDOUT, "-- status after --\n");
6836 fprintf(STDOUT, "\n**entry deleted**\n");
6838 EnumerateEntry(entry);
6840 fprintf(STDOUT, "\n**no change**\n");
6844 VPRINT("\n_______________________________\n");
6848 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6850 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6853 "Could not release lock on VLDB entry for volume %u\n",
6854 entry->volumeId[RWVOL]);
6863 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6866 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6868 struct rx_connection *aconn;
6869 afs_int32 code, error = 0;
6870 afs_int32 nentries, tentries = 0;
6871 struct VldbListByAttributes attributes;
6872 nbulkentries arrayEntries;
6873 afs_int32 failures = 0, modified, modifications = 0;
6874 struct nvldbentry *vlentry;
6875 afs_int32 si, nsi, j;
6880 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6882 /* Set up attributes to search VLDB */
6883 memset(&attributes, 0, sizeof(attributes));
6884 attributes.server = ntohl(aserver);
6885 attributes.Mask = VLLIST_SERVER;
6887 attributes.partition = apart;
6888 attributes.Mask |= VLLIST_PARTITION;
6891 VPRINT("Processing VLDB entries ...\n");
6893 /* While we need to collect more VLDB entries */
6894 for (si = 0; si != -1; si = nsi) {
6895 memset(&arrayEntries, 0, sizeof(arrayEntries));
6897 /* Collect set of VLDB entries */
6899 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6900 &arrayEntries, &nsi);
6901 if (code == RXGEN_OPCODE) {
6902 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6906 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6909 tentries += nentries;
6911 for (j = 0; j < nentries; j++) {
6912 vlentry = &arrayEntries.nbulkentries_val[j];
6913 MapHostToNetwork(vlentry);
6915 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6917 /* Tell CheckVldb not to update if appropriate */
6922 code = CheckVldb(vlentry, &modified, NULL);
6924 PrintError("", code);
6926 "Could not process VLDB entry for volume %s\n",
6929 } else if (modified) {
6935 fprintf(STDOUT, "...error encountered\n\n");
6937 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6942 if (arrayEntries.nbulkentries_val) {
6943 free(arrayEntries.nbulkentries_val);
6944 arrayEntries.nbulkentries_val = 0;
6949 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6950 tentries, failures, modifications);
6952 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6953 tentries, failures, modifications);
6958 rx_DestroyConnection(aconn);
6959 if (arrayEntries.nbulkentries_val)
6960 free(arrayEntries.nbulkentries_val);
6963 error = VOLSERFAILEDOP;
6967 /*rename volume <oldname> to <newname>, changing the names of the related
6968 *readonly and backup volumes. This operation is also idempotent.
6969 *salvager is capable of recovering from rename operation stopping halfway.
6970 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6972 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6974 struct nvldbentry storeEntry;
6975 afs_int32 vcode, code, rcode, error;
6977 char nameBuffer[256];
6979 struct rx_connection *aconn;
6984 aconn = (struct rx_connection *)0;
6988 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6991 " Could not lock the VLDB entry for the volume %u \n",
6992 entry->volumeId[RWVOL]);
6997 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6998 MapNetworkToHost(entry, &storeEntry);
6999 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7001 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7002 entry->volumeId[RWVOL]);
7006 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7007 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7008 * is concerned, oldname is lost */
7009 if (entry->flags & VLF_RWEXISTS) {
7010 index = Lp_GetRwIndex(entry);
7011 if (index == -1) { /* there is a serious discrepancy */
7013 "There is a serious discrepancy in VLDB entry for volume %u\n",
7014 entry->volumeId[RWVOL]);
7015 fprintf(STDERR, "try building VLDB from scratch\n");
7016 error = VOLSERVLDB_ERROR;
7019 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7021 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7022 entry->serverPartition[index], ITOffline, &tid);
7023 if (code) { /*volume doesnot exist */
7025 "Could not start transaction on the rw volume %u\n",
7026 entry->volumeId[RWVOL]);
7029 } else { /*volume exists, process it */
7032 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7033 entry->volumeId[RWVOL],
7034 entry->volumeId[ROVOL],
7035 entry->volumeId[BACKVOL]);
7037 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7038 code = AFSVolEndTrans(aconn, tid, &rcode);
7042 "Could not end transaction on volume %s %u\n",
7043 entry->name, entry->volumeId[RWVOL]);
7048 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7049 entry->name, entry->volumeId[RWVOL]);
7055 rx_DestroyConnection(aconn);
7056 aconn = (struct rx_connection *)0;
7058 /*end rw volume processing */
7059 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7060 index = Lp_GetRwIndex(entry);
7061 if (index == -1) { /* there is a serious discrepancy */
7063 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7064 entry->volumeId[BACKVOL]);
7065 fprintf(STDERR, "try building VLDB from scratch\n");
7066 error = VOLSERVLDB_ERROR;
7069 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7071 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7072 entry->serverPartition[index], ITOffline, &tid);
7073 if (code) { /*volume doesnot exist */
7075 "Could not start transaction on the backup volume %u\n",
7076 entry->volumeId[BACKVOL]);
7079 } else { /*volume exists, process it */
7080 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7082 "Volume name %s.backup exceeds the limit of %u characters\n",
7083 newname, VOLSER_OLDMAXVOLNAME);
7087 strcpy(nameBuffer, newname);
7088 strcat(nameBuffer, ".backup");
7091 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7092 entry->volumeId[RWVOL], 0, 0);
7094 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7095 code = AFSVolEndTrans(aconn, tid, &rcode);
7099 "Could not end transaction on the backup volume %u\n",
7100 entry->volumeId[BACKVOL]);
7106 "Could not set parameters on the backup volume %u\n",
7107 entry->volumeId[BACKVOL]);
7112 } /* end backup processing */
7114 rx_DestroyConnection(aconn);
7115 aconn = (struct rx_connection *)0;
7116 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7117 for (i = 0; i < entry->nServers; i++) {
7118 if (entry->serverFlags[i] & VLSF_ROVOL) {
7119 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7121 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7122 entry->serverPartition[i], ITOffline,
7124 if (code) { /*volume doesnot exist */
7126 "Could not start transaction on the ro volume %u\n",
7127 entry->volumeId[ROVOL]);
7130 } else { /*volume exists, process it */
7131 strcpy(nameBuffer, newname);
7132 strcat(nameBuffer, ".readonly");
7133 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7135 "Volume name %s exceeds the limit of %u characters\n",
7136 nameBuffer, VOLSER_OLDMAXVOLNAME);
7141 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7142 entry->volumeId[RWVOL], 0, 0);
7144 VPRINT2("Renamed RO volume %s on host %s\n",
7147 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7148 hostutil_GetNameByINet(entry->
7150 code = AFSVolEndTrans(aconn, tid, &rcode);
7154 "Could not end transaction on volume %u\n",
7155 entry->volumeId[ROVOL]);
7161 "Could not set parameters on the ro volume %u\n",
7162 entry->volumeId[ROVOL]);
7168 rx_DestroyConnection(aconn);
7169 aconn = (struct rx_connection *)0;
7176 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7178 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7181 "Could not unlock the VLDB entry for the volume %s %u\n",
7182 entry->name, entry->volumeId[RWVOL]);
7188 code = AFSVolEndTrans(aconn, tid, &rcode);
7192 fprintf(STDERR, "Failed to end transaction on a volume \n");
7198 rx_DestroyConnection(aconn);
7199 PrintError("", error);
7204 /*report on all the active transactions on volser */
7206 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7208 struct rx_connection *aconn;
7209 transDebugEntries transInfo;
7212 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7213 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7214 transInfo.transDebugEntries_len = 0;
7215 code = AFSVolMonitor(aconn, &transInfo);
7218 "Could not access status information about the server\n");
7219 PrintError("", code);
7220 if (transInfo.transDebugEntries_val)
7221 free(transInfo.transDebugEntries_val);
7223 rx_DestroyConnection(aconn);
7226 *rcount = transInfo.transDebugEntries_len;
7227 *rpntr = transInfo.transDebugEntries_val;
7229 rx_DestroyConnection(aconn);
7236 /*delete the volume without interacting with the vldb */
7238 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7241 struct rx_connection *aconn;
7243 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7244 error = DoVolDelete(aconn, volid, part,
7245 "the", 0, NULL, NULL);
7246 if (error == VNOVOL) {
7247 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7250 PrintError("", error);
7252 rx_DestroyConnection(aconn);
7257 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7258 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7260 struct rx_connection *conn = 0;
7262 afs_int32 code, error = 0, rcode;
7264 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7266 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7270 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7272 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7276 code = AFSVolSetFlags(conn, tid, setflag);
7278 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7283 #ifdef AFS_PTHREAD_ENV
7286 IOMGR_Sleep(sleeptime);
7293 code = AFSVolEndTrans(conn, tid, &rcode);
7294 if (code || rcode) {
7295 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7297 error = (code ? code : rcode);
7302 rx_DestroyConnection(conn);
7307 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7310 struct rx_connection *conn = 0;
7312 afs_int32 code, error = 0, rcode;
7314 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7316 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7320 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7322 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7326 code = AFSVolSetInfo(conn, tid, infop);
7328 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7335 code = AFSVolEndTrans(conn, tid, &rcode);
7336 if (code || rcode) {
7337 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7339 error = (code ? code : rcode);
7344 rx_DestroyConnection(conn);
7349 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7350 afs_int32 fromdate, struct volintSize *vol_size)
7352 struct rx_connection *aconn = (struct rx_connection *)0;
7353 afs_int32 tid = 0, rcode = 0;
7354 afs_int32 code, error = 0;
7357 /* get connections to the servers */
7358 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7360 VPRINT1("Starting transaction on volume %u...", afromvol);
7361 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7362 EGOTO1(error_exit, code,
7363 "Could not start transaction on the volume %u to be measured\n",
7367 VPRINT1("Getting size of volume on volume %u...", afromvol);
7368 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7369 EGOTO(error_exit, code, "Could not start the measurement process \n");
7374 VPRINT1("Ending transaction on volume %u...", afromvol);
7375 code = AFSVolEndTrans(aconn, tid, &rcode);
7376 if (code || rcode) {
7377 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7379 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7381 error = (code ? code : rcode);
7386 rx_DestroyConnection(aconn);
7388 PrintError("", error);
7392 /*maps the host addresses in <old > (present in network byte order) to
7393 that in< new> (present in host byte order )*/
7395 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7399 memset(new, 0, sizeof(struct nvldbentry));
7401 /*copy all the fields */
7402 strcpy(new->name, old->name);
7403 /* new->volumeType = old->volumeType;*/
7404 new->nServers = old->nServers;
7405 count = old->nServers;
7406 if (count < NMAXNSERVERS)
7408 for (i = 0; i < count; i++) {
7409 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7410 new->serverPartition[i] = old->serverPartition[i];
7411 new->serverFlags[i] = old->serverFlags[i];
7413 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7414 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7415 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7416 new->cloneId = old->cloneId;
7417 new->flags = old->flags;
7420 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7422 MapHostToNetwork(struct nvldbentry *entry)
7426 count = entry->nServers;
7427 if (count < NMAXNSERVERS)
7429 for (i = 0; i < count; i++) {
7430 entry->serverNumber[i] = htonl(entry->serverNumber[i]);