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_internal.h"
66 #include "volser_prototypes.h"
67 #include "vsutils_prototypes.h"
68 #include "lockprocs_prototypes.h"
70 struct ubik_client *cstruct;
71 int verbose = 0, noresolve = 0;
76 afs_int32 vldbEntryIndex;
79 /* Utility macros used by rest of this source file */
80 #define EPRINT(ec, es) \
82 fprintf(STDERR, "\n"); \
83 fprintf(STDERR, (es)); \
87 #define EPRINT1(ec, es, ep1) \
89 fprintf(STDERR, "\n"); \
90 fprintf(STDERR, (es), (ep1)); \
94 #define EPRINT2(ec, es, ep1, ep2) \
96 fprintf(STDERR, "\n"); \
97 fprintf(STDERR, (es), (ep1), (ep2)); \
101 #define EPRINT3(ec, es, ep1, ep2, ep3) \
103 fprintf(STDERR, "\n"); \
104 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
105 PrintError(" ",ec); \
108 #define EGOTO(where, ec, es) \
117 #define EGOTO1(where, ec, es, ep1) \
120 EPRINT1((ec),(es),(ep1)); \
126 #define EGOTO2(where, ec, es, ep1, ep2) \
129 EPRINT2((ec),(es),(ep1),(ep2)); \
135 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
138 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
145 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
146 #define VPRINT1(es, p) \
147 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
148 #define VPRINT2(es, p1, p2) \
149 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
150 #define VPRINT3(es, p1, p2, p3) \
151 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
153 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
154 #define VEPRINT(es) \
155 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
156 #define VEPRINT1(es, p) \
157 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
158 #define VEPRINT2(es, p1, p2) \
159 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
160 #define VEPRINT3(es, p1, p2, p3) \
161 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
163 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
167 /* getting rid of this */
168 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
171 /* Protos for static routines */
173 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
174 afs_int32 apart, afs_uint32 okvol,
177 static int DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
179 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
180 struct rx_connection **connPtr, afs_int32 * transPtr,
181 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr);
182 static int SimulateForwardMultiple(struct rx_connection *fromconn,
183 afs_int32 fromtid, afs_int32 fromdate,
184 manyDests * tr, afs_int32 flags,
185 void *cookie, manyResults * results);
186 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
187 afs_int32 apart, afs_int32 * modentry,
188 afs_uint32 * maxvolid);
191 /*map the partition <partId> into partition name <partName>*/
193 MapPartIdIntoName(afs_int32 partId, char *partName)
195 if (partId < 26) { /* what if partId > = 26 ? */
196 strcpy(partName, "/vicep");
197 partName[6] = partId + 'a';
200 } else if (partId < VOLMAXPARTS) {
201 strcpy(partName, "/vicep");
203 partName[6] = 'a' + (partId / 26);
204 partName[7] = 'a' + (partId % 26);
216 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
217 response = c = getchar();
218 while (!(c == EOF || c == '\n'))
219 c = getchar(); /*skip to end of line */
220 code = (response == 'y' || response == 'Y');
226 PrintError(char *msg, afs_int32 errcode)
228 fprintf(STDERR, "%s", msg);
229 /*replace by a big switch statement */
234 fprintf(STDERR, "Possible communication failure\n");
237 fprintf(STDERR, "Volume needs to be salvaged\n");
240 fprintf(STDERR, "Bad vnode number quoted\n");
244 "Volume not attached, does not exist, or not on line\n");
247 fprintf(STDERR, "Volume already exists\n");
250 fprintf(STDERR, "Volume is not in service\n");
253 fprintf(STDERR, "Volume is off line\n");
256 fprintf(STDERR, "Volume is already on line\n");
259 fprintf(STDERR, "Partition is full\n");
262 fprintf(STDERR, "Volume max quota exceeded\n");
265 fprintf(STDERR, "Volume temporarily unavailable\n");
268 fprintf(STDERR, "Volume has moved to another server\n");
271 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
274 fprintf(STDERR, "VLDB: a read terminated too early\n");
277 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
280 fprintf(STDERR, "VLDB: internal creation failure\n");
283 fprintf(STDERR, "VLDB: no such entry\n");
286 fprintf(STDERR, "VLDB: vldb database is empty\n");
289 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
292 fprintf(STDERR, "VLDB: volume name is illegal\n");
295 fprintf(STDERR, "VLDB: index was out of range\n");
298 fprintf(STDERR, "VLDB: bad volume type\n");
301 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
303 case VL_BADPARTITION:
304 fprintf(STDERR, "VLDB: bad partition number\n");
307 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
310 fprintf(STDERR, "VLDB: no such repsite server exists\n");
312 case VL_DUPREPSERVER:
313 fprintf(STDERR, "VLDB: replication site server already exists\n");
316 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
319 fprintf(STDERR, "VLDB: illegal reference count number\n");
321 case VL_SIZEEXCEEDED:
322 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
325 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
327 case VL_BADVOLIDBUMP:
328 fprintf(STDERR, "VLDB: illegal max volid increment\n");
330 case VL_IDALREADYHASHED:
331 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
334 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
337 fprintf(STDERR, "VLDB: bad volume operation code\n");
339 case VL_BADRELLOCKTYPE:
340 fprintf(STDERR, "VLDB: bad release lock type\n");
343 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
345 case VL_BADSERVERFLAG:
346 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
349 fprintf(STDERR, "VLDB: no permission access for call\n");
351 case VOLSERREAD_DUMPERROR:
353 "VOLSER: Problems encountered in reading the dump file !\n");
355 case VOLSERDUMPERROR:
356 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
358 case VOLSERATTACH_ERROR:
359 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
361 case VOLSERDETACH_ERROR:
362 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
364 case VOLSERILLEGAL_PARTITION:
365 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
367 case VOLSERBAD_ACCESS:
368 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
370 case VOLSERVLDB_ERROR:
371 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
374 fprintf(STDERR, "VOLSER: error in volume name\n");
377 fprintf(STDERR, "VOLSER: volume has moved\n");
380 fprintf(STDERR, "VOLSER: illegal operation\n");
382 case VOLSERBADRELEASE:
383 fprintf(STDERR, "VOLSER: release could not be completed\n");
386 fprintf(STDERR, "VOLSER: volume is busy\n");
388 case VOLSERNO_MEMORY:
389 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
393 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
395 case VOLSERMULTIRWVOL:
397 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
401 "VOLSER: not all entries were successfully processed\n");
408 initialize_KA_error_table();
409 initialize_RXK_error_table();
410 initialize_KTC_error_table();
411 initialize_ACFG_error_table();
412 initialize_CMD_error_table();
413 initialize_VL_error_table();
415 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
416 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
417 afs_error_message(errcode));
424 void init_volintInfo(struct volintInfo *vinfo) {
425 memset(vinfo, 0, sizeof(struct volintInfo));
427 vinfo->maxquota = -1;
429 vinfo->creationDate = -1;
430 vinfo->updateDate = -1;
438 static struct rx_securityClass *uvclass = 0;
439 static int uvindex = -1;
440 /* called by VLDBClient_Init to set the security module to be used in the RPC */
442 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
449 /* bind to volser on <port> <aserver> */
450 /* takes server address in network order, port in host order. dumb */
451 struct rx_connection *
452 UV_Bind(afs_int32 aserver, afs_int32 port)
454 register struct rx_connection *tc;
456 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
462 AFSVolCreateVolume_retry(struct rx_connection *z_conn,
463 afs_int32 partition, char *name, afs_int32 type,
464 afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
469 code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
471 if (code != VOLSERVOLBUSY)
474 #ifdef AFS_PTHREAD_ENV
477 IOMGR_Sleep(3-retries);
484 AFSVolTransCreate_retry(struct rx_connection *z_conn,
485 afs_int32 volume, afs_int32 partition,
486 afs_int32 flags, afs_int32 * trans)
491 code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
492 if (code != VOLSERVOLBUSY)
495 #ifdef AFS_PTHREAD_ENV
498 IOMGR_Sleep(3-retries);
505 /* if <okvol> is allright(indicated by beibg able to
506 * start a transaction, delete the <delvol> */
508 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
509 afs_uint32 okvol, afs_uint32 delvol)
511 afs_int32 error, code, tid, rcode;
516 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
519 code = AFSVolDeleteVolume(aconn, tid);
522 code = AFSVolEndTrans(aconn, tid, &rcode);
529 code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
531 code = AFSVolEndTrans(aconn, tid, &rcode);
536 code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
539 code = AFSVolDeleteVolume(aconn, tid);
542 code = AFSVolEndTrans(aconn, tid, &rcode);
555 /* called by EmuerateEntry, show vldb entry in a reasonable format */
557 SubEnumerateEntry(struct nvldbentry *entry)
565 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
566 if (entry->flags & RW_EXISTS)
567 fprintf(STDOUT, " valid \n");
569 fprintf(STDOUT, " invalid \n");
570 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
571 if (entry->flags & RO_EXISTS)
572 fprintf(STDOUT, " valid \n");
574 fprintf(STDOUT, " invalid \n");
575 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
576 if (entry->flags & BACK_EXISTS)
577 fprintf(STDOUT, " valid \n");
579 fprintf(STDOUT, " invalid \n");
580 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
581 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
583 if (entry->flags & RW_EXISTS)
584 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
585 if (entry->flags & RO_EXISTS)
586 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
587 if (entry->flags & BACK_EXISTS)
588 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
589 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
590 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
591 fprintf(STDOUT, "\n");
593 fprintf(STDOUT, " number of sites -> %lu\n",
594 (unsigned long)entry->nServers);
595 for (i = 0; i < entry->nServers; i++) {
596 if (entry->serverFlags[i] & NEW_REPSITE)
599 for (i = 0; i < entry->nServers; i++) {
600 MapPartIdIntoName(entry->serverPartition[i], pname);
601 fprintf(STDOUT, " server %s partition %s ",
602 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
603 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
604 if (entry->serverFlags[i] & ITSRWVOL)
605 fprintf(STDOUT, "RW Site ");
607 fprintf(STDOUT, "RO Site ");
609 if (entry->serverFlags[i] & NEW_REPSITE)
610 fprintf(STDOUT," -- New release");
612 if (!(entry->serverFlags[i] & ITSRWVOL))
613 fprintf(STDOUT," -- Old release");
615 if (entry->serverFlags[i] & RO_DONTUSE)
616 fprintf(STDOUT, " -- Not released");
618 fprintf(STDOUT, "\n");
625 /*enumerate the vldb entry corresponding to <entry> */
627 EnumerateEntry(struct nvldbentry *entry)
630 fprintf(STDOUT, "\n");
631 fprintf(STDOUT, "%s \n", entry->name);
632 SubEnumerateEntry(entry);
636 /* forcibly remove a volume. Very dangerous call */
638 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_uint32 volid)
640 register struct rx_connection *tconn;
641 register afs_int32 code;
643 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
645 code = AFSVolNukeVolume(tconn, partid, volid);
646 rx_DestroyConnection(tconn);
652 /* like df. Return usage of <pname> on <server> in <partition> */
654 UV_PartitionInfo64(afs_int32 server, char *pname,
655 struct diskPartition64 *partition)
657 register struct rx_connection *aconn;
660 aconn = (struct rx_connection *)0;
661 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
662 code = AFSVolPartitionInfo64(aconn, pname, partition);
663 if (code == RXGEN_OPCODE) {
664 struct diskPartition *dpp =
665 (struct diskPartition *)malloc(sizeof(struct diskPartition));
666 code = AFSVolPartitionInfo(aconn, pname, dpp);
668 strncpy(partition->name, dpp->name, 32);
669 strncpy(partition->devName, dpp->devName, 32);
670 partition->lock_fd = dpp->lock_fd;
671 partition->free = dpp->free;
672 partition->minFree = dpp->minFree;
677 fprintf(STDERR, "Could not get information on partition %s\n", pname);
678 PrintError("", code);
681 rx_DestroyConnection(aconn);
685 /* old interface to create volumes */
687 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
692 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
696 /* less old interface to create volumes */
698 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
699 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
700 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
702 afs_uint32 roid = 0, bkid = 0;
703 return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
704 aspare3, aspare4, anewid, &roid, &bkid);
708 * Create a volume on the given server and partition
710 * @param aserver server to create volume on
711 * @param spart partition to create volume on
712 * @param aname name of new volume
713 * @param aquota quota for new volume
714 * @param anewid contains the desired volume id for the new volume. If
715 * *anewid == 0, a new id will be chosen, and will be placed
716 * in *anewid when UV_CreateVolume3 returns.
717 * @param aroid contains the desired RO volume id. If NULL, the RO id entry
718 * will be unset. If *aroid == 0, an id will be chosen, and
719 * will be placed in *anewid when UV_CreateVolume3 returns.
720 * @param abkid same as aroid, except for the BK volume id instead of the
722 * @return 0 on success, error code otherwise.
725 UV_CreateVolume3(afs_int32 aserver, afs_int32 apart, char *aname,
726 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
727 afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
728 afs_uint32 * aroid, afs_uint32 * abkid)
730 register struct rx_connection *aconn;
732 register afs_int32 code;
734 afs_int32 rcode, vcode;
736 struct nvldbentry entry, storeEntry; /*the new vldb entry */
737 struct volintInfo tstatus;
740 aconn = (struct rx_connection *)0;
743 init_volintInfo(&tstatus);
744 tstatus.maxquota = aquota;
746 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
748 if (aroid && *aroid) {
749 VPRINT1("Using RO volume ID %d.\n", *aroid);
751 if (abkid && *abkid) {
752 VPRINT1("Using BK volume ID %d.\n", *abkid);
756 vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
758 fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
761 VPRINT1("Using volume ID %d.\n", *anewid);
763 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
764 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
766 if (aroid && *aroid == 0) {
767 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
768 EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
771 if (abkid && *abkid == 0) {
772 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
773 EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
777 /* rw,ro, bk id are related in the default case */
778 /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
780 if (aroid && *aroid == 0) {
783 if (abkid && *abkid == 0) {
788 AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
789 EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
792 code = AFSVolSetInfo(aconn, tid, &tstatus);
794 EPRINT(code, "Could not change quota, continuing...\n");
796 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
797 EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
800 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
802 /* set up the vldb entry for this volume */
803 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
805 entry.serverNumber[0] = aserver; /* this should have another
806 * level of indirection later */
807 entry.serverPartition[0] = apart; /* this should also have
808 * another indirection level */
809 entry.flags = RW_EXISTS; /* this records that rw volume exists */
810 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
811 entry.volumeId[RWVOL] = *anewid;
812 entry.volumeId[ROVOL] = aroid ? *aroid : 0;
813 entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
815 /*map into right byte order, before passing to xdr, the stuff has to be in host
816 * byte order. Xdr converts it into network order */
817 MapNetworkToHost(&entry, &storeEntry);
818 /* create the vldb entry */
819 vcode = VLDB_CreateEntry(&storeEntry);
822 "Could not create a VLDB entry for the volume %s %lu\n",
823 aname, (unsigned long)*anewid);
824 /*destroy the created volume */
825 VPRINT1("Deleting the newly created volume %u\n", *anewid);
826 AFSVolDeleteVolume(aconn, tid);
830 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
831 /* volume created, now terminate the transaction and release the connection */
832 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
833 * the volume will come online anyway when transaction timesout , so if
834 * vldb entry exists then the volume is guaranteed to exist too wrt create */
838 "Failed to end the transaction on the volume %s %lu\n", aname,
839 (unsigned long)*anewid);
846 code = AFSVolEndTrans(aconn, tid, &rcode);
848 fprintf(STDERR, "WARNING: could not end transaction\n");
851 rx_DestroyConnection(aconn);
852 PrintError("", error);
856 /* create a volume, given a server, partition number, volume name --> sends
857 * back new vol id in <anewid>*/
859 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
862 register struct rx_connection *aconn;
865 struct nvldbentry entry, storeEntry; /*the new vldb entry */
867 aconn = (struct rx_connection *)0;
870 /* set up the vldb entry for this volume */
871 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
873 entry.serverNumber[0] = aserver; /* this should have another
874 * level of indirection later */
875 entry.serverPartition[0] = apart; /* this should also have
876 * another indirection level */
877 entry.flags = RW_EXISTS; /* this records that rw volume exists */
878 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
879 entry.volumeId[RWVOL] = aid;
881 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
882 entry.volumeId[BACKVOL] = *anewid + 2;
884 entry.volumeId[ROVOL] = 0;
885 entry.volumeId[BACKVOL] = 0;
888 /*map into right byte order, before passing to xdr, the stuff has to be in host
889 * byte order. Xdr converts it into network order */
890 MapNetworkToHost(&entry, &storeEntry);
891 /* create the vldb entry */
892 vcode = VLDB_CreateEntry(&storeEntry);
895 "Could not create a VLDB entry for the volume %s %lu\n",
896 aname, (unsigned long)aid);
900 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
904 rx_DestroyConnection(aconn);
905 PrintError("", error);
909 /* Delete the volume <volid>on <aserver> <apart>
910 * the physical entry gets removed from the vldb only if the ref count
914 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
916 struct rx_connection *aconn = (struct rx_connection *)0;
918 afs_int32 code, rcode;
920 struct nvldbentry entry, storeEntry;
922 afs_int32 avoltype = -1, vtype;
923 int notondisk = 0, notinvldb = 0;
925 /* Find and read bhe VLDB entry for this volume */
926 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
928 if (code != VL_NOENT) {
929 EGOTO1(error_exit, code,
930 "Could not lock VLDB entry for the volume %u\n", avolid);
936 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
937 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
939 MapHostToNetwork(&entry);
942 EnumerateEntry(&entry);
945 /* Whether volume is in the VLDB or not. Delete the volume on disk */
946 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
947 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
949 if (code == VNOVOL) {
952 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
956 VPRINT1("Trying to delete the volume %u ...", avolid);
958 code = AFSVolDeleteVolume(aconn, ttid);
959 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
961 code = AFSVolEndTrans(aconn, ttid, &rcode);
962 code = (code ? code : rcode);
964 EGOTO1(error_exit, code,
965 "Could not end the transaction for the volume %u \n", avolid);
969 /* Now update the VLDB entry.
970 * But first, verify we have a VLDB entry.
971 * Whether volume is on disk or not. Delete the volume in VLDB.
976 if (avolid == entry.volumeId[BACKVOL]) {
977 /* Its a backup volume, modify the VLDB entry. Check that the
978 * backup volume is on the server/partition we asked to delete.
980 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
981 notinvldb = 2; /* Not on this server and partition */
985 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
987 entry.flags &= ~BACK_EXISTS;
991 else if (avolid == entry.volumeId[ROVOL]) {
992 /* Its a read-only volume, modify the VLDB entry. Check that the
993 * readonly volume is on the server/partition we asked to delete.
994 * If flags does not have RO_EIXSTS set, then this may mean the RO
995 * hasn't been released (and could exist in VLDB).
997 if (!Lp_ROMatch(aserver, apart, &entry)) {
998 notinvldb = 2; /* Not found on this server and partition */
1004 "Marking the readonly volume %lu deleted in the VLDB\n",
1005 (unsigned long)avolid);
1007 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
1009 if (!Lp_ROMatch(0, 0, &entry))
1010 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
1014 else if (avolid == entry.volumeId[RWVOL]) {
1015 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
1016 * Check that the readwrite volumes is on the server/partition we
1019 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
1020 notinvldb = 2; /* Not found on this server and partition */
1024 /* Delete backup if it exists */
1026 AFSVolTransCreate_retry(aconn, entry.volumeId[BACKVOL], apart,
1031 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
1032 entry.volumeId[BACKVOL]);
1035 code = AFSVolDeleteVolume(aconn, ttid);
1036 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
1037 entry.volumeId[BACKVOL]);
1039 code = AFSVolEndTrans(aconn, ttid, &rcode);
1041 code = (code ? code : rcode);
1042 EGOTO1(error_exit, code,
1043 "Could not end the transaction for the volume %u \n",
1044 entry.volumeId[BACKVOL]);
1046 fprintf(STDOUT, " done\n");
1051 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
1052 (unsigned long)avolid,
1054 flags & BACK_EXISTS) ? ", and its backup volume," :
1057 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
1059 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
1062 if (entry.flags & RO_EXISTS)
1063 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
1067 notinvldb = 2; /* Not found on this server and partition */
1071 /* Either delete or replace the VLDB entry */
1072 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
1075 "Last reference to the VLDB entry for %lu - deleting entry\n",
1076 (unsigned long)avolid);
1077 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
1078 EGOTO1(error_exit, code,
1079 "Could not delete the VLDB entry for the volume %u \n",
1082 MapNetworkToHost(&entry, &storeEntry);
1084 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
1085 (LOCKREL_OPCODE | LOCKREL_AFSID |
1086 LOCKREL_TIMESTAMP));
1087 EGOTO1(error_exit, code,
1088 "Could not update the VLDB entry for the volume %u \n",
1095 EPRINT(error, "\n");
1097 if (notondisk && notinvldb) {
1098 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
1099 ((notinvldb == 2) ? "on server and partition" : ""));
1101 error = VOLSERNOVOL;
1102 } else if (notondisk) {
1104 "WARNING: Volume %lu did not exist on the partition\n",
1105 (unsigned long)avolid);
1106 } else if (notinvldb) {
1107 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
1108 (unsigned long)avolid,
1109 ((notinvldb == 2) ? "on server and partition" : ""));
1113 code = AFSVolEndTrans(aconn, ttid, &rcode);
1114 code = (code ? code : rcode);
1116 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
1117 (unsigned long)avolid);
1118 PrintError("", code);
1126 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1127 (LOCKREL_OPCODE | LOCKREL_AFSID |
1128 LOCKREL_TIMESTAMP));
1131 "Could not release the lock on the VLDB entry for the volume %u \n",
1139 rx_DestroyConnection(aconn);
1143 /* add recovery to UV_MoveVolume */
1145 #define TESTC 0 /* set to test recovery code, clear for production */
1151 sigint_handler(int x)
1156 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1158 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1159 fprintf(STDOUT, "enter second control-c to exit\n");
1163 (void)signal(SIGINT, sigint_handler);
1168 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1169 * <atopart>. The operation is almost idempotent. The following
1170 * flags are recognized:
1172 * RV_NOCLONE - don't use a copy clone
1176 UV_MoveVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1177 afs_int32 atoserver, afs_int32 atopart, int flags)
1179 struct rx_connection *toconn, *fromconn;
1180 afs_int32 fromtid, totid, clonetid;
1183 char tmpName[VOLSER_MAXVOLNAME + 1];
1186 struct restoreCookie cookie;
1187 register afs_int32 vcode, code;
1188 afs_uint32 newVol, volid, backupId;
1189 struct volser_status tstatus;
1190 struct destServer destination;
1192 struct nvldbentry entry, storeEntry;
1193 int i, islocked, pntg;
1195 char in, lf; /* for test code */
1199 #ifdef ENABLE_BUGFIX_1165
1200 volEntries volumeInfo;
1201 struct volintInfo *infop = 0;
1205 fromconn = (struct rx_connection *)0;
1206 toconn = (struct rx_connection *)0;
1216 /* support control-c processing */
1219 (void)signal(SIGINT, sigint_handler);
1223 "\nThere are three tests points - verifies all code paths through recovery.\n");
1224 fprintf(STDOUT, "First test point - operation not started.\n");
1225 fprintf(STDOUT, "...test here (y, n)? ");
1227 fscanf(stdin, "%c", &in);
1228 fscanf(stdin, "%c", &lf); /* toss away */
1230 fprintf(STDOUT, "type control-c\n");
1232 fprintf(stdout, ".");
1237 /* or drop through */
1240 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1241 EGOTO1(mfail, vcode,
1242 "Could not fetch the entry for the volume %u from the VLDB \n",
1245 if (entry.volumeId[RWVOL] != afromvol) {
1246 fprintf(STDERR, "Only RW volume can be moved\n");
1250 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1251 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1254 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1255 EGOTO1(mfail, vcode,
1256 "Could not fetch the entry for the volume %u from the VLDB \n",
1259 backupId = entry.volumeId[BACKVOL];
1260 MapHostToNetwork(&entry);
1262 if (!Lp_Match(afromserver, afrompart, &entry)) {
1263 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1264 if (!Lp_Match(atoserver, atopart, &entry)) {
1265 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1266 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1267 (unsigned long)afromvol);
1268 fprintf(STDERR, "The current site is :");
1269 for (i = 0; i < entry.nServers; i++) {
1270 if (entry.serverFlags[i] == ITSRWVOL) {
1272 MapPartIdIntoName(entry.serverPartition[i], pname);
1273 fprintf(STDERR, " server %s partition %s \n",
1274 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1275 hostutil_GetNameByINet(entry.serverNumber[i]),
1280 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1281 (LOCKREL_OPCODE | LOCKREL_AFSID |
1282 LOCKREL_TIMESTAMP));
1283 EGOTO1(mfail, vcode,
1284 " Could not release lock on the VLDB entry for the volume %u \n",
1287 return VOLSERVOLMOVED;
1290 /* delete the volume afromvol on src_server */
1291 /* from-info does not exist but to-info does =>
1292 * we have already done the move, but the volume
1293 * may still be existing physically on from fileserver
1295 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1300 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITOffline,
1303 if (!code) { /* volume exists - delete it */
1304 VPRINT1("Setting flags on leftover source volume %u ...",
1307 AFSVolSetFlags(fromconn, fromtid,
1308 VTDeleteOnSalvage | VTOutOfService);
1310 "Failed to set flags on the leftover source volume %u\n",
1314 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1315 code = AFSVolDeleteVolume(fromconn, fromtid);
1317 "Failed to delete the leftover source volume %u\n",
1321 VPRINT1("Ending transaction on leftover source volume %u ...",
1323 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1328 "Could not end the transaction for the leftover source volume %u \n",
1333 /*delete the backup volume now */
1336 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
1339 if (!code) { /* backup volume exists - delete it */
1340 VPRINT1("Setting flags on leftover backup volume %u ...",
1343 AFSVolSetFlags(fromconn, fromtid,
1344 VTDeleteOnSalvage | VTOutOfService);
1346 "Failed to set flags on the backup volume %u\n", backupId);
1349 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1350 code = AFSVolDeleteVolume(fromconn, fromtid);
1352 "Could not delete the leftover backup volume %u\n",
1356 VPRINT1("Ending transaction on leftover backup volume %u ...",
1358 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1363 "Could not end the transaction for the leftover backup volume %u\n",
1373 /* From-info matches the vldb info about volid,
1374 * its ok start the move operation, the backup volume
1375 * on the old site is deleted in the process
1377 if (afrompart == atopart) {
1378 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1379 EGOTO2(mfail, error,
1380 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1381 afromserver, error);
1384 EGOTO1(mfail, VOLSERVOLMOVED,
1385 "Warning: Moving volume %u to its home partition ignored!\n",
1391 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1392 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1393 fromtid = totid = 0; /* initialize to uncreated */
1396 * clone the read/write volume locally.
1399 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1400 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1401 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1405 if (!(flags & RV_NOCLONE)) {
1406 /* Get a clone id */
1407 VPRINT1("Allocating new volume id for clone of volume %u ...",
1410 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1411 EGOTO1(mfail, vcode,
1412 "Could not get an ID for the clone of volume %u from the VLDB\n",
1416 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1417 VPRINT1("Cloning source volume %u ...", afromvol);
1418 strcpy(vname, "move-clone-temp");
1420 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1421 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1426 /* lookup the name of the volume we just cloned */
1428 code = AFSVolGetName(fromconn, fromtid, &volName);
1429 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1432 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1434 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1439 "Failed to end the transaction on the source volume %u\n",
1444 * Create the destination volume
1447 if (!(flags & RV_NOCLONE)) {
1448 /* All of this is to get the fromDate */
1449 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1451 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1454 "Failed to start a transaction on the cloned volume%u\n",
1458 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1460 AFSVolSetFlags(fromconn, clonetid,
1461 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1462 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1466 /* remember time from which we've dumped the volume */
1467 VPRINT1("Getting status of cloned volume %u ...", newVol);
1468 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1470 "Failed to get the status of the cloned volume %u\n",
1474 fromDate = CLOCKADJ(tstatus.creationDate);
1476 /* With RV_NOCLONE, just do a full copy from the source */
1481 #ifdef ENABLE_BUGFIX_1165
1483 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1484 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1485 * don't use this information...
1487 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1488 volumeInfo.volEntries_len = 0;
1489 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1491 "Failed to get the volint Info of the cloned volume %u\n",
1494 infop = (volintInfo *) volumeInfo.volEntries_val;
1495 infop->maxquota = -1; /* Else it will replace the default quota */
1496 infop->creationDate = -1; /* Else it will use the source creation date */
1497 infop->updateDate = -1; /* Else it will use the source update date */
1500 /* create a volume on the target machine */
1502 code = AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &totid);
1504 /* Delete the existing volume.
1505 * While we are deleting the volume in these steps, the transaction
1506 * we started against the cloned volume (clonetid above) will be
1507 * sitting idle. It will get cleaned up after 600 seconds
1509 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1510 code = AFSVolDeleteVolume(toconn, totid);
1512 "Could not delete the pre-existing volume %u on destination\n",
1517 ("Ending transaction on pre-existing volume %u on destination ...",
1519 code = AFSVolEndTrans(toconn, totid, &rcode);
1524 "Could not end the transaction on pre-existing volume %u on destination\n",
1529 VPRINT1("Creating the destination volume %u ...", volid);
1531 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1533 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1537 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1541 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1543 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1545 "Failed to set the flags on the destination volume %u\n", volid);
1549 * Now dump the clone to the new volume
1552 destination.destHost = ntohl(atoserver);
1553 destination.destPort = AFSCONF_VOLUMEPORT;
1554 destination.destSSID = 1;
1556 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1557 cookie.type = RWVOL;
1558 cookie.parent = entry.volumeId[RWVOL];
1561 if (!(flags & RV_NOCLONE)) {
1562 /* Copy the clone to the new volume */
1563 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1566 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1568 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1571 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1572 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1577 "Failed to end the transaction on the cloned volume %u\n",
1583 * reattach to the main-line volume, and incrementally dump it.
1586 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1587 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1589 "Failed to create a transaction on the source volume %u\n",
1593 /* now do the incremental */
1595 ("Doing the%s dump from source to destination for volume %u ... ",
1596 (flags & RV_NOCLONE) ? "" : " incremental",
1599 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1602 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1603 (flags & RV_NOCLONE) ? "" : " incremental");
1606 /* now adjust the flags so that the new volume becomes official */
1607 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1608 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1610 "Failed to set the flags to make old source volume offline\n");
1613 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1614 code = AFSVolSetFlags(toconn, totid, 0);
1616 "Failed to set the flags to make new source volume online\n");
1619 #ifdef ENABLE_BUGFIX_1165
1620 VPRINT1("Setting volume status on destination volume %u ...", volid);
1621 code = AFSVolSetInfo(toconn, totid, infop);
1623 "Failed to set volume status on the destination volume %u\n",
1628 /* put new volume online */
1629 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1630 code = AFSVolEndTrans(toconn, totid, &rcode);
1635 "Failed to end the transaction on the volume %u on the new site\n",
1639 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1640 MapNetworkToHost(&entry, &storeEntry);
1641 storeEntry.flags &= ~BACK_EXISTS;
1645 "Second test point - operation in progress but not complete.\n");
1646 fprintf(STDOUT, "...test here (y, n)? ");
1648 fscanf(stdin, "%c", &in);
1649 fscanf(stdin, "%c", &lf); /* toss away */
1651 fprintf(STDOUT, "type control-c\n");
1653 fprintf(stdout, ".");
1658 /* or drop through */
1661 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1663 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1664 (LOCKREL_OPCODE | LOCKREL_AFSID |
1665 LOCKREL_TIMESTAMP));
1668 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1669 storeEntry.name, (unsigned long)afromvol);
1678 "Third test point - operation complete but no cleanup.\n");
1679 fprintf(STDOUT, "...test here (y, n)? ");
1681 fscanf(stdin, "%c", &in);
1682 fscanf(stdin, "%c", &lf); /* toss away */
1684 fprintf(STDOUT, "type control-c\n");
1686 fprintf(stdout, ".");
1691 /* or drop through */
1694 /* This is tricky. File server is very stupid, and if you mark the volume
1695 * as VTOutOfService, it may mark the *good* instance (if you're moving
1696 * between partitions on the same machine) as out of service. Since
1697 * we're cleaning this code up in DEcorum, we're just going to kludge around
1698 * it for now by removing this call. */
1699 /* already out of service, just zap it now */
1701 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1704 "Failed to set the flags to make the old source volume offline\n");
1708 if (atoserver != afromserver) {
1709 /* set forwarding pointer for moved volumes */
1710 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1711 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1713 "Failed to set the forwarding pointer for the volume %u\n",
1718 VPRINT1("Deleting old volume %u on source ...", afromvol);
1719 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1720 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1724 VPRINT1("Ending transaction on old volume %u on the source ...",
1726 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1731 "Failed to end the transaction on the old volume %u on the source\n",
1735 /* Delete the backup volume on the original site */
1736 VPRINT1("Creating transaction for backup volume %u on source ...",
1739 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline, &fromtid);
1742 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1744 AFSVolSetFlags(fromconn, fromtid,
1745 VTDeleteOnSalvage | VTOutOfService);
1747 "Failed to set the flags on the backup volume %u on the source\n",
1751 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1752 code = AFSVolDeleteVolume(fromconn, fromtid);
1754 "Failed to delete the backup volume %u on the source\n",
1758 VPRINT1("Ending transaction on backup volume %u on source ...",
1760 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1765 "Failed to end the transaction on the backup volume %u on the source\n",
1769 code = 0; /* no backup volume? that's okay */
1772 if (!(flags & RV_NOCLONE)) {
1773 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1775 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
1778 "Failed to start a transaction on the cloned volume%u\n",
1782 /* now delete the clone */
1783 VPRINT1("Deleting the cloned volume %u ...", newVol);
1784 code = AFSVolDeleteVolume(fromconn, clonetid);
1785 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1789 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1790 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1795 "Failed to end the transaction on the cloned volume %u\n",
1804 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1805 fprintf(STDOUT, "...test here (y, n)? ");
1807 fscanf(stdin, "%c", &in);
1808 fscanf(stdin, "%c", &lf); /* toss away */
1810 fprintf(STDOUT, "type control-c\n");
1812 fprintf(stdout, ".");
1817 /* or drop through */
1820 /* normal cleanup code */
1822 if (entry.flags & RO_EXISTS)
1823 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1826 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1828 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1829 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1833 " Could not release the lock on the VLDB entry for the volume %lu \n",
1834 (unsigned long)afromvol);
1842 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1844 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1845 if (code || rcode) {
1848 "Could not end transaction on the source volume %lu\n",
1849 (unsigned long)afromvol);
1851 error = (code ? code : rcode);
1857 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1858 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1859 if (code || rcode) {
1862 "Could not end transaction on the source's clone volume %lu\n",
1863 (unsigned long)newVol);
1865 error = (code ? code : rcode);
1871 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1873 code = AFSVolEndTrans(toconn, totid, &rcode);
1877 "Could not end transaction on destination volume %lu\n",
1878 (unsigned long)afromvol);
1880 error = (code ? code : rcode);
1886 #ifdef ENABLE_BUGFIX_1165
1891 rx_DestroyConnection(fromconn);
1893 rx_DestroyConnection(toconn);
1894 PrintError("", error);
1897 /* come here only when the sky falls */
1902 "vos move: operation interrupted, cleanup in progress...\n");
1903 fprintf(STDOUT, "clear transaction contexts\n");
1907 /* unlock VLDB entry */
1909 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1910 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1911 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1917 VPRINT("Recovery: Ending transaction on clone volume ...");
1918 AFSVolEndTrans(fromconn, clonetid, &rcode);
1922 VPRINT("Recovery: Ending transaction on destination volume ...");
1923 AFSVolEndTrans(toconn, totid, &rcode);
1926 if (fromtid) { /* put it on-line */
1927 VPRINT("Recovery: Setting volume flags on source volume ...");
1928 AFSVolSetFlags(fromconn, fromtid, 0);
1931 VPRINT("Recovery: Ending transaction on source volume ...");
1932 AFSVolEndTrans(fromconn, fromtid, &rcode);
1936 VPRINT("Recovery: Accessing VLDB.\n");
1937 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1939 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1943 MapHostToNetwork(&entry);
1945 /* Delete either the volume on the source location or the target location.
1946 * If the vldb entry still points to the source location, then we know the
1947 * volume move didn't finish so we remove the volume from the target
1948 * location. Otherwise, we remove the volume from the source location.
1950 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1953 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1957 if (volid && toconn) {
1959 ("Recovery: Creating transaction for destination volume %u ...",
1962 AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &totid);
1968 ("Recovery: Setting flags on destination volume %u ...",
1970 AFSVolSetFlags(toconn, totid,
1971 VTDeleteOnSalvage | VTOutOfService);
1974 VPRINT1("Recovery: Deleting destination volume %u ...",
1976 AFSVolDeleteVolume(toconn, totid);
1980 ("Recovery: Ending transaction on destination volume %u ...",
1982 AFSVolEndTrans(toconn, totid, &rcode);
1986 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1991 /* put source volume on-line */
1993 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1996 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2001 VPRINT1("Recovery: Setting flags on source volume %u ...",
2003 AFSVolSetFlags(fromconn, fromtid, 0);
2007 ("Recovery: Ending transaction on source volume %u ...",
2009 AFSVolEndTrans(fromconn, fromtid, &rcode);
2013 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2017 } else { /* yep, move complete */
2020 "move complete - attempt cleanup of source partition - no guarantee\n");
2024 /* delete backup volume */
2026 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
2029 AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
2034 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2036 AFSVolSetFlags(fromconn, fromtid,
2037 VTDeleteOnSalvage | VTOutOfService);
2040 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
2041 AFSVolDeleteVolume(fromconn, fromtid);
2045 ("Recovery: Ending transaction on backup volume %u ...",
2047 AFSVolEndTrans(fromconn, fromtid, &rcode);
2051 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
2055 /* delete source volume */
2056 VPRINT1("Recovery: Creating transaction on source volume %u ...",
2059 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2064 VPRINT1("Recovery: Setting flags on backup volume %u ...",
2066 AFSVolSetFlags(fromconn, fromtid,
2067 VTDeleteOnSalvage | VTOutOfService);
2070 if (atoserver != afromserver) {
2071 VPRINT("Recovery: Setting volume forwarding pointer ...");
2072 AFSVolSetForwarding(fromconn, fromtid, atoserver);
2076 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
2077 AFSVolDeleteVolume(fromconn, fromtid);
2081 ("Recovery: Ending transaction on source volume %u ...",
2083 AFSVolEndTrans(fromconn, fromtid, &rcode);
2087 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2093 /* common cleanup - delete local clone */
2095 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2098 AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
2103 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
2104 AFSVolDeleteVolume(fromconn, clonetid);
2107 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2109 AFSVolEndTrans(fromconn, clonetid, &rcode);
2113 ("\nRecovery: Unable to start transaction on source volume %u.\n",
2118 /* unlock VLDB entry */
2120 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2122 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2123 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2127 done: /* routine cleanup */
2130 #ifdef ENABLE_BUGFIX_1165
2135 rx_DestroyConnection(fromconn);
2137 rx_DestroyConnection(toconn);
2140 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2148 UV_MoveVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2149 afs_int32 atoserver, afs_int32 atopart)
2151 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2152 atoserver, atopart, 0);
2156 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2157 * <atopart>. The new volume is named by <atovolname>. The new volume
2158 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2159 * from the VLDB. the following flags are supported:
2161 * RV_RDONLY - target volume is RO
2162 * RV_OFFLINE - leave target volume offline
2163 * RV_CPINCR - do incremental dump if target exists
2164 * RV_NOVLDB - don't create/update VLDB entry
2165 * RV_NOCLONE - don't use a copy clone
2168 UV_CopyVolume2(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2169 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2170 afs_uint32 atovolid, int flags)
2172 struct rx_connection *toconn, *fromconn;
2173 afs_int32 fromtid, totid, clonetid;
2176 afs_int32 fromDate, cloneFromDate;
2177 struct restoreCookie cookie;
2178 register afs_int32 vcode, code;
2179 afs_uint32 cloneVol, newVol;
2181 struct volser_status tstatus;
2182 struct destServer destination;
2184 struct nvldbentry entry, newentry, storeEntry;
2190 fromconn = (struct rx_connection *)0;
2191 toconn = (struct rx_connection *)0;
2199 /* support control-c processing */
2202 (void)signal(SIGINT, sigint_handler);
2204 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2205 EGOTO1(mfail, vcode,
2206 "Could not fetch the entry for the volume %u from the VLDB \n",
2208 MapHostToNetwork(&entry);
2211 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2212 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2213 fromtid = totid = 0; /* initialize to uncreated */
2216 /* check if we can shortcut and use a local clone instead of a full copy */
2217 if (afromserver == atoserver && afrompart == atopart) {
2222 * clone the read/write volume locally.
2226 if (!(flags & RV_NOCLONE)) {
2227 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2228 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
2230 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2234 /* Get a clone id */
2235 VPRINT1("Allocating new volume id for clone of volume %u ...",
2238 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2239 EGOTO1(mfail, vcode,
2240 "Could not get an ID for the clone of volume %u from the VLDB\n",
2248 /* Get a new volume id */
2249 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2251 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2252 EGOTO1(mfail, vcode,
2253 "Could not get an ID for the copy of volume %u from the VLDB\n",
2258 if (!(flags & RV_NOCLONE)) {
2259 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2260 VPRINT1("Cloning source volume %u ...", afromvol);
2261 strcpy(vname, "copy-clone-temp");
2263 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2265 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2269 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2271 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2276 "Failed to end the transaction on the source volume %u\n",
2282 * Create the destination volume
2285 if (!(flags & RV_NOCLONE)) {
2286 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2288 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2291 "Failed to start a transaction on the cloned volume%u\n",
2295 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2297 AFSVolSetFlags(fromconn, clonetid,
2298 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2299 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2303 /* remember time from which we've dumped the volume */
2304 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2305 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2307 "Failed to get the status of the cloned volume %u\n",
2311 fromDate = CLOCKADJ(tstatus.creationDate);
2316 /* create a volume on the target machine */
2318 code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &totid);
2320 if ((flags & RV_CPINCR)) {
2321 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2322 code = AFSVolGetStatus(toconn, totid, &tstatus);
2324 "Failed to get the status of the pre-existing volume %u\n",
2328 /* Using the update date should be OK here, but add some fudge */
2329 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2330 if ((flags & RV_NOCLONE))
2331 fromDate = cloneFromDate;
2333 /* XXX We should check that the source volume's creationDate is
2334 * XXX not newer than the existing target volume, and if not,
2335 * XXX throw away the existing target and do a full dump. */
2340 /* Delete the existing volume.
2341 * While we are deleting the volume in these steps, the transaction
2342 * we started against the cloned volume (clonetid above) will be
2343 * sitting idle. It will get cleaned up after 600 seconds
2345 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2346 code = AFSVolDeleteVolume(toconn, totid);
2348 "Could not delete the pre-existing volume %u on destination\n",
2353 ("Ending transaction on pre-existing volume %u on destination ...",
2355 code = AFSVolEndTrans(toconn, totid, &rcode);
2360 "Could not end the transaction on pre-existing volume %u on destination\n",
2365 VPRINT1("Creating the destination volume %u ...", newVol);
2367 AFSVolCreateVolume(toconn, atopart, atovolname,
2368 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2369 newVol, &newVol, &totid);
2370 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2374 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2376 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2378 "Failed to set the flags on the destination volume %u\n", newVol);
2383 destination.destHost = ntohl(atoserver);
2384 destination.destPort = AFSCONF_VOLUMEPORT;
2385 destination.destSSID = 1;
2387 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2388 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2393 * Now dump the clone to the new volume
2396 if (!(flags & RV_NOCLONE)) {
2397 /* XXX probably should have some code here that checks to see if
2398 * XXX we are copying to same server and partition - if so, just
2399 * XXX use a clone to save disk space */
2401 /* Copy the clone to the new volume */
2402 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2405 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2407 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2411 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2412 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2417 "Failed to end the transaction on the cloned volume %u\n",
2423 * reattach to the main-line volume, and incrementally dump it.
2426 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2427 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2429 "Failed to create a transaction on the source volume %u\n",
2433 /* now do the incremental */
2435 ("Doing the%s dump from source to destination for volume %u ... ",
2436 (flags & RV_NOCLONE) ? "" : " incremental",
2439 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2442 "Failed to do the%s dump from old site to new site\n",
2443 (flags & RV_NOCLONE) ? "" : " incremental");
2446 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2447 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2448 code = AFSVolSetFlags(toconn, totid, volflag);
2450 "Failed to set the flags to make destination volume online\n");
2453 /* put new volume online */
2454 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2455 code = AFSVolEndTrans(toconn, totid, &rcode);
2460 "Failed to end the transaction on the destination volume %u\n",
2464 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2465 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2470 "Failed to end the transaction on the source volume %u\n",
2476 if (!(flags & RV_NOCLONE)) {
2477 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2479 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2482 "Failed to start a transaction on the cloned volume%u\n",
2486 /* now delete the clone */
2487 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2488 code = AFSVolDeleteVolume(fromconn, clonetid);
2489 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2493 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2494 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2499 "Failed to end the transaction on the cloned volume %u\n",
2504 if (!(flags & RV_NOVLDB)) {
2505 /* create the vldb entry for the copied volume */
2506 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2507 newentry.nServers = 1;
2508 newentry.serverNumber[0] = atoserver;
2509 newentry.serverPartition[0] = atopart;
2510 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2511 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2512 newentry.volumeId[RWVOL] = newVol;
2513 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2514 newentry.volumeId[BACKVOL] = 0;
2515 newentry.cloneId = 0;
2516 /*map into right byte order, before passing to xdr, the stuff has to be in host
2517 * byte order. Xdr converts it into network order */
2518 MapNetworkToHost(&newentry, &storeEntry);
2519 /* create the vldb entry */
2520 vcode = VLDB_CreateEntry(&storeEntry);
2523 "Could not create a VLDB entry for the volume %s %lu\n",
2524 atovolname, (unsigned long)newVol);
2525 /*destroy the created volume */
2526 VPRINT1("Deleting the newly created volume %u\n", newVol);
2527 AFSVolDeleteVolume(toconn, totid);
2531 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2535 /* normal cleanup code */
2538 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2540 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2541 if (code || rcode) {
2544 "Could not end transaction on the source volume %lu\n",
2545 (unsigned long)afromvol);
2547 error = (code ? code : rcode);
2553 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2555 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2556 if (code || rcode) {
2559 "Could not end transaction on the source's clone volume %lu\n",
2560 (unsigned long)cloneVol);
2562 error = (code ? code : rcode);
2568 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2570 code = AFSVolEndTrans(toconn, totid, &rcode);
2574 "Could not end transaction on destination volume %lu\n",
2575 (unsigned long)newVol);
2577 error = (code ? code : rcode);
2582 rx_DestroyConnection(fromconn);
2584 rx_DestroyConnection(toconn);
2585 PrintError("", error);
2588 /* come here only when the sky falls */
2593 "vos copy: operation interrupted, cleanup in progress...\n");
2594 fprintf(STDOUT, "clear transaction contexts\n");
2599 VPRINT("Recovery: Ending transaction on clone volume ...");
2600 AFSVolEndTrans(fromconn, clonetid, &rcode);
2604 VPRINT("Recovery: Ending transaction on destination volume ...");
2605 AFSVolEndTrans(toconn, totid, &rcode);
2608 if (fromtid) { /* put it on-line */
2609 VPRINT("Recovery: Ending transaction on source volume ...");
2610 AFSVolEndTrans(fromconn, fromtid, &rcode);
2614 VPRINT("Recovery: Accessing VLDB.\n");
2615 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2617 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2621 MapHostToNetwork(&entry);
2623 /* common cleanup - delete local clone */
2625 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2628 AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
2633 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2634 AFSVolDeleteVolume(fromconn, clonetid);
2637 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2639 AFSVolEndTrans(fromconn, clonetid, &rcode);
2643 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2648 done: /* routine cleanup */
2650 rx_DestroyConnection(fromconn);
2652 rx_DestroyConnection(toconn);
2655 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2663 UV_CopyVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2664 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2666 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2667 atovolname, atoserver, atopart, 0, 0);
2672 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2673 * if one already exists, update it
2677 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid)
2679 struct rx_connection *aconn = (struct rx_connection *)0;
2680 afs_int32 ttid = 0, btid = 0;
2681 afs_uint32 backupID;
2682 afs_int32 code = 0, rcode = 0;
2683 char vname[VOLSER_MAXVOLNAME + 1];
2684 struct nvldbentry entry, storeEntry;
2685 afs_int32 error = 0;
2686 int vldblocked = 0, vldbmod = 0, backexists = 1;
2688 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2690 /* the calls to VLDB will succeed only if avolid is a RW volume,
2691 * since we are following the RW hash chain for searching */
2692 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2695 "Could not fetch the entry for the volume %lu from the VLDB \n",
2696 (unsigned long)avolid);
2700 MapHostToNetwork(&entry);
2702 /* These operations require the VLDB be locked since it means the VLDB
2703 * will change or the vldb is already locked.
2705 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2706 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2707 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2709 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2712 "Could not lock the VLDB entry for the volume %lu\n",
2713 (unsigned long)avolid);
2719 /* Reread the vldb entry */
2720 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2723 "Could not fetch the entry for the volume %lu from the VLDB \n",
2724 (unsigned long)avolid);
2728 MapHostToNetwork(&entry);
2731 if (!ISNAMEVALID(entry.name)) {
2732 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2734 error = VOLSERBADNAME;
2738 backupID = entry.volumeId[BACKVOL];
2739 if (backupID == INVALID_BID) {
2740 /* Get a backup volume id from the VLDB and update the vldb
2743 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2746 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2747 (unsigned long)avolid);
2751 entry.volumeId[BACKVOL] = backupID;
2755 /* Test to see if the backup volume exists by trying to create
2756 * a transaction on the backup volume. We've assumed the backup exists.
2758 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2760 if (code != VNOVOL) {
2761 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2762 (unsigned long)backupID);
2766 backexists = 0; /* backup volume does not exist */
2769 code = AFSVolEndTrans(aconn, btid, &rcode);
2771 if (code || rcode) {
2773 "Could not end transaction on the previous backup volume %lu\n",
2774 (unsigned long)backupID);
2775 error = (code ? code : rcode);
2780 /* Now go ahead and try to clone the RW volume.
2781 * First start a transaction on the RW volume
2783 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
2785 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2786 (unsigned long)avolid);
2791 /* Clone or reclone the volume, depending on whether the backup
2792 * volume exists or not
2795 VPRINT1("Re-cloning backup volume %u ...", backupID);
2797 code = AFSVolReClone(aconn, ttid, backupID);
2799 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2800 (unsigned long)backupID);
2805 VPRINT1("Creating a new backup clone %u ...", backupID);
2807 strcpy(vname, entry.name);
2808 strcat(vname, ".backup");
2810 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2812 fprintf(STDERR, "Failed to clone the volume %lu\n",
2813 (unsigned long)avolid);
2819 /* End the transaction on the RW volume */
2820 code = AFSVolEndTrans(aconn, ttid, &rcode);
2822 if (code || rcode) {
2824 "Failed to end the transaction on the rw volume %lu\n",
2825 (unsigned long)avolid);
2826 error = (code ? code : rcode);
2830 /* Mork vldb as backup exists */
2831 if (!(entry.flags & BACK_EXISTS)) {
2832 entry.flags |= BACK_EXISTS;
2836 /* Now go back to the backup volume and bring it on line */
2837 code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
2840 "Failed to start a transaction on the backup volume %lu\n",
2841 (unsigned long)backupID);
2846 code = AFSVolSetFlags(aconn, btid, 0);
2848 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2849 (unsigned long)backupID);
2854 code = AFSVolEndTrans(aconn, btid, &rcode);
2856 if (code || rcode) {
2858 "Failed to end the transaction on the backup volume %lu\n",
2859 (unsigned long)backupID);
2860 error = (code ? code : rcode);
2866 /* Will update the vldb below */
2870 code = AFSVolEndTrans(aconn, ttid, &rcode);
2871 if (code || rcode) {
2872 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2873 (unsigned long)avolid);
2875 error = (code ? code : rcode);
2880 code = AFSVolEndTrans(aconn, btid, &rcode);
2881 if (code || rcode) {
2883 "Could not end transaction the backup volume %lu\n",
2884 (unsigned long)backupID);
2886 error = (code ? code : rcode);
2890 /* Now update the vldb - if modified */
2893 MapNetworkToHost(&entry, &storeEntry);
2895 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2896 (LOCKREL_OPCODE | LOCKREL_AFSID |
2897 LOCKREL_TIMESTAMP));
2900 "Could not update the VLDB entry for the volume %lu \n",
2901 (unsigned long)avolid);
2907 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2908 (LOCKREL_OPCODE | LOCKREL_AFSID |
2909 LOCKREL_TIMESTAMP));
2912 "Could not unlock the VLDB entry for the volume %lu \n",
2913 (unsigned long)avolid);
2921 rx_DestroyConnection(aconn);
2923 PrintError("", error);
2927 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2928 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2929 * The new volume is named by <aname>, or by appending ".clone" to
2930 * the existing name if <aname> is NULL. The following flags are
2933 * RV_RDONLY - target volume is RO
2934 * RV_OFFLINE - leave target volume offline
2938 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 avolid,
2939 afs_uint32 acloneid, char *aname, int flags)
2941 struct rx_connection *aconn = (struct rx_connection *)0;
2942 afs_int32 ttid = 0, btid = 0;
2943 afs_int32 code = 0, rcode = 0;
2944 char vname[VOLSER_MAXVOLNAME + 1];
2945 afs_int32 error = 0;
2947 volEntries volumeInfo;
2949 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2952 volumeInfo.volEntries_val = (volintInfo *) 0;
2953 volumeInfo.volEntries_len = 0;
2954 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2956 fprintf(stderr, "Could not get info for volume %lu\n",
2957 (unsigned long)avolid);
2961 strncpy(vname, volumeInfo.volEntries_val[0].name,
2962 VOLSER_OLDMAXVOLNAME - 7);
2963 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2964 strcat(vname, ".clone");
2966 if (volumeInfo.volEntries_val)
2967 free(volumeInfo.volEntries_val);
2971 /* Get a clone id */
2972 VPRINT1("Allocating new volume id for clone of volume %u ...",
2974 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2976 "Could not get an ID for the clone of volume %u from the VLDB\n",
2981 /* Test to see if the clone volume exists by trying to create
2982 * a transaction on the clone volume. We've assumed the clone exists.
2984 /* XXX I wonder what happens if the clone has some other parent... */
2985 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
2987 if (code != VNOVOL) {
2988 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2989 (unsigned long)acloneid);
2993 backexists = 0; /* backup volume does not exist */
2996 code = AFSVolEndTrans(aconn, btid, &rcode);
2998 if (code || rcode) {
3000 "Could not end transaction on the previous clone volume %lu\n",
3001 (unsigned long)acloneid);
3002 error = (code ? code : rcode);
3007 /* Now go ahead and try to clone the RW volume.
3008 * First start a transaction on the RW volume
3010 code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
3012 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
3013 (unsigned long)avolid);
3018 /* Clone or reclone the volume, depending on whether the backup
3019 * volume exists or not
3022 VPRINT1("Re-cloning clone volume %u ...", acloneid);
3024 code = AFSVolReClone(aconn, ttid, acloneid);
3026 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
3027 (unsigned long)acloneid);
3032 VPRINT1("Creating a new clone %u ...", acloneid);
3034 code = AFSVolClone(aconn, ttid, 0,
3035 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
3038 fprintf(STDERR, "Failed to clone the volume %lu\n",
3039 (unsigned long)avolid);
3045 /* End the transaction on the RW volume */
3046 code = AFSVolEndTrans(aconn, ttid, &rcode);
3048 if (code || rcode) {
3050 "Failed to end the transaction on the rw volume %lu\n",
3051 (unsigned long)avolid);
3052 error = (code ? code : rcode);
3056 /* Now go back to the backup volume and bring it on line */
3057 if (!(flags & RV_OFFLINE)) {
3058 code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
3061 "Failed to start a transaction on the clone volume %lu\n",
3062 (unsigned long)acloneid);
3067 code = AFSVolSetFlags(aconn, btid, 0);
3069 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
3070 (unsigned long)acloneid);
3075 code = AFSVolEndTrans(aconn, btid, &rcode);
3077 if (code || rcode) {
3079 "Failed to end the transaction on the clone volume %lu\n",
3080 (unsigned long)acloneid);
3081 error = (code ? code : rcode);
3090 code = AFSVolEndTrans(aconn, ttid, &rcode);
3091 if (code || rcode) {
3092 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3093 (unsigned long)avolid);
3095 error = (code ? code : rcode);
3100 code = AFSVolEndTrans(aconn, btid, &rcode);
3101 if (code || rcode) {
3103 "Could not end transaction on the clone volume %lu\n",
3104 (unsigned long)acloneid);
3106 error = (code ? code : rcode);
3111 rx_DestroyConnection(aconn);
3113 PrintError("", error);
3118 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
3121 afs_int32 acode, ccode, rcode, tid;
3122 ccode = rcode = tid = 0;
3124 acode = AFSVolTransCreate_retry(conn, vid, part, flags, &tid);
3125 if (!acode) { /* It really was there */
3126 acode = AFSVolDeleteVolume(conn, tid);
3128 fprintf(STDERR, "Failed to delete volume %lu.\n",
3129 (unsigned long)vid);
3130 PrintError("", acode);
3132 ccode = AFSVolEndTrans(conn, tid, &rcode);
3136 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3137 (unsigned long)vid);
3138 PrintError("", ccode);
3145 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3146 #define ONERROR0(ec, es) if (ec) { fprintf(STDERR, (es)); error = (ec); goto rfail; }
3147 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3149 /* Get a "transaction" on this replica. Create the volume
3150 * if necessary. Return the time from which a dump should
3151 * be made (0 if it's a new volume)
3154 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3155 struct rx_connection **connPtr, afs_int32 * transPtr,
3156 afs_uint32 * crtimePtr, afs_uint32 * uptimePtr)
3159 struct volser_status tstatus;
3164 *connPtr = (struct rx_connection *)0;
3169 /* get connection to the replication site */
3170 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3172 goto fail; /* server is down */
3174 volid = vldbEntryPtr->volumeId[ROVOL];
3177 AFSVolTransCreate_retry(*connPtr, volid,
3178 vldbEntryPtr->serverPartition[index], ITOffline,
3181 /* If the volume does not exist, create it */
3182 if (!volid || code) {
3186 if (volid && (code != VNOVOL)) {
3187 PrintError("Failed to start a transaction on the RO volume.\n",
3192 strcpy(volname, vldbEntryPtr->name);
3193 strcat(volname, ".readonly");
3197 "Creating new volume %lu on replication site %s: ",
3198 (unsigned long)volid,
3199 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3200 serverNumber[index], hoststr) :
3201 hostutil_GetNameByINet(vldbEntryPtr->
3202 serverNumber[index]));
3207 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3209 vldbEntryPtr->volumeId[RWVOL], &volid,
3212 PrintError("Failed to create the ro volume: ", code);
3215 vldbEntryPtr->volumeId[ROVOL] = volid;
3219 /* The following is a bit redundant, since create sets these flags by default */
3221 AFSVolSetFlags(*connPtr, *transPtr,
3222 VTDeleteOnSalvage | VTOutOfService);
3224 PrintError("Failed to set flags on the ro volume: ", code);
3229 /* Otherwise, the transaction did succeed, so get the creation date of the
3230 * latest RO volume on the replication site
3233 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3234 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3235 serverNumber[index], hoststr) :
3236 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3238 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3240 PrintError("Failed to get status of volume on destination: ",
3244 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3245 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3252 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3257 PrintError("Could not end transaction on a ro volume: ", tcode);
3264 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3265 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3266 void *cookie, manyResults * results)
3270 for (i = 0; i < tr->manyDests_len; i++) {
3271 results->manyResults_val[i] =
3272 AFSVolForward(fromconn, fromtid, fromdate,
3273 &(tr->manyDests_val[i].server),
3274 tr->manyDests_val[i].trans, cookie);
3280 /* UV_ReleaseVolume()
3281 * Release volume <afromvol> on <afromserver> <afrompart> to all
3282 * its RO sites (full release). Unless the previous release was
3283 * incomplete: in which case we bring the remaining incomplete
3284 * volumes up to date with the volumes that were released
3286 * forceflag: Performs a full release.
3288 * Will create a clone from the RW, then dump the clone out to
3289 * the remaining replicas. If there is more than 1 RO sites,
3290 * ensure that the VLDB says at least one RO is available all
3291 * the time: Influences when we write back the VLDB entry.
3295 UV_ReleaseVolume(afs_uint32 afromvol, afs_int32 afromserver,
3296 afs_int32 afrompart, int forceflag)
3300 afs_int32 vcode, rcode, tcode;
3301 afs_uint32 cloneVolId, roVolId;
3302 struct replica *replicas = 0;
3303 struct nvldbentry entry, storeEntry;
3304 int i, volcount, m, fullrelease, vldbindex;
3306 struct restoreCookie cookie;
3307 struct rx_connection **toconns = 0;
3308 struct release *times = 0;
3310 struct rx_connection *fromconn = (struct rx_connection *)0;
3311 afs_int32 error = 0;
3313 afs_int32 clonetid = 0, onlinetid;
3314 afs_int32 fromtid = 0;
3315 afs_uint32 fromdate = 0;
3316 afs_uint32 thisdate;
3320 manyResults results;
3321 int rwindex, roindex, roclone, roexists;
3322 afs_uint32 rwcrdate = 0;
3323 afs_uint32 rwupdate, clcrdate;
3327 } remembertime[NMAXNSERVERS];
3328 int releasecount = 0;
3329 struct volser_status volstatus;
3332 memset((char *)remembertime, 0, sizeof(remembertime));
3333 memset((char *)&results, 0, sizeof(results));
3335 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3336 if (vcode != VL_RERELEASE)
3337 ONERROR(vcode, afromvol,
3338 "Could not lock the VLDB entry for the volume %u.\n");
3341 /* Get the vldb entry in readable format */
3342 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3343 ONERROR(vcode, afromvol,
3344 "Could not fetch the entry for the volume %u from the VLDB.\n");
3345 MapHostToNetwork(&entry);
3348 EnumerateEntry(&entry);
3350 if (!ISNAMEVALID(entry.name))
3351 ONERROR(VOLSERBADOP, entry.name,
3352 "Volume name %s is too long, rename before releasing.\n");
3353 if (entry.volumeId[RWVOL] != afromvol)
3354 ONERROR(VOLSERBADOP, afromvol,
3355 "The volume %u being released is not a read-write volume.\n");
3356 if (entry.nServers <= 1)
3357 ONERROR(VOLSERBADOP, afromvol,
3358 "Volume %u has no replicas - release operation is meaningless!\n");
3359 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3360 ONERROR(VOLSERBADOP, entry.name,
3361 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3363 /* roclone is true if one of the RO volumes is on the same
3364 * partition as the RW volume. In this case, we make the RO volume
3365 * on the same partition a clone instead of a complete copy.
3368 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3369 roclone = ((roindex == -1) ? 0 : 1);
3370 rwindex = Lp_GetRwIndex(&entry);
3372 ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
3374 /* Make sure we have a RO volume id to work with */
3375 if (entry.volumeId[ROVOL] == INVALID_BID) {
3376 /* need to get a new RO volume id */
3377 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3378 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3380 entry.volumeId[ROVOL] = roVolId;
3381 MapNetworkToHost(&entry, &storeEntry);
3382 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3383 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3386 /* Will we be completing a previously unfinished release. -force overrides */
3387 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3388 if (entry.serverFlags[i] & ITSROVOL) {
3390 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3393 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3396 /* Determine which volume id to use and see if it exists */
3399 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3400 code = VolumeExists(afromserver, afrompart, cloneVolId);
3401 roexists = ((code == ENODEV) ? 0 : 1);
3403 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3405 ONERROR(-1, afromserver,
3406 "Cannot establish connection with server 0x%x\n");
3410 fullrelease = 1; /* Do a full release if RO clone does not exist */
3412 /* Begin transaction on RW and mark it busy while we query it */
3413 code = AFSVolTransCreate_retry(
3414 fromconn, afromvol, afrompart, ITBusy, &fromtid
3416 ONERROR(code, afromvol,
3417 "Failed to start transaction on RW volume %u\n");
3419 /* Query the creation date for the RW */
3420 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3421 ONERROR(code, afromvol,
3422 "Failed to get the status of RW volume %u\n");
3423 rwcrdate = volstatus.creationDate;
3424 rwupdate = volstatus.updateDate;
3426 /* End transaction on RW */
3427 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3429 ONERROR((code ? code : rcode), afromvol,
3430 "Failed to end transaction on RW volume %u\n");
3432 /* Begin transaction on clone and mark it busy while we query it */
3433 code = AFSVolTransCreate_retry(
3434 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3436 ONERROR(code, cloneVolId,
3437 "Failed to start transaction on RW clone %u\n");
3439 /* Query the creation date for the clone */
3440 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3441 ONERROR(code, cloneVolId,
3442 "Failed to get the status of RW clone %u\n");
3443 clcrdate = volstatus.creationDate;
3445 /* End transaction on clone */
3446 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3448 ONERROR((code ? code : rcode), cloneVolId,
3449 "Failed to end transaction on RW clone %u\n");
3451 if (rwcrdate > clcrdate)
3452 fullrelease = 2;/* Do a full release if RO clone older than RW */
3457 switch (fullrelease) {
3459 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3460 (unsigned long)afromvol);
3463 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3464 (unsigned long)afromvol);
3467 fprintf(STDOUT, "This is a completion of a previous release\n");
3473 /* If the RO clone exists, then if the clone is a temporary
3474 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3475 * (it was recently added), then also delete it. We do not
3476 * want to "reclone" a temporary RO clone.
3479 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3480 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3481 if (code && (code != VNOVOL))
3486 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3487 * write this entry out to the vlserver until after the first
3488 * RO volume is released (temp RO clones don't count).
3490 for (i = 0; i < entry.nServers; i++) {
3491 entry.serverFlags[i] &= ~NEW_REPSITE;
3492 entry.serverFlags[i] |= RO_DONTUSE;
3494 entry.serverFlags[rwindex] |= NEW_REPSITE;
3495 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3497 /* Begin transaction on RW and mark it busy while we clone it */
3499 AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
3501 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3503 /* Clone or reclone the volume */
3505 VPRINT1("Recloning RW volume %u...", cloneVolId);
3506 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3507 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3511 strcpy(vname, entry.name);
3512 strcat(vname, ".readonly");
3513 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3515 strcpy(vname, "readonly-clone-temp");
3516 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3519 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3521 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3525 /* Get the time the RW was created for future information */
3526 VPRINT1("Getting status of RW volume %u...", afromvol);
3527 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3528 ONERROR(code, afromvol,
3529 "Failed to get the status of the RW volume %u\n");
3531 rwcrdate = volstatus.creationDate;
3532 rwupdate = volstatus.updateDate;
3534 /* End the transaction on the RW volume */
3535 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3536 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3538 ONERROR((code ? code : rcode), afromvol,
3539 "Failed to end cloning transaction on RW %u\n");
3542 /* Remember clone volume ID in case we fail or are interrupted */
3543 entry.cloneId = cloneVolId;
3546 /* Bring the RO clone online - though not if it's a temporary clone */
3547 VPRINT1("Starting transaction on RO clone volume %u...",
3550 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
3552 ONERROR(code, cloneVolId,
3553 "Failed to start transaction on volume %u\n");
3556 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3557 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3560 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3561 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3562 ONERROR((code ? code : rcode), cloneVolId,
3563 "Failed to end transaction on RO clone %u\n");
3566 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3568 /* Sleep so that a client searching for an online volume won't
3569 * find the clone offline and then the next RO offline while the
3570 * release brings the clone online and the next RO offline (race).
3571 * There is a fix in the 3.4 client that does not need this sleep
3572 * anymore, but we don't know what clients we have.
3574 if (entry.nServers > 2)
3577 /* Mark the RO clone in the VLDB as a good site (already released) */
3578 entry.serverFlags[roindex] |= NEW_REPSITE;
3579 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3580 entry.flags |= RO_EXISTS;
3584 /* Write out the VLDB entry only if the clone is not a temporary
3585 * clone. If we did this to a temporary clone then we would end
3586 * up marking all the ROs as "old release" making the ROs
3587 * temporarily unavailable.
3589 MapNetworkToHost(&entry, &storeEntry);
3590 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3591 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3592 ONERROR(vcode, entry.name,
3593 "Could not update vldb entry for %s.\n");
3598 /* Now we will release from the clone to the remaining RO replicas.
3599 * The first 2 ROs (counting the non-temporary RO clone) are released
3600 * individually: releasecount. This is to reduce the race condition
3601 * of clients trying to find an on-line RO volume. The remaining ROs
3602 * are released in parallel but no more than half the number of ROs
3603 * (rounded up) at a time: nservers.
3606 strcpy(vname, entry.name);
3607 strcat(vname, ".readonly");
3608 memset(&cookie, 0, sizeof(cookie));
3609 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3610 cookie.type = ROVOL;
3611 cookie.parent = entry.volumeId[RWVOL];
3614 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3616 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3617 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3619 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3621 results.manyResults_val =
3622 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3623 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3625 "Failed to create transaction on the release clone\n");
3627 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3628 memset(times, 0, (sizeof(struct release) * nservers + 1));
3629 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3630 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3632 /* Create a transaction on the cloned volume */
3633 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3635 AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3636 if (!fullrelease && code)
3637 ONERROR(VOLSERNOVOL, afromvol,
3638 "Old clone is inaccessible. Try vos release -f %u.\n");
3639 ONERROR0(code, "Failed to create transaction on the release clone\n");
3642 /* For each index in the VLDB */
3643 for (vldbindex = 0; vldbindex < entry.nServers;) {
3645 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3647 ((volcount < nservers) && (vldbindex < entry.nServers));
3649 /* The first two RO volumes will be released individually.
3650 * The rest are then released in parallel. This is a hack
3651 * for clients not recognizing right away when a RO volume
3652 * comes back on-line.
3654 if ((volcount == 1) && (releasecount < 2))
3657 if (vldbindex == roindex)
3658 continue; /* the clone */
3659 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3660 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3662 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3663 continue; /* not a RO vol */
3666 /* Get a Transaction on this replica. Get a new connection if
3667 * necessary. Create the volume if necessary. Return the
3668 * time from which the dump should be made (0 if it's a new
3669 * volume). Each volume might have a different time.
3671 replicas[volcount].server.destHost =
3672 ntohl(entry.serverNumber[vldbindex]);
3673 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3674 replicas[volcount].server.destSSID = 1;
3675 times[volcount].vldbEntryIndex = vldbindex;
3678 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3679 &(replicas[volcount].trans),
3680 &(times[volcount].crtime),
3681 &(times[volcount].uptime));
3685 /* Thisdate is the date from which we want to pick up all changes */
3686 if (forceflag || !fullrelease
3687 || (rwcrdate > times[volcount].crtime)) {
3688 /* If the forceflag is set, then we want to do a full dump.
3689 * If it's not a full release, we can't be sure that the creation
3690 * date is good (so we also do a full dump).
3691 * If the RW volume was replaced (its creation date is newer than
3692 * the last release), then we can't be sure what has changed (so
3693 * we do a full dump).
3696 } else if (remembertime[vldbindex].validtime) {
3697 /* Trans was prev ended. Use the time from the prev trans
3698 * because, prev trans may have created the volume. In which
3699 * case time[volcount].time would be now instead of 0.
3702 (remembertime[vldbindex].uptime < times[volcount].uptime)
3703 ? remembertime[vldbindex].uptime
3704 : times[volcount].uptime;
3706 thisdate = times[volcount].uptime;
3708 remembertime[vldbindex].validtime = 1;
3709 remembertime[vldbindex].uptime = thisdate;
3711 if (volcount == 0) {
3712 fromdate = thisdate;
3714 /* Include this volume if it is within 15 minutes of the earliest */
3716 thisdate) ? (fromdate - thisdate) : (thisdate -
3718 AFSVolEndTrans(toconns[volcount],
3719 replicas[volcount].trans, &rcode);
3720 replicas[volcount].trans = 0;
3723 if (thisdate < fromdate)
3724 fromdate = thisdate;
3732 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3733 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3734 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3735 vldbEntryIndex], hoststr) :
3736 hostutil_GetNameByINet(entry.
3737 serverNumber[times[0].
3740 for (s = 1; s < volcount; s++) {
3741 fprintf(STDOUT, " and %s",
3742 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3743 vldbEntryIndex], hoststr) :
3744 hostutil_GetNameByINet(entry.
3745 serverNumber[times[s].
3750 fprintf(STDOUT, " (full release)");
3753 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3755 fprintf(STDOUT, ".\n");
3759 /* Release the ones we have collected */
3760 tr.manyDests_val = &(replicas[0]);
3761 tr.manyDests_len = results.manyResults_len = volcount;
3763 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3764 0 /*spare */ , &cookie, &results);
3765 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3767 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3768 0 /*spare */ , &cookie, &results);
3773 PrintError("Release failed: ", code);
3775 for (m = 0; m < volcount; m++) {
3776 if (results.manyResults_val[m]) {
3777 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3778 /* we retry timed out transaction. When it is
3779 * not the first volume and the transaction wasn't found
3780 * (assume it timed out and was garbage collected by volser).
3783 ("Failed to dump volume from clone to a ro site: ",
3784 results.manyResults_val[m]);
3790 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3791 ROVOL, entry.volumeId[RWVOL], 0, 0);
3793 if ((m == 0) || (code != ENOENT)) {
3794 PrintError("Failed to set correct names and ids: ",
3800 /* have to clear dest. flags to ensure new vol goes online:
3801 * because the restore (forwarded) operation copied
3802 * the V_inService(=0) flag over to the destination.
3804 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3806 if ((m == 0) || (code != ENOENT)) {
3807 PrintError("Failed to set flags on ro volume: ",
3813 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3814 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3815 entry.flags |= RO_EXISTS;
3820 /* End the transactions and destroy the connections */
3821 for (s = 0; s < volcount; s++) {
3822 if (replicas[s].trans)
3823 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3824 replicas[s].trans = 0;
3828 if ((s == 0) || (code != ENOENT)) {
3829 PrintError("Could not end transaction on a ro volume: ",
3833 ("Transaction timed out on a ro volume. Will retry.\n",
3835 if (times[s].vldbEntryIndex < vldbindex)
3836 vldbindex = times[s].vldbEntryIndex;
3841 rx_DestroyConnection(toconns[s]);
3845 MapNetworkToHost(&entry, &storeEntry);
3846 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3847 ONERROR(vcode, afromvol,
3848 " Could not update VLDB entry for volume %u\n");
3849 } /* for each index in the vldb */
3851 /* End the transaction on the cloned volume */
3852 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3857 PrintError("Failed to end transaction on rw volume: ", code);
3859 /* Figure out if any volume were not released and say so */
3860 for (failure = 0, i = 0; i < entry.nServers; i++) {
3861 if (!(entry.serverFlags[i] & NEW_REPSITE))
3867 "The volume %lu could not be released to the following %d sites:\n",
3868 (unsigned long)afromvol, failure);
3869 for (i = 0; i < entry.nServers; i++) {
3870 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3871 MapPartIdIntoName(entry.serverPartition[i], pname);
3872 fprintf(STDERR, "\t%35s %s\n",
3873 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
3874 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3878 MapNetworkToHost(&entry, &storeEntry);
3880 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3882 ONERROR(vcode, afromvol,
3883 " Could not update VLDB entry for volume %u\n");
3885 ERROREXIT(VOLSERBADRELEASE);
3888 /* All the ROs were release successfully. Remove the temporary clone */
3891 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3892 (unsigned long)cloneVolId);
3895 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3896 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3901 for (i = 0; i < entry.nServers; i++)
3902 entry.serverFlags[i] &= ~NEW_REPSITE;
3904 /* Update the VLDB */
3905 VPRINT("updating VLDB ...");
3907 MapNetworkToHost(&entry, &storeEntry);
3909 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3910 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3911 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3916 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3920 "Failed to end cloning transaction on the RW volume %lu\n",
3921 (unsigned long)afromvol);
3927 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3931 "Failed to end transaction on the release clone %lu\n",
3932 (unsigned long)cloneVolId);
3937 for (i = 0; i < nservers; i++) {
3938 if (replicas && replicas[i].trans) {
3939 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3940 replicas[i].trans = 0;
3943 "Failed to end transaction on ro volume %u at server %s\n",
3944 entry.volumeId[ROVOL],
3945 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
3946 destHost), hoststr) :
3947 hostutil_GetNameByINet(htonl
3948 (replicas[i].server.destHost)));
3953 if (toconns && toconns[i]) {
3954 rx_DestroyConnection(toconns[i]);
3960 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3961 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3964 "Could not release lock on the VLDB entry for volume %lu\n",
3965 (unsigned long)afromvol);
3971 PrintError("", error);
3974 rx_DestroyConnection(fromconn);
3975 if (results.manyResults_val)
3976 free(results.manyResults_val);
3988 dump_sig_handler(int x)
3990 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3994 /* Dump the volume <afromvol> on <afromserver> and
3995 * <afrompart> to <afilename> starting from <fromdate>.
3996 * DumpFunction does the real work behind the scenes after
3997 * extracting parameters from the rock
4000 UV_DumpVolume(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
4002 afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
4005 struct rx_connection *fromconn = (struct rx_connection *)0;
4006 struct rx_call *fromcall = (struct rx_call *)0;
4007 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4008 afs_int32 code, error = 0, retry = 0;
4009 time_t tmv = fromdate;
4013 #ifndef AFS_NT40_ENV
4014 (void)signal(SIGPIPE, dump_sig_handler);
4016 (void)signal(SIGINT, dump_sig_handler);
4019 VEPRINT("Full Dump ...\n");
4021 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4025 /* get connections to the servers */
4026 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4028 VEPRINT1("Starting transaction on volume %u...", afromvol);
4029 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4030 EGOTO1(error_exit, code,
4031 "Could not start transaction on the volume %u to be dumped\n",
4035 fromcall = rx_NewCall(fromconn);
4037 VEPRINT1("Starting volume dump on volume %u...", afromvol);
4038 if (flags & VOLDUMPV2_OMITDIRS)
4039 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
4042 code = StartAFSVolDump(fromcall, fromtid, fromdate);
4043 EGOTO(error_exit, code, "Could not start the dump process \n");
4046 VEPRINT1("Dumping volume %u...", afromvol);
4047 code = DumpFunction(fromcall, rock);
4048 if (code == RXGEN_OPCODE)
4050 EGOTO(error_exit, code, "Error while dumping volume \n");
4055 code = rx_EndCall(fromcall, rxError);
4056 if (code && code != RXGEN_OPCODE)
4057 fprintf(STDERR, "Error in rx_EndCall\n");
4062 VEPRINT1("Ending transaction on volume %u...", afromvol);
4063 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4064 if (code || rcode) {
4065 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
4066 (unsigned long)afromvol);
4068 error = (code ? code : rcode);
4073 rx_DestroyConnection(fromconn);
4077 if (error != RXGEN_OPCODE)
4078 PrintError("", error);
4082 /* Clone the volume <afromvol> on <afromserver> and
4083 * <afrompart>, and then dump the clone volume to
4084 * <afilename> starting from <fromdate>.
4085 * DumpFunction does the real work behind the scenes after
4086 * extracting parameters from the rock
4089 UV_DumpClonedVolume(afs_uint32 afromvol, afs_int32 afromserver,
4090 afs_int32 afrompart, afs_int32 fromdate,
4091 afs_int32(*DumpFunction) (struct rx_call *, void *),
4092 void *rock, afs_int32 flags)
4094 struct rx_connection *fromconn = (struct rx_connection *)0;
4095 struct rx_call *fromcall = (struct rx_call *)0;
4096 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
4097 afs_int32 clonetid = 0;
4098 afs_int32 code = 0, error = 0;
4099 afs_uint32 clonevol = 0;
4101 time_t tmv = fromdate;
4105 #ifndef AFS_NT40_ENV
4106 (void)signal(SIGPIPE, dump_sig_handler);
4108 (void)signal(SIGINT, dump_sig_handler);
4111 VEPRINT("Full Dump ...\n");
4113 VEPRINT1("Incremental Dump (as of %.24s)...\n",
4117 /* get connections to the servers */
4118 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
4120 VEPRINT1("Starting transaction on volume %u...", afromvol);
4121 code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
4122 EGOTO1(error_exit, code,
4123 "Could not start transaction on the volume %u to be dumped\n",
4127 /* Get a clone id */
4128 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4129 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
4130 EGOTO1(error_exit, code,
4131 "Could not get an ID for the clone of volume %u from the VLDB\n",
4135 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4136 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4138 strcpy(vname, "dump-clone-temp");
4140 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
4141 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4145 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4147 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4151 EGOTO1(error_exit, code,
4152 "Failed to end the transaction on the volume %u\n", afromvol);
4156 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4158 AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
4160 EGOTO1(error_exit, code,
4161 "Failed to start a transaction on the cloned volume%u\n",
4165 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4166 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4167 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4172 fromcall = rx_NewCall(fromconn);
4174 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4175 if (flags & VOLDUMPV2_OMITDIRS)
4176 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4178 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4179 EGOTO(error_exit, code, "Could not start the dump process \n");
4182 VEPRINT1("Dumping volume %u...", afromvol);
4183 code = DumpFunction(fromcall, rock);
4184 EGOTO(error_exit, code, "Error while dumping volume \n");
4188 /* now delete the clone */
4189 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4190 code = AFSVolDeleteVolume(fromconn, clonetid);
4192 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4193 (unsigned long)clonevol);
4199 code = rx_EndCall(fromcall, rxError);
4201 fprintf(STDERR, "Error in rx_EndCall\n");
4207 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4208 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4209 if (code || rcode) {
4211 "Could not end transaction on the cloned volume %lu\n",
4212 (unsigned long)clonevol);
4214 error = (code ? code : rcode);
4219 rx_DestroyConnection(fromconn);
4221 PrintError("", error);
4228 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4229 * the dump file <afilename>. WriteData does all the real work
4230 * after extracting params from the rock
4233 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_uint32 tovolid,
4234 afs_int32 toparentid, char tovolname[], int flags,
4235 afs_int32(*WriteData) (struct rx_call *, void *),
4238 struct rx_connection *toconn, *tempconn;
4239 struct rx_call *tocall;
4240 afs_int32 totid, code, rcode, vcode, terror = 0;
4241 afs_int32 rxError = 0;
4242 struct volser_status tstatus;
4243 struct volintInfo vinfo;
4245 char tovolreal[VOLSER_OLDMAXVOLNAME];
4247 afs_int32 temptid, pparentid;
4249 struct nvldbentry entry, storeEntry;
4252 struct restoreCookie cookie;
4254 afs_int32 volflag, voltype, volsertype;
4255 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4256 int index, same, errcode;
4260 memset(&cookie, 0, sizeof(cookie));
4265 tocall = (struct rx_call *)0;
4266 toconn = (struct rx_connection *)0;
4267 tempconn = (struct rx_connection *)0;
4271 if (flags & RV_RDONLY) {
4273 volsertype = volser_RO;
4276 volsertype = volser_RW;
4280 pparentid = toparentid;
4281 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4282 if (pvolid == 0) { /*alot a new id if needed */
4283 vcode = VLDB_GetEntryByName(tovolname, &entry);
4284 if (vcode == VL_NOENT) {
4285 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4287 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4293 } else if (flags & RV_RDONLY) {
4294 if (entry.flags & RW_EXISTS) {
4296 "Entry for ReadWrite volume %s already exists!\n",
4298 error = VOLSERBADOP;
4301 if (!entry.volumeId[ROVOL]) {
4303 "Existing entry for volume %s has no ReadOnly ID\n",
4305 error = VOLSERBADOP;
4308 pvolid = entry.volumeId[ROVOL];
4309 pparentid = entry.volumeId[RWVOL];
4311 pvolid = entry.volumeId[RWVOL];
4312 pparentid = entry.volumeId[RWVOL];
4315 if (!pparentid) pparentid = pvolid;
4316 /* at this point we have a volume id to use/reuse for the volume to be restored */
4317 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4319 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4320 EGOTO1(refail, VOLSERBADOP,
4321 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4324 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4325 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4326 EGOTO1(refail, VOLSERBADOP,
4327 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4329 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4332 MapPartIdIntoName(topart, partName);
4333 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4334 tovolreal, (unsigned long)pvolid,
4335 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4336 hostutil_GetNameByINet(toserver), partName);
4339 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4342 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4343 VPRINT1("Deleting the previous volume %u ...", pvolid);
4346 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4347 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4350 code = AFSVolGetStatus(toconn, totid, &tstatus);
4351 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4354 oldCreateDate = tstatus.creationDate;
4355 oldUpdateDate = tstatus.updateDate;
4358 AFSVolSetFlags(toconn, totid,
4359 VTDeleteOnSalvage | VTOutOfService);
4360 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4363 code = AFSVolDeleteVolume(toconn, totid);
4364 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4366 code = AFSVolEndTrans(toconn, totid, &rcode);
4370 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4375 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4377 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4380 AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
4381 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4384 code = AFSVolGetStatus(toconn, totid, &tstatus);
4385 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4388 oldCreateDate = tstatus.creationDate;
4389 oldUpdateDate = tstatus.updateDate;
4396 cookie.parent = pparentid;
4397 cookie.type = voltype;
4399 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4401 tocall = rx_NewCall(toconn);
4402 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4404 fprintf(STDERR, "Volume restore Failed \n");
4408 code = WriteData(tocall, rock);
4410 fprintf(STDERR, "Could not transmit data\n");
4414 terror = rx_EndCall(tocall, rxError);
4415 tocall = (struct rx_call *)0;
4417 fprintf(STDERR, "rx_EndCall Failed \n");
4421 code = AFSVolGetStatus(toconn, totid, &tstatus);
4424 "Could not get status information about the volume %lu\n",
4425 (unsigned long)pvolid);
4429 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4431 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4432 (unsigned long)pvolid);
4437 if (flags & RV_CRDUMP)
4438 newCreateDate = tstatus.creationDate;
4439 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4440 newCreateDate = oldCreateDate;
4442 newCreateDate = time(0);
4443 if (flags & RV_LUDUMP)
4444 newUpdateDate = tstatus.updateDate;
4445 else if (flags & RV_LUKEEP)
4446 newUpdateDate = oldUpdateDate;
4448 newUpdateDate = time(0);
4449 code = AFSVolSetDate(toconn,totid, newCreateDate);
4451 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4456 init_volintInfo(&vinfo);
4457 vinfo.creationDate = newCreateDate;
4458 vinfo.updateDate = newUpdateDate;
4459 code = AFSVolSetInfo(toconn, totid, &vinfo);
4461 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4467 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4468 code = AFSVolSetFlags(toconn, totid, volflag);
4470 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4475 /* It isn't handled right in refail */
4476 code = AFSVolEndTrans(toconn, totid, &rcode);
4481 fprintf(STDERR, "Could not end transaction on %lu\n",
4482 (unsigned long)pvolid);
4488 fprintf(STDOUT, " done\n");
4490 if (success && (!reuseID || (flags & RV_FULLRST))) {
4491 /* Volume was restored on the file server, update the
4492 * VLDB to reflect the change.
4494 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4495 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4497 "Could not fetch the entry for volume number %lu from VLDB \n",
4498 (unsigned long)pvolid);
4503 MapHostToNetwork(&entry);
4504 if (vcode == VL_NOENT) { /* it doesnot exist already */
4505 /*make the vldb return this indication specifically */
4506 VPRINT("------- Creating a new VLDB entry ------- \n");
4507 strcpy(entry.name, tovolname);
4509 entry.serverNumber[0] = toserver; /*should be indirect */
4510 entry.serverPartition[0] = topart;
4511 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4512 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4513 if (flags & RV_RDONLY)
4514 entry.volumeId[ROVOL] = pvolid;
4515 else if (tstatus.cloneID != 0) {
4516 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4518 entry.volumeId[ROVOL] = INVALID_BID;
4519 entry.volumeId[RWVOL] = pparentid;
4521 if (tstatus.backupID != 0) {
4522 entry.volumeId[BACKVOL] = tstatus.backupID;
4523 /*this should come from status info on the volume if non zero */
4525 entry.volumeId[BACKVOL] = INVALID_BID;
4526 MapNetworkToHost(&entry, &storeEntry);
4527 vcode = VLDB_CreateEntry(&storeEntry);
4530 "Could not create the VLDB entry for volume number %lu \n",
4531 (unsigned long)pvolid);
4537 EnumerateEntry(&entry);
4538 } else { /*update the existing entry */
4540 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4541 fprintf(STDOUT, "------- Old entry -------\n");
4542 EnumerateEntry(&entry);
4543 fprintf(STDOUT, "------- New entry -------\n");
4546 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4550 "Could not lock the entry for volume number %lu \n",
4551 (unsigned long)pvolid);
4556 strcpy(entry.name, tovolname);
4558 /* Update the vlentry with the new information */
4559 if (flags & RV_RDONLY)
4560 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4562 index = Lp_GetRwIndex(&entry);
4564 /* Add the new site for the volume being restored */
4565 entry.serverNumber[entry.nServers] = toserver;
4566 entry.serverPartition[entry.nServers] = topart;
4567 entry.serverFlags[entry.nServers] =
4568 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4571 /* This volume should be deleted on the old site
4572 * if its different from new site.
4575 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4579 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4581 if ((!errcode && !same)
4582 || (entry.serverPartition[index] != topart)) {
4583 if (flags & RV_NODEL) {
4585 ("Not deleting the previous volume %u on server %s, ...",
4587 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4588 hostutil_GetNameByINet(entry.serverNumber[index]));
4591 UV_Bind(entry.serverNumber[index],
4592 AFSCONF_VOLUMEPORT);
4594 MapPartIdIntoName(entry.serverPartition[index],
4597 ("Deleting the previous volume %u on server %s, partition %s ...",
4599 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4600 hostutil_GetNameByINet(entry.serverNumber[index]),
4603 AFSVolTransCreate_retry(tempconn, pvolid,
4604 entry.serverPartition[index],
4605 ITOffline, &temptid);
4608 AFSVolSetFlags(tempconn, temptid,
4613 "Could not set flags on volume %lu on the older site\n",
4614 (unsigned long)pvolid);
4618 code = AFSVolDeleteVolume(tempconn, temptid);
4621 "Could not delete volume %lu on the older site\n",
4622 (unsigned long)pvolid);
4626 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4632 "Could not end transaction on volume %lu on the older site\n",
4633 (unsigned long)pvolid);
4638 MapPartIdIntoName(entry.serverPartition[index],
4643 entry.serverNumber[index] = toserver;
4644 entry.serverPartition[index] = topart;
4647 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4648 MapNetworkToHost(&entry, &storeEntry);
4650 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4651 LOCKREL_OPCODE | LOCKREL_AFSID |
4655 "Could not update the entry for volume number %lu \n",
4656 (unsigned long)pvolid);
4662 EnumerateEntry(&entry);
4669 code = rx_EndCall(tocall, rxError);
4675 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4676 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4679 "Could not release lock on the VLDB entry for the volume %lu\n",
4680 (unsigned long)pvolid);
4686 code = AFSVolEndTrans(toconn, totid, &rcode);
4690 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4691 (unsigned long)pvolid);
4697 code = AFSVolEndTrans(toconn, temptid, &rcode);
4701 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4702 (unsigned long)pvolid);
4708 rx_DestroyConnection(tempconn);
4710 rx_DestroyConnection(toconn);
4711 PrintError("", error);
4716 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_uint32 tovolid,
4717 char tovolname[], int flags,
4718 afs_int32(*WriteData) (struct rx_call *, void *),
4721 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4726 /*unlocks the vldb entry associated with <volid> */
4728 UV_LockRelease(afs_uint32 volid)
4732 VPRINT("Binding to the VLDB server\n");
4734 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4735 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4738 "Could not unlock the entry for volume number %lu in VLDB \n",
4739 (unsigned long)volid);
4740 PrintError("", vcode);
4743 VPRINT("VLDB updated\n");
4748 /* old interface to add rosites */
4750 UV_AddSite(afs_int32 server, afs_int32 part, afs_uint32 volid,
4753 return UV_AddSite2(server, part, volid, 0, valid);
4756 /*adds <server> and <part> as a readonly replication site for <volid>
4759 UV_AddSite2(afs_int32 server, afs_int32 part, afs_uint32 volid,
4760 afs_uint32 rovolid, afs_int32 valid)
4762 int j, nro = 0, islocked = 0;
4763 struct nvldbentry entry, storeEntry, entry2;
4764 afs_int32 vcode, error = 0;
4767 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4770 " Could not lock the VLDB entry for the volume %lu \n",
4771 (unsigned long)volid);
4776 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4779 "Could not fetch the VLDB entry for volume number %lu \n",
4780 (unsigned long)volid);
4784 if (!ISNAMEVALID(entry.name)) {
4786 "Volume name %s is too long, rename before adding site\n",
4788 error = VOLSERBADOP;
4791 MapHostToNetwork(&entry);
4793 /* See if it's too many entries */
4794 if (entry.nServers >= NMAXNSERVERS) {
4795 fprintf(STDERR, "Total number of entries will exceed %u\n",
4797 error = VOLSERBADOP;
4801 /* See if it's on the same server */
4802 for (j = 0; j < entry.nServers; j++) {
4803 if (entry.serverFlags[j] & ITSROVOL) {
4805 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4808 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4811 MapPartIdIntoName(entry.serverPartition[j], apartName);
4813 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4815 error = VOLSERBADOP;
4822 /* See if it's too many RO sites - leave one for the RW */
4823 if (nro >= NMAXNSERVERS - 1) {
4824 fprintf(STDERR, "Total number of sites will exceed %u\n",
4826 error = VOLSERBADOP;
4830 /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
4831 * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
4832 * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
4835 if (entry.volumeId[ROVOL] == INVALID_BID) {
4836 vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
4838 fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
4841 VPRINT1("Using RO volume id %d.\n", rovolid);
4842 entry.volumeId[ROVOL] = rovolid;
4844 fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
4845 rovolid, entry.volumeId[ROVOL]);
4849 VPRINT("Adding a new site ...");
4850 entry.serverNumber[entry.nServers] = server;
4851 entry.serverPartition[entry.nServers] = part;
4853 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4855 entry.serverFlags[entry.nServers] = (ITSROVOL);
4859 MapNetworkToHost(&entry, &storeEntry);
4861 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4862 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4864 fprintf(STDERR, "Could not update entry for volume %lu \n",
4865 (unsigned long)volid);
4874 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4875 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4878 "Could not release lock on volume entry for %lu \n",
4879 (unsigned long)volid);
4880 PrintError("", vcode);
4884 PrintError("", error);
4888 /*removes <server> <part> as read only site for <volid> from the vldb */
4890 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_uint32 volid)
4893 struct nvldbentry entry, storeEntry;
4896 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4898 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4899 (unsigned long)volid);
4900 PrintError("", vcode);
4904 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4907 "Could not fetch the entry for volume number %lu from VLDB \n",
4908 (unsigned long)volid);
4909 PrintError("", vcode);
4912 MapHostToNetwork(&entry);
4913 if (!Lp_ROMatch(server, part, &entry)) {
4914 /*this site doesnot exist */
4915 fprintf(STDERR, "This site is not a replication site \n");
4917 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4918 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4920 fprintf(STDERR, "Could not update entry for volume %lu \n",
4921 (unsigned long)volid);
4922 PrintError("", vcode);
4923 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4924 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4928 } else { /*remove the rep site */
4929 Lp_SetROValue(&entry, server, part, 0, 0);
4931 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4932 entry.flags &= ~RO_EXISTS;
4933 if (entry.nServers < 1) { /*this is the last ref */
4934 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4936 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4939 "Could not delete VLDB entry for volume %lu \n",
4940 (unsigned long)volid);
4941 PrintError("", vcode);
4946 MapNetworkToHost(&entry, &storeEntry);
4947 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4948 (unsigned long)volid);
4951 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4952 LOCKREL_OPCODE | LOCKREL_AFSID |
4956 "Could not release lock on volume entry for %lu \n",
4957 (unsigned long)volid);
4958 PrintError("", vcode);
4959 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4960 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4968 /*sets <server> <part> as read/write site for <volid> in the vldb */
4970 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_uint32 volid)
4973 struct nvldbentry entry, storeEntry;
4976 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4978 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4979 (unsigned long)volid);
4980 PrintError("", vcode);
4983 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4986 "Could not fetch the entry for volume number %lu from VLDB \n",
4987 (unsigned long)volid);
4988 PrintError("", vcode);
4991 MapHostToNetwork(&entry);
4992 index = Lp_GetRwIndex(&entry);
4994 /* no RW site exists */
4995 fprintf(STDERR, "No existing RW site for volume %lu",
4996 (unsigned long)volid);
4998 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4999 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5002 "Could not release lock on entry for volume %lu \n",
5003 (unsigned long)volid);
5004 PrintError("", vcode);
5008 } else { /* change the RW site */
5009 entry.serverNumber[index] = server;
5010 entry.serverPartition[index] = part;
5011 MapNetworkToHost(&entry, &storeEntry);
5013 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
5014 LOCKREL_OPCODE | LOCKREL_AFSID |
5017 fprintf(STDERR, "Could not update entry for volume %lu \n",
5018 (unsigned long)volid);
5019 PrintError("", vcode);
5020 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
5021 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5029 /*list all the partitions on <aserver> */
5031 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
5034 struct rx_connection *aconn;
5035 struct pIDs partIds;
5036 struct partEntries partEnts;
5037 register int i, j = 0, code;
5040 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5042 partEnts.partEntries_len = 0;
5043 partEnts.partEntries_val = NULL;
5044 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
5045 if (code == RXGEN_OPCODE) {
5046 for (i = 0; i < 26; i++) /* try old interface */
5047 partIds.partIds[i] = -1;
5048 code = AFSVolListPartitions(aconn, &partIds);
5050 for (i = 0; i < 26; i++) {
5051 if ((partIds.partIds[i]) != -1) {
5052 ptrPartList->partId[j] = partIds.partIds[i];
5053 ptrPartList->partFlags[j] = PARTVALID;
5056 ptrPartList->partFlags[i] = 0;
5061 *cntp = partEnts.partEntries_len;
5062 if (*cntp > VOLMAXPARTS) {
5064 "Warning: number of partitions on the server too high %d (process only %d)\n",
5065 *cntp, VOLMAXPARTS);
5066 *cntp = VOLMAXPARTS;
5068 for (i = 0; i < *cntp; i++) {
5069 ptrPartList->partId[i] = partEnts.partEntries_val[i];
5070 ptrPartList->partFlags[i] = PARTVALID;
5072 free(partEnts.partEntries_val);
5078 "Could not fetch the list of partitions from the server\n");
5079 PrintError("", code);
5081 rx_DestroyConnection(aconn);
5086 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
5087 This is used by the backup system */
5089 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
5090 struct volDescription *volPtr, afs_int32 arraySize)
5092 struct rx_connection *aconn;
5093 struct volDescription *curPtr;
5096 afs_int32 rcode = 0;
5097 afs_int32 success = 1;
5100 aconn = (struct rx_connection *)0;
5101 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5103 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5104 if (curPtr->volFlags & CLONEVALID) {
5105 curPtr->volFlags &= ~CLONEZAPPED;
5108 AFSVolTransCreate_retry(aconn, curPtr->volCloneId, apart, ITOffline,
5113 code = AFSVolDeleteVolume(aconn, tid);
5116 code = AFSVolEndTrans(aconn, tid, &rcode);
5121 curPtr->volFlags |= CLONEZAPPED;
5123 fprintf(STDERR, "Could not zap volume %lu\n",
5124 (unsigned long)curPtr->volCloneId);
5126 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
5127 curPtr->volCloneId);
5133 rx_DestroyConnection(aconn);
5137 /*return a list of clones of the volumes specified by volPtrArray. Used by the
5140 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
5141 struct volDescription *volPtr, afs_int32 arraySize)
5143 struct rx_connection *aconn;
5144 struct volDescription *curPtr;
5147 afs_int32 rcode = 0;
5149 int reuseCloneId = 0;
5150 afs_uint32 curCloneId = 0;
5151 char cloneName[256]; /*max vol name */
5153 aconn = (struct rx_connection *)0;
5154 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5156 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5158 else { /*get a bunch of id's from vldb */
5160 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5162 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5163 PrintError("", code);
5168 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5169 if (curPtr->volFlags & ENTRYVALID) {
5171 curPtr->volFlags |= CLONEVALID;
5172 /*make a clone of curParentId and record as curPtr->volCloneId */
5174 AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
5177 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5180 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5184 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5185 strcpy(cloneName, curPtr->volName);
5186 strcat(cloneName, "-tmpClone-");
5188 strcpy(cloneName, "-tmpClone");
5190 curPtr->volCloneId = curCloneId;
5195 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5196 &(curPtr->volCloneId));
5198 curPtr->volFlags &= ~CLONEVALID;
5200 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5201 curPtr->volName, (unsigned long)code);
5202 code = AFSVolEndTrans(aconn, tid, &rcode);
5204 fprintf(STDERR, "WARNING: could not end transaction\n");
5207 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5208 curPtr->volCloneId);
5209 code = AFSVolEndTrans(aconn, tid, &rcode);
5210 if (code || rcode) {
5211 curPtr->volFlags &= ~CLONEVALID;
5220 rx_DestroyConnection(aconn);
5225 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5226 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5228 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5229 struct volintInfo **resultPtr, afs_int32 * size)
5231 struct rx_connection *aconn;
5233 volEntries volumeInfo;
5237 *resultPtr = (volintInfo *) 0;
5238 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5239 volumeInfo.volEntries_len = 0;
5241 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5242 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5245 "Could not fetch the list of volumes from the server\n");
5247 *resultPtr = volumeInfo.volEntries_val;
5248 *size = volumeInfo.volEntries_len;
5252 rx_DestroyConnection(aconn);
5253 PrintError("", code);
5257 /*------------------------------------------------------------------------
5258 * EXPORTED UV_XListVolumes
5261 * List the extended information for all the volumes on a particular
5262 * File Server and partition. We may either return the volume's ID
5263 * or all of its extended information.
5266 * a_serverID : Address of the File Server for which we want
5267 * extended volume info.
5268 * a_partID : Partition for which we want the extended
5270 * a_all : If non-zero, fetch ALL the volume info,
5271 * otherwise just the volume ID.
5272 * a_resultPP : Ptr to the address of the area containing
5273 * the returned volume info.
5274 * a_numEntsInResultP : Ptr for the value we set for the number of
5279 * Otherise, the return value of AFSVolXListVolumes.
5282 * This routine is closely related to UV_ListVolumes, which returns
5283 * only the standard level of detail on AFS volumes. It is a
5284 * heavyweight operation, zipping through all the volume entries for
5285 * a given server/partition.
5289 *------------------------------------------------------------------------*/
5292 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5293 struct volintXInfo **a_resultPP,
5294 afs_int32 * a_numEntsInResultP)
5296 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5297 afs_int32 code; /*Error code to return */
5298 volXEntries volumeXInfo; /*Area for returned extended vol info */
5301 * Set up our error code and the area for returned extended volume info.
5302 * We set the val field to a null pointer as a hint for the stub to
5306 *a_numEntsInResultP = 0;
5307 *a_resultPP = (volintXInfo *) 0;
5308 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5309 volumeXInfo.volXEntries_len = 0;
5312 * Bind to the Volume Server port on the File Server machine in question,
5315 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5316 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5318 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5321 * We got the info; pull out the pointer to where the results lie
5322 * and how many entries are there.
5324 *a_resultPP = volumeXInfo.volXEntries_val;
5325 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5329 * If we got an Rx connection, throw it away.
5332 rx_DestroyConnection(rxConnP);
5334 PrintError("", code);
5336 } /*UV_XListVolumes */
5338 /* get all the information about volume <volid> on <aserver> and <apart> */
5340 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_uint32 volid,
5341 struct volintInfo **resultPtr)
5343 struct rx_connection *aconn;
5345 volEntries volumeInfo;
5349 *resultPtr = (volintInfo *) 0;
5350 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5351 volumeInfo.volEntries_len = 0;
5353 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5354 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5357 "Could not fetch the information about volume %lu from the server\n",
5358 (unsigned long)volid);
5360 *resultPtr = volumeInfo.volEntries_val;
5365 rx_DestroyConnection(aconn);
5366 PrintError("", code);
5370 /*------------------------------------------------------------------------
5371 * EXPORTED UV_XListOneVolume
5374 * List the extended information for a volume on a particular File
5375 * Server and partition.
5378 * a_serverID : Address of the File Server for which we want
5379 * extended volume info.
5380 * a_partID : Partition for which we want the extended
5382 * a_volID : Volume ID for which we want the info.
5383 * a_resultPP : Ptr to the address of the area containing
5384 * the returned volume info.
5388 * Otherise, the return value of AFSVolXListOneVolume.
5391 * This routine is closely related to UV_ListOneVolume, which returns
5392 * only the standard level of detail on the chosen AFS volume.
5396 *------------------------------------------------------------------------*/
5399 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
5400 struct volintXInfo **a_resultPP)
5402 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5403 afs_int32 code; /*Error code */
5404 volXEntries volumeXInfo; /*Area for returned info */
5407 * Set up our error code, and the area we're in which we are returning
5408 * the info. Setting the val field to a null pointer tells the stub
5409 * to allocate space for us.
5412 *a_resultPP = (volintXInfo *) 0;
5413 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5414 volumeXInfo.volXEntries_len = 0;
5417 * Bind to the Volume Server port on the File Server machine in question,
5420 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5421 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5424 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5427 * We got the info; pull out the pointer to where the results lie.
5429 *a_resultPP = volumeXInfo.volXEntries_val;
5432 * If we got an Rx connection, throw it away.
5435 rx_DestroyConnection(rxConnP);
5437 PrintError("", code);
5442 * Given a volume we read from a partition, check if it is
5443 * represented in the VLDB correctly.
5445 * The VLDB is looked up by the RW volume id (not its name).
5446 * The RW contains the true name of the volume (BK and RO set
5447 * the name in the VLDB only on creation of the VLDB entry).
5448 * We want rules strict enough that when we check all volumes
5449 * on one partition, it does not need to be done again. IE:
5450 * two volumes on different partitions won't constantly
5451 * change a VLDB entry away from what the other set.
5452 * For RW and BK volumes, we will always check the VLDB to see
5453 * if the two exist on the server/partition. May seem redundant,
5454 * but this is an easy check of the VLDB. IE: if the VLDB entry
5455 * says the BK exists but no BK volume is there, we will detect
5456 * this when we check the RW volume.
5457 * VLDB entries are locked only when a change needs to be done.
5458 * Output changed to look a lot like the "vos syncserv" otuput.
5461 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5462 afs_int32 * modentry, afs_uint32 * maxvolid)
5466 afs_int32 code, error = 0;
5467 struct nvldbentry entry, storeEntry;
5469 int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
5479 ((volumeinfo->type ==
5480 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5483 /* Check to see if the VLDB is ok without locking it (pass 1).
5484 * If it will change, then lock the VLDB entry, read it again,
5485 * then make the changes to it (pass 2).
5488 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5490 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5491 (unsigned long)rwvolid);
5497 createentry = 0; /* Do we need to create a VLDB entry */
5498 addvolume = 0; /* Add this volume to the VLDB entry */
5499 modified = 0; /* The VLDB entry was modified */
5501 /* Read the entry from VLDB by its RW volume id */
5502 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5504 if (code != VL_NOENT) {
5506 "Could not retreive the VLDB entry for volume %lu \n",
5507 (unsigned long)rwvolid);
5511 memset(&entry, 0, sizeof(entry));
5512 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5516 MapHostToNetwork(&entry);
5519 if (verbose && (pass == 1)) {
5520 fprintf(STDOUT, "_______________________________\n");
5521 fprintf(STDOUT, "\n-- status before -- \n");
5523 fprintf(STDOUT, "\n**does not exist**\n");
5525 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5526 || (entry.flags & BACK_EXISTS))
5527 EnumerateEntry(&entry);
5529 fprintf(STDOUT, "\n");
5532 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5538 /* Check existence of RW and BK volumes */
5539 code = CheckVldbRWBK(&entry, &mod);
5545 idx = Lp_GetRwIndex(&entry);
5546 if (idx == -1) { /* RW index not found in the VLDB entry */
5547 idx = entry.nServers; /* put it into next index */
5550 } else { /* RW index found in the VLDB entry. */
5551 /* Verify if this volume's location matches where the VLDB says it is */
5552 if (!Lp_Match(aserver, apart, &entry)) {
5553 if (entry.flags & RW_EXISTS) {
5554 /* The RW volume exists elsewhere - report this one a duplicate */
5556 MapPartIdIntoName(apart, pname);
5558 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5559 (unsigned long)rwvolid,
5561 afs_inet_ntoa_r(aserver, hoststr) :
5562 hostutil_GetNameByINet(aserver), pname);
5563 MapPartIdIntoName(entry.serverPartition[idx],
5566 " VLDB reports RW volume %lu exists on %s %s\n",
5567 (unsigned long)rwvolid,
5569 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5570 hostutil_GetNameByINet(entry.
5575 /* The RW volume does not exist - have VLDB point to this one */
5578 /* Check for orphaned BK volume on old partition */
5579 if (entry.flags & BACK_EXISTS) {
5581 MapPartIdIntoName(entry.serverPartition[idx],
5584 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5585 entry.volumeId[BACKVOL],
5587 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5588 hostutil_GetNameByINet(entry.
5591 MapPartIdIntoName(apart, pname);
5593 " VLDB reports its RW volume %lu exists on %s %s\n",
5594 (unsigned long)rwvolid,
5596 afs_inet_ntoa_r(aserver, hoststr) :
5597 hostutil_GetNameByINet(aserver),
5603 /* Volume location matches the VLDB location */
5604 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5605 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5608 (entry.name, volumeinfo->name,
5609 VOLSER_OLDMAXVOLNAME) != 0)) {
5617 entry.flags |= RW_EXISTS;
5618 entry.volumeId[RWVOL] = rwvolid;
5619 if (!entry.volumeId[BACKVOL])
5620 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5621 if (!entry.volumeId[ROVOL])
5622 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5624 entry.serverFlags[idx] = ITSRWVOL;
5625 entry.serverNumber[idx] = aserver;
5626 entry.serverPartition[idx] = apart;
5627 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5631 /* One last check - to update BK if need to */
5632 code = CheckVldbRWBK(&entry, &mod);
5640 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5646 /* Check existence of RW and BK volumes */
5647 code = CheckVldbRWBK(&entry, &mod);
5653 idx = Lp_GetRwIndex(&entry);
5654 if (idx == -1) { /* RW index not found in the VLDB entry */
5655 idx = entry.nServers; /* Put it into next index */
5658 } else { /* RW index found in the VLDB entry */
5659 /* Verify if this volume's location matches where the VLDB says it is */
5660 if (!Lp_Match(aserver, apart, &entry)) {
5661 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5663 MapPartIdIntoName(apart, pname);
5665 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5666 (unsigned long)volumeinfo->volid,
5668 afs_inet_ntoa_r(aserver, hoststr) :
5669 hostutil_GetNameByINet(aserver), pname);
5670 MapPartIdIntoName(entry.serverPartition[idx], pname);
5672 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5673 (unsigned long)rwvolid,
5675 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5676 hostutil_GetNameByINet(entry.
5681 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5682 if (!(entry.flags & BACK_EXISTS)) {
5684 } else if (volumeinfo->volid >
5685 entry.volumeId[BACKVOL]) {
5689 MapPartIdIntoName(entry.serverPartition[idx],
5692 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5693 entry.volumeId[BACKVOL],
5695 afs_inet_ntoa_r(aserver, hoststr) :
5696 hostutil_GetNameByINet(aserver),
5699 " VLDB reports its BK volume ID is %lu\n",
5700 (unsigned long)volumeinfo->volid);
5704 MapPartIdIntoName(entry.serverPartition[idx],
5707 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5708 (unsigned long)volumeinfo->volid,
5710 afs_inet_ntoa_r(aserver, hoststr) :
5711 hostutil_GetNameByINet(aserver),
5714 " VLDB reports its BK volume ID is %u\n",
5715 entry.volumeId[BACKVOL]);
5718 } else if (!entry.volumeId[BACKVOL]) {
5725 entry.flags |= BACK_EXISTS;
5726 entry.volumeId[RWVOL] = rwvolid;
5727 entry.volumeId[BACKVOL] = volumeinfo->volid;
5729 entry.serverNumber[idx] = aserver;
5730 entry.serverPartition[idx] = apart;
5731 entry.serverFlags[idx] = ITSBACKVOL;
5737 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5738 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5739 /* This is a quick check to see if the RO entry exists in the
5740 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5741 * RO volume listed in the VLDB exists).
5743 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5745 idx = entry.nServers;
5749 if (!(entry.flags & RO_EXISTS)) {
5754 /* Before we correct the VLDB entry, make sure all the
5755 * ROs listed in the VLDB exist.
5757 code = CheckVldbRO(&entry, &mod);
5763 if (!(entry.flags & RO_EXISTS)) {
5764 /* No RO exists in the VLDB entry - add this one */
5765 idx = entry.nServers;
5768 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5769 /* The volume headers's RO ID does not match that in the VLDB entry,
5770 * and the vol hdr's ID is greater (implies more recent). So delete
5771 * all the RO volumes listed in VLDB entry and add this volume.
5773 for (j = 0; j < entry.nServers; j++) {
5774 if (entry.serverFlags[j] & ITSROVOL) {
5775 /* Verify this volume exists and print message we are orphaning it */
5777 MapPartIdIntoName(apart, pname);
5779 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5780 entry.volumeId[ROVOL],
5782 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5783 hostutil_GetNameByINet(entry.
5787 " VLDB reports its RO volume ID is %lu\n",
5788 (unsigned long)volumeinfo->volid);
5791 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5792 entry.serverPartition[idx], 0L, 0L);
5799 idx = entry.nServers;
5802 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5803 /* The volume headers's RO ID does not match that in the VLDB entry,
5804 * and the vol hdr's ID is lower (implies its older). So orphan it.
5807 MapPartIdIntoName(apart, pname);
5809 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5810 (unsigned long)volumeinfo->volid,
5812 afs_inet_ntoa_r(aserver, hoststr) :
5813 hostutil_GetNameByINet(aserver), pname);
5815 " VLDB reports its RO volume ID is %u\n",
5816 entry.volumeId[ROVOL]);
5819 /* The RO volume ID in the volume header match that in the VLDB entry,
5820 * and there exist RO volumes in the VLDB entry. See if any of them
5821 * are this one. If not, then we add it.
5823 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5825 idx = entry.nServers;
5833 entry.flags |= RO_EXISTS;
5834 entry.volumeId[RWVOL] = rwvolid;
5835 entry.volumeId[ROVOL] = volumeinfo->volid;
5837 entry.serverNumber[idx] = aserver;
5838 entry.serverPartition[idx] = apart;
5839 entry.serverFlags[idx] = ITSROVOL;
5845 /* Remember largest volume id */
5846 if (entry.volumeId[ROVOL] > *maxvolid)
5847 *maxvolid = entry.volumeId[ROVOL];
5848 if (entry.volumeId[BACKVOL] > *maxvolid)
5849 *maxvolid = entry.volumeId[BACKVOL];
5850 if (entry.volumeId[RWVOL] > *maxvolid)
5851 *maxvolid = entry.volumeId[RWVOL];
5853 if (modified && doit) {
5854 MapNetworkToHost(&entry, &storeEntry);
5857 code = VLDB_CreateEntry(&storeEntry);
5860 "Could not create a VLDB entry for the volume %lu\n",
5861 (unsigned long)rwvolid);
5868 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5869 LOCKREL_OPCODE | LOCKREL_AFSID |
5872 fprintf(STDERR, "Could not update entry for %lu\n",
5873 (unsigned long)rwvolid);
5878 *modentry = modified;
5879 } else if (pass == 2) {
5881 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5882 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5884 PrintError("Could not unlock VLDB entry ", code);
5888 if (verbose && doit) {
5889 fprintf(STDOUT, "-- status after --\n");
5891 EnumerateEntry(&entry);
5893 fprintf(STDOUT, "\n**no change**\n");
5897 VPRINT("\n_______________________________\n");
5902 sortVolumes(const void *a, const void *b)
5904 volintInfo *v1 = (volintInfo *) a;
5905 volintInfo *v2 = (volintInfo *) b;
5906 afs_uint32 rwvolid1, rwvolid2;
5908 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5909 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5911 if (rwvolid1 > rwvolid2)
5912 return -1; /* lower RW id goes first */
5913 if (rwvolid1 < rwvolid2)
5916 if (v1->type == RWVOL)
5917 return -1; /* RW vols go first */
5918 if (v2->type == RWVOL)
5921 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5922 return -1; /* BK vols next */
5923 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5926 if (v1->volid < v2->volid)
5927 return 1; /* larger volids first */
5928 if (v1->volid > v2->volid)
5934 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5935 * Synchronize an individual volume against a sever and partition.
5936 * Checks the VLDB entry (similar to syncserv) as well as checks
5937 * if the volume exists on specified servers (similar to syncvldb).
5940 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5942 struct rx_connection *aconn = 0;
5943 afs_int32 j, k, code, vcode, error = 0;
5945 afs_int32 mod, modified = 0;
5946 struct nvldbentry vldbentry;
5947 afs_uint32 volumeid = 0;
5948 volEntries volumeInfo;
5949 struct partList PartList;
5951 afs_uint32 maxvolid = 0;
5953 volumeInfo.volEntries_val = (volintInfo *) 0;
5954 volumeInfo.volEntries_len = 0;
5956 /* Turn verbose logging off and do our own verbose logging */
5957 /* tverbose must be set before we call ERROR_EXIT() */
5964 if (!aserver && (flags & 1)) {
5965 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5969 /* Read the VLDB entry */
5970 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5971 if (vcode && (vcode != VL_NOENT)) {
5972 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5975 } else if (!vcode) {
5976 MapHostToNetwork(&vldbentry);
5980 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5981 fprintf(STDOUT, "_______________________________\n");
5982 fprintf(STDOUT, "\n-- status before -- \n");
5984 fprintf(STDOUT, "\n**does not exist**\n");
5986 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5987 || (vldbentry.flags & BACK_EXISTS))
5988 EnumerateEntry(&vldbentry);
5990 fprintf(STDOUT, "\n");
5993 /* Verify that all of the VLDB entries exist on the repective servers
5994 * and partitions (this does not require that avolname be a volume ID).
5995 * Equivalent to a syncserv.
5998 /* Tell CheckVldb not to update if appropriate */
6003 code = CheckVldb(&vldbentry, &mod);
6005 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
6013 /* If aserver is given, we will search for the desired volume on it */
6015 /* Generate array of partitions on the server that we will check */
6017 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6020 "Could not fetch the list of partitions from the server\n");
6024 PartList.partId[0] = apart;
6028 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6030 /* If a volume ID were given, search for it on each partition */
6031 if ((volumeid = atol(avolname))) {
6032 for (j = 0; j < pcnt; j++) {
6034 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
6037 if (code != ENODEV) {
6038 fprintf(STDERR, "Could not query server\n");
6046 /* Found one, sync it with VLDB entry */
6048 CheckVolume(volumeInfo.volEntries_val, aserver,
6049 PartList.partId[j], &mod, &maxvolid);
6056 if (volumeInfo.volEntries_val)
6057 free(volumeInfo.volEntries_val);
6058 volumeInfo.volEntries_val = (volintInfo *) 0;
6059 volumeInfo.volEntries_len = 0;
6063 /* Check to see if the RW, BK, and RO IDs exist on any
6064 * partitions. We get the volume IDs from the VLDB.
6066 rv = 1; /* Read the VLDB entry ? */
6067 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
6069 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
6071 if (vcode == VL_NOENT)
6074 "Could not access the VLDB for volume %s\n",
6081 if (vldbentry.volumeId[j] == 0)
6084 for (k = 0; k < pcnt; k++) { /* For each partition */
6085 volumeInfo.volEntries_val = (volintInfo *) 0;
6086 volumeInfo.volEntries_len = 0;
6088 AFSVolListOneVolume(aconn, PartList.partId[k],
6089 vldbentry.volumeId[j], &volumeInfo);
6091 if (code != ENODEV) {
6092 fprintf(STDERR, "Could not query server\n");
6100 /* Found one, sync it with VLDB entry */
6102 CheckVolume(volumeInfo.volEntries_val, aserver,
6103 PartList.partId[k], &mod, &maxvolid);
6110 if (volumeInfo.volEntries_val)
6111 free(volumeInfo.volEntries_val);
6112 volumeInfo.volEntries_val = (volintInfo *) 0;
6113 volumeInfo.volEntries_len = 0;
6119 /* If verbose output, print a summary of what changed */
6120 if (tverbose && !(flags & 2)) {
6121 fprintf(STDOUT, "-- status after --\n");
6122 code = VLDB_GetEntryByName(avolname, &vldbentry);
6123 if (code && (code != VL_NOENT)) {
6124 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
6128 if (modified && (code == VL_NOENT)) {
6129 fprintf(STDOUT, "\n**entry deleted**\n");
6130 } else if (modified) {
6131 EnumerateEntry(&vldbentry);
6133 fprintf(STDOUT, "\n**no change**\n");
6135 fprintf(STDOUT, "\n_______________________________\n");
6139 /* Now check if the maxvolid is larger than that stored in the VLDB */
6141 afs_uint32 maxvldbid = 0;
6142 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6145 "Could not get the highest allocated volume id from the VLDB\n");
6148 } else if (maxvolid > maxvldbid) {
6150 id = maxvolid - maxvldbid + 1;
6151 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6154 "Error in increasing highest allocated volume id in VLDB\n");
6164 fprintf(STDOUT, "...error encountered");
6166 fprintf(STDOUT, "...done entry\n");
6169 rx_DestroyConnection(aconn);
6170 if (volumeInfo.volEntries_val)
6171 free(volumeInfo.volEntries_val);
6173 PrintError("", error);
6178 * Synchronise vldb with the file server <aserver> and,
6179 * optionally, <apart>.
6182 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
6184 struct rx_connection *aconn;
6185 afs_int32 code, error = 0;
6188 volEntries volumeInfo;
6189 struct partList PartList;
6193 afs_int32 failures = 0, modifications = 0, tentries = 0;
6195 afs_uint32 maxvolid = 0;
6198 volumeInfo.volEntries_val = (volintInfo *) 0;
6199 volumeInfo.volEntries_len = 0;
6201 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6203 /* Generate array of partitions to check */
6205 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6208 "Could not fetch the list of partitions from the server\n");
6212 PartList.partId[0] = apart;
6216 VPRINT("Processing volume entries ...\n");
6218 /* Step through the array of partitions */
6219 for (i = 0; i < pcnt; i++) {
6220 apart = PartList.partId[i];
6221 MapPartIdIntoName(apart, pname);
6223 volumeInfo.volEntries_val = (volintInfo *) 0;
6224 volumeInfo.volEntries_len = 0;
6225 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6228 "Could not fetch the list of volumes from the server\n");
6232 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6233 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6234 sizeof(volintInfo), sortVolumes);
6237 for (vi = volumeInfo.volEntries_val, j = 0;
6238 j < volumeInfo.volEntries_len; j++, vi++) {
6246 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6247 j + 1, vi->name, (unsigned long)vi->volid,
6249 afs_inet_ntoa_r(aserver, hoststr) :
6250 hostutil_GetNameByINet(aserver), pname);
6258 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
6260 PrintError("", code);
6263 } else if (modified) {
6269 fprintf(STDOUT, "...error encountered\n\n");
6271 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6278 "Could not process entries on server %s partition %s\n",
6280 afs_inet_ntoa_r(aserver, hoststr) :
6281 hostutil_GetNameByINet(aserver), pname);
6283 if (volumeInfo.volEntries_val) {
6284 free(volumeInfo.volEntries_val);
6285 volumeInfo.volEntries_val = 0;
6288 } /* thru all partitions */
6291 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6292 tentries, failures, modifications);
6294 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6295 tentries, failures, modifications);
6299 /* Now check if the maxvolid is larger than that stored in the VLDB */
6301 afs_uint32 maxvldbid = 0;
6302 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6305 "Could not get the highest allocated volume id from the VLDB\n");
6308 } else if (maxvolid > maxvldbid) {
6310 id = maxvolid - maxvldbid + 1;
6311 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6314 "Error in increasing highest allocated volume id in VLDB\n");
6322 rx_DestroyConnection(aconn);
6323 if (volumeInfo.volEntries_val)
6324 free(volumeInfo.volEntries_val);
6325 PrintError("", error);
6330 * Determine if a volume exists on a server and partition.
6331 * Try creating a transaction on the volume. If we can,
6332 * the volume exists, if not, then return the error code.
6333 * Some error codes mean the volume is unavailable but
6334 * still exists - so we catch these error codes.
6337 VolumeExists(afs_int32 server, afs_int32 partition, afs_uint32 volumeid)
6339 struct rx_connection *conn = (struct rx_connection *)0;
6340 afs_int32 code = -1;
6341 volEntries volumeInfo;
6343 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6345 volumeInfo.volEntries_val = (volintInfo *) 0;
6346 volumeInfo.volEntries_len = 0;
6347 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6348 if (volumeInfo.volEntries_val)
6349 free(volumeInfo.volEntries_val);
6350 if (code == VOLSERILLEGAL_PARTITION)
6352 rx_DestroyConnection(conn);
6361 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6365 afs_int32 code, error = 0;
6371 idx = Lp_GetRwIndex(entry);
6373 /* Check to see if the RW volume exists and set the RW_EXISTS
6376 if (idx == -1) { /* Did not find a RW entry */
6377 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6378 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6383 VolumeExists(entry->serverNumber[idx],
6384 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6385 if (code == 0) { /* RW volume exists */
6386 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6387 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6390 } else if (code == ENODEV) { /* RW volume does not exist */
6391 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6392 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6396 /* If VLDB says it didn't exist, then ignore error */
6397 if (entry->flags & RW_EXISTS) {
6398 MapPartIdIntoName(entry->serverPartition[idx], pname);
6400 "Transaction call failed for RW volume %u on server %s %s\n",
6401 entry->volumeId[RWVOL],
6403 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6404 hostutil_GetNameByINet(entry->serverNumber[idx]),
6411 /* Check to see if the BK volume exists and set the BACK_EXISTS
6412 * flag accordingly. idx already ponts to the RW entry.
6414 if (idx == -1) { /* Did not find a RW entry */
6415 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6416 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6419 } else { /* Found a RW entry */
6421 VolumeExists(entry->serverNumber[idx],
6422 entry->serverPartition[idx],
6423 entry->volumeId[BACKVOL]);
6424 if (code == 0) { /* BK volume exists */
6425 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6426 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6429 } else if (code == ENODEV) { /* BK volume does not exist */
6430 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6431 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6435 /* If VLDB says it didn't exist, then ignore error */
6436 if (entry->flags & BACK_EXISTS) {
6437 MapPartIdIntoName(entry->serverPartition[idx], pname);
6439 "Transaction call failed for BK volume %u on server %s %s\n",
6440 entry->volumeId[BACKVOL],
6442 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6443 hostutil_GetNameByINet(entry->serverNumber[idx]),
6450 /* If there is an idx but the BK and RW volumes no
6451 * longer exist, then remove the RW entry.
6453 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6454 && !(entry->flags & BACK_EXISTS)) {
6455 Lp_SetRWValue(entry, entry->serverNumber[idx],
6456 entry->serverPartition[idx], 0L, 0L);
6463 *modified = modentry;
6468 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6471 int foundro = 0, modentry = 0;
6472 afs_int32 code, error = 0;
6479 /* Check to see if the RO volumes exist and set the RO_EXISTS
6482 for (idx = 0; idx < entry->nServers; idx++) {
6483 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6484 continue; /* not a RO */
6488 VolumeExists(entry->serverNumber[idx],
6489 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6490 if (code == 0) { /* RO volume exists */
6492 } else if (code == ENODEV) { /* RW volume does not exist */
6493 Lp_SetROValue(entry, entry->serverNumber[idx],
6494 entry->serverPartition[idx], 0L, 0L);
6499 MapPartIdIntoName(entry->serverPartition[idx], pname);
6501 "Transaction call failed for RO %u on server %s %s\n",
6502 entry->volumeId[ROVOL],
6504 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6505 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6510 if (foundro) { /* A RO volume exists */
6511 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6512 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6515 } else { /* A RO volume does not exist */
6516 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6517 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6524 *modified = modentry;
6529 * Ensure that <entry> matches with the info on file servers
6532 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6534 afs_int32 code, error = 0;
6535 struct nvldbentry storeEntry;
6536 int islocked = 0, mod, modentry, delentry = 0;
6537 int pass = 0, doit=1;
6545 fprintf(STDOUT, "_______________________________\n");
6546 fprintf(STDOUT, "\n-- status before -- \n");
6547 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6548 || (entry->flags & BACK_EXISTS))
6549 EnumerateEntry(entry);
6550 fprintf(STDOUT, "\n");
6553 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6554 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6555 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6559 /* Check to see if the VLDB is ok without locking it (pass 1).
6560 * If it will change, then lock the VLDB entry, read it again,
6561 * then make the changes to it (pass 2).
6565 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6568 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6569 entry->volumeId[RWVOL]);
6574 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6576 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6580 MapHostToNetwork(entry);
6586 /* Check if the RW and BK entries are ok */
6587 code = CheckVldbRWBK(entry, &mod);
6590 if (mod && (pass == 1) && doit)
6595 /* Check if the RO volumes entries are ok */
6596 code = CheckVldbRO(entry, &mod);
6599 if (mod && (pass == 1) && doit)
6604 /* The VLDB entry has been updated. If it as been modified, then
6605 * write the entry back out the the VLDB.
6607 if (modentry && doit) {
6611 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6612 && !(entry->flags & RO_EXISTS) && doit) {
6613 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6615 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6619 "Could not delete VLDB entry for volume %u \n",
6620 entry->volumeId[RWVOL]);
6625 /* Replace old entry with our new one */
6626 MapNetworkToHost(entry, &storeEntry);
6628 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6629 (LOCKREL_OPCODE | LOCKREL_AFSID |
6630 LOCKREL_TIMESTAMP));
6632 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6633 entry->volumeId[RWVOL]);
6642 if (verbose && doit) {
6643 fprintf(STDOUT, "-- status after --\n");
6645 fprintf(STDOUT, "\n**entry deleted**\n");
6647 EnumerateEntry(entry);
6649 fprintf(STDOUT, "\n**no change**\n");
6653 VPRINT("\n_______________________________\n");
6657 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6659 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6662 "Could not release lock on VLDB entry for volume %u\n",
6663 entry->volumeId[RWVOL]);
6672 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6675 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6677 struct rx_connection *aconn;
6678 afs_int32 code, error = 0;
6679 afs_int32 nentries, tentries = 0;
6680 struct VldbListByAttributes attributes;
6681 nbulkentries arrayEntries;
6682 afs_int32 failures = 0, modified, modifications = 0;
6683 struct nvldbentry *vlentry;
6684 afs_int32 si, nsi, j;
6689 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6691 /* Set up attributes to search VLDB */
6692 attributes.server = ntohl(aserver);
6693 attributes.Mask = VLLIST_SERVER;
6695 attributes.partition = apart;
6696 attributes.Mask |= VLLIST_PARTITION;
6699 VPRINT("Processing VLDB entries ...\n");
6701 /* While we need to collect more VLDB entries */
6702 for (si = 0; si != -1; si = nsi) {
6703 memset(&arrayEntries, 0, sizeof(arrayEntries));
6705 /* Collect set of VLDB entries */
6707 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6708 &arrayEntries, &nsi);
6709 if (code == RXGEN_OPCODE) {
6710 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6714 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6717 tentries += nentries;
6719 for (j = 0; j < nentries; j++) {
6720 vlentry = &arrayEntries.nbulkentries_val[j];
6721 MapHostToNetwork(vlentry);
6723 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6725 /* Tell CheckVldb not to update if appropriate */
6730 code = CheckVldb(vlentry, &modified);
6732 PrintError("", code);
6734 "Could not process VLDB entry for volume %s\n",
6737 } else if (modified) {
6743 fprintf(STDOUT, "...error encountered\n\n");
6745 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6750 if (arrayEntries.nbulkentries_val) {
6751 free(arrayEntries.nbulkentries_val);
6752 arrayEntries.nbulkentries_val = 0;
6757 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6758 tentries, failures, modifications);
6760 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6761 tentries, failures, modifications);
6766 rx_DestroyConnection(aconn);
6767 if (arrayEntries.nbulkentries_val)
6768 free(arrayEntries.nbulkentries_val);
6771 error = VOLSERFAILEDOP;
6775 /*rename volume <oldname> to <newname>, changing the names of the related
6776 *readonly and backup volumes. This operation is also idempotent.
6777 *salvager is capable of recovering from rename operation stopping halfway.
6778 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6780 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6782 struct nvldbentry storeEntry;
6783 afs_int32 vcode, code, rcode, error;
6785 char nameBuffer[256];
6787 struct rx_connection *aconn;
6792 aconn = (struct rx_connection *)0;
6796 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6799 " Could not lock the VLDB entry for the volume %u \n",
6800 entry->volumeId[RWVOL]);
6805 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6806 MapNetworkToHost(entry, &storeEntry);
6807 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6809 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6810 entry->volumeId[RWVOL]);
6814 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6815 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6816 * is concerned, oldname is lost */
6817 if (entry->flags & RW_EXISTS) {
6818 index = Lp_GetRwIndex(entry);
6819 if (index == -1) { /* there is a serious discrepancy */
6821 "There is a serious discrepancy in VLDB entry for volume %u\n",
6822 entry->volumeId[RWVOL]);
6823 fprintf(STDERR, "try building VLDB from scratch\n");
6824 error = VOLSERVLDB_ERROR;
6827 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6829 AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
6830 entry->serverPartition[index], ITOffline, &tid);
6831 if (code) { /*volume doesnot exist */
6833 "Could not start transaction on the rw volume %u\n",
6834 entry->volumeId[RWVOL]);
6837 } else { /*volume exists, process it */
6840 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6841 entry->volumeId[RWVOL],
6842 entry->volumeId[ROVOL],
6843 entry->volumeId[BACKVOL]);
6845 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6846 code = AFSVolEndTrans(aconn, tid, &rcode);
6850 "Could not end transaction on volume %s %u\n",
6851 entry->name, entry->volumeId[RWVOL]);
6856 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6857 entry->name, entry->volumeId[RWVOL]);
6863 rx_DestroyConnection(aconn);
6864 aconn = (struct rx_connection *)0;
6866 /*end rw volume processing */
6867 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6868 index = Lp_GetRwIndex(entry);
6869 if (index == -1) { /* there is a serious discrepancy */
6871 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6872 entry->volumeId[BACKVOL]);
6873 fprintf(STDERR, "try building VLDB from scratch\n");
6874 error = VOLSERVLDB_ERROR;
6877 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6879 AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
6880 entry->serverPartition[index], ITOffline, &tid);
6881 if (code) { /*volume doesnot exist */
6883 "Could not start transaction on the backup volume %u\n",
6884 entry->volumeId[BACKVOL]);
6887 } else { /*volume exists, process it */
6888 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6890 "Volume name %s.backup exceeds the limit of %u characters\n",
6891 newname, VOLSER_OLDMAXVOLNAME);
6895 strcpy(nameBuffer, newname);
6896 strcat(nameBuffer, ".backup");
6899 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6900 entry->volumeId[RWVOL], 0, 0);
6902 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6903 code = AFSVolEndTrans(aconn, tid, &rcode);
6907 "Could not end transaction on the backup volume %u\n",
6908 entry->volumeId[BACKVOL]);
6914 "Could not set parameters on the backup volume %u\n",
6915 entry->volumeId[BACKVOL]);
6920 } /* end backup processing */
6922 rx_DestroyConnection(aconn);
6923 aconn = (struct rx_connection *)0;
6924 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6925 for (i = 0; i < entry->nServers; i++) {
6926 if (entry->serverFlags[i] & ITSROVOL) {
6927 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6929 AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
6930 entry->serverPartition[i], ITOffline,
6932 if (code) { /*volume doesnot exist */
6934 "Could not start transaction on the ro volume %u\n",
6935 entry->volumeId[ROVOL]);
6938 } else { /*volume exists, process it */
6939 strcpy(nameBuffer, newname);
6940 strcat(nameBuffer, ".readonly");
6941 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6943 "Volume name %s exceeds the limit of %u characters\n",
6944 nameBuffer, VOLSER_OLDMAXVOLNAME);
6949 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6950 entry->volumeId[RWVOL], 0, 0);
6952 VPRINT2("Renamed RO volume %s on host %s\n",
6955 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
6956 hostutil_GetNameByINet(entry->
6958 code = AFSVolEndTrans(aconn, tid, &rcode);
6962 "Could not end transaction on volume %u\n",
6963 entry->volumeId[ROVOL]);
6969 "Could not set parameters on the ro volume %u\n",
6970 entry->volumeId[ROVOL]);
6976 rx_DestroyConnection(aconn);
6977 aconn = (struct rx_connection *)0;
6984 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6986 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6989 "Could not unlock the VLDB entry for the volume %s %u\n",
6990 entry->name, entry->volumeId[RWVOL]);
6996 code = AFSVolEndTrans(aconn, tid, &rcode);
7000 fprintf(STDERR, "Failed to end transaction on a volume \n");
7006 rx_DestroyConnection(aconn);
7007 PrintError("", error);
7012 /*report on all the active transactions on volser */
7014 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
7016 struct rx_connection *aconn;
7017 transDebugEntries transInfo;
7020 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7021 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
7022 transInfo.transDebugEntries_len = 0;
7023 code = AFSVolMonitor(aconn, &transInfo);
7026 "Could not access status information about the server\n");
7027 PrintError("", code);
7028 if (transInfo.transDebugEntries_val)
7029 free(transInfo.transDebugEntries_val);
7031 rx_DestroyConnection(aconn);
7034 *rcount = transInfo.transDebugEntries_len;
7035 *rpntr = transInfo.transDebugEntries_val;
7037 rx_DestroyConnection(aconn);
7044 /*delete the volume without interacting with the vldb */
7046 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_uint32 volid)
7048 afs_int32 rcode, ttid, error, code;
7049 struct rx_connection *aconn;
7055 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7056 code = AFSVolTransCreate_retry(aconn, volid, part, ITOffline, &ttid);
7058 fprintf(STDERR, "Could not start transaction on volume %lu\n",
7059 (unsigned long)volid);
7063 code = AFSVolDeleteVolume(aconn, ttid);
7065 fprintf(STDERR, "Could not delete volume %lu\n",
7066 (unsigned long)volid);
7070 code = AFSVolEndTrans(aconn, ttid, &rcode);
7075 fprintf(STDERR, "Could not end transaction on volume %lu\n",
7076 (unsigned long)volid);
7082 code = AFSVolEndTrans(aconn, ttid, &rcode);
7088 PrintError("", error);
7090 rx_DestroyConnection(aconn);
7095 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_uint32 volid,
7096 afs_int32 transflag, afs_int32 setflag, int sleeptime)
7098 struct rx_connection *conn = 0;
7100 afs_int32 code, error = 0, rcode;
7102 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7104 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
7108 code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
7110 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
7114 code = AFSVolSetFlags(conn, tid, setflag);
7116 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
7121 #ifdef AFS_PTHREAD_ENV
7124 IOMGR_Sleep(sleeptime);
7131 code = AFSVolEndTrans(conn, tid, &rcode);
7132 if (code || rcode) {
7133 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
7135 error = (code ? code : rcode);
7140 rx_DestroyConnection(conn);
7145 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_uint32 volid,
7148 struct rx_connection *conn = 0;
7150 afs_int32 code, error = 0, rcode;
7152 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
7154 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
7158 code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
7160 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7164 code = AFSVolSetInfo(conn, tid, infop);
7166 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7173 code = AFSVolEndTrans(conn, tid, &rcode);
7174 if (code || rcode) {
7175 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7177 error = (code ? code : rcode);
7182 rx_DestroyConnection(conn);
7187 UV_GetSize(afs_uint32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
7188 afs_int32 fromdate, struct volintSize *vol_size)
7190 struct rx_connection *aconn = (struct rx_connection *)0;
7191 afs_int32 tid = 0, rcode = 0;
7192 afs_int32 code, error = 0;
7195 /* get connections to the servers */
7196 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7198 VPRINT1("Starting transaction on volume %u...", afromvol);
7199 code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
7200 EGOTO1(error_exit, code,
7201 "Could not start transaction on the volume %u to be measured\n",
7205 VPRINT1("Getting size of volume on volume %u...", afromvol);
7206 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7207 EGOTO(error_exit, code, "Could not start the measurement process \n");
7212 VPRINT1("Ending transaction on volume %u...", afromvol);
7213 code = AFSVolEndTrans(aconn, tid, &rcode);
7214 if (code || rcode) {
7215 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7217 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7219 error = (code ? code : rcode);
7224 rx_DestroyConnection(aconn);
7226 PrintError("", error);
7230 /*maps the host addresses in <old > (present in network byte order) to
7231 that in< new> (present in host byte order )*/
7233 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7237 /*copy all the fields */
7238 strcpy(new->name, old->name);
7239 /* new->volumeType = old->volumeType;*/
7240 new->nServers = old->nServers;
7241 count = old->nServers;
7242 if (count < NMAXNSERVERS)
7244 for (i = 0; i < count; i++) {
7245 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7246 new->serverPartition[i] = old->serverPartition[i];
7247 new->serverFlags[i] = old->serverFlags[i];
7249 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7250 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7251 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7252 new->cloneId = old->cloneId;
7253 new->flags = old->flags;
7256 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7258 MapHostToNetwork(struct nvldbentry *entry)
7262 count = entry->nServers;
7263 if (count < NMAXNSERVERS)
7265 for (i = 0; i < count; i++) {
7266 entry->serverNumber[i] = htonl(entry->serverNumber[i]);