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 <afs/vlserver.h>
26 #include <afs/cellconfig.h>
29 #include <afs/afsint.h>
33 #include <afs/com_err.h>
35 #include <afs/kautils.h>
37 #include <afs/ihandle.h>
39 #include <afs/ntops.h>
41 #include <afs/vnode.h>
42 #include <afs/volume.h>
43 #define ERRCODE_RANGE 8 /* from error_table.h */
44 #define CLOCKSKEW 2 /* not really skew, but resolution */
45 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
47 /* for UV_MoveVolume() recovery */
51 #include "volser_internal.h"
52 #include "volser_prototypes.h"
53 #include "vsutils_prototypes.h"
54 #include "lockprocs_prototypes.h"
56 extern struct ubik_client *cstruct;
57 int verbose = 0, noresolve = 0;
62 afs_int32 vldbEntryIndex;
65 /* Utility macros used by rest of this source file */
66 #define EPRINT(ec, es) \
68 fprintf(STDERR, "\n"); \
69 fprintf(STDERR, (es)); \
73 #define EPRINT1(ec, es, ep1) \
75 fprintf(STDERR, "\n"); \
76 fprintf(STDERR, (es), (ep1)); \
80 #define EPRINT2(ec, es, ep1, ep2) \
82 fprintf(STDERR, "\n"); \
83 fprintf(STDERR, (es), (ep1), (ep2)); \
87 #define EPRINT3(ec, es, ep1, ep2, ep3) \
89 fprintf(STDERR, "\n"); \
90 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
94 #define EGOTO(where, ec, es) \
103 #define EGOTO1(where, ec, es, ep1) \
106 EPRINT1((ec),(es),(ep1)); \
112 #define EGOTO2(where, ec, es, ep1, ep2) \
115 EPRINT2((ec),(es),(ep1),(ep2)); \
121 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
124 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
131 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
132 #define VPRINT1(es, p) \
133 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
134 #define VPRINT2(es, p1, p2) \
135 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
136 #define VPRINT3(es, p1, p2, p3) \
137 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
139 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
140 #define VEPRINT(es) \
141 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
142 #define VEPRINT1(es, p) \
143 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
144 #define VEPRINT2(es, p1, p2) \
145 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
146 #define VEPRINT3(es, p1, p2, p3) \
147 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
149 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
153 /* getting rid of this */
154 #define ERROR_EXIT(code) do { \
160 /* Protos for static routines */
162 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
163 afs_int32 apart, afs_uint32 okvol,
166 static int DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
168 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
169 struct rx_connection **connPtr, afs_int32 * transPtr,
170 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
171 afs_int32 *origflags);
172 static int SimulateForwardMultiple(struct rx_connection *fromconn,
173 afs_int32 fromtid, afs_int32 fromdate,
174 manyDests * tr, afs_int32 flags,
175 void *cookie, manyResults * results);
176 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
177 afs_int32 apart, afs_int32 * modentry,
178 afs_uint32 * maxvolid, struct nvldbentry *aentry);
179 static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition,
180 afs_uint32 volumeid);
181 static afs_int32 CheckVldbRWBK(struct nvldbentry * entry,
182 afs_int32 * modified);
183 static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified);
184 static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified,
186 static void dump_sig_handler(int x);
187 static int sortVolumes(const void *a, const void *b);
190 /*map the partition <partId> into partition name <partName>*/
192 MapPartIdIntoName(afs_int32 partId, char *partName)
194 if (partId < 26) { /* what if partId > = 26 ? */
195 strcpy(partName, "/vicep");
196 partName[6] = partId + 'a';
199 } else if (partId < VOLMAXPARTS) {
200 strcpy(partName, "/vicep");
202 partName[6] = 'a' + (partId / 26);
203 partName[7] = 'a' + (partId % 26);
210 PrintError(char *msg, afs_int32 errcode)
212 fprintf(STDERR, "%s", msg);
213 /*replace by a big switch statement */
218 fprintf(STDERR, "Possible communication failure\n");
221 fprintf(STDERR, "Volume needs to be salvaged\n");
224 fprintf(STDERR, "Bad vnode number quoted\n");
228 "Volume not attached, does not exist, or not on line\n");
231 fprintf(STDERR, "Volume already exists\n");
234 fprintf(STDERR, "Volume is not in service\n");
237 fprintf(STDERR, "Volume is off line\n");
240 fprintf(STDERR, "Volume is already on line\n");
243 fprintf(STDERR, "Partition is full\n");
246 fprintf(STDERR, "Volume max quota exceeded\n");
249 fprintf(STDERR, "Volume temporarily unavailable\n");
252 fprintf(STDERR, "Volume has moved to another server\n");
255 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
258 fprintf(STDERR, "VLDB: a read terminated too early\n");
261 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
264 fprintf(STDERR, "VLDB: internal creation failure\n");
267 fprintf(STDERR, "VLDB: no such entry\n");
270 fprintf(STDERR, "VLDB: vldb database is empty\n");
273 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
276 fprintf(STDERR, "VLDB: volume name is illegal\n");
279 fprintf(STDERR, "VLDB: index was out of range\n");
282 fprintf(STDERR, "VLDB: bad volume type\n");
285 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
287 case VL_BADPARTITION:
288 fprintf(STDERR, "VLDB: bad partition number\n");
291 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
294 fprintf(STDERR, "VLDB: no such repsite server exists\n");
296 case VL_DUPREPSERVER:
297 fprintf(STDERR, "VLDB: replication site server already exists\n");
300 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
303 fprintf(STDERR, "VLDB: illegal reference count number\n");
305 case VL_SIZEEXCEEDED:
306 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
309 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
311 case VL_BADVOLIDBUMP:
312 fprintf(STDERR, "VLDB: illegal max volid increment\n");
314 case VL_IDALREADYHASHED:
315 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
318 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
321 fprintf(STDERR, "VLDB: bad volume operation code\n");
323 case VL_BADRELLOCKTYPE:
324 fprintf(STDERR, "VLDB: bad release lock type\n");
327 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
329 case VL_BADSERVERFLAG:
330 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
333 fprintf(STDERR, "VLDB: no permission access for call\n");
335 case VOLSERREAD_DUMPERROR:
337 "VOLSER: Problems encountered in reading the dump file !\n");
339 case VOLSERDUMPERROR:
340 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
342 case VOLSERATTACH_ERROR:
343 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
345 case VOLSERDETACH_ERROR:
346 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
348 case VOLSERILLEGAL_PARTITION:
349 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
351 case VOLSERBAD_ACCESS:
352 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
354 case VOLSERVLDB_ERROR:
355 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
358 fprintf(STDERR, "VOLSER: error in volume name\n");
361 fprintf(STDERR, "VOLSER: volume has moved\n");
364 fprintf(STDERR, "VOLSER: illegal operation\n");
366 case VOLSERBADRELEASE:
367 fprintf(STDERR, "VOLSER: release could not be completed\n");
370 fprintf(STDERR, "VOLSER: volume is busy\n");
372 case VOLSERNO_MEMORY:
373 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
377 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
379 case VOLSERMULTIRWVOL:
381 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
385 "VOLSER: not all entries were successfully processed\n");
389 initialize_RXK_error_table();
390 initialize_KTC_error_table();
391 initialize_ACFG_error_table();
392 initialize_VL_error_table();
394 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
395 afs_error_message(errcode));
402 void init_volintInfo(struct volintInfo *vinfo) {
403 memset(vinfo, 0, sizeof(struct volintInfo));
405 vinfo->maxquota = -1;
407 vinfo->creationDate = -1;
408 vinfo->updateDate = -1;
416 static struct rx_securityClass *uvclass = 0;
417 static int uvindex = -1;
418 /* called by VLDBClient_Init to set the security module to be used in the RPC */
420 UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
427 /* bind to volser on <port> <aserver> */
428 /* takes server address in network order, port in host order. dumb */
429 struct rx_connection *
430 UV_Bind(afs_uint32 aserver, afs_int32 port)
432 struct rx_connection *tc;
434 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
440 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
441 afs_int32 partition, char *name, afs_int32 type,
442 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
447 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
449 if (code != VOLSERVOLBUSY)
452 #ifdef AFS_PTHREAD_ENV
455 IOMGR_Sleep(3-retries);
462 AFSVolTransCreate_retry(struct rx_connection *z_conn,
463 afs_int32 volume, afs_int32 partition,
464 afs_int32 flags, afs_int32 * trans)
469 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
470 if (code != VOLSERVOLBUSY)
473 #ifdef AFS_PTHREAD_ENV
476 IOMGR_Sleep(3-retries);
483 /* if <okvol> is allright(indicated by beibg able to
484 * start a transaction, delete the <delvol> */
486 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
487 afs_uint32 okvol, afs_uint32 delvol)
489 afs_int32 error, code, tid, rcode;
494 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
497 code = AFSVolDeleteVolume(aconn, tid);
500 code = AFSVolEndTrans(aconn, tid, &rcode);
507 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
509 code = AFSVolEndTrans(aconn, tid, &rcode);
514 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
517 code = AFSVolDeleteVolume(aconn, tid);
520 code = AFSVolEndTrans(aconn, tid, &rcode);
533 /* called by EmuerateEntry, show vldb entry in a reasonable format */
535 SubEnumerateEntry(struct nvldbentry *entry)
543 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
544 if (entry->flags & RW_EXISTS)
545 fprintf(STDOUT, " valid \n");
547 fprintf(STDOUT, " invalid \n");
548 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
549 if (entry->flags & RO_EXISTS)
550 fprintf(STDOUT, " valid \n");
552 fprintf(STDOUT, " invalid \n");
553 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
554 if (entry->flags & BACK_EXISTS)
555 fprintf(STDOUT, " valid \n");
557 fprintf(STDOUT, " invalid \n");
558 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
559 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
561 if (entry->flags & RW_EXISTS)
562 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
563 if (entry->flags & RO_EXISTS)
564 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
565 if (entry->flags & BACK_EXISTS)
566 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
567 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
568 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
569 fprintf(STDOUT, "\n");
571 fprintf(STDOUT, " number of sites -> %lu\n",
572 (unsigned long)entry->nServers);
573 for (i = 0; i < entry->nServers; i++) {
574 if (entry->serverFlags[i] & NEW_REPSITE)
577 for (i = 0; i < entry->nServers; i++) {
578 MapPartIdIntoName(entry->serverPartition[i], pname);
579 fprintf(STDOUT, " server %s partition %s ",
580 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
581 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
582 if (entry->serverFlags[i] & ITSRWVOL)
583 fprintf(STDOUT, "RW Site ");
585 fprintf(STDOUT, "RO Site ");
587 if (entry->serverFlags[i] & NEW_REPSITE)
588 fprintf(STDOUT," -- New release");
590 if (!(entry->serverFlags[i] & ITSRWVOL))
591 fprintf(STDOUT," -- Old release");
593 if (entry->serverFlags[i] & RO_DONTUSE)
594 fprintf(STDOUT, " -- Not released");
596 fprintf(STDOUT, "\n");
603 /*enumerate the vldb entry corresponding to <entry> */
605 EnumerateEntry(struct nvldbentry *entry)
608 fprintf(STDOUT, "\n");
609 fprintf(STDOUT, "%s \n", entry->name);
610 SubEnumerateEntry(entry);
614 /* forcibly remove a volume. Very dangerous call */
616 UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
618 struct rx_connection *tconn;
621 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
623 code = AFSVolNukeVolume(tconn, partid, volid);
624 rx_DestroyConnection(tconn);
630 /* like df. Return usage of <pname> on <server> in <partition> */
632 UV_PartitionInfo64(afs_uint32 server, char *pname,
633 struct diskPartition64 *partition)
635 struct rx_connection *aconn;
638 aconn = (struct rx_connection *)0;
639 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
640 code = AFSVolPartitionInfo64(aconn, pname, partition);
641 if (code == RXGEN_OPCODE) {
642 struct diskPartition *dpp =
643 (struct diskPartition *)malloc(sizeof(struct diskPartition));
644 code = AFSVolPartitionInfo(aconn, pname, dpp);
646 strncpy(partition->name, dpp->name, 32);
647 strncpy(partition->devName, dpp->devName, 32);
648 partition->lock_fd = dpp->lock_fd;
649 partition->free = dpp->free;
650 partition->minFree = dpp->minFree;
655 fprintf(STDERR, "Could not get information on partition %s\n", pname);
656 PrintError("", code);
659 rx_DestroyConnection(aconn);
663 /* old interface to create volumes */
665 UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
670 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
674 /* less old interface to create volumes */
676 UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
677 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
678 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
680 afs_uint32 roid = 0, bkid = 0;
681 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
682 aspare3, aspare4, anewid, &roid, &bkid);
686 * Create a volume on the given server and partition
688 * @param aserver server to create volume on
689 * @param spart partition to create volume on
690 * @param aname name of new volume
691 * @param aquota quota for new volume
692 * @param anewid contains the desired volume id for the new volume. If
693 * *anewid == 0, a new id will be chosen, and will be placed
694 * in *anewid when UV_CreateVolume3 returns.
695 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
696 * will be unset. If *aroid == 0, an id will be chosen, and
697 * will be placed in *anewid when UV_CreateVolume3 returns.
698 * @param abkid same as aroid, except for the BK volume id instead of the
700 * @return 0 on success, error code otherwise.
703 UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
704 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
705 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
706 afs_uint32 * aroid, afs_uint32 * abkid)
708 struct rx_connection *aconn;
712 afs_int32 rcode, vcode;
714 struct nvldbentry entry, storeEntry; /*the new vldb entry */
715 struct volintInfo tstatus;
718 aconn = (struct rx_connection *)0;
721 init_volintInfo(&tstatus);
722 tstatus.maxquota = aquota;
724 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
726 if (aroid && *aroid) {
727 VPRINT1("Using RO volume ID %d.\n", *aroid);
729 if (abkid && *abkid) {
730 VPRINT1("Using BK volume ID %d.\n", *abkid);
734 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
736 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
739 VPRINT1("Using volume ID %d.\n", *anewid);
741 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
742 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
744 if (aroid && *aroid == 0) {
745 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
746 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
749 if (abkid && *abkid == 0) {
750 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
751 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
755 /* rw,ro, bk id are related in the default case */
756 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
758 if (aroid && *aroid == 0) {
761 if (abkid && *abkid == 0) {
766 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
767 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
770 code = AFSVolSetInfo(aconn, tid, &tstatus);
772 EPRINT(code, "Could not change quota, continuing...\n");
774 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
775 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
778 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
780 /* set up the vldb entry for this volume */
781 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
783 entry.serverNumber[0] = aserver; /* this should have another
784 * level of indirection later */
785 entry.serverPartition[0] = apart; /* this should also have
786 * another indirection level */
787 entry.flags = RW_EXISTS; /* this records that rw volume exists */
788 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
789 entry.volumeId[RWVOL] = *anewid;
790 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
791 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
793 /*map into right byte order, before passing to xdr, the stuff has to be in host
794 * byte order. Xdr converts it into network order */
795 MapNetworkToHost(&entry, &storeEntry);
796 /* create the vldb entry */
797 vcode = VLDB_CreateEntry(&storeEntry);
800 "Could not create a VLDB entry for the volume %s %lu\n",
801 aname, (unsigned long)*anewid);
802 /*destroy the created volume */
803 VPRINT1("Deleting the newly created volume %u\n", *anewid);
804 AFSVolDeleteVolume(aconn, tid);
808 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
809 /* volume created, now terminate the transaction and release the connection */
810 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
811 * the volume will come online anyway when transaction timesout , so if
812 * vldb entry exists then the volume is guaranteed to exist too wrt create */
816 "Failed to end the transaction on the volume %s %lu\n", aname,
817 (unsigned long)*anewid);
824 code = AFSVolEndTrans(aconn, tid, &rcode);
826 fprintf(STDERR, "WARNING: could not end transaction\n");
829 rx_DestroyConnection(aconn);
830 PrintError("", error);
834 /* create a volume, given a server, partition number, volume name --> sends
835 * back new vol id in <anewid>*/
837 UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
840 struct rx_connection *aconn;
843 struct nvldbentry entry, storeEntry; /*the new vldb entry */
845 aconn = (struct rx_connection *)0;
848 /* set up the vldb entry for this volume */
849 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
851 entry.serverNumber[0] = aserver; /* this should have another
852 * level of indirection later */
853 entry.serverPartition[0] = apart; /* this should also have
854 * another indirection level */
855 entry.flags = RW_EXISTS; /* this records that rw volume exists */
856 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
857 entry.volumeId[RWVOL] = aid;
859 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
860 entry.volumeId[BACKVOL] = *anewid + 2;
862 entry.volumeId[ROVOL] = 0;
863 entry.volumeId[BACKVOL] = 0;
866 /*map into right byte order, before passing to xdr, the stuff has to be in host
867 * byte order. Xdr converts it into network order */
868 MapNetworkToHost(&entry, &storeEntry);
869 /* create the vldb entry */
870 vcode = VLDB_CreateEntry(&storeEntry);
873 "Could not create a VLDB entry for the volume %s %lu\n",
874 aname, (unsigned long)aid);
878 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
882 rx_DestroyConnection(aconn);
883 PrintError("", error);
887 /* Delete the volume <volid>on <aserver> <apart>
888 * the physical entry gets removed from the vldb only if the ref count
892 UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
894 struct rx_connection *aconn = (struct rx_connection *)0;
896 afs_int32 code, rcode;
898 struct nvldbentry entry, storeEntry;
900 afs_int32 avoltype = -1, vtype;
901 int notondisk = 0, notinvldb = 0;
903 /* Find and read bhe VLDB entry for this volume */
904 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
906 if (code != VL_NOENT) {
907 EGOTO1(error_exit, code,
908 "Could not lock VLDB entry for the volume %u\n", avolid);
914 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
915 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
917 MapHostToNetwork(&entry);
920 EnumerateEntry(&entry);
923 /* Whether volume is in the VLDB or not. Delete the volume on disk */
924 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
925 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
927 if (code == VNOVOL) {
930 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
934 VPRINT1("Trying to delete the volume %u ...", avolid);
936 code = AFSVolDeleteVolume(aconn, ttid);
937 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
939 code = AFSVolEndTrans(aconn, ttid, &rcode);
940 code = (code ? code : rcode);
942 EGOTO1(error_exit, code,
943 "Could not end the transaction for the volume %u \n", avolid);
947 /* Now update the VLDB entry.
948 * But first, verify we have a VLDB entry.
949 * Whether volume is on disk or not. Delete the volume in VLDB.
954 if (avolid == entry.volumeId[BACKVOL]) {
955 /* Its a backup volume, modify the VLDB entry. Check that the
956 * backup volume is on the server/partition we asked to delete.
958 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
959 notinvldb = 2; /* Not on this server and partition */
963 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
965 entry.flags &= ~BACK_EXISTS;
969 else if (avolid == entry.volumeId[ROVOL]) {
970 /* Its a read-only volume, modify the VLDB entry. Check that the
971 * readonly volume is on the server/partition we asked to delete.
972 * If flags does not have RO_EIXSTS set, then this may mean the RO
973 * hasn't been released (and could exist in VLDB).
975 if (!Lp_ROMatch(aserver, apart, &entry)) {
976 notinvldb = 2; /* Not found on this server and partition */
982 "Marking the readonly volume %lu deleted in the VLDB\n",
983 (unsigned long)avolid);
985 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
987 if (!Lp_ROMatch(0, 0, &entry))
988 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
992 else if (avolid == entry.volumeId[RWVOL]) {
993 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
994 * Check that the readwrite volumes is on the server/partition we
997 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
998 notinvldb = 2; /* Not found on this server and partition */
1002 /* Delete backup if it exists */
1004 AFSVolTransCreate_retry(aconn, entry.volumeId[BACKVOL], apart,
1009 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
1010 entry.volumeId[BACKVOL]);
1013 code = AFSVolDeleteVolume(aconn, ttid);
1014 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
1015 entry.volumeId[BACKVOL]);
1017 code = AFSVolEndTrans(aconn, ttid, &rcode);
1019 code = (code ? code : rcode);
1020 EGOTO1(error_exit, code,
1021 "Could not end the transaction for the volume %u \n",
1022 entry.volumeId[BACKVOL]);
1024 fprintf(STDOUT, " done\n");
1029 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1030 (unsigned long)avolid,
1032 flags & BACK_EXISTS) ? ", and its backup volume," :
1035 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1037 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
1040 if (entry.flags & RO_EXISTS)
1041 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1045 notinvldb = 2; /* Not found on this server and partition */
1049 /* Either delete or replace the VLDB entry */
1050 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
1053 "Last reference to the VLDB entry for %lu - deleting entry\n",
1054 (unsigned long)avolid);
1055 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1056 EGOTO1(error_exit, code,
1057 "Could not delete the VLDB entry for the volume %u \n",
1060 MapNetworkToHost(&entry, &storeEntry);
1062 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1063 (LOCKREL_OPCODE | LOCKREL_AFSID |
1064 LOCKREL_TIMESTAMP));
1065 EGOTO1(error_exit, code,
1066 "Could not update the VLDB entry for the volume %u \n",
1073 EPRINT(error, "\n");
1075 if (notondisk && notinvldb) {
1076 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1077 ((notinvldb == 2) ? "on server and partition" : ""));
1079 error = VOLSERNOVOL;
1080 } else if (notondisk) {
1082 "WARNING: Volume %lu did not exist on the partition\n",
1083 (unsigned long)avolid);
1084 } else if (notinvldb) {
1085 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1086 (unsigned long)avolid,
1087 ((notinvldb == 2) ? "on server and partition" : ""));
1091 code = AFSVolEndTrans(aconn, ttid, &rcode);
1092 code = (code ? code : rcode);
1094 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1095 (unsigned long)avolid);
1096 PrintError("", code);
1104 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1105 (LOCKREL_OPCODE | LOCKREL_AFSID |
1106 LOCKREL_TIMESTAMP));
1109 "Could not release the lock on the VLDB entry for the volume %u \n",
1117 rx_DestroyConnection(aconn);
1121 /* add recovery to UV_MoveVolume */
1123 #define TESTC 0 /* set to test recovery code, clear for production */
1129 do_interrupt(void * unused)
1132 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1133 /* Avoid UNIX LWP from getting confused that our stack has suddenly
1134 * changed. This will avoid some sanity checks, but until a better way
1135 * is found, the only alternative is always crashing and burning on at
1136 * least the stack-overflow check. */
1137 lwp_cpptr->stack = NULL;
1142 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1144 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1145 fprintf(STDOUT, "enter second control-c to exit\n");
1153 sigint_handler(int x)
1155 #ifdef AFS_PTHREAD_ENV
1158 IOMGR_SoftSig(do_interrupt, 0);
1160 (void)signal(SIGINT, sigint_handler);
1163 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1164 * <atopart>. The operation is almost idempotent. The following
1165 * flags are recognized:
1167 * RV_NOCLONE - don't use a copy clone
1171 UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
1172 afs_uint32 atoserver, afs_int32 atopart, int flags)
1174 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
1175 * be changing during the move */
1176 struct rx_connection * volatile toconn;
1177 struct rx_connection * volatile fromconn;
1178 afs_int32 volatile fromtid;
1179 afs_int32 volatile totid;
1180 afs_int32 volatile clonetid;
1181 afs_uint32 volatile newVol;
1182 afs_uint32 volatile volid;
1183 afs_uint32 volatile backupId;
1184 int volatile islocked;
1189 char tmpName[VOLSER_MAXVOLNAME + 1];
1194 struct restoreCookie cookie;
1195 afs_int32 vcode, code;
1196 struct volser_status tstatus;
1197 struct destServer destination;
1199 struct nvldbentry entry, storeEntry;
1202 char in, lf; /* for test code */
1206 #ifdef ENABLE_BUGFIX_1165
1207 volEntries volumeInfo;
1208 struct volintInfo *infop = 0;
1212 fromconn = (struct rx_connection *)0;
1213 toconn = (struct rx_connection *)0;
1223 /* support control-c processing */
1226 (void)signal(SIGINT, sigint_handler);
1230 "\nThere are three tests points - verifies all code paths through recovery.\n");
1231 fprintf(STDOUT, "First test point - operation not started.\n");
1232 fprintf(STDOUT, "...test here (y, n)? ");
1234 fscanf(stdin, "%c", &in);
1235 fscanf(stdin, "%c", &lf); /* toss away */
1237 fprintf(STDOUT, "type control-c\n");
1239 fprintf(stdout, ".");
1244 /* or drop through */
1247 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1248 EGOTO1(mfail, vcode,
1249 "Could not fetch the entry for the volume %u from the VLDB \n",
1252 if (entry.volumeId[RWVOL] != afromvol) {
1253 fprintf(STDERR, "Only RW volume can be moved\n");
1257 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1258 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1261 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1262 EGOTO1(mfail, vcode,
1263 "Could not fetch the entry for the volume %u from the VLDB \n",
1266 backupId = entry.volumeId[BACKVOL];
1267 MapHostToNetwork(&entry);
1269 if (!Lp_Match(afromserver, afrompart, &entry)) {
1270 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1271 if (!Lp_Match(atoserver, atopart, &entry)) {
1272 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1273 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1274 (unsigned long)afromvol);
1275 fprintf(STDERR, "The current site is :");
1276 for (i = 0; i < entry.nServers; i++) {
1277 if (entry.serverFlags[i] == ITSRWVOL) {
1279 MapPartIdIntoName(entry.serverPartition[i], pname);
1280 fprintf(STDERR, " server %s partition %s \n",
1281 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1282 hostutil_GetNameByINet(entry.serverNumber[i]),
1287 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1288 (LOCKREL_OPCODE | LOCKREL_AFSID |
1289 LOCKREL_TIMESTAMP));
1290 EGOTO1(mfail, vcode,
1291 " Could not release lock on the VLDB entry for the volume %u \n",
1294 return VOLSERVOLMOVED;
1297 /* delete the volume afromvol on src_server */
1298 /* from-info does not exist but to-info does =>
1299 * we have already done the move, but the volume
1300 * may still be existing physically on from fileserver
1302 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1308 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITOffline,
1312 if (!code) { /* volume exists - delete it */
1313 VPRINT1("Setting flags on leftover source volume %u ...",
1316 AFSVolSetFlags(fromconn, fromtid,
1317 VTDeleteOnSalvage | VTOutOfService);
1319 "Failed to set flags on the leftover source volume %u\n",
1323 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1324 code = AFSVolDeleteVolume(fromconn, fromtid);
1326 "Failed to delete the leftover source volume %u\n",
1330 VPRINT1("Ending transaction on leftover source volume %u ...",
1332 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1337 "Could not end the transaction for the leftover source volume %u \n",
1342 /*delete the backup volume now */
1345 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
1349 if (!code) { /* backup volume exists - delete it */
1350 VPRINT1("Setting flags on leftover backup volume %u ...",
1353 AFSVolSetFlags(fromconn, fromtid,
1354 VTDeleteOnSalvage | VTOutOfService);
1356 "Failed to set flags on the backup volume %u\n", backupId);
1359 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1360 code = AFSVolDeleteVolume(fromconn, fromtid);
1362 "Could not delete the leftover backup volume %u\n",
1366 VPRINT1("Ending transaction on leftover backup volume %u ...",
1368 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1373 "Could not end the transaction for the leftover backup volume %u\n",
1383 /* From-info matches the vldb info about volid,
1384 * its ok start the move operation, the backup volume
1385 * on the old site is deleted in the process
1387 if (afrompart == atopart) {
1388 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1389 EGOTO2(mfail, error,
1390 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1391 afromserver, error);
1394 EGOTO1(mfail, VOLSERVOLMOVED,
1395 "Warning: Moving volume %u to its home partition ignored!\n",
1401 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1402 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1403 fromtid = totid = 0; /* initialize to uncreated */
1406 * clone the read/write volume locally.
1409 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1410 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1412 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1416 if (!(flags & RV_NOCLONE)) {
1417 /* Get a clone id */
1418 VPRINT1("Allocating new volume id for clone of volume %u ...",
1420 newVol = tmpVol = 0;
1421 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
1423 EGOTO1(mfail, vcode,
1424 "Could not get an ID for the clone of volume %u from the VLDB\n",
1428 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1429 VPRINT1("Cloning source volume %u ...", afromvol);
1430 strcpy(vname, "move-clone-temp");
1432 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
1434 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1439 /* lookup the name of the volume we just cloned */
1441 code = AFSVolGetName(fromconn, fromtid, &volName);
1442 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1445 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1447 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1452 "Failed to end the transaction on the source volume %u\n",
1457 * Create the destination volume
1460 if (!(flags & RV_NOCLONE)) {
1461 /* All of this is to get the fromDate */
1462 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1465 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1469 "Failed to start a transaction on the cloned volume%u\n",
1473 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1475 AFSVolSetFlags(fromconn, clonetid,
1476 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1477 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1481 /* remember time from which we've dumped the volume */
1482 VPRINT1("Getting status of cloned volume %u ...", newVol);
1483 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1485 "Failed to get the status of the cloned volume %u\n",
1489 fromDate = CLOCKADJ(tstatus.creationDate);
1491 /* With RV_NOCLONE, just do a full copy from the source */
1496 #ifdef ENABLE_BUGFIX_1165
1498 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1499 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1500 * don't use this information...
1502 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1503 volumeInfo.volEntries_len = 0;
1504 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1506 "Failed to get the volint Info of the cloned volume %u\n",
1509 infop = (volintInfo *) volumeInfo.volEntries_val;
1510 infop->maxquota = -1; /* Else it will replace the default quota */
1511 infop->creationDate = -1; /* Else it will use the source creation date */
1512 infop->updateDate = -1; /* Else it will use the source update date */
1515 /* create a volume on the target machine */
1518 code = AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &tmp);
1521 /* Delete the existing volume.
1522 * While we are deleting the volume in these steps, the transaction
1523 * we started against the cloned volume (clonetid above) will be
1524 * sitting idle. It will get cleaned up after 600 seconds
1526 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1527 code = AFSVolDeleteVolume(toconn, totid);
1529 "Could not delete the pre-existing volume %u on destination\n",
1534 ("Ending transaction on pre-existing volume %u on destination ...",
1536 code = AFSVolEndTrans(toconn, totid, &rcode);
1541 "Could not end the transaction on pre-existing volume %u on destination\n",
1546 VPRINT1("Creating the destination volume %u ...", volid);
1550 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
1554 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1558 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1562 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1564 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1566 "Failed to set the flags on the destination volume %u\n", volid);
1570 * Now dump the clone to the new volume
1573 destination.destHost = ntohl(atoserver);
1574 destination.destPort = AFSCONF_VOLUMEPORT;
1575 destination.destSSID = 1;
1577 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1578 cookie.type = RWVOL;
1579 cookie.parent = entry.volumeId[RWVOL];
1582 if (!(flags & RV_NOCLONE)) {
1583 /* Copy the clone to the new volume */
1584 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1587 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1589 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1592 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1593 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1598 "Failed to end the transaction on the cloned volume %u\n",
1604 * reattach to the main-line volume, and incrementally dump it.
1607 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1609 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
1612 "Failed to create a transaction on the source volume %u\n",
1616 /* now do the incremental */
1618 ("Doing the%s dump from source to destination for volume %u ... ",
1619 (flags & RV_NOCLONE) ? "" : " incremental",
1622 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1625 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1626 (flags & RV_NOCLONE) ? "" : " incremental");
1629 /* now adjust the flags so that the new volume becomes official */
1630 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1631 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1633 "Failed to set the flags to make old source volume offline\n");
1636 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1637 code = AFSVolSetFlags(toconn, totid, 0);
1639 "Failed to set the flags to make new source volume online\n");
1642 #ifdef ENABLE_BUGFIX_1165
1643 VPRINT1("Setting volume status on destination volume %u ...", volid);
1644 code = AFSVolSetInfo(toconn, totid, infop);
1646 "Failed to set volume status on the destination volume %u\n",
1651 /* put new volume online */
1652 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1653 code = AFSVolEndTrans(toconn, totid, &rcode);
1658 "Failed to end the transaction on the volume %u on the new site\n",
1662 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1663 MapNetworkToHost(&entry, &storeEntry);
1664 storeEntry.flags &= ~BACK_EXISTS;
1668 "Second test point - operation in progress but not complete.\n");
1669 fprintf(STDOUT, "...test here (y, n)? ");
1671 fscanf(stdin, "%c", &in);
1672 fscanf(stdin, "%c", &lf); /* toss away */
1674 fprintf(STDOUT, "type control-c\n");
1676 fprintf(stdout, ".");
1681 /* or drop through */
1684 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1686 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1687 (LOCKREL_OPCODE | LOCKREL_AFSID |
1688 LOCKREL_TIMESTAMP));
1691 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1692 storeEntry.name, (unsigned long)afromvol);
1701 "Third test point - operation complete but no cleanup.\n");
1702 fprintf(STDOUT, "...test here (y, n)? ");
1704 fscanf(stdin, "%c", &in);
1705 fscanf(stdin, "%c", &lf); /* toss away */
1707 fprintf(STDOUT, "type control-c\n");
1709 fprintf(stdout, ".");
1714 /* or drop through */
1717 /* This is tricky. File server is very stupid, and if you mark the volume
1718 * as VTOutOfService, it may mark the *good* instance (if you're moving
1719 * between partitions on the same machine) as out of service. Since
1720 * we're cleaning this code up in DEcorum, we're just going to kludge around
1721 * it for now by removing this call. */
1722 /* already out of service, just zap it now */
1724 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1727 "Failed to set the flags to make the old source volume offline\n");
1731 if (atoserver != afromserver) {
1732 /* set forwarding pointer for moved volumes */
1733 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1734 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1736 "Failed to set the forwarding pointer for the volume %u\n",
1741 VPRINT1("Deleting old volume %u on source ...", afromvol);
1742 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1743 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1747 VPRINT1("Ending transaction on old volume %u on the source ...",
1749 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1754 "Failed to end the transaction on the old volume %u on the source\n",
1758 /* Delete the backup volume on the original site */
1759 VPRINT1("Creating transaction for backup volume %u on source ...",
1763 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline, &tmp);
1767 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1769 AFSVolSetFlags(fromconn, fromtid,
1770 VTDeleteOnSalvage | VTOutOfService);
1772 "Failed to set the flags on the backup volume %u on the source\n",
1776 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1777 code = AFSVolDeleteVolume(fromconn, fromtid);
1779 "Failed to delete the backup volume %u on the source\n",
1783 VPRINT1("Ending transaction on backup volume %u on source ...",
1785 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1790 "Failed to end the transaction on the backup volume %u on the source\n",
1794 code = 0; /* no backup volume? that's okay */
1797 if (!(flags & RV_NOCLONE)) {
1798 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1801 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1805 "Failed to start a transaction on the cloned volume%u\n",
1809 /* now delete the clone */
1810 VPRINT1("Deleting the cloned volume %u ...", newVol);
1811 code = AFSVolDeleteVolume(fromconn, clonetid);
1812 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1816 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1817 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1822 "Failed to end the transaction on the cloned volume %u\n",
1831 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1832 fprintf(STDOUT, "...test here (y, n)? ");
1834 fscanf(stdin, "%c", &in);
1835 fscanf(stdin, "%c", &lf); /* toss away */
1837 fprintf(STDOUT, "type control-c\n");
1839 fprintf(stdout, ".");
1844 /* or drop through */
1847 /* normal cleanup code */
1849 if (entry.flags & RO_EXISTS)
1850 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1853 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1855 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1856 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1860 " Could not release the lock on the VLDB entry for the volume %lu \n",
1861 (unsigned long)afromvol);
1869 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1871 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1872 if (code || rcode) {
1875 "Could not end transaction on the source volume %lu\n",
1876 (unsigned long)afromvol);
1878 error = (code ? code : rcode);
1884 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1885 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1886 if (code || rcode) {
1889 "Could not end transaction on the source's clone volume %lu\n",
1890 (unsigned long)newVol);
1892 error = (code ? code : rcode);
1898 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1900 code = AFSVolEndTrans(toconn, totid, &rcode);
1904 "Could not end transaction on destination volume %lu\n",
1905 (unsigned long)afromvol);
1907 error = (code ? code : rcode);
1913 #ifdef ENABLE_BUGFIX_1165
1918 rx_DestroyConnection(fromconn);
1920 rx_DestroyConnection(toconn);
1921 PrintError("", error);
1924 /* come here only when the sky falls */
1929 "vos move: operation interrupted, cleanup in progress...\n");
1930 fprintf(STDOUT, "clear transaction contexts\n");
1934 /* unlock VLDB entry */
1936 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1937 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1938 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1944 VPRINT("Recovery: Ending transaction on clone volume ...");
1945 AFSVolEndTrans(fromconn, clonetid, &rcode);
1949 VPRINT("Recovery: Ending transaction on destination volume ...");
1950 AFSVolEndTrans(toconn, totid, &rcode);
1953 if (fromtid) { /* put it on-line */
1954 VPRINT("Recovery: Setting volume flags on source volume ...");
1955 AFSVolSetFlags(fromconn, fromtid, 0);
1958 VPRINT("Recovery: Ending transaction on source volume ...");
1959 AFSVolEndTrans(fromconn, fromtid, &rcode);
1963 VPRINT("Recovery: Accessing VLDB.\n");
1964 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1966 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1970 MapHostToNetwork(&entry);
1972 /* Delete either the volume on the source location or the target location.
1973 * If the vldb entry still points to the source location, then we know the
1974 * volume move didn't finish so we remove the volume from the target
1975 * location. Otherwise, we remove the volume from the source location.
1977 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1980 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1984 if (volid && toconn) {
1986 ("Recovery: Creating transaction for destination volume %u ...",
1990 AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &tmp);
1997 ("Recovery: Setting flags on destination volume %u ...",
1999 AFSVolSetFlags(toconn, totid,
2000 VTDeleteOnSalvage | VTOutOfService);
2003 VPRINT1("Recovery: Deleting destination volume %u ...",
2005 AFSVolDeleteVolume(toconn, totid);
2009 ("Recovery: Ending transaction on destination volume %u ...",
2011 AFSVolEndTrans(toconn, totid, &rcode);
2015 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
2020 /* put source volume on-line */
2022 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2026 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2032 VPRINT1("Recovery: Setting flags on source volume %u ...",
2034 AFSVolSetFlags(fromconn, fromtid, 0);
2038 ("Recovery: Ending transaction on source volume %u ...",
2040 AFSVolEndTrans(fromconn, fromtid, &rcode);
2044 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2048 } else { /* yep, move complete */
2051 "move complete - attempt cleanup of source partition - no guarantee\n");
2055 /* delete backup volume */
2057 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
2061 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
2067 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2069 AFSVolSetFlags(fromconn, fromtid,
2070 VTDeleteOnSalvage | VTOutOfService);
2073 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
2074 AFSVolDeleteVolume(fromconn, fromtid);
2078 ("Recovery: Ending transaction on backup volume %u ...",
2080 AFSVolEndTrans(fromconn, fromtid, &rcode);
2084 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
2088 /* delete source volume */
2089 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2093 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2099 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2101 AFSVolSetFlags(fromconn, fromtid,
2102 VTDeleteOnSalvage | VTOutOfService);
2105 if (atoserver != afromserver) {
2106 VPRINT("Recovery: Setting volume forwarding pointer ...");
2107 AFSVolSetForwarding(fromconn, fromtid, atoserver);
2111 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
2112 AFSVolDeleteVolume(fromconn, fromtid);
2116 ("Recovery: Ending transaction on source volume %u ...",
2118 AFSVolEndTrans(fromconn, fromtid, &rcode);
2122 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2128 /* common cleanup - delete local clone */
2130 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2134 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
2140 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
2141 AFSVolDeleteVolume(fromconn, clonetid);
2144 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2146 AFSVolEndTrans(fromconn, clonetid, &rcode);
2150 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2155 /* unlock VLDB entry */
2157 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2159 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2160 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2164 done: /* routine cleanup */
2167 #ifdef ENABLE_BUGFIX_1165
2172 rx_DestroyConnection(fromconn);
2174 rx_DestroyConnection(toconn);
2177 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2185 UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2186 afs_uint32 atoserver, afs_int32 atopart)
2188 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2189 atoserver, atopart, 0);
2193 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2194 * <atopart>. The new volume is named by <atovolname>. The new volume
2195 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2196 * from the VLDB. the following flags are supported:
2198 * RV_RDONLY - target volume is RO
2199 * RV_OFFLINE - leave target volume offline
2200 * RV_CPINCR - do incremental dump if target exists
2201 * RV_NOVLDB - don't create/update VLDB entry
2202 * RV_NOCLONE - don't use a copy clone
2205 UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2206 char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
2207 afs_uint32 atovolid, int flags)
2209 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
2210 * be changing during the copy */
2212 afs_int32 volatile clonetid;
2213 afs_int32 volatile totid;
2214 afs_int32 volatile fromtid;
2215 struct rx_connection * volatile fromconn;
2216 struct rx_connection * volatile toconn;
2217 afs_uint32 volatile cloneVol;
2221 afs_int32 fromDate, cloneFromDate;
2222 struct restoreCookie cookie;
2223 afs_int32 vcode, code;
2226 struct volser_status tstatus;
2227 struct destServer destination;
2228 struct nvldbentry entry, newentry, storeEntry;
2233 fromconn = (struct rx_connection *)0;
2234 toconn = (struct rx_connection *)0;
2242 /* support control-c processing */
2245 (void)signal(SIGINT, sigint_handler);
2247 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2248 EGOTO1(mfail, vcode,
2249 "Could not fetch the entry for the volume %u from the VLDB \n",
2251 MapHostToNetwork(&entry);
2254 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2255 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2256 fromtid = totid = 0; /* initialize to uncreated */
2259 * clone the read/write volume locally.
2263 if (!(flags & RV_NOCLONE)) {
2264 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2266 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2269 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2273 /* Get a clone id */
2274 VPRINT1("Allocating new volume id for clone of volume %u ...",
2278 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
2280 EGOTO1(mfail, vcode,
2281 "Could not get an ID for the clone of volume %u from the VLDB\n",
2289 /* Get a new volume id */
2290 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2292 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2293 EGOTO1(mfail, vcode,
2294 "Could not get an ID for the copy of volume %u from the VLDB\n",
2299 if (!(flags & RV_NOCLONE)) {
2300 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2301 VPRINT1("Cloning source volume %u ...", afromvol);
2302 strcpy(vname, "copy-clone-temp");
2305 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2308 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2312 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2314 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2319 "Failed to end the transaction on the source volume %u\n",
2325 * Create the destination volume
2328 if (!(flags & RV_NOCLONE)) {
2329 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2332 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2336 "Failed to start a transaction on the cloned volume%u\n",
2340 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2342 AFSVolSetFlags(fromconn, clonetid,
2343 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2344 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2348 /* remember time from which we've dumped the volume */
2349 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2350 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2352 "Failed to get the status of the cloned volume %u\n",
2356 fromDate = CLOCKADJ(tstatus.creationDate);
2361 /* create a volume on the target machine */
2364 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
2367 if ((flags & RV_CPINCR)) {
2368 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2369 code = AFSVolGetStatus(toconn, totid, &tstatus);
2371 "Failed to get the status of the pre-existing volume %u\n",
2375 /* Using the update date should be OK here, but add some fudge */
2376 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2377 if ((flags & RV_NOCLONE))
2378 fromDate = cloneFromDate;
2380 /* XXX We should check that the source volume's creationDate is
2381 * XXX not newer than the existing target volume, and if not,
2382 * XXX throw away the existing target and do a full dump. */
2387 /* Delete the existing volume.
2388 * While we are deleting the volume in these steps, the transaction
2389 * we started against the cloned volume (clonetid above) will be
2390 * sitting idle. It will get cleaned up after 600 seconds
2392 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2393 code = AFSVolDeleteVolume(toconn, totid);
2395 "Could not delete the pre-existing volume %u on destination\n",
2400 ("Ending transaction on pre-existing volume %u on destination ...",
2402 code = AFSVolEndTrans(toconn, totid, &rcode);
2407 "Could not end the transaction on pre-existing volume %u on destination\n",
2412 VPRINT1("Creating the destination volume %u ...", newVol);
2415 AFSVolCreateVolume(toconn, atopart, atovolname,
2416 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2417 newVol, &newVol, &tmp);
2419 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2423 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2425 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2427 "Failed to set the flags on the destination volume %u\n", newVol);
2432 destination.destHost = ntohl(atoserver);
2433 destination.destPort = AFSCONF_VOLUMEPORT;
2434 destination.destSSID = 1;
2436 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2437 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2442 * Now dump the clone to the new volume
2445 if (!(flags & RV_NOCLONE)) {
2446 /* XXX probably should have some code here that checks to see if
2447 * XXX we are copying to same server and partition - if so, just
2448 * XXX use a clone to save disk space */
2450 /* Copy the clone to the new volume */
2451 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2454 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2456 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2460 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2461 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2466 "Failed to end the transaction on the cloned volume %u\n",
2472 * reattach to the main-line volume, and incrementally dump it.
2475 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2477 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
2480 "Failed to create a transaction on the source volume %u\n",
2484 /* now do the incremental */
2486 ("Doing the%s dump from source to destination for volume %u ... ",
2487 (flags & RV_NOCLONE) ? "" : " incremental",
2490 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2493 "Failed to do the%s dump from old site to new site\n",
2494 (flags & RV_NOCLONE) ? "" : " incremental");
2497 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2498 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2499 code = AFSVolSetFlags(toconn, totid, volflag);
2501 "Failed to set the flags to make destination volume online\n");
2504 /* put new volume online */
2505 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2506 code = AFSVolEndTrans(toconn, totid, &rcode);
2511 "Failed to end the transaction on the destination volume %u\n",
2515 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2516 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2521 "Failed to end the transaction on the source volume %u\n",
2527 if (!(flags & RV_NOCLONE)) {
2528 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2531 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2535 "Failed to start a transaction on the cloned volume%u\n",
2539 /* now delete the clone */
2540 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2541 code = AFSVolDeleteVolume(fromconn, clonetid);
2542 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2546 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2547 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2552 "Failed to end the transaction on the cloned volume %u\n",
2557 if (!(flags & RV_NOVLDB)) {
2558 /* create the vldb entry for the copied volume */
2559 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2560 newentry.nServers = 1;
2561 newentry.serverNumber[0] = atoserver;
2562 newentry.serverPartition[0] = atopart;
2563 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2564 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2565 newentry.volumeId[RWVOL] = newVol;
2566 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2567 newentry.volumeId[BACKVOL] = 0;
2568 newentry.cloneId = 0;
2569 /*map into right byte order, before passing to xdr, the stuff has to be in host
2570 * byte order. Xdr converts it into network order */
2571 MapNetworkToHost(&newentry, &storeEntry);
2572 /* create the vldb entry */
2573 vcode = VLDB_CreateEntry(&storeEntry);
2576 "Could not create a VLDB entry for the volume %s %lu\n",
2577 atovolname, (unsigned long)newVol);
2578 /*destroy the created volume */
2579 VPRINT1("Deleting the newly created volume %u\n", newVol);
2580 AFSVolDeleteVolume(toconn, totid);
2584 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2588 /* normal cleanup code */
2591 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2593 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2594 if (code || rcode) {
2597 "Could not end transaction on the source volume %lu\n",
2598 (unsigned long)afromvol);
2600 error = (code ? code : rcode);
2606 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2608 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2609 if (code || rcode) {
2612 "Could not end transaction on the source's clone volume %lu\n",
2613 (unsigned long)cloneVol);
2615 error = (code ? code : rcode);
2621 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2623 code = AFSVolEndTrans(toconn, totid, &rcode);
2627 "Could not end transaction on destination volume %lu\n",
2628 (unsigned long)newVol);
2630 error = (code ? code : rcode);
2635 rx_DestroyConnection(fromconn);
2637 rx_DestroyConnection(toconn);
2638 PrintError("", error);
2641 /* come here only when the sky falls */
2646 "vos copy: operation interrupted, cleanup in progress...\n");
2647 fprintf(STDOUT, "clear transaction contexts\n");
2652 VPRINT("Recovery: Ending transaction on clone volume ...");
2653 AFSVolEndTrans(fromconn, clonetid, &rcode);
2657 VPRINT("Recovery: Ending transaction on destination volume ...");
2658 AFSVolEndTrans(toconn, totid, &rcode);
2661 if (fromtid) { /* put it on-line */
2662 VPRINT("Recovery: Ending transaction on source volume ...");
2663 AFSVolEndTrans(fromconn, fromtid, &rcode);
2667 VPRINT("Recovery: Accessing VLDB.\n");
2668 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2670 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2674 MapHostToNetwork(&entry);
2676 /* common cleanup - delete local clone */
2678 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2682 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2688 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2689 AFSVolDeleteVolume(fromconn, clonetid);
2692 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2694 AFSVolEndTrans(fromconn, clonetid, &rcode);
2698 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2703 done: /* routine cleanup */
2705 rx_DestroyConnection(fromconn);
2707 rx_DestroyConnection(toconn);
2710 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2718 UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
2719 char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
2721 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2722 atovolname, atoserver, atopart, 0, 0);
2727 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2728 * if one already exists, update it
2732 UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
2734 struct rx_connection *aconn = (struct rx_connection *)0;
2735 afs_int32 ttid = 0, btid = 0;
2736 afs_uint32 backupID;
2737 afs_int32 code = 0, rcode = 0;
2738 char vname[VOLSER_MAXVOLNAME + 1];
2739 struct nvldbentry entry, storeEntry;
2740 afs_int32 error = 0;
2741 int vldblocked = 0, vldbmod = 0, backexists = 1;
2743 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2745 /* the calls to VLDB will succeed only if avolid is a RW volume,
2746 * since we are following the RW hash chain for searching */
2747 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2750 "Could not fetch the entry for the volume %lu from the VLDB \n",
2751 (unsigned long)avolid);
2755 MapHostToNetwork(&entry);
2757 /* These operations require the VLDB be locked since it means the VLDB
2758 * will change or the vldb is already locked.
2760 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2761 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2762 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2764 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2767 "Could not lock the VLDB entry for the volume %lu\n",
2768 (unsigned long)avolid);
2774 /* Reread the vldb entry */
2775 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2778 "Could not fetch the entry for the volume %lu from the VLDB \n",
2779 (unsigned long)avolid);
2783 MapHostToNetwork(&entry);
2786 if (!ISNAMEVALID(entry.name)) {
2787 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2789 error = VOLSERBADNAME;
2793 backupID = entry.volumeId[BACKVOL];
2794 if (backupID == INVALID_BID) {
2795 /* Get a backup volume id from the VLDB and update the vldb
2798 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2801 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2802 (unsigned long)avolid);
2806 entry.volumeId[BACKVOL] = backupID;
2810 /* Test to see if the backup volume exists by trying to create
2811 * a transaction on the backup volume. We've assumed the backup exists.
2813 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2815 if (code != VNOVOL) {
2816 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2817 (unsigned long)backupID);
2821 backexists = 0; /* backup volume does not exist */
2824 code = AFSVolEndTrans(aconn, btid, &rcode);
2826 if (code || rcode) {
2828 "Could not end transaction on the previous backup volume %lu\n",
2829 (unsigned long)backupID);
2830 error = (code ? code : rcode);
2835 /* Now go ahead and try to clone the RW volume.
2836 * First start a transaction on the RW volume
2838 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
2840 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2841 (unsigned long)avolid);
2846 /* Clone or reclone the volume, depending on whether the backup
2847 * volume exists or not
2850 VPRINT1("Re-cloning backup volume %u ...", backupID);
2852 code = AFSVolReClone(aconn, ttid, backupID);
2854 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2855 (unsigned long)backupID);
2860 VPRINT1("Creating a new backup clone %u ...", backupID);
2862 strcpy(vname, entry.name);
2863 strcat(vname, ".backup");
2865 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2867 fprintf(STDERR, "Failed to clone the volume %lu\n",
2868 (unsigned long)avolid);
2874 /* End the transaction on the RW volume */
2875 code = AFSVolEndTrans(aconn, ttid, &rcode);
2877 if (code || rcode) {
2879 "Failed to end the transaction on the rw volume %lu\n",
2880 (unsigned long)avolid);
2881 error = (code ? code : rcode);
2885 /* Mork vldb as backup exists */
2886 if (!(entry.flags & BACK_EXISTS)) {
2887 entry.flags |= BACK_EXISTS;
2891 /* Now go back to the backup volume and bring it on line */
2892 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2895 "Failed to start a transaction on the backup volume %lu\n",
2896 (unsigned long)backupID);
2901 code = AFSVolSetFlags(aconn, btid, 0);
2903 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2904 (unsigned long)backupID);
2909 code = AFSVolEndTrans(aconn, btid, &rcode);
2911 if (code || rcode) {
2913 "Failed to end the transaction on the backup volume %lu\n",
2914 (unsigned long)backupID);
2915 error = (code ? code : rcode);
2921 /* Will update the vldb below */
2925 code = AFSVolEndTrans(aconn, ttid, &rcode);
2926 if (code || rcode) {
2927 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2928 (unsigned long)avolid);
2930 error = (code ? code : rcode);
2935 code = AFSVolEndTrans(aconn, btid, &rcode);
2936 if (code || rcode) {
2938 "Could not end transaction the backup volume %lu\n",
2939 (unsigned long)backupID);
2941 error = (code ? code : rcode);
2945 /* Now update the vldb - if modified */
2948 MapNetworkToHost(&entry, &storeEntry);
2950 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2951 (LOCKREL_OPCODE | LOCKREL_AFSID |
2952 LOCKREL_TIMESTAMP));
2955 "Could not update the VLDB entry for the volume %lu \n",
2956 (unsigned long)avolid);
2962 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2963 (LOCKREL_OPCODE | LOCKREL_AFSID |
2964 LOCKREL_TIMESTAMP));
2967 "Could not unlock the VLDB entry for the volume %lu \n",
2968 (unsigned long)avolid);
2976 rx_DestroyConnection(aconn);
2978 PrintError("", error);
2982 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2983 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2984 * The new volume is named by <aname>, or by appending ".clone" to
2985 * the existing name if <aname> is NULL. The following flags are
2988 * RV_RDONLY - target volume is RO
2989 * RV_OFFLINE - leave target volume offline
2993 UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
2994 afs_uint32 acloneid, char *aname, int flags)
2996 struct rx_connection *aconn = (struct rx_connection *)0;
2997 afs_int32 ttid = 0, btid = 0;
2998 afs_int32 code = 0, rcode = 0;
2999 char vname[VOLSER_MAXVOLNAME + 1];
3000 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 /* Test to see if the clone volume exists by trying to create
3038 * a transaction on the clone volume. We've assumed the clone exists.
3040 /* XXX I wonder what happens if the clone has some other parent... */
3041 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3043 if (code != VNOVOL) {
3044 fprintf(STDERR, "Could not reach the clone volume %lu\n",
3045 (unsigned long)acloneid);
3049 backexists = 0; /* backup volume does not exist */
3052 code = AFSVolEndTrans(aconn, btid, &rcode);
3054 if (code || rcode) {
3056 "Could not end transaction on the previous clone volume %lu\n",
3057 (unsigned long)acloneid);
3058 error = (code ? code : rcode);
3063 /* Now go ahead and try to clone the RW volume.
3064 * First start a transaction on the RW volume
3066 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
3068 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
3069 (unsigned long)avolid);
3074 /* Clone or reclone the volume, depending on whether the backup
3075 * volume exists or not
3078 VPRINT1("Re-cloning clone volume %u ...", acloneid);
3080 code = AFSVolReClone(aconn, ttid, acloneid);
3082 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
3083 (unsigned long)acloneid);
3088 VPRINT1("Creating a new clone %u ...", acloneid);
3090 if (flags & RV_RWONLY)
3091 type = readwriteVolume;
3092 else if (flags & RV_RDONLY)
3093 type = readonlyVolume;
3095 type = backupVolume;
3097 code = AFSVolClone(aconn, ttid, 0, type, aname, &acloneid);
3099 fprintf(STDERR, "Failed to clone the volume %lu\n",
3100 (unsigned long)avolid);
3106 /* End the transaction on the RW volume */
3107 code = AFSVolEndTrans(aconn, ttid, &rcode);
3109 if (code || rcode) {
3111 "Failed to end the transaction on the rw volume %lu\n",
3112 (unsigned long)avolid);
3113 error = (code ? code : rcode);
3117 /* Now go back to the backup volume and bring it on line */
3118 if (!(flags & RV_OFFLINE)) {
3119 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3122 "Failed to start a transaction on the clone volume %lu\n",
3123 (unsigned long)acloneid);
3128 code = AFSVolSetFlags(aconn, btid, 0);
3130 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3131 (unsigned long)acloneid);
3136 code = AFSVolEndTrans(aconn, btid, &rcode);
3138 if (code || rcode) {
3140 "Failed to end the transaction on the clone volume %lu\n",
3141 (unsigned long)acloneid);
3142 error = (code ? code : rcode);
3151 code = AFSVolEndTrans(aconn, ttid, &rcode);
3152 if (code || rcode) {
3153 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3154 (unsigned long)avolid);
3156 error = (code ? code : rcode);
3161 code = AFSVolEndTrans(aconn, btid, &rcode);
3162 if (code || rcode) {
3164 "Could not end transaction on the clone volume %lu\n",
3165 (unsigned long)acloneid);
3167 error = (code ? code : rcode);
3172 rx_DestroyConnection(aconn);
3174 PrintError("", error);
3179 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
3182 afs_int32 acode, ccode, rcode, tid;
3183 ccode = rcode = tid = 0;
3185 acode = AFSVolTransCreate_retry(conn, vid, part, flags, &tid);
3186 if (!acode) { /* It really was there */
3187 acode = AFSVolDeleteVolume(conn, tid);
3189 fprintf(STDERR, "Failed to delete volume %lu.\n",
3190 (unsigned long)vid);
3191 PrintError("", acode);
3193 ccode = AFSVolEndTrans(conn, tid, &rcode);
3197 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3198 (unsigned long)vid);
3199 PrintError("", ccode);
3206 #define ONERROR(ec, ep, es) do { \
3208 fprintf(STDERR, (es), (ep)); \
3213 #define ONERROR0(ec, es) do { \
3215 fprintf(STDERR, (es)); \
3220 #define ERROREXIT(ec) do { \
3225 /* Get a "transaction" on this replica. Create the volume
3226 * if necessary. Return the time from which a dump should
3227 * be made (0 if it's a new volume)
3230 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3231 struct rx_connection **connPtr, afs_int32 * transPtr,
3232 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
3233 afs_int32 *origflags)
3236 struct volser_status tstatus;
3241 *connPtr = (struct rx_connection *)0;
3246 /* get connection to the replication site */
3247 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3249 goto fail; /* server is down */
3251 volid = vldbEntryPtr->volumeId[ROVOL];
3254 AFSVolTransCreate_retry(*connPtr, volid,
3255 vldbEntryPtr->serverPartition[index], ITOffline,
3258 if (!code && (origflags[index] & RO_DONTUSE)) {
3259 /* If RO_DONTUSE is set, this is supposed to be an entirely new
3260 * site. Don't trust any data on it, since it is possible we
3261 * have encountered some temporary volume from some other
3262 * incomplete volume operation. It is difficult to detect if
3263 * that has happened vs if this is a legit volume, so just
3264 * delete it to be safe. */
3266 VPRINT1("Deleting extant RO_DONTUSE site on %s...",
3267 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3268 serverNumber[index], hoststr) :
3269 hostutil_GetNameByINet(vldbEntryPtr->
3270 serverNumber[index]));
3272 code = AFSVolDeleteVolume(*connPtr, *transPtr);
3274 PrintError("Failed to delete RO_DONTUSE site: ", code);
3278 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3284 PrintError("Failed to end transaction on RO_DONTUSE site: ",
3291 /* emulate what TransCreate would have returned, so we try to
3292 * create the volume below */
3297 /* If the volume does not exist, create it */
3298 if (!volid || code) {
3302 if (volid && (code != VNOVOL)) {
3303 PrintError("Failed to start a transaction on the RO volume.\n",
3308 strcpy(volname, vldbEntryPtr->name);
3309 strcat(volname, ".readonly");
3313 "Creating new volume %lu on replication site %s: ",
3314 (unsigned long)volid,
3315 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3316 serverNumber[index], hoststr) :
3317 hostutil_GetNameByINet(vldbEntryPtr->
3318 serverNumber[index]));
3323 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3325 vldbEntryPtr->volumeId[RWVOL], &volid,
3328 PrintError("Failed to create the ro volume: ", code);
3331 vldbEntryPtr->volumeId[ROVOL] = volid;
3335 /* The following is a bit redundant, since create sets these flags by default */
3337 AFSVolSetFlags(*connPtr, *transPtr,
3338 VTDeleteOnSalvage | VTOutOfService);
3340 PrintError("Failed to set flags on the ro volume: ", code);
3345 /* Otherwise, the transaction did succeed, so get the creation date of the
3346 * latest RO volume on the replication site
3349 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3350 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3351 serverNumber[index], hoststr) :
3352 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3354 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3356 PrintError("Failed to get status of volume on destination: ",
3360 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3361 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3368 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3373 PrintError("Could not end transaction on a ro volume: ", tcode);
3380 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3381 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3382 void *cookie, manyResults * results)
3386 for (i = 0; i < tr->manyDests_len; i++) {
3387 results->manyResults_val[i] =
3388 AFSVolForward(fromconn, fromtid, fromdate,
3389 &(tr->manyDests_val[i].server),
3390 tr->manyDests_val[i].trans, cookie);
3396 * Check if a trans has timed out, and recreate it if necessary.
3398 * @param[in] aconn RX connection to the relevant server
3399 * @param[inout] atid Transaction ID to check; if we recreated the trans,
3400 * contains the new trans ID on success
3401 * @param[in] apart Partition for the transaction
3402 * @param[in] astat The status of the original transaction
3404 * @return operation status
3405 * @retval 0 existing transaction is still valid, or we managed to recreate
3406 * the trans successfully
3407 * @retval nonzero Fatal error; bail out
3410 CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart,
3411 struct volser_status *astat)
3413 struct volser_status new_status;
3416 memset(&new_status, 0, sizeof(new_status));
3417 code = AFSVolGetStatus(aconn, *atid, &new_status);
3419 if (code == ENOENT) {
3421 VPRINT1("Old transaction on cloned volume %lu timed out, "
3422 "restarting transaction\n", (long unsigned) astat->volID);
3423 code = AFSVolTransCreate_retry(aconn, astat->volID, apart,
3426 PrintError("Failed to recreate cloned RO volume transaction\n",
3431 memset(&new_status, 0, sizeof(new_status));
3432 code = AFSVolGetStatus(aconn, *atid, &new_status);
3434 PrintError("Failed to get status on recreated transaction\n",
3439 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3440 PrintError("Recreated transaction on cloned RO volume, but "
3441 "the volume has changed!\n", 0);
3445 PrintError("Unable to get status of current cloned RO transaction\n",
3450 if (memcmp(&new_status, astat, sizeof(new_status)) != 0) {
3452 PrintError("Internal error: current GetStatus does not match "
3453 "original GetStatus?\n", 0);
3462 /* UV_ReleaseVolume()
3463 * Release volume <afromvol> on <afromserver> <afrompart> to all
3464 * its RO sites (full release). Unless the previous release was
3465 * incomplete: in which case we bring the remaining incomplete
3466 * volumes up to date with the volumes that were released
3468 * forceflag: Performs a full release.
3470 * Will create a clone from the RW, then dump the clone out to
3471 * the remaining replicas. If there is more than 1 RO sites,
3472 * ensure that the VLDB says at least one RO is available all
3473 * the time: Influences when we write back the VLDB entry.
3477 UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
3478 afs_int32 afrompart, int forceflag)
3482 afs_int32 vcode, rcode, tcode;
3483 afs_uint32 cloneVolId, roVolId;
3484 struct replica *replicas = 0;
3485 struct nvldbentry entry, storeEntry;
3486 int i, volcount, m, fullrelease, vldbindex;
3488 struct restoreCookie cookie;
3489 struct rx_connection **toconns = 0;
3490 struct release *times = 0;
3492 struct rx_connection *fromconn = (struct rx_connection *)0;
3493 afs_int32 error = 0;
3495 afs_int32 clonetid = 0, onlinetid;
3496 afs_int32 fromtid = 0;
3497 afs_uint32 fromdate = 0;
3498 afs_uint32 thisdate;
3502 manyResults results;
3503 int rwindex, roindex, roclone, roexists;
3504 afs_uint32 rwcrdate = 0;
3505 afs_uint32 clcrdate;
3509 } remembertime[NMAXNSERVERS];
3510 int releasecount = 0;
3511 struct volser_status volstatus;
3513 afs_int32 origflags[NMAXNSERVERS];
3514 struct volser_status orig_status;
3516 memset(remembertime, 0, sizeof(remembertime));
3517 memset(&results, 0, sizeof(results));
3518 memset(origflags, 0, sizeof(origflags));
3520 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3521 if (vcode != VL_RERELEASE)
3522 ONERROR(vcode, afromvol,
3523 "Could not lock the VLDB entry for the volume %u.\n");
3526 /* Get the vldb entry in readable format */
3527 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3528 ONERROR(vcode, afromvol,
3529 "Could not fetch the entry for the volume %u from the VLDB.\n");
3530 MapHostToNetwork(&entry);
3533 EnumerateEntry(&entry);
3535 if (!ISNAMEVALID(entry.name))
3536 ONERROR(VOLSERBADOP, entry.name,
3537 "Volume name %s is too long, rename before releasing.\n");
3538 if (entry.volumeId[RWVOL] != afromvol)
3539 ONERROR(VOLSERBADOP, afromvol,
3540 "The volume %u being released is not a read-write volume.\n");
3541 if (entry.nServers <= 1)
3542 ONERROR(VOLSERBADOP, afromvol,
3543 "Volume %u has no replicas - release operation is meaningless!\n");
3544 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3545 ONERROR(VOLSERBADOP, entry.name,
3546 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3548 /* roclone is true if one of the RO volumes is on the same
3549 * partition as the RW volume. In this case, we make the RO volume
3550 * on the same partition a clone instead of a complete copy.
3553 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3554 roclone = ((roindex == -1) ? 0 : 1);
3555 rwindex = Lp_GetRwIndex(&entry);
3557 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3559 /* Make sure we have a RO volume id to work with */
3560 if (entry.volumeId[ROVOL] == INVALID_BID) {
3561 /* need to get a new RO volume id */
3562 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3563 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3565 entry.volumeId[ROVOL] = roVolId;
3566 MapNetworkToHost(&entry, &storeEntry);
3567 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3568 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3571 /* Will we be completing a previously unfinished release. -force overrides */
3572 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3573 if (entry.serverFlags[i] & ITSROVOL) {
3575 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3577 origflags[i] = entry.serverFlags[i];
3579 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3582 /* Determine which volume id to use and see if it exists */
3585 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3586 code = VolumeExists(afromserver, afrompart, cloneVolId);
3587 roexists = ((code == ENODEV) ? 0 : 1);
3589 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3591 ONERROR(-1, afromserver,
3592 "Cannot establish connection with server 0x%x\n");
3596 fullrelease = 1; /* Do a full release if RO clone does not exist */
3598 /* Begin transaction on RW and mark it busy while we query it */
3599 code = AFSVolTransCreate_retry(
3600 fromconn, afromvol, afrompart, ITBusy, &fromtid
3602 ONERROR(code, afromvol,
3603 "Failed to start transaction on RW volume %u\n");
3605 /* Query the creation date for the RW */
3606 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3607 ONERROR(code, afromvol,
3608 "Failed to get the status of RW volume %u\n");
3609 rwcrdate = volstatus.creationDate;
3611 /* End transaction on RW */
3612 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3614 ONERROR((code ? code : rcode), afromvol,
3615 "Failed to end transaction on RW volume %u\n");
3617 /* Begin transaction on clone and mark it busy while we query it */
3618 code = AFSVolTransCreate_retry(
3619 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3621 ONERROR(code, cloneVolId,
3622 "Failed to start transaction on RW clone %u\n");
3624 /* Query the creation date for the clone */
3625 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3626 ONERROR(code, cloneVolId,
3627 "Failed to get the status of RW clone %u\n");
3628 clcrdate = volstatus.creationDate;
3630 /* End transaction on clone */
3631 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3633 ONERROR((code ? code : rcode), cloneVolId,
3634 "Failed to end transaction on RW clone %u\n");
3636 if (rwcrdate > clcrdate)
3637 fullrelease = 2;/* Do a full release if RO clone older than RW */
3642 switch (fullrelease) {
3644 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3645 (unsigned long)afromvol);
3648 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3649 (unsigned long)afromvol);
3652 fprintf(STDOUT, "This is a completion of a previous release\n");
3658 /* If the RO clone exists, then if the clone is a temporary
3659 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3660 * (it was recently added), then also delete it. We do not
3661 * want to "reclone" a temporary RO clone.
3664 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3665 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3666 if (code && (code != VNOVOL))
3671 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3672 * write this entry out to the vlserver until after the first
3673 * RO volume is released (temp RO clones don't count).
3675 for (i = 0; i < entry.nServers; i++) {
3676 entry.serverFlags[i] &= ~NEW_REPSITE;
3677 entry.serverFlags[i] |= RO_DONTUSE;
3679 entry.serverFlags[rwindex] |= NEW_REPSITE;
3680 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3682 /* Begin transaction on RW and mark it busy while we clone it */
3684 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
3686 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3688 /* Clone or reclone the volume */
3690 VPRINT1("Recloning RW volume %u...", cloneVolId);
3691 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3692 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3696 strcpy(vname, entry.name);
3697 strcat(vname, ".readonly");
3698 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3700 strcpy(vname, "readonly-clone-temp");
3701 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3704 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3706 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3710 /* Get the time the RW was created for future information */
3711 VPRINT1("Getting status of RW volume %u...", afromvol);
3712 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3713 ONERROR(code, afromvol,
3714 "Failed to get the status of the RW volume %u\n");
3716 rwcrdate = volstatus.creationDate;
3718 /* End the transaction on the RW volume */
3719 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3720 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3722 ONERROR((code ? code : rcode), afromvol,
3723 "Failed to end cloning transaction on RW %u\n");
3726 /* Remember clone volume ID in case we fail or are interrupted */
3727 entry.cloneId = cloneVolId;
3730 /* Bring the RO clone online - though not if it's a temporary clone */
3731 VPRINT1("Starting transaction on RO clone volume %u...",
3734 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3736 ONERROR(code, cloneVolId,
3737 "Failed to start transaction on volume %u\n");
3740 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3741 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3744 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3745 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3746 ONERROR((code ? code : rcode), cloneVolId,
3747 "Failed to end transaction on RO clone %u\n");
3750 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3752 /* Sleep so that a client searching for an online volume won't
3753 * find the clone offline and then the next RO offline while the
3754 * release brings the clone online and the next RO offline (race).
3755 * There is a fix in the 3.4 client that does not need this sleep
3756 * anymore, but we don't know what clients we have.
3758 if (entry.nServers > 2)
3761 /* Mark the RO clone in the VLDB as a good site (already released) */
3762 entry.serverFlags[roindex] |= NEW_REPSITE;
3763 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3764 entry.flags |= RO_EXISTS;
3768 /* Write out the VLDB entry only if the clone is not a temporary
3769 * clone. If we did this to a temporary clone then we would end
3770 * up marking all the ROs as "old release" making the ROs
3771 * temporarily unavailable.
3773 MapNetworkToHost(&entry, &storeEntry);
3774 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3775 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3776 ONERROR(vcode, entry.name,
3777 "Could not update vldb entry for %s.\n");
3782 /* Now we will release from the clone to the remaining RO replicas.
3783 * The first 2 ROs (counting the non-temporary RO clone) are released
3784 * individually: releasecount. This is to reduce the race condition
3785 * of clients trying to find an on-line RO volume. The remaining ROs
3786 * are released in parallel but no more than half the number of ROs
3787 * (rounded up) at a time: nservers.
3790 strcpy(vname, entry.name);
3791 strcat(vname, ".readonly");
3792 memset(&cookie, 0, sizeof(cookie));
3793 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3794 cookie.type = ROVOL;
3795 cookie.parent = entry.volumeId[RWVOL];
3798 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3800 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3801 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3803 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3805 results.manyResults_val =
3806 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3807 if (!replicas || !times || !results.manyResults_val || !toconns)
3809 "Failed to create transaction on the release clone\n");
3811 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3812 memset(times, 0, (sizeof(struct release) * nservers + 1));
3813 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3814 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3816 /* Create a transaction on the cloned volume */
3817 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3819 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3821 memset(&orig_status, 0, sizeof(orig_status));
3822 code = AFSVolGetStatus(fromconn, fromtid, &orig_status);
3824 if (!fullrelease && code)
3825 ONERROR(VOLSERNOVOL, afromvol,
3826 "Old clone is inaccessible. Try vos release -f %u.\n");
3827 ONERROR0(code, "Failed to create transaction on the release clone\n");
3830 /* For each index in the VLDB */
3831 for (vldbindex = 0; vldbindex < entry.nServers;) {
3833 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3835 ((volcount < nservers) && (vldbindex < entry.nServers));
3837 /* The first two RO volumes will be released individually.
3838 * The rest are then released in parallel. This is a hack
3839 * for clients not recognizing right away when a RO volume
3840 * comes back on-line.
3842 if ((volcount == 1) && (releasecount < 2))
3845 if (vldbindex == roindex)
3846 continue; /* the clone */
3847 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3848 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3850 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3851 continue; /* not a RO vol */
3854 /* Get a Transaction on this replica. Get a new connection if
3855 * necessary. Create the volume if necessary. Return the
3856 * time from which the dump should be made (0 if it's a new
3857 * volume). Each volume might have a different time.
3859 replicas[volcount].server.destHost =
3860 ntohl(entry.serverNumber[vldbindex]);
3861 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3862 replicas[volcount].server.destSSID = 1;
3863 times[volcount].vldbEntryIndex = vldbindex;
3866 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3867 &(replicas[volcount].trans),
3868 &(times[volcount].crtime),
3869 &(times[volcount].uptime),
3874 /* Thisdate is the date from which we want to pick up all changes */
3875 if (forceflag || !fullrelease
3876 || (rwcrdate > times[volcount].crtime)) {
3877 /* If the forceflag is set, then we want to do a full dump.
3878 * If it's not a full release, we can't be sure that the creation
3879 * date is good (so we also do a full dump).
3880 * If the RW volume was replaced (its creation date is newer than
3881 * the last release), then we can't be sure what has changed (so
3882 * we do a full dump).
3885 } else if (remembertime[vldbindex].validtime) {
3886 /* Trans was prev ended. Use the time from the prev trans
3887 * because, prev trans may have created the volume. In which
3888 * case time[volcount].time would be now instead of 0.
3891 (remembertime[vldbindex].uptime < times[volcount].uptime)
3892 ? remembertime[vldbindex].uptime
3893 : times[volcount].uptime;
3895 thisdate = times[volcount].uptime;
3897 remembertime[vldbindex].validtime = 1;
3898 remembertime[vldbindex].uptime = thisdate;
3900 if (volcount == 0) {
3901 fromdate = thisdate;
3903 /* Include this volume if it is within 15 minutes of the earliest */
3905 thisdate) ? (fromdate - thisdate) : (thisdate -
3907 AFSVolEndTrans(toconns[volcount],
3908 replicas[volcount].trans, &rcode);
3909 replicas[volcount].trans = 0;
3912 if (thisdate < fromdate)
3913 fromdate = thisdate;
3920 code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status);
3927 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3928 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3929 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3930 vldbEntryIndex], hoststr) :
3931 hostutil_GetNameByINet(entry.
3932 serverNumber[times[0].
3935 for (s = 1; s < volcount; s++) {
3936 fprintf(STDOUT, " and %s",
3937 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3938 vldbEntryIndex], hoststr) :
3939 hostutil_GetNameByINet(entry.
3940 serverNumber[times[s].
3945 fprintf(STDOUT, " (full release)");
3948 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3950 fprintf(STDOUT, ".\n");
3954 /* Release the ones we have collected */
3955 tr.manyDests_val = &(replicas[0]);
3956 tr.manyDests_len = results.manyResults_len = volcount;
3958 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3959 0 /*spare */ , &cookie, &results);
3960 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3962 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3963 0 /*spare */ , &cookie, &results);
3968 PrintError("Release failed: ", code);
3970 for (m = 0; m < volcount; m++) {
3971 if (results.manyResults_val[m]) {
3972 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3973 /* we retry timed out transaction. When it is
3974 * not the first volume and the transaction wasn't found
3975 * (assume it timed out and was garbage collected by volser).
3978 ("Failed to dump volume from clone to a ro site: ",
3979 results.manyResults_val[m]);
3985 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3986 ROVOL, entry.volumeId[RWVOL], 0, 0);
3988 if ((m == 0) || (code != ENOENT)) {
3989 PrintError("Failed to set correct names and ids: ",
3995 /* have to clear dest. flags to ensure new vol goes online:
3996 * because the restore (forwarded) operation copied
3997 * the V_inService(=0) flag over to the destination.
3999 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
4001 if ((m == 0) || (code != ENOENT)) {
4002 PrintError("Failed to set flags on ro volume: ",
4008 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
4009 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
4010 entry.flags |= RO_EXISTS;
4015 /* End the transactions and destroy the connections */
4016 for (s = 0; s < volcount; s++) {
4017 if (replicas[s].trans)
4018 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
4019 replicas[s].trans = 0;
4023 if ((s == 0) || (code != ENOENT)) {
4024 PrintError("Could not end transaction on a ro volume: ",
4028 ("Transaction timed out on a ro volume. Will retry.\n",
4030 if (times[s].vldbEntryIndex < vldbindex)
4031 vldbindex = times[s].vldbEntryIndex;
4036 rx_DestroyConnection(toconns[s]);
4040 MapNetworkToHost(&entry, &storeEntry);
4041 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
4042 ONERROR(vcode, afromvol,
4043 " Could not update VLDB entry for volume %u\n");
4044 } /* for each index in the vldb */
4046 /* End the transaction on the cloned volume */
4047 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4052 PrintError("Failed to end transaction on rw volume: ", code);
4054 /* Figure out if any volume were not released and say so */
4055 for (failure = 0, i = 0; i < entry.nServers; i++) {
4056 if (!(entry.serverFlags[i] & NEW_REPSITE))
4062 "The volume %lu could not be released to the following %d sites:\n",
4063 (unsigned long)afromvol, failure);
4064 for (i = 0; i < entry.nServers; i++) {
4065 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
4066 MapPartIdIntoName(entry.serverPartition[i], pname);
4067 fprintf(STDERR, "\t%35s %s\n",
4068 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
4069 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
4073 MapNetworkToHost(&entry, &storeEntry);
4075 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4077 ONERROR(vcode, afromvol,
4078 " Could not update VLDB entry for volume %u\n");
4080 ERROREXIT(VOLSERBADRELEASE);
4083 /* All the ROs were release successfully. Remove the temporary clone */
4086 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
4087 (unsigned long)cloneVolId);
4090 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
4091 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
4096 for (i = 0; i < entry.nServers; i++)
4097 entry.serverFlags[i] &= ~NEW_REPSITE;
4099 /* Update the VLDB */
4100 VPRINT("updating VLDB ...");
4102 MapNetworkToHost(&entry, &storeEntry);
4104 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
4105 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4106 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
4111 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4115 "Failed to end cloning transaction on the RW volume %lu\n",
4116 (unsigned long)afromvol);
4122 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4126 "Failed to end transaction on the release clone %lu\n",
4127 (unsigned long)cloneVolId);
4132 for (i = 0; i < nservers; i++) {
4133 if (replicas && replicas[i].trans) {
4134 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
4135 replicas[i].trans = 0;
4138 "Failed to end transaction on ro volume %u at server %s\n",
4139 entry.volumeId[ROVOL],
4140 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
4141 destHost), hoststr) :
4142 hostutil_GetNameByINet(htonl
4143 (replicas[i].server.destHost)));
4148 if (toconns && toconns[i]) {
4149 rx_DestroyConnection(toconns[i]);
4155 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
4156 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4159 "Could not release lock on the VLDB entry for volume %lu\n",
4160 (unsigned long)afromvol);
4166 PrintError("", error);
4169 rx_DestroyConnection(fromconn);
4170 if (results.manyResults_val)
4171 free(results.manyResults_val);
4183 dump_sig_handler(int x)
4185 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
4189 /* Dump the volume <afromvol> on <afromserver> and
4190 * <afrompart> to <afilename> starting from <fromdate>.
4191 * DumpFunction does the real work behind the scenes after
4192 * extracting parameters from the rock
4195 UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
4197 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4200 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4201 * be changing during the dump */
4202 struct rx_call * volatile fromcall = NULL;
4203 struct rx_connection * volatile fromconn = NULL;
4204 afs_int32 volatile fromtid = 0;
4206 afs_int32 rxError = 0, rcode = 0;
4207 afs_int32 code, error = 0;
4209 time_t tmv = fromdate;
4213 #ifndef AFS_NT40_ENV
4214 (void)signal(SIGPIPE, dump_sig_handler);
4216 (void)signal(SIGINT, dump_sig_handler);
4219 VEPRINT("Full Dump ...\n");
4221 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4225 /* get connections to the servers */
4226 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4228 VEPRINT1("Starting transaction on volume %u...", afromvol);
4230 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
4232 EGOTO1(error_exit, code,
4233 "Could not start transaction on the volume %u to be dumped\n",
4237 fromcall = rx_NewCall(fromconn);
4239 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4240 if (flags & VOLDUMPV2_OMITDIRS)
4241 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4243 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4244 EGOTO(error_exit, code, "Could not start the dump process \n");
4247 VEPRINT1("Dumping volume %u...", afromvol);
4248 code = DumpFunction(fromcall, rock);
4249 if (code == RXGEN_OPCODE)
4251 EGOTO(error_exit, code, "Error while dumping volume \n");
4256 code = rx_EndCall(fromcall, rxError);
4257 if (code && code != RXGEN_OPCODE)
4258 fprintf(STDERR, "Error in rx_EndCall\n");
4263 VEPRINT1("Ending transaction on volume %u...", afromvol);
4264 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4265 if (code || rcode) {
4266 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4267 (unsigned long)afromvol);
4269 error = (code ? code : rcode);
4274 rx_DestroyConnection(fromconn);
4276 if (error != RXGEN_OPCODE)
4277 PrintError("", error);
4281 /* Clone the volume <afromvol> on <afromserver> and
4282 * <afrompart>, and then dump the clone volume to
4283 * <afilename> starting from <fromdate>.
4284 * DumpFunction does the real work behind the scenes after
4285 * extracting parameters from the rock
4288 UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
4289 afs_int32 afrompart, afs_int32 fromdate,
4290 afs_int32(*DumpFunction) (struct rx_call *, void *),
4291 void *rock, afs_int32 flags)
4293 /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
4294 * be changing during the dump */
4295 struct rx_connection * volatile fromconn = NULL;
4296 struct rx_call * volatile fromcall = NULL;
4297 afs_int32 volatile clonetid = 0;
4298 afs_uint32 volatile clonevol = 0;
4301 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4302 afs_int32 code = 0, error = 0;
4305 time_t tmv = fromdate;
4309 #ifndef AFS_NT40_ENV
4310 (void)signal(SIGPIPE, dump_sig_handler);
4312 (void)signal(SIGINT, dump_sig_handler);
4315 VEPRINT("Full Dump ...\n");
4317 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4321 /* get connections to the servers */
4322 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4324 VEPRINT1("Starting transaction on volume %u...", afromvol);
4325 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4326 EGOTO1(error_exit, code,
4327 "Could not start transaction on the volume %u to be dumped\n",
4331 /* Get a clone id */
4332 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4334 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
4336 EGOTO1(error_exit, code,
4337 "Could not get an ID for the clone of volume %u from the VLDB\n",
4341 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4342 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4344 strcpy(vname, "dump-clone-temp");
4347 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
4349 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4353 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4355 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4359 EGOTO1(error_exit, code,
4360 "Failed to end the transaction on the volume %u\n", afromvol);
4364 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4367 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4370 EGOTO1(error_exit, code,
4371 "Failed to start a transaction on the cloned volume%u\n",
4375 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4376 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4377 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4382 fromcall = rx_NewCall(fromconn);
4384 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4385 if (flags & VOLDUMPV2_OMITDIRS)
4386 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4388 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4389 EGOTO(error_exit, code, "Could not start the dump process \n");
4392 VEPRINT1("Dumping volume %u...", afromvol);
4393 code = DumpFunction(fromcall, rock);
4394 EGOTO(error_exit, code, "Error while dumping volume \n");
4398 /* now delete the clone */
4399 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4400 code = AFSVolDeleteVolume(fromconn, clonetid);
4402 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4403 (unsigned long)clonevol);
4409 code = rx_EndCall(fromcall, rxError);
4411 fprintf(STDERR, "Error in rx_EndCall\n");
4417 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4418 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4419 if (code || rcode) {
4421 "Could not end transaction on the cloned volume %lu\n",
4422 (unsigned long)clonevol);
4424 error = (code ? code : rcode);
4429 rx_DestroyConnection(fromconn);
4431 PrintError("", error);
4438 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4439 * the dump file <afilename>. WriteData does all the real work
4440 * after extracting params from the rock
4443 UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4444 afs_uint32 toparentid, char tovolname[], int flags,
4445 afs_int32(*WriteData) (struct rx_call *, void *),
4448 struct rx_connection *toconn, *tempconn;
4449 struct rx_call *tocall;
4450 afs_int32 totid, code, rcode, vcode, terror = 0;
4451 afs_int32 rxError = 0;
4452 struct volser_status tstatus;
4453 struct volintInfo vinfo;
4455 char tovolreal[VOLSER_OLDMAXVOLNAME];
4457 afs_int32 temptid, pparentid;
4459 struct nvldbentry entry, storeEntry;
4462 struct restoreCookie cookie;
4464 afs_int32 volflag, voltype, volsertype;
4465 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4466 int index, same, errcode;
4470 memset(&cookie, 0, sizeof(cookie));
4475 tocall = (struct rx_call *)0;
4476 toconn = (struct rx_connection *)0;
4477 tempconn = (struct rx_connection *)0;
4481 if (flags & RV_RDONLY) {
4483 volsertype = volser_RO;
4486 volsertype = volser_RW;
4490 pparentid = toparentid;
4491 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4492 if (pvolid == 0) { /*alot a new id if needed */
4493 vcode = VLDB_GetEntryByName(tovolname, &entry);
4494 if (vcode == VL_NOENT) {
4495 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4497 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4503 } else if (flags & RV_RDONLY) {
4504 if (entry.flags & RW_EXISTS) {
4506 "Entry for ReadWrite volume %s already exists!\n",
4508 error = VOLSERBADOP;
4511 if (!entry.volumeId[ROVOL]) {
4513 "Existing entry for volume %s has no ReadOnly ID\n",
4515 error = VOLSERBADOP;
4518 pvolid = entry.volumeId[ROVOL];
4519 pparentid = entry.volumeId[RWVOL];
4521 pvolid = entry.volumeId[RWVOL];
4522 pparentid = entry.volumeId[RWVOL];
4525 if (!pparentid) pparentid = pvolid;
4526 /* at this point we have a volume id to use/reuse for the volume to be restored */
4527 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4529 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4530 EGOTO1(refail, VOLSERBADOP,
4531 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4534 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4535 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4536 EGOTO1(refail, VOLSERBADOP,
4537 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4539 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4542 MapPartIdIntoName(topart, partName);
4543 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4544 tovolreal, (unsigned long)pvolid,
4545 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4546 hostutil_GetNameByINet(toserver), partName);
4549 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4552 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4553 VPRINT1("Deleting the previous volume %u ...", pvolid);
4556 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4557 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4560 code = AFSVolGetStatus(toconn, totid, &tstatus);
4561 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4564 oldCreateDate = tstatus.creationDate;
4565 oldUpdateDate = tstatus.updateDate;
4568 AFSVolSetFlags(toconn, totid,
4569 VTDeleteOnSalvage | VTOutOfService);
4570 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4573 code = AFSVolDeleteVolume(toconn, totid);
4574 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4576 code = AFSVolEndTrans(toconn, totid, &rcode);
4580 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4585 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4587 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4590 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4591 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4594 code = AFSVolGetStatus(toconn, totid, &tstatus);
4595 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4598 oldCreateDate = tstatus.creationDate;
4599 oldUpdateDate = tstatus.updateDate;
4606 cookie.parent = pparentid;
4607 cookie.type = voltype;
4609 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4611 tocall = rx_NewCall(toconn);
4612 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4614 fprintf(STDERR, "Volume restore Failed \n");
4618 code = WriteData(tocall, rock);
4620 fprintf(STDERR, "Could not transmit data\n");
4624 terror = rx_EndCall(tocall, rxError);
4625 tocall = (struct rx_call *)0;
4627 fprintf(STDERR, "rx_EndCall Failed \n");
4631 code = AFSVolGetStatus(toconn, totid, &tstatus);
4634 "Could not get status information about the volume %lu\n",
4635 (unsigned long)pvolid);
4639 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4641 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4642 (unsigned long)pvolid);
4647 if (flags & RV_CRDUMP)
4648 newCreateDate = tstatus.creationDate;
4649 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4650 newCreateDate = oldCreateDate;
4652 newCreateDate = time(0);
4653 if (flags & RV_LUDUMP)
4654 newUpdateDate = tstatus.updateDate;
4655 else if (flags & RV_LUKEEP)
4656 newUpdateDate = oldUpdateDate;
4658 newUpdateDate = time(0);
4659 code = AFSVolSetDate(toconn,totid, newCreateDate);
4661 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4666 init_volintInfo(&vinfo);
4667 vinfo.creationDate = newCreateDate;
4668 vinfo.updateDate = newUpdateDate;
4669 code = AFSVolSetInfo(toconn, totid, &vinfo);
4671 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4677 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4678 code = AFSVolSetFlags(toconn, totid, volflag);
4680 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4685 /* It isn't handled right in refail */
4686 code = AFSVolEndTrans(toconn, totid, &rcode);
4691 fprintf(STDERR, "Could not end transaction on %lu\n",
4692 (unsigned long)pvolid);
4698 fprintf(STDOUT, " done\n");
4700 if (success && (!reuseID || (flags & RV_FULLRST))) {
4701 /* Volume was restored on the file server, update the
4702 * VLDB to reflect the change.
4704 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4705 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4707 "Could not fetch the entry for volume number %lu from VLDB \n",
4708 (unsigned long)pvolid);
4713 MapHostToNetwork(&entry);
4714 if (vcode == VL_NOENT) { /* it doesnot exist already */
4715 /*make the vldb return this indication specifically */
4716 VPRINT("------- Creating a new VLDB entry ------- \n");
4717 strcpy(entry.name, tovolname);
4719 entry.serverNumber[0] = toserver; /*should be indirect */
4720 entry.serverPartition[0] = topart;
4721 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4722 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4723 if (flags & RV_RDONLY)
4724 entry.volumeId[ROVOL] = pvolid;
4725 else if (tstatus.cloneID != 0) {
4726 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4728 entry.volumeId[ROVOL] = INVALID_BID;
4729 entry.volumeId[RWVOL] = pparentid;
4731 if (tstatus.backupID != 0) {
4732 entry.volumeId[BACKVOL] = tstatus.backupID;
4733 /*this should come from status info on the volume if non zero */
4735 entry.volumeId[BACKVOL] = INVALID_BID;
4736 MapNetworkToHost(&entry, &storeEntry);
4737 vcode = VLDB_CreateEntry(&storeEntry);
4740 "Could not create the VLDB entry for volume number %lu \n",
4741 (unsigned long)pvolid);
4747 EnumerateEntry(&entry);
4748 } else { /*update the existing entry */
4750 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4751 fprintf(STDOUT, "------- Old entry -------\n");
4752 EnumerateEntry(&entry);
4753 fprintf(STDOUT, "------- New entry -------\n");
4756 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4760 "Could not lock the entry for volume number %lu \n",
4761 (unsigned long)pvolid);
4766 strcpy(entry.name, tovolname);
4768 /* Update the vlentry with the new information */
4769 if (flags & RV_RDONLY)
4770 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4772 index = Lp_GetRwIndex(&entry);
4774 /* Add the new site for the volume being restored */
4775 entry.serverNumber[entry.nServers] = toserver;
4776 entry.serverPartition[entry.nServers] = topart;
4777 entry.serverFlags[entry.nServers] =
4778 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4781 /* This volume should be deleted on the old site
4782 * if its different from new site.
4785 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4789 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4791 if ((!errcode && !same)
4792 || (entry.serverPartition[index] != topart)) {
4793 if (flags & RV_NODEL) {
4795 ("Not deleting the previous volume %u on server %s, ...",
4797 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4798 hostutil_GetNameByINet(entry.serverNumber[index]));
4801 UV_Bind(entry.serverNumber[index],
4802 AFSCONF_VOLUMEPORT);
4804 MapPartIdIntoName(entry.serverPartition[index],
4807 ("Deleting the previous volume %u on server %s, partition %s ...",
4809 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4810 hostutil_GetNameByINet(entry.serverNumber[index]),
4813 AFSVolTransCreate_retry(tempconn, pvolid,
4814 entry.serverPartition[index],
4815 ITOffline, &temptid);
4818 AFSVolSetFlags(tempconn, temptid,
4823 "Could not set flags on volume %lu on the older site\n",
4824 (unsigned long)pvolid);
4828 code = AFSVolDeleteVolume(tempconn, temptid);
4831 "Could not delete volume %lu on the older site\n",
4832 (unsigned long)pvolid);
4836 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4842 "Could not end transaction on volume %lu on the older site\n",
4843 (unsigned long)pvolid);
4848 MapPartIdIntoName(entry.serverPartition[index],
4853 entry.serverNumber[index] = toserver;
4854 entry.serverPartition[index] = topart;
4857 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4858 MapNetworkToHost(&entry, &storeEntry);
4860 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4861 LOCKREL_OPCODE | LOCKREL_AFSID |
4865 "Could not update the entry for volume number %lu \n",
4866 (unsigned long)pvolid);
4872 EnumerateEntry(&entry);
4879 code = rx_EndCall(tocall, rxError);
4885 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4886 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4889 "Could not release lock on the VLDB entry for the volume %lu\n",
4890 (unsigned long)pvolid);
4896 code = AFSVolEndTrans(toconn, totid, &rcode);
4900 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4901 (unsigned long)pvolid);
4907 code = AFSVolEndTrans(toconn, temptid, &rcode);
4911 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4912 (unsigned long)pvolid);
4918 rx_DestroyConnection(tempconn);
4920 rx_DestroyConnection(toconn);
4921 PrintError("", error);
4926 UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
4927 char tovolname[], int flags,
4928 afs_int32(*WriteData) (struct rx_call *, void *),
4931 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4936 /*unlocks the vldb entry associated with <volid> */
4938 UV_LockRelease(afs_uint32 volid)
4942 VPRINT("Binding to the VLDB server\n");
4944 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4945 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4948 "Could not unlock the entry for volume number %lu in VLDB \n",
4949 (unsigned long)volid);
4950 PrintError("", vcode);
4953 VPRINT("VLDB updated\n");
4958 /* old interface to add rosites */
4960 UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4963 return UV_AddSite2(server, part, volid, 0, valid);
4966 /*adds <server> and <part> as a readonly replication site for <volid>
4969 UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
4970 afs_uint32 rovolid, afs_int32 valid)
4972 int j, nro = 0, islocked = 0;
4973 struct nvldbentry entry, storeEntry, entry2;
4974 afs_int32 vcode, error = 0;
4977 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4980 " Could not lock the VLDB entry for the volume %lu \n",
4981 (unsigned long)volid);
4986 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4989 "Could not fetch the VLDB entry for volume number %lu \n",
4990 (unsigned long)volid);
4994 if (!ISNAMEVALID(entry.name)) {
4996 "Volume name %s is too long, rename before adding site\n",
4998 error = VOLSERBADOP;
5001 MapHostToNetwork(&entry);
5003 /* See if it's too many entries */
5004 if (entry.nServers >= NMAXNSERVERS) {
5005 fprintf(STDERR, "Total number of entries will exceed %u\n",
5007 error = VOLSERBADOP;
5011 /* See if it's on the same server */
5012 for (j = 0; j < entry.nServers; j++) {
5013 if (entry.serverFlags[j] & ITSROVOL) {
5015 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
5018 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
5021 MapPartIdIntoName(entry.serverPartition[j], apartName);
5023 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
5025 error = VOLSERBADOP;
5032 /* See if it's too many RO sites - leave one for the RW */
5033 if (nro >= NMAXNSERVERS - 1) {
5034 fprintf(STDERR, "Total number of sites will exceed %u\n",
5036 error = VOLSERBADOP;
5040 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
5041 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
5042 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
5045 if (entry.volumeId[ROVOL] == INVALID_BID) {
5046 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
5048 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
5051 VPRINT1("Using RO volume id %d.\n", rovolid);
5052 entry.volumeId[ROVOL] = rovolid;
5054 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
5055 rovolid, entry.volumeId[ROVOL]);
5059 VPRINT("Adding a new site ...");
5060 entry.serverNumber[entry.nServers] = server;
5061 entry.serverPartition[entry.nServers] = part;
5063 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
5065 entry.serverFlags[entry.nServers] = (ITSROVOL);
5069 MapNetworkToHost(&entry, &storeEntry);
5071 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5072 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5074 fprintf(STDERR, "Could not update entry for volume %lu \n",
5075 (unsigned long)volid);
5084 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5085 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5088 "Could not release lock on volume entry for %lu \n",
5089 (unsigned long)volid);
5090 PrintError("", vcode);
5094 PrintError("", error);
5098 /*removes <server> <part> as read only site for <volid> from the vldb */
5100 UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5103 struct nvldbentry entry, storeEntry;
5105 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5107 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5108 (unsigned long)volid);
5109 PrintError("", vcode);
5112 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5115 "Could not fetch the entry for volume number %lu from VLDB \n",
5116 (unsigned long)volid);
5117 PrintError("", vcode);
5120 MapHostToNetwork(&entry);
5121 if (!Lp_ROMatch(server, part, &entry)) {
5122 /*this site doesnot exist */
5123 fprintf(STDERR, "This site is not a replication site \n");
5125 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5126 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5128 fprintf(STDERR, "Could not update entry for volume %lu \n",
5129 (unsigned long)volid);
5130 PrintError("", vcode);
5131 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5132 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5136 } else { /*remove the rep site */
5137 Lp_SetROValue(&entry, server, part, 0, 0);
5139 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
5140 entry.flags &= ~RO_EXISTS;
5141 if (entry.nServers < 1) { /*this is the last ref */
5142 VPRINT1("Deleting the VLDB entry for %u ...", volid);
5144 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
5147 "Could not delete VLDB entry for volume %lu \n",
5148 (unsigned long)volid);
5149 PrintError("", vcode);
5154 MapNetworkToHost(&entry, &storeEntry);
5155 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
5156 (unsigned long)volid);
5159 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5160 LOCKREL_OPCODE | LOCKREL_AFSID |
5164 "Could not release lock on volume entry for %lu \n",
5165 (unsigned long)volid);
5166 PrintError("", vcode);
5167 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5168 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5176 /*sets <server> <part> as read/write site for <volid> in the vldb */
5178 UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
5181 struct nvldbentry entry, storeEntry;
5184 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
5186 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
5187 (unsigned long)volid);
5188 PrintError("", vcode);
5191 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
5194 "Could not fetch the entry for volume number %lu from VLDB \n",
5195 (unsigned long)volid);
5196 PrintError("", vcode);
5199 MapHostToNetwork(&entry);
5200 index = Lp_GetRwIndex(&entry);
5202 /* no RW site exists */
5203 fprintf(STDERR, "No existing RW site for volume %lu",
5204 (unsigned long)volid);
5206 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5207 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5210 "Could not release lock on entry for volume %lu \n",
5211 (unsigned long)volid);
5212 PrintError("", vcode);
5216 } else { /* change the RW site */
5217 entry.serverNumber[index] = server;
5218 entry.serverPartition[index] = part;
5219 MapNetworkToHost(&entry, &storeEntry);
5221 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5222 LOCKREL_OPCODE | LOCKREL_AFSID |
5225 fprintf(STDERR, "Could not update entry for volume %lu \n",
5226 (unsigned long)volid);
5227 PrintError("", vcode);
5228 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5229 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5237 /*list all the partitions on <aserver> */
5239 UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
5242 struct rx_connection *aconn;
5243 struct pIDs partIds;
5244 struct partEntries partEnts;
5248 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5250 partEnts.partEntries_len = 0;
5251 partEnts.partEntries_val = NULL;
5252 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5253 if (code == RXGEN_OPCODE) {
5254 for (i = 0; i < 26; i++) /* try old interface */
5255 partIds.partIds[i] = -1;
5256 code = AFSVolListPartitions(aconn, &partIds);
5258 for (i = 0; i < 26; i++) {
5259 if ((partIds.partIds[i]) != -1) {
5260 ptrPartList->partId[j] = partIds.partIds[i];
5261 ptrPartList->partFlags[j] = PARTVALID;
5264 ptrPartList->partFlags[i] = 0;
5269 *cntp = partEnts.partEntries_len;
5270 if (*cntp > VOLMAXPARTS) {
5272 "Warning: number of partitions on the server too high %d (process only %d)\n",
5273 *cntp, VOLMAXPARTS);
5274 *cntp = VOLMAXPARTS;
5276 for (i = 0; i < *cntp; i++) {
5277 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5278 ptrPartList->partFlags[i] = PARTVALID;
5280 free(partEnts.partEntries_val);
5286 "Could not fetch the list of partitions from the server\n");
5287 PrintError("", code);
5289 rx_DestroyConnection(aconn);
5294 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5295 This is used by the backup system */
5297 UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
5298 struct volDescription *volPtr, afs_int32 arraySize)
5300 struct rx_connection *aconn;
5301 struct volDescription *curPtr;
5304 afs_int32 rcode = 0;
5305 afs_int32 success = 1;
5308 aconn = (struct rx_connection *)0;
5309 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5311 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5312 if (curPtr->volFlags & CLONEVALID) {
5313 curPtr->volFlags &= ~CLONEZAPPED;
5316 AFSVolTransCreate_retry(aconn, curPtr->volCloneId, apart, ITOffline,
5321 code = AFSVolDeleteVolume(aconn, tid);
5324 code = AFSVolEndTrans(aconn, tid, &rcode);
5329 curPtr->volFlags |= CLONEZAPPED;
5331 fprintf(STDERR, "Could not zap volume %lu\n",
5332 (unsigned long)curPtr->volCloneId);
5334 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5335 curPtr->volCloneId);
5341 rx_DestroyConnection(aconn);
5345 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5348 UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
5349 struct volDescription *volPtr, afs_int32 arraySize)
5351 struct rx_connection *aconn;
5352 struct volDescription *curPtr;
5355 afs_int32 rcode = 0;
5357 int reuseCloneId = 0;
5358 afs_uint32 curCloneId = 0;
5359 char cloneName[256]; /*max vol name */
5361 aconn = (struct rx_connection *)0;
5362 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5364 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5366 else { /*get a bunch of id's from vldb */
5368 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5370 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5371 PrintError("", code);
5376 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5377 if (curPtr->volFlags & ENTRYVALID) {
5379 curPtr->volFlags |= CLONEVALID;
5380 /*make a clone of curParentId and record as curPtr->volCloneId */
5382 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5385 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5388 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5392 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5393 strcpy(cloneName, curPtr->volName);
5394 strcat(cloneName, "-tmpClone-");
5396 strcpy(cloneName, "-tmpClone");
5398 curPtr->volCloneId = curCloneId;
5403 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5404 &(curPtr->volCloneId));
5406 curPtr->volFlags &= ~CLONEVALID;
5408 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5409 curPtr->volName, (unsigned long)code);
5410 code = AFSVolEndTrans(aconn, tid, &rcode);
5412 fprintf(STDERR, "WARNING: could not end transaction\n");
5415 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5416 curPtr->volCloneId);
5417 code = AFSVolEndTrans(aconn, tid, &rcode);
5418 if (code || rcode) {
5419 curPtr->volFlags &= ~CLONEVALID;
5428 rx_DestroyConnection(aconn);
5433 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5434 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5436 UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
5437 struct volintInfo **resultPtr, afs_int32 * size)
5439 struct rx_connection *aconn;
5441 volEntries volumeInfo;
5445 *resultPtr = (volintInfo *) 0;
5446 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5447 volumeInfo.volEntries_len = 0;
5449 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5450 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5453 "Could not fetch the list of volumes from the server\n");
5455 *resultPtr = volumeInfo.volEntries_val;
5456 *size = volumeInfo.volEntries_len;
5460 rx_DestroyConnection(aconn);
5461 PrintError("", code);
5465 /*------------------------------------------------------------------------
5466 * EXPORTED UV_XListVolumes
5469 * List the extended information for all the volumes on a particular
5470 * File Server and partition. We may either return the volume's ID
5471 * or all of its extended information.
5474 * a_serverID : Address of the File Server for which we want
5475 * extended volume info.
5476 * a_partID : Partition for which we want the extended
5478 * a_all : If non-zero, fetch ALL the volume info,
5479 * otherwise just the volume ID.
5480 * a_resultPP : Ptr to the address of the area containing
5481 * the returned volume info.
5482 * a_numEntsInResultP : Ptr for the value we set for the number of
5487 * Otherise, the return value of AFSVolXListVolumes.
5490 * This routine is closely related to UV_ListVolumes, which returns
5491 * only the standard level of detail on AFS volumes. It is a
5492 * heavyweight operation, zipping through all the volume entries for
5493 * a given server/partition.
5497 *------------------------------------------------------------------------*/
5500 UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
5501 struct volintXInfo **a_resultPP,
5502 afs_int32 * a_numEntsInResultP)
5504 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5505 afs_int32 code; /*Error code to return */
5506 volXEntries volumeXInfo; /*Area for returned extended vol info */
5509 * Set up our error code and the area for returned extended volume info.
5510 * We set the val field to a null pointer as a hint for the stub to
5514 *a_numEntsInResultP = 0;
5515 *a_resultPP = (volintXInfo *) 0;
5516 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5517 volumeXInfo.volXEntries_len = 0;
5520 * Bind to the Volume Server port on the File Server machine in question,
5523 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5524 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5526 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5529 * We got the info; pull out the pointer to where the results lie
5530 * and how many entries are there.
5532 *a_resultPP = volumeXInfo.volXEntries_val;
5533 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5537 * If we got an Rx connection, throw it away.
5540 rx_DestroyConnection(rxConnP);
5542 PrintError("", code);
5544 } /*UV_XListVolumes */
5546 /* get all the information about volume <volid> on <aserver> and <apart> */
5548 UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
5549 struct volintInfo **resultPtr)
5551 struct rx_connection *aconn;
5553 volEntries volumeInfo;
5557 *resultPtr = (volintInfo *) 0;
5558 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5559 volumeInfo.volEntries_len = 0;
5561 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5562 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5565 "Could not fetch the information about volume %lu from the server\n",
5566 (unsigned long)volid);
5568 *resultPtr = volumeInfo.volEntries_val;
5573 rx_DestroyConnection(aconn);
5574 PrintError("", code);
5578 /*------------------------------------------------------------------------
5579 * EXPORTED UV_XListOneVolume
5582 * List the extended information for a volume on a particular File
5583 * Server and partition.
5586 * a_serverID : Address of the File Server for which we want
5587 * extended volume info.
5588 * a_partID : Partition for which we want the extended
5590 * a_volID : Volume ID for which we want the info.
5591 * a_resultPP : Ptr to the address of the area containing
5592 * the returned volume info.
5596 * Otherise, the return value of AFSVolXListOneVolume.
5599 * This routine is closely related to UV_ListOneVolume, which returns
5600 * only the standard level of detail on the chosen AFS volume.
5604 *------------------------------------------------------------------------*/
5607 UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5608 struct volintXInfo **a_resultPP)
5610 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5611 afs_int32 code; /*Error code */
5612 volXEntries volumeXInfo; /*Area for returned info */
5615 * Set up our error code, and the area we're in which we are returning
5616 * the info. Setting the val field to a null pointer tells the stub
5617 * to allocate space for us.
5620 *a_resultPP = (volintXInfo *) 0;
5621 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5622 volumeXInfo.volXEntries_len = 0;
5625 * Bind to the Volume Server port on the File Server machine in question,
5628 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5629 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5632 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5635 * We got the info; pull out the pointer to where the results lie.
5637 *a_resultPP = volumeXInfo.volXEntries_val;
5640 * If we got an Rx connection, throw it away.
5643 rx_DestroyConnection(rxConnP);
5645 PrintError("", code);
5650 * Given a volume we read from a partition, check if it is
5651 * represented in the VLDB correctly.
5653 * The VLDB is looked up by the RW volume id (not its name).
5654 * The RW contains the true name of the volume (BK and RO set
5655 * the name in the VLDB only on creation of the VLDB entry).
5656 * We want rules strict enough that when we check all volumes
5657 * on one partition, it does not need to be done again. IE:
5658 * two volumes on different partitions won't constantly
5659 * change a VLDB entry away from what the other set.
5660 * For RW and BK volumes, we will always check the VLDB to see
5661 * if the two exist on the server/partition. May seem redundant,
5662 * but this is an easy check of the VLDB. IE: if the VLDB entry
5663 * says the BK exists but no BK volume is there, we will detect
5664 * this when we check the RW volume.
5665 * VLDB entries are locked only when a change needs to be done.
5666 * Output changed to look a lot like the "vos syncserv" otuput.
5669 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
5670 afs_int32 * modentry, afs_uint32 * maxvolid,
5671 struct nvldbentry *aentry)
5675 afs_int32 code, error = 0;
5676 struct nvldbentry entry, storeEntry;
5678 int pass = 0, createentry, addvolume, modified, mod, doit = 1;
5688 ((volumeinfo->type ==
5689 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5692 /* Check to see if the VLDB is ok without locking it (pass 1).
5693 * If it will change, then lock the VLDB entry, read it again,
5694 * then make the changes to it (pass 2).
5697 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5699 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5700 (unsigned long)rwvolid);
5705 createentry = 0; /* Do we need to create a VLDB entry */
5706 addvolume = 0; /* Add this volume to the VLDB entry */
5707 modified = 0; /* The VLDB entry was modified */
5710 memcpy(&entry, aentry, sizeof(entry));
5712 /* Read the entry from VLDB by its RW volume id */
5713 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5715 if (code != VL_NOENT) {
5717 "Could not retreive the VLDB entry for volume %lu \n",
5718 (unsigned long)rwvolid);
5722 memset(&entry, 0, sizeof(entry));
5723 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5727 MapHostToNetwork(&entry);
5731 if (verbose && (pass == 1)) {
5732 fprintf(STDOUT, "_______________________________\n");
5733 fprintf(STDOUT, "\n-- status before -- \n");
5735 fprintf(STDOUT, "\n**does not exist**\n");
5737 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5738 || (entry.flags & BACK_EXISTS))
5739 EnumerateEntry(&entry);
5741 fprintf(STDOUT, "\n");
5744 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5750 /* Check existence of RW and BK volumes */
5751 code = CheckVldbRWBK(&entry, &mod);
5757 idx = Lp_GetRwIndex(&entry);
5758 if (idx == -1) { /* RW index not found in the VLDB entry */
5759 idx = entry.nServers; /* put it into next index */
5762 } else { /* RW index found in the VLDB entry. */
5763 /* Verify if this volume's location matches where the VLDB says it is */
5764 if (!Lp_Match(aserver, apart, &entry)) {
5765 if (entry.flags & RW_EXISTS) {
5766 /* The RW volume exists elsewhere - report this one a duplicate */
5768 MapPartIdIntoName(apart, pname);
5770 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5771 (unsigned long)rwvolid,
5773 afs_inet_ntoa_r(aserver, hoststr) :
5774 hostutil_GetNameByINet(aserver), pname);
5775 MapPartIdIntoName(entry.serverPartition[idx],
5778 " VLDB reports RW volume %lu exists on %s %s\n",
5779 (unsigned long)rwvolid,
5781 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5782 hostutil_GetNameByINet(entry.
5787 /* The RW volume does not exist - have VLDB point to this one */
5790 /* Check for orphaned BK volume on old partition */
5791 if (entry.flags & BACK_EXISTS) {
5793 MapPartIdIntoName(entry.serverPartition[idx],
5796 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5797 entry.volumeId[BACKVOL],
5799 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5800 hostutil_GetNameByINet(entry.
5803 MapPartIdIntoName(apart, pname);
5805 " VLDB reports its RW volume %lu exists on %s %s\n",
5806 (unsigned long)rwvolid,
5808 afs_inet_ntoa_r(aserver, hoststr) :
5809 hostutil_GetNameByINet(aserver),
5815 /* Volume location matches the VLDB location */
5816 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5817 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5820 (entry.name, volumeinfo->name,
5821 VOLSER_OLDMAXVOLNAME) != 0)) {
5829 entry.flags |= RW_EXISTS;
5830 entry.volumeId[RWVOL] = rwvolid;
5831 if (!entry.volumeId[BACKVOL])
5832 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5833 if (!entry.volumeId[ROVOL])
5834 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5836 entry.serverFlags[idx] = ITSRWVOL;
5837 entry.serverNumber[idx] = aserver;
5838 entry.serverPartition[idx] = apart;
5839 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5843 /* One last check - to update BK if need to */
5844 code = CheckVldbRWBK(&entry, &mod);
5852 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5858 /* Check existence of RW and BK volumes */
5859 code = CheckVldbRWBK(&entry, &mod);
5865 idx = Lp_GetRwIndex(&entry);
5866 if (idx == -1) { /* RW index not found in the VLDB entry */
5867 idx = entry.nServers; /* Put it into next index */
5870 } else { /* RW index found in the VLDB entry */
5871 /* Verify if this volume's location matches where the VLDB says it is */
5872 if (!Lp_Match(aserver, apart, &entry)) {
5873 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5875 MapPartIdIntoName(apart, pname);
5877 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5878 (unsigned long)volumeinfo->volid,
5880 afs_inet_ntoa_r(aserver, hoststr) :
5881 hostutil_GetNameByINet(aserver), pname);
5882 MapPartIdIntoName(entry.serverPartition[idx], pname);
5884 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5885 (unsigned long)rwvolid,
5887 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5888 hostutil_GetNameByINet(entry.
5893 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5894 if (!(entry.flags & BACK_EXISTS)) {
5896 } else if (volumeinfo->volid >
5897 entry.volumeId[BACKVOL]) {
5901 MapPartIdIntoName(entry.serverPartition[idx],
5904 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5905 entry.volumeId[BACKVOL],
5907 afs_inet_ntoa_r(aserver, hoststr) :
5908 hostutil_GetNameByINet(aserver),
5911 " VLDB reports its BK volume ID is %lu\n",
5912 (unsigned long)volumeinfo->volid);
5916 MapPartIdIntoName(entry.serverPartition[idx],
5919 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5920 (unsigned long)volumeinfo->volid,
5922 afs_inet_ntoa_r(aserver, hoststr) :
5923 hostutil_GetNameByINet(aserver),
5926 " VLDB reports its BK volume ID is %u\n",
5927 entry.volumeId[BACKVOL]);
5930 } else if (!entry.volumeId[BACKVOL]) {
5937 entry.flags |= BACK_EXISTS;
5938 entry.volumeId[RWVOL] = rwvolid;
5939 entry.volumeId[BACKVOL] = volumeinfo->volid;
5941 entry.serverNumber[idx] = aserver;
5942 entry.serverPartition[idx] = apart;
5943 entry.serverFlags[idx] = ITSBACKVOL;
5949 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5950 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5951 /* This is a quick check to see if the RO entry exists in the
5952 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5953 * RO volume listed in the VLDB exists).
5955 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5957 idx = entry.nServers;
5961 if (!(entry.flags & RO_EXISTS)) {
5966 /* Before we correct the VLDB entry, make sure all the
5967 * ROs listed in the VLDB exist.
5969 code = CheckVldbRO(&entry, &mod);
5975 if (!(entry.flags & RO_EXISTS)) {
5976 /* No RO exists in the VLDB entry - add this one */
5977 idx = entry.nServers;
5980 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5981 /* The volume headers's RO ID does not match that in the VLDB entry,
5982 * and the vol hdr's ID is greater (implies more recent). So delete
5983 * all the RO volumes listed in VLDB entry and add this volume.
5985 for (j = 0; j < entry.nServers; j++) {
5986 if (entry.serverFlags[j] & ITSROVOL) {
5987 /* Verify this volume exists and print message we are orphaning it */
5989 MapPartIdIntoName(apart, pname);
5991 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5992 entry.volumeId[ROVOL],
5994 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5995 hostutil_GetNameByINet(entry.
5999 " VLDB reports its RO volume ID is %lu\n",
6000 (unsigned long)volumeinfo->volid);
6003 Lp_SetRWValue(&entry, entry.serverNumber[idx],
6004 entry.serverPartition[idx], 0L, 0L);
6011 idx = entry.nServers;
6014 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
6015 /* The volume headers's RO ID does not match that in the VLDB entry,
6016 * and the vol hdr's ID is lower (implies its older). So orphan it.
6019 MapPartIdIntoName(apart, pname);
6021 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
6022 (unsigned long)volumeinfo->volid,
6024 afs_inet_ntoa_r(aserver, hoststr) :
6025 hostutil_GetNameByINet(aserver), pname);
6027 " VLDB reports its RO volume ID is %u\n",
6028 entry.volumeId[ROVOL]);
6031 /* The RO volume ID in the volume header match that in the VLDB entry,
6032 * and there exist RO volumes in the VLDB entry. See if any of them
6033 * are this one. If not, then we add it.
6035 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
6037 idx = entry.nServers;
6045 entry.flags |= RO_EXISTS;
6046 entry.volumeId[RWVOL] = rwvolid;
6047 entry.volumeId[ROVOL] = volumeinfo->volid;
6049 entry.serverNumber[idx] = aserver;
6050 entry.serverPartition[idx] = apart;
6051 entry.serverFlags[idx] = ITSROVOL;
6057 /* Remember largest volume id */
6058 if (entry.volumeId[ROVOL] > *maxvolid)
6059 *maxvolid = entry.volumeId[ROVOL];
6060 if (entry.volumeId[BACKVOL] > *maxvolid)
6061 *maxvolid = entry.volumeId[BACKVOL];
6062 if (entry.volumeId[RWVOL] > *maxvolid)
6063 *maxvolid = entry.volumeId[RWVOL];
6065 if (modified && doit) {
6066 MapNetworkToHost(&entry, &storeEntry);
6069 code = VLDB_CreateEntry(&storeEntry);
6072 "Could not create a VLDB entry for the volume %lu\n",
6073 (unsigned long)rwvolid);
6080 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
6081 LOCKREL_OPCODE | LOCKREL_AFSID |
6084 fprintf(STDERR, "Could not update entry for %lu\n",
6085 (unsigned long)rwvolid);
6089 } else if (pass == 2) {
6091 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
6092 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6094 PrintError("Could not unlock VLDB entry ", code);
6098 if (modified && modentry) {
6103 memcpy(aentry, &entry, sizeof(entry));
6107 fprintf(STDOUT, "-- status after --\n");
6109 EnumerateEntry(&entry);
6111 fprintf(STDOUT, "\n**no change**\n");
6115 VPRINT("\n_______________________________\n");
6120 sortVolumes(const void *a, const void *b)
6122 volintInfo *v1 = (volintInfo *) a;
6123 volintInfo *v2 = (volintInfo *) b;
6124 afs_uint32 rwvolid1, rwvolid2;
6126 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
6127 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
6129 if (rwvolid1 > rwvolid2)
6130 return -1; /* lower RW id goes first */
6131 if (rwvolid1 < rwvolid2)
6134 if (v1->type == RWVOL)
6135 return -1; /* RW vols go first */
6136 if (v2->type == RWVOL)
6139 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
6140 return -1; /* BK vols next */
6141 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
6144 if (v1->volid < v2->volid)
6145 return 1; /* larger volids first */
6146 if (v1->volid > v2->volid)
6152 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
6153 * Synchronize an individual volume against a sever and partition.
6154 * Checks the VLDB entry (similar to syncserv) as well as checks
6155 * if the volume exists on specified servers (similar to syncvldb).
6158 UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
6160 struct rx_connection *aconn = 0;
6161 afs_int32 j, k, code, vcode, error = 0;
6163 afs_int32 mod, modified = 0, deleted = 0;
6164 struct nvldbentry vldbentry;
6165 afs_uint32 volumeid = 0;
6166 volEntries volumeInfo;
6167 struct partList PartList;
6169 afs_uint32 maxvolid = 0;
6171 volumeInfo.volEntries_val = (volintInfo *) 0;
6172 volumeInfo.volEntries_len = 0;
6174 /* Turn verbose logging off and do our own verbose logging */
6175 /* tverbose must be set before we call ERROR_EXIT() */
6182 if (!aserver && (flags & 1)) {
6183 /* fprintf(STDERR,"Partition option requires a server option\n"); */
6187 /* Read the VLDB entry */
6188 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6189 if (vcode && (vcode != VL_NOENT)) {
6190 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6193 } else if (!vcode) {
6194 MapHostToNetwork(&vldbentry);
6198 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
6199 fprintf(STDOUT, "_______________________________\n");
6200 fprintf(STDOUT, "\n-- status before -- \n");
6202 fprintf(STDOUT, "\n**does not exist**\n");
6204 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
6205 || (vldbentry.flags & BACK_EXISTS))
6206 EnumerateEntry(&vldbentry);
6208 fprintf(STDOUT, "\n");
6211 /* Verify that all of the VLDB entries exist on the repective servers
6212 * and partitions (this does not require that avolname be a volume ID).
6213 * Equivalent to a syncserv.
6216 /* Tell CheckVldb not to update if appropriate */
6221 code = CheckVldb(&vldbentry, &mod, &deleted);
6223 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6231 /* If aserver is given, we will search for the desired volume on it */
6233 /* Generate array of partitions on the server that we will check */
6235 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6238 "Could not fetch the list of partitions from the server\n");
6242 PartList.partId[0] = apart;
6246 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6248 /* If a volume ID were given, search for it on each partition */
6249 if ((volumeid = atol(avolname))) {
6250 for (j = 0; j < pcnt; j++) {
6252 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6255 if (code != ENODEV) {
6256 fprintf(STDERR, "Could not query server\n");
6264 /* Found one, sync it with VLDB entry */
6266 CheckVolume(volumeInfo.volEntries_val, aserver,
6267 PartList.partId[j], &mod, &maxvolid, &vldbentry);
6274 if (volumeInfo.volEntries_val)
6275 free(volumeInfo.volEntries_val);
6276 volumeInfo.volEntries_val = (volintInfo *) 0;
6277 volumeInfo.volEntries_len = 0;
6281 /* Check to see if the RW, BK, and RO IDs exist on any
6282 * partitions. We get the volume IDs from the VLDB.
6284 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6285 if (vldbentry.volumeId[j] == 0)
6288 for (k = 0; k < pcnt; k++) { /* For each partition */
6289 volumeInfo.volEntries_val = (volintInfo *) 0;
6290 volumeInfo.volEntries_len = 0;
6292 AFSVolListOneVolume(aconn, PartList.partId[k],
6293 vldbentry.volumeId[j], &volumeInfo);
6295 if (code != ENODEV) {
6296 fprintf(STDERR, "Could not query server\n");
6304 /* Found one, sync it with VLDB entry */
6306 CheckVolume(volumeInfo.volEntries_val, aserver,
6307 PartList.partId[k], &mod, &maxvolid, &vldbentry);
6314 if (volumeInfo.volEntries_val)
6315 free(volumeInfo.volEntries_val);
6316 volumeInfo.volEntries_val = (volintInfo *) 0;
6317 volumeInfo.volEntries_len = 0;
6323 /* If verbose output, print a summary of what changed */
6325 fprintf(STDOUT, "-- status after --\n");
6327 fprintf(STDOUT, "\n**entry deleted**\n");
6328 } else if (modified) {
6329 EnumerateEntry(&vldbentry);
6331 fprintf(STDOUT, "\n**no change**\n");
6333 fprintf(STDOUT, "\n_______________________________\n");
6337 /* Now check if the maxvolid is larger than that stored in the VLDB */
6339 afs_uint32 maxvldbid = 0;
6340 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6343 "Could not get the highest allocated volume id from the VLDB\n");
6346 } else if (maxvolid > maxvldbid) {
6348 id = maxvolid - maxvldbid + 1;
6349 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6352 "Error in increasing highest allocated volume id in VLDB\n");
6362 fprintf(STDOUT, "...error encountered");
6364 fprintf(STDOUT, "...done entry\n");
6367 rx_DestroyConnection(aconn);
6368 if (volumeInfo.volEntries_val)
6369 free(volumeInfo.volEntries_val);
6371 PrintError("", error);
6376 * Synchronise vldb with the file server <aserver> and,
6377 * optionally, <apart>.
6380 UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6382 struct rx_connection *aconn;
6383 afs_int32 code, error = 0;
6386 volEntries volumeInfo;
6387 struct partList PartList;
6391 afs_int32 failures = 0, modifications = 0, tentries = 0;
6393 afs_uint32 maxvolid = 0;
6396 volumeInfo.volEntries_val = (volintInfo *) 0;
6397 volumeInfo.volEntries_len = 0;
6399 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6401 /* Generate array of partitions to check */
6403 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6406 "Could not fetch the list of partitions from the server\n");
6410 PartList.partId[0] = apart;
6414 VPRINT("Processing volume entries ...\n");
6416 /* Step through the array of partitions */
6417 for (i = 0; i < pcnt; i++) {
6418 apart = PartList.partId[i];
6419 MapPartIdIntoName(apart, pname);
6421 volumeInfo.volEntries_val = (volintInfo *) 0;
6422 volumeInfo.volEntries_len = 0;
6423 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6426 "Could not fetch the list of volumes from the server\n");
6430 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6431 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6432 sizeof(volintInfo), sortVolumes);
6435 for (vi = volumeInfo.volEntries_val, j = 0;
6436 j < volumeInfo.volEntries_len; j++, vi++) {
6444 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6445 j + 1, vi->name, (unsigned long)vi->volid,
6447 afs_inet_ntoa_r(aserver, hoststr) :
6448 hostutil_GetNameByINet(aserver), pname);
6456 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
6458 PrintError("", code);
6461 } else if (modified) {
6467 fprintf(STDOUT, "...error encountered\n\n");
6469 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6476 "Could not process entries on server %s partition %s\n",
6478 afs_inet_ntoa_r(aserver, hoststr) :
6479 hostutil_GetNameByINet(aserver), pname);
6481 if (volumeInfo.volEntries_val) {
6482 free(volumeInfo.volEntries_val);
6483 volumeInfo.volEntries_val = 0;
6486 } /* thru all partitions */
6489 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6490 tentries, failures, modifications);
6492 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6493 tentries, failures, modifications);
6497 /* Now check if the maxvolid is larger than that stored in the VLDB */
6499 afs_uint32 maxvldbid = 0;
6500 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6503 "Could not get the highest allocated volume id from the VLDB\n");
6506 } else if (maxvolid > maxvldbid) {
6508 id = maxvolid - maxvldbid + 1;
6509 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6512 "Error in increasing highest allocated volume id in VLDB\n");
6520 rx_DestroyConnection(aconn);
6521 if (volumeInfo.volEntries_val)
6522 free(volumeInfo.volEntries_val);
6523 PrintError("", error);
6528 * Determine if a volume exists on a server and partition.
6529 * Try creating a transaction on the volume. If we can,
6530 * the volume exists, if not, then return the error code.
6531 * Some error codes mean the volume is unavailable but
6532 * still exists - so we catch these error codes.
6535 VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
6537 struct rx_connection *conn = (struct rx_connection *)0;
6538 afs_int32 code = -1;
6539 volEntries volumeInfo;
6541 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6543 volumeInfo.volEntries_val = (volintInfo *) 0;
6544 volumeInfo.volEntries_len = 0;
6545 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6546 if (volumeInfo.volEntries_val)
6547 free(volumeInfo.volEntries_val);
6548 if (code == VOLSERILLEGAL_PARTITION)
6550 rx_DestroyConnection(conn);
6559 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6563 afs_int32 code, error = 0;
6569 idx = Lp_GetRwIndex(entry);
6571 /* Check to see if the RW volume exists and set the RW_EXISTS
6574 if (idx == -1) { /* Did not find a RW entry */
6575 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6576 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6581 VolumeExists(entry->serverNumber[idx],
6582 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6583 if (code == 0) { /* RW volume exists */
6584 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6585 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6588 } else if (code == ENODEV) { /* RW volume does not exist */
6589 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6590 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6594 /* If VLDB says it didn't exist, then ignore error */
6595 if (entry->flags & RW_EXISTS) {
6596 MapPartIdIntoName(entry->serverPartition[idx], pname);
6598 "Transaction call failed for RW volume %u on server %s %s\n",
6599 entry->volumeId[RWVOL],
6601 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6602 hostutil_GetNameByINet(entry->serverNumber[idx]),
6609 /* Check to see if the BK volume exists and set the BACK_EXISTS
6610 * flag accordingly. idx already ponts to the RW entry.
6612 if (idx == -1) { /* Did not find a RW entry */
6613 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6614 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6617 } else { /* Found a RW entry */
6619 VolumeExists(entry->serverNumber[idx],
6620 entry->serverPartition[idx],
6621 entry->volumeId[BACKVOL]);
6622 if (code == 0) { /* BK volume exists */
6623 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6624 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6627 } else if (code == ENODEV) { /* BK volume does not exist */
6628 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6629 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6633 /* If VLDB says it didn't exist, then ignore error */
6634 if (entry->flags & BACK_EXISTS) {
6635 MapPartIdIntoName(entry->serverPartition[idx], pname);
6637 "Transaction call failed for BK volume %u on server %s %s\n",
6638 entry->volumeId[BACKVOL],
6640 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6641 hostutil_GetNameByINet(entry->serverNumber[idx]),
6648 /* If there is an idx but the BK and RW volumes no
6649 * longer exist, then remove the RW entry.
6651 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6652 && !(entry->flags & BACK_EXISTS)) {
6653 Lp_SetRWValue(entry, entry->serverNumber[idx],
6654 entry->serverPartition[idx], 0L, 0L);
6661 *modified = modentry;
6666 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6669 int foundro = 0, modentry = 0;
6670 afs_int32 code, error = 0;
6677 /* Check to see if the RO volumes exist and set the RO_EXISTS
6680 for (idx = 0; idx < entry->nServers; idx++) {
6681 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6682 continue; /* not a RO */
6686 VolumeExists(entry->serverNumber[idx],
6687 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6688 if (code == 0) { /* RO volume exists */
6690 } else if (code == ENODEV) { /* RW volume does not exist */
6691 Lp_SetROValue(entry, entry->serverNumber[idx],
6692 entry->serverPartition[idx], 0L, 0L);
6697 MapPartIdIntoName(entry->serverPartition[idx], pname);
6699 "Transaction call failed for RO %u on server %s %s\n",
6700 entry->volumeId[ROVOL],
6702 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6703 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6708 if (foundro) { /* A RO volume exists */
6709 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6710 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6713 } else { /* A RO volume does not exist */
6714 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6715 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6722 *modified = modentry;
6727 * Ensure that <entry> matches with the info on file servers
6730 CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
6732 afs_int32 code, error = 0;
6733 struct nvldbentry storeEntry;
6734 int islocked = 0, mod, modentry, delentry = 0;
6735 int pass = 0, doit=1;
6743 fprintf(STDOUT, "_______________________________\n");
6744 fprintf(STDOUT, "\n-- status before -- \n");
6745 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6746 || (entry->flags & BACK_EXISTS))
6747 EnumerateEntry(entry);
6748 fprintf(STDOUT, "\n");
6751 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6752 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6753 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6757 /* Check to see if the VLDB is ok without locking it (pass 1).
6758 * If it will change, then lock the VLDB entry, read it again,
6759 * then make the changes to it (pass 2).
6763 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6766 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6767 entry->volumeId[RWVOL]);
6772 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6774 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6778 MapHostToNetwork(entry);
6784 /* Check if the RW and BK entries are ok */
6785 code = CheckVldbRWBK(entry, &mod);
6788 if (mod && (pass == 1) && doit)
6793 /* Check if the RO volumes entries are ok */
6794 code = CheckVldbRO(entry, &mod);
6797 if (mod && (pass == 1) && doit)
6802 /* The VLDB entry has been updated. If it as been modified, then
6803 * write the entry back out the the VLDB.
6805 if (modentry && doit) {
6809 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6810 && !(entry->flags & RO_EXISTS) && doit) {
6811 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6813 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6817 "Could not delete VLDB entry for volume %u \n",
6818 entry->volumeId[RWVOL]);
6823 /* Replace old entry with our new one */
6824 MapNetworkToHost(entry, &storeEntry);
6826 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6827 (LOCKREL_OPCODE | LOCKREL_AFSID |
6828 LOCKREL_TIMESTAMP));
6830 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6831 entry->volumeId[RWVOL]);
6838 if (modified && modentry) {
6841 if (deleted && delentry) {
6846 fprintf(STDOUT, "-- status after --\n");
6848 fprintf(STDOUT, "\n**entry deleted**\n");
6850 EnumerateEntry(entry);
6852 fprintf(STDOUT, "\n**no change**\n");
6856 VPRINT("\n_______________________________\n");
6860 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6862 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6865 "Could not release lock on VLDB entry for volume %u\n",
6866 entry->volumeId[RWVOL]);
6875 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6878 UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
6880 struct rx_connection *aconn;
6881 afs_int32 code, error = 0;
6882 afs_int32 nentries, tentries = 0;
6883 struct VldbListByAttributes attributes;
6884 nbulkentries arrayEntries;
6885 afs_int32 failures = 0, modified, modifications = 0;
6886 struct nvldbentry *vlentry;
6887 afs_int32 si, nsi, j;
6892 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6894 /* Set up attributes to search VLDB */
6895 attributes.server = ntohl(aserver);
6896 attributes.Mask = VLLIST_SERVER;
6898 attributes.partition = apart;
6899 attributes.Mask |= VLLIST_PARTITION;
6902 VPRINT("Processing VLDB entries ...\n");
6904 /* While we need to collect more VLDB entries */
6905 for (si = 0; si != -1; si = nsi) {
6906 memset(&arrayEntries, 0, sizeof(arrayEntries));
6908 /* Collect set of VLDB entries */
6910 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6911 &arrayEntries, &nsi);
6912 if (code == RXGEN_OPCODE) {
6913 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6917 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6920 tentries += nentries;
6922 for (j = 0; j < nentries; j++) {
6923 vlentry = &arrayEntries.nbulkentries_val[j];
6924 MapHostToNetwork(vlentry);
6926 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6928 /* Tell CheckVldb not to update if appropriate */
6933 code = CheckVldb(vlentry, &modified, NULL);
6935 PrintError("", code);
6937 "Could not process VLDB entry for volume %s\n",
6940 } else if (modified) {
6946 fprintf(STDOUT, "...error encountered\n\n");
6948 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6953 if (arrayEntries.nbulkentries_val) {
6954 free(arrayEntries.nbulkentries_val);
6955 arrayEntries.nbulkentries_val = 0;
6960 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6961 tentries, failures, modifications);
6963 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6964 tentries, failures, modifications);
6969 rx_DestroyConnection(aconn);
6970 if (arrayEntries.nbulkentries_val)
6971 free(arrayEntries.nbulkentries_val);
6974 error = VOLSERFAILEDOP;
6978 /*rename volume <oldname> to <newname>, changing the names of the related
6979 *readonly and backup volumes. This operation is also idempotent.
6980 *salvager is capable of recovering from rename operation stopping halfway.
6981 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6983 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6985 struct nvldbentry storeEntry;
6986 afs_int32 vcode, code, rcode, error;
6988 char nameBuffer[256];
6990 struct rx_connection *aconn;
6995 aconn = (struct rx_connection *)0;
6999 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
7002 " Could not lock the VLDB entry for the volume %u \n",
7003 entry->volumeId[RWVOL]);
7008 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
7009 MapNetworkToHost(entry, &storeEntry);
7010 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
7012 fprintf(STDERR, "Could not update VLDB entry for %u\n",
7013 entry->volumeId[RWVOL]);
7017 VPRINT1("Recorded the new name %s in VLDB\n", newname);
7018 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
7019 * is concerned, oldname is lost */
7020 if (entry->flags & RW_EXISTS) {
7021 index = Lp_GetRwIndex(entry);
7022 if (index == -1) { /* there is a serious discrepancy */
7024 "There is a serious discrepancy in VLDB entry for volume %u\n",
7025 entry->volumeId[RWVOL]);
7026 fprintf(STDERR, "try building VLDB from scratch\n");
7027 error = VOLSERVLDB_ERROR;
7030 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7032 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
7033 entry->serverPartition[index], ITOffline, &tid);
7034 if (code) { /*volume doesnot exist */
7036 "Could not start transaction on the rw volume %u\n",
7037 entry->volumeId[RWVOL]);
7040 } else { /*volume exists, process it */
7043 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
7044 entry->volumeId[RWVOL],
7045 entry->volumeId[ROVOL],
7046 entry->volumeId[BACKVOL]);
7048 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
7049 code = AFSVolEndTrans(aconn, tid, &rcode);
7053 "Could not end transaction on volume %s %u\n",
7054 entry->name, entry->volumeId[RWVOL]);
7059 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
7060 entry->name, entry->volumeId[RWVOL]);
7066 rx_DestroyConnection(aconn);
7067 aconn = (struct rx_connection *)0;
7069 /*end rw volume processing */
7070 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
7071 index = Lp_GetRwIndex(entry);
7072 if (index == -1) { /* there is a serious discrepancy */
7074 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
7075 entry->volumeId[BACKVOL]);
7076 fprintf(STDERR, "try building VLDB from scratch\n");
7077 error = VOLSERVLDB_ERROR;
7080 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
7082 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
7083 entry->serverPartition[index], ITOffline, &tid);
7084 if (code) { /*volume doesnot exist */
7086 "Could not start transaction on the backup volume %u\n",
7087 entry->volumeId[BACKVOL]);
7090 } else { /*volume exists, process it */
7091 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
7093 "Volume name %s.backup exceeds the limit of %u characters\n",
7094 newname, VOLSER_OLDMAXVOLNAME);
7098 strcpy(nameBuffer, newname);
7099 strcat(nameBuffer, ".backup");
7102 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
7103 entry->volumeId[RWVOL], 0, 0);
7105 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
7106 code = AFSVolEndTrans(aconn, tid, &rcode);
7110 "Could not end transaction on the backup volume %u\n",
7111 entry->volumeId[BACKVOL]);
7117 "Could not set parameters on the backup volume %u\n",
7118 entry->volumeId[BACKVOL]);
7123 } /* end backup processing */
7125 rx_DestroyConnection(aconn);
7126 aconn = (struct rx_connection *)0;
7127 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
7128 for (i = 0; i < entry->nServers; i++) {
7129 if (entry->serverFlags[i] & ITSROVOL) {
7130 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
7132 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
7133 entry->serverPartition[i], ITOffline,
7135 if (code) { /*volume doesnot exist */
7137 "Could not start transaction on the ro volume %u\n",
7138 entry->volumeId[ROVOL]);
7141 } else { /*volume exists, process it */
7142 strcpy(nameBuffer, newname);
7143 strcat(nameBuffer, ".readonly");
7144 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
7146 "Volume name %s exceeds the limit of %u characters\n",
7147 nameBuffer, VOLSER_OLDMAXVOLNAME);
7152 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
7153 entry->volumeId[RWVOL], 0, 0);
7155 VPRINT2("Renamed RO volume %s on host %s\n",
7158 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
7159 hostutil_GetNameByINet(entry->
7161 code = AFSVolEndTrans(aconn, tid, &rcode);
7165 "Could not end transaction on volume %u\n",
7166 entry->volumeId[ROVOL]);
7172 "Could not set parameters on the ro volume %u\n",
7173 entry->volumeId[ROVOL]);
7179 rx_DestroyConnection(aconn);
7180 aconn = (struct rx_connection *)0;
7187 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
7189 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
7192 "Could not unlock the VLDB entry for the volume %s %u\n",
7193 entry->name, entry->volumeId[RWVOL]);
7199 code = AFSVolEndTrans(aconn, tid, &rcode);
7203 fprintf(STDERR, "Failed to end transaction on a volume \n");
7209 rx_DestroyConnection(aconn);
7210 PrintError("", error);
7215 /*report on all the active transactions on volser */
7217 UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7219 struct rx_connection *aconn;
7220 transDebugEntries transInfo;
7223 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7224 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7225 transInfo.transDebugEntries_len = 0;
7226 code = AFSVolMonitor(aconn, &transInfo);
7229 "Could not access status information about the server\n");
7230 PrintError("", code);
7231 if (transInfo.transDebugEntries_val)
7232 free(transInfo.transDebugEntries_val);
7234 rx_DestroyConnection(aconn);
7237 *rcount = transInfo.transDebugEntries_len;
7238 *rpntr = transInfo.transDebugEntries_val;
7240 rx_DestroyConnection(aconn);
7247 /*delete the volume without interacting with the vldb */
7249 UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
7251 afs_int32 rcode, ttid, error, code;
7252 struct rx_connection *aconn;
7258 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7259 code = AFSVolTransCreate_retry(aconn, volid, part, ITOffline, &ttid);
7261 fprintf(STDERR, "Could not start transaction on volume %lu\n",
7262 (unsigned long)volid);
7266 code = AFSVolDeleteVolume(aconn, ttid);
7268 fprintf(STDERR, "Could not delete volume %lu\n",
7269 (unsigned long)volid);
7273 code = AFSVolEndTrans(aconn, ttid, &rcode);
7278 fprintf(STDERR, "Could not end transaction on volume %lu\n",
7279 (unsigned long)volid);
7285 code = AFSVolEndTrans(aconn, ttid, &rcode);
7291 PrintError("", error);
7293 rx_DestroyConnection(aconn);
7298 UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7299 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7301 struct rx_connection *conn = 0;
7303 afs_int32 code, error = 0, rcode;
7305 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7307 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7311 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7313 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7317 code = AFSVolSetFlags(conn, tid, setflag);
7319 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7324 #ifdef AFS_PTHREAD_ENV
7327 IOMGR_Sleep(sleeptime);
7334 code = AFSVolEndTrans(conn, tid, &rcode);
7335 if (code || rcode) {
7336 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7338 error = (code ? code : rcode);
7343 rx_DestroyConnection(conn);
7348 UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
7351 struct rx_connection *conn = 0;
7353 afs_int32 code, error = 0, rcode;
7355 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7357 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7361 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7363 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7367 code = AFSVolSetInfo(conn, tid, infop);
7369 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7376 code = AFSVolEndTrans(conn, tid, &rcode);
7377 if (code || rcode) {
7378 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7380 error = (code ? code : rcode);
7385 rx_DestroyConnection(conn);
7390 UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
7391 afs_int32 fromdate, struct volintSize *vol_size)
7393 struct rx_connection *aconn = (struct rx_connection *)0;
7394 afs_int32 tid = 0, rcode = 0;
7395 afs_int32 code, error = 0;
7398 /* get connections to the servers */
7399 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7401 VPRINT1("Starting transaction on volume %u...", afromvol);
7402 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7403 EGOTO1(error_exit, code,
7404 "Could not start transaction on the volume %u to be measured\n",
7408 VPRINT1("Getting size of volume on volume %u...", afromvol);
7409 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7410 EGOTO(error_exit, code, "Could not start the measurement process \n");
7415 VPRINT1("Ending transaction on volume %u...", afromvol);
7416 code = AFSVolEndTrans(aconn, tid, &rcode);
7417 if (code || rcode) {
7418 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7420 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7422 error = (code ? code : rcode);
7427 rx_DestroyConnection(aconn);
7429 PrintError("", error);
7433 /*maps the host addresses in <old > (present in network byte order) to
7434 that in< new> (present in host byte order )*/
7436 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7440 /*copy all the fields */
7441 strcpy(new->name, old->name);
7442 /* new->volumeType = old->volumeType;*/
7443 new->nServers = old->nServers;
7444 count = old->nServers;
7445 if (count < NMAXNSERVERS)
7447 for (i = 0; i < count; i++) {
7448 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7449 new->serverPartition[i] = old->serverPartition[i];
7450 new->serverFlags[i] = old->serverFlags[i];
7452 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7453 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7454 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7455 new->cloneId = old->cloneId;
7456 new->flags = old->flags;
7459 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7461 MapHostToNetwork(struct nvldbentry *entry)
7465 count = entry->nServers;
7466 if (count < NMAXNSERVERS)
7468 for (i = 0; i < count; i++) {
7469 entry->serverNumber[i] = htonl(entry->serverNumber[i]);