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 #ifdef IGNORE_SOME_GCC_WARNINGS
14 # pragma GCC diagnostic warning "-Wformat-extra-args"
18 #include <sys/types.h>
22 #include <sys/statfs.h>
29 #include <netinet/in.h>
33 #include <afs/voldefs.h>
36 #include <afs/vlserver.h>
38 #include <afs/cellconfig.h>
41 #include <afs/afsint.h>
45 #include <afs/com_err.h>
47 #include <afs/kautils.h>
49 #include <afs/ihandle.h>
51 #include <afs/ntops.h>
53 #include <afs/vnode.h>
54 #include <afs/volume.h>
56 #define ERRCODE_RANGE 8 /* from error_table.h */
57 #define CLOCKSKEW 2 /* not really skew, but resolution */
58 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
60 /* for UV_MoveVolume() recovery */
62 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
65 #include "volser_prototypes.h"
66 #include "vsutils_prototypes.h"
67 #include "lockprocs_prototypes.h"
69 struct ubik_client *cstruct;
70 int verbose = 0, noresolve = 0;
75 afs_int32 vldbEntryIndex;
78 /* Utility macros used by rest of this source file */
79 #define EPRINT(ec, es) \
81 fprintf(STDERR, "\n"); \
82 fprintf(STDERR, (es)); \
86 #define EPRINT1(ec, es, ep1) \
88 fprintf(STDERR, "\n"); \
89 fprintf(STDERR, (es), (ep1)); \
93 #define EPRINT2(ec, es, ep1, ep2) \
95 fprintf(STDERR, "\n"); \
96 fprintf(STDERR, (es), (ep1), (ep2)); \
100 #define EPRINT3(ec, es, ep1, ep2, ep3) \
102 fprintf(STDERR, "\n"); \
103 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
104 PrintError(" ",ec); \
107 #define EGOTO(where, ec, es) \
116 #define EGOTO1(where, ec, es, ep1) \
119 EPRINT1((ec),(es),(ep1)); \
125 #define EGOTO2(where, ec, es, ep1, ep2) \
128 EPRINT2((ec),(es),(ep1),(ep2)); \
134 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
137 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
144 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
145 #define VPRINT1(es, p) \
146 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
147 #define VPRINT2(es, p1, p2) \
148 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
149 #define VPRINT3(es, p1, p2, p3) \
150 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
152 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
153 #define VEPRINT(es) \
154 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
155 #define VEPRINT1(es, p) \
156 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
157 #define VEPRINT2(es, p1, p2) \
158 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
159 #define VEPRINT3(es, p1, p2, p3) \
160 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
162 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
166 /* getting rid of this */
167 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
170 /* Protos for static routines */
172 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
173 afs_int32 apart, afs_uint32 okvol,
176 static int DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
178 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
179 struct rx_connection **connPtr, afs_int32 * transPtr,
180 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr);
181 static int SimulateForwardMultiple(struct rx_connection *fromconn,
182 afs_int32 fromtid, afs_int32 fromdate,
183 manyDests * tr, afs_int32 flags,
184 void *cookie, manyResults * results);
185 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
186 afs_int32 apart, afs_int32 * modentry,
187 afs_uint32 * maxvolid);
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);
215 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
216 response = c = getchar();
217 while (!(c == EOF || c == '\n'))
218 c = getchar(); /*skip to end of line */
219 code = (response == 'y' || response == 'Y');
225 PrintError(char *msg, afs_int32 errcode)
227 fprintf(STDERR, msg);
228 /*replace by a big switch statement */
233 fprintf(STDERR, "Possible communication failure\n");
236 fprintf(STDERR, "Volume needs to be salvaged\n");
239 fprintf(STDERR, "Bad vnode number quoted\n");
243 "Volume not attached, does not exist, or not on line\n");
246 fprintf(STDERR, "Volume already exists\n");
249 fprintf(STDERR, "Volume is not in service\n");
252 fprintf(STDERR, "Volume is off line\n");
255 fprintf(STDERR, "Volume is already on line\n");
258 fprintf(STDERR, "Partition is full\n");
261 fprintf(STDERR, "Volume max quota exceeded\n");
264 fprintf(STDERR, "Volume temporarily unavailable\n");
267 fprintf(STDERR, "Volume has moved to another server\n");
270 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
273 fprintf(STDERR, "VLDB: a read terminated too early\n");
276 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
279 fprintf(STDERR, "VLDB: internal creation failure\n");
282 fprintf(STDERR, "VLDB: no such entry\n");
285 fprintf(STDERR, "VLDB: vldb database is empty\n");
288 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
291 fprintf(STDERR, "VLDB: volume name is illegal\n");
294 fprintf(STDERR, "VLDB: index was out of range\n");
297 fprintf(STDERR, "VLDB: bad volume type\n");
300 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
302 case VL_BADPARTITION:
303 fprintf(STDERR, "VLDB: bad partition number\n");
306 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
309 fprintf(STDERR, "VLDB: no such repsite server exists\n");
311 case VL_DUPREPSERVER:
312 fprintf(STDERR, "VLDB: replication site server already exists\n");
315 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
318 fprintf(STDERR, "VLDB: illegal reference count number\n");
320 case VL_SIZEEXCEEDED:
321 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
324 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
326 case VL_BADVOLIDBUMP:
327 fprintf(STDERR, "VLDB: illegal max volid increment\n");
329 case VL_IDALREADYHASHED:
330 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
333 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
336 fprintf(STDERR, "VLDB: bad volume operation code\n");
338 case VL_BADRELLOCKTYPE:
339 fprintf(STDERR, "VLDB: bad release lock type\n");
342 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
344 case VL_BADSERVERFLAG:
345 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
348 fprintf(STDERR, "VLDB: no permission access for call\n");
350 case VOLSERREAD_DUMPERROR:
352 "VOLSER: Problems encountered in reading the dump file !\n");
354 case VOLSERDUMPERROR:
355 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
357 case VOLSERATTACH_ERROR:
358 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
360 case VOLSERDETACH_ERROR:
361 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
363 case VOLSERILLEGAL_PARTITION:
364 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
366 case VOLSERBAD_ACCESS:
367 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
369 case VOLSERVLDB_ERROR:
370 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
373 fprintf(STDERR, "VOLSER: error in volume name\n");
376 fprintf(STDERR, "VOLSER: volume has moved\n");
379 fprintf(STDERR, "VOLSER: illegal operation\n");
381 case VOLSERBADRELEASE:
382 fprintf(STDERR, "VOLSER: release could not be completed\n");
385 fprintf(STDERR, "VOLSER: volume is busy\n");
387 case VOLSERNO_MEMORY:
388 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
392 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
394 case VOLSERMULTIRWVOL:
396 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
400 "VOLSER: not all entries were successfully processed\n");
407 initialize_KA_error_table();
408 initialize_RXK_error_table();
409 initialize_KTC_error_table();
410 initialize_ACFG_error_table();
411 initialize_CMD_error_table();
412 initialize_VL_error_table();
414 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
415 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
416 afs_error_message(errcode));
423 void init_volintInfo(struct volintInfo *vinfo) {
424 memset(vinfo, 0, sizeof(struct volintInfo));
426 vinfo->maxquota = -1;
428 vinfo->creationDate = -1;
429 vinfo->updateDate = -1;
437 static struct rx_securityClass *uvclass = 0;
438 static int uvindex = -1;
439 /* called by VLDBClient_Init to set the security module to be used in the RPC */
441 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
448 /* bind to volser on <port> <aserver> */
449 /* takes server address in network order, port in host order. dumb */
450 struct rx_connection *
451 UV_Bind(afs_int32 aserver, afs_int32 port)
453 register struct rx_connection *tc;
455 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
461 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
462 afs_int32 partition, char *name, afs_int32 type,
463 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
468 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
470 if (code != VOLSERVOLBUSY)
473 #ifdef AFS_PTHREAD_ENV
476 IOMGR_Sleep(3-retries);
483 AFSVolTransCreate_retry(struct rx_connection *z_conn,
484 afs_int32 volume, afs_int32 partition,
485 afs_int32 flags, afs_int32 * trans)
490 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
491 if (code != VOLSERVOLBUSY)
494 #ifdef AFS_PTHREAD_ENV
497 IOMGR_Sleep(3-retries);
504 /* if <okvol> is allright(indicated by beibg able to
505 * start a transaction, delete the <delvol> */
507 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
508 afs_uint32 okvol, afs_uint32 delvol)
510 afs_int32 error, code, tid, rcode;
515 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
518 code = AFSVolDeleteVolume(aconn, tid);
521 code = AFSVolEndTrans(aconn, tid, &rcode);
528 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
530 code = AFSVolEndTrans(aconn, tid, &rcode);
535 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
538 code = AFSVolDeleteVolume(aconn, tid);
541 code = AFSVolEndTrans(aconn, tid, &rcode);
554 /* called by EmuerateEntry, show vldb entry in a reasonable format */
556 SubEnumerateEntry(struct nvldbentry *entry)
564 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
565 if (entry->flags & RW_EXISTS)
566 fprintf(STDOUT, " valid \n");
568 fprintf(STDOUT, " invalid \n");
569 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
570 if (entry->flags & RO_EXISTS)
571 fprintf(STDOUT, " valid \n");
573 fprintf(STDOUT, " invalid \n");
574 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
575 if (entry->flags & BACK_EXISTS)
576 fprintf(STDOUT, " valid \n");
578 fprintf(STDOUT, " invalid \n");
579 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
580 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
582 if (entry->flags & RW_EXISTS)
583 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
584 if (entry->flags & RO_EXISTS)
585 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
586 if (entry->flags & BACK_EXISTS)
587 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
588 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
589 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
590 fprintf(STDOUT, "\n");
592 fprintf(STDOUT, " number of sites -> %lu\n",
593 (unsigned long)entry->nServers);
594 for (i = 0; i < entry->nServers; i++) {
595 if (entry->serverFlags[i] & NEW_REPSITE)
598 for (i = 0; i < entry->nServers; i++) {
599 MapPartIdIntoName(entry->serverPartition[i], pname);
600 fprintf(STDOUT, " server %s partition %s ",
601 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
602 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
603 if (entry->serverFlags[i] & ITSRWVOL)
604 fprintf(STDOUT, "RW Site ");
606 fprintf(STDOUT, "RO Site ");
608 if (entry->serverFlags[i] & NEW_REPSITE)
609 fprintf(STDOUT," -- New release");
611 if (!(entry->serverFlags[i] & ITSRWVOL))
612 fprintf(STDOUT," -- Old release");
614 if (entry->serverFlags[i] & RO_DONTUSE)
615 fprintf(STDOUT, " -- Not released");
617 fprintf(STDOUT, "\n");
624 /*enumerate the vldb entry corresponding to <entry> */
626 EnumerateEntry(struct nvldbentry *entry)
629 fprintf(STDOUT, "\n");
630 fprintf(STDOUT, "%s \n", entry->name);
631 SubEnumerateEntry(entry);
635 /* forcibly remove a volume. Very dangerous call */
637 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_uint32 volid)
639 register struct rx_connection *tconn;
640 register afs_int32 code;
642 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
644 code = AFSVolNukeVolume(tconn, partid, volid);
645 rx_DestroyConnection(tconn);
651 /* like df. Return usage of <pname> on <server> in <partition> */
653 UV_PartitionInfo64(afs_int32 server, char *pname,
654 struct diskPartition64 *partition)
656 register struct rx_connection *aconn;
659 aconn = (struct rx_connection *)0;
660 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
661 code = AFSVolPartitionInfo64(aconn, pname, partition);
662 if (code == RXGEN_OPCODE) {
663 struct diskPartition *dpp =
664 (struct diskPartition *)malloc(sizeof(struct diskPartition));
665 code = AFSVolPartitionInfo(aconn, pname, dpp);
667 strncpy(partition->name, dpp->name, 32);
668 strncpy(partition->devName, dpp->devName, 32);
669 partition->lock_fd = dpp->lock_fd;
670 partition->free = dpp->free;
671 partition->minFree = dpp->minFree;
676 fprintf(STDERR, "Could not get information on partition %s\n", pname);
677 PrintError("", code);
680 rx_DestroyConnection(aconn);
684 /* old interface to create volumes */
686 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
691 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
695 /* less old interface to create volumes */
697 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
698 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
699 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
701 afs_uint32 roid = 0, bkid = 0;
702 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
703 aspare3, aspare4, anewid, &roid, &bkid);
707 * Create a volume on the given server and partition
709 * @param aserver server to create volume on
710 * @param spart partition to create volume on
711 * @param aname name of new volume
712 * @param aquota quota for new volume
713 * @param anewid contains the desired volume id for the new volume. If
714 * *anewid == 0, a new id will be chosen, and will be placed
715 * in *anewid when UV_CreateVolume3 returns.
716 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
717 * will be unset. If *aroid == 0, an id will be chosen, and
718 * will be placed in *anewid when UV_CreateVolume3 returns.
719 * @param abkid same as aroid, except for the BK volume id instead of the
721 * @return 0 on success, error code otherwise.
724 UV_CreateVolume3(afs_int32 aserver, afs_int32 apart, char *aname,
725 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
726 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
727 afs_uint32 * aroid, afs_uint32 * abkid)
729 register struct rx_connection *aconn;
731 register afs_int32 code;
733 afs_int32 rcode, vcode;
735 struct nvldbentry entry, storeEntry; /*the new vldb entry */
736 struct volintInfo tstatus;
739 aconn = (struct rx_connection *)0;
742 init_volintInfo(&tstatus);
743 tstatus.maxquota = aquota;
745 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
747 if (aroid && *aroid) {
748 VPRINT1("Using RO volume ID %d.\n", *aroid);
750 if (abkid && *abkid) {
751 VPRINT1("Using BK volume ID %d.\n", *abkid);
755 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
757 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
760 VPRINT1("Using volume ID %d.\n", *anewid);
762 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
763 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
765 if (aroid && *aroid == 0) {
766 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
767 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
770 if (abkid && *abkid == 0) {
771 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
772 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
776 /* rw,ro, bk id are related in the default case */
777 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
779 if (aroid && *aroid == 0) {
782 if (abkid && *abkid == 0) {
787 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
788 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
791 code = AFSVolSetInfo(aconn, tid, &tstatus);
793 EPRINT(code, "Could not change quota, continuing...\n");
795 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
796 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
799 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
801 /* set up the vldb entry for this volume */
802 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
804 entry.serverNumber[0] = aserver; /* this should have another
805 * level of indirection later */
806 entry.serverPartition[0] = apart; /* this should also have
807 * another indirection level */
808 entry.flags = RW_EXISTS; /* this records that rw volume exists */
809 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
810 entry.volumeId[RWVOL] = *anewid;
811 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
812 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
814 /*map into right byte order, before passing to xdr, the stuff has to be in host
815 * byte order. Xdr converts it into network order */
816 MapNetworkToHost(&entry, &storeEntry);
817 /* create the vldb entry */
818 vcode = VLDB_CreateEntry(&storeEntry);
821 "Could not create a VLDB entry for the volume %s %lu\n",
822 aname, (unsigned long)*anewid);
823 /*destroy the created volume */
824 VPRINT1("Deleting the newly created volume %u\n", *anewid);
825 AFSVolDeleteVolume(aconn, tid);
829 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
830 /* volume created, now terminate the transaction and release the connection */
831 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
832 * the volume will come online anyway when transaction timesout , so if
833 * vldb entry exists then the volume is guaranteed to exist too wrt create */
837 "Failed to end the transaction on the volume %s %lu\n", aname,
838 (unsigned long)*anewid);
845 code = AFSVolEndTrans(aconn, tid, &rcode);
847 fprintf(STDERR, "WARNING: could not end transaction\n");
850 rx_DestroyConnection(aconn);
851 PrintError("", error);
855 /* create a volume, given a server, partition number, volume name --> sends
856 * back new vol id in <anewid>*/
858 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
861 register struct rx_connection *aconn;
864 struct nvldbentry entry, storeEntry; /*the new vldb entry */
866 aconn = (struct rx_connection *)0;
869 /* set up the vldb entry for this volume */
870 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
872 entry.serverNumber[0] = aserver; /* this should have another
873 * level of indirection later */
874 entry.serverPartition[0] = apart; /* this should also have
875 * another indirection level */
876 entry.flags = RW_EXISTS; /* this records that rw volume exists */
877 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
878 entry.volumeId[RWVOL] = aid;
880 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
881 entry.volumeId[BACKVOL] = *anewid + 2;
883 entry.volumeId[ROVOL] = 0;
884 entry.volumeId[BACKVOL] = 0;
887 /*map into right byte order, before passing to xdr, the stuff has to be in host
888 * byte order. Xdr converts it into network order */
889 MapNetworkToHost(&entry, &storeEntry);
890 /* create the vldb entry */
891 vcode = VLDB_CreateEntry(&storeEntry);
894 "Could not create a VLDB entry for the volume %s %lu\n",
895 aname, (unsigned long)aid);
899 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
903 rx_DestroyConnection(aconn);
904 PrintError("", error);
908 /* Delete the volume <volid>on <aserver> <apart>
909 * the physical entry gets removed from the vldb only if the ref count
913 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
915 struct rx_connection *aconn = (struct rx_connection *)0;
917 afs_int32 code, rcode;
919 struct nvldbentry entry, storeEntry;
921 afs_int32 avoltype = -1, vtype;
922 int notondisk = 0, notinvldb = 0;
924 /* Find and read bhe VLDB entry for this volume */
925 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
927 if (code != VL_NOENT) {
928 EGOTO1(error_exit, code,
929 "Could not lock VLDB entry for the volume %u\n", avolid);
935 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
936 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
938 MapHostToNetwork(&entry);
941 EnumerateEntry(&entry);
944 /* Whether volume is in the VLDB or not. Delete the volume on disk */
945 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
946 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
948 if (code == VNOVOL) {
951 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
955 VPRINT1("Trying to delete the volume %u ...", avolid);
957 code = AFSVolDeleteVolume(aconn, ttid);
958 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
960 code = AFSVolEndTrans(aconn, ttid, &rcode);
961 code = (code ? code : rcode);
963 EGOTO1(error_exit, code,
964 "Could not end the transaction for the volume %u \n", avolid);
968 /* Now update the VLDB entry.
969 * But first, verify we have a VLDB entry.
970 * Whether volume is on disk or not. Delete the volume in VLDB.
975 if (avolid == entry.volumeId[BACKVOL]) {
976 /* Its a backup volume, modify the VLDB entry. Check that the
977 * backup volume is on the server/partition we asked to delete.
979 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
980 notinvldb = 2; /* Not on this server and partition */
984 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
986 entry.flags &= ~BACK_EXISTS;
990 else if (avolid == entry.volumeId[ROVOL]) {
991 /* Its a read-only volume, modify the VLDB entry. Check that the
992 * readonly volume is on the server/partition we asked to delete.
993 * If flags does not have RO_EIXSTS set, then this may mean the RO
994 * hasn't been released (and could exist in VLDB).
996 if (!Lp_ROMatch(aserver, apart, &entry)) {
997 notinvldb = 2; /* Not found on this server and partition */
1003 "Marking the readonly volume %lu deleted in the VLDB\n",
1004 (unsigned long)avolid);
1006 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
1008 if (!Lp_ROMatch(0, 0, &entry))
1009 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
1013 else if (avolid == entry.volumeId[RWVOL]) {
1014 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
1015 * Check that the readwrite volumes is on the server/partition we
1018 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
1019 notinvldb = 2; /* Not found on this server and partition */
1023 /* Delete backup if it exists */
1025 AFSVolTransCreate_retry(aconn, entry.volumeId[BACKVOL], apart,
1030 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
1031 entry.volumeId[BACKVOL]);
1034 code = AFSVolDeleteVolume(aconn, ttid);
1035 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
1036 entry.volumeId[BACKVOL]);
1038 code = AFSVolEndTrans(aconn, ttid, &rcode);
1040 code = (code ? code : rcode);
1041 EGOTO1(error_exit, code,
1042 "Could not end the transaction for the volume %u \n",
1043 entry.volumeId[BACKVOL]);
1045 fprintf(STDOUT, " done\n");
1050 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1051 (unsigned long)avolid,
1053 flags & BACK_EXISTS) ? ", and its backup volume," :
1056 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1058 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
1061 if (entry.flags & RO_EXISTS)
1062 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1066 notinvldb = 2; /* Not found on this server and partition */
1070 /* Either delete or replace the VLDB entry */
1071 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
1074 "Last reference to the VLDB entry for %lu - deleting entry\n",
1075 (unsigned long)avolid);
1076 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1077 EGOTO1(error_exit, code,
1078 "Could not delete the VLDB entry for the volume %u \n",
1081 MapNetworkToHost(&entry, &storeEntry);
1083 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1084 (LOCKREL_OPCODE | LOCKREL_AFSID |
1085 LOCKREL_TIMESTAMP));
1086 EGOTO1(error_exit, code,
1087 "Could not update the VLDB entry for the volume %u \n",
1094 EPRINT(error, "\n");
1096 if (notondisk && notinvldb) {
1097 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1098 ((notinvldb == 2) ? "on server and partition" : ""));
1100 error = VOLSERNOVOL;
1101 } else if (notondisk) {
1103 "WARNING: Volume %lu did not exist on the partition\n",
1104 (unsigned long)avolid);
1105 } else if (notinvldb) {
1106 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1107 (unsigned long)avolid,
1108 ((notinvldb == 2) ? "on server and partition" : ""));
1112 code = AFSVolEndTrans(aconn, ttid, &rcode);
1113 code = (code ? code : rcode);
1115 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1116 (unsigned long)avolid);
1117 PrintError("", code);
1125 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1126 (LOCKREL_OPCODE | LOCKREL_AFSID |
1127 LOCKREL_TIMESTAMP));
1130 "Could not release the lock on the VLDB entry for the volume %u \n",
1138 rx_DestroyConnection(aconn);
1142 /* add recovery to UV_MoveVolume */
1144 #define TESTC 0 /* set to test recovery code, clear for production */
1150 sigint_handler(int x)
1155 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1157 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1158 fprintf(STDOUT, "enter second control-c to exit\n");
1162 (void)signal(SIGINT, sigint_handler);
1167 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1168 * <atopart>. The operation is almost idempotent. The following
1169 * flags are recognized:
1171 * RV_NOCLONE - don't use a copy clone
1175 UV_MoveVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1176 afs_int32 atoserver, afs_int32 atopart, int flags)
1178 struct rx_connection *toconn, *fromconn;
1179 afs_int32 fromtid, totid, clonetid;
1182 char tmpName[VOLSER_MAXVOLNAME + 1];
1185 struct restoreCookie cookie;
1186 register afs_int32 vcode, code;
1187 afs_uint32 newVol, volid, backupId;
1188 struct volser_status tstatus;
1189 struct destServer destination;
1191 struct nvldbentry entry, storeEntry;
1192 int i, islocked, pntg;
1194 char in, lf; /* for test code */
1198 #ifdef ENABLE_BUGFIX_1165
1199 volEntries volumeInfo;
1200 struct volintInfo *infop = 0;
1204 fromconn = (struct rx_connection *)0;
1205 toconn = (struct rx_connection *)0;
1215 /* support control-c processing */
1218 (void)signal(SIGINT, sigint_handler);
1222 "\nThere are three tests points - verifies all code paths through recovery.\n");
1223 fprintf(STDOUT, "First test point - operation not started.\n");
1224 fprintf(STDOUT, "...test here (y, n)? ");
1226 fscanf(stdin, "%c", &in);
1227 fscanf(stdin, "%c", &lf); /* toss away */
1229 fprintf(STDOUT, "type control-c\n");
1231 fprintf(stdout, ".");
1236 /* or drop through */
1239 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1240 EGOTO1(mfail, vcode,
1241 "Could not fetch the entry for the volume %u from the VLDB \n",
1244 if (entry.volumeId[RWVOL] != afromvol) {
1245 fprintf(STDERR, "Only RW volume can be moved\n");
1249 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1250 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1253 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1254 EGOTO1(mfail, vcode,
1255 "Could not fetch the entry for the volume %u from the VLDB \n",
1258 backupId = entry.volumeId[BACKVOL];
1259 MapHostToNetwork(&entry);
1261 if (!Lp_Match(afromserver, afrompart, &entry)) {
1262 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1263 if (!Lp_Match(atoserver, atopart, &entry)) {
1264 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1265 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1266 (unsigned long)afromvol);
1267 fprintf(STDERR, "The current site is :");
1268 for (i = 0; i < entry.nServers; i++) {
1269 if (entry.serverFlags[i] == ITSRWVOL) {
1271 MapPartIdIntoName(entry.serverPartition[i], pname);
1272 fprintf(STDERR, " server %s partition %s \n",
1273 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1274 hostutil_GetNameByINet(entry.serverNumber[i]),
1279 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1280 (LOCKREL_OPCODE | LOCKREL_AFSID |
1281 LOCKREL_TIMESTAMP));
1282 EGOTO1(mfail, vcode,
1283 " Could not release lock on the VLDB entry for the volume %u \n",
1286 return VOLSERVOLMOVED;
1289 /* delete the volume afromvol on src_server */
1290 /* from-info does not exist but to-info does =>
1291 * we have already done the move, but the volume
1292 * may still be existing physically on from fileserver
1294 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1299 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITOffline,
1302 if (!code) { /* volume exists - delete it */
1303 VPRINT1("Setting flags on leftover source volume %u ...",
1306 AFSVolSetFlags(fromconn, fromtid,
1307 VTDeleteOnSalvage | VTOutOfService);
1309 "Failed to set flags on the leftover source volume %u\n",
1313 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1314 code = AFSVolDeleteVolume(fromconn, fromtid);
1316 "Failed to delete the leftover source volume %u\n",
1320 VPRINT1("Ending transaction on leftover source volume %u ...",
1322 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1327 "Could not end the transaction for the leftover source volume %u \n",
1332 /*delete the backup volume now */
1335 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
1338 if (!code) { /* backup volume exists - delete it */
1339 VPRINT1("Setting flags on leftover backup volume %u ...",
1342 AFSVolSetFlags(fromconn, fromtid,
1343 VTDeleteOnSalvage | VTOutOfService);
1345 "Failed to set flags on the backup volume %u\n", backupId);
1348 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1349 code = AFSVolDeleteVolume(fromconn, fromtid);
1351 "Could not delete the leftover backup volume %u\n",
1355 VPRINT1("Ending transaction on leftover backup volume %u ...",
1357 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1362 "Could not end the transaction for the leftover backup volume %u\n",
1372 /* From-info matches the vldb info about volid,
1373 * its ok start the move operation, the backup volume
1374 * on the old site is deleted in the process
1376 if (afrompart == atopart) {
1377 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1378 EGOTO2(mfail, error,
1379 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1380 afromserver, error);
1383 EGOTO1(mfail, VOLSERVOLMOVED,
1384 "Warning: Moving volume %u to its home partition ignored!\n",
1390 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1391 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1392 fromtid = totid = 0; /* initialize to uncreated */
1395 * clone the read/write volume locally.
1398 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1399 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1400 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1404 if (!(flags & RV_NOCLONE)) {
1405 /* Get a clone id */
1406 VPRINT1("Allocating new volume id for clone of volume %u ...",
1409 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1410 EGOTO1(mfail, vcode,
1411 "Could not get an ID for the clone of volume %u from the VLDB\n",
1415 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1416 VPRINT1("Cloning source volume %u ...", afromvol);
1417 strcpy(vname, "move-clone-temp");
1419 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1420 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1425 /* lookup the name of the volume we just cloned */
1427 code = AFSVolGetName(fromconn, fromtid, &volName);
1428 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1431 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1433 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1438 "Failed to end the transaction on the source volume %u\n",
1443 * Create the destination volume
1446 if (!(flags & RV_NOCLONE)) {
1447 /* All of this is to get the fromDate */
1448 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1450 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1453 "Failed to start a transaction on the cloned volume%u\n",
1457 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1459 AFSVolSetFlags(fromconn, clonetid,
1460 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1461 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1465 /* remember time from which we've dumped the volume */
1466 VPRINT1("Getting status of cloned volume %u ...", newVol);
1467 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1469 "Failed to get the status of the cloned volume %u\n",
1473 fromDate = CLOCKADJ(tstatus.creationDate);
1475 /* With RV_NOCLONE, just do a full copy from the source */
1480 #ifdef ENABLE_BUGFIX_1165
1482 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1483 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1484 * don't use this information...
1486 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1487 volumeInfo.volEntries_len = 0;
1488 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1490 "Failed to get the volint Info of the cloned volume %u\n",
1493 infop = (volintInfo *) volumeInfo.volEntries_val;
1494 infop->maxquota = -1; /* Else it will replace the default quota */
1495 infop->creationDate = -1; /* Else it will use the source creation date */
1496 infop->updateDate = -1; /* Else it will use the source update date */
1499 /* create a volume on the target machine */
1501 code = AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &totid);
1503 /* Delete the existing volume.
1504 * While we are deleting the volume in these steps, the transaction
1505 * we started against the cloned volume (clonetid above) will be
1506 * sitting idle. It will get cleaned up after 600 seconds
1508 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1509 code = AFSVolDeleteVolume(toconn, totid);
1511 "Could not delete the pre-existing volume %u on destination\n",
1516 ("Ending transaction on pre-existing volume %u on destination ...",
1518 code = AFSVolEndTrans(toconn, totid, &rcode);
1523 "Could not end the transaction on pre-existing volume %u on destination\n",
1528 VPRINT1("Creating the destination volume %u ...", volid);
1530 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1532 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1536 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1540 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1542 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1544 "Failed to set the flags on the destination volume %u\n", volid);
1548 * Now dump the clone to the new volume
1551 destination.destHost = ntohl(atoserver);
1552 destination.destPort = AFSCONF_VOLUMEPORT;
1553 destination.destSSID = 1;
1555 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1556 cookie.type = RWVOL;
1557 cookie.parent = entry.volumeId[RWVOL];
1560 if (!(flags & RV_NOCLONE)) {
1561 /* Copy the clone to the new volume */
1562 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1565 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1567 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1570 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1571 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1576 "Failed to end the transaction on the cloned volume %u\n",
1582 * reattach to the main-line volume, and incrementally dump it.
1585 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1586 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1588 "Failed to create a transaction on the source volume %u\n",
1592 /* now do the incremental */
1594 ("Doing the%s dump from source to destination for volume %u ... ",
1595 (flags & RV_NOCLONE) ? "" : " incremental",
1598 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1601 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1602 (flags & RV_NOCLONE) ? "" : " incremental");
1605 /* now adjust the flags so that the new volume becomes official */
1606 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1607 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1609 "Failed to set the flags to make old source volume offline\n");
1612 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1613 code = AFSVolSetFlags(toconn, totid, 0);
1615 "Failed to set the flags to make new source volume online\n");
1618 #ifdef ENABLE_BUGFIX_1165
1619 VPRINT1("Setting volume status on destination volume %u ...", volid);
1620 code = AFSVolSetInfo(toconn, totid, infop);
1622 "Failed to set volume status on the destination volume %u\n",
1627 /* put new volume online */
1628 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1629 code = AFSVolEndTrans(toconn, totid, &rcode);
1634 "Failed to end the transaction on the volume %u on the new site\n",
1638 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1639 MapNetworkToHost(&entry, &storeEntry);
1640 storeEntry.flags &= ~BACK_EXISTS;
1644 "Second test point - operation in progress but not complete.\n");
1645 fprintf(STDOUT, "...test here (y, n)? ");
1647 fscanf(stdin, "%c", &in);
1648 fscanf(stdin, "%c", &lf); /* toss away */
1650 fprintf(STDOUT, "type control-c\n");
1652 fprintf(stdout, ".");
1657 /* or drop through */
1660 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1662 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1663 (LOCKREL_OPCODE | LOCKREL_AFSID |
1664 LOCKREL_TIMESTAMP));
1667 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1668 storeEntry.name, (unsigned long)afromvol);
1677 "Third test point - operation complete but no cleanup.\n");
1678 fprintf(STDOUT, "...test here (y, n)? ");
1680 fscanf(stdin, "%c", &in);
1681 fscanf(stdin, "%c", &lf); /* toss away */
1683 fprintf(STDOUT, "type control-c\n");
1685 fprintf(stdout, ".");
1690 /* or drop through */
1693 /* This is tricky. File server is very stupid, and if you mark the volume
1694 * as VTOutOfService, it may mark the *good* instance (if you're moving
1695 * between partitions on the same machine) as out of service. Since
1696 * we're cleaning this code up in DEcorum, we're just going to kludge around
1697 * it for now by removing this call. */
1698 /* already out of service, just zap it now */
1700 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1703 "Failed to set the flags to make the old source volume offline\n");
1707 if (atoserver != afromserver) {
1708 /* set forwarding pointer for moved volumes */
1709 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1710 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1712 "Failed to set the forwarding pointer for the volume %u\n",
1717 VPRINT1("Deleting old volume %u on source ...", afromvol);
1718 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1719 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1723 VPRINT1("Ending transaction on old volume %u on the source ...",
1725 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1730 "Failed to end the transaction on the old volume %u on the source\n",
1734 /* Delete the backup volume on the original site */
1735 VPRINT1("Creating transaction for backup volume %u on source ...",
1738 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline, &fromtid);
1741 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1743 AFSVolSetFlags(fromconn, fromtid,
1744 VTDeleteOnSalvage | VTOutOfService);
1746 "Failed to set the flags on the backup volume %u on the source\n",
1750 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1751 code = AFSVolDeleteVolume(fromconn, fromtid);
1753 "Failed to delete the backup volume %u on the source\n",
1757 VPRINT1("Ending transaction on backup volume %u on source ...",
1759 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1764 "Failed to end the transaction on the backup volume %u on the source\n",
1768 code = 0; /* no backup volume? that's okay */
1771 if (!(flags & RV_NOCLONE)) {
1772 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1774 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1777 "Failed to start a transaction on the cloned volume%u\n",
1781 /* now delete the clone */
1782 VPRINT1("Deleting the cloned volume %u ...", newVol);
1783 code = AFSVolDeleteVolume(fromconn, clonetid);
1784 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1788 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1789 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1794 "Failed to end the transaction on the cloned volume %u\n",
1803 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1804 fprintf(STDOUT, "...test here (y, n)? ");
1806 fscanf(stdin, "%c", &in);
1807 fscanf(stdin, "%c", &lf); /* toss away */
1809 fprintf(STDOUT, "type control-c\n");
1811 fprintf(stdout, ".");
1816 /* or drop through */
1819 /* normal cleanup code */
1821 if (entry.flags & RO_EXISTS)
1822 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1825 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1827 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1828 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1832 " Could not release the lock on the VLDB entry for the volume %lu \n",
1833 (unsigned long)afromvol);
1841 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1843 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1844 if (code || rcode) {
1847 "Could not end transaction on the source volume %lu\n",
1848 (unsigned long)afromvol);
1850 error = (code ? code : rcode);
1856 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1857 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1858 if (code || rcode) {
1861 "Could not end transaction on the source's clone volume %lu\n",
1862 (unsigned long)newVol);
1864 error = (code ? code : rcode);
1870 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1872 code = AFSVolEndTrans(toconn, totid, &rcode);
1876 "Could not end transaction on destination volume %lu\n",
1877 (unsigned long)afromvol);
1879 error = (code ? code : rcode);
1885 #ifdef ENABLE_BUGFIX_1165
1890 rx_DestroyConnection(fromconn);
1892 rx_DestroyConnection(toconn);
1893 PrintError("", error);
1896 /* come here only when the sky falls */
1901 "vos move: operation interrupted, cleanup in progress...\n");
1902 fprintf(STDOUT, "clear transaction contexts\n");
1906 /* unlock VLDB entry */
1908 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1909 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1910 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1916 VPRINT("Recovery: Ending transaction on clone volume ...");
1917 AFSVolEndTrans(fromconn, clonetid, &rcode);
1921 VPRINT("Recovery: Ending transaction on destination volume ...");
1922 AFSVolEndTrans(toconn, totid, &rcode);
1925 if (fromtid) { /* put it on-line */
1926 VPRINT("Recovery: Setting volume flags on source volume ...");
1927 AFSVolSetFlags(fromconn, fromtid, 0);
1930 VPRINT("Recovery: Ending transaction on source volume ...");
1931 AFSVolEndTrans(fromconn, fromtid, &rcode);
1935 VPRINT("Recovery: Accessing VLDB.\n");
1936 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1938 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1942 MapHostToNetwork(&entry);
1944 /* Delete either the volume on the source location or the target location.
1945 * If the vldb entry still points to the source location, then we know the
1946 * volume move didn't finish so we remove the volume from the target
1947 * location. Otherwise, we remove the volume from the source location.
1949 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1952 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1956 if (volid && toconn) {
1958 ("Recovery: Creating transaction for destination volume %u ...",
1961 AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &totid);
1967 ("Recovery: Setting flags on destination volume %u ...",
1969 AFSVolSetFlags(toconn, totid,
1970 VTDeleteOnSalvage | VTOutOfService);
1973 VPRINT1("Recovery: Deleting destination volume %u ...",
1975 AFSVolDeleteVolume(toconn, totid);
1979 ("Recovery: Ending transaction on destination volume %u ...",
1981 AFSVolEndTrans(toconn, totid, &rcode);
1985 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1990 /* put source volume on-line */
1992 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1995 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2000 VPRINT1("Recovery: Setting flags on source volume %u ...",
2002 AFSVolSetFlags(fromconn, fromtid, 0);
2006 ("Recovery: Ending transaction on source volume %u ...",
2008 AFSVolEndTrans(fromconn, fromtid, &rcode);
2012 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2016 } else { /* yep, move complete */
2019 "move complete - attempt cleanup of source partition - no guarantee\n");
2023 /* delete backup volume */
2025 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
2028 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
2033 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2035 AFSVolSetFlags(fromconn, fromtid,
2036 VTDeleteOnSalvage | VTOutOfService);
2039 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
2040 AFSVolDeleteVolume(fromconn, fromtid);
2044 ("Recovery: Ending transaction on backup volume %u ...",
2046 AFSVolEndTrans(fromconn, fromtid, &rcode);
2050 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
2054 /* delete source volume */
2055 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2058 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2063 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2065 AFSVolSetFlags(fromconn, fromtid,
2066 VTDeleteOnSalvage | VTOutOfService);
2069 if (atoserver != afromserver) {
2070 VPRINT("Recovery: Setting volume forwarding pointer ...");
2071 AFSVolSetForwarding(fromconn, fromtid, atoserver);
2075 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
2076 AFSVolDeleteVolume(fromconn, fromtid);
2080 ("Recovery: Ending transaction on source volume %u ...",
2082 AFSVolEndTrans(fromconn, fromtid, &rcode);
2086 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2092 /* common cleanup - delete local clone */
2094 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2097 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
2102 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
2103 AFSVolDeleteVolume(fromconn, clonetid);
2106 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2108 AFSVolEndTrans(fromconn, clonetid, &rcode);
2112 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2117 /* unlock VLDB entry */
2119 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2121 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2122 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2126 done: /* routine cleanup */
2129 #ifdef ENABLE_BUGFIX_1165
2134 rx_DestroyConnection(fromconn);
2136 rx_DestroyConnection(toconn);
2139 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2147 UV_MoveVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2148 afs_int32 atoserver, afs_int32 atopart)
2150 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2151 atoserver, atopart, 0);
2155 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2156 * <atopart>. The new volume is named by <atovolname>. The new volume
2157 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2158 * from the VLDB. the following flags are supported:
2160 * RV_RDONLY - target volume is RO
2161 * RV_OFFLINE - leave target volume offline
2162 * RV_CPINCR - do incremental dump if target exists
2163 * RV_NOVLDB - don't create/update VLDB entry
2164 * RV_NOCLONE - don't use a copy clone
2167 UV_CopyVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2168 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2169 afs_uint32 atovolid, int flags)
2171 struct rx_connection *toconn, *fromconn;
2172 afs_int32 fromtid, totid, clonetid;
2175 afs_int32 fromDate, cloneFromDate;
2176 struct restoreCookie cookie;
2177 register afs_int32 vcode, code;
2178 afs_uint32 cloneVol, newVol;
2180 struct volser_status tstatus;
2181 struct destServer destination;
2183 struct nvldbentry entry, newentry, storeEntry;
2189 fromconn = (struct rx_connection *)0;
2190 toconn = (struct rx_connection *)0;
2198 /* support control-c processing */
2201 (void)signal(SIGINT, sigint_handler);
2203 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2204 EGOTO1(mfail, vcode,
2205 "Could not fetch the entry for the volume %u from the VLDB \n",
2207 MapHostToNetwork(&entry);
2210 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2211 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2212 fromtid = totid = 0; /* initialize to uncreated */
2215 /* check if we can shortcut and use a local clone instead of a full copy */
2216 if (afromserver == atoserver && afrompart == atopart) {
2221 * clone the read/write volume locally.
2225 if (!(flags & RV_NOCLONE)) {
2226 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2227 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2229 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2233 /* Get a clone id */
2234 VPRINT1("Allocating new volume id for clone of volume %u ...",
2237 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2238 EGOTO1(mfail, vcode,
2239 "Could not get an ID for the clone of volume %u from the VLDB\n",
2247 /* Get a new volume id */
2248 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2250 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2251 EGOTO1(mfail, vcode,
2252 "Could not get an ID for the copy of volume %u from the VLDB\n",
2257 if (!(flags & RV_NOCLONE)) {
2258 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2259 VPRINT1("Cloning source volume %u ...", afromvol);
2260 strcpy(vname, "copy-clone-temp");
2262 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2264 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2268 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2270 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2275 "Failed to end the transaction on the source volume %u\n",
2281 * Create the destination volume
2284 if (!(flags & RV_NOCLONE)) {
2285 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2287 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2290 "Failed to start a transaction on the cloned volume%u\n",
2294 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2296 AFSVolSetFlags(fromconn, clonetid,
2297 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2298 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2302 /* remember time from which we've dumped the volume */
2303 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2304 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2306 "Failed to get the status of the cloned volume %u\n",
2310 fromDate = CLOCKADJ(tstatus.creationDate);
2315 /* create a volume on the target machine */
2317 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &totid);
2319 if ((flags & RV_CPINCR)) {
2320 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2321 code = AFSVolGetStatus(toconn, totid, &tstatus);
2323 "Failed to get the status of the pre-existing volume %u\n",
2327 /* Using the update date should be OK here, but add some fudge */
2328 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2329 if ((flags & RV_NOCLONE))
2330 fromDate = cloneFromDate;
2332 /* XXX We should check that the source volume's creationDate is
2333 * XXX not newer than the existing target volume, and if not,
2334 * XXX throw away the existing target and do a full dump. */
2339 /* Delete the existing volume.
2340 * While we are deleting the volume in these steps, the transaction
2341 * we started against the cloned volume (clonetid above) will be
2342 * sitting idle. It will get cleaned up after 600 seconds
2344 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2345 code = AFSVolDeleteVolume(toconn, totid);
2347 "Could not delete the pre-existing volume %u on destination\n",
2352 ("Ending transaction on pre-existing volume %u on destination ...",
2354 code = AFSVolEndTrans(toconn, totid, &rcode);
2359 "Could not end the transaction on pre-existing volume %u on destination\n",
2364 VPRINT1("Creating the destination volume %u ...", newVol);
2366 AFSVolCreateVolume(toconn, atopart, atovolname,
2367 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2368 newVol, &newVol, &totid);
2369 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2373 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2375 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2377 "Failed to set the flags on the destination volume %u\n", newVol);
2382 destination.destHost = ntohl(atoserver);
2383 destination.destPort = AFSCONF_VOLUMEPORT;
2384 destination.destSSID = 1;
2386 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2387 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2392 * Now dump the clone to the new volume
2395 if (!(flags & RV_NOCLONE)) {
2396 /* XXX probably should have some code here that checks to see if
2397 * XXX we are copying to same server and partition - if so, just
2398 * XXX use a clone to save disk space */
2400 /* Copy the clone to the new volume */
2401 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2404 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2406 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2410 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2411 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2416 "Failed to end the transaction on the cloned volume %u\n",
2422 * reattach to the main-line volume, and incrementally dump it.
2425 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2426 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2428 "Failed to create a transaction on the source volume %u\n",
2432 /* now do the incremental */
2434 ("Doing the%s dump from source to destination for volume %u ... ",
2435 (flags & RV_NOCLONE) ? "" : " incremental",
2438 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2441 "Failed to do the%s dump from old site to new site\n",
2442 (flags & RV_NOCLONE) ? "" : " incremental");
2445 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2446 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2447 code = AFSVolSetFlags(toconn, totid, volflag);
2449 "Failed to set the flags to make destination volume online\n");
2452 /* put new volume online */
2453 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2454 code = AFSVolEndTrans(toconn, totid, &rcode);
2459 "Failed to end the transaction on the destination volume %u\n",
2463 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2464 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2469 "Failed to end the transaction on the source volume %u\n",
2475 if (!(flags & RV_NOCLONE)) {
2476 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2478 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2481 "Failed to start a transaction on the cloned volume%u\n",
2485 /* now delete the clone */
2486 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2487 code = AFSVolDeleteVolume(fromconn, clonetid);
2488 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2492 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2493 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2498 "Failed to end the transaction on the cloned volume %u\n",
2503 if (!(flags & RV_NOVLDB)) {
2504 /* create the vldb entry for the copied volume */
2505 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2506 newentry.nServers = 1;
2507 newentry.serverNumber[0] = atoserver;
2508 newentry.serverPartition[0] = atopart;
2509 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2510 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2511 newentry.volumeId[RWVOL] = newVol;
2512 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2513 newentry.volumeId[BACKVOL] = 0;
2514 newentry.cloneId = 0;
2515 /*map into right byte order, before passing to xdr, the stuff has to be in host
2516 * byte order. Xdr converts it into network order */
2517 MapNetworkToHost(&newentry, &storeEntry);
2518 /* create the vldb entry */
2519 vcode = VLDB_CreateEntry(&storeEntry);
2522 "Could not create a VLDB entry for the volume %s %lu\n",
2523 atovolname, (unsigned long)newVol);
2524 /*destroy the created volume */
2525 VPRINT1("Deleting the newly created volume %u\n", newVol);
2526 AFSVolDeleteVolume(toconn, totid);
2530 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2534 /* normal cleanup code */
2537 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2539 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2540 if (code || rcode) {
2543 "Could not end transaction on the source volume %lu\n",
2544 (unsigned long)afromvol);
2546 error = (code ? code : rcode);
2552 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2554 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2555 if (code || rcode) {
2558 "Could not end transaction on the source's clone volume %lu\n",
2559 (unsigned long)cloneVol);
2561 error = (code ? code : rcode);
2567 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2569 code = AFSVolEndTrans(toconn, totid, &rcode);
2573 "Could not end transaction on destination volume %lu\n",
2574 (unsigned long)newVol);
2576 error = (code ? code : rcode);
2581 rx_DestroyConnection(fromconn);
2583 rx_DestroyConnection(toconn);
2584 PrintError("", error);
2587 /* come here only when the sky falls */
2592 "vos copy: operation interrupted, cleanup in progress...\n");
2593 fprintf(STDOUT, "clear transaction contexts\n");
2598 VPRINT("Recovery: Ending transaction on clone volume ...");
2599 AFSVolEndTrans(fromconn, clonetid, &rcode);
2603 VPRINT("Recovery: Ending transaction on destination volume ...");
2604 AFSVolEndTrans(toconn, totid, &rcode);
2607 if (fromtid) { /* put it on-line */
2608 VPRINT("Recovery: Ending transaction on source volume ...");
2609 AFSVolEndTrans(fromconn, fromtid, &rcode);
2613 VPRINT("Recovery: Accessing VLDB.\n");
2614 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2616 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2620 MapHostToNetwork(&entry);
2622 /* common cleanup - delete local clone */
2624 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2627 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2632 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2633 AFSVolDeleteVolume(fromconn, clonetid);
2636 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2638 AFSVolEndTrans(fromconn, clonetid, &rcode);
2642 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2647 done: /* routine cleanup */
2649 rx_DestroyConnection(fromconn);
2651 rx_DestroyConnection(toconn);
2654 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2662 UV_CopyVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2663 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2665 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2666 atovolname, atoserver, atopart, 0, 0);
2671 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2672 * if one already exists, update it
2676 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
2678 struct rx_connection *aconn = (struct rx_connection *)0;
2679 afs_int32 ttid = 0, btid = 0;
2680 afs_uint32 backupID;
2681 afs_int32 code = 0, rcode = 0;
2682 char vname[VOLSER_MAXVOLNAME + 1];
2683 struct nvldbentry entry, storeEntry;
2684 afs_int32 error = 0;
2685 int vldblocked = 0, vldbmod = 0, backexists = 1;
2687 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2689 /* the calls to VLDB will succeed only if avolid is a RW volume,
2690 * since we are following the RW hash chain for searching */
2691 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2694 "Could not fetch the entry for the volume %lu from the VLDB \n",
2695 (unsigned long)avolid);
2699 MapHostToNetwork(&entry);
2701 /* These operations require the VLDB be locked since it means the VLDB
2702 * will change or the vldb is already locked.
2704 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2705 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2706 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2708 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2711 "Could not lock the VLDB entry for the volume %lu\n",
2712 (unsigned long)avolid);
2718 /* Reread the vldb entry */
2719 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2722 "Could not fetch the entry for the volume %lu from the VLDB \n",
2723 (unsigned long)avolid);
2727 MapHostToNetwork(&entry);
2730 if (!ISNAMEVALID(entry.name)) {
2731 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2733 error = VOLSERBADNAME;
2737 backupID = entry.volumeId[BACKVOL];
2738 if (backupID == INVALID_BID) {
2739 /* Get a backup volume id from the VLDB and update the vldb
2742 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2745 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2746 (unsigned long)avolid);
2750 entry.volumeId[BACKVOL] = backupID;
2754 /* Test to see if the backup volume exists by trying to create
2755 * a transaction on the backup volume. We've assumed the backup exists.
2757 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2759 if (code != VNOVOL) {
2760 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2761 (unsigned long)backupID);
2765 backexists = 0; /* backup volume does not exist */
2768 code = AFSVolEndTrans(aconn, btid, &rcode);
2770 if (code || rcode) {
2772 "Could not end transaction on the previous backup volume %lu\n",
2773 (unsigned long)backupID);
2774 error = (code ? code : rcode);
2779 /* Now go ahead and try to clone the RW volume.
2780 * First start a transaction on the RW volume
2782 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
2784 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2785 (unsigned long)avolid);
2790 /* Clone or reclone the volume, depending on whether the backup
2791 * volume exists or not
2794 VPRINT1("Re-cloning backup volume %u ...", backupID);
2796 code = AFSVolReClone(aconn, ttid, backupID);
2798 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2799 (unsigned long)backupID);
2804 VPRINT1("Creating a new backup clone %u ...", backupID);
2806 strcpy(vname, entry.name);
2807 strcat(vname, ".backup");
2809 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2811 fprintf(STDERR, "Failed to clone the volume %lu\n",
2812 (unsigned long)avolid);
2818 /* End the transaction on the RW volume */
2819 code = AFSVolEndTrans(aconn, ttid, &rcode);
2821 if (code || rcode) {
2823 "Failed to end the transaction on the rw volume %lu\n",
2824 (unsigned long)avolid);
2825 error = (code ? code : rcode);
2829 /* Mork vldb as backup exists */
2830 if (!(entry.flags & BACK_EXISTS)) {
2831 entry.flags |= BACK_EXISTS;
2835 /* Now go back to the backup volume and bring it on line */
2836 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2839 "Failed to start a transaction on the backup volume %lu\n",
2840 (unsigned long)backupID);
2845 code = AFSVolSetFlags(aconn, btid, 0);
2847 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2848 (unsigned long)backupID);
2853 code = AFSVolEndTrans(aconn, btid, &rcode);
2855 if (code || rcode) {
2857 "Failed to end the transaction on the backup volume %lu\n",
2858 (unsigned long)backupID);
2859 error = (code ? code : rcode);
2865 /* Will update the vldb below */
2869 code = AFSVolEndTrans(aconn, ttid, &rcode);
2870 if (code || rcode) {
2871 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2872 (unsigned long)avolid);
2874 error = (code ? code : rcode);
2879 code = AFSVolEndTrans(aconn, btid, &rcode);
2880 if (code || rcode) {
2882 "Could not end transaction the backup volume %lu\n",
2883 (unsigned long)backupID);
2885 error = (code ? code : rcode);
2889 /* Now update the vldb - if modified */
2892 MapNetworkToHost(&entry, &storeEntry);
2894 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2895 (LOCKREL_OPCODE | LOCKREL_AFSID |
2896 LOCKREL_TIMESTAMP));
2899 "Could not update the VLDB entry for the volume %lu \n",
2900 (unsigned long)avolid);
2906 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2907 (LOCKREL_OPCODE | LOCKREL_AFSID |
2908 LOCKREL_TIMESTAMP));
2911 "Could not unlock the VLDB entry for the volume %lu \n",
2912 (unsigned long)avolid);
2920 rx_DestroyConnection(aconn);
2922 PrintError("", error);
2926 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2927 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2928 * The new volume is named by <aname>, or by appending ".clone" to
2929 * the existing name if <aname> is NULL. The following flags are
2932 * RV_RDONLY - target volume is RO
2933 * RV_OFFLINE - leave target volume offline
2937 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid,
2938 afs_uint32 acloneid, char *aname, int flags)
2940 struct rx_connection *aconn = (struct rx_connection *)0;
2941 afs_int32 ttid = 0, btid = 0;
2942 afs_int32 code = 0, rcode = 0;
2943 char vname[VOLSER_MAXVOLNAME + 1];
2944 afs_int32 error = 0;
2946 volEntries volumeInfo;
2948 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2951 volumeInfo.volEntries_val = (volintInfo *) 0;
2952 volumeInfo.volEntries_len = 0;
2953 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2955 fprintf(stderr, "Could not get info for volume %lu\n",
2956 (unsigned long)avolid);
2960 strncpy(vname, volumeInfo.volEntries_val[0].name,
2961 VOLSER_OLDMAXVOLNAME - 7);
2962 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2963 strcat(vname, ".clone");
2965 if (volumeInfo.volEntries_val)
2966 free(volumeInfo.volEntries_val);
2970 /* Get a clone id */
2971 VPRINT1("Allocating new volume id for clone of volume %u ...",
2973 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2975 "Could not get an ID for the clone of volume %u from the VLDB\n",
2980 /* Test to see if the clone volume exists by trying to create
2981 * a transaction on the clone volume. We've assumed the clone exists.
2983 /* XXX I wonder what happens if the clone has some other parent... */
2984 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2986 if (code != VNOVOL) {
2987 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2988 (unsigned long)acloneid);
2992 backexists = 0; /* backup volume does not exist */
2995 code = AFSVolEndTrans(aconn, btid, &rcode);
2997 if (code || rcode) {
2999 "Could not end transaction on the previous clone volume %lu\n",
3000 (unsigned long)acloneid);
3001 error = (code ? code : rcode);
3006 /* Now go ahead and try to clone the RW volume.
3007 * First start a transaction on the RW volume
3009 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
3011 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
3012 (unsigned long)avolid);
3017 /* Clone or reclone the volume, depending on whether the backup
3018 * volume exists or not
3021 VPRINT1("Re-cloning clone volume %u ...", acloneid);
3023 code = AFSVolReClone(aconn, ttid, acloneid);
3025 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
3026 (unsigned long)acloneid);
3031 VPRINT1("Creating a new clone %u ...", acloneid);
3033 code = AFSVolClone(aconn, ttid, 0,
3034 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
3037 fprintf(STDERR, "Failed to clone the volume %lu\n",
3038 (unsigned long)avolid);
3044 /* End the transaction on the RW volume */
3045 code = AFSVolEndTrans(aconn, ttid, &rcode);
3047 if (code || rcode) {
3049 "Failed to end the transaction on the rw volume %lu\n",
3050 (unsigned long)avolid);
3051 error = (code ? code : rcode);
3055 /* Now go back to the backup volume and bring it on line */
3056 if (!(flags & RV_OFFLINE)) {
3057 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3060 "Failed to start a transaction on the clone volume %lu\n",
3061 (unsigned long)acloneid);
3066 code = AFSVolSetFlags(aconn, btid, 0);
3068 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3069 (unsigned long)acloneid);
3074 code = AFSVolEndTrans(aconn, btid, &rcode);
3076 if (code || rcode) {
3078 "Failed to end the transaction on the clone volume %lu\n",
3079 (unsigned long)acloneid);
3080 error = (code ? code : rcode);
3089 code = AFSVolEndTrans(aconn, ttid, &rcode);
3090 if (code || rcode) {
3091 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3092 (unsigned long)avolid);
3094 error = (code ? code : rcode);
3099 code = AFSVolEndTrans(aconn, btid, &rcode);
3100 if (code || rcode) {
3102 "Could not end transaction on the clone volume %lu\n",
3103 (unsigned long)acloneid);
3105 error = (code ? code : rcode);
3110 rx_DestroyConnection(aconn);
3112 PrintError("", error);
3117 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
3120 afs_int32 acode, ccode, rcode, tid;
3121 ccode = rcode = tid = 0;
3123 acode = AFSVolTransCreate_retry(conn, vid, part, flags, &tid);
3124 if (!acode) { /* It really was there */
3125 acode = AFSVolDeleteVolume(conn, tid);
3127 fprintf(STDERR, "Failed to delete volume %lu.\n",
3128 (unsigned long)vid);
3129 PrintError("", acode);
3131 ccode = AFSVolEndTrans(conn, tid, &rcode);
3135 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3136 (unsigned long)vid);
3137 PrintError("", ccode);
3144 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3145 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3147 /* Get a "transaction" on this replica. Create the volume
3148 * if necessary. Return the time from which a dump should
3149 * be made (0 if it's a new volume)
3152 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3153 struct rx_connection **connPtr, afs_int32 * transPtr,
3154 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr)
3157 struct volser_status tstatus;
3162 *connPtr = (struct rx_connection *)0;
3167 /* get connection to the replication site */
3168 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3170 goto fail; /* server is down */
3172 volid = vldbEntryPtr->volumeId[ROVOL];
3175 AFSVolTransCreate_retry(*connPtr, volid,
3176 vldbEntryPtr->serverPartition[index], ITOffline,
3179 /* If the volume does not exist, create it */
3180 if (!volid || code) {
3184 if (volid && (code != VNOVOL)) {
3185 PrintError("Failed to start a transaction on the RO volume.\n",
3190 strcpy(volname, vldbEntryPtr->name);
3191 strcat(volname, ".readonly");
3195 "Creating new volume %lu on replication site %s: ",
3196 (unsigned long)volid,
3197 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3198 serverNumber[index], hoststr) :
3199 hostutil_GetNameByINet(vldbEntryPtr->
3200 serverNumber[index]));
3205 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3207 vldbEntryPtr->volumeId[RWVOL], &volid,
3210 PrintError("Failed to create the ro volume: ", code);
3213 vldbEntryPtr->volumeId[ROVOL] = volid;
3217 /* The following is a bit redundant, since create sets these flags by default */
3219 AFSVolSetFlags(*connPtr, *transPtr,
3220 VTDeleteOnSalvage | VTOutOfService);
3222 PrintError("Failed to set flags on the ro volume: ", code);
3227 /* Otherwise, the transaction did succeed, so get the creation date of the
3228 * latest RO volume on the replication site
3231 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3232 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3233 serverNumber[index], hoststr) :
3234 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3236 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3238 PrintError("Failed to get status of volume on destination: ",
3242 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3243 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3250 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3255 PrintError("Could not end transaction on a ro volume: ", tcode);
3262 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3263 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3264 void *cookie, manyResults * results)
3268 for (i = 0; i < tr->manyDests_len; i++) {
3269 results->manyResults_val[i] =
3270 AFSVolForward(fromconn, fromtid, fromdate,
3271 &(tr->manyDests_val[i].server),
3272 tr->manyDests_val[i].trans, cookie);
3278 /* UV_ReleaseVolume()
3279 * Release volume <afromvol> on <afromserver> <afrompart> to all
3280 * its RO sites (full release). Unless the previous release was
3281 * incomplete: in which case we bring the remaining incomplete
3282 * volumes up to date with the volumes that were released
3284 * forceflag: Performs a full release.
3286 * Will create a clone from the RW, then dump the clone out to
3287 * the remaining replicas. If there is more than 1 RO sites,
3288 * ensure that the VLDB says at least one RO is available all
3289 * the time: Influences when we write back the VLDB entry.
3293 UV_ReleaseVolume(afs_uint32 afromvol, afs_int32 afromserver,
3294 afs_int32 afrompart, int forceflag)
3298 afs_int32 vcode, rcode, tcode;
3299 afs_uint32 cloneVolId, roVolId;
3300 struct replica *replicas = 0;
3301 struct nvldbentry entry, storeEntry;
3302 int i, volcount, m, fullrelease, vldbindex;
3304 struct restoreCookie cookie;
3305 struct rx_connection **toconns = 0;
3306 struct release *times = 0;
3308 struct rx_connection *fromconn = (struct rx_connection *)0;
3309 afs_int32 error = 0;
3311 afs_int32 clonetid = 0, onlinetid;
3312 afs_int32 fromtid = 0;
3313 afs_uint32 fromdate = 0;
3314 afs_uint32 thisdate;
3318 manyResults results;
3319 int rwindex, roindex, roclone, roexists;
3320 afs_uint32 rwcrdate = 0;
3321 afs_uint32 rwupdate, clcrdate;
3325 } remembertime[NMAXNSERVERS];
3326 int releasecount = 0;
3327 struct volser_status volstatus;
3330 memset((char *)remembertime, 0, sizeof(remembertime));
3331 memset((char *)&results, 0, sizeof(results));
3333 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3334 if (vcode != VL_RERELEASE)
3335 ONERROR(vcode, afromvol,
3336 "Could not lock the VLDB entry for the volume %u.\n");
3339 /* Get the vldb entry in readable format */
3340 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3341 ONERROR(vcode, afromvol,
3342 "Could not fetch the entry for the volume %u from the VLDB.\n");
3343 MapHostToNetwork(&entry);
3346 EnumerateEntry(&entry);
3348 if (!ISNAMEVALID(entry.name))
3349 ONERROR(VOLSERBADOP, entry.name,
3350 "Volume name %s is too long, rename before releasing.\n");
3351 if (entry.volumeId[RWVOL] != afromvol)
3352 ONERROR(VOLSERBADOP, afromvol,
3353 "The volume %u being released is not a read-write volume.\n");
3354 if (entry.nServers <= 1)
3355 ONERROR(VOLSERBADOP, afromvol,
3356 "Volume %u has no replicas - release operation is meaningless!\n");
3357 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3358 ONERROR(VOLSERBADOP, entry.name,
3359 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3361 /* roclone is true if one of the RO volumes is on the same
3362 * partition as the RW volume. In this case, we make the RO volume
3363 * on the same partition a clone instead of a complete copy.
3366 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3367 roclone = ((roindex == -1) ? 0 : 1);
3368 rwindex = Lp_GetRwIndex(&entry);
3370 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3372 /* Make sure we have a RO volume id to work with */
3373 if (entry.volumeId[ROVOL] == INVALID_BID) {
3374 /* need to get a new RO volume id */
3375 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3376 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3378 entry.volumeId[ROVOL] = roVolId;
3379 MapNetworkToHost(&entry, &storeEntry);
3380 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3381 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3384 /* Will we be completing a previously unfinished release. -force overrides */
3385 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3386 if (entry.serverFlags[i] & ITSROVOL) {
3388 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3391 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3394 /* Determine which volume id to use and see if it exists */
3397 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3398 code = VolumeExists(afromserver, afrompart, cloneVolId);
3399 roexists = ((code == ENODEV) ? 0 : 1);
3401 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3403 ONERROR(-1, afromserver,
3404 "Cannot establish connection with server 0x%x\n");
3408 fullrelease = 1; /* Do a full release if RO clone does not exist */
3410 /* Begin transaction on RW and mark it busy while we query it */
3411 code = AFSVolTransCreate_retry(
3412 fromconn, afromvol, afrompart, ITBusy, &fromtid
3414 ONERROR(code, afromvol,
3415 "Failed to start transaction on RW volume %u\n");
3417 /* Query the creation date for the RW */
3418 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3419 ONERROR(code, afromvol,
3420 "Failed to get the status of RW volume %u\n");
3421 rwcrdate = volstatus.creationDate;
3422 rwupdate = volstatus.updateDate;
3424 /* End transaction on RW */
3425 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3427 ONERROR((code ? code : rcode), afromvol,
3428 "Failed to end transaction on RW volume %u\n");
3430 /* Begin transaction on clone and mark it busy while we query it */
3431 code = AFSVolTransCreate_retry(
3432 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3434 ONERROR(code, cloneVolId,
3435 "Failed to start transaction on RW clone %u\n");
3437 /* Query the creation date for the clone */
3438 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3439 ONERROR(code, cloneVolId,
3440 "Failed to get the status of RW clone %u\n");
3441 clcrdate = volstatus.creationDate;
3443 /* End transaction on clone */
3444 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3446 ONERROR((code ? code : rcode), cloneVolId,
3447 "Failed to end transaction on RW clone %u\n");
3449 if (rwcrdate > clcrdate)
3450 fullrelease = 2;/* Do a full release if RO clone older than RW */
3455 switch (fullrelease) {
3457 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3458 (unsigned long)afromvol);
3461 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3462 (unsigned long)afromvol);
3465 fprintf(STDOUT, "This is a completion of a previous release\n");
3471 /* If the RO clone exists, then if the clone is a temporary
3472 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3473 * (it was recently added), then also delete it. We do not
3474 * want to "reclone" a temporary RO clone.
3477 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3478 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3479 if (code && (code != VNOVOL))
3484 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3485 * write this entry out to the vlserver until after the first
3486 * RO volume is released (temp RO clones don't count).
3488 for (i = 0; i < entry.nServers; i++) {
3489 entry.serverFlags[i] &= ~NEW_REPSITE;
3490 entry.serverFlags[i] |= RO_DONTUSE;
3492 entry.serverFlags[rwindex] |= NEW_REPSITE;
3493 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3495 /* Begin transaction on RW and mark it busy while we clone it */
3497 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
3499 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3501 /* Clone or reclone the volume */
3503 VPRINT1("Recloning RW volume %u...", cloneVolId);
3504 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3505 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3509 strcpy(vname, entry.name);
3510 strcat(vname, ".readonly");
3511 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3513 strcpy(vname, "readonly-clone-temp");
3514 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3517 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3519 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3523 /* Get the time the RW was created for future information */
3524 VPRINT1("Getting status of RW volume %u...", afromvol);
3525 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3526 ONERROR(code, afromvol,
3527 "Failed to get the status of the RW volume %u\n");
3529 rwcrdate = volstatus.creationDate;
3530 rwupdate = volstatus.updateDate;
3532 /* End the transaction on the RW volume */
3533 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3534 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3536 ONERROR((code ? code : rcode), afromvol,
3537 "Failed to end cloning transaction on RW %u\n");
3540 /* Remember clone volume ID in case we fail or are interrupted */
3541 entry.cloneId = cloneVolId;
3544 /* Bring the RO clone online - though not if it's a temporary clone */
3545 VPRINT1("Starting transaction on RO clone volume %u...",
3548 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3550 ONERROR(code, cloneVolId,
3551 "Failed to start transaction on volume %u\n");
3554 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3555 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3558 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3559 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3560 ONERROR((code ? code : rcode), cloneVolId,
3561 "Failed to end transaction on RO clone %u\n");
3564 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3566 /* Sleep so that a client searching for an online volume won't
3567 * find the clone offline and then the next RO offline while the
3568 * release brings the clone online and the next RO offline (race).
3569 * There is a fix in the 3.4 client that does not need this sleep
3570 * anymore, but we don't know what clients we have.
3572 if (entry.nServers > 2)
3575 /* Mark the RO clone in the VLDB as a good site (already released) */
3576 entry.serverFlags[roindex] |= NEW_REPSITE;
3577 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3578 entry.flags |= RO_EXISTS;
3582 /* Write out the VLDB entry only if the clone is not a temporary
3583 * clone. If we did this to a temporary clone then we would end
3584 * up marking all the ROs as "old release" making the ROs
3585 * temporarily unavailable.
3587 MapNetworkToHost(&entry, &storeEntry);
3588 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3589 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3590 ONERROR(vcode, entry.name,
3591 "Could not update vldb entry for %s.\n");
3596 /* Now we will release from the clone to the remaining RO replicas.
3597 * The first 2 ROs (counting the non-temporary RO clone) are released
3598 * individually: releasecount. This is to reduce the race condition
3599 * of clients trying to find an on-line RO volume. The remaining ROs
3600 * are released in parallel but no more than half the number of ROs
3601 * (rounded up) at a time: nservers.
3604 strcpy(vname, entry.name);
3605 strcat(vname, ".readonly");
3606 memset(&cookie, 0, sizeof(cookie));
3607 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3608 cookie.type = ROVOL;
3609 cookie.parent = entry.volumeId[RWVOL];
3612 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3614 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3615 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3617 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3619 results.manyResults_val =
3620 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3621 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3623 "Failed to create transaction on the release clone\n");
3625 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3626 memset(times, 0, (sizeof(struct release) * nservers + 1));
3627 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3628 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3630 /* Create a transaction on the cloned volume */
3631 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3633 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3634 if (!fullrelease && code)
3635 ONERROR(VOLSERNOVOL, afromvol,
3636 "Old clone is inaccessible. Try vos release -f %u.\n");
3637 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3640 /* For each index in the VLDB */
3641 for (vldbindex = 0; vldbindex < entry.nServers;) {
3643 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3645 ((volcount < nservers) && (vldbindex < entry.nServers));
3647 /* The first two RO volumes will be released individually.
3648 * The rest are then released in parallel. This is a hack
3649 * for clients not recognizing right away when a RO volume
3650 * comes back on-line.
3652 if ((volcount == 1) && (releasecount < 2))
3655 if (vldbindex == roindex)
3656 continue; /* the clone */
3657 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3658 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3660 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3661 continue; /* not a RO vol */
3664 /* Get a Transaction on this replica. Get a new connection if
3665 * necessary. Create the volume if necessary. Return the
3666 * time from which the dump should be made (0 if it's a new
3667 * volume). Each volume might have a different time.
3669 replicas[volcount].server.destHost =
3670 ntohl(entry.serverNumber[vldbindex]);
3671 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3672 replicas[volcount].server.destSSID = 1;
3673 times[volcount].vldbEntryIndex = vldbindex;
3676 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3677 &(replicas[volcount].trans),
3678 &(times[volcount].crtime),
3679 &(times[volcount].uptime));
3683 /* Thisdate is the date from which we want to pick up all changes */
3684 if (forceflag || !fullrelease
3685 || (rwcrdate > times[volcount].crtime)) {
3686 /* If the forceflag is set, then we want to do a full dump.
3687 * If it's not a full release, we can't be sure that the creation
3688 * date is good (so we also do a full dump).
3689 * If the RW volume was replaced (its creation date is newer than
3690 * the last release), then we can't be sure what has changed (so
3691 * we do a full dump).
3694 } else if (remembertime[vldbindex].validtime) {
3695 /* Trans was prev ended. Use the time from the prev trans
3696 * because, prev trans may have created the volume. In which
3697 * case time[volcount].time would be now instead of 0.
3700 (remembertime[vldbindex].uptime < times[volcount].uptime)
3701 ? remembertime[vldbindex].uptime
3702 : times[volcount].uptime;
3704 thisdate = times[volcount].uptime;
3706 remembertime[vldbindex].validtime = 1;
3707 remembertime[vldbindex].uptime = thisdate;
3709 if (volcount == 0) {
3710 fromdate = thisdate;
3712 /* Include this volume if it is within 15 minutes of the earliest */
3714 thisdate) ? (fromdate - thisdate) : (thisdate -
3716 AFSVolEndTrans(toconns[volcount],
3717 replicas[volcount].trans, &rcode);
3718 replicas[volcount].trans = 0;
3721 if (thisdate < fromdate)
3722 fromdate = thisdate;
3730 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3731 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3732 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3733 vldbEntryIndex], hoststr) :
3734 hostutil_GetNameByINet(entry.
3735 serverNumber[times[0].
3738 for (s = 1; s < volcount; s++) {
3739 fprintf(STDOUT, " and %s",
3740 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3741 vldbEntryIndex], hoststr) :
3742 hostutil_GetNameByINet(entry.
3743 serverNumber[times[s].
3748 fprintf(STDOUT, " (full release)");
3751 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3753 fprintf(STDOUT, ".\n");
3757 /* Release the ones we have collected */
3758 tr.manyDests_val = &(replicas[0]);
3759 tr.manyDests_len = results.manyResults_len = volcount;
3761 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3762 0 /*spare */ , &cookie, &results);
3763 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3765 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3766 0 /*spare */ , &cookie, &results);
3771 PrintError("Release failed: ", code);
3773 for (m = 0; m < volcount; m++) {
3774 if (results.manyResults_val[m]) {
3775 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3776 /* we retry timed out transaction. When it is
3777 * not the first volume and the transaction wasn't found
3778 * (assume it timed out and was garbage collected by volser).
3781 ("Failed to dump volume from clone to a ro site: ",
3782 results.manyResults_val[m]);
3788 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3789 ROVOL, entry.volumeId[RWVOL], 0, 0);
3791 if ((m == 0) || (code != ENOENT)) {
3792 PrintError("Failed to set correct names and ids: ",
3798 /* have to clear dest. flags to ensure new vol goes online:
3799 * because the restore (forwarded) operation copied
3800 * the V_inService(=0) flag over to the destination.
3802 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3804 if ((m == 0) || (code != ENOENT)) {
3805 PrintError("Failed to set flags on ro volume: ",
3811 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3812 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3813 entry.flags |= RO_EXISTS;
3818 /* End the transactions and destroy the connections */
3819 for (s = 0; s < volcount; s++) {
3820 if (replicas[s].trans)
3821 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3822 replicas[s].trans = 0;
3826 if ((s == 0) || (code != ENOENT)) {
3827 PrintError("Could not end transaction on a ro volume: ",
3831 ("Transaction timed out on a ro volume. Will retry.\n",
3833 if (times[s].vldbEntryIndex < vldbindex)
3834 vldbindex = times[s].vldbEntryIndex;
3839 rx_DestroyConnection(toconns[s]);
3843 MapNetworkToHost(&entry, &storeEntry);
3844 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3845 ONERROR(vcode, afromvol,
3846 " Could not update VLDB entry for volume %u\n");
3847 } /* for each index in the vldb */
3849 /* End the transaction on the cloned volume */
3850 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3855 PrintError("Failed to end transaction on rw volume: ", code);
3857 /* Figure out if any volume were not released and say so */
3858 for (failure = 0, i = 0; i < entry.nServers; i++) {
3859 if (!(entry.serverFlags[i] & NEW_REPSITE))
3865 "The volume %lu could not be released to the following %d sites:\n",
3866 (unsigned long)afromvol, failure);
3867 for (i = 0; i < entry.nServers; i++) {
3868 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3869 MapPartIdIntoName(entry.serverPartition[i], pname);
3870 fprintf(STDERR, "\t%35s %s\n",
3871 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
3872 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3876 MapNetworkToHost(&entry, &storeEntry);
3878 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3880 ONERROR(vcode, afromvol,
3881 " Could not update VLDB entry for volume %u\n");
3883 ERROREXIT(VOLSERBADRELEASE);
3886 /* All the ROs were release successfully. Remove the temporary clone */
3889 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3890 (unsigned long)cloneVolId);
3893 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3894 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3899 for (i = 0; i < entry.nServers; i++)
3900 entry.serverFlags[i] &= ~NEW_REPSITE;
3902 /* Update the VLDB */
3903 VPRINT("updating VLDB ...");
3905 MapNetworkToHost(&entry, &storeEntry);
3907 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3908 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3909 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3914 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3918 "Failed to end cloning transaction on the RW volume %lu\n",
3919 (unsigned long)afromvol);
3925 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3929 "Failed to end transaction on the release clone %lu\n",
3930 (unsigned long)cloneVolId);
3935 for (i = 0; i < nservers; i++) {
3936 if (replicas && replicas[i].trans) {
3937 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3938 replicas[i].trans = 0;
3941 "Failed to end transaction on ro volume %u at server %s\n",
3942 entry.volumeId[ROVOL],
3943 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
3944 destHost), hoststr) :
3945 hostutil_GetNameByINet(htonl
3946 (replicas[i].server.destHost)));
3951 if (toconns && toconns[i]) {
3952 rx_DestroyConnection(toconns[i]);
3958 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3959 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3962 "Could not release lock on the VLDB entry for volume %lu\n",
3963 (unsigned long)afromvol);
3969 PrintError("", error);
3972 rx_DestroyConnection(fromconn);
3973 if (results.manyResults_val)
3974 free(results.manyResults_val);
3986 dump_sig_handler(int x)
3988 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3992 /* Dump the volume <afromvol> on <afromserver> and
3993 * <afrompart> to <afilename> starting from <fromdate>.
3994 * DumpFunction does the real work behind the scenes after
3995 * extracting parameters from the rock
3998 UV_DumpVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
4000 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4003 struct rx_connection *fromconn = (struct rx_connection *)0;
4004 struct rx_call *fromcall = (struct rx_call *)0;
4005 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4006 afs_int32 code, error = 0, retry = 0;
4007 time_t tmv = fromdate;
4011 #ifndef AFS_NT40_ENV
4012 (void)signal(SIGPIPE, dump_sig_handler);
4014 (void)signal(SIGINT, dump_sig_handler);
4017 VEPRINT("Full Dump ...\n");
4019 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4023 /* get connections to the servers */
4024 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4026 VEPRINT1("Starting transaction on volume %u...", afromvol);
4027 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4028 EGOTO1(error_exit, code,
4029 "Could not start transaction on the volume %u to be dumped\n",
4033 fromcall = rx_NewCall(fromconn);
4035 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4036 if (flags & VOLDUMPV2_OMITDIRS)
4037 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4040 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4041 EGOTO(error_exit, code, "Could not start the dump process \n");
4044 VEPRINT1("Dumping volume %u...", afromvol);
4045 code = DumpFunction(fromcall, rock);
4046 if (code == RXGEN_OPCODE)
4048 EGOTO(error_exit, code, "Error while dumping volume \n");
4053 code = rx_EndCall(fromcall, rxError);
4054 if (code && code != RXGEN_OPCODE)
4055 fprintf(STDERR, "Error in rx_EndCall\n");
4060 VEPRINT1("Ending transaction on volume %u...", afromvol);
4061 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4062 if (code || rcode) {
4063 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4064 (unsigned long)afromvol);
4066 error = (code ? code : rcode);
4071 rx_DestroyConnection(fromconn);
4075 if (error != RXGEN_OPCODE)
4076 PrintError("", error);
4080 /* Clone the volume <afromvol> on <afromserver> and
4081 * <afrompart>, and then dump the clone volume to
4082 * <afilename> starting from <fromdate>.
4083 * DumpFunction does the real work behind the scenes after
4084 * extracting parameters from the rock
4087 UV_DumpClonedVolume(afs_uint32 afromvol, afs_int32 afromserver,
4088 afs_int32 afrompart, afs_int32 fromdate,
4089 afs_int32(*DumpFunction) (struct rx_call *, void *),
4090 void *rock, afs_int32 flags)
4092 struct rx_connection *fromconn = (struct rx_connection *)0;
4093 struct rx_call *fromcall = (struct rx_call *)0;
4094 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4095 afs_int32 clonetid = 0;
4096 afs_int32 code = 0, error = 0;
4097 afs_uint32 clonevol = 0;
4099 time_t tmv = fromdate;
4103 #ifndef AFS_NT40_ENV
4104 (void)signal(SIGPIPE, dump_sig_handler);
4106 (void)signal(SIGINT, dump_sig_handler);
4109 VEPRINT("Full Dump ...\n");
4111 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4115 /* get connections to the servers */
4116 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4118 VEPRINT1("Starting transaction on volume %u...", afromvol);
4119 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4120 EGOTO1(error_exit, code,
4121 "Could not start transaction on the volume %u to be dumped\n",
4125 /* Get a clone id */
4126 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4127 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
4128 EGOTO1(error_exit, code,
4129 "Could not get an ID for the clone of volume %u from the VLDB\n",
4133 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4134 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4136 strcpy(vname, "dump-clone-temp");
4138 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
4139 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4143 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4145 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4149 EGOTO1(error_exit, code,
4150 "Failed to end the transaction on the volume %u\n", afromvol);
4154 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4156 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4158 EGOTO1(error_exit, code,
4159 "Failed to start a transaction on the cloned volume%u\n",
4163 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4164 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4165 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4170 fromcall = rx_NewCall(fromconn);
4172 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4173 if (flags & VOLDUMPV2_OMITDIRS)
4174 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4176 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4177 EGOTO(error_exit, code, "Could not start the dump process \n");
4180 VEPRINT1("Dumping volume %u...", afromvol);
4181 code = DumpFunction(fromcall, rock);
4182 EGOTO(error_exit, code, "Error while dumping volume \n");
4186 /* now delete the clone */
4187 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4188 code = AFSVolDeleteVolume(fromconn, clonetid);
4190 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4191 (unsigned long)clonevol);
4197 code = rx_EndCall(fromcall, rxError);
4199 fprintf(STDERR, "Error in rx_EndCall\n");
4205 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4206 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4207 if (code || rcode) {
4209 "Could not end transaction on the cloned volume %lu\n",
4210 (unsigned long)clonevol);
4212 error = (code ? code : rcode);
4217 rx_DestroyConnection(fromconn);
4219 PrintError("", error);
4226 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4227 * the dump file <afilename>. WriteData does all the real work
4228 * after extracting params from the rock
4231 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_uint32 tovolid,
4232 afs_int32 toparentid, char tovolname[], int flags,
4233 afs_int32(*WriteData) (struct rx_call *, void *),
4236 struct rx_connection *toconn, *tempconn;
4237 struct rx_call *tocall;
4238 afs_int32 totid, code, rcode, vcode, terror = 0;
4239 afs_int32 rxError = 0;
4240 struct volser_status tstatus;
4241 struct volintInfo vinfo;
4243 char tovolreal[VOLSER_OLDMAXVOLNAME];
4245 afs_int32 temptid, pparentid;
4247 struct nvldbentry entry, storeEntry;
4250 struct restoreCookie cookie;
4252 afs_int32 volflag, voltype, volsertype;
4253 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4254 int index, same, errcode;
4258 memset(&cookie, 0, sizeof(cookie));
4263 tocall = (struct rx_call *)0;
4264 toconn = (struct rx_connection *)0;
4265 tempconn = (struct rx_connection *)0;
4269 if (flags & RV_RDONLY) {
4271 volsertype = volser_RO;
4274 volsertype = volser_RW;
4278 pparentid = toparentid;
4279 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4280 if (pvolid == 0) { /*alot a new id if needed */
4281 vcode = VLDB_GetEntryByName(tovolname, &entry);
4282 if (vcode == VL_NOENT) {
4283 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4285 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4291 } else if (flags & RV_RDONLY) {
4292 if (entry.flags & RW_EXISTS) {
4294 "Entry for ReadWrite volume %s already exists!\n",
4296 error = VOLSERBADOP;
4299 if (!entry.volumeId[ROVOL]) {
4301 "Existing entry for volume %s has no ReadOnly ID\n",
4303 error = VOLSERBADOP;
4306 pvolid = entry.volumeId[ROVOL];
4307 pparentid = entry.volumeId[RWVOL];
4309 pvolid = entry.volumeId[RWVOL];
4310 pparentid = entry.volumeId[RWVOL];
4313 if (!pparentid) pparentid = pvolid;
4314 /* at this point we have a volume id to use/reuse for the volume to be restored */
4315 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4317 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4318 EGOTO1(refail, VOLSERBADOP,
4319 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4322 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4323 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4324 EGOTO1(refail, VOLSERBADOP,
4325 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4327 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4330 MapPartIdIntoName(topart, partName);
4331 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4332 tovolreal, (unsigned long)pvolid,
4333 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4334 hostutil_GetNameByINet(toserver), partName);
4337 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4340 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4341 VPRINT1("Deleting the previous volume %u ...", pvolid);
4344 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4345 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4348 code = AFSVolGetStatus(toconn, totid, &tstatus);
4349 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4352 oldCreateDate = tstatus.creationDate;
4353 oldUpdateDate = tstatus.updateDate;
4356 AFSVolSetFlags(toconn, totid,
4357 VTDeleteOnSalvage | VTOutOfService);
4358 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4361 code = AFSVolDeleteVolume(toconn, totid);
4362 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4364 code = AFSVolEndTrans(toconn, totid, &rcode);
4368 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4373 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4375 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4378 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4379 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4382 code = AFSVolGetStatus(toconn, totid, &tstatus);
4383 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4386 oldCreateDate = tstatus.creationDate;
4387 oldUpdateDate = tstatus.updateDate;
4394 cookie.parent = pparentid;
4395 cookie.type = voltype;
4397 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4399 tocall = rx_NewCall(toconn);
4400 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4402 fprintf(STDERR, "Volume restore Failed \n");
4406 code = WriteData(tocall, rock);
4408 fprintf(STDERR, "Could not transmit data\n");
4412 terror = rx_EndCall(tocall, rxError);
4413 tocall = (struct rx_call *)0;
4415 fprintf(STDERR, "rx_EndCall Failed \n");
4419 code = AFSVolGetStatus(toconn, totid, &tstatus);
4422 "Could not get status information about the volume %lu\n",
4423 (unsigned long)pvolid);
4427 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4429 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4430 (unsigned long)pvolid);
4435 if (flags & RV_CRDUMP)
4436 newCreateDate = tstatus.creationDate;
4437 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4438 newCreateDate = oldCreateDate;
4440 newCreateDate = time(0);
4441 if (flags & RV_LUDUMP)
4442 newUpdateDate = tstatus.updateDate;
4443 else if (flags & RV_LUKEEP)
4444 newUpdateDate = oldUpdateDate;
4446 newUpdateDate = time(0);
4447 code = AFSVolSetDate(toconn,totid, newCreateDate);
4449 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4454 init_volintInfo(&vinfo);
4455 vinfo.creationDate = newCreateDate;
4456 vinfo.updateDate = newUpdateDate;
4457 code = AFSVolSetInfo(toconn, totid, &vinfo);
4459 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4465 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4466 code = AFSVolSetFlags(toconn, totid, volflag);
4468 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4473 /* It isn't handled right in refail */
4474 code = AFSVolEndTrans(toconn, totid, &rcode);
4479 fprintf(STDERR, "Could not end transaction on %lu\n",
4480 (unsigned long)pvolid);
4486 fprintf(STDOUT, " done\n");
4488 if (success && (!reuseID || (flags & RV_FULLRST))) {
4489 /* Volume was restored on the file server, update the
4490 * VLDB to reflect the change.
4492 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4493 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4495 "Could not fetch the entry for volume number %lu from VLDB \n",
4496 (unsigned long)pvolid);
4501 MapHostToNetwork(&entry);
4502 if (vcode == VL_NOENT) { /* it doesnot exist already */
4503 /*make the vldb return this indication specifically */
4504 VPRINT("------- Creating a new VLDB entry ------- \n");
4505 strcpy(entry.name, tovolname);
4507 entry.serverNumber[0] = toserver; /*should be indirect */
4508 entry.serverPartition[0] = topart;
4509 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4510 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4511 if (flags & RV_RDONLY)
4512 entry.volumeId[ROVOL] = pvolid;
4513 else if (tstatus.cloneID != 0) {
4514 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4516 entry.volumeId[ROVOL] = INVALID_BID;
4517 entry.volumeId[RWVOL] = pparentid;
4519 if (tstatus.backupID != 0) {
4520 entry.volumeId[BACKVOL] = tstatus.backupID;
4521 /*this should come from status info on the volume if non zero */
4523 entry.volumeId[BACKVOL] = INVALID_BID;
4524 MapNetworkToHost(&entry, &storeEntry);
4525 vcode = VLDB_CreateEntry(&storeEntry);
4528 "Could not create the VLDB entry for volume number %lu \n",
4529 (unsigned long)pvolid);
4535 EnumerateEntry(&entry);
4536 } else { /*update the existing entry */
4538 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4539 fprintf(STDOUT, "------- Old entry -------\n");
4540 EnumerateEntry(&entry);
4541 fprintf(STDOUT, "------- New entry -------\n");
4544 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4548 "Could not lock the entry for volume number %lu \n",
4549 (unsigned long)pvolid);
4554 strcpy(entry.name, tovolname);
4556 /* Update the vlentry with the new information */
4557 if (flags & RV_RDONLY)
4558 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4560 index = Lp_GetRwIndex(&entry);
4562 /* Add the new site for the volume being restored */
4563 entry.serverNumber[entry.nServers] = toserver;
4564 entry.serverPartition[entry.nServers] = topart;
4565 entry.serverFlags[entry.nServers] =
4566 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4569 /* This volume should be deleted on the old site
4570 * if its different from new site.
4573 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4577 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4579 if ((!errcode && !same)
4580 || (entry.serverPartition[index] != topart)) {
4581 if (flags & RV_NODEL) {
4583 ("Not deleting the previous volume %u on server %s, ...",
4585 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4586 hostutil_GetNameByINet(entry.serverNumber[index]));
4589 UV_Bind(entry.serverNumber[index],
4590 AFSCONF_VOLUMEPORT);
4592 MapPartIdIntoName(entry.serverPartition[index],
4595 ("Deleting the previous volume %u on server %s, partition %s ...",
4597 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4598 hostutil_GetNameByINet(entry.serverNumber[index]),
4601 AFSVolTransCreate_retry(tempconn, pvolid,
4602 entry.serverPartition[index],
4603 ITOffline, &temptid);
4606 AFSVolSetFlags(tempconn, temptid,
4611 "Could not set flags on volume %lu on the older site\n",
4612 (unsigned long)pvolid);
4616 code = AFSVolDeleteVolume(tempconn, temptid);
4619 "Could not delete volume %lu on the older site\n",
4620 (unsigned long)pvolid);
4624 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4630 "Could not end transaction on volume %lu on the older site\n",
4631 (unsigned long)pvolid);
4636 MapPartIdIntoName(entry.serverPartition[index],
4641 entry.serverNumber[index] = toserver;
4642 entry.serverPartition[index] = topart;
4645 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4646 MapNetworkToHost(&entry, &storeEntry);
4648 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4649 LOCKREL_OPCODE | LOCKREL_AFSID |
4653 "Could not update the entry for volume number %lu \n",
4654 (unsigned long)pvolid);
4660 EnumerateEntry(&entry);
4667 code = rx_EndCall(tocall, rxError);
4673 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4674 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4677 "Could not release lock on the VLDB entry for the volume %lu\n",
4678 (unsigned long)pvolid);
4684 code = AFSVolEndTrans(toconn, totid, &rcode);
4688 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4689 (unsigned long)pvolid);
4695 code = AFSVolEndTrans(toconn, temptid, &rcode);
4699 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4700 (unsigned long)pvolid);
4706 rx_DestroyConnection(tempconn);
4708 rx_DestroyConnection(toconn);
4709 PrintError("", error);
4714 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_uint32 tovolid,
4715 char tovolname[], int flags,
4716 afs_int32(*WriteData) (struct rx_call *, void *),
4719 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4724 /*unlocks the vldb entry associated with <volid> */
4726 UV_LockRelease(afs_uint32 volid)
4730 VPRINT("Binding to the VLDB server\n");
4732 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4733 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4736 "Could not unlock the entry for volume number %lu in VLDB \n",
4737 (unsigned long)volid);
4738 PrintError("", vcode);
4741 VPRINT("VLDB updated\n");
4746 /* old interface to add rosites */
4748 UV_AddSite(afs_int32 server, afs_int32 part, afs_uint32 volid,
4751 return UV_AddSite2(server, part, volid, 0, valid);
4754 /*adds <server> and <part> as a readonly replication site for <volid>
4757 UV_AddSite2(afs_int32 server, afs_int32 part, afs_uint32 volid,
4758 afs_uint32 rovolid, afs_int32 valid)
4760 int j, nro = 0, islocked = 0;
4761 struct nvldbentry entry, storeEntry, entry2;
4762 afs_int32 vcode, error = 0;
4765 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4768 " Could not lock the VLDB entry for the volume %lu \n",
4769 (unsigned long)volid);
4774 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4777 "Could not fetch the VLDB entry for volume number %lu \n",
4778 (unsigned long)volid);
4782 if (!ISNAMEVALID(entry.name)) {
4784 "Volume name %s is too long, rename before adding site\n",
4786 error = VOLSERBADOP;
4789 MapHostToNetwork(&entry);
4791 /* See if it's too many entries */
4792 if (entry.nServers >= NMAXNSERVERS) {
4793 fprintf(STDERR, "Total number of entries will exceed %u\n",
4795 error = VOLSERBADOP;
4799 /* See if it's on the same server */
4800 for (j = 0; j < entry.nServers; j++) {
4801 if (entry.serverFlags[j] & ITSROVOL) {
4803 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4806 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4809 MapPartIdIntoName(entry.serverPartition[j], apartName);
4811 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4813 error = VOLSERBADOP;
4820 /* See if it's too many RO sites - leave one for the RW */
4821 if (nro >= NMAXNSERVERS - 1) {
4822 fprintf(STDERR, "Total number of sites will exceed %u\n",
4824 error = VOLSERBADOP;
4828 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
4829 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
4830 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
4833 if (entry.volumeId[ROVOL] == INVALID_BID) {
4834 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
4836 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
4839 VPRINT1("Using RO volume id %d.\n", rovolid);
4840 entry.volumeId[ROVOL] = rovolid;
4842 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
4843 rovolid, entry.volumeId[ROVOL]);
4847 VPRINT("Adding a new site ...");
4848 entry.serverNumber[entry.nServers] = server;
4849 entry.serverPartition[entry.nServers] = part;
4851 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4853 entry.serverFlags[entry.nServers] = (ITSROVOL);
4857 MapNetworkToHost(&entry, &storeEntry);
4859 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4860 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4862 fprintf(STDERR, "Could not update entry for volume %lu \n",
4863 (unsigned long)volid);
4872 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4873 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4876 "Could not release lock on volume entry for %lu \n",
4877 (unsigned long)volid);
4878 PrintError("", vcode);
4882 PrintError("", error);
4886 /*removes <server> <part> as read only site for <volid> from the vldb */
4888 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_uint32 volid)
4891 struct nvldbentry entry, storeEntry;
4894 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4896 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4897 (unsigned long)volid);
4898 PrintError("", vcode);
4902 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4905 "Could not fetch the entry for volume number %lu from VLDB \n",
4906 (unsigned long)volid);
4907 PrintError("", vcode);
4910 MapHostToNetwork(&entry);
4911 if (!Lp_ROMatch(server, part, &entry)) {
4912 /*this site doesnot exist */
4913 fprintf(STDERR, "This site is not a replication site \n");
4915 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4916 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4918 fprintf(STDERR, "Could not update entry for volume %lu \n",
4919 (unsigned long)volid);
4920 PrintError("", vcode);
4921 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4922 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4926 } else { /*remove the rep site */
4927 Lp_SetROValue(&entry, server, part, 0, 0);
4929 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4930 entry.flags &= ~RO_EXISTS;
4931 if (entry.nServers < 1) { /*this is the last ref */
4932 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4934 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4937 "Could not delete VLDB entry for volume %lu \n",
4938 (unsigned long)volid);
4939 PrintError("", vcode);
4944 MapNetworkToHost(&entry, &storeEntry);
4945 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4946 (unsigned long)volid);
4949 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4950 LOCKREL_OPCODE | LOCKREL_AFSID |
4954 "Could not release lock on volume entry for %lu \n",
4955 (unsigned long)volid);
4956 PrintError("", vcode);
4957 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4958 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4966 /*sets <server> <part> as read/write site for <volid> in the vldb */
4968 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_uint32 volid)
4971 struct nvldbentry entry, storeEntry;
4974 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4976 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4977 (unsigned long)volid);
4978 PrintError("", vcode);
4981 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4984 "Could not fetch the entry for volume number %lu from VLDB \n",
4985 (unsigned long)volid);
4986 PrintError("", vcode);
4989 MapHostToNetwork(&entry);
4990 index = Lp_GetRwIndex(&entry);
4992 /* no RW site exists */
4993 fprintf(STDERR, "No existing RW site for volume %lu",
4994 (unsigned long)volid);
4996 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4997 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5000 "Could not release lock on entry for volume %lu \n",
5001 (unsigned long)volid);
5002 PrintError("", vcode);
5006 } else { /* change the RW site */
5007 entry.serverNumber[index] = server;
5008 entry.serverPartition[index] = part;
5009 MapNetworkToHost(&entry, &storeEntry);
5011 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5012 LOCKREL_OPCODE | LOCKREL_AFSID |
5015 fprintf(STDERR, "Could not update entry for volume %lu \n",
5016 (unsigned long)volid);
5017 PrintError("", vcode);
5018 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5019 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5027 /*list all the partitions on <aserver> */
5029 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
5032 struct rx_connection *aconn;
5033 struct pIDs partIds;
5034 struct partEntries partEnts;
5035 register int i, j = 0, code;
5038 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5040 partEnts.partEntries_len = 0;
5041 partEnts.partEntries_val = NULL;
5042 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5043 if (code == RXGEN_OPCODE) {
5044 for (i = 0; i < 26; i++) /* try old interface */
5045 partIds.partIds[i] = -1;
5046 code = AFSVolListPartitions(aconn, &partIds);
5048 for (i = 0; i < 26; i++) {
5049 if ((partIds.partIds[i]) != -1) {
5050 ptrPartList->partId[j] = partIds.partIds[i];
5051 ptrPartList->partFlags[j] = PARTVALID;
5054 ptrPartList->partFlags[i] = 0;
5059 *cntp = partEnts.partEntries_len;
5060 if (*cntp > VOLMAXPARTS) {
5062 "Warning: number of partitions on the server too high %d (process only %d)\n",
5063 *cntp, VOLMAXPARTS);
5064 *cntp = VOLMAXPARTS;
5066 for (i = 0; i < *cntp; i++) {
5067 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5068 ptrPartList->partFlags[i] = PARTVALID;
5070 free(partEnts.partEntries_val);
5076 "Could not fetch the list of partitions from the server\n");
5077 PrintError("", code);
5079 rx_DestroyConnection(aconn);
5084 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5085 This is used by the backup system */
5087 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
5088 struct volDescription *volPtr, afs_int32 arraySize)
5090 struct rx_connection *aconn;
5091 struct volDescription *curPtr;
5094 afs_int32 rcode = 0;
5095 afs_int32 success = 1;
5098 aconn = (struct rx_connection *)0;
5099 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5101 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5102 if (curPtr->volFlags & CLONEVALID) {
5103 curPtr->volFlags &= ~CLONEZAPPED;
5106 AFSVolTransCreate_retry(aconn, curPtr->volCloneId, apart, ITOffline,
5111 code = AFSVolDeleteVolume(aconn, tid);
5114 code = AFSVolEndTrans(aconn, tid, &rcode);
5119 curPtr->volFlags |= CLONEZAPPED;
5121 fprintf(STDERR, "Could not zap volume %lu\n",
5122 (unsigned long)curPtr->volCloneId);
5124 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5125 curPtr->volCloneId);
5131 rx_DestroyConnection(aconn);
5135 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5138 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
5139 struct volDescription *volPtr, afs_int32 arraySize)
5141 struct rx_connection *aconn;
5142 struct volDescription *curPtr;
5145 afs_int32 rcode = 0;
5147 int reuseCloneId = 0;
5148 afs_uint32 curCloneId = 0;
5149 char cloneName[256]; /*max vol name */
5151 aconn = (struct rx_connection *)0;
5152 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5154 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5156 else { /*get a bunch of id's from vldb */
5158 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5160 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5161 PrintError("", code);
5166 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5167 if (curPtr->volFlags & ENTRYVALID) {
5169 curPtr->volFlags |= CLONEVALID;
5170 /*make a clone of curParentId and record as curPtr->volCloneId */
5172 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5175 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5178 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5182 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5183 strcpy(cloneName, curPtr->volName);
5184 strcat(cloneName, "-tmpClone-");
5186 strcpy(cloneName, "-tmpClone");
5188 curPtr->volCloneId = curCloneId;
5193 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5194 &(curPtr->volCloneId));
5196 curPtr->volFlags &= ~CLONEVALID;
5198 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5199 curPtr->volName, (unsigned long)code);
5200 code = AFSVolEndTrans(aconn, tid, &rcode);
5202 fprintf(STDERR, "WARNING: could not end transaction\n");
5205 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5206 curPtr->volCloneId);
5207 code = AFSVolEndTrans(aconn, tid, &rcode);
5208 if (code || rcode) {
5209 curPtr->volFlags &= ~CLONEVALID;
5218 rx_DestroyConnection(aconn);
5223 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5224 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5226 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5227 struct volintInfo **resultPtr, afs_int32 * size)
5229 struct rx_connection *aconn;
5231 volEntries volumeInfo;
5235 *resultPtr = (volintInfo *) 0;
5236 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5237 volumeInfo.volEntries_len = 0;
5239 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5240 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5243 "Could not fetch the list of volumes from the server\n");
5245 *resultPtr = volumeInfo.volEntries_val;
5246 *size = volumeInfo.volEntries_len;
5250 rx_DestroyConnection(aconn);
5251 PrintError("", code);
5255 /*------------------------------------------------------------------------
5256 * EXPORTED UV_XListVolumes
5259 * List the extended information for all the volumes on a particular
5260 * File Server and partition. We may either return the volume's ID
5261 * or all of its extended information.
5264 * a_serverID : Address of the File Server for which we want
5265 * extended volume info.
5266 * a_partID : Partition for which we want the extended
5268 * a_all : If non-zero, fetch ALL the volume info,
5269 * otherwise just the volume ID.
5270 * a_resultPP : Ptr to the address of the area containing
5271 * the returned volume info.
5272 * a_numEntsInResultP : Ptr for the value we set for the number of
5277 * Otherise, the return value of AFSVolXListVolumes.
5280 * This routine is closely related to UV_ListVolumes, which returns
5281 * only the standard level of detail on AFS volumes. It is a
5282 * heavyweight operation, zipping through all the volume entries for
5283 * a given server/partition.
5287 *------------------------------------------------------------------------*/
5290 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5291 struct volintXInfo **a_resultPP,
5292 afs_int32 * a_numEntsInResultP)
5294 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5295 afs_int32 code; /*Error code to return */
5296 volXEntries volumeXInfo; /*Area for returned extended vol info */
5299 * Set up our error code and the area for returned extended volume info.
5300 * We set the val field to a null pointer as a hint for the stub to
5304 *a_numEntsInResultP = 0;
5305 *a_resultPP = (volintXInfo *) 0;
5306 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5307 volumeXInfo.volXEntries_len = 0;
5310 * Bind to the Volume Server port on the File Server machine in question,
5313 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5314 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5316 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5319 * We got the info; pull out the pointer to where the results lie
5320 * and how many entries are there.
5322 *a_resultPP = volumeXInfo.volXEntries_val;
5323 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5327 * If we got an Rx connection, throw it away.
5330 rx_DestroyConnection(rxConnP);
5332 PrintError("", code);
5334 } /*UV_XListVolumes */
5336 /* get all the information about volume <volid> on <aserver> and <apart> */
5338 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 volid,
5339 struct volintInfo **resultPtr)
5341 struct rx_connection *aconn;
5343 volEntries volumeInfo;
5347 *resultPtr = (volintInfo *) 0;
5348 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5349 volumeInfo.volEntries_len = 0;
5351 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5352 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5355 "Could not fetch the information about volume %lu from the server\n",
5356 (unsigned long)volid);
5358 *resultPtr = volumeInfo.volEntries_val;
5363 rx_DestroyConnection(aconn);
5364 PrintError("", code);
5368 /*------------------------------------------------------------------------
5369 * EXPORTED UV_XListOneVolume
5372 * List the extended information for a volume on a particular File
5373 * Server and partition.
5376 * a_serverID : Address of the File Server for which we want
5377 * extended volume info.
5378 * a_partID : Partition for which we want the extended
5380 * a_volID : Volume ID for which we want the info.
5381 * a_resultPP : Ptr to the address of the area containing
5382 * the returned volume info.
5386 * Otherise, the return value of AFSVolXListOneVolume.
5389 * This routine is closely related to UV_ListOneVolume, which returns
5390 * only the standard level of detail on the chosen AFS volume.
5394 *------------------------------------------------------------------------*/
5397 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5398 struct volintXInfo **a_resultPP)
5400 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5401 afs_int32 code; /*Error code */
5402 volXEntries volumeXInfo; /*Area for returned info */
5405 * Set up our error code, and the area we're in which we are returning
5406 * the info. Setting the val field to a null pointer tells the stub
5407 * to allocate space for us.
5410 *a_resultPP = (volintXInfo *) 0;
5411 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5412 volumeXInfo.volXEntries_len = 0;
5415 * Bind to the Volume Server port on the File Server machine in question,
5418 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5419 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5422 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5425 * We got the info; pull out the pointer to where the results lie.
5427 *a_resultPP = volumeXInfo.volXEntries_val;
5430 * If we got an Rx connection, throw it away.
5433 rx_DestroyConnection(rxConnP);
5435 PrintError("", code);
5440 * Given a volume we read from a partition, check if it is
5441 * represented in the VLDB correctly.
5443 * The VLDB is looked up by the RW volume id (not its name).
5444 * The RW contains the true name of the volume (BK and RO set
5445 * the name in the VLDB only on creation of the VLDB entry).
5446 * We want rules strict enough that when we check all volumes
5447 * on one partition, it does not need to be done again. IE:
5448 * two volumes on different partitions won't constantly
5449 * change a VLDB entry away from what the other set.
5450 * For RW and BK volumes, we will always check the VLDB to see
5451 * if the two exist on the server/partition. May seem redundant,
5452 * but this is an easy check of the VLDB. IE: if the VLDB entry
5453 * says the BK exists but no BK volume is there, we will detect
5454 * this when we check the RW volume.
5455 * VLDB entries are locked only when a change needs to be done.
5456 * Output changed to look a lot like the "vos syncserv" otuput.
5459 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5460 afs_int32 * modentry, afs_uint32 * maxvolid)
5464 afs_int32 code, error = 0;
5465 struct nvldbentry entry, storeEntry;
5467 int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
5477 ((volumeinfo->type ==
5478 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5481 /* Check to see if the VLDB is ok without locking it (pass 1).
5482 * If it will change, then lock the VLDB entry, read it again,
5483 * then make the changes to it (pass 2).
5486 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5488 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5489 (unsigned long)rwvolid);
5495 createentry = 0; /* Do we need to create a VLDB entry */
5496 addvolume = 0; /* Add this volume to the VLDB entry */
5497 modified = 0; /* The VLDB entry was modified */
5499 /* Read the entry from VLDB by its RW volume id */
5500 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5502 if (code != VL_NOENT) {
5504 "Could not retreive the VLDB entry for volume %lu \n",
5505 (unsigned long)rwvolid);
5509 memset(&entry, 0, sizeof(entry));
5510 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5514 MapHostToNetwork(&entry);
5517 if (verbose && (pass == 1)) {
5518 fprintf(STDOUT, "_______________________________\n");
5519 fprintf(STDOUT, "\n-- status before -- \n");
5521 fprintf(STDOUT, "\n**does not exist**\n");
5523 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5524 || (entry.flags & BACK_EXISTS))
5525 EnumerateEntry(&entry);
5527 fprintf(STDOUT, "\n");
5530 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5536 /* Check existence of RW and BK volumes */
5537 code = CheckVldbRWBK(&entry, &mod);
5543 idx = Lp_GetRwIndex(&entry);
5544 if (idx == -1) { /* RW index not found in the VLDB entry */
5545 idx = entry.nServers; /* put it into next index */
5548 } else { /* RW index found in the VLDB entry. */
5549 /* Verify if this volume's location matches where the VLDB says it is */
5550 if (!Lp_Match(aserver, apart, &entry)) {
5551 if (entry.flags & RW_EXISTS) {
5552 /* The RW volume exists elsewhere - report this one a duplicate */
5554 MapPartIdIntoName(apart, pname);
5556 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5557 (unsigned long)rwvolid,
5559 afs_inet_ntoa_r(aserver, hoststr) :
5560 hostutil_GetNameByINet(aserver), pname);
5561 MapPartIdIntoName(entry.serverPartition[idx],
5564 " VLDB reports RW volume %lu exists on %s %s\n",
5565 (unsigned long)rwvolid,
5567 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5568 hostutil_GetNameByINet(entry.
5573 /* The RW volume does not exist - have VLDB point to this one */
5576 /* Check for orphaned BK volume on old partition */
5577 if (entry.flags & BACK_EXISTS) {
5579 MapPartIdIntoName(entry.serverPartition[idx],
5582 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5583 entry.volumeId[BACKVOL],
5585 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5586 hostutil_GetNameByINet(entry.
5589 MapPartIdIntoName(apart, pname);
5591 " VLDB reports its RW volume %lu exists on %s %s\n",
5592 (unsigned long)rwvolid,
5594 afs_inet_ntoa_r(aserver, hoststr) :
5595 hostutil_GetNameByINet(aserver),
5601 /* Volume location matches the VLDB location */
5602 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5603 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5606 (entry.name, volumeinfo->name,
5607 VOLSER_OLDMAXVOLNAME) != 0)) {
5615 entry.flags |= RW_EXISTS;
5616 entry.volumeId[RWVOL] = rwvolid;
5617 if (!entry.volumeId[BACKVOL])
5618 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5619 if (!entry.volumeId[ROVOL])
5620 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5622 entry.serverFlags[idx] = ITSRWVOL;
5623 entry.serverNumber[idx] = aserver;
5624 entry.serverPartition[idx] = apart;
5625 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5629 /* One last check - to update BK if need to */
5630 code = CheckVldbRWBK(&entry, &mod);
5638 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5644 /* Check existence of RW and BK volumes */
5645 code = CheckVldbRWBK(&entry, &mod);
5651 idx = Lp_GetRwIndex(&entry);
5652 if (idx == -1) { /* RW index not found in the VLDB entry */
5653 idx = entry.nServers; /* Put it into next index */
5656 } else { /* RW index found in the VLDB entry */
5657 /* Verify if this volume's location matches where the VLDB says it is */
5658 if (!Lp_Match(aserver, apart, &entry)) {
5659 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5661 MapPartIdIntoName(apart, pname);
5663 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5664 (unsigned long)volumeinfo->volid,
5666 afs_inet_ntoa_r(aserver, hoststr) :
5667 hostutil_GetNameByINet(aserver), pname);
5668 MapPartIdIntoName(entry.serverPartition[idx], pname);
5670 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5671 (unsigned long)rwvolid,
5673 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5674 hostutil_GetNameByINet(entry.
5679 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5680 if (!(entry.flags & BACK_EXISTS)) {
5682 } else if (volumeinfo->volid >
5683 entry.volumeId[BACKVOL]) {
5687 MapPartIdIntoName(entry.serverPartition[idx],
5690 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5691 entry.volumeId[BACKVOL],
5693 afs_inet_ntoa_r(aserver, hoststr) :
5694 hostutil_GetNameByINet(aserver),
5697 " VLDB reports its BK volume ID is %lu\n",
5698 (unsigned long)volumeinfo->volid);
5702 MapPartIdIntoName(entry.serverPartition[idx],
5705 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5706 (unsigned long)volumeinfo->volid,
5708 afs_inet_ntoa_r(aserver, hoststr) :
5709 hostutil_GetNameByINet(aserver),
5712 " VLDB reports its BK volume ID is %u\n",
5713 entry.volumeId[BACKVOL]);
5716 } else if (!entry.volumeId[BACKVOL]) {
5723 entry.flags |= BACK_EXISTS;
5724 entry.volumeId[RWVOL] = rwvolid;
5725 entry.volumeId[BACKVOL] = volumeinfo->volid;
5727 entry.serverNumber[idx] = aserver;
5728 entry.serverPartition[idx] = apart;
5729 entry.serverFlags[idx] = ITSBACKVOL;
5735 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5736 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5737 /* This is a quick check to see if the RO entry exists in the
5738 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5739 * RO volume listed in the VLDB exists).
5741 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5743 idx = entry.nServers;
5747 if (!(entry.flags & RO_EXISTS)) {
5752 /* Before we correct the VLDB entry, make sure all the
5753 * ROs listed in the VLDB exist.
5755 code = CheckVldbRO(&entry, &mod);
5761 if (!(entry.flags & RO_EXISTS)) {
5762 /* No RO exists in the VLDB entry - add this one */
5763 idx = entry.nServers;
5766 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5767 /* The volume headers's RO ID does not match that in the VLDB entry,
5768 * and the vol hdr's ID is greater (implies more recent). So delete
5769 * all the RO volumes listed in VLDB entry and add this volume.
5771 for (j = 0; j < entry.nServers; j++) {
5772 if (entry.serverFlags[j] & ITSROVOL) {
5773 /* Verify this volume exists and print message we are orphaning it */
5775 MapPartIdIntoName(apart, pname);
5777 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5778 entry.volumeId[ROVOL],
5780 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5781 hostutil_GetNameByINet(entry.
5785 " VLDB reports its RO volume ID is %lu\n",
5786 (unsigned long)volumeinfo->volid);
5789 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5790 entry.serverPartition[idx], 0L, 0L);
5797 idx = entry.nServers;
5800 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5801 /* The volume headers's RO ID does not match that in the VLDB entry,
5802 * and the vol hdr's ID is lower (implies its older). So orphan it.
5805 MapPartIdIntoName(apart, pname);
5807 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5808 (unsigned long)volumeinfo->volid,
5810 afs_inet_ntoa_r(aserver, hoststr) :
5811 hostutil_GetNameByINet(aserver), pname);
5813 " VLDB reports its RO volume ID is %u\n",
5814 entry.volumeId[ROVOL]);
5817 /* The RO volume ID in the volume header match that in the VLDB entry,
5818 * and there exist RO volumes in the VLDB entry. See if any of them
5819 * are this one. If not, then we add it.
5821 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5823 idx = entry.nServers;
5831 entry.flags |= RO_EXISTS;
5832 entry.volumeId[RWVOL] = rwvolid;
5833 entry.volumeId[ROVOL] = volumeinfo->volid;
5835 entry.serverNumber[idx] = aserver;
5836 entry.serverPartition[idx] = apart;
5837 entry.serverFlags[idx] = ITSROVOL;
5843 /* Remember largest volume id */
5844 if (entry.volumeId[ROVOL] > *maxvolid)
5845 *maxvolid = entry.volumeId[ROVOL];
5846 if (entry.volumeId[BACKVOL] > *maxvolid)
5847 *maxvolid = entry.volumeId[BACKVOL];
5848 if (entry.volumeId[RWVOL] > *maxvolid)
5849 *maxvolid = entry.volumeId[RWVOL];
5851 if (modified && doit) {
5852 MapNetworkToHost(&entry, &storeEntry);
5855 code = VLDB_CreateEntry(&storeEntry);
5858 "Could not create a VLDB entry for the volume %lu\n",
5859 (unsigned long)rwvolid);
5866 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5867 LOCKREL_OPCODE | LOCKREL_AFSID |
5870 fprintf(STDERR, "Could not update entry for %lu\n",
5871 (unsigned long)rwvolid);
5876 *modentry = modified;
5877 } else if (pass == 2) {
5879 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5880 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5882 PrintError("Could not unlock VLDB entry ", code);
5886 if (verbose && doit) {
5887 fprintf(STDOUT, "-- status after --\n");
5889 EnumerateEntry(&entry);
5891 fprintf(STDOUT, "\n**no change**\n");
5895 VPRINT("\n_______________________________\n");
5900 sortVolumes(const void *a, const void *b)
5902 volintInfo *v1 = (volintInfo *) a;
5903 volintInfo *v2 = (volintInfo *) b;
5904 afs_uint32 rwvolid1, rwvolid2;
5906 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5907 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5909 if (rwvolid1 > rwvolid2)
5910 return -1; /* lower RW id goes first */
5911 if (rwvolid1 < rwvolid2)
5914 if (v1->type == RWVOL)
5915 return -1; /* RW vols go first */
5916 if (v2->type == RWVOL)
5919 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5920 return -1; /* BK vols next */
5921 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5924 if (v1->volid < v2->volid)
5925 return 1; /* larger volids first */
5926 if (v1->volid > v2->volid)
5932 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5933 * Synchronize an individual volume against a sever and partition.
5934 * Checks the VLDB entry (similar to syncserv) as well as checks
5935 * if the volume exists on specified servers (similar to syncvldb).
5938 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5940 struct rx_connection *aconn = 0;
5941 afs_int32 j, k, code, vcode, error = 0;
5943 afs_int32 mod, modified = 0;
5944 struct nvldbentry vldbentry;
5945 afs_uint32 volumeid = 0;
5946 volEntries volumeInfo;
5947 struct partList PartList;
5949 afs_uint32 maxvolid = 0;
5951 volumeInfo.volEntries_val = (volintInfo *) 0;
5952 volumeInfo.volEntries_len = 0;
5954 /* Turn verbose logging off and do our own verbose logging */
5955 /* tverbose must be set before we call ERROR_EXIT() */
5962 if (!aserver && (flags & 1)) {
5963 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5967 /* Read the VLDB entry */
5968 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5969 if (vcode && (vcode != VL_NOENT)) {
5970 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5973 } else if (!vcode) {
5974 MapHostToNetwork(&vldbentry);
5978 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5979 fprintf(STDOUT, "_______________________________\n");
5980 fprintf(STDOUT, "\n-- status before -- \n");
5982 fprintf(STDOUT, "\n**does not exist**\n");
5984 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5985 || (vldbentry.flags & BACK_EXISTS))
5986 EnumerateEntry(&vldbentry);
5988 fprintf(STDOUT, "\n");
5991 /* Verify that all of the VLDB entries exist on the repective servers
5992 * and partitions (this does not require that avolname be a volume ID).
5993 * Equivalent to a syncserv.
5996 /* Tell CheckVldb not to update if appropriate */
6001 code = CheckVldb(&vldbentry, &mod);
6003 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6011 /* If aserver is given, we will search for the desired volume on it */
6013 /* Generate array of partitions on the server that we will check */
6015 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6018 "Could not fetch the list of partitions from the server\n");
6022 PartList.partId[0] = apart;
6026 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6028 /* If a volume ID were given, search for it on each partition */
6029 if ((volumeid = atol(avolname))) {
6030 for (j = 0; j < pcnt; j++) {
6032 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6035 if (code != ENODEV) {
6036 fprintf(STDERR, "Could not query server\n");
6044 /* Found one, sync it with VLDB entry */
6046 CheckVolume(volumeInfo.volEntries_val, aserver,
6047 PartList.partId[j], &mod, &maxvolid);
6054 if (volumeInfo.volEntries_val)
6055 free(volumeInfo.volEntries_val);
6056 volumeInfo.volEntries_val = (volintInfo *) 0;
6057 volumeInfo.volEntries_len = 0;
6061 /* Check to see if the RW, BK, and RO IDs exist on any
6062 * partitions. We get the volume IDs from the VLDB.
6064 rv = 1; /* Read the VLDB entry ? */
6065 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6067 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6069 if (vcode == VL_NOENT)
6072 "Could not access the VLDB for volume %s\n",
6079 if (vldbentry.volumeId[j] == 0)
6082 for (k = 0; k < pcnt; k++) { /* For each partition */
6083 volumeInfo.volEntries_val = (volintInfo *) 0;
6084 volumeInfo.volEntries_len = 0;
6086 AFSVolListOneVolume(aconn, PartList.partId[k],
6087 vldbentry.volumeId[j], &volumeInfo);
6089 if (code != ENODEV) {
6090 fprintf(STDERR, "Could not query server\n");
6098 /* Found one, sync it with VLDB entry */
6100 CheckVolume(volumeInfo.volEntries_val, aserver,
6101 PartList.partId[k], &mod, &maxvolid);
6108 if (volumeInfo.volEntries_val)
6109 free(volumeInfo.volEntries_val);
6110 volumeInfo.volEntries_val = (volintInfo *) 0;
6111 volumeInfo.volEntries_len = 0;
6117 /* If verbose output, print a summary of what changed */
6118 if (tverbose && !(flags & 2)) {
6119 fprintf(STDOUT, "-- status after --\n");
6120 code = VLDB_GetEntryByName(avolname, &vldbentry);
6121 if (code && (code != VL_NOENT)) {
6122 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6126 if (modified && (code == VL_NOENT)) {
6127 fprintf(STDOUT, "\n**entry deleted**\n");
6128 } else if (modified) {
6129 EnumerateEntry(&vldbentry);
6131 fprintf(STDOUT, "\n**no change**\n");
6133 fprintf(STDOUT, "\n_______________________________\n");
6137 /* Now check if the maxvolid is larger than that stored in the VLDB */
6139 afs_uint32 maxvldbid = 0;
6140 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6143 "Could not get the highest allocated volume id from the VLDB\n");
6146 } else if (maxvolid > maxvldbid) {
6148 id = maxvolid - maxvldbid + 1;
6149 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6152 "Error in increasing highest allocated volume id in VLDB\n");
6162 fprintf(STDOUT, "...error encountered");
6164 fprintf(STDOUT, "...done entry\n");
6167 rx_DestroyConnection(aconn);
6168 if (volumeInfo.volEntries_val)
6169 free(volumeInfo.volEntries_val);
6171 PrintError("", error);
6176 * Synchronise vldb with the file server <aserver> and,
6177 * optionally, <apart>.
6180 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
6182 struct rx_connection *aconn;
6183 afs_int32 code, error = 0;
6186 volEntries volumeInfo;
6187 struct partList PartList;
6191 afs_int32 failures = 0, modifications = 0, tentries = 0;
6193 afs_uint32 maxvolid = 0;
6196 volumeInfo.volEntries_val = (volintInfo *) 0;
6197 volumeInfo.volEntries_len = 0;
6199 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6201 /* Generate array of partitions to check */
6203 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6206 "Could not fetch the list of partitions from the server\n");
6210 PartList.partId[0] = apart;
6214 VPRINT("Processing volume entries ...\n");
6216 /* Step through the array of partitions */
6217 for (i = 0; i < pcnt; i++) {
6218 apart = PartList.partId[i];
6219 MapPartIdIntoName(apart, pname);
6221 volumeInfo.volEntries_val = (volintInfo *) 0;
6222 volumeInfo.volEntries_len = 0;
6223 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6226 "Could not fetch the list of volumes from the server\n");
6230 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6231 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6232 sizeof(volintInfo), sortVolumes);
6235 for (vi = volumeInfo.volEntries_val, j = 0;
6236 j < volumeInfo.volEntries_len; j++, vi++) {
6244 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6245 j + 1, vi->name, (unsigned long)vi->volid,
6247 afs_inet_ntoa_r(aserver, hoststr) :
6248 hostutil_GetNameByINet(aserver), pname);
6256 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
6258 PrintError("", code);
6261 } else if (modified) {
6267 fprintf(STDOUT, "...error encountered\n\n");
6269 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6276 "Could not process entries on server %s partition %s\n",
6278 afs_inet_ntoa_r(aserver, hoststr) :
6279 hostutil_GetNameByINet(aserver), pname);
6281 if (volumeInfo.volEntries_val) {
6282 free(volumeInfo.volEntries_val);
6283 volumeInfo.volEntries_val = 0;
6286 } /* thru all partitions */
6289 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6290 tentries, failures, modifications);
6292 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6293 tentries, failures, modifications);
6297 /* Now check if the maxvolid is larger than that stored in the VLDB */
6299 afs_uint32 maxvldbid = 0;
6300 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6303 "Could not get the highest allocated volume id from the VLDB\n");
6306 } else if (maxvolid > maxvldbid) {
6308 id = maxvolid - maxvldbid + 1;
6309 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6312 "Error in increasing highest allocated volume id in VLDB\n");
6320 rx_DestroyConnection(aconn);
6321 if (volumeInfo.volEntries_val)
6322 free(volumeInfo.volEntries_val);
6323 PrintError("", error);
6328 * Determine if a volume exists on a server and partition.
6329 * Try creating a transaction on the volume. If we can,
6330 * the volume exists, if not, then return the error code.
6331 * Some error codes mean the volume is unavailable but
6332 * still exists - so we catch these error codes.
6335 VolumeExists(afs_int32 server, afs_int32 partition, afs_uint32 volumeid)
6337 struct rx_connection *conn = (struct rx_connection *)0;
6338 afs_int32 code = -1;
6339 volEntries volumeInfo;
6341 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6343 volumeInfo.volEntries_val = (volintInfo *) 0;
6344 volumeInfo.volEntries_len = 0;
6345 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6346 if (volumeInfo.volEntries_val)
6347 free(volumeInfo.volEntries_val);
6348 if (code == VOLSERILLEGAL_PARTITION)
6350 rx_DestroyConnection(conn);
6359 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6363 afs_int32 code, error = 0;
6369 idx = Lp_GetRwIndex(entry);
6371 /* Check to see if the RW volume exists and set the RW_EXISTS
6374 if (idx == -1) { /* Did not find a RW entry */
6375 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6376 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6381 VolumeExists(entry->serverNumber[idx],
6382 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6383 if (code == 0) { /* RW volume exists */
6384 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6385 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6388 } else if (code == ENODEV) { /* RW volume does not exist */
6389 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6390 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6394 /* If VLDB says it didn't exist, then ignore error */
6395 if (entry->flags & RW_EXISTS) {
6396 MapPartIdIntoName(entry->serverPartition[idx], pname);
6398 "Transaction call failed for RW volume %u on server %s %s\n",
6399 entry->volumeId[RWVOL],
6401 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6402 hostutil_GetNameByINet(entry->serverNumber[idx]),
6409 /* Check to see if the BK volume exists and set the BACK_EXISTS
6410 * flag accordingly. idx already ponts to the RW entry.
6412 if (idx == -1) { /* Did not find a RW entry */
6413 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6414 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6417 } else { /* Found a RW entry */
6419 VolumeExists(entry->serverNumber[idx],
6420 entry->serverPartition[idx],
6421 entry->volumeId[BACKVOL]);
6422 if (code == 0) { /* BK volume exists */
6423 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6424 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6427 } else if (code == ENODEV) { /* BK volume does not exist */
6428 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6429 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6433 /* If VLDB says it didn't exist, then ignore error */
6434 if (entry->flags & BACK_EXISTS) {
6435 MapPartIdIntoName(entry->serverPartition[idx], pname);
6437 "Transaction call failed for BK volume %u on server %s %s\n",
6438 entry->volumeId[BACKVOL],
6440 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6441 hostutil_GetNameByINet(entry->serverNumber[idx]),
6448 /* If there is an idx but the BK and RW volumes no
6449 * longer exist, then remove the RW entry.
6451 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6452 && !(entry->flags & BACK_EXISTS)) {
6453 Lp_SetRWValue(entry, entry->serverNumber[idx],
6454 entry->serverPartition[idx], 0L, 0L);
6461 *modified = modentry;
6466 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6469 int foundro = 0, modentry = 0;
6470 afs_int32 code, error = 0;
6477 /* Check to see if the RO volumes exist and set the RO_EXISTS
6480 for (idx = 0; idx < entry->nServers; idx++) {
6481 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6482 continue; /* not a RO */
6486 VolumeExists(entry->serverNumber[idx],
6487 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6488 if (code == 0) { /* RO volume exists */
6490 } else if (code == ENODEV) { /* RW volume does not exist */
6491 Lp_SetROValue(entry, entry->serverNumber[idx],
6492 entry->serverPartition[idx], 0L, 0L);
6497 MapPartIdIntoName(entry->serverPartition[idx], pname);
6499 "Transaction call failed for RO %u on server %s %s\n",
6500 entry->volumeId[ROVOL],
6502 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6503 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6508 if (foundro) { /* A RO volume exists */
6509 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6510 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6513 } else { /* A RO volume does not exist */
6514 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6515 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6522 *modified = modentry;
6527 * Ensure that <entry> matches with the info on file servers
6530 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6532 afs_int32 code, error = 0;
6533 struct nvldbentry storeEntry;
6534 int islocked = 0, mod, modentry, delentry = 0;
6535 int pass = 0, doit=1;
6543 fprintf(STDOUT, "_______________________________\n");
6544 fprintf(STDOUT, "\n-- status before -- \n");
6545 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6546 || (entry->flags & BACK_EXISTS))
6547 EnumerateEntry(entry);
6548 fprintf(STDOUT, "\n");
6551 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6552 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6553 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6557 /* Check to see if the VLDB is ok without locking it (pass 1).
6558 * If it will change, then lock the VLDB entry, read it again,
6559 * then make the changes to it (pass 2).
6563 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6566 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6567 entry->volumeId[RWVOL]);
6572 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6574 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6578 MapHostToNetwork(entry);
6584 /* Check if the RW and BK entries are ok */
6585 code = CheckVldbRWBK(entry, &mod);
6588 if (mod && (pass == 1) && doit)
6593 /* Check if the RO volumes entries are ok */
6594 code = CheckVldbRO(entry, &mod);
6597 if (mod && (pass == 1) && doit)
6602 /* The VLDB entry has been updated. If it as been modified, then
6603 * write the entry back out the the VLDB.
6605 if (modentry && doit) {
6609 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6610 && !(entry->flags & RO_EXISTS) && doit) {
6611 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6613 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6617 "Could not delete VLDB entry for volume %u \n",
6618 entry->volumeId[RWVOL]);
6623 /* Replace old entry with our new one */
6624 MapNetworkToHost(entry, &storeEntry);
6626 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6627 (LOCKREL_OPCODE | LOCKREL_AFSID |
6628 LOCKREL_TIMESTAMP));
6630 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6631 entry->volumeId[RWVOL]);
6640 if (verbose && doit) {
6641 fprintf(STDOUT, "-- status after --\n");
6643 fprintf(STDOUT, "\n**entry deleted**\n");
6645 EnumerateEntry(entry);
6647 fprintf(STDOUT, "\n**no change**\n");
6651 VPRINT("\n_______________________________\n");
6655 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6657 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6660 "Could not release lock on VLDB entry for volume %u\n",
6661 entry->volumeId[RWVOL]);
6670 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6673 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6675 struct rx_connection *aconn;
6676 afs_int32 code, error = 0;
6677 afs_int32 nentries, tentries = 0;
6678 struct VldbListByAttributes attributes;
6679 nbulkentries arrayEntries;
6680 afs_int32 failures = 0, modified, modifications = 0;
6681 struct nvldbentry *vlentry;
6682 afs_int32 si, nsi, j;
6687 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6689 /* Set up attributes to search VLDB */
6690 attributes.server = ntohl(aserver);
6691 attributes.Mask = VLLIST_SERVER;
6693 attributes.partition = apart;
6694 attributes.Mask |= VLLIST_PARTITION;
6697 VPRINT("Processing VLDB entries ...\n");
6699 /* While we need to collect more VLDB entries */
6700 for (si = 0; si != -1; si = nsi) {
6701 memset(&arrayEntries, 0, sizeof(arrayEntries));
6703 /* Collect set of VLDB entries */
6705 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6706 &arrayEntries, &nsi);
6707 if (code == RXGEN_OPCODE) {
6708 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6712 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6715 tentries += nentries;
6717 for (j = 0; j < nentries; j++) {
6718 vlentry = &arrayEntries.nbulkentries_val[j];
6719 MapHostToNetwork(vlentry);
6721 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6723 /* Tell CheckVldb not to update if appropriate */
6728 code = CheckVldb(vlentry, &modified);
6730 PrintError("", code);
6732 "Could not process VLDB entry for volume %s\n",
6735 } else if (modified) {
6741 fprintf(STDOUT, "...error encountered\n\n");
6743 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6748 if (arrayEntries.nbulkentries_val) {
6749 free(arrayEntries.nbulkentries_val);
6750 arrayEntries.nbulkentries_val = 0;
6755 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6756 tentries, failures, modifications);
6758 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6759 tentries, failures, modifications);
6764 rx_DestroyConnection(aconn);
6765 if (arrayEntries.nbulkentries_val)
6766 free(arrayEntries.nbulkentries_val);
6769 error = VOLSERFAILEDOP;
6773 /*rename volume <oldname> to <newname>, changing the names of the related
6774 *readonly and backup volumes. This operation is also idempotent.
6775 *salvager is capable of recovering from rename operation stopping halfway.
6776 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6778 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6780 struct nvldbentry storeEntry;
6781 afs_int32 vcode, code, rcode, error;
6783 char nameBuffer[256];
6785 struct rx_connection *aconn;
6790 aconn = (struct rx_connection *)0;
6794 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6797 " Could not lock the VLDB entry for the volume %u \n",
6798 entry->volumeId[RWVOL]);
6803 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6804 MapNetworkToHost(entry, &storeEntry);
6805 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6807 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6808 entry->volumeId[RWVOL]);
6812 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6813 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6814 * is concerned, oldname is lost */
6815 if (entry->flags & RW_EXISTS) {
6816 index = Lp_GetRwIndex(entry);
6817 if (index == -1) { /* there is a serious discrepancy */
6819 "There is a serious discrepancy in VLDB entry for volume %u\n",
6820 entry->volumeId[RWVOL]);
6821 fprintf(STDERR, "try building VLDB from scratch\n");
6822 error = VOLSERVLDB_ERROR;
6825 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6827 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
6828 entry->serverPartition[index], ITOffline, &tid);
6829 if (code) { /*volume doesnot exist */
6831 "Could not start transaction on the rw volume %u\n",
6832 entry->volumeId[RWVOL]);
6835 } else { /*volume exists, process it */
6838 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6839 entry->volumeId[RWVOL],
6840 entry->volumeId[ROVOL],
6841 entry->volumeId[BACKVOL]);
6843 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6844 code = AFSVolEndTrans(aconn, tid, &rcode);
6848 "Could not end transaction on volume %s %u\n",
6849 entry->name, entry->volumeId[RWVOL]);
6854 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6855 entry->name, entry->volumeId[RWVOL]);
6861 rx_DestroyConnection(aconn);
6862 aconn = (struct rx_connection *)0;
6864 /*end rw volume processing */
6865 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6866 index = Lp_GetRwIndex(entry);
6867 if (index == -1) { /* there is a serious discrepancy */
6869 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6870 entry->volumeId[BACKVOL]);
6871 fprintf(STDERR, "try building VLDB from scratch\n");
6872 error = VOLSERVLDB_ERROR;
6875 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6877 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
6878 entry->serverPartition[index], ITOffline, &tid);
6879 if (code) { /*volume doesnot exist */
6881 "Could not start transaction on the backup volume %u\n",
6882 entry->volumeId[BACKVOL]);
6885 } else { /*volume exists, process it */
6886 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6888 "Volume name %s.backup exceeds the limit of %u characters\n",
6889 newname, VOLSER_OLDMAXVOLNAME);
6893 strcpy(nameBuffer, newname);
6894 strcat(nameBuffer, ".backup");
6897 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6898 entry->volumeId[RWVOL], 0, 0);
6900 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6901 code = AFSVolEndTrans(aconn, tid, &rcode);
6905 "Could not end transaction on the backup volume %u\n",
6906 entry->volumeId[BACKVOL]);
6912 "Could not set parameters on the backup volume %u\n",
6913 entry->volumeId[BACKVOL]);
6918 } /* end backup processing */
6920 rx_DestroyConnection(aconn);
6921 aconn = (struct rx_connection *)0;
6922 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6923 for (i = 0; i < entry->nServers; i++) {
6924 if (entry->serverFlags[i] & ITSROVOL) {
6925 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6927 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
6928 entry->serverPartition[i], ITOffline,
6930 if (code) { /*volume doesnot exist */
6932 "Could not start transaction on the ro volume %u\n",
6933 entry->volumeId[ROVOL]);
6936 } else { /*volume exists, process it */
6937 strcpy(nameBuffer, newname);
6938 strcat(nameBuffer, ".readonly");
6939 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6941 "Volume name %s exceeds the limit of %u characters\n",
6942 nameBuffer, VOLSER_OLDMAXVOLNAME);
6947 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6948 entry->volumeId[RWVOL], 0, 0);
6950 VPRINT2("Renamed RO volume %s on host %s\n",
6953 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
6954 hostutil_GetNameByINet(entry->
6956 code = AFSVolEndTrans(aconn, tid, &rcode);
6960 "Could not end transaction on volume %u\n",
6961 entry->volumeId[ROVOL]);
6967 "Could not set parameters on the ro volume %u\n",
6968 entry->volumeId[ROVOL]);
6974 rx_DestroyConnection(aconn);
6975 aconn = (struct rx_connection *)0;
6982 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6984 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6987 "Could not unlock the VLDB entry for the volume %s %u\n",
6988 entry->name, entry->volumeId[RWVOL]);
6994 code = AFSVolEndTrans(aconn, tid, &rcode);
6998 fprintf(STDERR, "Failed to end transaction on a volume \n");
7004 rx_DestroyConnection(aconn);
7005 PrintError("", error);
7010 /*report on all the active transactions on volser */
7012 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7014 struct rx_connection *aconn;
7015 transDebugEntries transInfo;
7018 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7019 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7020 transInfo.transDebugEntries_len = 0;
7021 code = AFSVolMonitor(aconn, &transInfo);
7024 "Could not access status information about the server\n");
7025 PrintError("", code);
7026 if (transInfo.transDebugEntries_val)
7027 free(transInfo.transDebugEntries_val);
7029 rx_DestroyConnection(aconn);
7032 *rcount = transInfo.transDebugEntries_len;
7033 *rpntr = transInfo.transDebugEntries_val;
7035 rx_DestroyConnection(aconn);
7042 /*delete the volume without interacting with the vldb */
7044 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_uint32 volid)
7046 afs_int32 rcode, ttid, error, code;
7047 struct rx_connection *aconn;
7053 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7054 code = AFSVolTransCreate_retry(aconn, volid, part, ITOffline, &ttid);
7056 fprintf(STDERR, "Could not start transaction on volume %lu\n",
7057 (unsigned long)volid);
7061 code = AFSVolDeleteVolume(aconn, ttid);
7063 fprintf(STDERR, "Could not delete volume %lu\n",
7064 (unsigned long)volid);
7068 code = AFSVolEndTrans(aconn, ttid, &rcode);
7073 fprintf(STDERR, "Could not end transaction on volume %lu\n",
7074 (unsigned long)volid);
7080 code = AFSVolEndTrans(aconn, ttid, &rcode);
7086 PrintError("", error);
7088 rx_DestroyConnection(aconn);
7093 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_uint32 volid,
7094 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7096 struct rx_connection *conn = 0;
7098 afs_int32 code, error = 0, rcode;
7100 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7102 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7106 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7108 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7112 code = AFSVolSetFlags(conn, tid, setflag);
7114 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7119 #ifdef AFS_PTHREAD_ENV
7122 IOMGR_Sleep(sleeptime);
7129 code = AFSVolEndTrans(conn, tid, &rcode);
7130 if (code || rcode) {
7131 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7133 error = (code ? code : rcode);
7138 rx_DestroyConnection(conn);
7143 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_uint32 volid,
7146 struct rx_connection *conn = 0;
7148 afs_int32 code, error = 0, rcode;
7150 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7152 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7156 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7158 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7162 code = AFSVolSetInfo(conn, tid, infop);
7164 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7171 code = AFSVolEndTrans(conn, tid, &rcode);
7172 if (code || rcode) {
7173 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7175 error = (code ? code : rcode);
7180 rx_DestroyConnection(conn);
7185 UV_GetSize(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
7186 afs_int32 fromdate, struct volintSize *vol_size)
7188 struct rx_connection *aconn = (struct rx_connection *)0;
7189 afs_int32 tid = 0, rcode = 0;
7190 afs_int32 code, error = 0;
7193 /* get connections to the servers */
7194 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7196 VPRINT1("Starting transaction on volume %u...", afromvol);
7197 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7198 EGOTO1(error_exit, code,
7199 "Could not start transaction on the volume %u to be measured\n",
7203 VPRINT1("Getting size of volume on volume %u...", afromvol);
7204 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7205 EGOTO(error_exit, code, "Could not start the measurement process \n");
7210 VPRINT1("Ending transaction on volume %u...", afromvol);
7211 code = AFSVolEndTrans(aconn, tid, &rcode);
7212 if (code || rcode) {
7213 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7215 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7217 error = (code ? code : rcode);
7222 rx_DestroyConnection(aconn);
7224 PrintError("", error);
7228 /*maps the host addresses in <old > (present in network byte order) to
7229 that in< new> (present in host byte order )*/
7231 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7235 /*copy all the fields */
7236 strcpy(new->name, old->name);
7237 /* new->volumeType = old->volumeType;*/
7238 new->nServers = old->nServers;
7239 count = old->nServers;
7240 if (count < NMAXNSERVERS)
7242 for (i = 0; i < count; i++) {
7243 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7244 new->serverPartition[i] = old->serverPartition[i];
7245 new->serverFlags[i] = old->serverFlags[i];
7247 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7248 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7249 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7250 new->cloneId = old->cloneId;
7251 new->flags = old->flags;
7254 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7256 MapHostToNetwork(struct nvldbentry *entry)
7260 count = entry->nServers;
7261 if (count < NMAXNSERVERS)
7263 for (i = 0; i < count; i++) {
7264 entry->serverNumber[i] = htonl(entry->serverNumber[i]);