2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
17 #include <sys/statfs.h>
21 #include <afs/voldefs.h>
24 #include <rx/rx_queue.h>
25 #include <afs/vlserver.h>
27 #include <afs/cellconfig.h>
30 #include <afs/afsint.h>
34 #include <afs/com_err.h>
36 #include <afs/kautils.h>
38 #include <afs/ihandle.h>
40 #include <afs/ntops.h>
42 #include <afs/vnode.h>
43 #include <afs/volume.h>
44 #define ERRCODE_RANGE 8 /* from error_table.h */
45 #define CLOCKSKEW 2 /* not really skew, but resolution */
46 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
48 /* for UV_MoveVolume() recovery */
52 #include "volser_internal.h"
53 #include "volser_prototypes.h"
54 #include "vsutils_prototypes.h"
55 #include "lockprocs_prototypes.h"
57 extern struct ubik_client *cstruct;
58 int verbose = 0, noresolve = 0;
63 afs_int32 vldbEntryIndex;
66 /* Utility macros used by rest of this source file */
67 #define EPRINT(ec, es) \
69 fprintf(STDERR, "\n"); \
70 fprintf(STDERR, (es)); \
74 #define EPRINT1(ec, es, ep1) \
76 fprintf(STDERR, "\n"); \
77 fprintf(STDERR, (es), (ep1)); \
81 #define EPRINT2(ec, es, ep1, ep2) \
83 fprintf(STDERR, "\n"); \
84 fprintf(STDERR, (es), (ep1), (ep2)); \
88 #define EPRINT3(ec, es, ep1, ep2, ep3) \
90 fprintf(STDERR, "\n"); \
91 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
95 #define EGOTO(where, ec, es) \
104 #define EGOTO1(where, ec, es, ep1) \
107 EPRINT1((ec),(es),(ep1)); \
113 #define EGOTO2(where, ec, es, ep1, ep2) \
116 EPRINT2((ec),(es),(ep1),(ep2)); \
122 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
125 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
132 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
133 #define VPRINT1(es, p) \
134 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
135 #define VPRINT2(es, p1, p2) \
136 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
137 #define VPRINT3(es, p1, p2, p3) \
138 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
140 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
141 #define VEPRINT(es) \
142 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
143 #define VEPRINT1(es, p) \
144 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
145 #define VEPRINT2(es, p1, p2) \
146 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
147 #define VEPRINT3(es, p1, p2, p3) \
148 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
150 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
154 /* getting rid of this */
155 #define ERROR_EXIT(code) do { \
161 /* Protos for static routines */
163 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
164 afs_int32 apart, afs_uint32 okvol,
167 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
168 struct rx_connection **connPtr, afs_int32 * transPtr,
169 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
170 afs_int32 *origflags, afs_uint32 tmpVolId);
171 static int SimulateForwardMultiple(struct rx_connection *fromconn,
172 afs_int32 fromtid, afs_int32 fromdate,
173 manyDests * tr, afs_int32 flags,
174 void *cookie, manyResults * results);
175 static int DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
176 afs_int32 apart, int type, afs_uint32 cloneid,
177 char *typestring, char *pname, char *vname, char *suffix,
178 struct volser_status *volstatus, afs_int32 *transPtr);
179 static int DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
180 afs_int32 apart, char *typestring, afs_uint32 atoserver,
181 struct volser_status *volstatus, char *pprefix);
182 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
183 afs_int32 apart, afs_int32 * modentry,
184 afs_uint32 * maxvolid, struct nvldbentry *aentry);
185 static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition,
186 afs_uint32 volumeid);
187 static afs_int32 CheckVldbRWBK(struct nvldbentry * entry,
188 afs_int32 * modified);
189 static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified);
190 static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified,
192 static void dump_sig_handler(int x);
193 static int sortVolumes(const void *a, const void *b);
196 /*map the partition <partId> into partition name <partName>*/
198 MapPartIdIntoName(afs_int32 partId, char *partName)
200 if (partId < 26) { /* what if partId > = 26 ? */
201 strcpy(partName, "/vicep");
202 partName[6] = partId + 'a';
205 } else if (partId < VOLMAXPARTS) {
206 strcpy(partName, "/vicep");
208 partName[6] = 'a' + (partId / 26);
209 partName[7] = 'a' + (partId % 26);
216 PrintError(char *msg, afs_int32 errcode)
218 fprintf(STDERR, "%s", msg);
219 /*replace by a big switch statement */
224 fprintf(STDERR, "Possible communication failure\n");
227 fprintf(STDERR, "Volume needs to be salvaged\n");
230 fprintf(STDERR, "Bad vnode number quoted\n");
234 "Volume not attached, does not exist, or not on line\n");
237 fprintf(STDERR, "Volume already exists\n");
240 fprintf(STDERR, "Volume is not in service\n");
243 fprintf(STDERR, "Volume is off line\n");
246 fprintf(STDERR, "Volume is already on line\n");
249 fprintf(STDERR, "Partition is full\n");
252 fprintf(STDERR, "Volume max quota exceeded\n");
255 fprintf(STDERR, "Volume temporarily unavailable\n");
258 fprintf(STDERR, "Volume has moved to another server\n");
261 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
264 fprintf(STDERR, "VLDB: a read terminated too early\n");
267 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
270 fprintf(STDERR, "VLDB: internal creation failure\n");
273 fprintf(STDERR, "VLDB: no such entry\n");
276 fprintf(STDERR, "VLDB: vldb database is empty\n");
279 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
282 fprintf(STDERR, "VLDB: volume name is illegal\n");
285 fprintf(STDERR, "VLDB: index was out of range\n");
288 fprintf(STDERR, "VLDB: bad volume type\n");
291 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
293 case VL_BADPARTITION:
294 fprintf(STDERR, "VLDB: bad partition number\n");
297 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
300 fprintf(STDERR, "VLDB: no such repsite server exists\n");
302 case VL_DUPREPSERVER:
303 fprintf(STDERR, "VLDB: replication site server already exists\n");
306 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
309 fprintf(STDERR, "VLDB: illegal reference count number\n");
311 case VL_SIZEEXCEEDED:
312 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
315 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
317 case VL_BADVOLIDBUMP:
318 fprintf(STDERR, "VLDB: illegal max volid increment\n");
320 case VL_IDALREADYHASHED:
321 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
324 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
327 fprintf(STDERR, "VLDB: bad volume operation code\n");
329 case VL_BADRELLOCKTYPE:
330 fprintf(STDERR, "VLDB: bad release lock type\n");
333 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
335 case VL_BADSERVERFLAG:
336 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
339 fprintf(STDERR, "VLDB: no permission access for call\n");
341 case VOLSERREAD_DUMPERROR:
343 "VOLSER: Problems encountered in reading the dump file !\n");
345 case VOLSERDUMPERROR:
346 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
348 case VOLSERATTACH_ERROR:
349 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
351 case VOLSERDETACH_ERROR:
352 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
354 case VOLSERILLEGAL_PARTITION:
355 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
357 case VOLSERBAD_ACCESS:
358 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
360 case VOLSERVLDB_ERROR:
361 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
364 fprintf(STDERR, "VOLSER: error in volume name\n");
367 fprintf(STDERR, "VOLSER: volume has moved\n");
370 fprintf(STDERR, "VOLSER: illegal operation\n");
372 case VOLSERBADRELEASE:
373 fprintf(STDERR, "VOLSER: release could not be completed\n");
376 fprintf(STDERR, "VOLSER: volume is busy\n");
378 case VOLSERNO_MEMORY:
379 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
383 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
385 case VOLSERMULTIRWVOL:
387 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
391 "VOLSER: not all entries were successfully processed\n");
395 initialize_RXK_error_table();
396 initialize_KTC_error_table();
397 initialize_ACFG_error_table();
398 initialize_VL_error_table();
400 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
401 afs_error_message(errcode));
408 void init_volintInfo(struct volintInfo *vinfo) {
409 memset(vinfo, 0, sizeof(struct volintInfo));
411 vinfo->maxquota = -1;
413 vinfo->creationDate = -1;
414 vinfo->updateDate = -1;
422 static struct rx_securityClass *uvclass = 0;
423 static int uvindex = -1;
424 /* called by VLDBClient_Init to set the security module to be used in the RPC */
426 UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
433 /* bind to volser on <port> <aserver> */
434 /* takes server address in network order, port in host order. dumb */
435 struct rx_connection *
436 UV_Bind(afs_uint32 aserver, afs_int32 port)
438 struct rx_connection *tc;
440 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
446 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
447 afs_int32 partition, char *name, afs_int32 type,
448 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
453 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
455 if (code != VOLSERVOLBUSY)
458 #ifdef AFS_PTHREAD_ENV
461 IOMGR_Sleep(3-retries);
468 AFSVolTransCreate_retry(struct rx_connection *z_conn,
469 afs_int32 volume, afs_int32 partition,
470 afs_int32 flags, afs_int32 * trans)
475 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
476 if (code != VOLSERVOLBUSY)
479 #ifdef AFS_PTHREAD_ENV
482 IOMGR_Sleep(3-retries);
489 /* if <okvol> is allright(indicated by beibg able to
490 * start a transaction, delete the <delvol> */
492 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
493 afs_uint32 okvol, afs_uint32 delvol)
495 afs_int32 error, code, tid, rcode;
500 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
503 code = AFSVolDeleteVolume(aconn, tid);
506 code = AFSVolEndTrans(aconn, tid, &rcode);
513 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
515 code = AFSVolEndTrans(aconn, tid, &rcode);
520 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
523 code = AFSVolDeleteVolume(aconn, tid);
526 code = AFSVolEndTrans(aconn, tid, &rcode);
539 /* called by EmuerateEntry, show vldb entry in a reasonable format */
541 SubEnumerateEntry(struct nvldbentry *entry)
549 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
550 if (entry->flags & VLF_RWEXISTS)
551 fprintf(STDOUT, " valid \n");
553 fprintf(STDOUT, " invalid \n");
554 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
555 if (entry->flags & VLF_ROEXISTS)
556 fprintf(STDOUT, " valid \n");
558 fprintf(STDOUT, " invalid \n");
559 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
560 if (entry->flags & VLF_BACKEXISTS)
561 fprintf(STDOUT, " valid \n");
563 fprintf(STDOUT, " invalid \n");
564 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
565 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
567 if (entry->flags & VLF_RWEXISTS)
568 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
569 if (entry->flags & VLF_ROEXISTS)
570 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
571 if (entry->flags & VLF_BACKEXISTS)
572 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
573 if ((entry->cloneId != 0) && (entry->flags & VLF_ROEXISTS))
574 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
575 fprintf(STDOUT, "\n");
577 fprintf(STDOUT, " number of sites -> %lu\n",
578 (unsigned long)entry->nServers);
579 for (i = 0; i < entry->nServers; i++) {
580 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
583 for (i = 0; i < entry->nServers; i++) {
584 MapPartIdIntoName(entry->serverPartition[i], pname);
585 fprintf(STDOUT, " server %s partition %s ",
586 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
587 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
588 if (entry->serverFlags[i] & VLSF_RWVOL)
589 fprintf(STDOUT, "RW Site ");
591 fprintf(STDOUT, "RO Site ");
593 if (entry->serverFlags[i] & VLSF_NEWREPSITE)
594 fprintf(STDOUT," -- New release");
596 if (!(entry->serverFlags[i] & VLSF_RWVOL))
597 fprintf(STDOUT," -- Old release");
599 if (entry->serverFlags[i] & VLSF_DONTUSE)
600 fprintf(STDOUT, " -- Not released");
602 fprintf(STDOUT, "\n");
609 /*enumerate the vldb entry corresponding to <entry> */
611 EnumerateEntry(struct nvldbentry *entry)
614 fprintf(STDOUT, "\n");
615 fprintf(STDOUT, "%s \n", entry->name);
616 SubEnumerateEntry(entry);
620 /* forcibly remove a volume. Very dangerous call */
622 UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
624 struct rx_connection *tconn;
627 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
629 code = AFSVolNukeVolume(tconn, partid, volid);
630 rx_DestroyConnection(tconn);
636 /* like df. Return usage of <pname> on <server> in <partition> */
638 UV_PartitionInfo64(afs_uint32 server, char *pname,
639 struct diskPartition64 *partition)
641 struct rx_connection *aconn;
644 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
645 code = AFSVolPartitionInfo64(aconn, pname, partition);
646 if (code == RXGEN_OPCODE) {
647 struct diskPartition *dpp = malloc(sizeof(struct diskPartition));
648 code = AFSVolPartitionInfo(aconn, pname, dpp);
650 strncpy(partition->name, dpp->name, 32);
651 strncpy(partition->devName, dpp->devName, 32);
652 partition->lock_fd = dpp->lock_fd;
653 partition->free = dpp->free;
654 partition->minFree = dpp->minFree;
659 fprintf(STDERR, "Could not get information on partition %s\n", pname);
660 PrintError("", code);
663 rx_DestroyConnection(aconn);
667 /* old interface to create volumes */
669 UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
674 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
678 /* less old interface to create volumes */
680 UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
681 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
682 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
684 afs_uint32 roid = 0, bkid = 0;
685 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
686 aspare3, aspare4, anewid, &roid, &bkid);
690 * Create a volume on the given server and partition
692 * @param aserver server to create volume on
693 * @param spart partition to create volume on
694 * @param aname name of new volume
695 * @param aquota quota for new volume
696 * @param anewid contains the desired volume id for the new volume. If
697 * *anewid == 0, a new id will be chosen, and will be placed
698 * in *anewid when UV_CreateVolume3 returns.
699 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
700 * will be unset. If *aroid == 0, an id will be chosen, and
701 * will be placed in *anewid when UV_CreateVolume3 returns.
702 * @param abkid same as aroid, except for the BK volume id instead of the
704 * @return 0 on success, error code otherwise.
707 UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
708 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
709 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
710 afs_uint32 * aroid, afs_uint32 * abkid)
712 struct rx_connection *aconn;
716 afs_int32 rcode, vcode;
718 struct nvldbentry entry, storeEntry; /*the new vldb entry */
719 struct volintInfo tstatus;
724 memset(&storeEntry, 0, sizeof(struct nvldbentry));
726 init_volintInfo(&tstatus);
727 tstatus.maxquota = aquota;
729 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
731 if (aroid && *aroid) {
732 VPRINT1("Using RO volume ID %d.\n", *aroid);
734 if (abkid && *abkid) {
735 VPRINT1("Using BK volume ID %d.\n", *abkid);
739 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
741 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
744 VPRINT1("Using volume ID %d.\n", *anewid);
746 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
747 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
749 if (aroid && *aroid == 0) {
750 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
751 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
754 if (abkid && *abkid == 0) {
755 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
756 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
760 /* rw,ro, bk id are related in the default case */
761 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
763 if (aroid && *aroid != 0) {
764 lastid = max(lastid, *aroid);
766 if (abkid && *abkid != 0) {
767 lastid = max(lastid, *abkid);
769 if (aroid && *aroid == 0) {
772 if (abkid && *abkid == 0) {
777 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
778 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
781 code = AFSVolSetInfo(aconn, tid, &tstatus);
783 EPRINT(code, "Could not change quota, continuing...\n");
785 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
786 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
789 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
791 /* set up the vldb entry for this volume */
792 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
794 entry.serverNumber[0] = aserver; /* this should have another
795 * level of indirection later */
796 entry.serverPartition[0] = apart; /* this should also have
797 * another indirection level */
798 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
799 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
800 entry.volumeId[RWVOL] = *anewid;
801 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
802 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
804 /*map into right byte order, before passing to xdr, the stuff has to be in host
805 * byte order. Xdr converts it into network order */
806 MapNetworkToHost(&entry, &storeEntry);
807 /* create the vldb entry */
808 vcode = VLDB_CreateEntry(&storeEntry);
811 "Could not create a VLDB entry for the volume %s %lu\n",
812 aname, (unsigned long)*anewid);
813 /*destroy the created volume */
814 VPRINT1("Deleting the newly created volume %u\n", *anewid);
815 AFSVolDeleteVolume(aconn, tid);
819 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
820 /* volume created, now terminate the transaction and release the connection */
821 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
822 * the volume will come online anyway when transaction timesout , so if
823 * vldb entry exists then the volume is guaranteed to exist too wrt create */
827 "Failed to end the transaction on the volume %s %lu\n", aname,
828 (unsigned long)*anewid);
835 code = AFSVolEndTrans(aconn, tid, &rcode);
837 fprintf(STDERR, "WARNING: could not end transaction\n");
840 rx_DestroyConnection(aconn);
841 PrintError("", error);
845 /* create a volume, given a server, partition number, volume name --> sends
846 * back new vol id in <anewid>*/
848 UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
851 struct rx_connection *aconn;
854 struct nvldbentry entry, storeEntry; /*the new vldb entry */
856 memset(&storeEntry, 0, sizeof(struct nvldbentry));
858 aconn = (struct rx_connection *)0;
861 /* set up the vldb entry for this volume */
862 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
864 entry.serverNumber[0] = aserver; /* this should have another
865 * level of indirection later */
866 entry.serverPartition[0] = apart; /* this should also have
867 * another indirection level */
868 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
869 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
870 entry.volumeId[RWVOL] = aid;
872 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
873 entry.volumeId[BACKVOL] = *anewid + 2;
875 entry.volumeId[ROVOL] = 0;
876 entry.volumeId[BACKVOL] = 0;
879 /*map into right byte order, before passing to xdr, the stuff has to be in host
880 * byte order. Xdr converts it into network order */
881 MapNetworkToHost(&entry, &storeEntry);
882 /* create the vldb entry */
883 vcode = VLDB_CreateEntry(&storeEntry);
886 "Could not create a VLDB entry for the volume %s %lu\n",
887 aname, (unsigned long)aid);
891 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
895 rx_DestroyConnection(aconn);
896 PrintError("", error);
900 /* Delete the volume <volid>on <aserver> <apart>
901 * the physical entry gets removed from the vldb only if the ref count
905 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
907 struct rx_connection *aconn = (struct rx_connection *)0;
909 afs_int32 code, rcode;
911 struct nvldbentry entry, storeEntry;
913 afs_int32 avoltype = -1, vtype;
914 int notondisk = 0, notinvldb = 0;
916 memset(&storeEntry, 0, sizeof(struct nvldbentry));
918 /* Find and read bhe VLDB entry for this volume */
919 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
921 if (code != VL_NOENT) {
922 EGOTO1(error_exit, code,
923 "Could not lock VLDB entry for the volume %u\n", avolid);
929 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
930 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
932 MapHostToNetwork(&entry);
935 EnumerateEntry(&entry);
938 /* Whether volume is in the VLDB or not. Delete the volume on disk */
939 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
941 code = DoVolDelete(aconn, avolid, apart, "the", 0, NULL, NULL);
951 /* Now update the VLDB entry.
952 * But first, verify we have a VLDB entry.
953 * Whether volume is on disk or not. Delete the volume in VLDB.
958 if (avolid == entry.volumeId[BACKVOL]) {
959 /* Its a backup volume, modify the VLDB entry. Check that the
960 * backup volume is on the server/partition we asked to delete.
962 if (!(entry.flags & VLF_BACKEXISTS) || !Lp_Match(aserver, apart, &entry)) {
963 notinvldb = 2; /* Not on this server and partition */
967 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
969 entry.flags &= ~VLF_BACKEXISTS;
973 else if (avolid == entry.volumeId[ROVOL]) {
974 /* Its a read-only volume, modify the VLDB entry. Check that the
975 * readonly volume is on the server/partition we asked to delete.
976 * If flags does not have RO_EIXSTS set, then this may mean the RO
977 * hasn't been released (and could exist in VLDB).
979 if (!Lp_ROMatch(aserver, apart, &entry)) {
980 notinvldb = 2; /* Not found on this server and partition */
986 "Marking the readonly volume %lu deleted in the VLDB\n",
987 (unsigned long)avolid);
989 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
991 if (!Lp_ROMatch(0, 0, &entry))
992 entry.flags &= ~VLF_ROEXISTS; /* This was the last ro volume */
996 else if (avolid == entry.volumeId[RWVOL]) {
997 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
998 * Check that the readwrite volumes is on the server/partition we
1001 if (!(entry.flags & VLF_RWEXISTS) || !Lp_Match(aserver, apart, &entry)) {
1002 notinvldb = 2; /* Not found on this server and partition */
1006 if (entry.volumeId[BACKVOL]) {
1007 /* Delete backup if it exists */
1008 code = DoVolDelete(aconn, entry.volumeId[BACKVOL], apart,
1009 "the backup", 0, NULL, NULL);
1010 if (code && code != VNOVOL) {
1018 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1019 (unsigned long)avolid,
1021 flags & VLF_BACKEXISTS) ? ", and its backup volume," :
1024 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1026 entry.flags &= ~(VLF_BACKEXISTS | VLF_RWEXISTS);
1029 if (entry.flags & VLF_ROEXISTS)
1030 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1034 notinvldb = 2; /* Not found on this server and partition */
1038 /* Either delete or replace the VLDB entry */
1039 if ((entry.nServers <= 0) || !(entry.flags & (VLF_ROEXISTS | VLF_RWEXISTS))) {
1042 "Last reference to the VLDB entry for %lu - deleting entry\n",
1043 (unsigned long)avolid);
1044 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1045 EGOTO1(error_exit, code,
1046 "Could not delete the VLDB entry for the volume %u \n",
1049 MapNetworkToHost(&entry, &storeEntry);
1051 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1052 (LOCKREL_OPCODE | LOCKREL_AFSID |
1053 LOCKREL_TIMESTAMP));
1054 EGOTO1(error_exit, code,
1055 "Could not update the VLDB entry for the volume %u \n",
1062 EPRINT(error, "\n");
1064 if (notondisk && notinvldb) {
1065 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1066 ((notinvldb == 2) ? "on server and partition" : ""));
1068 error = VOLSERNOVOL;
1069 } else if (notondisk) {
1071 "WARNING: Volume %lu did not exist on the partition\n",
1072 (unsigned long)avolid);
1073 } else if (notinvldb) {
1074 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1075 (unsigned long)avolid,
1076 ((notinvldb == 2) ? "on server and partition" : ""));
1080 code = AFSVolEndTrans(aconn, ttid, &rcode);
1081 code = (code ? code : rcode);
1083 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1084 (unsigned long)avolid);
1085 PrintError("", code);
1093 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1094 (LOCKREL_OPCODE | LOCKREL_AFSID |
1095 LOCKREL_TIMESTAMP));
1098 "Could not release the lock on the VLDB entry for the volume %u \n",
1106 rx_DestroyConnection(aconn);
1110 /* add recovery to UV_MoveVolume */
1112 #define TESTC 0 /* set to test recovery code, clear for production */
1118 do_interrupt(void * unused)
1121 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1122 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1123 * changed. This will avoid some sanity checks, but until a better way
1124 * is found, the only alternative is always crashing and burning on at
1125 * least the stack-overflow check. */
1126 lwp_cpptr->stack = NULL;
1131 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1133 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1134 fprintf(STDOUT, "enter second control-c to exit\n");
1142 sigint_handler(int x)
1144 #ifdef AFS_PTHREAD_ENV
1147 IOMGR_SoftSig(do_interrupt, 0);
1149 (void)signal(SIGINT, sigint_handler);
1153 DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
1154 afs_int32 apart, char *ptypestring, afs_uint32 atoserver,
1155 struct volser_status *volstatus, char *pprefix)
1157 afs_int32 ttid = 0, code, rcode, error = 0;
1158 char *prefix, *typestring;
1167 typestring = ptypestring;
1173 VPRINT3("%sDeleting %s volume %u ...", prefix, typestring, avolid);
1176 AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
1178 /* return early and quietly for VNOVOL; don't continue the attempt to delete. */
1179 if (code == VNOVOL) {
1184 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1188 code = AFSVolGetStatus(aconn, ttid, volstatus);
1189 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1194 AFSVolSetFlags(aconn, ttid,
1195 VTDeleteOnSalvage | VTOutOfService);
1197 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1201 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1202 AFSVolSetForwarding(aconn, ttid, atoserver);
1206 code = AFSVolDeleteVolume(aconn, ttid);
1207 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1211 code = AFSVolEndTrans(aconn, ttid, &rcode);
1216 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1217 prefix, typestring, (unsigned long)avolid);
1223 if (beverbose && !error)
1229 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1230 afs_int32 apart, int type, afs_uint32 cloneid,
1231 char *typestring, char *pname, char *vname, char *suffix,
1232 struct volser_status *volstatus, afs_int32 *transPtr)
1235 afs_int32 ttid = 0, btid = 0;
1236 afs_int32 code = 0, rcode = 0;
1237 afs_int32 error = 0;
1238 int cloneexists = 1;
1240 /* Test to see if the clone volume exists by trying to create
1241 * a transaction on the clone volume. We've assumed the clone exists.
1243 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1245 if (code != VNOVOL) {
1246 EPRINT2(code, "Could not reach the %s volume %lu\n",
1247 typestring, (unsigned long)cloneid);
1251 cloneexists = 0; /* clone volume does not exist */
1254 code = AFSVolEndTrans(aconn, btid, &rcode);
1256 if (code || rcode) {
1258 "Could not end transaction on the previous %s volume %lu\n",
1259 typestring, (unsigned long)cloneid);
1260 error = (code ? code : rcode);
1265 /* Now go ahead and try to clone the RW volume.
1266 * First start a transaction on the RW volume
1268 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1270 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1271 (unsigned long)avolid);
1276 /* Clone or reclone the volume, depending on whether the clone
1277 * volume exists or not
1280 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1282 code = AFSVolReClone(aconn, ttid, cloneid);
1284 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1285 typestring, (unsigned long)cloneid);
1290 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1293 strcpy(cname, pname);
1294 strcat(cname, suffix);
1297 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1300 fprintf(STDERR, "Failed to clone the volume %lu\n",
1301 (unsigned long)avolid);
1310 VPRINT1("Getting status of parent volume %u...", avolid);
1311 code = AFSVolGetStatus(aconn, ttid, volstatus);
1313 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1314 (unsigned long)avolid);
1323 code = AFSVolEndTrans(aconn, ttid, &rcode);
1324 if (code || rcode) {
1325 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1326 (unsigned long)avolid);
1328 error = (code ? code : rcode);
1333 code = AFSVolEndTrans(aconn, btid, &rcode);
1334 if (code || rcode) {
1336 "Could not end transaction on the %s volume %lu\n",
1337 typestring, (unsigned long)cloneid);
1339 error = (code ? code : rcode);
1345 /* Convert volume from RO to RW; adjust the VLDB entry to match.
1346 * The nvldbentry passed to us has already been MapHostToNetwork'd
1351 UV_ConvertRO(afs_uint32 server, afs_uint32 partition, afs_uint32 volid,
1352 struct nvldbentry *entry)
1354 afs_int32 code, i, same;
1355 struct nvldbentry checkEntry, storeEntry;
1357 afs_int32 rwindex = 0;
1358 afs_uint32 rwserver = 0;
1359 afs_int32 roindex = 0;
1360 afs_uint32 roserver = 0;
1361 struct rx_connection *aconn;
1363 memset(&storeEntry, 0, sizeof(struct nvldbentry));
1366 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1370 "Unable to lock volume %lu, code %d\n",
1371 (unsigned long)entry->volumeId[RWVOL],vcode);
1372 PrintError("", vcode);
1376 /* make sure the VLDB entry hasn't changed since we started */
1377 memset(&checkEntry, 0, sizeof(checkEntry));
1378 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1381 "Could not fetch the entry for volume %lu from VLDB\n",
1382 (unsigned long)volid);
1383 PrintError("convertROtoRW ", vcode);
1388 MapHostToNetwork(&checkEntry);
1389 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1390 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1391 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1393 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1394 (unsigned long)volid);
1399 /* extract information from the original entry */
1400 for (i = 0; i < entry->nServers; i++) {
1401 if (entry->serverFlags[i] & VLSF_RWVOL) {
1403 rwserver = entry->serverNumber[i];
1404 /* rwpartition = entry->serverPartition[i]; */
1407 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1408 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1411 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1418 roserver = entry->serverNumber[i];
1419 /* ropartition = entry->serverPartition[i]; */
1426 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1427 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1430 "Converting RO volume %lu to RW volume failed with code %d\n",
1431 (unsigned long)volid, code);
1432 PrintError("convertROtoRW ", code);
1435 /* Update the VLDB to match what we did on disk as much as possible. */
1436 /* If the converted RO was in the VLDB, make it look like the new RW. */
1438 entry->serverFlags[roindex] = VLSF_RWVOL;
1440 /* Add a new site entry for the newly created RW. It's possible
1441 * (but unlikely) that we are already at MAXNSERVERS and that this
1442 * new site will invalidate the whole VLDB entry; however,
1443 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1444 * so we need no extra guard logic here.
1446 afs_int32 newrwindex = entry->nServers;
1447 (entry->nServers)++;
1448 entry->serverNumber[newrwindex] = server;
1449 entry->serverPartition[newrwindex] = partition;
1450 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1452 entry->flags |= VLF_RWEXISTS;
1453 entry->flags &= ~VLF_BACKEXISTS;
1455 /* if the old RW was in the VLDB, remove it by decrementing the number */
1456 /* of servers, replacing the RW entry with the last entry, and zeroing */
1457 /* out the last entry. */
1459 (entry->nServers)--;
1460 if (rwindex != entry->nServers) {
1461 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1462 entry->serverPartition[rwindex] =
1463 entry->serverPartition[entry->nServers];
1464 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1465 entry->serverNumber[entry->nServers] = 0;
1466 entry->serverPartition[entry->nServers] = 0;
1467 entry->serverFlags[entry->nServers] = 0;
1470 entry->flags &= ~VLF_ROEXISTS;
1471 for (i = 0; i < entry->nServers; i++) {
1472 if (entry->serverFlags[i] & VLSF_ROVOL) {
1473 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1474 entry->flags |= VLF_ROEXISTS;
1477 MapNetworkToHost(entry, &storeEntry);
1479 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1480 (LOCKREL_OPCODE | LOCKREL_AFSID |
1481 LOCKREL_TIMESTAMP));
1484 "Warning: volume converted, but vldb update failed with code %d!\n",
1489 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1492 "Unable to unlock volume %lu, code %d\n",
1493 (unsigned long)entry->volumeId[RWVOL],vcode);
1494 PrintError("", vcode);
1500 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1501 * <atopart>. The operation is almost idempotent. The following
1502 * flags are recognized:
1504 * RV_NOCLONE - don't use a copy clone
1508 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1509 afs_uint32 atoserver, afs_int32 atopart, int flags)
1511 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1512 * be changing during the move */
1513 struct rx_connection * volatile toconn;
1514 struct rx_connection * volatile fromconn;
1515 afs_int32 volatile fromtid;
1516 afs_int32 volatile totid;
1517 afs_int32 volatile clonetid;
1518 afs_uint32 volatile newVol;
1519 afs_uint32 volatile volid;
1520 afs_uint32 volatile backupId;
1521 int volatile islocked;
1526 char tmpName[VOLSER_MAXVOLNAME + 1];
1531 struct restoreCookie cookie;
1532 afs_int32 vcode, code;
1533 struct volser_status tstatus;
1534 struct destServer destination;
1536 struct nvldbentry entry, storeEntry;
1539 char in, lf; /* for test code */
1543 #ifdef ENABLE_BUGFIX_1165
1544 volEntries volumeInfo;
1545 struct volintInfo *infop = 0;
1549 fromconn = (struct rx_connection *)0;
1550 toconn = (struct rx_connection *)0;
1560 /* support control-c processing */
1563 (void)signal(SIGINT, sigint_handler);
1567 "\nThere are three tests points - verifies all code paths through recovery.\n");
1568 fprintf(STDOUT, "First test point - operation not started.\n");
1569 fprintf(STDOUT, "...test here (y, n)? ");
1571 if (fscanf(stdin, "%c", &in) < 1)
1573 if (fscanf(stdin, "%c", &lf) < 0) {
1574 /* toss away; don't care */
1577 fprintf(STDOUT, "type control-c\n");
1579 fprintf(stdout, ".");
1584 /* or drop through */
1587 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1588 EGOTO1(mfail, vcode,
1589 "Could not fetch the entry for the volume %u from the VLDB \n",
1592 if (entry.volumeId[RWVOL] != afromvol) {
1593 fprintf(STDERR, "Only RW volume can be moved\n");
1597 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1598 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1601 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1602 EGOTO1(mfail, vcode,
1603 "Could not fetch the entry for the volume %u from the VLDB \n",
1606 backupId = entry.volumeId[BACKVOL];
1607 MapHostToNetwork(&entry);
1609 if (!Lp_Match(afromserver, afrompart, &entry)) {
1610 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1611 if (!Lp_Match(atoserver, atopart, &entry)) {
1612 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1613 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1614 (unsigned long)afromvol);
1615 fprintf(STDERR, "The current site is :");
1616 for (i = 0; i < entry.nServers; i++) {
1617 if (entry.serverFlags[i] == VLSF_RWVOL) {
1619 MapPartIdIntoName(entry.serverPartition[i], pname);
1620 fprintf(STDERR, " server %s partition %s \n",
1621 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1622 hostutil_GetNameByINet(entry.serverNumber[i]),
1627 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1628 (LOCKREL_OPCODE | LOCKREL_AFSID |
1629 LOCKREL_TIMESTAMP));
1630 EGOTO1(mfail, vcode,
1631 " Could not release lock on the VLDB entry for the volume %u \n",
1634 return VOLSERVOLMOVED;
1637 /* delete the volume afromvol on src_server */
1638 /* from-info does not exist but to-info does =>
1639 * we have already done the move, but the volume
1640 * may still be existing physically on from fileserver
1642 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1645 code = DoVolDelete(fromconn, afromvol, afrompart,
1646 "leftover", 0, NULL, NULL);
1647 if (code && code != VNOVOL) {
1652 code = DoVolDelete(fromconn, backupId, afrompart,
1653 "leftover backup", 0, NULL, NULL);
1654 if (code && code != VNOVOL) {
1664 /* From-info matches the vldb info about volid,
1665 * its ok start the move operation, the backup volume
1666 * on the old site is deleted in the process
1668 if (afrompart == atopart) {
1669 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1670 EGOTO2(mfail, error,
1671 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1672 afromserver, error);
1675 EGOTO1(mfail, VOLSERVOLMOVED,
1676 "Warning: Moving volume %u to its home partition ignored!\n",
1682 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1683 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1684 totid = 0; /* initialize to uncreated */
1687 * clone the read/write volume locally.
1690 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1691 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1693 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1697 if (!(flags & RV_NOCLONE)) {
1698 /* Get a clone id */
1699 VPRINT1("Allocating new volume id for clone of volume %u ...",
1702 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1704 EGOTO1(mfail, vcode,
1705 "Could not get an ID for the clone of volume %u from the VLDB\n",
1709 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1710 VPRINT1("Cloning source volume %u ...", afromvol);
1711 strcpy(vname, "move-clone-temp");
1713 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1715 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1720 /* lookup the name of the volume we just cloned */
1722 code = AFSVolGetName(fromconn, fromtid, &volName);
1723 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1726 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1728 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1733 "Failed to end the transaction on the source volume %u\n",
1738 * Create the destination volume
1741 if (!(flags & RV_NOCLONE)) {
1742 /* All of this is to get the fromDate */
1743 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1746 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1750 "Failed to start a transaction on the cloned volume%u\n",
1754 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1756 AFSVolSetFlags(fromconn, clonetid,
1757 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1758 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1762 /* remember time from which we've dumped the volume */
1763 VPRINT1("Getting status of cloned volume %u ...", newVol);
1764 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1766 "Failed to get the status of the cloned volume %u\n",
1770 fromDate = CLOCKADJ(tstatus.creationDate);
1772 /* With RV_NOCLONE, just do a full copy from the source */
1777 #ifdef ENABLE_BUGFIX_1165
1779 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1780 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1781 * don't use this information...
1783 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1784 volumeInfo.volEntries_len = 0;
1785 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1787 "Failed to get the volint Info of the cloned volume %u\n",
1790 infop = (volintInfo *) volumeInfo.volEntries_val;
1791 infop->maxquota = -1; /* Else it will replace the default quota */
1792 infop->creationDate = -1; /* Else it will use the source creation date */
1793 infop->updateDate = -1; /* Else it will use the source update date */
1796 /* create a volume on the target machine */
1798 code = DoVolDelete(toconn, volid, atopart,
1799 "pre-existing destination", 0, NULL, NULL);
1800 if (code && code != VNOVOL) {
1805 VPRINT1("Creating the destination volume %u ...", volid);
1809 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1813 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1817 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1821 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1823 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1825 "Failed to set the flags on the destination volume %u\n", volid);
1829 * Now dump the clone to the new volume
1832 destination.destHost = ntohl(atoserver);
1833 destination.destPort = AFSCONF_VOLUMEPORT;
1834 destination.destSSID = 1;
1836 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1837 cookie.type = RWVOL;
1838 cookie.parent = entry.volumeId[RWVOL];
1841 if (!(flags & RV_NOCLONE)) {
1842 /* Copy the clone to the new volume */
1843 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1846 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1848 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1851 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1852 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1857 "Failed to end the transaction on the cloned volume %u\n",
1863 * reattach to the main-line volume, and incrementally dump it.
1866 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1868 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1871 "Failed to create a transaction on the source volume %u\n",
1875 /* now do the incremental */
1877 ("Doing the%s dump from source to destination for volume %u ... ",
1878 (flags & RV_NOCLONE) ? "" : " incremental",
1881 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1884 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1885 (flags & RV_NOCLONE) ? "" : " incremental");
1888 /* now adjust the flags so that the new volume becomes official */
1889 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1890 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1892 "Failed to set the flags to make old source volume offline\n");
1895 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1896 code = AFSVolSetFlags(toconn, totid, 0);
1898 "Failed to set the flags to make new source volume online\n");
1901 #ifdef ENABLE_BUGFIX_1165
1902 VPRINT1("Setting volume status on destination volume %u ...", volid);
1903 code = AFSVolSetInfo(toconn, totid, infop);
1905 "Failed to set volume status on the destination volume %u\n",
1910 /* put new volume online */
1911 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1912 code = AFSVolEndTrans(toconn, totid, &rcode);
1917 "Failed to end the transaction on the volume %u on the new site\n",
1921 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1922 MapNetworkToHost(&entry, &storeEntry);
1923 storeEntry.flags &= ~VLF_BACKEXISTS;
1927 "Second test point - operation in progress but not complete.\n");
1928 fprintf(STDOUT, "...test here (y, n)? ");
1930 if (fscanf(stdin, "%c", &in) < 1)
1932 if (fscanf(stdin, "%c", &lf) < 0) {
1933 /* toss away, don't care */
1936 fprintf(STDOUT, "type control-c\n");
1938 fprintf(stdout, ".");
1943 /* or drop through */
1946 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1948 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1949 (LOCKREL_OPCODE | LOCKREL_AFSID |
1950 LOCKREL_TIMESTAMP));
1953 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1954 storeEntry.name, (unsigned long)afromvol);
1963 "Third test point - operation complete but no cleanup.\n");
1964 fprintf(STDOUT, "...test here (y, n)? ");
1966 if (fscanf(stdin, "%c", &in) < 1)
1968 if (fscanf(stdin, "%c", &lf) < 0) {
1969 /* toss away; don't care */
1972 fprintf(STDOUT, "type control-c\n");
1974 fprintf(stdout, ".");
1979 /* or drop through */
1982 /* This is tricky. File server is very stupid, and if you mark the volume
1983 * as VTOutOfService, it may mark the *good* instance (if you're moving
1984 * between partitions on the same machine) as out of service. Since
1985 * we're cleaning this code up in DEcorum, we're just going to kludge around
1986 * it for now by removing this call. */
1987 /* already out of service, just zap it now */
1989 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1992 "Failed to set the flags to make the old source volume offline\n");
1996 if (atoserver != afromserver) {
1997 /* set forwarding pointer for moved volumes */
1998 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1999 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
2001 "Failed to set the forwarding pointer for the volume %u\n",
2006 VPRINT1("Deleting old volume %u on source ...", afromvol);
2007 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
2008 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
2012 VPRINT1("Ending transaction on old volume %u on the source ...",
2014 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2019 "Failed to end the transaction on the old volume %u on the source\n",
2023 code = DoVolDelete(fromconn, backupId, afrompart,
2024 "source backup", 0, NULL, NULL);
2025 if (code && code != VNOVOL) {
2030 code = 0; /* no backup volume? that's okay */
2033 if (!(flags & RV_NOCLONE)) {
2034 code = DoVolDelete(fromconn, newVol, afrompart,
2035 "cloned", 0, NULL, NULL);
2036 if (code && code != VNOVOL) {
2041 code = 0; /* clone missing? that's okay */
2048 fprintf(STDOUT, "Fourth test point - operation complete.\n");
2049 fprintf(STDOUT, "...test here (y, n)? ");
2051 if (fscanf(stdin, "%c", &in) < 1)
2053 if (fscanf(stdin, "%c", &lf) < 0) { /* toss away */
2057 fprintf(STDOUT, "type control-c\n");
2059 fprintf(stdout, ".");
2064 /* or drop through */
2067 /* normal cleanup code */
2069 if (entry.flags & VLF_ROEXISTS)
2070 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
2073 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
2075 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2076 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2080 " Could not release the lock on the VLDB entry for the volume %lu \n",
2081 (unsigned long)afromvol);
2089 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2091 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2092 if (code || rcode) {
2095 "Could not end transaction on the source volume %lu\n",
2096 (unsigned long)afromvol);
2098 error = (code ? code : rcode);
2104 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2105 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2106 if (code || rcode) {
2109 "Could not end transaction on the source's clone volume %lu\n",
2110 (unsigned long)newVol);
2112 error = (code ? code : rcode);
2118 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2120 code = AFSVolEndTrans(toconn, totid, &rcode);
2124 "Could not end transaction on destination volume %lu\n",
2125 (unsigned long)afromvol);
2127 error = (code ? code : rcode);
2133 #ifdef ENABLE_BUGFIX_1165
2138 rx_DestroyConnection(fromconn);
2140 rx_DestroyConnection(toconn);
2141 PrintError("", error);
2144 /* come here only when the sky falls */
2149 "vos move: operation interrupted, cleanup in progress...\n");
2150 fprintf(STDOUT, "clear transaction contexts\n");
2154 /* unlock VLDB entry */
2156 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2157 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2158 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2164 VPRINT("Recovery: Ending transaction on clone volume ...");
2165 AFSVolEndTrans(fromconn, clonetid, &rcode);
2169 VPRINT("Recovery: Ending transaction on destination volume ...");
2170 AFSVolEndTrans(toconn, totid, &rcode);
2173 if (fromtid) { /* put it on-line */
2174 VPRINT("Recovery: Setting volume flags on source volume ...");
2175 AFSVolSetFlags(fromconn, fromtid, 0);
2178 VPRINT("Recovery: Ending transaction on source volume ...");
2179 AFSVolEndTrans(fromconn, fromtid, &rcode);
2183 VPRINT("Recovery: Accessing VLDB.\n");
2184 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2186 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2190 MapHostToNetwork(&entry);
2192 /* Delete either the volume on the source location or the target location.
2193 * If the vldb entry still points to the source location, then we know the
2194 * volume move didn't finish so we remove the volume from the target
2195 * location. Otherwise, we remove the volume from the source location.
2197 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2200 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2204 if (volid && toconn) {
2205 code = DoVolDelete(toconn, volid, atopart,
2206 "destination", 0, NULL, "Recovery:");
2207 if (code == VNOVOL) {
2208 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2212 /* put source volume on-line */
2214 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2218 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2224 VPRINT1("Recovery: Setting flags on source volume %u ...",
2226 AFSVolSetFlags(fromconn, fromtid, 0);
2230 ("Recovery: Ending transaction on source volume %u ...",
2232 AFSVolEndTrans(fromconn, fromtid, &rcode);
2236 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2240 } else { /* yep, move complete */
2243 "move complete - attempt cleanup of source partition - no guarantee\n");
2247 /* delete backup volume */
2249 code = DoVolDelete(fromconn, backupId, afrompart,
2250 "backup", 0, NULL, "Recovery:");
2251 if (code == VNOVOL) {
2252 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2255 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2256 (atoserver != afromserver)?atoserver:0,
2258 if (code == VNOVOL) {
2259 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2264 /* common cleanup - delete local clone */
2266 code = DoVolDelete(fromconn, newVol, afrompart,
2267 "clone", 0, NULL, "Recovery:");
2268 if (code == VNOVOL) {
2269 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2273 /* unlock VLDB entry */
2275 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2277 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2278 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2281 done: /* routine cleanup */
2284 #ifdef ENABLE_BUGFIX_1165
2289 rx_DestroyConnection(fromconn);
2291 rx_DestroyConnection(toconn);
2294 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2302 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2303 afs_uint32 atoserver, afs_int32 atopart)
2305 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2306 atoserver, atopart, 0);
2310 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2311 * <atopart>. The new volume is named by <atovolname>. The new volume
2312 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2313 * from the VLDB. the following flags are supported:
2315 * RV_RDONLY - target volume is RO
2316 * RV_OFFLINE - leave target volume offline
2317 * RV_CPINCR - do incremental dump if target exists
2318 * RV_NOVLDB - don't create/update VLDB entry
2319 * RV_NOCLONE - don't use a copy clone
2322 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2323 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2324 afs_uint32 atovolid, int flags)
2326 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2327 * be changing during the copy */
2329 afs_int32 volatile clonetid;
2330 afs_int32 volatile totid;
2331 afs_int32 volatile fromtid;
2332 struct rx_connection * volatile fromconn;
2333 struct rx_connection * volatile toconn;
2334 afs_uint32 volatile cloneVol;
2338 afs_int32 fromDate, cloneFromDate;
2339 struct restoreCookie cookie;
2340 afs_int32 vcode, code;
2343 struct volser_status tstatus;
2344 struct destServer destination;
2345 struct nvldbentry entry, newentry, storeEntry;
2350 fromconn = (struct rx_connection *)0;
2351 toconn = (struct rx_connection *)0;
2359 /* support control-c processing */
2362 (void)signal(SIGINT, sigint_handler);
2364 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2365 EGOTO1(mfail, vcode,
2366 "Could not fetch the entry for the volume %u from the VLDB \n",
2368 MapHostToNetwork(&entry);
2371 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2372 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2373 fromtid = totid = 0; /* initialize to uncreated */
2376 * clone the read/write volume locally.
2380 if (!(flags & RV_NOCLONE)) {
2381 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2383 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2386 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2390 /* Get a clone id */
2391 VPRINT1("Allocating new volume id for clone of volume %u ...",
2395 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2397 EGOTO1(mfail, vcode,
2398 "Could not get an ID for the clone of volume %u from the VLDB\n",
2406 /* Get a new volume id */
2407 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2409 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2410 EGOTO1(mfail, vcode,
2411 "Could not get an ID for the copy of volume %u from the VLDB\n",
2416 if (!(flags & RV_NOCLONE)) {
2417 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2418 VPRINT1("Cloning source volume %u ...", afromvol);
2419 strcpy(vname, "copy-clone-temp");
2422 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2425 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2429 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2431 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2436 "Failed to end the transaction on the source volume %u\n",
2442 * Create the destination volume
2445 if (!(flags & RV_NOCLONE)) {
2446 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2449 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2453 "Failed to start a transaction on the cloned volume%u\n",
2457 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2459 AFSVolSetFlags(fromconn, clonetid,
2460 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2461 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2465 /* remember time from which we've dumped the volume */
2466 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2467 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2469 "Failed to get the status of the cloned volume %u\n",
2473 fromDate = CLOCKADJ(tstatus.creationDate);
2478 /* create a volume on the target machine */
2481 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2484 if ((flags & RV_CPINCR)) {
2485 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2486 code = AFSVolGetStatus(toconn, totid, &tstatus);
2488 "Failed to get the status of the pre-existing volume %u\n",
2492 /* Using the update date should be OK here, but add some fudge */
2493 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2494 if ((flags & RV_NOCLONE))
2495 fromDate = cloneFromDate;
2497 /* XXX We should check that the source volume's creationDate is
2498 * XXX not newer than the existing target volume, and if not,
2499 * XXX throw away the existing target and do a full dump. */
2504 /* Delete the existing volume.
2505 * While we are deleting the volume in these steps, the transaction
2506 * we started against the cloned volume (clonetid above) will be
2507 * sitting idle. It will get cleaned up after 600 seconds
2509 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2510 code = AFSVolDeleteVolume(toconn, totid);
2512 "Could not delete the pre-existing volume %u on destination\n",
2517 ("Ending transaction on pre-existing volume %u on destination ...",
2519 code = AFSVolEndTrans(toconn, totid, &rcode);
2524 "Could not end the transaction on pre-existing volume %u on destination\n",
2529 VPRINT1("Creating the destination volume %u ...", newVol);
2532 AFSVolCreateVolume(toconn, atopart, atovolname,
2533 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2534 newVol, &newVol, &tmp);
2536 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2540 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2542 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2544 "Failed to set the flags on the destination volume %u\n", newVol);
2549 destination.destHost = ntohl(atoserver);
2550 destination.destPort = AFSCONF_VOLUMEPORT;
2551 destination.destSSID = 1;
2553 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2554 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2559 * Now dump the clone to the new volume
2562 if (!(flags & RV_NOCLONE)) {
2563 /* XXX probably should have some code here that checks to see if
2564 * XXX we are copying to same server and partition - if so, just
2565 * XXX use a clone to save disk space */
2567 /* Copy the clone to the new volume */
2568 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2571 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2573 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2577 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2578 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2583 "Failed to end the transaction on the cloned volume %u\n",
2589 * reattach to the main-line volume, and incrementally dump it.
2592 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2594 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2597 "Failed to create a transaction on the source volume %u\n",
2601 /* now do the incremental */
2603 ("Doing the%s dump from source to destination for volume %u ... ",
2604 (flags & RV_NOCLONE) ? "" : " incremental",
2607 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2610 "Failed to do the%s dump from old site to new site\n",
2611 (flags & RV_NOCLONE) ? "" : " incremental");
2614 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2615 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2616 code = AFSVolSetFlags(toconn, totid, volflag);
2618 "Failed to set the flags to make destination volume online\n");
2621 /* put new volume online */
2622 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2623 code = AFSVolEndTrans(toconn, totid, &rcode);
2628 "Failed to end the transaction on the destination volume %u\n",
2632 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2633 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2638 "Failed to end the transaction on the source volume %u\n",
2644 if (!(flags & RV_NOCLONE)) {
2645 code = DoVolDelete(fromconn, cloneVol, afrompart,
2646 "cloned", 0, NULL, NULL);
2647 if (code && code != VNOVOL) {
2652 code = 0; /* clone missing? that's ok */
2655 if (!(flags & RV_NOVLDB)) {
2656 /* create the vldb entry for the copied volume */
2657 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2658 newentry.nServers = 1;
2659 newentry.serverNumber[0] = atoserver;
2660 newentry.serverPartition[0] = atopart;
2661 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2662 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2663 newentry.volumeId[RWVOL] = newVol;
2664 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2665 newentry.volumeId[BACKVOL] = 0;
2666 newentry.cloneId = 0;
2667 /*map into right byte order, before passing to xdr, the stuff has to be in host
2668 * byte order. Xdr converts it into network order */
2669 MapNetworkToHost(&newentry, &storeEntry);
2670 /* create the vldb entry */
2671 vcode = VLDB_CreateEntry(&storeEntry);
2674 "Could not create a VLDB entry for the volume %s %lu\n",
2675 atovolname, (unsigned long)newVol);
2676 /*destroy the created volume */
2677 VPRINT1("Deleting the newly created volume %u\n", newVol);
2678 AFSVolDeleteVolume(toconn, totid);
2682 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2686 /* normal cleanup code */
2689 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2691 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2692 if (code || rcode) {
2695 "Could not end transaction on the source volume %lu\n",
2696 (unsigned long)afromvol);
2698 error = (code ? code : rcode);
2704 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2706 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2707 if (code || rcode) {
2710 "Could not end transaction on the source's clone volume %lu\n",
2711 (unsigned long)cloneVol);
2713 error = (code ? code : rcode);
2719 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2721 code = AFSVolEndTrans(toconn, totid, &rcode);
2725 "Could not end transaction on destination volume %lu\n",
2726 (unsigned long)newVol);
2728 error = (code ? code : rcode);
2733 rx_DestroyConnection(fromconn);
2735 rx_DestroyConnection(toconn);
2736 PrintError("", error);
2739 /* come here only when the sky falls */
2744 "vos copy: operation interrupted, cleanup in progress...\n");
2745 fprintf(STDOUT, "clear transaction contexts\n");
2750 VPRINT("Recovery: Ending transaction on clone volume ...");
2751 AFSVolEndTrans(fromconn, clonetid, &rcode);
2755 VPRINT("Recovery: Ending transaction on destination volume ...");
2756 AFSVolEndTrans(toconn, totid, &rcode);
2759 if (fromtid) { /* put it on-line */
2760 VPRINT("Recovery: Ending transaction on source volume ...");
2761 AFSVolEndTrans(fromconn, fromtid, &rcode);
2765 VPRINT("Recovery: Accessing VLDB.\n");
2766 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2768 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2772 MapHostToNetwork(&entry);
2774 /* common cleanup - delete local clone */
2776 DoVolDelete(fromconn, cloneVol, afrompart, "clone", 0, NULL,
2780 done: /* routine cleanup */
2782 rx_DestroyConnection(fromconn);
2784 rx_DestroyConnection(toconn);
2787 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2795 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2796 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2798 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2799 atovolname, atoserver, atopart, 0, 0);
2804 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2805 * if one already exists, update it
2809 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2811 struct rx_connection *aconn = (struct rx_connection *)0;
2812 afs_int32 ttid = 0, btid = 0;
2813 afs_uint32 backupID;
2814 afs_int32 code = 0, rcode = 0;
2815 struct nvldbentry entry, storeEntry;
2816 afs_int32 error = 0;
2817 int vldblocked = 0, vldbmod = 0;
2819 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2821 /* the calls to VLDB will succeed only if avolid is a RW volume,
2822 * since we are following the RW hash chain for searching */
2823 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2826 "Could not fetch the entry for the volume %lu from the VLDB \n",
2827 (unsigned long)avolid);
2831 MapHostToNetwork(&entry);
2833 /* These operations require the VLDB be locked since it means the VLDB
2834 * will change or the vldb is already locked.
2836 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2837 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2838 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2840 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2843 "Could not lock the VLDB entry for the volume %lu\n",
2844 (unsigned long)avolid);
2850 /* Reread the vldb entry */
2851 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2854 "Could not fetch the entry for the volume %lu from the VLDB \n",
2855 (unsigned long)avolid);
2859 MapHostToNetwork(&entry);
2862 if (!ISNAMEVALID(entry.name)) {
2863 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2865 error = VOLSERBADNAME;
2869 backupID = entry.volumeId[BACKVOL];
2870 if (backupID == INVALID_BID) {
2871 /* Get a backup volume id from the VLDB and update the vldb
2874 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2877 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2878 (unsigned long)avolid);
2882 entry.volumeId[BACKVOL] = backupID;
2886 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2887 entry.name, NULL, ".backup", NULL, NULL);
2893 /* Mark vldb as backup exists */
2894 if (!(entry.flags & VLF_BACKEXISTS)) {
2895 entry.flags |= VLF_BACKEXISTS;
2899 /* Now go back to the backup volume and bring it on line */
2900 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2903 "Failed to start a transaction on the backup volume %lu\n",
2904 (unsigned long)backupID);
2909 code = AFSVolSetFlags(aconn, btid, 0);
2911 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2912 (unsigned long)backupID);
2917 code = AFSVolEndTrans(aconn, btid, &rcode);
2919 if (code || rcode) {
2921 "Failed to end the transaction on the backup volume %lu\n",
2922 (unsigned long)backupID);
2923 error = (code ? code : rcode);
2927 /* Will update the vldb below */
2931 code = AFSVolEndTrans(aconn, ttid, &rcode);
2932 if (code || rcode) {
2933 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2934 (unsigned long)avolid);
2936 error = (code ? code : rcode);
2941 code = AFSVolEndTrans(aconn, btid, &rcode);
2942 if (code || rcode) {
2944 "Could not end transaction the backup volume %lu\n",
2945 (unsigned long)backupID);
2947 error = (code ? code : rcode);
2951 /* Now update the vldb - if modified */
2954 MapNetworkToHost(&entry, &storeEntry);
2956 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2957 (LOCKREL_OPCODE | LOCKREL_AFSID |
2958 LOCKREL_TIMESTAMP));
2961 "Could not update the VLDB entry for the volume %lu \n",
2962 (unsigned long)avolid);
2968 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2969 (LOCKREL_OPCODE | LOCKREL_AFSID |
2970 LOCKREL_TIMESTAMP));
2973 "Could not unlock the VLDB entry for the volume %lu \n",
2974 (unsigned long)avolid);
2982 rx_DestroyConnection(aconn);
2984 PrintError("", error);
2988 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2989 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2990 * The new volume is named by <aname>, or by appending ".clone" to
2991 * the existing name if <aname> is NULL. The following flags are
2994 * RV_RDONLY - target volume is RO
2995 * RV_OFFLINE - leave target volume offline
2999 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
3000 afs_uint32 acloneid, char *aname, int flags)
3002 struct rx_connection *aconn = (struct rx_connection *)0;
3003 afs_int32 ttid = 0, btid = 0;
3004 afs_int32 code = 0, rcode = 0;
3005 char vname[VOLSER_MAXVOLNAME + 1];
3006 afs_int32 error = 0;
3007 volEntries volumeInfo;
3010 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
3013 volumeInfo.volEntries_val = (volintInfo *) 0;
3014 volumeInfo.volEntries_len = 0;
3015 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
3017 fprintf(stderr, "Could not get info for volume %lu\n",
3018 (unsigned long)avolid);
3022 strncpy(vname, volumeInfo.volEntries_val[0].name,
3023 VOLSER_OLDMAXVOLNAME - 7);
3024 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
3025 strcat(vname, ".clone");
3027 if (volumeInfo.volEntries_val)
3028 free(volumeInfo.volEntries_val);
3032 /* Get a clone id */
3033 VPRINT1("Allocating new volume id for clone of volume %u ...",
3035 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
3037 "Could not get an ID for the clone of volume %u from the VLDB\n",
3042 if (flags & RV_RWONLY)
3043 type = readwriteVolume;
3044 else if (flags & RV_RDONLY)
3045 type = readonlyVolume;
3047 type = backupVolume;
3049 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
3050 NULL, aname, NULL, NULL, NULL);
3056 /* Now go back to the backup volume and bring it on line */
3057 if (!(flags & RV_OFFLINE)) {
3058 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3061 "Failed to start a transaction on the clone volume %lu\n",
3062 (unsigned long)acloneid);
3067 code = AFSVolSetFlags(aconn, btid, 0);
3069 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3070 (unsigned long)acloneid);
3075 code = AFSVolEndTrans(aconn, btid, &rcode);
3077 if (code || rcode) {
3079 "Failed to end the transaction on the clone volume %lu\n",
3080 (unsigned long)acloneid);
3081 error = (code ? code : rcode);
3088 code = AFSVolEndTrans(aconn, ttid, &rcode);
3089 if (code || rcode) {
3090 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3091 (unsigned long)avolid);
3093 error = (code ? code : rcode);
3098 code = AFSVolEndTrans(aconn, btid, &rcode);
3099 if (code || rcode) {
3101 "Could not end transaction on the clone volume %lu\n",
3102 (unsigned long)acloneid);
3104 error = (code ? code : rcode);
3109 rx_DestroyConnection(aconn);
3111 PrintError("", error);
3115 #define ONERROR(ec, ep, es) do { \
3117 fprintf(STDERR, (es), (ep)); \
3122 #define ONERROR0(ec, es) do { \
3124 fprintf(STDERR, (es)); \
3129 #define ERROREXIT(ec) do { \
3134 /* Get a "transaction" on this replica. Create the volume
3135 * if necessary. Return the time from which a dump should
3136 * be made (0 if it's a new volume)
3139 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3140 struct rx_connection **connPtr, afs_int32 * transPtr,
3141 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3142 afs_int32 *origflags, afs_uint32 tmpVolId)
3145 struct volser_status tstatus;
3150 *connPtr = (struct rx_connection *)0;
3155 /* get connection to the replication site */
3156 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3158 goto fail; /* server is down */
3160 volid = vldbEntryPtr->volumeId[ROVOL];
3164 AFSVolTransCreate_retry(*connPtr, volid,
3165 vldbEntryPtr->serverPartition[index], ITOffline,
3168 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3169 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3170 * site. Don't trust any data on it, since it is possible we
3171 * have encountered some temporary volume from some other
3172 * incomplete volume operation. It is difficult to detect if
3173 * that has happened vs if this is a legit volume, so just
3174 * delete it to be safe. */
3176 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3177 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3178 serverNumber[index], hoststr) :
3179 hostutil_GetNameByINet(vldbEntryPtr->
3180 serverNumber[index]));
3182 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3184 PrintError("Failed to delete RO_DONTUSE site: ", code);
3188 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3194 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3201 /* emulate what TransCreate would have returned, so we try to
3202 * create the volume below */
3207 /* If the volume does not exist, create it */
3208 if (!volid || code) {
3209 char volname[VL_MAXNAMELEN];
3212 if (volid && (code != VNOVOL)) {
3213 PrintError("Failed to start a transaction on the RO volume.\n",
3218 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3220 if (strlcat(volname,
3221 tmpVolId?".roclone":".readonly",
3222 sizeof(volname)) >= sizeof(volname)) {
3224 PrintError("Volume name is too long\n", code);
3230 "Creating new volume %lu on replication site %s: ",
3231 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3232 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3233 serverNumber[index], hoststr) :
3234 hostutil_GetNameByINet(vldbEntryPtr->
3235 serverNumber[index]));
3240 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3242 vldbEntryPtr->volumeId[RWVOL],
3243 tmpVolId?&tmpVolId:&volid,
3246 PrintError("Failed to create the ro volume: ", code);
3249 vldbEntryPtr->volumeId[ROVOL] = volid;
3253 /* The following is a bit redundant, since create sets these flags by default */
3255 AFSVolSetFlags(*connPtr, *transPtr,
3256 VTDeleteOnSalvage | VTOutOfService);
3258 PrintError("Failed to set flags on the ro volume: ", code);
3263 /* Otherwise, the transaction did succeed, so get the creation date of the
3264 * latest RO volume on the replication site
3267 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3268 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3269 serverNumber[index], hoststr) :
3270 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3272 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3274 PrintError("Failed to get status of volume on destination: ",
3279 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3284 code = DoVolClone(*connPtr, volid,
3285 vldbEntryPtr->serverPartition[index],
3286 readonlyVolume, tmpVolId, "temporary",
3287 vldbEntryPtr->name, NULL, ".roclone", NULL,
3292 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3293 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3300 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3304 if (tcode && tcode != ENOENT)
3305 PrintError("Could not end transaction on a ro volume: ", tcode);
3312 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3313 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3314 void *cookie, manyResults * results)
3318 for (i = 0; i < tr->manyDests_len; i++) {
3319 results->manyResults_val[i] =
3320 AFSVolForward(fromconn, fromtid, fromdate,
3321 &(tr->manyDests_val[i].server),
3322 tr->manyDests_val[i].trans, cookie);
3328 * Check if a trans has timed out, and recreate it if necessary.
3330 * @param[in] aconn RX connection to the relevant server
3331 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3332 * contains the new trans ID on success
3333 * @param[in] apart Partition for the transaction
3334 * @param[in] astat The status of the original transaction
3336 * @return operation status
3337 * @retval 0 existing transaction is still valid, or we managed to recreate
3338 * the trans successfully
3339 * @retval nonzero Fatal error; bail out
3342 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3343 struct volser_status *astat)
3345 struct volser_status new_status;
3348 memset(&new_status, 0, sizeof(new_status));
3349 code = AFSVolGetStatus(aconn, *atid, &new_status);
3351 if (code == ENOENT) {
3353 VPRINT1("Old transaction on cloned volume %lu timed out, "
3354 "restarting transaction\n", (long unsigned) astat->volID);
3355 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3358 PrintError("Failed to recreate cloned RO volume transaction\n",
3363 memset(&new_status, 0, sizeof(new_status));
3364 code = AFSVolGetStatus(aconn, *atid, &new_status);
3366 PrintError("Failed to get status on recreated transaction\n",
3371 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3372 PrintError("Recreated transaction on cloned RO volume, but "
3373 "the volume has changed!\n", 0);
3377 PrintError("Unable to get status of current cloned RO transaction\n",
3382 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3384 PrintError("Internal error: current GetStatus does not match "
3385 "original GetStatus?\n", 0);
3394 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3395 struct rx_connection **toconns, struct release *times,
3398 afs_int32 s, code = 0, rcode = 0;
3399 /* End the transactions and destroy the connections */
3400 for (s = 0; s < volcount; s++) {
3401 if (replicas[s].trans) {
3402 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3404 replicas[s].trans = 0;
3408 if ((s == 0) || (code != ENOENT)) {
3409 PrintError("Could not end transaction on a ro volume: ",
3413 ("Transaction timed out on a ro volume. Will retry.\n",
3415 if (times[s].vldbEntryIndex < *vldbindex)
3416 *vldbindex = times[s].vldbEntryIndex;
3421 rx_DestroyConnection(toconns[s]);
3427 * Release a volume to read-only sites
3429 * Release volume <afromvol> on <afromserver> <afrompart> to all its RO
3430 * sites (complete release), unless the previous release was incomplete
3431 * or new sites were added without changes to the read-write volume, in
3432 * which case we bring the remaining volumes up to date with the volumes
3433 * that were previously released successfully.
3435 * Will create a clone from the RW, then dump the clone out to
3436 * the remaining replicas. If there is more than 1 RO sites,
3437 * ensure that the VLDB says at least one RO is available all
3438 * the time: Influences when we write back the VLDB entry.
3440 * @param[in] afromvol volume to be released
3441 * @param[in] afromserver server containing afromvol
3442 * @param[in] afrompart partition containing afromvol
3443 * @param[in] flags bitmap of options
3444 * REL_COMPLETE - force a complete release
3445 * REL_FULLDUMPS - force full dumps
3448 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3449 afs_int32 afrompart, int flags)
3453 afs_int32 vcode, rcode, tcode;
3454 afs_uint32 cloneVolId = 0, roVolId;
3455 struct replica *replicas = 0;
3456 struct nvldbentry entry, storeEntry;
3457 int i, volcount = 0, m, vldbindex;
3459 struct restoreCookie cookie;
3460 struct rx_connection **toconns = 0;
3461 struct release *times = 0;
3463 struct rx_connection *fromconn = (struct rx_connection *)0;
3464 afs_int32 error = 0;
3466 afs_int32 clonetid = 0, onlinetid;
3467 afs_int32 fromtid = 0;
3468 afs_uint32 fromdate = 0;
3469 afs_uint32 thisdate;
3473 manyResults results;
3474 int rwindex, roindex, roclone, roexists;
3475 afs_uint32 rwcrdate = 0, rwupdate = 0;
3476 afs_uint32 clcrdate;
3480 } remembertime[NMAXNSERVERS];
3481 int releasecount = 0;
3482 struct volser_status volstatus;
3484 afs_int32 origflags[NMAXNSERVERS];
3485 struct volser_status orig_status;
3486 int notreleased = 0;
3487 int tried_justnewsites = 0;
3488 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3489 int sites = 0; /* number of ro sites */
3490 int new_sites = 0; /* number of ro sites markes as new */
3493 CR_PARTIAL = 0x0000, /**< just new sites added or recover from a previous failed release */
3494 CR_FORCED = 0x0001, /**< complete: forced by caller */
3495 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3496 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3497 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3498 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3499 } complete_release_t;
3501 complete_release_t complete_release = CR_PARTIAL;
3503 memset(remembertime, 0, sizeof(remembertime));
3504 memset(&results, 0, sizeof(results));
3505 memset(origflags, 0, sizeof(origflags));
3507 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3508 if (vcode != VL_RERELEASE)
3509 ONERROR(vcode, afromvol,
3510 "Could not lock the VLDB entry for the volume %u.\n");
3513 /* Get the vldb entry in readable format */
3514 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3515 ONERROR(vcode, afromvol,
3516 "Could not fetch the entry for the volume %u from the VLDB.\n");
3517 MapHostToNetwork(&entry);
3520 EnumerateEntry(&entry);
3522 if (!ISNAMEVALID(entry.name))
3523 ONERROR(VOLSERBADOP, entry.name,
3524 "Volume name %s is too long, rename before releasing.\n");
3525 if (entry.volumeId[RWVOL] != afromvol)
3526 ONERROR(VOLSERBADOP, afromvol,
3527 "The volume %u being released is not a read-write volume.\n");
3528 if (entry.nServers <= 1)
3529 ONERROR(VOLSERBADOP, afromvol,
3530 "Volume %u has no replicas - release operation is meaningless!\n");
3531 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3532 ONERROR(VOLSERBADOP, entry.name,
3533 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3535 /* roclone is true if one of the RO volumes is on the same
3536 * partition as the RW volume. In this case, we make the RO volume
3537 * on the same partition a clone instead of a complete copy.
3540 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3541 roclone = ((roindex == -1) ? 0 : 1);
3542 rwindex = Lp_GetRwIndex(&entry);
3544 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3546 /* Make sure we have a RO volume id to work with */
3547 if (entry.volumeId[ROVOL] == INVALID_BID) {
3548 /* need to get a new RO volume id */
3549 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3550 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3552 entry.volumeId[ROVOL] = roVolId;
3553 MapNetworkToHost(&entry, &storeEntry);
3554 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3555 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3559 * Determine if this is to be a complete release or a recovery of a
3560 * previous unfinished release. The previous release is considered to be
3561 * unfinished when the clone was successfully distributed to at least one
3562 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3565 * The caller can override the vldb flags check using the -force
3566 * or -force-reclone flag, to force this to be a complete release.
3568 for (i = 0; i < entry.nServers; i++) {
3569 if (entry.serverFlags[i] & VLSF_ROVOL) {
3571 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3573 if (entry.serverFlags[i] & VLSF_DONTUSE)
3576 origflags[i] = entry.serverFlags[i];
3579 if (flags & REL_COMPLETE) {
3580 complete_release |= CR_FORCED;
3583 if (new_sites == 0) {
3584 complete_release |= CR_LAST_OK;
3585 } else if (new_sites == sites) {
3586 complete_release |= CR_ALL_NEW;
3589 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3590 && !(complete_release & CR_FORCED)) {
3591 if (notreleased && notreleased != sites) {
3592 /* we have some new unreleased sites. try to just release to those,
3593 * if the RW has not changed. The caller can override with -force
3594 * or with -force-reclone. */
3599 /* Determine which volume id to use and see if it exists */
3600 cloneVolId = (complete_release || entry.cloneId == 0)
3601 ? entry.volumeId[ROVOL] : entry.cloneId;
3603 code = VolumeExists(afromserver, afrompart, cloneVolId);
3604 roexists = ((code == ENODEV) ? 0 : 1);
3606 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3608 ONERROR(-1, afromserver,
3609 "Cannot establish connection with server 0x%x\n");
3611 if (!complete_release) {
3613 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3615 /* Begin transaction on RW and mark it busy while we query it */
3616 code = AFSVolTransCreate_retry(
3617 fromconn, afromvol, afrompart, ITBusy, &fromtid
3619 ONERROR(code, afromvol,
3620 "Failed to start transaction on RW volume %u\n");
3622 /* Query the creation date for the RW */
3623 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3624 ONERROR(code, afromvol,
3625 "Failed to get the status of RW volume %u\n");
3626 rwcrdate = volstatus.creationDate;
3628 /* End transaction on RW */
3629 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3631 ONERROR((code ? code : rcode), afromvol,
3632 "Failed to end transaction on RW volume %u\n");
3634 /* Begin transaction on clone and mark it busy while we query it */
3635 code = AFSVolTransCreate_retry(
3636 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3638 ONERROR(code, cloneVolId,
3639 "Failed to start transaction on RW clone %u\n");
3641 /* Query the creation date for the clone */
3642 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3643 ONERROR(code, cloneVolId,
3644 "Failed to get the status of RW clone %u\n");
3645 clcrdate = volstatus.creationDate;
3647 /* End transaction on clone */
3648 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3650 ONERROR((code ? code : rcode), cloneVolId,
3651 "Failed to end transaction on RW clone %u\n");
3653 if (rwcrdate > clcrdate)
3654 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3658 if (!complete_release || (complete_release & CR_NEW_RW)) {
3659 /* in case the RW has changed, and just to be safe */
3664 if (!complete_release) {
3666 "This is a recovery of previously failed release\n");
3668 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3669 if (complete_release == CR_LAST_OK) {
3671 tried_justnewsites = 1;
3672 fprintf(STDOUT, "\nThere are new RO sites; we will try to "
3673 "only release to new sites");
3677 if (complete_release & CR_FORCED) {
3678 fprintf(STDOUT, "%sforced", sep);
3681 if (complete_release & CR_LAST_OK) {
3682 fprintf(STDOUT, "%slast ok", sep);
3685 if (complete_release & CR_ALL_NEW) {
3686 fprintf(STDOUT, "%sall sites are new", sep);
3689 if (complete_release & CR_NEW_RW) {
3690 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3693 if (complete_release & CR_RO_MISSING) {
3694 fprintf(STDOUT, "%sro clone missing", sep);
3696 fprintf(STDOUT, ")");
3698 fprintf(STDOUT, "\n");
3702 if (complete_release) {
3703 afs_int32 oldest = 0;
3704 /* If the RO clone exists, then if the clone is a temporary
3705 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3706 * (it was recently added), then also delete it. We do not
3707 * want to "reclone" a temporary RO clone.
3710 /* clean up any previous tmp clone before starting if staying up */
3712 && (!roclone || (entry.serverFlags[roindex] & VLSF_DONTUSE))) {
3713 code = DoVolDelete(fromconn,
3715 afrompart, "the", 0, NULL, NULL);
3716 if (code && (code != VNOVOL))
3722 VPRINT("Querying old RO sites for update times...");
3723 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3724 volEntries volumeInfo;
3725 struct rx_connection *conn;
3728 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL)) {
3731 if ((entry.serverFlags[vldbindex] & VLSF_DONTUSE)) {
3734 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3736 fprintf(STDERR, "Cannot establish connection to server %s\n",
3737 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3741 volumeInfo.volEntries_val = NULL;
3742 volumeInfo.volEntries_len = 0;
3743 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3744 entry.volumeId[ROVOL],
3747 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3748 (unsigned long)entry.volumeId[ROVOL],
3749 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3750 PrintError("", code);
3752 rx_DestroyConnection(conn);
3756 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3758 if (oldest == 0 || crdate < oldest) {
3762 rx_DestroyConnection(conn);
3763 free(volumeInfo.volEntries_val);
3764 volumeInfo.volEntries_val = NULL;
3765 volumeInfo.volEntries_len = 0;
3770 volEntries volumeInfo;
3771 volumeInfo.volEntries_val = NULL;
3772 volumeInfo.volEntries_len = 0;
3773 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3776 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3777 (unsigned long)afromvol,
3778 hostutil_GetNameByINet(afromserver));
3779 PrintError("", code);
3782 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3784 free(volumeInfo.volEntries_val);
3785 volumeInfo.volEntries_val = NULL;
3786 volumeInfo.volEntries_len = 0;
3789 if (justnewsites && oldest <= rwupdate) {
3790 /* RW has changed */
3794 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3795 * write this entry out to the vlserver until after the first
3796 * RO volume is released (temp RO clones don't count).
3798 * If 'justnewsites' is set, we're only updating sites that have
3799 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3801 for (i = 0; i < entry.nServers; i++) {
3803 if ((entry.serverFlags[i] & VLSF_DONTUSE)) {
3804 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3806 entry.serverFlags[i] |= VLSF_NEWREPSITE;
3809 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3810 entry.serverFlags[i] |= VLSF_DONTUSE;
3813 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3814 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3817 if (justnewsites && roexists) {
3818 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3819 * anything with the RO clone, so skip the reclone */
3822 } else if (complete_release) {
3825 strcpy(vname, entry.name);
3826 strcat(vname, ".readonly");
3828 strcpy(vname, "readonly-clone-temp");
3831 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3832 cloneVolId, roclone?"permanent RO":
3833 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3839 if (justnewsites && rwupdate != volstatus.updateDate) {
3841 /* reset the serverFlags as if 'justnewsites' had never been set */
3842 for (i = 0; i < entry.nServers; i++) {
3843 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3844 entry.serverFlags[i] |= VLSF_DONTUSE;
3846 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3847 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3850 rwcrdate = volstatus.creationDate;
3852 /* Remember clone volume ID in case we fail or are interrupted */
3853 entry.cloneId = cloneVolId;
3856 /* Bring the RO clone online - though not if it's a temporary clone */
3857 VPRINT1("Starting transaction on RO clone volume %u...",
3860 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3862 ONERROR(code, cloneVolId,
3863 "Failed to start transaction on volume %u\n");
3866 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3867 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3870 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3871 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3872 ONERROR((code ? code : rcode), cloneVolId,
3873 "Failed to end transaction on RO clone %u\n");
3876 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3878 /* Sleep so that a client searching for an online volume won't
3879 * find the clone offline and then the next RO offline while the
3880 * release brings the clone online and the next RO offline (race).
3881 * There is a fix in the 3.4 client that does not need this sleep
3882 * anymore, but we don't know what clients we have.
3884 if (entry.nServers > 2 && !justnewsites)
3887 /* Mark the RO clone in the VLDB as a good site (already released) */
3888 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
3889 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
3890 entry.flags |= VLF_ROEXISTS;
3894 /* Write out the VLDB entry only if the clone is not a temporary
3895 * clone. If we did this to a temporary clone then we would end
3896 * up marking all the ROs as "old release" making the ROs
3897 * temporarily unavailable.
3899 MapNetworkToHost(&entry, &storeEntry);
3900 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3901 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3902 ONERROR(vcode, entry.name,
3903 "Could not update vldb entry for %s.\n");
3909 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3910 /* act like this is a completion of a previous release */
3911 complete_release = CR_PARTIAL;
3912 } else if (tried_justnewsites) {
3913 VPRINT("RW vol has changed; releasing to all sites\n");
3916 /* Now we will release from the clone to the remaining RO replicas.
3917 * The first 2 ROs (counting the non-temporary RO clone) are released
3918 * individually: releasecount. This is to reduce the race condition
3919 * of clients trying to find an on-line RO volume. The remaining ROs
3920 * are released in parallel but no more than half the number of ROs
3921 * (rounded up) at a time: nservers.
3924 strcpy(vname, entry.name);
3925 strcat(vname, ".readonly");
3926 memset(&cookie, 0, sizeof(cookie));
3927 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3928 cookie.type = ROVOL;
3929 cookie.parent = entry.volumeId[RWVOL];
3932 /* how many to do at once, excluding clone */
3934 nservers = entry.nServers; /* can do all, none offline */
3936 nservers = entry.nServers / 2;
3937 replicas = calloc(nservers + 1, sizeof(struct replica));
3938 times = calloc(nservers + 1, sizeof(struct release));
3939 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3940 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3941 if (!replicas || !times || !results.manyResults_val || !toconns)
3943 "Failed to create transaction on the release clone\n");
3945 /* Create a transaction on the cloned volume */
3946 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3948 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3950 memset(&orig_status, 0, sizeof(orig_status));
3951 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3953 if (!complete_release && code)
3954 ONERROR(VOLSERNOVOL, afromvol,
3955 "Old clone is inaccessible. Try vos release -f %u.\n");
3956 ONERROR0(code, "Failed to create transaction on the release clone\n");
3959 /* For each index in the VLDB */
3960 for (vldbindex = 0; vldbindex < entry.nServers;) {
3961 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3963 ((volcount < nservers) && (vldbindex < entry.nServers));
3965 if (!justnewsites) {
3966 /* The first two RO volumes will be released individually.
3967 * The rest are then released in parallel. This is a hack
3968 * for clients not recognizing right away when a RO volume
3969 * comes back on-line.
3971 if ((volcount == 1) && (releasecount < 2))
3975 if (vldbindex == roindex)
3976 continue; /* the clone */
3977 if ((entry.serverFlags[vldbindex] & VLSF_NEWREPSITE)
3978 && !(entry.serverFlags[vldbindex] & VLSF_DONTUSE))
3980 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL))
3981 continue; /* not a RO vol */
3984 /* Get a Transaction on this replica. Get a new connection if
3985 * necessary. Create the volume if necessary. Return the
3986 * time from which the dump should be made (0 if it's a new
3987 * volume). Each volume might have a different time.
3989 replicas[volcount].server.destHost =
3990 ntohl(entry.serverNumber[vldbindex]);
3991 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3992 replicas[volcount].server.destSSID = 1;
3993 times[volcount].vldbEntryIndex = vldbindex;
3996 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3997 &(replicas[volcount].trans),
3998 &(times[volcount].crtime),
3999 &(times[volcount].uptime),
4004 /* Thisdate is the date from which we want to pick up all changes */
4005 if (flags & REL_FULLDUMPS) {
4006 /* Do a full dump when forced by the caller. */
4007 VPRINT("This will be a full dump: forced\n");
4009 } else if (complete_release == CR_PARTIAL) {
4011 VPRINT("This will be a full dump: read-only volume needs be created for new site\n");
4014 * We cannot be sure the creation date is good since the previous
4015 * release failed, so do a full dump.
4017 VPRINT("This will be a full dump: previous release failed\n");
4020 } else if (times[volcount].crtime == 0) {
4021 /* A full dump is needed for a new read-only volume. */
4023 ("This will be a full dump: read-only volume needs to be created\n");
4025 } else if ((rwcrdate > times[volcount].crtime)) {
4026 /* If the RW volume was replaced (its creation date is newer than
4027 * the last release), then we can't be sure what has changed (so
4028 * we do a full dump).
4031 ("This will be a full dump: read-write volume was replaced\n");
4033 } else if (remembertime[vldbindex].validtime) {
4034 /* Trans was prev ended. Use the time from the prev trans
4035 * because, prev trans may have created the volume. In which
4036 * case time[volcount].time would be now instead of 0.
4039 (remembertime[vldbindex].uptime < times[volcount].uptime)
4040 ? remembertime[vldbindex].uptime
4041 : times[volcount].uptime;
4043 thisdate = times[volcount].uptime;
4045 remembertime[vldbindex].validtime = 1;
4046 remembertime[vldbindex].uptime = thisdate;
4048 if (volcount == 0) {
4049 fromdate = thisdate;
4051 /* Include this volume if it is within 15 minutes of the earliest */
4053 thisdate) ? (fromdate - thisdate) : (thisdate -
4055 AFSVolEndTrans(toconns[volcount],
4056 replicas[volcount].trans, &rcode);
4057 replicas[volcount].trans = 0;
4060 if (thisdate < fromdate)
4061 fromdate = thisdate;
4068 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
4075 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
4076 (unsigned long)cloneVolId,
4077 entry.volumeId[ROVOL],
4078 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
4079 vldbEntryIndex], hoststr) :
4080 hostutil_GetNameByINet(entry.
4081 serverNumber[times[0].
4084 for (s = 1; s < volcount; s++) {
4085 fprintf(STDOUT, " and %s",
4086 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
4087 vldbEntryIndex], hoststr) :
4088 hostutil_GetNameByINet(entry.
4089 serverNumber[times[s].
4094 fprintf(STDOUT, " (entire volume)");
4097 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4099 fprintf(STDOUT, ".\n");
4103 /* Release the ones we have collected */
4104 tr.manyDests_val = &(replicas[0]);
4105 tr.manyDests_len = results.manyResults_len = volcount;
4107 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4108 0 /*spare */ , &cookie, &results);
4109 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4111 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4112 0 /*spare */ , &cookie, &results);
4117 PrintError("Release failed: ", code);
4119 for (m = 0; m < volcount; m++) {
4120 if (results.manyResults_val[m]) {
4121 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4122 /* we retry timed out transaction. When it is
4123 * not the first volume and the transaction wasn't found
4124 * (assume it timed out and was garbage collected by volser).
4127 ("Failed to dump volume from clone to a ro site: ",
4128 results.manyResults_val[m]);
4134 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4135 ROVOL, entry.volumeId[RWVOL], 0, 0);
4137 if ((m == 0) || (code != ENOENT)) {
4138 PrintError("Failed to set correct names and ids: ",
4144 /* have to clear dest. flags to ensure new vol goes online:
4145 * because the restore (forwarded) operation copied
4146 * the V_inService(=0) flag over to the destination.
4148 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4150 if ((m == 0) || (code != ENOENT)) {
4151 PrintError("Failed to set flags on ro volume: ",
4157 entry.serverFlags[times[m].vldbEntryIndex] |= VLSF_NEWREPSITE;
4158 entry.serverFlags[times[m].vldbEntryIndex] &= ~VLSF_DONTUSE;
4159 entry.flags |= VLF_ROEXISTS;
4164 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4165 MapNetworkToHost(&entry, &storeEntry);
4166 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4167 ONERROR(vcode, afromvol,
4168 " Could not update VLDB entry for volume %u\n");
4169 } /* for each index in the vldb */
4171 /* End the transaction on the cloned volume */
4172 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4177 PrintError("Failed to end transaction on rw volume: ", code);
4179 /* Figure out if any volume were not released and say so */
4180 for (failure = 0, i = 0; i < entry.nServers; i++) {
4181 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE))
4187 "The volume %lu could not be released to the following %d sites:\n",
4188 (unsigned long)afromvol, failure);
4189 for (i = 0; i < entry.nServers; i++) {
4190 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE)) {
4191 MapPartIdIntoName(entry.serverPartition[i], pname);
4192 fprintf(STDERR, "\t%35s %s\n",
4193 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4194 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4197 MapNetworkToHost(&entry, &storeEntry);
4199 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4201 ONERROR(vcode, afromvol,
4202 " Could not update VLDB entry for volume %u\n");
4204 ERROREXIT(VOLSERBADRELEASE);
4208 /* All the ROs were release successfully. Remove the temporary clone */
4211 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4212 (unsigned long)cloneVolId);
4215 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4217 if (code && code != VNOVOL)
4218 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4222 for (i = 0; i < entry.nServers; i++)
4223 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
4225 /* Update the VLDB */
4226 VPRINT("updating VLDB ...");
4228 MapNetworkToHost(&entry, &storeEntry);
4230 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4231 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4232 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4237 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4241 "Failed to end cloning transaction on the RW volume %lu\n",
4242 (unsigned long)afromvol);
4248 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4252 "Failed to end transaction on the release clone %lu\n",
4253 (unsigned long)cloneVolId);
4258 for (i = 0; i < nservers; i++) {
4259 if (replicas && replicas[i].trans) {
4260 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4261 replicas[i].trans = 0;
4264 "Failed to end transaction on ro volume %u at server %s\n",
4265 entry.volumeId[ROVOL],
4266 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4267 destHost), hoststr) :
4268 hostutil_GetNameByINet(htonl
4269 (replicas[i].server.destHost)));
4274 if (toconns && toconns[i]) {
4275 rx_DestroyConnection(toconns[i]);
4281 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4282 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4285 "Could not release lock on the VLDB entry for volume %lu\n",
4286 (unsigned long)afromvol);
4292 PrintError("", error);
4295 rx_DestroyConnection(fromconn);
4296 if (results.manyResults_val)
4297 free(results.manyResults_val);
4309 dump_sig_handler(int x)
4311 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4315 /* Dump the volume <afromvol> on <afromserver> and
4316 * <afrompart> to <afilename> starting from <fromdate>.
4317 * DumpFunction does the real work behind the scenes after
4318 * extracting parameters from the rock
4321 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4323 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4326 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4327 * be changing during the dump */
4328 struct rx_call * volatile fromcall = NULL;
4329 struct rx_connection * volatile fromconn = NULL;
4330 afs_int32 volatile fromtid = 0;
4332 afs_int32 rcode = 0;
4333 afs_int32 code, error = 0;
4335 time_t tmv = fromdate;
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);
4356 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4358 EGOTO1(error_exit, code,
4359 "Could not start transaction on the volume %u to be dumped\n",
4363 fromcall = rx_NewCall(fromconn);
4365 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4366 if (flags & VOLDUMPV2_OMITDIRS)
4367 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4369 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4370 EGOTO(error_exit, code, "Could not start the dump process \n");
4373 VEPRINT1("Dumping volume %u...", afromvol);
4374 code = DumpFunction(fromcall, rock);
4375 if (code == RXGEN_OPCODE)
4377 EGOTO(error_exit, code, "Error while dumping volume \n");
4382 code = rx_EndCall(fromcall, 0);
4383 if (code && code != RXGEN_OPCODE)
4384 fprintf(STDERR, "Error in rx_EndCall\n");
4389 VEPRINT1("Ending transaction on volume %u...", afromvol);
4390 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4391 if (code || rcode) {
4392 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4393 (unsigned long)afromvol);
4395 error = (code ? code : rcode);
4400 rx_DestroyConnection(fromconn);
4402 if (error != RXGEN_OPCODE)
4403 PrintError("", error);
4407 /* Clone the volume <afromvol> on <afromserver> and
4408 * <afrompart>, and then dump the clone volume to
4409 * <afilename> starting from <fromdate>.
4410 * DumpFunction does the real work behind the scenes after
4411 * extracting parameters from the rock
4414 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4415 afs_int32 afrompart, afs_int32 fromdate,
4416 afs_int32(*DumpFunction) (struct rx_call *, void *),
4417 void *rock, afs_int32 flags)
4419 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4420 * be changing during the dump */
4421 struct rx_connection * volatile fromconn = NULL;
4422 struct rx_call * volatile fromcall = NULL;
4423 afs_int32 volatile clonetid = 0;
4424 afs_uint32 volatile clonevol = 0;
4427 afs_int32 fromtid = 0, rcode = 0;
4428 afs_int32 code = 0, error = 0;
4430 time_t tmv = fromdate;
4431 char *volName = NULL;
4435 #ifndef AFS_NT40_ENV
4436 (void)signal(SIGPIPE, dump_sig_handler);
4438 (void)signal(SIGINT, dump_sig_handler);
4441 VEPRINT("Full Dump ...\n");
4443 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4447 /* get connections to the servers */
4448 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4450 VEPRINT1("Starting transaction on volume %u...", afromvol);
4451 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4452 EGOTO1(error_exit, code,
4453 "Could not start transaction on the volume %u to be dumped\n",
4457 VEPRINT1("Getting the name for volume %u ...", afromvol);
4458 code = AFSVolGetName(fromconn, fromtid, &volName);
4459 EGOTO1(error_exit, code,
4460 "Failed to get the name of the volume %u\n",afromvol);
4463 /* Get a clone id */
4464 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4466 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4468 EGOTO1(error_exit, code,
4469 "Could not get an ID for the clone of volume %u from the VLDB\n",
4473 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4474 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4478 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, volName, &tmpVol);
4480 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4484 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4486 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4490 EGOTO1(error_exit, code,
4491 "Failed to end the transaction on the volume %u\n", afromvol);
4495 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4498 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4501 EGOTO1(error_exit, code,
4502 "Failed to start a transaction on the cloned volume%u\n",
4506 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4507 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4508 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4513 fromcall = rx_NewCall(fromconn);
4515 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4516 if (flags & VOLDUMPV2_OMITDIRS)
4517 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4519 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4520 EGOTO(error_exit, code, "Could not start the dump process \n");
4523 VEPRINT1("Dumping volume %u...", afromvol);
4524 code = DumpFunction(fromcall, rock);
4525 EGOTO(error_exit, code, "Error while dumping volume \n");
4532 /* now delete the clone */
4533 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4534 code = AFSVolDeleteVolume(fromconn, clonetid);
4536 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4537 (unsigned long)clonevol);
4543 code = rx_EndCall(fromcall, 0);
4545 fprintf(STDERR, "Error in rx_EndCall\n");
4551 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4552 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4553 if (code || rcode) {
4555 "Could not end transaction on the cloned volume %lu\n",
4556 (unsigned long)clonevol);
4558 error = (code ? code : rcode);
4563 rx_DestroyConnection(fromconn);
4565 PrintError("", error);
4572 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4573 * the dump file <afilename>. WriteData does all the real work
4574 * after extracting params from the rock
4577 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4578 afs_uint32 toparentid, char tovolname[], int flags,
4579 afs_int32(*WriteData) (struct rx_call *, void *),
4582 struct rx_connection *toconn, *tempconn;
4583 struct rx_call *tocall;
4584 afs_int32 totid, code, rcode, vcode, terror = 0;
4585 struct volser_status tstatus;
4586 struct volintInfo vinfo;
4588 char tovolreal[VOLSER_OLDMAXVOLNAME];
4590 afs_int32 temptid, pparentid;
4591 struct nvldbentry entry, storeEntry;
4594 struct restoreCookie cookie;
4596 afs_int32 volflag, voltype, volsertype;
4597 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4598 VolumeId oldCloneId = 0;
4599 VolumeId oldBackupId = 0;
4600 int index, same, errcode;
4604 memset(&cookie, 0, sizeof(cookie));
4608 tocall = (struct rx_call *)0;
4609 tempconn = (struct rx_connection *)0;
4613 if (flags & RV_RDONLY) {
4615 volsertype = volser_RO;
4618 volsertype = volser_RW;
4622 pparentid = toparentid;
4623 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4624 if (pvolid == 0) { /*alot a new id if needed */
4625 vcode = VLDB_GetEntryByName(tovolname, &entry);
4626 if (vcode == VL_NOENT) {
4627 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4629 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4635 } else if (flags & RV_RDONLY) {
4636 if (entry.flags & VLF_RWEXISTS) {
4638 "Entry for ReadWrite volume %s already exists!\n",
4640 error = VOLSERBADOP;
4643 if (!entry.volumeId[ROVOL]) {
4645 "Existing entry for volume %s has no ReadOnly ID\n",
4647 error = VOLSERBADOP;
4650 pvolid = entry.volumeId[ROVOL];
4651 pparentid = entry.volumeId[RWVOL];
4653 pvolid = entry.volumeId[RWVOL];
4654 pparentid = entry.volumeId[RWVOL];
4657 if (!pparentid) pparentid = pvolid;
4658 /* at this point we have a volume id to use/reuse for the volume to be restored */
4659 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4661 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4662 EGOTO1(refail, VOLSERBADOP,
4663 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4666 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4667 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4668 EGOTO1(refail, VOLSERBADOP,
4669 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4671 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4674 MapPartIdIntoName(topart, partName);
4675 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4676 tovolreal, (unsigned long)pvolid,
4677 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4678 hostutil_GetNameByINet(toserver), partName);
4681 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4684 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4685 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4687 if (code && code != VNOVOL) {
4693 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4695 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4698 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4699 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4702 code = AFSVolGetStatus(toconn, totid, &tstatus);
4703 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4707 oldCreateDate = tstatus.creationDate;
4708 oldUpdateDate = tstatus.updateDate;
4709 oldCloneId = tstatus.cloneID;
4710 oldBackupId = tstatus.backupID;
4716 cookie.parent = pparentid;
4717 cookie.type = voltype;
4719 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4721 tocall = rx_NewCall(toconn);
4722 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4724 fprintf(STDERR, "Volume restore Failed \n");
4728 code = WriteData(tocall, rock);
4730 fprintf(STDERR, "Could not transmit data\n");
4734 terror = rx_EndCall(tocall, 0);
4735 tocall = (struct rx_call *)0;
4737 fprintf(STDERR, "rx_EndCall Failed \n");
4741 code = AFSVolGetStatus(toconn, totid, &tstatus);
4744 "Could not get status information about the volume %lu\n",
4745 (unsigned long)pvolid);
4749 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid,
4750 oldCloneId, oldBackupId);
4752 fprintf(STDERR, "Could not set the right type and IDs on %lu\n",
4753 (unsigned long)pvolid);
4758 if (flags & RV_CRDUMP)
4759 newCreateDate = tstatus.creationDate;
4760 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4761 newCreateDate = oldCreateDate;
4763 newCreateDate = time(0);
4764 if (flags & RV_LUDUMP)
4765 newUpdateDate = tstatus.updateDate;
4766 else if (flags & RV_LUKEEP)
4767 newUpdateDate = oldUpdateDate;
4769 newUpdateDate = time(0);
4770 code = AFSVolSetDate(toconn,totid, newCreateDate);
4772 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4777 init_volintInfo(&vinfo);
4778 vinfo.creationDate = newCreateDate;
4779 vinfo.updateDate = newUpdateDate;
4780 code = AFSVolSetInfo(toconn, totid, &vinfo);
4782 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4788 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4789 code = AFSVolSetFlags(toconn, totid, volflag);
4791 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4796 /* It isn't handled right in refail */
4797 code = AFSVolEndTrans(toconn, totid, &rcode);
4802 fprintf(STDERR, "Could not end transaction on %lu\n",
4803 (unsigned long)pvolid);
4808 fprintf(STDOUT, " done\n");
4810 if (!reuseID || (flags & RV_FULLRST)) {
4811 /* Volume was restored on the file server, update the
4812 * VLDB to reflect the change.
4814 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4815 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4817 "Could not fetch the entry for volume number %lu from VLDB \n",
4818 (unsigned long)pvolid);
4823 MapHostToNetwork(&entry);
4824 if (vcode == VL_NOENT) { /* it doesnot exist already */
4825 /*make the vldb return this indication specifically */
4826 VPRINT("------- Creating a new VLDB entry ------- \n");
4827 strcpy(entry.name, tovolname);
4829 entry.serverNumber[0] = toserver; /*should be indirect */
4830 entry.serverPartition[0] = topart;
4831 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4832 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4833 if (flags & RV_RDONLY)
4834 entry.volumeId[ROVOL] = pvolid;
4835 else if (tstatus.cloneID != 0) {
4836 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4838 entry.volumeId[ROVOL] = INVALID_BID;
4839 entry.volumeId[RWVOL] = pparentid;
4841 if (tstatus.backupID != 0) {
4842 entry.volumeId[BACKVOL] = tstatus.backupID;
4843 /*this should come from status info on the volume if non zero */
4845 entry.volumeId[BACKVOL] = INVALID_BID;
4846 MapNetworkToHost(&entry, &storeEntry);
4847 vcode = VLDB_CreateEntry(&storeEntry);
4850 "Could not create the VLDB entry for volume number %lu \n",
4851 (unsigned long)pvolid);
4857 EnumerateEntry(&entry);
4858 } else { /*update the existing entry */
4860 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4861 fprintf(STDOUT, "------- Old entry -------\n");
4862 EnumerateEntry(&entry);
4863 fprintf(STDOUT, "------- New entry -------\n");
4866 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4870 "Could not lock the entry for volume number %lu \n",
4871 (unsigned long)pvolid);
4876 strcpy(entry.name, tovolname);
4878 /* Update the vlentry with the new information */
4879 if (flags & RV_RDONLY)
4880 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4882 index = Lp_GetRwIndex(&entry);
4884 /* Add the new site for the volume being restored */
4885 entry.serverNumber[entry.nServers] = toserver;
4886 entry.serverPartition[entry.nServers] = topart;
4887 entry.serverFlags[entry.nServers] =
4888 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4891 /* This volume should be deleted on the old site
4892 * if its different from new site.
4895 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4899 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4901 if ((!errcode && !same)
4902 || (entry.serverPartition[index] != topart)) {
4903 if (flags & RV_NODEL) {
4905 ("Not deleting the previous volume %u on server %s, ...",
4907 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4908 hostutil_GetNameByINet(entry.serverNumber[index]));
4911 UV_Bind(entry.serverNumber[index],
4912 AFSCONF_VOLUMEPORT);
4914 MapPartIdIntoName(entry.serverPartition[index],
4917 ("Deleting the previous volume %u on server %s, partition %s ...",
4919 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4920 hostutil_GetNameByINet(entry.serverNumber[index]),
4922 code = DoVolDelete(tempconn, pvolid,
4923 entry.serverPartition[index],
4924 "the", 0, NULL, NULL);
4925 if (code && code != VNOVOL) {
4929 MapPartIdIntoName(entry.serverPartition[index],
4933 entry.serverNumber[index] = toserver;
4934 entry.serverPartition[index] = topart;
4937 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4938 MapNetworkToHost(&entry, &storeEntry);
4940 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4941 LOCKREL_OPCODE | LOCKREL_AFSID |
4945 "Could not update the entry for volume number %lu \n",
4946 (unsigned long)pvolid);
4952 EnumerateEntry(&entry);
4959 code = rx_EndCall(tocall, 0);
4965 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4966 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4969 "Could not release lock on the VLDB entry for the volume %lu\n",
4970 (unsigned long)pvolid);
4976 code = AFSVolEndTrans(toconn, totid, &rcode);
4980 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4981 (unsigned long)pvolid);
4987 code = AFSVolEndTrans(toconn, temptid, &rcode);
4991 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4992 (unsigned long)pvolid);
4998 rx_DestroyConnection(tempconn);
5000 rx_DestroyConnection(toconn);
5001 PrintError("", error);
5006 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
5007 char tovolname[], int flags,
5008 afs_int32(*WriteData) (struct rx_call *, void *),
5011 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
5016 /*unlocks the vldb entry associated with <volid> */
5018 UV_LockRelease(afs_uint32 volid)
5022 VPRINT("Binding to the VLDB server\n");
5024 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5025 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5028 "Could not unlock the entry for volume number %lu in VLDB \n",
5029 (unsigned long)volid);
5030 PrintError("", vcode);
5033 VPRINT("VLDB updated\n");
5038 /* old interface to add rosites */
5040 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5043 return UV_AddSite2(server, part, volid, 0, valid);
5046 /*adds <server> and <part> as a readonly replication site for <volid>
5049 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5050 afs_uint32 rovolid, afs_int32 valid)
5052 int j, nro = 0, islocked = 0;
5053 struct nvldbentry entry, storeEntry, entry2;
5054 afs_int32 vcode, error = 0;
5057 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5060 " Could not lock the VLDB entry for the volume %lu \n",
5061 (unsigned long)volid);
5066 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
5069 "Could not fetch the VLDB entry for volume number %lu \n",
5070 (unsigned long)volid);
5074 if (!ISNAMEVALID(entry.name)) {
5076 "Volume name %s is too long, rename before adding site\n",
5078 error = VOLSERBADOP;
5081 MapHostToNetwork(&entry);
5083 /* See if it's too many entries */
5084 if (entry.nServers >= NMAXNSERVERS) {
5085 fprintf(STDERR, "Total number of entries will exceed %u\n",
5087 error = VOLSERBADOP;
5091 /* See if it's on the same server */
5092 for (j = 0; j < entry.nServers; j++) {
5093 if (entry.serverFlags[j] & VLSF_ROVOL) {
5095 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5098 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5101 MapPartIdIntoName(entry.serverPartition[j], apartName);
5103 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5105 error = VOLSERBADOP;
5112 /* See if it's too many RO sites - leave one for the RW */
5113 if (nro >= NMAXNSERVERS - 1) {
5114 fprintf(STDERR, "Total number of sites will exceed %u\n",
5116 error = VOLSERBADOP;
5120 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5121 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5122 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5125 if (entry.volumeId[ROVOL] == INVALID_BID) {
5126 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5128 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5131 VPRINT1("Using RO volume id %d.\n", rovolid);
5132 entry.volumeId[ROVOL] = rovolid;
5134 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5135 rovolid, entry.volumeId[ROVOL]);
5139 VPRINT("Adding a new site ...");
5140 entry.serverNumber[entry.nServers] = server;
5141 entry.serverPartition[entry.nServers] = part;
5143 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5145 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5149 MapNetworkToHost(&entry, &storeEntry);
5151 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5152 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5154 fprintf(STDERR, "Could not update entry for volume %lu \n",
5155 (unsigned long)volid);
5164 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5165 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5168 "Could not release lock on volume entry for %lu \n",
5169 (unsigned long)volid);
5170 PrintError("", vcode);
5174 PrintError("", error);
5178 /*removes <server> <part> as read only site for <volid> from the vldb */
5180 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5183 struct nvldbentry entry, storeEntry;
5185 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5187 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5188 (unsigned long)volid);
5189 PrintError("", vcode);
5192 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5195 "Could not fetch the entry for volume number %lu from VLDB \n",
5196 (unsigned long)volid);
5197 PrintError("", vcode);
5200 MapHostToNetwork(&entry);
5201 if (!Lp_ROMatch(server, part, &entry)) {
5202 /*this site doesnot exist */
5203 fprintf(STDERR, "This site is not a replication site \n");
5205 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5206 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5208 fprintf(STDERR, "Could not update entry for volume %lu \n",
5209 (unsigned long)volid);
5210 PrintError("", vcode);
5211 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5212 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5216 } else { /*remove the rep site */
5217 Lp_SetROValue(&entry, server, part, 0, 0);
5219 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5220 entry.flags &= ~VLF_ROEXISTS;
5221 if (entry.nServers < 1) { /*this is the last ref */
5222 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5224 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5227 "Could not delete VLDB entry for volume %lu \n",
5228 (unsigned long)volid);
5229 PrintError("", vcode);
5234 MapNetworkToHost(&entry, &storeEntry);
5235 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5236 (unsigned long)volid);
5239 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5240 LOCKREL_OPCODE | LOCKREL_AFSID |
5244 "Could not release lock on volume entry for %lu \n",
5245 (unsigned long)volid);
5246 PrintError("", vcode);
5247 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5248 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5256 /*sets <server> <part> as read/write site for <volid> in the vldb */
5258 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5261 struct nvldbentry entry, storeEntry;
5264 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5266 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5267 (unsigned long)volid);
5268 PrintError("", vcode);
5271 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5274 "Could not fetch the entry for volume number %lu from VLDB \n",
5275 (unsigned long)volid);
5276 PrintError("", vcode);
5279 MapHostToNetwork(&entry);
5280 index = Lp_GetRwIndex(&entry);
5282 /* no RW site exists */
5283 fprintf(STDERR, "No existing RW site for volume %lu",
5284 (unsigned long)volid);
5286 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5287 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5290 "Could not release lock on entry for volume %lu \n",
5291 (unsigned long)volid);
5292 PrintError("", vcode);
5296 } else { /* change the RW site */
5297 entry.serverNumber[index] = server;
5298 entry.serverPartition[index] = part;
5299 MapNetworkToHost(&entry, &storeEntry);
5301 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5302 LOCKREL_OPCODE | LOCKREL_AFSID |
5305 fprintf(STDERR, "Could not update entry for volume %lu \n",
5306 (unsigned long)volid);
5307 PrintError("", vcode);
5308 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5309 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5317 /*list all the partitions on <aserver> */
5319 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5322 struct rx_connection *aconn;
5323 struct pIDs partIds;
5324 struct partEntries partEnts;
5328 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5330 partEnts.partEntries_len = 0;
5331 partEnts.partEntries_val = NULL;
5332 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5333 if (code == RXGEN_OPCODE) {
5334 for (i = 0; i < 26; i++) /* try old interface */
5335 partIds.partIds[i] = -1;
5336 code = AFSVolListPartitions(aconn, &partIds);
5338 for (i = 0; i < 26; i++) {
5339 if ((partIds.partIds[i]) != -1) {
5340 ptrPartList->partId[j] = partIds.partIds[i];
5341 ptrPartList->partFlags[j] = PARTVALID;
5344 ptrPartList->partFlags[i] = 0;
5349 *cntp = partEnts.partEntries_len;
5350 if (*cntp > VOLMAXPARTS) {
5352 "Warning: number of partitions on the server too high %d (process only %d)\n",
5353 *cntp, VOLMAXPARTS);
5354 *cntp = VOLMAXPARTS;
5356 for (i = 0; i < *cntp; i++) {
5357 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5358 ptrPartList->partFlags[i] = PARTVALID;
5360 free(partEnts.partEntries_val);
5366 "Could not fetch the list of partitions from the server\n");
5367 PrintError("", code);
5369 rx_DestroyConnection(aconn);
5374 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5375 This is used by the backup system */
5377 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5378 struct volDescription *volPtr, afs_int32 arraySize)
5380 struct rx_connection *aconn;
5381 struct volDescription *curPtr;
5384 afs_int32 success = 1;
5386 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5388 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5389 if (curPtr->volFlags & CLONEVALID) {
5390 curPtr->volFlags &= ~CLONEZAPPED;
5393 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5394 "clone", 0, NULL, NULL);
5399 curPtr->volFlags |= CLONEZAPPED;
5401 fprintf(STDERR, "Could not zap volume %lu\n",
5402 (unsigned long)curPtr->volCloneId);
5404 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5405 curPtr->volCloneId);
5410 rx_DestroyConnection(aconn);
5414 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5417 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5418 struct volDescription *volPtr, afs_int32 arraySize)
5420 struct rx_connection *aconn;
5421 struct volDescription *curPtr;
5424 afs_int32 rcode = 0;
5426 int reuseCloneId = 0;
5427 afs_uint32 curCloneId = 0;
5428 char cloneName[256]; /*max vol name */
5430 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5432 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5434 else { /*get a bunch of id's from vldb */
5436 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5438 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5439 PrintError("", code);
5444 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5445 if (curPtr->volFlags & ENTRYVALID) {
5447 curPtr->volFlags |= CLONEVALID;
5448 /*make a clone of curParentId and record as curPtr->volCloneId */
5450 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5453 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5456 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5460 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5461 strcpy(cloneName, curPtr->volName);
5462 strcat(cloneName, "-tmpClone-");
5464 strcpy(cloneName, "-tmpClone");
5466 curPtr->volCloneId = curCloneId;
5471 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5472 &(curPtr->volCloneId));
5474 curPtr->volFlags &= ~CLONEVALID;
5476 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5477 curPtr->volName, (unsigned long)code);
5478 code = AFSVolEndTrans(aconn, tid, &rcode);
5480 fprintf(STDERR, "WARNING: could not end transaction\n");
5483 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5484 curPtr->volCloneId);
5485 code = AFSVolEndTrans(aconn, tid, &rcode);
5486 if (code || rcode) {
5487 curPtr->volFlags &= ~CLONEVALID;
5496 rx_DestroyConnection(aconn);
5501 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5502 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5504 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5505 struct volintInfo **resultPtr, afs_int32 * size)
5507 struct rx_connection *aconn;
5509 volEntries volumeInfo;
5512 *resultPtr = (volintInfo *) 0;
5513 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5514 volumeInfo.volEntries_len = 0;
5516 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5517 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5520 "Could not fetch the list of volumes from the server\n");
5522 *resultPtr = volumeInfo.volEntries_val;
5523 *size = volumeInfo.volEntries_len;
5527 rx_DestroyConnection(aconn);
5528 PrintError("", code);
5532 /*------------------------------------------------------------------------
5533 * EXPORTED UV_XListVolumes
5536 * List the extended information for all the volumes on a particular
5537 * File Server and partition. We may either return the volume's ID
5538 * or all of its extended information.
5541 * a_serverID : Address of the File Server for which we want
5542 * extended volume info.
5543 * a_partID : Partition for which we want the extended
5545 * a_all : If non-zero, fetch ALL the volume info,
5546 * otherwise just the volume ID.
5547 * a_resultPP : Ptr to the address of the area containing
5548 * the returned volume info.
5549 * a_numEntsInResultP : Ptr for the value we set for the number of
5554 * Otherise, the return value of AFSVolXListVolumes.
5557 * This routine is closely related to UV_ListVolumes, which returns
5558 * only the standard level of detail on AFS volumes. It is a
5559 * heavyweight operation, zipping through all the volume entries for
5560 * a given server/partition.
5564 *------------------------------------------------------------------------*/
5567 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5568 struct volintXInfo **a_resultPP,
5569 afs_int32 * a_numEntsInResultP)
5571 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5572 afs_int32 code; /*Error code to return */
5573 volXEntries volumeXInfo; /*Area for returned extended vol info */
5576 * Set up our error code and the area for returned extended volume info.
5577 * We set the val field to a null pointer as a hint for the stub to
5580 *a_numEntsInResultP = 0;
5581 *a_resultPP = (volintXInfo *) 0;
5582 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5583 volumeXInfo.volXEntries_len = 0;
5586 * Bind to the Volume Server port on the File Server machine in question,
5589 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5590 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5592 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5595 * We got the info; pull out the pointer to where the results lie
5596 * and how many entries are there.
5598 *a_resultPP = volumeXInfo.volXEntries_val;
5599 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5603 * If we got an Rx connection, throw it away.
5606 rx_DestroyConnection(rxConnP);
5608 PrintError("", code);
5610 } /*UV_XListVolumes */
5612 /* get all the information about volume <volid> on <aserver> and <apart> */
5614 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5615 struct volintInfo **resultPtr)
5617 struct rx_connection *aconn;
5619 volEntries volumeInfo;
5621 *resultPtr = (volintInfo *) 0;
5622 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5623 volumeInfo.volEntries_len = 0;
5625 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5626 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5629 "Could not fetch the information about volume %lu from the server\n",
5630 (unsigned long)volid);
5632 *resultPtr = volumeInfo.volEntries_val;
5637 rx_DestroyConnection(aconn);
5638 PrintError("", code);
5642 /*------------------------------------------------------------------------
5643 * EXPORTED UV_XListOneVolume
5646 * List the extended information for a volume on a particular File
5647 * Server and partition.
5650 * a_serverID : Address of the File Server for which we want
5651 * extended volume info.
5652 * a_partID : Partition for which we want the extended
5654 * a_volID : Volume ID for which we want the info.
5655 * a_resultPP : Ptr to the address of the area containing
5656 * the returned volume info.
5660 * Otherise, the return value of AFSVolXListOneVolume.
5663 * This routine is closely related to UV_ListOneVolume, which returns
5664 * only the standard level of detail on the chosen AFS volume.
5668 *------------------------------------------------------------------------*/
5671 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5672 struct volintXInfo **a_resultPP)
5674 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5675 afs_int32 code; /*Error code */
5676 volXEntries volumeXInfo; /*Area for returned info */
5679 * Set up our error code, and the area we're in which we are returning
5680 * the info. Setting the val field to a null pointer tells the stub
5681 * to allocate space for us.
5683 *a_resultPP = (volintXInfo *) 0;
5684 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5685 volumeXInfo.volXEntries_len = 0;
5688 * Bind to the Volume Server port on the File Server machine in question,
5691 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5692 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5695 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5698 * We got the info; pull out the pointer to where the results lie.
5700 *a_resultPP = volumeXInfo.volXEntries_val;
5703 * If we got an Rx connection, throw it away.
5706 rx_DestroyConnection(rxConnP);
5708 PrintError("", code);
5713 * Given a volume we read from a partition, check if it is
5714 * represented in the VLDB correctly.
5716 * The VLDB is looked up by the RW volume id (not its name).
5717 * The RW contains the true name of the volume (BK and RO set
5718 * the name in the VLDB only on creation of the VLDB entry).
5719 * We want rules strict enough that when we check all volumes
5720 * on one partition, it does not need to be done again. IE:
5721 * two volumes on different partitions won't constantly
5722 * change a VLDB entry away from what the other set.
5723 * For RW and BK volumes, we will always check the VLDB to see
5724 * if the two exist on the server/partition. May seem redundant,
5725 * but this is an easy check of the VLDB. IE: if the VLDB entry
5726 * says the BK exists but no BK volume is there, we will detect
5727 * this when we check the RW volume.
5728 * VLDB entries are locked only when a change needs to be done.
5729 * Output changed to look a lot like the "vos syncserv" otuput.
5732 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5733 afs_int32 * modentry, afs_uint32 * maxvolid,
5734 struct nvldbentry *aentry)
5738 afs_int32 code, error = 0;
5739 struct nvldbentry entry, storeEntry;
5741 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5751 ((volumeinfo->type ==
5752 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5755 /* Check to see if the VLDB is ok without locking it (pass 1).
5756 * If it will change, then lock the VLDB entry, read it again,
5757 * then make the changes to it (pass 2).
5760 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5762 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5763 (unsigned long)rwvolid);
5768 createentry = 0; /* Do we need to create a VLDB entry */
5769 addvolume = 0; /* Add this volume to the VLDB entry */
5770 modified = 0; /* The VLDB entry was modified */
5773 memcpy(&entry, aentry, sizeof(entry));
5775 /* Read the entry from VLDB by its RW volume id */
5776 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5778 if (code != VL_NOENT) {
5780 "Could not retrieve the VLDB entry for volume %lu \n",
5781 (unsigned long)rwvolid);
5785 memset(&entry, 0, sizeof(entry));
5786 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5790 MapHostToNetwork(&entry);
5794 if (verbose && (pass == 1)) {
5795 fprintf(STDOUT, "_______________________________\n");
5796 fprintf(STDOUT, "\n-- status before -- \n");
5798 fprintf(STDOUT, "\n**does not exist**\n");
5800 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
5801 || (entry.flags & VLF_BACKEXISTS))
5802 EnumerateEntry(&entry);
5804 fprintf(STDOUT, "\n");
5807 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5813 /* Check existence of RW and BK volumes */
5814 code = CheckVldbRWBK(&entry, &mod);
5820 idx = Lp_GetRwIndex(&entry);
5821 if (idx == -1) { /* RW index not found in the VLDB entry */
5822 idx = entry.nServers; /* put it into next index */
5825 } else { /* RW index found in the VLDB entry. */
5826 /* Verify if this volume's location matches where the VLDB says it is */
5827 if (!Lp_Match(aserver, apart, &entry)) {
5828 if (entry.flags & VLF_RWEXISTS) {
5829 /* The RW volume exists elsewhere - report this one a duplicate */
5831 MapPartIdIntoName(apart, pname);
5833 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5834 (unsigned long)rwvolid,
5836 afs_inet_ntoa_r(aserver, hoststr) :
5837 hostutil_GetNameByINet(aserver), pname);
5838 MapPartIdIntoName(entry.serverPartition[idx],
5841 " VLDB reports RW volume %lu exists on %s %s\n",
5842 (unsigned long)rwvolid,
5844 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5845 hostutil_GetNameByINet(entry.
5850 /* The RW volume does not exist - have VLDB point to this one */
5853 /* Check for orphaned BK volume on old partition */
5854 if (entry.flags & VLF_BACKEXISTS) {
5856 MapPartIdIntoName(entry.serverPartition[idx],
5859 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5860 entry.volumeId[BACKVOL],
5862 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5863 hostutil_GetNameByINet(entry.
5866 MapPartIdIntoName(apart, pname);
5868 " VLDB reports its RW volume %lu exists on %s %s\n",
5869 (unsigned long)rwvolid,
5871 afs_inet_ntoa_r(aserver, hoststr) :
5872 hostutil_GetNameByINet(aserver),
5878 /* Volume location matches the VLDB location */
5879 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5880 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5883 (entry.name, volumeinfo->name,
5884 VOLSER_OLDMAXVOLNAME) != 0)) {
5892 entry.flags |= VLF_RWEXISTS;
5893 entry.volumeId[RWVOL] = rwvolid;
5894 if (!entry.volumeId[BACKVOL])
5895 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5896 if (!entry.volumeId[ROVOL])
5897 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5899 entry.serverFlags[idx] = VLSF_RWVOL;
5900 entry.serverNumber[idx] = aserver;
5901 entry.serverPartition[idx] = apart;
5902 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5906 /* One last check - to update BK if need to */
5907 code = CheckVldbRWBK(&entry, &mod);
5915 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5921 /* Check existence of RW and BK volumes */
5922 code = CheckVldbRWBK(&entry, &mod);
5928 idx = Lp_GetRwIndex(&entry);
5929 if (idx == -1) { /* RW index not found in the VLDB entry */
5930 idx = entry.nServers; /* Put it into next index */
5933 } else { /* RW index found in the VLDB entry */
5934 /* Verify if this volume's location matches where the VLDB says it is */
5935 if (!Lp_Match(aserver, apart, &entry)) {
5936 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5938 MapPartIdIntoName(apart, pname);
5940 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5941 (unsigned long)volumeinfo->volid,
5943 afs_inet_ntoa_r(aserver, hoststr) :
5944 hostutil_GetNameByINet(aserver), pname);
5945 MapPartIdIntoName(entry.serverPartition[idx], pname);
5947 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5948 (unsigned long)rwvolid,
5950 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5951 hostutil_GetNameByINet(entry.
5956 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5957 if (!(entry.flags & VLF_BACKEXISTS)) {
5959 } else if (volumeinfo->volid >
5960 entry.volumeId[BACKVOL]) {
5964 MapPartIdIntoName(entry.serverPartition[idx],
5967 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5968 entry.volumeId[BACKVOL],
5970 afs_inet_ntoa_r(aserver, hoststr) :
5971 hostutil_GetNameByINet(aserver),
5974 " VLDB reports its BK volume ID is %lu\n",
5975 (unsigned long)volumeinfo->volid);
5979 MapPartIdIntoName(entry.serverPartition[idx],
5982 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5983 (unsigned long)volumeinfo->volid,
5985 afs_inet_ntoa_r(aserver, hoststr) :
5986 hostutil_GetNameByINet(aserver),
5989 " VLDB reports its BK volume ID is %u\n",
5990 entry.volumeId[BACKVOL]);
5993 } else if (!entry.volumeId[BACKVOL]) {
6000 entry.flags |= VLF_BACKEXISTS;
6001 entry.volumeId[RWVOL] = rwvolid;
6002 entry.volumeId[BACKVOL] = volumeinfo->volid;
6004 entry.serverNumber[idx] = aserver;
6005 entry.serverPartition[idx] = apart;
6006 entry.serverFlags[idx] = VLSF_RWVOL;
6012 else if (volumeinfo->type == ROVOL) { /* A RO volume */
6013 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
6014 /* This is a quick check to see if the RO entry exists in the
6015 * VLDB so we avoid the CheckVldbRO() call (which checks if each
6016 * RO volume listed in the VLDB exists).
6018 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6020 idx = entry.nServers;
6024 if (!(entry.flags & VLF_ROEXISTS)) {
6029 /* Before we correct the VLDB entry, make sure all the
6030 * ROs listed in the VLDB exist.
6032 code = CheckVldbRO(&entry, &mod);
6038 if (!(entry.flags & VLF_ROEXISTS)) {
6039 /* No RO exists in the VLDB entry - add this one */
6040 idx = entry.nServers;
6043 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
6044 /* The volume headers's RO ID does not match that in the VLDB entry,
6045 * and the vol hdr's ID is greater (implies more recent). So delete
6046 * all the RO volumes listed in VLDB entry and add this volume.
6048 for (j = 0; j < entry.nServers; j++) {
6049 if (entry.serverFlags[j] & VLSF_ROVOL) {
6050 /* Verify this volume exists and print message we are orphaning it */
6052 MapPartIdIntoName(apart, pname);
6054 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
6055 entry.volumeId[ROVOL],
6057 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
6058 hostutil_GetNameByINet(entry.
6062 " VLDB reports its RO volume ID is %lu\n",
6063 (unsigned long)volumeinfo->volid);
6066 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6067 entry.serverPartition[idx], 0L, 0L);
6074 idx = entry.nServers;
6077 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6078 /* The volume headers's RO ID does not match that in the VLDB entry,
6079 * and the vol hdr's ID is lower (implies its older). So orphan it.
6082 MapPartIdIntoName(apart, pname);
6084 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6085 (unsigned long)volumeinfo->volid,
6087 afs_inet_ntoa_r(aserver, hoststr) :
6088 hostutil_GetNameByINet(aserver), pname);
6090 " VLDB reports its RO volume ID is %u\n",
6091 entry.volumeId[ROVOL]);
6094 /* The RO volume ID in the volume header match that in the VLDB entry,
6095 * and there exist RO volumes in the VLDB entry. See if any of them
6096 * are this one. If not, then we add it.
6098 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6100 idx = entry.nServers;
6108 entry.flags |= VLF_ROEXISTS;
6109 entry.volumeId[RWVOL] = rwvolid;
6110 entry.volumeId[ROVOL] = volumeinfo->volid;
6112 entry.serverNumber[idx] = aserver;
6113 entry.serverPartition[idx] = apart;
6114 entry.serverFlags[idx] = VLSF_ROVOL;
6120 /* Remember largest volume id */
6121 if (entry.volumeId[ROVOL] > *maxvolid)
6122 *maxvolid = entry.volumeId[ROVOL];
6123 if (entry.volumeId[BACKVOL] > *maxvolid)
6124 *maxvolid = entry.volumeId[BACKVOL];
6125 if (entry.volumeId[RWVOL] > *maxvolid)
6126 *maxvolid = entry.volumeId[RWVOL];
6128 if (modified && doit) {
6129 MapNetworkToHost(&entry, &storeEntry);
6132 code = VLDB_CreateEntry(&storeEntry);
6135 "Could not create a VLDB entry for the volume %lu\n",
6136 (unsigned long)rwvolid);
6143 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6144 LOCKREL_OPCODE | LOCKREL_AFSID |
6147 fprintf(STDERR, "Could not update entry for %lu\n",
6148 (unsigned long)rwvolid);
6152 } else if (pass == 2) {
6154 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6155 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6157 PrintError("Could not unlock VLDB entry ", code);
6161 if (modified && modentry) {
6166 memcpy(aentry, &entry, sizeof(entry));
6170 fprintf(STDOUT, "-- status after --\n");
6172 EnumerateEntry(&entry);
6174 fprintf(STDOUT, "\n**no change**\n");
6178 VPRINT("\n_______________________________\n");
6183 sortVolumes(const void *a, const void *b)
6185 volintInfo *v1 = (volintInfo *) a;
6186 volintInfo *v2 = (volintInfo *) b;
6187 afs_uint32 rwvolid1, rwvolid2;
6189 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6190 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6192 if (rwvolid1 > rwvolid2)
6193 return -1; /* lower RW id goes first */
6194 if (rwvolid1 < rwvolid2)
6197 if (v1->type == RWVOL)
6198 return -1; /* RW vols go first */
6199 if (v2->type == RWVOL)
6202 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6203 return -1; /* BK vols next */
6204 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6207 if (v1->volid < v2->volid)
6208 return 1; /* larger volids first */
6209 if (v1->volid > v2->volid)
6215 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6216 * Synchronize an individual volume against a sever and partition.
6217 * Checks the VLDB entry (similar to syncserv) as well as checks
6218 * if the volume exists on specified servers (similar to syncvldb).
6221 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6223 struct rx_connection *aconn = 0;
6224 afs_int32 j, k, code, vcode, error = 0;
6226 afs_int32 mod, modified = 0, deleted = 0;
6227 struct nvldbentry vldbentry;
6228 afs_uint32 volumeid = 0;
6229 volEntries volumeInfo;
6230 struct partList PartList;
6232 afs_uint32 maxvolid = 0;
6234 volumeInfo.volEntries_val = (volintInfo *) 0;
6235 volumeInfo.volEntries_len = 0;
6237 /* Turn verbose logging off and do our own verbose logging */
6238 /* tverbose must be set before we call ERROR_EXIT() */
6245 if (!aserver && (flags & 1)) {
6246 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6250 /* Read the VLDB entry */
6251 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6252 if (vcode && (vcode != VL_NOENT)) {
6253 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6256 } else if (!vcode) {
6257 MapHostToNetwork(&vldbentry);
6261 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6262 fprintf(STDOUT, "_______________________________\n");
6263 fprintf(STDOUT, "\n-- status before -- \n");
6265 fprintf(STDOUT, "\n**does not exist**\n");
6267 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6268 || (vldbentry.flags & VLF_BACKEXISTS))
6269 EnumerateEntry(&vldbentry);
6271 fprintf(STDOUT, "\n");
6274 /* Verify that all of the VLDB entries exist on the repective servers
6275 * and partitions (this does not require that avolname be a volume ID).
6276 * Equivalent to a syncserv.
6279 /* Tell CheckVldb not to update if appropriate */
6284 code = CheckVldb(&vldbentry, &mod, &deleted);
6286 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6294 /* If aserver is given, we will search for the desired volume on it */
6296 /* Generate array of partitions on the server that we will check */
6298 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6301 "Could not fetch the list of partitions from the server\n");
6305 PartList.partId[0] = apart;
6309 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6311 /* If a volume ID were given, search for it on each partition */
6312 if ((volumeid = atol(avolname))) {
6313 for (j = 0; j < pcnt; j++) {
6315 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6318 if (code != ENODEV) {
6319 fprintf(STDERR, "Could not query server\n");
6327 /* Found one, sync it with VLDB entry */
6329 CheckVolume(volumeInfo.volEntries_val, aserver,
6330 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6337 if (volumeInfo.volEntries_val)
6338 free(volumeInfo.volEntries_val);
6339 volumeInfo.volEntries_val = (volintInfo *) 0;
6340 volumeInfo.volEntries_len = 0;
6344 /* Check to see if the RW, BK, and RO IDs exist on any
6345 * partitions. We get the volume IDs from the VLDB.
6347 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6348 if (vldbentry.volumeId[j] == 0)
6351 for (k = 0; k < pcnt; k++) { /* For each partition */
6352 volumeInfo.volEntries_val = (volintInfo *) 0;
6353 volumeInfo.volEntries_len = 0;
6355 AFSVolListOneVolume(aconn, PartList.partId[k],
6356 vldbentry.volumeId[j], &volumeInfo);
6358 if (code != ENODEV) {
6359 fprintf(STDERR, "Could not query server\n");
6367 /* Found one, sync it with VLDB entry */
6369 CheckVolume(volumeInfo.volEntries_val, aserver,
6370 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6377 if (volumeInfo.volEntries_val)
6378 free(volumeInfo.volEntries_val);
6379 volumeInfo.volEntries_val = (volintInfo *) 0;
6380 volumeInfo.volEntries_len = 0;
6386 /* If verbose output, print a summary of what changed */
6388 fprintf(STDOUT, "-- status after --\n");
6390 fprintf(STDOUT, "\n**entry deleted**\n");
6391 } else if (modified) {
6392 EnumerateEntry(&vldbentry);
6394 fprintf(STDOUT, "\n**no change**\n");
6396 fprintf(STDOUT, "\n_______________________________\n");
6400 /* Now check if the maxvolid is larger than that stored in the VLDB */
6402 afs_uint32 maxvldbid = 0;
6403 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6406 "Could not get the highest allocated volume id from the VLDB\n");
6409 } else if (maxvolid > maxvldbid) {
6411 id = maxvolid - maxvldbid + 1;
6412 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6415 "Error in increasing highest allocated volume id in VLDB\n");
6425 fprintf(STDOUT, "...error encountered");
6427 fprintf(STDOUT, "...done entry\n");
6430 rx_DestroyConnection(aconn);
6431 if (volumeInfo.volEntries_val)
6432 free(volumeInfo.volEntries_val);
6434 PrintError("", error);
6439 * Synchronise vldb with the file server <aserver> and,
6440 * optionally, <apart>.
6443 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6445 struct rx_connection *aconn;
6446 afs_int32 code, error = 0;
6449 volEntries volumeInfo;
6450 struct partList PartList;
6454 afs_int32 failures = 0, modifications = 0, tentries = 0;
6456 afs_uint32 maxvolid = 0;
6459 volumeInfo.volEntries_val = (volintInfo *) 0;
6460 volumeInfo.volEntries_len = 0;
6462 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6464 /* Generate array of partitions to check */
6466 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6469 "Could not fetch the list of partitions from the server\n");
6473 PartList.partId[0] = apart;
6477 VPRINT("Processing volume entries ...\n");
6479 /* Step through the array of partitions */
6480 for (i = 0; i < pcnt; i++) {
6481 apart = PartList.partId[i];
6482 MapPartIdIntoName(apart, pname);
6484 volumeInfo.volEntries_val = (volintInfo *) 0;
6485 volumeInfo.volEntries_len = 0;
6486 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6489 "Could not fetch the list of volumes from the server\n");
6493 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6494 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6495 sizeof(volintInfo), sortVolumes);
6498 for (vi = volumeInfo.volEntries_val, j = 0;
6499 j < volumeInfo.volEntries_len; j++, vi++) {
6507 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6508 j + 1, vi->name, (unsigned long)vi->volid,
6510 afs_inet_ntoa_r(aserver, hoststr) :
6511 hostutil_GetNameByINet(aserver), pname);
6519 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6521 PrintError("", code);
6524 } else if (modified) {
6530 fprintf(STDOUT, "...error encountered\n\n");
6532 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6539 "Could not process entries on server %s partition %s\n",
6541 afs_inet_ntoa_r(aserver, hoststr) :
6542 hostutil_GetNameByINet(aserver), pname);
6544 if (volumeInfo.volEntries_val) {
6545 free(volumeInfo.volEntries_val);
6546 volumeInfo.volEntries_val = 0;
6549 } /* thru all partitions */
6552 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6553 tentries, failures, modifications);
6555 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6556 tentries, failures, modifications);
6560 /* Now check if the maxvolid is larger than that stored in the VLDB */
6562 afs_uint32 maxvldbid = 0;
6563 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6566 "Could not get the highest allocated volume id from the VLDB\n");
6569 } else if (maxvolid > maxvldbid) {
6571 id = maxvolid - maxvldbid + 1;
6572 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6575 "Error in increasing highest allocated volume id in VLDB\n");
6583 rx_DestroyConnection(aconn);
6584 if (volumeInfo.volEntries_val)
6585 free(volumeInfo.volEntries_val);
6586 PrintError("", error);
6591 * Determine if a volume exists on a server and partition.
6592 * Try creating a transaction on the volume. If we can,
6593 * the volume exists, if not, then return the error code.
6594 * Some error codes mean the volume is unavailable but
6595 * still exists - so we catch these error codes.
6598 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6600 struct rx_connection *conn = (struct rx_connection *)0;
6601 afs_int32 code = -1;
6602 volEntries volumeInfo;
6604 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6606 volumeInfo.volEntries_val = (volintInfo *) 0;
6607 volumeInfo.volEntries_len = 0;
6608 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6609 if (volumeInfo.volEntries_val)
6610 free(volumeInfo.volEntries_val);
6611 if (code == VOLSERILLEGAL_PARTITION)
6613 rx_DestroyConnection(conn);
6622 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6626 afs_int32 code, error = 0;
6632 idx = Lp_GetRwIndex(entry);
6634 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6637 if (idx == -1) { /* Did not find a RW entry */
6638 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6639 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6644 VolumeExists(entry->serverNumber[idx],
6645 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6646 if (code == 0) { /* RW volume exists */
6647 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6648 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6651 } else if (code == ENODEV) { /* RW volume does not exist */
6652 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6653 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6657 /* If VLDB says it didn't exist, then ignore error */
6658 if (entry->flags & VLF_RWEXISTS) {
6659 MapPartIdIntoName(entry->serverPartition[idx], pname);
6661 "Transaction call failed for RW volume %u on server %s %s\n",
6662 entry->volumeId[RWVOL],
6664 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6665 hostutil_GetNameByINet(entry->serverNumber[idx]),
6672 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6673 * flag accordingly. idx already ponts to the RW entry.
6675 if (idx == -1) { /* Did not find a RW entry */
6676 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6677 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6680 } else { /* Found a RW entry */
6682 VolumeExists(entry->serverNumber[idx],
6683 entry->serverPartition[idx],
6684 entry->volumeId[BACKVOL]);
6685 if (code == 0) { /* BK volume exists */
6686 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6687 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6690 } else if (code == ENODEV) { /* BK volume does not exist */
6691 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6692 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6696 /* If VLDB says it didn't exist, then ignore error */
6697 if (entry->flags & VLF_BACKEXISTS) {
6698 MapPartIdIntoName(entry->serverPartition[idx], pname);
6700 "Transaction call failed for BK volume %u on server %s %s\n",
6701 entry->volumeId[BACKVOL],
6703 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6704 hostutil_GetNameByINet(entry->serverNumber[idx]),
6711 /* If there is an idx but the BK and RW volumes no
6712 * longer exist, then remove the RW entry.
6714 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6715 && !(entry->flags & VLF_BACKEXISTS)) {
6716 Lp_SetRWValue(entry, entry->serverNumber[idx],
6717 entry->serverPartition[idx], 0L, 0L);
6724 *modified = modentry;
6729 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6732 int foundro = 0, modentry = 0;
6733 afs_int32 code, error = 0;
6740 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6743 for (idx = 0; idx < entry->nServers; idx++) {
6744 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6745 continue; /* not a RO */
6749 VolumeExists(entry->serverNumber[idx],
6750 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6751 if (code == 0) { /* RO volume exists */
6753 } else if (code == ENODEV) { /* RW volume does not exist */
6754 Lp_SetROValue(entry, entry->serverNumber[idx],
6755 entry->serverPartition[idx], 0L, 0L);
6760 MapPartIdIntoName(entry->serverPartition[idx], pname);
6762 "Transaction call failed for RO %u on server %s %s\n",
6763 entry->volumeId[ROVOL],
6765 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6766 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6771 if (foundro) { /* A RO volume exists */
6772 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6773 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6776 } else { /* A RO volume does not exist */
6777 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6778 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
6785 *modified = modentry;
6790 * Ensure that <entry> matches with the info on file servers
6793 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6795 afs_int32 code, error = 0;
6796 struct nvldbentry storeEntry;
6797 int islocked = 0, mod, modentry, delentry = 0;
6798 int pass = 0, doit=1;
6806 fprintf(STDOUT, "_______________________________\n");
6807 fprintf(STDOUT, "\n-- status before -- \n");
6808 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
6809 || (entry->flags & VLF_BACKEXISTS))
6810 EnumerateEntry(entry);
6811 fprintf(STDOUT, "\n");
6814 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6815 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6816 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6820 /* Check to see if the VLDB is ok without locking it (pass 1).
6821 * If it will change, then lock the VLDB entry, read it again,
6822 * then make the changes to it (pass 2).
6826 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6829 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6830 entry->volumeId[RWVOL]);
6835 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6837 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6841 MapHostToNetwork(entry);
6847 /* Check if the RW and BK entries are ok */
6848 code = CheckVldbRWBK(entry, &mod);
6851 if (mod && (pass == 1) && doit)
6856 /* Check if the RO volumes entries are ok */
6857 code = CheckVldbRO(entry, &mod);
6860 if (mod && (pass == 1) && doit)
6865 /* The VLDB entry has been updated. If it as been modified, then
6866 * write the entry back out the the VLDB.
6868 if (modentry && doit) {
6872 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
6873 && !(entry->flags & VLF_ROEXISTS) && doit) {
6874 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6876 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6880 "Could not delete VLDB entry for volume %u \n",
6881 entry->volumeId[RWVOL]);
6886 /* Replace old entry with our new one */
6887 MapNetworkToHost(entry, &storeEntry);
6889 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6890 (LOCKREL_OPCODE | LOCKREL_AFSID |
6891 LOCKREL_TIMESTAMP));
6893 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6894 entry->volumeId[RWVOL]);
6901 if (modified && modentry) {
6904 if (deleted && delentry) {
6909 fprintf(STDOUT, "-- status after --\n");
6911 fprintf(STDOUT, "\n**entry deleted**\n");
6913 EnumerateEntry(entry);
6915 fprintf(STDOUT, "\n**no change**\n");
6919 VPRINT("\n_______________________________\n");
6923 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6925 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6928 "Could not release lock on VLDB entry for volume %u\n",
6929 entry->volumeId[RWVOL]);
6938 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6941 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6943 struct rx_connection *aconn;
6944 afs_int32 code, error = 0;
6945 afs_int32 nentries, tentries = 0;
6946 struct VldbListByAttributes attributes;
6947 nbulkentries arrayEntries;
6948 afs_int32 failures = 0, modified, modifications = 0;
6949 struct nvldbentry *vlentry;
6950 afs_int32 si, nsi, j;
6955 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6957 /* Set up attributes to search VLDB */
6958 memset(&attributes, 0, sizeof(attributes));
6959 attributes.server = ntohl(aserver);
6960 attributes.Mask = VLLIST_SERVER;
6962 attributes.partition = apart;
6963 attributes.Mask |= VLLIST_PARTITION;
6966 VPRINT("Processing VLDB entries ...\n");
6968 /* While we need to collect more VLDB entries */
6969 for (si = 0; si != -1; si = nsi) {
6970 memset(&arrayEntries, 0, sizeof(arrayEntries));
6972 /* Collect set of VLDB entries */
6974 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6975 &arrayEntries, &nsi);
6976 if (code == RXGEN_OPCODE) {
6977 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6981 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6984 tentries += nentries;
6986 for (j = 0; j < nentries; j++) {
6987 vlentry = &arrayEntries.nbulkentries_val[j];
6988 MapHostToNetwork(vlentry);
6990 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6992 /* Tell CheckVldb not to update if appropriate */
6997 code = CheckVldb(vlentry, &modified, NULL);
6999 PrintError("", code);
7001 "Could not process VLDB entry for volume %s\n",
7004 } else if (modified) {
7010 fprintf(STDOUT, "...error encountered\n\n");
7012 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
7017 if (arrayEntries.nbulkentries_val) {
7018 free(arrayEntries.nbulkentries_val);
7019 arrayEntries.nbulkentries_val = 0;
7024 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
7025 tentries, failures, modifications);
7027 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
7028 tentries, failures, modifications);
7033 rx_DestroyConnection(aconn);
7034 if (arrayEntries.nbulkentries_val)
7035 free(arrayEntries.nbulkentries_val);
7038 error = VOLSERFAILEDOP;
7042 /*rename volume <oldname> to <newname>, changing the names of the related
7043 *readonly and backup volumes. This operation is also idempotent.
7044 *salvager is capable of recovering from rename operation stopping halfway.
7045 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
7047 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
7049 struct nvldbentry storeEntry;
7050 afs_int32 vcode, code, rcode, error;
7052 char nameBuffer[256];
7054 struct rx_connection *aconn;
7059 aconn = (struct rx_connection *)0;
7063 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7066 " Could not lock the VLDB entry for the volume %u \n",
7067 entry->volumeId[RWVOL]);
7072 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7073 MapNetworkToHost(entry, &storeEntry);
7074 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7076 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7077 entry->volumeId[RWVOL]);
7081 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7082 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7083 * is concerned, oldname is lost */
7084 if (entry->flags & VLF_RWEXISTS) {
7085 index = Lp_GetRwIndex(entry);
7086 if (index == -1) { /* there is a serious discrepancy */
7088 "There is a serious discrepancy in VLDB entry for volume %u\n",
7089 entry->volumeId[RWVOL]);
7090 fprintf(STDERR, "try building VLDB from scratch\n");
7091 error = VOLSERVLDB_ERROR;
7094 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7096 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7097 entry->serverPartition[index], ITOffline, &tid);
7098 if (code) { /*volume doesnot exist */
7100 "Could not start transaction on the rw volume %u\n",
7101 entry->volumeId[RWVOL]);
7104 } else { /*volume exists, process it */
7107 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7108 entry->volumeId[RWVOL],
7109 entry->volumeId[ROVOL],
7110 entry->volumeId[BACKVOL]);
7112 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7113 code = AFSVolEndTrans(aconn, tid, &rcode);
7117 "Could not end transaction on volume %s %u\n",
7118 entry->name, entry->volumeId[RWVOL]);
7123 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7124 entry->name, entry->volumeId[RWVOL]);
7130 rx_DestroyConnection(aconn);
7131 aconn = (struct rx_connection *)0;
7133 /*end rw volume processing */
7134 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7135 index = Lp_GetRwIndex(entry);
7136 if (index == -1) { /* there is a serious discrepancy */
7138 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7139 entry->volumeId[BACKVOL]);
7140 fprintf(STDERR, "try building VLDB from scratch\n");
7141 error = VOLSERVLDB_ERROR;
7144 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7146 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7147 entry->serverPartition[index], ITOffline, &tid);
7148 if (code) { /*volume doesnot exist */
7150 "Could not start transaction on the backup volume %u\n",
7151 entry->volumeId[BACKVOL]);
7154 } else { /*volume exists, process it */
7155 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7157 "Volume name %s.backup exceeds the limit of %u characters\n",
7158 newname, VOLSER_OLDMAXVOLNAME);
7162 strcpy(nameBuffer, newname);
7163 strcat(nameBuffer, ".backup");
7166 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7167 entry->volumeId[RWVOL], 0, 0);
7169 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7170 code = AFSVolEndTrans(aconn, tid, &rcode);
7174 "Could not end transaction on the backup volume %u\n",
7175 entry->volumeId[BACKVOL]);
7181 "Could not set parameters on the backup volume %u\n",
7182 entry->volumeId[BACKVOL]);
7187 } /* end backup processing */
7189 rx_DestroyConnection(aconn);
7190 aconn = (struct rx_connection *)0;
7191 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7192 for (i = 0; i < entry->nServers; i++) {
7193 if (entry->serverFlags[i] & VLSF_ROVOL) {
7194 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7196 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7197 entry->serverPartition[i], ITOffline,
7199 if (code) { /*volume doesnot exist */
7201 "Could not start transaction on the ro volume %u\n",
7202 entry->volumeId[ROVOL]);
7205 } else { /*volume exists, process it */
7206 strcpy(nameBuffer, newname);
7207 strcat(nameBuffer, ".readonly");
7208 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7210 "Volume name %s exceeds the limit of %u characters\n",
7211 nameBuffer, VOLSER_OLDMAXVOLNAME);
7216 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7217 entry->volumeId[RWVOL], 0, 0);
7219 VPRINT2("Renamed RO volume %s on host %s\n",
7222 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7223 hostutil_GetNameByINet(entry->
7225 code = AFSVolEndTrans(aconn, tid, &rcode);
7229 "Could not end transaction on volume %u\n",
7230 entry->volumeId[ROVOL]);
7236 "Could not set parameters on the ro volume %u\n",
7237 entry->volumeId[ROVOL]);
7243 rx_DestroyConnection(aconn);
7244 aconn = (struct rx_connection *)0;
7251 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7253 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7256 "Could not unlock the VLDB entry for the volume %s %u\n",
7257 entry->name, entry->volumeId[RWVOL]);
7263 code = AFSVolEndTrans(aconn, tid, &rcode);
7267 fprintf(STDERR, "Failed to end transaction on a volume \n");
7273 rx_DestroyConnection(aconn);
7274 PrintError("", error);
7279 /*report on all the active transactions on volser */
7281 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7283 struct rx_connection *aconn;
7284 transDebugEntries transInfo;
7287 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7288 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7289 transInfo.transDebugEntries_len = 0;
7290 code = AFSVolMonitor(aconn, &transInfo);
7293 "Could not access status information about the server\n");
7294 PrintError("", code);
7295 if (transInfo.transDebugEntries_val)
7296 free(transInfo.transDebugEntries_val);
7298 rx_DestroyConnection(aconn);
7301 *rcount = transInfo.transDebugEntries_len;
7302 *rpntr = transInfo.transDebugEntries_val;
7304 rx_DestroyConnection(aconn);
7311 /*delete the volume without interacting with the vldb */
7313 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7316 struct rx_connection *aconn;
7318 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7319 error = DoVolDelete(aconn, volid, part,
7320 "the", 0, NULL, NULL);
7321 if (error == VNOVOL) {
7322 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7325 PrintError("", error);
7327 rx_DestroyConnection(aconn);
7332 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7333 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7335 struct rx_connection *conn = 0;
7337 afs_int32 code, error = 0, rcode;
7339 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7341 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7345 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7347 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7351 code = AFSVolSetFlags(conn, tid, setflag);
7353 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7358 #ifdef AFS_PTHREAD_ENV
7361 IOMGR_Sleep(sleeptime);
7368 code = AFSVolEndTrans(conn, tid, &rcode);
7369 if (code || rcode) {
7370 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7372 error = (code ? code : rcode);
7377 rx_DestroyConnection(conn);
7382 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7385 struct rx_connection *conn = 0;
7387 afs_int32 code, error = 0, rcode;
7389 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7391 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7395 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7397 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7401 code = AFSVolSetInfo(conn, tid, infop);
7403 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7410 code = AFSVolEndTrans(conn, tid, &rcode);
7411 if (code || rcode) {
7412 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7414 error = (code ? code : rcode);
7419 rx_DestroyConnection(conn);
7424 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7425 afs_int32 fromdate, struct volintSize *vol_size)
7427 struct rx_connection *aconn = (struct rx_connection *)0;
7428 afs_int32 tid = 0, rcode = 0;
7429 afs_int32 code, error = 0;
7432 /* get connections to the servers */
7433 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7435 VPRINT1("Starting transaction on volume %u...", afromvol);
7436 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7437 EGOTO1(error_exit, code,
7438 "Could not start transaction on the volume %u to be measured\n",
7442 VPRINT1("Getting size of volume on volume %u...", afromvol);
7443 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7444 EGOTO(error_exit, code, "Could not start the measurement process \n");
7449 VPRINT1("Ending transaction on volume %u...", afromvol);
7450 code = AFSVolEndTrans(aconn, tid, &rcode);
7451 if (code || rcode) {
7452 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7454 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7456 error = (code ? code : rcode);
7461 rx_DestroyConnection(aconn);
7463 PrintError("", error);
7467 /*maps the host addresses in <old > (present in network byte order) to
7468 that in< new> (present in host byte order )*/
7470 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7474 memset(new, 0, sizeof(struct nvldbentry));
7476 /*copy all the fields */
7477 strcpy(new->name, old->name);
7478 /* new->volumeType = old->volumeType;*/
7479 new->nServers = old->nServers;
7480 count = old->nServers;
7481 if (count < NMAXNSERVERS)
7483 for (i = 0; i < count; i++) {
7484 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7485 new->serverPartition[i] = old->serverPartition[i];
7486 new->serverFlags[i] = old->serverFlags[i];
7488 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7489 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7490 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7491 new->cloneId = old->cloneId;
7492 new->flags = old->flags;
7495 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7497 MapHostToNetwork(struct nvldbentry *entry)
7501 count = entry->nServers;
7502 if (count < NMAXNSERVERS)
7504 for (i = 0; i < count; i++) {
7505 entry->serverNumber[i] = htonl(entry->serverNumber[i]);