2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
17 #include <sys/statfs.h>
21 #include <afs/voldefs.h>
24 #include <rx/rx_queue.h>
25 #include <afs/vlserver.h>
27 #include <afs/cellconfig.h>
30 #include <afs/afsint.h>
34 #include <afs/com_err.h>
36 #include <afs/kautils.h>
38 #include <afs/ihandle.h>
40 #include <afs/ntops.h>
42 #include <afs/vnode.h>
43 #include <afs/volume.h>
44 #define ERRCODE_RANGE 8 /* from error_table.h */
45 #define CLOCKSKEW 2 /* not really skew, but resolution */
46 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
48 /* for UV_MoveVolume() recovery */
52 #include "volser_internal.h"
53 #include "volser_prototypes.h"
54 #include "vsutils_prototypes.h"
55 #include "lockprocs_prototypes.h"
57 extern struct ubik_client *cstruct;
58 int verbose = 0, noresolve = 0;
63 afs_int32 vldbEntryIndex;
66 /* Utility macros used by rest of this source file */
67 #define EPRINT(ec, es) \
69 fprintf(STDERR, "\n"); \
70 fprintf(STDERR, (es)); \
74 #define EPRINT1(ec, es, ep1) \
76 fprintf(STDERR, "\n"); \
77 fprintf(STDERR, (es), (ep1)); \
81 #define EPRINT2(ec, es, ep1, ep2) \
83 fprintf(STDERR, "\n"); \
84 fprintf(STDERR, (es), (ep1), (ep2)); \
88 #define EPRINT3(ec, es, ep1, ep2, ep3) \
90 fprintf(STDERR, "\n"); \
91 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
95 #define EGOTO(where, ec, es) \
104 #define EGOTO1(where, ec, es, ep1) \
107 EPRINT1((ec),(es),(ep1)); \
113 #define EGOTO2(where, ec, es, ep1, ep2) \
116 EPRINT2((ec),(es),(ep1),(ep2)); \
122 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
125 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
132 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
133 #define VPRINT1(es, p) \
134 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
135 #define VPRINT2(es, p1, p2) \
136 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
137 #define VPRINT3(es, p1, p2, p3) \
138 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
140 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
141 #define VEPRINT(es) \
142 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
143 #define VEPRINT1(es, p) \
144 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
145 #define VEPRINT2(es, p1, p2) \
146 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
147 #define VEPRINT3(es, p1, p2, p3) \
148 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
150 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
154 /* getting rid of this */
155 #define ERROR_EXIT(code) do { \
161 /* Protos for static routines */
162 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
163 struct rx_connection **connPtr, afs_int32 * transPtr,
164 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
165 afs_int32 *origflags, afs_uint32 tmpVolId);
166 static int SimulateForwardMultiple(struct rx_connection *fromconn,
167 afs_int32 fromtid, afs_int32 fromdate,
168 manyDests * tr, afs_int32 flags,
169 void *cookie, manyResults * results);
170 static int DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
171 afs_int32 apart, int type, afs_uint32 cloneid,
172 char *typestring, char *pname, char *vname, char *suffix,
173 struct volser_status *volstatus, afs_int32 *transPtr);
174 static int DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
175 afs_int32 apart, char *typestring, afs_uint32 atoserver,
176 struct volser_status *volstatus, char *pprefix);
177 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
178 afs_int32 apart, afs_int32 * modentry,
179 afs_uint32 * maxvolid, struct nvldbentry *aentry);
180 static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition,
181 afs_uint32 volumeid);
182 static afs_int32 CheckVldbRWBK(struct nvldbentry * entry,
183 afs_int32 * modified);
184 static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified);
185 static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified,
187 static void dump_sig_handler(int x);
188 static int sortVolumes(const void *a, const void *b);
191 /*map the partition <partId> into partition name <partName>*/
193 MapPartIdIntoName(afs_int32 partId, char *partName)
195 if (partId < 26) { /* what if partId > = 26 ? */
196 strcpy(partName, "/vicep");
197 partName[6] = partId + 'a';
200 } else if (partId < VOLMAXPARTS) {
201 strcpy(partName, "/vicep");
203 partName[6] = 'a' + (partId / 26);
204 partName[7] = 'a' + (partId % 26);
211 PrintError(char *msg, afs_int32 errcode)
213 fprintf(STDERR, "%s", msg);
214 /*replace by a big switch statement */
219 fprintf(STDERR, "Possible communication failure\n");
222 fprintf(STDERR, "Volume needs to be salvaged\n");
225 fprintf(STDERR, "Bad vnode number quoted\n");
229 "Volume not attached, does not exist, or not on line\n");
232 fprintf(STDERR, "Volume already exists\n");
235 fprintf(STDERR, "Volume is not in service\n");
238 fprintf(STDERR, "Volume is off line\n");
241 fprintf(STDERR, "Volume is already on line\n");
244 fprintf(STDERR, "Partition is full\n");
247 fprintf(STDERR, "Volume max quota exceeded\n");
250 fprintf(STDERR, "Volume temporarily unavailable\n");
253 fprintf(STDERR, "Volume has moved to another server\n");
256 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
259 fprintf(STDERR, "VLDB: a read terminated too early\n");
262 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
265 fprintf(STDERR, "VLDB: internal creation failure\n");
268 fprintf(STDERR, "VLDB: no such entry\n");
271 fprintf(STDERR, "VLDB: vldb database is empty\n");
274 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
277 fprintf(STDERR, "VLDB: volume name is illegal\n");
280 fprintf(STDERR, "VLDB: index was out of range\n");
283 fprintf(STDERR, "VLDB: bad volume type\n");
286 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
288 case VL_BADPARTITION:
289 fprintf(STDERR, "VLDB: bad partition number\n");
292 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
295 fprintf(STDERR, "VLDB: no such repsite server exists\n");
297 case VL_DUPREPSERVER:
298 fprintf(STDERR, "VLDB: replication site server already exists\n");
301 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
304 fprintf(STDERR, "VLDB: illegal reference count number\n");
306 case VL_SIZEEXCEEDED:
307 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
310 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
312 case VL_BADVOLIDBUMP:
313 fprintf(STDERR, "VLDB: illegal max volid increment\n");
315 case VL_IDALREADYHASHED:
316 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
319 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
322 fprintf(STDERR, "VLDB: bad volume operation code\n");
324 case VL_BADRELLOCKTYPE:
325 fprintf(STDERR, "VLDB: bad release lock type\n");
328 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
330 case VL_BADSERVERFLAG:
331 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
334 fprintf(STDERR, "VLDB: no permission access for call\n");
336 case VOLSERREAD_DUMPERROR:
338 "VOLSER: Problems encountered in reading the dump file !\n");
340 case VOLSERDUMPERROR:
341 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
343 case VOLSERATTACH_ERROR:
344 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
346 case VOLSERDETACH_ERROR:
347 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
349 case VOLSERILLEGAL_PARTITION:
350 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
352 case VOLSERBAD_ACCESS:
353 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
355 case VOLSERVLDB_ERROR:
356 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
359 fprintf(STDERR, "VOLSER: error in volume name\n");
362 fprintf(STDERR, "VOLSER: volume has moved\n");
365 fprintf(STDERR, "VOLSER: illegal operation\n");
367 case VOLSERBADRELEASE:
368 fprintf(STDERR, "VOLSER: release could not be completed\n");
371 fprintf(STDERR, "VOLSER: volume is busy\n");
373 case VOLSERNO_MEMORY:
374 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
378 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
380 case VOLSERMULTIRWVOL:
382 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
386 "VOLSER: not all entries were successfully processed\n");
390 initialize_RXK_error_table();
391 initialize_KTC_error_table();
392 initialize_ACFG_error_table();
393 initialize_VL_error_table();
395 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
396 afs_error_message(errcode));
403 void init_volintInfo(struct volintInfo *vinfo) {
404 memset(vinfo, 0, sizeof(struct volintInfo));
406 vinfo->maxquota = -1;
408 vinfo->creationDate = -1;
409 vinfo->updateDate = -1;
417 static struct rx_securityClass *uvclass = 0;
418 static int uvindex = -1;
419 /* called by VLDBClient_Init to set the security module to be used in the RPC */
421 UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
428 /* bind to volser on <port> <aserver> */
429 /* takes server address in network order, port in host order. dumb */
430 struct rx_connection *
431 UV_Bind(afs_uint32 aserver, afs_int32 port)
433 struct rx_connection *tc;
435 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
441 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
442 afs_int32 partition, char *name, afs_int32 type,
443 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
448 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
450 if (code != VOLSERVOLBUSY)
453 #ifdef AFS_PTHREAD_ENV
456 IOMGR_Sleep(3-retries);
463 AFSVolTransCreate_retry(struct rx_connection *z_conn,
464 afs_int32 volume, afs_int32 partition,
465 afs_int32 flags, afs_int32 * trans)
470 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
471 if (code != VOLSERVOLBUSY)
474 #ifdef AFS_PTHREAD_ENV
477 IOMGR_Sleep(3-retries);
483 /* called by EmuerateEntry, show vldb entry in a reasonable format */
485 SubEnumerateEntry(struct nvldbentry *entry)
492 if (entry->flags & VLF_RWEXISTS)
493 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
494 if (entry->flags & VLF_ROEXISTS)
495 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
496 if (entry->flags & VLF_BACKEXISTS)
497 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
498 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
499 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
500 fprintf(STDOUT, "\n");
501 fprintf(STDOUT, " number of sites -> %lu\n",
502 (unsigned long)entry->nServers);
503 for (i = 0; i < entry->nServers; i++) {
504 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
507 for (i = 0; i < entry->nServers; i++) {
508 MapPartIdIntoName(entry->serverPartition[i], pname);
509 fprintf(STDOUT, " server %s partition %s ",
510 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
511 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
512 if (entry->serverFlags[i] & VLSF_RWVOL)
513 fprintf(STDOUT, "RW Site ");
515 fprintf(STDOUT, "RO Site ");
517 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
518 fprintf(STDOUT," -- New release");
520 if (!(entry->serverFlags[i] & VLSF_RWVOL))
521 fprintf(STDOUT," -- Old release");
523 if (entry->serverFlags[i] & VLSF_DONTUSE)
524 fprintf(STDOUT, " -- Not released");
526 fprintf(STDOUT, "\n");
533 /*enumerate the vldb entry corresponding to <entry> */
535 EnumerateEntry(struct nvldbentry *entry)
538 fprintf(STDOUT, "\n");
539 fprintf(STDOUT, "%s \n", entry->name);
540 SubEnumerateEntry(entry);
544 /* forcibly remove a volume. Very dangerous call */
546 UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
548 struct rx_connection *tconn;
551 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
553 code = AFSVolNukeVolume(tconn, partid, volid);
554 rx_DestroyConnection(tconn);
560 /* like df. Return usage of <pname> on <server> in <partition> */
562 UV_PartitionInfo64(afs_uint32 server, char *pname,
563 struct diskPartition64 *partition)
565 struct rx_connection *aconn;
568 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
569 code = AFSVolPartitionInfo64(aconn, pname, partition);
570 if (code == RXGEN_OPCODE) {
571 struct diskPartition *dpp = malloc(sizeof(struct diskPartition));
572 code = AFSVolPartitionInfo(aconn, pname, dpp);
574 strncpy(partition->name, dpp->name, 32);
575 strncpy(partition->devName, dpp->devName, 32);
576 partition->lock_fd = dpp->lock_fd;
577 partition->free = dpp->free;
578 partition->minFree = dpp->minFree;
583 fprintf(STDERR, "Could not get information on partition %s\n", pname);
584 PrintError("", code);
587 rx_DestroyConnection(aconn);
591 /* old interface to create volumes */
593 UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
598 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
602 /* less old interface to create volumes */
604 UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
605 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
606 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
608 afs_uint32 roid = 0, bkid = 0;
609 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
610 aspare3, aspare4, anewid, &roid, &bkid);
614 * Create a volume on the given server and partition
616 * @param aserver server to create volume on
617 * @param spart partition to create volume on
618 * @param aname name of new volume
619 * @param aquota quota for new volume
620 * @param anewid contains the desired volume id for the new volume. If
621 * *anewid == 0, a new id will be chosen, and will be placed
622 * in *anewid when UV_CreateVolume3 returns.
623 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
624 * will be unset. If *aroid == 0, an id will be chosen, and
625 * will be placed in *anewid when UV_CreateVolume3 returns.
626 * @param abkid same as aroid, except for the BK volume id instead of the
628 * @return 0 on success, error code otherwise.
631 UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
632 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
633 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
634 afs_uint32 * aroid, afs_uint32 * abkid)
636 struct rx_connection *aconn;
640 afs_int32 rcode, vcode;
642 struct nvldbentry entry, storeEntry; /*the new vldb entry */
643 struct volintInfo tstatus;
648 memset(&storeEntry, 0, sizeof(struct nvldbentry));
650 init_volintInfo(&tstatus);
651 tstatus.maxquota = aquota;
653 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
655 if (aroid && *aroid) {
656 VPRINT1("Using RO volume ID %d.\n", *aroid);
658 if (abkid && *abkid) {
659 VPRINT1("Using BK volume ID %d.\n", *abkid);
663 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
665 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
668 VPRINT1("Using volume ID %d.\n", *anewid);
670 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
671 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
673 if (aroid && *aroid == 0) {
674 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
675 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
678 if (abkid && *abkid == 0) {
679 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
680 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
684 /* rw,ro, bk id are related in the default case */
685 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
687 if (aroid && *aroid != 0) {
688 lastid = max(lastid, *aroid);
690 if (abkid && *abkid != 0) {
691 lastid = max(lastid, *abkid);
693 if (aroid && *aroid == 0) {
696 if (abkid && *abkid == 0) {
701 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
702 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
705 code = AFSVolSetInfo(aconn, tid, &tstatus);
707 EPRINT(code, "Could not change quota, continuing...\n");
709 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
710 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
713 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
715 /* set up the vldb entry for this volume */
716 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
718 entry.serverNumber[0] = aserver; /* this should have another
719 * level of indirection later */
720 entry.serverPartition[0] = apart; /* this should also have
721 * another indirection level */
722 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
723 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
724 entry.volumeId[RWVOL] = *anewid;
725 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
726 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
728 /*map into right byte order, before passing to xdr, the stuff has to be in host
729 * byte order. Xdr converts it into network order */
730 MapNetworkToHost(&entry, &storeEntry);
731 /* create the vldb entry */
732 vcode = VLDB_CreateEntry(&storeEntry);
735 "Could not create a VLDB entry for the volume %s %lu\n",
736 aname, (unsigned long)*anewid);
737 /*destroy the created volume */
738 VPRINT1("Deleting the newly created volume %u\n", *anewid);
739 AFSVolDeleteVolume(aconn, tid);
743 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
744 /* volume created, now terminate the transaction and release the connection */
745 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
746 * the volume will come online anyway when transaction timesout , so if
747 * vldb entry exists then the volume is guaranteed to exist too wrt create */
751 "Failed to end the transaction on the volume %s %lu\n", aname,
752 (unsigned long)*anewid);
759 code = AFSVolEndTrans(aconn, tid, &rcode);
761 fprintf(STDERR, "WARNING: could not end transaction\n");
764 rx_DestroyConnection(aconn);
765 PrintError("", error);
769 /* create a volume, given a server, partition number, volume name --> sends
770 * back new vol id in <anewid>*/
772 UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
775 struct rx_connection *aconn;
778 struct nvldbentry entry, storeEntry; /*the new vldb entry */
780 memset(&storeEntry, 0, sizeof(struct nvldbentry));
782 aconn = (struct rx_connection *)0;
785 /* set up the vldb entry for this volume */
786 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
788 entry.serverNumber[0] = aserver; /* this should have another
789 * level of indirection later */
790 entry.serverPartition[0] = apart; /* this should also have
791 * another indirection level */
792 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
793 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
794 entry.volumeId[RWVOL] = aid;
795 entry.volumeId[ROVOL] = 0;
796 entry.volumeId[BACKVOL] = 0;
798 /*map into right byte order, before passing to xdr, the stuff has to be in host
799 * byte order. Xdr converts it into network order */
800 MapNetworkToHost(&entry, &storeEntry);
801 /* create the vldb entry */
802 vcode = VLDB_CreateEntry(&storeEntry);
805 "Could not create a VLDB entry for the volume %s %lu\n",
806 aname, (unsigned long)aid);
810 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
814 rx_DestroyConnection(aconn);
815 PrintError("", error);
819 /* Delete the volume <volid>on <aserver> <apart>
820 * the physical entry gets removed from the vldb only if the ref count
824 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
826 struct rx_connection *aconn = (struct rx_connection *)0;
828 afs_int32 code, rcode;
830 struct nvldbentry entry, storeEntry;
832 afs_int32 avoltype = -1, vtype;
833 int notondisk = 0, notinvldb = 0;
835 memset(&storeEntry, 0, sizeof(struct nvldbentry));
837 /* Find and read bhe VLDB entry for this volume */
838 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
840 if (code != VL_NOENT) {
841 EGOTO1(error_exit, code,
842 "Could not lock VLDB entry for the volume %u\n", avolid);
848 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
849 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
851 MapHostToNetwork(&entry);
854 EnumerateEntry(&entry);
857 /* Whether volume is in the VLDB or not. Delete the volume on disk */
858 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
860 code = DoVolDelete(aconn, avolid, apart, "the", 0, NULL, NULL);
870 /* Now update the VLDB entry.
871 * But first, verify we have a VLDB entry.
872 * Whether volume is on disk or not. Delete the volume in VLDB.
877 if (avolid == entry.volumeId[BACKVOL]) {
878 /* Its a backup volume, modify the VLDB entry. Check that the
879 * backup volume is on the server/partition we asked to delete.
881 if (!(entry.flags & VLF_BACKEXISTS) || !Lp_Match(aserver, apart, &entry)) {
882 notinvldb = 2; /* Not on this server and partition */
886 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
888 entry.flags &= ~VLF_BACKEXISTS;
892 else if (avolid == entry.volumeId[ROVOL]) {
893 /* Its a read-only volume, modify the VLDB entry. Check that the
894 * readonly volume is on the server/partition we asked to delete.
895 * If flags does not have RO_EIXSTS set, then this may mean the RO
896 * hasn't been released (and could exist in VLDB).
898 if (!Lp_ROMatch(aserver, apart, &entry)) {
899 notinvldb = 2; /* Not found on this server and partition */
905 "Marking the readonly volume %lu deleted in the VLDB\n",
906 (unsigned long)avolid);
908 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
910 if (!Lp_ROMatch(0, 0, &entry))
911 entry.flags &= ~VLF_ROEXISTS; /* This was the last ro volume */
915 else if (avolid == entry.volumeId[RWVOL]) {
916 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
917 * Check that the readwrite volumes is on the server/partition we
920 if (!(entry.flags & VLF_RWEXISTS) || !Lp_Match(aserver, apart, &entry)) {
921 notinvldb = 2; /* Not found on this server and partition */
925 if (entry.volumeId[BACKVOL]) {
926 /* Delete backup if it exists */
927 code = DoVolDelete(aconn, entry.volumeId[BACKVOL], apart,
928 "the backup", 0, NULL, NULL);
929 if (code && code != VNOVOL) {
937 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
938 (unsigned long)avolid,
940 flags & VLF_BACKEXISTS) ? ", and its backup volume," :
943 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
945 entry.flags &= ~(VLF_BACKEXISTS | VLF_RWEXISTS);
948 if (entry.flags & VLF_ROEXISTS)
949 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
953 notinvldb = 2; /* Not found on this server and partition */
957 /* Either delete or replace the VLDB entry */
958 if ((entry.nServers <= 0) || !(entry.flags & (VLF_ROEXISTS | VLF_RWEXISTS))) {
961 "Last reference to the VLDB entry for %lu - deleting entry\n",
962 (unsigned long)avolid);
963 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
964 EGOTO1(error_exit, code,
965 "Could not delete the VLDB entry for the volume %u \n",
968 MapNetworkToHost(&entry, &storeEntry);
970 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
971 (LOCKREL_OPCODE | LOCKREL_AFSID |
973 EGOTO1(error_exit, code,
974 "Could not update the VLDB entry for the volume %u \n",
983 if (notondisk && notinvldb) {
984 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
985 ((notinvldb == 2) ? "on server and partition" : ""));
988 } else if (notondisk) {
990 "WARNING: Volume %lu did not exist on the partition\n",
991 (unsigned long)avolid);
992 } else if (notinvldb) {
993 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
994 (unsigned long)avolid,
995 ((notinvldb == 2) ? "on server and partition" : ""));
999 code = AFSVolEndTrans(aconn, ttid, &rcode);
1000 code = (code ? code : rcode);
1002 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1003 (unsigned long)avolid);
1004 PrintError("", code);
1012 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1013 (LOCKREL_OPCODE | LOCKREL_AFSID |
1014 LOCKREL_TIMESTAMP));
1017 "Could not release the lock on the VLDB entry for the volume %u \n",
1025 rx_DestroyConnection(aconn);
1029 /* add recovery to UV_MoveVolume */
1031 #define TESTC 0 /* set to test recovery code, clear for production */
1037 do_interrupt(void * unused)
1040 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1041 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1042 * changed. This will avoid some sanity checks, but until a better way
1043 * is found, the only alternative is always crashing and burning on at
1044 * least the stack-overflow check. */
1045 lwp_cpptr->stack = NULL;
1050 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1052 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1053 fprintf(STDOUT, "enter second control-c to exit\n");
1061 sigint_handler(int x)
1063 #ifdef AFS_PTHREAD_ENV
1066 IOMGR_SoftSig(do_interrupt, 0);
1068 (void)signal(SIGINT, sigint_handler);
1072 DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
1073 afs_int32 apart, char *ptypestring, afs_uint32 atoserver,
1074 struct volser_status *volstatus, char *pprefix)
1076 afs_int32 ttid = 0, code, rcode, error = 0;
1077 char *prefix, *typestring;
1086 typestring = ptypestring;
1092 VPRINT3("%sDeleting %s volume %u ...", prefix, typestring, avolid);
1095 AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
1097 /* return early and quietly for VNOVOL; don't continue the attempt to delete. */
1098 if (code == VNOVOL) {
1103 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1107 code = AFSVolGetStatus(aconn, ttid, volstatus);
1108 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1113 AFSVolSetFlags(aconn, ttid,
1114 VTDeleteOnSalvage | VTOutOfService);
1116 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1120 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1121 AFSVolSetForwarding(aconn, ttid, atoserver);
1125 code = AFSVolDeleteVolume(aconn, ttid);
1126 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1130 code = AFSVolEndTrans(aconn, ttid, &rcode);
1135 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1136 prefix, typestring, (unsigned long)avolid);
1142 if (beverbose && !error)
1148 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1149 afs_int32 apart, int type, afs_uint32 cloneid,
1150 char *typestring, char *pname, char *vname, char *suffix,
1151 struct volser_status *volstatus, afs_int32 *transPtr)
1154 afs_int32 ttid = 0, btid = 0;
1155 afs_int32 code = 0, rcode = 0;
1156 afs_int32 error = 0;
1157 int cloneexists = 1;
1159 /* Test to see if the clone volume exists by trying to create
1160 * a transaction on the clone volume. We've assumed the clone exists.
1162 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1164 if (code != VNOVOL) {
1165 EPRINT2(code, "Could not reach the %s volume %lu\n",
1166 typestring, (unsigned long)cloneid);
1170 cloneexists = 0; /* clone volume does not exist */
1173 code = AFSVolEndTrans(aconn, btid, &rcode);
1175 if (code || rcode) {
1177 "Could not end transaction on the previous %s volume %lu\n",
1178 typestring, (unsigned long)cloneid);
1179 error = (code ? code : rcode);
1184 /* Now go ahead and try to clone the RW volume.
1185 * First start a transaction on the RW volume
1187 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1189 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1190 (unsigned long)avolid);
1195 /* Clone or reclone the volume, depending on whether the clone
1196 * volume exists or not
1199 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1201 code = AFSVolReClone(aconn, ttid, cloneid);
1203 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1204 typestring, (unsigned long)cloneid);
1209 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1212 strcpy(cname, pname);
1213 strcat(cname, suffix);
1216 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1219 fprintf(STDERR, "Failed to clone the volume %lu\n",
1220 (unsigned long)avolid);
1229 VPRINT1("Getting status of parent volume %u...", avolid);
1230 code = AFSVolGetStatus(aconn, ttid, volstatus);
1232 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1233 (unsigned long)avolid);
1242 code = AFSVolEndTrans(aconn, ttid, &rcode);
1243 if (code || rcode) {
1244 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1245 (unsigned long)avolid);
1247 error = (code ? code : rcode);
1252 code = AFSVolEndTrans(aconn, btid, &rcode);
1253 if (code || rcode) {
1255 "Could not end transaction on the %s volume %lu\n",
1256 typestring, (unsigned long)cloneid);
1258 error = (code ? code : rcode);
1264 /* Convert volume from RO to RW; adjust the VLDB entry to match.
1265 * The nvldbentry passed to us has already been MapHostToNetwork'd
1270 UV_ConvertRO(afs_uint32 server, afs_uint32 partition, afs_uint32 volid,
1271 struct nvldbentry *entry)
1273 afs_int32 code, i, same;
1274 struct nvldbentry checkEntry, storeEntry;
1276 afs_int32 rwindex = 0;
1277 afs_uint32 rwserver = 0;
1278 afs_int32 roindex = 0;
1279 afs_uint32 roserver = 0;
1280 struct rx_connection *aconn;
1282 memset(&storeEntry, 0, sizeof(struct nvldbentry));
1285 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1289 "Unable to lock volume %lu, code %d\n",
1290 (unsigned long)entry->volumeId[RWVOL],vcode);
1291 PrintError("", vcode);
1295 /* make sure the VLDB entry hasn't changed since we started */
1296 memset(&checkEntry, 0, sizeof(checkEntry));
1297 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1300 "Could not fetch the entry for volume %lu from VLDB\n",
1301 (unsigned long)volid);
1302 PrintError("convertROtoRW ", vcode);
1307 MapHostToNetwork(&checkEntry);
1308 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1309 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1310 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1312 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1313 (unsigned long)volid);
1318 /* extract information from the original entry */
1319 for (i = 0; i < entry->nServers; i++) {
1320 if (entry->serverFlags[i] & VLSF_RWVOL) {
1322 rwserver = entry->serverNumber[i];
1323 /* rwpartition = entry->serverPartition[i]; */
1326 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1327 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1330 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1337 roserver = entry->serverNumber[i];
1338 /* ropartition = entry->serverPartition[i]; */
1345 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1346 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1349 "Converting RO volume %lu to RW volume failed with code %d\n",
1350 (unsigned long)volid, code);
1351 PrintError("convertROtoRW ", code);
1354 /* Update the VLDB to match what we did on disk as much as possible. */
1355 /* If the converted RO was in the VLDB, make it look like the new RW. */
1357 entry->serverFlags[roindex] = VLSF_RWVOL;
1359 /* Add a new site entry for the newly created RW. It's possible
1360 * (but unlikely) that we are already at MAXNSERVERS and that this
1361 * new site will invalidate the whole VLDB entry; however,
1362 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1363 * so we need no extra guard logic here.
1365 afs_int32 newrwindex = entry->nServers;
1366 (entry->nServers)++;
1367 entry->serverNumber[newrwindex] = server;
1368 entry->serverPartition[newrwindex] = partition;
1369 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1371 entry->flags |= VLF_RWEXISTS;
1372 entry->flags &= ~VLF_BACKEXISTS;
1374 /* if the old RW was in the VLDB, remove it by decrementing the number */
1375 /* of servers, replacing the RW entry with the last entry, and zeroing */
1376 /* out the last entry. */
1378 (entry->nServers)--;
1379 if (rwindex != entry->nServers) {
1380 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1381 entry->serverPartition[rwindex] =
1382 entry->serverPartition[entry->nServers];
1383 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1384 entry->serverNumber[entry->nServers] = 0;
1385 entry->serverPartition[entry->nServers] = 0;
1386 entry->serverFlags[entry->nServers] = 0;
1389 entry->flags &= ~VLF_ROEXISTS;
1390 for (i = 0; i < entry->nServers; i++) {
1391 if (entry->serverFlags[i] & VLSF_ROVOL) {
1392 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1393 entry->flags |= VLF_ROEXISTS;
1396 MapNetworkToHost(entry, &storeEntry);
1398 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1399 (LOCKREL_OPCODE | LOCKREL_AFSID |
1400 LOCKREL_TIMESTAMP));
1403 "Warning: volume converted, but vldb update failed with code %d!\n",
1408 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1411 "Unable to unlock volume %lu, code %d\n",
1412 (unsigned long)entry->volumeId[RWVOL],vcode);
1413 PrintError("", vcode);
1419 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1420 * <atopart>. The operation is almost idempotent. The following
1421 * flags are recognized:
1423 * RV_NOCLONE - don't use a copy clone
1427 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1428 afs_uint32 atoserver, afs_int32 atopart, int flags)
1430 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1431 * be changing during the move */
1432 struct rx_connection * volatile toconn;
1433 struct rx_connection * volatile fromconn;
1434 afs_int32 volatile fromtid;
1435 afs_int32 volatile totid;
1436 afs_int32 volatile clonetid;
1437 afs_uint32 volatile newVol;
1438 afs_uint32 volatile volid;
1439 afs_uint32 volatile backupId;
1440 int volatile islocked;
1445 char tmpName[VOLSER_MAXVOLNAME + 1];
1450 struct restoreCookie cookie;
1451 afs_int32 vcode, code;
1452 struct volser_status tstatus;
1453 struct destServer destination;
1455 struct nvldbentry entry, storeEntry;
1458 char in, lf; /* for test code */
1462 #ifdef ENABLE_BUGFIX_1165
1463 volEntries volumeInfo;
1464 struct volintInfo *infop = 0;
1468 fromconn = (struct rx_connection *)0;
1469 toconn = (struct rx_connection *)0;
1479 /* support control-c processing */
1482 (void)signal(SIGINT, sigint_handler);
1486 "\nThere are three tests points - verifies all code paths through recovery.\n");
1487 fprintf(STDOUT, "First test point - operation not started.\n");
1488 fprintf(STDOUT, "...test here (y, n)? ");
1490 if (fscanf(stdin, "%c", &in) < 1)
1492 if (fscanf(stdin, "%c", &lf) < 0) {
1493 /* toss away; don't care */
1496 fprintf(STDOUT, "type control-c\n");
1498 fprintf(stdout, ".");
1503 /* or drop through */
1506 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1507 EGOTO1(mfail, vcode,
1508 "Could not fetch the entry for the volume %u from the VLDB \n",
1511 if (entry.volumeId[RWVOL] != afromvol) {
1512 fprintf(STDERR, "Only RW volume can be moved\n");
1516 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1517 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1520 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1521 EGOTO1(mfail, vcode,
1522 "Could not fetch the entry for the volume %u from the VLDB \n",
1525 backupId = entry.volumeId[BACKVOL];
1526 MapHostToNetwork(&entry);
1528 if (!Lp_Match(afromserver, afrompart, &entry)) {
1529 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1530 if (!Lp_Match(atoserver, atopart, &entry)) {
1531 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1532 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1533 (unsigned long)afromvol);
1534 fprintf(STDERR, "The current site is :");
1535 for (i = 0; i < entry.nServers; i++) {
1536 if (entry.serverFlags[i] == VLSF_RWVOL) {
1538 MapPartIdIntoName(entry.serverPartition[i], pname);
1539 fprintf(STDERR, " server %s partition %s \n",
1540 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1541 hostutil_GetNameByINet(entry.serverNumber[i]),
1546 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1547 (LOCKREL_OPCODE | LOCKREL_AFSID |
1548 LOCKREL_TIMESTAMP));
1549 EGOTO1(mfail, vcode,
1550 " Could not release lock on the VLDB entry for the volume %u \n",
1553 return VOLSERVOLMOVED;
1556 /* delete the volume afromvol on src_server */
1557 /* from-info does not exist but to-info does =>
1558 * we have already done the move, but the volume
1559 * may still be existing physically on from fileserver
1561 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1564 code = DoVolDelete(fromconn, afromvol, afrompart,
1565 "leftover", 0, NULL, NULL);
1566 if (code && code != VNOVOL) {
1571 code = DoVolDelete(fromconn, backupId, afrompart,
1572 "leftover backup", 0, NULL, NULL);
1573 if (code && code != VNOVOL) {
1583 /* From-info matches the vldb info about volid,
1584 * its ok start the move operation, the backup volume
1585 * on the old site is deleted in the process
1587 if (afrompart == atopart) {
1588 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1589 EGOTO2(mfail, error,
1590 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1591 afromserver, error);
1594 EGOTO1(mfail, VOLSERVOLMOVED,
1595 "Warning: Moving volume %u to its home partition ignored!\n",
1601 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1602 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1603 totid = 0; /* initialize to uncreated */
1606 * clone the read/write volume locally.
1609 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1610 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1612 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1616 if (!(flags & RV_NOCLONE)) {
1617 /* Get a clone id */
1618 VPRINT1("Allocating new volume id for clone of volume %u ...",
1621 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1623 EGOTO1(mfail, vcode,
1624 "Could not get an ID for the clone of volume %u from the VLDB\n",
1628 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1629 VPRINT1("Cloning source volume %u ...", afromvol);
1630 strcpy(vname, "move-clone-temp");
1632 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1634 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1639 /* lookup the name of the volume we just cloned */
1641 code = AFSVolGetName(fromconn, fromtid, &volName);
1642 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1645 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1647 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1652 "Failed to end the transaction on the source volume %u\n",
1657 * Create the destination volume
1660 if (!(flags & RV_NOCLONE)) {
1661 /* All of this is to get the fromDate */
1662 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1665 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1669 "Failed to start a transaction on the cloned volume%u\n",
1673 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1675 AFSVolSetFlags(fromconn, clonetid,
1676 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1677 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1681 /* remember time from which we've dumped the volume */
1682 VPRINT1("Getting status of cloned volume %u ...", newVol);
1683 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1685 "Failed to get the status of the cloned volume %u\n",
1689 fromDate = CLOCKADJ(tstatus.creationDate);
1691 /* With RV_NOCLONE, just do a full copy from the source */
1696 #ifdef ENABLE_BUGFIX_1165
1698 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1699 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1700 * don't use this information...
1702 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1703 volumeInfo.volEntries_len = 0;
1704 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1706 "Failed to get the volint Info of the cloned volume %u\n",
1709 infop = (volintInfo *) volumeInfo.volEntries_val;
1710 infop->maxquota = -1; /* Else it will replace the default quota */
1711 infop->creationDate = -1; /* Else it will use the source creation date */
1712 infop->updateDate = -1; /* Else it will use the source update date */
1715 /* create a volume on the target machine */
1717 code = DoVolDelete(toconn, volid, atopart,
1718 "pre-existing destination", 0, NULL, NULL);
1719 if (code && code != VNOVOL) {
1724 VPRINT1("Creating the destination volume %u ...", volid);
1728 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1732 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1736 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1740 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1742 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1744 "Failed to set the flags on the destination volume %u\n", volid);
1748 * Now dump the clone to the new volume
1751 destination.destHost = ntohl(atoserver);
1752 destination.destPort = AFSCONF_VOLUMEPORT;
1753 destination.destSSID = 1;
1755 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1756 cookie.type = RWVOL;
1757 cookie.parent = entry.volumeId[RWVOL];
1760 if (!(flags & RV_NOCLONE)) {
1761 /* Copy the clone to the new volume */
1762 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1765 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1767 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1770 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1771 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1776 "Failed to end the transaction on the cloned volume %u\n",
1782 * reattach to the main-line volume, and incrementally dump it.
1785 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1787 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1790 "Failed to create a transaction on the source volume %u\n",
1794 /* now do the incremental */
1796 ("Doing the%s dump from source to destination for volume %u ... ",
1797 (flags & RV_NOCLONE) ? "" : " incremental",
1800 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1803 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1804 (flags & RV_NOCLONE) ? "" : " incremental");
1807 /* now adjust the flags so that the new volume becomes official */
1808 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1809 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1811 "Failed to set the flags to make old source volume offline\n");
1814 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1815 code = AFSVolSetFlags(toconn, totid, 0);
1817 "Failed to set the flags to make new source volume online\n");
1820 #ifdef ENABLE_BUGFIX_1165
1821 VPRINT1("Setting volume status on destination volume %u ...", volid);
1822 code = AFSVolSetInfo(toconn, totid, infop);
1824 "Failed to set volume status on the destination volume %u\n",
1829 /* put new volume online */
1830 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1831 code = AFSVolEndTrans(toconn, totid, &rcode);
1836 "Failed to end the transaction on the volume %u on the new site\n",
1840 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1841 MapNetworkToHost(&entry, &storeEntry);
1842 storeEntry.flags &= ~VLF_BACKEXISTS;
1846 "Second test point - operation in progress but not complete.\n");
1847 fprintf(STDOUT, "...test here (y, n)? ");
1849 if (fscanf(stdin, "%c", &in) < 1)
1851 if (fscanf(stdin, "%c", &lf) < 0) {
1852 /* toss away, don't care */
1855 fprintf(STDOUT, "type control-c\n");
1857 fprintf(stdout, ".");
1862 /* or drop through */
1865 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1867 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1868 (LOCKREL_OPCODE | LOCKREL_AFSID |
1869 LOCKREL_TIMESTAMP));
1872 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1873 storeEntry.name, (unsigned long)afromvol);
1882 "Third test point - operation complete but no cleanup.\n");
1883 fprintf(STDOUT, "...test here (y, n)? ");
1885 if (fscanf(stdin, "%c", &in) < 1)
1887 if (fscanf(stdin, "%c", &lf) < 0) {
1888 /* toss away; don't care */
1891 fprintf(STDOUT, "type control-c\n");
1893 fprintf(stdout, ".");
1898 /* or drop through */
1900 if (atoserver != afromserver) {
1901 /* set forwarding pointer for moved volumes */
1902 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1903 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1905 "Failed to set the forwarding pointer for the volume %u\n",
1910 VPRINT1("Deleting old volume %u on source ...", afromvol);
1911 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1912 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1916 VPRINT1("Ending transaction on old volume %u on the source ...",
1918 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1923 "Failed to end the transaction on the old volume %u on the source\n",
1927 code = DoVolDelete(fromconn, backupId, afrompart,
1928 "source backup", 0, NULL, NULL);
1929 if (code && code != VNOVOL) {
1934 code = 0; /* no backup volume? that's okay */
1937 if (!(flags & RV_NOCLONE)) {
1938 code = DoVolDelete(fromconn, newVol, afrompart,
1939 "cloned", 0, NULL, NULL);
1940 if (code && code != VNOVOL) {
1945 code = 0; /* clone missing? that's okay */
1952 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1953 fprintf(STDOUT, "...test here (y, n)? ");
1955 if (fscanf(stdin, "%c", &in) < 1)
1957 if (fscanf(stdin, "%c", &lf) < 0) { /* toss away */
1961 fprintf(STDOUT, "type control-c\n");
1963 fprintf(stdout, ".");
1968 /* or drop through */
1971 /* normal cleanup code */
1973 if (entry.flags & VLF_ROEXISTS)
1974 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1977 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1979 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1980 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1984 " Could not release the lock on the VLDB entry for the volume %lu \n",
1985 (unsigned long)afromvol);
1993 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1995 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1996 if (code || rcode) {
1999 "Could not end transaction on the source volume %lu\n",
2000 (unsigned long)afromvol);
2002 error = (code ? code : rcode);
2008 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2009 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2010 if (code || rcode) {
2013 "Could not end transaction on the source's clone volume %lu\n",
2014 (unsigned long)newVol);
2016 error = (code ? code : rcode);
2022 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2024 code = AFSVolEndTrans(toconn, totid, &rcode);
2028 "Could not end transaction on destination volume %lu\n",
2029 (unsigned long)afromvol);
2031 error = (code ? code : rcode);
2037 #ifdef ENABLE_BUGFIX_1165
2042 rx_DestroyConnection(fromconn);
2044 rx_DestroyConnection(toconn);
2045 PrintError("", error);
2048 /* come here only when the sky falls */
2053 "vos move: operation interrupted, cleanup in progress...\n");
2054 fprintf(STDOUT, "clear transaction contexts\n");
2058 /* unlock VLDB entry */
2060 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2061 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2062 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2068 VPRINT("Recovery: Ending transaction on clone volume ...");
2069 AFSVolEndTrans(fromconn, clonetid, &rcode);
2073 VPRINT("Recovery: Ending transaction on destination volume ...");
2074 AFSVolEndTrans(toconn, totid, &rcode);
2077 if (fromtid) { /* put it on-line */
2078 VPRINT("Recovery: Setting volume flags on source volume ...");
2079 AFSVolSetFlags(fromconn, fromtid, 0);
2082 VPRINT("Recovery: Ending transaction on source volume ...");
2083 AFSVolEndTrans(fromconn, fromtid, &rcode);
2087 VPRINT("Recovery: Accessing VLDB.\n");
2088 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2090 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2094 MapHostToNetwork(&entry);
2096 /* Delete either the volume on the source location or the target location.
2097 * If the vldb entry still points to the source location, then we know the
2098 * volume move didn't finish so we remove the volume from the target
2099 * location. Otherwise, we remove the volume from the source location.
2101 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2104 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2108 if (volid && toconn) {
2109 code = DoVolDelete(toconn, volid, atopart,
2110 "destination", 0, NULL, "Recovery:");
2111 if (code == VNOVOL) {
2112 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2116 /* put source volume on-line */
2118 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2122 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2128 VPRINT1("Recovery: Setting flags on source volume %u ...",
2130 AFSVolSetFlags(fromconn, fromtid, 0);
2134 ("Recovery: Ending transaction on source volume %u ...",
2136 AFSVolEndTrans(fromconn, fromtid, &rcode);
2140 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2144 } else { /* yep, move complete */
2147 "move complete - attempt cleanup of source partition - no guarantee\n");
2151 /* delete backup volume */
2153 code = DoVolDelete(fromconn, backupId, afrompart,
2154 "backup", 0, NULL, "Recovery:");
2155 if (code == VNOVOL) {
2156 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2159 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2160 (atoserver != afromserver)?atoserver:0,
2162 if (code == VNOVOL) {
2163 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2168 /* common cleanup - delete local clone */
2170 code = DoVolDelete(fromconn, newVol, afrompart,
2171 "clone", 0, NULL, "Recovery:");
2172 if (code == VNOVOL) {
2173 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2177 /* unlock VLDB entry */
2179 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2181 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2182 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2185 done: /* routine cleanup */
2188 #ifdef ENABLE_BUGFIX_1165
2193 rx_DestroyConnection(fromconn);
2195 rx_DestroyConnection(toconn);
2198 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2206 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2207 afs_uint32 atoserver, afs_int32 atopart)
2209 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2210 atoserver, atopart, 0);
2214 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2215 * <atopart>. The new volume is named by <atovolname>. The new volume
2216 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2217 * from the VLDB. the following flags are supported:
2219 * RV_RDONLY - target volume is RO
2220 * RV_OFFLINE - leave target volume offline
2221 * RV_CPINCR - do incremental dump if target exists
2222 * RV_NOVLDB - don't create/update VLDB entry
2223 * RV_NOCLONE - don't use a copy clone
2226 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2227 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2228 afs_uint32 atovolid, int flags)
2230 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2231 * be changing during the copy */
2233 afs_int32 volatile clonetid;
2234 afs_int32 volatile totid;
2235 afs_int32 volatile fromtid;
2236 struct rx_connection * volatile fromconn;
2237 struct rx_connection * volatile toconn;
2238 afs_uint32 volatile cloneVol;
2242 afs_int32 fromDate, cloneFromDate;
2243 struct restoreCookie cookie;
2244 afs_int32 vcode, code;
2247 struct volser_status tstatus;
2248 struct destServer destination;
2249 struct nvldbentry entry, newentry, storeEntry;
2254 fromconn = (struct rx_connection *)0;
2255 toconn = (struct rx_connection *)0;
2263 /* support control-c processing */
2266 (void)signal(SIGINT, sigint_handler);
2268 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2269 EGOTO1(mfail, vcode,
2270 "Could not fetch the entry for the volume %u from the VLDB \n",
2272 MapHostToNetwork(&entry);
2275 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2276 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2277 fromtid = totid = 0; /* initialize to uncreated */
2280 * clone the read/write volume locally.
2284 if (!(flags & RV_NOCLONE)) {
2285 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2287 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2290 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2294 /* Get a clone id */
2295 VPRINT1("Allocating new volume id for clone of volume %u ...",
2299 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2301 EGOTO1(mfail, vcode,
2302 "Could not get an ID for the clone of volume %u from the VLDB\n",
2310 /* Get a new volume id */
2311 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2313 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2314 EGOTO1(mfail, vcode,
2315 "Could not get an ID for the copy of volume %u from the VLDB\n",
2320 if (!(flags & RV_NOCLONE)) {
2321 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2322 VPRINT1("Cloning source volume %u ...", afromvol);
2323 strcpy(vname, "copy-clone-temp");
2326 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2329 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2333 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2335 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2340 "Failed to end the transaction on the source volume %u\n",
2346 * Create the destination volume
2349 if (!(flags & RV_NOCLONE)) {
2350 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2353 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2357 "Failed to start a transaction on the cloned volume%u\n",
2361 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2363 AFSVolSetFlags(fromconn, clonetid,
2364 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2365 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2369 /* remember time from which we've dumped the volume */
2370 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2371 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2373 "Failed to get the status of the cloned volume %u\n",
2377 fromDate = CLOCKADJ(tstatus.creationDate);
2382 /* create a volume on the target machine */
2385 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2388 if ((flags & RV_CPINCR)) {
2389 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2390 code = AFSVolGetStatus(toconn, totid, &tstatus);
2392 "Failed to get the status of the pre-existing volume %u\n",
2396 /* Using the update date should be OK here, but add some fudge */
2397 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2398 if ((flags & RV_NOCLONE))
2399 fromDate = cloneFromDate;
2401 /* XXX We should check that the source volume's creationDate is
2402 * XXX not newer than the existing target volume, and if not,
2403 * XXX throw away the existing target and do a full dump. */
2408 /* Delete the existing volume.
2409 * While we are deleting the volume in these steps, the transaction
2410 * we started against the cloned volume (clonetid above) will be
2411 * sitting idle. It will get cleaned up after 600 seconds
2413 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2414 code = AFSVolDeleteVolume(toconn, totid);
2416 "Could not delete the pre-existing volume %u on destination\n",
2421 ("Ending transaction on pre-existing volume %u on destination ...",
2423 code = AFSVolEndTrans(toconn, totid, &rcode);
2428 "Could not end the transaction on pre-existing volume %u on destination\n",
2433 VPRINT1("Creating the destination volume %u ...", newVol);
2436 AFSVolCreateVolume(toconn, atopart, atovolname,
2437 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2438 newVol, &newVol, &tmp);
2440 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2444 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2446 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2448 "Failed to set the flags on the destination volume %u\n", newVol);
2453 destination.destHost = ntohl(atoserver);
2454 destination.destPort = AFSCONF_VOLUMEPORT;
2455 destination.destSSID = 1;
2457 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2458 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2463 * Now dump the clone to the new volume
2466 if (!(flags & RV_NOCLONE)) {
2467 /* XXX probably should have some code here that checks to see if
2468 * XXX we are copying to same server and partition - if so, just
2469 * XXX use a clone to save disk space */
2471 /* Copy the clone to the new volume */
2472 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2475 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2477 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2481 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2482 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2487 "Failed to end the transaction on the cloned volume %u\n",
2493 * reattach to the main-line volume, and incrementally dump it.
2496 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2498 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2501 "Failed to create a transaction on the source volume %u\n",
2505 /* now do the incremental */
2507 ("Doing the%s dump from source to destination for volume %u ... ",
2508 (flags & RV_NOCLONE) ? "" : " incremental",
2511 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2514 "Failed to do the%s dump from old site to new site\n",
2515 (flags & RV_NOCLONE) ? "" : " incremental");
2518 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2519 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2520 code = AFSVolSetFlags(toconn, totid, volflag);
2522 "Failed to set the flags to make destination volume online\n");
2525 /* put new volume online */
2526 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2527 code = AFSVolEndTrans(toconn, totid, &rcode);
2532 "Failed to end the transaction on the destination volume %u\n",
2536 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2537 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2542 "Failed to end the transaction on the source volume %u\n",
2548 if (!(flags & RV_NOCLONE)) {
2549 code = DoVolDelete(fromconn, cloneVol, afrompart,
2550 "cloned", 0, NULL, NULL);
2551 if (code && code != VNOVOL) {
2556 code = 0; /* clone missing? that's ok */
2559 if (!(flags & RV_NOVLDB)) {
2560 /* create the vldb entry for the copied volume */
2561 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2562 newentry.nServers = 1;
2563 newentry.serverNumber[0] = atoserver;
2564 newentry.serverPartition[0] = atopart;
2565 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2566 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2567 newentry.volumeId[RWVOL] = newVol;
2568 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2569 newentry.volumeId[BACKVOL] = 0;
2570 newentry.cloneId = 0;
2571 /*map into right byte order, before passing to xdr, the stuff has to be in host
2572 * byte order. Xdr converts it into network order */
2573 MapNetworkToHost(&newentry, &storeEntry);
2574 /* create the vldb entry */
2575 vcode = VLDB_CreateEntry(&storeEntry);
2578 "Could not create a VLDB entry for the volume %s %lu\n",
2579 atovolname, (unsigned long)newVol);
2580 /*destroy the created volume */
2581 VPRINT1("Deleting the newly created volume %u\n", newVol);
2582 AFSVolDeleteVolume(toconn, totid);
2586 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2590 /* normal cleanup code */
2593 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2595 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2596 if (code || rcode) {
2599 "Could not end transaction on the source volume %lu\n",
2600 (unsigned long)afromvol);
2602 error = (code ? code : rcode);
2608 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2610 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2611 if (code || rcode) {
2614 "Could not end transaction on the source's clone volume %lu\n",
2615 (unsigned long)cloneVol);
2617 error = (code ? code : rcode);
2623 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2625 code = AFSVolEndTrans(toconn, totid, &rcode);
2629 "Could not end transaction on destination volume %lu\n",
2630 (unsigned long)newVol);
2632 error = (code ? code : rcode);
2637 rx_DestroyConnection(fromconn);
2639 rx_DestroyConnection(toconn);
2640 PrintError("", error);
2643 /* come here only when the sky falls */
2648 "vos copy: operation interrupted, cleanup in progress...\n");
2649 fprintf(STDOUT, "clear transaction contexts\n");
2654 VPRINT("Recovery: Ending transaction on clone volume ...");
2655 AFSVolEndTrans(fromconn, clonetid, &rcode);
2659 VPRINT("Recovery: Ending transaction on destination volume ...");
2660 AFSVolEndTrans(toconn, totid, &rcode);
2663 if (fromtid) { /* put it on-line */
2664 VPRINT("Recovery: Ending transaction on source volume ...");
2665 AFSVolEndTrans(fromconn, fromtid, &rcode);
2669 VPRINT("Recovery: Accessing VLDB.\n");
2670 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2672 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2676 MapHostToNetwork(&entry);
2678 /* common cleanup - delete local clone */
2680 DoVolDelete(fromconn, cloneVol, afrompart, "clone", 0, NULL,
2684 done: /* routine cleanup */
2686 rx_DestroyConnection(fromconn);
2688 rx_DestroyConnection(toconn);
2691 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2699 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2700 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2702 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2703 atovolname, atoserver, atopart, 0, 0);
2708 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2709 * if one already exists, update it
2713 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2715 struct rx_connection *aconn = (struct rx_connection *)0;
2716 afs_int32 ttid = 0, btid = 0;
2717 afs_uint32 backupID;
2718 afs_int32 code = 0, rcode = 0;
2719 struct nvldbentry entry, storeEntry;
2720 afs_int32 error = 0;
2721 int vldblocked = 0, vldbmod = 0;
2723 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2725 /* the calls to VLDB will succeed only if avolid is a RW volume,
2726 * since we are following the RW hash chain for searching */
2727 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2730 "Could not fetch the entry for the volume %lu from the VLDB \n",
2731 (unsigned long)avolid);
2735 MapHostToNetwork(&entry);
2737 /* These operations require the VLDB be locked since it means the VLDB
2738 * will change or the vldb is already locked.
2740 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2741 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2742 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2744 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2747 "Could not lock the VLDB entry for the volume %lu\n",
2748 (unsigned long)avolid);
2754 /* Reread the vldb entry */
2755 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2758 "Could not fetch the entry for the volume %lu from the VLDB \n",
2759 (unsigned long)avolid);
2763 MapHostToNetwork(&entry);
2766 if (!ISNAMEVALID(entry.name)) {
2767 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2769 error = VOLSERBADNAME;
2773 backupID = entry.volumeId[BACKVOL];
2774 if (backupID == INVALID_BID) {
2775 /* Get a backup volume id from the VLDB and update the vldb
2778 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2781 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2782 (unsigned long)avolid);
2786 entry.volumeId[BACKVOL] = backupID;
2790 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2791 entry.name, NULL, ".backup", NULL, NULL);
2797 /* Mark vldb as backup exists */
2798 if (!(entry.flags & VLF_BACKEXISTS)) {
2799 entry.flags |= VLF_BACKEXISTS;
2803 /* Now go back to the backup volume and bring it on line */
2804 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2807 "Failed to start a transaction on the backup volume %lu\n",
2808 (unsigned long)backupID);
2813 code = AFSVolSetFlags(aconn, btid, 0);
2815 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2816 (unsigned long)backupID);
2821 code = AFSVolEndTrans(aconn, btid, &rcode);
2823 if (code || rcode) {
2825 "Failed to end the transaction on the backup volume %lu\n",
2826 (unsigned long)backupID);
2827 error = (code ? code : rcode);
2831 /* Will update the vldb below */
2835 code = AFSVolEndTrans(aconn, ttid, &rcode);
2836 if (code || rcode) {
2837 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2838 (unsigned long)avolid);
2840 error = (code ? code : rcode);
2845 code = AFSVolEndTrans(aconn, btid, &rcode);
2846 if (code || rcode) {
2848 "Could not end transaction the backup volume %lu\n",
2849 (unsigned long)backupID);
2851 error = (code ? code : rcode);
2855 /* Now update the vldb - if modified */
2858 MapNetworkToHost(&entry, &storeEntry);
2860 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2861 (LOCKREL_OPCODE | LOCKREL_AFSID |
2862 LOCKREL_TIMESTAMP));
2865 "Could not update the VLDB entry for the volume %lu \n",
2866 (unsigned long)avolid);
2872 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2873 (LOCKREL_OPCODE | LOCKREL_AFSID |
2874 LOCKREL_TIMESTAMP));
2877 "Could not unlock the VLDB entry for the volume %lu \n",
2878 (unsigned long)avolid);
2886 rx_DestroyConnection(aconn);
2888 PrintError("", error);
2892 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2893 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2894 * The new volume is named by <aname>, or by appending ".clone" to
2895 * the existing name if <aname> is NULL. The following flags are
2898 * RV_RDONLY - target volume is RO
2899 * RV_OFFLINE - leave target volume offline
2903 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2904 afs_uint32 acloneid, char *aname, int flags)
2906 struct rx_connection *aconn = (struct rx_connection *)0;
2907 afs_int32 ttid = 0, btid = 0;
2908 afs_int32 code = 0, rcode = 0;
2909 char vname[VOLSER_MAXVOLNAME + 1];
2910 afs_int32 error = 0;
2911 volEntries volumeInfo;
2914 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2917 volumeInfo.volEntries_val = (volintInfo *) 0;
2918 volumeInfo.volEntries_len = 0;
2919 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2921 fprintf(stderr, "Could not get info for volume %lu\n",
2922 (unsigned long)avolid);
2926 strncpy(vname, volumeInfo.volEntries_val[0].name,
2927 VOLSER_OLDMAXVOLNAME - 7);
2928 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2929 strcat(vname, ".clone");
2931 if (volumeInfo.volEntries_val)
2932 free(volumeInfo.volEntries_val);
2936 /* Get a clone id */
2937 VPRINT1("Allocating new volume id for clone of volume %u ...",
2939 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2941 "Could not get an ID for the clone of volume %u from the VLDB\n",
2946 if (flags & RV_RWONLY)
2947 type = readwriteVolume;
2948 else if (flags & RV_RDONLY)
2949 type = readonlyVolume;
2951 type = backupVolume;
2953 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
2954 NULL, aname, NULL, NULL, NULL);
2960 /* Now go back to the backup volume and bring it on line */
2961 if (!(flags & RV_OFFLINE)) {
2962 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2965 "Failed to start a transaction on the clone volume %lu\n",
2966 (unsigned long)acloneid);
2971 code = AFSVolSetFlags(aconn, btid, 0);
2973 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2974 (unsigned long)acloneid);
2979 code = AFSVolEndTrans(aconn, btid, &rcode);
2981 if (code || rcode) {
2983 "Failed to end the transaction on the clone volume %lu\n",
2984 (unsigned long)acloneid);
2985 error = (code ? code : rcode);
2992 code = AFSVolEndTrans(aconn, ttid, &rcode);
2993 if (code || rcode) {
2994 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2995 (unsigned long)avolid);
2997 error = (code ? code : rcode);
3002 code = AFSVolEndTrans(aconn, btid, &rcode);
3003 if (code || rcode) {
3005 "Could not end transaction on the clone volume %lu\n",
3006 (unsigned long)acloneid);
3008 error = (code ? code : rcode);
3013 rx_DestroyConnection(aconn);
3015 PrintError("", error);
3019 #define ONERROR(ec, ep, es) do { \
3021 fprintf(STDERR, (es), (ep)); \
3026 #define ONERROR0(ec, es) do { \
3028 fprintf(STDERR, (es)); \
3033 #define ERROREXIT(ec) do { \
3038 /* Get a "transaction" on this replica. Create the volume
3039 * if necessary. Return the time from which a dump should
3040 * be made (0 if it's a new volume)
3043 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3044 struct rx_connection **connPtr, afs_int32 * transPtr,
3045 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3046 afs_int32 *origflags, afs_uint32 tmpVolId)
3049 struct volser_status tstatus;
3054 *connPtr = (struct rx_connection *)0;
3059 /* get connection to the replication site */
3060 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3062 goto fail; /* server is down */
3064 volid = vldbEntryPtr->volumeId[ROVOL];
3068 AFSVolTransCreate_retry(*connPtr, volid,
3069 vldbEntryPtr->serverPartition[index], ITOffline,
3072 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3073 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3074 * site. Don't trust any data on it, since it is possible we
3075 * have encountered some temporary volume from some other
3076 * incomplete volume operation. It is difficult to detect if
3077 * that has happened vs if this is a legit volume, so just
3078 * delete it to be safe. */
3080 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3081 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3082 serverNumber[index], hoststr) :
3083 hostutil_GetNameByINet(vldbEntryPtr->
3084 serverNumber[index]));
3086 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3088 PrintError("Failed to delete RO_DONTUSE site: ", code);
3092 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3098 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3105 /* emulate what TransCreate would have returned, so we try to
3106 * create the volume below */
3111 /* If the volume does not exist, create it */
3112 if (!volid || code) {
3113 char volname[VL_MAXNAMELEN];
3116 if (volid && (code != VNOVOL)) {
3117 PrintError("Failed to start a transaction on the RO volume.\n",
3122 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3124 if (strlcat(volname,
3125 tmpVolId?".roclone":".readonly",
3126 sizeof(volname)) >= sizeof(volname)) {
3128 PrintError("Volume name is too long\n", code);
3134 "Creating new volume %lu on replication site %s: ",
3135 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3136 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3137 serverNumber[index], hoststr) :
3138 hostutil_GetNameByINet(vldbEntryPtr->
3139 serverNumber[index]));
3144 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3146 vldbEntryPtr->volumeId[RWVOL],
3147 tmpVolId?&tmpVolId:&volid,
3150 PrintError("Failed to create the ro volume: ", code);
3153 vldbEntryPtr->volumeId[ROVOL] = volid;
3157 /* The following is a bit redundant, since create sets these flags by default */
3159 AFSVolSetFlags(*connPtr, *transPtr,
3160 VTDeleteOnSalvage | VTOutOfService);
3162 PrintError("Failed to set flags on the ro volume: ", code);
3167 /* Otherwise, the transaction did succeed, so get the creation date of the
3168 * latest RO volume on the replication site
3171 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3172 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3173 serverNumber[index], hoststr) :
3174 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3176 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3178 PrintError("Failed to get status of volume on destination: ",
3183 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3188 code = DoVolClone(*connPtr, volid,
3189 vldbEntryPtr->serverPartition[index],
3190 readonlyVolume, tmpVolId, "temporary",
3191 vldbEntryPtr->name, NULL, ".roclone", NULL,
3196 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3197 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3204 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3208 if (tcode && tcode != ENOENT)
3209 PrintError("Could not end transaction on a ro volume: ", tcode);
3216 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3217 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3218 void *cookie, manyResults * results)
3222 for (i = 0; i < tr->manyDests_len; i++) {
3223 results->manyResults_val[i] =
3224 AFSVolForward(fromconn, fromtid, fromdate,
3225 &(tr->manyDests_val[i].server),
3226 tr->manyDests_val[i].trans, cookie);
3232 * Check if a trans has timed out, and recreate it if necessary.
3234 * @param[in] aconn RX connection to the relevant server
3235 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3236 * contains the new trans ID on success
3237 * @param[in] apart Partition for the transaction
3238 * @param[in] astat The status of the original transaction
3240 * @return operation status
3241 * @retval 0 existing transaction is still valid, or we managed to recreate
3242 * the trans successfully
3243 * @retval nonzero Fatal error; bail out
3246 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3247 struct volser_status *astat)
3249 struct volser_status new_status;
3252 memset(&new_status, 0, sizeof(new_status));
3253 code = AFSVolGetStatus(aconn, *atid, &new_status);
3255 if (code == ENOENT) {
3257 VPRINT1("Old transaction on cloned volume %lu timed out, "
3258 "restarting transaction\n", (long unsigned) astat->volID);
3259 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3262 PrintError("Failed to recreate cloned RO volume transaction\n",
3267 memset(&new_status, 0, sizeof(new_status));
3268 code = AFSVolGetStatus(aconn, *atid, &new_status);
3270 PrintError("Failed to get status on recreated transaction\n",
3275 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3276 PrintError("Recreated transaction on cloned RO volume, but "
3277 "the volume has changed!\n", 0);
3281 PrintError("Unable to get status of current cloned RO transaction\n",
3286 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3288 PrintError("Internal error: current GetStatus does not match "
3289 "original GetStatus?\n", 0);
3298 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3299 struct rx_connection **toconns, struct release *times,
3302 afs_int32 s, code = 0, rcode = 0;
3303 /* End the transactions and destroy the connections */
3304 for (s = 0; s < volcount; s++) {
3305 if (replicas[s].trans) {
3306 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3308 replicas[s].trans = 0;
3312 if ((s == 0) || (code != ENOENT)) {
3313 PrintError("Could not end transaction on a ro volume: ",
3317 ("Transaction timed out on a ro volume. Will retry.\n",
3319 if (times[s].vldbEntryIndex < *vldbindex)
3320 *vldbindex = times[s].vldbEntryIndex;
3325 rx_DestroyConnection(toconns[s]);
3331 * Release a volume to read-only sites
3333 * Release volume <afromvol> on <afromserver> <afrompart> to all its RO
3334 * sites (complete release), unless the previous release was incomplete
3335 * or new sites were added without changes to the read-write volume, in
3336 * which case we bring the remaining volumes up to date with the volumes
3337 * that were previously released successfully.
3339 * Will create a clone from the RW, then dump the clone out to
3340 * the remaining replicas. If there is more than 1 RO sites,
3341 * ensure that the VLDB says at least one RO is available all
3342 * the time: Influences when we write back the VLDB entry.
3344 * @param[in] afromvol volume to be released
3345 * @param[in] afromserver server containing afromvol
3346 * @param[in] afrompart partition containing afromvol
3347 * @param[in] flags bitmap of options
3348 * REL_COMPLETE - force a complete release
3349 * REL_FULLDUMPS - force full dumps
3352 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3353 afs_int32 afrompart, int flags)
3357 afs_int32 vcode, rcode, tcode;
3358 afs_uint32 cloneVolId = 0, roVolId;
3359 struct replica *replicas = 0;
3360 struct nvldbentry entry, storeEntry;
3361 int i, volcount = 0, m, vldbindex;
3363 struct restoreCookie cookie;
3364 struct rx_connection **toconns = 0;
3365 struct release *times = 0;
3367 struct rx_connection *fromconn = (struct rx_connection *)0;
3368 afs_int32 error = 0;
3370 afs_int32 clonetid = 0, onlinetid;
3371 afs_int32 fromtid = 0;
3372 afs_uint32 fromdate = 0;
3373 afs_uint32 thisdate;
3377 manyResults results;
3378 int rwindex, roindex, roclone, roexists;
3379 afs_uint32 rwcrdate = 0, rwupdate = 0;
3380 afs_uint32 clcrdate;
3384 } remembertime[NMAXNSERVERS];
3385 int releasecount = 0;
3386 struct volser_status volstatus;
3388 afs_int32 origflags[NMAXNSERVERS];
3389 struct volser_status orig_status;
3390 int notreleased = 0;
3391 int tried_justnewsites = 0;
3392 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3393 int sites = 0; /* number of ro sites */
3394 int new_sites = 0; /* number of ro sites markes as new */
3397 CR_PARTIAL = 0x0000, /**< just new sites added or recover from a previous failed release */
3398 CR_FORCED = 0x0001, /**< complete: forced by caller */
3399 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3400 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3401 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3402 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3403 } complete_release_t;
3405 complete_release_t complete_release = CR_PARTIAL;
3407 memset(remembertime, 0, sizeof(remembertime));
3408 memset(&results, 0, sizeof(results));
3409 memset(origflags, 0, sizeof(origflags));
3411 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3412 if (vcode != VL_RERELEASE)
3413 ONERROR(vcode, afromvol,
3414 "Could not lock the VLDB entry for the volume %u.\n");
3417 /* Get the vldb entry in readable format */
3418 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3419 ONERROR(vcode, afromvol,
3420 "Could not fetch the entry for the volume %u from the VLDB.\n");
3421 MapHostToNetwork(&entry);
3424 EnumerateEntry(&entry);
3426 if (!ISNAMEVALID(entry.name))
3427 ONERROR(VOLSERBADOP, entry.name,
3428 "Volume name %s is too long, rename before releasing.\n");
3429 if (entry.volumeId[RWVOL] != afromvol)
3430 ONERROR(VOLSERBADOP, afromvol,
3431 "The volume %u being released is not a read-write volume.\n");
3432 if (entry.nServers <= 1)
3433 ONERROR(VOLSERBADOP, afromvol,
3434 "Volume %u has no replicas - release operation is meaningless!\n");
3435 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3436 ONERROR(VOLSERBADOP, entry.name,
3437 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3439 /* roclone is true if one of the RO volumes is on the same
3440 * partition as the RW volume. In this case, we make the RO volume
3441 * on the same partition a clone instead of a complete copy.
3444 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3445 roclone = ((roindex == -1) ? 0 : 1);
3446 rwindex = Lp_GetRwIndex(&entry);
3448 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3450 /* Make sure we have a RO volume id to work with */
3451 if (entry.volumeId[ROVOL] == INVALID_BID) {
3452 /* need to get a new RO volume id */
3453 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3454 ONERROR(vcode, entry.name, "Can't allocate ID for RO volume of %s\n");
3456 entry.volumeId[ROVOL] = roVolId;
3457 MapNetworkToHost(&entry, &storeEntry);
3458 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3459 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3463 * Determine if this is to be a complete release or a recovery of a
3464 * previous unfinished release. The previous release is considered to be
3465 * unfinished when the clone was successfully distributed to at least one
3466 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3469 * The caller can override the vldb flags check using the -force
3470 * or -force-reclone flag, to force this to be a complete release.
3472 for (i = 0; i < entry.nServers; i++) {
3473 if (entry.serverFlags[i] & VLSF_ROVOL) {
3475 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3477 if (entry.serverFlags[i] & VLSF_DONTUSE)
3480 origflags[i] = entry.serverFlags[i];
3483 if (flags & REL_COMPLETE) {
3484 complete_release |= CR_FORCED;
3487 if (new_sites == 0) {
3488 complete_release |= CR_LAST_OK;
3489 } else if (new_sites == sites) {
3490 complete_release |= CR_ALL_NEW;
3493 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3494 && !(complete_release & CR_FORCED)) {
3495 if (notreleased && notreleased != sites) {
3496 /* we have some new unreleased sites. try to just release to those,
3497 * if the RW has not changed. The caller can override with -force
3498 * or with -force-reclone. */
3503 /* Determine which volume id to use and see if it exists */
3504 cloneVolId = (complete_release || entry.cloneId == 0)
3505 ? entry.volumeId[ROVOL] : entry.cloneId;
3507 code = VolumeExists(afromserver, afrompart, cloneVolId);
3508 roexists = ((code == ENODEV) ? 0 : 1);
3510 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3512 ONERROR(-1, afromserver,
3513 "Cannot establish connection with server 0x%x\n");
3515 if (!complete_release) {
3517 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3519 /* Begin transaction on RW and mark it busy while we query it */
3520 code = AFSVolTransCreate_retry(
3521 fromconn, afromvol, afrompart, ITBusy, &fromtid
3523 ONERROR(code, afromvol,
3524 "Failed to start transaction on RW volume %u\n");
3526 /* Query the creation date for the RW */
3527 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3528 ONERROR(code, afromvol,
3529 "Failed to get the status of RW volume %u\n");
3530 rwcrdate = volstatus.creationDate;
3532 /* End transaction on RW */
3533 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3535 ONERROR((code ? code : rcode), afromvol,
3536 "Failed to end transaction on RW volume %u\n");
3538 /* Begin transaction on clone and mark it busy while we query it */
3539 code = AFSVolTransCreate_retry(
3540 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3542 ONERROR(code, cloneVolId,
3543 "Failed to start transaction on RW clone %u\n");
3545 /* Query the creation date for the clone */
3546 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3547 ONERROR(code, cloneVolId,
3548 "Failed to get the status of RW clone %u\n");
3549 clcrdate = volstatus.creationDate;
3551 /* End transaction on clone */
3552 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3554 ONERROR((code ? code : rcode), cloneVolId,
3555 "Failed to end transaction on RW clone %u\n");
3557 if (rwcrdate > clcrdate)
3558 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3562 if (!complete_release || (complete_release & CR_NEW_RW)) {
3563 /* in case the RW has changed, and just to be safe */
3568 if (!complete_release) {
3570 "This is a recovery of previously failed release\n");
3572 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3573 if (complete_release == CR_LAST_OK) {
3575 tried_justnewsites = 1;
3576 fprintf(STDOUT, "\nThere are new RO sites; we will try to "
3577 "only release to new sites");
3581 if (complete_release & CR_FORCED) {
3582 fprintf(STDOUT, "%sforced", sep);
3585 if (complete_release & CR_LAST_OK) {
3586 fprintf(STDOUT, "%slast ok", sep);
3589 if (complete_release & CR_ALL_NEW) {
3590 fprintf(STDOUT, "%sall sites are new", sep);
3593 if (complete_release & CR_NEW_RW) {
3594 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3597 if (complete_release & CR_RO_MISSING) {
3598 fprintf(STDOUT, "%sro clone missing", sep);
3600 fprintf(STDOUT, ")");
3602 fprintf(STDOUT, "\n");
3606 if (complete_release) {
3607 afs_int32 oldest = 0;
3608 /* If the RO clone exists, then if the clone is a temporary
3609 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3610 * (it was recently added), then also delete it. We do not
3611 * want to "reclone" a temporary RO clone.
3614 /* clean up any previous tmp clone before starting if staying up */
3616 && (!roclone || (entry.serverFlags[roindex] & VLSF_DONTUSE))) {
3617 code = DoVolDelete(fromconn,
3619 afrompart, "the", 0, NULL, NULL);
3620 if (code && (code != VNOVOL))
3626 VPRINT("Querying old RO sites for update times...");
3627 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3628 volEntries volumeInfo;
3629 struct rx_connection *conn;
3632 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL)) {
3635 if ((entry.serverFlags[vldbindex] & VLSF_DONTUSE)) {
3638 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3640 fprintf(STDERR, "Cannot establish connection to server %s\n",
3641 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3645 volumeInfo.volEntries_val = NULL;
3646 volumeInfo.volEntries_len = 0;
3647 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3648 entry.volumeId[ROVOL],
3651 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3652 (unsigned long)entry.volumeId[ROVOL],
3653 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3654 PrintError("", code);
3656 rx_DestroyConnection(conn);
3660 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3662 if (oldest == 0 || crdate < oldest) {
3666 rx_DestroyConnection(conn);
3667 free(volumeInfo.volEntries_val);
3668 volumeInfo.volEntries_val = NULL;
3669 volumeInfo.volEntries_len = 0;
3674 volEntries volumeInfo;
3675 volumeInfo.volEntries_val = NULL;
3676 volumeInfo.volEntries_len = 0;
3677 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3680 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3681 (unsigned long)afromvol,
3682 hostutil_GetNameByINet(afromserver));
3683 PrintError("", code);
3686 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3688 free(volumeInfo.volEntries_val);
3689 volumeInfo.volEntries_val = NULL;
3690 volumeInfo.volEntries_len = 0;
3693 if (justnewsites && oldest <= rwupdate) {
3694 /* RW has changed */
3698 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3699 * write this entry out to the vlserver until after the first
3700 * RO volume is released (temp RO clones don't count).
3702 * If 'justnewsites' is set, we're only updating sites that have
3703 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3705 for (i = 0; i < entry.nServers; i++) {
3707 if ((entry.serverFlags[i] & VLSF_DONTUSE)) {
3708 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3710 entry.serverFlags[i] |= VLSF_NEWREPSITE;
3713 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3714 entry.serverFlags[i] |= VLSF_DONTUSE;
3717 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3718 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3721 if (justnewsites && roexists) {
3722 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3723 * anything with the RO clone, so skip the reclone */
3726 } else if (complete_release) {
3729 strcpy(vname, entry.name);
3730 strcat(vname, ".readonly");
3732 strcpy(vname, "readonly-clone-temp");
3735 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3736 cloneVolId, roclone?"permanent RO":
3737 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3743 if (justnewsites && rwupdate != volstatus.updateDate) {
3745 /* reset the serverFlags as if 'justnewsites' had never been set */
3746 for (i = 0; i < entry.nServers; i++) {
3747 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3748 entry.serverFlags[i] |= VLSF_DONTUSE;
3750 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3751 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3754 rwcrdate = volstatus.creationDate;
3756 /* Remember clone volume ID in case we fail or are interrupted */
3757 entry.cloneId = cloneVolId;
3760 /* Bring the RO clone online - though not if it's a temporary clone */
3761 VPRINT1("Starting transaction on RO clone volume %u...",
3764 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3766 ONERROR(code, cloneVolId,
3767 "Failed to start transaction on volume %u\n");
3770 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3771 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3774 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3775 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3776 ONERROR((code ? code : rcode), cloneVolId,
3777 "Failed to end transaction on RO clone %u\n");
3780 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3782 /* Sleep so that a client searching for an online volume won't
3783 * find the clone offline and then the next RO offline while the
3784 * release brings the clone online and the next RO offline (race).
3785 * There is a fix in the 3.4 client that does not need this sleep
3786 * anymore, but we don't know what clients we have.
3788 if (entry.nServers > 2 && !justnewsites)
3791 /* Mark the RO clone in the VLDB as a good site (already released) */
3792 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
3793 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
3794 entry.flags |= VLF_ROEXISTS;
3798 /* Write out the VLDB entry only if the clone is not a temporary
3799 * clone. If we did this to a temporary clone then we would end
3800 * up marking all the ROs as "old release" making the ROs
3801 * temporarily unavailable.
3803 MapNetworkToHost(&entry, &storeEntry);
3804 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3805 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3806 ONERROR(vcode, entry.name,
3807 "Could not update vldb entry for %s.\n");
3813 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3814 /* act like this is a completion of a previous release */
3815 complete_release = CR_PARTIAL;
3816 } else if (tried_justnewsites) {
3817 VPRINT("RW vol has changed; releasing to all sites\n");
3820 /* Now we will release from the clone to the remaining RO replicas.
3821 * The first 2 ROs (counting the non-temporary RO clone) are released
3822 * individually: releasecount. This is to reduce the race condition
3823 * of clients trying to find an on-line RO volume. The remaining ROs
3824 * are released in parallel but no more than half the number of ROs
3825 * (rounded up) at a time: nservers.
3828 strcpy(vname, entry.name);
3829 strcat(vname, ".readonly");
3830 memset(&cookie, 0, sizeof(cookie));
3831 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3832 cookie.type = ROVOL;
3833 cookie.parent = entry.volumeId[RWVOL];
3836 /* how many to do at once, excluding clone */
3838 nservers = entry.nServers; /* can do all, none offline */
3840 nservers = entry.nServers / 2;
3841 replicas = calloc(nservers + 1, sizeof(struct replica));
3842 times = calloc(nservers + 1, sizeof(struct release));
3843 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3844 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3845 if (!replicas || !times || !results.manyResults_val || !toconns)
3847 "Failed to create transaction on the release clone\n");
3849 /* Create a transaction on the cloned volume */
3850 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3852 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3854 memset(&orig_status, 0, sizeof(orig_status));
3855 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3857 if (!complete_release && code)
3858 ONERROR(VOLSERNOVOL, afromvol,
3859 "Old clone is inaccessible. Try vos release -f %u.\n");
3860 ONERROR0(code, "Failed to create transaction on the release clone\n");
3863 /* For each index in the VLDB */
3864 for (vldbindex = 0; vldbindex < entry.nServers;) {
3865 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3867 ((volcount < nservers) && (vldbindex < entry.nServers));
3869 if (!justnewsites) {
3870 /* The first two RO volumes will be released individually.
3871 * The rest are then released in parallel. This is a hack
3872 * for clients not recognizing right away when a RO volume
3873 * comes back on-line.
3875 if ((volcount == 1) && (releasecount < 2))
3879 if (vldbindex == roindex)
3880 continue; /* the clone */
3881 if ((entry.serverFlags[vldbindex] & VLSF_NEWREPSITE)
3882 && !(entry.serverFlags[vldbindex] & VLSF_DONTUSE))
3884 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL))
3885 continue; /* not a RO vol */
3888 /* Get a Transaction on this replica. Get a new connection if
3889 * necessary. Create the volume if necessary. Return the
3890 * time from which the dump should be made (0 if it's a new
3891 * volume). Each volume might have a different time.
3893 replicas[volcount].server.destHost =
3894 ntohl(entry.serverNumber[vldbindex]);
3895 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3896 replicas[volcount].server.destSSID = 1;
3897 times[volcount].vldbEntryIndex = vldbindex;
3900 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3901 &(replicas[volcount].trans),
3902 &(times[volcount].crtime),
3903 &(times[volcount].uptime),
3908 /* Thisdate is the date from which we want to pick up all changes */
3909 if (flags & REL_FULLDUMPS) {
3910 /* Do a full dump when forced by the caller. */
3911 VPRINT("This will be a full dump: forced\n");
3913 } else if (complete_release == CR_PARTIAL) {
3915 VPRINT("This will be a full dump: read-only volume needs be created for new site\n");
3918 * We cannot be sure the creation date is good since the previous
3919 * release failed, so do a full dump.
3921 VPRINT("This will be a full dump: previous release failed\n");
3924 } else if (times[volcount].crtime == 0) {
3925 /* A full dump is needed for a new read-only volume. */
3927 ("This will be a full dump: read-only volume needs to be created\n");
3929 } else if ((rwcrdate > times[volcount].crtime)) {
3930 /* If the RW volume was replaced (its creation date is newer than
3931 * the last release), then we can't be sure what has changed (so
3932 * we do a full dump).
3935 ("This will be a full dump: read-write volume was replaced\n");
3937 } else if (remembertime[vldbindex].validtime) {
3938 /* Trans was prev ended. Use the time from the prev trans
3939 * because, prev trans may have created the volume. In which
3940 * case time[volcount].time would be now instead of 0.
3943 (remembertime[vldbindex].uptime < times[volcount].uptime)
3944 ? remembertime[vldbindex].uptime
3945 : times[volcount].uptime;
3947 thisdate = times[volcount].uptime;
3949 remembertime[vldbindex].validtime = 1;
3950 remembertime[vldbindex].uptime = thisdate;
3952 if (volcount == 0) {
3953 fromdate = thisdate;
3955 /* Include this volume if it is within 15 minutes of the earliest */
3957 thisdate) ? (fromdate - thisdate) : (thisdate -
3959 AFSVolEndTrans(toconns[volcount],
3960 replicas[volcount].trans, &rcode);
3961 replicas[volcount].trans = 0;
3964 if (thisdate < fromdate)
3965 fromdate = thisdate;
3972 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
3979 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3980 (unsigned long)cloneVolId,
3981 entry.volumeId[ROVOL],
3982 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3983 vldbEntryIndex], hoststr) :
3984 hostutil_GetNameByINet(entry.
3985 serverNumber[times[0].
3988 for (s = 1; s < volcount; s++) {
3989 fprintf(STDOUT, " and %s",
3990 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3991 vldbEntryIndex], hoststr) :
3992 hostutil_GetNameByINet(entry.
3993 serverNumber[times[s].
3998 fprintf(STDOUT, " (entire volume)");
4001 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4003 fprintf(STDOUT, ".\n");
4007 /* Release the ones we have collected */
4008 tr.manyDests_val = &(replicas[0]);
4009 tr.manyDests_len = results.manyResults_len = volcount;
4011 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4012 0 /*spare */ , &cookie, &results);
4013 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4015 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4016 0 /*spare */ , &cookie, &results);
4021 PrintError("Release failed: ", code);
4023 for (m = 0; m < volcount; m++) {
4024 if (results.manyResults_val[m]) {
4025 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4026 /* we retry timed out transaction. When it is
4027 * not the first volume and the transaction wasn't found
4028 * (assume it timed out and was garbage collected by volser).
4031 ("Failed to dump volume from clone to a ro site: ",
4032 results.manyResults_val[m]);
4038 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4039 ROVOL, entry.volumeId[RWVOL], 0, 0);
4041 if ((m == 0) || (code != ENOENT)) {
4042 PrintError("Failed to set correct names and ids: ",
4048 /* have to clear dest. flags to ensure new vol goes online:
4049 * because the restore (forwarded) operation copied
4050 * the V_inService(=0) flag over to the destination.
4052 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4054 if ((m == 0) || (code != ENOENT)) {
4055 PrintError("Failed to set flags on ro volume: ",
4061 entry.serverFlags[times[m].vldbEntryIndex] |= VLSF_NEWREPSITE;
4062 entry.serverFlags[times[m].vldbEntryIndex] &= ~VLSF_DONTUSE;
4063 entry.flags |= VLF_ROEXISTS;
4068 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4069 MapNetworkToHost(&entry, &storeEntry);
4070 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4071 ONERROR(vcode, afromvol,
4072 " Could not update VLDB entry for volume %u\n");
4073 } /* for each index in the vldb */
4075 /* End the transaction on the cloned volume */
4076 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4081 PrintError("Failed to end transaction on rw volume: ", code);
4083 /* Figure out if any volume were not released and say so */
4084 for (failure = 0, i = 0; i < entry.nServers; i++) {
4085 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE))
4091 "The volume %lu could not be released to the following %d sites:\n",
4092 (unsigned long)afromvol, failure);
4093 for (i = 0; i < entry.nServers; i++) {
4094 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE)) {
4095 MapPartIdIntoName(entry.serverPartition[i], pname);
4096 fprintf(STDERR, "\t%35s %s\n",
4097 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4098 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4101 MapNetworkToHost(&entry, &storeEntry);
4103 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4105 ONERROR(vcode, afromvol,
4106 " Could not update VLDB entry for volume %u\n");
4108 ERROREXIT(VOLSERBADRELEASE);
4112 /* All the ROs were release successfully. Remove the temporary clone */
4115 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4116 (unsigned long)cloneVolId);
4119 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4121 if (code && code != VNOVOL)
4122 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4126 for (i = 0; i < entry.nServers; i++)
4127 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
4129 /* Update the VLDB */
4130 VPRINT("updating VLDB ...");
4132 MapNetworkToHost(&entry, &storeEntry);
4134 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4135 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4136 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4141 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4145 "Failed to end cloning transaction on the RW volume %lu\n",
4146 (unsigned long)afromvol);
4152 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4156 "Failed to end transaction on the release clone %lu\n",
4157 (unsigned long)cloneVolId);
4162 for (i = 0; i < nservers; i++) {
4163 if (replicas && replicas[i].trans) {
4164 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4165 replicas[i].trans = 0;
4168 "Failed to end transaction on ro volume %u at server %s\n",
4169 entry.volumeId[ROVOL],
4170 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4171 destHost), hoststr) :
4172 hostutil_GetNameByINet(htonl
4173 (replicas[i].server.destHost)));
4178 if (toconns && toconns[i]) {
4179 rx_DestroyConnection(toconns[i]);
4185 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4186 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4189 "Could not release lock on the VLDB entry for volume %lu\n",
4190 (unsigned long)afromvol);
4196 PrintError("", error);
4199 rx_DestroyConnection(fromconn);
4200 if (results.manyResults_val)
4201 free(results.manyResults_val);
4213 dump_sig_handler(int x)
4215 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4219 /* Dump the volume <afromvol> on <afromserver> and
4220 * <afrompart> to <afilename> starting from <fromdate>.
4221 * DumpFunction does the real work behind the scenes after
4222 * extracting parameters from the rock
4225 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4227 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4230 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4231 * be changing during the dump */
4232 struct rx_call * volatile fromcall = NULL;
4233 struct rx_connection * volatile fromconn = NULL;
4234 afs_int32 volatile fromtid = 0;
4236 afs_int32 rcode = 0;
4237 afs_int32 code, error = 0;
4239 time_t tmv = fromdate;
4243 #ifndef AFS_NT40_ENV
4244 (void)signal(SIGPIPE, dump_sig_handler);
4246 (void)signal(SIGINT, dump_sig_handler);
4249 VEPRINT("Full Dump ...\n");
4251 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4255 /* get connections to the servers */
4256 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4258 VEPRINT1("Starting transaction on volume %u...", afromvol);
4260 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4262 EGOTO1(error_exit, code,
4263 "Could not start transaction on the volume %u to be dumped\n",
4267 fromcall = rx_NewCall(fromconn);
4269 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4270 if (flags & VOLDUMPV2_OMITDIRS)
4271 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4273 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4274 EGOTO(error_exit, code, "Could not start the dump process \n");
4277 VEPRINT1("Dumping volume %u...", afromvol);
4278 code = DumpFunction(fromcall, rock);
4279 if (code == RXGEN_OPCODE)
4281 EGOTO(error_exit, code, "Error while dumping volume \n");
4286 code = rx_EndCall(fromcall, 0);
4287 if (code && code != RXGEN_OPCODE)
4288 fprintf(STDERR, "Error in rx_EndCall\n");
4293 VEPRINT1("Ending transaction on volume %u...", afromvol);
4294 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4295 if (code || rcode) {
4296 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4297 (unsigned long)afromvol);
4299 error = (code ? code : rcode);
4304 rx_DestroyConnection(fromconn);
4306 if (error != RXGEN_OPCODE)
4307 PrintError("", error);
4311 /* Clone the volume <afromvol> on <afromserver> and
4312 * <afrompart>, and then dump the clone volume to
4313 * <afilename> starting from <fromdate>.
4314 * DumpFunction does the real work behind the scenes after
4315 * extracting parameters from the rock
4318 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4319 afs_int32 afrompart, afs_int32 fromdate,
4320 afs_int32(*DumpFunction) (struct rx_call *, void *),
4321 void *rock, afs_int32 flags)
4323 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4324 * be changing during the dump */
4325 struct rx_connection * volatile fromconn = NULL;
4326 struct rx_call * volatile fromcall = NULL;
4327 afs_int32 volatile clonetid = 0;
4328 afs_uint32 volatile clonevol = 0;
4331 afs_int32 fromtid = 0, rcode = 0;
4332 afs_int32 code = 0, error = 0;
4334 time_t tmv = fromdate;
4335 char *volName = NULL;
4339 #ifndef AFS_NT40_ENV
4340 (void)signal(SIGPIPE, dump_sig_handler);
4342 (void)signal(SIGINT, dump_sig_handler);
4345 VEPRINT("Full Dump ...\n");
4347 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4351 /* get connections to the servers */
4352 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4354 VEPRINT1("Starting transaction on volume %u...", afromvol);
4355 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4356 EGOTO1(error_exit, code,
4357 "Could not start transaction on the volume %u to be dumped\n",
4361 VEPRINT1("Getting the name for volume %u ...", afromvol);
4362 code = AFSVolGetName(fromconn, fromtid, &volName);
4363 EGOTO1(error_exit, code,
4364 "Failed to get the name of the volume %u\n",afromvol);
4367 /* Get a clone id */
4368 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4370 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4372 EGOTO1(error_exit, code,
4373 "Could not get an ID for the clone of volume %u from the VLDB\n",
4377 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4378 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4382 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, volName, &tmpVol);
4384 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4388 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4390 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4394 EGOTO1(error_exit, code,
4395 "Failed to end the transaction on the volume %u\n", afromvol);
4399 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4402 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4405 EGOTO1(error_exit, code,
4406 "Failed to start a transaction on the cloned volume%u\n",
4410 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4411 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4412 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4417 fromcall = rx_NewCall(fromconn);
4419 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4420 if (flags & VOLDUMPV2_OMITDIRS)
4421 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4423 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4424 EGOTO(error_exit, code, "Could not start the dump process \n");
4427 VEPRINT1("Dumping volume %u...", afromvol);
4428 code = DumpFunction(fromcall, rock);
4429 EGOTO(error_exit, code, "Error while dumping volume \n");
4436 /* now delete the clone */
4437 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4438 code = AFSVolDeleteVolume(fromconn, clonetid);
4440 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4441 (unsigned long)clonevol);
4447 code = rx_EndCall(fromcall, 0);
4449 fprintf(STDERR, "Error in rx_EndCall\n");
4455 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4456 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4457 if (code || rcode) {
4459 "Could not end transaction on the cloned volume %lu\n",
4460 (unsigned long)clonevol);
4462 error = (code ? code : rcode);
4467 rx_DestroyConnection(fromconn);
4469 PrintError("", error);
4476 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4477 * the dump file <afilename>. WriteData does all the real work
4478 * after extracting params from the rock
4481 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4482 afs_uint32 toparentid, char tovolname[], int flags,
4483 afs_int32(*WriteData) (struct rx_call *, void *),
4486 struct rx_connection *toconn, *tempconn;
4487 struct rx_call *tocall;
4488 afs_int32 totid, code, rcode, vcode, terror = 0;
4489 struct volser_status tstatus;
4490 struct volintInfo vinfo;
4492 char tovolreal[VOLSER_OLDMAXVOLNAME];
4494 afs_int32 temptid, pparentid;
4495 struct nvldbentry entry, storeEntry;
4498 struct restoreCookie cookie;
4500 afs_int32 volflag, voltype, volsertype;
4501 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4502 VolumeId oldCloneId = 0;
4503 VolumeId oldBackupId = 0;
4504 int index, same, errcode;
4508 memset(&cookie, 0, sizeof(cookie));
4512 tocall = (struct rx_call *)0;
4513 tempconn = (struct rx_connection *)0;
4517 if (flags & RV_RDONLY) {
4519 volsertype = volser_RO;
4522 volsertype = volser_RW;
4526 pparentid = toparentid;
4527 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4528 if (pvolid == 0) { /*alot a new id if needed */
4529 vcode = VLDB_GetEntryByName(tovolname, &entry);
4530 if (vcode == VL_NOENT) {
4531 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4533 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4540 fprintf(STDERR, "Could not fetch the VLDB entry for the volume %s\n",
4544 } else if (flags & RV_RDONLY) {
4545 /* -readonly restore is prohibited if an RW already exists */
4546 if (entry.flags & VLF_RWEXISTS) {
4548 "Entry for ReadWrite volume %s already exists!\n",
4550 error = VOLSERBADOP;
4553 if (!entry.volumeId[ROVOL]) {
4555 "Existing entry for volume %s has no ReadOnly ID\n",
4557 error = VOLSERBADOP;
4560 pvolid = entry.volumeId[ROVOL];
4561 pparentid = entry.volumeId[RWVOL];
4563 pvolid = entry.volumeId[RWVOL];
4564 pparentid = entry.volumeId[RWVOL];
4567 if (!pparentid) pparentid = pvolid;
4568 /* at this point we have a volume id to use/reuse for the volume to be restored */
4569 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4571 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4572 EGOTO1(refail, VOLSERBADOP,
4573 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4576 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4577 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4578 EGOTO1(refail, VOLSERBADOP,
4579 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4581 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4584 MapPartIdIntoName(topart, partName);
4585 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4586 tovolreal, (unsigned long)pvolid,
4587 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4588 hostutil_GetNameByINet(toserver), partName);
4592 * Obtain a transaction and get the status of the target volume. Create a new
4593 * volume if the target volume does not already exist.
4595 memset(&tstatus, 0, sizeof(tstatus));
4596 if ((flags & RV_FULLRST) != 0) {
4597 /* Full restore: Delete existing volume then create anew. */
4598 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0, &tstatus, NULL);
4599 if (code && code != VNOVOL) {
4603 code = AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4605 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4607 /* Incremental restore: Obtain a transaction on the existing volume. */
4608 code = AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4610 code = AFSVolGetStatus(toconn, totid, &tstatus);
4611 EGOTO1(refail, code, "Could not get timestamp from volume %u\n", pvolid);
4612 } else if (code == VNOVOL) {
4613 code = AFSVolCreateVolume(toconn, topart, tovolreal, volsertype,
4614 pparentid, &pvolid, &totid);
4615 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4617 EGOTO1(refail, code, "Failed to start transaction on %u\n", pvolid);
4620 oldCreateDate = tstatus.creationDate;
4621 oldUpdateDate = tstatus.updateDate;
4622 oldCloneId = tstatus.cloneID;
4623 oldBackupId = tstatus.backupID;
4625 cookie.parent = pparentid;
4626 cookie.type = voltype;
4628 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4630 tocall = rx_NewCall(toconn);
4631 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4633 fprintf(STDERR, "Volume restore Failed \n");
4637 code = WriteData(tocall, rock);
4639 fprintf(STDERR, "Could not transmit data\n");
4643 terror = rx_EndCall(tocall, 0);
4644 tocall = (struct rx_call *)0;
4646 fprintf(STDERR, "rx_EndCall Failed \n");
4650 code = AFSVolGetStatus(toconn, totid, &tstatus);
4653 "Could not get status information about the volume %lu\n",
4654 (unsigned long)pvolid);
4658 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid,
4659 oldCloneId, oldBackupId);
4661 fprintf(STDERR, "Could not set the right type and IDs on %lu\n",
4662 (unsigned long)pvolid);
4667 if (flags & RV_CRDUMP)
4668 newCreateDate = tstatus.creationDate;
4669 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4670 newCreateDate = oldCreateDate;
4672 newCreateDate = time(0);
4673 if (flags & RV_LUDUMP)
4674 newUpdateDate = tstatus.updateDate;
4675 else if (flags & RV_LUKEEP)
4676 newUpdateDate = oldUpdateDate;
4678 newUpdateDate = time(0);
4679 code = AFSVolSetDate(toconn,totid, newCreateDate);
4681 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4686 init_volintInfo(&vinfo);
4687 vinfo.creationDate = newCreateDate;
4688 vinfo.updateDate = newUpdateDate;
4689 code = AFSVolSetInfo(toconn, totid, &vinfo);
4691 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4697 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4698 code = AFSVolSetFlags(toconn, totid, volflag);
4700 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4705 /* It isn't handled right in refail */
4706 code = AFSVolEndTrans(toconn, totid, &rcode);
4711 fprintf(STDERR, "Could not end transaction on %lu\n",
4712 (unsigned long)pvolid);
4717 fprintf(STDOUT, " done\n");
4719 if (!reuseID || (flags & RV_FULLRST)) {
4720 /* Volume was restored on the file server, update the
4721 * VLDB to reflect the change.
4723 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4724 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4726 "Could not fetch the entry for volume number %lu from VLDB \n",
4727 (unsigned long)pvolid);
4732 MapHostToNetwork(&entry);
4733 if (vcode == VL_NOENT) { /* it doesnot exist already */
4734 /*make the vldb return this indication specifically */
4735 VPRINT("------- Creating a new VLDB entry ------- \n");
4736 strcpy(entry.name, tovolname);
4738 entry.serverNumber[0] = toserver; /*should be indirect */
4739 entry.serverPartition[0] = topart;
4740 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4741 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4742 if (flags & RV_RDONLY)
4743 entry.volumeId[ROVOL] = pvolid;
4744 else if (tstatus.cloneID != 0) {
4745 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4747 entry.volumeId[ROVOL] = INVALID_BID;
4748 entry.volumeId[RWVOL] = pparentid;
4750 if (tstatus.backupID != 0) {
4751 entry.volumeId[BACKVOL] = tstatus.backupID;
4752 /*this should come from status info on the volume if non zero */
4754 entry.volumeId[BACKVOL] = INVALID_BID;
4755 MapNetworkToHost(&entry, &storeEntry);
4756 vcode = VLDB_CreateEntry(&storeEntry);
4759 "Could not create the VLDB entry for volume number %lu \n",
4760 (unsigned long)pvolid);
4766 EnumerateEntry(&entry);
4767 } else { /*update the existing entry */
4769 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4770 fprintf(STDOUT, "------- Old entry -------\n");
4771 EnumerateEntry(&entry);
4772 fprintf(STDOUT, "------- New entry -------\n");
4775 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4779 "Could not lock the entry for volume number %lu \n",
4780 (unsigned long)pvolid);
4785 strcpy(entry.name, tovolname);
4787 /* Update the vlentry with the new information */
4788 if (flags & RV_RDONLY)
4789 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4791 index = Lp_GetRwIndex(&entry);
4793 /* Add the new site for the volume being restored */
4794 entry.serverNumber[entry.nServers] = toserver;
4795 entry.serverPartition[entry.nServers] = topart;
4796 entry.serverFlags[entry.nServers] =
4797 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4800 /* This volume should be deleted on the old site
4801 * if its different from new site.
4804 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4808 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4810 if ((!errcode && !same)
4811 || (entry.serverPartition[index] != topart)) {
4812 if (flags & RV_NODEL) {
4814 ("Not deleting the previous volume %u on server %s, ...",
4816 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4817 hostutil_GetNameByINet(entry.serverNumber[index]));
4820 UV_Bind(entry.serverNumber[index],
4821 AFSCONF_VOLUMEPORT);
4823 MapPartIdIntoName(entry.serverPartition[index],
4826 ("Deleting the previous volume %u on server %s, partition %s ...",
4828 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4829 hostutil_GetNameByINet(entry.serverNumber[index]),
4831 code = DoVolDelete(tempconn, pvolid,
4832 entry.serverPartition[index],
4833 "the", 0, NULL, NULL);
4834 if (code && code != VNOVOL) {
4838 MapPartIdIntoName(entry.serverPartition[index],
4842 entry.serverNumber[index] = toserver;
4843 entry.serverPartition[index] = topart;
4846 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4847 MapNetworkToHost(&entry, &storeEntry);
4849 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4850 LOCKREL_OPCODE | LOCKREL_AFSID |
4854 "Could not update the entry for volume number %lu \n",
4855 (unsigned long)pvolid);
4861 EnumerateEntry(&entry);
4868 code = rx_EndCall(tocall, 0);
4874 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4875 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4878 "Could not release lock on the VLDB entry for the volume %lu\n",
4879 (unsigned long)pvolid);
4885 code = AFSVolEndTrans(toconn, totid, &rcode);
4889 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4890 (unsigned long)pvolid);
4896 code = AFSVolEndTrans(toconn, temptid, &rcode);
4900 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4901 (unsigned long)pvolid);
4907 rx_DestroyConnection(tempconn);
4909 rx_DestroyConnection(toconn);
4910 PrintError("", error);
4915 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4916 char tovolname[], int flags,
4917 afs_int32(*WriteData) (struct rx_call *, void *),
4920 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4925 /*unlocks the vldb entry associated with <volid> */
4927 UV_LockRelease(afs_uint32 volid)
4931 VPRINT("Binding to the VLDB server\n");
4933 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4934 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4937 "Could not unlock the entry for volume number %lu in VLDB \n",
4938 (unsigned long)volid);
4939 PrintError("", vcode);
4942 VPRINT("VLDB updated\n");
4947 /* old interface to add rosites */
4949 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4952 return UV_AddSite2(server, part, volid, 0, valid);
4955 /*adds <server> and <part> as a readonly replication site for <volid>
4958 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4959 afs_uint32 rovolid, afs_int32 valid)
4961 int j, nro = 0, islocked = 0;
4962 struct nvldbentry entry, storeEntry, entry2;
4963 afs_int32 vcode, error = 0;
4966 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4969 " Could not lock the VLDB entry for the volume %lu \n",
4970 (unsigned long)volid);
4975 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4978 "Could not fetch the VLDB entry for volume number %lu \n",
4979 (unsigned long)volid);
4983 if (!ISNAMEVALID(entry.name)) {
4985 "Volume name %s is too long, rename before adding site\n",
4987 error = VOLSERBADOP;
4990 MapHostToNetwork(&entry);
4992 /* See if it's too many entries */
4993 if (entry.nServers >= NMAXNSERVERS) {
4994 fprintf(STDERR, "Total number of entries will exceed %u\n",
4996 error = VOLSERBADOP;
5000 /* See if it's on the same server */
5001 for (j = 0; j < entry.nServers; j++) {
5002 if (entry.serverFlags[j] & VLSF_ROVOL) {
5004 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5007 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5010 MapPartIdIntoName(entry.serverPartition[j], apartName);
5012 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5014 error = VOLSERBADOP;
5021 /* See if it's too many RO sites - leave one for the RW */
5022 if (nro >= NMAXNSERVERS - 1) {
5023 fprintf(STDERR, "Total number of sites will exceed %u\n",
5025 error = VOLSERBADOP;
5029 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5030 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5031 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5034 if (entry.volumeId[ROVOL] == INVALID_BID) {
5035 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5037 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5040 VPRINT1("Using RO volume id %d.\n", rovolid);
5041 entry.volumeId[ROVOL] = rovolid;
5043 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5044 rovolid, entry.volumeId[ROVOL]);
5048 VPRINT("Adding a new site ...");
5049 entry.serverNumber[entry.nServers] = server;
5050 entry.serverPartition[entry.nServers] = part;
5052 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5054 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5058 MapNetworkToHost(&entry, &storeEntry);
5060 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5061 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5063 fprintf(STDERR, "Could not update entry for volume %lu \n",
5064 (unsigned long)volid);
5073 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5074 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5077 "Could not release lock on volume entry for %lu \n",
5078 (unsigned long)volid);
5079 PrintError("", vcode);
5083 PrintError("", error);
5087 /*removes <server> <part> as read only site for <volid> from the vldb */
5089 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5092 struct nvldbentry entry, storeEntry;
5094 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5096 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5097 (unsigned long)volid);
5098 PrintError("", vcode);
5101 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5104 "Could not fetch the entry for volume number %lu from VLDB \n",
5105 (unsigned long)volid);
5106 PrintError("", vcode);
5109 MapHostToNetwork(&entry);
5110 if (!Lp_ROMatch(server, part, &entry)) {
5111 /*this site doesnot exist */
5112 fprintf(STDERR, "This site is not a replication site \n");
5114 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5115 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5117 fprintf(STDERR, "Could not update entry for volume %lu \n",
5118 (unsigned long)volid);
5119 PrintError("", vcode);
5120 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5121 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5125 } else { /*remove the rep site */
5126 Lp_SetROValue(&entry, server, part, 0, 0);
5128 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5129 entry.flags &= ~VLF_ROEXISTS;
5130 if (entry.nServers < 1) { /*this is the last ref */
5131 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5133 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5136 "Could not delete VLDB entry for volume %lu \n",
5137 (unsigned long)volid);
5138 PrintError("", vcode);
5143 MapNetworkToHost(&entry, &storeEntry);
5144 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5145 (unsigned long)volid);
5148 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5149 LOCKREL_OPCODE | LOCKREL_AFSID |
5153 "Could not release lock on volume entry for %lu \n",
5154 (unsigned long)volid);
5155 PrintError("", vcode);
5156 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5157 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5160 fprintf(STDOUT, " done\n");
5166 /*sets <server> <part> as read/write site for <volid> in the vldb */
5168 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5171 struct nvldbentry entry, storeEntry;
5174 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5176 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5177 (unsigned long)volid);
5178 PrintError("", vcode);
5181 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5184 "Could not fetch the entry for volume number %lu from VLDB \n",
5185 (unsigned long)volid);
5186 PrintError("", vcode);
5189 MapHostToNetwork(&entry);
5190 index = Lp_GetRwIndex(&entry);
5192 /* no RW site exists */
5193 fprintf(STDERR, "No existing RW site for volume %lu",
5194 (unsigned long)volid);
5196 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5197 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5200 "Could not release lock on entry for volume %lu \n",
5201 (unsigned long)volid);
5202 PrintError("", vcode);
5206 } else { /* change the RW site */
5207 entry.serverNumber[index] = server;
5208 entry.serverPartition[index] = part;
5209 MapNetworkToHost(&entry, &storeEntry);
5211 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5212 LOCKREL_OPCODE | LOCKREL_AFSID |
5215 fprintf(STDERR, "Could not update entry for volume %lu \n",
5216 (unsigned long)volid);
5217 PrintError("", vcode);
5218 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5219 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5227 /*list all the partitions on <aserver> */
5229 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5232 struct rx_connection *aconn;
5233 struct pIDs partIds;
5234 struct partEntries partEnts;
5238 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5240 partEnts.partEntries_len = 0;
5241 partEnts.partEntries_val = NULL;
5242 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5243 if (code == RXGEN_OPCODE) {
5244 for (i = 0; i < 26; i++) /* try old interface */
5245 partIds.partIds[i] = -1;
5246 code = AFSVolListPartitions(aconn, &partIds);
5248 for (i = 0; i < 26; i++) {
5249 if ((partIds.partIds[i]) != -1) {
5250 ptrPartList->partId[j] = partIds.partIds[i];
5251 ptrPartList->partFlags[j] = PARTVALID;
5254 ptrPartList->partFlags[i] = 0;
5259 *cntp = partEnts.partEntries_len;
5260 if (*cntp > VOLMAXPARTS) {
5262 "Warning: number of partitions on the server too high %d (process only %d)\n",
5263 *cntp, VOLMAXPARTS);
5264 *cntp = VOLMAXPARTS;
5266 for (i = 0; i < *cntp; i++) {
5267 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5268 ptrPartList->partFlags[i] = PARTVALID;
5270 free(partEnts.partEntries_val);
5276 "Could not fetch the list of partitions from the server\n");
5277 PrintError("", code);
5279 rx_DestroyConnection(aconn);
5284 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5285 This is used by the backup system */
5287 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5288 struct volDescription *volPtr, afs_int32 arraySize)
5290 struct rx_connection *aconn;
5291 struct volDescription *curPtr;
5294 afs_int32 success = 1;
5296 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5298 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5299 if (curPtr->volFlags & CLONEVALID) {
5300 curPtr->volFlags &= ~CLONEZAPPED;
5303 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5304 "clone", 0, NULL, NULL);
5309 curPtr->volFlags |= CLONEZAPPED;
5311 fprintf(STDERR, "Could not zap volume %lu\n",
5312 (unsigned long)curPtr->volCloneId);
5314 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5315 curPtr->volCloneId);
5320 rx_DestroyConnection(aconn);
5324 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5327 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5328 struct volDescription *volPtr, afs_int32 arraySize)
5330 struct rx_connection *aconn;
5331 struct volDescription *curPtr;
5334 afs_int32 rcode = 0;
5336 int reuseCloneId = 0;
5337 afs_uint32 curCloneId = 0;
5338 char cloneName[256]; /*max vol name */
5340 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5342 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5344 else { /*get a bunch of id's from vldb */
5346 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5348 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5349 PrintError("", code);
5354 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5355 if (curPtr->volFlags & ENTRYVALID) {
5357 curPtr->volFlags |= CLONEVALID;
5358 /*make a clone of curParentId and record as curPtr->volCloneId */
5360 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5363 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5366 curPtr->volFlags &= ~CLONEVALID; /* can't clone */
5370 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5371 strcpy(cloneName, curPtr->volName);
5372 strcat(cloneName, "-tmpClone-");
5374 strcpy(cloneName, "-tmpClone");
5376 curPtr->volCloneId = curCloneId;
5381 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5382 &(curPtr->volCloneId));
5384 curPtr->volFlags &= ~CLONEVALID;
5386 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5387 curPtr->volName, (unsigned long)code);
5388 code = AFSVolEndTrans(aconn, tid, &rcode);
5390 fprintf(STDERR, "WARNING: could not end transaction\n");
5393 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5394 curPtr->volCloneId);
5395 code = AFSVolEndTrans(aconn, tid, &rcode);
5396 if (code || rcode) {
5397 curPtr->volFlags &= ~CLONEVALID;
5406 rx_DestroyConnection(aconn);
5411 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5412 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5414 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5415 struct volintInfo **resultPtr, afs_int32 * size)
5417 struct rx_connection *aconn;
5419 volEntries volumeInfo;
5422 *resultPtr = (volintInfo *) 0;
5423 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5424 volumeInfo.volEntries_len = 0;
5426 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5427 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5430 "Could not fetch the list of volumes from the server\n");
5432 *resultPtr = volumeInfo.volEntries_val;
5433 *size = volumeInfo.volEntries_len;
5437 rx_DestroyConnection(aconn);
5438 PrintError("", code);
5442 /*------------------------------------------------------------------------
5443 * EXPORTED UV_XListVolumes
5446 * List the extended information for all the volumes on a particular
5447 * File Server and partition. We may either return the volume's ID
5448 * or all of its extended information.
5451 * a_serverID : Address of the File Server for which we want
5452 * extended volume info.
5453 * a_partID : Partition for which we want the extended
5455 * a_all : If non-zero, fetch ALL the volume info,
5456 * otherwise just the volume ID.
5457 * a_resultPP : Ptr to the address of the area containing
5458 * the returned volume info.
5459 * a_numEntsInResultP : Ptr for the value we set for the number of
5464 * Otherise, the return value of AFSVolXListVolumes.
5467 * This routine is closely related to UV_ListVolumes, which returns
5468 * only the standard level of detail on AFS volumes. It is a
5469 * heavyweight operation, zipping through all the volume entries for
5470 * a given server/partition.
5474 *------------------------------------------------------------------------*/
5477 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5478 struct volintXInfo **a_resultPP,
5479 afs_int32 * a_numEntsInResultP)
5481 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5482 afs_int32 code; /*Error code to return */
5483 volXEntries volumeXInfo; /*Area for returned extended vol info */
5486 * Set up our error code and the area for returned extended volume info.
5487 * We set the val field to a null pointer as a hint for the stub to
5490 *a_numEntsInResultP = 0;
5491 *a_resultPP = (volintXInfo *) 0;
5492 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5493 volumeXInfo.volXEntries_len = 0;
5496 * Bind to the Volume Server port on the File Server machine in question,
5499 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5500 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5502 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5505 * We got the info; pull out the pointer to where the results lie
5506 * and how many entries are there.
5508 *a_resultPP = volumeXInfo.volXEntries_val;
5509 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5513 * If we got an Rx connection, throw it away.
5516 rx_DestroyConnection(rxConnP);
5518 PrintError("", code);
5520 } /*UV_XListVolumes */
5522 /* get all the information about volume <volid> on <aserver> and <apart> */
5524 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5525 struct volintInfo **resultPtr)
5527 struct rx_connection *aconn;
5529 volEntries volumeInfo;
5531 *resultPtr = (volintInfo *) 0;
5532 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5533 volumeInfo.volEntries_len = 0;
5535 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5536 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5539 "Could not fetch the information about volume %lu from the server\n",
5540 (unsigned long)volid);
5542 *resultPtr = volumeInfo.volEntries_val;
5547 rx_DestroyConnection(aconn);
5548 PrintError("", code);
5552 /*------------------------------------------------------------------------
5553 * EXPORTED UV_XListOneVolume
5556 * List the extended information for a volume on a particular File
5557 * Server and partition.
5560 * a_serverID : Address of the File Server for which we want
5561 * extended volume info.
5562 * a_partID : Partition for which we want the extended
5564 * a_volID : Volume ID for which we want the info.
5565 * a_resultPP : Ptr to the address of the area containing
5566 * the returned volume info.
5570 * Otherise, the return value of AFSVolXListOneVolume.
5573 * This routine is closely related to UV_ListOneVolume, which returns
5574 * only the standard level of detail on the chosen AFS volume.
5578 *------------------------------------------------------------------------*/
5581 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5582 struct volintXInfo **a_resultPP)
5584 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5585 afs_int32 code; /*Error code */
5586 volXEntries volumeXInfo; /*Area for returned info */
5589 * Set up our error code, and the area we're in which we are returning
5590 * the info. Setting the val field to a null pointer tells the stub
5591 * to allocate space for us.
5593 *a_resultPP = (volintXInfo *) 0;
5594 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5595 volumeXInfo.volXEntries_len = 0;
5598 * Bind to the Volume Server port on the File Server machine in question,
5601 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5602 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5605 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5608 * We got the info; pull out the pointer to where the results lie.
5610 *a_resultPP = volumeXInfo.volXEntries_val;
5613 * If we got an Rx connection, throw it away.
5616 rx_DestroyConnection(rxConnP);
5618 PrintError("", code);
5623 * Given a volume we read from a partition, check if it is
5624 * represented in the VLDB correctly.
5626 * The VLDB is looked up by the RW volume id (not its name).
5627 * The RW contains the true name of the volume (BK and RO set
5628 * the name in the VLDB only on creation of the VLDB entry).
5629 * We want rules strict enough that when we check all volumes
5630 * on one partition, it does not need to be done again. IE:
5631 * two volumes on different partitions won't constantly
5632 * change a VLDB entry away from what the other set.
5633 * For RW and BK volumes, we will always check the VLDB to see
5634 * if the two exist on the server/partition. May seem redundant,
5635 * but this is an easy check of the VLDB. IE: if the VLDB entry
5636 * says the BK exists but no BK volume is there, we will detect
5637 * this when we check the RW volume.
5638 * VLDB entries are locked only when a change needs to be done.
5639 * Output changed to look a lot like the "vos syncserv" otuput.
5642 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5643 afs_int32 * modentry, afs_uint32 * maxvolid,
5644 struct nvldbentry *aentry)
5648 afs_int32 code, error = 0;
5649 struct nvldbentry entry, storeEntry;
5651 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5661 ((volumeinfo->type ==
5662 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5665 /* Check to see if the VLDB is ok without locking it (pass 1).
5666 * If it will change, then lock the VLDB entry, read it again,
5667 * then make the changes to it (pass 2).
5670 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5672 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5673 (unsigned long)rwvolid);
5678 createentry = 0; /* Do we need to create a VLDB entry */
5679 addvolume = 0; /* Add this volume to the VLDB entry */
5680 modified = 0; /* The VLDB entry was modified */
5683 memcpy(&entry, aentry, sizeof(entry));
5685 /* Read the entry from VLDB by its RW volume id */
5686 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5688 if (code != VL_NOENT) {
5690 "Could not retrieve the VLDB entry for volume %lu \n",
5691 (unsigned long)rwvolid);
5695 memset(&entry, 0, sizeof(entry));
5696 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5700 MapHostToNetwork(&entry);
5704 if (verbose && (pass == 1)) {
5705 fprintf(STDOUT, "_______________________________\n");
5706 fprintf(STDOUT, "\n-- status before -- \n");
5708 fprintf(STDOUT, "\n**does not exist**\n");
5710 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
5711 || (entry.flags & VLF_BACKEXISTS))
5712 EnumerateEntry(&entry);
5714 fprintf(STDOUT, "\n");
5717 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5723 /* Check existence of RW and BK volumes */
5724 code = CheckVldbRWBK(&entry, &mod);
5730 idx = Lp_GetRwIndex(&entry);
5731 if (idx == -1) { /* RW index not found in the VLDB entry */
5732 idx = entry.nServers; /* put it into next index */
5735 } else { /* RW index found in the VLDB entry. */
5736 /* Verify if this volume's location matches where the VLDB says it is */
5737 if (!Lp_Match(aserver, apart, &entry)) {
5738 if (entry.flags & VLF_RWEXISTS) {
5739 /* The RW volume exists elsewhere - report this one a duplicate */
5741 MapPartIdIntoName(apart, pname);
5743 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5744 (unsigned long)rwvolid,
5746 afs_inet_ntoa_r(aserver, hoststr) :
5747 hostutil_GetNameByINet(aserver), pname);
5748 MapPartIdIntoName(entry.serverPartition[idx],
5751 " VLDB reports RW volume %lu exists on %s %s\n",
5752 (unsigned long)rwvolid,
5754 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5755 hostutil_GetNameByINet(entry.
5760 /* The RW volume does not exist - have VLDB point to this one */
5763 /* Check for orphaned BK volume on old partition */
5764 if (entry.flags & VLF_BACKEXISTS) {
5766 MapPartIdIntoName(entry.serverPartition[idx],
5769 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5770 entry.volumeId[BACKVOL],
5772 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5773 hostutil_GetNameByINet(entry.
5776 MapPartIdIntoName(apart, pname);
5778 " VLDB reports its RW volume %lu exists on %s %s\n",
5779 (unsigned long)rwvolid,
5781 afs_inet_ntoa_r(aserver, hoststr) :
5782 hostutil_GetNameByINet(aserver),
5788 /* Volume location matches the VLDB location */
5789 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5790 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5793 (entry.name, volumeinfo->name,
5794 VOLSER_OLDMAXVOLNAME) != 0)) {
5802 entry.flags |= VLF_RWEXISTS;
5803 entry.volumeId[RWVOL] = rwvolid;
5804 if (!entry.volumeId[BACKVOL])
5805 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5806 if (!entry.volumeId[ROVOL])
5807 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5809 entry.serverFlags[idx] = VLSF_RWVOL;
5810 entry.serverNumber[idx] = aserver;
5811 entry.serverPartition[idx] = apart;
5812 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5816 /* One last check - to update BK if need to */
5817 code = CheckVldbRWBK(&entry, &mod);
5825 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5831 /* Check existence of RW and BK volumes */
5832 code = CheckVldbRWBK(&entry, &mod);
5838 idx = Lp_GetRwIndex(&entry);
5839 if (idx == -1) { /* RW index not found in the VLDB entry */
5840 idx = entry.nServers; /* Put it into next index */
5843 } else { /* RW index found in the VLDB entry */
5844 /* Verify if this volume's location matches where the VLDB says it is */
5845 if (!Lp_Match(aserver, apart, &entry)) {
5846 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5848 MapPartIdIntoName(apart, pname);
5850 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5851 (unsigned long)volumeinfo->volid,
5853 afs_inet_ntoa_r(aserver, hoststr) :
5854 hostutil_GetNameByINet(aserver), pname);
5855 MapPartIdIntoName(entry.serverPartition[idx], pname);
5857 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5858 (unsigned long)rwvolid,
5860 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5861 hostutil_GetNameByINet(entry.
5866 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5867 if (!(entry.flags & VLF_BACKEXISTS)) {
5869 } else if (volumeinfo->volid >
5870 entry.volumeId[BACKVOL]) {
5874 MapPartIdIntoName(entry.serverPartition[idx],
5877 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5878 entry.volumeId[BACKVOL],
5880 afs_inet_ntoa_r(aserver, hoststr) :
5881 hostutil_GetNameByINet(aserver),
5884 " VLDB reports its BK volume ID is %lu\n",
5885 (unsigned long)volumeinfo->volid);
5889 MapPartIdIntoName(entry.serverPartition[idx],
5892 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5893 (unsigned long)volumeinfo->volid,
5895 afs_inet_ntoa_r(aserver, hoststr) :
5896 hostutil_GetNameByINet(aserver),
5899 " VLDB reports its BK volume ID is %u\n",
5900 entry.volumeId[BACKVOL]);
5903 } else if (!entry.volumeId[BACKVOL]) {
5910 entry.flags |= VLF_BACKEXISTS;
5911 entry.volumeId[RWVOL] = rwvolid;
5912 entry.volumeId[BACKVOL] = volumeinfo->volid;
5914 entry.serverNumber[idx] = aserver;
5915 entry.serverPartition[idx] = apart;
5916 entry.serverFlags[idx] = VLSF_RWVOL;
5922 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5923 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5924 /* This is a quick check to see if the RO entry exists in the
5925 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5926 * RO volume listed in the VLDB exists).
5928 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5930 idx = entry.nServers;
5934 if (!(entry.flags & VLF_ROEXISTS)) {
5939 /* Before we correct the VLDB entry, make sure all the
5940 * ROs listed in the VLDB exist.
5942 code = CheckVldbRO(&entry, &mod);
5948 if (!(entry.flags & VLF_ROEXISTS)) {
5949 /* No RO exists in the VLDB entry - add this one */
5950 idx = entry.nServers;
5953 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5954 /* The volume headers's RO ID does not match that in the VLDB entry,
5955 * and the vol hdr's ID is greater (implies more recent). So delete
5956 * all the RO volumes listed in VLDB entry and add this volume.
5958 for (j = 0; j < entry.nServers; j++) {
5959 if (entry.serverFlags[j] & VLSF_ROVOL) {
5960 /* Verify this volume exists and print message we are orphaning it */
5962 MapPartIdIntoName(apart, pname);
5964 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5965 entry.volumeId[ROVOL],
5967 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5968 hostutil_GetNameByINet(entry.
5972 " VLDB reports its RO volume ID is %lu\n",
5973 (unsigned long)volumeinfo->volid);
5976 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5977 entry.serverPartition[idx], 0L, 0L);
5984 idx = entry.nServers;
5987 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5988 /* The volume headers's RO ID does not match that in the VLDB entry,
5989 * and the vol hdr's ID is lower (implies its older). So orphan it.
5992 MapPartIdIntoName(apart, pname);
5994 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5995 (unsigned long)volumeinfo->volid,
5997 afs_inet_ntoa_r(aserver, hoststr) :
5998 hostutil_GetNameByINet(aserver), pname);
6000 " VLDB reports its RO volume ID is %u\n",
6001 entry.volumeId[ROVOL]);
6004 /* The RO volume ID in the volume header match that in the VLDB entry,
6005 * and there exist RO volumes in the VLDB entry. See if any of them
6006 * are this one. If not, then we add it.
6008 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6010 idx = entry.nServers;
6018 entry.flags |= VLF_ROEXISTS;
6019 entry.volumeId[RWVOL] = rwvolid;
6020 entry.volumeId[ROVOL] = volumeinfo->volid;
6022 entry.serverNumber[idx] = aserver;
6023 entry.serverPartition[idx] = apart;
6024 entry.serverFlags[idx] = VLSF_ROVOL;
6030 /* Remember largest volume id */
6031 if (entry.volumeId[ROVOL] > *maxvolid)
6032 *maxvolid = entry.volumeId[ROVOL];
6033 if (entry.volumeId[BACKVOL] > *maxvolid)
6034 *maxvolid = entry.volumeId[BACKVOL];
6035 if (entry.volumeId[RWVOL] > *maxvolid)
6036 *maxvolid = entry.volumeId[RWVOL];
6038 if (modified && doit) {
6039 MapNetworkToHost(&entry, &storeEntry);
6042 code = VLDB_CreateEntry(&storeEntry);
6045 "Could not create a VLDB entry for the volume %lu\n",
6046 (unsigned long)rwvolid);
6053 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6054 LOCKREL_OPCODE | LOCKREL_AFSID |
6057 fprintf(STDERR, "Could not update entry for %lu\n",
6058 (unsigned long)rwvolid);
6062 } else if (pass == 2) {
6064 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6065 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6067 PrintError("Could not unlock VLDB entry ", code);
6071 if (modified && modentry) {
6076 memcpy(aentry, &entry, sizeof(entry));
6080 fprintf(STDOUT, "-- status after --\n");
6082 EnumerateEntry(&entry);
6084 fprintf(STDOUT, "\n**no change**\n");
6088 VPRINT("\n_______________________________\n");
6093 sortVolumes(const void *a, const void *b)
6095 volintInfo *v1 = (volintInfo *) a;
6096 volintInfo *v2 = (volintInfo *) b;
6097 afs_uint32 rwvolid1, rwvolid2;
6099 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6100 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6102 if (rwvolid1 > rwvolid2)
6103 return -1; /* lower RW id goes first */
6104 if (rwvolid1 < rwvolid2)
6107 if (v1->type == RWVOL)
6108 return -1; /* RW vols go first */
6109 if (v2->type == RWVOL)
6112 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6113 return -1; /* BK vols next */
6114 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6117 if (v1->volid < v2->volid)
6118 return 1; /* larger volids first */
6119 if (v1->volid > v2->volid)
6125 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6126 * Synchronize an individual volume against a sever and partition.
6127 * Checks the VLDB entry (similar to syncserv) as well as checks
6128 * if the volume exists on specified servers (similar to syncvldb).
6131 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6133 struct rx_connection *aconn = 0;
6134 afs_int32 j, k, code, vcode, error = 0;
6136 afs_int32 mod, modified = 0, deleted = 0;
6137 struct nvldbentry vldbentry;
6138 afs_uint32 volumeid = 0;
6139 volEntries volumeInfo;
6140 struct partList PartList;
6142 afs_uint32 maxvolid = 0;
6144 volumeInfo.volEntries_val = (volintInfo *) 0;
6145 volumeInfo.volEntries_len = 0;
6147 /* Turn verbose logging off and do our own verbose logging */
6148 /* tverbose must be set before we call ERROR_EXIT() */
6155 if (!aserver && (flags & 1)) {
6156 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6160 /* Read the VLDB entry */
6161 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6162 if (vcode && (vcode != VL_NOENT)) {
6163 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6166 } else if (!vcode) {
6167 MapHostToNetwork(&vldbentry);
6171 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6172 fprintf(STDOUT, "_______________________________\n");
6173 fprintf(STDOUT, "\n-- status before -- \n");
6175 fprintf(STDOUT, "\n**does not exist**\n");
6177 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6178 || (vldbentry.flags & VLF_BACKEXISTS))
6179 EnumerateEntry(&vldbentry);
6181 fprintf(STDOUT, "\n");
6184 /* Verify that all of the VLDB entries exist on the repective servers
6185 * and partitions (this does not require that avolname be a volume ID).
6186 * Equivalent to a syncserv.
6189 /* Tell CheckVldb not to update if appropriate */
6194 code = CheckVldb(&vldbentry, &mod, &deleted);
6196 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6204 /* If aserver is given, we will search for the desired volume on it */
6206 /* Generate array of partitions on the server that we will check */
6208 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6211 "Could not fetch the list of partitions from the server\n");
6215 PartList.partId[0] = apart;
6219 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6221 /* If a volume ID were given, search for it on each partition */
6222 if ((volumeid = atol(avolname))) {
6223 for (j = 0; j < pcnt; j++) {
6225 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6228 if (code != ENODEV) {
6229 fprintf(STDERR, "Could not query server\n");
6237 /* Found one, sync it with VLDB entry */
6239 CheckVolume(volumeInfo.volEntries_val, aserver,
6240 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6247 if (volumeInfo.volEntries_val)
6248 free(volumeInfo.volEntries_val);
6249 volumeInfo.volEntries_val = (volintInfo *) 0;
6250 volumeInfo.volEntries_len = 0;
6254 /* Check to see if the RW, BK, and RO IDs exist on any
6255 * partitions. We get the volume IDs from the VLDB.
6257 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6258 if (vldbentry.volumeId[j] == 0)
6261 for (k = 0; k < pcnt; k++) { /* For each partition */
6262 volumeInfo.volEntries_val = (volintInfo *) 0;
6263 volumeInfo.volEntries_len = 0;
6265 AFSVolListOneVolume(aconn, PartList.partId[k],
6266 vldbentry.volumeId[j], &volumeInfo);
6268 if (code != ENODEV) {
6269 fprintf(STDERR, "Could not query server\n");
6277 /* Found one, sync it with VLDB entry */
6279 CheckVolume(volumeInfo.volEntries_val, aserver,
6280 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6287 if (volumeInfo.volEntries_val)
6288 free(volumeInfo.volEntries_val);
6289 volumeInfo.volEntries_val = (volintInfo *) 0;
6290 volumeInfo.volEntries_len = 0;
6296 /* If verbose output, print a summary of what changed */
6298 fprintf(STDOUT, "-- status after --\n");
6300 fprintf(STDOUT, "\n**entry deleted**\n");
6301 } else if (modified) {
6302 EnumerateEntry(&vldbentry);
6304 fprintf(STDOUT, "\n**no change**\n");
6306 fprintf(STDOUT, "\n_______________________________\n");
6310 /* Now check if the maxvolid is larger than that stored in the VLDB */
6312 afs_uint32 maxvldbid = 0;
6313 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6316 "Could not get the highest allocated volume id from the VLDB\n");
6319 } else if (maxvolid > maxvldbid) {
6321 id = maxvolid - maxvldbid + 1;
6322 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6325 "Error in increasing highest allocated volume id in VLDB\n");
6335 fprintf(STDOUT, "...error encountered");
6337 fprintf(STDOUT, "...done entry\n");
6340 rx_DestroyConnection(aconn);
6341 if (volumeInfo.volEntries_val)
6342 free(volumeInfo.volEntries_val);
6344 PrintError("", error);
6349 * Synchronise vldb with the file server <aserver> and,
6350 * optionally, <apart>.
6353 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6355 struct rx_connection *aconn;
6356 afs_int32 code, error = 0;
6359 volEntries volumeInfo;
6360 struct partList PartList;
6364 afs_int32 failures = 0, modifications = 0, tentries = 0;
6366 afs_uint32 maxvolid = 0;
6369 volumeInfo.volEntries_val = (volintInfo *) 0;
6370 volumeInfo.volEntries_len = 0;
6372 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6374 /* Generate array of partitions to check */
6376 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6379 "Could not fetch the list of partitions from the server\n");
6383 PartList.partId[0] = apart;
6387 VPRINT("Processing volume entries ...\n");
6389 /* Step through the array of partitions */
6390 for (i = 0; i < pcnt; i++) {
6391 apart = PartList.partId[i];
6392 MapPartIdIntoName(apart, pname);
6394 volumeInfo.volEntries_val = (volintInfo *) 0;
6395 volumeInfo.volEntries_len = 0;
6396 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6399 "Could not fetch the list of volumes from the server\n");
6403 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6404 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6405 sizeof(volintInfo), sortVolumes);
6408 for (vi = volumeInfo.volEntries_val, j = 0;
6409 j < volumeInfo.volEntries_len; j++, vi++) {
6417 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6418 j + 1, vi->name, (unsigned long)vi->volid,
6420 afs_inet_ntoa_r(aserver, hoststr) :
6421 hostutil_GetNameByINet(aserver), pname);
6429 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6431 PrintError("", code);
6434 } else if (modified) {
6440 fprintf(STDOUT, "...error encountered\n\n");
6442 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6449 "Could not process entries on server %s partition %s\n",
6451 afs_inet_ntoa_r(aserver, hoststr) :
6452 hostutil_GetNameByINet(aserver), pname);
6454 if (volumeInfo.volEntries_val) {
6455 free(volumeInfo.volEntries_val);
6456 volumeInfo.volEntries_val = 0;
6459 } /* thru all partitions */
6462 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6463 tentries, failures, modifications);
6465 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6466 tentries, failures, modifications);
6470 /* Now check if the maxvolid is larger than that stored in the VLDB */
6472 afs_uint32 maxvldbid = 0;
6473 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6476 "Could not get the highest allocated volume id from the VLDB\n");
6479 } else if (maxvolid > maxvldbid) {
6481 id = maxvolid - maxvldbid + 1;
6482 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6485 "Error in increasing highest allocated volume id in VLDB\n");
6493 rx_DestroyConnection(aconn);
6494 if (volumeInfo.volEntries_val)
6495 free(volumeInfo.volEntries_val);
6496 PrintError("", error);
6501 * Determine if a volume exists on a server and partition.
6502 * Try creating a transaction on the volume. If we can,
6503 * the volume exists, if not, then return the error code.
6504 * Some error codes mean the volume is unavailable but
6505 * still exists - so we catch these error codes.
6508 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6510 struct rx_connection *conn = (struct rx_connection *)0;
6511 afs_int32 code = -1;
6512 volEntries volumeInfo;
6514 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6516 volumeInfo.volEntries_val = (volintInfo *) 0;
6517 volumeInfo.volEntries_len = 0;
6518 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6519 if (volumeInfo.volEntries_val)
6520 free(volumeInfo.volEntries_val);
6521 if (code == VOLSERILLEGAL_PARTITION)
6523 rx_DestroyConnection(conn);
6532 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6536 afs_int32 code, error = 0;
6542 idx = Lp_GetRwIndex(entry);
6544 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6547 if (idx == -1) { /* Did not find a RW entry */
6548 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6549 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6554 VolumeExists(entry->serverNumber[idx],
6555 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6556 if (code == 0) { /* RW volume exists */
6557 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6558 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6561 } else if (code == ENODEV) { /* RW volume does not exist */
6562 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6563 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6567 /* If VLDB says it didn't exist, then ignore error */
6568 if (entry->flags & VLF_RWEXISTS) {
6569 MapPartIdIntoName(entry->serverPartition[idx], pname);
6571 "Transaction call failed for RW volume %u on server %s %s\n",
6572 entry->volumeId[RWVOL],
6574 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6575 hostutil_GetNameByINet(entry->serverNumber[idx]),
6582 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6583 * flag accordingly. idx already ponts to the RW entry.
6585 if (idx == -1) { /* Did not find a RW entry */
6586 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6587 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6590 } else { /* Found a RW entry */
6592 VolumeExists(entry->serverNumber[idx],
6593 entry->serverPartition[idx],
6594 entry->volumeId[BACKVOL]);
6595 if (code == 0) { /* BK volume exists */
6596 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6597 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6600 } else if (code == ENODEV) { /* BK volume does not exist */
6601 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6602 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6606 /* If VLDB says it didn't exist, then ignore error */
6607 if (entry->flags & VLF_BACKEXISTS) {
6608 MapPartIdIntoName(entry->serverPartition[idx], pname);
6610 "Transaction call failed for BK volume %u on server %s %s\n",
6611 entry->volumeId[BACKVOL],
6613 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6614 hostutil_GetNameByINet(entry->serverNumber[idx]),
6621 /* If there is an idx but the BK and RW volumes no
6622 * longer exist, then remove the RW entry.
6624 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6625 && !(entry->flags & VLF_BACKEXISTS)) {
6626 Lp_SetRWValue(entry, entry->serverNumber[idx],
6627 entry->serverPartition[idx], 0L, 0L);
6634 *modified = modentry;
6639 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6642 int foundro = 0, modentry = 0;
6643 afs_int32 code, error = 0;
6650 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6653 for (idx = 0; idx < entry->nServers; idx++) {
6654 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6655 continue; /* not a RO */
6659 VolumeExists(entry->serverNumber[idx],
6660 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6661 if (code == 0) { /* RO volume exists */
6663 } else if (code == ENODEV) { /* RW volume does not exist */
6664 Lp_SetROValue(entry, entry->serverNumber[idx],
6665 entry->serverPartition[idx], 0L, 0L);
6670 MapPartIdIntoName(entry->serverPartition[idx], pname);
6672 "Transaction call failed for RO %u on server %s %s\n",
6673 entry->volumeId[ROVOL],
6675 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6676 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6681 if (foundro) { /* A RO volume exists */
6682 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6683 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6686 } else { /* A RO volume does not exist */
6687 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6688 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
6695 *modified = modentry;
6700 * Ensure that <entry> matches with the info on file servers
6703 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6705 afs_int32 code, error = 0;
6706 struct nvldbentry storeEntry;
6707 int islocked = 0, mod, modentry, delentry = 0;
6708 int pass = 0, doit=1;
6716 fprintf(STDOUT, "_______________________________\n");
6717 fprintf(STDOUT, "\n-- status before -- \n");
6718 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
6719 || (entry->flags & VLF_BACKEXISTS))
6720 EnumerateEntry(entry);
6721 fprintf(STDOUT, "\n");
6724 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6725 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6726 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6730 /* Check to see if the VLDB is ok without locking it (pass 1).
6731 * If it will change, then lock the VLDB entry, read it again,
6732 * then make the changes to it (pass 2).
6736 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6739 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6740 entry->volumeId[RWVOL]);
6745 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6747 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6751 MapHostToNetwork(entry);
6757 /* Check if the RW and BK entries are ok */
6758 code = CheckVldbRWBK(entry, &mod);
6761 if (mod && (pass == 1) && doit)
6766 /* Check if the RO volumes entries are ok */
6767 code = CheckVldbRO(entry, &mod);
6770 if (mod && (pass == 1) && doit)
6775 /* The VLDB entry has been updated. If it as been modified, then
6776 * write the entry back out the the VLDB.
6778 if (modentry && doit) {
6782 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
6783 && !(entry->flags & VLF_ROEXISTS) && doit) {
6784 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6786 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6790 "Could not delete VLDB entry for volume %u \n",
6791 entry->volumeId[RWVOL]);
6796 /* Replace old entry with our new one */
6797 MapNetworkToHost(entry, &storeEntry);
6799 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6800 (LOCKREL_OPCODE | LOCKREL_AFSID |
6801 LOCKREL_TIMESTAMP));
6803 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6804 entry->volumeId[RWVOL]);
6811 if (modified && modentry) {
6814 if (deleted && delentry) {
6819 fprintf(STDOUT, "-- status after --\n");
6821 fprintf(STDOUT, "\n**entry deleted**\n");
6823 EnumerateEntry(entry);
6825 fprintf(STDOUT, "\n**no change**\n");
6829 VPRINT("\n_______________________________\n");
6833 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6835 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6838 "Could not release lock on VLDB entry for volume %u\n",
6839 entry->volumeId[RWVOL]);
6848 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6851 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6853 struct rx_connection *aconn;
6854 afs_int32 code, error = 0;
6855 afs_int32 nentries, tentries = 0;
6856 struct VldbListByAttributes attributes;
6857 nbulkentries arrayEntries;
6858 afs_int32 failures = 0, modified, modifications = 0;
6859 struct nvldbentry *vlentry;
6860 afs_int32 si, nsi, j;
6865 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6867 /* Set up attributes to search VLDB */
6868 memset(&attributes, 0, sizeof(attributes));
6869 attributes.server = ntohl(aserver);
6870 attributes.Mask = VLLIST_SERVER;
6872 attributes.partition = apart;
6873 attributes.Mask |= VLLIST_PARTITION;
6876 VPRINT("Processing VLDB entries ...\n");
6878 /* While we need to collect more VLDB entries */
6879 for (si = 0; si != -1; si = nsi) {
6880 memset(&arrayEntries, 0, sizeof(arrayEntries));
6882 /* Collect set of VLDB entries */
6884 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6885 &arrayEntries, &nsi);
6886 if (code == RXGEN_OPCODE) {
6887 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6891 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6894 tentries += nentries;
6896 for (j = 0; j < nentries; j++) {
6897 vlentry = &arrayEntries.nbulkentries_val[j];
6898 MapHostToNetwork(vlentry);
6900 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6902 /* Tell CheckVldb not to update if appropriate */
6907 code = CheckVldb(vlentry, &modified, NULL);
6909 PrintError("", code);
6911 "Could not process VLDB entry for volume %s\n",
6914 } else if (modified) {
6920 fprintf(STDOUT, "...error encountered\n\n");
6922 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6927 if (arrayEntries.nbulkentries_val) {
6928 free(arrayEntries.nbulkentries_val);
6929 arrayEntries.nbulkentries_val = 0;
6934 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6935 tentries, failures, modifications);
6937 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6938 tentries, failures, modifications);
6943 rx_DestroyConnection(aconn);
6944 if (arrayEntries.nbulkentries_val)
6945 free(arrayEntries.nbulkentries_val);
6948 error = VOLSERFAILEDOP;
6952 /*rename volume <oldname> to <newname>, changing the names of the related
6953 *readonly and backup volumes. This operation is also idempotent.
6954 *salvager is capable of recovering from rename operation stopping halfway.
6955 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6957 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6959 struct nvldbentry storeEntry;
6960 afs_int32 vcode, code, rcode, error;
6962 char nameBuffer[256];
6964 struct rx_connection *aconn;
6969 aconn = (struct rx_connection *)0;
6973 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6976 " Could not lock the VLDB entry for the volume %u \n",
6977 entry->volumeId[RWVOL]);
6984 * Match the flags we just set via SetLock,
6985 * so we don't invalidate our compare below.
6987 entry->flags &= ~VLOP_ALLOPERS;
6988 entry->flags |= VLOP_ADDSITE;
6991 * Now get the entry again (under lock) and
6992 * verify the volume hasn't otherwise changed.
6994 vcode = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, &storeEntry);
6997 "Could not obtain the VLDB entry for the volume %u\n",
6998 entry->volumeId[RWVOL]);
7002 /* Convert to net order to match entry, which was passed in net order. */
7003 MapHostToNetwork(&storeEntry);
7004 if (memcmp(entry, &storeEntry, sizeof(*entry)) != 0) {
7006 "VLDB entry for volume %u has changed; "
7007 "please reissue the command.\n",
7008 entry->volumeId[RWVOL]);
7009 error = VL_BADENTRY; /* an arbitrary choice, but closest to the truth */
7013 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7014 /* Note that we are reusing storeEntry. */
7015 MapNetworkToHost(entry, &storeEntry);
7016 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7018 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7019 entry->volumeId[RWVOL]);
7023 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7024 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7025 * is concerned, oldname is lost */
7026 if (entry->flags & VLF_RWEXISTS) {
7027 index = Lp_GetRwIndex(entry);
7028 if (index == -1) { /* there is a serious discrepancy */
7030 "There is a serious discrepancy in VLDB entry for volume %u\n",
7031 entry->volumeId[RWVOL]);
7032 fprintf(STDERR, "try building VLDB from scratch\n");
7033 error = VOLSERVLDB_ERROR;
7036 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7038 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7039 entry->serverPartition[index], ITOffline, &tid);
7040 if (code) { /*volume doesnot exist */
7042 "Could not start transaction on the rw volume %u\n",
7043 entry->volumeId[RWVOL]);
7046 } else { /*volume exists, process it */
7049 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7050 entry->volumeId[RWVOL],
7051 entry->volumeId[ROVOL],
7052 entry->volumeId[BACKVOL]);
7054 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7055 code = AFSVolEndTrans(aconn, tid, &rcode);
7059 "Could not end transaction on volume %s %u\n",
7060 entry->name, entry->volumeId[RWVOL]);
7065 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7066 entry->name, entry->volumeId[RWVOL]);
7072 rx_DestroyConnection(aconn);
7073 aconn = (struct rx_connection *)0;
7075 /*end rw volume processing */
7076 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7077 index = Lp_GetRwIndex(entry);
7078 if (index == -1) { /* there is a serious discrepancy */
7080 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7081 entry->volumeId[BACKVOL]);
7082 fprintf(STDERR, "try building VLDB from scratch\n");
7083 error = VOLSERVLDB_ERROR;
7086 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7088 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7089 entry->serverPartition[index], ITOffline, &tid);
7090 if (code) { /*volume doesnot exist */
7092 "Could not start transaction on the backup volume %u\n",
7093 entry->volumeId[BACKVOL]);
7096 } else { /*volume exists, process it */
7097 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7099 "Volume name %s.backup exceeds the limit of %u characters\n",
7100 newname, VOLSER_OLDMAXVOLNAME);
7104 strcpy(nameBuffer, newname);
7105 strcat(nameBuffer, ".backup");
7108 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7109 entry->volumeId[RWVOL], 0, 0);
7111 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7112 code = AFSVolEndTrans(aconn, tid, &rcode);
7116 "Could not end transaction on the backup volume %u\n",
7117 entry->volumeId[BACKVOL]);
7123 "Could not set parameters on the backup volume %u\n",
7124 entry->volumeId[BACKVOL]);
7129 } /* end backup processing */
7131 rx_DestroyConnection(aconn);
7132 aconn = (struct rx_connection *)0;
7133 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7134 for (i = 0; i < entry->nServers; i++) {
7135 if (entry->serverFlags[i] & VLSF_ROVOL) {
7136 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7138 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7139 entry->serverPartition[i], ITOffline,
7141 if (code) { /*volume doesnot exist */
7143 "Could not start transaction on the ro volume %u\n",
7144 entry->volumeId[ROVOL]);
7147 } else { /*volume exists, process it */
7148 strcpy(nameBuffer, newname);
7149 strcat(nameBuffer, ".readonly");
7150 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7152 "Volume name %s exceeds the limit of %u characters\n",
7153 nameBuffer, VOLSER_OLDMAXVOLNAME);
7158 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7159 entry->volumeId[RWVOL], 0, 0);
7161 VPRINT2("Renamed RO volume %s on host %s\n",
7164 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7165 hostutil_GetNameByINet(entry->
7167 code = AFSVolEndTrans(aconn, tid, &rcode);
7171 "Could not end transaction on volume %u\n",
7172 entry->volumeId[ROVOL]);
7178 "Could not set parameters on the ro volume %u\n",
7179 entry->volumeId[ROVOL]);
7185 rx_DestroyConnection(aconn);
7186 aconn = (struct rx_connection *)0;
7193 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7195 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7198 "Could not unlock the VLDB entry for the volume %s %u\n",
7199 entry->name, entry->volumeId[RWVOL]);
7205 code = AFSVolEndTrans(aconn, tid, &rcode);
7209 fprintf(STDERR, "Failed to end transaction on a volume \n");
7215 rx_DestroyConnection(aconn);
7216 PrintError("", error);
7221 /*report on all the active transactions on volser */
7223 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7225 struct rx_connection *aconn;
7226 transDebugEntries transInfo;
7229 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7230 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7231 transInfo.transDebugEntries_len = 0;
7232 code = AFSVolMonitor(aconn, &transInfo);
7235 "Could not access status information about the server\n");
7236 PrintError("", code);
7237 if (transInfo.transDebugEntries_val)
7238 free(transInfo.transDebugEntries_val);
7240 rx_DestroyConnection(aconn);
7243 *rcount = transInfo.transDebugEntries_len;
7244 *rpntr = transInfo.transDebugEntries_val;
7246 rx_DestroyConnection(aconn);
7253 /*delete the volume without interacting with the vldb */
7255 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7258 struct rx_connection *aconn;
7260 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7261 error = DoVolDelete(aconn, volid, part,
7262 "the", 0, NULL, NULL);
7263 if (error == VNOVOL) {
7264 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7267 PrintError("", error);
7269 rx_DestroyConnection(aconn);
7274 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7275 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7277 struct rx_connection *conn = 0;
7279 afs_int32 code, error = 0, rcode;
7281 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7283 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7287 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7289 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7293 code = AFSVolSetFlags(conn, tid, setflag);
7295 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7300 #ifdef AFS_PTHREAD_ENV
7303 IOMGR_Sleep(sleeptime);
7310 code = AFSVolEndTrans(conn, tid, &rcode);
7311 if (code || rcode) {
7312 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7314 error = (code ? code : rcode);
7319 rx_DestroyConnection(conn);
7324 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7327 struct rx_connection *conn = 0;
7329 afs_int32 code, error = 0, rcode;
7331 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7333 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7337 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7339 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7343 code = AFSVolSetInfo(conn, tid, infop);
7345 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7352 code = AFSVolEndTrans(conn, tid, &rcode);
7353 if (code || rcode) {
7354 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7356 error = (code ? code : rcode);
7361 rx_DestroyConnection(conn);
7366 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7367 afs_int32 fromdate, struct volintSize *vol_size)
7369 struct rx_connection *aconn = (struct rx_connection *)0;
7370 afs_int32 tid = 0, rcode = 0;
7371 afs_int32 code, error = 0;
7374 /* get connections to the servers */
7375 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7377 VPRINT1("Starting transaction on volume %u...", afromvol);
7378 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7379 EGOTO1(error_exit, code,
7380 "Could not start transaction on the volume %u to be measured\n",
7384 VPRINT1("Getting size of volume on volume %u...", afromvol);
7385 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7386 EGOTO(error_exit, code, "Could not start the measurement process \n");
7391 VPRINT1("Ending transaction on volume %u...", afromvol);
7392 code = AFSVolEndTrans(aconn, tid, &rcode);
7393 if (code || rcode) {
7394 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7396 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7398 error = (code ? code : rcode);
7403 rx_DestroyConnection(aconn);
7405 PrintError("", error);
7409 /*maps the host addresses in <old > (present in network byte order) to
7410 that in< new> (present in host byte order )*/
7412 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7416 memset(new, 0, sizeof(struct nvldbentry));
7418 /*copy all the fields */
7419 strcpy(new->name, old->name);
7420 /* new->volumeType = old->volumeType;*/
7421 new->nServers = old->nServers;
7422 count = old->nServers;
7423 if (count < NMAXNSERVERS)
7425 for (i = 0; i < count; i++) {
7426 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7427 new->serverPartition[i] = old->serverPartition[i];
7428 new->serverFlags[i] = old->serverFlags[i];
7430 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7431 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7432 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7433 new->cloneId = old->cloneId;
7434 new->flags = old->flags;
7437 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7439 MapHostToNetwork(struct nvldbentry *entry)
7443 count = entry->nServers;
7444 if (count < NMAXNSERVERS)
7446 for (i = 0; i < count; i++) {
7447 entry->serverNumber[i] = htonl(entry->serverNumber[i]);