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 if (entry.flags & VLF_RWEXISTS) {
4547 "Entry for ReadWrite volume %s already exists!\n",
4549 error = VOLSERBADOP;
4552 if (!entry.volumeId[ROVOL]) {
4554 "Existing entry for volume %s has no ReadOnly ID\n",
4556 error = VOLSERBADOP;
4559 pvolid = entry.volumeId[ROVOL];
4560 pparentid = entry.volumeId[RWVOL];
4562 pvolid = entry.volumeId[RWVOL];
4563 pparentid = entry.volumeId[RWVOL];
4566 if (!pparentid) pparentid = pvolid;
4567 /* at this point we have a volume id to use/reuse for the volume to be restored */
4568 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4570 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4571 EGOTO1(refail, VOLSERBADOP,
4572 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4575 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4576 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4577 EGOTO1(refail, VOLSERBADOP,
4578 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4580 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4583 MapPartIdIntoName(topart, partName);
4584 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4585 tovolreal, (unsigned long)pvolid,
4586 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4587 hostutil_GetNameByINet(toserver), partName);
4591 * Obtain a transaction and get the status of the target volume. Create a new
4592 * volume if the target volume does not already exist.
4594 memset(&tstatus, 0, sizeof(tstatus));
4595 if ((flags & RV_FULLRST) != 0) {
4596 /* Full restore: Delete existing volume then create anew. */
4597 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0, &tstatus, NULL);
4598 if (code && code != VNOVOL) {
4602 code = AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4604 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4606 /* Incremental restore: Obtain a transaction on the existing volume. */
4607 code = AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4609 code = AFSVolGetStatus(toconn, totid, &tstatus);
4610 EGOTO1(refail, code, "Could not get timestamp from volume %u\n", pvolid);
4611 } else if (code == VNOVOL) {
4612 code = AFSVolCreateVolume(toconn, topart, tovolreal, volsertype,
4613 pparentid, &pvolid, &totid);
4614 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4616 EGOTO1(refail, code, "Failed to start transaction on %u\n", pvolid);
4619 oldCreateDate = tstatus.creationDate;
4620 oldUpdateDate = tstatus.updateDate;
4621 oldCloneId = tstatus.cloneID;
4622 oldBackupId = tstatus.backupID;
4624 cookie.parent = pparentid;
4625 cookie.type = voltype;
4627 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4629 tocall = rx_NewCall(toconn);
4630 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4632 fprintf(STDERR, "Volume restore Failed \n");
4636 code = WriteData(tocall, rock);
4638 fprintf(STDERR, "Could not transmit data\n");
4642 terror = rx_EndCall(tocall, 0);
4643 tocall = (struct rx_call *)0;
4645 fprintf(STDERR, "rx_EndCall Failed \n");
4649 code = AFSVolGetStatus(toconn, totid, &tstatus);
4652 "Could not get status information about the volume %lu\n",
4653 (unsigned long)pvolid);
4657 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid,
4658 oldCloneId, oldBackupId);
4660 fprintf(STDERR, "Could not set the right type and IDs on %lu\n",
4661 (unsigned long)pvolid);
4666 if (flags & RV_CRDUMP)
4667 newCreateDate = tstatus.creationDate;
4668 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4669 newCreateDate = oldCreateDate;
4671 newCreateDate = time(0);
4672 if (flags & RV_LUDUMP)
4673 newUpdateDate = tstatus.updateDate;
4674 else if (flags & RV_LUKEEP)
4675 newUpdateDate = oldUpdateDate;
4677 newUpdateDate = time(0);
4678 code = AFSVolSetDate(toconn,totid, newCreateDate);
4680 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4685 init_volintInfo(&vinfo);
4686 vinfo.creationDate = newCreateDate;
4687 vinfo.updateDate = newUpdateDate;
4688 code = AFSVolSetInfo(toconn, totid, &vinfo);
4690 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4696 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4697 code = AFSVolSetFlags(toconn, totid, volflag);
4699 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4704 /* It isn't handled right in refail */
4705 code = AFSVolEndTrans(toconn, totid, &rcode);
4710 fprintf(STDERR, "Could not end transaction on %lu\n",
4711 (unsigned long)pvolid);
4716 fprintf(STDOUT, " done\n");
4718 if (!reuseID || (flags & RV_FULLRST)) {
4719 /* Volume was restored on the file server, update the
4720 * VLDB to reflect the change.
4722 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4723 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4725 "Could not fetch the entry for volume number %lu from VLDB \n",
4726 (unsigned long)pvolid);
4731 MapHostToNetwork(&entry);
4732 if (vcode == VL_NOENT) { /* it doesnot exist already */
4733 /*make the vldb return this indication specifically */
4734 VPRINT("------- Creating a new VLDB entry ------- \n");
4735 strcpy(entry.name, tovolname);
4737 entry.serverNumber[0] = toserver; /*should be indirect */
4738 entry.serverPartition[0] = topart;
4739 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4740 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4741 if (flags & RV_RDONLY)
4742 entry.volumeId[ROVOL] = pvolid;
4743 else if (tstatus.cloneID != 0) {
4744 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4746 entry.volumeId[ROVOL] = INVALID_BID;
4747 entry.volumeId[RWVOL] = pparentid;
4749 if (tstatus.backupID != 0) {
4750 entry.volumeId[BACKVOL] = tstatus.backupID;
4751 /*this should come from status info on the volume if non zero */
4753 entry.volumeId[BACKVOL] = INVALID_BID;
4754 MapNetworkToHost(&entry, &storeEntry);
4755 vcode = VLDB_CreateEntry(&storeEntry);
4758 "Could not create the VLDB entry for volume number %lu \n",
4759 (unsigned long)pvolid);
4765 EnumerateEntry(&entry);
4766 } else { /*update the existing entry */
4768 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4769 fprintf(STDOUT, "------- Old entry -------\n");
4770 EnumerateEntry(&entry);
4771 fprintf(STDOUT, "------- New entry -------\n");
4774 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4778 "Could not lock the entry for volume number %lu \n",
4779 (unsigned long)pvolid);
4784 strcpy(entry.name, tovolname);
4786 /* Update the vlentry with the new information */
4787 if (flags & RV_RDONLY)
4788 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4790 index = Lp_GetRwIndex(&entry);
4792 /* Add the new site for the volume being restored */
4793 entry.serverNumber[entry.nServers] = toserver;
4794 entry.serverPartition[entry.nServers] = topart;
4795 entry.serverFlags[entry.nServers] =
4796 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4799 /* This volume should be deleted on the old site
4800 * if its different from new site.
4803 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4807 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4809 if ((!errcode && !same)
4810 || (entry.serverPartition[index] != topart)) {
4811 if (flags & RV_NODEL) {
4813 ("Not deleting the previous volume %u on server %s, ...",
4815 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4816 hostutil_GetNameByINet(entry.serverNumber[index]));
4819 UV_Bind(entry.serverNumber[index],
4820 AFSCONF_VOLUMEPORT);
4822 MapPartIdIntoName(entry.serverPartition[index],
4825 ("Deleting the previous volume %u on server %s, partition %s ...",
4827 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4828 hostutil_GetNameByINet(entry.serverNumber[index]),
4830 code = DoVolDelete(tempconn, pvolid,
4831 entry.serverPartition[index],
4832 "the", 0, NULL, NULL);
4833 if (code && code != VNOVOL) {
4837 MapPartIdIntoName(entry.serverPartition[index],
4841 entry.serverNumber[index] = toserver;
4842 entry.serverPartition[index] = topart;
4845 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4846 MapNetworkToHost(&entry, &storeEntry);
4848 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4849 LOCKREL_OPCODE | LOCKREL_AFSID |
4853 "Could not update the entry for volume number %lu \n",
4854 (unsigned long)pvolid);
4860 EnumerateEntry(&entry);
4867 code = rx_EndCall(tocall, 0);
4873 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4874 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4877 "Could not release lock on the VLDB entry for the volume %lu\n",
4878 (unsigned long)pvolid);
4884 code = AFSVolEndTrans(toconn, totid, &rcode);
4888 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4889 (unsigned long)pvolid);
4895 code = AFSVolEndTrans(toconn, temptid, &rcode);
4899 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4900 (unsigned long)pvolid);
4906 rx_DestroyConnection(tempconn);
4908 rx_DestroyConnection(toconn);
4909 PrintError("", error);
4914 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4915 char tovolname[], int flags,
4916 afs_int32(*WriteData) (struct rx_call *, void *),
4919 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4924 /*unlocks the vldb entry associated with <volid> */
4926 UV_LockRelease(afs_uint32 volid)
4930 VPRINT("Binding to the VLDB server\n");
4932 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4933 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4936 "Could not unlock the entry for volume number %lu in VLDB \n",
4937 (unsigned long)volid);
4938 PrintError("", vcode);
4941 VPRINT("VLDB updated\n");
4946 /* old interface to add rosites */
4948 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4951 return UV_AddSite2(server, part, volid, 0, valid);
4954 /*adds <server> and <part> as a readonly replication site for <volid>
4957 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4958 afs_uint32 rovolid, afs_int32 valid)
4960 int j, nro = 0, islocked = 0;
4961 struct nvldbentry entry, storeEntry, entry2;
4962 afs_int32 vcode, error = 0;
4965 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4968 " Could not lock the VLDB entry for the volume %lu \n",
4969 (unsigned long)volid);
4974 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4977 "Could not fetch the VLDB entry for volume number %lu \n",
4978 (unsigned long)volid);
4982 if (!ISNAMEVALID(entry.name)) {
4984 "Volume name %s is too long, rename before adding site\n",
4986 error = VOLSERBADOP;
4989 MapHostToNetwork(&entry);
4991 /* See if it's too many entries */
4992 if (entry.nServers >= NMAXNSERVERS) {
4993 fprintf(STDERR, "Total number of entries will exceed %u\n",
4995 error = VOLSERBADOP;
4999 /* See if it's on the same server */
5000 for (j = 0; j < entry.nServers; j++) {
5001 if (entry.serverFlags[j] & VLSF_ROVOL) {
5003 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5006 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5009 MapPartIdIntoName(entry.serverPartition[j], apartName);
5011 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5013 error = VOLSERBADOP;
5020 /* See if it's too many RO sites - leave one for the RW */
5021 if (nro >= NMAXNSERVERS - 1) {
5022 fprintf(STDERR, "Total number of sites will exceed %u\n",
5024 error = VOLSERBADOP;
5028 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5029 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5030 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5033 if (entry.volumeId[ROVOL] == INVALID_BID) {
5034 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5036 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5039 VPRINT1("Using RO volume id %d.\n", rovolid);
5040 entry.volumeId[ROVOL] = rovolid;
5042 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5043 rovolid, entry.volumeId[ROVOL]);
5047 VPRINT("Adding a new site ...");
5048 entry.serverNumber[entry.nServers] = server;
5049 entry.serverPartition[entry.nServers] = part;
5051 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5053 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5057 MapNetworkToHost(&entry, &storeEntry);
5059 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5060 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5062 fprintf(STDERR, "Could not update entry for volume %lu \n",
5063 (unsigned long)volid);
5072 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5073 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5076 "Could not release lock on volume entry for %lu \n",
5077 (unsigned long)volid);
5078 PrintError("", vcode);
5082 PrintError("", error);
5086 /*removes <server> <part> as read only site for <volid> from the vldb */
5088 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5091 struct nvldbentry entry, storeEntry;
5093 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5095 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5096 (unsigned long)volid);
5097 PrintError("", vcode);
5100 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5103 "Could not fetch the entry for volume number %lu from VLDB \n",
5104 (unsigned long)volid);
5105 PrintError("", vcode);
5108 MapHostToNetwork(&entry);
5109 if (!Lp_ROMatch(server, part, &entry)) {
5110 /*this site doesnot exist */
5111 fprintf(STDERR, "This site is not a replication site \n");
5113 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5114 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5116 fprintf(STDERR, "Could not update entry for volume %lu \n",
5117 (unsigned long)volid);
5118 PrintError("", vcode);
5119 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5120 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5124 } else { /*remove the rep site */
5125 Lp_SetROValue(&entry, server, part, 0, 0);
5127 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5128 entry.flags &= ~VLF_ROEXISTS;
5129 if (entry.nServers < 1) { /*this is the last ref */
5130 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5132 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5135 "Could not delete VLDB entry for volume %lu \n",
5136 (unsigned long)volid);
5137 PrintError("", vcode);
5142 MapNetworkToHost(&entry, &storeEntry);
5143 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5144 (unsigned long)volid);
5147 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5148 LOCKREL_OPCODE | LOCKREL_AFSID |
5152 "Could not release lock on volume entry for %lu \n",
5153 (unsigned long)volid);
5154 PrintError("", vcode);
5155 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5156 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5159 fprintf(STDOUT, " done\n");
5165 /*sets <server> <part> as read/write site for <volid> in the vldb */
5167 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5170 struct nvldbentry entry, storeEntry;
5173 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5175 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5176 (unsigned long)volid);
5177 PrintError("", vcode);
5180 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5183 "Could not fetch the entry for volume number %lu from VLDB \n",
5184 (unsigned long)volid);
5185 PrintError("", vcode);
5188 MapHostToNetwork(&entry);
5189 index = Lp_GetRwIndex(&entry);
5191 /* no RW site exists */
5192 fprintf(STDERR, "No existing RW site for volume %lu",
5193 (unsigned long)volid);
5195 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5196 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5199 "Could not release lock on entry for volume %lu \n",
5200 (unsigned long)volid);
5201 PrintError("", vcode);
5205 } else { /* change the RW site */
5206 entry.serverNumber[index] = server;
5207 entry.serverPartition[index] = part;
5208 MapNetworkToHost(&entry, &storeEntry);
5210 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5211 LOCKREL_OPCODE | LOCKREL_AFSID |
5214 fprintf(STDERR, "Could not update entry for volume %lu \n",
5215 (unsigned long)volid);
5216 PrintError("", vcode);
5217 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5218 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5226 /*list all the partitions on <aserver> */
5228 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5231 struct rx_connection *aconn;
5232 struct pIDs partIds;
5233 struct partEntries partEnts;
5237 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5239 partEnts.partEntries_len = 0;
5240 partEnts.partEntries_val = NULL;
5241 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5242 if (code == RXGEN_OPCODE) {
5243 for (i = 0; i < 26; i++) /* try old interface */
5244 partIds.partIds[i] = -1;
5245 code = AFSVolListPartitions(aconn, &partIds);
5247 for (i = 0; i < 26; i++) {
5248 if ((partIds.partIds[i]) != -1) {
5249 ptrPartList->partId[j] = partIds.partIds[i];
5250 ptrPartList->partFlags[j] = PARTVALID;
5253 ptrPartList->partFlags[i] = 0;
5258 *cntp = partEnts.partEntries_len;
5259 if (*cntp > VOLMAXPARTS) {
5261 "Warning: number of partitions on the server too high %d (process only %d)\n",
5262 *cntp, VOLMAXPARTS);
5263 *cntp = VOLMAXPARTS;
5265 for (i = 0; i < *cntp; i++) {
5266 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5267 ptrPartList->partFlags[i] = PARTVALID;
5269 free(partEnts.partEntries_val);
5275 "Could not fetch the list of partitions from the server\n");
5276 PrintError("", code);
5278 rx_DestroyConnection(aconn);
5283 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5284 This is used by the backup system */
5286 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5287 struct volDescription *volPtr, afs_int32 arraySize)
5289 struct rx_connection *aconn;
5290 struct volDescription *curPtr;
5293 afs_int32 success = 1;
5295 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5297 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5298 if (curPtr->volFlags & CLONEVALID) {
5299 curPtr->volFlags &= ~CLONEZAPPED;
5302 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5303 "clone", 0, NULL, NULL);
5308 curPtr->volFlags |= CLONEZAPPED;
5310 fprintf(STDERR, "Could not zap volume %lu\n",
5311 (unsigned long)curPtr->volCloneId);
5313 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5314 curPtr->volCloneId);
5319 rx_DestroyConnection(aconn);
5323 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5326 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5327 struct volDescription *volPtr, afs_int32 arraySize)
5329 struct rx_connection *aconn;
5330 struct volDescription *curPtr;
5333 afs_int32 rcode = 0;
5335 int reuseCloneId = 0;
5336 afs_uint32 curCloneId = 0;
5337 char cloneName[256]; /*max vol name */
5339 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5341 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5343 else { /*get a bunch of id's from vldb */
5345 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5347 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5348 PrintError("", code);
5353 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5354 if (curPtr->volFlags & ENTRYVALID) {
5356 curPtr->volFlags |= CLONEVALID;
5357 /*make a clone of curParentId and record as curPtr->volCloneId */
5359 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5362 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5365 curPtr->volFlags &= ~CLONEVALID; /* can't clone */
5369 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5370 strcpy(cloneName, curPtr->volName);
5371 strcat(cloneName, "-tmpClone-");
5373 strcpy(cloneName, "-tmpClone");
5375 curPtr->volCloneId = curCloneId;
5380 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5381 &(curPtr->volCloneId));
5383 curPtr->volFlags &= ~CLONEVALID;
5385 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5386 curPtr->volName, (unsigned long)code);
5387 code = AFSVolEndTrans(aconn, tid, &rcode);
5389 fprintf(STDERR, "WARNING: could not end transaction\n");
5392 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5393 curPtr->volCloneId);
5394 code = AFSVolEndTrans(aconn, tid, &rcode);
5395 if (code || rcode) {
5396 curPtr->volFlags &= ~CLONEVALID;
5405 rx_DestroyConnection(aconn);
5410 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5411 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5413 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5414 struct volintInfo **resultPtr, afs_int32 * size)
5416 struct rx_connection *aconn;
5418 volEntries volumeInfo;
5421 *resultPtr = (volintInfo *) 0;
5422 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5423 volumeInfo.volEntries_len = 0;
5425 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5426 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5429 "Could not fetch the list of volumes from the server\n");
5431 *resultPtr = volumeInfo.volEntries_val;
5432 *size = volumeInfo.volEntries_len;
5436 rx_DestroyConnection(aconn);
5437 PrintError("", code);
5441 /*------------------------------------------------------------------------
5442 * EXPORTED UV_XListVolumes
5445 * List the extended information for all the volumes on a particular
5446 * File Server and partition. We may either return the volume's ID
5447 * or all of its extended information.
5450 * a_serverID : Address of the File Server for which we want
5451 * extended volume info.
5452 * a_partID : Partition for which we want the extended
5454 * a_all : If non-zero, fetch ALL the volume info,
5455 * otherwise just the volume ID.
5456 * a_resultPP : Ptr to the address of the area containing
5457 * the returned volume info.
5458 * a_numEntsInResultP : Ptr for the value we set for the number of
5463 * Otherise, the return value of AFSVolXListVolumes.
5466 * This routine is closely related to UV_ListVolumes, which returns
5467 * only the standard level of detail on AFS volumes. It is a
5468 * heavyweight operation, zipping through all the volume entries for
5469 * a given server/partition.
5473 *------------------------------------------------------------------------*/
5476 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5477 struct volintXInfo **a_resultPP,
5478 afs_int32 * a_numEntsInResultP)
5480 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5481 afs_int32 code; /*Error code to return */
5482 volXEntries volumeXInfo; /*Area for returned extended vol info */
5485 * Set up our error code and the area for returned extended volume info.
5486 * We set the val field to a null pointer as a hint for the stub to
5489 *a_numEntsInResultP = 0;
5490 *a_resultPP = (volintXInfo *) 0;
5491 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5492 volumeXInfo.volXEntries_len = 0;
5495 * Bind to the Volume Server port on the File Server machine in question,
5498 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5499 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5501 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5504 * We got the info; pull out the pointer to where the results lie
5505 * and how many entries are there.
5507 *a_resultPP = volumeXInfo.volXEntries_val;
5508 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5512 * If we got an Rx connection, throw it away.
5515 rx_DestroyConnection(rxConnP);
5517 PrintError("", code);
5519 } /*UV_XListVolumes */
5521 /* get all the information about volume <volid> on <aserver> and <apart> */
5523 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5524 struct volintInfo **resultPtr)
5526 struct rx_connection *aconn;
5528 volEntries volumeInfo;
5530 *resultPtr = (volintInfo *) 0;
5531 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5532 volumeInfo.volEntries_len = 0;
5534 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5535 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5538 "Could not fetch the information about volume %lu from the server\n",
5539 (unsigned long)volid);
5541 *resultPtr = volumeInfo.volEntries_val;
5546 rx_DestroyConnection(aconn);
5547 PrintError("", code);
5551 /*------------------------------------------------------------------------
5552 * EXPORTED UV_XListOneVolume
5555 * List the extended information for a volume on a particular File
5556 * Server and partition.
5559 * a_serverID : Address of the File Server for which we want
5560 * extended volume info.
5561 * a_partID : Partition for which we want the extended
5563 * a_volID : Volume ID for which we want the info.
5564 * a_resultPP : Ptr to the address of the area containing
5565 * the returned volume info.
5569 * Otherise, the return value of AFSVolXListOneVolume.
5572 * This routine is closely related to UV_ListOneVolume, which returns
5573 * only the standard level of detail on the chosen AFS volume.
5577 *------------------------------------------------------------------------*/
5580 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5581 struct volintXInfo **a_resultPP)
5583 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5584 afs_int32 code; /*Error code */
5585 volXEntries volumeXInfo; /*Area for returned info */
5588 * Set up our error code, and the area we're in which we are returning
5589 * the info. Setting the val field to a null pointer tells the stub
5590 * to allocate space for us.
5592 *a_resultPP = (volintXInfo *) 0;
5593 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5594 volumeXInfo.volXEntries_len = 0;
5597 * Bind to the Volume Server port on the File Server machine in question,
5600 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5601 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5604 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5607 * We got the info; pull out the pointer to where the results lie.
5609 *a_resultPP = volumeXInfo.volXEntries_val;
5612 * If we got an Rx connection, throw it away.
5615 rx_DestroyConnection(rxConnP);
5617 PrintError("", code);
5622 * Given a volume we read from a partition, check if it is
5623 * represented in the VLDB correctly.
5625 * The VLDB is looked up by the RW volume id (not its name).
5626 * The RW contains the true name of the volume (BK and RO set
5627 * the name in the VLDB only on creation of the VLDB entry).
5628 * We want rules strict enough that when we check all volumes
5629 * on one partition, it does not need to be done again. IE:
5630 * two volumes on different partitions won't constantly
5631 * change a VLDB entry away from what the other set.
5632 * For RW and BK volumes, we will always check the VLDB to see
5633 * if the two exist on the server/partition. May seem redundant,
5634 * but this is an easy check of the VLDB. IE: if the VLDB entry
5635 * says the BK exists but no BK volume is there, we will detect
5636 * this when we check the RW volume.
5637 * VLDB entries are locked only when a change needs to be done.
5638 * Output changed to look a lot like the "vos syncserv" otuput.
5641 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5642 afs_int32 * modentry, afs_uint32 * maxvolid,
5643 struct nvldbentry *aentry)
5647 afs_int32 code, error = 0;
5648 struct nvldbentry entry, storeEntry;
5650 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5660 ((volumeinfo->type ==
5661 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5664 /* Check to see if the VLDB is ok without locking it (pass 1).
5665 * If it will change, then lock the VLDB entry, read it again,
5666 * then make the changes to it (pass 2).
5669 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5671 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5672 (unsigned long)rwvolid);
5677 createentry = 0; /* Do we need to create a VLDB entry */
5678 addvolume = 0; /* Add this volume to the VLDB entry */
5679 modified = 0; /* The VLDB entry was modified */
5682 memcpy(&entry, aentry, sizeof(entry));
5684 /* Read the entry from VLDB by its RW volume id */
5685 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5687 if (code != VL_NOENT) {
5689 "Could not retrieve the VLDB entry for volume %lu \n",
5690 (unsigned long)rwvolid);
5694 memset(&entry, 0, sizeof(entry));
5695 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5699 MapHostToNetwork(&entry);
5703 if (verbose && (pass == 1)) {
5704 fprintf(STDOUT, "_______________________________\n");
5705 fprintf(STDOUT, "\n-- status before -- \n");
5707 fprintf(STDOUT, "\n**does not exist**\n");
5709 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
5710 || (entry.flags & VLF_BACKEXISTS))
5711 EnumerateEntry(&entry);
5713 fprintf(STDOUT, "\n");
5716 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5722 /* Check existence of RW and BK volumes */
5723 code = CheckVldbRWBK(&entry, &mod);
5729 idx = Lp_GetRwIndex(&entry);
5730 if (idx == -1) { /* RW index not found in the VLDB entry */
5731 idx = entry.nServers; /* put it into next index */
5734 } else { /* RW index found in the VLDB entry. */
5735 /* Verify if this volume's location matches where the VLDB says it is */
5736 if (!Lp_Match(aserver, apart, &entry)) {
5737 if (entry.flags & VLF_RWEXISTS) {
5738 /* The RW volume exists elsewhere - report this one a duplicate */
5740 MapPartIdIntoName(apart, pname);
5742 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5743 (unsigned long)rwvolid,
5745 afs_inet_ntoa_r(aserver, hoststr) :
5746 hostutil_GetNameByINet(aserver), pname);
5747 MapPartIdIntoName(entry.serverPartition[idx],
5750 " VLDB reports RW volume %lu exists on %s %s\n",
5751 (unsigned long)rwvolid,
5753 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5754 hostutil_GetNameByINet(entry.
5759 /* The RW volume does not exist - have VLDB point to this one */
5762 /* Check for orphaned BK volume on old partition */
5763 if (entry.flags & VLF_BACKEXISTS) {
5765 MapPartIdIntoName(entry.serverPartition[idx],
5768 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5769 entry.volumeId[BACKVOL],
5771 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5772 hostutil_GetNameByINet(entry.
5775 MapPartIdIntoName(apart, pname);
5777 " VLDB reports its RW volume %lu exists on %s %s\n",
5778 (unsigned long)rwvolid,
5780 afs_inet_ntoa_r(aserver, hoststr) :
5781 hostutil_GetNameByINet(aserver),
5787 /* Volume location matches the VLDB location */
5788 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5789 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5792 (entry.name, volumeinfo->name,
5793 VOLSER_OLDMAXVOLNAME) != 0)) {
5801 entry.flags |= VLF_RWEXISTS;
5802 entry.volumeId[RWVOL] = rwvolid;
5803 if (!entry.volumeId[BACKVOL])
5804 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5805 if (!entry.volumeId[ROVOL])
5806 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5808 entry.serverFlags[idx] = VLSF_RWVOL;
5809 entry.serverNumber[idx] = aserver;
5810 entry.serverPartition[idx] = apart;
5811 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5815 /* One last check - to update BK if need to */
5816 code = CheckVldbRWBK(&entry, &mod);
5824 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5830 /* Check existence of RW and BK volumes */
5831 code = CheckVldbRWBK(&entry, &mod);
5837 idx = Lp_GetRwIndex(&entry);
5838 if (idx == -1) { /* RW index not found in the VLDB entry */
5839 idx = entry.nServers; /* Put it into next index */
5842 } else { /* RW index found in the VLDB entry */
5843 /* Verify if this volume's location matches where the VLDB says it is */
5844 if (!Lp_Match(aserver, apart, &entry)) {
5845 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5847 MapPartIdIntoName(apart, pname);
5849 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5850 (unsigned long)volumeinfo->volid,
5852 afs_inet_ntoa_r(aserver, hoststr) :
5853 hostutil_GetNameByINet(aserver), pname);
5854 MapPartIdIntoName(entry.serverPartition[idx], pname);
5856 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5857 (unsigned long)rwvolid,
5859 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5860 hostutil_GetNameByINet(entry.
5865 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5866 if (!(entry.flags & VLF_BACKEXISTS)) {
5868 } else if (volumeinfo->volid >
5869 entry.volumeId[BACKVOL]) {
5873 MapPartIdIntoName(entry.serverPartition[idx],
5876 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5877 entry.volumeId[BACKVOL],
5879 afs_inet_ntoa_r(aserver, hoststr) :
5880 hostutil_GetNameByINet(aserver),
5883 " VLDB reports its BK volume ID is %lu\n",
5884 (unsigned long)volumeinfo->volid);
5888 MapPartIdIntoName(entry.serverPartition[idx],
5891 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5892 (unsigned long)volumeinfo->volid,
5894 afs_inet_ntoa_r(aserver, hoststr) :
5895 hostutil_GetNameByINet(aserver),
5898 " VLDB reports its BK volume ID is %u\n",
5899 entry.volumeId[BACKVOL]);
5902 } else if (!entry.volumeId[BACKVOL]) {
5909 entry.flags |= VLF_BACKEXISTS;
5910 entry.volumeId[RWVOL] = rwvolid;
5911 entry.volumeId[BACKVOL] = volumeinfo->volid;
5913 entry.serverNumber[idx] = aserver;
5914 entry.serverPartition[idx] = apart;
5915 entry.serverFlags[idx] = VLSF_RWVOL;
5921 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5922 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5923 /* This is a quick check to see if the RO entry exists in the
5924 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5925 * RO volume listed in the VLDB exists).
5927 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5929 idx = entry.nServers;
5933 if (!(entry.flags & VLF_ROEXISTS)) {
5938 /* Before we correct the VLDB entry, make sure all the
5939 * ROs listed in the VLDB exist.
5941 code = CheckVldbRO(&entry, &mod);
5947 if (!(entry.flags & VLF_ROEXISTS)) {
5948 /* No RO exists in the VLDB entry - add this one */
5949 idx = entry.nServers;
5952 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5953 /* The volume headers's RO ID does not match that in the VLDB entry,
5954 * and the vol hdr's ID is greater (implies more recent). So delete
5955 * all the RO volumes listed in VLDB entry and add this volume.
5957 for (j = 0; j < entry.nServers; j++) {
5958 if (entry.serverFlags[j] & VLSF_ROVOL) {
5959 /* Verify this volume exists and print message we are orphaning it */
5961 MapPartIdIntoName(apart, pname);
5963 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5964 entry.volumeId[ROVOL],
5966 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5967 hostutil_GetNameByINet(entry.
5971 " VLDB reports its RO volume ID is %lu\n",
5972 (unsigned long)volumeinfo->volid);
5975 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5976 entry.serverPartition[idx], 0L, 0L);
5983 idx = entry.nServers;
5986 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5987 /* The volume headers's RO ID does not match that in the VLDB entry,
5988 * and the vol hdr's ID is lower (implies its older). So orphan it.
5991 MapPartIdIntoName(apart, pname);
5993 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5994 (unsigned long)volumeinfo->volid,
5996 afs_inet_ntoa_r(aserver, hoststr) :
5997 hostutil_GetNameByINet(aserver), pname);
5999 " VLDB reports its RO volume ID is %u\n",
6000 entry.volumeId[ROVOL]);
6003 /* The RO volume ID in the volume header match that in the VLDB entry,
6004 * and there exist RO volumes in the VLDB entry. See if any of them
6005 * are this one. If not, then we add it.
6007 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6009 idx = entry.nServers;
6017 entry.flags |= VLF_ROEXISTS;
6018 entry.volumeId[RWVOL] = rwvolid;
6019 entry.volumeId[ROVOL] = volumeinfo->volid;
6021 entry.serverNumber[idx] = aserver;
6022 entry.serverPartition[idx] = apart;
6023 entry.serverFlags[idx] = VLSF_ROVOL;
6029 /* Remember largest volume id */
6030 if (entry.volumeId[ROVOL] > *maxvolid)
6031 *maxvolid = entry.volumeId[ROVOL];
6032 if (entry.volumeId[BACKVOL] > *maxvolid)
6033 *maxvolid = entry.volumeId[BACKVOL];
6034 if (entry.volumeId[RWVOL] > *maxvolid)
6035 *maxvolid = entry.volumeId[RWVOL];
6037 if (modified && doit) {
6038 MapNetworkToHost(&entry, &storeEntry);
6041 code = VLDB_CreateEntry(&storeEntry);
6044 "Could not create a VLDB entry for the volume %lu\n",
6045 (unsigned long)rwvolid);
6052 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6053 LOCKREL_OPCODE | LOCKREL_AFSID |
6056 fprintf(STDERR, "Could not update entry for %lu\n",
6057 (unsigned long)rwvolid);
6061 } else if (pass == 2) {
6063 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6064 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6066 PrintError("Could not unlock VLDB entry ", code);
6070 if (modified && modentry) {
6075 memcpy(aentry, &entry, sizeof(entry));
6079 fprintf(STDOUT, "-- status after --\n");
6081 EnumerateEntry(&entry);
6083 fprintf(STDOUT, "\n**no change**\n");
6087 VPRINT("\n_______________________________\n");
6092 sortVolumes(const void *a, const void *b)
6094 volintInfo *v1 = (volintInfo *) a;
6095 volintInfo *v2 = (volintInfo *) b;
6096 afs_uint32 rwvolid1, rwvolid2;
6098 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6099 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6101 if (rwvolid1 > rwvolid2)
6102 return -1; /* lower RW id goes first */
6103 if (rwvolid1 < rwvolid2)
6106 if (v1->type == RWVOL)
6107 return -1; /* RW vols go first */
6108 if (v2->type == RWVOL)
6111 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6112 return -1; /* BK vols next */
6113 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6116 if (v1->volid < v2->volid)
6117 return 1; /* larger volids first */
6118 if (v1->volid > v2->volid)
6124 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6125 * Synchronize an individual volume against a sever and partition.
6126 * Checks the VLDB entry (similar to syncserv) as well as checks
6127 * if the volume exists on specified servers (similar to syncvldb).
6130 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6132 struct rx_connection *aconn = 0;
6133 afs_int32 j, k, code, vcode, error = 0;
6135 afs_int32 mod, modified = 0, deleted = 0;
6136 struct nvldbentry vldbentry;
6137 afs_uint32 volumeid = 0;
6138 volEntries volumeInfo;
6139 struct partList PartList;
6141 afs_uint32 maxvolid = 0;
6143 volumeInfo.volEntries_val = (volintInfo *) 0;
6144 volumeInfo.volEntries_len = 0;
6146 /* Turn verbose logging off and do our own verbose logging */
6147 /* tverbose must be set before we call ERROR_EXIT() */
6154 if (!aserver && (flags & 1)) {
6155 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6159 /* Read the VLDB entry */
6160 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6161 if (vcode && (vcode != VL_NOENT)) {
6162 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6165 } else if (!vcode) {
6166 MapHostToNetwork(&vldbentry);
6170 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6171 fprintf(STDOUT, "_______________________________\n");
6172 fprintf(STDOUT, "\n-- status before -- \n");
6174 fprintf(STDOUT, "\n**does not exist**\n");
6176 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6177 || (vldbentry.flags & VLF_BACKEXISTS))
6178 EnumerateEntry(&vldbentry);
6180 fprintf(STDOUT, "\n");
6183 /* Verify that all of the VLDB entries exist on the repective servers
6184 * and partitions (this does not require that avolname be a volume ID).
6185 * Equivalent to a syncserv.
6188 /* Tell CheckVldb not to update if appropriate */
6193 code = CheckVldb(&vldbentry, &mod, &deleted);
6195 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6203 /* If aserver is given, we will search for the desired volume on it */
6205 /* Generate array of partitions on the server that we will check */
6207 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6210 "Could not fetch the list of partitions from the server\n");
6214 PartList.partId[0] = apart;
6218 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6220 /* If a volume ID were given, search for it on each partition */
6221 if ((volumeid = atol(avolname))) {
6222 for (j = 0; j < pcnt; j++) {
6224 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6227 if (code != ENODEV) {
6228 fprintf(STDERR, "Could not query server\n");
6236 /* Found one, sync it with VLDB entry */
6238 CheckVolume(volumeInfo.volEntries_val, aserver,
6239 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6246 if (volumeInfo.volEntries_val)
6247 free(volumeInfo.volEntries_val);
6248 volumeInfo.volEntries_val = (volintInfo *) 0;
6249 volumeInfo.volEntries_len = 0;
6253 /* Check to see if the RW, BK, and RO IDs exist on any
6254 * partitions. We get the volume IDs from the VLDB.
6256 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6257 if (vldbentry.volumeId[j] == 0)
6260 for (k = 0; k < pcnt; k++) { /* For each partition */
6261 volumeInfo.volEntries_val = (volintInfo *) 0;
6262 volumeInfo.volEntries_len = 0;
6264 AFSVolListOneVolume(aconn, PartList.partId[k],
6265 vldbentry.volumeId[j], &volumeInfo);
6267 if (code != ENODEV) {
6268 fprintf(STDERR, "Could not query server\n");
6276 /* Found one, sync it with VLDB entry */
6278 CheckVolume(volumeInfo.volEntries_val, aserver,
6279 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6286 if (volumeInfo.volEntries_val)
6287 free(volumeInfo.volEntries_val);
6288 volumeInfo.volEntries_val = (volintInfo *) 0;
6289 volumeInfo.volEntries_len = 0;
6295 /* If verbose output, print a summary of what changed */
6297 fprintf(STDOUT, "-- status after --\n");
6299 fprintf(STDOUT, "\n**entry deleted**\n");
6300 } else if (modified) {
6301 EnumerateEntry(&vldbentry);
6303 fprintf(STDOUT, "\n**no change**\n");
6305 fprintf(STDOUT, "\n_______________________________\n");
6309 /* Now check if the maxvolid is larger than that stored in the VLDB */
6311 afs_uint32 maxvldbid = 0;
6312 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6315 "Could not get the highest allocated volume id from the VLDB\n");
6318 } else if (maxvolid > maxvldbid) {
6320 id = maxvolid - maxvldbid + 1;
6321 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6324 "Error in increasing highest allocated volume id in VLDB\n");
6334 fprintf(STDOUT, "...error encountered");
6336 fprintf(STDOUT, "...done entry\n");
6339 rx_DestroyConnection(aconn);
6340 if (volumeInfo.volEntries_val)
6341 free(volumeInfo.volEntries_val);
6343 PrintError("", error);
6348 * Synchronise vldb with the file server <aserver> and,
6349 * optionally, <apart>.
6352 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6354 struct rx_connection *aconn;
6355 afs_int32 code, error = 0;
6358 volEntries volumeInfo;
6359 struct partList PartList;
6363 afs_int32 failures = 0, modifications = 0, tentries = 0;
6365 afs_uint32 maxvolid = 0;
6368 volumeInfo.volEntries_val = (volintInfo *) 0;
6369 volumeInfo.volEntries_len = 0;
6371 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6373 /* Generate array of partitions to check */
6375 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6378 "Could not fetch the list of partitions from the server\n");
6382 PartList.partId[0] = apart;
6386 VPRINT("Processing volume entries ...\n");
6388 /* Step through the array of partitions */
6389 for (i = 0; i < pcnt; i++) {
6390 apart = PartList.partId[i];
6391 MapPartIdIntoName(apart, pname);
6393 volumeInfo.volEntries_val = (volintInfo *) 0;
6394 volumeInfo.volEntries_len = 0;
6395 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6398 "Could not fetch the list of volumes from the server\n");
6402 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6403 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6404 sizeof(volintInfo), sortVolumes);
6407 for (vi = volumeInfo.volEntries_val, j = 0;
6408 j < volumeInfo.volEntries_len; j++, vi++) {
6416 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6417 j + 1, vi->name, (unsigned long)vi->volid,
6419 afs_inet_ntoa_r(aserver, hoststr) :
6420 hostutil_GetNameByINet(aserver), pname);
6428 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6430 PrintError("", code);
6433 } else if (modified) {
6439 fprintf(STDOUT, "...error encountered\n\n");
6441 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6448 "Could not process entries on server %s partition %s\n",
6450 afs_inet_ntoa_r(aserver, hoststr) :
6451 hostutil_GetNameByINet(aserver), pname);
6453 if (volumeInfo.volEntries_val) {
6454 free(volumeInfo.volEntries_val);
6455 volumeInfo.volEntries_val = 0;
6458 } /* thru all partitions */
6461 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6462 tentries, failures, modifications);
6464 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6465 tentries, failures, modifications);
6469 /* Now check if the maxvolid is larger than that stored in the VLDB */
6471 afs_uint32 maxvldbid = 0;
6472 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6475 "Could not get the highest allocated volume id from the VLDB\n");
6478 } else if (maxvolid > maxvldbid) {
6480 id = maxvolid - maxvldbid + 1;
6481 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6484 "Error in increasing highest allocated volume id in VLDB\n");
6492 rx_DestroyConnection(aconn);
6493 if (volumeInfo.volEntries_val)
6494 free(volumeInfo.volEntries_val);
6495 PrintError("", error);
6500 * Determine if a volume exists on a server and partition.
6501 * Try creating a transaction on the volume. If we can,
6502 * the volume exists, if not, then return the error code.
6503 * Some error codes mean the volume is unavailable but
6504 * still exists - so we catch these error codes.
6507 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6509 struct rx_connection *conn = (struct rx_connection *)0;
6510 afs_int32 code = -1;
6511 volEntries volumeInfo;
6513 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6515 volumeInfo.volEntries_val = (volintInfo *) 0;
6516 volumeInfo.volEntries_len = 0;
6517 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6518 if (volumeInfo.volEntries_val)
6519 free(volumeInfo.volEntries_val);
6520 if (code == VOLSERILLEGAL_PARTITION)
6522 rx_DestroyConnection(conn);
6531 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6535 afs_int32 code, error = 0;
6541 idx = Lp_GetRwIndex(entry);
6543 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6546 if (idx == -1) { /* Did not find a RW entry */
6547 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6548 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6553 VolumeExists(entry->serverNumber[idx],
6554 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6555 if (code == 0) { /* RW volume exists */
6556 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6557 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6560 } else if (code == ENODEV) { /* RW volume does not exist */
6561 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6562 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6566 /* If VLDB says it didn't exist, then ignore error */
6567 if (entry->flags & VLF_RWEXISTS) {
6568 MapPartIdIntoName(entry->serverPartition[idx], pname);
6570 "Transaction call failed for RW volume %u on server %s %s\n",
6571 entry->volumeId[RWVOL],
6573 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6574 hostutil_GetNameByINet(entry->serverNumber[idx]),
6581 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6582 * flag accordingly. idx already ponts to the RW entry.
6584 if (idx == -1) { /* Did not find a RW entry */
6585 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6586 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6589 } else { /* Found a RW entry */
6591 VolumeExists(entry->serverNumber[idx],
6592 entry->serverPartition[idx],
6593 entry->volumeId[BACKVOL]);
6594 if (code == 0) { /* BK volume exists */
6595 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6596 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6599 } else if (code == ENODEV) { /* BK volume does not exist */
6600 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6601 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6605 /* If VLDB says it didn't exist, then ignore error */
6606 if (entry->flags & VLF_BACKEXISTS) {
6607 MapPartIdIntoName(entry->serverPartition[idx], pname);
6609 "Transaction call failed for BK volume %u on server %s %s\n",
6610 entry->volumeId[BACKVOL],
6612 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6613 hostutil_GetNameByINet(entry->serverNumber[idx]),
6620 /* If there is an idx but the BK and RW volumes no
6621 * longer exist, then remove the RW entry.
6623 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6624 && !(entry->flags & VLF_BACKEXISTS)) {
6625 Lp_SetRWValue(entry, entry->serverNumber[idx],
6626 entry->serverPartition[idx], 0L, 0L);
6633 *modified = modentry;
6638 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6641 int foundro = 0, modentry = 0;
6642 afs_int32 code, error = 0;
6649 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6652 for (idx = 0; idx < entry->nServers; idx++) {
6653 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6654 continue; /* not a RO */
6658 VolumeExists(entry->serverNumber[idx],
6659 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6660 if (code == 0) { /* RO volume exists */
6662 } else if (code == ENODEV) { /* RW volume does not exist */
6663 Lp_SetROValue(entry, entry->serverNumber[idx],
6664 entry->serverPartition[idx], 0L, 0L);
6669 MapPartIdIntoName(entry->serverPartition[idx], pname);
6671 "Transaction call failed for RO %u on server %s %s\n",
6672 entry->volumeId[ROVOL],
6674 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6675 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6680 if (foundro) { /* A RO volume exists */
6681 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6682 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6685 } else { /* A RO volume does not exist */
6686 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6687 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
6694 *modified = modentry;
6699 * Ensure that <entry> matches with the info on file servers
6702 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6704 afs_int32 code, error = 0;
6705 struct nvldbentry storeEntry;
6706 int islocked = 0, mod, modentry, delentry = 0;
6707 int pass = 0, doit=1;
6715 fprintf(STDOUT, "_______________________________\n");
6716 fprintf(STDOUT, "\n-- status before -- \n");
6717 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
6718 || (entry->flags & VLF_BACKEXISTS))
6719 EnumerateEntry(entry);
6720 fprintf(STDOUT, "\n");
6723 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6724 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6725 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6729 /* Check to see if the VLDB is ok without locking it (pass 1).
6730 * If it will change, then lock the VLDB entry, read it again,
6731 * then make the changes to it (pass 2).
6735 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6738 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6739 entry->volumeId[RWVOL]);
6744 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6746 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6750 MapHostToNetwork(entry);
6756 /* Check if the RW and BK entries are ok */
6757 code = CheckVldbRWBK(entry, &mod);
6760 if (mod && (pass == 1) && doit)
6765 /* Check if the RO volumes entries are ok */
6766 code = CheckVldbRO(entry, &mod);
6769 if (mod && (pass == 1) && doit)
6774 /* The VLDB entry has been updated. If it as been modified, then
6775 * write the entry back out the the VLDB.
6777 if (modentry && doit) {
6781 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
6782 && !(entry->flags & VLF_ROEXISTS) && doit) {
6783 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6785 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6789 "Could not delete VLDB entry for volume %u \n",
6790 entry->volumeId[RWVOL]);
6795 /* Replace old entry with our new one */
6796 MapNetworkToHost(entry, &storeEntry);
6798 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6799 (LOCKREL_OPCODE | LOCKREL_AFSID |
6800 LOCKREL_TIMESTAMP));
6802 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6803 entry->volumeId[RWVOL]);
6810 if (modified && modentry) {
6813 if (deleted && delentry) {
6818 fprintf(STDOUT, "-- status after --\n");
6820 fprintf(STDOUT, "\n**entry deleted**\n");
6822 EnumerateEntry(entry);
6824 fprintf(STDOUT, "\n**no change**\n");
6828 VPRINT("\n_______________________________\n");
6832 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6834 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6837 "Could not release lock on VLDB entry for volume %u\n",
6838 entry->volumeId[RWVOL]);
6847 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6850 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6852 struct rx_connection *aconn;
6853 afs_int32 code, error = 0;
6854 afs_int32 nentries, tentries = 0;
6855 struct VldbListByAttributes attributes;
6856 nbulkentries arrayEntries;
6857 afs_int32 failures = 0, modified, modifications = 0;
6858 struct nvldbentry *vlentry;
6859 afs_int32 si, nsi, j;
6864 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6866 /* Set up attributes to search VLDB */
6867 memset(&attributes, 0, sizeof(attributes));
6868 attributes.server = ntohl(aserver);
6869 attributes.Mask = VLLIST_SERVER;
6871 attributes.partition = apart;
6872 attributes.Mask |= VLLIST_PARTITION;
6875 VPRINT("Processing VLDB entries ...\n");
6877 /* While we need to collect more VLDB entries */
6878 for (si = 0; si != -1; si = nsi) {
6879 memset(&arrayEntries, 0, sizeof(arrayEntries));
6881 /* Collect set of VLDB entries */
6883 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6884 &arrayEntries, &nsi);
6885 if (code == RXGEN_OPCODE) {
6886 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6890 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6893 tentries += nentries;
6895 for (j = 0; j < nentries; j++) {
6896 vlentry = &arrayEntries.nbulkentries_val[j];
6897 MapHostToNetwork(vlentry);
6899 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6901 /* Tell CheckVldb not to update if appropriate */
6906 code = CheckVldb(vlentry, &modified, NULL);
6908 PrintError("", code);
6910 "Could not process VLDB entry for volume %s\n",
6913 } else if (modified) {
6919 fprintf(STDOUT, "...error encountered\n\n");
6921 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6926 if (arrayEntries.nbulkentries_val) {
6927 free(arrayEntries.nbulkentries_val);
6928 arrayEntries.nbulkentries_val = 0;
6933 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6934 tentries, failures, modifications);
6936 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6937 tentries, failures, modifications);
6942 rx_DestroyConnection(aconn);
6943 if (arrayEntries.nbulkentries_val)
6944 free(arrayEntries.nbulkentries_val);
6947 error = VOLSERFAILEDOP;
6951 /*rename volume <oldname> to <newname>, changing the names of the related
6952 *readonly and backup volumes. This operation is also idempotent.
6953 *salvager is capable of recovering from rename operation stopping halfway.
6954 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6956 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6958 struct nvldbentry storeEntry;
6959 afs_int32 vcode, code, rcode, error;
6961 char nameBuffer[256];
6963 struct rx_connection *aconn;
6968 aconn = (struct rx_connection *)0;
6972 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6975 " Could not lock the VLDB entry for the volume %u \n",
6976 entry->volumeId[RWVOL]);
6983 * Match the flags we just set via SetLock,
6984 * so we don't invalidate our compare below.
6986 entry->flags &= ~VLOP_ALLOPERS;
6987 entry->flags |= VLOP_ADDSITE;
6990 * Now get the entry again (under lock) and
6991 * verify the volume hasn't otherwise changed.
6993 vcode = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, &storeEntry);
6996 "Could not obtain the VLDB entry for the volume %u\n",
6997 entry->volumeId[RWVOL]);
7001 /* Convert to net order to match entry, which was passed in net order. */
7002 MapHostToNetwork(&storeEntry);
7003 if (memcmp(entry, &storeEntry, sizeof(*entry)) != 0) {
7005 "VLDB entry for volume %u has changed; "
7006 "please reissue the command.\n",
7007 entry->volumeId[RWVOL]);
7008 error = VL_BADENTRY; /* an arbitrary choice, but closest to the truth */
7012 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7013 /* Note that we are reusing storeEntry. */
7014 MapNetworkToHost(entry, &storeEntry);
7015 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7017 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7018 entry->volumeId[RWVOL]);
7022 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7023 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7024 * is concerned, oldname is lost */
7025 if (entry->flags & VLF_RWEXISTS) {
7026 index = Lp_GetRwIndex(entry);
7027 if (index == -1) { /* there is a serious discrepancy */
7029 "There is a serious discrepancy in VLDB entry for volume %u\n",
7030 entry->volumeId[RWVOL]);
7031 fprintf(STDERR, "try building VLDB from scratch\n");
7032 error = VOLSERVLDB_ERROR;
7035 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7037 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7038 entry->serverPartition[index], ITOffline, &tid);
7039 if (code) { /*volume doesnot exist */
7041 "Could not start transaction on the rw volume %u\n",
7042 entry->volumeId[RWVOL]);
7045 } else { /*volume exists, process it */
7048 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7049 entry->volumeId[RWVOL],
7050 entry->volumeId[ROVOL],
7051 entry->volumeId[BACKVOL]);
7053 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7054 code = AFSVolEndTrans(aconn, tid, &rcode);
7058 "Could not end transaction on volume %s %u\n",
7059 entry->name, entry->volumeId[RWVOL]);
7064 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7065 entry->name, entry->volumeId[RWVOL]);
7071 rx_DestroyConnection(aconn);
7072 aconn = (struct rx_connection *)0;
7074 /*end rw volume processing */
7075 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7076 index = Lp_GetRwIndex(entry);
7077 if (index == -1) { /* there is a serious discrepancy */
7079 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7080 entry->volumeId[BACKVOL]);
7081 fprintf(STDERR, "try building VLDB from scratch\n");
7082 error = VOLSERVLDB_ERROR;
7085 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7087 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7088 entry->serverPartition[index], ITOffline, &tid);
7089 if (code) { /*volume doesnot exist */
7091 "Could not start transaction on the backup volume %u\n",
7092 entry->volumeId[BACKVOL]);
7095 } else { /*volume exists, process it */
7096 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7098 "Volume name %s.backup exceeds the limit of %u characters\n",
7099 newname, VOLSER_OLDMAXVOLNAME);
7103 strcpy(nameBuffer, newname);
7104 strcat(nameBuffer, ".backup");
7107 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7108 entry->volumeId[RWVOL], 0, 0);
7110 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7111 code = AFSVolEndTrans(aconn, tid, &rcode);
7115 "Could not end transaction on the backup volume %u\n",
7116 entry->volumeId[BACKVOL]);
7122 "Could not set parameters on the backup volume %u\n",
7123 entry->volumeId[BACKVOL]);
7128 } /* end backup processing */
7130 rx_DestroyConnection(aconn);
7131 aconn = (struct rx_connection *)0;
7132 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7133 for (i = 0; i < entry->nServers; i++) {
7134 if (entry->serverFlags[i] & VLSF_ROVOL) {
7135 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7137 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7138 entry->serverPartition[i], ITOffline,
7140 if (code) { /*volume doesnot exist */
7142 "Could not start transaction on the ro volume %u\n",
7143 entry->volumeId[ROVOL]);
7146 } else { /*volume exists, process it */
7147 strcpy(nameBuffer, newname);
7148 strcat(nameBuffer, ".readonly");
7149 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7151 "Volume name %s exceeds the limit of %u characters\n",
7152 nameBuffer, VOLSER_OLDMAXVOLNAME);
7157 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7158 entry->volumeId[RWVOL], 0, 0);
7160 VPRINT2("Renamed RO volume %s on host %s\n",
7163 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7164 hostutil_GetNameByINet(entry->
7166 code = AFSVolEndTrans(aconn, tid, &rcode);
7170 "Could not end transaction on volume %u\n",
7171 entry->volumeId[ROVOL]);
7177 "Could not set parameters on the ro volume %u\n",
7178 entry->volumeId[ROVOL]);
7184 rx_DestroyConnection(aconn);
7185 aconn = (struct rx_connection *)0;
7192 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7194 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7197 "Could not unlock the VLDB entry for the volume %s %u\n",
7198 entry->name, entry->volumeId[RWVOL]);
7204 code = AFSVolEndTrans(aconn, tid, &rcode);
7208 fprintf(STDERR, "Failed to end transaction on a volume \n");
7214 rx_DestroyConnection(aconn);
7215 PrintError("", error);
7220 /*report on all the active transactions on volser */
7222 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7224 struct rx_connection *aconn;
7225 transDebugEntries transInfo;
7228 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7229 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7230 transInfo.transDebugEntries_len = 0;
7231 code = AFSVolMonitor(aconn, &transInfo);
7234 "Could not access status information about the server\n");
7235 PrintError("", code);
7236 if (transInfo.transDebugEntries_val)
7237 free(transInfo.transDebugEntries_val);
7239 rx_DestroyConnection(aconn);
7242 *rcount = transInfo.transDebugEntries_len;
7243 *rpntr = transInfo.transDebugEntries_val;
7245 rx_DestroyConnection(aconn);
7252 /*delete the volume without interacting with the vldb */
7254 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7257 struct rx_connection *aconn;
7259 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7260 error = DoVolDelete(aconn, volid, part,
7261 "the", 0, NULL, NULL);
7262 if (error == VNOVOL) {
7263 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7266 PrintError("", error);
7268 rx_DestroyConnection(aconn);
7273 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7274 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7276 struct rx_connection *conn = 0;
7278 afs_int32 code, error = 0, rcode;
7280 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7282 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7286 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7288 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7292 code = AFSVolSetFlags(conn, tid, setflag);
7294 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7299 #ifdef AFS_PTHREAD_ENV
7302 IOMGR_Sleep(sleeptime);
7309 code = AFSVolEndTrans(conn, tid, &rcode);
7310 if (code || rcode) {
7311 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7313 error = (code ? code : rcode);
7318 rx_DestroyConnection(conn);
7323 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7326 struct rx_connection *conn = 0;
7328 afs_int32 code, error = 0, rcode;
7330 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7332 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7336 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7338 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7342 code = AFSVolSetInfo(conn, tid, infop);
7344 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7351 code = AFSVolEndTrans(conn, tid, &rcode);
7352 if (code || rcode) {
7353 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7355 error = (code ? code : rcode);
7360 rx_DestroyConnection(conn);
7365 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7366 afs_int32 fromdate, struct volintSize *vol_size)
7368 struct rx_connection *aconn = (struct rx_connection *)0;
7369 afs_int32 tid = 0, rcode = 0;
7370 afs_int32 code, error = 0;
7373 /* get connections to the servers */
7374 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7376 VPRINT1("Starting transaction on volume %u...", afromvol);
7377 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7378 EGOTO1(error_exit, code,
7379 "Could not start transaction on the volume %u to be measured\n",
7383 VPRINT1("Getting size of volume on volume %u...", afromvol);
7384 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7385 EGOTO(error_exit, code, "Could not start the measurement process \n");
7390 VPRINT1("Ending transaction on volume %u...", afromvol);
7391 code = AFSVolEndTrans(aconn, tid, &rcode);
7392 if (code || rcode) {
7393 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7395 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7397 error = (code ? code : rcode);
7402 rx_DestroyConnection(aconn);
7404 PrintError("", error);
7408 /*maps the host addresses in <old > (present in network byte order) to
7409 that in< new> (present in host byte order )*/
7411 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7415 memset(new, 0, sizeof(struct nvldbentry));
7417 /*copy all the fields */
7418 strcpy(new->name, old->name);
7419 /* new->volumeType = old->volumeType;*/
7420 new->nServers = old->nServers;
7421 count = old->nServers;
7422 if (count < NMAXNSERVERS)
7424 for (i = 0; i < count; i++) {
7425 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7426 new->serverPartition[i] = old->serverPartition[i];
7427 new->serverFlags[i] = old->serverFlags[i];
7429 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7430 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7431 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7432 new->cloneId = old->cloneId;
7433 new->flags = old->flags;
7436 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7438 MapHostToNetwork(struct nvldbentry *entry)
7442 count = entry->nServers;
7443 if (count < NMAXNSERVERS)
7445 for (i = 0; i < count; i++) {
7446 entry->serverNumber[i] = htonl(entry->serverNumber[i]);