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>
60 struct ubik_client *cstruct;
66 afs_int32 vldbEntryIndex;
69 /* Utility macros used by rest of this source file */
70 #define EPRINT(ec, es) \
72 fprintf(STDERR, "\n"); \
73 fprintf(STDERR, (es)); \
77 #define EPRINT1(ec, es, ep1) \
79 fprintf(STDERR, "\n"); \
80 fprintf(STDERR, (es), (ep1)); \
84 #define EPRINT2(ec, es, ep1, ep2) \
86 fprintf(STDERR, "\n"); \
87 fprintf(STDERR, (es), (ep1), (ep2)); \
91 #define EPRINT3(ec, es, ep1, ep2, ep3) \
93 fprintf(STDERR, "\n"); \
94 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
98 #define EGOTO(where, ec, es) \
107 #define EGOTO1(where, ec, es, ep1) \
110 EPRINT1((ec),(es),(ep1)); \
116 #define EGOTO2(where, ec, es, ep1, ep2) \
119 EPRINT2((ec),(es),(ep1),(ep2)); \
125 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
128 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
135 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
136 #define VPRINT1(es, p) \
137 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
138 #define VPRINT2(es, p1, p2) \
139 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
140 #define VPRINT3(es, p1, p2, p3) \
141 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
143 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
144 #define VEPRINT(es) \
145 { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
146 #define VEPRINT1(es, p) \
147 { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
148 #define VEPRINT2(es, p1, p2) \
149 { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
150 #define VEPRINT3(es, p1, p2, p3) \
151 { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
153 { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
157 /* getting rid of this */
158 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
161 /* Protos for static routines */
162 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
163 afs_int32 apart, afs_int32 okvol,
165 static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
167 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
168 struct rx_connection **connPtr, afs_int32 * transPtr,
169 afs_int32 * crtimePtr, afs_int32 * uptimePtr);
170 static int SimulateForwardMultiple(struct rx_connection *fromconn,
171 afs_int32 fromtid, afs_int32 fromdate,
172 manyDests * tr, afs_int32 flags,
173 void *cookie, manyResults * results);
174 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
175 afs_int32 apart, afs_int32 * modentry,
176 afs_uint32 * maxvolid);
179 /*map the partition <partId> into partition name <partName>*/
181 MapPartIdIntoName(afs_int32 partId, char *partName)
183 if (partId < 26) { /* what if partId > = 26 ? */
184 strcpy(partName, "/vicep");
185 partName[6] = partId + 'a';
188 } else if (partId < VOLMAXPARTS) {
189 strcpy(partName, "/vicep");
191 partName[6] = 'a' + (partId / 26);
192 partName[7] = 'a' + (partId % 26);
204 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
205 response = c = getchar();
206 while (!(c == EOF || c == '\n'))
207 c = getchar(); /*skip to end of line */
208 code = (response == 'y' || response == 'Y');
214 PrintError(char *msg, afs_int32 errcode)
216 fprintf(STDERR, msg);
217 /*replace by a big switch statement */
222 fprintf(STDERR, "Possible communication failure\n");
225 fprintf(STDERR, "Volume needs to be salvaged\n");
228 fprintf(STDERR, "Bad vnode number quoted\n");
232 "Volume not attached, does not exist, or not on line\n");
235 fprintf(STDERR, "Volume already exists\n");
238 fprintf(STDERR, "Volume is not in service\n");
241 fprintf(STDERR, "Volume is off line\n");
244 fprintf(STDERR, "Volume is already on line\n");
247 fprintf(STDERR, "Partition is full\n");
250 fprintf(STDERR, "Volume max quota exceeded\n");
253 fprintf(STDERR, "Volume temporarily unavailable\n");
256 fprintf(STDERR, "Volume has moved to another server\n");
259 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
262 fprintf(STDERR, "VLDB: a read terminated too early\n");
265 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
268 fprintf(STDERR, "VLDB: internal creation failure\n");
271 fprintf(STDERR, "VLDB: no such entry\n");
274 fprintf(STDERR, "VLDB: vldb database is empty\n");
277 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
280 fprintf(STDERR, "VLDB: volume name is illegal\n");
283 fprintf(STDERR, "VLDB: index was out of range\n");
286 fprintf(STDERR, "VLDB: bad volume type\n");
289 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
291 case VL_BADPARTITION:
292 fprintf(STDERR, "VLDB: bad partition number\n");
295 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
298 fprintf(STDERR, "VLDB: no such repsite server exists\n");
300 case VL_DUPREPSERVER:
301 fprintf(STDERR, "VLDB: replication site server already exists\n");
304 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
307 fprintf(STDERR, "VLDB: illegal reference count number\n");
309 case VL_SIZEEXCEEDED:
310 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
313 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
315 case VL_BADVOLIDBUMP:
316 fprintf(STDERR, "VLDB: illegal max volid increment\n");
318 case VL_IDALREADYHASHED:
319 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
322 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
325 fprintf(STDERR, "VLDB: bad volume operation code\n");
327 case VL_BADRELLOCKTYPE:
328 fprintf(STDERR, "VLDB: bad release lock type\n");
331 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
333 case VL_BADSERVERFLAG:
334 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
337 fprintf(STDERR, "VLDB: no permission access for call\n");
339 case VOLSERREAD_DUMPERROR:
341 "VOLSER: Problems encountered in reading the dump file !\n");
343 case VOLSERDUMPERROR:
344 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
346 case VOLSERATTACH_ERROR:
347 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
349 case VOLSERDETACH_ERROR:
350 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
352 case VOLSERILLEGAL_PARTITION:
353 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
355 case VOLSERBAD_ACCESS:
356 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
358 case VOLSERVLDB_ERROR:
359 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
362 fprintf(STDERR, "VOLSER: error in volume name\n");
365 fprintf(STDERR, "VOLSER: volume has moved\n");
368 fprintf(STDERR, "VOLSER: illegal operation\n");
370 case VOLSERBADRELEASE:
371 fprintf(STDERR, "VOLSER: release could not be completed\n");
374 fprintf(STDERR, "VOLSER: volume is busy\n");
376 case VOLSERNO_MEMORY:
377 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
381 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
383 case VOLSERMULTIRWVOL:
385 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
389 "VOLSER: not all entries were successfully processed\n");
396 initialize_KA_error_table();
397 initialize_RXK_error_table();
398 initialize_KTC_error_table();
399 initialize_ACFG_error_table();
400 initialize_CMD_error_table();
401 initialize_VL_error_table();
403 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
404 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
405 afs_error_message(errcode));
412 void init_volintInfo(struct volintInfo *vinfo) {
413 memset(vinfo, 0, sizeof(struct volintInfo));
415 vinfo->maxquota = -1;
417 vinfo->creationDate = -1;
418 vinfo->updateDate = -1;
426 static struct rx_securityClass *uvclass = 0;
427 static int uvindex = -1;
428 /* called by VLDBClient_Init to set the security module to be used in the RPC */
430 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
437 /* bind to volser on <port> <aserver> */
438 /* takes server address in network order, port in host order. dumb */
439 struct rx_connection *
440 UV_Bind(afs_int32 aserver, afs_int32 port)
442 register struct rx_connection *tc;
444 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
449 /* if <okvol> is allright(indicated by beibg able to
450 * start a transaction, delete the <delvol> */
452 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
453 afs_int32 okvol, afs_int32 delvol)
455 afs_int32 error, code, tid, rcode;
461 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
464 code = AFSVolDeleteVolume(aconn, tid);
467 code = AFSVolEndTrans(aconn, tid, &rcode);
474 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
476 code = AFSVolEndTrans(aconn, tid, &rcode);
481 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
484 code = AFSVolDeleteVolume(aconn, tid);
487 code = AFSVolEndTrans(aconn, tid, &rcode);
498 /* called by EmuerateEntry, show vldb entry in a reasonable format */
500 SubEnumerateEntry(struct nvldbentry *entry)
507 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
508 if (entry->flags & RW_EXISTS)
509 fprintf(STDOUT, " valid \n");
511 fprintf(STDOUT, " invalid \n");
512 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
513 if (entry->flags & RO_EXISTS)
514 fprintf(STDOUT, " valid \n");
516 fprintf(STDOUT, " invalid \n");
517 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
518 if (entry->flags & BACK_EXISTS)
519 fprintf(STDOUT, " valid \n");
521 fprintf(STDOUT, " invalid \n");
522 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
523 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
525 if (entry->flags & RW_EXISTS)
526 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
527 if (entry->flags & RO_EXISTS)
528 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
529 if (entry->flags & BACK_EXISTS)
530 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
531 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
532 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
533 fprintf(STDOUT, "\n");
535 fprintf(STDOUT, " number of sites -> %lu\n",
536 (unsigned long)entry->nServers);
537 for (i = 0; i < entry->nServers; i++) {
538 if (entry->serverFlags[i] & NEW_REPSITE)
541 for (i = 0; i < entry->nServers; i++) {
542 MapPartIdIntoName(entry->serverPartition[i], pname);
543 fprintf(STDOUT, " server %s partition %s ",
544 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
545 if (entry->serverFlags[i] & ITSRWVOL)
546 fprintf(STDOUT, "RW Site ");
548 fprintf(STDOUT, "RO Site ");
550 if (entry->serverFlags[i] & NEW_REPSITE)
551 fprintf(STDOUT," -- New release");
553 if (!(entry->serverFlags[i] & ITSRWVOL))
554 fprintf(STDOUT," -- Old release");
556 if (entry->serverFlags[i] & RO_DONTUSE)
557 fprintf(STDOUT, " -- Not released");
559 fprintf(STDOUT, "\n");
566 /*enumerate the vldb entry corresponding to <entry> */
568 EnumerateEntry(struct nvldbentry *entry)
571 fprintf(STDOUT, "\n");
572 fprintf(STDOUT, "%s \n", entry->name);
573 SubEnumerateEntry(entry);
577 /* forcibly remove a volume. Very dangerous call */
579 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
581 register struct rx_connection *tconn;
582 register afs_int32 code;
584 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
586 code = AFSVolNukeVolume(tconn, partid, volid);
587 rx_DestroyConnection(tconn);
593 /* like df. Return usage of <pname> on <server> in <partition> */
595 UV_PartitionInfo(afs_int32 server, char *pname,
596 struct diskPartition *partition)
598 register struct rx_connection *aconn;
602 aconn = (struct rx_connection *)0;
603 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
604 code = AFSVolPartitionInfo(aconn, pname, partition);
606 fprintf(STDERR, "Could not get information on partition %s\n", pname);
607 PrintError("", code);
610 rx_DestroyConnection(aconn);
614 /* old interface to create volume */
616 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
620 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
624 /* create a volume, given a server, partition number, volume name --> sends
625 * back new vol id in <anewid>*/
627 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
628 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
629 afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
632 register struct rx_connection *aconn;
634 register afs_int32 code;
636 afs_int32 rcode, vcode;
637 struct nvldbentry entry, storeEntry; /*the new vldb entry */
638 struct volintInfo tstatus;
641 aconn = (struct rx_connection *)0;
644 init_volintInfo(&tstatus);
645 tstatus.maxquota = aquota;
647 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
648 /* next the next 3 available ids from the VLDB */
649 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 3, anewid);
650 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
653 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
654 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
657 code = AFSVolSetInfo(aconn, tid, &tstatus);
659 EPRINT(code, "Could not change quota, continuing...\n");
661 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
662 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
665 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
667 /* set up the vldb entry for this volume */
668 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
670 entry.serverNumber[0] = aserver; /* this should have another
671 * level of indirection later */
672 entry.serverPartition[0] = apart; /* this should also have
673 * another indirection level */
674 entry.flags = RW_EXISTS; /* this records that rw volume exists */
675 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
676 entry.volumeId[RWVOL] = *anewid;
677 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
678 entry.volumeId[BACKVOL] = *anewid + 2;
680 /*map into right byte order, before passing to xdr, the stuff has to be in host
681 * byte order. Xdr converts it into network order */
682 MapNetworkToHost(&entry, &storeEntry);
683 /* create the vldb entry */
684 vcode = VLDB_CreateEntry(&storeEntry);
687 "Could not create a VLDB entry for the volume %s %lu\n",
688 aname, (unsigned long)*anewid);
689 /*destroy the created volume */
690 VPRINT1("Deleting the newly created volume %u\n", *anewid);
691 AFSVolDeleteVolume(aconn, tid);
695 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
696 /* volume created, now terminate the transaction and release the connection */
697 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
698 * the volume will come online anyway when transaction timesout , so if
699 * vldb entry exists then the volume is guaranteed to exist too wrt create */
703 "Failed to end the transaction on the volume %s %lu\n", aname,
704 (unsigned long)*anewid);
711 code = AFSVolEndTrans(aconn, tid, &rcode);
713 fprintf(STDERR, "WARNING: could not end transaction\n");
716 rx_DestroyConnection(aconn);
717 PrintError("", error);
723 /* create a volume, given a server, partition number, volume name --> sends
724 * back new vol id in <anewid>*/
726 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
729 register struct rx_connection *aconn;
732 struct nvldbentry entry, storeEntry; /*the new vldb entry */
734 aconn = (struct rx_connection *)0;
737 /* set up the vldb entry for this volume */
738 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
740 entry.serverNumber[0] = aserver; /* this should have another
741 * level of indirection later */
742 entry.serverPartition[0] = apart; /* this should also have
743 * another indirection level */
744 entry.flags = RW_EXISTS; /* this records that rw volume exists */
745 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
746 entry.volumeId[RWVOL] = aid;
748 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
749 entry.volumeId[BACKVOL] = *anewid + 2;
751 entry.volumeId[ROVOL] = 0;
752 entry.volumeId[BACKVOL] = 0;
755 /*map into right byte order, before passing to xdr, the stuff has to be in host
756 * byte order. Xdr converts it into network order */
757 MapNetworkToHost(&entry, &storeEntry);
758 /* create the vldb entry */
759 vcode = VLDB_CreateEntry(&storeEntry);
762 "Could not create a VLDB entry for the volume %s %lu\n",
763 aname, (unsigned long)aid);
767 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
771 rx_DestroyConnection(aconn);
772 PrintError("", error);
776 /* Delete the volume <volid>on <aserver> <apart>
777 * the physical entry gets removed from the vldb only if the ref count
781 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
783 struct rx_connection *aconn = (struct rx_connection *)0;
785 afs_int32 code, rcode;
787 struct nvldbentry entry, storeEntry;
789 afs_int32 avoltype = -1, vtype;
790 int notondisk = 0, notinvldb = 0;
792 /* Find and read bhe VLDB entry for this volume */
793 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
795 if (code != VL_NOENT) {
796 EGOTO1(error_exit, code,
797 "Could not lock VLDB entry for the volume %u\n", avolid);
803 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
804 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
806 MapHostToNetwork(&entry);
809 EnumerateEntry(&entry);
812 /* Whether volume is in the VLDB or not. Delete the volume on disk */
813 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
814 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
816 if (code == VNOVOL) {
819 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
823 VPRINT1("Trying to delete the volume %u ...", avolid);
825 code = AFSVolDeleteVolume(aconn, ttid);
826 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
828 code = AFSVolEndTrans(aconn, ttid, &rcode);
829 code = (code ? code : rcode);
831 EGOTO1(error_exit, code,
832 "Could not end the transaction for the volume %u \n", avolid);
836 /* Now update the VLDB entry.
837 * But first, verify we have a VLDB entry.
838 * Whether volume is on disk or not. Delete the volume in VLDB.
843 if (avolid == entry.volumeId[BACKVOL]) {
844 /* Its a backup volume, modify the VLDB entry. Check that the
845 * backup volume is on the server/partition we asked to delete.
847 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
848 notinvldb = 2; /* Not on this server and partition */
852 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
854 entry.flags &= ~BACK_EXISTS;
858 else if (avolid == entry.volumeId[ROVOL]) {
859 /* Its a read-only volume, modify the VLDB entry. Check that the
860 * readonly volume is on the server/partition we asked to delete.
861 * If flags does not have RO_EIXSTS set, then this may mean the RO
862 * hasn't been released (and could exist in VLDB).
864 if (!Lp_ROMatch(aserver, apart, &entry)) {
865 notinvldb = 2; /* Not found on this server and partition */
871 "Marking the readonly volume %lu deleted in the VLDB\n",
872 (unsigned long)avolid);
874 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
876 if (!Lp_ROMatch(0, 0, &entry))
877 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
881 else if (avolid == entry.volumeId[RWVOL]) {
882 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
883 * Check that the readwrite volumes is on the server/partition we
886 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
887 notinvldb = 2; /* Not found on this server and partition */
891 /* Delete backup if it exists */
893 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
897 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
898 entry.volumeId[BACKVOL]);
901 code = AFSVolDeleteVolume(aconn, ttid);
902 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
903 entry.volumeId[BACKVOL]);
905 code = AFSVolEndTrans(aconn, ttid, &rcode);
907 code = (code ? code : rcode);
908 EGOTO1(error_exit, code,
909 "Could not end the transaction for the volume %u \n",
910 entry.volumeId[BACKVOL]);
912 fprintf(STDOUT, " done\n");
917 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
918 (unsigned long)avolid,
920 flags & BACK_EXISTS) ? ", and its backup volume," :
923 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
925 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
928 if (entry.flags & RO_EXISTS)
929 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
933 notinvldb = 2; /* Not found on this server and partition */
937 /* Either delete or replace the VLDB entry */
938 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
941 "Last reference to the VLDB entry for %lu - deleting entry\n",
942 (unsigned long)avolid);
943 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
944 EGOTO1(error_exit, code,
945 "Could not delete the VLDB entry for the volume %u \n",
948 MapNetworkToHost(&entry, &storeEntry);
950 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
951 (LOCKREL_OPCODE | LOCKREL_AFSID |
953 EGOTO1(error_exit, code,
954 "Could not update the VLDB entry for the volume %u \n",
963 if (notondisk && notinvldb) {
964 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
965 ((notinvldb == 2) ? "on server and partition" : ""));
968 } else if (notondisk) {
970 "WARNING: Volume %lu did not exist on the partition\n",
971 (unsigned long)avolid);
972 } else if (notinvldb) {
973 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
974 (unsigned long)avolid,
975 ((notinvldb == 2) ? "on server and partition" : ""));
979 code = AFSVolEndTrans(aconn, ttid, &rcode);
980 code = (code ? code : rcode);
982 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
983 (unsigned long)avolid);
984 PrintError("", code);
992 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
993 (LOCKREL_OPCODE | LOCKREL_AFSID |
997 "Could not release the lock on the VLDB entry for the volume %u \n",
1005 rx_DestroyConnection(aconn);
1009 /* add recovery to UV_MoveVolume */
1011 #define TESTC 0 /* set to test recovery code, clear for production */
1017 sigint_handler(int x)
1022 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1024 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1025 fprintf(STDOUT, "enter second control-c to exit\n");
1029 (void)signal(SIGINT, sigint_handler);
1034 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1035 * <atopart>. The operation is almost idempotent. The following
1036 * flags are recognized:
1038 * RV_NOCLONE - don't use a copy clone
1042 UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1043 afs_int32 atoserver, afs_int32 atopart, int flags)
1045 struct rx_connection *toconn, *fromconn;
1046 afs_int32 fromtid, totid, clonetid;
1049 char tmpName[VOLSER_MAXVOLNAME + 1];
1052 struct restoreCookie cookie;
1053 register afs_int32 vcode, code;
1054 afs_int32 newVol, volid, backupId;
1055 struct volser_status tstatus;
1056 struct destServer destination;
1058 struct nvldbentry entry, storeEntry;
1059 int i, islocked, pntg;
1061 char in, lf; /* for test code */
1064 #ifdef ENABLE_BUGFIX_1165
1065 volEntries volumeInfo;
1066 struct volintInfo *infop = 0;
1070 fromconn = (struct rx_connection *)0;
1071 toconn = (struct rx_connection *)0;
1081 /* support control-c processing */
1084 (void)signal(SIGINT, sigint_handler);
1088 "\nThere are three tests points - verifies all code paths through recovery.\n");
1089 fprintf(STDOUT, "First test point - operation not started.\n");
1090 fprintf(STDOUT, "...test here (y, n)? ");
1092 fscanf(stdin, "%c", &in);
1093 fscanf(stdin, "%c", &lf); /* toss away */
1095 fprintf(STDOUT, "type control-c\n");
1097 fprintf(stdout, ".");
1102 /* or drop through */
1105 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1106 EGOTO1(mfail, vcode,
1107 "Could not fetch the entry for the volume %u from the VLDB \n",
1110 if (entry.volumeId[RWVOL] != afromvol) {
1111 fprintf(STDERR, "Only RW volume can be moved\n");
1115 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1116 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1119 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1120 EGOTO1(mfail, vcode,
1121 "Could not fetch the entry for the volume %u from the VLDB \n",
1124 backupId = entry.volumeId[BACKVOL];
1125 MapHostToNetwork(&entry);
1127 if (!Lp_Match(afromserver, afrompart, &entry)) {
1128 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1129 if (!Lp_Match(atoserver, atopart, &entry)) {
1130 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1131 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1132 (unsigned long)afromvol);
1133 fprintf(STDERR, "The current site is :");
1134 for (i = 0; i < entry.nServers; i++) {
1135 if (entry.serverFlags[i] == ITSRWVOL) {
1137 MapPartIdIntoName(entry.serverPartition[i], pname);
1138 fprintf(STDERR, " server %s partition %s \n",
1139 hostutil_GetNameByINet(entry.serverNumber[i]),
1144 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1145 (LOCKREL_OPCODE | LOCKREL_AFSID |
1146 LOCKREL_TIMESTAMP));
1147 EGOTO1(mfail, vcode,
1148 " Could not release lock on the VLDB entry for the volume %u \n",
1151 return VOLSERVOLMOVED;
1154 /* delete the volume afromvol on src_server */
1155 /* from-info does not exist but to-info does =>
1156 * we have already done the move, but the volume
1157 * may still be existing physically on from fileserver
1159 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1164 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1166 if (!code) { /* volume exists - delete it */
1167 VPRINT1("Setting flags on leftover source volume %u ...",
1170 AFSVolSetFlags(fromconn, fromtid,
1171 VTDeleteOnSalvage | VTOutOfService);
1173 "Failed to set flags on the leftover source volume %u\n",
1177 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1178 code = AFSVolDeleteVolume(fromconn, fromtid);
1180 "Failed to delete the leftover source volume %u\n",
1184 VPRINT1("Ending transaction on leftover source volume %u ...",
1186 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1191 "Could not end the transaction for the leftover source volume %u \n",
1196 /*delete the backup volume now */
1199 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1201 if (!code) { /* backup volume exists - delete it */
1202 VPRINT1("Setting flags on leftover backup volume %u ...",
1205 AFSVolSetFlags(fromconn, fromtid,
1206 VTDeleteOnSalvage | VTOutOfService);
1208 "Failed to set flags on the backup volume %u\n", backupId);
1211 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1212 code = AFSVolDeleteVolume(fromconn, fromtid);
1214 "Could not delete the leftover backup volume %u\n",
1218 VPRINT1("Ending transaction on leftover backup volume %u ...",
1220 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1225 "Could not end the transaction for the leftover backup volume %u\n",
1235 /* From-info matches the vldb info about volid,
1236 * its ok start the move operation, the backup volume
1237 * on the old site is deleted in the process
1239 if (afrompart == atopart) {
1240 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1241 EGOTO2(mfail, error,
1242 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1243 afromserver, error);
1246 EGOTO1(mfail, VOLSERVOLMOVED,
1247 "Warning: Moving volume %u to its home partition ignored!\n",
1253 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1254 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1255 fromtid = totid = 0; /* initialize to uncreated */
1258 * clone the read/write volume locally.
1261 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1262 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1263 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1267 if (!(flags & RV_NOCLONE)) {
1268 /* Get a clone id */
1269 VPRINT1("Allocating new volume id for clone of volume %u ...",
1272 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1273 EGOTO1(mfail, vcode,
1274 "Could not get an ID for the clone of volume %u from the VLDB\n",
1278 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1279 VPRINT1("Cloning source volume %u ...", afromvol);
1280 strcpy(vname, "move-clone-temp");
1282 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1283 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1288 /* lookup the name of the volume we just cloned */
1290 code = AFSVolGetName(fromconn, fromtid, &volName);
1291 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1294 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1296 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1301 "Failed to end the transaction on the source volume %u\n",
1306 * Create the destination volume
1309 if (!(flags & RV_NOCLONE)) {
1310 /* All of this is to get the fromDate */
1311 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1313 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1316 "Failed to start a transaction on the cloned volume%u\n",
1320 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1322 AFSVolSetFlags(fromconn, clonetid,
1323 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1324 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1328 /* remember time from which we've dumped the volume */
1329 VPRINT1("Getting status of cloned volume %u ...", newVol);
1330 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1332 "Failed to get the status of the cloned volume %u\n",
1336 fromDate = CLOCKADJ(tstatus.creationDate);
1338 /* With RV_NOCLONE, just do a full copy from the source */
1343 #ifdef ENABLE_BUGFIX_1165
1345 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1346 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1347 * don't use this information...
1349 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1350 volumeInfo.volEntries_len = 0;
1351 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1353 "Failed to get the volint Info of the cloned volume %u\n",
1356 infop = (volintInfo *) volumeInfo.volEntries_val;
1357 infop->maxquota = -1; /* Else it will replace the default quota */
1358 infop->creationDate = -1; /* Else it will use the source creation date */
1359 infop->updateDate = -1; /* Else it will use the source update date */
1362 /* create a volume on the target machine */
1364 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1366 /* Delete the existing volume.
1367 * While we are deleting the volume in these steps, the transaction
1368 * we started against the cloned volume (clonetid above) will be
1369 * sitting idle. It will get cleaned up after 600 seconds
1371 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1372 code = AFSVolDeleteVolume(toconn, totid);
1374 "Could not delete the pre-existing volume %u on destination\n",
1379 ("Ending transaction on pre-existing volume %u on destination ...",
1381 code = AFSVolEndTrans(toconn, totid, &rcode);
1386 "Could not end the transaction on pre-existing volume %u on destination\n",
1391 VPRINT1("Creating the destination volume %u ...", volid);
1393 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1395 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1399 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1403 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1405 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1407 "Failed to set the flags on the destination volume %u\n", volid);
1411 * Now dump the clone to the new volume
1414 destination.destHost = ntohl(atoserver);
1415 destination.destPort = AFSCONF_VOLUMEPORT;
1416 destination.destSSID = 1;
1418 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1419 cookie.type = RWVOL;
1420 cookie.parent = entry.volumeId[RWVOL];
1423 if (!(flags & RV_NOCLONE)) {
1424 /* Copy the clone to the new volume */
1425 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1428 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1430 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1433 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1434 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1439 "Failed to end the transaction on the cloned volume %u\n",
1445 * reattach to the main-line volume, and incrementally dump it.
1448 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1449 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1451 "Failed to create a transaction on the source volume %u\n",
1455 /* now do the incremental */
1457 ("Doing the%s dump from source to destination for volume %u ... ",
1458 (flags & RV_NOCLONE) ? "" : " incremental",
1461 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1464 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1465 (flags & RV_NOCLONE) ? "" : " incremental");
1468 /* now adjust the flags so that the new volume becomes official */
1469 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1470 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1472 "Failed to set the flags to make old source volume offline\n");
1475 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1476 code = AFSVolSetFlags(toconn, totid, 0);
1478 "Failed to set the flags to make new source volume online\n");
1481 #ifdef ENABLE_BUGFIX_1165
1482 VPRINT1("Setting volume status on destination volume %u ...", volid);
1483 code = AFSVolSetInfo(toconn, totid, infop);
1485 "Failed to set volume status on the destination volume %u\n",
1490 /* put new volume online */
1491 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1492 code = AFSVolEndTrans(toconn, totid, &rcode);
1497 "Failed to end the transaction on the volume %u on the new site\n",
1501 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1502 MapNetworkToHost(&entry, &storeEntry);
1503 storeEntry.flags &= ~BACK_EXISTS;
1507 "Second test point - operation in progress but not complete.\n");
1508 fprintf(STDOUT, "...test here (y, n)? ");
1510 fscanf(stdin, "%c", &in);
1511 fscanf(stdin, "%c", &lf); /* toss away */
1513 fprintf(STDOUT, "type control-c\n");
1515 fprintf(stdout, ".");
1520 /* or drop through */
1523 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1525 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1526 (LOCKREL_OPCODE | LOCKREL_AFSID |
1527 LOCKREL_TIMESTAMP));
1530 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1531 storeEntry.name, (unsigned long)afromvol);
1540 "Third test point - operation complete but no cleanup.\n");
1541 fprintf(STDOUT, "...test here (y, n)? ");
1543 fscanf(stdin, "%c", &in);
1544 fscanf(stdin, "%c", &lf); /* toss away */
1546 fprintf(STDOUT, "type control-c\n");
1548 fprintf(stdout, ".");
1553 /* or drop through */
1556 /* This is tricky. File server is very stupid, and if you mark the volume
1557 * as VTOutOfService, it may mark the *good* instance (if you're moving
1558 * between partitions on the same machine) as out of service. Since
1559 * we're cleaning this code up in DEcorum, we're just going to kludge around
1560 * it for now by removing this call. */
1561 /* already out of service, just zap it now */
1563 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1566 "Failed to set the flags to make the old source volume offline\n");
1570 if (atoserver != afromserver) {
1571 /* set forwarding pointer for moved volumes */
1572 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1573 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1575 "Failed to set the forwarding pointer for the volume %u\n",
1580 VPRINT1("Deleting old volume %u on source ...", afromvol);
1581 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1582 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1586 VPRINT1("Ending transaction on old volume %u on the source ...",
1588 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1593 "Failed to end the transaction on the old volume %u on the source\n",
1597 /* Delete the backup volume on the original site */
1598 VPRINT1("Creating transaction for backup volume %u on source ...",
1601 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1604 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1606 AFSVolSetFlags(fromconn, fromtid,
1607 VTDeleteOnSalvage | VTOutOfService);
1609 "Failed to set the flags on the backup volume %u on the source\n",
1613 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1614 code = AFSVolDeleteVolume(fromconn, fromtid);
1616 "Failed to delete the backup volume %u on the source\n",
1620 VPRINT1("Ending transaction on backup volume %u on source ...",
1622 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1627 "Failed to end the transaction on the backup volume %u on the source\n",
1631 code = 0; /* no backup volume? that's okay */
1634 if (!(flags & RV_NOCLONE)) {
1635 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1637 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1640 "Failed to start a transaction on the cloned volume%u\n",
1644 /* now delete the clone */
1645 VPRINT1("Deleting the cloned volume %u ...", newVol);
1646 code = AFSVolDeleteVolume(fromconn, clonetid);
1647 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1651 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1652 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1657 "Failed to end the transaction on the cloned volume %u\n",
1666 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1667 fprintf(STDOUT, "...test here (y, n)? ");
1669 fscanf(stdin, "%c", &in);
1670 fscanf(stdin, "%c", &lf); /* toss away */
1672 fprintf(STDOUT, "type control-c\n");
1674 fprintf(stdout, ".");
1679 /* or drop through */
1682 /* normal cleanup code */
1684 if (entry.flags & RO_EXISTS)
1685 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1688 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1690 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1691 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1695 " Could not release the lock on the VLDB entry for the volume %lu \n",
1696 (unsigned long)afromvol);
1704 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1706 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1707 if (code || rcode) {
1710 "Could not end transaction on the source volume %lu\n",
1711 (unsigned long)afromvol);
1713 error = (code ? code : rcode);
1719 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1720 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1721 if (code || rcode) {
1724 "Could not end transaction on the source's clone volume %lu\n",
1725 (unsigned long)newVol);
1727 error = (code ? code : rcode);
1733 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1735 code = AFSVolEndTrans(toconn, totid, &rcode);
1739 "Could not end transaction on destination volume %lu\n",
1740 (unsigned long)afromvol);
1742 error = (code ? code : rcode);
1748 #ifdef ENABLE_BUGFIX_1165
1753 rx_DestroyConnection(fromconn);
1755 rx_DestroyConnection(toconn);
1756 PrintError("", error);
1759 /* come here only when the sky falls */
1764 "vos move: operation interrupted, cleanup in progress...\n");
1765 fprintf(STDOUT, "clear transaction contexts\n");
1769 /* unlock VLDB entry */
1771 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1772 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1773 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1778 VPRINT("Recovery: Ending transaction on clone volume ...");
1779 AFSVolEndTrans(fromconn, clonetid, &rcode);
1783 VPRINT("Recovery: Ending transaction on destination volume ...");
1784 AFSVolEndTrans(toconn, totid, &rcode);
1787 if (fromtid) { /* put it on-line */
1788 VPRINT("Recovery: Setting volume flags on source volume ...");
1789 AFSVolSetFlags(fromconn, fromtid, 0);
1792 VPRINT("Recovery: Ending transaction on source volume ...");
1793 AFSVolEndTrans(fromconn, fromtid, &rcode);
1797 VPRINT("Recovery: Accessing VLDB.\n");
1798 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1800 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1804 MapHostToNetwork(&entry);
1806 /* Delete either the volume on the source location or the target location.
1807 * If the vldb entry still points to the source location, then we know the
1808 * volume move didn't finish so we remove the volume from the target
1809 * location. Otherwise, we remove the volume from the source location.
1811 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1814 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1818 if (volid && toconn) {
1820 ("Recovery: Creating transaction for destination volume %u ...",
1823 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1829 ("Recovery: Setting flags on destination volume %u ...",
1831 AFSVolSetFlags(toconn, totid,
1832 VTDeleteOnSalvage | VTOutOfService);
1835 VPRINT1("Recovery: Deleting destination volume %u ...",
1837 AFSVolDeleteVolume(toconn, totid);
1841 ("Recovery: Ending transaction on destination volume %u ...",
1843 AFSVolEndTrans(toconn, totid, &rcode);
1847 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1852 /* put source volume on-line */
1854 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1857 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1862 VPRINT1("Recovery: Setting flags on source volume %u ...",
1864 AFSVolSetFlags(fromconn, fromtid, 0);
1868 ("Recovery: Ending transaction on source volume %u ...",
1870 AFSVolEndTrans(fromconn, fromtid, &rcode);
1874 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1878 } else { /* yep, move complete */
1881 "move complete - attempt cleanup of source partition - no guarantee\n");
1885 /* delete backup volume */
1887 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1890 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1895 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1897 AFSVolSetFlags(fromconn, fromtid,
1898 VTDeleteOnSalvage | VTOutOfService);
1901 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1902 AFSVolDeleteVolume(fromconn, fromtid);
1906 ("Recovery: Ending transaction on backup volume %u ...",
1908 AFSVolEndTrans(fromconn, fromtid, &rcode);
1912 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1916 /* delete source volume */
1917 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1920 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1925 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1927 AFSVolSetFlags(fromconn, fromtid,
1928 VTDeleteOnSalvage | VTOutOfService);
1931 if (atoserver != afromserver) {
1932 VPRINT("Recovery: Setting volume forwarding pointer ...");
1933 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1937 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1938 AFSVolDeleteVolume(fromconn, fromtid);
1942 ("Recovery: Ending transaction on source volume %u ...",
1944 AFSVolEndTrans(fromconn, fromtid, &rcode);
1948 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1954 /* common cleanup - delete local clone */
1956 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1959 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1964 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1965 AFSVolDeleteVolume(fromconn, clonetid);
1968 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1970 AFSVolEndTrans(fromconn, clonetid, &rcode);
1974 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1979 /* unlock VLDB entry */
1980 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
1982 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1983 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1986 done: /* routine cleanup */
1989 #ifdef ENABLE_BUGFIX_1165
1994 rx_DestroyConnection(fromconn);
1996 rx_DestroyConnection(toconn);
1999 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2007 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2008 afs_int32 atoserver, afs_int32 atopart)
2010 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2011 atoserver, atopart, 0);
2015 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2016 * <atopart>. The new volume is named by <atovolname>. The new volume
2017 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2018 * from the VLDB. the following flags are supported:
2020 * RV_RDONLY - target volume is RO
2021 * RV_OFFLINE - leave target volume offline
2022 * RV_CPINCR - do incremental dump if target exists
2023 * RV_NOVLDB - don't create/update VLDB entry
2024 * RV_NOCLONE - don't use a copy clone
2027 UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2028 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2029 afs_int32 atovolid, int flags)
2031 struct rx_connection *toconn, *fromconn;
2032 afs_int32 fromtid, totid, clonetid;
2035 afs_int32 fromDate, cloneFromDate;
2036 struct restoreCookie cookie;
2037 register afs_int32 vcode, code;
2038 afs_int32 cloneVol, newVol, volflag;
2039 struct volser_status tstatus;
2040 struct destServer destination;
2042 struct nvldbentry entry, newentry, storeEntry;
2048 fromconn = (struct rx_connection *)0;
2049 toconn = (struct rx_connection *)0;
2057 /* support control-c processing */
2060 (void)signal(SIGINT, sigint_handler);
2062 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2063 EGOTO1(mfail, vcode,
2064 "Could not fetch the entry for the volume %u from the VLDB \n",
2066 MapHostToNetwork(&entry);
2069 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2070 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2071 fromtid = totid = 0; /* initialize to uncreated */
2074 /* check if we can shortcut and use a local clone instead of a full copy */
2075 if (afromserver == atoserver && afrompart == atopart) {
2080 * clone the read/write volume locally.
2084 if (!(flags & RV_NOCLONE)) {
2085 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2086 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2088 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2092 /* Get a clone id */
2093 VPRINT1("Allocating new volume id for clone of volume %u ...",
2096 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2097 EGOTO1(mfail, vcode,
2098 "Could not get an ID for the clone of volume %u from the VLDB\n",
2106 /* Get a new volume id */
2107 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2109 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2110 EGOTO1(mfail, vcode,
2111 "Could not get an ID for the copy of volume %u from the VLDB\n",
2116 if (!(flags & RV_NOCLONE)) {
2117 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2118 VPRINT1("Cloning source volume %u ...", afromvol);
2119 strcpy(vname, "copy-clone-temp");
2121 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2123 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2127 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2129 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2134 "Failed to end the transaction on the source volume %u\n",
2140 * Create the destination volume
2143 if (!(flags & RV_NOCLONE)) {
2144 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2146 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2149 "Failed to start a transaction on the cloned volume%u\n",
2153 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2155 AFSVolSetFlags(fromconn, clonetid,
2156 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2157 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2161 /* remember time from which we've dumped the volume */
2162 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2163 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2165 "Failed to get the status of the cloned volume %u\n",
2169 fromDate = CLOCKADJ(tstatus.creationDate);
2174 /* create a volume on the target machine */
2176 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2178 if ((flags & RV_CPINCR)) {
2179 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2180 code = AFSVolGetStatus(toconn, totid, &tstatus);
2182 "Failed to get the status of the pre-existing volume %u\n",
2186 /* Using the update date should be OK here, but add some fudge */
2187 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2188 if ((flags & RV_NOCLONE))
2189 fromDate = cloneFromDate;
2191 /* XXX We should check that the source volume's creationDate is
2192 * XXX not newer than the existing target volume, and if not,
2193 * XXX throw away the existing target and do a full dump. */
2198 /* Delete the existing volume.
2199 * While we are deleting the volume in these steps, the transaction
2200 * we started against the cloned volume (clonetid above) will be
2201 * sitting idle. It will get cleaned up after 600 seconds
2203 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2204 code = AFSVolDeleteVolume(toconn, totid);
2206 "Could not delete the pre-existing volume %u on destination\n",
2211 ("Ending transaction on pre-existing volume %u on destination ...",
2213 code = AFSVolEndTrans(toconn, totid, &rcode);
2218 "Could not end the transaction on pre-existing volume %u on destination\n",
2223 VPRINT1("Creating the destination volume %u ...", newVol);
2225 AFSVolCreateVolume(toconn, atopart, atovolname,
2226 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2227 newVol, &newVol, &totid);
2228 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2232 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2234 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2236 "Failed to set the flags on the destination volume %u\n", newVol);
2241 destination.destHost = ntohl(atoserver);
2242 destination.destPort = AFSCONF_VOLUMEPORT;
2243 destination.destSSID = 1;
2245 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2246 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2251 * Now dump the clone to the new volume
2254 if (!(flags & RV_NOCLONE)) {
2255 /* XXX probably should have some code here that checks to see if
2256 * XXX we are copying to same server and partition - if so, just
2257 * XXX use a clone to save disk space */
2259 /* Copy the clone to the new volume */
2260 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2263 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2265 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2269 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2270 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2275 "Failed to end the transaction on the cloned volume %u\n",
2281 * reattach to the main-line volume, and incrementally dump it.
2284 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2285 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2287 "Failed to create a transaction on the source volume %u\n",
2291 /* now do the incremental */
2293 ("Doing the%s dump from source to destination for volume %u ... ",
2294 (flags & RV_NOCLONE) ? "" : " incremental",
2297 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2300 "Failed to do the%s dump from old site to new site\n",
2304 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2305 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2306 code = AFSVolSetFlags(toconn, totid, volflag);
2308 "Failed to set the flags to make destination volume online\n");
2311 /* put new volume online */
2312 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2313 code = AFSVolEndTrans(toconn, totid, &rcode);
2318 "Failed to end the transaction on the destination volume %u\n",
2322 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2323 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2328 "Failed to end the transaction on the source volume %u\n",
2334 if (!(flags & RV_NOCLONE)) {
2335 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2337 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2340 "Failed to start a transaction on the cloned volume%u\n",
2344 /* now delete the clone */
2345 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2346 code = AFSVolDeleteVolume(fromconn, clonetid);
2347 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2351 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2352 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2357 "Failed to end the transaction on the cloned volume %u\n",
2362 if (!(flags & RV_NOVLDB)) {
2363 /* create the vldb entry for the copied volume */
2364 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2365 newentry.nServers = 1;
2366 newentry.serverNumber[0] = atoserver;
2367 newentry.serverPartition[0] = atopart;
2368 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2369 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2370 newentry.volumeId[RWVOL] = newVol;
2371 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2372 newentry.volumeId[BACKVOL] = 0;
2373 newentry.cloneId = 0;
2374 /*map into right byte order, before passing to xdr, the stuff has to be in host
2375 * byte order. Xdr converts it into network order */
2376 MapNetworkToHost(&newentry, &storeEntry);
2377 /* create the vldb entry */
2378 vcode = VLDB_CreateEntry(&storeEntry);
2381 "Could not create a VLDB entry for the volume %s %lu\n",
2382 atovolname, (unsigned long)newVol);
2383 /*destroy the created volume */
2384 VPRINT1("Deleting the newly created volume %u\n", newVol);
2385 AFSVolDeleteVolume(toconn, totid);
2389 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2393 /* normal cleanup code */
2396 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2398 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2399 if (code || rcode) {
2402 "Could not end transaction on the source volume %lu\n",
2403 (unsigned long)afromvol);
2405 error = (code ? code : rcode);
2411 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2413 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2414 if (code || rcode) {
2417 "Could not end transaction on the source's clone volume %lu\n",
2418 (unsigned long)cloneVol);
2420 error = (code ? code : rcode);
2426 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2428 code = AFSVolEndTrans(toconn, totid, &rcode);
2432 "Could not end transaction on destination volume %lu\n",
2433 (unsigned long)newVol);
2435 error = (code ? code : rcode);
2440 rx_DestroyConnection(fromconn);
2442 rx_DestroyConnection(toconn);
2443 PrintError("", error);
2446 /* come here only when the sky falls */
2451 "vos copy: operation interrupted, cleanup in progress...\n");
2452 fprintf(STDOUT, "clear transaction contexts\n");
2457 VPRINT("Recovery: Ending transaction on clone volume ...");
2458 AFSVolEndTrans(fromconn, clonetid, &rcode);
2462 VPRINT("Recovery: Ending transaction on destination volume ...");
2463 AFSVolEndTrans(toconn, totid, &rcode);
2466 if (fromtid) { /* put it on-line */
2467 VPRINT("Recovery: Ending transaction on source volume ...");
2468 AFSVolEndTrans(fromconn, fromtid, &rcode);
2472 VPRINT("Recovery: Accessing VLDB.\n");
2473 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2475 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2479 MapHostToNetwork(&entry);
2481 /* common cleanup - delete local clone */
2483 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2486 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2491 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2492 AFSVolDeleteVolume(fromconn, clonetid);
2495 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2497 AFSVolEndTrans(fromconn, clonetid, &rcode);
2501 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2506 done: /* routine cleanup */
2508 rx_DestroyConnection(fromconn);
2510 rx_DestroyConnection(toconn);
2513 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2521 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2522 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2524 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2525 atovolname, atoserver, atopart, 0, 0);
2530 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2531 * if one already exists, update it
2535 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2537 struct rx_connection *aconn = (struct rx_connection *)0;
2538 afs_int32 ttid = 0, btid = 0;
2540 afs_int32 code = 0, rcode = 0;
2541 char vname[VOLSER_MAXVOLNAME + 1];
2542 struct nvldbentry entry, storeEntry;
2543 afs_int32 error = 0;
2544 int vldblocked = 0, vldbmod = 0, backexists = 1;
2546 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2548 /* the calls to VLDB will succeed only if avolid is a RW volume,
2549 * since we are following the RW hash chain for searching */
2550 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2553 "Could not fetch the entry for the volume %lu from the VLDB \n",
2554 (unsigned long)avolid);
2558 MapHostToNetwork(&entry);
2560 /* These operations require the VLDB be locked since it means the VLDB
2561 * will change or the vldb is already locked.
2563 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2564 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2565 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2567 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2570 "Could not lock the VLDB entry for the volume %lu\n",
2571 (unsigned long)avolid);
2577 /* Reread the vldb entry */
2578 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2581 "Could not fetch the entry for the volume %lu from the VLDB \n",
2582 (unsigned long)avolid);
2586 MapHostToNetwork(&entry);
2589 if (!ISNAMEVALID(entry.name)) {
2590 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2592 error = VOLSERBADNAME;
2596 backupID = entry.volumeId[BACKVOL];
2597 if (backupID == INVALID_BID) {
2598 /* Get a backup volume id from the VLDB and update the vldb
2601 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2604 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2605 (unsigned long)avolid);
2609 entry.volumeId[BACKVOL] = backupID;
2613 /* Test to see if the backup volume exists by trying to create
2614 * a transaction on the backup volume. We've assumed the backup exists.
2616 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2618 if (code != VNOVOL) {
2619 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2620 (unsigned long)backupID);
2624 backexists = 0; /* backup volume does not exist */
2627 code = AFSVolEndTrans(aconn, btid, &rcode);
2629 if (code || rcode) {
2631 "Could not end transaction on the previous backup volume %lu\n",
2632 (unsigned long)backupID);
2633 error = (code ? code : rcode);
2638 /* Now go ahead and try to clone the RW volume.
2639 * First start a transaction on the RW volume
2641 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2643 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2644 (unsigned long)avolid);
2649 /* Clone or reclone the volume, depending on whether the backup
2650 * volume exists or not
2653 VPRINT1("Re-cloning backup volume %u ...", backupID);
2655 code = AFSVolReClone(aconn, ttid, backupID);
2657 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2658 (unsigned long)backupID);
2663 VPRINT1("Creating a new backup clone %u ...", backupID);
2665 strcpy(vname, entry.name);
2666 strcat(vname, ".backup");
2668 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2670 fprintf(STDERR, "Failed to clone the volume %lu\n",
2671 (unsigned long)avolid);
2677 /* End the transaction on the RW volume */
2678 code = AFSVolEndTrans(aconn, ttid, &rcode);
2680 if (code || rcode) {
2682 "Failed to end the transaction on the rw volume %lu\n",
2683 (unsigned long)avolid);
2684 error = (code ? code : rcode);
2688 /* Mork vldb as backup exists */
2689 if (!(entry.flags & BACK_EXISTS)) {
2690 entry.flags |= BACK_EXISTS;
2694 /* Now go back to the backup volume and bring it on line */
2695 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2698 "Failed to start a transaction on the backup volume %lu\n",
2699 (unsigned long)backupID);
2704 code = AFSVolSetFlags(aconn, btid, 0);
2706 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2707 (unsigned long)backupID);
2712 code = AFSVolEndTrans(aconn, btid, &rcode);
2714 if (code || rcode) {
2716 "Failed to end the transaction on the backup volume %lu\n",
2717 (unsigned long)backupID);
2718 error = (code ? code : rcode);
2724 /* Will update the vldb below */
2728 code = AFSVolEndTrans(aconn, ttid, &rcode);
2729 if (code || rcode) {
2730 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2731 (unsigned long)avolid);
2733 error = (code ? code : rcode);
2738 code = AFSVolEndTrans(aconn, btid, &rcode);
2739 if (code || rcode) {
2741 "Could not end transaction the backup volume %lu\n",
2742 (unsigned long)backupID);
2744 error = (code ? code : rcode);
2748 /* Now update the vldb - if modified */
2751 MapNetworkToHost(&entry, &storeEntry);
2753 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2754 (LOCKREL_OPCODE | LOCKREL_AFSID |
2755 LOCKREL_TIMESTAMP));
2758 "Could not update the VLDB entry for the volume %lu \n",
2759 (unsigned long)avolid);
2765 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2766 (LOCKREL_OPCODE | LOCKREL_AFSID |
2767 LOCKREL_TIMESTAMP));
2770 "Could not unlock the VLDB entry for the volume %lu \n",
2771 (unsigned long)avolid);
2779 rx_DestroyConnection(aconn);
2781 PrintError("", error);
2785 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2786 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2787 * The new volume is named by <aname>, or by appending ".clone" to
2788 * the existing name if <aname> is NULL. The following flags are
2791 * RV_RDONLY - target volume is RO
2792 * RV_OFFLINE - leave target volume offline
2796 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
2797 afs_int32 acloneid, char *aname, int flags)
2799 struct rx_connection *aconn = (struct rx_connection *)0;
2800 afs_int32 ttid = 0, btid = 0;
2801 afs_int32 code = 0, rcode = 0;
2802 char vname[VOLSER_MAXVOLNAME + 1];
2803 afs_int32 error = 0;
2805 volEntries volumeInfo;
2807 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2810 volumeInfo.volEntries_val = (volintInfo *) 0;
2811 volumeInfo.volEntries_len = 0;
2812 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2814 fprintf(stderr, "Could not get info for volume %lu\n",
2815 (unsigned long)avolid);
2819 strncpy(vname, volumeInfo.volEntries_val[0].name,
2820 VOLSER_OLDMAXVOLNAME - 7);
2821 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2822 strcat(vname, ".clone");
2824 if (volumeInfo.volEntries_val)
2825 free(volumeInfo.volEntries_val);
2829 /* Get a clone id */
2830 VPRINT1("Allocating new volume id for clone of volume %u ...",
2832 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2834 "Could not get an ID for the clone of volume %u from the VLDB\n",
2839 /* Test to see if the clone volume exists by trying to create
2840 * a transaction on the clone volume. We've assumed the clone exists.
2842 /* XXX I wonder what happens if the clone has some other parent... */
2843 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2845 if (code != VNOVOL) {
2846 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2847 (unsigned long)acloneid);
2851 backexists = 0; /* backup volume does not exist */
2854 code = AFSVolEndTrans(aconn, btid, &rcode);
2856 if (code || rcode) {
2858 "Could not end transaction on the previous clone volume %lu\n",
2859 (unsigned long)acloneid);
2860 error = (code ? code : rcode);
2865 /* Now go ahead and try to clone the RW volume.
2866 * First start a transaction on the RW volume
2868 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2870 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2871 (unsigned long)avolid);
2876 /* Clone or reclone the volume, depending on whether the backup
2877 * volume exists or not
2880 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2882 code = AFSVolReClone(aconn, ttid, acloneid);
2884 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2885 (unsigned long)acloneid);
2890 VPRINT1("Creating a new clone %u ...", acloneid);
2892 code = AFSVolClone(aconn, ttid, 0,
2893 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2896 fprintf(STDERR, "Failed to clone the volume %lu\n",
2897 (unsigned long)avolid);
2903 /* End the transaction on the RW volume */
2904 code = AFSVolEndTrans(aconn, ttid, &rcode);
2906 if (code || rcode) {
2908 "Failed to end the transaction on the rw volume %lu\n",
2909 (unsigned long)avolid);
2910 error = (code ? code : rcode);
2914 /* Now go back to the backup volume and bring it on line */
2915 if (!(flags & RV_OFFLINE)) {
2916 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2919 "Failed to start a transaction on the clone volume %lu\n",
2920 (unsigned long)acloneid);
2925 code = AFSVolSetFlags(aconn, btid, 0);
2927 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2928 (unsigned long)acloneid);
2933 code = AFSVolEndTrans(aconn, btid, &rcode);
2935 if (code || rcode) {
2937 "Failed to end the transaction on the clone volume %lu\n",
2938 (unsigned long)acloneid);
2939 error = (code ? code : rcode);
2948 code = AFSVolEndTrans(aconn, ttid, &rcode);
2949 if (code || rcode) {
2950 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2951 (unsigned long)avolid);
2953 error = (code ? code : rcode);
2958 code = AFSVolEndTrans(aconn, btid, &rcode);
2959 if (code || rcode) {
2961 "Could not end transaction on the clone volume %lu\n",
2962 (unsigned long)acloneid);
2964 error = (code ? code : rcode);
2969 rx_DestroyConnection(aconn);
2971 PrintError("", error);
2976 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2979 afs_int32 acode, ccode, rcode, tid;
2980 ccode = rcode = tid = 0;
2982 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2983 if (!acode) { /* It really was there */
2984 acode = AFSVolDeleteVolume(conn, tid);
2986 fprintf(STDERR, "Failed to delete volume %lu.\n",
2987 (unsigned long)vid);
2988 PrintError("", acode);
2990 ccode = AFSVolEndTrans(conn, tid, &rcode);
2994 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
2995 (unsigned long)vid);
2996 PrintError("", ccode);
3003 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3004 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3006 /* Get a "transaction" on this replica. Create the volume
3007 * if necessary. Return the time from which a dump should
3008 * be made (0 if it's a new volume)
3011 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3012 struct rx_connection **connPtr, afs_int32 * transPtr,
3013 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3016 struct volser_status tstatus;
3017 int code, rcode, tcode;
3019 *connPtr = (struct rx_connection *)0;
3024 /* get connection to the replication site */
3025 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3027 goto fail; /* server is down */
3029 volid = vldbEntryPtr->volumeId[ROVOL];
3032 AFSVolTransCreate(*connPtr, volid,
3033 vldbEntryPtr->serverPartition[index], ITOffline,
3036 /* If the volume does not exist, create it */
3037 if (!volid || code) {
3040 if (volid && (code != VNOVOL)) {
3041 PrintError("Failed to start a transaction on the RO volume.\n",
3046 strcpy(volname, vldbEntryPtr->name);
3047 strcat(volname, ".readonly");
3051 "Creating new volume %lu on replication site %s: ",
3052 (unsigned long)volid,
3053 hostutil_GetNameByINet(vldbEntryPtr->
3054 serverNumber[index]));
3059 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3061 vldbEntryPtr->volumeId[RWVOL], &volid,
3064 PrintError("Failed to create the ro volume: ", code);
3067 vldbEntryPtr->volumeId[ROVOL] = volid;
3071 /* The following is a bit redundant, since create sets these flags by default */
3073 AFSVolSetFlags(*connPtr, *transPtr,
3074 VTDeleteOnSalvage | VTOutOfService);
3076 PrintError("Failed to set flags on the ro volume: ", code);
3081 /* Otherwise, the transaction did succeed, so get the creation date of the
3082 * latest RO volume on the replication site
3085 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3086 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3088 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3090 PrintError("Failed to get status of volume on destination: ",
3094 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3095 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3102 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3107 PrintError("Could not end transaction on a ro volume: ", tcode);
3114 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3115 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3116 void *cookie, manyResults * results)
3120 for (i = 0; i < tr->manyDests_len; i++) {
3121 results->manyResults_val[i] =
3122 AFSVolForward(fromconn, fromtid, fromdate,
3123 &(tr->manyDests_val[i].server),
3124 tr->manyDests_val[i].trans, cookie);
3130 /* UV_ReleaseVolume()
3131 * Release volume <afromvol> on <afromserver> <afrompart> to all
3132 * its RO sites (full release). Unless the previous release was
3133 * incomplete: in which case we bring the remaining incomplete
3134 * volumes up to date with the volumes that were released
3136 * forceflag: Performs a full release.
3138 * Will create a clone from the RW, then dump the clone out to
3139 * the remaining replicas. If there is more than 1 RO sites,
3140 * ensure that the VLDB says at least one RO is available all
3141 * the time: Influences when we write back the VLDB entry.
3145 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
3146 afs_int32 afrompart, int forceflag)
3149 afs_int32 code, vcode, rcode, tcode;
3150 afs_int32 cloneVolId, roVolId;
3151 struct replica *replicas = 0;
3152 struct nvldbentry entry, storeEntry;
3153 int i, volcount, m, fullrelease, vldbindex;
3155 struct restoreCookie cookie;
3156 struct rx_connection **toconns = 0;
3157 struct release *times = 0;
3159 struct rx_connection *fromconn = (struct rx_connection *)0;
3160 afs_int32 error = 0;
3162 afs_int32 clonetid = 0, onlinetid;
3163 afs_int32 fromtid = 0;
3164 afs_uint32 fromdate, thisdate;
3168 manyResults results;
3169 int rwindex, roindex, roclone, roexists;
3170 afs_int32 rwcrdate, rwupdate, clcrdate;
3174 } remembertime[NMAXNSERVERS];
3175 int releasecount = 0;
3176 struct volser_status volstatus;
3178 memset((char *)remembertime, 0, sizeof(remembertime));
3179 memset((char *)&results, 0, sizeof(results));
3181 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3182 if (vcode != VL_RERELEASE)
3183 ONERROR(vcode, afromvol,
3184 "Could not lock the VLDB entry for the volume %u.\n");
3187 /* Get the vldb entry in readable format */
3188 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3189 ONERROR(vcode, afromvol,
3190 "Could not fetch the entry for the volume %u from the VLDB.\n");
3191 MapHostToNetwork(&entry);
3194 EnumerateEntry(&entry);
3196 if (!ISNAMEVALID(entry.name))
3197 ONERROR(VOLSERBADOP, entry.name,
3198 "Volume name %s is too long, rename before releasing.\n");
3199 if (entry.volumeId[RWVOL] != afromvol)
3200 ONERROR(VOLSERBADOP, afromvol,
3201 "The volume %u being released is not a read-write volume.\n");
3202 if (entry.nServers <= 1)
3203 ONERROR(VOLSERBADOP, afromvol,
3204 "Volume %u has no replicas - release operation is meaningless!\n");
3205 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3206 ONERROR(VOLSERBADOP, entry.name,
3207 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3209 /* roclone is true if one of the RO volumes is on the same
3210 * partition as the RW volume. In this case, we make the RO volume
3211 * on the same partition a clone instead of a complete copy.
3214 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3215 roclone = ((roindex == -1) ? 0 : 1);
3216 rwindex = Lp_GetRwIndex(&entry);
3218 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3220 /* Make sure we have a RO volume id to work with */
3221 if (entry.volumeId[ROVOL] == INVALID_BID) {
3222 /* need to get a new RO volume id */
3223 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3224 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3226 entry.volumeId[ROVOL] = roVolId;
3227 MapNetworkToHost(&entry, &storeEntry);
3228 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3229 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3232 /* Will we be completing a previously unfinished release. -force overrides */
3233 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3234 if (entry.serverFlags[i] & ITSROVOL) {
3236 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3239 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3242 /* Determine which volume id to use and see if it exists */
3245 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3246 code = VolumeExists(afromserver, afrompart, cloneVolId);
3247 roexists = ((code == ENODEV) ? 0 : 1);
3249 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3251 ONERROR(-1, afromserver,
3252 "Cannot establish connection with server 0x%x\n");
3256 fullrelease = 1; /* Do a full release if RO clone does not exist */
3258 /* Begin transaction on RW and mark it busy while we query it */
3259 code = AFSVolTransCreate(
3260 fromconn, afromvol, afrompart, ITBusy, &fromtid
3262 ONERROR(code, afromvol,
3263 "Failed to start transaction on RW volume %u\n");
3265 /* Query the creation date for the RW */
3266 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3267 ONERROR(code, afromvol,
3268 "Failed to get the status of RW volume %u\n");
3269 rwcrdate = volstatus.creationDate;
3270 rwupdate = volstatus.updateDate;
3272 /* End transaction on RW */
3273 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3275 ONERROR((code ? code : rcode), afromvol,
3276 "Failed to end transaction on RW volume %u\n");
3278 /* Begin transaction on clone and mark it busy while we query it */
3279 code = AFSVolTransCreate(
3280 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3282 ONERROR(code, cloneVolId,
3283 "Failed to start transaction on RW clone %u\n");
3285 /* Query the creation date for the clone */
3286 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3287 ONERROR(code, cloneVolId,
3288 "Failed to get the status of RW clone %u\n");
3289 clcrdate = volstatus.creationDate;
3291 /* End transaction on clone */
3292 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3294 ONERROR((code ? code : rcode), cloneVolId,
3295 "Failed to end transaction on RW clone %u\n");
3297 if (rwcrdate > clcrdate)
3298 fullrelease = 2;/* Do a full release if RO clone older than RW */
3303 switch (fullrelease) {
3305 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3306 (unsigned long)afromvol);
3309 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3310 (unsigned long)afromvol);
3313 fprintf(STDOUT, "This is a completion of a previous release\n");
3319 /* If the RO clone exists, then if the clone is a temporary
3320 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3321 * (it was recently added), then also delete it. We do not
3322 * want to "reclone" a temporary RO clone.
3325 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3326 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3327 if (code && (code != VNOVOL))
3332 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3333 * write this entry out to the vlserver until after the first
3334 * RO volume is released (temp RO clones don't count).
3336 for (i = 0; i < entry.nServers; i++) {
3337 entry.serverFlags[i] &= ~NEW_REPSITE;
3338 entry.serverFlags[i] |= RO_DONTUSE;
3340 entry.serverFlags[rwindex] |= NEW_REPSITE;
3341 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3343 /* Begin transaction on RW and mark it busy while we clone it */
3345 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3347 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3349 /* Clone or reclone the volume */
3351 VPRINT1("Recloning RW volume %u...", cloneVolId);
3352 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3353 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3357 strcpy(vname, entry.name);
3358 strcat(vname, ".readonly");
3359 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3361 strcpy(vname, "readonly-clone-temp");
3362 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3365 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3367 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3371 /* Get the time the RW was created for future information */
3372 VPRINT1("Getting status of RW volume %u...", afromvol);
3373 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3374 ONERROR(code, afromvol,
3375 "Failed to get the status of the RW volume %u\n");
3377 rwcrdate = volstatus.creationDate;
3378 rwupdate = volstatus.updateDate;
3380 /* End the transaction on the RW volume */
3381 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3382 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3384 ONERROR((code ? code : rcode), afromvol,
3385 "Failed to end cloning transaction on RW %u\n");
3388 /* Remember clone volume ID in case we fail or are interrupted */
3389 entry.cloneId = cloneVolId;
3392 /* Bring the RO clone online - though not if it's a temporary clone */
3393 VPRINT1("Starting transaction on RO clone volume %u...",
3396 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3398 ONERROR(code, cloneVolId,
3399 "Failed to start transaction on volume %u\n");
3402 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3403 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3406 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3407 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3408 ONERROR((code ? code : rcode), cloneVolId,
3409 "Failed to end transaction on RO clone %u\n");
3412 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3414 /* Sleep so that a client searching for an online volume won't
3415 * find the clone offline and then the next RO offline while the
3416 * release brings the clone online and the next RO offline (race).
3417 * There is a fix in the 3.4 client that does not need this sleep
3418 * anymore, but we don't know what clients we have.
3420 if (entry.nServers > 2)
3423 /* Mark the RO clone in the VLDB as a good site (already released) */
3424 entry.serverFlags[roindex] |= NEW_REPSITE;
3425 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3426 entry.flags |= RO_EXISTS;
3430 /* Write out the VLDB entry only if the clone is not a temporary
3431 * clone. If we did this to a temporary clone then we would end
3432 * up marking all the ROs as "old release" making the ROs
3433 * temporarily unavailable.
3435 MapNetworkToHost(&entry, &storeEntry);
3436 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3437 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3438 ONERROR(vcode, entry.name,
3439 "Could not update vldb entry for %s.\n");
3444 /* Now we will release from the clone to the remaining RO replicas.
3445 * The first 2 ROs (counting the non-temporary RO clone) are released
3446 * individually: releasecount. This is to reduce the race condition
3447 * of clients trying to find an on-line RO volume. The remaining ROs
3448 * are released in parallel but no more than half the number of ROs
3449 * (rounded up) at a time: nservers.
3452 strcpy(vname, entry.name);
3453 strcat(vname, ".readonly");
3454 memset(&cookie, 0, sizeof(cookie));
3455 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3456 cookie.type = ROVOL;
3457 cookie.parent = entry.volumeId[RWVOL];
3460 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3462 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3463 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3465 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3467 results.manyResults_val =
3468 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3469 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3471 "Failed to create transaction on the release clone\n");
3473 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3474 memset(times, 0, (sizeof(struct release) * nservers + 1));
3475 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3476 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3478 /* Create a transaction on the cloned volume */
3479 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3481 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3482 if (!fullrelease && code)
3483 ONERROR(VOLSERNOVOL, afromvol,
3484 "Old clone is inaccessible. Try vos release -f %u.\n");
3485 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3488 /* For each index in the VLDB */
3489 for (vldbindex = 0; vldbindex < entry.nServers;) {
3491 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3493 ((volcount < nservers) && (vldbindex < entry.nServers));
3495 /* The first two RO volumes will be released individually.
3496 * The rest are then released in parallel. This is a hack
3497 * for clients not recognizing right away when a RO volume
3498 * comes back on-line.
3500 if ((volcount == 1) && (releasecount < 2))
3503 if (vldbindex == roindex)
3504 continue; /* the clone */
3505 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3506 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3508 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3509 continue; /* not a RO vol */
3512 /* Get a Transaction on this replica. Get a new connection if
3513 * necessary. Create the volume if necessary. Return the
3514 * time from which the dump should be made (0 if it's a new
3515 * volume). Each volume might have a different time.
3517 replicas[volcount].server.destHost =
3518 ntohl(entry.serverNumber[vldbindex]);
3519 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3520 replicas[volcount].server.destSSID = 1;
3521 times[volcount].vldbEntryIndex = vldbindex;
3524 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3525 &(replicas[volcount].trans),
3526 &(times[volcount].crtime),
3527 &(times[volcount].uptime));
3531 /* Thisdate is the date from which we want to pick up all changes */
3532 if (forceflag || !fullrelease
3533 || (rwcrdate > times[volcount].crtime)) {
3534 /* If the forceflag is set, then we want to do a full dump.
3535 * If it's not a full release, we can't be sure that the creation
3536 * date is good (so we also do a full dump).
3537 * If the RW volume was replaced (its creation date is newer than
3538 * the last release), then we can't be sure what has changed (so
3539 * we do a full dump).
3542 } else if (remembertime[vldbindex].validtime) {
3543 /* Trans was prev ended. Use the time from the prev trans
3544 * because, prev trans may have created the volume. In which
3545 * case time[volcount].time would be now instead of 0.
3548 (remembertime[vldbindex].uptime < times[volcount].uptime)
3549 ? remembertime[vldbindex].uptime
3550 : times[volcount].uptime;
3552 thisdate = times[volcount].uptime;
3554 remembertime[vldbindex].validtime = 1;
3555 remembertime[vldbindex].uptime = thisdate;
3557 if (volcount == 0) {
3558 fromdate = thisdate;
3560 /* Include this volume if it is within 15 minutes of the earliest */
3562 thisdate) ? (fromdate - thisdate) : (thisdate -
3564 AFSVolEndTrans(toconns[volcount],
3565 replicas[volcount].trans, &rcode);
3566 replicas[volcount].trans = 0;
3569 if (thisdate < fromdate)
3570 fromdate = thisdate;
3578 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3579 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3580 hostutil_GetNameByINet(entry.
3581 serverNumber[times[0].
3584 for (s = 1; s < volcount; s++) {
3585 fprintf(STDOUT, " and %s",
3586 hostutil_GetNameByINet(entry.
3587 serverNumber[times[s].
3592 fprintf(STDOUT, " (full release)");
3595 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3597 fprintf(STDOUT, ".\n");
3601 /* Release the ones we have collected */
3602 tr.manyDests_val = &(replicas[0]);
3603 tr.manyDests_len = results.manyResults_len = volcount;
3605 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3606 0 /*spare */ , &cookie, &results);
3607 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3609 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3610 0 /*spare */ , &cookie, &results);
3615 PrintError("Release failed: ", code);
3617 for (m = 0; m < volcount; m++) {
3618 if (results.manyResults_val[m]) {
3619 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3620 /* we retry timed out transaction. When it is
3621 * not the first volume and the transaction wasn't found
3622 * (assume it timed out and was garbage collected by volser).
3625 ("Failed to dump volume from clone to a ro site: ",
3626 results.manyResults_val[m]);
3632 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3633 ROVOL, entry.volumeId[RWVOL], 0, 0);
3635 if ((m == 0) || (code != ENOENT)) {
3636 PrintError("Failed to set correct names and ids: ",
3642 /* have to clear dest. flags to ensure new vol goes online:
3643 * because the restore (forwarded) operation copied
3644 * the V_inService(=0) flag over to the destination.
3646 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3648 if ((m == 0) || (code != ENOENT)) {
3649 PrintError("Failed to set flags on ro volume: ",
3655 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3656 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3657 entry.flags |= RO_EXISTS;
3662 /* End the transactions and destroy the connections */
3663 for (s = 0; s < volcount; s++) {
3664 if (replicas[s].trans)
3665 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3666 replicas[s].trans = 0;
3670 if ((s == 0) || (code != ENOENT)) {
3671 PrintError("Could not end transaction on a ro volume: ",
3675 ("Transaction timed out on a ro volume. Will retry.\n",
3677 if (times[s].vldbEntryIndex < vldbindex)
3678 vldbindex = times[s].vldbEntryIndex;
3683 rx_DestroyConnection(toconns[s]);
3687 MapNetworkToHost(&entry, &storeEntry);
3688 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3689 ONERROR(vcode, afromvol,
3690 " Could not update VLDB entry for volume %u\n");
3691 } /* for each index in the vldb */
3693 /* End the transaction on the cloned volume */
3694 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3699 PrintError("Failed to end transaction on rw volume: ", code);
3701 /* Figure out if any volume were not released and say so */
3702 for (failure = 0, i = 0; i < entry.nServers; i++) {
3703 if (!(entry.serverFlags[i] & NEW_REPSITE))
3709 "The volume %lu could not be released to the following %d sites:\n",
3710 (unsigned long)afromvol, failure);
3711 for (i = 0; i < entry.nServers; i++) {
3712 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3713 MapPartIdIntoName(entry.serverPartition[i], pname);
3714 fprintf(STDERR, "\t%35s %s\n",
3715 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3719 MapNetworkToHost(&entry, &storeEntry);
3721 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3723 ONERROR(vcode, afromvol,
3724 " Could not update VLDB entry for volume %u\n");
3726 ERROREXIT(VOLSERBADRELEASE);
3729 /* All the ROs were release successfully. Remove the temporary clone */
3732 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3733 (unsigned long)cloneVolId);
3736 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3737 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3742 for (i = 0; i < entry.nServers; i++)
3743 entry.serverFlags[i] &= ~NEW_REPSITE;
3745 /* Update the VLDB */
3746 VPRINT("updating VLDB ...");
3748 MapNetworkToHost(&entry, &storeEntry);
3750 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3751 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3752 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3757 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3761 "Failed to end cloning transaction on the RW volume %lu\n",
3762 (unsigned long)afromvol);
3768 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3772 "Failed to end transaction on the release clone %lu\n",
3773 (unsigned long)cloneVolId);
3778 for (i = 0; i < nservers; i++) {
3779 if (replicas && replicas[i].trans) {
3780 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3781 replicas[i].trans = 0;
3784 "Failed to end transaction on ro volume %u at server %s\n",
3785 entry.volumeId[ROVOL],
3786 hostutil_GetNameByINet(htonl
3787 (replicas[i].server.
3793 if (toconns && toconns[i]) {
3794 rx_DestroyConnection(toconns[i]);
3800 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3801 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3804 "Could not release lock on the VLDB entry for volume %lu\n",
3805 (unsigned long)afromvol);
3811 PrintError("", error);
3814 rx_DestroyConnection(fromconn);
3815 if (results.manyResults_val)
3816 free(results.manyResults_val);
3828 dump_sig_handler(int x)
3830 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3834 /* Dump the volume <afromvol> on <afromserver> and
3835 * <afrompart> to <afilename> starting from <fromdate>.
3836 * DumpFunction does the real work behind the scenes after
3837 * extracting parameters from the rock
3840 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3841 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock,
3844 struct rx_connection *fromconn = (struct rx_connection *)0;
3845 struct rx_call *fromcall = (struct rx_call *)0;
3846 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3847 afs_int32 code, error = 0, retry = 0;
3848 time_t tmv = fromdate;
3852 #ifndef AFS_NT40_ENV
3853 (void)signal(SIGPIPE, dump_sig_handler);
3855 (void)signal(SIGINT, dump_sig_handler);
3858 VEPRINT("Full Dump ...\n");
3860 VEPRINT1("Incremental Dump (as of %.24s)...\n",
3864 /* get connections to the servers */
3865 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3867 VEPRINT1("Starting transaction on volume %u...", afromvol);
3868 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3869 EGOTO1(error_exit, code,
3870 "Could not start transaction on the volume %u to be dumped\n",
3874 fromcall = rx_NewCall(fromconn);
3876 VEPRINT1("Starting volume dump on volume %u...", afromvol);
3877 if (flags & VOLDUMPV2_OMITDIRS)
3878 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
3881 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3882 EGOTO(error_exit, code, "Could not start the dump process \n");
3885 VEPRINT1("Dumping volume %u...", afromvol);
3886 code = DumpFunction(fromcall, rock);
3887 if (code == RXGEN_OPCODE)
3889 EGOTO(error_exit, code, "Error while dumping volume \n");
3894 code = rx_EndCall(fromcall, rxError);
3895 if (code && code != RXGEN_OPCODE)
3896 fprintf(STDERR, "Error in rx_EndCall\n");
3901 VEPRINT1("Ending transaction on volume %u...", afromvol);
3902 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3903 if (code || rcode) {
3904 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3905 (unsigned long)afromvol);
3907 error = (code ? code : rcode);
3912 rx_DestroyConnection(fromconn);
3916 if (error != RXGEN_OPCODE)
3917 PrintError("", error);
3921 /* Clone the volume <afromvol> on <afromserver> and
3922 * <afrompart>, and then dump the clone volume to
3923 * <afilename> starting from <fromdate>.
3924 * DumpFunction does the real work behind the scenes after
3925 * extracting parameters from the rock
3928 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3929 afs_int32 afrompart, afs_int32 fromdate,
3930 afs_int32(*DumpFunction) (), char *rock, afs_int32 flags)
3932 struct rx_connection *fromconn = (struct rx_connection *)0;
3933 struct rx_call *fromcall = (struct rx_call *)0;
3934 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3935 afs_int32 clonetid = 0;
3936 afs_int32 code = 0, vcode = 0, error = 0;
3937 afs_int32 clonevol = 0;
3939 time_t tmv = fromdate;
3943 #ifndef AFS_NT40_ENV
3944 (void)signal(SIGPIPE, dump_sig_handler);
3946 (void)signal(SIGINT, dump_sig_handler);
3949 VEPRINT("Full Dump ...\n");
3951 VEPRINT1("Incremental Dump (as of %.24s)...\n",
3955 /* get connections to the servers */
3956 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3958 VEPRINT1("Starting transaction on volume %u...", afromvol);
3959 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3960 EGOTO1(error_exit, code,
3961 "Could not start transaction on the volume %u to be dumped\n",
3965 /* Get a clone id */
3966 VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3967 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
3968 EGOTO1(error_exit, code,
3969 "Could not get an ID for the clone of volume %u from the VLDB\n",
3973 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3974 VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3976 strcpy(vname, "dump-clone-temp");
3978 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3979 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3983 VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
3985 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3989 EGOTO1(error_exit, code,
3990 "Failed to end the transaction on the volume %u\n", afromvol);
3994 VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
3996 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
3998 EGOTO1(error_exit, code,
3999 "Failed to start a transaction on the cloned volume%u\n",
4003 VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
4004 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4005 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4010 fromcall = rx_NewCall(fromconn);
4012 VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4013 if (flags & VOLDUMPV2_OMITDIRS)
4014 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4016 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4017 EGOTO(error_exit, code, "Could not start the dump process \n");
4020 VEPRINT1("Dumping volume %u...", afromvol);
4021 code = DumpFunction(fromcall, rock);
4022 EGOTO(error_exit, code, "Error while dumping volume \n");
4026 /* now delete the clone */
4027 VEPRINT1("Deleting the cloned volume %u ...", clonevol);
4028 code = AFSVolDeleteVolume(fromconn, clonetid);
4030 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4031 (unsigned long)clonevol);
4037 code = rx_EndCall(fromcall, rxError);
4039 fprintf(STDERR, "Error in rx_EndCall\n");
4045 VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
4046 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4047 if (code || rcode) {
4049 "Could not end transaction on the cloned volume %lu\n",
4050 (unsigned long)clonevol);
4052 error = (code ? code : rcode);
4057 rx_DestroyConnection(fromconn);
4059 PrintError("", error);
4066 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4067 * the dump file <afilename>. WriteData does all the real work
4068 * after extracting params from the rock
4071 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4072 afs_int32 toparentid, char tovolname[], int flags,
4073 afs_int32(*WriteData) (), char *rock)
4075 struct rx_connection *toconn, *tempconn;
4076 struct rx_call *tocall;
4077 afs_int32 totid, code, rcode, vcode, terror = 0;
4078 afs_int32 rxError = 0;
4079 struct volser_status tstatus;
4080 struct volintInfo vinfo;
4082 char tovolreal[VOLSER_OLDMAXVOLNAME];
4083 afs_int32 pvolid, pparentid;
4086 struct nvldbentry entry, storeEntry;
4089 struct restoreCookie cookie;
4091 afs_int32 volflag, voltype, volsertype;
4092 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4093 int index, same, errcode;
4097 memset(&cookie, 0, sizeof(cookie));
4102 tocall = (struct rx_call *)0;
4103 toconn = (struct rx_connection *)0;
4104 tempconn = (struct rx_connection *)0;
4108 if (flags & RV_RDONLY) {
4110 volsertype = volser_RO;
4113 volsertype = volser_RW;
4117 pparentid = toparentid;
4118 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4119 if (pvolid == 0) { /*alot a new id if needed */
4120 vcode = VLDB_GetEntryByName(tovolname, &entry);
4121 if (vcode == VL_NOENT) {
4122 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4124 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4130 } else if (flags & RV_RDONLY) {
4131 if (entry.flags & RW_EXISTS) {
4133 "Entry for ReadWrite volume %s already exists!\n",
4135 error = VOLSERBADOP;
4138 if (!entry.volumeId[ROVOL]) {
4140 "Existing entry for volume %s has no ReadOnly ID\n",
4142 error = VOLSERBADOP;
4145 pvolid = entry.volumeId[ROVOL];
4146 pparentid = entry.volumeId[RWVOL];
4148 pvolid = entry.volumeId[RWVOL];
4149 pparentid = entry.volumeId[RWVOL];
4152 if (!pparentid) pparentid = pvolid;
4153 /* at this point we have a volume id to use/reuse for the volume to be restored */
4154 strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
4156 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4157 EGOTO1(refail, VOLSERBADOP,
4158 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4161 if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
4162 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
4163 EGOTO1(refail, VOLSERBADOP,
4164 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
4166 snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
4169 MapPartIdIntoName(topart, partName);
4170 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4171 tovolreal, (unsigned long)pvolid,
4172 hostutil_GetNameByINet(toserver), partName);
4175 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
4178 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4179 VPRINT1("Deleting the previous volume %u ...", pvolid);
4182 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4183 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4186 code = AFSVolGetStatus(toconn, totid, &tstatus);
4187 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4190 oldCreateDate = tstatus.creationDate;
4191 oldUpdateDate = tstatus.updateDate;
4194 AFSVolSetFlags(toconn, totid,
4195 VTDeleteOnSalvage | VTOutOfService);
4196 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4199 code = AFSVolDeleteVolume(toconn, totid);
4200 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4202 code = AFSVolEndTrans(toconn, totid, &rcode);
4206 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4211 AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
4213 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4216 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4217 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4220 code = AFSVolGetStatus(toconn, totid, &tstatus);
4221 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4224 oldCreateDate = tstatus.creationDate;
4225 oldUpdateDate = tstatus.updateDate;
4232 cookie.parent = pparentid;
4233 cookie.type = voltype;
4235 strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
4237 tocall = rx_NewCall(toconn);
4238 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4240 fprintf(STDERR, "Volume restore Failed \n");
4244 code = WriteData(tocall, rock);
4246 fprintf(STDERR, "Could not transmit data\n");
4250 terror = rx_EndCall(tocall, rxError);
4251 tocall = (struct rx_call *)0;
4253 fprintf(STDERR, "rx_EndCall Failed \n");
4257 code = AFSVolGetStatus(toconn, totid, &tstatus);
4260 "Could not get status information about the volume %lu\n",
4261 (unsigned long)pvolid);
4265 code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
4267 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4268 (unsigned long)pvolid);
4273 if (flags & RV_CRDUMP)
4274 newCreateDate = tstatus.creationDate;
4275 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4276 newCreateDate = oldCreateDate;
4278 newCreateDate = time(0);
4279 if (flags & RV_LUDUMP)
4280 newUpdateDate = tstatus.updateDate;
4281 else if (flags & RV_LUKEEP)
4282 newUpdateDate = oldUpdateDate;
4284 newUpdateDate = time(0);
4285 code = AFSVolSetDate(toconn,totid, newCreateDate);
4287 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4292 init_volintInfo(&vinfo);
4293 vinfo.creationDate = newCreateDate;
4294 vinfo.updateDate = newUpdateDate;
4295 code = AFSVolSetInfo(toconn, totid, &vinfo);
4297 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4303 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4304 code = AFSVolSetFlags(toconn, totid, volflag);
4306 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4311 /* It isn't handled right in refail */
4312 code = AFSVolEndTrans(toconn, totid, &rcode);
4317 fprintf(STDERR, "Could not end transaction on %lu\n",
4318 (unsigned long)pvolid);
4324 fprintf(STDOUT, " done\n");
4326 if (success && (!reuseID || (flags & RV_FULLRST))) {
4327 /* Volume was restored on the file server, update the
4328 * VLDB to reflect the change.
4330 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4331 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4333 "Could not fetch the entry for volume number %lu from VLDB \n",
4334 (unsigned long)pvolid);
4339 MapHostToNetwork(&entry);
4340 if (vcode == VL_NOENT) { /* it doesnot exist already */
4341 /*make the vldb return this indication specifically */
4342 VPRINT("------- Creating a new VLDB entry ------- \n");
4343 strcpy(entry.name, tovolname);
4345 entry.serverNumber[0] = toserver; /*should be indirect */
4346 entry.serverPartition[0] = topart;
4347 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4348 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4349 if (flags & RV_RDONLY)
4350 entry.volumeId[ROVOL] = pvolid;
4351 else if (tstatus.cloneID != 0) {
4352 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4354 entry.volumeId[ROVOL] = INVALID_BID;
4355 entry.volumeId[RWVOL] = pparentid;
4357 if (tstatus.backupID != 0) {
4358 entry.volumeId[BACKVOL] = tstatus.backupID;
4359 /*this should come from status info on the volume if non zero */
4361 entry.volumeId[BACKVOL] = INVALID_BID;
4362 MapNetworkToHost(&entry, &storeEntry);
4363 vcode = VLDB_CreateEntry(&storeEntry);
4366 "Could not create the VLDB entry for volume number %lu \n",
4367 (unsigned long)pvolid);
4373 EnumerateEntry(&entry);
4374 } else { /*update the existing entry */
4376 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4377 fprintf(STDOUT, "------- Old entry -------\n");
4378 EnumerateEntry(&entry);
4379 fprintf(STDOUT, "------- New entry -------\n");
4382 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4386 "Could not lock the entry for volume number %lu \n",
4387 (unsigned long)pvolid);
4392 strcpy(entry.name, tovolname);
4394 /* Update the vlentry with the new information */
4395 if (flags & RV_RDONLY)
4396 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4398 index = Lp_GetRwIndex(&entry);
4400 /* Add the new site for the volume being restored */
4401 entry.serverNumber[entry.nServers] = toserver;
4402 entry.serverPartition[entry.nServers] = topart;
4403 entry.serverFlags[entry.nServers] =
4404 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4407 /* This volume should be deleted on the old site
4408 * if its different from new site.
4411 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4415 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4417 if ((!errcode && !same)
4418 || (entry.serverPartition[index] != topart)) {
4419 if (flags & RV_NODEL) {
4421 ("Not deleting the previous volume %u on server %s, ...",
4423 hostutil_GetNameByINet(entry.serverNumber[index]));
4426 UV_Bind(entry.serverNumber[index],
4427 AFSCONF_VOLUMEPORT);
4429 MapPartIdIntoName(entry.serverPartition[index],
4432 ("Deleting the previous volume %u on server %s, partition %s ...",
4434 hostutil_GetNameByINet(entry.serverNumber[index]),
4437 AFSVolTransCreate(tempconn, pvolid,
4438 entry.serverPartition[index],
4439 ITOffline, &temptid);
4442 AFSVolSetFlags(tempconn, temptid,
4447 "Could not set flags on volume %lu on the older site\n",
4448 (unsigned long)pvolid);
4452 code = AFSVolDeleteVolume(tempconn, temptid);
4455 "Could not delete volume %lu on the older site\n",
4456 (unsigned long)pvolid);
4460 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4466 "Could not end transaction on volume %lu on the older site\n",
4467 (unsigned long)pvolid);
4472 MapPartIdIntoName(entry.serverPartition[index],
4477 entry.serverNumber[index] = toserver;
4478 entry.serverPartition[index] = topart;
4481 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4482 MapNetworkToHost(&entry, &storeEntry);
4484 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4485 LOCKREL_OPCODE | LOCKREL_AFSID |
4489 "Could not update the entry for volume number %lu \n",
4490 (unsigned long)pvolid);
4496 EnumerateEntry(&entry);
4503 code = rx_EndCall(tocall, rxError);
4509 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4510 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4513 "Could not release lock on the VLDB entry for the volume %lu\n",
4514 (unsigned long)pvolid);
4520 code = AFSVolEndTrans(toconn, totid, &rcode);
4524 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4525 (unsigned long)pvolid);
4531 code = AFSVolEndTrans(toconn, temptid, &rcode);
4535 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4536 (unsigned long)pvolid);
4542 rx_DestroyConnection(tempconn);
4544 rx_DestroyConnection(toconn);
4545 PrintError("", error);
4550 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4551 char tovolname[], int flags, afs_int32(*WriteData) (),
4554 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4559 /*unlocks the vldb entry associated with <volid> */
4561 UV_LockRelease(afs_int32 volid)
4567 VPRINT("Binding to the VLDB server\n");
4569 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4570 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4573 "Could not unlock the entry for volume number %lu in VLDB \n",
4574 (unsigned long)volid);
4575 PrintError("", vcode);
4578 VPRINT("VLDB updated\n");
4583 /*adds <server> and <part> as a readonly replication site for <volid>
4586 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid, afs_int32 valid)
4588 int j, nro = 0, islocked = 0;
4589 struct nvldbentry entry, storeEntry;
4590 afs_int32 vcode, error = 0;
4593 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4596 " Could not lock the VLDB entry for the volume %lu \n",
4597 (unsigned long)volid);
4602 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4605 "Could not fetch the VLDB entry for volume number %lu \n",
4606 (unsigned long)volid);
4610 if (!ISNAMEVALID(entry.name)) {
4612 "Volume name %s is too long, rename before adding site\n",
4614 error = VOLSERBADOP;
4617 MapHostToNetwork(&entry);
4619 /* See if it's too many entries */
4620 if (entry.nServers >= NMAXNSERVERS) {
4621 fprintf(STDERR, "Total number of entries will exceed %u\n",
4623 error = VOLSERBADOP;
4627 /* See if it's on the same server */
4628 for (j = 0; j < entry.nServers; j++) {
4629 if (entry.serverFlags[j] & ITSROVOL) {
4631 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4634 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4637 MapPartIdIntoName(entry.serverPartition[j], apartName);
4639 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4641 error = VOLSERBADOP;
4648 /* See if it's too many RO sites - leave one for the RW */
4649 if (nro >= NMAXNSERVERS - 1) {
4650 fprintf(STDERR, "Total number of sites will exceed %u\n",
4652 error = VOLSERBADOP;
4656 VPRINT("Adding a new site ...");
4657 entry.serverNumber[entry.nServers] = server;
4658 entry.serverPartition[entry.nServers] = part;
4660 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4662 entry.serverFlags[entry.nServers] = (ITSROVOL);
4666 MapNetworkToHost(&entry, &storeEntry);
4668 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4669 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4671 fprintf(STDERR, "Could not update entry for volume %lu \n",
4672 (unsigned long)volid);
4681 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4682 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4685 "Could not release lock on volume entry for %lu \n",
4686 (unsigned long)volid);
4687 PrintError("", vcode);
4691 PrintError("", error);
4695 /*removes <server> <part> as read only site for <volid> from the vldb */
4697 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4700 struct nvldbentry entry, storeEntry;
4703 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4705 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4706 (unsigned long)volid);
4707 PrintError("", vcode);
4711 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4714 "Could not fetch the entry for volume number %lu from VLDB \n",
4715 (unsigned long)volid);
4716 PrintError("", vcode);
4719 MapHostToNetwork(&entry);
4720 if (!Lp_ROMatch(server, part, &entry)) {
4721 /*this site doesnot exist */
4722 fprintf(STDERR, "This site is not a replication site \n");
4724 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4725 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4727 fprintf(STDERR, "Could not update entry for volume %lu \n",
4728 (unsigned long)volid);
4729 PrintError("", vcode);
4730 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4731 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4735 } else { /*remove the rep site */
4736 Lp_SetROValue(&entry, server, part, 0, 0);
4738 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4739 entry.flags &= ~RO_EXISTS;
4740 if (entry.nServers < 1) { /*this is the last ref */
4741 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4743 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4746 "Could not delete VLDB entry for volume %lu \n",
4747 (unsigned long)volid);
4748 PrintError("", vcode);
4753 MapNetworkToHost(&entry, &storeEntry);
4754 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4755 (unsigned long)volid);
4758 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4759 LOCKREL_OPCODE | LOCKREL_AFSID |
4763 "Could not release lock on volume entry for %lu \n",
4764 (unsigned long)volid);
4765 PrintError("", vcode);
4766 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4767 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4775 /*sets <server> <part> as read/write site for <volid> in the vldb */
4777 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4780 struct nvldbentry entry, storeEntry;
4783 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4785 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4786 (unsigned long)volid);
4787 PrintError("", vcode);
4790 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4793 "Could not fetch the entry for volume number %lu from VLDB \n",
4794 (unsigned long)volid);
4795 PrintError("", vcode);
4798 MapHostToNetwork(&entry);
4799 index = Lp_GetRwIndex(&entry);
4801 /* no RW site exists */
4802 fprintf(STDERR, "No existing RW site for volume %lu",
4803 (unsigned long)volid);
4805 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4806 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4809 "Could not release lock on entry for volume %lu \n",
4810 (unsigned long)volid);
4811 PrintError("", vcode);
4815 } else { /* change the RW site */
4816 entry.serverNumber[index] = server;
4817 entry.serverPartition[index] = part;
4818 MapNetworkToHost(&entry, &storeEntry);
4820 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4821 LOCKREL_OPCODE | LOCKREL_AFSID |
4824 fprintf(STDERR, "Could not update entry for volume %lu \n",
4825 (unsigned long)volid);
4826 PrintError("", vcode);
4827 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4828 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4836 /*list all the partitions on <aserver> */
4838 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4841 struct rx_connection *aconn;
4842 struct pIDs partIds;
4843 struct partEntries partEnts;
4844 register int i, j = 0, code;
4847 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4849 partEnts.partEntries_len = 0;
4850 partEnts.partEntries_val = NULL;
4851 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4852 if (code == RXGEN_OPCODE) {
4853 for (i = 0; i < 26; i++) /* try old interface */
4854 partIds.partIds[i] = -1;
4855 code = AFSVolListPartitions(aconn, &partIds);
4857 for (i = 0; i < 26; i++) {
4858 if ((partIds.partIds[i]) != -1) {
4859 ptrPartList->partId[j] = partIds.partIds[i];
4860 ptrPartList->partFlags[j] = PARTVALID;
4863 ptrPartList->partFlags[i] = 0;
4868 *cntp = partEnts.partEntries_len;
4869 if (*cntp > VOLMAXPARTS) {
4871 "Warning: number of partitions on the server too high %d (process only %d)\n",
4872 *cntp, VOLMAXPARTS);
4873 *cntp = VOLMAXPARTS;
4875 for (i = 0; i < *cntp; i++) {
4876 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4877 ptrPartList->partFlags[i] = PARTVALID;
4879 free(partEnts.partEntries_val);
4885 "Could not fetch the list of partitions from the server\n");
4886 PrintError("", code);
4888 rx_DestroyConnection(aconn);
4893 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4894 This is used by the backup system */
4896 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4897 struct volDescription *volPtr, afs_int32 arraySize)
4899 struct rx_connection *aconn;
4900 struct volDescription *curPtr;
4903 afs_int32 rcode = 0;
4904 afs_int32 success = 1;
4907 aconn = (struct rx_connection *)0;
4908 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4910 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4911 if (curPtr->volFlags & CLONEVALID) {
4912 curPtr->volFlags &= ~CLONEZAPPED;
4915 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4920 code = AFSVolDeleteVolume(aconn, tid);
4923 code = AFSVolEndTrans(aconn, tid, &rcode);
4928 curPtr->volFlags |= CLONEZAPPED;
4930 fprintf(STDERR, "Could not zap volume %lu\n",
4931 (unsigned long)curPtr->volCloneId);
4933 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4934 curPtr->volCloneId);
4940 rx_DestroyConnection(aconn);
4944 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4947 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4948 struct volDescription *volPtr, afs_int32 arraySize)
4950 struct rx_connection *aconn;
4951 struct volDescription *curPtr;
4954 afs_int32 rcode = 0;
4956 int reuseCloneId = 0;
4957 afs_int32 curCloneId = 0;
4958 char cloneName[256]; /*max vol name */
4960 aconn = (struct rx_connection *)0;
4961 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4963 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4965 else { /*get a bunch of id's from vldb */
4967 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
4969 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4970 PrintError("", code);
4975 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4976 if (curPtr->volFlags & ENTRYVALID) {
4978 curPtr->volFlags |= CLONEVALID;
4979 /*make a clone of curParentId and record as curPtr->volCloneId */
4981 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4984 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4987 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
4991 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
4992 strcpy(cloneName, curPtr->volName);
4993 strcat(cloneName, "-tmpClone-");
4995 strcpy(cloneName, "-tmpClone");
4997 curPtr->volCloneId = curCloneId;
5002 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
5003 &(curPtr->volCloneId));
5005 curPtr->volFlags &= ~CLONEVALID;
5007 fprintf(STDERR, "Could not clone %s due to error %lu\n",
5008 curPtr->volName, (unsigned long)code);
5009 code = AFSVolEndTrans(aconn, tid, &rcode);
5011 fprintf(STDERR, "WARNING: could not end transaction\n");
5014 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
5015 curPtr->volCloneId);
5016 code = AFSVolEndTrans(aconn, tid, &rcode);
5017 if (code || rcode) {
5018 curPtr->volFlags &= ~CLONEVALID;
5027 rx_DestroyConnection(aconn);
5032 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5033 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5035 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5036 struct volintInfo **resultPtr, afs_int32 * size)
5038 struct rx_connection *aconn;
5040 volEntries volumeInfo;
5044 *resultPtr = (volintInfo *) 0;
5045 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5046 volumeInfo.volEntries_len = 0;
5048 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5049 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5052 "Could not fetch the list of volumes from the server\n");
5054 *resultPtr = volumeInfo.volEntries_val;
5055 *size = volumeInfo.volEntries_len;
5059 rx_DestroyConnection(aconn);
5060 PrintError("", code);
5064 /*------------------------------------------------------------------------
5065 * EXPORTED UV_XListVolumes
5068 * List the extended information for all the volumes on a particular
5069 * File Server and partition. We may either return the volume's ID
5070 * or all of its extended information.
5073 * a_serverID : Address of the File Server for which we want
5074 * extended volume info.
5075 * a_partID : Partition for which we want the extended
5077 * a_all : If non-zero, fetch ALL the volume info,
5078 * otherwise just the volume ID.
5079 * a_resultPP : Ptr to the address of the area containing
5080 * the returned volume info.
5081 * a_numEntsInResultP : Ptr for the value we set for the number of
5086 * Otherise, the return value of AFSVolXListVolumes.
5089 * This routine is closely related to UV_ListVolumes, which returns
5090 * only the standard level of detail on AFS volumes. It is a
5091 * heavyweight operation, zipping through all the volume entries for
5092 * a given server/partition.
5096 *------------------------------------------------------------------------*/
5099 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5100 struct volintXInfo **a_resultPP,
5101 afs_int32 * a_numEntsInResultP)
5103 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5104 afs_int32 code; /*Error code to return */
5105 volXEntries volumeXInfo; /*Area for returned extended vol info */
5108 * Set up our error code and the area for returned extended volume info.
5109 * We set the val field to a null pointer as a hint for the stub to
5113 *a_numEntsInResultP = 0;
5114 *a_resultPP = (volintXInfo *) 0;
5115 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5116 volumeXInfo.volXEntries_len = 0;
5119 * Bind to the Volume Server port on the File Server machine in question,
5122 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5123 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5125 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5128 * We got the info; pull out the pointer to where the results lie
5129 * and how many entries are there.
5131 *a_resultPP = volumeXInfo.volXEntries_val;
5132 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5136 * If we got an Rx connection, throw it away.
5139 rx_DestroyConnection(rxConnP);
5141 PrintError("", code);
5143 } /*UV_XListVolumes */
5145 /* get all the information about volume <volid> on <aserver> and <apart> */
5147 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
5148 struct volintInfo **resultPtr)
5150 struct rx_connection *aconn;
5152 volEntries volumeInfo;
5156 *resultPtr = (volintInfo *) 0;
5157 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5158 volumeInfo.volEntries_len = 0;
5160 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5161 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5164 "Could not fetch the information about volume %lu from the server\n",
5165 (unsigned long)volid);
5167 *resultPtr = volumeInfo.volEntries_val;
5172 rx_DestroyConnection(aconn);
5173 PrintError("", code);
5177 /*------------------------------------------------------------------------
5178 * EXPORTED UV_XListOneVolume
5181 * List the extended information for a volume on a particular File
5182 * Server and partition.
5185 * a_serverID : Address of the File Server for which we want
5186 * extended volume info.
5187 * a_partID : Partition for which we want the extended
5189 * a_volID : Volume ID for which we want the info.
5190 * a_resultPP : Ptr to the address of the area containing
5191 * the returned volume info.
5195 * Otherise, the return value of AFSVolXListOneVolume.
5198 * This routine is closely related to UV_ListOneVolume, which returns
5199 * only the standard level of detail on the chosen AFS volume.
5203 *------------------------------------------------------------------------*/
5206 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
5207 struct volintXInfo **a_resultPP)
5209 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5210 afs_int32 code; /*Error code */
5211 volXEntries volumeXInfo; /*Area for returned info */
5214 * Set up our error code, and the area we're in which we are returning
5215 * the info. Setting the val field to a null pointer tells the stub
5216 * to allocate space for us.
5219 *a_resultPP = (volintXInfo *) 0;
5220 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5221 volumeXInfo.volXEntries_len = 0;
5224 * Bind to the Volume Server port on the File Server machine in question,
5227 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5228 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5231 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5234 * We got the info; pull out the pointer to where the results lie.
5236 *a_resultPP = volumeXInfo.volXEntries_val;
5239 * If we got an Rx connection, throw it away.
5242 rx_DestroyConnection(rxConnP);
5244 PrintError("", code);
5249 * Given a volume we read from a partition, check if it is
5250 * represented in the VLDB correctly.
5252 * The VLDB is looked up by the RW volume id (not its name).
5253 * The RW contains the true name of the volume (BK and RO set
5254 * the name in the VLDB only on creation of the VLDB entry).
5255 * We want rules strict enough that when we check all volumes
5256 * on one partition, it does not need to be done again. IE:
5257 * two volumes on different partitions won't constantly
5258 * change a VLDB entry away from what the other set.
5259 * For RW and BK volumes, we will always check the VLDB to see
5260 * if the two exist on the server/partition. May seem redundant,
5261 * but this is an easy check of the VLDB. IE: if the VLDB entry
5262 * says the BK exists but no BK volume is there, we will detect
5263 * this when we check the RW volume.
5264 * VLDB entries are locked only when a change needs to be done.
5265 * Output changed to look a lot like the "vos syncserv" otuput.
5268 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5269 afs_int32 * modentry, afs_uint32 * maxvolid)
5272 afs_int32 code, error = 0;
5273 struct nvldbentry entry, storeEntry;
5275 int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
5284 ((volumeinfo->type ==
5285 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5288 /* Check to see if the VLDB is ok without locking it (pass 1).
5289 * If it will change, then lock the VLDB entry, read it again,
5290 * then make the changes to it (pass 2).
5293 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5295 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5296 (unsigned long)rwvolid);
5302 createentry = 0; /* Do we need to create a VLDB entry */
5303 addvolume = 0; /* Add this volume to the VLDB entry */
5304 modified = 0; /* The VLDB entry was modified */
5306 /* Read the entry from VLDB by its RW volume id */
5307 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5309 if (code != VL_NOENT) {
5311 "Could not retreive the VLDB entry for volume %lu \n",
5312 (unsigned long)rwvolid);
5316 memset(&entry, 0, sizeof(entry));
5317 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5321 MapHostToNetwork(&entry);
5324 if (verbose && (pass == 1)) {
5325 fprintf(STDOUT, "_______________________________\n");
5326 fprintf(STDOUT, "\n-- status before -- \n");
5328 fprintf(STDOUT, "\n**does not exist**\n");
5330 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5331 || (entry.flags & BACK_EXISTS))
5332 EnumerateEntry(&entry);
5334 fprintf(STDOUT, "\n");
5337 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5343 /* Check existence of RW and BK volumes */
5344 code = CheckVldbRWBK(&entry, &mod);
5350 idx = Lp_GetRwIndex(&entry);
5351 if (idx == -1) { /* RW index not found in the VLDB entry */
5352 idx = entry.nServers; /* put it into next index */
5355 } else { /* RW index found in the VLDB entry. */
5356 /* Verify if this volume's location matches where the VLDB says it is */
5357 if (!Lp_Match(aserver, apart, &entry)) {
5358 if (entry.flags & RW_EXISTS) {
5359 /* The RW volume exists elsewhere - report this one a duplicate */
5361 MapPartIdIntoName(apart, pname);
5363 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5364 (unsigned long)rwvolid,
5365 hostutil_GetNameByINet(aserver), pname);
5366 MapPartIdIntoName(entry.serverPartition[idx],
5369 " VLDB reports RW volume %lu exists on %s %s\n",
5370 (unsigned long)rwvolid,
5371 hostutil_GetNameByINet(entry.
5376 /* The RW volume does not exist - have VLDB point to this one */
5379 /* Check for orphaned BK volume on old partition */
5380 if (entry.flags & BACK_EXISTS) {
5382 MapPartIdIntoName(entry.serverPartition[idx],
5385 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5386 entry.volumeId[BACKVOL],
5387 hostutil_GetNameByINet(entry.
5390 MapPartIdIntoName(apart, pname);
5392 " VLDB reports its RW volume %lu exists on %s %s\n",
5393 (unsigned long)rwvolid,
5394 hostutil_GetNameByINet(aserver),
5400 /* Volume location matches the VLDB location */
5401 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5402 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5405 (entry.name, volumeinfo->name,
5406 VOLSER_OLDMAXVOLNAME) != 0)) {
5414 entry.flags |= RW_EXISTS;
5415 entry.volumeId[RWVOL] = rwvolid;
5416 if (!entry.volumeId[BACKVOL])
5417 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5418 if (!entry.volumeId[ROVOL])
5419 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5421 entry.serverFlags[idx] = ITSRWVOL;
5422 entry.serverNumber[idx] = aserver;
5423 entry.serverPartition[idx] = apart;
5424 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5428 /* One last check - to update BK if need to */
5429 code = CheckVldbRWBK(&entry, &mod);
5437 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5443 /* Check existence of RW and BK volumes */
5444 code = CheckVldbRWBK(&entry, &mod);
5450 idx = Lp_GetRwIndex(&entry);
5451 if (idx == -1) { /* RW index not found in the VLDB entry */
5452 idx = entry.nServers; /* Put it into next index */
5455 } else { /* RW index found in the VLDB entry */
5456 /* Verify if this volume's location matches where the VLDB says it is */
5457 if (!Lp_Match(aserver, apart, &entry)) {
5458 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5460 MapPartIdIntoName(apart, pname);
5462 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5463 (unsigned long)volumeinfo->volid,
5464 hostutil_GetNameByINet(aserver), pname);
5465 MapPartIdIntoName(entry.serverPartition[idx], pname);
5467 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5468 (unsigned long)rwvolid,
5469 hostutil_GetNameByINet(entry.
5474 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5475 if (!(entry.flags & BACK_EXISTS)) {
5477 } else if (volumeinfo->volid >
5478 entry.volumeId[BACKVOL]) {
5482 MapPartIdIntoName(entry.serverPartition[idx],
5485 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5486 entry.volumeId[BACKVOL],
5487 hostutil_GetNameByINet(aserver),
5490 " VLDB reports its BK volume ID is %lu\n",
5491 (unsigned long)volumeinfo->volid);
5495 MapPartIdIntoName(entry.serverPartition[idx],
5498 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5499 (unsigned long)volumeinfo->volid,
5500 hostutil_GetNameByINet(aserver),
5503 " VLDB reports its BK volume ID is %u\n",
5504 entry.volumeId[BACKVOL]);
5507 } else if (!entry.volumeId[BACKVOL]) {
5514 entry.flags |= BACK_EXISTS;
5515 entry.volumeId[RWVOL] = rwvolid;
5516 entry.volumeId[BACKVOL] = volumeinfo->volid;
5518 entry.serverNumber[idx] = aserver;
5519 entry.serverPartition[idx] = apart;
5520 entry.serverFlags[idx] = ITSRWVOL;
5526 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5527 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5528 /* This is a quick check to see if the RO entry exists in the
5529 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5530 * RO volume listed in the VLDB exists).
5532 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5534 idx = entry.nServers;
5538 if (!(entry.flags & RO_EXISTS)) {
5543 /* Before we correct the VLDB entry, make sure all the
5544 * ROs listed in the VLDB exist.
5546 code = CheckVldbRO(&entry, &mod);
5552 if (!(entry.flags & RO_EXISTS)) {
5553 /* No RO exists in the VLDB entry - add this one */
5554 idx = entry.nServers;
5557 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5558 /* The volume headers's RO ID does not match that in the VLDB entry,
5559 * and the vol hdr's ID is greater (implies more recent). So delete
5560 * all the RO volumes listed in VLDB entry and add this volume.
5562 for (j = 0; j < entry.nServers; j++) {
5563 if (entry.serverFlags[j] & ITSROVOL) {
5564 /* Verify this volume exists and print message we are orphaning it */
5566 MapPartIdIntoName(apart, pname);
5568 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5569 entry.volumeId[ROVOL],
5570 hostutil_GetNameByINet(entry.
5574 " VLDB reports its RO volume ID is %lu\n",
5575 (unsigned long)volumeinfo->volid);
5578 Lp_SetRWValue(&entry, entry.serverNumber[idx],
5579 entry.serverPartition[idx], 0L, 0L);
5586 idx = entry.nServers;
5589 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5590 /* The volume headers's RO ID does not match that in the VLDB entry,
5591 * and the vol hdr's ID is lower (implies its older). So orphan it.
5594 MapPartIdIntoName(apart, pname);
5596 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5597 (unsigned long)volumeinfo->volid,
5598 hostutil_GetNameByINet(aserver), pname);
5600 " VLDB reports its RO volume ID is %u\n",
5601 entry.volumeId[ROVOL]);
5604 /* The RO volume ID in the volume header match that in the VLDB entry,
5605 * and there exist RO volumes in the VLDB entry. See if any of them
5606 * are this one. If not, then we add it.
5608 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5610 idx = entry.nServers;
5618 entry.flags |= RO_EXISTS;
5619 entry.volumeId[RWVOL] = rwvolid;
5620 entry.volumeId[ROVOL] = volumeinfo->volid;
5622 entry.serverNumber[idx] = aserver;
5623 entry.serverPartition[idx] = apart;
5624 entry.serverFlags[idx] = ITSROVOL;
5630 /* Remember largest volume id */
5631 if (entry.volumeId[ROVOL] > *maxvolid)
5632 *maxvolid = entry.volumeId[ROVOL];
5633 if (entry.volumeId[BACKVOL] > *maxvolid)
5634 *maxvolid = entry.volumeId[BACKVOL];
5635 if (entry.volumeId[RWVOL] > *maxvolid)
5636 *maxvolid = entry.volumeId[RWVOL];
5638 if (modified && doit) {
5639 MapNetworkToHost(&entry, &storeEntry);
5642 code = VLDB_CreateEntry(&storeEntry);
5645 "Could not create a VLDB entry for the volume %lu\n",
5646 (unsigned long)rwvolid);
5653 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5654 LOCKREL_OPCODE | LOCKREL_AFSID |
5657 fprintf(STDERR, "Could not update entry for %lu\n",
5658 (unsigned long)rwvolid);
5663 *modentry = modified;
5664 } else if (pass == 2) {
5666 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5667 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5669 PrintError("Could not unlock VLDB entry ", code);
5673 if (verbose && doit) {
5674 fprintf(STDOUT, "-- status after --\n");
5676 EnumerateEntry(&entry);
5678 fprintf(STDOUT, "\n**no change**\n");
5682 VPRINT("\n_______________________________\n");
5687 sortVolumes(const void *a, const void *b)
5689 volintInfo *v1 = (volintInfo *) a;
5690 volintInfo *v2 = (volintInfo *) b;
5691 afs_int32 rwvolid1, rwvolid2;
5693 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5694 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5696 if (rwvolid1 > rwvolid2)
5697 return -1; /* lower RW id goes first */
5698 if (rwvolid1 < rwvolid2)
5701 if (v1->type == RWVOL)
5702 return -1; /* RW vols go first */
5703 if (v2->type == RWVOL)
5706 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5707 return -1; /* BK vols next */
5708 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5711 if (v1->volid < v2->volid)
5712 return 1; /* larger volids first */
5713 if (v1->volid > v2->volid)
5719 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5720 * Synchronize an individual volume against a sever and partition.
5721 * Checks the VLDB entry (similar to syncserv) as well as checks
5722 * if the volume exists on specified servers (similar to syncvldb).
5725 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5727 struct rx_connection *aconn = 0;
5728 afs_int32 j, k, code, vcode, error = 0;
5729 afs_int32 tverbose, mod, modified = 0;
5730 struct nvldbentry vldbentry;
5731 afs_int32 volumeid = 0;
5732 volEntries volumeInfo;
5733 struct partList PartList;
5735 afs_int32 maxvolid = 0;
5737 volumeInfo.volEntries_val = (volintInfo *) 0;
5738 volumeInfo.volEntries_len = 0;
5740 if (!aserver && (flags & 1)) {
5741 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5745 /* Turn verbose logging off and do our own verbose logging */
5751 /* Read the VLDB entry */
5752 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5753 if (vcode && (vcode != VL_NOENT)) {
5754 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5757 } else if (!vcode) {
5758 MapHostToNetwork(&vldbentry);
5762 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5763 fprintf(STDOUT, "_______________________________\n");
5764 fprintf(STDOUT, "\n-- status before -- \n");
5766 fprintf(STDOUT, "\n**does not exist**\n");
5768 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5769 || (vldbentry.flags & BACK_EXISTS))
5770 EnumerateEntry(&vldbentry);
5772 fprintf(STDOUT, "\n");
5775 /* Verify that all of the VLDB entries exist on the repective servers
5776 * and partitions (this does not require that avolname be a volume ID).
5777 * Equivalent to a syncserv.
5780 /* Tell CheckVldb not to update if appropriate */
5785 code = CheckVldb(&vldbentry, &mod);
5787 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5795 /* If aserver is given, we will search for the desired volume on it */
5797 /* Generate array of partitions on the server that we will check */
5799 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5802 "Could not fetch the list of partitions from the server\n");
5806 PartList.partId[0] = apart;
5810 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5812 /* If a volume ID were given, search for it on each partition */
5813 if ((volumeid = atol(avolname))) {
5814 for (j = 0; j < pcnt; j++) {
5816 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5819 if (code != ENODEV) {
5820 fprintf(STDERR, "Could not query server\n");
5828 /* Found one, sync it with VLDB entry */
5830 CheckVolume(volumeInfo.volEntries_val, aserver,
5831 PartList.partId[j], &mod, &maxvolid);
5838 if (volumeInfo.volEntries_val)
5839 free(volumeInfo.volEntries_val);
5840 volumeInfo.volEntries_val = (volintInfo *) 0;
5841 volumeInfo.volEntries_len = 0;
5845 /* Check to see if the RW, BK, and RO IDs exist on any
5846 * partitions. We get the volume IDs from the VLDB.
5848 rv = 1; /* Read the VLDB entry ? */
5849 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5851 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5853 if (vcode == VL_NOENT)
5856 "Could not access the VLDB for volume %s\n",
5863 if (vldbentry.volumeId[j] == 0)
5866 for (k = 0; k < pcnt; k++) { /* For each partition */
5867 volumeInfo.volEntries_val = (volintInfo *) 0;
5868 volumeInfo.volEntries_len = 0;
5870 AFSVolListOneVolume(aconn, PartList.partId[k],
5871 vldbentry.volumeId[j], &volumeInfo);
5873 if (code != ENODEV) {
5874 fprintf(STDERR, "Could not query server\n");
5882 /* Found one, sync it with VLDB entry */
5884 CheckVolume(volumeInfo.volEntries_val, aserver,
5885 PartList.partId[k], &mod, &maxvolid);
5892 if (volumeInfo.volEntries_val)
5893 free(volumeInfo.volEntries_val);
5894 volumeInfo.volEntries_val = (volintInfo *) 0;
5895 volumeInfo.volEntries_len = 0;
5901 /* If verbose output, print a summary of what changed */
5902 if (tverbose && !(flags & 2)) {
5903 fprintf(STDOUT, "-- status after --\n");
5904 code = VLDB_GetEntryByName(avolname, &vldbentry);
5905 if (code && (code != VL_NOENT)) {
5906 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5910 if (modified && (code == VL_NOENT)) {
5911 fprintf(STDOUT, "\n**entry deleted**\n");
5912 } else if (modified) {
5913 EnumerateEntry(&vldbentry);
5915 fprintf(STDOUT, "\n**no change**\n");
5917 fprintf(STDOUT, "\n_______________________________\n");
5921 /* Now check if the maxvolid is larger than that stored in the VLDB */
5923 afs_int32 maxvldbid = 0;
5924 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
5927 "Could not get the highest allocated volume id from the VLDB\n");
5930 } else if (maxvolid > maxvldbid) {
5932 id = maxvolid - maxvldbid + 1;
5933 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
5936 "Error in increasing highest allocated volume id in VLDB\n");
5946 fprintf(STDOUT, "...error encountered");
5948 fprintf(STDOUT, "...done entry\n");
5951 rx_DestroyConnection(aconn);
5952 if (volumeInfo.volEntries_val)
5953 free(volumeInfo.volEntries_val);
5955 PrintError("", error);
5960 * Synchronise vldb with the file server <aserver> and,
5961 * optionally, <apart>.
5964 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5966 struct rx_connection *aconn;
5967 afs_int32 code, error = 0;
5969 volEntries volumeInfo;
5970 struct partList PartList;
5974 afs_int32 failures = 0, modifications = 0, tentries = 0;
5976 afs_uint32 maxvolid = 0;
5978 volumeInfo.volEntries_val = (volintInfo *) 0;
5979 volumeInfo.volEntries_len = 0;
5981 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5983 /* Generate array of partitions to check */
5985 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5988 "Could not fetch the list of partitions from the server\n");
5992 PartList.partId[0] = apart;
5996 VPRINT("Processing volume entries ...\n");
5998 /* Step through the array of partitions */
5999 for (i = 0; i < pcnt; i++) {
6000 apart = PartList.partId[i];
6001 MapPartIdIntoName(apart, pname);
6003 volumeInfo.volEntries_val = (volintInfo *) 0;
6004 volumeInfo.volEntries_len = 0;
6005 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
6008 "Could not fetch the list of volumes from the server\n");
6012 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
6013 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
6014 sizeof(volintInfo), sortVolumes);
6017 for (vi = volumeInfo.volEntries_val, j = 0;
6018 j < volumeInfo.volEntries_len; j++, vi++) {
6026 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
6027 j + 1, vi->name, (unsigned long)vi->volid,
6028 hostutil_GetNameByINet(aserver), pname);
6036 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
6038 PrintError("", code);
6041 } else if (modified) {
6047 fprintf(STDOUT, "...error encountered\n\n");
6049 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6056 "Could not process entries on server %s partition %s\n",
6057 hostutil_GetNameByINet(aserver), pname);
6059 if (volumeInfo.volEntries_val) {
6060 free(volumeInfo.volEntries_val);
6061 volumeInfo.volEntries_val = 0;
6064 } /* thru all partitions */
6067 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6068 tentries, failures, modifications);
6070 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6071 tentries, failures, modifications);
6075 /* Now check if the maxvolid is larger than that stored in the VLDB */
6077 afs_int32 maxvldbid = 0;
6078 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6081 "Could not get the highest allocated volume id from the VLDB\n");
6084 } else if (maxvolid > maxvldbid) {
6086 id = maxvolid - maxvldbid + 1;
6087 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6090 "Error in increasing highest allocated volume id in VLDB\n");
6098 rx_DestroyConnection(aconn);
6099 if (volumeInfo.volEntries_val)
6100 free(volumeInfo.volEntries_val);
6101 PrintError("", error);
6106 * Determine if a volume exists on a server and partition.
6107 * Try creating a transaction on the volume. If we can,
6108 * the volume exists, if not, then return the error code.
6109 * Some error codes mean the volume is unavailable but
6110 * still exists - so we catch these error codes.
6113 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
6115 struct rx_connection *conn = (struct rx_connection *)0;
6116 afs_int32 code = -1;
6117 volEntries volumeInfo;
6119 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6121 volumeInfo.volEntries_val = (volintInfo *) 0;
6122 volumeInfo.volEntries_len = 0;
6123 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6124 if (volumeInfo.volEntries_val)
6125 free(volumeInfo.volEntries_val);
6126 if (code == VOLSERILLEGAL_PARTITION)
6128 rx_DestroyConnection(conn);
6137 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6141 afs_int32 code, error = 0;
6146 idx = Lp_GetRwIndex(entry);
6148 /* Check to see if the RW volume exists and set the RW_EXISTS
6151 if (idx == -1) { /* Did not find a RW entry */
6152 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6153 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6158 VolumeExists(entry->serverNumber[idx],
6159 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6160 if (code == 0) { /* RW volume exists */
6161 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6162 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6165 } else if (code == ENODEV) { /* RW volume does not exist */
6166 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6167 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6171 /* If VLDB says it didn't exist, then ignore error */
6172 if (entry->flags & RW_EXISTS) {
6173 MapPartIdIntoName(entry->serverPartition[idx], pname);
6175 "Transaction call failed for RW volume %u on server %s %s\n",
6176 entry->volumeId[RWVOL],
6177 hostutil_GetNameByINet(entry->serverNumber[idx]),
6184 /* Check to see if the BK volume exists and set the BACK_EXISTS
6185 * flag accordingly. idx already ponts to the RW entry.
6187 if (idx == -1) { /* Did not find a RW entry */
6188 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6189 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6192 } else { /* Found a RW entry */
6194 VolumeExists(entry->serverNumber[idx],
6195 entry->serverPartition[idx],
6196 entry->volumeId[BACKVOL]);
6197 if (code == 0) { /* BK volume exists */
6198 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6199 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6202 } else if (code == ENODEV) { /* BK volume does not exist */
6203 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6204 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6208 /* If VLDB says it didn't exist, then ignore error */
6209 if (entry->flags & BACK_EXISTS) {
6210 MapPartIdIntoName(entry->serverPartition[idx], pname);
6212 "Transaction call failed for BK volume %u on server %s %s\n",
6213 entry->volumeId[BACKVOL],
6214 hostutil_GetNameByINet(entry->serverNumber[idx]),
6221 /* If there is an idx but the BK and RW volumes no
6222 * longer exist, then remove the RW entry.
6224 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6225 && !(entry->flags & BACK_EXISTS)) {
6226 Lp_SetRWValue(entry, entry->serverNumber[idx],
6227 entry->serverPartition[idx], 0L, 0L);
6234 *modified = modentry;
6239 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6242 int foundro = 0, modentry = 0;
6243 afs_int32 code, error = 0;
6249 /* Check to see if the RO volumes exist and set the RO_EXISTS
6252 for (idx = 0; idx < entry->nServers; idx++) {
6253 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6254 continue; /* not a RO */
6258 VolumeExists(entry->serverNumber[idx],
6259 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6260 if (code == 0) { /* RO volume exists */
6262 } else if (code == ENODEV) { /* RW volume does not exist */
6263 Lp_SetROValue(entry, entry->serverNumber[idx],
6264 entry->serverPartition[idx], 0L, 0L);
6269 MapPartIdIntoName(entry->serverPartition[idx], pname);
6271 "Transaction call failed for RO %u on server %s %s\n",
6272 entry->volumeId[ROVOL],
6273 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6278 if (foundro) { /* A RO volume exists */
6279 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6280 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6283 } else { /* A RO volume does not exist */
6284 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6285 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6292 *modified = modentry;
6297 * Ensure that <entry> matches with the info on file servers
6300 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6302 afs_int32 code, error = 0;
6303 struct nvldbentry storeEntry;
6304 int islocked = 0, mod, modentry, delentry = 0;
6305 int pass = 0, doit=1;
6313 fprintf(STDOUT, "_______________________________\n");
6314 fprintf(STDOUT, "\n-- status before -- \n");
6315 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6316 || (entry->flags & BACK_EXISTS))
6317 EnumerateEntry(entry);
6318 fprintf(STDOUT, "\n");
6321 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6322 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6323 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6327 /* Check to see if the VLDB is ok without locking it (pass 1).
6328 * If it will change, then lock the VLDB entry, read it again,
6329 * then make the changes to it (pass 2).
6333 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6336 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6337 entry->volumeId[RWVOL]);
6342 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6344 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6348 MapHostToNetwork(entry);
6354 /* Check if the RW and BK entries are ok */
6355 code = CheckVldbRWBK(entry, &mod);
6358 if (mod && (pass == 1) && doit)
6363 /* Check if the RO volumes entries are ok */
6364 code = CheckVldbRO(entry, &mod);
6367 if (mod && (pass == 1) && doit)
6372 /* The VLDB entry has been updated. If it as been modified, then
6373 * write the entry back out the the VLDB.
6375 if (modentry && doit) {
6379 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6380 && !(entry->flags & RO_EXISTS) && doit) {
6381 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6383 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6387 "Could not delete VLDB entry for volume %u \n",
6388 entry->volumeId[RWVOL]);
6393 /* Replace old entry with our new one */
6394 MapNetworkToHost(entry, &storeEntry);
6396 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6397 (LOCKREL_OPCODE | LOCKREL_AFSID |
6398 LOCKREL_TIMESTAMP));
6400 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6401 entry->volumeId[RWVOL]);
6410 if (verbose && doit) {
6411 fprintf(STDOUT, "-- status after --\n");
6413 fprintf(STDOUT, "\n**entry deleted**\n");
6415 EnumerateEntry(entry);
6417 fprintf(STDOUT, "\n**no change**\n");
6421 VPRINT("\n_______________________________\n");
6425 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6427 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6430 "Could not release lock on VLDB entry for volume %u\n",
6431 entry->volumeId[RWVOL]);
6440 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6443 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6445 struct rx_connection *aconn;
6446 afs_int32 code, error = 0;
6447 afs_int32 nentries, tentries = 0;
6448 struct VldbListByAttributes attributes;
6449 nbulkentries arrayEntries;
6450 afs_int32 failures = 0, modified, modifications = 0;
6451 struct nvldbentry *vlentry;
6452 afs_int32 si, nsi, j;
6457 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6459 /* Set up attributes to search VLDB */
6460 attributes.server = ntohl(aserver);
6461 attributes.Mask = VLLIST_SERVER;
6463 attributes.partition = apart;
6464 attributes.Mask |= VLLIST_PARTITION;
6467 VPRINT("Processing VLDB entries ...\n");
6469 /* While we need to collect more VLDB entries */
6470 for (si = 0; si != -1; si = nsi) {
6471 memset(&arrayEntries, 0, sizeof(arrayEntries));
6473 /* Collect set of VLDB entries */
6475 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6476 &arrayEntries, &nsi);
6477 if (code == RXGEN_OPCODE) {
6478 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6482 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6485 tentries += nentries;
6487 for (j = 0; j < nentries; j++) {
6488 vlentry = &arrayEntries.nbulkentries_val[j];
6489 MapHostToNetwork(vlentry);
6491 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6493 /* Tell CheckVldb not to update if appropriate */
6498 code = CheckVldb(vlentry, &modified);
6500 PrintError("", code);
6502 "Could not process VLDB entry for volume %s\n",
6505 } else if (modified) {
6511 fprintf(STDOUT, "...error encountered\n\n");
6513 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6518 if (arrayEntries.nbulkentries_val) {
6519 free(arrayEntries.nbulkentries_val);
6520 arrayEntries.nbulkentries_val = 0;
6525 VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
6526 tentries, failures, modifications);
6528 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
6529 tentries, failures, modifications);
6534 rx_DestroyConnection(aconn);
6535 if (arrayEntries.nbulkentries_val)
6536 free(arrayEntries.nbulkentries_val);
6539 error = VOLSERFAILEDOP;
6543 /*rename volume <oldname> to <newname>, changing the names of the related
6544 *readonly and backup volumes. This operation is also idempotent.
6545 *salvager is capable of recovering from rename operation stopping halfway.
6546 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6548 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6550 struct nvldbentry storeEntry;
6551 afs_int32 vcode, code, rcode, error;
6553 char nameBuffer[256];
6555 struct rx_connection *aconn;
6559 aconn = (struct rx_connection *)0;
6563 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6566 " Could not lock the VLDB entry for the volume %u \n",
6567 entry->volumeId[RWVOL]);
6572 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6573 MapNetworkToHost(entry, &storeEntry);
6574 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6576 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6577 entry->volumeId[RWVOL]);
6581 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6582 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6583 * is concerned, oldname is lost */
6584 if (entry->flags & RW_EXISTS) {
6585 index = Lp_GetRwIndex(entry);
6586 if (index == -1) { /* there is a serious discrepancy */
6588 "There is a serious discrepancy in VLDB entry for volume %u\n",
6589 entry->volumeId[RWVOL]);
6590 fprintf(STDERR, "try building VLDB from scratch\n");
6591 error = VOLSERVLDB_ERROR;
6594 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6596 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6597 entry->serverPartition[index], ITOffline, &tid);
6598 if (code) { /*volume doesnot exist */
6600 "Could not start transaction on the rw volume %u\n",
6601 entry->volumeId[RWVOL]);
6604 } else { /*volume exists, process it */
6607 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6608 entry->volumeId[RWVOL],
6609 entry->volumeId[ROVOL],
6610 entry->volumeId[BACKVOL]);
6612 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6613 code = AFSVolEndTrans(aconn, tid, &rcode);
6617 "Could not end transaction on volume %s %u\n",
6618 entry->name, entry->volumeId[RWVOL]);
6623 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6624 entry->name, entry->volumeId[RWVOL]);
6630 rx_DestroyConnection(aconn);
6631 aconn = (struct rx_connection *)0;
6633 /*end rw volume processing */
6634 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6635 index = Lp_GetRwIndex(entry);
6636 if (index == -1) { /* there is a serious discrepancy */
6638 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6639 entry->volumeId[BACKVOL]);
6640 fprintf(STDERR, "try building VLDB from scratch\n");
6641 error = VOLSERVLDB_ERROR;
6644 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6646 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6647 entry->serverPartition[index], ITOffline, &tid);
6648 if (code) { /*volume doesnot exist */
6650 "Could not start transaction on the backup volume %u\n",
6651 entry->volumeId[BACKVOL]);
6654 } else { /*volume exists, process it */
6655 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6657 "Volume name %s.backup exceeds the limit of %u characters\n",
6658 newname, VOLSER_OLDMAXVOLNAME);
6662 strcpy(nameBuffer, newname);
6663 strcat(nameBuffer, ".backup");
6666 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6667 entry->volumeId[RWVOL], 0, 0);
6669 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6670 code = AFSVolEndTrans(aconn, tid, &rcode);
6674 "Could not end transaction on the backup volume %u\n",
6675 entry->volumeId[BACKVOL]);
6681 "Could not set parameters on the backup volume %u\n",
6682 entry->volumeId[BACKVOL]);
6687 } /* end backup processing */
6689 rx_DestroyConnection(aconn);
6690 aconn = (struct rx_connection *)0;
6691 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6692 for (i = 0; i < entry->nServers; i++) {
6693 if (entry->serverFlags[i] & ITSROVOL) {
6694 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6696 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6697 entry->serverPartition[i], ITOffline,
6699 if (code) { /*volume doesnot exist */
6701 "Could not start transaction on the ro volume %u\n",
6702 entry->volumeId[ROVOL]);
6705 } else { /*volume exists, process it */
6706 strcpy(nameBuffer, newname);
6707 strcat(nameBuffer, ".readonly");
6708 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6710 "Volume name %s exceeds the limit of %u characters\n",
6711 nameBuffer, VOLSER_OLDMAXVOLNAME);
6716 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6717 entry->volumeId[RWVOL], 0, 0);
6719 VPRINT2("Renamed RO volume %s on host %s\n",
6721 hostutil_GetNameByINet(entry->
6723 code = AFSVolEndTrans(aconn, tid, &rcode);
6727 "Could not end transaction on volume %u\n",
6728 entry->volumeId[ROVOL]);
6734 "Could not set parameters on the ro volume %u\n",
6735 entry->volumeId[ROVOL]);
6741 rx_DestroyConnection(aconn);
6742 aconn = (struct rx_connection *)0;
6749 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6751 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6754 "Could not unlock the VLDB entry for the volume %s %u\n",
6755 entry->name, entry->volumeId[RWVOL]);
6761 code = AFSVolEndTrans(aconn, tid, &rcode);
6765 fprintf(STDERR, "Failed to end transaction on a volume \n");
6771 rx_DestroyConnection(aconn);
6772 PrintError("", error);
6777 /*report on all the active transactions on volser */
6779 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6781 struct rx_connection *aconn;
6782 transDebugEntries transInfo;
6785 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6786 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6787 transInfo.transDebugEntries_len = 0;
6788 code = AFSVolMonitor(aconn, &transInfo);
6791 "Could not access status information about the server\n");
6792 PrintError("", code);
6793 if (transInfo.transDebugEntries_val)
6794 free(transInfo.transDebugEntries_val);
6796 rx_DestroyConnection(aconn);
6799 *rcount = transInfo.transDebugEntries_len;
6800 *rpntr = transInfo.transDebugEntries_val;
6802 rx_DestroyConnection(aconn);
6809 /*delete the volume without interacting with the vldb */
6811 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6813 afs_int32 rcode, ttid, error, code;
6814 struct rx_connection *aconn;
6820 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6821 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6823 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6824 (unsigned long)volid);
6828 code = AFSVolDeleteVolume(aconn, ttid);
6830 fprintf(STDERR, "Could not delete volume %lu\n",
6831 (unsigned long)volid);
6835 code = AFSVolEndTrans(aconn, ttid, &rcode);
6840 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6841 (unsigned long)volid);
6847 code = AFSVolEndTrans(aconn, ttid, &rcode);
6853 PrintError("", error);
6855 rx_DestroyConnection(aconn);
6860 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6861 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6863 struct rx_connection *conn = 0;
6865 afs_int32 code, error = 0, rcode;
6867 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6869 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6873 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6875 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6879 code = AFSVolSetFlags(conn, tid, setflag);
6881 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6886 #ifdef AFS_PTHREAD_ENV
6889 IOMGR_Sleep(sleeptime);
6896 code = AFSVolEndTrans(conn, tid, &rcode);
6897 if (code || rcode) {
6898 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6900 error = (code ? code : rcode);
6905 rx_DestroyConnection(conn);
6910 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6913 struct rx_connection *conn = 0;
6915 afs_int32 code, error = 0, rcode;
6917 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6919 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6923 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6925 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6929 code = AFSVolSetInfo(conn, tid, infop);
6931 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6938 code = AFSVolEndTrans(conn, tid, &rcode);
6939 if (code || rcode) {
6940 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6942 error = (code ? code : rcode);
6947 rx_DestroyConnection(conn);
6952 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6953 afs_int32 fromdate, struct volintSize *vol_size)
6955 struct rx_connection *aconn = (struct rx_connection *)0;
6956 afs_int32 tid = 0, rcode = 0;
6957 afs_int32 code, error = 0;
6960 /* get connections to the servers */
6961 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6963 VPRINT1("Starting transaction on volume %u...", afromvol);
6964 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6965 EGOTO1(error_exit, code,
6966 "Could not start transaction on the volume %u to be measured\n",
6970 VPRINT1("Getting size of volume on volume %u...", afromvol);
6971 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6972 EGOTO(error_exit, code, "Could not start the measurement process \n");
6977 VPRINT1("Ending transaction on volume %u...", afromvol);
6978 code = AFSVolEndTrans(aconn, tid, &rcode);
6979 if (code || rcode) {
6980 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6982 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6984 error = (code ? code : rcode);
6989 rx_DestroyConnection(aconn);
6991 PrintError("", error);
6995 /*maps the host addresses in <old > (present in network byte order) to
6996 that in< new> (present in host byte order )*/
6998 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
7002 /*copy all the fields */
7003 strcpy(new->name, old->name);
7004 /* new->volumeType = old->volumeType;*/
7005 new->nServers = old->nServers;
7006 count = old->nServers;
7007 if (count < NMAXNSERVERS)
7009 for (i = 0; i < count; i++) {
7010 new->serverNumber[i] = ntohl(old->serverNumber[i]);
7011 new->serverPartition[i] = old->serverPartition[i];
7012 new->serverFlags[i] = old->serverFlags[i];
7014 new->volumeId[RWVOL] = old->volumeId[RWVOL];
7015 new->volumeId[ROVOL] = old->volumeId[ROVOL];
7016 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
7017 new->cloneId = old->cloneId;
7018 new->flags = old->flags;
7021 /*maps the host entries in <entry> which are present in host byte order to network byte order */
7023 MapHostToNetwork(struct nvldbentry *entry)
7027 count = entry->nServers;
7028 if (count < NMAXNSERVERS)
7030 for (i = 0; i < count; i++) {
7031 entry->serverNumber[i] = htonl(entry->serverNumber[i]);