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 init_volintInfo(&tstatus);
725 tstatus.maxquota = aquota;
727 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
729 if (aroid && *aroid) {
730 VPRINT1("Using RO volume ID %d.\n", *aroid);
732 if (abkid && *abkid) {
733 VPRINT1("Using BK volume ID %d.\n", *abkid);
737 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
739 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
742 VPRINT1("Using volume ID %d.\n", *anewid);
744 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
745 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
747 if (aroid && *aroid == 0) {
748 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
749 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
752 if (abkid && *abkid == 0) {
753 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
754 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
758 /* rw,ro, bk id are related in the default case */
759 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
761 if (aroid && *aroid != 0) {
762 lastid = max(lastid, *aroid);
764 if (abkid && *abkid != 0) {
765 lastid = max(lastid, *abkid);
767 if (aroid && *aroid == 0) {
770 if (abkid && *abkid == 0) {
775 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
776 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
779 code = AFSVolSetInfo(aconn, tid, &tstatus);
781 EPRINT(code, "Could not change quota, continuing...\n");
783 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
784 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
787 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
789 /* set up the vldb entry for this volume */
790 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
792 entry.serverNumber[0] = aserver; /* this should have another
793 * level of indirection later */
794 entry.serverPartition[0] = apart; /* this should also have
795 * another indirection level */
796 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
797 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
798 entry.volumeId[RWVOL] = *anewid;
799 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
800 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
802 /*map into right byte order, before passing to xdr, the stuff has to be in host
803 * byte order. Xdr converts it into network order */
804 MapNetworkToHost(&entry, &storeEntry);
805 /* create the vldb entry */
806 vcode = VLDB_CreateEntry(&storeEntry);
809 "Could not create a VLDB entry for the volume %s %lu\n",
810 aname, (unsigned long)*anewid);
811 /*destroy the created volume */
812 VPRINT1("Deleting the newly created volume %u\n", *anewid);
813 AFSVolDeleteVolume(aconn, tid);
817 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
818 /* volume created, now terminate the transaction and release the connection */
819 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
820 * the volume will come online anyway when transaction timesout , so if
821 * vldb entry exists then the volume is guaranteed to exist too wrt create */
825 "Failed to end the transaction on the volume %s %lu\n", aname,
826 (unsigned long)*anewid);
833 code = AFSVolEndTrans(aconn, tid, &rcode);
835 fprintf(STDERR, "WARNING: could not end transaction\n");
838 rx_DestroyConnection(aconn);
839 PrintError("", error);
843 /* create a volume, given a server, partition number, volume name --> sends
844 * back new vol id in <anewid>*/
846 UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
849 struct rx_connection *aconn;
852 struct nvldbentry entry, storeEntry; /*the new vldb entry */
854 aconn = (struct rx_connection *)0;
857 /* set up the vldb entry for this volume */
858 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
860 entry.serverNumber[0] = aserver; /* this should have another
861 * level of indirection later */
862 entry.serverPartition[0] = apart; /* this should also have
863 * another indirection level */
864 entry.flags = VLF_RWEXISTS; /* this records that rw volume exists */
865 entry.serverFlags[0] = VLSF_RWVOL; /*this rep site has rw vol */
866 entry.volumeId[RWVOL] = aid;
868 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
869 entry.volumeId[BACKVOL] = *anewid + 2;
871 entry.volumeId[ROVOL] = 0;
872 entry.volumeId[BACKVOL] = 0;
875 /*map into right byte order, before passing to xdr, the stuff has to be in host
876 * byte order. Xdr converts it into network order */
877 MapNetworkToHost(&entry, &storeEntry);
878 /* create the vldb entry */
879 vcode = VLDB_CreateEntry(&storeEntry);
882 "Could not create a VLDB entry for the volume %s %lu\n",
883 aname, (unsigned long)aid);
887 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
891 rx_DestroyConnection(aconn);
892 PrintError("", error);
896 /* Delete the volume <volid>on <aserver> <apart>
897 * the physical entry gets removed from the vldb only if the ref count
901 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
903 struct rx_connection *aconn = (struct rx_connection *)0;
905 afs_int32 code, rcode;
907 struct nvldbentry entry, storeEntry;
909 afs_int32 avoltype = -1, vtype;
910 int notondisk = 0, notinvldb = 0;
912 /* Find and read bhe VLDB entry for this volume */
913 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
915 if (code != VL_NOENT) {
916 EGOTO1(error_exit, code,
917 "Could not lock VLDB entry for the volume %u\n", avolid);
923 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
924 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
926 MapHostToNetwork(&entry);
929 EnumerateEntry(&entry);
932 /* Whether volume is in the VLDB or not. Delete the volume on disk */
933 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
935 code = DoVolDelete(aconn, avolid, apart, "the", 0, NULL, NULL);
945 /* Now update the VLDB entry.
946 * But first, verify we have a VLDB entry.
947 * Whether volume is on disk or not. Delete the volume in VLDB.
952 if (avolid == entry.volumeId[BACKVOL]) {
953 /* Its a backup volume, modify the VLDB entry. Check that the
954 * backup volume is on the server/partition we asked to delete.
956 if (!(entry.flags & VLF_BACKEXISTS) || !Lp_Match(aserver, apart, &entry)) {
957 notinvldb = 2; /* Not on this server and partition */
961 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
963 entry.flags &= ~VLF_BACKEXISTS;
967 else if (avolid == entry.volumeId[ROVOL]) {
968 /* Its a read-only volume, modify the VLDB entry. Check that the
969 * readonly volume is on the server/partition we asked to delete.
970 * If flags does not have RO_EIXSTS set, then this may mean the RO
971 * hasn't been released (and could exist in VLDB).
973 if (!Lp_ROMatch(aserver, apart, &entry)) {
974 notinvldb = 2; /* Not found on this server and partition */
980 "Marking the readonly volume %lu deleted in the VLDB\n",
981 (unsigned long)avolid);
983 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
985 if (!Lp_ROMatch(0, 0, &entry))
986 entry.flags &= ~VLF_ROEXISTS; /* This was the last ro volume */
990 else if (avolid == entry.volumeId[RWVOL]) {
991 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
992 * Check that the readwrite volumes is on the server/partition we
995 if (!(entry.flags & VLF_RWEXISTS) || !Lp_Match(aserver, apart, &entry)) {
996 notinvldb = 2; /* Not found on this server and partition */
1000 if (entry.volumeId[BACKVOL]) {
1001 /* Delete backup if it exists */
1002 code = DoVolDelete(aconn, entry.volumeId[BACKVOL], apart,
1003 "the backup", 0, NULL, NULL);
1004 if (code && code != VNOVOL) {
1012 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1013 (unsigned long)avolid,
1015 flags & VLF_BACKEXISTS) ? ", and its backup volume," :
1018 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1020 entry.flags &= ~(VLF_BACKEXISTS | VLF_RWEXISTS);
1023 if (entry.flags & VLF_ROEXISTS)
1024 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1028 notinvldb = 2; /* Not found on this server and partition */
1032 /* Either delete or replace the VLDB entry */
1033 if ((entry.nServers <= 0) || !(entry.flags & (VLF_ROEXISTS | VLF_RWEXISTS))) {
1036 "Last reference to the VLDB entry for %lu - deleting entry\n",
1037 (unsigned long)avolid);
1038 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1039 EGOTO1(error_exit, code,
1040 "Could not delete the VLDB entry for the volume %u \n",
1043 MapNetworkToHost(&entry, &storeEntry);
1045 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1046 (LOCKREL_OPCODE | LOCKREL_AFSID |
1047 LOCKREL_TIMESTAMP));
1048 EGOTO1(error_exit, code,
1049 "Could not update the VLDB entry for the volume %u \n",
1056 EPRINT(error, "\n");
1058 if (notondisk && notinvldb) {
1059 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1060 ((notinvldb == 2) ? "on server and partition" : ""));
1062 error = VOLSERNOVOL;
1063 } else if (notondisk) {
1065 "WARNING: Volume %lu did not exist on the partition\n",
1066 (unsigned long)avolid);
1067 } else if (notinvldb) {
1068 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1069 (unsigned long)avolid,
1070 ((notinvldb == 2) ? "on server and partition" : ""));
1074 code = AFSVolEndTrans(aconn, ttid, &rcode);
1075 code = (code ? code : rcode);
1077 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1078 (unsigned long)avolid);
1079 PrintError("", code);
1087 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1088 (LOCKREL_OPCODE | LOCKREL_AFSID |
1089 LOCKREL_TIMESTAMP));
1092 "Could not release the lock on the VLDB entry for the volume %u \n",
1100 rx_DestroyConnection(aconn);
1104 /* add recovery to UV_MoveVolume */
1106 #define TESTC 0 /* set to test recovery code, clear for production */
1112 do_interrupt(void * unused)
1115 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1116 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1117 * changed. This will avoid some sanity checks, but until a better way
1118 * is found, the only alternative is always crashing and burning on at
1119 * least the stack-overflow check. */
1120 lwp_cpptr->stack = NULL;
1125 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1127 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1128 fprintf(STDOUT, "enter second control-c to exit\n");
1136 sigint_handler(int x)
1138 #ifdef AFS_PTHREAD_ENV
1141 IOMGR_SoftSig(do_interrupt, 0);
1143 (void)signal(SIGINT, sigint_handler);
1147 DoVolDelete(struct rx_connection *aconn, afs_uint32 avolid,
1148 afs_int32 apart, char *ptypestring, afs_uint32 atoserver,
1149 struct volser_status *volstatus, char *pprefix)
1151 afs_int32 ttid = 0, code, rcode, error = 0;
1152 char *prefix, *typestring;
1161 typestring = ptypestring;
1167 VPRINT3("%sDeleting %s volume %u ...", prefix, typestring, avolid);
1170 AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
1172 /* return early and quietly for VNOVOL; don't continue the attempt to delete. */
1173 if (code == VNOVOL) {
1178 EGOTO2(dfail, code, "%sFailed to start transaction on %u\n",
1182 code = AFSVolGetStatus(aconn, ttid, volstatus);
1183 EGOTO2(dfail, code, "%sCould not get timestamp from volume %u\n",
1188 AFSVolSetFlags(aconn, ttid,
1189 VTDeleteOnSalvage | VTOutOfService);
1191 EGOTO2(dfail, code, "%sCould not set flags on volume %u \n",
1195 VPRINT1("%sSetting volume forwarding pointer ...", prefix);
1196 AFSVolSetForwarding(aconn, ttid, atoserver);
1200 code = AFSVolDeleteVolume(aconn, ttid);
1201 EGOTO2(dfail, code, "%sCould not delete volume %u\n", prefix, avolid);
1205 code = AFSVolEndTrans(aconn, ttid, &rcode);
1210 fprintf(STDERR, "%sCould not end transaction on %s volume %lu \n",
1211 prefix, typestring, (unsigned long)avolid);
1217 if (beverbose && !error)
1223 DoVolClone(struct rx_connection *aconn, afs_uint32 avolid,
1224 afs_int32 apart, int type, afs_uint32 cloneid,
1225 char *typestring, char *pname, char *vname, char *suffix,
1226 struct volser_status *volstatus, afs_int32 *transPtr)
1229 afs_int32 ttid = 0, btid = 0;
1230 afs_int32 code = 0, rcode = 0;
1231 afs_int32 error = 0;
1232 int cloneexists = 1;
1234 /* Test to see if the clone volume exists by trying to create
1235 * a transaction on the clone volume. We've assumed the clone exists.
1237 code = AFSVolTransCreate_retry(aconn, cloneid, apart, ITOffline, &btid);
1239 if (code != VNOVOL) {
1240 EPRINT2(code, "Could not reach the %s volume %lu\n",
1241 typestring, (unsigned long)cloneid);
1245 cloneexists = 0; /* clone volume does not exist */
1248 code = AFSVolEndTrans(aconn, btid, &rcode);
1250 if (code || rcode) {
1252 "Could not end transaction on the previous %s volume %lu\n",
1253 typestring, (unsigned long)cloneid);
1254 error = (code ? code : rcode);
1259 /* Now go ahead and try to clone the RW volume.
1260 * First start a transaction on the RW volume
1262 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
1264 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
1265 (unsigned long)avolid);
1270 /* Clone or reclone the volume, depending on whether the clone
1271 * volume exists or not
1274 VPRINT2("Re-cloning %s volume %u ...", typestring, cloneid);
1276 code = AFSVolReClone(aconn, ttid, cloneid);
1278 EPRINT2(code, "Could not re-clone %s volume %lu\n",
1279 typestring, (unsigned long)cloneid);
1284 VPRINT2("Creating a new %s clone %u ...", typestring, cloneid);
1287 strcpy(cname, pname);
1288 strcat(cname, suffix);
1291 code = AFSVolClone(aconn, ttid, 0, type, vname?vname:cname,
1294 fprintf(STDERR, "Failed to clone the volume %lu\n",
1295 (unsigned long)avolid);
1304 VPRINT1("Getting status of parent volume %u...", avolid);
1305 code = AFSVolGetStatus(aconn, ttid, volstatus);
1307 fprintf(STDERR, "Failed to get the status of the parent volume %lu\n",
1308 (unsigned long)avolid);
1317 code = AFSVolEndTrans(aconn, ttid, &rcode);
1318 if (code || rcode) {
1319 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1320 (unsigned long)avolid);
1322 error = (code ? code : rcode);
1327 code = AFSVolEndTrans(aconn, btid, &rcode);
1328 if (code || rcode) {
1330 "Could not end transaction on the %s volume %lu\n",
1331 typestring, (unsigned long)cloneid);
1333 error = (code ? code : rcode);
1339 /* Convert volume from RO to RW; adjust the VLDB entry to match.
1340 * The nvldbentry passed to us has already been MapHostToNetwork'd
1345 UV_ConvertRO(afs_uint32 server, afs_uint32 partition, afs_uint32 volid,
1346 struct nvldbentry *entry)
1348 afs_int32 code, i, same;
1349 struct nvldbentry checkEntry, storeEntry;
1351 afs_int32 rwindex = 0;
1352 afs_uint32 rwserver = 0;
1353 afs_int32 roindex = 0;
1354 afs_uint32 roserver = 0;
1355 struct rx_connection *aconn;
1358 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
1362 "Unable to lock volume %lu, code %d\n",
1363 (unsigned long)entry->volumeId[RWVOL],vcode);
1364 PrintError("", vcode);
1368 /* make sure the VLDB entry hasn't changed since we started */
1369 memset(&checkEntry, 0, sizeof(checkEntry));
1370 vcode = VLDB_GetEntryByID(volid, -1, &checkEntry);
1373 "Could not fetch the entry for volume %lu from VLDB\n",
1374 (unsigned long)volid);
1375 PrintError("convertROtoRW ", vcode);
1380 MapHostToNetwork(&checkEntry);
1381 entry->flags &= ~VLOP_ALLOPERS; /* clear any stale lock operation flags */
1382 entry->flags |= VLOP_MOVE; /* set to match SetLock operation above */
1383 if (memcmp(entry, &checkEntry, sizeof(*entry)) != 0) {
1385 "VLDB entry for volume %lu has changed; please reissue the command.\n",
1386 (unsigned long)volid);
1391 /* extract information from the original entry */
1392 for (i = 0; i < entry->nServers; i++) {
1393 if (entry->serverFlags[i] & VLSF_RWVOL) {
1395 rwserver = entry->serverNumber[i];
1396 /* rwpartition = entry->serverPartition[i]; */
1399 } else if ((entry->serverFlags[i] & VLSF_ROVOL) && !roserver) {
1400 same = VLDB_IsSameAddrs(server, entry->serverNumber[i], &code);
1403 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1410 roserver = entry->serverNumber[i];
1411 /* ropartition = entry->serverPartition[i]; */
1418 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
1419 code = AFSVolConvertROtoRWvolume(aconn, partition, volid);
1422 "Converting RO volume %lu to RW volume failed with code %d\n",
1423 (unsigned long)volid, code);
1424 PrintError("convertROtoRW ", code);
1427 /* Update the VLDB to match what we did on disk as much as possible. */
1428 /* If the converted RO was in the VLDB, make it look like the new RW. */
1430 entry->serverFlags[roindex] = VLSF_RWVOL;
1432 /* Add a new site entry for the newly created RW. It's possible
1433 * (but unlikely) that we are already at MAXNSERVERS and that this
1434 * new site will invalidate the whole VLDB entry; however,
1435 * VLDB_ReplaceEntry will detect this and return VL_BADSERVER,
1436 * so we need no extra guard logic here.
1438 afs_int32 newrwindex = entry->nServers;
1439 (entry->nServers)++;
1440 entry->serverNumber[newrwindex] = server;
1441 entry->serverPartition[newrwindex] = partition;
1442 entry->serverFlags[newrwindex] = VLSF_RWVOL;
1444 entry->flags |= VLF_RWEXISTS;
1445 entry->flags &= ~VLF_BACKEXISTS;
1447 /* if the old RW was in the VLDB, remove it by decrementing the number */
1448 /* of servers, replacing the RW entry with the last entry, and zeroing */
1449 /* out the last entry. */
1451 (entry->nServers)--;
1452 if (rwindex != entry->nServers) {
1453 entry->serverNumber[rwindex] = entry->serverNumber[entry->nServers];
1454 entry->serverPartition[rwindex] =
1455 entry->serverPartition[entry->nServers];
1456 entry->serverFlags[rwindex] = entry->serverFlags[entry->nServers];
1457 entry->serverNumber[entry->nServers] = 0;
1458 entry->serverPartition[entry->nServers] = 0;
1459 entry->serverFlags[entry->nServers] = 0;
1462 entry->flags &= ~VLF_ROEXISTS;
1463 for (i = 0; i < entry->nServers; i++) {
1464 if (entry->serverFlags[i] & VLSF_ROVOL) {
1465 if (!(entry->serverFlags[i] & (VLSF_DONTUSE | VLSF_NEWREPSITE)))
1466 entry->flags |= VLF_ROEXISTS;
1469 MapNetworkToHost(entry, &storeEntry);
1471 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
1472 (LOCKREL_OPCODE | LOCKREL_AFSID |
1473 LOCKREL_TIMESTAMP));
1476 "Warning: volume converted, but vldb update failed with code %d!\n",
1481 vcode = UV_LockRelease(entry->volumeId[RWVOL]);
1484 "Unable to unlock volume %lu, code %d\n",
1485 (unsigned long)entry->volumeId[RWVOL],vcode);
1486 PrintError("", vcode);
1492 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1493 * <atopart>. The operation is almost idempotent. The following
1494 * flags are recognized:
1496 * RV_NOCLONE - don't use a copy clone
1500 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1501 afs_uint32 atoserver, afs_int32 atopart, int flags)
1503 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1504 * be changing during the move */
1505 struct rx_connection * volatile toconn;
1506 struct rx_connection * volatile fromconn;
1507 afs_int32 volatile fromtid;
1508 afs_int32 volatile totid;
1509 afs_int32 volatile clonetid;
1510 afs_uint32 volatile newVol;
1511 afs_uint32 volatile volid;
1512 afs_uint32 volatile backupId;
1513 int volatile islocked;
1518 char tmpName[VOLSER_MAXVOLNAME + 1];
1523 struct restoreCookie cookie;
1524 afs_int32 vcode, code;
1525 struct volser_status tstatus;
1526 struct destServer destination;
1528 struct nvldbentry entry, storeEntry;
1531 char in, lf; /* for test code */
1535 #ifdef ENABLE_BUGFIX_1165
1536 volEntries volumeInfo;
1537 struct volintInfo *infop = 0;
1541 fromconn = (struct rx_connection *)0;
1542 toconn = (struct rx_connection *)0;
1552 /* support control-c processing */
1555 (void)signal(SIGINT, sigint_handler);
1559 "\nThere are three tests points - verifies all code paths through recovery.\n");
1560 fprintf(STDOUT, "First test point - operation not started.\n");
1561 fprintf(STDOUT, "...test here (y, n)? ");
1563 if (fscanf(stdin, "%c", &in) < 1)
1565 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1568 fprintf(STDOUT, "type control-c\n");
1570 fprintf(stdout, ".");
1575 /* or drop through */
1578 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1579 EGOTO1(mfail, vcode,
1580 "Could not fetch the entry for the volume %u from the VLDB \n",
1583 if (entry.volumeId[RWVOL] != afromvol) {
1584 fprintf(STDERR, "Only RW volume can be moved\n");
1588 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1589 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1592 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1593 EGOTO1(mfail, vcode,
1594 "Could not fetch the entry for the volume %u from the VLDB \n",
1597 backupId = entry.volumeId[BACKVOL];
1598 MapHostToNetwork(&entry);
1600 if (!Lp_Match(afromserver, afrompart, &entry)) {
1601 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1602 if (!Lp_Match(atoserver, atopart, &entry)) {
1603 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1604 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1605 (unsigned long)afromvol);
1606 fprintf(STDERR, "The current site is :");
1607 for (i = 0; i < entry.nServers; i++) {
1608 if (entry.serverFlags[i] == VLSF_RWVOL) {
1610 MapPartIdIntoName(entry.serverPartition[i], pname);
1611 fprintf(STDERR, " server %s partition %s \n",
1612 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1613 hostutil_GetNameByINet(entry.serverNumber[i]),
1618 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1619 (LOCKREL_OPCODE | LOCKREL_AFSID |
1620 LOCKREL_TIMESTAMP));
1621 EGOTO1(mfail, vcode,
1622 " Could not release lock on the VLDB entry for the volume %u \n",
1625 return VOLSERVOLMOVED;
1628 /* delete the volume afromvol on src_server */
1629 /* from-info does not exist but to-info does =>
1630 * we have already done the move, but the volume
1631 * may still be existing physically on from fileserver
1633 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1636 code = DoVolDelete(fromconn, afromvol, afrompart,
1637 "leftover", 0, NULL, NULL);
1638 if (code && code != VNOVOL) {
1643 code = DoVolDelete(fromconn, backupId, afrompart,
1644 "leftover backup", 0, NULL, NULL);
1645 if (code && code != VNOVOL) {
1655 /* From-info matches the vldb info about volid,
1656 * its ok start the move operation, the backup volume
1657 * on the old site is deleted in the process
1659 if (afrompart == atopart) {
1660 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1661 EGOTO2(mfail, error,
1662 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1663 afromserver, error);
1666 EGOTO1(mfail, VOLSERVOLMOVED,
1667 "Warning: Moving volume %u to its home partition ignored!\n",
1673 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1674 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1675 totid = 0; /* initialize to uncreated */
1678 * clone the read/write volume locally.
1681 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1682 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1684 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1688 if (!(flags & RV_NOCLONE)) {
1689 /* Get a clone id */
1690 VPRINT1("Allocating new volume id for clone of volume %u ...",
1693 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1695 EGOTO1(mfail, vcode,
1696 "Could not get an ID for the clone of volume %u from the VLDB\n",
1700 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1701 VPRINT1("Cloning source volume %u ...", afromvol);
1702 strcpy(vname, "move-clone-temp");
1704 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1706 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1711 /* lookup the name of the volume we just cloned */
1713 code = AFSVolGetName(fromconn, fromtid, &volName);
1714 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1717 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1719 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1724 "Failed to end the transaction on the source volume %u\n",
1729 * Create the destination volume
1732 if (!(flags & RV_NOCLONE)) {
1733 /* All of this is to get the fromDate */
1734 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1737 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1741 "Failed to start a transaction on the cloned volume%u\n",
1745 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1747 AFSVolSetFlags(fromconn, clonetid,
1748 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1749 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1753 /* remember time from which we've dumped the volume */
1754 VPRINT1("Getting status of cloned volume %u ...", newVol);
1755 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1757 "Failed to get the status of the cloned volume %u\n",
1761 fromDate = CLOCKADJ(tstatus.creationDate);
1763 /* With RV_NOCLONE, just do a full copy from the source */
1768 #ifdef ENABLE_BUGFIX_1165
1770 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1771 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1772 * don't use this information...
1774 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1775 volumeInfo.volEntries_len = 0;
1776 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1778 "Failed to get the volint Info of the cloned volume %u\n",
1781 infop = (volintInfo *) volumeInfo.volEntries_val;
1782 infop->maxquota = -1; /* Else it will replace the default quota */
1783 infop->creationDate = -1; /* Else it will use the source creation date */
1784 infop->updateDate = -1; /* Else it will use the source update date */
1787 /* create a volume on the target machine */
1789 code = DoVolDelete(toconn, volid, atopart,
1790 "pre-existing destination", 0, NULL, NULL);
1791 if (code && code != VNOVOL) {
1796 VPRINT1("Creating the destination volume %u ...", volid);
1800 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1804 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1808 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1812 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1814 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1816 "Failed to set the flags on the destination volume %u\n", volid);
1820 * Now dump the clone to the new volume
1823 destination.destHost = ntohl(atoserver);
1824 destination.destPort = AFSCONF_VOLUMEPORT;
1825 destination.destSSID = 1;
1827 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1828 cookie.type = RWVOL;
1829 cookie.parent = entry.volumeId[RWVOL];
1832 if (!(flags & RV_NOCLONE)) {
1833 /* Copy the clone to the new volume */
1834 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1837 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1839 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1842 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1843 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1848 "Failed to end the transaction on the cloned volume %u\n",
1854 * reattach to the main-line volume, and incrementally dump it.
1857 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1859 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1862 "Failed to create a transaction on the source volume %u\n",
1866 /* now do the incremental */
1868 ("Doing the%s dump from source to destination for volume %u ... ",
1869 (flags & RV_NOCLONE) ? "" : " incremental",
1872 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1875 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1876 (flags & RV_NOCLONE) ? "" : " incremental");
1879 /* now adjust the flags so that the new volume becomes official */
1880 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1881 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1883 "Failed to set the flags to make old source volume offline\n");
1886 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1887 code = AFSVolSetFlags(toconn, totid, 0);
1889 "Failed to set the flags to make new source volume online\n");
1892 #ifdef ENABLE_BUGFIX_1165
1893 VPRINT1("Setting volume status on destination volume %u ...", volid);
1894 code = AFSVolSetInfo(toconn, totid, infop);
1896 "Failed to set volume status on the destination volume %u\n",
1901 /* put new volume online */
1902 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1903 code = AFSVolEndTrans(toconn, totid, &rcode);
1908 "Failed to end the transaction on the volume %u on the new site\n",
1912 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1913 MapNetworkToHost(&entry, &storeEntry);
1914 storeEntry.flags &= ~VLF_BACKEXISTS;
1918 "Second test point - operation in progress but not complete.\n");
1919 fprintf(STDOUT, "...test here (y, n)? ");
1921 if (fscanf(stdin, "%c", &in) < 1)
1923 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1926 fprintf(STDOUT, "type control-c\n");
1928 fprintf(stdout, ".");
1933 /* or drop through */
1936 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1938 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1939 (LOCKREL_OPCODE | LOCKREL_AFSID |
1940 LOCKREL_TIMESTAMP));
1943 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1944 storeEntry.name, (unsigned long)afromvol);
1953 "Third test point - operation complete but no cleanup.\n");
1954 fprintf(STDOUT, "...test here (y, n)? ");
1956 if (fscanf(stdin, "%c", &in) < 1)
1958 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
1961 fprintf(STDOUT, "type control-c\n");
1963 fprintf(stdout, ".");
1968 /* or drop through */
1971 /* This is tricky. File server is very stupid, and if you mark the volume
1972 * as VTOutOfService, it may mark the *good* instance (if you're moving
1973 * between partitions on the same machine) as out of service. Since
1974 * we're cleaning this code up in DEcorum, we're just going to kludge around
1975 * it for now by removing this call. */
1976 /* already out of service, just zap it now */
1978 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1981 "Failed to set the flags to make the old source volume offline\n");
1985 if (atoserver != afromserver) {
1986 /* set forwarding pointer for moved volumes */
1987 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1988 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1990 "Failed to set the forwarding pointer for the volume %u\n",
1995 VPRINT1("Deleting old volume %u on source ...", afromvol);
1996 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1997 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
2001 VPRINT1("Ending transaction on old volume %u on the source ...",
2003 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2008 "Failed to end the transaction on the old volume %u on the source\n",
2012 code = DoVolDelete(fromconn, backupId, afrompart,
2013 "source backup", 0, NULL, NULL);
2014 if (code && code != VNOVOL) {
2019 code = 0; /* no backup volume? that's okay */
2022 if (!(flags & RV_NOCLONE)) {
2023 code = DoVolDelete(fromconn, newVol, afrompart,
2024 "cloned", 0, NULL, NULL);
2026 if (code == VNOVOL) {
2027 EPRINT1(code, "Failed to start transaction on %u\n", newVol);
2038 fprintf(STDOUT, "Fourth test point - operation complete.\n");
2039 fprintf(STDOUT, "...test here (y, n)? ");
2041 if (fscanf(stdin, "%c", &in) < 1)
2043 if (fscanf(stdin, "%c", &lf) < 0) /* toss away */
2046 fprintf(STDOUT, "type control-c\n");
2048 fprintf(stdout, ".");
2053 /* or drop through */
2056 /* normal cleanup code */
2058 if (entry.flags & VLF_ROEXISTS)
2059 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
2062 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
2064 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2065 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2069 " Could not release the lock on the VLDB entry for the volume %lu \n",
2070 (unsigned long)afromvol);
2078 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2080 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2081 if (code || rcode) {
2084 "Could not end transaction on the source volume %lu\n",
2085 (unsigned long)afromvol);
2087 error = (code ? code : rcode);
2093 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
2094 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2095 if (code || rcode) {
2098 "Could not end transaction on the source's clone volume %lu\n",
2099 (unsigned long)newVol);
2101 error = (code ? code : rcode);
2107 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2109 code = AFSVolEndTrans(toconn, totid, &rcode);
2113 "Could not end transaction on destination volume %lu\n",
2114 (unsigned long)afromvol);
2116 error = (code ? code : rcode);
2122 #ifdef ENABLE_BUGFIX_1165
2127 rx_DestroyConnection(fromconn);
2129 rx_DestroyConnection(toconn);
2130 PrintError("", error);
2133 /* come here only when the sky falls */
2138 "vos move: operation interrupted, cleanup in progress...\n");
2139 fprintf(STDOUT, "clear transaction contexts\n");
2143 /* unlock VLDB entry */
2145 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
2146 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2147 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2153 VPRINT("Recovery: Ending transaction on clone volume ...");
2154 AFSVolEndTrans(fromconn, clonetid, &rcode);
2158 VPRINT("Recovery: Ending transaction on destination volume ...");
2159 AFSVolEndTrans(toconn, totid, &rcode);
2162 if (fromtid) { /* put it on-line */
2163 VPRINT("Recovery: Setting volume flags on source volume ...");
2164 AFSVolSetFlags(fromconn, fromtid, 0);
2167 VPRINT("Recovery: Ending transaction on source volume ...");
2168 AFSVolEndTrans(fromconn, fromtid, &rcode);
2172 VPRINT("Recovery: Accessing VLDB.\n");
2173 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2175 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2179 MapHostToNetwork(&entry);
2181 /* Delete either the volume on the source location or the target location.
2182 * If the vldb entry still points to the source location, then we know the
2183 * volume move didn't finish so we remove the volume from the target
2184 * location. Otherwise, we remove the volume from the source location.
2186 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
2189 "move incomplete - attempt cleanup of target partition - no guarantee\n");
2193 if (volid && toconn) {
2194 code = DoVolDelete(toconn, volid, atopart,
2195 "destination", 0, NULL, "Recovery:");
2196 if (code == VNOVOL) {
2197 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", volid);
2201 /* put source volume on-line */
2203 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2207 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2213 VPRINT1("Recovery: Setting flags on source volume %u ...",
2215 AFSVolSetFlags(fromconn, fromtid, 0);
2219 ("Recovery: Ending transaction on source volume %u ...",
2221 AFSVolEndTrans(fromconn, fromtid, &rcode);
2225 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2229 } else { /* yep, move complete */
2232 "move complete - attempt cleanup of source partition - no guarantee\n");
2236 /* delete backup volume */
2238 code = DoVolDelete(fromconn, backupId, afrompart,
2239 "backup", 0, NULL, "Recovery:");
2240 if (code == VNOVOL) {
2241 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", backupId);
2244 code = DoVolDelete(fromconn, afromvol, afrompart, "source",
2245 (atoserver != afromserver)?atoserver:0,
2247 if (code == VNOVOL) {
2248 EPRINT1(code, "Failed to start transaction on %u\n", afromvol);
2253 /* common cleanup - delete local clone */
2255 code = DoVolDelete(fromconn, newVol, afrompart,
2256 "clone", 0, NULL, "Recovery:");
2257 if (code == VNOVOL) {
2258 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", newVol);
2262 /* unlock VLDB entry */
2264 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2266 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2267 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2270 done: /* routine cleanup */
2273 #ifdef ENABLE_BUGFIX_1165
2278 rx_DestroyConnection(fromconn);
2280 rx_DestroyConnection(toconn);
2283 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2291 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2292 afs_uint32 atoserver, afs_int32 atopart)
2294 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2295 atoserver, atopart, 0);
2299 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2300 * <atopart>. The new volume is named by <atovolname>. The new volume
2301 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2302 * from the VLDB. the following flags are supported:
2304 * RV_RDONLY - target volume is RO
2305 * RV_OFFLINE - leave target volume offline
2306 * RV_CPINCR - do incremental dump if target exists
2307 * RV_NOVLDB - don't create/update VLDB entry
2308 * RV_NOCLONE - don't use a copy clone
2311 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2312 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2313 afs_uint32 atovolid, int flags)
2315 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2316 * be changing during the copy */
2318 afs_int32 volatile clonetid;
2319 afs_int32 volatile totid;
2320 afs_int32 volatile fromtid;
2321 struct rx_connection * volatile fromconn;
2322 struct rx_connection * volatile toconn;
2323 afs_uint32 volatile cloneVol;
2327 afs_int32 fromDate, cloneFromDate;
2328 struct restoreCookie cookie;
2329 afs_int32 vcode, code;
2332 struct volser_status tstatus;
2333 struct destServer destination;
2334 struct nvldbentry entry, newentry, storeEntry;
2339 fromconn = (struct rx_connection *)0;
2340 toconn = (struct rx_connection *)0;
2348 /* support control-c processing */
2351 (void)signal(SIGINT, sigint_handler);
2353 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2354 EGOTO1(mfail, vcode,
2355 "Could not fetch the entry for the volume %u from the VLDB \n",
2357 MapHostToNetwork(&entry);
2360 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2361 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2362 fromtid = totid = 0; /* initialize to uncreated */
2365 * clone the read/write volume locally.
2369 if (!(flags & RV_NOCLONE)) {
2370 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2372 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2375 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2379 /* Get a clone id */
2380 VPRINT1("Allocating new volume id for clone of volume %u ...",
2384 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2386 EGOTO1(mfail, vcode,
2387 "Could not get an ID for the clone of volume %u from the VLDB\n",
2395 /* Get a new volume id */
2396 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2398 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2399 EGOTO1(mfail, vcode,
2400 "Could not get an ID for the copy of volume %u from the VLDB\n",
2405 if (!(flags & RV_NOCLONE)) {
2406 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2407 VPRINT1("Cloning source volume %u ...", afromvol);
2408 strcpy(vname, "copy-clone-temp");
2411 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2414 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2418 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2420 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2425 "Failed to end the transaction on the source volume %u\n",
2431 * Create the destination volume
2434 if (!(flags & RV_NOCLONE)) {
2435 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2438 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2442 "Failed to start a transaction on the cloned volume%u\n",
2446 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2448 AFSVolSetFlags(fromconn, clonetid,
2449 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2450 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2454 /* remember time from which we've dumped the volume */
2455 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2456 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2458 "Failed to get the status of the cloned volume %u\n",
2462 fromDate = CLOCKADJ(tstatus.creationDate);
2467 /* create a volume on the target machine */
2470 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2473 if ((flags & RV_CPINCR)) {
2474 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2475 code = AFSVolGetStatus(toconn, totid, &tstatus);
2477 "Failed to get the status of the pre-existing volume %u\n",
2481 /* Using the update date should be OK here, but add some fudge */
2482 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2483 if ((flags & RV_NOCLONE))
2484 fromDate = cloneFromDate;
2486 /* XXX We should check that the source volume's creationDate is
2487 * XXX not newer than the existing target volume, and if not,
2488 * XXX throw away the existing target and do a full dump. */
2493 /* Delete the existing volume.
2494 * While we are deleting the volume in these steps, the transaction
2495 * we started against the cloned volume (clonetid above) will be
2496 * sitting idle. It will get cleaned up after 600 seconds
2498 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2499 code = AFSVolDeleteVolume(toconn, totid);
2501 "Could not delete the pre-existing volume %u on destination\n",
2506 ("Ending transaction on pre-existing volume %u on destination ...",
2508 code = AFSVolEndTrans(toconn, totid, &rcode);
2513 "Could not end the transaction on pre-existing volume %u on destination\n",
2518 VPRINT1("Creating the destination volume %u ...", newVol);
2521 AFSVolCreateVolume(toconn, atopart, atovolname,
2522 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2523 newVol, &newVol, &tmp);
2525 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2529 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2531 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2533 "Failed to set the flags on the destination volume %u\n", newVol);
2538 destination.destHost = ntohl(atoserver);
2539 destination.destPort = AFSCONF_VOLUMEPORT;
2540 destination.destSSID = 1;
2542 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2543 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2548 * Now dump the clone to the new volume
2551 if (!(flags & RV_NOCLONE)) {
2552 /* XXX probably should have some code here that checks to see if
2553 * XXX we are copying to same server and partition - if so, just
2554 * XXX use a clone to save disk space */
2556 /* Copy the clone to the new volume */
2557 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2560 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2562 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2566 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2567 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2572 "Failed to end the transaction on the cloned volume %u\n",
2578 * reattach to the main-line volume, and incrementally dump it.
2581 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2583 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2586 "Failed to create a transaction on the source volume %u\n",
2590 /* now do the incremental */
2592 ("Doing the%s dump from source to destination for volume %u ... ",
2593 (flags & RV_NOCLONE) ? "" : " incremental",
2596 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2599 "Failed to do the%s dump from old site to new site\n",
2600 (flags & RV_NOCLONE) ? "" : " incremental");
2603 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2604 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2605 code = AFSVolSetFlags(toconn, totid, volflag);
2607 "Failed to set the flags to make destination volume online\n");
2610 /* put new volume online */
2611 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2612 code = AFSVolEndTrans(toconn, totid, &rcode);
2617 "Failed to end the transaction on the destination volume %u\n",
2621 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2622 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2627 "Failed to end the transaction on the source volume %u\n",
2633 if (!(flags & RV_NOCLONE)) {
2634 code = DoVolDelete(fromconn, cloneVol, afrompart,
2635 "cloned", 0, NULL, NULL);
2637 if (code == VNOVOL) {
2638 EPRINT1(code, "Failed to start transaction on %u\n", cloneVol);
2645 if (!(flags & RV_NOVLDB)) {
2646 /* create the vldb entry for the copied volume */
2647 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2648 newentry.nServers = 1;
2649 newentry.serverNumber[0] = atoserver;
2650 newentry.serverPartition[0] = atopart;
2651 newentry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
2652 newentry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
2653 newentry.volumeId[RWVOL] = newVol;
2654 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2655 newentry.volumeId[BACKVOL] = 0;
2656 newentry.cloneId = 0;
2657 /*map into right byte order, before passing to xdr, the stuff has to be in host
2658 * byte order. Xdr converts it into network order */
2659 MapNetworkToHost(&newentry, &storeEntry);
2660 /* create the vldb entry */
2661 vcode = VLDB_CreateEntry(&storeEntry);
2664 "Could not create a VLDB entry for the volume %s %lu\n",
2665 atovolname, (unsigned long)newVol);
2666 /*destroy the created volume */
2667 VPRINT1("Deleting the newly created volume %u\n", newVol);
2668 AFSVolDeleteVolume(toconn, totid);
2672 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2676 /* normal cleanup code */
2679 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2681 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2682 if (code || rcode) {
2685 "Could not end transaction on the source volume %lu\n",
2686 (unsigned long)afromvol);
2688 error = (code ? code : rcode);
2694 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2696 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2697 if (code || rcode) {
2700 "Could not end transaction on the source's clone volume %lu\n",
2701 (unsigned long)cloneVol);
2703 error = (code ? code : rcode);
2709 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2711 code = AFSVolEndTrans(toconn, totid, &rcode);
2715 "Could not end transaction on destination volume %lu\n",
2716 (unsigned long)newVol);
2718 error = (code ? code : rcode);
2723 rx_DestroyConnection(fromconn);
2725 rx_DestroyConnection(toconn);
2726 PrintError("", error);
2729 /* come here only when the sky falls */
2734 "vos copy: operation interrupted, cleanup in progress...\n");
2735 fprintf(STDOUT, "clear transaction contexts\n");
2740 VPRINT("Recovery: Ending transaction on clone volume ...");
2741 AFSVolEndTrans(fromconn, clonetid, &rcode);
2745 VPRINT("Recovery: Ending transaction on destination volume ...");
2746 AFSVolEndTrans(toconn, totid, &rcode);
2749 if (fromtid) { /* put it on-line */
2750 VPRINT("Recovery: Ending transaction on source volume ...");
2751 AFSVolEndTrans(fromconn, fromtid, &rcode);
2755 VPRINT("Recovery: Accessing VLDB.\n");
2756 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2758 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2762 MapHostToNetwork(&entry);
2764 /* common cleanup - delete local clone */
2766 code = DoVolDelete(fromconn, cloneVol, afrompart,
2767 "clone", 0, NULL, "Recovery:");
2768 if (code == VNOVOL) {
2769 EPRINT1(code, "Recovery: Failed to start transaction on %u\n", cloneVol);
2773 done: /* routine cleanup */
2775 rx_DestroyConnection(fromconn);
2777 rx_DestroyConnection(toconn);
2780 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2788 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2789 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2791 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2792 atovolname, atoserver, atopart, 0, 0);
2797 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2798 * if one already exists, update it
2802 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2804 struct rx_connection *aconn = (struct rx_connection *)0;
2805 afs_int32 ttid = 0, btid = 0;
2806 afs_uint32 backupID;
2807 afs_int32 code = 0, rcode = 0;
2808 struct nvldbentry entry, storeEntry;
2809 afs_int32 error = 0;
2810 int vldblocked = 0, vldbmod = 0;
2812 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2814 /* the calls to VLDB will succeed only if avolid is a RW volume,
2815 * since we are following the RW hash chain for searching */
2816 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2819 "Could not fetch the entry for the volume %lu from the VLDB \n",
2820 (unsigned long)avolid);
2824 MapHostToNetwork(&entry);
2826 /* These operations require the VLDB be locked since it means the VLDB
2827 * will change or the vldb is already locked.
2829 if (!(entry.flags & VLF_BACKEXISTS) || /* backup volume doesnt exist */
2830 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2831 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2833 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2836 "Could not lock the VLDB entry for the volume %lu\n",
2837 (unsigned long)avolid);
2843 /* Reread the vldb entry */
2844 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2847 "Could not fetch the entry for the volume %lu from the VLDB \n",
2848 (unsigned long)avolid);
2852 MapHostToNetwork(&entry);
2855 if (!ISNAMEVALID(entry.name)) {
2856 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2858 error = VOLSERBADNAME;
2862 backupID = entry.volumeId[BACKVOL];
2863 if (backupID == INVALID_BID) {
2864 /* Get a backup volume id from the VLDB and update the vldb
2867 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2870 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2871 (unsigned long)avolid);
2875 entry.volumeId[BACKVOL] = backupID;
2879 code = DoVolClone(aconn, avolid, apart, backupVolume, backupID, "backup",
2880 entry.name, NULL, ".backup", NULL, NULL);
2886 /* Mark vldb as backup exists */
2887 if (!(entry.flags & VLF_BACKEXISTS)) {
2888 entry.flags |= VLF_BACKEXISTS;
2892 /* Now go back to the backup volume and bring it on line */
2893 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2896 "Failed to start a transaction on the backup volume %lu\n",
2897 (unsigned long)backupID);
2902 code = AFSVolSetFlags(aconn, btid, 0);
2904 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2905 (unsigned long)backupID);
2910 code = AFSVolEndTrans(aconn, btid, &rcode);
2912 if (code || rcode) {
2914 "Failed to end the transaction on the backup volume %lu\n",
2915 (unsigned long)backupID);
2916 error = (code ? code : rcode);
2922 /* Will update the vldb below */
2926 code = AFSVolEndTrans(aconn, ttid, &rcode);
2927 if (code || rcode) {
2928 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2929 (unsigned long)avolid);
2931 error = (code ? code : rcode);
2936 code = AFSVolEndTrans(aconn, btid, &rcode);
2937 if (code || rcode) {
2939 "Could not end transaction the backup volume %lu\n",
2940 (unsigned long)backupID);
2942 error = (code ? code : rcode);
2946 /* Now update the vldb - if modified */
2949 MapNetworkToHost(&entry, &storeEntry);
2951 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2952 (LOCKREL_OPCODE | LOCKREL_AFSID |
2953 LOCKREL_TIMESTAMP));
2956 "Could not update the VLDB entry for the volume %lu \n",
2957 (unsigned long)avolid);
2963 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2964 (LOCKREL_OPCODE | LOCKREL_AFSID |
2965 LOCKREL_TIMESTAMP));
2968 "Could not unlock the VLDB entry for the volume %lu \n",
2969 (unsigned long)avolid);
2977 rx_DestroyConnection(aconn);
2979 PrintError("", error);
2983 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2984 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2985 * The new volume is named by <aname>, or by appending ".clone" to
2986 * the existing name if <aname> is NULL. The following flags are
2989 * RV_RDONLY - target volume is RO
2990 * RV_OFFLINE - leave target volume offline
2994 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2995 afs_uint32 acloneid, char *aname, int flags)
2997 struct rx_connection *aconn = (struct rx_connection *)0;
2998 afs_int32 ttid = 0, btid = 0;
2999 afs_int32 code = 0, rcode = 0;
3000 char vname[VOLSER_MAXVOLNAME + 1];
3001 afs_int32 error = 0;
3002 volEntries volumeInfo;
3005 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
3008 volumeInfo.volEntries_val = (volintInfo *) 0;
3009 volumeInfo.volEntries_len = 0;
3010 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
3012 fprintf(stderr, "Could not get info for volume %lu\n",
3013 (unsigned long)avolid);
3017 strncpy(vname, volumeInfo.volEntries_val[0].name,
3018 VOLSER_OLDMAXVOLNAME - 7);
3019 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
3020 strcat(vname, ".clone");
3022 if (volumeInfo.volEntries_val)
3023 free(volumeInfo.volEntries_val);
3027 /* Get a clone id */
3028 VPRINT1("Allocating new volume id for clone of volume %u ...",
3030 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
3032 "Could not get an ID for the clone of volume %u from the VLDB\n",
3037 if (flags & RV_RWONLY)
3038 type = readwriteVolume;
3039 else if (flags & RV_RDONLY)
3040 type = readonlyVolume;
3042 type = backupVolume;
3044 code = DoVolClone(aconn, avolid, apart, type, acloneid, "clone",
3045 NULL, aname, NULL, NULL, NULL);
3051 /* Now go back to the backup volume and bring it on line */
3052 if (!(flags & RV_OFFLINE)) {
3053 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3056 "Failed to start a transaction on the clone volume %lu\n",
3057 (unsigned long)acloneid);
3062 code = AFSVolSetFlags(aconn, btid, 0);
3064 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3065 (unsigned long)acloneid);
3070 code = AFSVolEndTrans(aconn, btid, &rcode);
3072 if (code || rcode) {
3074 "Failed to end the transaction on the clone volume %lu\n",
3075 (unsigned long)acloneid);
3076 error = (code ? code : rcode);
3085 code = AFSVolEndTrans(aconn, ttid, &rcode);
3086 if (code || rcode) {
3087 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3088 (unsigned long)avolid);
3090 error = (code ? code : rcode);
3095 code = AFSVolEndTrans(aconn, btid, &rcode);
3096 if (code || rcode) {
3098 "Could not end transaction on the clone volume %lu\n",
3099 (unsigned long)acloneid);
3101 error = (code ? code : rcode);
3106 rx_DestroyConnection(aconn);
3108 PrintError("", error);
3112 #define ONERROR(ec, ep, es) do { \
3114 fprintf(STDERR, (es), (ep)); \
3119 #define ONERROR0(ec, es) do { \
3121 fprintf(STDERR, (es)); \
3126 #define ERROREXIT(ec) do { \
3131 /* Get a "transaction" on this replica. Create the volume
3132 * if necessary. Return the time from which a dump should
3133 * be made (0 if it's a new volume)
3136 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3137 struct rx_connection **connPtr, afs_int32 * transPtr,
3138 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3139 afs_int32 *origflags, afs_uint32 tmpVolId)
3142 struct volser_status tstatus;
3147 *connPtr = (struct rx_connection *)0;
3152 /* get connection to the replication site */
3153 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3155 goto fail; /* server is down */
3157 volid = vldbEntryPtr->volumeId[ROVOL];
3161 AFSVolTransCreate_retry(*connPtr, volid,
3162 vldbEntryPtr->serverPartition[index], ITOffline,
3165 if (!code && (origflags[index] & VLSF_DONTUSE)) {
3166 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3167 * site. Don't trust any data on it, since it is possible we
3168 * have encountered some temporary volume from some other
3169 * incomplete volume operation. It is difficult to detect if
3170 * that has happened vs if this is a legit volume, so just
3171 * delete it to be safe. */
3173 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3174 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3175 serverNumber[index], hoststr) :
3176 hostutil_GetNameByINet(vldbEntryPtr->
3177 serverNumber[index]));
3179 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3181 PrintError("Failed to delete RO_DONTUSE site: ", code);
3185 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3191 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3198 /* emulate what TransCreate would have returned, so we try to
3199 * create the volume below */
3204 /* If the volume does not exist, create it */
3205 if (!volid || code) {
3206 char volname[VL_MAXNAMELEN];
3209 if (volid && (code != VNOVOL)) {
3210 PrintError("Failed to start a transaction on the RO volume.\n",
3215 strlcpy(volname, vldbEntryPtr->name, sizeof(volname));
3217 if (strlcat(volname,
3218 tmpVolId?".roclone":".readonly",
3219 sizeof(volname)) >= sizeof(volname)) {
3221 PrintError("Volume name is too long\n", code);
3227 "Creating new volume %lu on replication site %s: ",
3228 tmpVolId?(unsigned long)tmpVolId:(unsigned long)volid,
3229 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3230 serverNumber[index], hoststr) :
3231 hostutil_GetNameByINet(vldbEntryPtr->
3232 serverNumber[index]));
3237 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3239 vldbEntryPtr->volumeId[RWVOL],
3240 tmpVolId?&tmpVolId:&volid,
3243 PrintError("Failed to create the ro volume: ", code);
3246 vldbEntryPtr->volumeId[ROVOL] = volid;
3250 /* The following is a bit redundant, since create sets these flags by default */
3252 AFSVolSetFlags(*connPtr, *transPtr,
3253 VTDeleteOnSalvage | VTOutOfService);
3255 PrintError("Failed to set flags on the ro volume: ", code);
3260 /* Otherwise, the transaction did succeed, so get the creation date of the
3261 * latest RO volume on the replication site
3264 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3265 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3266 serverNumber[index], hoststr) :
3267 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3269 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3271 PrintError("Failed to get status of volume on destination: ",
3276 code = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3281 code = DoVolClone(*connPtr, volid,
3282 vldbEntryPtr->serverPartition[index],
3283 readonlyVolume, tmpVolId, "temporary",
3284 vldbEntryPtr->name, NULL, ".roclone", NULL,
3289 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3290 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3297 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3301 if (tcode && tcode != ENOENT)
3302 PrintError("Could not end transaction on a ro volume: ", tcode);
3309 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3310 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3311 void *cookie, manyResults * results)
3315 for (i = 0; i < tr->manyDests_len; i++) {
3316 results->manyResults_val[i] =
3317 AFSVolForward(fromconn, fromtid, fromdate,
3318 &(tr->manyDests_val[i].server),
3319 tr->manyDests_val[i].trans, cookie);
3325 * Check if a trans has timed out, and recreate it if necessary.
3327 * @param[in] aconn RX connection to the relevant server
3328 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3329 * contains the new trans ID on success
3330 * @param[in] apart Partition for the transaction
3331 * @param[in] astat The status of the original transaction
3333 * @return operation status
3334 * @retval 0 existing transaction is still valid, or we managed to recreate
3335 * the trans successfully
3336 * @retval nonzero Fatal error; bail out
3339 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3340 struct volser_status *astat)
3342 struct volser_status new_status;
3345 memset(&new_status, 0, sizeof(new_status));
3346 code = AFSVolGetStatus(aconn, *atid, &new_status);
3348 if (code == ENOENT) {
3350 VPRINT1("Old transaction on cloned volume %lu timed out, "
3351 "restarting transaction\n", (long unsigned) astat->volID);
3352 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3355 PrintError("Failed to recreate cloned RO volume transaction\n",
3360 memset(&new_status, 0, sizeof(new_status));
3361 code = AFSVolGetStatus(aconn, *atid, &new_status);
3363 PrintError("Failed to get status on recreated transaction\n",
3368 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3369 PrintError("Recreated transaction on cloned RO volume, but "
3370 "the volume has changed!\n", 0);
3374 PrintError("Unable to get status of current cloned RO transaction\n",
3379 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3381 PrintError("Internal error: current GetStatus does not match "
3382 "original GetStatus?\n", 0);
3391 PutTrans(afs_int32 *vldbindex, struct replica *replicas,
3392 struct rx_connection **toconns, struct release *times,
3395 afs_int32 s, code = 0, rcode = 0;
3396 /* End the transactions and destroy the connections */
3397 for (s = 0; s < volcount; s++) {
3398 if (replicas[s].trans) {
3399 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3401 replicas[s].trans = 0;
3405 if ((s == 0) || (code != ENOENT)) {
3406 PrintError("Could not end transaction on a ro volume: ",
3410 ("Transaction timed out on a ro volume. Will retry.\n",
3412 if (times[s].vldbEntryIndex < *vldbindex)
3413 *vldbindex = times[s].vldbEntryIndex;
3418 rx_DestroyConnection(toconns[s]);
3424 * Release a volume to read-only sites
3426 * Release volume <afromvol> on <afromserver> <afrompart> to all
3427 * its RO sites (full release). Unless the previous release was
3428 * incomplete: in which case we bring the remaining incomplete
3429 * volumes up to date with the volumes that were released
3432 * Will create a clone from the RW, then dump the clone out to
3433 * the remaining replicas. If there is more than 1 RO sites,
3434 * ensure that the VLDB says at least one RO is available all
3435 * the time: Influences when we write back the VLDB entry.
3437 * @param[in] afromvol volume to be released
3438 * @param[in] afromserver server containing afromvol
3439 * @param[in] afrompart partition containing afromvol
3440 * @param[in] flags bitmap of options
3441 * REL_COMPLETE - force a complete release
3442 * REL_FULLDUMPS - force full dumps
3445 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3446 afs_int32 afrompart, int flags)
3450 afs_int32 vcode, rcode, tcode;
3451 afs_uint32 cloneVolId = 0, roVolId;
3452 struct replica *replicas = 0;
3453 struct nvldbentry entry, storeEntry;
3454 int i, volcount = 0, m, vldbindex;
3456 struct restoreCookie cookie;
3457 struct rx_connection **toconns = 0;
3458 struct release *times = 0;
3460 struct rx_connection *fromconn = (struct rx_connection *)0;
3461 afs_int32 error = 0;
3463 afs_int32 clonetid = 0, onlinetid;
3464 afs_int32 fromtid = 0;
3465 afs_uint32 fromdate = 0;
3466 afs_uint32 thisdate;
3470 manyResults results;
3471 int rwindex, roindex, roclone, roexists;
3472 afs_uint32 rwcrdate = 0, rwupdate = 0;
3473 afs_uint32 clcrdate;
3477 } remembertime[NMAXNSERVERS];
3478 int releasecount = 0;
3479 struct volser_status volstatus;
3481 afs_int32 origflags[NMAXNSERVERS];
3482 struct volser_status orig_status;
3483 int notreleased = 0;
3484 int tried_justnewsites = 0;
3485 int justnewsites = 0; /* are we just trying to release to new RO sites? */
3486 int sites = 0; /* number of ro sites */
3487 int new_sites = 0; /* number of ro sites markes as new */
3490 CR_RECOVER = 0x0000, /**< not complete: a recovery from a previous failed release */
3491 CR_FORCED = 0x0001, /**< complete: forced by caller */
3492 CR_LAST_OK = 0x0002, /**< complete: no sites have been marked as new release */
3493 CR_ALL_NEW = 0x0004, /**< complete: all sites have been marked as new release */
3494 CR_NEW_RW = 0x0008, /**< complete: read-write has changed */
3495 CR_RO_MISSING = 0x0010, /**< complete: ro clone is missing */
3496 } complete_release_t;
3498 complete_release_t complete_release = CR_RECOVER;
3500 memset(remembertime, 0, sizeof(remembertime));
3501 memset(&results, 0, sizeof(results));
3502 memset(origflags, 0, sizeof(origflags));
3504 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3505 if (vcode != VL_RERELEASE)
3506 ONERROR(vcode, afromvol,
3507 "Could not lock the VLDB entry for the volume %u.\n");
3510 /* Get the vldb entry in readable format */
3511 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3512 ONERROR(vcode, afromvol,
3513 "Could not fetch the entry for the volume %u from the VLDB.\n");
3514 MapHostToNetwork(&entry);
3517 EnumerateEntry(&entry);
3519 if (!ISNAMEVALID(entry.name))
3520 ONERROR(VOLSERBADOP, entry.name,
3521 "Volume name %s is too long, rename before releasing.\n");
3522 if (entry.volumeId[RWVOL] != afromvol)
3523 ONERROR(VOLSERBADOP, afromvol,
3524 "The volume %u being released is not a read-write volume.\n");
3525 if (entry.nServers <= 1)
3526 ONERROR(VOLSERBADOP, afromvol,
3527 "Volume %u has no replicas - release operation is meaningless!\n");
3528 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3529 ONERROR(VOLSERBADOP, entry.name,
3530 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3532 /* roclone is true if one of the RO volumes is on the same
3533 * partition as the RW volume. In this case, we make the RO volume
3534 * on the same partition a clone instead of a complete copy.
3537 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3538 roclone = ((roindex == -1) ? 0 : 1);
3539 rwindex = Lp_GetRwIndex(&entry);
3541 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3543 /* Make sure we have a RO volume id to work with */
3544 if (entry.volumeId[ROVOL] == INVALID_BID) {
3545 /* need to get a new RO volume id */
3546 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3547 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3549 entry.volumeId[ROVOL] = roVolId;
3550 MapNetworkToHost(&entry, &storeEntry);
3551 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3552 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3556 * Determine if this is to be a complete release or a recovery of a
3557 * previous unfinished release. The previous release is considered to be
3558 * unfinished when the clone was successfully distributed to at least one
3559 * (but not all) of the read-only sites, as indicated by the NEW_REPSITE
3562 * The caller can override the vldb flags check using the -force
3563 * or -force-reclone flag, to force this to be a complete release.
3565 for (i = 0; i < entry.nServers; i++) {
3566 if (entry.serverFlags[i] & VLSF_ROVOL) {
3568 if (entry.serverFlags[i] & VLSF_NEWREPSITE)
3570 if (entry.serverFlags[i] & VLSF_DONTUSE)
3573 origflags[i] = entry.serverFlags[i];
3576 if (flags & REL_COMPLETE) {
3577 complete_release |= CR_FORCED;
3580 if (new_sites == 0) {
3581 complete_release |= CR_LAST_OK;
3582 } else if (new_sites == sites) {
3583 complete_release |= CR_ALL_NEW;
3586 if ((complete_release & (CR_LAST_OK | CR_ALL_NEW))
3587 && !(complete_release & CR_FORCED)) {
3588 if (notreleased && notreleased != sites) {
3589 /* we have some new unreleased sites. try to just release to those,
3590 * if the RW has not changed. The caller can override with -force
3591 * or with -force-reclone. */
3596 /* Determine which volume id to use and see if it exists */
3597 cloneVolId = (complete_release || entry.cloneId == 0)
3598 ? entry.volumeId[ROVOL] : entry.cloneId;
3600 code = VolumeExists(afromserver, afrompart, cloneVolId);
3601 roexists = ((code == ENODEV) ? 0 : 1);
3603 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3605 ONERROR(-1, afromserver,
3606 "Cannot establish connection with server 0x%x\n");
3608 if (!complete_release) {
3610 complete_release |= CR_RO_MISSING; /* Do a complete release if RO clone does not exist */
3612 /* Begin transaction on RW and mark it busy while we query it */
3613 code = AFSVolTransCreate_retry(
3614 fromconn, afromvol, afrompart, ITBusy, &fromtid
3616 ONERROR(code, afromvol,
3617 "Failed to start transaction on RW volume %u\n");
3619 /* Query the creation date for the RW */
3620 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3621 ONERROR(code, afromvol,
3622 "Failed to get the status of RW volume %u\n");
3623 rwcrdate = volstatus.creationDate;
3625 /* End transaction on RW */
3626 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3628 ONERROR((code ? code : rcode), afromvol,
3629 "Failed to end transaction on RW volume %u\n");
3631 /* Begin transaction on clone and mark it busy while we query it */
3632 code = AFSVolTransCreate_retry(
3633 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3635 ONERROR(code, cloneVolId,
3636 "Failed to start transaction on RW clone %u\n");
3638 /* Query the creation date for the clone */
3639 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3640 ONERROR(code, cloneVolId,
3641 "Failed to get the status of RW clone %u\n");
3642 clcrdate = volstatus.creationDate;
3644 /* End transaction on clone */
3645 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3647 ONERROR((code ? code : rcode), cloneVolId,
3648 "Failed to end transaction on RW clone %u\n");
3650 if (rwcrdate > clcrdate)
3651 complete_release |= CR_NEW_RW; /* Do a complete release if RO clone older than RW */
3655 if (!complete_release || (complete_release & CR_NEW_RW)) {
3656 /* in case the RW has changed, and just to be safe */
3661 if (!complete_release) {
3663 "This is a recovery of previously failed release\n");
3665 fprintf(STDOUT, "This is a complete release of volume %u", afromvol);
3666 /* Give the reasons for a complete release, except if only CR_LAST_OK. */
3667 if (complete_release != CR_LAST_OK) {
3669 if (complete_release & CR_FORCED) {
3670 fprintf(STDOUT, "%sforced", sep);
3673 if (complete_release & CR_LAST_OK) {
3674 fprintf(STDOUT, "%slast ok", sep);
3677 if (complete_release & CR_ALL_NEW) {
3678 fprintf(STDOUT, "%sall sites are new", sep);
3681 if (complete_release & CR_NEW_RW) {
3682 fprintf(STDOUT, "%srw %u changed", sep, afromvol);
3685 if (complete_release & CR_RO_MISSING) {
3686 fprintf(STDOUT, "%sro clone missing", sep);
3688 fprintf(STDOUT, ")");
3690 fprintf(STDOUT, "\n");
3692 tried_justnewsites = 1;
3693 fprintf(STDOUT, "There are new RO sites; we will try to "
3694 "only release to new sites\n");
3699 if (complete_release) {
3700 afs_int32 oldest = 0;
3701 /* If the RO clone exists, then if the clone is a temporary
3702 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3703 * (it was recently added), then also delete it. We do not
3704 * want to "reclone" a temporary RO clone.
3707 /* clean up any previous tmp clone before starting if staying up */
3709 && (!roclone || (entry.serverFlags[roindex] & VLSF_DONTUSE))) {
3710 code = DoVolDelete(fromconn,
3712 afrompart, "the", 0, NULL, NULL);
3713 if (code && (code != VNOVOL))
3719 VPRINT("Querying old RO sites for update times...");
3720 for (vldbindex = 0; vldbindex < entry.nServers; vldbindex++) {
3721 volEntries volumeInfo;
3722 struct rx_connection *conn;
3725 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL)) {
3728 if ((entry.serverFlags[vldbindex] & VLSF_DONTUSE)) {
3731 conn = UV_Bind(entry.serverNumber[vldbindex], AFSCONF_VOLUMEPORT);
3733 fprintf(STDERR, "Cannot establish connection to server %s\n",
3734 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3738 volumeInfo.volEntries_val = NULL;
3739 volumeInfo.volEntries_len = 0;
3740 code = AFSVolListOneVolume(conn, entry.serverPartition[vldbindex],
3741 entry.volumeId[ROVOL],
3744 fprintf(STDERR, "Could not fetch information about RO vol %lu from server %s\n",
3745 (unsigned long)entry.volumeId[ROVOL],
3746 hostutil_GetNameByINet(entry.serverNumber[vldbindex]));
3747 PrintError("", code);
3749 rx_DestroyConnection(conn);
3753 crdate = CLOCKADJ(volumeInfo.volEntries_val[0].creationDate);
3755 if (oldest == 0 || crdate < oldest) {
3759 rx_DestroyConnection(conn);
3760 free(volumeInfo.volEntries_val);
3761 volumeInfo.volEntries_val = NULL;
3762 volumeInfo.volEntries_len = 0;
3767 volEntries volumeInfo;
3768 volumeInfo.volEntries_val = NULL;
3769 volumeInfo.volEntries_len = 0;
3770 code = AFSVolListOneVolume(fromconn, afrompart, afromvol,
3773 fprintf(STDERR, "Could not fetch information about RW vol %lu from server %s\n",
3774 (unsigned long)afromvol,
3775 hostutil_GetNameByINet(afromserver));
3776 PrintError("", code);
3779 rwupdate = volumeInfo.volEntries_val[0].updateDate;
3781 free(volumeInfo.volEntries_val);
3782 volumeInfo.volEntries_val = NULL;
3783 volumeInfo.volEntries_len = 0;
3786 if (justnewsites && oldest <= rwupdate) {
3787 /* RW has changed */
3791 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3792 * write this entry out to the vlserver until after the first
3793 * RO volume is released (temp RO clones don't count).
3795 * If 'justnewsites' is set, we're only updating sites that have
3796 * RO_DONTUSE set, so set NEW_REPSITE for all of the others.
3798 for (i = 0; i < entry.nServers; i++) {
3800 if ((entry.serverFlags[i] & VLSF_DONTUSE)) {
3801 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3803 entry.serverFlags[i] |= VLSF_NEWREPSITE;
3806 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3807 entry.serverFlags[i] |= VLSF_DONTUSE;
3810 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3811 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3814 if (justnewsites && roexists) {
3815 /* if 'justnewsites' and 'roexists' are set, we don't need to do
3816 * anything with the RO clone, so skip the reclone */
3819 } else if (complete_release) {
3822 strcpy(vname, entry.name);
3823 strcat(vname, ".readonly");
3825 strcpy(vname, "readonly-clone-temp");
3828 code = DoVolClone(fromconn, afromvol, afrompart, readonlyVolume,
3829 cloneVolId, roclone?"permanent RO":
3830 "temporary RO", NULL, vname, NULL, &volstatus, NULL);
3836 if (justnewsites && rwupdate != volstatus.updateDate) {
3838 /* reset the serverFlags as if 'justnewsites' had never been set */
3839 for (i = 0; i < entry.nServers; i++) {
3840 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
3841 entry.serverFlags[i] |= VLSF_DONTUSE;
3843 entry.serverFlags[rwindex] |= VLSF_NEWREPSITE;
3844 entry.serverFlags[rwindex] &= ~VLSF_DONTUSE;
3847 rwcrdate = volstatus.creationDate;
3849 /* Remember clone volume ID in case we fail or are interrupted */
3850 entry.cloneId = cloneVolId;
3853 /* Bring the RO clone online - though not if it's a temporary clone */
3854 VPRINT1("Starting transaction on RO clone volume %u...",
3857 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3859 ONERROR(code, cloneVolId,
3860 "Failed to start transaction on volume %u\n");
3863 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3864 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3867 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3868 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3869 ONERROR((code ? code : rcode), cloneVolId,
3870 "Failed to end transaction on RO clone %u\n");
3873 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3875 /* Sleep so that a client searching for an online volume won't
3876 * find the clone offline and then the next RO offline while the
3877 * release brings the clone online and the next RO offline (race).
3878 * There is a fix in the 3.4 client that does not need this sleep
3879 * anymore, but we don't know what clients we have.
3881 if (entry.nServers > 2 && !justnewsites)
3884 /* Mark the RO clone in the VLDB as a good site (already released) */
3885 entry.serverFlags[roindex] |= VLSF_NEWREPSITE;
3886 entry.serverFlags[roindex] &= ~VLSF_DONTUSE;
3887 entry.flags |= VLF_ROEXISTS;
3891 /* Write out the VLDB entry only if the clone is not a temporary
3892 * clone. If we did this to a temporary clone then we would end
3893 * up marking all the ROs as "old release" making the ROs
3894 * temporarily unavailable.
3896 MapNetworkToHost(&entry, &storeEntry);
3897 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3898 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3899 ONERROR(vcode, entry.name,
3900 "Could not update vldb entry for %s.\n");
3906 VPRINT("RW vol has not changed; only releasing to new RO sites\n");
3907 /* act like this is a completion of a previous release */
3908 complete_release = CR_RECOVER;
3909 } else if (tried_justnewsites) {
3910 VPRINT("RW vol has changed; releasing to all sites\n");
3913 /* Now we will release from the clone to the remaining RO replicas.
3914 * The first 2 ROs (counting the non-temporary RO clone) are released
3915 * individually: releasecount. This is to reduce the race condition
3916 * of clients trying to find an on-line RO volume. The remaining ROs
3917 * are released in parallel but no more than half the number of ROs
3918 * (rounded up) at a time: nservers.
3921 strcpy(vname, entry.name);
3922 strcat(vname, ".readonly");
3923 memset(&cookie, 0, sizeof(cookie));
3924 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3925 cookie.type = ROVOL;
3926 cookie.parent = entry.volumeId[RWVOL];
3929 /* how many to do at once, excluding clone */
3931 nservers = entry.nServers; /* can do all, none offline */
3933 nservers = entry.nServers / 2;
3934 replicas = calloc(nservers + 1, sizeof(struct replica));
3935 times = calloc(nservers + 1, sizeof(struct release));
3936 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
3937 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
3938 if (!replicas || !times || !results.manyResults_val || !toconns)
3940 "Failed to create transaction on the release clone\n");
3942 /* Create a transaction on the cloned volume */
3943 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3945 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3947 memset(&orig_status, 0, sizeof(orig_status));
3948 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3950 if (!complete_release && code)
3951 ONERROR(VOLSERNOVOL, afromvol,
3952 "Old clone is inaccessible. Try vos release -f %u.\n");
3953 ONERROR0(code, "Failed to create transaction on the release clone\n");
3956 /* For each index in the VLDB */
3957 for (vldbindex = 0; vldbindex < entry.nServers;) {
3958 /* Get a transaction on the replicas. Pick replicas which have an old release. */
3960 ((volcount < nservers) && (vldbindex < entry.nServers));
3962 if (!justnewsites) {
3963 /* The first two RO volumes will be released individually.
3964 * The rest are then released in parallel. This is a hack
3965 * for clients not recognizing right away when a RO volume
3966 * comes back on-line.
3968 if ((volcount == 1) && (releasecount < 2))
3972 if (vldbindex == roindex)
3973 continue; /* the clone */
3974 if ((entry.serverFlags[vldbindex] & VLSF_NEWREPSITE)
3975 && !(entry.serverFlags[vldbindex] & VLSF_DONTUSE))
3977 if (!(entry.serverFlags[vldbindex] & VLSF_ROVOL))
3978 continue; /* not a RO vol */
3981 /* Get a Transaction on this replica. Get a new connection if
3982 * necessary. Create the volume if necessary. Return the
3983 * time from which the dump should be made (0 if it's a new
3984 * volume). Each volume might have a different time.
3986 replicas[volcount].server.destHost =
3987 ntohl(entry.serverNumber[vldbindex]);
3988 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3989 replicas[volcount].server.destSSID = 1;
3990 times[volcount].vldbEntryIndex = vldbindex;
3993 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3994 &(replicas[volcount].trans),
3995 &(times[volcount].crtime),
3996 &(times[volcount].uptime),
4001 /* Thisdate is the date from which we want to pick up all changes */
4002 if (flags & REL_FULLDUMPS) {
4003 /* Do a full dump when forced by the caller. */
4004 VPRINT("This will be a full dump: forced\n");
4006 } else if (!complete_release) {
4007 /* If this release is a recovery of a failed release, we can't be
4008 * sure the creation date is good, so do a full dump.
4010 VPRINT("This will be a full dump: previous release failed\n");
4012 } else if (times[volcount].crtime == 0) {
4013 /* A full dump is needed for a new read-only volume. */
4015 ("This will be a full dump: read-only volume needs to be created\n");
4017 } else if ((rwcrdate > times[volcount].crtime)) {
4018 /* If the RW volume was replaced (its creation date is newer than
4019 * the last release), then we can't be sure what has changed (so
4020 * we do a full dump).
4023 ("This will be a full dump: read-write volume was replaced\n");
4025 } else if (remembertime[vldbindex].validtime) {
4026 /* Trans was prev ended. Use the time from the prev trans
4027 * because, prev trans may have created the volume. In which
4028 * case time[volcount].time would be now instead of 0.
4031 (remembertime[vldbindex].uptime < times[volcount].uptime)
4032 ? remembertime[vldbindex].uptime
4033 : times[volcount].uptime;
4035 thisdate = times[volcount].uptime;
4037 remembertime[vldbindex].validtime = 1;
4038 remembertime[vldbindex].uptime = thisdate;
4040 if (volcount == 0) {
4041 fromdate = thisdate;
4043 /* Include this volume if it is within 15 minutes of the earliest */
4045 thisdate) ? (fromdate - thisdate) : (thisdate -
4047 AFSVolEndTrans(toconns[volcount],
4048 replicas[volcount].trans, &rcode);
4049 replicas[volcount].trans = 0;
4052 if (thisdate < fromdate)
4053 fromdate = thisdate;
4060 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
4067 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
4068 (unsigned long)cloneVolId,
4069 entry.volumeId[ROVOL],
4070 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
4071 vldbEntryIndex], hoststr) :
4072 hostutil_GetNameByINet(entry.
4073 serverNumber[times[0].
4076 for (s = 1; s < volcount; s++) {
4077 fprintf(STDOUT, " and %s",
4078 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
4079 vldbEntryIndex], hoststr) :
4080 hostutil_GetNameByINet(entry.
4081 serverNumber[times[s].
4086 fprintf(STDOUT, " (entire volume)");
4089 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
4091 fprintf(STDOUT, ".\n");
4095 /* Release the ones we have collected */
4096 tr.manyDests_val = &(replicas[0]);
4097 tr.manyDests_len = results.manyResults_len = volcount;
4099 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
4100 0 /*spare */ , &cookie, &results);
4101 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
4103 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
4104 0 /*spare */ , &cookie, &results);
4109 PrintError("Release failed: ", code);
4111 for (m = 0; m < volcount; m++) {
4112 if (results.manyResults_val[m]) {
4113 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
4114 /* we retry timed out transaction. When it is
4115 * not the first volume and the transaction wasn't found
4116 * (assume it timed out and was garbage collected by volser).
4119 ("Failed to dump volume from clone to a ro site: ",
4120 results.manyResults_val[m]);
4126 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
4127 ROVOL, entry.volumeId[RWVOL], 0, 0);
4129 if ((m == 0) || (code != ENOENT)) {
4130 PrintError("Failed to set correct names and ids: ",
4136 /* have to clear dest. flags to ensure new vol goes online:
4137 * because the restore (forwarded) operation copied
4138 * the V_inService(=0) flag over to the destination.
4140 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4142 if ((m == 0) || (code != ENOENT)) {
4143 PrintError("Failed to set flags on ro volume: ",
4149 entry.serverFlags[times[m].vldbEntryIndex] |= VLSF_NEWREPSITE;
4150 entry.serverFlags[times[m].vldbEntryIndex] &= ~VLSF_DONTUSE;
4151 entry.flags |= VLF_ROEXISTS;
4156 PutTrans(&vldbindex, replicas, toconns, times, volcount);
4157 MapNetworkToHost(&entry, &storeEntry);
4158 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4159 ONERROR(vcode, afromvol,
4160 " Could not update VLDB entry for volume %u\n");
4161 } /* for each index in the vldb */
4163 /* End the transaction on the cloned volume */
4164 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4169 PrintError("Failed to end transaction on rw volume: ", code);
4171 /* Figure out if any volume were not released and say so */
4172 for (failure = 0, i = 0; i < entry.nServers; i++) {
4173 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE))
4179 "The volume %lu could not be released to the following %d sites:\n",
4180 (unsigned long)afromvol, failure);
4181 for (i = 0; i < entry.nServers; i++) {
4182 if (!(entry.serverFlags[i] & VLSF_NEWREPSITE)) {
4183 MapPartIdIntoName(entry.serverPartition[i], pname);
4184 fprintf(STDERR, "\t%35s %s\n",
4185 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4186 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4189 MapNetworkToHost(&entry, &storeEntry);
4191 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4193 ONERROR(vcode, afromvol,
4194 " Could not update VLDB entry for volume %u\n");
4196 ERROREXIT(VOLSERBADRELEASE);
4200 /* All the ROs were release successfully. Remove the temporary clone */
4203 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4204 (unsigned long)cloneVolId);
4207 code = DoVolDelete(fromconn, cloneVolId, afrompart, NULL, 0, NULL,
4209 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4213 for (i = 0; i < entry.nServers; i++)
4214 entry.serverFlags[i] &= ~VLSF_NEWREPSITE;
4216 /* Update the VLDB */
4217 VPRINT("updating VLDB ...");
4219 MapNetworkToHost(&entry, &storeEntry);
4221 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4222 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4223 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4228 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4232 "Failed to end cloning transaction on the RW volume %lu\n",
4233 (unsigned long)afromvol);
4239 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4243 "Failed to end transaction on the release clone %lu\n",
4244 (unsigned long)cloneVolId);
4249 for (i = 0; i < nservers; i++) {
4250 if (replicas && replicas[i].trans) {
4251 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4252 replicas[i].trans = 0;
4255 "Failed to end transaction on ro volume %u at server %s\n",
4256 entry.volumeId[ROVOL],
4257 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4258 destHost), hoststr) :
4259 hostutil_GetNameByINet(htonl
4260 (replicas[i].server.destHost)));
4265 if (toconns && toconns[i]) {
4266 rx_DestroyConnection(toconns[i]);
4272 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4273 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4276 "Could not release lock on the VLDB entry for volume %lu\n",
4277 (unsigned long)afromvol);
4283 PrintError("", error);
4286 rx_DestroyConnection(fromconn);
4287 if (results.manyResults_val)
4288 free(results.manyResults_val);
4300 dump_sig_handler(int x)
4302 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4306 /* Dump the volume <afromvol> on <afromserver> and
4307 * <afrompart> to <afilename> starting from <fromdate>.
4308 * DumpFunction does the real work behind the scenes after
4309 * extracting parameters from the rock
4312 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4314 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4317 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4318 * be changing during the dump */
4319 struct rx_call * volatile fromcall = NULL;
4320 struct rx_connection * volatile fromconn = NULL;
4321 afs_int32 volatile fromtid = 0;
4323 afs_int32 rcode = 0;
4324 afs_int32 code, error = 0;
4326 time_t tmv = fromdate;
4330 #ifndef AFS_NT40_ENV
4331 (void)signal(SIGPIPE, dump_sig_handler);
4333 (void)signal(SIGINT, dump_sig_handler);
4336 VEPRINT("Full Dump ...\n");
4338 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4342 /* get connections to the servers */
4343 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4345 VEPRINT1("Starting transaction on volume %u...", afromvol);
4347 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4349 EGOTO1(error_exit, code,
4350 "Could not start transaction on the volume %u to be dumped\n",
4354 fromcall = rx_NewCall(fromconn);
4356 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4357 if (flags & VOLDUMPV2_OMITDIRS)
4358 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4360 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4361 EGOTO(error_exit, code, "Could not start the dump process \n");
4364 VEPRINT1("Dumping volume %u...", afromvol);
4365 code = DumpFunction(fromcall, rock);
4366 if (code == RXGEN_OPCODE)
4368 EGOTO(error_exit, code, "Error while dumping volume \n");
4373 code = rx_EndCall(fromcall, 0);
4374 if (code && code != RXGEN_OPCODE)
4375 fprintf(STDERR, "Error in rx_EndCall\n");
4380 VEPRINT1("Ending transaction on volume %u...", afromvol);
4381 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4382 if (code || rcode) {
4383 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4384 (unsigned long)afromvol);
4386 error = (code ? code : rcode);
4391 rx_DestroyConnection(fromconn);
4393 if (error != RXGEN_OPCODE)
4394 PrintError("", error);
4398 /* Clone the volume <afromvol> on <afromserver> and
4399 * <afrompart>, and then dump the clone volume to
4400 * <afilename> starting from <fromdate>.
4401 * DumpFunction does the real work behind the scenes after
4402 * extracting parameters from the rock
4405 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4406 afs_int32 afrompart, afs_int32 fromdate,
4407 afs_int32(*DumpFunction) (struct rx_call *, void *),
4408 void *rock, afs_int32 flags)
4410 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4411 * be changing during the dump */
4412 struct rx_connection * volatile fromconn = NULL;
4413 struct rx_call * volatile fromcall = NULL;
4414 afs_int32 volatile clonetid = 0;
4415 afs_uint32 volatile clonevol = 0;
4418 afs_int32 fromtid = 0, rcode = 0;
4419 afs_int32 code = 0, error = 0;
4422 time_t tmv = fromdate;
4426 #ifndef AFS_NT40_ENV
4427 (void)signal(SIGPIPE, dump_sig_handler);
4429 (void)signal(SIGINT, dump_sig_handler);
4432 VEPRINT("Full Dump ...\n");
4434 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4438 /* get connections to the servers */
4439 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4441 VEPRINT1("Starting transaction on volume %u...", afromvol);
4442 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4443 EGOTO1(error_exit, code,
4444 "Could not start transaction on the volume %u to be dumped\n",
4448 /* Get a clone id */
4449 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4451 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4453 EGOTO1(error_exit, code,
4454 "Could not get an ID for the clone of volume %u from the VLDB\n",
4458 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4459 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4461 strcpy(vname, "dump-clone-temp");
4464 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
4466 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4470 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4472 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4476 EGOTO1(error_exit, code,
4477 "Failed to end the transaction on the volume %u\n", afromvol);
4481 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4484 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4487 EGOTO1(error_exit, code,
4488 "Failed to start a transaction on the cloned volume%u\n",
4492 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4493 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4494 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4499 fromcall = rx_NewCall(fromconn);
4501 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4502 if (flags & VOLDUMPV2_OMITDIRS)
4503 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4505 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4506 EGOTO(error_exit, code, "Could not start the dump process \n");
4509 VEPRINT1("Dumping volume %u...", afromvol);
4510 code = DumpFunction(fromcall, rock);
4511 EGOTO(error_exit, code, "Error while dumping volume \n");
4515 /* now delete the clone */
4516 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4517 code = AFSVolDeleteVolume(fromconn, clonetid);
4519 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4520 (unsigned long)clonevol);
4526 code = rx_EndCall(fromcall, 0);
4528 fprintf(STDERR, "Error in rx_EndCall\n");
4534 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4535 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4536 if (code || rcode) {
4538 "Could not end transaction on the cloned volume %lu\n",
4539 (unsigned long)clonevol);
4541 error = (code ? code : rcode);
4546 rx_DestroyConnection(fromconn);
4548 PrintError("", error);
4555 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4556 * the dump file <afilename>. WriteData does all the real work
4557 * after extracting params from the rock
4560 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4561 afs_uint32 toparentid, char tovolname[], int flags,
4562 afs_int32(*WriteData) (struct rx_call *, void *),
4565 struct rx_connection *toconn, *tempconn;
4566 struct rx_call *tocall;
4567 afs_int32 totid, code, rcode, vcode, terror = 0;
4568 struct volser_status tstatus;
4569 struct volintInfo vinfo;
4571 char tovolreal[VOLSER_OLDMAXVOLNAME];
4573 afs_int32 temptid, pparentid;
4574 struct nvldbentry entry, storeEntry;
4577 struct restoreCookie cookie;
4579 afs_int32 volflag, voltype, volsertype;
4580 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4581 VolumeId oldCloneId = 0;
4582 VolumeId oldBackupId = 0;
4583 int index, same, errcode;
4587 memset(&cookie, 0, sizeof(cookie));
4591 tocall = (struct rx_call *)0;
4592 tempconn = (struct rx_connection *)0;
4596 if (flags & RV_RDONLY) {
4598 volsertype = volser_RO;
4601 volsertype = volser_RW;
4605 pparentid = toparentid;
4606 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4607 if (pvolid == 0) { /*alot a new id if needed */
4608 vcode = VLDB_GetEntryByName(tovolname, &entry);
4609 if (vcode == VL_NOENT) {
4610 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4612 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4618 } else if (flags & RV_RDONLY) {
4619 if (entry.flags & VLF_RWEXISTS) {
4621 "Entry for ReadWrite volume %s already exists!\n",
4623 error = VOLSERBADOP;
4626 if (!entry.volumeId[ROVOL]) {
4628 "Existing entry for volume %s has no ReadOnly ID\n",
4630 error = VOLSERBADOP;
4633 pvolid = entry.volumeId[ROVOL];
4634 pparentid = entry.volumeId[RWVOL];
4636 pvolid = entry.volumeId[RWVOL];
4637 pparentid = entry.volumeId[RWVOL];
4640 if (!pparentid) pparentid = pvolid;
4641 /* at this point we have a volume id to use/reuse for the volume to be restored */
4642 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4644 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4645 EGOTO1(refail, VOLSERBADOP,
4646 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4649 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4650 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4651 EGOTO1(refail, VOLSERBADOP,
4652 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4654 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4657 MapPartIdIntoName(topart, partName);
4658 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4659 tovolreal, (unsigned long)pvolid,
4660 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4661 hostutil_GetNameByINet(toserver), partName);
4664 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4667 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4668 code = DoVolDelete(toconn, pvolid, topart, "the previous", 0,
4670 if (code && code != VNOVOL) {
4676 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4678 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4681 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4682 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4685 code = AFSVolGetStatus(toconn, totid, &tstatus);
4686 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4690 oldCreateDate = tstatus.creationDate;
4691 oldUpdateDate = tstatus.updateDate;
4692 oldCloneId = tstatus.cloneID;
4693 oldBackupId = tstatus.backupID;
4699 cookie.parent = pparentid;
4700 cookie.type = voltype;
4702 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4704 tocall = rx_NewCall(toconn);
4705 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4707 fprintf(STDERR, "Volume restore Failed \n");
4711 code = WriteData(tocall, rock);
4713 fprintf(STDERR, "Could not transmit data\n");
4717 terror = rx_EndCall(tocall, 0);
4718 tocall = (struct rx_call *)0;
4720 fprintf(STDERR, "rx_EndCall Failed \n");
4724 code = AFSVolGetStatus(toconn, totid, &tstatus);
4727 "Could not get status information about the volume %lu\n",
4728 (unsigned long)pvolid);
4732 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid,
4733 oldCloneId, oldBackupId);
4735 fprintf(STDERR, "Could not set the right type and IDs on %lu\n",
4736 (unsigned long)pvolid);
4741 if (flags & RV_CRDUMP)
4742 newCreateDate = tstatus.creationDate;
4743 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4744 newCreateDate = oldCreateDate;
4746 newCreateDate = time(0);
4747 if (flags & RV_LUDUMP)
4748 newUpdateDate = tstatus.updateDate;
4749 else if (flags & RV_LUKEEP)
4750 newUpdateDate = oldUpdateDate;
4752 newUpdateDate = time(0);
4753 code = AFSVolSetDate(toconn,totid, newCreateDate);
4755 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4760 init_volintInfo(&vinfo);
4761 vinfo.creationDate = newCreateDate;
4762 vinfo.updateDate = newUpdateDate;
4763 code = AFSVolSetInfo(toconn, totid, &vinfo);
4765 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4771 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4772 code = AFSVolSetFlags(toconn, totid, volflag);
4774 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4779 /* It isn't handled right in refail */
4780 code = AFSVolEndTrans(toconn, totid, &rcode);
4785 fprintf(STDERR, "Could not end transaction on %lu\n",
4786 (unsigned long)pvolid);
4791 fprintf(STDOUT, " done\n");
4793 if (!reuseID || (flags & RV_FULLRST)) {
4794 /* Volume was restored on the file server, update the
4795 * VLDB to reflect the change.
4797 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4798 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4800 "Could not fetch the entry for volume number %lu from VLDB \n",
4801 (unsigned long)pvolid);
4806 MapHostToNetwork(&entry);
4807 if (vcode == VL_NOENT) { /* it doesnot exist already */
4808 /*make the vldb return this indication specifically */
4809 VPRINT("------- Creating a new VLDB entry ------- \n");
4810 strcpy(entry.name, tovolname);
4812 entry.serverNumber[0] = toserver; /*should be indirect */
4813 entry.serverPartition[0] = topart;
4814 entry.serverFlags[0] = (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4815 entry.flags = (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4816 if (flags & RV_RDONLY)
4817 entry.volumeId[ROVOL] = pvolid;
4818 else if (tstatus.cloneID != 0) {
4819 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4821 entry.volumeId[ROVOL] = INVALID_BID;
4822 entry.volumeId[RWVOL] = pparentid;
4824 if (tstatus.backupID != 0) {
4825 entry.volumeId[BACKVOL] = tstatus.backupID;
4826 /*this should come from status info on the volume if non zero */
4828 entry.volumeId[BACKVOL] = INVALID_BID;
4829 MapNetworkToHost(&entry, &storeEntry);
4830 vcode = VLDB_CreateEntry(&storeEntry);
4833 "Could not create the VLDB entry for volume number %lu \n",
4834 (unsigned long)pvolid);
4840 EnumerateEntry(&entry);
4841 } else { /*update the existing entry */
4843 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4844 fprintf(STDOUT, "------- Old entry -------\n");
4845 EnumerateEntry(&entry);
4846 fprintf(STDOUT, "------- New entry -------\n");
4849 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4853 "Could not lock the entry for volume number %lu \n",
4854 (unsigned long)pvolid);
4859 strcpy(entry.name, tovolname);
4861 /* Update the vlentry with the new information */
4862 if (flags & RV_RDONLY)
4863 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4865 index = Lp_GetRwIndex(&entry);
4867 /* Add the new site for the volume being restored */
4868 entry.serverNumber[entry.nServers] = toserver;
4869 entry.serverPartition[entry.nServers] = topart;
4870 entry.serverFlags[entry.nServers] =
4871 (flags & RV_RDONLY) ? VLSF_ROVOL : VLSF_RWVOL;
4874 /* This volume should be deleted on the old site
4875 * if its different from new site.
4878 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4882 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4884 if ((!errcode && !same)
4885 || (entry.serverPartition[index] != topart)) {
4886 if (flags & RV_NODEL) {
4888 ("Not deleting the previous volume %u on server %s, ...",
4890 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4891 hostutil_GetNameByINet(entry.serverNumber[index]));
4894 UV_Bind(entry.serverNumber[index],
4895 AFSCONF_VOLUMEPORT);
4897 MapPartIdIntoName(entry.serverPartition[index],
4900 ("Deleting the previous volume %u on server %s, partition %s ...",
4902 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4903 hostutil_GetNameByINet(entry.serverNumber[index]),
4905 code = DoVolDelete(tempconn, pvolid,
4906 entry.serverPartition[index],
4907 "the", 0, NULL, NULL);
4908 if (code && code != VNOVOL) {
4912 MapPartIdIntoName(entry.serverPartition[index],
4916 entry.serverNumber[index] = toserver;
4917 entry.serverPartition[index] = topart;
4920 entry.flags |= (flags & RV_RDONLY) ? VLF_ROEXISTS : VLF_RWEXISTS;
4921 MapNetworkToHost(&entry, &storeEntry);
4923 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4924 LOCKREL_OPCODE | LOCKREL_AFSID |
4928 "Could not update the entry for volume number %lu \n",
4929 (unsigned long)pvolid);
4935 EnumerateEntry(&entry);
4942 code = rx_EndCall(tocall, 0);
4948 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4949 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4952 "Could not release lock on the VLDB entry for the volume %lu\n",
4953 (unsigned long)pvolid);
4959 code = AFSVolEndTrans(toconn, totid, &rcode);
4963 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4964 (unsigned long)pvolid);
4970 code = AFSVolEndTrans(toconn, temptid, &rcode);
4974 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4975 (unsigned long)pvolid);
4981 rx_DestroyConnection(tempconn);
4983 rx_DestroyConnection(toconn);
4984 PrintError("", error);
4989 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4990 char tovolname[], int flags,
4991 afs_int32(*WriteData) (struct rx_call *, void *),
4994 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4999 /*unlocks the vldb entry associated with <volid> */
5001 UV_LockRelease(afs_uint32 volid)
5005 VPRINT("Binding to the VLDB server\n");
5007 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
5008 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5011 "Could not unlock the entry for volume number %lu in VLDB \n",
5012 (unsigned long)volid);
5013 PrintError("", vcode);
5016 VPRINT("VLDB updated\n");
5021 /* old interface to add rosites */
5023 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5026 return UV_AddSite2(server, part, volid, 0, valid);
5029 /*adds <server> and <part> as a readonly replication site for <volid>
5032 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
5033 afs_uint32 rovolid, afs_int32 valid)
5035 int j, nro = 0, islocked = 0;
5036 struct nvldbentry entry, storeEntry, entry2;
5037 afs_int32 vcode, error = 0;
5040 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5043 " Could not lock the VLDB entry for the volume %lu \n",
5044 (unsigned long)volid);
5049 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
5052 "Could not fetch the VLDB entry for volume number %lu \n",
5053 (unsigned long)volid);
5057 if (!ISNAMEVALID(entry.name)) {
5059 "Volume name %s is too long, rename before adding site\n",
5061 error = VOLSERBADOP;
5064 MapHostToNetwork(&entry);
5066 /* See if it's too many entries */
5067 if (entry.nServers >= NMAXNSERVERS) {
5068 fprintf(STDERR, "Total number of entries will exceed %u\n",
5070 error = VOLSERBADOP;
5074 /* See if it's on the same server */
5075 for (j = 0; j < entry.nServers; j++) {
5076 if (entry.serverFlags[j] & VLSF_ROVOL) {
5078 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5081 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5084 MapPartIdIntoName(entry.serverPartition[j], apartName);
5086 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5088 error = VOLSERBADOP;
5095 /* See if it's too many RO sites - leave one for the RW */
5096 if (nro >= NMAXNSERVERS - 1) {
5097 fprintf(STDERR, "Total number of sites will exceed %u\n",
5099 error = VOLSERBADOP;
5103 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5104 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5105 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5108 if (entry.volumeId[ROVOL] == INVALID_BID) {
5109 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5111 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5114 VPRINT1("Using RO volume id %d.\n", rovolid);
5115 entry.volumeId[ROVOL] = rovolid;
5117 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5118 rovolid, entry.volumeId[ROVOL]);
5122 VPRINT("Adding a new site ...");
5123 entry.serverNumber[entry.nServers] = server;
5124 entry.serverPartition[entry.nServers] = part;
5126 entry.serverFlags[entry.nServers] = (VLSF_ROVOL | VLSF_DONTUSE);
5128 entry.serverFlags[entry.nServers] = (VLSF_ROVOL);
5132 MapNetworkToHost(&entry, &storeEntry);
5134 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5135 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5137 fprintf(STDERR, "Could not update entry for volume %lu \n",
5138 (unsigned long)volid);
5147 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5148 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5151 "Could not release lock on volume entry for %lu \n",
5152 (unsigned long)volid);
5153 PrintError("", vcode);
5157 PrintError("", error);
5161 /*removes <server> <part> as read only site for <volid> from the vldb */
5163 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5166 struct nvldbentry entry, storeEntry;
5168 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5170 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5171 (unsigned long)volid);
5172 PrintError("", vcode);
5175 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5178 "Could not fetch the entry for volume number %lu from VLDB \n",
5179 (unsigned long)volid);
5180 PrintError("", vcode);
5183 MapHostToNetwork(&entry);
5184 if (!Lp_ROMatch(server, part, &entry)) {
5185 /*this site doesnot exist */
5186 fprintf(STDERR, "This site is not a replication site \n");
5188 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5189 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5191 fprintf(STDERR, "Could not update entry for volume %lu \n",
5192 (unsigned long)volid);
5193 PrintError("", vcode);
5194 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5195 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5199 } else { /*remove the rep site */
5200 Lp_SetROValue(&entry, server, part, 0, 0);
5202 if ((entry.nServers == 1) && (entry.flags & VLF_RWEXISTS))
5203 entry.flags &= ~VLF_ROEXISTS;
5204 if (entry.nServers < 1) { /*this is the last ref */
5205 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5207 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5210 "Could not delete VLDB entry for volume %lu \n",
5211 (unsigned long)volid);
5212 PrintError("", vcode);
5217 MapNetworkToHost(&entry, &storeEntry);
5218 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5219 (unsigned long)volid);
5222 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5223 LOCKREL_OPCODE | LOCKREL_AFSID |
5227 "Could not release lock on volume entry for %lu \n",
5228 (unsigned long)volid);
5229 PrintError("", vcode);
5230 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5231 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5239 /*sets <server> <part> as read/write site for <volid> in the vldb */
5241 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5244 struct nvldbentry entry, storeEntry;
5247 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5249 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5250 (unsigned long)volid);
5251 PrintError("", vcode);
5254 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5257 "Could not fetch the entry for volume number %lu from VLDB \n",
5258 (unsigned long)volid);
5259 PrintError("", vcode);
5262 MapHostToNetwork(&entry);
5263 index = Lp_GetRwIndex(&entry);
5265 /* no RW site exists */
5266 fprintf(STDERR, "No existing RW site for volume %lu",
5267 (unsigned long)volid);
5269 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5270 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5273 "Could not release lock on entry for volume %lu \n",
5274 (unsigned long)volid);
5275 PrintError("", vcode);
5279 } else { /* change the RW site */
5280 entry.serverNumber[index] = server;
5281 entry.serverPartition[index] = part;
5282 MapNetworkToHost(&entry, &storeEntry);
5284 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5285 LOCKREL_OPCODE | LOCKREL_AFSID |
5288 fprintf(STDERR, "Could not update entry for volume %lu \n",
5289 (unsigned long)volid);
5290 PrintError("", vcode);
5291 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5292 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5300 /*list all the partitions on <aserver> */
5302 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5305 struct rx_connection *aconn;
5306 struct pIDs partIds;
5307 struct partEntries partEnts;
5311 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5313 partEnts.partEntries_len = 0;
5314 partEnts.partEntries_val = NULL;
5315 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5316 if (code == RXGEN_OPCODE) {
5317 for (i = 0; i < 26; i++) /* try old interface */
5318 partIds.partIds[i] = -1;
5319 code = AFSVolListPartitions(aconn, &partIds);
5321 for (i = 0; i < 26; i++) {
5322 if ((partIds.partIds[i]) != -1) {
5323 ptrPartList->partId[j] = partIds.partIds[i];
5324 ptrPartList->partFlags[j] = PARTVALID;
5327 ptrPartList->partFlags[i] = 0;
5332 *cntp = partEnts.partEntries_len;
5333 if (*cntp > VOLMAXPARTS) {
5335 "Warning: number of partitions on the server too high %d (process only %d)\n",
5336 *cntp, VOLMAXPARTS);
5337 *cntp = VOLMAXPARTS;
5339 for (i = 0; i < *cntp; i++) {
5340 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5341 ptrPartList->partFlags[i] = PARTVALID;
5343 free(partEnts.partEntries_val);
5349 "Could not fetch the list of partitions from the server\n");
5350 PrintError("", code);
5352 rx_DestroyConnection(aconn);
5357 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5358 This is used by the backup system */
5360 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5361 struct volDescription *volPtr, afs_int32 arraySize)
5363 struct rx_connection *aconn;
5364 struct volDescription *curPtr;
5367 afs_int32 success = 1;
5369 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5371 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5372 if (curPtr->volFlags & CLONEVALID) {
5373 curPtr->volFlags &= ~CLONEZAPPED;
5376 code = DoVolDelete(aconn, curPtr->volCloneId, apart,
5377 "clone", 0, NULL, NULL);
5382 curPtr->volFlags |= CLONEZAPPED;
5384 fprintf(STDERR, "Could not zap volume %lu\n",
5385 (unsigned long)curPtr->volCloneId);
5387 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5388 curPtr->volCloneId);
5393 rx_DestroyConnection(aconn);
5397 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5400 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5401 struct volDescription *volPtr, afs_int32 arraySize)
5403 struct rx_connection *aconn;
5404 struct volDescription *curPtr;
5407 afs_int32 rcode = 0;
5409 int reuseCloneId = 0;
5410 afs_uint32 curCloneId = 0;
5411 char cloneName[256]; /*max vol name */
5413 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5415 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5417 else { /*get a bunch of id's from vldb */
5419 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5421 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5422 PrintError("", code);
5427 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5428 if (curPtr->volFlags & ENTRYVALID) {
5430 curPtr->volFlags |= CLONEVALID;
5431 /*make a clone of curParentId and record as curPtr->volCloneId */
5433 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5436 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5439 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5443 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5444 strcpy(cloneName, curPtr->volName);
5445 strcat(cloneName, "-tmpClone-");
5447 strcpy(cloneName, "-tmpClone");
5449 curPtr->volCloneId = curCloneId;
5454 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5455 &(curPtr->volCloneId));
5457 curPtr->volFlags &= ~CLONEVALID;
5459 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5460 curPtr->volName, (unsigned long)code);
5461 code = AFSVolEndTrans(aconn, tid, &rcode);
5463 fprintf(STDERR, "WARNING: could not end transaction\n");
5466 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5467 curPtr->volCloneId);
5468 code = AFSVolEndTrans(aconn, tid, &rcode);
5469 if (code || rcode) {
5470 curPtr->volFlags &= ~CLONEVALID;
5479 rx_DestroyConnection(aconn);
5484 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5485 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5487 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5488 struct volintInfo **resultPtr, afs_int32 * size)
5490 struct rx_connection *aconn;
5492 volEntries volumeInfo;
5496 *resultPtr = (volintInfo *) 0;
5497 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5498 volumeInfo.volEntries_len = 0;
5500 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5501 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5504 "Could not fetch the list of volumes from the server\n");
5506 *resultPtr = volumeInfo.volEntries_val;
5507 *size = volumeInfo.volEntries_len;
5511 rx_DestroyConnection(aconn);
5512 PrintError("", code);
5516 /*------------------------------------------------------------------------
5517 * EXPORTED UV_XListVolumes
5520 * List the extended information for all the volumes on a particular
5521 * File Server and partition. We may either return the volume's ID
5522 * or all of its extended information.
5525 * a_serverID : Address of the File Server for which we want
5526 * extended volume info.
5527 * a_partID : Partition for which we want the extended
5529 * a_all : If non-zero, fetch ALL the volume info,
5530 * otherwise just the volume ID.
5531 * a_resultPP : Ptr to the address of the area containing
5532 * the returned volume info.
5533 * a_numEntsInResultP : Ptr for the value we set for the number of
5538 * Otherise, the return value of AFSVolXListVolumes.
5541 * This routine is closely related to UV_ListVolumes, which returns
5542 * only the standard level of detail on AFS volumes. It is a
5543 * heavyweight operation, zipping through all the volume entries for
5544 * a given server/partition.
5548 *------------------------------------------------------------------------*/
5551 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5552 struct volintXInfo **a_resultPP,
5553 afs_int32 * a_numEntsInResultP)
5555 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5556 afs_int32 code; /*Error code to return */
5557 volXEntries volumeXInfo; /*Area for returned extended vol info */
5560 * Set up our error code and the area for returned extended volume info.
5561 * We set the val field to a null pointer as a hint for the stub to
5564 *a_numEntsInResultP = 0;
5565 *a_resultPP = (volintXInfo *) 0;
5566 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5567 volumeXInfo.volXEntries_len = 0;
5570 * Bind to the Volume Server port on the File Server machine in question,
5573 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5574 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5576 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5579 * We got the info; pull out the pointer to where the results lie
5580 * and how many entries are there.
5582 *a_resultPP = volumeXInfo.volXEntries_val;
5583 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5587 * If we got an Rx connection, throw it away.
5590 rx_DestroyConnection(rxConnP);
5592 PrintError("", code);
5594 } /*UV_XListVolumes */
5596 /* get all the information about volume <volid> on <aserver> and <apart> */
5598 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5599 struct volintInfo **resultPtr)
5601 struct rx_connection *aconn;
5603 volEntries volumeInfo;
5605 *resultPtr = (volintInfo *) 0;
5606 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5607 volumeInfo.volEntries_len = 0;
5609 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5610 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5613 "Could not fetch the information about volume %lu from the server\n",
5614 (unsigned long)volid);
5616 *resultPtr = volumeInfo.volEntries_val;
5621 rx_DestroyConnection(aconn);
5622 PrintError("", code);
5626 /*------------------------------------------------------------------------
5627 * EXPORTED UV_XListOneVolume
5630 * List the extended information for a volume on a particular File
5631 * Server and partition.
5634 * a_serverID : Address of the File Server for which we want
5635 * extended volume info.
5636 * a_partID : Partition for which we want the extended
5638 * a_volID : Volume ID for which we want the info.
5639 * a_resultPP : Ptr to the address of the area containing
5640 * the returned volume info.
5644 * Otherise, the return value of AFSVolXListOneVolume.
5647 * This routine is closely related to UV_ListOneVolume, which returns
5648 * only the standard level of detail on the chosen AFS volume.
5652 *------------------------------------------------------------------------*/
5655 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5656 struct volintXInfo **a_resultPP)
5658 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5659 afs_int32 code; /*Error code */
5660 volXEntries volumeXInfo; /*Area for returned info */
5663 * Set up our error code, and the area we're in which we are returning
5664 * the info. Setting the val field to a null pointer tells the stub
5665 * to allocate space for us.
5667 *a_resultPP = (volintXInfo *) 0;
5668 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5669 volumeXInfo.volXEntries_len = 0;
5672 * Bind to the Volume Server port on the File Server machine in question,
5675 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5676 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5679 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5682 * We got the info; pull out the pointer to where the results lie.
5684 *a_resultPP = volumeXInfo.volXEntries_val;
5687 * If we got an Rx connection, throw it away.
5690 rx_DestroyConnection(rxConnP);
5692 PrintError("", code);
5697 * Given a volume we read from a partition, check if it is
5698 * represented in the VLDB correctly.
5700 * The VLDB is looked up by the RW volume id (not its name).
5701 * The RW contains the true name of the volume (BK and RO set
5702 * the name in the VLDB only on creation of the VLDB entry).
5703 * We want rules strict enough that when we check all volumes
5704 * on one partition, it does not need to be done again. IE:
5705 * two volumes on different partitions won't constantly
5706 * change a VLDB entry away from what the other set.
5707 * For RW and BK volumes, we will always check the VLDB to see
5708 * if the two exist on the server/partition. May seem redundant,
5709 * but this is an easy check of the VLDB. IE: if the VLDB entry
5710 * says the BK exists but no BK volume is there, we will detect
5711 * this when we check the RW volume.
5712 * VLDB entries are locked only when a change needs to be done.
5713 * Output changed to look a lot like the "vos syncserv" otuput.
5716 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5717 afs_int32 * modentry, afs_uint32 * maxvolid,
5718 struct nvldbentry *aentry)
5722 afs_int32 code, error = 0;
5723 struct nvldbentry entry, storeEntry;
5725 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5735 ((volumeinfo->type ==
5736 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5739 /* Check to see if the VLDB is ok without locking it (pass 1).
5740 * If it will change, then lock the VLDB entry, read it again,
5741 * then make the changes to it (pass 2).
5744 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5746 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5747 (unsigned long)rwvolid);
5752 createentry = 0; /* Do we need to create a VLDB entry */
5753 addvolume = 0; /* Add this volume to the VLDB entry */
5754 modified = 0; /* The VLDB entry was modified */
5757 memcpy(&entry, aentry, sizeof(entry));
5759 /* Read the entry from VLDB by its RW volume id */
5760 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5762 if (code != VL_NOENT) {
5764 "Could not retrieve the VLDB entry for volume %lu \n",
5765 (unsigned long)rwvolid);
5769 memset(&entry, 0, sizeof(entry));
5770 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5774 MapHostToNetwork(&entry);
5778 if (verbose && (pass == 1)) {
5779 fprintf(STDOUT, "_______________________________\n");
5780 fprintf(STDOUT, "\n-- status before -- \n");
5782 fprintf(STDOUT, "\n**does not exist**\n");
5784 if ((entry.flags & VLF_RWEXISTS) || (entry.flags & VLF_ROEXISTS)
5785 || (entry.flags & VLF_BACKEXISTS))
5786 EnumerateEntry(&entry);
5788 fprintf(STDOUT, "\n");
5791 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5797 /* Check existence of RW and BK volumes */
5798 code = CheckVldbRWBK(&entry, &mod);
5804 idx = Lp_GetRwIndex(&entry);
5805 if (idx == -1) { /* RW index not found in the VLDB entry */
5806 idx = entry.nServers; /* put it into next index */
5809 } else { /* RW index found in the VLDB entry. */
5810 /* Verify if this volume's location matches where the VLDB says it is */
5811 if (!Lp_Match(aserver, apart, &entry)) {
5812 if (entry.flags & VLF_RWEXISTS) {
5813 /* The RW volume exists elsewhere - report this one a duplicate */
5815 MapPartIdIntoName(apart, pname);
5817 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5818 (unsigned long)rwvolid,
5820 afs_inet_ntoa_r(aserver, hoststr) :
5821 hostutil_GetNameByINet(aserver), pname);
5822 MapPartIdIntoName(entry.serverPartition[idx],
5825 " VLDB reports RW volume %lu exists on %s %s\n",
5826 (unsigned long)rwvolid,
5828 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5829 hostutil_GetNameByINet(entry.
5834 /* The RW volume does not exist - have VLDB point to this one */
5837 /* Check for orphaned BK volume on old partition */
5838 if (entry.flags & VLF_BACKEXISTS) {
5840 MapPartIdIntoName(entry.serverPartition[idx],
5843 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5844 entry.volumeId[BACKVOL],
5846 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5847 hostutil_GetNameByINet(entry.
5850 MapPartIdIntoName(apart, pname);
5852 " VLDB reports its RW volume %lu exists on %s %s\n",
5853 (unsigned long)rwvolid,
5855 afs_inet_ntoa_r(aserver, hoststr) :
5856 hostutil_GetNameByINet(aserver),
5862 /* Volume location matches the VLDB location */
5863 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5864 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5867 (entry.name, volumeinfo->name,
5868 VOLSER_OLDMAXVOLNAME) != 0)) {
5876 entry.flags |= VLF_RWEXISTS;
5877 entry.volumeId[RWVOL] = rwvolid;
5878 if (!entry.volumeId[BACKVOL])
5879 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5880 if (!entry.volumeId[ROVOL])
5881 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5883 entry.serverFlags[idx] = VLSF_RWVOL;
5884 entry.serverNumber[idx] = aserver;
5885 entry.serverPartition[idx] = apart;
5886 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5890 /* One last check - to update BK if need to */
5891 code = CheckVldbRWBK(&entry, &mod);
5899 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5905 /* Check existence of RW and BK volumes */
5906 code = CheckVldbRWBK(&entry, &mod);
5912 idx = Lp_GetRwIndex(&entry);
5913 if (idx == -1) { /* RW index not found in the VLDB entry */
5914 idx = entry.nServers; /* Put it into next index */
5917 } else { /* RW index found in the VLDB entry */
5918 /* Verify if this volume's location matches where the VLDB says it is */
5919 if (!Lp_Match(aserver, apart, &entry)) {
5920 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5922 MapPartIdIntoName(apart, pname);
5924 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5925 (unsigned long)volumeinfo->volid,
5927 afs_inet_ntoa_r(aserver, hoststr) :
5928 hostutil_GetNameByINet(aserver), pname);
5929 MapPartIdIntoName(entry.serverPartition[idx], pname);
5931 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5932 (unsigned long)rwvolid,
5934 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5935 hostutil_GetNameByINet(entry.
5940 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5941 if (!(entry.flags & VLF_BACKEXISTS)) {
5943 } else if (volumeinfo->volid >
5944 entry.volumeId[BACKVOL]) {
5948 MapPartIdIntoName(entry.serverPartition[idx],
5951 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5952 entry.volumeId[BACKVOL],
5954 afs_inet_ntoa_r(aserver, hoststr) :
5955 hostutil_GetNameByINet(aserver),
5958 " VLDB reports its BK volume ID is %lu\n",
5959 (unsigned long)volumeinfo->volid);
5963 MapPartIdIntoName(entry.serverPartition[idx],
5966 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5967 (unsigned long)volumeinfo->volid,
5969 afs_inet_ntoa_r(aserver, hoststr) :
5970 hostutil_GetNameByINet(aserver),
5973 " VLDB reports its BK volume ID is %u\n",
5974 entry.volumeId[BACKVOL]);
5977 } else if (!entry.volumeId[BACKVOL]) {
5984 entry.flags |= VLF_BACKEXISTS;
5985 entry.volumeId[RWVOL] = rwvolid;
5986 entry.volumeId[BACKVOL] = volumeinfo->volid;
5988 entry.serverNumber[idx] = aserver;
5989 entry.serverPartition[idx] = apart;
5990 entry.serverFlags[idx] = VLSF_RWVOL;
5996 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5997 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5998 /* This is a quick check to see if the RO entry exists in the
5999 * VLDB so we avoid the CheckVldbRO() call (which checks if each
6000 * RO volume listed in the VLDB exists).
6002 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6004 idx = entry.nServers;
6008 if (!(entry.flags & VLF_ROEXISTS)) {
6013 /* Before we correct the VLDB entry, make sure all the
6014 * ROs listed in the VLDB exist.
6016 code = CheckVldbRO(&entry, &mod);
6022 if (!(entry.flags & VLF_ROEXISTS)) {
6023 /* No RO exists in the VLDB entry - add this one */
6024 idx = entry.nServers;
6027 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
6028 /* The volume headers's RO ID does not match that in the VLDB entry,
6029 * and the vol hdr's ID is greater (implies more recent). So delete
6030 * all the RO volumes listed in VLDB entry and add this volume.
6032 for (j = 0; j < entry.nServers; j++) {
6033 if (entry.serverFlags[j] & VLSF_ROVOL) {
6034 /* Verify this volume exists and print message we are orphaning it */
6036 MapPartIdIntoName(apart, pname);
6038 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
6039 entry.volumeId[ROVOL],
6041 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
6042 hostutil_GetNameByINet(entry.
6046 " VLDB reports its RO volume ID is %lu\n",
6047 (unsigned long)volumeinfo->volid);
6050 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6051 entry.serverPartition[idx], 0L, 0L);
6058 idx = entry.nServers;
6061 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6062 /* The volume headers's RO ID does not match that in the VLDB entry,
6063 * and the vol hdr's ID is lower (implies its older). So orphan it.
6066 MapPartIdIntoName(apart, pname);
6068 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6069 (unsigned long)volumeinfo->volid,
6071 afs_inet_ntoa_r(aserver, hoststr) :
6072 hostutil_GetNameByINet(aserver), pname);
6074 " VLDB reports its RO volume ID is %u\n",
6075 entry.volumeId[ROVOL]);
6078 /* The RO volume ID in the volume header match that in the VLDB entry,
6079 * and there exist RO volumes in the VLDB entry. See if any of them
6080 * are this one. If not, then we add it.
6082 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6084 idx = entry.nServers;
6092 entry.flags |= VLF_ROEXISTS;
6093 entry.volumeId[RWVOL] = rwvolid;
6094 entry.volumeId[ROVOL] = volumeinfo->volid;
6096 entry.serverNumber[idx] = aserver;
6097 entry.serverPartition[idx] = apart;
6098 entry.serverFlags[idx] = VLSF_ROVOL;
6104 /* Remember largest volume id */
6105 if (entry.volumeId[ROVOL] > *maxvolid)
6106 *maxvolid = entry.volumeId[ROVOL];
6107 if (entry.volumeId[BACKVOL] > *maxvolid)
6108 *maxvolid = entry.volumeId[BACKVOL];
6109 if (entry.volumeId[RWVOL] > *maxvolid)
6110 *maxvolid = entry.volumeId[RWVOL];
6112 if (modified && doit) {
6113 MapNetworkToHost(&entry, &storeEntry);
6116 code = VLDB_CreateEntry(&storeEntry);
6119 "Could not create a VLDB entry for the volume %lu\n",
6120 (unsigned long)rwvolid);
6127 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6128 LOCKREL_OPCODE | LOCKREL_AFSID |
6131 fprintf(STDERR, "Could not update entry for %lu\n",
6132 (unsigned long)rwvolid);
6136 } else if (pass == 2) {
6138 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6139 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6141 PrintError("Could not unlock VLDB entry ", code);
6145 if (modified && modentry) {
6150 memcpy(aentry, &entry, sizeof(entry));
6154 fprintf(STDOUT, "-- status after --\n");
6156 EnumerateEntry(&entry);
6158 fprintf(STDOUT, "\n**no change**\n");
6162 VPRINT("\n_______________________________\n");
6167 sortVolumes(const void *a, const void *b)
6169 volintInfo *v1 = (volintInfo *) a;
6170 volintInfo *v2 = (volintInfo *) b;
6171 afs_uint32 rwvolid1, rwvolid2;
6173 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6174 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6176 if (rwvolid1 > rwvolid2)
6177 return -1; /* lower RW id goes first */
6178 if (rwvolid1 < rwvolid2)
6181 if (v1->type == RWVOL)
6182 return -1; /* RW vols go first */
6183 if (v2->type == RWVOL)
6186 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6187 return -1; /* BK vols next */
6188 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6191 if (v1->volid < v2->volid)
6192 return 1; /* larger volids first */
6193 if (v1->volid > v2->volid)
6199 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6200 * Synchronize an individual volume against a sever and partition.
6201 * Checks the VLDB entry (similar to syncserv) as well as checks
6202 * if the volume exists on specified servers (similar to syncvldb).
6205 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6207 struct rx_connection *aconn = 0;
6208 afs_int32 j, k, code, vcode, error = 0;
6210 afs_int32 mod, modified = 0, deleted = 0;
6211 struct nvldbentry vldbentry;
6212 afs_uint32 volumeid = 0;
6213 volEntries volumeInfo;
6214 struct partList PartList;
6216 afs_uint32 maxvolid = 0;
6218 volumeInfo.volEntries_val = (volintInfo *) 0;
6219 volumeInfo.volEntries_len = 0;
6221 /* Turn verbose logging off and do our own verbose logging */
6222 /* tverbose must be set before we call ERROR_EXIT() */
6229 if (!aserver && (flags & 1)) {
6230 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6234 /* Read the VLDB entry */
6235 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6236 if (vcode && (vcode != VL_NOENT)) {
6237 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6240 } else if (!vcode) {
6241 MapHostToNetwork(&vldbentry);
6245 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6246 fprintf(STDOUT, "_______________________________\n");
6247 fprintf(STDOUT, "\n-- status before -- \n");
6249 fprintf(STDOUT, "\n**does not exist**\n");
6251 if ((vldbentry.flags & VLF_RWEXISTS) || (vldbentry.flags & VLF_ROEXISTS)
6252 || (vldbentry.flags & VLF_BACKEXISTS))
6253 EnumerateEntry(&vldbentry);
6255 fprintf(STDOUT, "\n");
6258 /* Verify that all of the VLDB entries exist on the repective servers
6259 * and partitions (this does not require that avolname be a volume ID).
6260 * Equivalent to a syncserv.
6263 /* Tell CheckVldb not to update if appropriate */
6268 code = CheckVldb(&vldbentry, &mod, &deleted);
6270 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6278 /* If aserver is given, we will search for the desired volume on it */
6280 /* Generate array of partitions on the server that we will check */
6282 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6285 "Could not fetch the list of partitions from the server\n");
6289 PartList.partId[0] = apart;
6293 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6295 /* If a volume ID were given, search for it on each partition */
6296 if ((volumeid = atol(avolname))) {
6297 for (j = 0; j < pcnt; j++) {
6299 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6302 if (code != ENODEV) {
6303 fprintf(STDERR, "Could not query server\n");
6311 /* Found one, sync it with VLDB entry */
6313 CheckVolume(volumeInfo.volEntries_val, aserver,
6314 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6321 if (volumeInfo.volEntries_val)
6322 free(volumeInfo.volEntries_val);
6323 volumeInfo.volEntries_val = (volintInfo *) 0;
6324 volumeInfo.volEntries_len = 0;
6328 /* Check to see if the RW, BK, and RO IDs exist on any
6329 * partitions. We get the volume IDs from the VLDB.
6331 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6332 if (vldbentry.volumeId[j] == 0)
6335 for (k = 0; k < pcnt; k++) { /* For each partition */
6336 volumeInfo.volEntries_val = (volintInfo *) 0;
6337 volumeInfo.volEntries_len = 0;
6339 AFSVolListOneVolume(aconn, PartList.partId[k],
6340 vldbentry.volumeId[j], &volumeInfo);
6342 if (code != ENODEV) {
6343 fprintf(STDERR, "Could not query server\n");
6351 /* Found one, sync it with VLDB entry */
6353 CheckVolume(volumeInfo.volEntries_val, aserver,
6354 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6361 if (volumeInfo.volEntries_val)
6362 free(volumeInfo.volEntries_val);
6363 volumeInfo.volEntries_val = (volintInfo *) 0;
6364 volumeInfo.volEntries_len = 0;
6370 /* If verbose output, print a summary of what changed */
6372 fprintf(STDOUT, "-- status after --\n");
6374 fprintf(STDOUT, "\n**entry deleted**\n");
6375 } else if (modified) {
6376 EnumerateEntry(&vldbentry);
6378 fprintf(STDOUT, "\n**no change**\n");
6380 fprintf(STDOUT, "\n_______________________________\n");
6384 /* Now check if the maxvolid is larger than that stored in the VLDB */
6386 afs_uint32 maxvldbid = 0;
6387 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6390 "Could not get the highest allocated volume id from the VLDB\n");
6393 } else if (maxvolid > maxvldbid) {
6395 id = maxvolid - maxvldbid + 1;
6396 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6399 "Error in increasing highest allocated volume id in VLDB\n");
6409 fprintf(STDOUT, "...error encountered");
6411 fprintf(STDOUT, "...done entry\n");
6414 rx_DestroyConnection(aconn);
6415 if (volumeInfo.volEntries_val)
6416 free(volumeInfo.volEntries_val);
6418 PrintError("", error);
6423 * Synchronise vldb with the file server <aserver> and,
6424 * optionally, <apart>.
6427 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6429 struct rx_connection *aconn;
6430 afs_int32 code, error = 0;
6433 volEntries volumeInfo;
6434 struct partList PartList;
6438 afs_int32 failures = 0, modifications = 0, tentries = 0;
6440 afs_uint32 maxvolid = 0;
6443 volumeInfo.volEntries_val = (volintInfo *) 0;
6444 volumeInfo.volEntries_len = 0;
6446 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6448 /* Generate array of partitions to check */
6450 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6453 "Could not fetch the list of partitions from the server\n");
6457 PartList.partId[0] = apart;
6461 VPRINT("Processing volume entries ...\n");
6463 /* Step through the array of partitions */
6464 for (i = 0; i < pcnt; i++) {
6465 apart = PartList.partId[i];
6466 MapPartIdIntoName(apart, pname);
6468 volumeInfo.volEntries_val = (volintInfo *) 0;
6469 volumeInfo.volEntries_len = 0;
6470 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6473 "Could not fetch the list of volumes from the server\n");
6477 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6478 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6479 sizeof(volintInfo), sortVolumes);
6482 for (vi = volumeInfo.volEntries_val, j = 0;
6483 j < volumeInfo.volEntries_len; j++, vi++) {
6491 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6492 j + 1, vi->name, (unsigned long)vi->volid,
6494 afs_inet_ntoa_r(aserver, hoststr) :
6495 hostutil_GetNameByINet(aserver), pname);
6503 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6505 PrintError("", code);
6508 } else if (modified) {
6514 fprintf(STDOUT, "...error encountered\n\n");
6516 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6523 "Could not process entries on server %s partition %s\n",
6525 afs_inet_ntoa_r(aserver, hoststr) :
6526 hostutil_GetNameByINet(aserver), pname);
6528 if (volumeInfo.volEntries_val) {
6529 free(volumeInfo.volEntries_val);
6530 volumeInfo.volEntries_val = 0;
6533 } /* thru all partitions */
6536 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6537 tentries, failures, modifications);
6539 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6540 tentries, failures, modifications);
6544 /* Now check if the maxvolid is larger than that stored in the VLDB */
6546 afs_uint32 maxvldbid = 0;
6547 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6550 "Could not get the highest allocated volume id from the VLDB\n");
6553 } else if (maxvolid > maxvldbid) {
6555 id = maxvolid - maxvldbid + 1;
6556 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6559 "Error in increasing highest allocated volume id in VLDB\n");
6567 rx_DestroyConnection(aconn);
6568 if (volumeInfo.volEntries_val)
6569 free(volumeInfo.volEntries_val);
6570 PrintError("", error);
6575 * Determine if a volume exists on a server and partition.
6576 * Try creating a transaction on the volume. If we can,
6577 * the volume exists, if not, then return the error code.
6578 * Some error codes mean the volume is unavailable but
6579 * still exists - so we catch these error codes.
6582 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6584 struct rx_connection *conn = (struct rx_connection *)0;
6585 afs_int32 code = -1;
6586 volEntries volumeInfo;
6588 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6590 volumeInfo.volEntries_val = (volintInfo *) 0;
6591 volumeInfo.volEntries_len = 0;
6592 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6593 if (volumeInfo.volEntries_val)
6594 free(volumeInfo.volEntries_val);
6595 if (code == VOLSERILLEGAL_PARTITION)
6597 rx_DestroyConnection(conn);
6606 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6610 afs_int32 code, error = 0;
6616 idx = Lp_GetRwIndex(entry);
6618 /* Check to see if the RW volume exists and set the VLF_RWEXISTS
6621 if (idx == -1) { /* Did not find a RW entry */
6622 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6623 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6628 VolumeExists(entry->serverNumber[idx],
6629 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6630 if (code == 0) { /* RW volume exists */
6631 if (!(entry->flags & VLF_RWEXISTS)) { /* ... yet entry says RW does not exist */
6632 entry->flags |= VLF_RWEXISTS; /* ... so say RW does exist */
6635 } else if (code == ENODEV) { /* RW volume does not exist */
6636 if (entry->flags & VLF_RWEXISTS) { /* ... yet entry says RW exists */
6637 entry->flags &= ~VLF_RWEXISTS; /* ... so say RW does not exist */
6641 /* If VLDB says it didn't exist, then ignore error */
6642 if (entry->flags & VLF_RWEXISTS) {
6643 MapPartIdIntoName(entry->serverPartition[idx], pname);
6645 "Transaction call failed for RW volume %u on server %s %s\n",
6646 entry->volumeId[RWVOL],
6648 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6649 hostutil_GetNameByINet(entry->serverNumber[idx]),
6656 /* Check to see if the BK volume exists and set the VLF_BACKEXISTS
6657 * flag accordingly. idx already ponts to the RW entry.
6659 if (idx == -1) { /* Did not find a RW entry */
6660 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6661 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6664 } else { /* Found a RW entry */
6666 VolumeExists(entry->serverNumber[idx],
6667 entry->serverPartition[idx],
6668 entry->volumeId[BACKVOL]);
6669 if (code == 0) { /* BK volume exists */
6670 if (!(entry->flags & VLF_BACKEXISTS)) { /* ... yet entry says BK does not exist */
6671 entry->flags |= VLF_BACKEXISTS; /* ... so say BK does exist */
6674 } else if (code == ENODEV) { /* BK volume does not exist */
6675 if (entry->flags & VLF_BACKEXISTS) { /* ... yet entry says BK exists */
6676 entry->flags &= ~VLF_BACKEXISTS; /* ... so say BK does not exist */
6680 /* If VLDB says it didn't exist, then ignore error */
6681 if (entry->flags & VLF_BACKEXISTS) {
6682 MapPartIdIntoName(entry->serverPartition[idx], pname);
6684 "Transaction call failed for BK volume %u on server %s %s\n",
6685 entry->volumeId[BACKVOL],
6687 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6688 hostutil_GetNameByINet(entry->serverNumber[idx]),
6695 /* If there is an idx but the BK and RW volumes no
6696 * longer exist, then remove the RW entry.
6698 if ((idx != -1) && !(entry->flags & VLF_RWEXISTS)
6699 && !(entry->flags & VLF_BACKEXISTS)) {
6700 Lp_SetRWValue(entry, entry->serverNumber[idx],
6701 entry->serverPartition[idx], 0L, 0L);
6708 *modified = modentry;
6713 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6716 int foundro = 0, modentry = 0;
6717 afs_int32 code, error = 0;
6724 /* Check to see if the RO volumes exist and set the VLF_ROEXISTS
6727 for (idx = 0; idx < entry->nServers; idx++) {
6728 if (!(entry->serverFlags[idx] & VLSF_ROVOL)) {
6729 continue; /* not a RO */
6733 VolumeExists(entry->serverNumber[idx],
6734 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6735 if (code == 0) { /* RO volume exists */
6737 } else if (code == ENODEV) { /* RW volume does not exist */
6738 Lp_SetROValue(entry, entry->serverNumber[idx],
6739 entry->serverPartition[idx], 0L, 0L);
6744 MapPartIdIntoName(entry->serverPartition[idx], pname);
6746 "Transaction call failed for RO %u on server %s %s\n",
6747 entry->volumeId[ROVOL],
6749 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6750 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6755 if (foundro) { /* A RO volume exists */
6756 if (!(entry->flags & VLF_ROEXISTS)) { /* ... yet entry says RW does not exist */
6757 entry->flags |= VLF_ROEXISTS; /* ... so say RW does exist */
6760 } else { /* A RO volume does not exist */
6761 if (entry->flags & VLF_ROEXISTS) { /* ... yet entry says RO exists */
6762 entry->flags &= ~VLF_ROEXISTS; /* ... so say RO does not exist */
6769 *modified = modentry;
6774 * Ensure that <entry> matches with the info on file servers
6777 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6779 afs_int32 code, error = 0;
6780 struct nvldbentry storeEntry;
6781 int islocked = 0, mod, modentry, delentry = 0;
6782 int pass = 0, doit=1;
6790 fprintf(STDOUT, "_______________________________\n");
6791 fprintf(STDOUT, "\n-- status before -- \n");
6792 if ((entry->flags & VLF_RWEXISTS) || (entry->flags & VLF_ROEXISTS)
6793 || (entry->flags & VLF_BACKEXISTS))
6794 EnumerateEntry(entry);
6795 fprintf(STDOUT, "\n");
6798 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6799 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6800 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6804 /* Check to see if the VLDB is ok without locking it (pass 1).
6805 * If it will change, then lock the VLDB entry, read it again,
6806 * then make the changes to it (pass 2).
6810 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6813 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6814 entry->volumeId[RWVOL]);
6819 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6821 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6825 MapHostToNetwork(entry);
6831 /* Check if the RW and BK entries are ok */
6832 code = CheckVldbRWBK(entry, &mod);
6835 if (mod && (pass == 1) && doit)
6840 /* Check if the RO volumes entries are ok */
6841 code = CheckVldbRO(entry, &mod);
6844 if (mod && (pass == 1) && doit)
6849 /* The VLDB entry has been updated. If it as been modified, then
6850 * write the entry back out the the VLDB.
6852 if (modentry && doit) {
6856 if (!(entry->flags & VLF_RWEXISTS) && !(entry->flags & VLF_BACKEXISTS)
6857 && !(entry->flags & VLF_ROEXISTS) && doit) {
6858 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6860 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6864 "Could not delete VLDB entry for volume %u \n",
6865 entry->volumeId[RWVOL]);
6870 /* Replace old entry with our new one */
6871 MapNetworkToHost(entry, &storeEntry);
6873 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6874 (LOCKREL_OPCODE | LOCKREL_AFSID |
6875 LOCKREL_TIMESTAMP));
6877 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6878 entry->volumeId[RWVOL]);
6885 if (modified && modentry) {
6888 if (deleted && delentry) {
6893 fprintf(STDOUT, "-- status after --\n");
6895 fprintf(STDOUT, "\n**entry deleted**\n");
6897 EnumerateEntry(entry);
6899 fprintf(STDOUT, "\n**no change**\n");
6903 VPRINT("\n_______________________________\n");
6907 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6909 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6912 "Could not release lock on VLDB entry for volume %u\n",
6913 entry->volumeId[RWVOL]);
6922 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6925 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6927 struct rx_connection *aconn;
6928 afs_int32 code, error = 0;
6929 afs_int32 nentries, tentries = 0;
6930 struct VldbListByAttributes attributes;
6931 nbulkentries arrayEntries;
6932 afs_int32 failures = 0, modified, modifications = 0;
6933 struct nvldbentry *vlentry;
6934 afs_int32 si, nsi, j;
6939 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6941 /* Set up attributes to search VLDB */
6942 attributes.server = ntohl(aserver);
6943 attributes.Mask = VLLIST_SERVER;
6945 attributes.partition = apart;
6946 attributes.Mask |= VLLIST_PARTITION;
6949 VPRINT("Processing VLDB entries ...\n");
6951 /* While we need to collect more VLDB entries */
6952 for (si = 0; si != -1; si = nsi) {
6953 memset(&arrayEntries, 0, sizeof(arrayEntries));
6955 /* Collect set of VLDB entries */
6957 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6958 &arrayEntries, &nsi);
6959 if (code == RXGEN_OPCODE) {
6960 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6964 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6967 tentries += nentries;
6969 for (j = 0; j < nentries; j++) {
6970 vlentry = &arrayEntries.nbulkentries_val[j];
6971 MapHostToNetwork(vlentry);
6973 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6975 /* Tell CheckVldb not to update if appropriate */
6980 code = CheckVldb(vlentry, &modified, NULL);
6982 PrintError("", code);
6984 "Could not process VLDB entry for volume %s\n",
6987 } else if (modified) {
6993 fprintf(STDOUT, "...error encountered\n\n");
6995 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
7000 if (arrayEntries.nbulkentries_val) {
7001 free(arrayEntries.nbulkentries_val);
7002 arrayEntries.nbulkentries_val = 0;
7007 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
7008 tentries, failures, modifications);
7010 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
7011 tentries, failures, modifications);
7016 rx_DestroyConnection(aconn);
7017 if (arrayEntries.nbulkentries_val)
7018 free(arrayEntries.nbulkentries_val);
7021 error = VOLSERFAILEDOP;
7025 /*rename volume <oldname> to <newname>, changing the names of the related
7026 *readonly and backup volumes. This operation is also idempotent.
7027 *salvager is capable of recovering from rename operation stopping halfway.
7028 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
7030 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
7032 struct nvldbentry storeEntry;
7033 afs_int32 vcode, code, rcode, error;
7035 char nameBuffer[256];
7037 struct rx_connection *aconn;
7042 aconn = (struct rx_connection *)0;
7046 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7049 " Could not lock the VLDB entry for the volume %u \n",
7050 entry->volumeId[RWVOL]);
7055 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7056 MapNetworkToHost(entry, &storeEntry);
7057 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7059 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7060 entry->volumeId[RWVOL]);
7064 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7065 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7066 * is concerned, oldname is lost */
7067 if (entry->flags & VLF_RWEXISTS) {
7068 index = Lp_GetRwIndex(entry);
7069 if (index == -1) { /* there is a serious discrepancy */
7071 "There is a serious discrepancy in VLDB entry for volume %u\n",
7072 entry->volumeId[RWVOL]);
7073 fprintf(STDERR, "try building VLDB from scratch\n");
7074 error = VOLSERVLDB_ERROR;
7077 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7079 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7080 entry->serverPartition[index], ITOffline, &tid);
7081 if (code) { /*volume doesnot exist */
7083 "Could not start transaction on the rw volume %u\n",
7084 entry->volumeId[RWVOL]);
7087 } else { /*volume exists, process it */
7090 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7091 entry->volumeId[RWVOL],
7092 entry->volumeId[ROVOL],
7093 entry->volumeId[BACKVOL]);
7095 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7096 code = AFSVolEndTrans(aconn, tid, &rcode);
7100 "Could not end transaction on volume %s %u\n",
7101 entry->name, entry->volumeId[RWVOL]);
7106 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7107 entry->name, entry->volumeId[RWVOL]);
7113 rx_DestroyConnection(aconn);
7114 aconn = (struct rx_connection *)0;
7116 /*end rw volume processing */
7117 if (entry->flags & VLF_BACKEXISTS) { /*process the backup volume */
7118 index = Lp_GetRwIndex(entry);
7119 if (index == -1) { /* there is a serious discrepancy */
7121 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7122 entry->volumeId[BACKVOL]);
7123 fprintf(STDERR, "try building VLDB from scratch\n");
7124 error = VOLSERVLDB_ERROR;
7127 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7129 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7130 entry->serverPartition[index], ITOffline, &tid);
7131 if (code) { /*volume doesnot exist */
7133 "Could not start transaction on the backup volume %u\n",
7134 entry->volumeId[BACKVOL]);
7137 } else { /*volume exists, process it */
7138 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7140 "Volume name %s.backup exceeds the limit of %u characters\n",
7141 newname, VOLSER_OLDMAXVOLNAME);
7145 strcpy(nameBuffer, newname);
7146 strcat(nameBuffer, ".backup");
7149 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7150 entry->volumeId[RWVOL], 0, 0);
7152 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7153 code = AFSVolEndTrans(aconn, tid, &rcode);
7157 "Could not end transaction on the backup volume %u\n",
7158 entry->volumeId[BACKVOL]);
7164 "Could not set parameters on the backup volume %u\n",
7165 entry->volumeId[BACKVOL]);
7170 } /* end backup processing */
7172 rx_DestroyConnection(aconn);
7173 aconn = (struct rx_connection *)0;
7174 if (entry->flags & VLF_ROEXISTS) { /*process the ro volumes */
7175 for (i = 0; i < entry->nServers; i++) {
7176 if (entry->serverFlags[i] & VLSF_ROVOL) {
7177 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7179 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7180 entry->serverPartition[i], ITOffline,
7182 if (code) { /*volume doesnot exist */
7184 "Could not start transaction on the ro volume %u\n",
7185 entry->volumeId[ROVOL]);
7188 } else { /*volume exists, process it */
7189 strcpy(nameBuffer, newname);
7190 strcat(nameBuffer, ".readonly");
7191 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7193 "Volume name %s exceeds the limit of %u characters\n",
7194 nameBuffer, VOLSER_OLDMAXVOLNAME);
7199 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7200 entry->volumeId[RWVOL], 0, 0);
7202 VPRINT2("Renamed RO volume %s on host %s\n",
7205 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7206 hostutil_GetNameByINet(entry->
7208 code = AFSVolEndTrans(aconn, tid, &rcode);
7212 "Could not end transaction on volume %u\n",
7213 entry->volumeId[ROVOL]);
7219 "Could not set parameters on the ro volume %u\n",
7220 entry->volumeId[ROVOL]);
7226 rx_DestroyConnection(aconn);
7227 aconn = (struct rx_connection *)0;
7234 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7236 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7239 "Could not unlock the VLDB entry for the volume %s %u\n",
7240 entry->name, entry->volumeId[RWVOL]);
7246 code = AFSVolEndTrans(aconn, tid, &rcode);
7250 fprintf(STDERR, "Failed to end transaction on a volume \n");
7256 rx_DestroyConnection(aconn);
7257 PrintError("", error);
7262 /*report on all the active transactions on volser */
7264 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7266 struct rx_connection *aconn;
7267 transDebugEntries transInfo;
7270 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7271 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7272 transInfo.transDebugEntries_len = 0;
7273 code = AFSVolMonitor(aconn, &transInfo);
7276 "Could not access status information about the server\n");
7277 PrintError("", code);
7278 if (transInfo.transDebugEntries_val)
7279 free(transInfo.transDebugEntries_val);
7281 rx_DestroyConnection(aconn);
7284 *rcount = transInfo.transDebugEntries_len;
7285 *rpntr = transInfo.transDebugEntries_val;
7287 rx_DestroyConnection(aconn);
7294 /*delete the volume without interacting with the vldb */
7296 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7299 struct rx_connection *aconn;
7301 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7302 error = DoVolDelete(aconn, volid, part,
7303 "the", 0, NULL, NULL);
7304 if (error == VNOVOL) {
7305 EPRINT1(error, "Failed to start transaction on %u\n", volid);
7308 PrintError("", error);
7310 rx_DestroyConnection(aconn);
7315 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7316 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7318 struct rx_connection *conn = 0;
7320 afs_int32 code, error = 0, rcode;
7322 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7324 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7328 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7330 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7334 code = AFSVolSetFlags(conn, tid, setflag);
7336 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7341 #ifdef AFS_PTHREAD_ENV
7344 IOMGR_Sleep(sleeptime);
7351 code = AFSVolEndTrans(conn, tid, &rcode);
7352 if (code || rcode) {
7353 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7355 error = (code ? code : rcode);
7360 rx_DestroyConnection(conn);
7365 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7368 struct rx_connection *conn = 0;
7370 afs_int32 code, error = 0, rcode;
7372 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7374 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7378 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7380 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7384 code = AFSVolSetInfo(conn, tid, infop);
7386 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7393 code = AFSVolEndTrans(conn, tid, &rcode);
7394 if (code || rcode) {
7395 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7397 error = (code ? code : rcode);
7402 rx_DestroyConnection(conn);
7407 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7408 afs_int32 fromdate, struct volintSize *vol_size)
7410 struct rx_connection *aconn = (struct rx_connection *)0;
7411 afs_int32 tid = 0, rcode = 0;
7412 afs_int32 code, error = 0;
7415 /* get connections to the servers */
7416 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7418 VPRINT1("Starting transaction on volume %u...", afromvol);
7419 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7420 EGOTO1(error_exit, code,
7421 "Could not start transaction on the volume %u to be measured\n",
7425 VPRINT1("Getting size of volume on volume %u...", afromvol);
7426 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7427 EGOTO(error_exit, code, "Could not start the measurement process \n");
7432 VPRINT1("Ending transaction on volume %u...", afromvol);
7433 code = AFSVolEndTrans(aconn, tid, &rcode);
7434 if (code || rcode) {
7435 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7437 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7439 error = (code ? code : rcode);
7444 rx_DestroyConnection(aconn);
7446 PrintError("", error);
7450 /*maps the host addresses in <old > (present in network byte order) to
7451 that in< new> (present in host byte order )*/
7453 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7457 /*copy all the fields */
7458 strcpy(new->name, old->name);
7459 /* new->volumeType = old->volumeType;*/
7460 new->nServers = old->nServers;
7461 count = old->nServers;
7462 if (count < NMAXNSERVERS)
7464 for (i = 0; i < count; i++) {
7465 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7466 new->serverPartition[i] = old->serverPartition[i];
7467 new->serverFlags[i] = old->serverFlags[i];
7469 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7470 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7471 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7472 new->cloneId = old->cloneId;
7473 new->flags = old->flags;
7476 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7478 MapHostToNetwork(struct nvldbentry *entry)
7482 count = entry->nServers;
7483 if (count < NMAXNSERVERS)
7485 for (i = 0; i < count; i++) {
7486 entry->serverNumber[i] = htonl(entry->serverNumber[i]);