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) /* toss away */
1576 fprintf(STDOUT, "type control-c\n");
1578 fprintf(stdout, ".");
1583 /* or drop through */
1586 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1587 EGOTO1(mfail, vcode,
1588 "Could not fetch the entry for the volume %u from the VLDB \n",
1591 if (entry.volumeId[RWVOL] != afromvol) {
1592 fprintf(STDERR, "Only RW volume can be moved\n");
1596 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1597 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1600 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1601 EGOTO1(mfail, vcode,
1602 "Could not fetch the entry for the volume %u from the VLDB \n",
1605 backupId = entry.volumeId[BACKVOL];
1606 MapHostToNetwork(&entry);
1608 if (!Lp_Match(afromserver, afrompart, &entry)) {
1609 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1610 if (!Lp_Match(atoserver, atopart, &entry)) {
1611 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1612 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1613 (unsigned long)afromvol);
1614 fprintf(STDERR, "The current site is :");
1615 for (i = 0; i < entry.nServers; i++) {
1616 if (entry.serverFlags[i] == VLSF_RWVOL) {
1618 MapPartIdIntoName(entry.serverPartition[i], pname);
1619 fprintf(STDERR, " server %s partition %s \n",
1620 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1621 hostutil_GetNameByINet(entry.serverNumber[i]),
1626 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1627 (LOCKREL_OPCODE | LOCKREL_AFSID |
1628 LOCKREL_TIMESTAMP));
1629 EGOTO1(mfail, vcode,
1630 " Could not release lock on the VLDB entry for the volume %u \n",
1633 return VOLSERVOLMOVED;
1636 /* delete the volume afromvol on src_server */
1637 /* from-info does not exist but to-info does =>
1638 * we have already done the move, but the volume
1639 * may still be existing physically on from fileserver
1641 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1644 code = DoVolDelete(fromconn, afromvol, afrompart,
1645 "leftover", 0, NULL, NULL);
1646 if (code && code != VNOVOL) {
1651 code = DoVolDelete(fromconn, backupId, afrompart,
1652 "leftover backup", 0, NULL, NULL);
1653 if (code && code != VNOVOL) {
1663 /* From-info matches the vldb info about volid,
1664 * its ok start the move operation, the backup volume
1665 * on the old site is deleted in the process
1667 if (afrompart == atopart) {
1668 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1669 EGOTO2(mfail, error,
1670 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1671 afromserver, error);
1674 EGOTO1(mfail, VOLSERVOLMOVED,
1675 "Warning: Moving volume %u to its home partition ignored!\n",
1681 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1682 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1683 totid = 0; /* initialize to uncreated */
1686 * clone the read/write volume locally.
1689 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1690 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1692 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1696 if (!(flags & RV_NOCLONE)) {
1697 /* Get a clone id */
1698 VPRINT1("Allocating new volume id for clone of volume %u ...",
1701 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1703 EGOTO1(mfail, vcode,
1704 "Could not get an ID for the clone of volume %u from the VLDB\n",
1708 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1709 VPRINT1("Cloning source volume %u ...", afromvol);
1710 strcpy(vname, "move-clone-temp");
1712 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1714 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1719 /* lookup the name of the volume we just cloned */
1721 code = AFSVolGetName(fromconn, fromtid, &volName);
1722 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1725 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1727 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1732 "Failed to end the transaction on the source volume %u\n",
1737 * Create the destination volume
1740 if (!(flags & RV_NOCLONE)) {
1741 /* All of this is to get the fromDate */
1742 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1745 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1749 "Failed to start a transaction on the cloned volume%u\n",
1753 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1755 AFSVolSetFlags(fromconn, clonetid,
1756 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1757 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1761 /* remember time from which we've dumped the volume */
1762 VPRINT1("Getting status of cloned volume %u ...", newVol);
1763 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1765 "Failed to get the status of the cloned volume %u\n",
1769 fromDate = CLOCKADJ(tstatus.creationDate);
1771 /* With RV_NOCLONE, just do a full copy from the source */
1776 #ifdef ENABLE_BUGFIX_1165
1778 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1779 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1780 * don't use this information...
1782 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1783 volumeInfo.volEntries_len = 0;
1784 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1786 "Failed to get the volint Info of the cloned volume %u\n",
1789 infop = (volintInfo *) volumeInfo.volEntries_val;
1790 infop->maxquota = -1; /* Else it will replace the default quota */
1791 infop->creationDate = -1; /* Else it will use the source creation date */
1792 infop->updateDate = -1; /* Else it will use the source update date */
1795 /* create a volume on the target machine */
1797 code = DoVolDelete(toconn, volid, atopart,
1798 "pre-existing destination", 0, NULL, NULL);
1799 if (code && code != VNOVOL) {
1804 VPRINT1("Creating the destination volume %u ...", volid);
1808 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1812 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1816 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1820 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1822 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1824 "Failed to set the flags on the destination volume %u\n", volid);
1828 * Now dump the clone to the new volume
1831 destination.destHost = ntohl(atoserver);
1832 destination.destPort = AFSCONF_VOLUMEPORT;
1833 destination.destSSID = 1;
1835 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1836 cookie.type = RWVOL;
1837 cookie.parent = entry.volumeId[RWVOL];
1840 if (!(flags & RV_NOCLONE)) {
1841 /* Copy the clone to the new volume */
1842 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1845 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1847 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1850 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1851 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1856 "Failed to end the transaction on the cloned volume %u\n",
1862 * reattach to the main-line volume, and incrementally dump it.
1865 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1867 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1870 "Failed to create a transaction on the source volume %u\n",
1874 /* now do the incremental */
1876 ("Doing the%s dump from source to destination for volume %u ... ",
1877 (flags & RV_NOCLONE) ? "" : " incremental",
1880 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1883 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1884 (flags & RV_NOCLONE) ? "" : " incremental");
1887 /* now adjust the flags so that the new volume becomes official */
1888 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1889 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1891 "Failed to set the flags to make old source volume offline\n");
1894 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1895 code = AFSVolSetFlags(toconn, totid, 0);
1897 "Failed to set the flags to make new source volume online\n");
1900 #ifdef ENABLE_BUGFIX_1165
1901 VPRINT1("Setting volume status on destination volume %u ...", volid);
1902 code = AFSVolSetInfo(toconn, totid, infop);
1904 "Failed to set volume status on the destination volume %u\n",
1909 /* put new volume online */
1910 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1911 code = AFSVolEndTrans(toconn, totid, &rcode);
1916 "Failed to end the transaction on the volume %u on the new site\n",
1920 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1921 MapNetworkToHost(&entry, &storeEntry);
1922 storeEntry.flags &= ~VLF_BACKEXISTS;
1926 "Second test point - operation in progress but not complete.\n");
1927 fprintf(STDOUT, "...test here (y, n)? ");
1929 if (fscanf(stdin, "%c", &in) < 1)
1931 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1934 fprintf(STDOUT, "type control-c\n");
1936 fprintf(stdout, ".");
1941 /* or drop through */
1944 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1946 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1947 (LOCKREL_OPCODE | LOCKREL_AFSID |
1948 LOCKREL_TIMESTAMP));
1951 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1952 storeEntry.name, (unsigned long)afromvol);
1961 "Third test point - operation complete but no cleanup.\n");
1962 fprintf(STDOUT, "...test here (y, n)? ");
1964 if (fscanf(stdin, "%c", &in) < 1)
1966 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1969 fprintf(STDOUT, "type control-c\n");
1971 fprintf(stdout, ".");
1976 /* or drop through */
1979 /* This is tricky. File server is very stupid, and if you mark the volume
1980 * as VTOutOfService, it may mark the *good* instance (if you're moving
1981 * between partitions on the same machine) as out of service. Since
1982 * we're cleaning this code up in DEcorum, we're just going to kludge around
1983 * it for now by removing this call. */
1984 /* already out of service, just zap it now */
1986 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1989 "Failed to set the flags to make the old source volume offline\n");
1993 if (atoserver != afromserver) {
1994 /* set forwarding pointer for moved volumes */
1995 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1996 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1998 "Failed to set the forwarding pointer for the volume %u\n",
2003 VPRINT1("Deleting old volume %u on source ...", afromvol);
2004 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
2005 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
2009 VPRINT1("Ending transaction on old volume %u on the source ...",
2011 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2016 "Failed to end the transaction on the old volume %u on the source\n",
2020 code = DoVolDelete(fromconn, backupId, afrompart,
2021 "source backup", 0, NULL, NULL);
2022 if (code && code != VNOVOL) {
2027 code = 0; /* no backup volume? that's okay */
2030 if (!(flags & RV_NOCLONE)) {
2031 code = DoVolDelete(fromconn, newVol, afrompart,
2032 "cloned", 0, NULL, NULL);
2034 if (code == VNOVOL) {
2035 EPRINT1(code, "Failed to start transaction on %u\n", newVol);
2046 fprintf(STDOUT, "Fourth test point - operation complete.\n");
2047 fprintf(STDOUT, "...test here (y, n)? ");
2049 if (fscanf(stdin, "%c", &in) < 1)
2051 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
2054 fprintf(STDOUT, "type control-c\n");
2056 fprintf(stdout, ".");
2061 /* or drop through */
2064 /* normal cleanup code */
2066 if (entry.flags & VLF_ROEXISTS)
2067 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
2070 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
2072 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2073 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2077 " Could not release the lock on the VLDB entry for the volume %lu \n",
2078 (unsigned long)afromvol);
2086 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2088 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2089 if (code || rcode) {
2092 "Could not end transaction on the source volume %lu\n",
2093 (unsigned long)afromvol);
2095 error = (code ? code : rcode);
2101 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2102 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2103 if (code || rcode) {
2106 "Could not end transaction on the source's clone volume %lu\n",
2107 (unsigned long)newVol);
2109 error = (code ? code : rcode);
2115 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2117 code = AFSVolEndTrans(toconn, totid, &rcode);
2121 "Could not end transaction on destination volume %lu\n",
2122 (unsigned long)afromvol);
2124 error = (code ? code : rcode);
2130 #ifdef ENABLE_BUGFIX_1165
2135 rx_DestroyConnection(fromconn);
2137 rx_DestroyConnection(toconn);
2138 PrintError("", error);
2141 /* come here only when the sky falls */
2146 "vos move: operation interrupted, cleanup in progress...\n");
2147 fprintf(STDOUT, "clear transaction contexts\n");
2151 /* unlock VLDB entry */
2153 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2154 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2155 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2161 VPRINT("Recovery: Ending transaction on clone volume ...");
2162 AFSVolEndTrans(fromconn, clonetid, &rcode);
2166 VPRINT("Recovery: Ending transaction on destination volume ...");
2167 AFSVolEndTrans(toconn, totid, &rcode);
2170 if (fromtid) { /* put it on-line */
2171 VPRINT("Recovery: Setting volume flags on source volume ...");
2172 AFSVolSetFlags(fromconn, fromtid, 0);
2175 VPRINT("Recovery: Ending transaction on source volume ...");
2176 AFSVolEndTrans(fromconn, fromtid, &rcode);
2180 VPRINT("Recovery: Accessing VLDB.\n");
2181 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2183 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2187 MapHostToNetwork(&entry);
2189 /* Delete either the volume on the source location or the target location.
2190 * If the vldb entry still points to the source location, then we know the
2191 * volume move didn't finish so we remove the volume from the target
2192 * location. Otherwise, we remove the volume from the source location.
2194 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2197 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2201 if (volid && toconn) {
2202 code = DoVolDelete(toconn, volid, atopart,
2203 "destination", 0, NULL, "Recovery:");
2204 if (code == VNOVOL) {
2205 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2209 /* put source volume on-line */
2211 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2215 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2221 VPRINT1("Recovery: Setting flags on source volume %u ...",
2223 AFSVolSetFlags(fromconn, fromtid, 0);
2227 ("Recovery: Ending transaction on source volume %u ...",
2229 AFSVolEndTrans(fromconn, fromtid, &rcode);
2233 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2237 } else { /* yep, move complete */
2240 "move complete - attempt cleanup of source partition - no guarantee\n");
2244 /* delete backup volume */
2246 code = DoVolDelete(fromconn, backupId, afrompart,
2247 "backup", 0, NULL, "Recovery:");
2248 if (code == VNOVOL) {
2249 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2252 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2253 (atoserver != afromserver)?atoserver:0,
2255 if (code == VNOVOL) {
2256 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2261 /* common cleanup - delete local clone */
2263 code = DoVolDelete(fromconn, newVol, afrompart,
2264 "clone", 0, NULL, "Recovery:");
2265 if (code == VNOVOL) {
2266 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2270 /* unlock VLDB entry */
2272 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2274 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2275 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2278 done: /* routine cleanup */
2281 #ifdef ENABLE_BUGFIX_1165
2286 rx_DestroyConnection(fromconn);
2288 rx_DestroyConnection(toconn);
2291 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2299 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2300 afs_uint32 atoserver, afs_int32 atopart)
2302 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2303 atoserver, atopart, 0);
2307 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2308 * <atopart>. The new volume is named by <atovolname>. The new volume
2309 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2310 * from the VLDB. the following flags are supported:
2312 * RV_RDONLY - target volume is RO
2313 * RV_OFFLINE - leave target volume offline
2314 * RV_CPINCR - do incremental dump if target exists
2315 * RV_NOVLDB - don't create/update VLDB entry
2316 * RV_NOCLONE - don't use a copy clone
2319 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2320 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2321 afs_uint32 atovolid, int flags)
2323 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2324 * be changing during the copy */
2326 afs_int32 volatile clonetid;
2327 afs_int32 volatile totid;
2328 afs_int32 volatile fromtid;
2329 struct rx_connection * volatile fromconn;
2330 struct rx_connection * volatile toconn;
2331 afs_uint32 volatile cloneVol;
2335 afs_int32 fromDate, cloneFromDate;
2336 struct restoreCookie cookie;
2337 afs_int32 vcode, code;
2340 struct volser_status tstatus;
2341 struct destServer destination;
2342 struct nvldbentry entry, newentry, storeEntry;
2347 fromconn = (struct rx_connection *)0;
2348 toconn = (struct rx_connection *)0;
2356 /* support control-c processing */
2359 (void)signal(SIGINT, sigint_handler);
2361 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2362 EGOTO1(mfail, vcode,
2363 "Could not fetch the entry for the volume %u from the VLDB \n",
2365 MapHostToNetwork(&entry);
2368 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2369 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2370 fromtid = totid = 0; /* initialize to uncreated */
2373 * clone the read/write volume locally.
2377 if (!(flags & RV_NOCLONE)) {
2378 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2380 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2383 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2387 /* Get a clone id */
2388 VPRINT1("Allocating new volume id for clone of volume %u ...",
2392 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2394 EGOTO1(mfail, vcode,
2395 "Could not get an ID for the clone of volume %u from the VLDB\n",
2403 /* Get a new volume id */
2404 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2406 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2407 EGOTO1(mfail, vcode,
2408 "Could not get an ID for the copy of volume %u from the VLDB\n",
2413 if (!(flags & RV_NOCLONE)) {
2414 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2415 VPRINT1("Cloning source volume %u ...", afromvol);
2416 strcpy(vname, "copy-clone-temp");
2419 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2422 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2426 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2428 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2433 "Failed to end the transaction on the source volume %u\n",
2439 * Create the destination volume
2442 if (!(flags & RV_NOCLONE)) {
2443 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2446 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2450 "Failed to start a transaction on the cloned volume%u\n",
2454 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2456 AFSVolSetFlags(fromconn, clonetid,
2457 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2458 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2462 /* remember time from which we've dumped the volume */
2463 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2464 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2466 "Failed to get the status of the cloned volume %u\n",
2470 fromDate = CLOCKADJ(tstatus.creationDate);
2475 /* create a volume on the target machine */
2478 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2481 if ((flags & RV_CPINCR)) {
2482 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2483 code = AFSVolGetStatus(toconn, totid, &tstatus);
2485 "Failed to get the status of the pre-existing volume %u\n",
2489 /* Using the update date should be OK here, but add some fudge */
2490 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2491 if ((flags & RV_NOCLONE))
2492 fromDate = cloneFromDate;
2494 /* XXX We should check that the source volume's creationDate is
2495 * XXX not newer than the existing target volume, and if not,
2496 * XXX throw away the existing target and do a full dump. */
2501 /* Delete the existing volume.
2502 * While we are deleting the volume in these steps, the transaction
2503 * we started against the cloned volume (clonetid above) will be
2504 * sitting idle. It will get cleaned up after 600 seconds
2506 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2507 code = AFSVolDeleteVolume(toconn, totid);
2509 "Could not delete the pre-existing volume %u on destination\n",
2514 ("Ending transaction on pre-existing volume %u on destination ...",
2516 code = AFSVolEndTrans(toconn, totid, &rcode);
2521 "Could not end the transaction on pre-existing volume %u on destination\n",
2526 VPRINT1("Creating the destination volume %u ...", newVol);
2529 AFSVolCreateVolume(toconn, atopart, atovolname,
2530 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2531 newVol, &newVol, &tmp);
2533 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2537 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2539 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2541 "Failed to set the flags on the destination volume %u\n", newVol);
2546 destination.destHost = ntohl(atoserver);
2547 destination.destPort = AFSCONF_VOLUMEPORT;
2548 destination.destSSID = 1;
2550 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2551 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2556 * Now dump the clone to the new volume
2559 if (!(flags & RV_NOCLONE)) {
2560 /* XXX probably should have some code here that checks to see if
2561 * XXX we are copying to same server and partition - if so, just
2562 * XXX use a clone to save disk space */
2564 /* Copy the clone to the new volume */
2565 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2568 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2570 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2574 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2575 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2580 "Failed to end the transaction on the cloned volume %u\n",
2586 * reattach to the main-line volume, and incrementally dump it.
2589 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2591 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2594 "Failed to create a transaction on the source volume %u\n",
2598 /* now do the incremental */
2600 ("Doing the%s dump from source to destination for volume %u ... ",
2601 (flags & RV_NOCLONE) ? "" : " incremental",
2604 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2607 "Failed to do the%s dump from old site to new site\n",
2608 (flags & RV_NOCLONE) ? "" : " incremental");
2611 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2612 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2613 code = AFSVolSetFlags(toconn, totid, volflag);
2615 "Failed to set the flags to make destination volume online\n");
2618 /* put new volume online */
2619 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2620 code = AFSVolEndTrans(toconn, totid, &rcode);
2625 "Failed to end the transaction on the destination volume %u\n",
2629 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2630 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2635 "Failed to end the transaction on the source volume %u\n",
2641 if (!(flags & RV_NOCLONE)) {
2642 code = DoVolDelete(fromconn, cloneVol, afrompart,
2643 "cloned", 0, NULL, NULL);
2645 if (code == VNOVOL) {
2646 EPRINT1(code, "Failed to start transaction on %u\n", cloneVol);
2653 if (!(flags & RV_NOVLDB)) {
2654 /* create the vldb entry for the copied volume */
2655 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2656 newentry.nServers = 1;
2657 newentry.serverNumber[0] = atoserver;
2658 newentry.serverPartition[0] = atopart;
2659 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2660 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2661 newentry.volumeId[RWVOL] = newVol;
2662 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2663 newentry.volumeId[BACKVOL] = 0;
2664 newentry.cloneId = 0;
2665 /*map into right byte order, before passing to xdr, the stuff has to be in host
2666 * byte order. Xdr converts it into network order */
2667 MapNetworkToHost(&newentry, &storeEntry);
2668 /* create the vldb entry */
2669 vcode = VLDB_CreateEntry(&storeEntry);
2672 "Could not create a VLDB entry for the volume %s %lu\n",
2673 atovolname, (unsigned long)newVol);
2674 /*destroy the created volume */
2675 VPRINT1("Deleting the newly created volume %u\n", newVol);
2676 AFSVolDeleteVolume(toconn, totid);
2680 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2684 /* normal cleanup code */
2687 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2689 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2690 if (code || rcode) {
2693 "Could not end transaction on the source volume %lu\n",
2694 (unsigned long)afromvol);
2696 error = (code ? code : rcode);
2702 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2704 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2705 if (code || rcode) {
2708 "Could not end transaction on the source's clone volume %lu\n",
2709 (unsigned long)cloneVol);
2711 error = (code ? code : rcode);
2717 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2719 code = AFSVolEndTrans(toconn, totid, &rcode);
2723 "Could not end transaction on destination volume %lu\n",
2724 (unsigned long)newVol);
2726 error = (code ? code : rcode);
2731 rx_DestroyConnection(fromconn);
2733 rx_DestroyConnection(toconn);
2734 PrintError("", error);
2737 /* come here only when the sky falls */
2742 "vos copy: operation interrupted, cleanup in progress...\n");
2743 fprintf(STDOUT, "clear transaction contexts\n");
2748 VPRINT("Recovery: Ending transaction on clone volume ...");
2749 AFSVolEndTrans(fromconn, clonetid, &rcode);
2753 VPRINT("Recovery: Ending transaction on destination volume ...");
2754 AFSVolEndTrans(toconn, totid, &rcode);
2757 if (fromtid) { /* put it on-line */
2758 VPRINT("Recovery: Ending transaction on source volume ...");
2759 AFSVolEndTrans(fromconn, fromtid, &rcode);
2763 VPRINT("Recovery: Accessing VLDB.\n");
2764 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2766 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2770 MapHostToNetwork(&entry);
2772 /* common cleanup - delete local clone */
2774 code = DoVolDelete(fromconn, cloneVol, afrompart,
2775 "clone", 0, NULL, "Recovery:");
2776 if (code == VNOVOL) {
2777 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", cloneVol);
2781 done: /* routine cleanup */
2783 rx_DestroyConnection(fromconn);
2785 rx_DestroyConnection(toconn);
2788 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2796 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2797 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2799 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2800 atovolname, atoserver, atopart, 0, 0);
2805 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2806 * if one already exists, update it
2810 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2812 struct rx_connection *aconn = (struct rx_connection *)0;
2813 afs_int32 ttid = 0, btid = 0;
2814 afs_uint32 backupID;
2815 afs_int32 code = 0, rcode = 0;
2816 struct nvldbentry entry, storeEntry;
2817 afs_int32 error = 0;
2818 int vldblocked = 0, vldbmod = 0;
2820 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2822 /* the calls to VLDB will succeed only if avolid is a RW volume,
2823 * since we are following the RW hash chain for searching */
2824 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2827 "Could not fetch the entry for the volume %lu from the VLDB \n",
2828 (unsigned long)avolid);
2832 MapHostToNetwork(&entry);
2834 /* These operations require the VLDB be locked since it means the VLDB
2835 * will change or the vldb is already locked.
2837 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2838 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2839 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2841 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2844 "Could not lock the VLDB entry for the volume %lu\n",
2845 (unsigned long)avolid);
2851 /* Reread the vldb entry */
2852 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2855 "Could not fetch the entry for the volume %lu from the VLDB \n",
2856 (unsigned long)avolid);
2860 MapHostToNetwork(&entry);
2863 if (!ISNAMEVALID(entry.name)) {
2864 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2866 error = VOLSERBADNAME;
2870 backupID = entry.volumeId[BACKVOL];
2871 if (backupID == INVALID_BID) {
2872 /* Get a backup volume id from the VLDB and update the vldb
2875 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2878 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2879 (unsigned long)avolid);
2883 entry.volumeId[BACKVOL] = backupID;
2887 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2888 entry.name, NULL, ".backup", NULL, NULL);
2894 /* Mark vldb as backup exists */
2895 if (!(entry.flags & VLF_BACKEXISTS)) {
2896 entry.flags |= VLF_BACKEXISTS;
2900 /* Now go back to the backup volume and bring it on line */
2901 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2904 "Failed to start a transaction on the backup volume %lu\n",
2905 (unsigned long)backupID);
2910 code = AFSVolSetFlags(aconn, btid, 0);
2912 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2913 (unsigned long)backupID);
2918 code = AFSVolEndTrans(aconn, btid, &rcode);
2920 if (code || rcode) {
2922 "Failed to end the transaction on the backup volume %lu\n",
2923 (unsigned long)backupID);
2924 error = (code ? code : rcode);
2928 /* Will update the vldb below */
2932 code = AFSVolEndTrans(aconn, ttid, &rcode);
2933 if (code || rcode) {
2934 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2935 (unsigned long)avolid);
2937 error = (code ? code : rcode);
2942 code = AFSVolEndTrans(aconn, btid, &rcode);
2943 if (code || rcode) {
2945 "Could not end transaction the backup volume %lu\n",
2946 (unsigned long)backupID);
2948 error = (code ? code : rcode);
2952 /* Now update the vldb - if modified */
2955 MapNetworkToHost(&entry, &storeEntry);
2957 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2958 (LOCKREL_OPCODE | LOCKREL_AFSID |
2959 LOCKREL_TIMESTAMP));
2962 "Could not update the VLDB entry for the volume %lu \n",
2963 (unsigned long)avolid);
2969 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2970 (LOCKREL_OPCODE | LOCKREL_AFSID |
2971 LOCKREL_TIMESTAMP));
2974 "Could not unlock the VLDB entry for the volume %lu \n",
2975 (unsigned long)avolid);
2983 rx_DestroyConnection(aconn);
2985 PrintError("", error);
2989 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2990 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2991 * The new volume is named by <aname>, or by appending ".clone" to
2992 * the existing name if <aname> is NULL. The following flags are
2995 * RV_RDONLY - target volume is RO
2996 * RV_OFFLINE - leave target volume offline
3000 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
3001 afs_uint32 acloneid, char *aname, int flags)
3003 struct rx_connection *aconn = (struct rx_connection *)0;
3004 afs_int32 ttid = 0, btid = 0;
3005 afs_int32 code = 0, rcode = 0;
3006 char vname[VOLSER_MAXVOLNAME + 1];
3007 afs_int32 error = 0;
3008 volEntries volumeInfo;
3011 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
3014 volumeInfo.volEntries_val = (volintInfo *) 0;
3015 volumeInfo.volEntries_len = 0;
3016 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
3018 fprintf(stderr, "Could not get info for volume %lu\n",
3019 (unsigned long)avolid);
3023 strncpy(vname, volumeInfo.volEntries_val[0].name,
3024 VOLSER_OLDMAXVOLNAME - 7);
3025 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
3026 strcat(vname, ".clone");
3028 if (volumeInfo.volEntries_val)
3029 free(volumeInfo.volEntries_val);
3033 /* Get a clone id */
3034 VPRINT1("Allocating new volume id for clone of volume %u ...",
3036 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
3038 "Could not get an ID for the clone of volume %u from the VLDB\n",
3043 if (flags & RV_RWONLY)
3044 type = readwriteVolume;
3045 else if (flags & RV_RDONLY)
3046 type = readonlyVolume;
3048 type = backupVolume;
3050 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
3051 NULL, aname, NULL, NULL, NULL);
3057 /* Now go back to the backup volume and bring it on line */
3058 if (!(flags & RV_OFFLINE)) {
3059 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3062 "Failed to start a transaction on the clone volume %lu\n",
3063 (unsigned long)acloneid);
3068 code = AFSVolSetFlags(aconn, btid, 0);
3070 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3071 (unsigned long)acloneid);
3076 code = AFSVolEndTrans(aconn, btid, &rcode);
3078 if (code || rcode) {
3080 "Failed to end the transaction on the clone volume %lu\n",
3081 (unsigned long)acloneid);
3082 error = (code ? code : rcode);
3089 code = AFSVolEndTrans(aconn, ttid, &rcode);
3090 if (code || rcode) {
3091 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3092 (unsigned long)avolid);
3094 error = (code ? code : rcode);
3099 code = AFSVolEndTrans(aconn, btid, &rcode);
3100 if (code || rcode) {
3102 "Could not end transaction on the clone volume %lu\n",
3103 (unsigned long)acloneid);
3105 error = (code ? code : rcode);
3110 rx_DestroyConnection(aconn);
3112 PrintError("", error);
3116 #define ONERROR(ec, ep, es) do { \
3118 fprintf(STDERR, (es), (ep)); \
3123 #define ONERROR0(ec, es) do { \
3125 fprintf(STDERR, (es)); \
3130 #define ERROREXIT(ec) do { \
3135 /* Get a "transaction" on this replica. Create the volume
3136 * if necessary. Return the time from which a dump should
3137 * be made (0 if it's a new volume)
3140 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3141 struct rx_connection **connPtr, afs_int32 * transPtr,
3142 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3143 afs_int32 *origflags, afs_uint32 tmpVolId)
3146 struct volser_status tstatus;
3151 *connPtr = (struct rx_connection *)0;
3156 /* get connection to the replication site */
3157 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3159 goto fail; /* server is down */
3161 volid = vldbEntryPtr->volumeId[ROVOL];
3165 AFSVolTransCreate_retry(*connPtr, volid,
3166 vldbEntryPtr->serverPartition[index], ITOffline,
3169 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3170 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3171 * site. Don't trust any data on it, since it is possible we
3172 * have encountered some temporary volume from some other
3173 * incomplete volume operation. It is difficult to detect if
3174 * that has happened vs if this is a legit volume, so just
3175 * delete it to be safe. */
3177 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3178 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3179 serverNumber[index], hoststr) :
3180 hostutil_GetNameByINet(vldbEntryPtr->
3181 serverNumber[index]));
3183 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3185 PrintError("Failed to delete RO_DONTUSE site: ", code);
3189 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3195 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3202 /* emulate what TransCreate would have returned, so we try to
3203 * create the volume below */
3208 /* If the volume does not exist, create it */
3209 if (!volid || code) {
3210 char volname[VL_MAXNAMELEN];
3213 if (volid && (code != VNOVOL)) {
3214 PrintError("Failed to start a transaction on the RO volume.\n",
3219 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3221 if (strlcat(volname,
3222 tmpVolId?".roclone":".readonly",
3223 sizeof(volname)) >= sizeof(volname)) {
3225 PrintError("Volume name is too long\n", code);
3231 "Creating new volume %lu on replication site %s: ",
3232 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3233 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3234 serverNumber[index], hoststr) :
3235 hostutil_GetNameByINet(vldbEntryPtr->
3236 serverNumber[index]));
3241 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3243 vldbEntryPtr->volumeId[RWVOL],
3244 tmpVolId?&tmpVolId:&volid,
3247 PrintError("Failed to create the ro volume: ", code);
3250 vldbEntryPtr->volumeId[ROVOL] = volid;
3254 /* The following is a bit redundant, since create sets these flags by default */
3256 AFSVolSetFlags(*connPtr, *transPtr,
3257 VTDeleteOnSalvage | VTOutOfService);
3259 PrintError("Failed to set flags on the ro volume: ", code);
3264 /* Otherwise, the transaction did succeed, so get the creation date of the
3265 * latest RO volume on the replication site
3268 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3269 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3270 serverNumber[index], hoststr) :
3271 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3273 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3275 PrintError("Failed to get status of volume on destination: ",
3280 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3285 code = DoVolClone(*connPtr, volid,
3286 vldbEntryPtr->serverPartition[index],
3287 readonlyVolume, tmpVolId, "temporary",
3288 vldbEntryPtr->name, NULL, ".roclone", NULL,
3293 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3294 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3301 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3305 if (tcode && tcode != ENOENT)
3306 PrintError("Could not end transaction on a ro volume: ", tcode);
3313 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3314 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3315 void *cookie, manyResults * results)
3319 for (i = 0; i < tr->manyDests_len; i++) {
3320 results->manyResults_val[i] =
3321 AFSVolForward(fromconn, fromtid, fromdate,
3322 &(tr->manyDests_val[i].server),
3323 tr->manyDests_val[i].trans, cookie);
3329 * Check if a trans has timed out, and recreate it if necessary.
3331 * @param[in] aconn RX connection to the relevant server
3332 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3333 * contains the new trans ID on success
3334 * @param[in] apart Partition for the transaction
3335 * @param[in] astat The status of the original transaction
3337 * @return operation status
3338 * @retval 0 existing transaction is still valid, or we managed to recreate
3339 * the trans successfully
3340 * @retval nonzero Fatal error; bail out
3343 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3344 struct volser_status *astat)
3346 struct volser_status new_status;
3349 memset(&new_status, 0, sizeof(new_status));
3350 code = AFSVolGetStatus(aconn, *atid, &new_status);
3352 if (code == ENOENT) {
3354 VPRINT1("Old transaction on cloned volume %lu timed out, "
3355 "restarting transaction\n", (long unsigned) astat->volID);
3356 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3359 PrintError("Failed to recreate cloned RO volume transaction\n",
3364 memset(&new_status, 0, sizeof(new_status));
3365 code = AFSVolGetStatus(aconn, *atid, &new_status);
3367 PrintError("Failed to get status on recreated transaction\n",
3372 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3373 PrintError("Recreated transaction on cloned RO volume, but "
3374 "the volume has changed!\n", 0);
3378 PrintError("Unable to get status of current cloned RO transaction\n",
3383 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3385 PrintError("Internal error: current GetStatus does not match "
3386 "original GetStatus?\n", 0);
3395 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3396 struct rx_connection **toconns, struct release *times,
3399 afs_int32 s, code = 0, rcode = 0;
3400 /* End the transactions and destroy the connections */
3401 for (s = 0; s < volcount; s++) {
3402 if (replicas[s].trans) {
3403 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3405 replicas[s].trans = 0;
3409 if ((s == 0) || (code != ENOENT)) {
3410 PrintError("Could not end transaction on a ro volume: ",
3414 ("Transaction timed out on a ro volume. Will retry.\n",
3416 if (times[s].vldbEntryIndex < *vldbindex)
3417 *vldbindex = times[s].vldbEntryIndex;
3422 rx_DestroyConnection(toconns[s]);
3428 * Release a volume to read-only sites
3430 * Release volume <afromvol> on <afromserver> <afrompart> to all
3431 * its RO sites (full release). Unless the previous release was
3432 * incomplete: in which case we bring the remaining incomplete
3433 * volumes up to date with the volumes that were released
3436 * Will create a clone from the RW, then dump the clone out to
3437 * the remaining replicas. If there is more than 1 RO sites,
3438 * ensure that the VLDB says at least one RO is available all
3439 * the time: Influences when we write back the VLDB entry.
3441 * @param[in] afromvol volume to be released
3442 * @param[in] afromserver server containing afromvol
3443 * @param[in] afrompart partition containing afromvol
3444 * @param[in] flags bitmap of options
3445 * REL_COMPLETE - force a complete release
3446 * REL_FULLDUMPS - force full dumps
3449 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3450 afs_int32 afrompart, int flags)
3454 afs_int32 vcode, rcode, tcode;
3455 afs_uint32 cloneVolId = 0, roVolId;
3456 struct replica *replicas = 0;
3457 struct nvldbentry entry, storeEntry;
3458 int i, volcount = 0, m, vldbindex;
3460 struct restoreCookie cookie;
3461 struct rx_connection **toconns = 0;
3462 struct release *times = 0;
3464 struct rx_connection *fromconn = (struct rx_connection *)0;
3465 afs_int32 error = 0;
3467 afs_int32 clonetid = 0, onlinetid;
3468 afs_int32 fromtid = 0;
3469 afs_uint32 fromdate = 0;
3470 afs_uint32 thisdate;
3474 manyResults results;
3475 int rwindex, roindex, roclone, roexists;
3476 afs_uint32 rwcrdate = 0, rwupdate = 0;
3477 afs_uint32 clcrdate;
3481 } remembertime[NMAXNSERVERS];
3482 int releasecount = 0;
3483 struct volser_status volstatus;
3485 afs_int32 origflags[NMAXNSERVERS];
3486 struct volser_status orig_status;
3487 int notreleased = 0;
3488 int tried_justnewsites = 0;
3489 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3490 int sites = 0; /* number of ro sites */
3491 int new_sites = 0; /* number of ro sites markes as new */
3494 CR_RECOVER = 0x0000, /**< not complete: a recovery from a previous failed release */
3495 CR_FORCED = 0x0001, /**< complete: forced by caller */
3496 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3497 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3498 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3499 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3500 } complete_release_t;
3502 complete_release_t complete_release = CR_RECOVER;
3504 memset(remembertime, 0, sizeof(remembertime));
3505 memset(&results, 0, sizeof(results));
3506 memset(origflags, 0, sizeof(origflags));
3508 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3509 if (vcode != VL_RERELEASE)
3510 ONERROR(vcode, afromvol,
3511 "Could not lock the VLDB entry for the volume %u.\n");
3514 /* Get the vldb entry in readable format */
3515 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3516 ONERROR(vcode, afromvol,
3517 "Could not fetch the entry for the volume %u from the VLDB.\n");
3518 MapHostToNetwork(&entry);
3521 EnumerateEntry(&entry);
3523 if (!ISNAMEVALID(entry.name))
3524 ONERROR(VOLSERBADOP, entry.name,
3525 "Volume name %s is too long, rename before releasing.\n");
3526 if (entry.volumeId[RWVOL] != afromvol)
3527 ONERROR(VOLSERBADOP, afromvol,
3528 "The volume %u being released is not a read-write volume.\n");
3529 if (entry.nServers <= 1)
3530 ONERROR(VOLSERBADOP, afromvol,
3531 "Volume %u has no replicas - release operation is meaningless!\n");
3532 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3533 ONERROR(VOLSERBADOP, entry.name,
3534 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3536 /* roclone is true if one of the RO volumes is on the same
3537 * partition as the RW volume. In this case, we make the RO volume
3538 * on the same partition a clone instead of a complete copy.
3541 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3542 roclone = ((roindex == -1) ? 0 : 1);
3543 rwindex = Lp_GetRwIndex(&entry);
3545 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3547 /* Make sure we have a RO volume id to work with */
3548 if (entry.volumeId[ROVOL] == INVALID_BID) {
3549 /* need to get a new RO volume id */
3550 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3551 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3553 entry.volumeId[ROVOL] = roVolId;
3554 MapNetworkToHost(&entry, &storeEntry);
3555 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3556 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3560 * Determine if this is to be a complete release or a recovery of a
3561 * previous unfinished release. The previous release is considered to be
3562 * unfinished when the clone was successfully distributed to at least one
3563 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3566 * The caller can override the vldb flags check using the -force
3567 * or -force-reclone flag, to force this to be a complete release.
3569 for (i = 0; i < entry.nServers; i++) {
3570 if (entry.serverFlags[i] & VLSF_ROVOL) {
3572 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3574 if (entry.serverFlags[i] & VLSF_DONTUSE)
3577 origflags[i] = entry.serverFlags[i];
3580 if (flags & REL_COMPLETE) {
3581 complete_release |= CR_FORCED;
3584 if (new_sites == 0) {
3585 complete_release |= CR_LAST_OK;
3586 } else if (new_sites == sites) {
3587 complete_release |= CR_ALL_NEW;
3590 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3591 && !(complete_release & CR_FORCED)) {
3592 if (notreleased && notreleased != sites) {
3593 /* we have some new unreleased sites. try to just release to those,
3594 * if the RW has not changed. The caller can override with -force
3595 * or with -force-reclone. */
3600 /* Determine which volume id to use and see if it exists */
3601 cloneVolId = (complete_release || entry.cloneId == 0)
3602 ? entry.volumeId[ROVOL] : entry.cloneId;
3604 code = VolumeExists(afromserver, afrompart, cloneVolId);
3605 roexists = ((code == ENODEV) ? 0 : 1);
3607 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3609 ONERROR(-1, afromserver,
3610 "Cannot establish connection with server 0x%x\n");
3612 if (!complete_release) {
3614 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3616 /* Begin transaction on RW and mark it busy while we query it */
3617 code = AFSVolTransCreate_retry(
3618 fromconn, afromvol, afrompart, ITBusy, &fromtid
3620 ONERROR(code, afromvol,
3621 "Failed to start transaction on RW volume %u\n");
3623 /* Query the creation date for the RW */
3624 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3625 ONERROR(code, afromvol,
3626 "Failed to get the status of RW volume %u\n");
3627 rwcrdate = volstatus.creationDate;
3629 /* End transaction on RW */
3630 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3632 ONERROR((code ? code : rcode), afromvol,
3633 "Failed to end transaction on RW volume %u\n");
3635 /* Begin transaction on clone and mark it busy while we query it */
3636 code = AFSVolTransCreate_retry(
3637 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3639 ONERROR(code, cloneVolId,
3640 "Failed to start transaction on RW clone %u\n");
3642 /* Query the creation date for the clone */
3643 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3644 ONERROR(code, cloneVolId,
3645 "Failed to get the status of RW clone %u\n");
3646 clcrdate = volstatus.creationDate;
3648 /* End transaction on clone */
3649 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3651 ONERROR((code ? code : rcode), cloneVolId,
3652 "Failed to end transaction on RW clone %u\n");
3654 if (rwcrdate > clcrdate)
3655 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3659 if (!complete_release || (complete_release & CR_NEW_RW)) {
3660 /* in case the RW has changed, and just to be safe */
3665 if (!complete_release) {
3667 "This is a recovery of previously failed release\n");
3669 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3670 /* Give the reasons for a complete release, except if only CR_LAST_OK. */
3671 if (complete_release != CR_LAST_OK) {
3673 if (complete_release & CR_FORCED) {
3674 fprintf(STDOUT, "%sforced", sep);
3677 if (complete_release & CR_LAST_OK) {
3678 fprintf(STDOUT, "%slast ok", sep);
3681 if (complete_release & CR_ALL_NEW) {
3682 fprintf(STDOUT, "%sall sites are new", sep);
3685 if (complete_release & CR_NEW_RW) {
3686 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3689 if (complete_release & CR_RO_MISSING) {
3690 fprintf(STDOUT, "%sro clone missing", sep);
3692 fprintf(STDOUT, ")");
3694 fprintf(STDOUT, "\n");
3696 tried_justnewsites = 1;
3697 fprintf(STDOUT, "There are new RO sites; we will try to "
3698 "only release to new sites\n");
3703 if (complete_release) {
3704 afs_int32 oldest = 0;
3705 /* If the RO clone exists, then if the clone is a temporary
3706 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3707 * (it was recently added), then also delete it. We do not
3708 * want to "reclone" a temporary RO clone.
3711 /* clean up any previous tmp clone before starting if staying up */
3713 && (!roclone || (entry.serverFlags[roindex] & VLSF_DONTUSE))) {
3714 code = DoVolDelete(fromconn,
3716 afrompart, "the", 0, NULL, NULL);
3717 if (code && (code != VNOVOL))
3723 VPRINT("Querying old RO sites for update times...");
3724 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3725 volEntries volumeInfo;
3726 struct rx_connection *conn;
3729 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL)) {
3732 if ((entry.serverFlags[vldbindex] & VLSF_DONTUSE)) {
3735 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3737 fprintf(STDERR, "Cannot establish connection to server %s\n",
3738 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3742 volumeInfo.volEntries_val = NULL;
3743 volumeInfo.volEntries_len = 0;
3744 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3745 entry.volumeId[ROVOL],
3748 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3749 (unsigned long)entry.volumeId[ROVOL],
3750 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3751 PrintError("", code);
3753 rx_DestroyConnection(conn);
3757 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3759 if (oldest == 0 || crdate < oldest) {
3763 rx_DestroyConnection(conn);
3764 free(volumeInfo.volEntries_val);
3765 volumeInfo.volEntries_val = NULL;
3766 volumeInfo.volEntries_len = 0;
3771 volEntries volumeInfo;
3772 volumeInfo.volEntries_val = NULL;
3773 volumeInfo.volEntries_len = 0;
3774 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3777 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3778 (unsigned long)afromvol,
3779 hostutil_GetNameByINet(afromserver));
3780 PrintError("", code);
3783 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3785 free(volumeInfo.volEntries_val);
3786 volumeInfo.volEntries_val = NULL;
3787 volumeInfo.volEntries_len = 0;
3790 if (justnewsites && oldest <= rwupdate) {
3791 /* RW has changed */
3795 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3796 * write this entry out to the vlserver until after the first
3797 * RO volume is released (temp RO clones don't count).
3799 * If 'justnewsites' is set, we're only updating sites that have
3800 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3802 for (i = 0; i < entry.nServers; i++) {
3804 if ((entry.serverFlags[i] & VLSF_DONTUSE)) {
3805 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3807 entry.serverFlags[i] |= VLSF_NEWREPSITE;
3810 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3811 entry.serverFlags[i] |= VLSF_DONTUSE;
3814 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3815 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3818 if (justnewsites && roexists) {
3819 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3820 * anything with the RO clone, so skip the reclone */
3823 } else if (complete_release) {
3826 strcpy(vname, entry.name);
3827 strcat(vname, ".readonly");
3829 strcpy(vname, "readonly-clone-temp");
3832 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3833 cloneVolId, roclone?"permanent RO":
3834 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3840 if (justnewsites && rwupdate != volstatus.updateDate) {
3842 /* reset the serverFlags as if 'justnewsites' had never been set */
3843 for (i = 0; i < entry.nServers; i++) {
3844 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3845 entry.serverFlags[i] |= VLSF_DONTUSE;
3847 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3848 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3851 rwcrdate = volstatus.creationDate;
3853 /* Remember clone volume ID in case we fail or are interrupted */
3854 entry.cloneId = cloneVolId;
3857 /* Bring the RO clone online - though not if it's a temporary clone */
3858 VPRINT1("Starting transaction on RO clone volume %u...",
3861 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3863 ONERROR(code, cloneVolId,
3864 "Failed to start transaction on volume %u\n");
3867 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3868 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3871 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3872 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3873 ONERROR((code ? code : rcode), cloneVolId,
3874 "Failed to end transaction on RO clone %u\n");
3877 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3879 /* Sleep so that a client searching for an online volume won't
3880 * find the clone offline and then the next RO offline while the
3881 * release brings the clone online and the next RO offline (race).
3882 * There is a fix in the 3.4 client that does not need this sleep
3883 * anymore, but we don't know what clients we have.
3885 if (entry.nServers > 2 && !justnewsites)
3888 /* Mark the RO clone in the VLDB as a good site (already released) */
3889 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
3890 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
3891 entry.flags |= VLF_ROEXISTS;
3895 /* Write out the VLDB entry only if the clone is not a temporary
3896 * clone. If we did this to a temporary clone then we would end
3897 * up marking all the ROs as "old release" making the ROs
3898 * temporarily unavailable.
3900 MapNetworkToHost(&entry, &storeEntry);
3901 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3902 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3903 ONERROR(vcode, entry.name,
3904 "Could not update vldb entry for %s.\n");
3910 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3911 /* act like this is a completion of a previous release */
3912 complete_release = CR_RECOVER;
3913 } else if (tried_justnewsites) {
3914 VPRINT("RW vol has changed; releasing to all sites\n");
3917 /* Now we will release from the clone to the remaining RO replicas.
3918 * The first 2 ROs (counting the non-temporary RO clone) are released
3919 * individually: releasecount. This is to reduce the race condition
3920 * of clients trying to find an on-line RO volume. The remaining ROs
3921 * are released in parallel but no more than half the number of ROs
3922 * (rounded up) at a time: nservers.
3925 strcpy(vname, entry.name);
3926 strcat(vname, ".readonly");
3927 memset(&cookie, 0, sizeof(cookie));
3928 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3929 cookie.type = ROVOL;
3930 cookie.parent = entry.volumeId[RWVOL];
3933 /* how many to do at once, excluding clone */
3935 nservers = entry.nServers; /* can do all, none offline */
3937 nservers = entry.nServers / 2;
3938 replicas = calloc(nservers + 1, sizeof(struct replica));
3939 times = calloc(nservers + 1, sizeof(struct release));
3940 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3941 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3942 if (!replicas || !times || !results.manyResults_val || !toconns)
3944 "Failed to create transaction on the release clone\n");
3946 /* Create a transaction on the cloned volume */
3947 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3949 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3951 memset(&orig_status, 0, sizeof(orig_status));
3952 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3954 if (!complete_release && code)
3955 ONERROR(VOLSERNOVOL, afromvol,
3956 "Old clone is inaccessible. Try vos release -f %u.\n");
3957 ONERROR0(code, "Failed to create transaction on the release clone\n");
3960 /* For each index in the VLDB */
3961 for (vldbindex = 0; vldbindex < entry.nServers;) {
3962 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3964 ((volcount < nservers) && (vldbindex < entry.nServers));
3966 if (!justnewsites) {
3967 /* The first two RO volumes will be released individually.
3968 * The rest are then released in parallel. This is a hack
3969 * for clients not recognizing right away when a RO volume
3970 * comes back on-line.
3972 if ((volcount == 1) && (releasecount < 2))
3976 if (vldbindex == roindex)
3977 continue; /* the clone */
3978 if ((entry.serverFlags[vldbindex] & VLSF_NEWREPSITE)
3979 && !(entry.serverFlags[vldbindex] & VLSF_DONTUSE))
3981 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL))
3982 continue; /* not a RO vol */
3985 /* Get a Transaction on this replica. Get a new connection if
3986 * necessary. Create the volume if necessary. Return the
3987 * time from which the dump should be made (0 if it's a new
3988 * volume). Each volume might have a different time.
3990 replicas[volcount].server.destHost =
3991 ntohl(entry.serverNumber[vldbindex]);
3992 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3993 replicas[volcount].server.destSSID = 1;
3994 times[volcount].vldbEntryIndex = vldbindex;
3997 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3998 &(replicas[volcount].trans),
3999 &(times[volcount].crtime),
4000 &(times[volcount].uptime),
4005 /* Thisdate is the date from which we want to pick up all changes */
4006 if (flags & REL_FULLDUMPS) {
4007 /* Do a full dump when forced by the caller. */
4008 VPRINT("This will be a full dump: forced\n");
4010 } else if (!complete_release) {
4011 /* If this release is a recovery of a failed release, we can't be
4012 * sure the creation date is good, so do a full dump.
4014 VPRINT("This will be a full dump: previous release failed\n");
4016 } else if (times[volcount].crtime == 0) {
4017 /* A full dump is needed for a new read-only volume. */
4019 ("This will be a full dump: read-only volume needs to be created\n");
4021 } else if ((rwcrdate > times[volcount].crtime)) {
4022 /* If the RW volume was replaced (its creation date is newer than
4023 * the last release), then we can't be sure what has changed (so
4024 * we do a full dump).
4027 ("This will be a full dump: read-write volume was replaced\n");
4029 } else if (remembertime[vldbindex].validtime) {
4030 /* Trans was prev ended. Use the time from the prev trans
4031 * because, prev trans may have created the volume. In which
4032 * case time[volcount].time would be now instead of 0.
4035 (remembertime[vldbindex].uptime < times[volcount].uptime)
4036 ? remembertime[vldbindex].uptime
4037 : times[volcount].uptime;
4039 thisdate = times[volcount].uptime;
4041 remembertime[vldbindex].validtime = 1;
4042 remembertime[vldbindex].uptime = thisdate;
4044 if (volcount == 0) {
4045 fromdate = thisdate;
4047 /* Include this volume if it is within 15 minutes of the earliest */
4049 thisdate) ? (fromdate - thisdate) : (thisdate -
4051 AFSVolEndTrans(toconns[volcount],
4052 replicas[volcount].trans, &rcode);
4053 replicas[volcount].trans = 0;
4056 if (thisdate < fromdate)
4057 fromdate = thisdate;
4064 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
4071 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
4072 (unsigned long)cloneVolId,
4073 entry.volumeId[ROVOL],
4074 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
4075 vldbEntryIndex], hoststr) :
4076 hostutil_GetNameByINet(entry.
4077 serverNumber[times[0].
4080 for (s = 1; s < volcount; s++) {
4081 fprintf(STDOUT, " and %s",
4082 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
4083 vldbEntryIndex], hoststr) :
4084 hostutil_GetNameByINet(entry.
4085 serverNumber[times[s].
4090 fprintf(STDOUT, " (entire volume)");
4093 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4095 fprintf(STDOUT, ".\n");
4099 /* Release the ones we have collected */
4100 tr.manyDests_val = &(replicas[0]);
4101 tr.manyDests_len = results.manyResults_len = volcount;
4103 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4104 0 /*spare */ , &cookie, &results);
4105 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4107 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4108 0 /*spare */ , &cookie, &results);
4113 PrintError("Release failed: ", code);
4115 for (m = 0; m < volcount; m++) {
4116 if (results.manyResults_val[m]) {
4117 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4118 /* we retry timed out transaction. When it is
4119 * not the first volume and the transaction wasn't found
4120 * (assume it timed out and was garbage collected by volser).
4123 ("Failed to dump volume from clone to a ro site: ",
4124 results.manyResults_val[m]);
4130 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4131 ROVOL, entry.volumeId[RWVOL], 0, 0);
4133 if ((m == 0) || (code != ENOENT)) {
4134 PrintError("Failed to set correct names and ids: ",
4140 /* have to clear dest. flags to ensure new vol goes online:
4141 * because the restore (forwarded) operation copied
4142 * the V_inService(=0) flag over to the destination.
4144 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4146 if ((m == 0) || (code != ENOENT)) {
4147 PrintError("Failed to set flags on ro volume: ",
4153 entry.serverFlags[times[m].vldbEntryIndex] |= VLSF_NEWREPSITE;
4154 entry.serverFlags[times[m].vldbEntryIndex] &= ~VLSF_DONTUSE;
4155 entry.flags |= VLF_ROEXISTS;
4160 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4161 MapNetworkToHost(&entry, &storeEntry);
4162 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4163 ONERROR(vcode, afromvol,
4164 " Could not update VLDB entry for volume %u\n");
4165 } /* for each index in the vldb */
4167 /* End the transaction on the cloned volume */
4168 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4173 PrintError("Failed to end transaction on rw volume: ", code);
4175 /* Figure out if any volume were not released and say so */
4176 for (failure = 0, i = 0; i < entry.nServers; i++) {
4177 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE))
4183 "The volume %lu could not be released to the following %d sites:\n",
4184 (unsigned long)afromvol, failure);
4185 for (i = 0; i < entry.nServers; i++) {
4186 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE)) {
4187 MapPartIdIntoName(entry.serverPartition[i], pname);
4188 fprintf(STDERR, "\t%35s %s\n",
4189 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4190 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4193 MapNetworkToHost(&entry, &storeEntry);
4195 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4197 ONERROR(vcode, afromvol,
4198 " Could not update VLDB entry for volume %u\n");
4200 ERROREXIT(VOLSERBADRELEASE);
4204 /* All the ROs were release successfully. Remove the temporary clone */
4207 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4208 (unsigned long)cloneVolId);
4211 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4213 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4217 for (i = 0; i < entry.nServers; i++)
4218 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
4220 /* Update the VLDB */
4221 VPRINT("updating VLDB ...");
4223 MapNetworkToHost(&entry, &storeEntry);
4225 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4226 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4227 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4232 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4236 "Failed to end cloning transaction on the RW volume %lu\n",
4237 (unsigned long)afromvol);
4243 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4247 "Failed to end transaction on the release clone %lu\n",
4248 (unsigned long)cloneVolId);
4253 for (i = 0; i < nservers; i++) {
4254 if (replicas && replicas[i].trans) {
4255 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4256 replicas[i].trans = 0;
4259 "Failed to end transaction on ro volume %u at server %s\n",
4260 entry.volumeId[ROVOL],
4261 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4262 destHost), hoststr) :
4263 hostutil_GetNameByINet(htonl
4264 (replicas[i].server.destHost)));
4269 if (toconns && toconns[i]) {
4270 rx_DestroyConnection(toconns[i]);
4276 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4277 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4280 "Could not release lock on the VLDB entry for volume %lu\n",
4281 (unsigned long)afromvol);
4287 PrintError("", error);
4290 rx_DestroyConnection(fromconn);
4291 if (results.manyResults_val)
4292 free(results.manyResults_val);
4304 dump_sig_handler(int x)
4306 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4310 /* Dump the volume <afromvol> on <afromserver> and
4311 * <afrompart> to <afilename> starting from <fromdate>.
4312 * DumpFunction does the real work behind the scenes after
4313 * extracting parameters from the rock
4316 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4318 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4321 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4322 * be changing during the dump */
4323 struct rx_call * volatile fromcall = NULL;
4324 struct rx_connection * volatile fromconn = NULL;
4325 afs_int32 volatile fromtid = 0;
4327 afs_int32 rcode = 0;
4328 afs_int32 code, error = 0;
4330 time_t tmv = fromdate;
4334 #ifndef AFS_NT40_ENV
4335 (void)signal(SIGPIPE, dump_sig_handler);
4337 (void)signal(SIGINT, dump_sig_handler);
4340 VEPRINT("Full Dump ...\n");
4342 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4346 /* get connections to the servers */
4347 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4349 VEPRINT1("Starting transaction on volume %u...", afromvol);
4351 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4353 EGOTO1(error_exit, code,
4354 "Could not start transaction on the volume %u to be dumped\n",
4358 fromcall = rx_NewCall(fromconn);
4360 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4361 if (flags & VOLDUMPV2_OMITDIRS)
4362 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4364 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4365 EGOTO(error_exit, code, "Could not start the dump process \n");
4368 VEPRINT1("Dumping volume %u...", afromvol);
4369 code = DumpFunction(fromcall, rock);
4370 if (code == RXGEN_OPCODE)
4372 EGOTO(error_exit, code, "Error while dumping volume \n");
4377 code = rx_EndCall(fromcall, 0);
4378 if (code && code != RXGEN_OPCODE)
4379 fprintf(STDERR, "Error in rx_EndCall\n");
4384 VEPRINT1("Ending transaction on volume %u...", afromvol);
4385 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4386 if (code || rcode) {
4387 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4388 (unsigned long)afromvol);
4390 error = (code ? code : rcode);
4395 rx_DestroyConnection(fromconn);
4397 if (error != RXGEN_OPCODE)
4398 PrintError("", error);
4402 /* Clone the volume <afromvol> on <afromserver> and
4403 * <afrompart>, and then dump the clone volume to
4404 * <afilename> starting from <fromdate>.
4405 * DumpFunction does the real work behind the scenes after
4406 * extracting parameters from the rock
4409 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4410 afs_int32 afrompart, afs_int32 fromdate,
4411 afs_int32(*DumpFunction) (struct rx_call *, void *),
4412 void *rock, afs_int32 flags)
4414 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4415 * be changing during the dump */
4416 struct rx_connection * volatile fromconn = NULL;
4417 struct rx_call * volatile fromcall = NULL;
4418 afs_int32 volatile clonetid = 0;
4419 afs_uint32 volatile clonevol = 0;
4422 afs_int32 fromtid = 0, rcode = 0;
4423 afs_int32 code = 0, error = 0;
4425 time_t tmv = fromdate;
4426 char *volName = NULL;
4430 #ifndef AFS_NT40_ENV
4431 (void)signal(SIGPIPE, dump_sig_handler);
4433 (void)signal(SIGINT, dump_sig_handler);
4436 VEPRINT("Full Dump ...\n");
4438 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4442 /* get connections to the servers */
4443 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4445 VEPRINT1("Starting transaction on volume %u...", afromvol);
4446 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4447 EGOTO1(error_exit, code,
4448 "Could not start transaction on the volume %u to be dumped\n",
4452 VEPRINT1("Getting the name for volume %u ...", afromvol);
4453 code = AFSVolGetName(fromconn, fromtid, &volName);
4454 EGOTO1(error_exit, code,
4455 "Failed to get the name of the volume %u\n",afromvol);
4458 /* Get a clone id */
4459 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4461 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4463 EGOTO1(error_exit, code,
4464 "Could not get an ID for the clone of volume %u from the VLDB\n",
4468 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4469 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4473 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, volName, &tmpVol);
4475 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4479 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4481 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4485 EGOTO1(error_exit, code,
4486 "Failed to end the transaction on the volume %u\n", afromvol);
4490 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4493 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4496 EGOTO1(error_exit, code,
4497 "Failed to start a transaction on the cloned volume%u\n",
4501 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4502 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4503 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4508 fromcall = rx_NewCall(fromconn);
4510 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4511 if (flags & VOLDUMPV2_OMITDIRS)
4512 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4514 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4515 EGOTO(error_exit, code, "Could not start the dump process \n");
4518 VEPRINT1("Dumping volume %u...", afromvol);
4519 code = DumpFunction(fromcall, rock);
4520 EGOTO(error_exit, code, "Error while dumping volume \n");
4527 /* now delete the clone */
4528 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4529 code = AFSVolDeleteVolume(fromconn, clonetid);
4531 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4532 (unsigned long)clonevol);
4538 code = rx_EndCall(fromcall, 0);
4540 fprintf(STDERR, "Error in rx_EndCall\n");
4546 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4547 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4548 if (code || rcode) {
4550 "Could not end transaction on the cloned volume %lu\n",
4551 (unsigned long)clonevol);
4553 error = (code ? code : rcode);
4558 rx_DestroyConnection(fromconn);
4560 PrintError("", error);
4567 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4568 * the dump file <afilename>. WriteData does all the real work
4569 * after extracting params from the rock
4572 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4573 afs_uint32 toparentid, char tovolname[], int flags,
4574 afs_int32(*WriteData) (struct rx_call *, void *),
4577 struct rx_connection *toconn, *tempconn;
4578 struct rx_call *tocall;
4579 afs_int32 totid, code, rcode, vcode, terror = 0;
4580 struct volser_status tstatus;
4581 struct volintInfo vinfo;
4583 char tovolreal[VOLSER_OLDMAXVOLNAME];
4585 afs_int32 temptid, pparentid;
4586 struct nvldbentry entry, storeEntry;
4589 struct restoreCookie cookie;
4591 afs_int32 volflag, voltype, volsertype;
4592 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4593 VolumeId oldCloneId = 0;
4594 VolumeId oldBackupId = 0;
4595 int index, same, errcode;
4599 memset(&cookie, 0, sizeof(cookie));
4603 tocall = (struct rx_call *)0;
4604 tempconn = (struct rx_connection *)0;
4608 if (flags & RV_RDONLY) {
4610 volsertype = volser_RO;
4613 volsertype = volser_RW;
4617 pparentid = toparentid;
4618 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4619 if (pvolid == 0) { /*alot a new id if needed */
4620 vcode = VLDB_GetEntryByName(tovolname, &entry);
4621 if (vcode == VL_NOENT) {
4622 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4624 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4630 } else if (flags & RV_RDONLY) {
4631 if (entry.flags & VLF_RWEXISTS) {
4633 "Entry for ReadWrite volume %s already exists!\n",
4635 error = VOLSERBADOP;
4638 if (!entry.volumeId[ROVOL]) {
4640 "Existing entry for volume %s has no ReadOnly ID\n",
4642 error = VOLSERBADOP;
4645 pvolid = entry.volumeId[ROVOL];
4646 pparentid = entry.volumeId[RWVOL];
4648 pvolid = entry.volumeId[RWVOL];
4649 pparentid = entry.volumeId[RWVOL];
4652 if (!pparentid) pparentid = pvolid;
4653 /* at this point we have a volume id to use/reuse for the volume to be restored */
4654 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4656 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4657 EGOTO1(refail, VOLSERBADOP,
4658 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4661 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4662 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4663 EGOTO1(refail, VOLSERBADOP,
4664 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4666 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4669 MapPartIdIntoName(topart, partName);
4670 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4671 tovolreal, (unsigned long)pvolid,
4672 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4673 hostutil_GetNameByINet(toserver), partName);
4676 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4679 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4680 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4682 if (code && code != VNOVOL) {
4688 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4690 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4693 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4694 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4697 code = AFSVolGetStatus(toconn, totid, &tstatus);
4698 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4702 oldCreateDate = tstatus.creationDate;
4703 oldUpdateDate = tstatus.updateDate;
4704 oldCloneId = tstatus.cloneID;
4705 oldBackupId = tstatus.backupID;
4711 cookie.parent = pparentid;
4712 cookie.type = voltype;
4714 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4716 tocall = rx_NewCall(toconn);
4717 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4719 fprintf(STDERR, "Volume restore Failed \n");
4723 code = WriteData(tocall, rock);
4725 fprintf(STDERR, "Could not transmit data\n");
4729 terror = rx_EndCall(tocall, 0);
4730 tocall = (struct rx_call *)0;
4732 fprintf(STDERR, "rx_EndCall Failed \n");
4736 code = AFSVolGetStatus(toconn, totid, &tstatus);
4739 "Could not get status information about the volume %lu\n",
4740 (unsigned long)pvolid);
4744 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid,
4745 oldCloneId, oldBackupId);
4747 fprintf(STDERR, "Could not set the right type and IDs on %lu\n",
4748 (unsigned long)pvolid);
4753 if (flags & RV_CRDUMP)
4754 newCreateDate = tstatus.creationDate;
4755 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4756 newCreateDate = oldCreateDate;
4758 newCreateDate = time(0);
4759 if (flags & RV_LUDUMP)
4760 newUpdateDate = tstatus.updateDate;
4761 else if (flags & RV_LUKEEP)
4762 newUpdateDate = oldUpdateDate;
4764 newUpdateDate = time(0);
4765 code = AFSVolSetDate(toconn,totid, newCreateDate);
4767 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4772 init_volintInfo(&vinfo);
4773 vinfo.creationDate = newCreateDate;
4774 vinfo.updateDate = newUpdateDate;
4775 code = AFSVolSetInfo(toconn, totid, &vinfo);
4777 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4783 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4784 code = AFSVolSetFlags(toconn, totid, volflag);
4786 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4791 /* It isn't handled right in refail */
4792 code = AFSVolEndTrans(toconn, totid, &rcode);
4797 fprintf(STDERR, "Could not end transaction on %lu\n",
4798 (unsigned long)pvolid);
4803 fprintf(STDOUT, " done\n");
4805 if (!reuseID || (flags & RV_FULLRST)) {
4806 /* Volume was restored on the file server, update the
4807 * VLDB to reflect the change.
4809 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4810 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4812 "Could not fetch the entry for volume number %lu from VLDB \n",
4813 (unsigned long)pvolid);
4818 MapHostToNetwork(&entry);
4819 if (vcode == VL_NOENT) { /* it doesnot exist already */
4820 /*make the vldb return this indication specifically */
4821 VPRINT("------- Creating a new VLDB entry ------- \n");
4822 strcpy(entry.name, tovolname);
4824 entry.serverNumber[0] = toserver; /*should be indirect */
4825 entry.serverPartition[0] = topart;
4826 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4827 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4828 if (flags & RV_RDONLY)
4829 entry.volumeId[ROVOL] = pvolid;
4830 else if (tstatus.cloneID != 0) {
4831 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4833 entry.volumeId[ROVOL] = INVALID_BID;
4834 entry.volumeId[RWVOL] = pparentid;
4836 if (tstatus.backupID != 0) {
4837 entry.volumeId[BACKVOL] = tstatus.backupID;
4838 /*this should come from status info on the volume if non zero */
4840 entry.volumeId[BACKVOL] = INVALID_BID;
4841 MapNetworkToHost(&entry, &storeEntry);
4842 vcode = VLDB_CreateEntry(&storeEntry);
4845 "Could not create the VLDB entry for volume number %lu \n",
4846 (unsigned long)pvolid);
4852 EnumerateEntry(&entry);
4853 } else { /*update the existing entry */
4855 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4856 fprintf(STDOUT, "------- Old entry -------\n");
4857 EnumerateEntry(&entry);
4858 fprintf(STDOUT, "------- New entry -------\n");
4861 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4865 "Could not lock the entry for volume number %lu \n",
4866 (unsigned long)pvolid);
4871 strcpy(entry.name, tovolname);
4873 /* Update the vlentry with the new information */
4874 if (flags & RV_RDONLY)
4875 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4877 index = Lp_GetRwIndex(&entry);
4879 /* Add the new site for the volume being restored */
4880 entry.serverNumber[entry.nServers] = toserver;
4881 entry.serverPartition[entry.nServers] = topart;
4882 entry.serverFlags[entry.nServers] =
4883 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4886 /* This volume should be deleted on the old site
4887 * if its different from new site.
4890 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4894 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4896 if ((!errcode && !same)
4897 || (entry.serverPartition[index] != topart)) {
4898 if (flags & RV_NODEL) {
4900 ("Not deleting the previous volume %u on server %s, ...",
4902 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4903 hostutil_GetNameByINet(entry.serverNumber[index]));
4906 UV_Bind(entry.serverNumber[index],
4907 AFSCONF_VOLUMEPORT);
4909 MapPartIdIntoName(entry.serverPartition[index],
4912 ("Deleting the previous volume %u on server %s, partition %s ...",
4914 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4915 hostutil_GetNameByINet(entry.serverNumber[index]),
4917 code = DoVolDelete(tempconn, pvolid,
4918 entry.serverPartition[index],
4919 "the", 0, NULL, NULL);
4920 if (code && code != VNOVOL) {
4924 MapPartIdIntoName(entry.serverPartition[index],
4928 entry.serverNumber[index] = toserver;
4929 entry.serverPartition[index] = topart;
4932 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4933 MapNetworkToHost(&entry, &storeEntry);
4935 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4936 LOCKREL_OPCODE | LOCKREL_AFSID |
4940 "Could not update the entry for volume number %lu \n",
4941 (unsigned long)pvolid);
4947 EnumerateEntry(&entry);
4954 code = rx_EndCall(tocall, 0);
4960 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4961 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4964 "Could not release lock on the VLDB entry for the volume %lu\n",
4965 (unsigned long)pvolid);
4971 code = AFSVolEndTrans(toconn, totid, &rcode);
4975 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4976 (unsigned long)pvolid);
4982 code = AFSVolEndTrans(toconn, temptid, &rcode);
4986 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4987 (unsigned long)pvolid);
4993 rx_DestroyConnection(tempconn);
4995 rx_DestroyConnection(toconn);
4996 PrintError("", error);
5001 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
5002 char tovolname[], int flags,
5003 afs_int32(*WriteData) (struct rx_call *, void *),
5006 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
5011 /*unlocks the vldb entry associated with <volid> */
5013 UV_LockRelease(afs_uint32 volid)
5017 VPRINT("Binding to the VLDB server\n");
5019 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5020 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5023 "Could not unlock the entry for volume number %lu in VLDB \n",
5024 (unsigned long)volid);
5025 PrintError("", vcode);
5028 VPRINT("VLDB updated\n");
5033 /* old interface to add rosites */
5035 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5038 return UV_AddSite2(server, part, volid, 0, valid);
5041 /*adds <server> and <part> as a readonly replication site for <volid>
5044 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5045 afs_uint32 rovolid, afs_int32 valid)
5047 int j, nro = 0, islocked = 0;
5048 struct nvldbentry entry, storeEntry, entry2;
5049 afs_int32 vcode, error = 0;
5052 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5055 " Could not lock the VLDB entry for the volume %lu \n",
5056 (unsigned long)volid);
5061 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
5064 "Could not fetch the VLDB entry for volume number %lu \n",
5065 (unsigned long)volid);
5069 if (!ISNAMEVALID(entry.name)) {
5071 "Volume name %s is too long, rename before adding site\n",
5073 error = VOLSERBADOP;
5076 MapHostToNetwork(&entry);
5078 /* See if it's too many entries */
5079 if (entry.nServers >= NMAXNSERVERS) {
5080 fprintf(STDERR, "Total number of entries will exceed %u\n",
5082 error = VOLSERBADOP;
5086 /* See if it's on the same server */
5087 for (j = 0; j < entry.nServers; j++) {
5088 if (entry.serverFlags[j] & VLSF_ROVOL) {
5090 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5093 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5096 MapPartIdIntoName(entry.serverPartition[j], apartName);
5098 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5100 error = VOLSERBADOP;
5107 /* See if it's too many RO sites - leave one for the RW */
5108 if (nro >= NMAXNSERVERS - 1) {
5109 fprintf(STDERR, "Total number of sites will exceed %u\n",
5111 error = VOLSERBADOP;
5115 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5116 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5117 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5120 if (entry.volumeId[ROVOL] == INVALID_BID) {
5121 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5123 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5126 VPRINT1("Using RO volume id %d.\n", rovolid);
5127 entry.volumeId[ROVOL] = rovolid;
5129 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5130 rovolid, entry.volumeId[ROVOL]);
5134 VPRINT("Adding a new site ...");
5135 entry.serverNumber[entry.nServers] = server;
5136 entry.serverPartition[entry.nServers] = part;
5138 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5140 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5144 MapNetworkToHost(&entry, &storeEntry);
5146 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5147 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5149 fprintf(STDERR, "Could not update entry for volume %lu \n",
5150 (unsigned long)volid);
5159 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5160 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5163 "Could not release lock on volume entry for %lu \n",
5164 (unsigned long)volid);
5165 PrintError("", vcode);
5169 PrintError("", error);
5173 /*removes <server> <part> as read only site for <volid> from the vldb */
5175 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5178 struct nvldbentry entry, storeEntry;
5180 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5182 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5183 (unsigned long)volid);
5184 PrintError("", vcode);
5187 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5190 "Could not fetch the entry for volume number %lu from VLDB \n",
5191 (unsigned long)volid);
5192 PrintError("", vcode);
5195 MapHostToNetwork(&entry);
5196 if (!Lp_ROMatch(server, part, &entry)) {
5197 /*this site doesnot exist */
5198 fprintf(STDERR, "This site is not a replication site \n");
5200 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5201 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5203 fprintf(STDERR, "Could not update entry for volume %lu \n",
5204 (unsigned long)volid);
5205 PrintError("", vcode);
5206 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5207 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5211 } else { /*remove the rep site */
5212 Lp_SetROValue(&entry, server, part, 0, 0);
5214 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5215 entry.flags &= ~VLF_ROEXISTS;
5216 if (entry.nServers < 1) { /*this is the last ref */
5217 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5219 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5222 "Could not delete VLDB entry for volume %lu \n",
5223 (unsigned long)volid);
5224 PrintError("", vcode);
5229 MapNetworkToHost(&entry, &storeEntry);
5230 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5231 (unsigned long)volid);
5234 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5235 LOCKREL_OPCODE | LOCKREL_AFSID |
5239 "Could not release lock on volume entry for %lu \n",
5240 (unsigned long)volid);
5241 PrintError("", vcode);
5242 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5243 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5251 /*sets <server> <part> as read/write site for <volid> in the vldb */
5253 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5256 struct nvldbentry entry, storeEntry;
5259 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5261 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5262 (unsigned long)volid);
5263 PrintError("", vcode);
5266 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5269 "Could not fetch the entry for volume number %lu from VLDB \n",
5270 (unsigned long)volid);
5271 PrintError("", vcode);
5274 MapHostToNetwork(&entry);
5275 index = Lp_GetRwIndex(&entry);
5277 /* no RW site exists */
5278 fprintf(STDERR, "No existing RW site for volume %lu",
5279 (unsigned long)volid);
5281 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5282 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5285 "Could not release lock on entry for volume %lu \n",
5286 (unsigned long)volid);
5287 PrintError("", vcode);
5291 } else { /* change the RW site */
5292 entry.serverNumber[index] = server;
5293 entry.serverPartition[index] = part;
5294 MapNetworkToHost(&entry, &storeEntry);
5296 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5297 LOCKREL_OPCODE | LOCKREL_AFSID |
5300 fprintf(STDERR, "Could not update entry for volume %lu \n",
5301 (unsigned long)volid);
5302 PrintError("", vcode);
5303 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5304 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5312 /*list all the partitions on <aserver> */
5314 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5317 struct rx_connection *aconn;
5318 struct pIDs partIds;
5319 struct partEntries partEnts;
5323 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5325 partEnts.partEntries_len = 0;
5326 partEnts.partEntries_val = NULL;
5327 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5328 if (code == RXGEN_OPCODE) {
5329 for (i = 0; i < 26; i++) /* try old interface */
5330 partIds.partIds[i] = -1;
5331 code = AFSVolListPartitions(aconn, &partIds);
5333 for (i = 0; i < 26; i++) {
5334 if ((partIds.partIds[i]) != -1) {
5335 ptrPartList->partId[j] = partIds.partIds[i];
5336 ptrPartList->partFlags[j] = PARTVALID;
5339 ptrPartList->partFlags[i] = 0;
5344 *cntp = partEnts.partEntries_len;
5345 if (*cntp > VOLMAXPARTS) {
5347 "Warning: number of partitions on the server too high %d (process only %d)\n",
5348 *cntp, VOLMAXPARTS);
5349 *cntp = VOLMAXPARTS;
5351 for (i = 0; i < *cntp; i++) {
5352 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5353 ptrPartList->partFlags[i] = PARTVALID;
5355 free(partEnts.partEntries_val);
5361 "Could not fetch the list of partitions from the server\n");
5362 PrintError("", code);
5364 rx_DestroyConnection(aconn);
5369 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5370 This is used by the backup system */
5372 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5373 struct volDescription *volPtr, afs_int32 arraySize)
5375 struct rx_connection *aconn;
5376 struct volDescription *curPtr;
5379 afs_int32 success = 1;
5381 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5383 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5384 if (curPtr->volFlags & CLONEVALID) {
5385 curPtr->volFlags &= ~CLONEZAPPED;
5388 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5389 "clone", 0, NULL, NULL);
5394 curPtr->volFlags |= CLONEZAPPED;
5396 fprintf(STDERR, "Could not zap volume %lu\n",
5397 (unsigned long)curPtr->volCloneId);
5399 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5400 curPtr->volCloneId);
5405 rx_DestroyConnection(aconn);
5409 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5412 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5413 struct volDescription *volPtr, afs_int32 arraySize)
5415 struct rx_connection *aconn;
5416 struct volDescription *curPtr;
5419 afs_int32 rcode = 0;
5421 int reuseCloneId = 0;
5422 afs_uint32 curCloneId = 0;
5423 char cloneName[256]; /*max vol name */
5425 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5427 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5429 else { /*get a bunch of id's from vldb */
5431 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5433 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5434 PrintError("", code);
5439 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5440 if (curPtr->volFlags & ENTRYVALID) {
5442 curPtr->volFlags |= CLONEVALID;
5443 /*make a clone of curParentId and record as curPtr->volCloneId */
5445 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5448 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5451 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5455 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5456 strcpy(cloneName, curPtr->volName);
5457 strcat(cloneName, "-tmpClone-");
5459 strcpy(cloneName, "-tmpClone");
5461 curPtr->volCloneId = curCloneId;
5466 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5467 &(curPtr->volCloneId));
5469 curPtr->volFlags &= ~CLONEVALID;
5471 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5472 curPtr->volName, (unsigned long)code);
5473 code = AFSVolEndTrans(aconn, tid, &rcode);
5475 fprintf(STDERR, "WARNING: could not end transaction\n");
5478 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5479 curPtr->volCloneId);
5480 code = AFSVolEndTrans(aconn, tid, &rcode);
5481 if (code || rcode) {
5482 curPtr->volFlags &= ~CLONEVALID;
5491 rx_DestroyConnection(aconn);
5496 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5497 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5499 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5500 struct volintInfo **resultPtr, afs_int32 * size)
5502 struct rx_connection *aconn;
5504 volEntries volumeInfo;
5508 *resultPtr = (volintInfo *) 0;
5509 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5510 volumeInfo.volEntries_len = 0;
5512 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5513 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5516 "Could not fetch the list of volumes from the server\n");
5518 *resultPtr = volumeInfo.volEntries_val;
5519 *size = volumeInfo.volEntries_len;
5523 rx_DestroyConnection(aconn);
5524 PrintError("", code);
5528 /*------------------------------------------------------------------------
5529 * EXPORTED UV_XListVolumes
5532 * List the extended information for all the volumes on a particular
5533 * File Server and partition. We may either return the volume's ID
5534 * or all of its extended information.
5537 * a_serverID : Address of the File Server for which we want
5538 * extended volume info.
5539 * a_partID : Partition for which we want the extended
5541 * a_all : If non-zero, fetch ALL the volume info,
5542 * otherwise just the volume ID.
5543 * a_resultPP : Ptr to the address of the area containing
5544 * the returned volume info.
5545 * a_numEntsInResultP : Ptr for the value we set for the number of
5550 * Otherise, the return value of AFSVolXListVolumes.
5553 * This routine is closely related to UV_ListVolumes, which returns
5554 * only the standard level of detail on AFS volumes. It is a
5555 * heavyweight operation, zipping through all the volume entries for
5556 * a given server/partition.
5560 *------------------------------------------------------------------------*/
5563 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5564 struct volintXInfo **a_resultPP,
5565 afs_int32 * a_numEntsInResultP)
5567 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5568 afs_int32 code; /*Error code to return */
5569 volXEntries volumeXInfo; /*Area for returned extended vol info */
5572 * Set up our error code and the area for returned extended volume info.
5573 * We set the val field to a null pointer as a hint for the stub to
5576 *a_numEntsInResultP = 0;
5577 *a_resultPP = (volintXInfo *) 0;
5578 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5579 volumeXInfo.volXEntries_len = 0;
5582 * Bind to the Volume Server port on the File Server machine in question,
5585 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5586 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5588 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5591 * We got the info; pull out the pointer to where the results lie
5592 * and how many entries are there.
5594 *a_resultPP = volumeXInfo.volXEntries_val;
5595 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5599 * If we got an Rx connection, throw it away.
5602 rx_DestroyConnection(rxConnP);
5604 PrintError("", code);
5606 } /*UV_XListVolumes */
5608 /* get all the information about volume <volid> on <aserver> and <apart> */
5610 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5611 struct volintInfo **resultPtr)
5613 struct rx_connection *aconn;
5615 volEntries volumeInfo;
5617 *resultPtr = (volintInfo *) 0;
5618 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5619 volumeInfo.volEntries_len = 0;
5621 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5622 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5625 "Could not fetch the information about volume %lu from the server\n",
5626 (unsigned long)volid);
5628 *resultPtr = volumeInfo.volEntries_val;
5633 rx_DestroyConnection(aconn);
5634 PrintError("", code);
5638 /*------------------------------------------------------------------------
5639 * EXPORTED UV_XListOneVolume
5642 * List the extended information for a volume on a particular File
5643 * Server and partition.
5646 * a_serverID : Address of the File Server for which we want
5647 * extended volume info.
5648 * a_partID : Partition for which we want the extended
5650 * a_volID : Volume ID for which we want the info.
5651 * a_resultPP : Ptr to the address of the area containing
5652 * the returned volume info.
5656 * Otherise, the return value of AFSVolXListOneVolume.
5659 * This routine is closely related to UV_ListOneVolume, which returns
5660 * only the standard level of detail on the chosen AFS volume.
5664 *------------------------------------------------------------------------*/
5667 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5668 struct volintXInfo **a_resultPP)
5670 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5671 afs_int32 code; /*Error code */
5672 volXEntries volumeXInfo; /*Area for returned info */
5675 * Set up our error code, and the area we're in which we are returning
5676 * the info. Setting the val field to a null pointer tells the stub
5677 * to allocate space for us.
5679 *a_resultPP = (volintXInfo *) 0;
5680 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5681 volumeXInfo.volXEntries_len = 0;
5684 * Bind to the Volume Server port on the File Server machine in question,
5687 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5688 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5691 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5694 * We got the info; pull out the pointer to where the results lie.
5696 *a_resultPP = volumeXInfo.volXEntries_val;
5699 * If we got an Rx connection, throw it away.
5702 rx_DestroyConnection(rxConnP);
5704 PrintError("", code);
5709 * Given a volume we read from a partition, check if it is
5710 * represented in the VLDB correctly.
5712 * The VLDB is looked up by the RW volume id (not its name).
5713 * The RW contains the true name of the volume (BK and RO set
5714 * the name in the VLDB only on creation of the VLDB entry).
5715 * We want rules strict enough that when we check all volumes
5716 * on one partition, it does not need to be done again. IE:
5717 * two volumes on different partitions won't constantly
5718 * change a VLDB entry away from what the other set.
5719 * For RW and BK volumes, we will always check the VLDB to see
5720 * if the two exist on the server/partition. May seem redundant,
5721 * but this is an easy check of the VLDB. IE: if the VLDB entry
5722 * says the BK exists but no BK volume is there, we will detect
5723 * this when we check the RW volume.
5724 * VLDB entries are locked only when a change needs to be done.
5725 * Output changed to look a lot like the "vos syncserv" otuput.
5728 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5729 afs_int32 * modentry, afs_uint32 * maxvolid,
5730 struct nvldbentry *aentry)
5734 afs_int32 code, error = 0;
5735 struct nvldbentry entry, storeEntry;
5737 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5747 ((volumeinfo->type ==
5748 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5751 /* Check to see if the VLDB is ok without locking it (pass 1).
5752 * If it will change, then lock the VLDB entry, read it again,
5753 * then make the changes to it (pass 2).
5756 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5758 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5759 (unsigned long)rwvolid);
5764 createentry = 0; /* Do we need to create a VLDB entry */
5765 addvolume = 0; /* Add this volume to the VLDB entry */
5766 modified = 0; /* The VLDB entry was modified */
5769 memcpy(&entry, aentry, sizeof(entry));
5771 /* Read the entry from VLDB by its RW volume id */
5772 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5774 if (code != VL_NOENT) {
5776 "Could not retrieve the VLDB entry for volume %lu \n",
5777 (unsigned long)rwvolid);
5781 memset(&entry, 0, sizeof(entry));
5782 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5786 MapHostToNetwork(&entry);
5790 if (verbose && (pass == 1)) {
5791 fprintf(STDOUT, "_______________________________\n");
5792 fprintf(STDOUT, "\n-- status before -- \n");
5794 fprintf(STDOUT, "\n**does not exist**\n");
5796 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
5797 || (entry.flags & VLF_BACKEXISTS))
5798 EnumerateEntry(&entry);
5800 fprintf(STDOUT, "\n");
5803 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5809 /* Check existence of RW and BK volumes */
5810 code = CheckVldbRWBK(&entry, &mod);
5816 idx = Lp_GetRwIndex(&entry);
5817 if (idx == -1) { /* RW index not found in the VLDB entry */
5818 idx = entry.nServers; /* put it into next index */
5821 } else { /* RW index found in the VLDB entry. */
5822 /* Verify if this volume's location matches where the VLDB says it is */
5823 if (!Lp_Match(aserver, apart, &entry)) {
5824 if (entry.flags & VLF_RWEXISTS) {
5825 /* The RW volume exists elsewhere - report this one a duplicate */
5827 MapPartIdIntoName(apart, pname);
5829 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5830 (unsigned long)rwvolid,
5832 afs_inet_ntoa_r(aserver, hoststr) :
5833 hostutil_GetNameByINet(aserver), pname);
5834 MapPartIdIntoName(entry.serverPartition[idx],
5837 " VLDB reports RW volume %lu exists on %s %s\n",
5838 (unsigned long)rwvolid,
5840 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5841 hostutil_GetNameByINet(entry.
5846 /* The RW volume does not exist - have VLDB point to this one */
5849 /* Check for orphaned BK volume on old partition */
5850 if (entry.flags & VLF_BACKEXISTS) {
5852 MapPartIdIntoName(entry.serverPartition[idx],
5855 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5856 entry.volumeId[BACKVOL],
5858 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5859 hostutil_GetNameByINet(entry.
5862 MapPartIdIntoName(apart, pname);
5864 " VLDB reports its RW volume %lu exists on %s %s\n",
5865 (unsigned long)rwvolid,
5867 afs_inet_ntoa_r(aserver, hoststr) :
5868 hostutil_GetNameByINet(aserver),
5874 /* Volume location matches the VLDB location */
5875 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5876 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5879 (entry.name, volumeinfo->name,
5880 VOLSER_OLDMAXVOLNAME) != 0)) {
5888 entry.flags |= VLF_RWEXISTS;
5889 entry.volumeId[RWVOL] = rwvolid;
5890 if (!entry.volumeId[BACKVOL])
5891 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5892 if (!entry.volumeId[ROVOL])
5893 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5895 entry.serverFlags[idx] = VLSF_RWVOL;
5896 entry.serverNumber[idx] = aserver;
5897 entry.serverPartition[idx] = apart;
5898 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5902 /* One last check - to update BK if need to */
5903 code = CheckVldbRWBK(&entry, &mod);
5911 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5917 /* Check existence of RW and BK volumes */
5918 code = CheckVldbRWBK(&entry, &mod);
5924 idx = Lp_GetRwIndex(&entry);
5925 if (idx == -1) { /* RW index not found in the VLDB entry */
5926 idx = entry.nServers; /* Put it into next index */
5929 } else { /* RW index found in the VLDB entry */
5930 /* Verify if this volume's location matches where the VLDB says it is */
5931 if (!Lp_Match(aserver, apart, &entry)) {
5932 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5934 MapPartIdIntoName(apart, pname);
5936 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5937 (unsigned long)volumeinfo->volid,
5939 afs_inet_ntoa_r(aserver, hoststr) :
5940 hostutil_GetNameByINet(aserver), pname);
5941 MapPartIdIntoName(entry.serverPartition[idx], pname);
5943 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5944 (unsigned long)rwvolid,
5946 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5947 hostutil_GetNameByINet(entry.
5952 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5953 if (!(entry.flags & VLF_BACKEXISTS)) {
5955 } else if (volumeinfo->volid >
5956 entry.volumeId[BACKVOL]) {
5960 MapPartIdIntoName(entry.serverPartition[idx],
5963 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5964 entry.volumeId[BACKVOL],
5966 afs_inet_ntoa_r(aserver, hoststr) :
5967 hostutil_GetNameByINet(aserver),
5970 " VLDB reports its BK volume ID is %lu\n",
5971 (unsigned long)volumeinfo->volid);
5975 MapPartIdIntoName(entry.serverPartition[idx],
5978 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5979 (unsigned long)volumeinfo->volid,
5981 afs_inet_ntoa_r(aserver, hoststr) :
5982 hostutil_GetNameByINet(aserver),
5985 " VLDB reports its BK volume ID is %u\n",
5986 entry.volumeId[BACKVOL]);
5989 } else if (!entry.volumeId[BACKVOL]) {
5996 entry.flags |= VLF_BACKEXISTS;
5997 entry.volumeId[RWVOL] = rwvolid;
5998 entry.volumeId[BACKVOL] = volumeinfo->volid;
6000 entry.serverNumber[idx] = aserver;
6001 entry.serverPartition[idx] = apart;
6002 entry.serverFlags[idx] = VLSF_RWVOL;
6008 else if (volumeinfo->type == ROVOL) { /* A RO volume */
6009 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
6010 /* This is a quick check to see if the RO entry exists in the
6011 * VLDB so we avoid the CheckVldbRO() call (which checks if each
6012 * RO volume listed in the VLDB exists).
6014 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6016 idx = entry.nServers;
6020 if (!(entry.flags & VLF_ROEXISTS)) {
6025 /* Before we correct the VLDB entry, make sure all the
6026 * ROs listed in the VLDB exist.
6028 code = CheckVldbRO(&entry, &mod);
6034 if (!(entry.flags & VLF_ROEXISTS)) {
6035 /* No RO exists in the VLDB entry - add this one */
6036 idx = entry.nServers;
6039 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
6040 /* The volume headers's RO ID does not match that in the VLDB entry,
6041 * and the vol hdr's ID is greater (implies more recent). So delete
6042 * all the RO volumes listed in VLDB entry and add this volume.
6044 for (j = 0; j < entry.nServers; j++) {
6045 if (entry.serverFlags[j] & VLSF_ROVOL) {
6046 /* Verify this volume exists and print message we are orphaning it */
6048 MapPartIdIntoName(apart, pname);
6050 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
6051 entry.volumeId[ROVOL],
6053 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
6054 hostutil_GetNameByINet(entry.
6058 " VLDB reports its RO volume ID is %lu\n",
6059 (unsigned long)volumeinfo->volid);
6062 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6063 entry.serverPartition[idx], 0L, 0L);
6070 idx = entry.nServers;
6073 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6074 /* The volume headers's RO ID does not match that in the VLDB entry,
6075 * and the vol hdr's ID is lower (implies its older). So orphan it.
6078 MapPartIdIntoName(apart, pname);
6080 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6081 (unsigned long)volumeinfo->volid,
6083 afs_inet_ntoa_r(aserver, hoststr) :
6084 hostutil_GetNameByINet(aserver), pname);
6086 " VLDB reports its RO volume ID is %u\n",
6087 entry.volumeId[ROVOL]);
6090 /* The RO volume ID in the volume header match that in the VLDB entry,
6091 * and there exist RO volumes in the VLDB entry. See if any of them
6092 * are this one. If not, then we add it.
6094 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6096 idx = entry.nServers;
6104 entry.flags |= VLF_ROEXISTS;
6105 entry.volumeId[RWVOL] = rwvolid;
6106 entry.volumeId[ROVOL] = volumeinfo->volid;
6108 entry.serverNumber[idx] = aserver;
6109 entry.serverPartition[idx] = apart;
6110 entry.serverFlags[idx] = VLSF_ROVOL;
6116 /* Remember largest volume id */
6117 if (entry.volumeId[ROVOL] > *maxvolid)
6118 *maxvolid = entry.volumeId[ROVOL];
6119 if (entry.volumeId[BACKVOL] > *maxvolid)
6120 *maxvolid = entry.volumeId[BACKVOL];
6121 if (entry.volumeId[RWVOL] > *maxvolid)
6122 *maxvolid = entry.volumeId[RWVOL];
6124 if (modified && doit) {
6125 MapNetworkToHost(&entry, &storeEntry);
6128 code = VLDB_CreateEntry(&storeEntry);
6131 "Could not create a VLDB entry for the volume %lu\n",
6132 (unsigned long)rwvolid);
6139 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6140 LOCKREL_OPCODE | LOCKREL_AFSID |
6143 fprintf(STDERR, "Could not update entry for %lu\n",
6144 (unsigned long)rwvolid);
6148 } else if (pass == 2) {
6150 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6151 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6153 PrintError("Could not unlock VLDB entry ", code);
6157 if (modified && modentry) {
6162 memcpy(aentry, &entry, sizeof(entry));
6166 fprintf(STDOUT, "-- status after --\n");
6168 EnumerateEntry(&entry);
6170 fprintf(STDOUT, "\n**no change**\n");
6174 VPRINT("\n_______________________________\n");
6179 sortVolumes(const void *a, const void *b)
6181 volintInfo *v1 = (volintInfo *) a;
6182 volintInfo *v2 = (volintInfo *) b;
6183 afs_uint32 rwvolid1, rwvolid2;
6185 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6186 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6188 if (rwvolid1 > rwvolid2)
6189 return -1; /* lower RW id goes first */
6190 if (rwvolid1 < rwvolid2)
6193 if (v1->type == RWVOL)
6194 return -1; /* RW vols go first */
6195 if (v2->type == RWVOL)
6198 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6199 return -1; /* BK vols next */
6200 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6203 if (v1->volid < v2->volid)
6204 return 1; /* larger volids first */
6205 if (v1->volid > v2->volid)
6211 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6212 * Synchronize an individual volume against a sever and partition.
6213 * Checks the VLDB entry (similar to syncserv) as well as checks
6214 * if the volume exists on specified servers (similar to syncvldb).
6217 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6219 struct rx_connection *aconn = 0;
6220 afs_int32 j, k, code, vcode, error = 0;
6222 afs_int32 mod, modified = 0, deleted = 0;
6223 struct nvldbentry vldbentry;
6224 afs_uint32 volumeid = 0;
6225 volEntries volumeInfo;
6226 struct partList PartList;
6228 afs_uint32 maxvolid = 0;
6230 volumeInfo.volEntries_val = (volintInfo *) 0;
6231 volumeInfo.volEntries_len = 0;
6233 /* Turn verbose logging off and do our own verbose logging */
6234 /* tverbose must be set before we call ERROR_EXIT() */
6241 if (!aserver && (flags & 1)) {
6242 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6246 /* Read the VLDB entry */
6247 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6248 if (vcode && (vcode != VL_NOENT)) {
6249 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6252 } else if (!vcode) {
6253 MapHostToNetwork(&vldbentry);
6257 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6258 fprintf(STDOUT, "_______________________________\n");
6259 fprintf(STDOUT, "\n-- status before -- \n");
6261 fprintf(STDOUT, "\n**does not exist**\n");
6263 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6264 || (vldbentry.flags & VLF_BACKEXISTS))
6265 EnumerateEntry(&vldbentry);
6267 fprintf(STDOUT, "\n");
6270 /* Verify that all of the VLDB entries exist on the repective servers
6271 * and partitions (this does not require that avolname be a volume ID).
6272 * Equivalent to a syncserv.
6275 /* Tell CheckVldb not to update if appropriate */
6280 code = CheckVldb(&vldbentry, &mod, &deleted);
6282 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6290 /* If aserver is given, we will search for the desired volume on it */
6292 /* Generate array of partitions on the server that we will check */
6294 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6297 "Could not fetch the list of partitions from the server\n");
6301 PartList.partId[0] = apart;
6305 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6307 /* If a volume ID were given, search for it on each partition */
6308 if ((volumeid = atol(avolname))) {
6309 for (j = 0; j < pcnt; j++) {
6311 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6314 if (code != ENODEV) {
6315 fprintf(STDERR, "Could not query server\n");
6323 /* Found one, sync it with VLDB entry */
6325 CheckVolume(volumeInfo.volEntries_val, aserver,
6326 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6333 if (volumeInfo.volEntries_val)
6334 free(volumeInfo.volEntries_val);
6335 volumeInfo.volEntries_val = (volintInfo *) 0;
6336 volumeInfo.volEntries_len = 0;
6340 /* Check to see if the RW, BK, and RO IDs exist on any
6341 * partitions. We get the volume IDs from the VLDB.
6343 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6344 if (vldbentry.volumeId[j] == 0)
6347 for (k = 0; k < pcnt; k++) { /* For each partition */
6348 volumeInfo.volEntries_val = (volintInfo *) 0;
6349 volumeInfo.volEntries_len = 0;
6351 AFSVolListOneVolume(aconn, PartList.partId[k],
6352 vldbentry.volumeId[j], &volumeInfo);
6354 if (code != ENODEV) {
6355 fprintf(STDERR, "Could not query server\n");
6363 /* Found one, sync it with VLDB entry */
6365 CheckVolume(volumeInfo.volEntries_val, aserver,
6366 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6373 if (volumeInfo.volEntries_val)
6374 free(volumeInfo.volEntries_val);
6375 volumeInfo.volEntries_val = (volintInfo *) 0;
6376 volumeInfo.volEntries_len = 0;
6382 /* If verbose output, print a summary of what changed */
6384 fprintf(STDOUT, "-- status after --\n");
6386 fprintf(STDOUT, "\n**entry deleted**\n");
6387 } else if (modified) {
6388 EnumerateEntry(&vldbentry);
6390 fprintf(STDOUT, "\n**no change**\n");
6392 fprintf(STDOUT, "\n_______________________________\n");
6396 /* Now check if the maxvolid is larger than that stored in the VLDB */
6398 afs_uint32 maxvldbid = 0;
6399 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6402 "Could not get the highest allocated volume id from the VLDB\n");
6405 } else if (maxvolid > maxvldbid) {
6407 id = maxvolid - maxvldbid + 1;
6408 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6411 "Error in increasing highest allocated volume id in VLDB\n");
6421 fprintf(STDOUT, "...error encountered");
6423 fprintf(STDOUT, "...done entry\n");
6426 rx_DestroyConnection(aconn);
6427 if (volumeInfo.volEntries_val)
6428 free(volumeInfo.volEntries_val);
6430 PrintError("", error);
6435 * Synchronise vldb with the file server <aserver> and,
6436 * optionally, <apart>.
6439 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6441 struct rx_connection *aconn;
6442 afs_int32 code, error = 0;
6445 volEntries volumeInfo;
6446 struct partList PartList;
6450 afs_int32 failures = 0, modifications = 0, tentries = 0;
6452 afs_uint32 maxvolid = 0;
6455 volumeInfo.volEntries_val = (volintInfo *) 0;
6456 volumeInfo.volEntries_len = 0;
6458 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6460 /* Generate array of partitions to check */
6462 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6465 "Could not fetch the list of partitions from the server\n");
6469 PartList.partId[0] = apart;
6473 VPRINT("Processing volume entries ...\n");
6475 /* Step through the array of partitions */
6476 for (i = 0; i < pcnt; i++) {
6477 apart = PartList.partId[i];
6478 MapPartIdIntoName(apart, pname);
6480 volumeInfo.volEntries_val = (volintInfo *) 0;
6481 volumeInfo.volEntries_len = 0;
6482 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6485 "Could not fetch the list of volumes from the server\n");
6489 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6490 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6491 sizeof(volintInfo), sortVolumes);
6494 for (vi = volumeInfo.volEntries_val, j = 0;
6495 j < volumeInfo.volEntries_len; j++, vi++) {
6503 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6504 j + 1, vi->name, (unsigned long)vi->volid,
6506 afs_inet_ntoa_r(aserver, hoststr) :
6507 hostutil_GetNameByINet(aserver), pname);
6515 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6517 PrintError("", code);
6520 } else if (modified) {
6526 fprintf(STDOUT, "...error encountered\n\n");
6528 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6535 "Could not process entries on server %s partition %s\n",
6537 afs_inet_ntoa_r(aserver, hoststr) :
6538 hostutil_GetNameByINet(aserver), pname);
6540 if (volumeInfo.volEntries_val) {
6541 free(volumeInfo.volEntries_val);
6542 volumeInfo.volEntries_val = 0;
6545 } /* thru all partitions */
6548 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6549 tentries, failures, modifications);
6551 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6552 tentries, failures, modifications);
6556 /* Now check if the maxvolid is larger than that stored in the VLDB */
6558 afs_uint32 maxvldbid = 0;
6559 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6562 "Could not get the highest allocated volume id from the VLDB\n");
6565 } else if (maxvolid > maxvldbid) {
6567 id = maxvolid - maxvldbid + 1;
6568 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6571 "Error in increasing highest allocated volume id in VLDB\n");
6579 rx_DestroyConnection(aconn);
6580 if (volumeInfo.volEntries_val)
6581 free(volumeInfo.volEntries_val);
6582 PrintError("", error);
6587 * Determine if a volume exists on a server and partition.
6588 * Try creating a transaction on the volume. If we can,
6589 * the volume exists, if not, then return the error code.
6590 * Some error codes mean the volume is unavailable but
6591 * still exists - so we catch these error codes.
6594 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6596 struct rx_connection *conn = (struct rx_connection *)0;
6597 afs_int32 code = -1;
6598 volEntries volumeInfo;
6600 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6602 volumeInfo.volEntries_val = (volintInfo *) 0;
6603 volumeInfo.volEntries_len = 0;
6604 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6605 if (volumeInfo.volEntries_val)
6606 free(volumeInfo.volEntries_val);
6607 if (code == VOLSERILLEGAL_PARTITION)
6609 rx_DestroyConnection(conn);
6618 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6622 afs_int32 code, error = 0;
6628 idx = Lp_GetRwIndex(entry);
6630 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6633 if (idx == -1) { /* Did not find a RW entry */
6634 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6635 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6640 VolumeExists(entry->serverNumber[idx],
6641 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6642 if (code == 0) { /* RW volume exists */
6643 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6644 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6647 } else if (code == ENODEV) { /* RW volume does not exist */
6648 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6649 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6653 /* If VLDB says it didn't exist, then ignore error */
6654 if (entry->flags & VLF_RWEXISTS) {
6655 MapPartIdIntoName(entry->serverPartition[idx], pname);
6657 "Transaction call failed for RW volume %u on server %s %s\n",
6658 entry->volumeId[RWVOL],
6660 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6661 hostutil_GetNameByINet(entry->serverNumber[idx]),
6668 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6669 * flag accordingly. idx already ponts to the RW entry.
6671 if (idx == -1) { /* Did not find a RW entry */
6672 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6673 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6676 } else { /* Found a RW entry */
6678 VolumeExists(entry->serverNumber[idx],
6679 entry->serverPartition[idx],
6680 entry->volumeId[BACKVOL]);
6681 if (code == 0) { /* BK volume exists */
6682 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6683 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6686 } else if (code == ENODEV) { /* BK volume does not exist */
6687 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6688 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6692 /* If VLDB says it didn't exist, then ignore error */
6693 if (entry->flags & VLF_BACKEXISTS) {
6694 MapPartIdIntoName(entry->serverPartition[idx], pname);
6696 "Transaction call failed for BK volume %u on server %s %s\n",
6697 entry->volumeId[BACKVOL],
6699 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6700 hostutil_GetNameByINet(entry->serverNumber[idx]),
6707 /* If there is an idx but the BK and RW volumes no
6708 * longer exist, then remove the RW entry.
6710 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6711 && !(entry->flags & VLF_BACKEXISTS)) {
6712 Lp_SetRWValue(entry, entry->serverNumber[idx],
6713 entry->serverPartition[idx], 0L, 0L);
6720 *modified = modentry;
6725 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6728 int foundro = 0, modentry = 0;
6729 afs_int32 code, error = 0;
6736 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6739 for (idx = 0; idx < entry->nServers; idx++) {
6740 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6741 continue; /* not a RO */
6745 VolumeExists(entry->serverNumber[idx],
6746 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6747 if (code == 0) { /* RO volume exists */
6749 } else if (code == ENODEV) { /* RW volume does not exist */
6750 Lp_SetROValue(entry, entry->serverNumber[idx],
6751 entry->serverPartition[idx], 0L, 0L);
6756 MapPartIdIntoName(entry->serverPartition[idx], pname);
6758 "Transaction call failed for RO %u on server %s %s\n",
6759 entry->volumeId[ROVOL],
6761 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6762 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6767 if (foundro) { /* A RO volume exists */
6768 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6769 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6772 } else { /* A RO volume does not exist */
6773 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6774 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
6781 *modified = modentry;
6786 * Ensure that <entry> matches with the info on file servers
6789 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6791 afs_int32 code, error = 0;
6792 struct nvldbentry storeEntry;
6793 int islocked = 0, mod, modentry, delentry = 0;
6794 int pass = 0, doit=1;
6802 fprintf(STDOUT, "_______________________________\n");
6803 fprintf(STDOUT, "\n-- status before -- \n");
6804 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
6805 || (entry->flags & VLF_BACKEXISTS))
6806 EnumerateEntry(entry);
6807 fprintf(STDOUT, "\n");
6810 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6811 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6812 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6816 /* Check to see if the VLDB is ok without locking it (pass 1).
6817 * If it will change, then lock the VLDB entry, read it again,
6818 * then make the changes to it (pass 2).
6822 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6825 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6826 entry->volumeId[RWVOL]);
6831 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6833 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6837 MapHostToNetwork(entry);
6843 /* Check if the RW and BK entries are ok */
6844 code = CheckVldbRWBK(entry, &mod);
6847 if (mod && (pass == 1) && doit)
6852 /* Check if the RO volumes entries are ok */
6853 code = CheckVldbRO(entry, &mod);
6856 if (mod && (pass == 1) && doit)
6861 /* The VLDB entry has been updated. If it as been modified, then
6862 * write the entry back out the the VLDB.
6864 if (modentry && doit) {
6868 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
6869 && !(entry->flags & VLF_ROEXISTS) && doit) {
6870 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6872 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6876 "Could not delete VLDB entry for volume %u \n",
6877 entry->volumeId[RWVOL]);
6882 /* Replace old entry with our new one */
6883 MapNetworkToHost(entry, &storeEntry);
6885 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6886 (LOCKREL_OPCODE | LOCKREL_AFSID |
6887 LOCKREL_TIMESTAMP));
6889 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6890 entry->volumeId[RWVOL]);
6897 if (modified && modentry) {
6900 if (deleted && delentry) {
6905 fprintf(STDOUT, "-- status after --\n");
6907 fprintf(STDOUT, "\n**entry deleted**\n");
6909 EnumerateEntry(entry);
6911 fprintf(STDOUT, "\n**no change**\n");
6915 VPRINT("\n_______________________________\n");
6919 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6921 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6924 "Could not release lock on VLDB entry for volume %u\n",
6925 entry->volumeId[RWVOL]);
6934 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6937 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6939 struct rx_connection *aconn;
6940 afs_int32 code, error = 0;
6941 afs_int32 nentries, tentries = 0;
6942 struct VldbListByAttributes attributes;
6943 nbulkentries arrayEntries;
6944 afs_int32 failures = 0, modified, modifications = 0;
6945 struct nvldbentry *vlentry;
6946 afs_int32 si, nsi, j;
6951 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6953 /* Set up attributes to search VLDB */
6954 memset(&attributes, 0, sizeof(attributes));
6955 attributes.server = ntohl(aserver);
6956 attributes.Mask = VLLIST_SERVER;
6958 attributes.partition = apart;
6959 attributes.Mask |= VLLIST_PARTITION;
6962 VPRINT("Processing VLDB entries ...\n");
6964 /* While we need to collect more VLDB entries */
6965 for (si = 0; si != -1; si = nsi) {
6966 memset(&arrayEntries, 0, sizeof(arrayEntries));
6968 /* Collect set of VLDB entries */
6970 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6971 &arrayEntries, &nsi);
6972 if (code == RXGEN_OPCODE) {
6973 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6977 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6980 tentries += nentries;
6982 for (j = 0; j < nentries; j++) {
6983 vlentry = &arrayEntries.nbulkentries_val[j];
6984 MapHostToNetwork(vlentry);
6986 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6988 /* Tell CheckVldb not to update if appropriate */
6993 code = CheckVldb(vlentry, &modified, NULL);
6995 PrintError("", code);
6997 "Could not process VLDB entry for volume %s\n",
7000 } else if (modified) {
7006 fprintf(STDOUT, "...error encountered\n\n");
7008 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
7013 if (arrayEntries.nbulkentries_val) {
7014 free(arrayEntries.nbulkentries_val);
7015 arrayEntries.nbulkentries_val = 0;
7020 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
7021 tentries, failures, modifications);
7023 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
7024 tentries, failures, modifications);
7029 rx_DestroyConnection(aconn);
7030 if (arrayEntries.nbulkentries_val)
7031 free(arrayEntries.nbulkentries_val);
7034 error = VOLSERFAILEDOP;
7038 /*rename volume <oldname> to <newname>, changing the names of the related
7039 *readonly and backup volumes. This operation is also idempotent.
7040 *salvager is capable of recovering from rename operation stopping halfway.
7041 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
7043 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
7045 struct nvldbentry storeEntry;
7046 afs_int32 vcode, code, rcode, error;
7048 char nameBuffer[256];
7050 struct rx_connection *aconn;
7055 aconn = (struct rx_connection *)0;
7059 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7062 " Could not lock the VLDB entry for the volume %u \n",
7063 entry->volumeId[RWVOL]);
7068 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7069 MapNetworkToHost(entry, &storeEntry);
7070 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7072 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7073 entry->volumeId[RWVOL]);
7077 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7078 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7079 * is concerned, oldname is lost */
7080 if (entry->flags & VLF_RWEXISTS) {
7081 index = Lp_GetRwIndex(entry);
7082 if (index == -1) { /* there is a serious discrepancy */
7084 "There is a serious discrepancy in VLDB entry for volume %u\n",
7085 entry->volumeId[RWVOL]);
7086 fprintf(STDERR, "try building VLDB from scratch\n");
7087 error = VOLSERVLDB_ERROR;
7090 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7092 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7093 entry->serverPartition[index], ITOffline, &tid);
7094 if (code) { /*volume doesnot exist */
7096 "Could not start transaction on the rw volume %u\n",
7097 entry->volumeId[RWVOL]);
7100 } else { /*volume exists, process it */
7103 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7104 entry->volumeId[RWVOL],
7105 entry->volumeId[ROVOL],
7106 entry->volumeId[BACKVOL]);
7108 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7109 code = AFSVolEndTrans(aconn, tid, &rcode);
7113 "Could not end transaction on volume %s %u\n",
7114 entry->name, entry->volumeId[RWVOL]);
7119 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7120 entry->name, entry->volumeId[RWVOL]);
7126 rx_DestroyConnection(aconn);
7127 aconn = (struct rx_connection *)0;
7129 /*end rw volume processing */
7130 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7131 index = Lp_GetRwIndex(entry);
7132 if (index == -1) { /* there is a serious discrepancy */
7134 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7135 entry->volumeId[BACKVOL]);
7136 fprintf(STDERR, "try building VLDB from scratch\n");
7137 error = VOLSERVLDB_ERROR;
7140 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7142 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7143 entry->serverPartition[index], ITOffline, &tid);
7144 if (code) { /*volume doesnot exist */
7146 "Could not start transaction on the backup volume %u\n",
7147 entry->volumeId[BACKVOL]);
7150 } else { /*volume exists, process it */
7151 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7153 "Volume name %s.backup exceeds the limit of %u characters\n",
7154 newname, VOLSER_OLDMAXVOLNAME);
7158 strcpy(nameBuffer, newname);
7159 strcat(nameBuffer, ".backup");
7162 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7163 entry->volumeId[RWVOL], 0, 0);
7165 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7166 code = AFSVolEndTrans(aconn, tid, &rcode);
7170 "Could not end transaction on the backup volume %u\n",
7171 entry->volumeId[BACKVOL]);
7177 "Could not set parameters on the backup volume %u\n",
7178 entry->volumeId[BACKVOL]);
7183 } /* end backup processing */
7185 rx_DestroyConnection(aconn);
7186 aconn = (struct rx_connection *)0;
7187 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7188 for (i = 0; i < entry->nServers; i++) {
7189 if (entry->serverFlags[i] & VLSF_ROVOL) {
7190 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7192 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7193 entry->serverPartition[i], ITOffline,
7195 if (code) { /*volume doesnot exist */
7197 "Could not start transaction on the ro volume %u\n",
7198 entry->volumeId[ROVOL]);
7201 } else { /*volume exists, process it */
7202 strcpy(nameBuffer, newname);
7203 strcat(nameBuffer, ".readonly");
7204 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7206 "Volume name %s exceeds the limit of %u characters\n",
7207 nameBuffer, VOLSER_OLDMAXVOLNAME);
7212 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7213 entry->volumeId[RWVOL], 0, 0);
7215 VPRINT2("Renamed RO volume %s on host %s\n",
7218 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7219 hostutil_GetNameByINet(entry->
7221 code = AFSVolEndTrans(aconn, tid, &rcode);
7225 "Could not end transaction on volume %u\n",
7226 entry->volumeId[ROVOL]);
7232 "Could not set parameters on the ro volume %u\n",
7233 entry->volumeId[ROVOL]);
7239 rx_DestroyConnection(aconn);
7240 aconn = (struct rx_connection *)0;
7247 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7249 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7252 "Could not unlock the VLDB entry for the volume %s %u\n",
7253 entry->name, entry->volumeId[RWVOL]);
7259 code = AFSVolEndTrans(aconn, tid, &rcode);
7263 fprintf(STDERR, "Failed to end transaction on a volume \n");
7269 rx_DestroyConnection(aconn);
7270 PrintError("", error);
7275 /*report on all the active transactions on volser */
7277 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7279 struct rx_connection *aconn;
7280 transDebugEntries transInfo;
7283 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7284 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7285 transInfo.transDebugEntries_len = 0;
7286 code = AFSVolMonitor(aconn, &transInfo);
7289 "Could not access status information about the server\n");
7290 PrintError("", code);
7291 if (transInfo.transDebugEntries_val)
7292 free(transInfo.transDebugEntries_val);
7294 rx_DestroyConnection(aconn);
7297 *rcount = transInfo.transDebugEntries_len;
7298 *rpntr = transInfo.transDebugEntries_val;
7300 rx_DestroyConnection(aconn);
7307 /*delete the volume without interacting with the vldb */
7309 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7312 struct rx_connection *aconn;
7314 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7315 error = DoVolDelete(aconn, volid, part,
7316 "the", 0, NULL, NULL);
7317 if (error == VNOVOL) {
7318 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7321 PrintError("", error);
7323 rx_DestroyConnection(aconn);
7328 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7329 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7331 struct rx_connection *conn = 0;
7333 afs_int32 code, error = 0, rcode;
7335 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7337 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7341 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7343 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7347 code = AFSVolSetFlags(conn, tid, setflag);
7349 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7354 #ifdef AFS_PTHREAD_ENV
7357 IOMGR_Sleep(sleeptime);
7364 code = AFSVolEndTrans(conn, tid, &rcode);
7365 if (code || rcode) {
7366 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7368 error = (code ? code : rcode);
7373 rx_DestroyConnection(conn);
7378 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7381 struct rx_connection *conn = 0;
7383 afs_int32 code, error = 0, rcode;
7385 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7387 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7391 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7393 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7397 code = AFSVolSetInfo(conn, tid, infop);
7399 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7406 code = AFSVolEndTrans(conn, tid, &rcode);
7407 if (code || rcode) {
7408 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7410 error = (code ? code : rcode);
7415 rx_DestroyConnection(conn);
7420 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7421 afs_int32 fromdate, struct volintSize *vol_size)
7423 struct rx_connection *aconn = (struct rx_connection *)0;
7424 afs_int32 tid = 0, rcode = 0;
7425 afs_int32 code, error = 0;
7428 /* get connections to the servers */
7429 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7431 VPRINT1("Starting transaction on volume %u...", afromvol);
7432 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7433 EGOTO1(error_exit, code,
7434 "Could not start transaction on the volume %u to be measured\n",
7438 VPRINT1("Getting size of volume on volume %u...", afromvol);
7439 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7440 EGOTO(error_exit, code, "Could not start the measurement process \n");
7445 VPRINT1("Ending transaction on volume %u...", afromvol);
7446 code = AFSVolEndTrans(aconn, tid, &rcode);
7447 if (code || rcode) {
7448 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7450 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7452 error = (code ? code : rcode);
7457 rx_DestroyConnection(aconn);
7459 PrintError("", error);
7463 /*maps the host addresses in <old > (present in network byte order) to
7464 that in< new> (present in host byte order )*/
7466 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7470 memset(new, 0, sizeof(struct nvldbentry));
7472 /*copy all the fields */
7473 strcpy(new->name, old->name);
7474 /* new->volumeType = old->volumeType;*/
7475 new->nServers = old->nServers;
7476 count = old->nServers;
7477 if (count < NMAXNSERVERS)
7479 for (i = 0; i < count; i++) {
7480 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7481 new->serverPartition[i] = old->serverPartition[i];
7482 new->serverFlags[i] = old->serverFlags[i];
7484 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7485 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7486 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7487 new->cloneId = old->cloneId;
7488 new->flags = old->flags;
7491 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7493 MapHostToNetwork(struct nvldbentry *entry)
7497 count = entry->nServers;
7498 if (count < NMAXNSERVERS)
7500 for (i = 0; i < count; i++) {
7501 entry->serverNumber[i] = htonl(entry->serverNumber[i]);