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;
1283 memset(&storeEntry, 0, sizeof(struct nvldbentry));
1286 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1290 "Unable to lock volume %lu, code %d\n",
1291 (unsigned long)entry->volumeId[RWVOL],vcode);
1292 PrintError("", vcode);
1297 /* make sure the VLDB entry hasn't changed since we started */
1298 memset(&checkEntry, 0, sizeof(checkEntry));
1299 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1302 "Could not fetch the entry for volume %lu from VLDB\n",
1303 (unsigned long)volid);
1304 PrintError("convertROtoRW ", vcode);
1309 MapHostToNetwork(&checkEntry);
1310 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1311 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1312 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1314 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1315 (unsigned long)volid);
1320 /* extract information from the original entry */
1321 for (i = 0; i < entry->nServers; i++) {
1322 if (entry->serverFlags[i] & VLSF_RWVOL) {
1324 rwserver = entry->serverNumber[i];
1325 /* rwpartition = entry->serverPartition[i]; */
1328 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1329 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1332 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1339 roserver = entry->serverNumber[i];
1340 /* ropartition = entry->serverPartition[i]; */
1347 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1348 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1351 "Converting RO volume %lu to RW volume failed with code %d\n",
1352 (unsigned long)volid, code);
1353 PrintError("convertROtoRW ", code);
1356 /* Update the VLDB to match what we did on disk as much as possible. */
1357 /* If the converted RO was in the VLDB, make it look like the new RW. */
1359 entry->serverFlags[roindex] = VLSF_RWVOL;
1361 /* Add a new site entry for the newly created RW. It's possible
1362 * (but unlikely) that we are already at MAXNSERVERS and that this
1363 * new site will invalidate the whole VLDB entry; however,
1364 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1365 * so we need no extra guard logic here.
1367 afs_int32 newrwindex = entry->nServers;
1368 (entry->nServers)++;
1369 entry->serverNumber[newrwindex] = server;
1370 entry->serverPartition[newrwindex] = partition;
1371 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1373 entry->flags |= VLF_RWEXISTS;
1374 entry->flags &= ~VLF_BACKEXISTS;
1376 /* if the old RW was in the VLDB, remove it by decrementing the number */
1377 /* of servers, replacing the RW entry with the last entry, and zeroing */
1378 /* out the last entry. */
1380 (entry->nServers)--;
1381 if (rwindex != entry->nServers) {
1382 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1383 entry->serverPartition[rwindex] =
1384 entry->serverPartition[entry->nServers];
1385 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1386 entry->serverNumber[entry->nServers] = 0;
1387 entry->serverPartition[entry->nServers] = 0;
1388 entry->serverFlags[entry->nServers] = 0;
1391 entry->flags &= ~VLF_ROEXISTS;
1392 for (i = 0; i < entry->nServers; i++) {
1393 if (entry->serverFlags[i] & VLSF_ROVOL) {
1394 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1395 entry->flags |= VLF_ROEXISTS;
1398 MapNetworkToHost(entry, &storeEntry);
1400 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1401 (LOCKREL_OPCODE | LOCKREL_AFSID |
1402 LOCKREL_TIMESTAMP));
1405 "Warning: volume converted, but vldb update failed with code %d!\n",
1409 islocked = 0; /* unlocked by the successful VLDB_ReplaceEntry above */
1413 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1416 "Unable to unlock volume %lu, code %d\n",
1417 (unsigned long)entry->volumeId[RWVOL],vcode);
1418 PrintError("", vcode);
1425 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1426 * <atopart>. The operation is almost idempotent. The following
1427 * flags are recognized:
1429 * RV_NOCLONE - don't use a copy clone
1433 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1434 afs_uint32 atoserver, afs_int32 atopart, int flags)
1436 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1437 * be changing during the move */
1438 struct rx_connection * volatile toconn;
1439 struct rx_connection * volatile fromconn;
1440 afs_int32 volatile fromtid;
1441 afs_int32 volatile totid;
1442 afs_int32 volatile clonetid;
1443 afs_uint32 volatile newVol;
1444 afs_uint32 volatile volid;
1445 afs_uint32 volatile backupId;
1446 int volatile islocked;
1451 char tmpName[VOLSER_MAXVOLNAME + 1];
1456 struct restoreCookie cookie;
1457 afs_int32 vcode, code;
1458 struct volser_status tstatus;
1459 struct destServer destination;
1461 struct nvldbentry entry, storeEntry;
1464 char in, lf; /* for test code */
1468 #ifdef ENABLE_BUGFIX_1165
1469 volEntries volumeInfo;
1470 struct volintInfo *infop = 0;
1474 fromconn = (struct rx_connection *)0;
1475 toconn = (struct rx_connection *)0;
1485 /* support control-c processing */
1488 (void)signal(SIGINT, sigint_handler);
1492 "\nThere are three tests points - verifies all code paths through recovery.\n");
1493 fprintf(STDOUT, "First test point - operation not started.\n");
1494 fprintf(STDOUT, "...test here (y, n)? ");
1496 if (fscanf(stdin, "%c", &in) < 1)
1498 if (fscanf(stdin, "%c", &lf) < 0) {
1499 /* toss away; don't care */
1502 fprintf(STDOUT, "type control-c\n");
1504 fprintf(stdout, ".");
1509 /* or drop through */
1512 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1513 EGOTO1(mfail, vcode,
1514 "Could not fetch the entry for the volume %u from the VLDB \n",
1517 if (entry.volumeId[RWVOL] != afromvol) {
1518 fprintf(STDERR, "Only RW volume can be moved\n");
1522 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1523 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1526 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1527 EGOTO1(mfail, vcode,
1528 "Could not fetch the entry for the volume %u from the VLDB \n",
1531 backupId = entry.volumeId[BACKVOL];
1532 MapHostToNetwork(&entry);
1534 if (!Lp_Match(afromserver, afrompart, &entry)) {
1535 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1536 if (!Lp_Match(atoserver, atopart, &entry)) {
1537 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1538 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1539 (unsigned long)afromvol);
1540 fprintf(STDERR, "The current site is :");
1541 for (i = 0; i < entry.nServers; i++) {
1542 if (entry.serverFlags[i] == VLSF_RWVOL) {
1544 MapPartIdIntoName(entry.serverPartition[i], pname);
1545 fprintf(STDERR, " server %s partition %s \n",
1546 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1547 hostutil_GetNameByINet(entry.serverNumber[i]),
1552 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1553 (LOCKREL_OPCODE | LOCKREL_AFSID |
1554 LOCKREL_TIMESTAMP));
1555 EGOTO1(mfail, vcode,
1556 " Could not release lock on the VLDB entry for the volume %u \n",
1559 return VOLSERVOLMOVED;
1562 /* delete the volume afromvol on src_server */
1563 /* from-info does not exist but to-info does =>
1564 * we have already done the move, but the volume
1565 * may still be existing physically on from fileserver
1567 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1570 code = DoVolDelete(fromconn, afromvol, afrompart,
1571 "leftover", 0, NULL, NULL);
1572 if (code && code != VNOVOL) {
1577 code = DoVolDelete(fromconn, backupId, afrompart,
1578 "leftover backup", 0, NULL, NULL);
1579 if (code && code != VNOVOL) {
1589 /* From-info matches the vldb info about volid,
1590 * its ok start the move operation, the backup volume
1591 * on the old site is deleted in the process
1593 if (afrompart == atopart) {
1594 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1595 EGOTO2(mfail, error,
1596 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1597 afromserver, error);
1600 EGOTO1(mfail, VOLSERVOLMOVED,
1601 "Warning: Moving volume %u to its home partition ignored!\n",
1607 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1608 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1609 totid = 0; /* initialize to uncreated */
1612 * clone the read/write volume locally.
1615 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1616 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1618 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1622 if (!(flags & RV_NOCLONE)) {
1623 /* Get a clone id */
1624 VPRINT1("Allocating new volume id for clone of volume %u ...",
1627 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1629 EGOTO1(mfail, vcode,
1630 "Could not get an ID for the clone of volume %u from the VLDB\n",
1634 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1635 VPRINT1("Cloning source volume %u ...", afromvol);
1636 strcpy(vname, "move-clone-temp");
1638 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1640 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1645 /* lookup the name of the volume we just cloned */
1647 code = AFSVolGetName(fromconn, fromtid, &volName);
1648 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1651 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1653 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1658 "Failed to end the transaction on the source volume %u\n",
1663 * Create the destination volume
1666 if (!(flags & RV_NOCLONE)) {
1667 /* All of this is to get the fromDate */
1668 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1671 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1675 "Failed to start a transaction on the cloned volume%u\n",
1679 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1681 AFSVolSetFlags(fromconn, clonetid,
1682 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1683 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1687 /* remember time from which we've dumped the volume */
1688 VPRINT1("Getting status of cloned volume %u ...", newVol);
1689 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1691 "Failed to get the status of the cloned volume %u\n",
1695 fromDate = CLOCKADJ(tstatus.creationDate);
1697 /* With RV_NOCLONE, just do a full copy from the source */
1702 #ifdef ENABLE_BUGFIX_1165
1704 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1705 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1706 * don't use this information...
1708 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1709 volumeInfo.volEntries_len = 0;
1710 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1712 "Failed to get the volint Info of the cloned volume %u\n",
1715 infop = (volintInfo *) volumeInfo.volEntries_val;
1716 infop->maxquota = -1; /* Else it will replace the default quota */
1717 infop->creationDate = -1; /* Else it will use the source creation date */
1718 infop->updateDate = -1; /* Else it will use the source update date */
1721 /* create a volume on the target machine */
1723 code = DoVolDelete(toconn, volid, atopart,
1724 "pre-existing destination", 0, NULL, NULL);
1725 if (code && code != VNOVOL) {
1730 VPRINT1("Creating the destination volume %u ...", volid);
1734 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1738 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1742 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1746 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1748 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1750 "Failed to set the flags on the destination volume %u\n", volid);
1754 * Now dump the clone to the new volume
1757 destination.destHost = ntohl(atoserver);
1758 destination.destPort = AFSCONF_VOLUMEPORT;
1759 destination.destSSID = 1;
1761 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1762 cookie.type = RWVOL;
1763 cookie.parent = entry.volumeId[RWVOL];
1766 if (!(flags & RV_NOCLONE)) {
1767 /* Copy the clone to the new volume */
1768 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1771 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1773 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1776 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1777 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1782 "Failed to end the transaction on the cloned volume %u\n",
1788 * reattach to the main-line volume, and incrementally dump it.
1791 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1793 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1796 "Failed to create a transaction on the source volume %u\n",
1800 /* now do the incremental */
1802 ("Doing the%s dump from source to destination for volume %u ... ",
1803 (flags & RV_NOCLONE) ? "" : " incremental",
1806 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1809 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1810 (flags & RV_NOCLONE) ? "" : " incremental");
1813 /* now adjust the flags so that the new volume becomes official */
1814 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1815 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1817 "Failed to set the flags to make old source volume offline\n");
1820 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1821 code = AFSVolSetFlags(toconn, totid, 0);
1823 "Failed to set the flags to make new source volume online\n");
1826 #ifdef ENABLE_BUGFIX_1165
1827 VPRINT1("Setting volume status on destination volume %u ...", volid);
1828 code = AFSVolSetInfo(toconn, totid, infop);
1830 "Failed to set volume status on the destination volume %u\n",
1835 /* put new volume online */
1836 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1837 code = AFSVolEndTrans(toconn, totid, &rcode);
1842 "Failed to end the transaction on the volume %u on the new site\n",
1846 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1847 MapNetworkToHost(&entry, &storeEntry);
1848 storeEntry.flags &= ~VLF_BACKEXISTS;
1852 "Second test point - operation in progress but not complete.\n");
1853 fprintf(STDOUT, "...test here (y, n)? ");
1855 if (fscanf(stdin, "%c", &in) < 1)
1857 if (fscanf(stdin, "%c", &lf) < 0) {
1858 /* toss away, don't care */
1861 fprintf(STDOUT, "type control-c\n");
1863 fprintf(stdout, ".");
1868 /* or drop through */
1871 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1873 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1874 (LOCKREL_OPCODE | LOCKREL_AFSID |
1875 LOCKREL_TIMESTAMP));
1878 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1879 storeEntry.name, (unsigned long)afromvol);
1888 "Third test point - operation complete but no cleanup.\n");
1889 fprintf(STDOUT, "...test here (y, n)? ");
1891 if (fscanf(stdin, "%c", &in) < 1)
1893 if (fscanf(stdin, "%c", &lf) < 0) {
1894 /* toss away; don't care */
1897 fprintf(STDOUT, "type control-c\n");
1899 fprintf(stdout, ".");
1904 /* or drop through */
1906 if (atoserver != afromserver) {
1907 /* set forwarding pointer for moved volumes */
1908 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1909 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1911 "Failed to set the forwarding pointer for the volume %u\n",
1916 VPRINT1("Deleting old volume %u on source ...", afromvol);
1917 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1918 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1922 VPRINT1("Ending transaction on old volume %u on the source ...",
1924 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1929 "Failed to end the transaction on the old volume %u on the source\n",
1933 code = DoVolDelete(fromconn, backupId, afrompart,
1934 "source backup", 0, NULL, NULL);
1935 if (code && code != VNOVOL) {
1940 code = 0; /* no backup volume? that's okay */
1943 if (!(flags & RV_NOCLONE)) {
1944 code = DoVolDelete(fromconn, newVol, afrompart,
1945 "cloned", 0, NULL, NULL);
1946 if (code && code != VNOVOL) {
1951 code = 0; /* clone missing? that's okay */
1958 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1959 fprintf(STDOUT, "...test here (y, n)? ");
1961 if (fscanf(stdin, "%c", &in) < 1)
1963 if (fscanf(stdin, "%c", &lf) < 0) { /* toss away */
1967 fprintf(STDOUT, "type control-c\n");
1969 fprintf(stdout, ".");
1974 /* or drop through */
1977 /* normal cleanup code */
1979 if (entry.flags & VLF_ROEXISTS)
1980 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1983 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1985 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1986 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1990 " Could not release the lock on the VLDB entry for the volume %lu \n",
1991 (unsigned long)afromvol);
1999 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2001 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2002 if (code || rcode) {
2005 "Could not end transaction on the source volume %lu\n",
2006 (unsigned long)afromvol);
2008 error = (code ? code : rcode);
2014 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2015 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2016 if (code || rcode) {
2019 "Could not end transaction on the source's clone volume %lu\n",
2020 (unsigned long)newVol);
2022 error = (code ? code : rcode);
2028 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2030 code = AFSVolEndTrans(toconn, totid, &rcode);
2034 "Could not end transaction on destination volume %lu\n",
2035 (unsigned long)afromvol);
2037 error = (code ? code : rcode);
2043 #ifdef ENABLE_BUGFIX_1165
2048 rx_DestroyConnection(fromconn);
2050 rx_DestroyConnection(toconn);
2051 PrintError("", error);
2054 /* come here only when the sky falls */
2059 "vos move: operation interrupted, cleanup in progress...\n");
2060 fprintf(STDOUT, "clear transaction contexts\n");
2064 /* unlock VLDB entry */
2066 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2067 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2068 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2074 VPRINT("Recovery: Ending transaction on clone volume ...");
2075 AFSVolEndTrans(fromconn, clonetid, &rcode);
2079 VPRINT("Recovery: Ending transaction on destination volume ...");
2080 AFSVolEndTrans(toconn, totid, &rcode);
2083 if (fromtid) { /* put it on-line */
2084 VPRINT("Recovery: Setting volume flags on source volume ...");
2085 AFSVolSetFlags(fromconn, fromtid, 0);
2088 VPRINT("Recovery: Ending transaction on source volume ...");
2089 AFSVolEndTrans(fromconn, fromtid, &rcode);
2093 VPRINT("Recovery: Accessing VLDB.\n");
2094 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2096 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2100 MapHostToNetwork(&entry);
2102 /* Delete either the volume on the source location or the target location.
2103 * If the vldb entry still points to the source location, then we know the
2104 * volume move didn't finish so we remove the volume from the target
2105 * location. Otherwise, we remove the volume from the source location.
2107 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2110 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2114 if (volid && toconn) {
2115 code = DoVolDelete(toconn, volid, atopart,
2116 "destination", 0, NULL, "Recovery:");
2117 if (code == VNOVOL) {
2118 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2122 /* put source volume on-line */
2124 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2128 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2134 VPRINT1("Recovery: Setting flags on source volume %u ...",
2136 AFSVolSetFlags(fromconn, fromtid, 0);
2140 ("Recovery: Ending transaction on source volume %u ...",
2142 AFSVolEndTrans(fromconn, fromtid, &rcode);
2146 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2150 } else { /* yep, move complete */
2153 "move complete - attempt cleanup of source partition - no guarantee\n");
2157 /* delete backup volume */
2159 code = DoVolDelete(fromconn, backupId, afrompart,
2160 "backup", 0, NULL, "Recovery:");
2161 if (code == VNOVOL) {
2162 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2165 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2166 (atoserver != afromserver)?atoserver:0,
2168 if (code == VNOVOL) {
2169 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2174 /* common cleanup - delete local clone */
2176 code = DoVolDelete(fromconn, newVol, afrompart,
2177 "clone", 0, NULL, "Recovery:");
2178 if (code == VNOVOL) {
2179 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2183 /* unlock VLDB entry */
2185 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2187 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2188 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2191 done: /* routine cleanup */
2194 #ifdef ENABLE_BUGFIX_1165
2199 rx_DestroyConnection(fromconn);
2201 rx_DestroyConnection(toconn);
2204 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2212 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2213 afs_uint32 atoserver, afs_int32 atopart)
2215 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2216 atoserver, atopart, 0);
2220 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2221 * <atopart>. The new volume is named by <atovolname>. The new volume
2222 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2223 * from the VLDB. the following flags are supported:
2225 * RV_RDONLY - target volume is RO
2226 * RV_OFFLINE - leave target volume offline
2227 * RV_CPINCR - do incremental dump if target exists
2228 * RV_NOVLDB - don't create/update VLDB entry
2229 * RV_NOCLONE - don't use a copy clone
2232 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2233 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2234 afs_uint32 atovolid, int flags)
2236 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2237 * be changing during the copy */
2239 afs_int32 volatile clonetid;
2240 afs_int32 volatile totid;
2241 afs_int32 volatile fromtid;
2242 struct rx_connection * volatile fromconn;
2243 struct rx_connection * volatile toconn;
2244 afs_uint32 volatile cloneVol;
2248 afs_int32 fromDate, cloneFromDate;
2249 struct restoreCookie cookie;
2250 afs_int32 vcode, code;
2253 struct volser_status tstatus;
2254 struct destServer destination;
2255 struct nvldbentry entry, newentry, storeEntry;
2260 fromconn = (struct rx_connection *)0;
2261 toconn = (struct rx_connection *)0;
2269 /* support control-c processing */
2272 (void)signal(SIGINT, sigint_handler);
2274 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2275 EGOTO1(mfail, vcode,
2276 "Could not fetch the entry for the volume %u from the VLDB \n",
2278 MapHostToNetwork(&entry);
2281 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2282 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2283 fromtid = totid = 0; /* initialize to uncreated */
2286 * clone the read/write volume locally.
2290 if (!(flags & RV_NOCLONE)) {
2291 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2293 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2296 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2300 /* Get a clone id */
2301 VPRINT1("Allocating new volume id for clone of volume %u ...",
2305 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2307 EGOTO1(mfail, vcode,
2308 "Could not get an ID for the clone of volume %u from the VLDB\n",
2316 /* Get a new volume id */
2317 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2319 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2320 EGOTO1(mfail, vcode,
2321 "Could not get an ID for the copy of volume %u from the VLDB\n",
2326 if (!(flags & RV_NOCLONE)) {
2327 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2328 VPRINT1("Cloning source volume %u ...", afromvol);
2329 strcpy(vname, "copy-clone-temp");
2332 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2335 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2339 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2341 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2346 "Failed to end the transaction on the source volume %u\n",
2352 * Create the destination volume
2355 if (!(flags & RV_NOCLONE)) {
2356 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2359 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2363 "Failed to start a transaction on the cloned volume%u\n",
2367 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2369 AFSVolSetFlags(fromconn, clonetid,
2370 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2371 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2375 /* remember time from which we've dumped the volume */
2376 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2377 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2379 "Failed to get the status of the cloned volume %u\n",
2383 fromDate = CLOCKADJ(tstatus.creationDate);
2388 /* create a volume on the target machine */
2391 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2394 if ((flags & RV_CPINCR)) {
2395 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2396 code = AFSVolGetStatus(toconn, totid, &tstatus);
2398 "Failed to get the status of the pre-existing volume %u\n",
2402 /* Using the update date should be OK here, but add some fudge */
2403 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2404 if ((flags & RV_NOCLONE))
2405 fromDate = cloneFromDate;
2407 /* XXX We should check that the source volume's creationDate is
2408 * XXX not newer than the existing target volume, and if not,
2409 * XXX throw away the existing target and do a full dump. */
2414 /* Delete the existing volume.
2415 * While we are deleting the volume in these steps, the transaction
2416 * we started against the cloned volume (clonetid above) will be
2417 * sitting idle. It will get cleaned up after 600 seconds
2419 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2420 code = AFSVolDeleteVolume(toconn, totid);
2422 "Could not delete the pre-existing volume %u on destination\n",
2427 ("Ending transaction on pre-existing volume %u on destination ...",
2429 code = AFSVolEndTrans(toconn, totid, &rcode);
2434 "Could not end the transaction on pre-existing volume %u on destination\n",
2439 VPRINT1("Creating the destination volume %u ...", newVol);
2442 AFSVolCreateVolume(toconn, atopart, atovolname,
2443 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2444 newVol, &newVol, &tmp);
2446 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2450 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2452 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2454 "Failed to set the flags on the destination volume %u\n", newVol);
2459 destination.destHost = ntohl(atoserver);
2460 destination.destPort = AFSCONF_VOLUMEPORT;
2461 destination.destSSID = 1;
2463 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2464 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2469 * Now dump the clone to the new volume
2472 if (!(flags & RV_NOCLONE)) {
2473 /* XXX probably should have some code here that checks to see if
2474 * XXX we are copying to same server and partition - if so, just
2475 * XXX use a clone to save disk space */
2477 /* Copy the clone to the new volume */
2478 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2481 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2483 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2487 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2488 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2493 "Failed to end the transaction on the cloned volume %u\n",
2499 * reattach to the main-line volume, and incrementally dump it.
2502 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2504 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2507 "Failed to create a transaction on the source volume %u\n",
2511 /* now do the incremental */
2513 ("Doing the%s dump from source to destination for volume %u ... ",
2514 (flags & RV_NOCLONE) ? "" : " incremental",
2517 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2520 "Failed to do the%s dump from old site to new site\n",
2521 (flags & RV_NOCLONE) ? "" : " incremental");
2524 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2525 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2526 code = AFSVolSetFlags(toconn, totid, volflag);
2528 "Failed to set the flags to make destination volume online\n");
2531 /* put new volume online */
2532 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2533 code = AFSVolEndTrans(toconn, totid, &rcode);
2538 "Failed to end the transaction on the destination volume %u\n",
2542 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2543 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2548 "Failed to end the transaction on the source volume %u\n",
2554 if (!(flags & RV_NOCLONE)) {
2555 code = DoVolDelete(fromconn, cloneVol, afrompart,
2556 "cloned", 0, NULL, NULL);
2557 if (code && code != VNOVOL) {
2562 code = 0; /* clone missing? that's ok */
2565 if (!(flags & RV_NOVLDB)) {
2566 /* create the vldb entry for the copied volume */
2567 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2568 newentry.nServers = 1;
2569 newentry.serverNumber[0] = atoserver;
2570 newentry.serverPartition[0] = atopart;
2571 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2572 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2573 newentry.volumeId[RWVOL] = newVol;
2574 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2575 newentry.volumeId[BACKVOL] = 0;
2576 newentry.cloneId = 0;
2577 /*map into right byte order, before passing to xdr, the stuff has to be in host
2578 * byte order. Xdr converts it into network order */
2579 MapNetworkToHost(&newentry, &storeEntry);
2580 /* create the vldb entry */
2581 vcode = VLDB_CreateEntry(&storeEntry);
2584 "Could not create a VLDB entry for the volume %s %lu\n",
2585 atovolname, (unsigned long)newVol);
2586 /*destroy the created volume */
2587 VPRINT1("Deleting the newly created volume %u\n", newVol);
2588 AFSVolDeleteVolume(toconn, totid);
2592 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2596 /* normal cleanup code */
2599 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2601 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2602 if (code || rcode) {
2605 "Could not end transaction on the source volume %lu\n",
2606 (unsigned long)afromvol);
2608 error = (code ? code : rcode);
2614 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2616 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2617 if (code || rcode) {
2620 "Could not end transaction on the source's clone volume %lu\n",
2621 (unsigned long)cloneVol);
2623 error = (code ? code : rcode);
2629 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2631 code = AFSVolEndTrans(toconn, totid, &rcode);
2635 "Could not end transaction on destination volume %lu\n",
2636 (unsigned long)newVol);
2638 error = (code ? code : rcode);
2643 rx_DestroyConnection(fromconn);
2645 rx_DestroyConnection(toconn);
2646 PrintError("", error);
2649 /* come here only when the sky falls */
2654 "vos copy: operation interrupted, cleanup in progress...\n");
2655 fprintf(STDOUT, "clear transaction contexts\n");
2660 VPRINT("Recovery: Ending transaction on clone volume ...");
2661 AFSVolEndTrans(fromconn, clonetid, &rcode);
2665 VPRINT("Recovery: Ending transaction on destination volume ...");
2666 AFSVolEndTrans(toconn, totid, &rcode);
2669 if (fromtid) { /* put it on-line */
2670 VPRINT("Recovery: Ending transaction on source volume ...");
2671 AFSVolEndTrans(fromconn, fromtid, &rcode);
2675 VPRINT("Recovery: Accessing VLDB.\n");
2676 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2678 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2682 MapHostToNetwork(&entry);
2684 /* common cleanup - delete local clone */
2686 DoVolDelete(fromconn, cloneVol, afrompart, "clone", 0, NULL,
2690 done: /* routine cleanup */
2692 rx_DestroyConnection(fromconn);
2694 rx_DestroyConnection(toconn);
2697 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2705 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2706 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2708 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2709 atovolname, atoserver, atopart, 0, 0);
2714 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2715 * if one already exists, update it
2719 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2721 struct rx_connection *aconn = (struct rx_connection *)0;
2722 afs_int32 ttid = 0, btid = 0;
2723 afs_uint32 backupID;
2724 afs_int32 code = 0, rcode = 0;
2725 struct nvldbentry entry, storeEntry;
2726 afs_int32 error = 0;
2727 int vldblocked = 0, vldbmod = 0;
2729 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2731 /* the calls to VLDB will succeed only if avolid is a RW volume,
2732 * since we are following the RW hash chain for searching */
2733 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2736 "Could not fetch the entry for the volume %lu from the VLDB \n",
2737 (unsigned long)avolid);
2741 MapHostToNetwork(&entry);
2743 /* These operations require the VLDB be locked since it means the VLDB
2744 * will change or the vldb is already locked.
2746 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2747 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2748 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2750 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2753 "Could not lock the VLDB entry for the volume %lu\n",
2754 (unsigned long)avolid);
2760 /* Reread the vldb entry */
2761 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2764 "Could not fetch the entry for the volume %lu from the VLDB \n",
2765 (unsigned long)avolid);
2769 MapHostToNetwork(&entry);
2772 if (!ISNAMEVALID(entry.name)) {
2773 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2775 error = VOLSERBADNAME;
2779 backupID = entry.volumeId[BACKVOL];
2780 if (backupID == INVALID_BID) {
2781 /* Get a backup volume id from the VLDB and update the vldb
2784 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2787 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2788 (unsigned long)avolid);
2792 entry.volumeId[BACKVOL] = backupID;
2796 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2797 entry.name, NULL, ".backup", NULL, NULL);
2803 /* Mark vldb as backup exists */
2804 if (!(entry.flags & VLF_BACKEXISTS)) {
2805 entry.flags |= VLF_BACKEXISTS;
2809 /* Now go back to the backup volume and bring it on line */
2810 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2813 "Failed to start a transaction on the backup volume %lu\n",
2814 (unsigned long)backupID);
2819 code = AFSVolSetFlags(aconn, btid, 0);
2821 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2822 (unsigned long)backupID);
2827 code = AFSVolEndTrans(aconn, btid, &rcode);
2829 if (code || rcode) {
2831 "Failed to end the transaction on the backup volume %lu\n",
2832 (unsigned long)backupID);
2833 error = (code ? code : rcode);
2837 /* Will update the vldb below */
2841 code = AFSVolEndTrans(aconn, ttid, &rcode);
2842 if (code || rcode) {
2843 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2844 (unsigned long)avolid);
2846 error = (code ? code : rcode);
2851 code = AFSVolEndTrans(aconn, btid, &rcode);
2852 if (code || rcode) {
2854 "Could not end transaction the backup volume %lu\n",
2855 (unsigned long)backupID);
2857 error = (code ? code : rcode);
2861 /* Now update the vldb - if modified */
2864 MapNetworkToHost(&entry, &storeEntry);
2866 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2867 (LOCKREL_OPCODE | LOCKREL_AFSID |
2868 LOCKREL_TIMESTAMP));
2871 "Could not update the VLDB entry for the volume %lu \n",
2872 (unsigned long)avolid);
2878 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2879 (LOCKREL_OPCODE | LOCKREL_AFSID |
2880 LOCKREL_TIMESTAMP));
2883 "Could not unlock the VLDB entry for the volume %lu \n",
2884 (unsigned long)avolid);
2892 rx_DestroyConnection(aconn);
2894 PrintError("", error);
2898 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2899 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2900 * The new volume is named by <aname>, or by appending ".clone" to
2901 * the existing name if <aname> is NULL. The following flags are
2904 * RV_RDONLY - target volume is RO
2905 * RV_OFFLINE - leave target volume offline
2909 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2910 afs_uint32 acloneid, char *aname, int flags)
2912 struct rx_connection *aconn = (struct rx_connection *)0;
2913 afs_int32 ttid = 0, btid = 0;
2914 afs_int32 code = 0, rcode = 0;
2915 char vname[VOLSER_MAXVOLNAME + 1];
2916 afs_int32 error = 0;
2917 volEntries volumeInfo;
2920 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2923 volumeInfo.volEntries_val = (volintInfo *) 0;
2924 volumeInfo.volEntries_len = 0;
2925 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2927 fprintf(stderr, "Could not get info for volume %lu\n",
2928 (unsigned long)avolid);
2932 strncpy(vname, volumeInfo.volEntries_val[0].name,
2933 VOLSER_OLDMAXVOLNAME - 7);
2934 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2935 strcat(vname, ".clone");
2937 if (volumeInfo.volEntries_val)
2938 free(volumeInfo.volEntries_val);
2942 /* Get a clone id */
2943 VPRINT1("Allocating new volume id for clone of volume %u ...",
2945 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2947 "Could not get an ID for the clone of volume %u from the VLDB\n",
2952 if (flags & RV_RWONLY)
2953 type = readwriteVolume;
2954 else if (flags & RV_RDONLY)
2955 type = readonlyVolume;
2957 type = backupVolume;
2959 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
2960 NULL, aname, NULL, NULL, NULL);
2966 /* Now go back to the backup volume and bring it on line */
2967 if (!(flags & RV_OFFLINE)) {
2968 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2971 "Failed to start a transaction on the clone volume %lu\n",
2972 (unsigned long)acloneid);
2977 code = AFSVolSetFlags(aconn, btid, 0);
2979 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2980 (unsigned long)acloneid);
2985 code = AFSVolEndTrans(aconn, btid, &rcode);
2987 if (code || rcode) {
2989 "Failed to end the transaction on the clone volume %lu\n",
2990 (unsigned long)acloneid);
2991 error = (code ? code : rcode);
2998 code = AFSVolEndTrans(aconn, ttid, &rcode);
2999 if (code || rcode) {
3000 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3001 (unsigned long)avolid);
3003 error = (code ? code : rcode);
3008 code = AFSVolEndTrans(aconn, btid, &rcode);
3009 if (code || rcode) {
3011 "Could not end transaction on the clone volume %lu\n",
3012 (unsigned long)acloneid);
3014 error = (code ? code : rcode);
3019 rx_DestroyConnection(aconn);
3021 PrintError("", error);
3025 #define ONERROR(ec, ep, es) do { \
3027 fprintf(STDERR, (es), (ep)); \
3032 #define ONERROR0(ec, es) do { \
3034 fprintf(STDERR, (es)); \
3039 #define ERROREXIT(ec) do { \
3044 /* Get a "transaction" on this replica. Create the volume
3045 * if necessary. Return the time from which a dump should
3046 * be made (0 if it's a new volume)
3049 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3050 struct rx_connection **connPtr, afs_int32 * transPtr,
3051 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3052 afs_int32 *origflags, afs_uint32 tmpVolId)
3055 struct volser_status tstatus;
3060 *connPtr = (struct rx_connection *)0;
3065 /* get connection to the replication site */
3066 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3068 goto fail; /* server is down */
3070 volid = vldbEntryPtr->volumeId[ROVOL];
3074 AFSVolTransCreate_retry(*connPtr, volid,
3075 vldbEntryPtr->serverPartition[index], ITOffline,
3078 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3079 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3080 * site. Don't trust any data on it, since it is possible we
3081 * have encountered some temporary volume from some other
3082 * incomplete volume operation. It is difficult to detect if
3083 * that has happened vs if this is a legit volume, so just
3084 * delete it to be safe. */
3086 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3087 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3088 serverNumber[index], hoststr) :
3089 hostutil_GetNameByINet(vldbEntryPtr->
3090 serverNumber[index]));
3092 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3094 PrintError("Failed to delete RO_DONTUSE site: ", code);
3098 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3104 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3111 /* emulate what TransCreate would have returned, so we try to
3112 * create the volume below */
3117 /* If the volume does not exist, create it */
3118 if (!volid || code) {
3119 char volname[VL_MAXNAMELEN];
3122 if (volid && (code != VNOVOL)) {
3123 PrintError("Failed to start a transaction on the RO volume.\n",
3128 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3130 if (strlcat(volname,
3131 tmpVolId?".roclone":".readonly",
3132 sizeof(volname)) >= sizeof(volname)) {
3134 PrintError("Volume name is too long\n", code);
3140 "Creating new volume %lu on replication site %s: ",
3141 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3142 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3143 serverNumber[index], hoststr) :
3144 hostutil_GetNameByINet(vldbEntryPtr->
3145 serverNumber[index]));
3150 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3152 vldbEntryPtr->volumeId[RWVOL],
3153 tmpVolId?&tmpVolId:&volid,
3156 PrintError("Failed to create the ro volume: ", code);
3159 vldbEntryPtr->volumeId[ROVOL] = volid;
3163 /* The following is a bit redundant, since create sets these flags by default */
3165 AFSVolSetFlags(*connPtr, *transPtr,
3166 VTDeleteOnSalvage | VTOutOfService);
3168 PrintError("Failed to set flags on the ro volume: ", code);
3173 /* Otherwise, the transaction did succeed, so get the creation date of the
3174 * latest RO volume on the replication site
3177 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3178 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3179 serverNumber[index], hoststr) :
3180 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3182 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3184 PrintError("Failed to get status of volume on destination: ",
3189 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3194 code = DoVolClone(*connPtr, volid,
3195 vldbEntryPtr->serverPartition[index],
3196 readonlyVolume, tmpVolId, "temporary",
3197 vldbEntryPtr->name, NULL, ".roclone", NULL,
3202 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3203 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3210 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3214 if (tcode && tcode != ENOENT)
3215 PrintError("Could not end transaction on a ro volume: ", tcode);
3222 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3223 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3224 void *cookie, manyResults * results)
3228 for (i = 0; i < tr->manyDests_len; i++) {
3229 results->manyResults_val[i] =
3230 AFSVolForward(fromconn, fromtid, fromdate,
3231 &(tr->manyDests_val[i].server),
3232 tr->manyDests_val[i].trans, cookie);
3238 * Check if a trans has timed out, and recreate it if necessary.
3240 * @param[in] aconn RX connection to the relevant server
3241 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3242 * contains the new trans ID on success
3243 * @param[in] apart Partition for the transaction
3244 * @param[in] astat The status of the original transaction
3246 * @return operation status
3247 * @retval 0 existing transaction is still valid, or we managed to recreate
3248 * the trans successfully
3249 * @retval nonzero Fatal error; bail out
3252 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3253 struct volser_status *astat)
3255 struct volser_status new_status;
3258 memset(&new_status, 0, sizeof(new_status));
3259 code = AFSVolGetStatus(aconn, *atid, &new_status);
3261 if (code == ENOENT) {
3263 VPRINT1("Old transaction on cloned volume %lu timed out, "
3264 "restarting transaction\n", (long unsigned) astat->volID);
3265 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3268 PrintError("Failed to recreate cloned RO volume transaction\n",
3273 memset(&new_status, 0, sizeof(new_status));
3274 code = AFSVolGetStatus(aconn, *atid, &new_status);
3276 PrintError("Failed to get status on recreated transaction\n",
3281 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3282 PrintError("Recreated transaction on cloned RO volume, but "
3283 "the volume has changed!\n", 0);
3287 PrintError("Unable to get status of current cloned RO transaction\n",
3292 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3294 PrintError("Internal error: current GetStatus does not match "
3295 "original GetStatus?\n", 0);
3304 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3305 struct rx_connection **toconns, struct release *times,
3308 afs_int32 s, code = 0, rcode = 0;
3309 /* End the transactions and destroy the connections */
3310 for (s = 0; s < volcount; s++) {
3311 if (replicas[s].trans) {
3312 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3314 replicas[s].trans = 0;
3318 if ((s == 0) || (code != ENOENT)) {
3319 PrintError("Could not end transaction on a ro volume: ",
3323 ("Transaction timed out on a ro volume. Will retry.\n",
3325 if (times[s].vldbEntryIndex < *vldbindex)
3326 *vldbindex = times[s].vldbEntryIndex;
3331 rx_DestroyConnection(toconns[s]);
3337 * Release a volume to read-only sites
3339 * Release volume <afromvol> on <afromserver> <afrompart> to all its RO
3340 * sites (complete release), unless the previous release was incomplete
3341 * or new sites were added without changes to the read-write volume, in
3342 * which case we bring the remaining volumes up to date with the volumes
3343 * that were previously released successfully.
3345 * Will create a clone from the RW, then dump the clone out to
3346 * the remaining replicas. If there is more than 1 RO sites,
3347 * ensure that the VLDB says at least one RO is available all
3348 * the time: Influences when we write back the VLDB entry.
3350 * @param[in] afromvol volume to be released
3351 * @param[in] afromserver server containing afromvol
3352 * @param[in] afrompart partition containing afromvol
3353 * @param[in] flags bitmap of options
3354 * REL_COMPLETE - force a complete release
3355 * REL_FULLDUMPS - force full dumps
3358 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3359 afs_int32 afrompart, int flags)
3363 afs_int32 vcode, rcode, tcode;
3364 afs_uint32 cloneVolId = 0, roVolId;
3365 struct replica *replicas = 0;
3366 struct nvldbentry entry, storeEntry;
3367 int i, volcount = 0, m, vldbindex;
3369 struct restoreCookie cookie;
3370 struct rx_connection **toconns = 0;
3371 struct release *times = 0;
3373 struct rx_connection *fromconn = (struct rx_connection *)0;
3374 afs_int32 error = 0;
3376 afs_int32 clonetid = 0, onlinetid;
3377 afs_int32 fromtid = 0;
3378 afs_uint32 fromdate = 0;
3379 afs_uint32 thisdate;
3383 manyResults results;
3384 int rwindex, roindex, roclone, roexists;
3385 afs_uint32 rwcrdate = 0, rwupdate = 0;
3386 afs_uint32 clcrdate;
3390 } remembertime[NMAXNSERVERS];
3391 int releasecount = 0;
3392 struct volser_status volstatus;
3394 afs_int32 origflags[NMAXNSERVERS];
3395 struct volser_status orig_status;
3396 int notreleased = 0;
3397 int tried_justnewsites = 0;
3398 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3399 int sites = 0; /* number of ro sites */
3400 int new_sites = 0; /* number of ro sites markes as new */
3403 CR_PARTIAL = 0x0000, /**< just new sites added or recover from a previous failed release */
3404 CR_FORCED = 0x0001, /**< complete: forced by caller */
3405 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3406 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3407 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3408 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3409 } complete_release_t;
3411 complete_release_t complete_release = CR_PARTIAL;
3413 memset(remembertime, 0, sizeof(remembertime));
3414 memset(&results, 0, sizeof(results));
3415 memset(origflags, 0, sizeof(origflags));
3417 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3418 if (vcode != VL_RERELEASE)
3419 ONERROR(vcode, afromvol,
3420 "Could not lock the VLDB entry for the volume %u.\n");
3423 /* Get the vldb entry in readable format */
3424 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3425 ONERROR(vcode, afromvol,
3426 "Could not fetch the entry for the volume %u from the VLDB.\n");
3427 MapHostToNetwork(&entry);
3430 EnumerateEntry(&entry);
3432 if (!ISNAMEVALID(entry.name))
3433 ONERROR(VOLSERBADOP, entry.name,
3434 "Volume name %s is too long, rename before releasing.\n");
3435 if (entry.volumeId[RWVOL] != afromvol)
3436 ONERROR(VOLSERBADOP, afromvol,
3437 "The volume %u being released is not a read-write volume.\n");
3438 if (entry.nServers <= 1)
3439 ONERROR(VOLSERBADOP, afromvol,
3440 "Volume %u has no replicas - release operation is meaningless!\n");
3441 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3442 ONERROR(VOLSERBADOP, entry.name,
3443 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3445 /* roclone is true if one of the RO volumes is on the same
3446 * partition as the RW volume. In this case, we make the RO volume
3447 * on the same partition a clone instead of a complete copy.
3450 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3451 roclone = ((roindex == -1) ? 0 : 1);
3452 rwindex = Lp_GetRwIndex(&entry);
3454 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3456 /* Make sure we have a RO volume id to work with */
3457 if (entry.volumeId[ROVOL] == INVALID_BID) {
3458 /* need to get a new RO volume id */
3459 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3460 ONERROR(vcode, entry.name, "Can't allocate ID for RO volume of %s\n");
3462 entry.volumeId[ROVOL] = roVolId;
3463 MapNetworkToHost(&entry, &storeEntry);
3464 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3465 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3469 * Determine if this is to be a complete release or a recovery of a
3470 * previous unfinished release. The previous release is considered to be
3471 * unfinished when the clone was successfully distributed to at least one
3472 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3475 * The caller can override the vldb flags check using the -force
3476 * or -force-reclone flag, to force this to be a complete release.
3478 for (i = 0; i < entry.nServers; i++) {
3479 if (entry.serverFlags[i] & VLSF_ROVOL) {
3481 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3483 if (entry.serverFlags[i] & VLSF_DONTUSE)
3486 origflags[i] = entry.serverFlags[i];
3489 if (flags & REL_COMPLETE) {
3490 complete_release |= CR_FORCED;
3493 if (new_sites == 0) {
3494 complete_release |= CR_LAST_OK;
3495 } else if (new_sites == sites) {
3496 complete_release |= CR_ALL_NEW;
3499 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3500 && !(complete_release & CR_FORCED)) {
3501 if (notreleased && notreleased != sites) {
3502 /* we have some new unreleased sites. try to just release to those,
3503 * if the RW has not changed. The caller can override with -force
3504 * or with -force-reclone. */
3509 /* Determine which volume id to use and see if it exists */
3510 cloneVolId = (complete_release || entry.cloneId == 0)
3511 ? entry.volumeId[ROVOL] : entry.cloneId;
3513 code = VolumeExists(afromserver, afrompart, cloneVolId);
3514 roexists = ((code == ENODEV) ? 0 : 1);
3516 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3518 ONERROR(-1, afromserver,
3519 "Cannot establish connection with server 0x%x\n");
3521 if (!complete_release) {
3523 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3525 /* Begin transaction on RW and mark it busy while we query it */
3526 code = AFSVolTransCreate_retry(
3527 fromconn, afromvol, afrompart, ITBusy, &fromtid
3529 ONERROR(code, afromvol,
3530 "Failed to start transaction on RW volume %u\n");
3532 /* Query the creation date for the RW */
3533 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3534 ONERROR(code, afromvol,
3535 "Failed to get the status of RW volume %u\n");
3536 rwcrdate = volstatus.creationDate;
3538 /* End transaction on RW */
3539 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3541 ONERROR((code ? code : rcode), afromvol,
3542 "Failed to end transaction on RW volume %u\n");
3544 /* Begin transaction on clone and mark it busy while we query it */
3545 code = AFSVolTransCreate_retry(
3546 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3548 ONERROR(code, cloneVolId,
3549 "Failed to start transaction on RW clone %u\n");
3551 /* Query the creation date for the clone */
3552 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3553 ONERROR(code, cloneVolId,
3554 "Failed to get the status of RW clone %u\n");
3555 clcrdate = volstatus.creationDate;
3557 /* End transaction on clone */
3558 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3560 ONERROR((code ? code : rcode), cloneVolId,
3561 "Failed to end transaction on RW clone %u\n");
3563 if (rwcrdate > clcrdate)
3564 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3568 if (!complete_release || (complete_release & CR_NEW_RW)) {
3569 /* in case the RW has changed, and just to be safe */
3574 if (!complete_release) {
3576 "This is a recovery of previously failed release\n");
3578 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3579 if (complete_release == CR_LAST_OK) {
3581 tried_justnewsites = 1;
3582 fprintf(STDOUT, "\nThere are new RO sites; we will try to "
3583 "only release to new sites");
3587 if (complete_release & CR_FORCED) {
3588 fprintf(STDOUT, "%sforced", sep);
3591 if (complete_release & CR_LAST_OK) {
3592 fprintf(STDOUT, "%slast ok", sep);
3595 if (complete_release & CR_ALL_NEW) {
3596 fprintf(STDOUT, "%sall sites are new", sep);
3599 if (complete_release & CR_NEW_RW) {
3600 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3603 if (complete_release & CR_RO_MISSING) {
3604 fprintf(STDOUT, "%sro clone missing", sep);
3606 fprintf(STDOUT, ")");
3608 fprintf(STDOUT, "\n");
3612 if (complete_release) {
3613 afs_int32 oldest = 0;
3614 /* If the RO clone exists, then if the clone is a temporary
3615 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3616 * (it was recently added), then also delete it. We do not
3617 * want to "reclone" a temporary RO clone.
3620 /* clean up any previous tmp clone before starting if staying up */
3622 && (!roclone || (entry.serverFlags[roindex] & VLSF_DONTUSE))) {
3623 code = DoVolDelete(fromconn,
3625 afrompart, "the", 0, NULL, NULL);
3626 if (code && (code != VNOVOL))
3632 VPRINT("Querying old RO sites for update times...");
3633 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3634 volEntries volumeInfo;
3635 struct rx_connection *conn;
3638 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL)) {
3641 if ((entry.serverFlags[vldbindex] & VLSF_DONTUSE)) {
3644 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3646 fprintf(STDERR, "Cannot establish connection to server %s\n",
3647 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3651 volumeInfo.volEntries_val = NULL;
3652 volumeInfo.volEntries_len = 0;
3653 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3654 entry.volumeId[ROVOL],
3657 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3658 (unsigned long)entry.volumeId[ROVOL],
3659 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3660 PrintError("", code);
3662 rx_DestroyConnection(conn);
3666 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3668 if (oldest == 0 || crdate < oldest) {
3672 rx_DestroyConnection(conn);
3673 free(volumeInfo.volEntries_val);
3674 volumeInfo.volEntries_val = NULL;
3675 volumeInfo.volEntries_len = 0;
3680 volEntries volumeInfo;
3681 volumeInfo.volEntries_val = NULL;
3682 volumeInfo.volEntries_len = 0;
3683 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3686 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3687 (unsigned long)afromvol,
3688 hostutil_GetNameByINet(afromserver));
3689 PrintError("", code);
3692 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3694 free(volumeInfo.volEntries_val);
3695 volumeInfo.volEntries_val = NULL;
3696 volumeInfo.volEntries_len = 0;
3699 if (justnewsites && oldest <= rwupdate) {
3700 /* RW has changed */
3704 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3705 * write this entry out to the vlserver until after the first
3706 * RO volume is released (temp RO clones don't count).
3708 * If 'justnewsites' is set, we're only updating sites that have
3709 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3711 for (i = 0; i < entry.nServers; i++) {
3713 if ((entry.serverFlags[i] & VLSF_DONTUSE)) {
3714 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3716 entry.serverFlags[i] |= VLSF_NEWREPSITE;
3719 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3720 entry.serverFlags[i] |= VLSF_DONTUSE;
3723 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3724 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3727 if (justnewsites && roexists) {
3728 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3729 * anything with the RO clone, so skip the reclone */
3732 } else if (complete_release) {
3735 strcpy(vname, entry.name);
3736 strcat(vname, ".readonly");
3738 strcpy(vname, "readonly-clone-temp");
3741 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3742 cloneVolId, roclone?"permanent RO":
3743 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3749 if (justnewsites && rwupdate != volstatus.updateDate) {
3751 /* reset the serverFlags as if 'justnewsites' had never been set */
3752 for (i = 0; i < entry.nServers; i++) {
3753 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3754 entry.serverFlags[i] |= VLSF_DONTUSE;
3756 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3757 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3760 rwcrdate = volstatus.creationDate;
3762 /* Remember clone volume ID in case we fail or are interrupted */
3763 entry.cloneId = cloneVolId;
3766 /* Bring the RO clone online - though not if it's a temporary clone */
3767 VPRINT1("Starting transaction on RO clone volume %u...",
3770 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3772 ONERROR(code, cloneVolId,
3773 "Failed to start transaction on volume %u\n");
3776 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3777 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3780 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3781 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3782 ONERROR((code ? code : rcode), cloneVolId,
3783 "Failed to end transaction on RO clone %u\n");
3786 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3788 /* Sleep so that a client searching for an online volume won't
3789 * find the clone offline and then the next RO offline while the
3790 * release brings the clone online and the next RO offline (race).
3791 * There is a fix in the 3.4 client that does not need this sleep
3792 * anymore, but we don't know what clients we have.
3794 if (entry.nServers > 2 && !justnewsites)
3797 /* Mark the RO clone in the VLDB as a good site (already released) */
3798 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
3799 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
3800 entry.flags |= VLF_ROEXISTS;
3804 /* Write out the VLDB entry only if the clone is not a temporary
3805 * clone. If we did this to a temporary clone then we would end
3806 * up marking all the ROs as "old release" making the ROs
3807 * temporarily unavailable.
3809 MapNetworkToHost(&entry, &storeEntry);
3810 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3811 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3812 ONERROR(vcode, entry.name,
3813 "Could not update vldb entry for %s.\n");
3819 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3820 /* act like this is a completion of a previous release */
3821 complete_release = CR_PARTIAL;
3822 } else if (tried_justnewsites) {
3823 VPRINT("RW vol has changed; releasing to all sites\n");
3826 /* Now we will release from the clone to the remaining RO replicas.
3827 * The first 2 ROs (counting the non-temporary RO clone) are released
3828 * individually: releasecount. This is to reduce the race condition
3829 * of clients trying to find an on-line RO volume. The remaining ROs
3830 * are released in parallel but no more than half the number of ROs
3831 * (rounded up) at a time: nservers.
3834 strcpy(vname, entry.name);
3835 strcat(vname, ".readonly");
3836 memset(&cookie, 0, sizeof(cookie));
3837 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3838 cookie.type = ROVOL;
3839 cookie.parent = entry.volumeId[RWVOL];
3842 /* how many to do at once, excluding clone */
3844 nservers = entry.nServers; /* can do all, none offline */
3846 nservers = entry.nServers / 2;
3847 replicas = calloc(nservers + 1, sizeof(struct replica));
3848 times = calloc(nservers + 1, sizeof(struct release));
3849 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3850 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3851 if (!replicas || !times || !results.manyResults_val || !toconns)
3853 "Failed to create transaction on the release clone\n");
3855 /* Create a transaction on the cloned volume */
3856 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3858 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3860 memset(&orig_status, 0, sizeof(orig_status));
3861 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3863 if (!complete_release && code)
3864 ONERROR(VOLSERNOVOL, afromvol,
3865 "Old clone is inaccessible. Try vos release -f %u.\n");
3866 ONERROR0(code, "Failed to create transaction on the release clone\n");
3869 /* For each index in the VLDB */
3870 for (vldbindex = 0; vldbindex < entry.nServers;) {
3871 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3873 ((volcount < nservers) && (vldbindex < entry.nServers));
3875 if (!justnewsites) {
3876 /* The first two RO volumes will be released individually.
3877 * The rest are then released in parallel. This is a hack
3878 * for clients not recognizing right away when a RO volume
3879 * comes back on-line.
3881 if ((volcount == 1) && (releasecount < 2))
3885 if (vldbindex == roindex)
3886 continue; /* the clone */
3887 if ((entry.serverFlags[vldbindex] & VLSF_NEWREPSITE)
3888 && !(entry.serverFlags[vldbindex] & VLSF_DONTUSE))
3890 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL))
3891 continue; /* not a RO vol */
3894 /* Get a Transaction on this replica. Get a new connection if
3895 * necessary. Create the volume if necessary. Return the
3896 * time from which the dump should be made (0 if it's a new
3897 * volume). Each volume might have a different time.
3899 replicas[volcount].server.destHost =
3900 ntohl(entry.serverNumber[vldbindex]);
3901 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3902 replicas[volcount].server.destSSID = 1;
3903 times[volcount].vldbEntryIndex = vldbindex;
3906 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3907 &(replicas[volcount].trans),
3908 &(times[volcount].crtime),
3909 &(times[volcount].uptime),
3914 /* Thisdate is the date from which we want to pick up all changes */
3915 if (flags & REL_FULLDUMPS) {
3916 /* Do a full dump when forced by the caller. */
3917 VPRINT("This will be a full dump: forced\n");
3919 } else if (complete_release == CR_PARTIAL) {
3921 VPRINT("This will be a full dump: read-only volume needs be created for new site\n");
3924 * We cannot be sure the creation date is good since the previous
3925 * release failed, so do a full dump.
3927 VPRINT("This will be a full dump: previous release failed\n");
3930 } else if (times[volcount].crtime == 0) {
3931 /* A full dump is needed for a new read-only volume. */
3933 ("This will be a full dump: read-only volume needs to be created\n");
3935 } else if ((rwcrdate > times[volcount].crtime)) {
3936 /* If the RW volume was replaced (its creation date is newer than
3937 * the last release), then we can't be sure what has changed (so
3938 * we do a full dump).
3941 ("This will be a full dump: read-write volume was replaced\n");
3943 } else if (remembertime[vldbindex].validtime) {
3944 /* Trans was prev ended. Use the time from the prev trans
3945 * because, prev trans may have created the volume. In which
3946 * case time[volcount].time would be now instead of 0.
3949 (remembertime[vldbindex].uptime < times[volcount].uptime)
3950 ? remembertime[vldbindex].uptime
3951 : times[volcount].uptime;
3953 thisdate = times[volcount].uptime;
3955 remembertime[vldbindex].validtime = 1;
3956 remembertime[vldbindex].uptime = thisdate;
3958 if (volcount == 0) {
3959 fromdate = thisdate;
3961 /* Include this volume if it is within 15 minutes of the earliest */
3963 thisdate) ? (fromdate - thisdate) : (thisdate -
3965 AFSVolEndTrans(toconns[volcount],
3966 replicas[volcount].trans, &rcode);
3967 replicas[volcount].trans = 0;
3970 if (thisdate < fromdate)
3971 fromdate = thisdate;
3978 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
3985 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3986 (unsigned long)cloneVolId,
3987 entry.volumeId[ROVOL],
3988 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3989 vldbEntryIndex], hoststr) :
3990 hostutil_GetNameByINet(entry.
3991 serverNumber[times[0].
3994 for (s = 1; s < volcount; s++) {
3995 fprintf(STDOUT, " and %s",
3996 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3997 vldbEntryIndex], hoststr) :
3998 hostutil_GetNameByINet(entry.
3999 serverNumber[times[s].
4004 fprintf(STDOUT, " (entire volume)");
4007 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4009 fprintf(STDOUT, ".\n");
4013 /* Release the ones we have collected */
4014 tr.manyDests_val = &(replicas[0]);
4015 tr.manyDests_len = results.manyResults_len = volcount;
4017 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4018 0 /*spare */ , &cookie, &results);
4019 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4021 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4022 0 /*spare */ , &cookie, &results);
4027 PrintError("Release failed: ", code);
4029 for (m = 0; m < volcount; m++) {
4030 if (results.manyResults_val[m]) {
4031 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4032 /* we retry timed out transaction. When it is
4033 * not the first volume and the transaction wasn't found
4034 * (assume it timed out and was garbage collected by volser).
4037 ("Failed to dump volume from clone to a ro site: ",
4038 results.manyResults_val[m]);
4044 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4045 ROVOL, entry.volumeId[RWVOL], 0, 0);
4047 if ((m == 0) || (code != ENOENT)) {
4048 PrintError("Failed to set correct names and ids: ",
4054 /* have to clear dest. flags to ensure new vol goes online:
4055 * because the restore (forwarded) operation copied
4056 * the V_inService(=0) flag over to the destination.
4058 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4060 if ((m == 0) || (code != ENOENT)) {
4061 PrintError("Failed to set flags on ro volume: ",
4067 entry.serverFlags[times[m].vldbEntryIndex] |= VLSF_NEWREPSITE;
4068 entry.serverFlags[times[m].vldbEntryIndex] &= ~VLSF_DONTUSE;
4069 entry.flags |= VLF_ROEXISTS;
4074 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4075 MapNetworkToHost(&entry, &storeEntry);
4076 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4077 ONERROR(vcode, afromvol,
4078 " Could not update VLDB entry for volume %u\n");
4079 } /* for each index in the vldb */
4081 /* End the transaction on the cloned volume */
4082 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4087 PrintError("Failed to end transaction on rw volume: ", code);
4089 /* Figure out if any volume were not released and say so */
4090 for (failure = 0, i = 0; i < entry.nServers; i++) {
4091 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE))
4097 "The volume %lu could not be released to the following %d sites:\n",
4098 (unsigned long)afromvol, failure);
4099 for (i = 0; i < entry.nServers; i++) {
4100 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE)) {
4101 MapPartIdIntoName(entry.serverPartition[i], pname);
4102 fprintf(STDERR, "\t%35s %s\n",
4103 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4104 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4107 MapNetworkToHost(&entry, &storeEntry);
4109 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4111 ONERROR(vcode, afromvol,
4112 " Could not update VLDB entry for volume %u\n");
4114 ERROREXIT(VOLSERBADRELEASE);
4118 /* All the ROs were release successfully. Remove the temporary clone */
4121 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4122 (unsigned long)cloneVolId);
4125 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4127 if (code && code != VNOVOL)
4128 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4132 for (i = 0; i < entry.nServers; i++)
4133 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
4135 /* Update the VLDB */
4136 VPRINT("updating VLDB ...");
4138 MapNetworkToHost(&entry, &storeEntry);
4140 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4141 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4142 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4143 islocked = 0; /* lock released by successful VLDB_ReplaceEntry above */
4148 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4152 "Failed to end cloning transaction on the RW volume %lu\n",
4153 (unsigned long)afromvol);
4159 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4163 "Failed to end transaction on the release clone %lu\n",
4164 (unsigned long)cloneVolId);
4169 for (i = 0; i < nservers; i++) {
4170 if (replicas && replicas[i].trans) {
4171 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4172 replicas[i].trans = 0;
4175 "Failed to end transaction on ro volume %u at server %s\n",
4176 entry.volumeId[ROVOL],
4177 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4178 destHost), hoststr) :
4179 hostutil_GetNameByINet(htonl
4180 (replicas[i].server.destHost)));
4185 if (toconns && toconns[i]) {
4186 rx_DestroyConnection(toconns[i]);
4192 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4193 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4196 "Could not release lock on the VLDB entry for volume %lu\n",
4197 (unsigned long)afromvol);
4203 PrintError("", error);
4206 rx_DestroyConnection(fromconn);
4207 if (results.manyResults_val)
4208 free(results.manyResults_val);
4220 dump_sig_handler(int x)
4222 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4226 /* Dump the volume <afromvol> on <afromserver> and
4227 * <afrompart> to <afilename> starting from <fromdate>.
4228 * DumpFunction does the real work behind the scenes after
4229 * extracting parameters from the rock
4232 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4234 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4237 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4238 * be changing during the dump */
4239 struct rx_call * volatile fromcall = NULL;
4240 struct rx_connection * volatile fromconn = NULL;
4241 afs_int32 volatile fromtid = 0;
4243 afs_int32 rcode = 0;
4244 afs_int32 code, error = 0;
4246 time_t tmv = fromdate;
4250 #ifndef AFS_NT40_ENV
4251 (void)signal(SIGPIPE, dump_sig_handler);
4253 (void)signal(SIGINT, dump_sig_handler);
4256 VEPRINT("Full Dump ...\n");
4258 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4262 /* get connections to the servers */
4263 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4265 VEPRINT1("Starting transaction on volume %u...", afromvol);
4267 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4269 EGOTO1(error_exit, code,
4270 "Could not start transaction on the volume %u to be dumped\n",
4274 fromcall = rx_NewCall(fromconn);
4276 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4277 if (flags & VOLDUMPV2_OMITDIRS)
4278 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4280 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4281 EGOTO(error_exit, code, "Could not start the dump process \n");
4284 VEPRINT1("Dumping volume %u...", afromvol);
4285 code = DumpFunction(fromcall, rock);
4286 if (code == RXGEN_OPCODE)
4288 EGOTO(error_exit, code, "Error while dumping volume \n");
4293 code = rx_EndCall(fromcall, 0);
4294 if (code && code != RXGEN_OPCODE)
4295 fprintf(STDERR, "Error in rx_EndCall\n");
4300 VEPRINT1("Ending transaction on volume %u...", afromvol);
4301 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4302 if (code || rcode) {
4303 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4304 (unsigned long)afromvol);
4306 error = (code ? code : rcode);
4311 rx_DestroyConnection(fromconn);
4313 if (error != RXGEN_OPCODE)
4314 PrintError("", error);
4318 /* Clone the volume <afromvol> on <afromserver> and
4319 * <afrompart>, and then dump the clone volume to
4320 * <afilename> starting from <fromdate>.
4321 * DumpFunction does the real work behind the scenes after
4322 * extracting parameters from the rock
4325 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4326 afs_int32 afrompart, afs_int32 fromdate,
4327 afs_int32(*DumpFunction) (struct rx_call *, void *),
4328 void *rock, afs_int32 flags)
4330 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4331 * be changing during the dump */
4332 struct rx_connection * volatile fromconn = NULL;
4333 struct rx_call * volatile fromcall = NULL;
4334 afs_int32 volatile clonetid = 0;
4335 afs_uint32 volatile clonevol = 0;
4338 afs_int32 fromtid = 0, rcode = 0;
4339 afs_int32 code = 0, error = 0;
4341 time_t tmv = fromdate;
4342 char *volName = NULL;
4346 #ifndef AFS_NT40_ENV
4347 (void)signal(SIGPIPE, dump_sig_handler);
4349 (void)signal(SIGINT, dump_sig_handler);
4352 VEPRINT("Full Dump ...\n");
4354 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4358 /* get connections to the servers */
4359 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4361 VEPRINT1("Starting transaction on volume %u...", afromvol);
4362 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4363 EGOTO1(error_exit, code,
4364 "Could not start transaction on the volume %u to be dumped\n",
4368 VEPRINT1("Getting the name for volume %u ...", afromvol);
4369 code = AFSVolGetName(fromconn, fromtid, &volName);
4370 EGOTO1(error_exit, code,
4371 "Failed to get the name of the volume %u\n",afromvol);
4374 /* Get a clone id */
4375 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4377 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4379 EGOTO1(error_exit, code,
4380 "Could not get an ID for the clone of volume %u from the VLDB\n",
4384 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4385 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4389 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, volName, &tmpVol);
4391 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4395 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4397 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4401 EGOTO1(error_exit, code,
4402 "Failed to end the transaction on the volume %u\n", afromvol);
4406 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4409 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4412 EGOTO1(error_exit, code,
4413 "Failed to start a transaction on the cloned volume%u\n",
4417 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4418 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4419 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4424 fromcall = rx_NewCall(fromconn);
4426 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4427 if (flags & VOLDUMPV2_OMITDIRS)
4428 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4430 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4431 EGOTO(error_exit, code, "Could not start the dump process \n");
4434 VEPRINT1("Dumping volume %u...", afromvol);
4435 code = DumpFunction(fromcall, rock);
4436 EGOTO(error_exit, code, "Error while dumping volume \n");
4443 /* now delete the clone */
4444 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4445 code = AFSVolDeleteVolume(fromconn, clonetid);
4447 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4448 (unsigned long)clonevol);
4454 code = rx_EndCall(fromcall, 0);
4456 fprintf(STDERR, "Error in rx_EndCall\n");
4462 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4463 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4464 if (code || rcode) {
4466 "Could not end transaction on the cloned volume %lu\n",
4467 (unsigned long)clonevol);
4469 error = (code ? code : rcode);
4474 rx_DestroyConnection(fromconn);
4476 PrintError("", error);
4483 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4484 * the dump file <afilename>. WriteData does all the real work
4485 * after extracting params from the rock
4488 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4489 afs_uint32 toparentid, char tovolname[], int flags,
4490 afs_int32(*WriteData) (struct rx_call *, void *),
4493 struct rx_connection *toconn, *tempconn;
4494 struct rx_call *tocall;
4495 afs_int32 totid, code, rcode, vcode, terror = 0;
4496 struct volser_status tstatus;
4497 struct volintInfo vinfo;
4499 char tovolreal[VOLSER_OLDMAXVOLNAME];
4501 afs_int32 temptid, pparentid;
4502 struct nvldbentry entry, storeEntry;
4505 struct restoreCookie cookie;
4507 afs_int32 volflag, voltype, volsertype;
4508 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4509 VolumeId oldCloneId = 0;
4510 VolumeId oldBackupId = 0;
4511 int index, same, errcode;
4515 memset(&cookie, 0, sizeof(cookie));
4519 tocall = (struct rx_call *)0;
4520 tempconn = (struct rx_connection *)0;
4524 if (flags & RV_RDONLY) {
4526 volsertype = volser_RO;
4529 volsertype = volser_RW;
4533 pparentid = toparentid;
4534 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4535 if (pvolid == 0) { /*alot a new id if needed */
4536 vcode = VLDB_GetEntryByName(tovolname, &entry);
4537 if (vcode == VL_NOENT) {
4538 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4540 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4547 fprintf(STDERR, "Could not fetch the VLDB entry for the volume %s\n",
4551 } else if (flags & RV_RDONLY) {
4552 /* -readonly restore is prohibited if an RW already exists */
4553 if (entry.flags & VLF_RWEXISTS) {
4555 "Entry for ReadWrite volume %s already exists!\n",
4557 error = VOLSERBADOP;
4560 if (!entry.volumeId[ROVOL]) {
4562 "Existing entry for volume %s has no ReadOnly ID\n",
4564 error = VOLSERBADOP;
4567 pvolid = entry.volumeId[ROVOL];
4568 pparentid = entry.volumeId[RWVOL];
4570 pvolid = entry.volumeId[RWVOL];
4571 pparentid = entry.volumeId[RWVOL];
4574 if (!pparentid) pparentid = pvolid;
4575 /* at this point we have a volume id to use/reuse for the volume to be restored */
4576 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4578 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4579 EGOTO1(refail, VOLSERBADOP,
4580 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4583 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4584 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4585 EGOTO1(refail, VOLSERBADOP,
4586 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4588 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4591 MapPartIdIntoName(topart, partName);
4592 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4593 tovolreal, (unsigned long)pvolid,
4594 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4595 hostutil_GetNameByINet(toserver), partName);
4599 * Obtain a transaction and get the status of the target volume. Create a new
4600 * volume if the target volume does not already exist.
4602 memset(&tstatus, 0, sizeof(tstatus));
4603 if ((flags & RV_FULLRST) != 0) {
4604 /* Full restore: Delete existing volume then create anew. */
4605 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0, &tstatus, NULL);
4606 if (code && code != VNOVOL) {
4610 code = AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4612 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4614 /* Incremental restore: Obtain a transaction on the existing volume. */
4615 code = AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4617 code = AFSVolGetStatus(toconn, totid, &tstatus);
4618 EGOTO1(refail, code, "Could not get timestamp from volume %u\n", pvolid);
4619 } else if (code == VNOVOL) {
4620 code = AFSVolCreateVolume(toconn, topart, tovolreal, volsertype,
4621 pparentid, &pvolid, &totid);
4622 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4624 EGOTO1(refail, code, "Failed to start transaction on %u\n", pvolid);
4627 oldCreateDate = tstatus.creationDate;
4628 oldUpdateDate = tstatus.updateDate;
4629 oldCloneId = tstatus.cloneID;
4630 oldBackupId = tstatus.backupID;
4632 cookie.parent = pparentid;
4633 cookie.type = voltype;
4635 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4637 tocall = rx_NewCall(toconn);
4638 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4640 fprintf(STDERR, "Volume restore Failed \n");
4644 code = WriteData(tocall, rock);
4646 fprintf(STDERR, "Could not transmit data\n");
4650 terror = rx_EndCall(tocall, 0);
4651 tocall = (struct rx_call *)0;
4653 fprintf(STDERR, "rx_EndCall Failed \n");
4657 code = AFSVolGetStatus(toconn, totid, &tstatus);
4660 "Could not get status information about the volume %lu\n",
4661 (unsigned long)pvolid);
4665 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid,
4666 oldCloneId, oldBackupId);
4668 fprintf(STDERR, "Could not set the right type and IDs on %lu\n",
4669 (unsigned long)pvolid);
4674 if (flags & RV_CRDUMP)
4675 newCreateDate = tstatus.creationDate;
4676 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4677 newCreateDate = oldCreateDate;
4679 newCreateDate = time(0);
4680 if (flags & RV_LUDUMP)
4681 newUpdateDate = tstatus.updateDate;
4682 else if (flags & RV_LUKEEP)
4683 newUpdateDate = oldUpdateDate;
4685 newUpdateDate = time(0);
4686 code = AFSVolSetDate(toconn,totid, newCreateDate);
4688 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4693 init_volintInfo(&vinfo);
4694 vinfo.creationDate = newCreateDate;
4695 vinfo.updateDate = newUpdateDate;
4696 code = AFSVolSetInfo(toconn, totid, &vinfo);
4698 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4704 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4705 code = AFSVolSetFlags(toconn, totid, volflag);
4707 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4712 /* It isn't handled right in refail */
4713 code = AFSVolEndTrans(toconn, totid, &rcode);
4718 fprintf(STDERR, "Could not end transaction on %lu\n",
4719 (unsigned long)pvolid);
4724 fprintf(STDOUT, " done\n");
4726 if (!reuseID || (flags & RV_FULLRST)) {
4727 /* Volume was restored on the file server, update the
4728 * VLDB to reflect the change.
4730 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4731 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4733 "Could not fetch the entry for volume number %lu from VLDB \n",
4734 (unsigned long)pvolid);
4739 MapHostToNetwork(&entry);
4740 if (vcode == VL_NOENT) { /* it doesnot exist already */
4741 /*make the vldb return this indication specifically */
4742 VPRINT("------- Creating a new VLDB entry ------- \n");
4743 strcpy(entry.name, tovolname);
4745 entry.serverNumber[0] = toserver; /*should be indirect */
4746 entry.serverPartition[0] = topart;
4747 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4748 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4749 if (flags & RV_RDONLY)
4750 entry.volumeId[ROVOL] = pvolid;
4751 else if (tstatus.cloneID != 0) {
4752 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4754 entry.volumeId[ROVOL] = INVALID_BID;
4755 entry.volumeId[RWVOL] = pparentid;
4757 if (tstatus.backupID != 0) {
4758 entry.volumeId[BACKVOL] = tstatus.backupID;
4759 /*this should come from status info on the volume if non zero */
4761 entry.volumeId[BACKVOL] = INVALID_BID;
4762 MapNetworkToHost(&entry, &storeEntry);
4763 vcode = VLDB_CreateEntry(&storeEntry);
4766 "Could not create the VLDB entry for volume number %lu \n",
4767 (unsigned long)pvolid);
4773 EnumerateEntry(&entry);
4774 } else { /*update the existing entry */
4776 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4777 fprintf(STDOUT, "------- Old entry -------\n");
4778 EnumerateEntry(&entry);
4779 fprintf(STDOUT, "------- New entry -------\n");
4782 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4786 "Could not lock the entry for volume number %lu \n",
4787 (unsigned long)pvolid);
4792 strcpy(entry.name, tovolname);
4794 /* Update the vlentry with the new information */
4795 if (flags & RV_RDONLY)
4796 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4798 index = Lp_GetRwIndex(&entry);
4800 /* Add the new site for the volume being restored */
4801 entry.serverNumber[entry.nServers] = toserver;
4802 entry.serverPartition[entry.nServers] = topart;
4803 entry.serverFlags[entry.nServers] =
4804 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4807 /* This volume should be deleted on the old site
4808 * if its different from new site.
4811 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4815 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4817 if ((!errcode && !same)
4818 || (entry.serverPartition[index] != topart)) {
4819 if (flags & RV_NODEL) {
4821 ("Not deleting the previous volume %u on server %s, ...",
4823 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4824 hostutil_GetNameByINet(entry.serverNumber[index]));
4827 UV_Bind(entry.serverNumber[index],
4828 AFSCONF_VOLUMEPORT);
4830 MapPartIdIntoName(entry.serverPartition[index],
4833 ("Deleting the previous volume %u on server %s, partition %s ...",
4835 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4836 hostutil_GetNameByINet(entry.serverNumber[index]),
4838 code = DoVolDelete(tempconn, pvolid,
4839 entry.serverPartition[index],
4840 "the", 0, NULL, NULL);
4841 if (code && code != VNOVOL) {
4845 MapPartIdIntoName(entry.serverPartition[index],
4849 entry.serverNumber[index] = toserver;
4850 entry.serverPartition[index] = topart;
4853 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4854 MapNetworkToHost(&entry, &storeEntry);
4856 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4857 LOCKREL_OPCODE | LOCKREL_AFSID |
4861 "Could not update the entry for volume number %lu \n",
4862 (unsigned long)pvolid);
4868 EnumerateEntry(&entry);
4875 code = rx_EndCall(tocall, 0);
4881 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4882 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4885 "Could not release lock on the VLDB entry for the volume %lu\n",
4886 (unsigned long)pvolid);
4892 code = AFSVolEndTrans(toconn, totid, &rcode);
4896 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4897 (unsigned long)pvolid);
4903 code = AFSVolEndTrans(toconn, temptid, &rcode);
4907 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4908 (unsigned long)pvolid);
4914 rx_DestroyConnection(tempconn);
4916 rx_DestroyConnection(toconn);
4917 PrintError("", error);
4922 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4923 char tovolname[], int flags,
4924 afs_int32(*WriteData) (struct rx_call *, void *),
4927 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4932 /*unlocks the vldb entry associated with <volid> */
4934 UV_LockRelease(afs_uint32 volid)
4938 VPRINT("Binding to the VLDB server\n");
4940 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4941 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4944 "Could not unlock the entry for volume number %lu in VLDB \n",
4945 (unsigned long)volid);
4946 PrintError("", vcode);
4949 VPRINT("VLDB updated\n");
4954 /* old interface to add rosites */
4956 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4959 return UV_AddSite2(server, part, volid, 0, valid);
4962 /*adds <server> and <part> as a readonly replication site for <volid>
4965 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4966 afs_uint32 rovolid, afs_int32 valid)
4968 int j, nro = 0, islocked = 0;
4969 struct nvldbentry entry, storeEntry, entry2;
4970 afs_int32 vcode, error = 0;
4973 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4976 " Could not lock the VLDB entry for the volume %lu \n",
4977 (unsigned long)volid);
4982 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4985 "Could not fetch the VLDB entry for volume number %lu \n",
4986 (unsigned long)volid);
4990 if (!ISNAMEVALID(entry.name)) {
4992 "Volume name %s is too long, rename before adding site\n",
4994 error = VOLSERBADOP;
4997 MapHostToNetwork(&entry);
4999 /* See if it's too many entries */
5000 if (entry.nServers >= NMAXNSERVERS) {
5001 fprintf(STDERR, "Total number of entries will exceed %u\n",
5003 error = VOLSERBADOP;
5007 /* See if it's on the same server */
5008 for (j = 0; j < entry.nServers; j++) {
5009 if (entry.serverFlags[j] & VLSF_ROVOL) {
5011 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5014 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5017 MapPartIdIntoName(entry.serverPartition[j], apartName);
5019 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5021 error = VOLSERBADOP;
5028 /* See if it's too many RO sites - leave one for the RW */
5029 if (nro >= NMAXNSERVERS - 1) {
5030 fprintf(STDERR, "Total number of sites will exceed %u\n",
5032 error = VOLSERBADOP;
5036 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5037 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5038 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5041 if (entry.volumeId[ROVOL] == INVALID_BID) {
5042 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5044 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5047 VPRINT1("Using RO volume id %d.\n", rovolid);
5048 entry.volumeId[ROVOL] = rovolid;
5050 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5051 rovolid, entry.volumeId[ROVOL]);
5055 VPRINT("Adding a new site ...");
5056 entry.serverNumber[entry.nServers] = server;
5057 entry.serverPartition[entry.nServers] = part;
5059 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5061 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5065 MapNetworkToHost(&entry, &storeEntry);
5067 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5068 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5070 fprintf(STDERR, "Could not update entry for volume %lu \n",
5071 (unsigned long)volid);
5080 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5081 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5084 "Could not release lock on volume entry for %lu \n",
5085 (unsigned long)volid);
5086 PrintError("", vcode);
5090 PrintError("", error);
5094 /*removes <server> <part> as read only site for <volid> from the vldb */
5096 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5099 struct nvldbentry entry, storeEntry;
5101 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5103 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5104 (unsigned long)volid);
5105 PrintError("", vcode);
5108 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5111 "Could not fetch the entry for volume number %lu from VLDB \n",
5112 (unsigned long)volid);
5113 PrintError("", vcode);
5116 MapHostToNetwork(&entry);
5117 if (!Lp_ROMatch(server, part, &entry)) {
5118 /*this site doesnot exist */
5119 fprintf(STDERR, "This site is not a replication site \n");
5121 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5122 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5124 fprintf(STDERR, "Could not update entry for volume %lu \n",
5125 (unsigned long)volid);
5126 PrintError("", vcode);
5127 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5128 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5132 } else { /*remove the rep site */
5133 Lp_SetROValue(&entry, server, part, 0, 0);
5135 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5136 entry.flags &= ~VLF_ROEXISTS;
5137 if (entry.nServers < 1) { /*this is the last ref */
5138 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5140 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5143 "Could not delete VLDB entry for volume %lu \n",
5144 (unsigned long)volid);
5145 PrintError("", vcode);
5150 MapNetworkToHost(&entry, &storeEntry);
5151 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5152 (unsigned long)volid);
5155 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5156 LOCKREL_OPCODE | LOCKREL_AFSID |
5160 "Could not release lock on volume entry for %lu \n",
5161 (unsigned long)volid);
5162 PrintError("", vcode);
5163 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5164 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5167 fprintf(STDOUT, " done\n");
5173 /*sets <server> <part> as read/write site for <volid> in the vldb */
5175 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5178 struct nvldbentry entry, storeEntry;
5181 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5183 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5184 (unsigned long)volid);
5185 PrintError("", vcode);
5188 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5191 "Could not fetch the entry for volume number %lu from VLDB \n",
5192 (unsigned long)volid);
5193 PrintError("", vcode);
5196 MapHostToNetwork(&entry);
5197 index = Lp_GetRwIndex(&entry);
5199 /* no RW site exists */
5200 fprintf(STDERR, "No existing RW site for volume %lu",
5201 (unsigned long)volid);
5203 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5204 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5207 "Could not release lock on entry for volume %lu \n",
5208 (unsigned long)volid);
5209 PrintError("", vcode);
5213 } else { /* change the RW site */
5214 entry.serverNumber[index] = server;
5215 entry.serverPartition[index] = part;
5216 MapNetworkToHost(&entry, &storeEntry);
5218 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5219 LOCKREL_OPCODE | LOCKREL_AFSID |
5222 fprintf(STDERR, "Could not update entry for volume %lu \n",
5223 (unsigned long)volid);
5224 PrintError("", vcode);
5225 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5226 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5234 /*list all the partitions on <aserver> */
5236 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5239 struct rx_connection *aconn;
5240 struct pIDs partIds;
5241 struct partEntries partEnts;
5245 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5247 partEnts.partEntries_len = 0;
5248 partEnts.partEntries_val = NULL;
5249 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5250 if (code == RXGEN_OPCODE) {
5251 for (i = 0; i < 26; i++) /* try old interface */
5252 partIds.partIds[i] = -1;
5253 code = AFSVolListPartitions(aconn, &partIds);
5255 for (i = 0; i < 26; i++) {
5256 if ((partIds.partIds[i]) != -1) {
5257 ptrPartList->partId[j] = partIds.partIds[i];
5258 ptrPartList->partFlags[j] = PARTVALID;
5261 ptrPartList->partFlags[i] = 0;
5266 *cntp = partEnts.partEntries_len;
5267 if (*cntp > VOLMAXPARTS) {
5269 "Warning: number of partitions on the server too high %d (process only %d)\n",
5270 *cntp, VOLMAXPARTS);
5271 *cntp = VOLMAXPARTS;
5273 for (i = 0; i < *cntp; i++) {
5274 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5275 ptrPartList->partFlags[i] = PARTVALID;
5277 free(partEnts.partEntries_val);
5283 "Could not fetch the list of partitions from the server\n");
5284 PrintError("", code);
5286 rx_DestroyConnection(aconn);
5291 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5292 This is used by the backup system */
5294 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5295 struct volDescription *volPtr, afs_int32 arraySize)
5297 struct rx_connection *aconn;
5298 struct volDescription *curPtr;
5301 afs_int32 success = 1;
5303 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5305 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5306 if (curPtr->volFlags & CLONEVALID) {
5307 curPtr->volFlags &= ~CLONEZAPPED;
5310 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5311 "clone", 0, NULL, NULL);
5316 curPtr->volFlags |= CLONEZAPPED;
5318 fprintf(STDERR, "Could not zap volume %lu\n",
5319 (unsigned long)curPtr->volCloneId);
5321 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5322 curPtr->volCloneId);
5327 rx_DestroyConnection(aconn);
5331 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5334 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5335 struct volDescription *volPtr, afs_int32 arraySize)
5337 struct rx_connection *aconn;
5338 struct volDescription *curPtr;
5341 afs_int32 rcode = 0;
5343 int reuseCloneId = 0;
5344 afs_uint32 curCloneId = 0;
5345 char cloneName[256]; /*max vol name */
5347 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5349 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5351 else { /*get a bunch of id's from vldb */
5353 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5355 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5356 PrintError("", code);
5361 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5362 if (curPtr->volFlags & ENTRYVALID) {
5364 curPtr->volFlags |= CLONEVALID;
5365 /*make a clone of curParentId and record as curPtr->volCloneId */
5367 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5370 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5373 curPtr->volFlags &= ~CLONEVALID; /* can't clone */
5377 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5378 strcpy(cloneName, curPtr->volName);
5379 strcat(cloneName, "-tmpClone-");
5381 strcpy(cloneName, "-tmpClone");
5383 curPtr->volCloneId = curCloneId;
5388 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5389 &(curPtr->volCloneId));
5391 curPtr->volFlags &= ~CLONEVALID;
5393 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5394 curPtr->volName, (unsigned long)code);
5395 code = AFSVolEndTrans(aconn, tid, &rcode);
5397 fprintf(STDERR, "WARNING: could not end transaction\n");
5400 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5401 curPtr->volCloneId);
5402 code = AFSVolEndTrans(aconn, tid, &rcode);
5403 if (code || rcode) {
5404 curPtr->volFlags &= ~CLONEVALID;
5413 rx_DestroyConnection(aconn);
5418 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5419 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5421 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5422 struct volintInfo **resultPtr, afs_int32 * size)
5424 struct rx_connection *aconn;
5426 volEntries volumeInfo;
5429 *resultPtr = (volintInfo *) 0;
5430 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5431 volumeInfo.volEntries_len = 0;
5433 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5434 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5437 "Could not fetch the list of volumes from the server\n");
5439 *resultPtr = volumeInfo.volEntries_val;
5440 *size = volumeInfo.volEntries_len;
5444 rx_DestroyConnection(aconn);
5445 PrintError("", code);
5449 /*------------------------------------------------------------------------
5450 * EXPORTED UV_XListVolumes
5453 * List the extended information for all the volumes on a particular
5454 * File Server and partition. We may either return the volume's ID
5455 * or all of its extended information.
5458 * a_serverID : Address of the File Server for which we want
5459 * extended volume info.
5460 * a_partID : Partition for which we want the extended
5462 * a_all : If non-zero, fetch ALL the volume info,
5463 * otherwise just the volume ID.
5464 * a_resultPP : Ptr to the address of the area containing
5465 * the returned volume info.
5466 * a_numEntsInResultP : Ptr for the value we set for the number of
5471 * Otherise, the return value of AFSVolXListVolumes.
5474 * This routine is closely related to UV_ListVolumes, which returns
5475 * only the standard level of detail on AFS volumes. It is a
5476 * heavyweight operation, zipping through all the volume entries for
5477 * a given server/partition.
5481 *------------------------------------------------------------------------*/
5484 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5485 struct volintXInfo **a_resultPP,
5486 afs_int32 * a_numEntsInResultP)
5488 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5489 afs_int32 code; /*Error code to return */
5490 volXEntries volumeXInfo; /*Area for returned extended vol info */
5493 * Set up our error code and the area for returned extended volume info.
5494 * We set the val field to a null pointer as a hint for the stub to
5497 *a_numEntsInResultP = 0;
5498 *a_resultPP = (volintXInfo *) 0;
5499 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5500 volumeXInfo.volXEntries_len = 0;
5503 * Bind to the Volume Server port on the File Server machine in question,
5506 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5507 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5509 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5512 * We got the info; pull out the pointer to where the results lie
5513 * and how many entries are there.
5515 *a_resultPP = volumeXInfo.volXEntries_val;
5516 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5520 * If we got an Rx connection, throw it away.
5523 rx_DestroyConnection(rxConnP);
5525 PrintError("", code);
5527 } /*UV_XListVolumes */
5529 /* get all the information about volume <volid> on <aserver> and <apart> */
5531 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5532 struct volintInfo **resultPtr)
5534 struct rx_connection *aconn;
5536 volEntries volumeInfo;
5538 *resultPtr = (volintInfo *) 0;
5539 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5540 volumeInfo.volEntries_len = 0;
5542 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5543 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5546 "Could not fetch the information about volume %lu from the server\n",
5547 (unsigned long)volid);
5549 *resultPtr = volumeInfo.volEntries_val;
5554 rx_DestroyConnection(aconn);
5555 PrintError("", code);
5559 /*------------------------------------------------------------------------
5560 * EXPORTED UV_XListOneVolume
5563 * List the extended information for a volume on a particular File
5564 * Server and partition.
5567 * a_serverID : Address of the File Server for which we want
5568 * extended volume info.
5569 * a_partID : Partition for which we want the extended
5571 * a_volID : Volume ID for which we want the info.
5572 * a_resultPP : Ptr to the address of the area containing
5573 * the returned volume info.
5577 * Otherise, the return value of AFSVolXListOneVolume.
5580 * This routine is closely related to UV_ListOneVolume, which returns
5581 * only the standard level of detail on the chosen AFS volume.
5585 *------------------------------------------------------------------------*/
5588 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5589 struct volintXInfo **a_resultPP)
5591 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5592 afs_int32 code; /*Error code */
5593 volXEntries volumeXInfo; /*Area for returned info */
5596 * Set up our error code, and the area we're in which we are returning
5597 * the info. Setting the val field to a null pointer tells the stub
5598 * to allocate space for us.
5600 *a_resultPP = (volintXInfo *) 0;
5601 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5602 volumeXInfo.volXEntries_len = 0;
5605 * Bind to the Volume Server port on the File Server machine in question,
5608 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5609 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5612 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5615 * We got the info; pull out the pointer to where the results lie.
5617 *a_resultPP = volumeXInfo.volXEntries_val;
5620 * If we got an Rx connection, throw it away.
5623 rx_DestroyConnection(rxConnP);
5625 PrintError("", code);
5630 * Given a volume we read from a partition, check if it is
5631 * represented in the VLDB correctly.
5633 * The VLDB is looked up by the RW volume id (not its name).
5634 * The RW contains the true name of the volume (BK and RO set
5635 * the name in the VLDB only on creation of the VLDB entry).
5636 * We want rules strict enough that when we check all volumes
5637 * on one partition, it does not need to be done again. IE:
5638 * two volumes on different partitions won't constantly
5639 * change a VLDB entry away from what the other set.
5640 * For RW and BK volumes, we will always check the VLDB to see
5641 * if the two exist on the server/partition. May seem redundant,
5642 * but this is an easy check of the VLDB. IE: if the VLDB entry
5643 * says the BK exists but no BK volume is there, we will detect
5644 * this when we check the RW volume.
5645 * VLDB entries are locked only when a change needs to be done.
5646 * Output changed to look a lot like the "vos syncserv" otuput.
5649 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5650 afs_int32 * modentry, afs_uint32 * maxvolid,
5651 struct nvldbentry *aentry)
5655 afs_int32 code, error = 0;
5656 struct nvldbentry entry, storeEntry;
5658 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5668 ((volumeinfo->type ==
5669 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5672 /* Check to see if the VLDB is ok without locking it (pass 1).
5673 * If it will change, then lock the VLDB entry, read it again,
5674 * then make the changes to it (pass 2).
5677 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5679 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5680 (unsigned long)rwvolid);
5685 createentry = 0; /* Do we need to create a VLDB entry */
5686 addvolume = 0; /* Add this volume to the VLDB entry */
5687 modified = 0; /* The VLDB entry was modified */
5690 memcpy(&entry, aentry, sizeof(entry));
5692 /* Read the entry from VLDB by its RW volume id */
5693 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5695 if (code != VL_NOENT) {
5697 "Could not retrieve the VLDB entry for volume %lu \n",
5698 (unsigned long)rwvolid);
5702 memset(&entry, 0, sizeof(entry));
5703 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5707 MapHostToNetwork(&entry);
5711 if (verbose && (pass == 1)) {
5712 fprintf(STDOUT, "_______________________________\n");
5713 fprintf(STDOUT, "\n-- status before -- \n");
5715 fprintf(STDOUT, "\n**does not exist**\n");
5717 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
5718 || (entry.flags & VLF_BACKEXISTS))
5719 EnumerateEntry(&entry);
5721 fprintf(STDOUT, "\n");
5724 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5730 /* Check existence of RW and BK volumes */
5731 code = CheckVldbRWBK(&entry, &mod);
5737 idx = Lp_GetRwIndex(&entry);
5738 if (idx == -1) { /* RW index not found in the VLDB entry */
5739 idx = entry.nServers; /* put it into next index */
5742 } else { /* RW index found in the VLDB entry. */
5743 /* Verify if this volume's location matches where the VLDB says it is */
5744 if (!Lp_Match(aserver, apart, &entry)) {
5745 if (entry.flags & VLF_RWEXISTS) {
5746 /* The RW volume exists elsewhere - report this one a duplicate */
5748 MapPartIdIntoName(apart, pname);
5750 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5751 (unsigned long)rwvolid,
5753 afs_inet_ntoa_r(aserver, hoststr) :
5754 hostutil_GetNameByINet(aserver), pname);
5755 MapPartIdIntoName(entry.serverPartition[idx],
5758 " VLDB reports RW volume %lu exists on %s %s\n",
5759 (unsigned long)rwvolid,
5761 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5762 hostutil_GetNameByINet(entry.
5767 /* The RW volume does not exist - have VLDB point to this one */
5770 /* Check for orphaned BK volume on old partition */
5771 if (entry.flags & VLF_BACKEXISTS) {
5773 MapPartIdIntoName(entry.serverPartition[idx],
5776 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5777 entry.volumeId[BACKVOL],
5779 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5780 hostutil_GetNameByINet(entry.
5783 MapPartIdIntoName(apart, pname);
5785 " VLDB reports its RW volume %lu exists on %s %s\n",
5786 (unsigned long)rwvolid,
5788 afs_inet_ntoa_r(aserver, hoststr) :
5789 hostutil_GetNameByINet(aserver),
5795 /* Volume location matches the VLDB location */
5796 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5797 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5800 (entry.name, volumeinfo->name,
5801 VOLSER_OLDMAXVOLNAME) != 0)) {
5809 entry.flags |= VLF_RWEXISTS;
5810 entry.volumeId[RWVOL] = rwvolid;
5811 if (!entry.volumeId[BACKVOL])
5812 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5813 if (!entry.volumeId[ROVOL])
5814 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5816 entry.serverFlags[idx] = VLSF_RWVOL;
5817 entry.serverNumber[idx] = aserver;
5818 entry.serverPartition[idx] = apart;
5819 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5823 /* One last check - to update BK if need to */
5824 code = CheckVldbRWBK(&entry, &mod);
5832 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5838 /* Check existence of RW and BK volumes */
5839 code = CheckVldbRWBK(&entry, &mod);
5845 idx = Lp_GetRwIndex(&entry);
5846 if (idx == -1) { /* RW index not found in the VLDB entry */
5847 idx = entry.nServers; /* Put it into next index */
5850 } else { /* RW index found in the VLDB entry */
5851 /* Verify if this volume's location matches where the VLDB says it is */
5852 if (!Lp_Match(aserver, apart, &entry)) {
5853 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5855 MapPartIdIntoName(apart, pname);
5857 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5858 (unsigned long)volumeinfo->volid,
5860 afs_inet_ntoa_r(aserver, hoststr) :
5861 hostutil_GetNameByINet(aserver), pname);
5862 MapPartIdIntoName(entry.serverPartition[idx], pname);
5864 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5865 (unsigned long)rwvolid,
5867 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5868 hostutil_GetNameByINet(entry.
5873 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5874 if (!(entry.flags & VLF_BACKEXISTS)) {
5876 } else if (volumeinfo->volid >
5877 entry.volumeId[BACKVOL]) {
5881 MapPartIdIntoName(entry.serverPartition[idx],
5884 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5885 entry.volumeId[BACKVOL],
5887 afs_inet_ntoa_r(aserver, hoststr) :
5888 hostutil_GetNameByINet(aserver),
5891 " VLDB reports its BK volume ID is %lu\n",
5892 (unsigned long)volumeinfo->volid);
5896 MapPartIdIntoName(entry.serverPartition[idx],
5899 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5900 (unsigned long)volumeinfo->volid,
5902 afs_inet_ntoa_r(aserver, hoststr) :
5903 hostutil_GetNameByINet(aserver),
5906 " VLDB reports its BK volume ID is %u\n",
5907 entry.volumeId[BACKVOL]);
5910 } else if (!entry.volumeId[BACKVOL]) {
5917 entry.flags |= VLF_BACKEXISTS;
5918 entry.volumeId[RWVOL] = rwvolid;
5919 entry.volumeId[BACKVOL] = volumeinfo->volid;
5921 entry.serverNumber[idx] = aserver;
5922 entry.serverPartition[idx] = apart;
5923 entry.serverFlags[idx] = VLSF_RWVOL;
5929 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5930 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5931 /* This is a quick check to see if the RO entry exists in the
5932 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5933 * RO volume listed in the VLDB exists).
5935 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5937 idx = entry.nServers;
5941 if (!(entry.flags & VLF_ROEXISTS)) {
5946 /* Before we correct the VLDB entry, make sure all the
5947 * ROs listed in the VLDB exist.
5949 code = CheckVldbRO(&entry, &mod);
5955 if (!(entry.flags & VLF_ROEXISTS)) {
5956 /* No RO exists in the VLDB entry - add this one */
5957 idx = entry.nServers;
5960 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5961 /* The volume headers's RO ID does not match that in the VLDB entry,
5962 * and the vol hdr's ID is greater (implies more recent). So delete
5963 * all the RO volumes listed in VLDB entry and add this volume.
5965 for (j = 0; j < entry.nServers; j++) {
5966 if (entry.serverFlags[j] & VLSF_ROVOL) {
5967 /* Verify this volume exists and print message we are orphaning it */
5969 MapPartIdIntoName(apart, pname);
5971 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5972 entry.volumeId[ROVOL],
5974 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5975 hostutil_GetNameByINet(entry.
5979 " VLDB reports its RO volume ID is %lu\n",
5980 (unsigned long)volumeinfo->volid);
5983 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5984 entry.serverPartition[idx], 0L, 0L);
5991 idx = entry.nServers;
5994 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5995 /* The volume headers's RO ID does not match that in the VLDB entry,
5996 * and the vol hdr's ID is lower (implies its older). So orphan it.
5999 MapPartIdIntoName(apart, pname);
6001 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6002 (unsigned long)volumeinfo->volid,
6004 afs_inet_ntoa_r(aserver, hoststr) :
6005 hostutil_GetNameByINet(aserver), pname);
6007 " VLDB reports its RO volume ID is %u\n",
6008 entry.volumeId[ROVOL]);
6011 /* The RO volume ID in the volume header match that in the VLDB entry,
6012 * and there exist RO volumes in the VLDB entry. See if any of them
6013 * are this one. If not, then we add it.
6015 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6017 idx = entry.nServers;
6025 entry.flags |= VLF_ROEXISTS;
6026 entry.volumeId[RWVOL] = rwvolid;
6027 entry.volumeId[ROVOL] = volumeinfo->volid;
6029 entry.serverNumber[idx] = aserver;
6030 entry.serverPartition[idx] = apart;
6031 entry.serverFlags[idx] = VLSF_ROVOL;
6037 /* Remember largest volume id */
6038 if (entry.volumeId[ROVOL] > *maxvolid)
6039 *maxvolid = entry.volumeId[ROVOL];
6040 if (entry.volumeId[BACKVOL] > *maxvolid)
6041 *maxvolid = entry.volumeId[BACKVOL];
6042 if (entry.volumeId[RWVOL] > *maxvolid)
6043 *maxvolid = entry.volumeId[RWVOL];
6045 if (modified && doit) {
6046 MapNetworkToHost(&entry, &storeEntry);
6049 code = VLDB_CreateEntry(&storeEntry);
6052 "Could not create a VLDB entry for the volume %lu\n",
6053 (unsigned long)rwvolid);
6060 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6061 LOCKREL_OPCODE | LOCKREL_AFSID |
6064 fprintf(STDERR, "Could not update entry for %lu\n",
6065 (unsigned long)rwvolid);
6069 } else if (pass == 2) {
6071 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6072 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6074 PrintError("Could not unlock VLDB entry ", code);
6078 if (modified && modentry) {
6083 memcpy(aentry, &entry, sizeof(entry));
6087 fprintf(STDOUT, "-- status after --\n");
6089 EnumerateEntry(&entry);
6091 fprintf(STDOUT, "\n**no change**\n");
6095 VPRINT("\n_______________________________\n");
6100 sortVolumes(const void *a, const void *b)
6102 volintInfo *v1 = (volintInfo *) a;
6103 volintInfo *v2 = (volintInfo *) b;
6104 afs_uint32 rwvolid1, rwvolid2;
6106 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6107 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6109 if (rwvolid1 > rwvolid2)
6110 return -1; /* lower RW id goes first */
6111 if (rwvolid1 < rwvolid2)
6114 if (v1->type == RWVOL)
6115 return -1; /* RW vols go first */
6116 if (v2->type == RWVOL)
6119 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6120 return -1; /* BK vols next */
6121 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6124 if (v1->volid < v2->volid)
6125 return 1; /* larger volids first */
6126 if (v1->volid > v2->volid)
6132 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6133 * Synchronize an individual volume against a sever and partition.
6134 * Checks the VLDB entry (similar to syncserv) as well as checks
6135 * if the volume exists on specified servers (similar to syncvldb).
6138 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6140 struct rx_connection *aconn = 0;
6141 afs_int32 j, k, code, vcode, error = 0;
6143 afs_int32 mod, modified = 0, deleted = 0;
6144 struct nvldbentry vldbentry;
6145 afs_uint32 volumeid = 0;
6146 volEntries volumeInfo;
6147 struct partList PartList;
6149 afs_uint32 maxvolid = 0;
6151 volumeInfo.volEntries_val = (volintInfo *) 0;
6152 volumeInfo.volEntries_len = 0;
6154 /* Turn verbose logging off and do our own verbose logging */
6155 /* tverbose must be set before we call ERROR_EXIT() */
6162 if (!aserver && (flags & 1)) {
6163 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6167 /* Read the VLDB entry */
6168 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6169 if (vcode && (vcode != VL_NOENT)) {
6170 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6173 } else if (!vcode) {
6174 MapHostToNetwork(&vldbentry);
6178 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6179 fprintf(STDOUT, "_______________________________\n");
6180 fprintf(STDOUT, "\n-- status before -- \n");
6182 fprintf(STDOUT, "\n**does not exist**\n");
6184 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6185 || (vldbentry.flags & VLF_BACKEXISTS))
6186 EnumerateEntry(&vldbentry);
6188 fprintf(STDOUT, "\n");
6191 /* Verify that all of the VLDB entries exist on the repective servers
6192 * and partitions (this does not require that avolname be a volume ID).
6193 * Equivalent to a syncserv.
6196 /* Tell CheckVldb not to update if appropriate */
6201 code = CheckVldb(&vldbentry, &mod, &deleted);
6203 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6211 /* If aserver is given, we will search for the desired volume on it */
6213 /* Generate array of partitions on the server that we will check */
6215 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6218 "Could not fetch the list of partitions from the server\n");
6222 PartList.partId[0] = apart;
6226 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6228 /* If a volume ID were given, search for it on each partition */
6229 if ((volumeid = atol(avolname))) {
6230 for (j = 0; j < pcnt; j++) {
6232 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6235 if (code != ENODEV) {
6236 fprintf(STDERR, "Could not query server\n");
6244 /* Found one, sync it with VLDB entry */
6246 CheckVolume(volumeInfo.volEntries_val, aserver,
6247 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6254 if (volumeInfo.volEntries_val)
6255 free(volumeInfo.volEntries_val);
6256 volumeInfo.volEntries_val = (volintInfo *) 0;
6257 volumeInfo.volEntries_len = 0;
6261 /* Check to see if the RW, BK, and RO IDs exist on any
6262 * partitions. We get the volume IDs from the VLDB.
6264 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6265 if (vldbentry.volumeId[j] == 0)
6268 for (k = 0; k < pcnt; k++) { /* For each partition */
6269 volumeInfo.volEntries_val = (volintInfo *) 0;
6270 volumeInfo.volEntries_len = 0;
6272 AFSVolListOneVolume(aconn, PartList.partId[k],
6273 vldbentry.volumeId[j], &volumeInfo);
6275 if (code != ENODEV) {
6276 fprintf(STDERR, "Could not query server\n");
6284 /* Found one, sync it with VLDB entry */
6286 CheckVolume(volumeInfo.volEntries_val, aserver,
6287 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6294 if (volumeInfo.volEntries_val)
6295 free(volumeInfo.volEntries_val);
6296 volumeInfo.volEntries_val = (volintInfo *) 0;
6297 volumeInfo.volEntries_len = 0;
6303 /* If verbose output, print a summary of what changed */
6305 fprintf(STDOUT, "-- status after --\n");
6307 fprintf(STDOUT, "\n**entry deleted**\n");
6308 } else if (modified) {
6309 EnumerateEntry(&vldbentry);
6311 fprintf(STDOUT, "\n**no change**\n");
6313 fprintf(STDOUT, "\n_______________________________\n");
6317 /* Now check if the maxvolid is larger than that stored in the VLDB */
6319 afs_uint32 maxvldbid = 0;
6320 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6323 "Could not get the highest allocated volume id from the VLDB\n");
6326 } else if (maxvolid > maxvldbid) {
6328 id = maxvolid - maxvldbid + 1;
6329 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6332 "Error in increasing highest allocated volume id in VLDB\n");
6342 fprintf(STDOUT, "...error encountered");
6344 fprintf(STDOUT, "...done entry\n");
6347 rx_DestroyConnection(aconn);
6348 if (volumeInfo.volEntries_val)
6349 free(volumeInfo.volEntries_val);
6351 PrintError("", error);
6356 * Synchronise vldb with the file server <aserver> and,
6357 * optionally, <apart>.
6360 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6362 struct rx_connection *aconn;
6363 afs_int32 code, error = 0;
6366 volEntries volumeInfo;
6367 struct partList PartList;
6371 afs_int32 failures = 0, modifications = 0, tentries = 0;
6373 afs_uint32 maxvolid = 0;
6376 volumeInfo.volEntries_val = (volintInfo *) 0;
6377 volumeInfo.volEntries_len = 0;
6379 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6381 /* Generate array of partitions to check */
6383 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6386 "Could not fetch the list of partitions from the server\n");
6390 PartList.partId[0] = apart;
6394 VPRINT("Processing volume entries ...\n");
6396 /* Step through the array of partitions */
6397 for (i = 0; i < pcnt; i++) {
6398 apart = PartList.partId[i];
6399 MapPartIdIntoName(apart, pname);
6401 volumeInfo.volEntries_val = (volintInfo *) 0;
6402 volumeInfo.volEntries_len = 0;
6403 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6406 "Could not fetch the list of volumes from the server\n");
6410 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6411 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6412 sizeof(volintInfo), sortVolumes);
6415 for (vi = volumeInfo.volEntries_val, j = 0;
6416 j < volumeInfo.volEntries_len; j++, vi++) {
6424 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6425 j + 1, vi->name, (unsigned long)vi->volid,
6427 afs_inet_ntoa_r(aserver, hoststr) :
6428 hostutil_GetNameByINet(aserver), pname);
6436 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6438 PrintError("", code);
6441 } else if (modified) {
6447 fprintf(STDOUT, "...error encountered\n\n");
6449 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6456 "Could not process entries on server %s partition %s\n",
6458 afs_inet_ntoa_r(aserver, hoststr) :
6459 hostutil_GetNameByINet(aserver), pname);
6461 if (volumeInfo.volEntries_val) {
6462 free(volumeInfo.volEntries_val);
6463 volumeInfo.volEntries_val = 0;
6466 } /* thru all partitions */
6469 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6470 tentries, failures, modifications);
6472 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6473 tentries, failures, modifications);
6477 /* Now check if the maxvolid is larger than that stored in the VLDB */
6479 afs_uint32 maxvldbid = 0;
6480 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6483 "Could not get the highest allocated volume id from the VLDB\n");
6486 } else if (maxvolid > maxvldbid) {
6488 id = maxvolid - maxvldbid + 1;
6489 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6492 "Error in increasing highest allocated volume id in VLDB\n");
6500 rx_DestroyConnection(aconn);
6501 if (volumeInfo.volEntries_val)
6502 free(volumeInfo.volEntries_val);
6503 PrintError("", error);
6508 * Determine if a volume exists on a server and partition.
6509 * Try creating a transaction on the volume. If we can,
6510 * the volume exists, if not, then return the error code.
6511 * Some error codes mean the volume is unavailable but
6512 * still exists - so we catch these error codes.
6515 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6517 struct rx_connection *conn = (struct rx_connection *)0;
6518 afs_int32 code = -1;
6519 volEntries volumeInfo;
6521 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6523 volumeInfo.volEntries_val = (volintInfo *) 0;
6524 volumeInfo.volEntries_len = 0;
6525 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6526 if (volumeInfo.volEntries_val)
6527 free(volumeInfo.volEntries_val);
6528 if (code == VOLSERILLEGAL_PARTITION)
6530 rx_DestroyConnection(conn);
6539 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6543 afs_int32 code, error = 0;
6549 idx = Lp_GetRwIndex(entry);
6551 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6554 if (idx == -1) { /* Did not find a RW entry */
6555 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6556 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6561 VolumeExists(entry->serverNumber[idx],
6562 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6563 if (code == 0) { /* RW volume exists */
6564 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6565 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6568 } else if (code == ENODEV) { /* RW volume does not exist */
6569 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6570 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6574 /* If VLDB says it didn't exist, then ignore error */
6575 if (entry->flags & VLF_RWEXISTS) {
6576 MapPartIdIntoName(entry->serverPartition[idx], pname);
6578 "Transaction call failed for RW volume %u on server %s %s\n",
6579 entry->volumeId[RWVOL],
6581 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6582 hostutil_GetNameByINet(entry->serverNumber[idx]),
6589 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6590 * flag accordingly. idx already ponts to the RW entry.
6592 if (idx == -1) { /* Did not find a RW entry */
6593 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6594 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6597 } else { /* Found a RW entry */
6599 VolumeExists(entry->serverNumber[idx],
6600 entry->serverPartition[idx],
6601 entry->volumeId[BACKVOL]);
6602 if (code == 0) { /* BK volume exists */
6603 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6604 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6607 } else if (code == ENODEV) { /* BK volume does not exist */
6608 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6609 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6613 /* If VLDB says it didn't exist, then ignore error */
6614 if (entry->flags & VLF_BACKEXISTS) {
6615 MapPartIdIntoName(entry->serverPartition[idx], pname);
6617 "Transaction call failed for BK volume %u on server %s %s\n",
6618 entry->volumeId[BACKVOL],
6620 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6621 hostutil_GetNameByINet(entry->serverNumber[idx]),
6628 /* If there is an idx but the BK and RW volumes no
6629 * longer exist, then remove the RW entry.
6631 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6632 && !(entry->flags & VLF_BACKEXISTS)) {
6633 Lp_SetRWValue(entry, entry->serverNumber[idx],
6634 entry->serverPartition[idx], 0L, 0L);
6641 *modified = modentry;
6646 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6649 int foundro = 0, modentry = 0;
6650 afs_int32 code, error = 0;
6657 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6660 for (idx = 0; idx < entry->nServers; idx++) {
6661 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6662 continue; /* not a RO */
6666 VolumeExists(entry->serverNumber[idx],
6667 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6668 if (code == 0) { /* RO volume exists */
6670 } else if (code == ENODEV) { /* RW volume does not exist */
6671 Lp_SetROValue(entry, entry->serverNumber[idx],
6672 entry->serverPartition[idx], 0L, 0L);
6677 MapPartIdIntoName(entry->serverPartition[idx], pname);
6679 "Transaction call failed for RO %u on server %s %s\n",
6680 entry->volumeId[ROVOL],
6682 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6683 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6688 if (foundro) { /* A RO volume exists */
6689 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6690 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6693 } else { /* A RO volume does not exist */
6694 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6695 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
6702 *modified = modentry;
6707 * Ensure that <entry> matches with the info on file servers
6710 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6712 afs_int32 code, error = 0;
6713 struct nvldbentry storeEntry;
6714 int islocked = 0, mod, modentry, delentry = 0;
6715 int pass = 0, doit=1;
6723 fprintf(STDOUT, "_______________________________\n");
6724 fprintf(STDOUT, "\n-- status before -- \n");
6725 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
6726 || (entry->flags & VLF_BACKEXISTS))
6727 EnumerateEntry(entry);
6728 fprintf(STDOUT, "\n");
6731 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6732 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6733 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6737 /* Check to see if the VLDB is ok without locking it (pass 1).
6738 * If it will change, then lock the VLDB entry, read it again,
6739 * then make the changes to it (pass 2).
6743 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6746 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6747 entry->volumeId[RWVOL]);
6752 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6754 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6758 MapHostToNetwork(entry);
6764 /* Check if the RW and BK entries are ok */
6765 code = CheckVldbRWBK(entry, &mod);
6768 if (mod && (pass == 1) && doit)
6773 /* Check if the RO volumes entries are ok */
6774 code = CheckVldbRO(entry, &mod);
6777 if (mod && (pass == 1) && doit)
6782 /* The VLDB entry has been updated. If it as been modified, then
6783 * write the entry back out the the VLDB.
6785 if (modentry && doit) {
6789 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
6790 && !(entry->flags & VLF_ROEXISTS) && doit) {
6791 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6793 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6797 "Could not delete VLDB entry for volume %u \n",
6798 entry->volumeId[RWVOL]);
6803 /* Replace old entry with our new one */
6804 MapNetworkToHost(entry, &storeEntry);
6806 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6807 (LOCKREL_OPCODE | LOCKREL_AFSID |
6808 LOCKREL_TIMESTAMP));
6810 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6811 entry->volumeId[RWVOL]);
6818 if (modified && modentry) {
6821 if (deleted && delentry) {
6826 fprintf(STDOUT, "-- status after --\n");
6828 fprintf(STDOUT, "\n**entry deleted**\n");
6830 EnumerateEntry(entry);
6832 fprintf(STDOUT, "\n**no change**\n");
6836 VPRINT("\n_______________________________\n");
6840 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6842 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6845 "Could not release lock on VLDB entry for volume %u\n",
6846 entry->volumeId[RWVOL]);
6855 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6858 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6860 struct rx_connection *aconn;
6861 afs_int32 code, error = 0;
6862 afs_int32 nentries, tentries = 0;
6863 struct VldbListByAttributes attributes;
6864 nbulkentries arrayEntries;
6865 afs_int32 failures = 0, modified, modifications = 0;
6866 struct nvldbentry *vlentry;
6867 afs_int32 si, nsi, j;
6872 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6874 /* Set up attributes to search VLDB */
6875 memset(&attributes, 0, sizeof(attributes));
6876 attributes.server = ntohl(aserver);
6877 attributes.Mask = VLLIST_SERVER;
6879 attributes.partition = apart;
6880 attributes.Mask |= VLLIST_PARTITION;
6883 VPRINT("Processing VLDB entries ...\n");
6885 /* While we need to collect more VLDB entries */
6886 for (si = 0; si != -1; si = nsi) {
6887 memset(&arrayEntries, 0, sizeof(arrayEntries));
6889 /* Collect set of VLDB entries */
6891 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6892 &arrayEntries, &nsi);
6893 if (code == RXGEN_OPCODE) {
6894 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6898 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6901 tentries += nentries;
6903 for (j = 0; j < nentries; j++) {
6904 vlentry = &arrayEntries.nbulkentries_val[j];
6905 MapHostToNetwork(vlentry);
6907 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6909 /* Tell CheckVldb not to update if appropriate */
6914 code = CheckVldb(vlentry, &modified, NULL);
6916 PrintError("", code);
6918 "Could not process VLDB entry for volume %s\n",
6921 } else if (modified) {
6927 fprintf(STDOUT, "...error encountered\n\n");
6929 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6934 if (arrayEntries.nbulkentries_val) {
6935 free(arrayEntries.nbulkentries_val);
6936 arrayEntries.nbulkentries_val = 0;
6941 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6942 tentries, failures, modifications);
6944 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6945 tentries, failures, modifications);
6950 rx_DestroyConnection(aconn);
6951 if (arrayEntries.nbulkentries_val)
6952 free(arrayEntries.nbulkentries_val);
6955 error = VOLSERFAILEDOP;
6959 /*rename volume <oldname> to <newname>, changing the names of the related
6960 *readonly and backup volumes. This operation is also idempotent.
6961 *salvager is capable of recovering from rename operation stopping halfway.
6962 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6964 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6966 struct nvldbentry storeEntry;
6967 afs_int32 vcode, code, rcode, error;
6969 char nameBuffer[256];
6971 struct rx_connection *aconn;
6976 aconn = (struct rx_connection *)0;
6980 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6983 " Could not lock the VLDB entry for the volume %u \n",
6984 entry->volumeId[RWVOL]);
6991 * Match the flags we just set via SetLock,
6992 * so we don't invalidate our compare below.
6994 entry->flags &= ~VLOP_ALLOPERS;
6995 entry->flags |= VLOP_ADDSITE;
6998 * Now get the entry again (under lock) and
6999 * verify the volume hasn't otherwise changed.
7001 vcode = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, &storeEntry);
7004 "Could not obtain the VLDB entry for the volume %u\n",
7005 entry->volumeId[RWVOL]);
7009 /* Convert to net order to match entry, which was passed in net order. */
7010 MapHostToNetwork(&storeEntry);
7011 if (memcmp(entry, &storeEntry, sizeof(*entry)) != 0) {
7013 "VLDB entry for volume %u has changed; "
7014 "please reissue the command.\n",
7015 entry->volumeId[RWVOL]);
7016 error = VL_BADENTRY; /* an arbitrary choice, but closest to the truth */
7020 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7021 /* Note that we are reusing storeEntry. */
7022 MapNetworkToHost(entry, &storeEntry);
7023 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7025 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7026 entry->volumeId[RWVOL]);
7030 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7031 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7032 * is concerned, oldname is lost */
7033 if (entry->flags & VLF_RWEXISTS) {
7034 index = Lp_GetRwIndex(entry);
7035 if (index == -1) { /* there is a serious discrepancy */
7037 "There is a serious discrepancy in VLDB entry for volume %u\n",
7038 entry->volumeId[RWVOL]);
7039 fprintf(STDERR, "try building VLDB from scratch\n");
7040 error = VOLSERVLDB_ERROR;
7043 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7045 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7046 entry->serverPartition[index], ITOffline, &tid);
7047 if (code) { /*volume doesnot exist */
7049 "Could not start transaction on the rw volume %u\n",
7050 entry->volumeId[RWVOL]);
7053 } else { /*volume exists, process it */
7056 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7057 entry->volumeId[RWVOL],
7058 entry->volumeId[ROVOL],
7059 entry->volumeId[BACKVOL]);
7061 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7062 code = AFSVolEndTrans(aconn, tid, &rcode);
7066 "Could not end transaction on volume %s %u\n",
7067 entry->name, entry->volumeId[RWVOL]);
7072 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7073 entry->name, entry->volumeId[RWVOL]);
7079 rx_DestroyConnection(aconn);
7080 aconn = (struct rx_connection *)0;
7082 /*end rw volume processing */
7083 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7084 index = Lp_GetRwIndex(entry);
7085 if (index == -1) { /* there is a serious discrepancy */
7087 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7088 entry->volumeId[BACKVOL]);
7089 fprintf(STDERR, "try building VLDB from scratch\n");
7090 error = VOLSERVLDB_ERROR;
7093 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7095 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7096 entry->serverPartition[index], ITOffline, &tid);
7097 if (code) { /*volume doesnot exist */
7099 "Could not start transaction on the backup volume %u\n",
7100 entry->volumeId[BACKVOL]);
7103 } else { /*volume exists, process it */
7104 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7106 "Volume name %s.backup exceeds the limit of %u characters\n",
7107 newname, VOLSER_OLDMAXVOLNAME);
7111 strcpy(nameBuffer, newname);
7112 strcat(nameBuffer, ".backup");
7115 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7116 entry->volumeId[RWVOL], 0, 0);
7118 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7119 code = AFSVolEndTrans(aconn, tid, &rcode);
7123 "Could not end transaction on the backup volume %u\n",
7124 entry->volumeId[BACKVOL]);
7130 "Could not set parameters on the backup volume %u\n",
7131 entry->volumeId[BACKVOL]);
7136 } /* end backup processing */
7138 rx_DestroyConnection(aconn);
7139 aconn = (struct rx_connection *)0;
7140 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7141 for (i = 0; i < entry->nServers; i++) {
7142 if (entry->serverFlags[i] & VLSF_ROVOL) {
7143 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7145 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7146 entry->serverPartition[i], ITOffline,
7148 if (code) { /*volume doesnot exist */
7150 "Could not start transaction on the ro volume %u\n",
7151 entry->volumeId[ROVOL]);
7154 } else { /*volume exists, process it */
7155 strcpy(nameBuffer, newname);
7156 strcat(nameBuffer, ".readonly");
7157 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7159 "Volume name %s exceeds the limit of %u characters\n",
7160 nameBuffer, VOLSER_OLDMAXVOLNAME);
7165 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7166 entry->volumeId[RWVOL], 0, 0);
7168 VPRINT2("Renamed RO volume %s on host %s\n",
7171 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7172 hostutil_GetNameByINet(entry->
7174 code = AFSVolEndTrans(aconn, tid, &rcode);
7178 "Could not end transaction on volume %u\n",
7179 entry->volumeId[ROVOL]);
7185 "Could not set parameters on the ro volume %u\n",
7186 entry->volumeId[ROVOL]);
7192 rx_DestroyConnection(aconn);
7193 aconn = (struct rx_connection *)0;
7200 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7202 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7205 "Could not unlock the VLDB entry for the volume %s %u\n",
7206 entry->name, entry->volumeId[RWVOL]);
7212 code = AFSVolEndTrans(aconn, tid, &rcode);
7216 fprintf(STDERR, "Failed to end transaction on a volume \n");
7222 rx_DestroyConnection(aconn);
7223 PrintError("", error);
7228 /*report on all the active transactions on volser */
7230 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7232 struct rx_connection *aconn;
7233 transDebugEntries transInfo;
7236 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7237 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7238 transInfo.transDebugEntries_len = 0;
7239 code = AFSVolMonitor(aconn, &transInfo);
7242 "Could not access status information about the server\n");
7243 PrintError("", code);
7244 if (transInfo.transDebugEntries_val)
7245 free(transInfo.transDebugEntries_val);
7247 rx_DestroyConnection(aconn);
7250 *rcount = transInfo.transDebugEntries_len;
7251 *rpntr = transInfo.transDebugEntries_val;
7253 rx_DestroyConnection(aconn);
7260 /*delete the volume without interacting with the vldb */
7262 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7265 struct rx_connection *aconn;
7267 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7268 error = DoVolDelete(aconn, volid, part,
7269 "the", 0, NULL, NULL);
7270 if (error == VNOVOL) {
7271 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7274 PrintError("", error);
7276 rx_DestroyConnection(aconn);
7281 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7282 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7284 struct rx_connection *conn = 0;
7286 afs_int32 code, error = 0, rcode;
7288 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7290 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7294 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7296 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7300 code = AFSVolSetFlags(conn, tid, setflag);
7302 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7307 #ifdef AFS_PTHREAD_ENV
7310 IOMGR_Sleep(sleeptime);
7317 code = AFSVolEndTrans(conn, tid, &rcode);
7318 if (code || rcode) {
7319 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7321 error = (code ? code : rcode);
7326 rx_DestroyConnection(conn);
7331 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7334 struct rx_connection *conn = 0;
7336 afs_int32 code, error = 0, rcode;
7338 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7340 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7344 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7346 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7350 code = AFSVolSetInfo(conn, tid, infop);
7352 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7359 code = AFSVolEndTrans(conn, tid, &rcode);
7360 if (code || rcode) {
7361 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7363 error = (code ? code : rcode);
7368 rx_DestroyConnection(conn);
7373 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7374 afs_int32 fromdate, struct volintSize *vol_size)
7376 struct rx_connection *aconn = (struct rx_connection *)0;
7377 afs_int32 tid = 0, rcode = 0;
7378 afs_int32 code, error = 0;
7381 /* get connections to the servers */
7382 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7384 VPRINT1("Starting transaction on volume %u...", afromvol);
7385 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7386 EGOTO1(error_exit, code,
7387 "Could not start transaction on the volume %u to be measured\n",
7391 VPRINT1("Getting size of volume on volume %u...", afromvol);
7392 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7393 EGOTO(error_exit, code, "Could not start the measurement process \n");
7398 VPRINT1("Ending transaction on volume %u...", afromvol);
7399 code = AFSVolEndTrans(aconn, tid, &rcode);
7400 if (code || rcode) {
7401 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7403 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7405 error = (code ? code : rcode);
7410 rx_DestroyConnection(aconn);
7412 PrintError("", error);
7416 /*maps the host addresses in <old > (present in network byte order) to
7417 that in< new> (present in host byte order )*/
7419 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7423 memset(new, 0, sizeof(struct nvldbentry));
7425 /*copy all the fields */
7426 strcpy(new->name, old->name);
7427 /* new->volumeType = old->volumeType;*/
7428 new->nServers = old->nServers;
7429 count = old->nServers;
7430 if (count < NMAXNSERVERS)
7432 for (i = 0; i < count; i++) {
7433 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7434 new->serverPartition[i] = old->serverPartition[i];
7435 new->serverFlags[i] = old->serverFlags[i];
7437 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7438 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7439 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7440 new->cloneId = old->cloneId;
7441 new->flags = old->flags;
7444 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7446 MapHostToNetwork(struct nvldbentry *entry)
7450 count = entry->nServers;
7451 if (count < NMAXNSERVERS)
7453 for (i = 0; i < count; i++) {
7454 entry->serverNumber[i] = htonl(entry->serverNumber[i]);