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>
17 #include <sys/types.h>
21 #include <sys/statfs.h>
28 #include <netinet/in.h>
32 #include <afs/voldefs.h>
35 #include <afs/vlserver.h>
37 #include <afs/cellconfig.h>
40 #include <afs/afsint.h>
44 #include <afs/com_err.h>
46 #include <afs/kautils.h>
49 #define ERRCODE_RANGE 8 /* from error_table.h */
50 #define CLOCKSKEW 2 /* not really skew, but resolution */
51 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
53 /* for UV_MoveVolume() recovery */
55 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
58 #include "volser_prototypes.h"
59 #include "vsutils_prototypes.h"
60 #include "lockprocs_prototypes.h"
62 struct ubik_client *cstruct;
63 int verbose = 0, noresolve = 0;
68 afs_int32 vldbEntryIndex;
71 /* Utility macros used by rest of this source file */
72 #define EPRINT(ec, es) \
74 fprintf(STDERR, "\n"); \
75 fprintf(STDERR, (es)); \
79 #define EPRINT1(ec, es, ep1) \
81 fprintf(STDERR, "\n"); \
82 fprintf(STDERR, (es), (ep1)); \
86 #define EPRINT2(ec, es, ep1, ep2) \
88 fprintf(STDERR, "\n"); \
89 fprintf(STDERR, (es), (ep1), (ep2)); \
93 #define EPRINT3(ec, es, ep1, ep2, ep3) \
95 fprintf(STDERR, "\n"); \
96 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
100 #define EGOTO(where, ec, es) \
109 #define EGOTO1(where, ec, es, ep1) \
112 EPRINT1((ec),(es),(ep1)); \
118 #define EGOTO2(where, ec, es, ep1, ep2) \
121 EPRINT2((ec),(es),(ep1),(ep2)); \
127 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
130 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
137 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
138 #define VPRINT1(es, p) \
139 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
140 #define VPRINT2(es, p1, p2) \
141 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
142 #define VPRINT3(es, p1, p2, p3) \
143 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
145 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
146 #define VEPRINT(es) \
147 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
148 #define VEPRINT1(es, p) \
149 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
150 #define VEPRINT2(es, p1, p2) \
151 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
152 #define VEPRINT3(es, p1, p2, p3) \
153 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
155 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
159 /* getting rid of this */
160 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
163 /* Protos for static routines */
164 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
165 afs_int32 apart, afs_int32 okvol,
167 static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
169 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
170 struct rx_connection **connPtr, afs_int32 * transPtr,
171 afs_int32 * crtimePtr, afs_int32 * uptimePtr);
172 static int SimulateForwardMultiple(struct rx_connection *fromconn,
173 afs_int32 fromtid, afs_int32 fromdate,
174 manyDests * tr, afs_int32 flags,
175 void *cookie, manyResults * results);
176 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
177 afs_int32 apart, afs_int32 * modentry,
178 afs_uint32 * maxvolid);
181 /*map the partition <partId> into partition name <partName>*/
183 MapPartIdIntoName(afs_int32 partId, char *partName)
185 if (partId < 26) { /* what if partId > = 26 ? */
186 strcpy(partName, "/vicep");
187 partName[6] = partId + 'a';
190 } else if (partId < VOLMAXPARTS) {
191 strcpy(partName, "/vicep");
193 partName[6] = 'a' + (partId / 26);
194 partName[7] = 'a' + (partId % 26);
206 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
207 response = c = getchar();
208 while (!(c == EOF || c == '\n'))
209 c = getchar(); /*skip to end of line */
210 code = (response == 'y' || response == 'Y');
216 PrintError(char *msg, afs_int32 errcode)
218 fprintf(STDERR, msg);
219 /*replace by a big switch statement */
224 fprintf(STDERR, "Possible communication failure\n");
227 fprintf(STDERR, "Volume needs to be salvaged\n");
230 fprintf(STDERR, "Bad vnode number quoted\n");
234 "Volume not attached, does not exist, or not on line\n");
237 fprintf(STDERR, "Volume already exists\n");
240 fprintf(STDERR, "Volume is not in service\n");
243 fprintf(STDERR, "Volume is off line\n");
246 fprintf(STDERR, "Volume is already on line\n");
249 fprintf(STDERR, "Partition is full\n");
252 fprintf(STDERR, "Volume max quota exceeded\n");
255 fprintf(STDERR, "Volume temporarily unavailable\n");
258 fprintf(STDERR, "Volume has moved to another server\n");
261 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
264 fprintf(STDERR, "VLDB: a read terminated too early\n");
267 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
270 fprintf(STDERR, "VLDB: internal creation failure\n");
273 fprintf(STDERR, "VLDB: no such entry\n");
276 fprintf(STDERR, "VLDB: vldb database is empty\n");
279 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
282 fprintf(STDERR, "VLDB: volume name is illegal\n");
285 fprintf(STDERR, "VLDB: index was out of range\n");
288 fprintf(STDERR, "VLDB: bad volume type\n");
291 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
293 case VL_BADPARTITION:
294 fprintf(STDERR, "VLDB: bad partition number\n");
297 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
300 fprintf(STDERR, "VLDB: no such repsite server exists\n");
302 case VL_DUPREPSERVER:
303 fprintf(STDERR, "VLDB: replication site server already exists\n");
306 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
309 fprintf(STDERR, "VLDB: illegal reference count number\n");
311 case VL_SIZEEXCEEDED:
312 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
315 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
317 case VL_BADVOLIDBUMP:
318 fprintf(STDERR, "VLDB: illegal max volid increment\n");
320 case VL_IDALREADYHASHED:
321 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
324 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
327 fprintf(STDERR, "VLDB: bad volume operation code\n");
329 case VL_BADRELLOCKTYPE:
330 fprintf(STDERR, "VLDB: bad release lock type\n");
333 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
335 case VL_BADSERVERFLAG:
336 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
339 fprintf(STDERR, "VLDB: no permission access for call\n");
341 case VOLSERREAD_DUMPERROR:
343 "VOLSER: Problems encountered in reading the dump file !\n");
345 case VOLSERDUMPERROR:
346 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
348 case VOLSERATTACH_ERROR:
349 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
351 case VOLSERDETACH_ERROR:
352 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
354 case VOLSERILLEGAL_PARTITION:
355 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
357 case VOLSERBAD_ACCESS:
358 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
360 case VOLSERVLDB_ERROR:
361 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
364 fprintf(STDERR, "VOLSER: error in volume name\n");
367 fprintf(STDERR, "VOLSER: volume has moved\n");
370 fprintf(STDERR, "VOLSER: illegal operation\n");
372 case VOLSERBADRELEASE:
373 fprintf(STDERR, "VOLSER: release could not be completed\n");
376 fprintf(STDERR, "VOLSER: volume is busy\n");
378 case VOLSERNO_MEMORY:
379 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
383 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
385 case VOLSERMULTIRWVOL:
387 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
391 "VOLSER: not all entries were successfully processed\n");
398 initialize_KA_error_table();
399 initialize_RXK_error_table();
400 initialize_KTC_error_table();
401 initialize_ACFG_error_table();
402 initialize_CMD_error_table();
403 initialize_VL_error_table();
405 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
406 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
407 afs_error_message(errcode));
414 void init_volintInfo(struct volintInfo *vinfo) {
415 memset(vinfo, 0, sizeof(struct volintInfo));
417 vinfo->maxquota = -1;
419 vinfo->creationDate = -1;
420 vinfo->updateDate = -1;
428 static struct rx_securityClass *uvclass = 0;
429 static int uvindex = -1;
430 /* called by VLDBClient_Init to set the security module to be used in the RPC */
432 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
439 /* bind to volser on <port> <aserver> */
440 /* takes server address in network order, port in host order. dumb */
441 struct rx_connection *
442 UV_Bind(afs_int32 aserver, afs_int32 port)
444 register struct rx_connection *tc;
446 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
451 /* if <okvol> is allright(indicated by beibg able to
452 * start a transaction, delete the <delvol> */
454 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
455 afs_int32 okvol, afs_int32 delvol)
457 afs_int32 error, code, tid, rcode;
463 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
466 code = AFSVolDeleteVolume(aconn, tid);
469 code = AFSVolEndTrans(aconn, tid, &rcode);
476 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
478 code = AFSVolEndTrans(aconn, tid, &rcode);
483 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
486 code = AFSVolDeleteVolume(aconn, tid);
489 code = AFSVolEndTrans(aconn, tid, &rcode);
500 /* called by EmuerateEntry, show vldb entry in a reasonable format */
502 SubEnumerateEntry(struct nvldbentry *entry)
510 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
511 if (entry->flags & RW_EXISTS)
512 fprintf(STDOUT, " valid \n");
514 fprintf(STDOUT, " invalid \n");
515 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
516 if (entry->flags & RO_EXISTS)
517 fprintf(STDOUT, " valid \n");
519 fprintf(STDOUT, " invalid \n");
520 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
521 if (entry->flags & BACK_EXISTS)
522 fprintf(STDOUT, " valid \n");
524 fprintf(STDOUT, " invalid \n");
525 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
526 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
528 if (entry->flags & RW_EXISTS)
529 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
530 if (entry->flags & RO_EXISTS)
531 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
532 if (entry->flags & BACK_EXISTS)
533 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
534 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
535 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
536 fprintf(STDOUT, "\n");
538 fprintf(STDOUT, " number of sites -> %lu\n",
539 (unsigned long)entry->nServers);
540 for (i = 0; i < entry->nServers; i++) {
541 if (entry->serverFlags[i] & NEW_REPSITE)
544 for (i = 0; i < entry->nServers; i++) {
545 MapPartIdIntoName(entry->serverPartition[i], pname);
546 fprintf(STDOUT, " server %s partition %s ",
547 noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
548 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
549 if (entry->serverFlags[i] & ITSRWVOL)
550 fprintf(STDOUT, "RW Site ");
552 fprintf(STDOUT, "RO Site ");
554 if (entry->serverFlags[i] & NEW_REPSITE)
555 fprintf(STDOUT," -- New release");
557 if (!(entry->serverFlags[i] & ITSRWVOL))
558 fprintf(STDOUT," -- Old release");
560 if (entry->serverFlags[i] & RO_DONTUSE)
561 fprintf(STDOUT, " -- Not released");
563 fprintf(STDOUT, "\n");
570 /*enumerate the vldb entry corresponding to <entry> */
572 EnumerateEntry(struct nvldbentry *entry)
575 fprintf(STDOUT, "\n");
576 fprintf(STDOUT, "%s \n", entry->name);
577 SubEnumerateEntry(entry);
581 /* forcibly remove a volume. Very dangerous call */
583 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
585 register struct rx_connection *tconn;
586 register afs_int32 code;
588 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
590 code = AFSVolNukeVolume(tconn, partid, volid);
591 rx_DestroyConnection(tconn);
597 /* like df. Return usage of <pname> on <server> in <partition> */
599 UV_PartitionInfo64(afs_int32 server, char *pname,
600 struct diskPartition64 *partition)
602 register struct rx_connection *aconn;
605 aconn = (struct rx_connection *)0;
606 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
607 code = AFSVolPartitionInfo64(aconn, pname, partition);
608 if (code == RXGEN_OPCODE) {
609 struct diskPartition *dpp =
610 (struct diskPartition *)malloc(sizeof(struct diskPartition));
611 code = AFSVolPartitionInfo(aconn, pname, dpp);
613 strncpy(partition->name, dpp->name, 32);
614 strncpy(partition->devName, dpp->devName, 32);
615 partition->lock_fd = dpp->lock_fd;
616 partition->free = dpp->free;
617 partition->minFree = dpp->minFree;
622 fprintf(STDERR, "Could not get information on partition %s\n", pname);
623 PrintError("", code);
626 rx_DestroyConnection(aconn);
630 /* old interface to create volume */
632 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
636 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
640 /* create a volume, given a server, partition number, volume name --> sends
641 * back new vol id in <anewid>*/
643 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
644 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
645 afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
648 register struct rx_connection *aconn;
650 register afs_int32 code;
652 afs_int32 rcode, vcode;
653 struct nvldbentry entry, storeEntry; /*the new vldb entry */
654 struct volintInfo tstatus;
657 aconn = (struct rx_connection *)0;
660 init_volintInfo(&tstatus);
661 tstatus.maxquota = aquota;
663 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
664 /* next the next 3 available ids from the VLDB */
665 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 3, anewid);
666 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
669 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
670 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
673 code = AFSVolSetInfo(aconn, tid, &tstatus);
675 EPRINT(code, "Could not change quota, continuing...\n");
677 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
678 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
681 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
683 /* set up the vldb entry for this volume */
684 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
686 entry.serverNumber[0] = aserver; /* this should have another
687 * level of indirection later */
688 entry.serverPartition[0] = apart; /* this should also have
689 * another indirection level */
690 entry.flags = RW_EXISTS; /* this records that rw volume exists */
691 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
692 entry.volumeId[RWVOL] = *anewid;
693 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
694 entry.volumeId[BACKVOL] = *anewid + 2;
696 /*map into right byte order, before passing to xdr, the stuff has to be in host
697 * byte order. Xdr converts it into network order */
698 MapNetworkToHost(&entry, &storeEntry);
699 /* create the vldb entry */
700 vcode = VLDB_CreateEntry(&storeEntry);
703 "Could not create a VLDB entry for the volume %s %lu\n",
704 aname, (unsigned long)*anewid);
705 /*destroy the created volume */
706 VPRINT1("Deleting the newly created volume %u\n", *anewid);
707 AFSVolDeleteVolume(aconn, tid);
711 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
712 /* volume created, now terminate the transaction and release the connection */
713 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
714 * the volume will come online anyway when transaction timesout , so if
715 * vldb entry exists then the volume is guaranteed to exist too wrt create */
719 "Failed to end the transaction on the volume %s %lu\n", aname,
720 (unsigned long)*anewid);
727 code = AFSVolEndTrans(aconn, tid, &rcode);
729 fprintf(STDERR, "WARNING: could not end transaction\n");
732 rx_DestroyConnection(aconn);
733 PrintError("", error);
739 /* create a volume, given a server, partition number, volume name --> sends
740 * back new vol id in <anewid>*/
742 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
745 register struct rx_connection *aconn;
748 struct nvldbentry entry, storeEntry; /*the new vldb entry */
750 aconn = (struct rx_connection *)0;
753 /* set up the vldb entry for this volume */
754 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
756 entry.serverNumber[0] = aserver; /* this should have another
757 * level of indirection later */
758 entry.serverPartition[0] = apart; /* this should also have
759 * another indirection level */
760 entry.flags = RW_EXISTS; /* this records that rw volume exists */
761 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
762 entry.volumeId[RWVOL] = aid;
764 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
765 entry.volumeId[BACKVOL] = *anewid + 2;
767 entry.volumeId[ROVOL] = 0;
768 entry.volumeId[BACKVOL] = 0;
771 /*map into right byte order, before passing to xdr, the stuff has to be in host
772 * byte order. Xdr converts it into network order */
773 MapNetworkToHost(&entry, &storeEntry);
774 /* create the vldb entry */
775 vcode = VLDB_CreateEntry(&storeEntry);
778 "Could not create a VLDB entry for the volume %s %lu\n",
779 aname, (unsigned long)aid);
783 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
787 rx_DestroyConnection(aconn);
788 PrintError("", error);
792 /* Delete the volume <volid>on <aserver> <apart>
793 * the physical entry gets removed from the vldb only if the ref count
797 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
799 struct rx_connection *aconn = (struct rx_connection *)0;
801 afs_int32 code, rcode;
803 struct nvldbentry entry, storeEntry;
805 afs_int32 avoltype = -1, vtype;
806 int notondisk = 0, notinvldb = 0;
808 /* Find and read bhe VLDB entry for this volume */
809 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
811 if (code != VL_NOENT) {
812 EGOTO1(error_exit, code,
813 "Could not lock VLDB entry for the volume %u\n", avolid);
819 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
820 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
822 MapHostToNetwork(&entry);
825 EnumerateEntry(&entry);
828 /* Whether volume is in the VLDB or not. Delete the volume on disk */
829 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
830 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
832 if (code == VNOVOL) {
835 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
839 VPRINT1("Trying to delete the volume %u ...", avolid);
841 code = AFSVolDeleteVolume(aconn, ttid);
842 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
844 code = AFSVolEndTrans(aconn, ttid, &rcode);
845 code = (code ? code : rcode);
847 EGOTO1(error_exit, code,
848 "Could not end the transaction for the volume %u \n", avolid);
852 /* Now update the VLDB entry.
853 * But first, verify we have a VLDB entry.
854 * Whether volume is on disk or not. Delete the volume in VLDB.
859 if (avolid == entry.volumeId[BACKVOL]) {
860 /* Its a backup volume, modify the VLDB entry. Check that the
861 * backup volume is on the server/partition we asked to delete.
863 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
864 notinvldb = 2; /* Not on this server and partition */
868 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
870 entry.flags &= ~BACK_EXISTS;
874 else if (avolid == entry.volumeId[ROVOL]) {
875 /* Its a read-only volume, modify the VLDB entry. Check that the
876 * readonly volume is on the server/partition we asked to delete.
877 * If flags does not have RO_EIXSTS set, then this may mean the RO
878 * hasn't been released (and could exist in VLDB).
880 if (!Lp_ROMatch(aserver, apart, &entry)) {
881 notinvldb = 2; /* Not found on this server and partition */
887 "Marking the readonly volume %lu deleted in the VLDB\n",
888 (unsigned long)avolid);
890 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
892 if (!Lp_ROMatch(0, 0, &entry))
893 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
897 else if (avolid == entry.volumeId[RWVOL]) {
898 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
899 * Check that the readwrite volumes is on the server/partition we
902 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
903 notinvldb = 2; /* Not found on this server and partition */
907 /* Delete backup if it exists */
909 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
913 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
914 entry.volumeId[BACKVOL]);
917 code = AFSVolDeleteVolume(aconn, ttid);
918 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
919 entry.volumeId[BACKVOL]);
921 code = AFSVolEndTrans(aconn, ttid, &rcode);
923 code = (code ? code : rcode);
924 EGOTO1(error_exit, code,
925 "Could not end the transaction for the volume %u \n",
926 entry.volumeId[BACKVOL]);
928 fprintf(STDOUT, " done\n");
933 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
934 (unsigned long)avolid,
936 flags & BACK_EXISTS) ? ", and its backup volume," :
939 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
941 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
944 if (entry.flags & RO_EXISTS)
945 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
949 notinvldb = 2; /* Not found on this server and partition */
953 /* Either delete or replace the VLDB entry */
954 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
957 "Last reference to the VLDB entry for %lu - deleting entry\n",
958 (unsigned long)avolid);
959 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
960 EGOTO1(error_exit, code,
961 "Could not delete the VLDB entry for the volume %u \n",
964 MapNetworkToHost(&entry, &storeEntry);
966 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
967 (LOCKREL_OPCODE | LOCKREL_AFSID |
969 EGOTO1(error_exit, code,
970 "Could not update the VLDB entry for the volume %u \n",
979 if (notondisk && notinvldb) {
980 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
981 ((notinvldb == 2) ? "on server and partition" : ""));
984 } else if (notondisk) {
986 "WARNING: Volume %lu did not exist on the partition\n",
987 (unsigned long)avolid);
988 } else if (notinvldb) {
989 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
990 (unsigned long)avolid,
991 ((notinvldb == 2) ? "on server and partition" : ""));
995 code = AFSVolEndTrans(aconn, ttid, &rcode);
996 code = (code ? code : rcode);
998 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
999 (unsigned long)avolid);
1000 PrintError("", code);
1008 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
1009 (LOCKREL_OPCODE | LOCKREL_AFSID |
1010 LOCKREL_TIMESTAMP));
1013 "Could not release the lock on the VLDB entry for the volume %u \n",
1021 rx_DestroyConnection(aconn);
1025 /* add recovery to UV_MoveVolume */
1027 #define TESTC 0 /* set to test recovery code, clear for production */
1033 sigint_handler(int x)
1038 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1040 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1041 fprintf(STDOUT, "enter second control-c to exit\n");
1045 (void)signal(SIGINT, sigint_handler);
1050 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1051 * <atopart>. The operation is almost idempotent. The following
1052 * flags are recognized:
1054 * RV_NOCLONE - don't use a copy clone
1058 UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1059 afs_int32 atoserver, afs_int32 atopart, int flags)
1061 struct rx_connection *toconn, *fromconn;
1062 afs_int32 fromtid, totid, clonetid;
1065 char tmpName[VOLSER_MAXVOLNAME + 1];
1068 struct restoreCookie cookie;
1069 register afs_int32 vcode, code;
1070 afs_int32 newVol, volid, backupId;
1071 struct volser_status tstatus;
1072 struct destServer destination;
1074 struct nvldbentry entry, storeEntry;
1075 int i, islocked, pntg;
1077 char in, lf; /* for test code */
1081 #ifdef ENABLE_BUGFIX_1165
1082 volEntries volumeInfo;
1083 struct volintInfo *infop = 0;
1087 fromconn = (struct rx_connection *)0;
1088 toconn = (struct rx_connection *)0;
1098 /* support control-c processing */
1101 (void)signal(SIGINT, sigint_handler);
1105 "\nThere are three tests points - verifies all code paths through recovery.\n");
1106 fprintf(STDOUT, "First test point - operation not started.\n");
1107 fprintf(STDOUT, "...test here (y, n)? ");
1109 fscanf(stdin, "%c", &in);
1110 fscanf(stdin, "%c", &lf); /* toss away */
1112 fprintf(STDOUT, "type control-c\n");
1114 fprintf(stdout, ".");
1119 /* or drop through */
1122 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1123 EGOTO1(mfail, vcode,
1124 "Could not fetch the entry for the volume %u from the VLDB \n",
1127 if (entry.volumeId[RWVOL] != afromvol) {
1128 fprintf(STDERR, "Only RW volume can be moved\n");
1132 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1133 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1136 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1137 EGOTO1(mfail, vcode,
1138 "Could not fetch the entry for the volume %u from the VLDB \n",
1141 backupId = entry.volumeId[BACKVOL];
1142 MapHostToNetwork(&entry);
1144 if (!Lp_Match(afromserver, afrompart, &entry)) {
1145 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1146 if (!Lp_Match(atoserver, atopart, &entry)) {
1147 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1148 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1149 (unsigned long)afromvol);
1150 fprintf(STDERR, "The current site is :");
1151 for (i = 0; i < entry.nServers; i++) {
1152 if (entry.serverFlags[i] == ITSRWVOL) {
1154 MapPartIdIntoName(entry.serverPartition[i], pname);
1155 fprintf(STDERR, " server %s partition %s \n",
1156 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
1157 hostutil_GetNameByINet(entry.serverNumber[i]),
1162 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1163 (LOCKREL_OPCODE | LOCKREL_AFSID |
1164 LOCKREL_TIMESTAMP));
1165 EGOTO1(mfail, vcode,
1166 " Could not release lock on the VLDB entry for the volume %u \n",
1169 return VOLSERVOLMOVED;
1172 /* delete the volume afromvol on src_server */
1173 /* from-info does not exist but to-info does =>
1174 * we have already done the move, but the volume
1175 * may still be existing physically on from fileserver
1177 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1182 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1184 if (!code) { /* volume exists - delete it */
1185 VPRINT1("Setting flags on leftover source volume %u ...",
1188 AFSVolSetFlags(fromconn, fromtid,
1189 VTDeleteOnSalvage | VTOutOfService);
1191 "Failed to set flags on the leftover source volume %u\n",
1195 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1196 code = AFSVolDeleteVolume(fromconn, fromtid);
1198 "Failed to delete the leftover source volume %u\n",
1202 VPRINT1("Ending transaction on leftover source volume %u ...",
1204 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1209 "Could not end the transaction for the leftover source volume %u \n",
1214 /*delete the backup volume now */
1217 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1219 if (!code) { /* backup volume exists - delete it */
1220 VPRINT1("Setting flags on leftover backup volume %u ...",
1223 AFSVolSetFlags(fromconn, fromtid,
1224 VTDeleteOnSalvage | VTOutOfService);
1226 "Failed to set flags on the backup volume %u\n", backupId);
1229 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1230 code = AFSVolDeleteVolume(fromconn, fromtid);
1232 "Could not delete the leftover backup volume %u\n",
1236 VPRINT1("Ending transaction on leftover backup volume %u ...",
1238 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1243 "Could not end the transaction for the leftover backup volume %u\n",
1253 /* From-info matches the vldb info about volid,
1254 * its ok start the move operation, the backup volume
1255 * on the old site is deleted in the process
1257 if (afrompart == atopart) {
1258 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1259 EGOTO2(mfail, error,
1260 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1261 afromserver, error);
1264 EGOTO1(mfail, VOLSERVOLMOVED,
1265 "Warning: Moving volume %u to its home partition ignored!\n",
1271 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1272 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1273 fromtid = totid = 0; /* initialize to uncreated */
1276 * clone the read/write volume locally.
1279 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1280 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1281 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1285 if (!(flags & RV_NOCLONE)) {
1286 /* Get a clone id */
1287 VPRINT1("Allocating new volume id for clone of volume %u ...",
1290 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1291 EGOTO1(mfail, vcode,
1292 "Could not get an ID for the clone of volume %u from the VLDB\n",
1296 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1297 VPRINT1("Cloning source volume %u ...", afromvol);
1298 strcpy(vname, "move-clone-temp");
1300 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1301 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1306 /* lookup the name of the volume we just cloned */
1308 code = AFSVolGetName(fromconn, fromtid, &volName);
1309 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1312 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1314 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1319 "Failed to end the transaction on the source volume %u\n",
1324 * Create the destination volume
1327 if (!(flags & RV_NOCLONE)) {
1328 /* All of this is to get the fromDate */
1329 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1331 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1334 "Failed to start a transaction on the cloned volume%u\n",
1338 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1340 AFSVolSetFlags(fromconn, clonetid,
1341 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1342 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1346 /* remember time from which we've dumped the volume */
1347 VPRINT1("Getting status of cloned volume %u ...", newVol);
1348 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1350 "Failed to get the status of the cloned volume %u\n",
1354 fromDate = CLOCKADJ(tstatus.creationDate);
1356 /* With RV_NOCLONE, just do a full copy from the source */
1361 #ifdef ENABLE_BUGFIX_1165
1363 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1364 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1365 * don't use this information...
1367 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1368 volumeInfo.volEntries_len = 0;
1369 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1371 "Failed to get the volint Info of the cloned volume %u\n",
1374 infop = (volintInfo *) volumeInfo.volEntries_val;
1375 infop->maxquota = -1; /* Else it will replace the default quota */
1376 infop->creationDate = -1; /* Else it will use the source creation date */
1377 infop->updateDate = -1; /* Else it will use the source update date */
1380 /* create a volume on the target machine */
1382 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1384 /* Delete the existing volume.
1385 * While we are deleting the volume in these steps, the transaction
1386 * we started against the cloned volume (clonetid above) will be
1387 * sitting idle. It will get cleaned up after 600 seconds
1389 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1390 code = AFSVolDeleteVolume(toconn, totid);
1392 "Could not delete the pre-existing volume %u on destination\n",
1397 ("Ending transaction on pre-existing volume %u on destination ...",
1399 code = AFSVolEndTrans(toconn, totid, &rcode);
1404 "Could not end the transaction on pre-existing volume %u on destination\n",
1409 VPRINT1("Creating the destination volume %u ...", volid);
1411 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1413 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1417 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1421 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1423 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1425 "Failed to set the flags on the destination volume %u\n", volid);
1429 * Now dump the clone to the new volume
1432 destination.destHost = ntohl(atoserver);
1433 destination.destPort = AFSCONF_VOLUMEPORT;
1434 destination.destSSID = 1;
1436 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1437 cookie.type = RWVOL;
1438 cookie.parent = entry.volumeId[RWVOL];
1441 if (!(flags & RV_NOCLONE)) {
1442 /* Copy the clone to the new volume */
1443 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1446 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1448 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1451 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1452 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1457 "Failed to end the transaction on the cloned volume %u\n",
1463 * reattach to the main-line volume, and incrementally dump it.
1466 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1467 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1469 "Failed to create a transaction on the source volume %u\n",
1473 /* now do the incremental */
1475 ("Doing the%s dump from source to destination for volume %u ... ",
1476 (flags & RV_NOCLONE) ? "" : " incremental",
1479 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1482 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1483 (flags & RV_NOCLONE) ? "" : " incremental");
1486 /* now adjust the flags so that the new volume becomes official */
1487 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1488 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1490 "Failed to set the flags to make old source volume offline\n");
1493 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1494 code = AFSVolSetFlags(toconn, totid, 0);
1496 "Failed to set the flags to make new source volume online\n");
1499 #ifdef ENABLE_BUGFIX_1165
1500 VPRINT1("Setting volume status on destination volume %u ...", volid);
1501 code = AFSVolSetInfo(toconn, totid, infop);
1503 "Failed to set volume status on the destination volume %u\n",
1508 /* put new volume online */
1509 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1510 code = AFSVolEndTrans(toconn, totid, &rcode);
1515 "Failed to end the transaction on the volume %u on the new site\n",
1519 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1520 MapNetworkToHost(&entry, &storeEntry);
1521 storeEntry.flags &= ~BACK_EXISTS;
1525 "Second test point - operation in progress but not complete.\n");
1526 fprintf(STDOUT, "...test here (y, n)? ");
1528 fscanf(stdin, "%c", &in);
1529 fscanf(stdin, "%c", &lf); /* toss away */
1531 fprintf(STDOUT, "type control-c\n");
1533 fprintf(stdout, ".");
1538 /* or drop through */
1541 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1543 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1544 (LOCKREL_OPCODE | LOCKREL_AFSID |
1545 LOCKREL_TIMESTAMP));
1548 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1549 storeEntry.name, (unsigned long)afromvol);
1558 "Third test point - operation complete but no cleanup.\n");
1559 fprintf(STDOUT, "...test here (y, n)? ");
1561 fscanf(stdin, "%c", &in);
1562 fscanf(stdin, "%c", &lf); /* toss away */
1564 fprintf(STDOUT, "type control-c\n");
1566 fprintf(stdout, ".");
1571 /* or drop through */
1574 /* This is tricky. File server is very stupid, and if you mark the volume
1575 * as VTOutOfService, it may mark the *good* instance (if you're moving
1576 * between partitions on the same machine) as out of service. Since
1577 * we're cleaning this code up in DEcorum, we're just going to kludge around
1578 * it for now by removing this call. */
1579 /* already out of service, just zap it now */
1581 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1584 "Failed to set the flags to make the old source volume offline\n");
1588 if (atoserver != afromserver) {
1589 /* set forwarding pointer for moved volumes */
1590 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1591 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1593 "Failed to set the forwarding pointer for the volume %u\n",
1598 VPRINT1("Deleting old volume %u on source ...", afromvol);
1599 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1600 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1604 VPRINT1("Ending transaction on old volume %u on the source ...",
1606 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1611 "Failed to end the transaction on the old volume %u on the source\n",
1615 /* Delete the backup volume on the original site */
1616 VPRINT1("Creating transaction for backup volume %u on source ...",
1619 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1622 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1624 AFSVolSetFlags(fromconn, fromtid,
1625 VTDeleteOnSalvage | VTOutOfService);
1627 "Failed to set the flags on the backup volume %u on the source\n",
1631 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1632 code = AFSVolDeleteVolume(fromconn, fromtid);
1634 "Failed to delete the backup volume %u on the source\n",
1638 VPRINT1("Ending transaction on backup volume %u on source ...",
1640 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1645 "Failed to end the transaction on the backup volume %u on the source\n",
1649 code = 0; /* no backup volume? that's okay */
1652 if (!(flags & RV_NOCLONE)) {
1653 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1655 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1658 "Failed to start a transaction on the cloned volume%u\n",
1662 /* now delete the clone */
1663 VPRINT1("Deleting the cloned volume %u ...", newVol);
1664 code = AFSVolDeleteVolume(fromconn, clonetid);
1665 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1669 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1670 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1675 "Failed to end the transaction on the cloned volume %u\n",
1684 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1685 fprintf(STDOUT, "...test here (y, n)? ");
1687 fscanf(stdin, "%c", &in);
1688 fscanf(stdin, "%c", &lf); /* toss away */
1690 fprintf(STDOUT, "type control-c\n");
1692 fprintf(stdout, ".");
1697 /* or drop through */
1700 /* normal cleanup code */
1702 if (entry.flags & RO_EXISTS)
1703 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1706 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1708 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1709 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1713 " Could not release the lock on the VLDB entry for the volume %lu \n",
1714 (unsigned long)afromvol);
1722 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1724 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1725 if (code || rcode) {
1728 "Could not end transaction on the source volume %lu\n",
1729 (unsigned long)afromvol);
1731 error = (code ? code : rcode);
1737 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1738 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1739 if (code || rcode) {
1742 "Could not end transaction on the source's clone volume %lu\n",
1743 (unsigned long)newVol);
1745 error = (code ? code : rcode);
1751 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1753 code = AFSVolEndTrans(toconn, totid, &rcode);
1757 "Could not end transaction on destination volume %lu\n",
1758 (unsigned long)afromvol);
1760 error = (code ? code : rcode);
1766 #ifdef ENABLE_BUGFIX_1165
1771 rx_DestroyConnection(fromconn);
1773 rx_DestroyConnection(toconn);
1774 PrintError("", error);
1777 /* come here only when the sky falls */
1782 "vos move: operation interrupted, cleanup in progress...\n");
1783 fprintf(STDOUT, "clear transaction contexts\n");
1787 /* unlock VLDB entry */
1789 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1790 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1791 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1797 VPRINT("Recovery: Ending transaction on clone volume ...");
1798 AFSVolEndTrans(fromconn, clonetid, &rcode);
1802 VPRINT("Recovery: Ending transaction on destination volume ...");
1803 AFSVolEndTrans(toconn, totid, &rcode);
1806 if (fromtid) { /* put it on-line */
1807 VPRINT("Recovery: Setting volume flags on source volume ...");
1808 AFSVolSetFlags(fromconn, fromtid, 0);
1811 VPRINT("Recovery: Ending transaction on source volume ...");
1812 AFSVolEndTrans(fromconn, fromtid, &rcode);
1816 VPRINT("Recovery: Accessing VLDB.\n");
1817 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1819 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1823 MapHostToNetwork(&entry);
1825 /* Delete either the volume on the source location or the target location.
1826 * If the vldb entry still points to the source location, then we know the
1827 * volume move didn't finish so we remove the volume from the target
1828 * location. Otherwise, we remove the volume from the source location.
1830 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1833 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1837 if (volid && toconn) {
1839 ("Recovery: Creating transaction for destination volume %u ...",
1842 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1848 ("Recovery: Setting flags on destination volume %u ...",
1850 AFSVolSetFlags(toconn, totid,
1851 VTDeleteOnSalvage | VTOutOfService);
1854 VPRINT1("Recovery: Deleting destination volume %u ...",
1856 AFSVolDeleteVolume(toconn, totid);
1860 ("Recovery: Ending transaction on destination volume %u ...",
1862 AFSVolEndTrans(toconn, totid, &rcode);
1866 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1871 /* put source volume on-line */
1873 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1876 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1881 VPRINT1("Recovery: Setting flags on source volume %u ...",
1883 AFSVolSetFlags(fromconn, fromtid, 0);
1887 ("Recovery: Ending transaction on source volume %u ...",
1889 AFSVolEndTrans(fromconn, fromtid, &rcode);
1893 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1897 } else { /* yep, move complete */
1900 "move complete - attempt cleanup of source partition - no guarantee\n");
1904 /* delete backup volume */
1906 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1909 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1914 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1916 AFSVolSetFlags(fromconn, fromtid,
1917 VTDeleteOnSalvage | VTOutOfService);
1920 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1921 AFSVolDeleteVolume(fromconn, fromtid);
1925 ("Recovery: Ending transaction on backup volume %u ...",
1927 AFSVolEndTrans(fromconn, fromtid, &rcode);
1931 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1935 /* delete source volume */
1936 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1939 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1944 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1946 AFSVolSetFlags(fromconn, fromtid,
1947 VTDeleteOnSalvage | VTOutOfService);
1950 if (atoserver != afromserver) {
1951 VPRINT("Recovery: Setting volume forwarding pointer ...");
1952 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1956 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1957 AFSVolDeleteVolume(fromconn, fromtid);
1961 ("Recovery: Ending transaction on source volume %u ...",
1963 AFSVolEndTrans(fromconn, fromtid, &rcode);
1967 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1973 /* common cleanup - delete local clone */
1975 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1978 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1983 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1984 AFSVolDeleteVolume(fromconn, clonetid);
1987 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1989 AFSVolEndTrans(fromconn, clonetid, &rcode);
1993 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1998 /* unlock VLDB entry */
2000 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
2002 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
2003 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
2007 done: /* routine cleanup */
2010 #ifdef ENABLE_BUGFIX_1165
2015 rx_DestroyConnection(fromconn);
2017 rx_DestroyConnection(toconn);
2020 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2028 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2029 afs_int32 atoserver, afs_int32 atopart)
2031 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2032 atoserver, atopart, 0);
2036 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2037 * <atopart>. The new volume is named by <atovolname>. The new volume
2038 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2039 * from the VLDB. the following flags are supported:
2041 * RV_RDONLY - target volume is RO
2042 * RV_OFFLINE - leave target volume offline
2043 * RV_CPINCR - do incremental dump if target exists
2044 * RV_NOVLDB - don't create/update VLDB entry
2045 * RV_NOCLONE - don't use a copy clone
2048 UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2049 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2050 afs_int32 atovolid, int flags)
2052 struct rx_connection *toconn, *fromconn;
2053 afs_int32 fromtid, totid, clonetid;
2056 afs_int32 fromDate, cloneFromDate;
2057 struct restoreCookie cookie;
2058 register afs_int32 vcode, code;
2059 afs_int32 cloneVol, newVol, volflag;
2060 struct volser_status tstatus;
2061 struct destServer destination;
2063 struct nvldbentry entry, newentry, storeEntry;
2069 fromconn = (struct rx_connection *)0;
2070 toconn = (struct rx_connection *)0;
2078 /* support control-c processing */
2081 (void)signal(SIGINT, sigint_handler);
2083 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2084 EGOTO1(mfail, vcode,
2085 "Could not fetch the entry for the volume %u from the VLDB \n",
2087 MapHostToNetwork(&entry);
2090 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2091 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2092 fromtid = totid = 0; /* initialize to uncreated */
2095 /* check if we can shortcut and use a local clone instead of a full copy */
2096 if (afromserver == atoserver && afrompart == atopart) {
2101 * clone the read/write volume locally.
2105 if (!(flags & RV_NOCLONE)) {
2106 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2107 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2109 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2113 /* Get a clone id */
2114 VPRINT1("Allocating new volume id for clone of volume %u ...",
2117 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2118 EGOTO1(mfail, vcode,
2119 "Could not get an ID for the clone of volume %u from the VLDB\n",
2127 /* Get a new volume id */
2128 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2130 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2131 EGOTO1(mfail, vcode,
2132 "Could not get an ID for the copy of volume %u from the VLDB\n",
2137 if (!(flags & RV_NOCLONE)) {
2138 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2139 VPRINT1("Cloning source volume %u ...", afromvol);
2140 strcpy(vname, "copy-clone-temp");
2142 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2144 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2148 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2150 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2155 "Failed to end the transaction on the source volume %u\n",
2161 * Create the destination volume
2164 if (!(flags & RV_NOCLONE)) {
2165 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2167 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2170 "Failed to start a transaction on the cloned volume%u\n",
2174 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2176 AFSVolSetFlags(fromconn, clonetid,
2177 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2178 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2182 /* remember time from which we've dumped the volume */
2183 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2184 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2186 "Failed to get the status of the cloned volume %u\n",
2190 fromDate = CLOCKADJ(tstatus.creationDate);
2195 /* create a volume on the target machine */
2197 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2199 if ((flags & RV_CPINCR)) {
2200 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2201 code = AFSVolGetStatus(toconn, totid, &tstatus);
2203 "Failed to get the status of the pre-existing volume %u\n",
2207 /* Using the update date should be OK here, but add some fudge */
2208 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2209 if ((flags & RV_NOCLONE))
2210 fromDate = cloneFromDate;
2212 /* XXX We should check that the source volume's creationDate is
2213 * XXX not newer than the existing target volume, and if not,
2214 * XXX throw away the existing target and do a full dump. */
2219 /* Delete the existing volume.
2220 * While we are deleting the volume in these steps, the transaction
2221 * we started against the cloned volume (clonetid above) will be
2222 * sitting idle. It will get cleaned up after 600 seconds
2224 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2225 code = AFSVolDeleteVolume(toconn, totid);
2227 "Could not delete the pre-existing volume %u on destination\n",
2232 ("Ending transaction on pre-existing volume %u on destination ...",
2234 code = AFSVolEndTrans(toconn, totid, &rcode);
2239 "Could not end the transaction on pre-existing volume %u on destination\n",
2244 VPRINT1("Creating the destination volume %u ...", newVol);
2246 AFSVolCreateVolume(toconn, atopart, atovolname,
2247 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2248 newVol, &newVol, &totid);
2249 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2253 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2255 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2257 "Failed to set the flags on the destination volume %u\n", newVol);
2262 destination.destHost = ntohl(atoserver);
2263 destination.destPort = AFSCONF_VOLUMEPORT;
2264 destination.destSSID = 1;
2266 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2267 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2272 * Now dump the clone to the new volume
2275 if (!(flags & RV_NOCLONE)) {
2276 /* XXX probably should have some code here that checks to see if
2277 * XXX we are copying to same server and partition - if so, just
2278 * XXX use a clone to save disk space */
2280 /* Copy the clone to the new volume */
2281 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2284 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2286 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2290 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2291 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2296 "Failed to end the transaction on the cloned volume %u\n",
2302 * reattach to the main-line volume, and incrementally dump it.
2305 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2306 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2308 "Failed to create a transaction on the source volume %u\n",
2312 /* now do the incremental */
2314 ("Doing the%s dump from source to destination for volume %u ... ",
2315 (flags & RV_NOCLONE) ? "" : " incremental",
2318 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2321 "Failed to do the%s dump from old site to new site\n",
2325 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2326 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2327 code = AFSVolSetFlags(toconn, totid, volflag);
2329 "Failed to set the flags to make destination volume online\n");
2332 /* put new volume online */
2333 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2334 code = AFSVolEndTrans(toconn, totid, &rcode);
2339 "Failed to end the transaction on the destination volume %u\n",
2343 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2344 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2349 "Failed to end the transaction on the source volume %u\n",
2355 if (!(flags & RV_NOCLONE)) {
2356 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2358 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2361 "Failed to start a transaction on the cloned volume%u\n",
2365 /* now delete the clone */
2366 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2367 code = AFSVolDeleteVolume(fromconn, clonetid);
2368 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2372 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2373 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2378 "Failed to end the transaction on the cloned volume %u\n",
2383 if (!(flags & RV_NOVLDB)) {
2384 /* create the vldb entry for the copied volume */
2385 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2386 newentry.nServers = 1;
2387 newentry.serverNumber[0] = atoserver;
2388 newentry.serverPartition[0] = atopart;
2389 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2390 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2391 newentry.volumeId[RWVOL] = newVol;
2392 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2393 newentry.volumeId[BACKVOL] = 0;
2394 newentry.cloneId = 0;
2395 /*map into right byte order, before passing to xdr, the stuff has to be in host
2396 * byte order. Xdr converts it into network order */
2397 MapNetworkToHost(&newentry, &storeEntry);
2398 /* create the vldb entry */
2399 vcode = VLDB_CreateEntry(&storeEntry);
2402 "Could not create a VLDB entry for the volume %s %lu\n",
2403 atovolname, (unsigned long)newVol);
2404 /*destroy the created volume */
2405 VPRINT1("Deleting the newly created volume %u\n", newVol);
2406 AFSVolDeleteVolume(toconn, totid);
2410 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2414 /* normal cleanup code */
2417 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2419 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2420 if (code || rcode) {
2423 "Could not end transaction on the source volume %lu\n",
2424 (unsigned long)afromvol);
2426 error = (code ? code : rcode);
2432 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2434 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2435 if (code || rcode) {
2438 "Could not end transaction on the source's clone volume %lu\n",
2439 (unsigned long)cloneVol);
2441 error = (code ? code : rcode);
2447 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2449 code = AFSVolEndTrans(toconn, totid, &rcode);
2453 "Could not end transaction on destination volume %lu\n",
2454 (unsigned long)newVol);
2456 error = (code ? code : rcode);
2461 rx_DestroyConnection(fromconn);
2463 rx_DestroyConnection(toconn);
2464 PrintError("", error);
2467 /* come here only when the sky falls */
2472 "vos copy: operation interrupted, cleanup in progress...\n");
2473 fprintf(STDOUT, "clear transaction contexts\n");
2478 VPRINT("Recovery: Ending transaction on clone volume ...");
2479 AFSVolEndTrans(fromconn, clonetid, &rcode);
2483 VPRINT("Recovery: Ending transaction on destination volume ...");
2484 AFSVolEndTrans(toconn, totid, &rcode);
2487 if (fromtid) { /* put it on-line */
2488 VPRINT("Recovery: Ending transaction on source volume ...");
2489 AFSVolEndTrans(fromconn, fromtid, &rcode);
2493 VPRINT("Recovery: Accessing VLDB.\n");
2494 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2496 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2500 MapHostToNetwork(&entry);
2502 /* common cleanup - delete local clone */
2504 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2507 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2512 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2513 AFSVolDeleteVolume(fromconn, clonetid);
2516 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2518 AFSVolEndTrans(fromconn, clonetid, &rcode);
2522 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2527 done: /* routine cleanup */
2529 rx_DestroyConnection(fromconn);
2531 rx_DestroyConnection(toconn);
2534 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2542 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2543 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2545 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2546 atovolname, atoserver, atopart, 0, 0);
2551 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2552 * if one already exists, update it
2556 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2558 struct rx_connection *aconn = (struct rx_connection *)0;
2559 afs_int32 ttid = 0, btid = 0;
2561 afs_int32 code = 0, rcode = 0;
2562 char vname[VOLSER_MAXVOLNAME + 1];
2563 struct nvldbentry entry, storeEntry;
2564 afs_int32 error = 0;
2565 int vldblocked = 0, vldbmod = 0, backexists = 1;
2567 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2569 /* the calls to VLDB will succeed only if avolid is a RW volume,
2570 * since we are following the RW hash chain for searching */
2571 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2574 "Could not fetch the entry for the volume %lu from the VLDB \n",
2575 (unsigned long)avolid);
2579 MapHostToNetwork(&entry);
2581 /* These operations require the VLDB be locked since it means the VLDB
2582 * will change or the vldb is already locked.
2584 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2585 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2586 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2588 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2591 "Could not lock the VLDB entry for the volume %lu\n",
2592 (unsigned long)avolid);
2598 /* Reread the vldb entry */
2599 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2602 "Could not fetch the entry for the volume %lu from the VLDB \n",
2603 (unsigned long)avolid);
2607 MapHostToNetwork(&entry);
2610 if (!ISNAMEVALID(entry.name)) {
2611 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2613 error = VOLSERBADNAME;
2617 backupID = entry.volumeId[BACKVOL];
2618 if (backupID == INVALID_BID) {
2619 /* Get a backup volume id from the VLDB and update the vldb
2622 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2625 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2626 (unsigned long)avolid);
2630 entry.volumeId[BACKVOL] = backupID;
2634 /* Test to see if the backup volume exists by trying to create
2635 * a transaction on the backup volume. We've assumed the backup exists.
2637 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2639 if (code != VNOVOL) {
2640 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2641 (unsigned long)backupID);
2645 backexists = 0; /* backup volume does not exist */
2648 code = AFSVolEndTrans(aconn, btid, &rcode);
2650 if (code || rcode) {
2652 "Could not end transaction on the previous backup volume %lu\n",
2653 (unsigned long)backupID);
2654 error = (code ? code : rcode);
2659 /* Now go ahead and try to clone the RW volume.
2660 * First start a transaction on the RW volume
2662 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2664 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2665 (unsigned long)avolid);
2670 /* Clone or reclone the volume, depending on whether the backup
2671 * volume exists or not
2674 VPRINT1("Re-cloning backup volume %u ...", backupID);
2676 code = AFSVolReClone(aconn, ttid, backupID);
2678 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2679 (unsigned long)backupID);
2684 VPRINT1("Creating a new backup clone %u ...", backupID);
2686 strcpy(vname, entry.name);
2687 strcat(vname, ".backup");
2689 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2691 fprintf(STDERR, "Failed to clone the volume %lu\n",
2692 (unsigned long)avolid);
2698 /* End the transaction on the RW volume */
2699 code = AFSVolEndTrans(aconn, ttid, &rcode);
2701 if (code || rcode) {
2703 "Failed to end the transaction on the rw volume %lu\n",
2704 (unsigned long)avolid);
2705 error = (code ? code : rcode);
2709 /* Mork vldb as backup exists */
2710 if (!(entry.flags & BACK_EXISTS)) {
2711 entry.flags |= BACK_EXISTS;
2715 /* Now go back to the backup volume and bring it on line */
2716 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2719 "Failed to start a transaction on the backup volume %lu\n",
2720 (unsigned long)backupID);
2725 code = AFSVolSetFlags(aconn, btid, 0);
2727 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2728 (unsigned long)backupID);
2733 code = AFSVolEndTrans(aconn, btid, &rcode);
2735 if (code || rcode) {
2737 "Failed to end the transaction on the backup volume %lu\n",
2738 (unsigned long)backupID);
2739 error = (code ? code : rcode);
2745 /* Will update the vldb below */
2749 code = AFSVolEndTrans(aconn, ttid, &rcode);
2750 if (code || rcode) {
2751 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2752 (unsigned long)avolid);
2754 error = (code ? code : rcode);
2759 code = AFSVolEndTrans(aconn, btid, &rcode);
2760 if (code || rcode) {
2762 "Could not end transaction the backup volume %lu\n",
2763 (unsigned long)backupID);
2765 error = (code ? code : rcode);
2769 /* Now update the vldb - if modified */
2772 MapNetworkToHost(&entry, &storeEntry);
2774 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2775 (LOCKREL_OPCODE | LOCKREL_AFSID |
2776 LOCKREL_TIMESTAMP));
2779 "Could not update the VLDB entry for the volume %lu \n",
2780 (unsigned long)avolid);
2786 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2787 (LOCKREL_OPCODE | LOCKREL_AFSID |
2788 LOCKREL_TIMESTAMP));
2791 "Could not unlock the VLDB entry for the volume %lu \n",
2792 (unsigned long)avolid);
2800 rx_DestroyConnection(aconn);
2802 PrintError("", error);
2806 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2807 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2808 * The new volume is named by <aname>, or by appending ".clone" to
2809 * the existing name if <aname> is NULL. The following flags are
2812 * RV_RDONLY - target volume is RO
2813 * RV_OFFLINE - leave target volume offline
2817 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
2818 afs_int32 acloneid, char *aname, int flags)
2820 struct rx_connection *aconn = (struct rx_connection *)0;
2821 afs_int32 ttid = 0, btid = 0;
2822 afs_int32 code = 0, rcode = 0;
2823 char vname[VOLSER_MAXVOLNAME + 1];
2824 afs_int32 error = 0;
2826 volEntries volumeInfo;
2828 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2831 volumeInfo.volEntries_val = (volintInfo *) 0;
2832 volumeInfo.volEntries_len = 0;
2833 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2835 fprintf(stderr, "Could not get info for volume %lu\n",
2836 (unsigned long)avolid);
2840 strncpy(vname, volumeInfo.volEntries_val[0].name,
2841 VOLSER_OLDMAXVOLNAME - 7);
2842 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2843 strcat(vname, ".clone");
2845 if (volumeInfo.volEntries_val)
2846 free(volumeInfo.volEntries_val);
2850 /* Get a clone id */
2851 VPRINT1("Allocating new volume id for clone of volume %u ...",
2853 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2855 "Could not get an ID for the clone of volume %u from the VLDB\n",
2860 /* Test to see if the clone volume exists by trying to create
2861 * a transaction on the clone volume. We've assumed the clone exists.
2863 /* XXX I wonder what happens if the clone has some other parent... */
2864 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2866 if (code != VNOVOL) {
2867 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2868 (unsigned long)acloneid);
2872 backexists = 0; /* backup volume does not exist */
2875 code = AFSVolEndTrans(aconn, btid, &rcode);
2877 if (code || rcode) {
2879 "Could not end transaction on the previous clone volume %lu\n",
2880 (unsigned long)acloneid);
2881 error = (code ? code : rcode);
2886 /* Now go ahead and try to clone the RW volume.
2887 * First start a transaction on the RW volume
2889 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2891 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2892 (unsigned long)avolid);
2897 /* Clone or reclone the volume, depending on whether the backup
2898 * volume exists or not
2901 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2903 code = AFSVolReClone(aconn, ttid, acloneid);
2905 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2906 (unsigned long)acloneid);
2911 VPRINT1("Creating a new clone %u ...", acloneid);
2913 code = AFSVolClone(aconn, ttid, 0,
2914 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2917 fprintf(STDERR, "Failed to clone the volume %lu\n",
2918 (unsigned long)avolid);
2924 /* End the transaction on the RW volume */
2925 code = AFSVolEndTrans(aconn, ttid, &rcode);
2927 if (code || rcode) {
2929 "Failed to end the transaction on the rw volume %lu\n",
2930 (unsigned long)avolid);
2931 error = (code ? code : rcode);
2935 /* Now go back to the backup volume and bring it on line */
2936 if (!(flags & RV_OFFLINE)) {
2937 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2940 "Failed to start a transaction on the clone volume %lu\n",
2941 (unsigned long)acloneid);
2946 code = AFSVolSetFlags(aconn, btid, 0);
2948 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2949 (unsigned long)acloneid);
2954 code = AFSVolEndTrans(aconn, btid, &rcode);
2956 if (code || rcode) {
2958 "Failed to end the transaction on the clone volume %lu\n",
2959 (unsigned long)acloneid);
2960 error = (code ? code : rcode);
2969 code = AFSVolEndTrans(aconn, ttid, &rcode);
2970 if (code || rcode) {
2971 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2972 (unsigned long)avolid);
2974 error = (code ? code : rcode);
2979 code = AFSVolEndTrans(aconn, btid, &rcode);
2980 if (code || rcode) {
2982 "Could not end transaction on the clone volume %lu\n",
2983 (unsigned long)acloneid);
2985 error = (code ? code : rcode);
2990 rx_DestroyConnection(aconn);
2992 PrintError("", error);
2997 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
3000 afs_int32 acode, ccode, rcode, tid;
3001 ccode = rcode = tid = 0;
3003 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
3004 if (!acode) { /* It really was there */
3005 acode = AFSVolDeleteVolume(conn, tid);
3007 fprintf(STDERR, "Failed to delete volume %lu.\n",
3008 (unsigned long)vid);
3009 PrintError("", acode);
3011 ccode = AFSVolEndTrans(conn, tid, &rcode);
3015 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
3016 (unsigned long)vid);
3017 PrintError("", ccode);
3024 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3025 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3027 /* Get a "transaction" on this replica. Create the volume
3028 * if necessary. Return the time from which a dump should
3029 * be made (0 if it's a new volume)
3032 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3033 struct rx_connection **connPtr, afs_int32 * transPtr,
3034 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3037 struct volser_status tstatus;
3038 int code, rcode, tcode;
3041 *connPtr = (struct rx_connection *)0;
3046 /* get connection to the replication site */
3047 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3049 goto fail; /* server is down */
3051 volid = vldbEntryPtr->volumeId[ROVOL];
3054 AFSVolTransCreate(*connPtr, volid,
3055 vldbEntryPtr->serverPartition[index], ITOffline,
3058 /* If the volume does not exist, create it */
3059 if (!volid || code) {
3063 if (volid && (code != VNOVOL)) {
3064 PrintError("Failed to start a transaction on the RO volume.\n",
3069 strcpy(volname, vldbEntryPtr->name);
3070 strcat(volname, ".readonly");
3074 "Creating new volume %lu on replication site %s: ",
3075 (unsigned long)volid,
3076 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3077 serverNumber[index], hoststr) :
3078 hostutil_GetNameByINet(vldbEntryPtr->
3079 serverNumber[index]));
3084 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3086 vldbEntryPtr->volumeId[RWVOL], &volid,
3089 PrintError("Failed to create the ro volume: ", code);
3092 vldbEntryPtr->volumeId[ROVOL] = volid;
3096 /* The following is a bit redundant, since create sets these flags by default */
3098 AFSVolSetFlags(*connPtr, *transPtr,
3099 VTDeleteOnSalvage | VTOutOfService);
3101 PrintError("Failed to set flags on the ro volume: ", code);
3106 /* Otherwise, the transaction did succeed, so get the creation date of the
3107 * latest RO volume on the replication site
3110 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3111 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
3112 serverNumber[index], hoststr) :
3113 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3115 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3117 PrintError("Failed to get status of volume on destination: ",
3121 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3122 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3129 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3134 PrintError("Could not end transaction on a ro volume: ", tcode);
3141 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3142 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3143 void *cookie, manyResults * results)
3147 for (i = 0; i < tr->manyDests_len; i++) {
3148 results->manyResults_val[i] =
3149 AFSVolForward(fromconn, fromtid, fromdate,
3150 &(tr->manyDests_val[i].server),
3151 tr->manyDests_val[i].trans, cookie);
3157 /* UV_ReleaseVolume()
3158 * Release volume <afromvol> on <afromserver> <afrompart> to all
3159 * its RO sites (full release). Unless the previous release was
3160 * incomplete: in which case we bring the remaining incomplete
3161 * volumes up to date with the volumes that were released
3163 * forceflag: Performs a full release.
3165 * Will create a clone from the RW, then dump the clone out to
3166 * the remaining replicas. If there is more than 1 RO sites,
3167 * ensure that the VLDB says at least one RO is available all
3168 * the time: Influences when we write back the VLDB entry.
3172 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
3173 afs_int32 afrompart, int forceflag)
3176 afs_int32 code, vcode, rcode, tcode;
3177 afs_int32 cloneVolId, roVolId;
3178 struct replica *replicas = 0;
3179 struct nvldbentry entry, storeEntry;
3180 int i, volcount, m, fullrelease, vldbindex;
3182 struct restoreCookie cookie;
3183 struct rx_connection **toconns = 0;
3184 struct release *times = 0;
3186 struct rx_connection *fromconn = (struct rx_connection *)0;
3187 afs_int32 error = 0;
3189 afs_int32 clonetid = 0, onlinetid;
3190 afs_int32 fromtid = 0;
3191 afs_uint32 fromdate, thisdate;
3195 manyResults results;
3196 int rwindex, roindex, roclone, roexists;
3197 afs_int32 rwcrdate, rwupdate, clcrdate;
3201 } remembertime[NMAXNSERVERS];
3202 int releasecount = 0;
3203 struct volser_status volstatus;
3206 memset((char *)remembertime, 0, sizeof(remembertime));
3207 memset((char *)&results, 0, sizeof(results));
3209 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3210 if (vcode != VL_RERELEASE)
3211 ONERROR(vcode, afromvol,
3212 "Could not lock the VLDB entry for the volume %u.\n");
3215 /* Get the vldb entry in readable format */
3216 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3217 ONERROR(vcode, afromvol,
3218 "Could not fetch the entry for the volume %u from the VLDB.\n");
3219 MapHostToNetwork(&entry);
3222 EnumerateEntry(&entry);
3224 if (!ISNAMEVALID(entry.name))
3225 ONERROR(VOLSERBADOP, entry.name,
3226 "Volume name %s is too long, rename before releasing.\n");
3227 if (entry.volumeId[RWVOL] != afromvol)
3228 ONERROR(VOLSERBADOP, afromvol,
3229 "The volume %u being released is not a read-write volume.\n");
3230 if (entry.nServers <= 1)
3231 ONERROR(VOLSERBADOP, afromvol,
3232 "Volume %u has no replicas - release operation is meaningless!\n");
3233 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3234 ONERROR(VOLSERBADOP, entry.name,
3235 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3237 /* roclone is true if one of the RO volumes is on the same
3238 * partition as the RW volume. In this case, we make the RO volume
3239 * on the same partition a clone instead of a complete copy.
3242 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3243 roclone = ((roindex == -1) ? 0 : 1);
3244 rwindex = Lp_GetRwIndex(&entry);
3246 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3248 /* Make sure we have a RO volume id to work with */
3249 if (entry.volumeId[ROVOL] == INVALID_BID) {
3250 /* need to get a new RO volume id */
3251 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3252 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3254 entry.volumeId[ROVOL] = roVolId;
3255 MapNetworkToHost(&entry, &storeEntry);
3256 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3257 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3260 /* Will we be completing a previously unfinished release. -force overrides */
3261 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3262 if (entry.serverFlags[i] & ITSROVOL) {
3264 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3267 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3270 /* Determine which volume id to use and see if it exists */
3273 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3274 code = VolumeExists(afromserver, afrompart, cloneVolId);
3275 roexists = ((code == ENODEV) ? 0 : 1);
3277 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3279 ONERROR(-1, afromserver,
3280 "Cannot establish connection with server 0x%x\n");
3284 fullrelease = 1; /* Do a full release if RO clone does not exist */
3286 /* Begin transaction on RW and mark it busy while we query it */
3287 code = AFSVolTransCreate(
3288 fromconn, afromvol, afrompart, ITBusy, &fromtid
3290 ONERROR(code, afromvol,
3291 "Failed to start transaction on RW volume %u\n");
3293 /* Query the creation date for the RW */
3294 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3295 ONERROR(code, afromvol,
3296 "Failed to get the status of RW volume %u\n");
3297 rwcrdate = volstatus.creationDate;
3298 rwupdate = volstatus.updateDate;
3300 /* End transaction on RW */
3301 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3303 ONERROR((code ? code : rcode), afromvol,
3304 "Failed to end transaction on RW volume %u\n");
3306 /* Begin transaction on clone and mark it busy while we query it */
3307 code = AFSVolTransCreate(
3308 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3310 ONERROR(code, cloneVolId,
3311 "Failed to start transaction on RW clone %u\n");
3313 /* Query the creation date for the clone */
3314 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3315 ONERROR(code, cloneVolId,
3316 "Failed to get the status of RW clone %u\n");
3317 clcrdate = volstatus.creationDate;
3319 /* End transaction on clone */
3320 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3322 ONERROR((code ? code : rcode), cloneVolId,
3323 "Failed to end transaction on RW clone %u\n");
3325 if (rwcrdate > clcrdate)
3326 fullrelease = 2;/* Do a full release if RO clone older than RW */
3331 switch (fullrelease) {
3333 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3334 (unsigned long)afromvol);
3337 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3338 (unsigned long)afromvol);
3341 fprintf(STDOUT, "This is a completion of a previous release\n");
3347 /* If the RO clone exists, then if the clone is a temporary
3348 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3349 * (it was recently added), then also delete it. We do not
3350 * want to "reclone" a temporary RO clone.
3353 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3354 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3355 if (code && (code != VNOVOL))
3360 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3361 * write this entry out to the vlserver until after the first
3362 * RO volume is released (temp RO clones don't count).
3364 for (i = 0; i < entry.nServers; i++) {
3365 entry.serverFlags[i] &= ~NEW_REPSITE;
3366 entry.serverFlags[i] |= RO_DONTUSE;
3368 entry.serverFlags[rwindex] |= NEW_REPSITE;
3369 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3371 /* Begin transaction on RW and mark it busy while we clone it */
3373 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3375 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3377 /* Clone or reclone the volume */
3379 VPRINT1("Recloning RW volume %u...", cloneVolId);
3380 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3381 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3385 strcpy(vname, entry.name);
3386 strcat(vname, ".readonly");
3387 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3389 strcpy(vname, "readonly-clone-temp");
3390 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3393 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3395 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3399 /* Get the time the RW was created for future information */
3400 VPRINT1("Getting status of RW volume %u...", afromvol);
3401 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3402 ONERROR(code, afromvol,
3403 "Failed to get the status of the RW volume %u\n");
3405 rwcrdate = volstatus.creationDate;
3406 rwupdate = volstatus.updateDate;
3408 /* End the transaction on the RW volume */
3409 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3410 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3412 ONERROR((code ? code : rcode), afromvol,
3413 "Failed to end cloning transaction on RW %u\n");
3416 /* Remember clone volume ID in case we fail or are interrupted */
3417 entry.cloneId = cloneVolId;
3420 /* Bring the RO clone online - though not if it's a temporary clone */
3421 VPRINT1("Starting transaction on RO clone volume %u...",
3424 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3426 ONERROR(code, cloneVolId,
3427 "Failed to start transaction on volume %u\n");
3430 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3431 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3434 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3435 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3436 ONERROR((code ? code : rcode), cloneVolId,
3437 "Failed to end transaction on RO clone %u\n");
3440 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3442 /* Sleep so that a client searching for an online volume won't
3443 * find the clone offline and then the next RO offline while the
3444 * release brings the clone online and the next RO offline (race).
3445 * There is a fix in the 3.4 client that does not need this sleep
3446 * anymore, but we don't know what clients we have.
3448 if (entry.nServers > 2)
3451 /* Mark the RO clone in the VLDB as a good site (already released) */
3452 entry.serverFlags[roindex] |= NEW_REPSITE;
3453 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3454 entry.flags |= RO_EXISTS;
3458 /* Write out the VLDB entry only if the clone is not a temporary
3459 * clone. If we did this to a temporary clone then we would end
3460 * up marking all the ROs as "old release" making the ROs
3461 * temporarily unavailable.
3463 MapNetworkToHost(&entry, &storeEntry);
3464 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3465 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3466 ONERROR(vcode, entry.name,
3467 "Could not update vldb entry for %s.\n");
3472 /* Now we will release from the clone to the remaining RO replicas.
3473 * The first 2 ROs (counting the non-temporary RO clone) are released
3474 * individually: releasecount. This is to reduce the race condition
3475 * of clients trying to find an on-line RO volume. The remaining ROs
3476 * are released in parallel but no more than half the number of ROs
3477 * (rounded up) at a time: nservers.
3480 strcpy(vname, entry.name);
3481 strcat(vname, ".readonly");
3482 memset(&cookie, 0, sizeof(cookie));
3483 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3484 cookie.type = ROVOL;
3485 cookie.parent = entry.volumeId[RWVOL];
3488 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3490 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3491 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3493 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3495 results.manyResults_val =
3496 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3497 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3499 "Failed to create transaction on the release clone\n");
3501 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3502 memset(times, 0, (sizeof(struct release) * nservers + 1));
3503 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3504 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3506 /* Create a transaction on the cloned volume */
3507 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3509 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3510 if (!fullrelease && code)
3511 ONERROR(VOLSERNOVOL, afromvol,
3512 "Old clone is inaccessible. Try vos release -f %u.\n");
3513 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3516 /* For each index in the VLDB */
3517 for (vldbindex = 0; vldbindex < entry.nServers;) {
3519 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3521 ((volcount < nservers) && (vldbindex < entry.nServers));
3523 /* The first two RO volumes will be released individually.
3524 * The rest are then released in parallel. This is a hack
3525 * for clients not recognizing right away when a RO volume
3526 * comes back on-line.
3528 if ((volcount == 1) && (releasecount < 2))
3531 if (vldbindex == roindex)
3532 continue; /* the clone */
3533 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3534 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3536 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3537 continue; /* not a RO vol */
3540 /* Get a Transaction on this replica. Get a new connection if
3541 * necessary. Create the volume if necessary. Return the
3542 * time from which the dump should be made (0 if it's a new
3543 * volume). Each volume might have a different time.
3545 replicas[volcount].server.destHost =
3546 ntohl(entry.serverNumber[vldbindex]);
3547 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3548 replicas[volcount].server.destSSID = 1;
3549 times[volcount].vldbEntryIndex = vldbindex;
3552 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3553 &(replicas[volcount].trans),
3554 &(times[volcount].crtime),
3555 &(times[volcount].uptime));
3559 /* Thisdate is the date from which we want to pick up all changes */
3560 if (forceflag || !fullrelease
3561 || (rwcrdate > times[volcount].crtime)) {
3562 /* If the forceflag is set, then we want to do a full dump.
3563 * If it's not a full release, we can't be sure that the creation
3564 * date is good (so we also do a full dump).
3565 * If the RW volume was replaced (its creation date is newer than
3566 * the last release), then we can't be sure what has changed (so
3567 * we do a full dump).
3570 } else if (remembertime[vldbindex].validtime) {
3571 /* Trans was prev ended. Use the time from the prev trans
3572 * because, prev trans may have created the volume. In which
3573 * case time[volcount].time would be now instead of 0.
3576 (remembertime[vldbindex].uptime < times[volcount].uptime)
3577 ? remembertime[vldbindex].uptime
3578 : times[volcount].uptime;
3580 thisdate = times[volcount].uptime;
3582 remembertime[vldbindex].validtime = 1;
3583 remembertime[vldbindex].uptime = thisdate;
3585 if (volcount == 0) {
3586 fromdate = thisdate;
3588 /* Include this volume if it is within 15 minutes of the earliest */
3590 thisdate) ? (fromdate - thisdate) : (thisdate -
3592 AFSVolEndTrans(toconns[volcount],
3593 replicas[volcount].trans, &rcode);
3594 replicas[volcount].trans = 0;
3597 if (thisdate < fromdate)
3598 fromdate = thisdate;
3606 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3607 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3608 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0].
3609 vldbEntryIndex], hoststr) :
3610 hostutil_GetNameByINet(entry.
3611 serverNumber[times[0].
3614 for (s = 1; s < volcount; s++) {
3615 fprintf(STDOUT, " and %s",
3616 noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s].
3617 vldbEntryIndex], hoststr) :
3618 hostutil_GetNameByINet(entry.
3619 serverNumber[times[s].
3624 fprintf(STDOUT, " (full release)");
3627 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3629 fprintf(STDOUT, ".\n");
3633 /* Release the ones we have collected */
3634 tr.manyDests_val = &(replicas[0]);
3635 tr.manyDests_len = results.manyResults_len = volcount;
3637 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3638 0 /*spare */ , &cookie, &results);
3639 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3641 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3642 0 /*spare */ , &cookie, &results);
3647 PrintError("Release failed: ", code);
3649 for (m = 0; m < volcount; m++) {
3650 if (results.manyResults_val[m]) {
3651 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3652 /* we retry timed out transaction. When it is
3653 * not the first volume and the transaction wasn't found
3654 * (assume it timed out and was garbage collected by volser).
3657 ("Failed to dump volume from clone to a ro site: ",
3658 results.manyResults_val[m]);
3664 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3665 ROVOL, entry.volumeId[RWVOL], 0, 0);
3667 if ((m == 0) || (code != ENOENT)) {
3668 PrintError("Failed to set correct names and ids: ",
3674 /* have to clear dest. flags to ensure new vol goes online:
3675 * because the restore (forwarded) operation copied
3676 * the V_inService(=0) flag over to the destination.
3678 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3680 if ((m == 0) || (code != ENOENT)) {
3681 PrintError("Failed to set flags on ro volume: ",
3687 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3688 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3689 entry.flags |= RO_EXISTS;
3694 /* End the transactions and destroy the connections */
3695 for (s = 0; s < volcount; s++) {
3696 if (replicas[s].trans)
3697 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3698 replicas[s].trans = 0;
3702 if ((s == 0) || (code != ENOENT)) {
3703 PrintError("Could not end transaction on a ro volume: ",
3707 ("Transaction timed out on a ro volume. Will retry.\n",
3709 if (times[s].vldbEntryIndex < vldbindex)
3710 vldbindex = times[s].vldbEntryIndex;
3715 rx_DestroyConnection(toconns[s]);
3719 MapNetworkToHost(&entry, &storeEntry);
3720 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3721 ONERROR(vcode, afromvol,
3722 " Could not update VLDB entry for volume %u\n");
3723 } /* for each index in the vldb */
3725 /* End the transaction on the cloned volume */
3726 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3731 PrintError("Failed to end transaction on rw volume: ", code);
3733 /* Figure out if any volume were not released and say so */
3734 for (failure = 0, i = 0; i < entry.nServers; i++) {
3735 if (!(entry.serverFlags[i] & NEW_REPSITE))
3741 "The volume %lu could not be released to the following %d sites:\n",
3742 (unsigned long)afromvol, failure);
3743 for (i = 0; i < entry.nServers; i++) {
3744 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3745 MapPartIdIntoName(entry.serverPartition[i], pname);
3746 fprintf(STDERR, "\t%35s %s\n",
3747 noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) :
3748 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3752 MapNetworkToHost(&entry, &storeEntry);
3754 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3756 ONERROR(vcode, afromvol,
3757 " Could not update VLDB entry for volume %u\n");
3759 ERROREXIT(VOLSERBADRELEASE);
3762 /* All the ROs were release successfully. Remove the temporary clone */
3765 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3766 (unsigned long)cloneVolId);
3769 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3770 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3775 for (i = 0; i < entry.nServers; i++)
3776 entry.serverFlags[i] &= ~NEW_REPSITE;
3778 /* Update the VLDB */
3779 VPRINT("updating VLDB ...");
3781 MapNetworkToHost(&entry, &storeEntry);
3783 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3784 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3785 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3790 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3794 "Failed to end cloning transaction on the RW volume %lu\n",
3795 (unsigned long)afromvol);
3801 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3805 "Failed to end transaction on the release clone %lu\n",
3806 (unsigned long)cloneVolId);
3811 for (i = 0; i < nservers; i++) {
3812 if (replicas && replicas[i].trans) {
3813 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3814 replicas[i].trans = 0;
3817 "Failed to end transaction on ro volume %u at server %s\n",
3818 entry.volumeId[ROVOL],
3819 noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.
3820 destHost), hoststr) :
3821 hostutil_GetNameByINet(htonl
3822 (replicas[i].server.destHost)));
3827 if (toconns && toconns[i]) {
3828 rx_DestroyConnection(toconns[i]);
3834 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3835 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3838 "Could not release lock on the VLDB entry for volume %lu\n",
3839 (unsigned long)afromvol);
3845 PrintError("", error);
3848 rx_DestroyConnection(fromconn);
3849 if (results.manyResults_val)
3850 free(results.manyResults_val);
3862 dump_sig_handler(int x)
3864 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3868 /* Dump the volume <afromvol> on <afromserver> and
3869 * <afrompart> to <afilename> starting from <fromdate>.
3870 * DumpFunction does the real work behind the scenes after
3871 * extracting parameters from the rock
3874 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3875 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock,
3878 struct rx_connection *fromconn = (struct rx_connection *)0;
3879 struct rx_call *fromcall = (struct rx_call *)0;
3880 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3881 afs_int32 code, error = 0, retry = 0;
3882 time_t tmv = fromdate;
3886 #ifndef AFS_NT40_ENV
3887 (void)signal(SIGPIPE, dump_sig_handler);
3889 (void)signal(SIGINT, dump_sig_handler);
3892 VEPRINT("Full Dump ...\n");
3894 VEPRINT1("Incremental Dump (as of %.24s)...\n",
3898 /* get connections to the servers */
3899 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3901 VEPRINT1("Starting transaction on volume %u...", afromvol);
3902 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3903 EGOTO1(error_exit, code,
3904 "Could not start transaction on the volume %u to be dumped\n",
3908 fromcall = rx_NewCall(fromconn);
3910 VEPRINT1("Starting volume dump on volume %u...", afromvol);
3911 if (flags & VOLDUMPV2_OMITDIRS)
3912 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
3915 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3916 EGOTO(error_exit, code, "Could not start the dump process \n");
3919 VEPRINT1("Dumping volume %u...", afromvol);
3920 code = DumpFunction(fromcall, rock);
3921 if (code == RXGEN_OPCODE)
3923 EGOTO(error_exit, code, "Error while dumping volume \n");
3928 code = rx_EndCall(fromcall, rxError);
3929 if (code && code != RXGEN_OPCODE)
3930 fprintf(STDERR, "Error in rx_EndCall\n");
3935 VEPRINT1("Ending transaction on volume %u...", afromvol);
3936 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3937 if (code || rcode) {
3938 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3939 (unsigned long)afromvol);
3941 error = (code ? code : rcode);
3946 rx_DestroyConnection(fromconn);
3950 if (error != RXGEN_OPCODE)
3951 PrintError("", error);
3955 /* Clone the volume <afromvol> on <afromserver> and
3956 * <afrompart>, and then dump the clone volume to
3957 * <afilename> starting from <fromdate>.
3958 * DumpFunction does the real work behind the scenes after
3959 * extracting parameters from the rock
3962 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3963 afs_int32 afrompart, afs_int32 fromdate,
3964 afs_int32(*DumpFunction) (), char *rock, afs_int32 flags)
3966 struct rx_connection *fromconn = (struct rx_connection *)0;
3967 struct rx_call *fromcall = (struct rx_call *)0;
3968 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3969 afs_int32 clonetid = 0;
3970 afs_int32 code = 0, vcode = 0, error = 0;
3971 afs_int32 clonevol = 0;
3973 time_t tmv = fromdate;
3977 #ifndef AFS_NT40_ENV
3978 (void)signal(SIGPIPE, dump_sig_handler);
3980 (void)signal(SIGINT, dump_sig_handler);
3983 VEPRINT("Full Dump ...\n");
3985 VEPRINT1("Incremental Dump (as of %.24s)...\n",
3989 /* get connections to the servers */
3990 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3992 VEPRINT1("Starting transaction on volume %u...", afromvol);
3993 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3994 EGOTO1(error_exit, code,
3995 "Could not start transaction on the volume %u to be dumped\n",
3999 /* Get a clone id */
4000 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
4001 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
4002 EGOTO1(error_exit, code,
4003 "Could not get an ID for the clone of volume %u from the VLDB\n",
4007 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
4008 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
4010 strcpy(vname, "dump-clone-temp");
4012 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
4013 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
4017 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
4019 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
4023 EGOTO1(error_exit, code,
4024 "Failed to end the transaction on the volume %u\n", afromvol);
4028 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
4030 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
4032 EGOTO1(error_exit, code,
4033 "Failed to start a transaction on the cloned volume%u\n",
4037 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4038 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4039 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4044 fromcall = rx_NewCall(fromconn);
4046 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4047 if (flags & VOLDUMPV2_OMITDIRS)
4048 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4050 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4051 EGOTO(error_exit, code, "Could not start the dump process \n");
4054 VEPRINT1("Dumping volume %u...", afromvol);
4055 code = DumpFunction(fromcall, rock);
4056 EGOTO(error_exit, code, "Error while dumping volume \n");
4060 /* now delete the clone */
4061 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4062 code = AFSVolDeleteVolume(fromconn, clonetid);
4064 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4065 (unsigned long)clonevol);
4071 code = rx_EndCall(fromcall, rxError);
4073 fprintf(STDERR, "Error in rx_EndCall\n");
4079 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4080 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4081 if (code || rcode) {
4083 "Could not end transaction on the cloned volume %lu\n",
4084 (unsigned long)clonevol);
4086 error = (code ? code : rcode);
4091 rx_DestroyConnection(fromconn);
4093 PrintError("", error);
4100 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4101 * the dump file <afilename>. WriteData does all the real work
4102 * after extracting params from the rock
4105 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4106 afs_int32 toparentid, char tovolname[], int flags,
4107 afs_int32(*WriteData) (), char *rock)
4109 struct rx_connection *toconn, *tempconn;
4110 struct rx_call *tocall;
4111 afs_int32 totid, code, rcode, vcode, terror = 0;
4112 afs_int32 rxError = 0;
4113 struct volser_status tstatus;
4114 struct volintInfo vinfo;
4116 char tovolreal[VOLSER_OLDMAXVOLNAME];
4117 afs_int32 pvolid, pparentid;
4120 struct nvldbentry entry, storeEntry;
4123 struct restoreCookie cookie;
4125 afs_int32 volflag, voltype, volsertype;
4126 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4127 int index, same, errcode;
4131 memset(&cookie, 0, sizeof(cookie));
4136 tocall = (struct rx_call *)0;
4137 toconn = (struct rx_connection *)0;
4138 tempconn = (struct rx_connection *)0;
4142 if (flags & RV_RDONLY) {
4144 volsertype = volser_RO;
4147 volsertype = volser_RW;
4151 pparentid = toparentid;
4152 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4153 if (pvolid == 0) { /*alot a new id if needed */
4154 vcode = VLDB_GetEntryByName(tovolname, &entry);
4155 if (vcode == VL_NOENT) {
4156 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4158 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4164 } else if (flags & RV_RDONLY) {
4165 if (entry.flags & RW_EXISTS) {
4167 "Entry for ReadWrite volume %s already exists!\n",
4169 error = VOLSERBADOP;
4172 if (!entry.volumeId[ROVOL]) {
4174 "Existing entry for volume %s has no ReadOnly ID\n",
4176 error = VOLSERBADOP;
4179 pvolid = entry.volumeId[ROVOL];
4180 pparentid = entry.volumeId[RWVOL];
4182 pvolid = entry.volumeId[RWVOL];
4183 pparentid = entry.volumeId[RWVOL];
4186 if (!pparentid) pparentid = pvolid;
4187 /* at this point we have a volume id to use/reuse for the volume to be restored */
4188 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4190 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4191 EGOTO1(refail, VOLSERBADOP,
4192 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4195 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4196 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4197 EGOTO1(refail, VOLSERBADOP,
4198 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4200 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4203 MapPartIdIntoName(topart, partName);
4204 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4205 tovolreal, (unsigned long)pvolid,
4206 noresolve ? afs_inet_ntoa_r(toserver, hoststr) :
4207 hostutil_GetNameByINet(toserver), partName);
4210 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4213 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4214 VPRINT1("Deleting the previous volume %u ...", pvolid);
4217 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4218 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4221 code = AFSVolGetStatus(toconn, totid, &tstatus);
4222 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4225 oldCreateDate = tstatus.creationDate;
4226 oldUpdateDate = tstatus.updateDate;
4229 AFSVolSetFlags(toconn, totid,
4230 VTDeleteOnSalvage | VTOutOfService);
4231 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4234 code = AFSVolDeleteVolume(toconn, totid);
4235 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4237 code = AFSVolEndTrans(toconn, totid, &rcode);
4241 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4246 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4248 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4251 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4252 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4255 code = AFSVolGetStatus(toconn, totid, &tstatus);
4256 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4259 oldCreateDate = tstatus.creationDate;
4260 oldUpdateDate = tstatus.updateDate;
4267 cookie.parent = pparentid;
4268 cookie.type = voltype;
4270 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4272 tocall = rx_NewCall(toconn);
4273 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4275 fprintf(STDERR, "Volume restore Failed \n");
4279 code = WriteData(tocall, rock);
4281 fprintf(STDERR, "Could not transmit data\n");
4285 terror = rx_EndCall(tocall, rxError);
4286 tocall = (struct rx_call *)0;
4288 fprintf(STDERR, "rx_EndCall Failed \n");
4292 code = AFSVolGetStatus(toconn, totid, &tstatus);
4295 "Could not get status information about the volume %lu\n",
4296 (unsigned long)pvolid);
4300 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4302 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4303 (unsigned long)pvolid);
4308 if (flags & RV_CRDUMP)
4309 newCreateDate = tstatus.creationDate;
4310 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4311 newCreateDate = oldCreateDate;
4313 newCreateDate = time(0);
4314 if (flags & RV_LUDUMP)
4315 newUpdateDate = tstatus.updateDate;
4316 else if (flags & RV_LUKEEP)
4317 newUpdateDate = oldUpdateDate;
4319 newUpdateDate = time(0);
4320 code = AFSVolSetDate(toconn,totid, newCreateDate);
4322 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4327 init_volintInfo(&vinfo);
4328 vinfo.creationDate = newCreateDate;
4329 vinfo.updateDate = newUpdateDate;
4330 code = AFSVolSetInfo(toconn, totid, &vinfo);
4332 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4338 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4339 code = AFSVolSetFlags(toconn, totid, volflag);
4341 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4346 /* It isn't handled right in refail */
4347 code = AFSVolEndTrans(toconn, totid, &rcode);
4352 fprintf(STDERR, "Could not end transaction on %lu\n",
4353 (unsigned long)pvolid);
4359 fprintf(STDOUT, " done\n");
4361 if (success && (!reuseID || (flags & RV_FULLRST))) {
4362 /* Volume was restored on the file server, update the
4363 * VLDB to reflect the change.
4365 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4366 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4368 "Could not fetch the entry for volume number %lu from VLDB \n",
4369 (unsigned long)pvolid);
4374 MapHostToNetwork(&entry);
4375 if (vcode == VL_NOENT) { /* it doesnot exist already */
4376 /*make the vldb return this indication specifically */
4377 VPRINT("------- Creating a new VLDB entry ------- \n");
4378 strcpy(entry.name, tovolname);
4380 entry.serverNumber[0] = toserver; /*should be indirect */
4381 entry.serverPartition[0] = topart;
4382 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4383 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4384 if (flags & RV_RDONLY)
4385 entry.volumeId[ROVOL] = pvolid;
4386 else if (tstatus.cloneID != 0) {
4387 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4389 entry.volumeId[ROVOL] = INVALID_BID;
4390 entry.volumeId[RWVOL] = pparentid;
4392 if (tstatus.backupID != 0) {
4393 entry.volumeId[BACKVOL] = tstatus.backupID;
4394 /*this should come from status info on the volume if non zero */
4396 entry.volumeId[BACKVOL] = INVALID_BID;
4397 MapNetworkToHost(&entry, &storeEntry);
4398 vcode = VLDB_CreateEntry(&storeEntry);
4401 "Could not create the VLDB entry for volume number %lu \n",
4402 (unsigned long)pvolid);
4408 EnumerateEntry(&entry);
4409 } else { /*update the existing entry */
4411 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4412 fprintf(STDOUT, "------- Old entry -------\n");
4413 EnumerateEntry(&entry);
4414 fprintf(STDOUT, "------- New entry -------\n");
4417 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4421 "Could not lock the entry for volume number %lu \n",
4422 (unsigned long)pvolid);
4427 strcpy(entry.name, tovolname);
4429 /* Update the vlentry with the new information */
4430 if (flags & RV_RDONLY)
4431 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4433 index = Lp_GetRwIndex(&entry);
4435 /* Add the new site for the volume being restored */
4436 entry.serverNumber[entry.nServers] = toserver;
4437 entry.serverPartition[entry.nServers] = topart;
4438 entry.serverFlags[entry.nServers] =
4439 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4442 /* This volume should be deleted on the old site
4443 * if its different from new site.
4446 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4450 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4452 if ((!errcode && !same)
4453 || (entry.serverPartition[index] != topart)) {
4454 if (flags & RV_NODEL) {
4456 ("Not deleting the previous volume %u on server %s, ...",
4458 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4459 hostutil_GetNameByINet(entry.serverNumber[index]));
4462 UV_Bind(entry.serverNumber[index],
4463 AFSCONF_VOLUMEPORT);
4465 MapPartIdIntoName(entry.serverPartition[index],
4468 ("Deleting the previous volume %u on server %s, partition %s ...",
4470 noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :
4471 hostutil_GetNameByINet(entry.serverNumber[index]),
4474 AFSVolTransCreate(tempconn, pvolid,
4475 entry.serverPartition[index],
4476 ITOffline, &temptid);
4479 AFSVolSetFlags(tempconn, temptid,
4484 "Could not set flags on volume %lu on the older site\n",
4485 (unsigned long)pvolid);
4489 code = AFSVolDeleteVolume(tempconn, temptid);
4492 "Could not delete volume %lu on the older site\n",
4493 (unsigned long)pvolid);
4497 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4503 "Could not end transaction on volume %lu on the older site\n",
4504 (unsigned long)pvolid);
4509 MapPartIdIntoName(entry.serverPartition[index],
4514 entry.serverNumber[index] = toserver;
4515 entry.serverPartition[index] = topart;
4518 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4519 MapNetworkToHost(&entry, &storeEntry);
4521 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4522 LOCKREL_OPCODE | LOCKREL_AFSID |
4526 "Could not update the entry for volume number %lu \n",
4527 (unsigned long)pvolid);
4533 EnumerateEntry(&entry);
4540 code = rx_EndCall(tocall, rxError);
4546 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4547 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4550 "Could not release lock on the VLDB entry for the volume %lu\n",
4551 (unsigned long)pvolid);
4557 code = AFSVolEndTrans(toconn, totid, &rcode);
4561 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4562 (unsigned long)pvolid);
4568 code = AFSVolEndTrans(toconn, temptid, &rcode);
4572 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4573 (unsigned long)pvolid);
4579 rx_DestroyConnection(tempconn);
4581 rx_DestroyConnection(toconn);
4582 PrintError("", error);
4587 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4588 char tovolname[], int flags, afs_int32(*WriteData) (),
4591 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4596 /*unlocks the vldb entry associated with <volid> */
4598 UV_LockRelease(afs_int32 volid)
4604 VPRINT("Binding to the VLDB server\n");
4606 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4607 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4610 "Could not unlock the entry for volume number %lu in VLDB \n",
4611 (unsigned long)volid);
4612 PrintError("", vcode);
4615 VPRINT("VLDB updated\n");
4620 /*adds <server> and <part> as a readonly replication site for <volid>
4623 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid, afs_int32 valid)
4625 int j, nro = 0, islocked = 0;
4626 struct nvldbentry entry, storeEntry;
4627 afs_int32 vcode, error = 0;
4630 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4633 " Could not lock the VLDB entry for the volume %lu \n",
4634 (unsigned long)volid);
4639 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4642 "Could not fetch the VLDB entry for volume number %lu \n",
4643 (unsigned long)volid);
4647 if (!ISNAMEVALID(entry.name)) {
4649 "Volume name %s is too long, rename before adding site\n",
4651 error = VOLSERBADOP;
4654 MapHostToNetwork(&entry);
4656 /* See if it's too many entries */
4657 if (entry.nServers >= NMAXNSERVERS) {
4658 fprintf(STDERR, "Total number of entries will exceed %u\n",
4660 error = VOLSERBADOP;
4664 /* See if it's on the same server */
4665 for (j = 0; j < entry.nServers; j++) {
4666 if (entry.serverFlags[j] & ITSROVOL) {
4668 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4671 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4674 MapPartIdIntoName(entry.serverPartition[j], apartName);
4676 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4678 error = VOLSERBADOP;
4685 /* See if it's too many RO sites - leave one for the RW */
4686 if (nro >= NMAXNSERVERS - 1) {
4687 fprintf(STDERR, "Total number of sites will exceed %u\n",
4689 error = VOLSERBADOP;
4693 VPRINT("Adding a new site ...");
4694 entry.serverNumber[entry.nServers] = server;
4695 entry.serverPartition[entry.nServers] = part;
4697 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4699 entry.serverFlags[entry.nServers] = (ITSROVOL);
4703 MapNetworkToHost(&entry, &storeEntry);
4705 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4706 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4708 fprintf(STDERR, "Could not update entry for volume %lu \n",
4709 (unsigned long)volid);
4718 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4719 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4722 "Could not release lock on volume entry for %lu \n",
4723 (unsigned long)volid);
4724 PrintError("", vcode);
4728 PrintError("", error);
4732 /*removes <server> <part> as read only site for <volid> from the vldb */
4734 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4737 struct nvldbentry entry, storeEntry;
4740 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4742 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4743 (unsigned long)volid);
4744 PrintError("", vcode);
4748 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4751 "Could not fetch the entry for volume number %lu from VLDB \n",
4752 (unsigned long)volid);
4753 PrintError("", vcode);
4756 MapHostToNetwork(&entry);
4757 if (!Lp_ROMatch(server, part, &entry)) {
4758 /*this site doesnot exist */
4759 fprintf(STDERR, "This site is not a replication site \n");
4761 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4762 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4764 fprintf(STDERR, "Could not update entry for volume %lu \n",
4765 (unsigned long)volid);
4766 PrintError("", vcode);
4767 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4768 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4772 } else { /*remove the rep site */
4773 Lp_SetROValue(&entry, server, part, 0, 0);
4775 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4776 entry.flags &= ~RO_EXISTS;
4777 if (entry.nServers < 1) { /*this is the last ref */
4778 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4780 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4783 "Could not delete VLDB entry for volume %lu \n",
4784 (unsigned long)volid);
4785 PrintError("", vcode);
4790 MapNetworkToHost(&entry, &storeEntry);
4791 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4792 (unsigned long)volid);
4795 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4796 LOCKREL_OPCODE | LOCKREL_AFSID |
4800 "Could not release lock on volume entry for %lu \n",
4801 (unsigned long)volid);
4802 PrintError("", vcode);
4803 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4804 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4812 /*sets <server> <part> as read/write site for <volid> in the vldb */
4814 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4817 struct nvldbentry entry, storeEntry;
4820 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4822 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4823 (unsigned long)volid);
4824 PrintError("", vcode);
4827 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4830 "Could not fetch the entry for volume number %lu from VLDB \n",
4831 (unsigned long)volid);
4832 PrintError("", vcode);
4835 MapHostToNetwork(&entry);
4836 index = Lp_GetRwIndex(&entry);
4838 /* no RW site exists */
4839 fprintf(STDERR, "No existing RW site for volume %lu",
4840 (unsigned long)volid);
4842 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4843 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4846 "Could not release lock on entry for volume %lu \n",
4847 (unsigned long)volid);
4848 PrintError("", vcode);
4852 } else { /* change the RW site */
4853 entry.serverNumber[index] = server;
4854 entry.serverPartition[index] = part;
4855 MapNetworkToHost(&entry, &storeEntry);
4857 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4858 LOCKREL_OPCODE | LOCKREL_AFSID |
4861 fprintf(STDERR, "Could not update entry for volume %lu \n",
4862 (unsigned long)volid);
4863 PrintError("", vcode);
4864 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4865 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4873 /*list all the partitions on <aserver> */
4875 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4878 struct rx_connection *aconn;
4879 struct pIDs partIds;
4880 struct partEntries partEnts;
4881 register int i, j = 0, code;
4884 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4886 partEnts.partEntries_len = 0;
4887 partEnts.partEntries_val = NULL;
4888 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4889 if (code == RXGEN_OPCODE) {
4890 for (i = 0; i < 26; i++) /* try old interface */
4891 partIds.partIds[i] = -1;
4892 code = AFSVolListPartitions(aconn, &partIds);
4894 for (i = 0; i < 26; i++) {
4895 if ((partIds.partIds[i]) != -1) {
4896 ptrPartList->partId[j] = partIds.partIds[i];
4897 ptrPartList->partFlags[j] = PARTVALID;
4900 ptrPartList->partFlags[i] = 0;
4905 *cntp = partEnts.partEntries_len;
4906 if (*cntp > VOLMAXPARTS) {
4908 "Warning: number of partitions on the server too high %d (process only %d)\n",
4909 *cntp, VOLMAXPARTS);
4910 *cntp = VOLMAXPARTS;
4912 for (i = 0; i < *cntp; i++) {
4913 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4914 ptrPartList->partFlags[i] = PARTVALID;
4916 free(partEnts.partEntries_val);
4922 "Could not fetch the list of partitions from the server\n");
4923 PrintError("", code);
4925 rx_DestroyConnection(aconn);
4930 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4931 This is used by the backup system */
4933 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4934 struct volDescription *volPtr, afs_int32 arraySize)
4936 struct rx_connection *aconn;
4937 struct volDescription *curPtr;
4940 afs_int32 rcode = 0;
4941 afs_int32 success = 1;
4944 aconn = (struct rx_connection *)0;
4945 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4947 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4948 if (curPtr->volFlags & CLONEVALID) {
4949 curPtr->volFlags &= ~CLONEZAPPED;
4952 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4957 code = AFSVolDeleteVolume(aconn, tid);
4960 code = AFSVolEndTrans(aconn, tid, &rcode);
4965 curPtr->volFlags |= CLONEZAPPED;
4967 fprintf(STDERR, "Could not zap volume %lu\n",
4968 (unsigned long)curPtr->volCloneId);
4970 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4971 curPtr->volCloneId);
4977 rx_DestroyConnection(aconn);
4981 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4984 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4985 struct volDescription *volPtr, afs_int32 arraySize)
4987 struct rx_connection *aconn;
4988 struct volDescription *curPtr;
4991 afs_int32 rcode = 0;
4993 int reuseCloneId = 0;
4994 afs_int32 curCloneId = 0;
4995 char cloneName[256]; /*max vol name */
4997 aconn = (struct rx_connection *)0;
4998 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5000 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
5002 else { /*get a bunch of id's from vldb */
5004 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
5006 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
5007 PrintError("", code);
5012 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
5013 if (curPtr->volFlags & ENTRYVALID) {
5015 curPtr->volFlags |= CLONEVALID;
5016 /*make a clone of curParentId and record as curPtr->volCloneId */
5018 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
5021 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
5024 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
5028 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
5029 strcpy(cloneName, curPtr->volName);
5030 strcat(cloneName, "-tmpClone-");
5032 strcpy(cloneName, "-tmpClone");
5034 curPtr->volCloneId = curCloneId;
5039 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5040 &(curPtr->volCloneId));
5042 curPtr->volFlags &= ~CLONEVALID;
5044 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5045 curPtr->volName, (unsigned long)code);
5046 code = AFSVolEndTrans(aconn, tid, &rcode);
5048 fprintf(STDERR, "WARNING: could not end transaction\n");
5051 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5052 curPtr->volCloneId);
5053 code = AFSVolEndTrans(aconn, tid, &rcode);
5054 if (code || rcode) {
5055 curPtr->volFlags &= ~CLONEVALID;
5064 rx_DestroyConnection(aconn);
5069 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5070 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5072 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5073 struct volintInfo **resultPtr, afs_int32 * size)
5075 struct rx_connection *aconn;
5077 volEntries volumeInfo;
5081 *resultPtr = (volintInfo *) 0;
5082 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5083 volumeInfo.volEntries_len = 0;
5085 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5086 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5089 "Could not fetch the list of volumes from the server\n");
5091 *resultPtr = volumeInfo.volEntries_val;
5092 *size = volumeInfo.volEntries_len;
5096 rx_DestroyConnection(aconn);
5097 PrintError("", code);
5101 /*------------------------------------------------------------------------
5102 * EXPORTED UV_XListVolumes
5105 * List the extended information for all the volumes on a particular
5106 * File Server and partition. We may either return the volume's ID
5107 * or all of its extended information.
5110 * a_serverID : Address of the File Server for which we want
5111 * extended volume info.
5112 * a_partID : Partition for which we want the extended
5114 * a_all : If non-zero, fetch ALL the volume info,
5115 * otherwise just the volume ID.
5116 * a_resultPP : Ptr to the address of the area containing
5117 * the returned volume info.
5118 * a_numEntsInResultP : Ptr for the value we set for the number of
5123 * Otherise, the return value of AFSVolXListVolumes.
5126 * This routine is closely related to UV_ListVolumes, which returns
5127 * only the standard level of detail on AFS volumes. It is a
5128 * heavyweight operation, zipping through all the volume entries for
5129 * a given server/partition.
5133 *------------------------------------------------------------------------*/
5136 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5137 struct volintXInfo **a_resultPP,
5138 afs_int32 * a_numEntsInResultP)
5140 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5141 afs_int32 code; /*Error code to return */
5142 volXEntries volumeXInfo; /*Area for returned extended vol info */
5145 * Set up our error code and the area for returned extended volume info.
5146 * We set the val field to a null pointer as a hint for the stub to
5150 *a_numEntsInResultP = 0;
5151 *a_resultPP = (volintXInfo *) 0;
5152 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5153 volumeXInfo.volXEntries_len = 0;
5156 * Bind to the Volume Server port on the File Server machine in question,
5159 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5160 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5162 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5165 * We got the info; pull out the pointer to where the results lie
5166 * and how many entries are there.
5168 *a_resultPP = volumeXInfo.volXEntries_val;
5169 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5173 * If we got an Rx connection, throw it away.
5176 rx_DestroyConnection(rxConnP);
5178 PrintError("", code);
5180 } /*UV_XListVolumes */
5182 /* get all the information about volume <volid> on <aserver> and <apart> */
5184 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
5185 struct volintInfo **resultPtr)
5187 struct rx_connection *aconn;
5189 volEntries volumeInfo;
5193 *resultPtr = (volintInfo *) 0;
5194 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5195 volumeInfo.volEntries_len = 0;
5197 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5198 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5201 "Could not fetch the information about volume %lu from the server\n",
5202 (unsigned long)volid);
5204 *resultPtr = volumeInfo.volEntries_val;
5209 rx_DestroyConnection(aconn);
5210 PrintError("", code);
5214 /*------------------------------------------------------------------------
5215 * EXPORTED UV_XListOneVolume
5218 * List the extended information for a volume on a particular File
5219 * Server and partition.
5222 * a_serverID : Address of the File Server for which we want
5223 * extended volume info.
5224 * a_partID : Partition for which we want the extended
5226 * a_volID : Volume ID for which we want the info.
5227 * a_resultPP : Ptr to the address of the area containing
5228 * the returned volume info.
5232 * Otherise, the return value of AFSVolXListOneVolume.
5235 * This routine is closely related to UV_ListOneVolume, which returns
5236 * only the standard level of detail on the chosen AFS volume.
5240 *------------------------------------------------------------------------*/
5243 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
5244 struct volintXInfo **a_resultPP)
5246 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5247 afs_int32 code; /*Error code */
5248 volXEntries volumeXInfo; /*Area for returned info */
5251 * Set up our error code, and the area we're in which we are returning
5252 * the info. Setting the val field to a null pointer tells the stub
5253 * to allocate space for us.
5256 *a_resultPP = (volintXInfo *) 0;
5257 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5258 volumeXInfo.volXEntries_len = 0;
5261 * Bind to the Volume Server port on the File Server machine in question,
5264 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5265 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5268 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5271 * We got the info; pull out the pointer to where the results lie.
5273 *a_resultPP = volumeXInfo.volXEntries_val;
5276 * If we got an Rx connection, throw it away.
5279 rx_DestroyConnection(rxConnP);
5281 PrintError("", code);
5286 * Given a volume we read from a partition, check if it is
5287 * represented in the VLDB correctly.
5289 * The VLDB is looked up by the RW volume id (not its name).
5290 * The RW contains the true name of the volume (BK and RO set
5291 * the name in the VLDB only on creation of the VLDB entry).
5292 * We want rules strict enough that when we check all volumes
5293 * on one partition, it does not need to be done again. IE:
5294 * two volumes on different partitions won't constantly
5295 * change a VLDB entry away from what the other set.
5296 * For RW and BK volumes, we will always check the VLDB to see
5297 * if the two exist on the server/partition. May seem redundant,
5298 * but this is an easy check of the VLDB. IE: if the VLDB entry
5299 * says the BK exists but no BK volume is there, we will detect
5300 * this when we check the RW volume.
5301 * VLDB entries are locked only when a change needs to be done.
5302 * Output changed to look a lot like the "vos syncserv" otuput.
5305 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5306 afs_int32 * modentry, afs_uint32 * maxvolid)
5309 afs_int32 code, error = 0;
5310 struct nvldbentry entry, storeEntry;
5312 int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
5322 ((volumeinfo->type ==
5323 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5326 /* Check to see if the VLDB is ok without locking it (pass 1).
5327 * If it will change, then lock the VLDB entry, read it again,
5328 * then make the changes to it (pass 2).
5331 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5333 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5334 (unsigned long)rwvolid);
5340 createentry = 0; /* Do we need to create a VLDB entry */
5341 addvolume = 0; /* Add this volume to the VLDB entry */
5342 modified = 0; /* The VLDB entry was modified */
5344 /* Read the entry from VLDB by its RW volume id */
5345 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5347 if (code != VL_NOENT) {
5349 "Could not retreive the VLDB entry for volume %lu \n",
5350 (unsigned long)rwvolid);
5354 memset(&entry, 0, sizeof(entry));
5355 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5359 MapHostToNetwork(&entry);
5362 if (verbose && (pass == 1)) {
5363 fprintf(STDOUT, "_______________________________\n");
5364 fprintf(STDOUT, "\n-- status before -- \n");
5366 fprintf(STDOUT, "\n**does not exist**\n");
5368 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5369 || (entry.flags & BACK_EXISTS))
5370 EnumerateEntry(&entry);
5372 fprintf(STDOUT, "\n");
5375 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5381 /* Check existence of RW and BK volumes */
5382 code = CheckVldbRWBK(&entry, &mod);
5388 idx = Lp_GetRwIndex(&entry);
5389 if (idx == -1) { /* RW index not found in the VLDB entry */
5390 idx = entry.nServers; /* put it into next index */
5393 } else { /* RW index found in the VLDB entry. */
5394 /* Verify if this volume's location matches where the VLDB says it is */
5395 if (!Lp_Match(aserver, apart, &entry)) {
5396 if (entry.flags & RW_EXISTS) {
5397 /* The RW volume exists elsewhere - report this one a duplicate */
5399 MapPartIdIntoName(apart, pname);
5401 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5402 (unsigned long)rwvolid,
5404 afs_inet_ntoa_r(aserver, hoststr) :
5405 hostutil_GetNameByINet(aserver), pname);
5406 MapPartIdIntoName(entry.serverPartition[idx],
5409 " VLDB reports RW volume %lu exists on %s %s\n",
5410 (unsigned long)rwvolid,
5412 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5413 hostutil_GetNameByINet(entry.
5418 /* The RW volume does not exist - have VLDB point to this one */
5421 /* Check for orphaned BK volume on old partition */
5422 if (entry.flags & BACK_EXISTS) {
5424 MapPartIdIntoName(entry.serverPartition[idx],
5427 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5428 entry.volumeId[BACKVOL],
5430 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5431 hostutil_GetNameByINet(entry.
5434 MapPartIdIntoName(apart, pname);
5436 " VLDB reports its RW volume %lu exists on %s %s\n",
5437 (unsigned long)rwvolid,
5439 afs_inet_ntoa_r(aserver, hoststr) :
5440 hostutil_GetNameByINet(aserver),
5446 /* Volume location matches the VLDB location */
5447 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5448 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5451 (entry.name, volumeinfo->name,
5452 VOLSER_OLDMAXVOLNAME) != 0)) {
5460 entry.flags |= RW_EXISTS;
5461 entry.volumeId[RWVOL] = rwvolid;
5462 if (!entry.volumeId[BACKVOL])
5463 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5464 if (!entry.volumeId[ROVOL])
5465 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5467 entry.serverFlags[idx] = ITSRWVOL;
5468 entry.serverNumber[idx] = aserver;
5469 entry.serverPartition[idx] = apart;
5470 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5474 /* One last check - to update BK if need to */
5475 code = CheckVldbRWBK(&entry, &mod);
5483 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5489 /* Check existence of RW and BK volumes */
5490 code = CheckVldbRWBK(&entry, &mod);
5496 idx = Lp_GetRwIndex(&entry);
5497 if (idx == -1) { /* RW index not found in the VLDB entry */
5498 idx = entry.nServers; /* Put it into next index */
5501 } else { /* RW index found in the VLDB entry */
5502 /* Verify if this volume's location matches where the VLDB says it is */
5503 if (!Lp_Match(aserver, apart, &entry)) {
5504 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5506 MapPartIdIntoName(apart, pname);
5508 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5509 (unsigned long)volumeinfo->volid,
5511 afs_inet_ntoa_r(aserver, hoststr) :
5512 hostutil_GetNameByINet(aserver), pname);
5513 MapPartIdIntoName(entry.serverPartition[idx], pname);
5515 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5516 (unsigned long)rwvolid,
5518 afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
5519 hostutil_GetNameByINet(entry.
5524 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5525 if (!(entry.flags & BACK_EXISTS)) {
5527 } else if (volumeinfo->volid >
5528 entry.volumeId[BACKVOL]) {
5532 MapPartIdIntoName(entry.serverPartition[idx],
5535 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5536 entry.volumeId[BACKVOL],
5538 afs_inet_ntoa_r(aserver, hoststr) :
5539 hostutil_GetNameByINet(aserver),
5542 " VLDB reports its BK volume ID is %lu\n",
5543 (unsigned long)volumeinfo->volid);
5547 MapPartIdIntoName(entry.serverPartition[idx],
5550 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5551 (unsigned long)volumeinfo->volid,
5553 afs_inet_ntoa_r(aserver, hoststr) :
5554 hostutil_GetNameByINet(aserver),
5557 " VLDB reports its BK volume ID is %u\n",
5558 entry.volumeId[BACKVOL]);
5561 } else if (!entry.volumeId[BACKVOL]) {
5568 entry.flags |= BACK_EXISTS;
5569 entry.volumeId[RWVOL] = rwvolid;
5570 entry.volumeId[BACKVOL] = volumeinfo->volid;
5572 entry.serverNumber[idx] = aserver;
5573 entry.serverPartition[idx] = apart;
5574 entry.serverFlags[idx] = ITSBACKVOL;
5580 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5581 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5582 /* This is a quick check to see if the RO entry exists in the
5583 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5584 * RO volume listed in the VLDB exists).
5586 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5588 idx = entry.nServers;
5592 if (!(entry.flags & RO_EXISTS)) {
5597 /* Before we correct the VLDB entry, make sure all the
5598 * ROs listed in the VLDB exist.
5600 code = CheckVldbRO(&entry, &mod);
5606 if (!(entry.flags & RO_EXISTS)) {
5607 /* No RO exists in the VLDB entry - add this one */
5608 idx = entry.nServers;
5611 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5612 /* The volume headers's RO ID does not match that in the VLDB entry,
5613 * and the vol hdr's ID is greater (implies more recent). So delete
5614 * all the RO volumes listed in VLDB entry and add this volume.
5616 for (j = 0; j < entry.nServers; j++) {
5617 if (entry.serverFlags[j] & ITSROVOL) {
5618 /* Verify this volume exists and print message we are orphaning it */
5620 MapPartIdIntoName(apart, pname);
5622 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5623 entry.volumeId[ROVOL],
5625 afs_inet_ntoa_r(entry.serverNumber[j], hoststr) :
5626 hostutil_GetNameByINet(entry.
5630 " VLDB reports its RO volume ID is %lu\n",
5631 (unsigned long)volumeinfo->volid);
5634 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5635 entry.serverPartition[idx], 0L, 0L);
5642 idx = entry.nServers;
5645 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5646 /* The volume headers's RO ID does not match that in the VLDB entry,
5647 * and the vol hdr's ID is lower (implies its older). So orphan it.
5650 MapPartIdIntoName(apart, pname);
5652 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5653 (unsigned long)volumeinfo->volid,
5655 afs_inet_ntoa_r(aserver, hoststr) :
5656 hostutil_GetNameByINet(aserver), pname);
5658 " VLDB reports its RO volume ID is %u\n",
5659 entry.volumeId[ROVOL]);
5662 /* The RO volume ID in the volume header match that in the VLDB entry,
5663 * and there exist RO volumes in the VLDB entry. See if any of them
5664 * are this one. If not, then we add it.
5666 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5668 idx = entry.nServers;
5676 entry.flags |= RO_EXISTS;
5677 entry.volumeId[RWVOL] = rwvolid;
5678 entry.volumeId[ROVOL] = volumeinfo->volid;
5680 entry.serverNumber[idx] = aserver;
5681 entry.serverPartition[idx] = apart;
5682 entry.serverFlags[idx] = ITSROVOL;
5688 /* Remember largest volume id */
5689 if (entry.volumeId[ROVOL] > *maxvolid)
5690 *maxvolid = entry.volumeId[ROVOL];
5691 if (entry.volumeId[BACKVOL] > *maxvolid)
5692 *maxvolid = entry.volumeId[BACKVOL];
5693 if (entry.volumeId[RWVOL] > *maxvolid)
5694 *maxvolid = entry.volumeId[RWVOL];
5696 if (modified && doit) {
5697 MapNetworkToHost(&entry, &storeEntry);
5700 code = VLDB_CreateEntry(&storeEntry);
5703 "Could not create a VLDB entry for the volume %lu\n",
5704 (unsigned long)rwvolid);
5711 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5712 LOCKREL_OPCODE | LOCKREL_AFSID |
5715 fprintf(STDERR, "Could not update entry for %lu\n",
5716 (unsigned long)rwvolid);
5721 *modentry = modified;
5722 } else if (pass == 2) {
5724 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5725 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5727 PrintError("Could not unlock VLDB entry ", code);
5731 if (verbose && doit) {
5732 fprintf(STDOUT, "-- status after --\n");
5734 EnumerateEntry(&entry);
5736 fprintf(STDOUT, "\n**no change**\n");
5740 VPRINT("\n_______________________________\n");
5745 sortVolumes(const void *a, const void *b)
5747 volintInfo *v1 = (volintInfo *) a;
5748 volintInfo *v2 = (volintInfo *) b;
5749 afs_int32 rwvolid1, rwvolid2;
5751 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5752 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5754 if (rwvolid1 > rwvolid2)
5755 return -1; /* lower RW id goes first */
5756 if (rwvolid1 < rwvolid2)
5759 if (v1->type == RWVOL)
5760 return -1; /* RW vols go first */
5761 if (v2->type == RWVOL)
5764 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5765 return -1; /* BK vols next */
5766 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5769 if (v1->volid < v2->volid)
5770 return 1; /* larger volids first */
5771 if (v1->volid > v2->volid)
5777 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5778 * Synchronize an individual volume against a sever and partition.
5779 * Checks the VLDB entry (similar to syncserv) as well as checks
5780 * if the volume exists on specified servers (similar to syncvldb).
5783 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5785 struct rx_connection *aconn = 0;
5786 afs_int32 j, k, code, vcode, error = 0;
5787 afs_int32 tverbose, mod, modified = 0;
5788 struct nvldbentry vldbentry;
5789 afs_int32 volumeid = 0;
5790 volEntries volumeInfo;
5791 struct partList PartList;
5793 afs_int32 maxvolid = 0;
5795 volumeInfo.volEntries_val = (volintInfo *) 0;
5796 volumeInfo.volEntries_len = 0;
5798 if (!aserver && (flags & 1)) {
5799 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5803 /* Turn verbose logging off and do our own verbose logging */
5809 /* Read the VLDB entry */
5810 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5811 if (vcode && (vcode != VL_NOENT)) {
5812 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5815 } else if (!vcode) {
5816 MapHostToNetwork(&vldbentry);
5820 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5821 fprintf(STDOUT, "_______________________________\n");
5822 fprintf(STDOUT, "\n-- status before -- \n");
5824 fprintf(STDOUT, "\n**does not exist**\n");
5826 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5827 || (vldbentry.flags & BACK_EXISTS))
5828 EnumerateEntry(&vldbentry);
5830 fprintf(STDOUT, "\n");
5833 /* Verify that all of the VLDB entries exist on the repective servers
5834 * and partitions (this does not require that avolname be a volume ID).
5835 * Equivalent to a syncserv.
5838 /* Tell CheckVldb not to update if appropriate */
5843 code = CheckVldb(&vldbentry, &mod);
5845 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5853 /* If aserver is given, we will search for the desired volume on it */
5855 /* Generate array of partitions on the server that we will check */
5857 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5860 "Could not fetch the list of partitions from the server\n");
5864 PartList.partId[0] = apart;
5868 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5870 /* If a volume ID were given, search for it on each partition */
5871 if ((volumeid = atol(avolname))) {
5872 for (j = 0; j < pcnt; j++) {
5874 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5877 if (code != ENODEV) {
5878 fprintf(STDERR, "Could not query server\n");
5886 /* Found one, sync it with VLDB entry */
5888 CheckVolume(volumeInfo.volEntries_val, aserver,
5889 PartList.partId[j], &mod, &maxvolid);
5896 if (volumeInfo.volEntries_val)
5897 free(volumeInfo.volEntries_val);
5898 volumeInfo.volEntries_val = (volintInfo *) 0;
5899 volumeInfo.volEntries_len = 0;
5903 /* Check to see if the RW, BK, and RO IDs exist on any
5904 * partitions. We get the volume IDs from the VLDB.
5906 rv = 1; /* Read the VLDB entry ? */
5907 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5909 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5911 if (vcode == VL_NOENT)
5914 "Could not access the VLDB for volume %s\n",
5921 if (vldbentry.volumeId[j] == 0)
5924 for (k = 0; k < pcnt; k++) { /* For each partition */
5925 volumeInfo.volEntries_val = (volintInfo *) 0;
5926 volumeInfo.volEntries_len = 0;
5928 AFSVolListOneVolume(aconn, PartList.partId[k],
5929 vldbentry.volumeId[j], &volumeInfo);
5931 if (code != ENODEV) {
5932 fprintf(STDERR, "Could not query server\n");
5940 /* Found one, sync it with VLDB entry */
5942 CheckVolume(volumeInfo.volEntries_val, aserver,
5943 PartList.partId[k], &mod, &maxvolid);
5950 if (volumeInfo.volEntries_val)
5951 free(volumeInfo.volEntries_val);
5952 volumeInfo.volEntries_val = (volintInfo *) 0;
5953 volumeInfo.volEntries_len = 0;
5959 /* If verbose output, print a summary of what changed */
5960 if (tverbose && !(flags & 2)) {
5961 fprintf(STDOUT, "-- status after --\n");
5962 code = VLDB_GetEntryByName(avolname, &vldbentry);
5963 if (code && (code != VL_NOENT)) {
5964 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5968 if (modified && (code == VL_NOENT)) {
5969 fprintf(STDOUT, "\n**entry deleted**\n");
5970 } else if (modified) {
5971 EnumerateEntry(&vldbentry);
5973 fprintf(STDOUT, "\n**no change**\n");
5975 fprintf(STDOUT, "\n_______________________________\n");
5979 /* Now check if the maxvolid is larger than that stored in the VLDB */
5981 afs_int32 maxvldbid = 0;
5982 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
5985 "Could not get the highest allocated volume id from the VLDB\n");
5988 } else if (maxvolid > maxvldbid) {
5990 id = maxvolid - maxvldbid + 1;
5991 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
5994 "Error in increasing highest allocated volume id in VLDB\n");
6004 fprintf(STDOUT, "...error encountered");
6006 fprintf(STDOUT, "...done entry\n");
6009 rx_DestroyConnection(aconn);
6010 if (volumeInfo.volEntries_val)
6011 free(volumeInfo.volEntries_val);
6013 PrintError("", error);
6018 * Synchronise vldb with the file server <aserver> and,
6019 * optionally, <apart>.
6022 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
6024 struct rx_connection *aconn;
6025 afs_int32 code, error = 0;
6027 volEntries volumeInfo;
6028 struct partList PartList;
6032 afs_int32 failures = 0, modifications = 0, tentries = 0;
6034 afs_uint32 maxvolid = 0;
6037 volumeInfo.volEntries_val = (volintInfo *) 0;
6038 volumeInfo.volEntries_len = 0;
6040 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6042 /* Generate array of partitions to check */
6044 code = UV_ListPartitions(aserver, &PartList, &pcnt);
6047 "Could not fetch the list of partitions from the server\n");
6051 PartList.partId[0] = apart;
6055 VPRINT("Processing volume entries ...\n");
6057 /* Step through the array of partitions */
6058 for (i = 0; i < pcnt; i++) {
6059 apart = PartList.partId[i];
6060 MapPartIdIntoName(apart, pname);
6062 volumeInfo.volEntries_val = (volintInfo *) 0;
6063 volumeInfo.volEntries_len = 0;
6064 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6067 "Could not fetch the list of volumes from the server\n");
6071 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6072 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6073 sizeof(volintInfo), sortVolumes);
6076 for (vi = volumeInfo.volEntries_val, j = 0;
6077 j < volumeInfo.volEntries_len; j++, vi++) {
6085 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6086 j + 1, vi->name, (unsigned long)vi->volid,
6088 afs_inet_ntoa_r(aserver, hoststr) :
6089 hostutil_GetNameByINet(aserver), pname);
6097 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
6099 PrintError("", code);
6102 } else if (modified) {
6108 fprintf(STDOUT, "...error encountered\n\n");
6110 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6117 "Could not process entries on server %s partition %s\n",
6119 afs_inet_ntoa_r(aserver, hoststr) :
6120 hostutil_GetNameByINet(aserver), pname);
6122 if (volumeInfo.volEntries_val) {
6123 free(volumeInfo.volEntries_val);
6124 volumeInfo.volEntries_val = 0;
6127 } /* thru all partitions */
6130 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6131 tentries, failures, modifications);
6133 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6134 tentries, failures, modifications);
6138 /* Now check if the maxvolid is larger than that stored in the VLDB */
6140 afs_int32 maxvldbid = 0;
6141 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6144 "Could not get the highest allocated volume id from the VLDB\n");
6147 } else if (maxvolid > maxvldbid) {
6149 id = maxvolid - maxvldbid + 1;
6150 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6153 "Error in increasing highest allocated volume id in VLDB\n");
6161 rx_DestroyConnection(aconn);
6162 if (volumeInfo.volEntries_val)
6163 free(volumeInfo.volEntries_val);
6164 PrintError("", error);
6169 * Determine if a volume exists on a server and partition.
6170 * Try creating a transaction on the volume. If we can,
6171 * the volume exists, if not, then return the error code.
6172 * Some error codes mean the volume is unavailable but
6173 * still exists - so we catch these error codes.
6176 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
6178 struct rx_connection *conn = (struct rx_connection *)0;
6179 afs_int32 code = -1;
6180 volEntries volumeInfo;
6182 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6184 volumeInfo.volEntries_val = (volintInfo *) 0;
6185 volumeInfo.volEntries_len = 0;
6186 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6187 if (volumeInfo.volEntries_val)
6188 free(volumeInfo.volEntries_val);
6189 if (code == VOLSERILLEGAL_PARTITION)
6191 rx_DestroyConnection(conn);
6200 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6204 afs_int32 code, error = 0;
6210 idx = Lp_GetRwIndex(entry);
6212 /* Check to see if the RW volume exists and set the RW_EXISTS
6215 if (idx == -1) { /* Did not find a RW entry */
6216 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6217 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6222 VolumeExists(entry->serverNumber[idx],
6223 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6224 if (code == 0) { /* RW volume exists */
6225 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6226 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6229 } else if (code == ENODEV) { /* RW volume does not exist */
6230 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6231 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6235 /* If VLDB says it didn't exist, then ignore error */
6236 if (entry->flags & RW_EXISTS) {
6237 MapPartIdIntoName(entry->serverPartition[idx], pname);
6239 "Transaction call failed for RW volume %u on server %s %s\n",
6240 entry->volumeId[RWVOL],
6242 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6243 hostutil_GetNameByINet(entry->serverNumber[idx]),
6250 /* Check to see if the BK volume exists and set the BACK_EXISTS
6251 * flag accordingly. idx already ponts to the RW entry.
6253 if (idx == -1) { /* Did not find a RW entry */
6254 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6255 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6258 } else { /* Found a RW entry */
6260 VolumeExists(entry->serverNumber[idx],
6261 entry->serverPartition[idx],
6262 entry->volumeId[BACKVOL]);
6263 if (code == 0) { /* BK volume exists */
6264 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6265 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6268 } else if (code == ENODEV) { /* BK volume does not exist */
6269 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6270 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6274 /* If VLDB says it didn't exist, then ignore error */
6275 if (entry->flags & BACK_EXISTS) {
6276 MapPartIdIntoName(entry->serverPartition[idx], pname);
6278 "Transaction call failed for BK volume %u on server %s %s\n",
6279 entry->volumeId[BACKVOL],
6281 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6282 hostutil_GetNameByINet(entry->serverNumber[idx]),
6289 /* If there is an idx but the BK and RW volumes no
6290 * longer exist, then remove the RW entry.
6292 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6293 && !(entry->flags & BACK_EXISTS)) {
6294 Lp_SetRWValue(entry, entry->serverNumber[idx],
6295 entry->serverPartition[idx], 0L, 0L);
6302 *modified = modentry;
6307 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6310 int foundro = 0, modentry = 0;
6311 afs_int32 code, error = 0;
6318 /* Check to see if the RO volumes exist and set the RO_EXISTS
6321 for (idx = 0; idx < entry->nServers; idx++) {
6322 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6323 continue; /* not a RO */
6327 VolumeExists(entry->serverNumber[idx],
6328 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6329 if (code == 0) { /* RO volume exists */
6331 } else if (code == ENODEV) { /* RW volume does not exist */
6332 Lp_SetROValue(entry, entry->serverNumber[idx],
6333 entry->serverPartition[idx], 0L, 0L);
6338 MapPartIdIntoName(entry->serverPartition[idx], pname);
6340 "Transaction call failed for RO %u on server %s %s\n",
6341 entry->volumeId[ROVOL],
6343 afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) :
6344 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6349 if (foundro) { /* A RO volume exists */
6350 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6351 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6354 } else { /* A RO volume does not exist */
6355 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6356 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6363 *modified = modentry;
6368 * Ensure that <entry> matches with the info on file servers
6371 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6373 afs_int32 code, error = 0;
6374 struct nvldbentry storeEntry;
6375 int islocked = 0, mod, modentry, delentry = 0;
6376 int pass = 0, doit=1;
6384 fprintf(STDOUT, "_______________________________\n");
6385 fprintf(STDOUT, "\n-- status before -- \n");
6386 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6387 || (entry->flags & BACK_EXISTS))
6388 EnumerateEntry(entry);
6389 fprintf(STDOUT, "\n");
6392 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6393 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6394 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6398 /* Check to see if the VLDB is ok without locking it (pass 1).
6399 * If it will change, then lock the VLDB entry, read it again,
6400 * then make the changes to it (pass 2).
6404 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6407 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6408 entry->volumeId[RWVOL]);
6413 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6415 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6419 MapHostToNetwork(entry);
6425 /* Check if the RW and BK entries are ok */
6426 code = CheckVldbRWBK(entry, &mod);
6429 if (mod && (pass == 1) && doit)
6434 /* Check if the RO volumes entries are ok */
6435 code = CheckVldbRO(entry, &mod);
6438 if (mod && (pass == 1) && doit)
6443 /* The VLDB entry has been updated. If it as been modified, then
6444 * write the entry back out the the VLDB.
6446 if (modentry && doit) {
6450 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6451 && !(entry->flags & RO_EXISTS) && doit) {
6452 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6454 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6458 "Could not delete VLDB entry for volume %u \n",
6459 entry->volumeId[RWVOL]);
6464 /* Replace old entry with our new one */
6465 MapNetworkToHost(entry, &storeEntry);
6467 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6468 (LOCKREL_OPCODE | LOCKREL_AFSID |
6469 LOCKREL_TIMESTAMP));
6471 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6472 entry->volumeId[RWVOL]);
6481 if (verbose && doit) {
6482 fprintf(STDOUT, "-- status after --\n");
6484 fprintf(STDOUT, "\n**entry deleted**\n");
6486 EnumerateEntry(entry);
6488 fprintf(STDOUT, "\n**no change**\n");
6492 VPRINT("\n_______________________________\n");
6496 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6498 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6501 "Could not release lock on VLDB entry for volume %u\n",
6502 entry->volumeId[RWVOL]);
6511 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6514 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6516 struct rx_connection *aconn;
6517 afs_int32 code, error = 0;
6518 afs_int32 nentries, tentries = 0;
6519 struct VldbListByAttributes attributes;
6520 nbulkentries arrayEntries;
6521 afs_int32 failures = 0, modified, modifications = 0;
6522 struct nvldbentry *vlentry;
6523 afs_int32 si, nsi, j;
6528 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6530 /* Set up attributes to search VLDB */
6531 attributes.server = ntohl(aserver);
6532 attributes.Mask = VLLIST_SERVER;
6534 attributes.partition = apart;
6535 attributes.Mask |= VLLIST_PARTITION;
6538 VPRINT("Processing VLDB entries ...\n");
6540 /* While we need to collect more VLDB entries */
6541 for (si = 0; si != -1; si = nsi) {
6542 memset(&arrayEntries, 0, sizeof(arrayEntries));
6544 /* Collect set of VLDB entries */
6546 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6547 &arrayEntries, &nsi);
6548 if (code == RXGEN_OPCODE) {
6549 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6553 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6556 tentries += nentries;
6558 for (j = 0; j < nentries; j++) {
6559 vlentry = &arrayEntries.nbulkentries_val[j];
6560 MapHostToNetwork(vlentry);
6562 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6564 /* Tell CheckVldb not to update if appropriate */
6569 code = CheckVldb(vlentry, &modified);
6571 PrintError("", code);
6573 "Could not process VLDB entry for volume %s\n",
6576 } else if (modified) {
6582 fprintf(STDOUT, "...error encountered\n\n");
6584 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6589 if (arrayEntries.nbulkentries_val) {
6590 free(arrayEntries.nbulkentries_val);
6591 arrayEntries.nbulkentries_val = 0;
6596 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6597 tentries, failures, modifications);
6599 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6600 tentries, failures, modifications);
6605 rx_DestroyConnection(aconn);
6606 if (arrayEntries.nbulkentries_val)
6607 free(arrayEntries.nbulkentries_val);
6610 error = VOLSERFAILEDOP;
6614 /*rename volume <oldname> to <newname>, changing the names of the related
6615 *readonly and backup volumes. This operation is also idempotent.
6616 *salvager is capable of recovering from rename operation stopping halfway.
6617 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6619 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6621 struct nvldbentry storeEntry;
6622 afs_int32 vcode, code, rcode, error;
6624 char nameBuffer[256];
6626 struct rx_connection *aconn;
6631 aconn = (struct rx_connection *)0;
6635 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6638 " Could not lock the VLDB entry for the volume %u \n",
6639 entry->volumeId[RWVOL]);
6644 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6645 MapNetworkToHost(entry, &storeEntry);
6646 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6648 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6649 entry->volumeId[RWVOL]);
6653 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6654 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6655 * is concerned, oldname is lost */
6656 if (entry->flags & RW_EXISTS) {
6657 index = Lp_GetRwIndex(entry);
6658 if (index == -1) { /* there is a serious discrepancy */
6660 "There is a serious discrepancy in VLDB entry for volume %u\n",
6661 entry->volumeId[RWVOL]);
6662 fprintf(STDERR, "try building VLDB from scratch\n");
6663 error = VOLSERVLDB_ERROR;
6666 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6668 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6669 entry->serverPartition[index], ITOffline, &tid);
6670 if (code) { /*volume doesnot exist */
6672 "Could not start transaction on the rw volume %u\n",
6673 entry->volumeId[RWVOL]);
6676 } else { /*volume exists, process it */
6679 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6680 entry->volumeId[RWVOL],
6681 entry->volumeId[ROVOL],
6682 entry->volumeId[BACKVOL]);
6684 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6685 code = AFSVolEndTrans(aconn, tid, &rcode);
6689 "Could not end transaction on volume %s %u\n",
6690 entry->name, entry->volumeId[RWVOL]);
6695 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6696 entry->name, entry->volumeId[RWVOL]);
6702 rx_DestroyConnection(aconn);
6703 aconn = (struct rx_connection *)0;
6705 /*end rw volume processing */
6706 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6707 index = Lp_GetRwIndex(entry);
6708 if (index == -1) { /* there is a serious discrepancy */
6710 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6711 entry->volumeId[BACKVOL]);
6712 fprintf(STDERR, "try building VLDB from scratch\n");
6713 error = VOLSERVLDB_ERROR;
6716 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6718 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6719 entry->serverPartition[index], ITOffline, &tid);
6720 if (code) { /*volume doesnot exist */
6722 "Could not start transaction on the backup volume %u\n",
6723 entry->volumeId[BACKVOL]);
6726 } else { /*volume exists, process it */
6727 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6729 "Volume name %s.backup exceeds the limit of %u characters\n",
6730 newname, VOLSER_OLDMAXVOLNAME);
6734 strcpy(nameBuffer, newname);
6735 strcat(nameBuffer, ".backup");
6738 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6739 entry->volumeId[RWVOL], 0, 0);
6741 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6742 code = AFSVolEndTrans(aconn, tid, &rcode);
6746 "Could not end transaction on the backup volume %u\n",
6747 entry->volumeId[BACKVOL]);
6753 "Could not set parameters on the backup volume %u\n",
6754 entry->volumeId[BACKVOL]);
6759 } /* end backup processing */
6761 rx_DestroyConnection(aconn);
6762 aconn = (struct rx_connection *)0;
6763 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6764 for (i = 0; i < entry->nServers; i++) {
6765 if (entry->serverFlags[i] & ITSROVOL) {
6766 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6768 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6769 entry->serverPartition[i], ITOffline,
6771 if (code) { /*volume doesnot exist */
6773 "Could not start transaction on the ro volume %u\n",
6774 entry->volumeId[ROVOL]);
6777 } else { /*volume exists, process it */
6778 strcpy(nameBuffer, newname);
6779 strcat(nameBuffer, ".readonly");
6780 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6782 "Volume name %s exceeds the limit of %u characters\n",
6783 nameBuffer, VOLSER_OLDMAXVOLNAME);
6788 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6789 entry->volumeId[RWVOL], 0, 0);
6791 VPRINT2("Renamed RO volume %s on host %s\n",
6794 afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
6795 hostutil_GetNameByINet(entry->
6797 code = AFSVolEndTrans(aconn, tid, &rcode);
6801 "Could not end transaction on volume %u\n",
6802 entry->volumeId[ROVOL]);
6808 "Could not set parameters on the ro volume %u\n",
6809 entry->volumeId[ROVOL]);
6815 rx_DestroyConnection(aconn);
6816 aconn = (struct rx_connection *)0;
6823 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6825 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6828 "Could not unlock the VLDB entry for the volume %s %u\n",
6829 entry->name, entry->volumeId[RWVOL]);
6835 code = AFSVolEndTrans(aconn, tid, &rcode);
6839 fprintf(STDERR, "Failed to end transaction on a volume \n");
6845 rx_DestroyConnection(aconn);
6846 PrintError("", error);
6851 /*report on all the active transactions on volser */
6853 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6855 struct rx_connection *aconn;
6856 transDebugEntries transInfo;
6859 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6860 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6861 transInfo.transDebugEntries_len = 0;
6862 code = AFSVolMonitor(aconn, &transInfo);
6865 "Could not access status information about the server\n");
6866 PrintError("", code);
6867 if (transInfo.transDebugEntries_val)
6868 free(transInfo.transDebugEntries_val);
6870 rx_DestroyConnection(aconn);
6873 *rcount = transInfo.transDebugEntries_len;
6874 *rpntr = transInfo.transDebugEntries_val;
6876 rx_DestroyConnection(aconn);
6883 /*delete the volume without interacting with the vldb */
6885 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6887 afs_int32 rcode, ttid, error, code;
6888 struct rx_connection *aconn;
6894 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6895 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6897 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6898 (unsigned long)volid);
6902 code = AFSVolDeleteVolume(aconn, ttid);
6904 fprintf(STDERR, "Could not delete volume %lu\n",
6905 (unsigned long)volid);
6909 code = AFSVolEndTrans(aconn, ttid, &rcode);
6914 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6915 (unsigned long)volid);
6921 code = AFSVolEndTrans(aconn, ttid, &rcode);
6927 PrintError("", error);
6929 rx_DestroyConnection(aconn);
6934 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6935 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6937 struct rx_connection *conn = 0;
6939 afs_int32 code, error = 0, rcode;
6941 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6943 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6947 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6949 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6953 code = AFSVolSetFlags(conn, tid, setflag);
6955 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6960 #ifdef AFS_PTHREAD_ENV
6963 IOMGR_Sleep(sleeptime);
6970 code = AFSVolEndTrans(conn, tid, &rcode);
6971 if (code || rcode) {
6972 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6974 error = (code ? code : rcode);
6979 rx_DestroyConnection(conn);
6984 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6987 struct rx_connection *conn = 0;
6989 afs_int32 code, error = 0, rcode;
6991 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6993 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6997 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6999 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
7003 code = AFSVolSetInfo(conn, tid, infop);
7005 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
7012 code = AFSVolEndTrans(conn, tid, &rcode);
7013 if (code || rcode) {
7014 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
7016 error = (code ? code : rcode);
7021 rx_DestroyConnection(conn);
7026 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
7027 afs_int32 fromdate, struct volintSize *vol_size)
7029 struct rx_connection *aconn = (struct rx_connection *)0;
7030 afs_int32 tid = 0, rcode = 0;
7031 afs_int32 code, error = 0;
7034 /* get connections to the servers */
7035 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
7037 VPRINT1("Starting transaction on volume %u...", afromvol);
7038 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
7039 EGOTO1(error_exit, code,
7040 "Could not start transaction on the volume %u to be measured\n",
7044 VPRINT1("Getting size of volume on volume %u...", afromvol);
7045 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
7046 EGOTO(error_exit, code, "Could not start the measurement process \n");
7051 VPRINT1("Ending transaction on volume %u...", afromvol);
7052 code = AFSVolEndTrans(aconn, tid, &rcode);
7053 if (code || rcode) {
7054 fprintf(STDERR, "Could not end transaction on the volume %u\n",
7056 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
7058 error = (code ? code : rcode);
7063 rx_DestroyConnection(aconn);
7065 PrintError("", error);
7069 /*maps the host addresses in <old > (present in network byte order) to
7070 that in< new> (present in host byte order )*/
7072 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7076 /*copy all the fields */
7077 strcpy(new->name, old->name);
7078 /* new->volumeType = old->volumeType;*/
7079 new->nServers = old->nServers;
7080 count = old->nServers;
7081 if (count < NMAXNSERVERS)
7083 for (i = 0; i < count; i++) {
7084 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7085 new->serverPartition[i] = old->serverPartition[i];
7086 new->serverFlags[i] = old->serverFlags[i];
7088 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7089 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7090 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7091 new->cloneId = old->cloneId;
7092 new->flags = old->flags;
7095 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7097 MapHostToNetwork(struct nvldbentry *entry)
7101 count = entry->nServers;
7102 if (count < NMAXNSERVERS)
7104 for (i = 0; i < count; i++) {
7105 entry->serverNumber[i] = htonl(entry->serverNumber[i]);