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>
20 #include <sys/statfs.h>
27 #include <netinet/in.h>
39 #include <afs/voldefs.h>
42 #include <afs/vlserver.h>
45 #include <afs/cellconfig.h>
48 #include <afs/afsint.h>
52 #include <afs/com_err.h>
54 #include <afs/kautils.h>
57 #define ERRCODE_RANGE 8 /* from error_table.h */
58 #define CLOCKSKEW 2 /* not really skew, but resolution */
60 /* for UV_MoveVolume() recovery */
62 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
65 #include <volser_prototypes.h>
67 struct ubik_client *cstruct;
73 afs_int32 vldbEntryIndex;
76 /* Utility macros used by rest of this source file */
77 #define EPRINT(ec, es) \
79 fprintf(STDERR, "\n"); \
80 fprintf(STDERR, (es)); \
84 #define EPRINT1(ec, es, ep1) \
86 fprintf(STDERR, "\n"); \
87 fprintf(STDERR, (es), (ep1)); \
91 #define EPRINT2(ec, es, ep1, ep2) \
93 fprintf(STDERR, "\n"); \
94 fprintf(STDERR, (es), (ep1), (ep2)); \
98 #define EPRINT3(ec, es, ep1, ep2, ep3) \
100 fprintf(STDERR, "\n"); \
101 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
102 PrintError(" ",ec); \
105 #define EGOTO(where, ec, es) \
114 #define EGOTO1(where, ec, es, ep1) \
117 EPRINT1((ec),(es),(ep1)); \
123 #define EGOTO2(where, ec, es, ep1, ep2) \
126 EPRINT2((ec),(es),(ep1),(ep2)); \
132 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
135 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
142 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
143 #define VPRINT1(es, p) \
144 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
145 #define VPRINT2(es, p1, p2) \
146 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
147 #define VPRINT3(es, p1, p2, p3) \
148 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
150 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
154 /* getting rid of this */
155 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
158 /* Protos for static routines */
159 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
160 afs_int32 apart, afs_int32 okvol,
162 static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
164 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
165 struct rx_connection **connPtr, afs_int32 * transPtr,
166 afs_int32 * crtimePtr, afs_int32 * uptimePtr);
167 static int SimulateForwardMultiple(struct rx_connection *fromconn,
168 afs_int32 fromtid, afs_int32 fromdate,
169 manyDests * tr, afs_int32 flags,
170 void *cookie, manyResults * results);
171 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
172 afs_int32 apart, afs_int32 * modentry,
173 afs_uint32 * maxvolid);
176 /*map the partition <partId> into partition name <partName>*/
178 MapPartIdIntoName(afs_int32 partId, char *partName)
180 if (partId < 26) { /* what if partId > = 26 ? */
181 strcpy(partName, "/vicep");
182 partName[6] = partId + 'a';
185 } else if (partId < VOLMAXPARTS) {
186 strcpy(partName, "/vicep");
188 partName[6] = 'a' + (partId / 26);
189 partName[7] = 'a' + (partId % 26);
201 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
202 response = c = getchar();
203 while (!(c == EOF || c == '\n'))
204 c = getchar(); /*skip to end of line */
205 code = (response == 'y' || response == 'Y');
211 PrintError(char *msg, afs_int32 errcode)
213 fprintf(STDERR, msg);
214 /*replace by a big switch statement */
219 fprintf(STDERR, "Possible communication failure\n");
222 fprintf(STDERR, "Volume needs to be salvaged\n");
225 fprintf(STDERR, "Bad vnode number quoted\n");
229 "Volume not attached, does not exist, or not on line\n");
232 fprintf(STDERR, "Volume already exists\n");
235 fprintf(STDERR, "Volume is not in service\n");
238 fprintf(STDERR, "Volume is off line\n");
241 fprintf(STDERR, "Volume is already on line\n");
244 fprintf(STDERR, "Partition is full\n");
247 fprintf(STDERR, "Volume max quota exceeded\n");
250 fprintf(STDERR, "Volume temporarily unavailable\n");
253 fprintf(STDERR, "Volume has moved to another server\n");
256 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
259 fprintf(STDERR, "VLDB: a read terminated too early\n");
262 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
265 fprintf(STDERR, "VLDB: internal creation failure\n");
268 fprintf(STDERR, "VLDB: no such entry\n");
271 fprintf(STDERR, "VLDB: vldb database is empty\n");
274 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
277 fprintf(STDERR, "VLDB: volume name is illegal\n");
280 fprintf(STDERR, "VLDB: index was out of range\n");
283 fprintf(STDERR, "VLDB: bad volume type\n");
286 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
288 case VL_BADPARTITION:
289 fprintf(STDERR, "VLDB: bad partition number\n");
292 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
295 fprintf(STDERR, "VLDB: no such repsite server exists\n");
297 case VL_DUPREPSERVER:
298 fprintf(STDERR, "VLDB: replication site server already exists\n");
301 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
304 fprintf(STDERR, "VLDB: illegal reference count number\n");
306 case VL_SIZEEXCEEDED:
307 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
310 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
312 case VL_BADVOLIDBUMP:
313 fprintf(STDERR, "VLDB: illegal max volid increment\n");
315 case VL_IDALREADYHASHED:
316 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
319 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
322 fprintf(STDERR, "VLDB: bad volume operation code\n");
324 case VL_BADRELLOCKTYPE:
325 fprintf(STDERR, "VLDB: bad release lock type\n");
328 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
330 case VL_BADSERVERFLAG:
331 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
334 fprintf(STDERR, "VLDB: no permission access for call\n");
336 case VOLSERREAD_DUMPERROR:
338 "VOLSER: Problems encountered in reading the dump file !\n");
340 case VOLSERDUMPERROR:
341 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
343 case VOLSERATTACH_ERROR:
344 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
346 case VOLSERDETACH_ERROR:
347 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
349 case VOLSERILLEGAL_PARTITION:
350 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
352 case VOLSERBAD_ACCESS:
353 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
355 case VOLSERVLDB_ERROR:
356 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
359 fprintf(STDERR, "VOLSER: error in volume name\n");
362 fprintf(STDERR, "VOLSER: volume has moved\n");
365 fprintf(STDERR, "VOLSER: illegal operation\n");
367 case VOLSERBADRELEASE:
368 fprintf(STDERR, "VOLSER: release could not be completed\n");
371 fprintf(STDERR, "VOLSER: volume is busy\n");
373 case VOLSERNO_MEMORY:
374 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
378 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
380 case VOLSERMULTIRWVOL:
382 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
386 "VOLSER: not all entries were successfully processed\n");
393 initialize_KA_error_table();
394 initialize_RXK_error_table();
395 initialize_KTC_error_table();
396 initialize_ACFG_error_table();
397 initialize_CMD_error_table();
398 initialize_VL_error_table();
400 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
401 fprintf(STDERR, "%s: %s\n", error_table_name(errcode),
402 error_message(errcode));
409 void init_volintInfo(struct volintInfo *vinfo) {
410 memset(vinfo, 0, sizeof(struct volintInfo));
412 vinfo->maxquota = -1;
414 vinfo->creationDate = -1;
415 vinfo->updateDate = -1;
423 static struct rx_securityClass *uvclass = 0;
424 static int uvindex = -1;
425 /* called by VLDBClient_Init to set the security module to be used in the RPC */
427 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
434 /* bind to volser on <port> <aserver> */
435 /* takes server address in network order, port in host order. dumb */
436 struct rx_connection *
437 UV_Bind(afs_int32 aserver, afs_int32 port)
439 register struct rx_connection *tc;
441 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
446 /* if <okvol> is allright(indicated by beibg able to
447 * start a transaction, delete the <delvol> */
449 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
450 afs_int32 okvol, afs_int32 delvol)
452 afs_int32 error, code, tid, rcode;
458 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
461 code = AFSVolDeleteVolume(aconn, tid);
464 code = AFSVolEndTrans(aconn, tid, &rcode);
471 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
473 code = AFSVolEndTrans(aconn, tid, &rcode);
478 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
481 code = AFSVolDeleteVolume(aconn, tid);
484 code = AFSVolEndTrans(aconn, tid, &rcode);
495 /* called by EmuerateEntry, show vldb entry in a reasonable format */
497 SubEnumerateEntry(struct nvldbentry *entry)
504 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
505 if (entry->flags & RW_EXISTS)
506 fprintf(STDOUT, " valid \n");
508 fprintf(STDOUT, " invalid \n");
509 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
510 if (entry->flags & RO_EXISTS)
511 fprintf(STDOUT, " valid \n");
513 fprintf(STDOUT, " invalid \n");
514 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
515 if (entry->flags & BACK_EXISTS)
516 fprintf(STDOUT, " valid \n");
518 fprintf(STDOUT, " invalid \n");
519 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
520 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
522 if (entry->flags & RW_EXISTS)
523 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
524 if (entry->flags & RO_EXISTS)
525 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
526 if (entry->flags & BACK_EXISTS)
527 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
528 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
529 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
530 fprintf(STDOUT, "\n");
532 fprintf(STDOUT, " number of sites -> %lu\n",
533 (unsigned long)entry->nServers);
534 for (i = 0; i < entry->nServers; i++) {
535 if (entry->serverFlags[i] & NEW_REPSITE)
538 for (i = 0; i < entry->nServers; i++) {
539 MapPartIdIntoName(entry->serverPartition[i], pname);
540 fprintf(STDOUT, " server %s partition %s ",
541 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
542 if (entry->serverFlags[i] & ITSRWVOL)
543 fprintf(STDOUT, "RW Site ");
545 fprintf(STDOUT, "RO Site ");
547 if (entry->serverFlags[i] & NEW_REPSITE)
548 fprintf(STDOUT," -- New release");
550 if (!(entry->serverFlags[i] & ITSRWVOL))
551 fprintf(STDOUT," -- Old release");
553 if (entry->serverFlags[i] & RO_DONTUSE)
554 fprintf(STDOUT, " -- Not released");
556 fprintf(STDOUT, "\n");
563 /*enumerate the vldb entry corresponding to <entry> */
565 EnumerateEntry(struct nvldbentry *entry)
568 fprintf(STDOUT, "\n");
569 fprintf(STDOUT, "%s \n", entry->name);
570 SubEnumerateEntry(entry);
574 /* forcibly remove a volume. Very dangerous call */
576 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
578 register struct rx_connection *tconn;
579 register afs_int32 code;
581 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
583 code = AFSVolNukeVolume(tconn, partid, volid);
584 rx_DestroyConnection(tconn);
590 /* like df. Return usage of <pname> on <server> in <partition> */
592 UV_PartitionInfo(afs_int32 server, char *pname,
593 struct diskPartition *partition)
595 register struct rx_connection *aconn;
599 aconn = (struct rx_connection *)0;
600 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
601 code = AFSVolPartitionInfo(aconn, pname, partition);
603 fprintf(STDERR, "Could not get information on partition %s\n", pname);
604 PrintError("", code);
607 rx_DestroyConnection(aconn);
611 /* old interface to create volume */
613 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
617 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
621 /* create a volume, given a server, partition number, volume name --> sends
622 * back new vol id in <anewid>*/
624 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
625 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
626 afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
629 register struct rx_connection *aconn;
631 register afs_int32 code;
633 afs_int32 rcode, vcode;
634 struct nvldbentry entry, storeEntry; /*the new vldb entry */
635 struct volintInfo tstatus;
638 aconn = (struct rx_connection *)0;
641 init_volintInfo(&tstatus);
642 tstatus.maxquota = aquota;
644 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
645 /* next the next 3 available ids from the VLDB */
646 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 3, anewid);
647 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
650 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
651 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
654 code = AFSVolSetInfo(aconn, tid, &tstatus);
656 EPRINT(code, "Could not change quota (error %d), continuing...\n");
658 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
659 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
662 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
664 /* set up the vldb entry for this volume */
665 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
667 entry.serverNumber[0] = aserver; /* this should have another
668 * level of indirection later */
669 entry.serverPartition[0] = apart; /* this should also have
670 * another indirection level */
671 entry.flags = RW_EXISTS; /* this records that rw volume exists */
672 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
673 entry.volumeId[RWVOL] = *anewid;
674 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
675 entry.volumeId[BACKVOL] = *anewid + 2;
677 /*map into right byte order, before passing to xdr, the stuff has to be in host
678 * byte order. Xdr converts it into network order */
679 MapNetworkToHost(&entry, &storeEntry);
680 /* create the vldb entry */
681 vcode = VLDB_CreateEntry(&storeEntry);
684 "Could not create a VLDB entry for the volume %s %lu\n",
685 aname, (unsigned long)*anewid);
686 /*destroy the created volume */
687 VPRINT1("Deleting the newly created volume %u\n", *anewid);
688 AFSVolDeleteVolume(aconn, tid);
692 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
693 /* volume created, now terminate the transaction and release the connection */
694 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
695 * the volume will come online anyway when transaction timesout , so if
696 * vldb entry exists then the volume is guaranteed to exist too wrt create */
700 "Failed to end the transaction on the volume %s %lu\n", aname,
701 (unsigned long)*anewid);
708 code = AFSVolEndTrans(aconn, tid, &rcode);
710 fprintf(STDERR, "WARNING: could not end transaction\n");
713 rx_DestroyConnection(aconn);
714 PrintError("", error);
720 /* create a volume, given a server, partition number, volume name --> sends
721 * back new vol id in <anewid>*/
723 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
726 register struct rx_connection *aconn;
729 struct nvldbentry entry, storeEntry; /*the new vldb entry */
731 aconn = (struct rx_connection *)0;
734 /* set up the vldb entry for this volume */
735 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
737 entry.serverNumber[0] = aserver; /* this should have another
738 * level of indirection later */
739 entry.serverPartition[0] = apart; /* this should also have
740 * another indirection level */
741 entry.flags = RW_EXISTS; /* this records that rw volume exists */
742 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
743 entry.volumeId[RWVOL] = aid;
745 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
746 entry.volumeId[BACKVOL] = *anewid + 2;
748 entry.volumeId[ROVOL] = 0;
749 entry.volumeId[BACKVOL] = 0;
752 /*map into right byte order, before passing to xdr, the stuff has to be in host
753 * byte order. Xdr converts it into network order */
754 MapNetworkToHost(&entry, &storeEntry);
755 /* create the vldb entry */
756 vcode = VLDB_CreateEntry(&storeEntry);
759 "Could not create a VLDB entry for the volume %s %lu\n",
760 aname, (unsigned long)aid);
764 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
768 rx_DestroyConnection(aconn);
769 PrintError("", error);
773 /* Delete the volume <volid>on <aserver> <apart>
774 * the physical entry gets removed from the vldb only if the ref count
778 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
780 struct rx_connection *aconn = (struct rx_connection *)0;
782 afs_int32 code, rcode;
784 struct nvldbentry entry, storeEntry;
786 afs_int32 avoltype = -1, vtype;
787 int notondisk = 0, notinvldb = 0;
789 /* Find and read bhe VLDB entry for this volume */
790 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, avoltype, VLOP_DELETE);
792 if (code != VL_NOENT) {
793 EGOTO1(error_exit, code,
794 "Could not lock VLDB entry for the volume %u\n", avolid);
800 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
801 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
803 MapHostToNetwork(&entry);
806 EnumerateEntry(&entry);
809 /* Whether volume is in the VLDB or not. Delete the volume on disk */
810 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
811 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
813 if (code == VNOVOL) {
816 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
820 VPRINT1("Trying to delete the volume %u ...", avolid);
822 code = AFSVolDeleteVolume(aconn, ttid);
823 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
825 code = AFSVolEndTrans(aconn, ttid, &rcode);
826 code = (code ? code : rcode);
828 EGOTO1(error_exit, code,
829 "Could not end the transaction for the volume %u \n", avolid);
833 /* Now update the VLDB entry.
834 * But first, verify we have a VLDB entry.
835 * Whether volume is on disk or not. Delete the volume in VLDB.
840 if (avolid == entry.volumeId[BACKVOL]) {
841 /* Its a backup volume, modify the VLDB entry. Check that the
842 * backup volume is on the server/partition we asked to delete.
844 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
845 notinvldb = 2; /* Not on this server and partition */
849 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
851 entry.flags &= ~BACK_EXISTS;
855 else if (avolid == entry.volumeId[ROVOL]) {
856 /* Its a read-only volume, modify the VLDB entry. Check that the
857 * readonly volume is on the server/partition we asked to delete.
858 * If flags does not have RO_EIXSTS set, then this may mean the RO
859 * hasn't been released (and could exist in VLDB).
861 if (!Lp_ROMatch(aserver, apart, &entry)) {
862 notinvldb = 2; /* Not found on this server and partition */
868 "Marking the readonly volume %lu deleted in the VLDB\n",
869 (unsigned long)avolid);
871 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
873 if (!Lp_ROMatch(0, 0, &entry))
874 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
878 else if (avolid == entry.volumeId[RWVOL]) {
879 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
880 * Check that the readwrite volumes is on the server/partition we
883 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
884 notinvldb = 2; /* Not found on this server and partition */
888 /* Delete backup if it exists */
890 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
894 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
895 entry.volumeId[BACKVOL]);
898 code = AFSVolDeleteVolume(aconn, ttid);
899 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
900 entry.volumeId[BACKVOL]);
902 code = AFSVolEndTrans(aconn, ttid, &rcode);
904 code = (code ? code : rcode);
905 EGOTO1(error_exit, code,
906 "Could not end the transaction for the volume %u \n",
907 entry.volumeId[BACKVOL]);
909 fprintf(STDOUT, " done\n");
914 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
915 (unsigned long)avolid,
917 flags & BACK_EXISTS) ? ", and its backup volume," :
920 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
922 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
925 if (entry.flags & RO_EXISTS)
926 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
930 notinvldb = 2; /* Not found on this server and partition */
934 /* Either delete or replace the VLDB entry */
935 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
938 "Last reference to the VLDB entry for %lu - deleting entry\n",
939 (unsigned long)avolid);
940 code = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, vtype);
941 EGOTO1(error_exit, code,
942 "Could not delete the VLDB entry for the volume %u \n",
945 MapNetworkToHost(&entry, &storeEntry);
947 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
948 (LOCKREL_OPCODE | LOCKREL_AFSID |
950 EGOTO1(error_exit, code,
951 "Could not update the VLDB entry for the volume %u \n",
960 if (notondisk && notinvldb) {
961 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
962 ((notinvldb == 2) ? "on server and partition" : ""));
965 } else if (notondisk) {
967 "WARNING: Volume %lu did not exist on the partition\n",
968 (unsigned long)avolid);
969 } else if (notinvldb) {
970 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
971 (unsigned long)avolid,
972 ((notinvldb == 2) ? "on server and partition" : ""));
976 code = AFSVolEndTrans(aconn, ttid, &rcode);
977 code = (code ? code : rcode);
979 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
980 (unsigned long)avolid);
981 PrintError("", code);
989 ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, -1,
990 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
993 "Could not release the lock on the VLDB entry for the volume %u \n",
1001 rx_DestroyConnection(aconn);
1005 /* add recovery to UV_MoveVolume */
1007 #define TESTC 0 /* set to test recovery code, clear for production */
1013 sigint_handler(int x)
1018 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1020 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1021 fprintf(STDOUT, "enter second control-c to exit\n");
1025 (void)signal(SIGINT, sigint_handler);
1030 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1031 * <atopart>. The operation is almost idempotent. The following
1032 * flags are recognized:
1034 * RV_NOCLONE - don't use a copy clone
1038 UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1039 afs_int32 atoserver, afs_int32 atopart, int flags)
1041 struct rx_connection *toconn, *fromconn;
1042 afs_int32 fromtid, totid, clonetid;
1045 char tmpName[VOLSER_MAXVOLNAME + 1];
1048 struct restoreCookie cookie;
1049 register afs_int32 vcode, code;
1050 afs_int32 newVol, volid, backupId;
1051 struct volser_status tstatus;
1052 struct destServer destination;
1054 struct nvldbentry entry, storeEntry;
1055 int i, islocked, pntg;
1057 char in, lf; /* for test code */
1060 #ifdef ENABLE_BUGFIX_1165
1061 volEntries volumeInfo;
1062 struct volintInfo *infop = 0;
1066 fromconn = (struct rx_connection *)0;
1067 toconn = (struct rx_connection *)0;
1077 /* support control-c processing */
1080 (void)signal(SIGINT, sigint_handler);
1084 "\nThere are three tests points - verifies all code paths through recovery.\n");
1085 fprintf(STDOUT, "First test point - operation not started.\n");
1086 fprintf(STDOUT, "...test here (y, n)? ");
1088 fscanf(stdin, "%c", &in);
1089 fscanf(stdin, "%c", &lf); /* toss away */
1091 fprintf(STDOUT, "type control-c\n");
1093 fprintf(stdout, ".");
1098 /* or drop through */
1101 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1102 EGOTO1(mfail, vcode,
1103 "Could not fetch the entry for the volume %u from the VLDB \n",
1106 if (entry.volumeId[RWVOL] != afromvol) {
1107 fprintf(STDERR, "Only RW volume can be moved\n");
1111 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1112 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1115 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1116 EGOTO1(mfail, vcode,
1117 "Could not fetch the entry for the volume %u from the VLDB \n",
1120 backupId = entry.volumeId[BACKVOL];
1121 MapHostToNetwork(&entry);
1123 if (!Lp_Match(afromserver, afrompart, &entry)) {
1124 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1125 if (!Lp_Match(atoserver, atopart, &entry)) {
1126 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1127 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1128 (unsigned long)afromvol);
1129 fprintf(STDERR, "The current site is :");
1130 for (i = 0; i < entry.nServers; i++) {
1131 if (entry.serverFlags[i] == ITSRWVOL) {
1133 MapPartIdIntoName(entry.serverPartition[i], pname);
1134 fprintf(STDERR, " server %s partition %s \n",
1135 hostutil_GetNameByINet(entry.serverNumber[i]),
1140 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1141 (LOCKREL_OPCODE | LOCKREL_AFSID |
1142 LOCKREL_TIMESTAMP));
1143 EGOTO1(mfail, vcode,
1144 " Could not release lock on the VLDB entry for the volume %u \n",
1147 return VOLSERVOLMOVED;
1150 /* delete the volume afromvol on src_server */
1151 /* from-info does not exist but to-info does =>
1152 * we have already done the move, but the volume
1153 * may still be existing physically on from fileserver
1155 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1160 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1162 if (!code) { /* volume exists - delete it */
1163 VPRINT1("Setting flags on leftover source volume %u ...",
1166 AFSVolSetFlags(fromconn, fromtid,
1167 VTDeleteOnSalvage | VTOutOfService);
1169 "Failed to set flags on the leftover source volume %u\n",
1173 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1174 code = AFSVolDeleteVolume(fromconn, fromtid);
1176 "Failed to delete the leftover source volume %u\n",
1180 VPRINT1("Ending transaction on leftover source volume %u ...",
1182 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1187 "Could not end the transaction for the leftover source volume %u \n",
1192 /*delete the backup volume now */
1195 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1197 if (!code) { /* backup volume exists - delete it */
1198 VPRINT1("Setting flags on leftover backup volume %u ...",
1201 AFSVolSetFlags(fromconn, fromtid,
1202 VTDeleteOnSalvage | VTOutOfService);
1204 "Failed to set flags on the backup volume %u\n", backupId);
1207 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1208 code = AFSVolDeleteVolume(fromconn, fromtid);
1210 "Could not delete the leftover backup volume %u\n",
1214 VPRINT1("Ending transaction on leftover backup volume %u ...",
1216 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1221 "Could not end the transaction for the leftover backup volume %u\n",
1231 /* From-info matches the vldb info about volid,
1232 * its ok start the move operation, the backup volume
1233 * on the old site is deleted in the process
1235 if (afrompart == atopart) {
1236 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1237 EGOTO2(mfail, error,
1238 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1239 afromserver, error);
1242 EGOTO1(mfail, VOLSERVOLMOVED,
1243 "Warning: Moving volume %u to its home partition ignored!\n",
1249 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1250 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1251 fromtid = totid = 0; /* initialize to uncreated */
1254 * clone the read/write volume locally.
1257 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1258 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1259 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1263 if (!(flags & RV_NOCLONE)) {
1264 /* Get a clone id */
1265 VPRINT1("Allocating new volume id for clone of volume %u ...",
1268 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
1269 EGOTO1(mfail, vcode,
1270 "Could not get an ID for the clone of volume %u from the VLDB\n",
1274 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1275 VPRINT1("Cloning source volume %u ...", afromvol);
1276 strcpy(vname, "move-clone-temp");
1278 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1279 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1284 /* lookup the name of the volume we just cloned */
1286 code = AFSVolGetName(fromconn, fromtid, &volName);
1287 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1290 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1292 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1297 "Failed to end the transaction on the source volume %u\n",
1302 * Create the destination volume
1305 if (!(flags & RV_NOCLONE)) {
1306 /* All of this is to get the fromDate */
1307 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1309 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1312 "Failed to start a transaction on the cloned volume%u\n",
1316 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1318 AFSVolSetFlags(fromconn, clonetid,
1319 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1320 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1324 /* remember time from which we've dumped the volume */
1325 VPRINT1("Getting status of cloned volume %u ...", newVol);
1326 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1328 "Failed to get the status of the cloned volume %u\n",
1332 fromDate = tstatus.creationDate - CLOCKSKEW;
1334 /* With RV_NOCLONE, just do a full copy from the source */
1339 #ifdef ENABLE_BUGFIX_1165
1341 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1342 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1343 * don't use this information...
1345 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1346 volumeInfo.volEntries_len = 0;
1347 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1349 "Failed to get the volint Info of the cloned volume %u\n",
1352 infop = (volintInfo *) volumeInfo.volEntries_val;
1353 infop->maxquota = -1; /* Else it will replace the default quota */
1354 infop->creationDate = -1; /* Else it will use the source creation date */
1355 infop->updateDate = -1; /* Else it will use the source update date */
1358 /* create a volume on the target machine */
1360 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1362 /* Delete the existing volume.
1363 * While we are deleting the volume in these steps, the transaction
1364 * we started against the cloned volume (clonetid above) will be
1365 * sitting idle. It will get cleaned up after 600 seconds
1367 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1368 code = AFSVolDeleteVolume(toconn, totid);
1370 "Could not delete the pre-existing volume %u on destination\n",
1375 ("Ending transaction on pre-existing volume %u on destination ...",
1377 code = AFSVolEndTrans(toconn, totid, &rcode);
1382 "Could not end the transaction on pre-existing volume %u on destination\n",
1387 VPRINT1("Creating the destination volume %u ...", volid);
1389 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1391 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1395 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1399 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1401 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1403 "Failed to set the flags on the destination volume %u\n", volid);
1407 * Now dump the clone to the new volume
1410 destination.destHost = ntohl(atoserver);
1411 destination.destPort = AFSCONF_VOLUMEPORT;
1412 destination.destSSID = 1;
1414 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1415 cookie.type = RWVOL;
1416 cookie.parent = entry.volumeId[RWVOL];
1419 if (!(flags & RV_NOCLONE)) {
1420 /* Copy the clone to the new volume */
1421 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1424 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1426 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1429 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1430 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1435 "Failed to end the transaction on the cloned volume %u\n",
1441 * reattach to the main-line volume, and incrementally dump it.
1444 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1445 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1447 "Failed to create a transaction on the source volume %u\n",
1451 /* now do the incremental */
1453 ("Doing the%s dump from source to destination for volume %u ... ",
1454 (flags & RV_NOCLONE) ? "" : " incremental",
1457 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1460 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1461 (flags & RV_NOCLONE) ? "" : " incremental");
1464 /* now adjust the flags so that the new volume becomes official */
1465 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1466 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1468 "Failed to set the flags to make old source volume offline\n");
1471 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1472 code = AFSVolSetFlags(toconn, totid, 0);
1474 "Failed to set the flags to make new source volume online\n");
1477 #ifdef ENABLE_BUGFIX_1165
1478 VPRINT1("Setting volume status on destination volume %u ...", volid);
1479 code = AFSVolSetInfo(toconn, totid, infop);
1481 "Failed to set volume status on the destination volume %u\n",
1486 /* put new volume online */
1487 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1488 code = AFSVolEndTrans(toconn, totid, &rcode);
1493 "Failed to end the transaction on the volume %u on the new site\n",
1497 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1498 MapNetworkToHost(&entry, &storeEntry);
1499 storeEntry.flags &= ~BACK_EXISTS;
1503 "Second test point - operation in progress but not complete.\n");
1504 fprintf(STDOUT, "...test here (y, n)? ");
1506 fscanf(stdin, "%c", &in);
1507 fscanf(stdin, "%c", &lf); /* toss away */
1509 fprintf(STDOUT, "type control-c\n");
1511 fprintf(stdout, ".");
1516 /* or drop through */
1519 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1521 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1522 (LOCKREL_OPCODE | LOCKREL_AFSID |
1523 LOCKREL_TIMESTAMP));
1526 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1527 storeEntry.name, (unsigned long)afromvol);
1536 "Third test point - operation complete but no cleanup.\n");
1537 fprintf(STDOUT, "...test here (y, n)? ");
1539 fscanf(stdin, "%c", &in);
1540 fscanf(stdin, "%c", &lf); /* toss away */
1542 fprintf(STDOUT, "type control-c\n");
1544 fprintf(stdout, ".");
1549 /* or drop through */
1552 /* This is tricky. File server is very stupid, and if you mark the volume
1553 * as VTOutOfService, it may mark the *good* instance (if you're moving
1554 * between partitions on the same machine) as out of service. Since
1555 * we're cleaning this code up in DEcorum, we're just going to kludge around
1556 * it for now by removing this call. */
1557 /* already out of service, just zap it now */
1559 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1562 "Failed to set the flags to make the old source volume offline\n");
1566 if (atoserver != afromserver) {
1567 /* set forwarding pointer for moved volumes */
1568 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1569 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1571 "Failed to set the forwarding pointer for the volume %u\n",
1576 VPRINT1("Deleting old volume %u on source ...", afromvol);
1577 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1578 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1582 VPRINT1("Ending transaction on old volume %u on the source ...",
1584 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1589 "Failed to end the transaction on the old volume %u on the source\n",
1593 /* Delete the backup volume on the original site */
1594 VPRINT1("Creating transaction for backup volume %u on source ...",
1597 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1600 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1602 AFSVolSetFlags(fromconn, fromtid,
1603 VTDeleteOnSalvage | VTOutOfService);
1605 "Failed to set the flags on the backup volume %u on the source\n",
1609 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1610 code = AFSVolDeleteVolume(fromconn, fromtid);
1612 "Failed to delete the backup volume %u on the source\n",
1616 VPRINT1("Ending transaction on backup volume %u on source ...",
1618 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1623 "Failed to end the transaction on the backup volume %u on the source\n",
1627 code = 0; /* no backup volume? that's okay */
1630 if (!(flags & RV_NOCLONE)) {
1631 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1633 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1636 "Failed to start a transaction on the cloned volume%u\n",
1640 /* now delete the clone */
1641 VPRINT1("Deleting the cloned volume %u ...", newVol);
1642 code = AFSVolDeleteVolume(fromconn, clonetid);
1643 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1647 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1648 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1653 "Failed to end the transaction on the cloned volume %u\n",
1662 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1663 fprintf(STDOUT, "...test here (y, n)? ");
1665 fscanf(stdin, "%c", &in);
1666 fscanf(stdin, "%c", &lf); /* toss away */
1668 fprintf(STDOUT, "type control-c\n");
1670 fprintf(stdout, ".");
1675 /* or drop through */
1678 /* normal cleanup code */
1680 if (entry.flags & RO_EXISTS)
1681 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1684 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1686 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1687 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1691 " Could not release the lock on the VLDB entry for the volume %lu \n",
1692 (unsigned long)afromvol);
1700 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1702 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1703 if (code || rcode) {
1706 "Could not end transaction on the source volume %lu\n",
1707 (unsigned long)afromvol);
1709 error = (code ? code : rcode);
1715 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1716 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1717 if (code || rcode) {
1720 "Could not end transaction on the source's clone volume %lu\n",
1721 (unsigned long)newVol);
1723 error = (code ? code : rcode);
1729 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1731 code = AFSVolEndTrans(toconn, totid, &rcode);
1735 "Could not end transaction on destination volume %lu\n",
1736 (unsigned long)afromvol);
1738 error = (code ? code : rcode);
1744 #ifdef ENABLE_BUGFIX_1165
1749 rx_DestroyConnection(fromconn);
1751 rx_DestroyConnection(toconn);
1752 PrintError("", error);
1755 /* come here only when the sky falls */
1760 "vos move: operation interrupted, cleanup in progress...\n");
1761 fprintf(STDOUT, "clear transaction contexts\n");
1765 /* unlock VLDB entry */
1767 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1768 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1769 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1774 VPRINT("Recovery: Ending transaction on clone volume ...");
1775 AFSVolEndTrans(fromconn, clonetid, &rcode);
1779 VPRINT("Recovery: Ending transaction on destination volume ...");
1780 AFSVolEndTrans(toconn, totid, &rcode);
1783 if (fromtid) { /* put it on-line */
1784 VPRINT("Recovery: Setting volume flags on source volume ...");
1785 AFSVolSetFlags(fromconn, fromtid, 0);
1788 VPRINT("Recovery: Ending transaction on source volume ...");
1789 AFSVolEndTrans(fromconn, fromtid, &rcode);
1793 VPRINT("Recovery: Accessing VLDB.\n");
1794 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1796 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1800 MapHostToNetwork(&entry);
1802 /* Delete either the volume on the source location or the target location.
1803 * If the vldb entry still points to the source location, then we know the
1804 * volume move didn't finish so we remove the volume from the target
1805 * location. Otherwise, we remove the volume from the source location.
1807 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1810 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1814 if (volid && toconn) {
1816 ("Recovery: Creating transaction for destination volume %u ...",
1819 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1825 ("Recovery: Setting flags on destination volume %u ...",
1827 AFSVolSetFlags(toconn, totid,
1828 VTDeleteOnSalvage | VTOutOfService);
1831 VPRINT1("Recovery: Deleting destination volume %u ...",
1833 AFSVolDeleteVolume(toconn, totid);
1837 ("Recovery: Ending transaction on destination volume %u ...",
1839 AFSVolEndTrans(toconn, totid, &rcode);
1843 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1848 /* put source volume on-line */
1850 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1853 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1858 VPRINT1("Recovery: Setting flags on source volume %u ...",
1860 AFSVolSetFlags(fromconn, fromtid, 0);
1864 ("Recovery: Ending transaction on source volume %u ...",
1866 AFSVolEndTrans(fromconn, fromtid, &rcode);
1870 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1874 } else { /* yep, move complete */
1877 "move complete - attempt cleanup of source partition - no guarantee\n");
1881 /* delete backup volume */
1883 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1886 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1891 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1893 AFSVolSetFlags(fromconn, fromtid,
1894 VTDeleteOnSalvage | VTOutOfService);
1897 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1898 AFSVolDeleteVolume(fromconn, fromtid);
1902 ("Recovery: Ending transaction on backup volume %u ...",
1904 AFSVolEndTrans(fromconn, fromtid, &rcode);
1908 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1912 /* delete source volume */
1913 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1916 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1921 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1923 AFSVolSetFlags(fromconn, fromtid,
1924 VTDeleteOnSalvage | VTOutOfService);
1927 if (atoserver != afromserver) {
1928 VPRINT("Recovery: Setting volume forwarding pointer ...");
1929 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1933 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1934 AFSVolDeleteVolume(fromconn, fromtid);
1938 ("Recovery: Ending transaction on source volume %u ...",
1940 AFSVolEndTrans(fromconn, fromtid, &rcode);
1944 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1950 /* common cleanup - delete local clone */
1952 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1955 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1960 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1961 AFSVolDeleteVolume(fromconn, clonetid);
1964 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1966 AFSVolEndTrans(fromconn, clonetid, &rcode);
1970 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1975 /* unlock VLDB entry */
1976 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
1978 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1979 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1982 done: /* routine cleanup */
1985 #ifdef ENABLE_BUGFIX_1165
1990 rx_DestroyConnection(fromconn);
1992 rx_DestroyConnection(toconn);
1995 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2003 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2004 afs_int32 atoserver, afs_int32 atopart)
2006 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2007 atoserver, atopart, 0);
2011 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2012 * <atopart>. The new volume is named by <atovolname>. The new volume
2013 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2014 * from the VLDB. the following flags are supported:
2016 * RV_RDONLY - target volume is RO
2017 * RV_OFFLINE - leave target volume offline
2018 * RV_CPINCR - do incremental dump if target exists
2019 * RV_NOVLDB - don't create/update VLDB entry
2020 * RV_NOCLONE - don't use a copy clone
2023 UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2024 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2025 afs_int32 atovolid, int flags)
2027 struct rx_connection *toconn, *fromconn;
2028 afs_int32 fromtid, totid, clonetid;
2031 afs_int32 fromDate, cloneFromDate;
2032 struct restoreCookie cookie;
2033 register afs_int32 vcode, code;
2034 afs_int32 cloneVol, newVol, volflag;
2035 struct volser_status tstatus;
2036 struct destServer destination;
2038 struct nvldbentry entry, newentry, storeEntry;
2044 fromconn = (struct rx_connection *)0;
2045 toconn = (struct rx_connection *)0;
2053 /* support control-c processing */
2056 (void)signal(SIGINT, sigint_handler);
2058 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2059 EGOTO1(mfail, vcode,
2060 "Could not fetch the entry for the volume %u from the VLDB \n",
2062 MapHostToNetwork(&entry);
2065 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2066 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2067 fromtid = totid = 0; /* initialize to uncreated */
2070 /* check if we can shortcut and use a local clone instead of a full copy */
2071 if (afromserver == atoserver && afrompart == atopart) {
2076 * clone the read/write volume locally.
2080 if (!(flags & RV_NOCLONE)) {
2081 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2082 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2084 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2088 /* Get a clone id */
2089 VPRINT1("Allocating new volume id for clone of volume %u ...",
2092 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &cloneVol);
2093 EGOTO1(mfail, vcode,
2094 "Could not get an ID for the clone of volume %u from the VLDB\n",
2102 /* Get a new volume id */
2103 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2105 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
2106 EGOTO1(mfail, vcode,
2107 "Could not get an ID for the copy of volume %u from the VLDB\n",
2112 if (!(flags & RV_NOCLONE)) {
2113 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2114 VPRINT1("Cloning source volume %u ...", afromvol);
2115 strcpy(vname, "copy-clone-temp");
2117 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2119 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2123 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2125 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2130 "Failed to end the transaction on the source volume %u\n",
2136 * Create the destination volume
2139 if (!(flags & RV_NOCLONE)) {
2140 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2142 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2145 "Failed to start a transaction on the cloned volume%u\n",
2149 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2151 AFSVolSetFlags(fromconn, clonetid,
2152 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2153 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2157 /* remember time from which we've dumped the volume */
2158 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2159 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2161 "Failed to get the status of the cloned volume %u\n",
2165 fromDate = tstatus.creationDate - CLOCKSKEW;
2170 /* create a volume on the target machine */
2172 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2174 if ((flags & RV_CPINCR)) {
2175 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2176 code = AFSVolGetStatus(toconn, totid, &tstatus);
2178 "Failed to get the status of the pre-existing volume %u\n",
2182 /* Using the update date should be OK here, but add some fudge */
2183 cloneFromDate = tstatus.updateDate - CLOCKSKEW;
2184 if ((flags & RV_NOCLONE))
2185 fromDate = cloneFromDate;
2187 /* XXX We should check that the source volume's creationDate is
2188 * XXX not newer than the existing target volume, and if not,
2189 * XXX throw away the existing target and do a full dump. */
2194 /* Delete the existing volume.
2195 * While we are deleting the volume in these steps, the transaction
2196 * we started against the cloned volume (clonetid above) will be
2197 * sitting idle. It will get cleaned up after 600 seconds
2199 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2200 code = AFSVolDeleteVolume(toconn, totid);
2202 "Could not delete the pre-existing volume %u on destination\n",
2207 ("Ending transaction on pre-existing volume %u on destination ...",
2209 code = AFSVolEndTrans(toconn, totid, &rcode);
2214 "Could not end the transaction on pre-existing volume %u on destination\n",
2219 VPRINT1("Creating the destination volume %u ...", newVol);
2221 AFSVolCreateVolume(toconn, atopart, atovolname,
2222 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2223 newVol, &newVol, &totid);
2224 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2228 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2230 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2232 "Failed to set the flags on the destination volume %u\n", newVol);
2237 destination.destHost = ntohl(atoserver);
2238 destination.destPort = AFSCONF_VOLUMEPORT;
2239 destination.destSSID = 1;
2241 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2242 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2247 * Now dump the clone to the new volume
2250 if (!(flags & RV_NOCLONE)) {
2251 /* XXX probably should have some code here that checks to see if
2252 * XXX we are copying to same server and partition - if so, just
2253 * XXX use a clone to save disk space */
2255 /* Copy the clone to the new volume */
2256 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2259 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2261 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2265 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2266 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2271 "Failed to end the transaction on the cloned volume %u\n",
2277 * reattach to the main-line volume, and incrementally dump it.
2280 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2281 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2283 "Failed to create a transaction on the source volume %u\n",
2287 /* now do the incremental */
2289 ("Doing the%s dump from source to destination for volume %u ... ",
2290 (flags & RV_NOCLONE) ? "" : " incremental",
2293 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2296 "Failed to do the%s dump from old site to new site\n",
2300 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2301 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2302 code = AFSVolSetFlags(toconn, totid, volflag);
2304 "Failed to set the flags to make destination volume online\n");
2307 /* put new volume online */
2308 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2309 code = AFSVolEndTrans(toconn, totid, &rcode);
2314 "Failed to end the transaction on the destination volume %u\n",
2318 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2319 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2324 "Failed to end the transaction on the source volume %u\n",
2330 if (!(flags & RV_NOCLONE)) {
2331 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2333 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2336 "Failed to start a transaction on the cloned volume%u\n",
2340 /* now delete the clone */
2341 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2342 code = AFSVolDeleteVolume(fromconn, clonetid);
2343 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2347 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2348 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2353 "Failed to end the transaction on the cloned volume %u\n",
2358 if (!(flags & RV_NOVLDB)) {
2359 /* create the vldb entry for the copied volume */
2360 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2361 newentry.nServers = 1;
2362 newentry.serverNumber[0] = atoserver;
2363 newentry.serverPartition[0] = atopart;
2364 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2365 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2366 newentry.volumeId[RWVOL] = newVol;
2367 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2368 newentry.volumeId[BACKVOL] = 0;
2369 newentry.cloneId = 0;
2370 /*map into right byte order, before passing to xdr, the stuff has to be in host
2371 * byte order. Xdr converts it into network order */
2372 MapNetworkToHost(&newentry, &storeEntry);
2373 /* create the vldb entry */
2374 vcode = VLDB_CreateEntry(&storeEntry);
2377 "Could not create a VLDB entry for the volume %s %lu\n",
2378 atovolname, (unsigned long)newVol);
2379 /*destroy the created volume */
2380 VPRINT1("Deleting the newly created volume %u\n", newVol);
2381 AFSVolDeleteVolume(toconn, totid);
2385 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2389 /* normal cleanup code */
2392 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2394 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2395 if (code || rcode) {
2398 "Could not end transaction on the source volume %lu\n",
2399 (unsigned long)afromvol);
2401 error = (code ? code : rcode);
2407 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2409 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2410 if (code || rcode) {
2413 "Could not end transaction on the source's clone volume %lu\n",
2414 (unsigned long)cloneVol);
2416 error = (code ? code : rcode);
2422 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2424 code = AFSVolEndTrans(toconn, totid, &rcode);
2428 "Could not end transaction on destination volume %lu\n",
2429 (unsigned long)newVol);
2431 error = (code ? code : rcode);
2436 rx_DestroyConnection(fromconn);
2438 rx_DestroyConnection(toconn);
2439 PrintError("", error);
2442 /* come here only when the sky falls */
2447 "vos copy: operation interrupted, cleanup in progress...\n");
2448 fprintf(STDOUT, "clear transaction contexts\n");
2453 VPRINT("Recovery: Ending transaction on clone volume ...");
2454 AFSVolEndTrans(fromconn, clonetid, &rcode);
2458 VPRINT("Recovery: Ending transaction on destination volume ...");
2459 AFSVolEndTrans(toconn, totid, &rcode);
2462 if (fromtid) { /* put it on-line */
2463 VPRINT("Recovery: Ending transaction on source volume ...");
2464 AFSVolEndTrans(fromconn, fromtid, &rcode);
2468 VPRINT("Recovery: Accessing VLDB.\n");
2469 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2471 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2475 MapHostToNetwork(&entry);
2477 /* common cleanup - delete local clone */
2479 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2482 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
2487 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2488 AFSVolDeleteVolume(fromconn, clonetid);
2491 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2493 AFSVolEndTrans(fromconn, clonetid, &rcode);
2497 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2502 done: /* routine cleanup */
2504 rx_DestroyConnection(fromconn);
2506 rx_DestroyConnection(toconn);
2509 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2517 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2518 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2520 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2521 atovolname, atoserver, atopart, 0, 0);
2526 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2527 * if one already exists, update it
2531 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2533 struct rx_connection *aconn = (struct rx_connection *)0;
2534 afs_int32 ttid = 0, btid = 0;
2536 afs_int32 code = 0, rcode = 0;
2537 char vname[VOLSER_MAXVOLNAME + 1];
2538 struct nvldbentry entry, storeEntry;
2539 afs_int32 error = 0;
2540 int vldblocked = 0, vldbmod = 0, backexists = 1;
2542 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2544 /* the calls to VLDB will succeed only if avolid is a RW volume,
2545 * since we are following the RW hash chain for searching */
2546 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2549 "Could not fetch the entry for the volume %lu from the VLDB \n",
2550 (unsigned long)avolid);
2554 MapHostToNetwork(&entry);
2556 /* These operations require the VLDB be locked since it means the VLDB
2557 * will change or the vldb is already locked.
2559 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2560 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2561 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2563 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2566 "Could not lock the VLDB entry for the volume %lu\n",
2567 (unsigned long)avolid);
2573 /* Reread the vldb entry */
2574 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2577 "Could not fetch the entry for the volume %lu from the VLDB \n",
2578 (unsigned long)avolid);
2582 MapHostToNetwork(&entry);
2585 if (!ISNAMEVALID(entry.name)) {
2586 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2588 error = VOLSERBADNAME;
2592 backupID = entry.volumeId[BACKVOL];
2593 if (backupID == INVALID_BID) {
2594 /* Get a backup volume id from the VLDB and update the vldb
2597 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &backupID);
2600 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2601 (unsigned long)avolid);
2605 entry.volumeId[BACKVOL] = backupID;
2609 /* Test to see if the backup volume exists by trying to create
2610 * a transaction on the backup volume. We've assumed the backup exists.
2612 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2614 if (code != VNOVOL) {
2615 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2616 (unsigned long)backupID);
2620 backexists = 0; /* backup volume does not exist */
2623 code = AFSVolEndTrans(aconn, btid, &rcode);
2625 if (code || rcode) {
2627 "Could not end transaction on the previous backup volume %lu\n",
2628 (unsigned long)backupID);
2629 error = (code ? code : rcode);
2634 /* Now go ahead and try to clone the RW volume.
2635 * First start a transaction on the RW volume
2637 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2639 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2640 (unsigned long)avolid);
2645 /* Clone or reclone the volume, depending on whether the backup
2646 * volume exists or not
2649 VPRINT1("Re-cloning backup volume %u ...", backupID);
2651 code = AFSVolReClone(aconn, ttid, backupID);
2653 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2654 (unsigned long)backupID);
2659 VPRINT1("Creating a new backup clone %u ...", backupID);
2661 strcpy(vname, entry.name);
2662 strcat(vname, ".backup");
2664 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2666 fprintf(STDERR, "Failed to clone the volume %lu\n",
2667 (unsigned long)avolid);
2673 /* End the transaction on the RW volume */
2674 code = AFSVolEndTrans(aconn, ttid, &rcode);
2676 if (code || rcode) {
2678 "Failed to end the transaction on the rw volume %lu\n",
2679 (unsigned long)avolid);
2680 error = (code ? code : rcode);
2684 /* Mork vldb as backup exists */
2685 if (!(entry.flags & BACK_EXISTS)) {
2686 entry.flags |= BACK_EXISTS;
2690 /* Now go back to the backup volume and bring it on line */
2691 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2694 "Failed to start a transaction on the backup volume %lu\n",
2695 (unsigned long)backupID);
2700 code = AFSVolSetFlags(aconn, btid, 0);
2702 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2703 (unsigned long)backupID);
2708 code = AFSVolEndTrans(aconn, btid, &rcode);
2710 if (code || rcode) {
2712 "Failed to end the transaction on the backup volume %lu\n",
2713 (unsigned long)backupID);
2714 error = (code ? code : rcode);
2720 /* Will update the vldb below */
2724 code = AFSVolEndTrans(aconn, ttid, &rcode);
2725 if (code || rcode) {
2726 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2727 (unsigned long)avolid);
2729 error = (code ? code : rcode);
2734 code = AFSVolEndTrans(aconn, btid, &rcode);
2735 if (code || rcode) {
2737 "Could not end transaction the backup volume %lu\n",
2738 (unsigned long)backupID);
2740 error = (code ? code : rcode);
2744 /* Now update the vldb - if modified */
2747 MapNetworkToHost(&entry, &storeEntry);
2749 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2750 (LOCKREL_OPCODE | LOCKREL_AFSID |
2751 LOCKREL_TIMESTAMP));
2754 "Could not update the VLDB entry for the volume %lu \n",
2755 (unsigned long)avolid);
2761 ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, RWVOL,
2762 (LOCKREL_OPCODE | LOCKREL_AFSID |
2763 LOCKREL_TIMESTAMP));
2766 "Could not unlock the VLDB entry for the volume %lu \n",
2767 (unsigned long)avolid);
2775 rx_DestroyConnection(aconn);
2777 PrintError("", error);
2781 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2782 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2783 * The new volume is named by <aname>, or by appending ".clone" to
2784 * the existing name if <aname> is NULL. The following flags are
2787 * RV_RDONLY - target volume is RO
2788 * RV_OFFLINE - leave target volume offline
2792 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
2793 afs_int32 acloneid, char *aname, int flags)
2795 struct rx_connection *aconn = (struct rx_connection *)0;
2796 afs_int32 ttid = 0, btid = 0;
2797 afs_int32 code = 0, rcode = 0;
2798 char vname[VOLSER_MAXVOLNAME + 1];
2799 afs_int32 error = 0;
2801 volEntries volumeInfo;
2803 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2806 volumeInfo.volEntries_val = (volintInfo *) 0;
2807 volumeInfo.volEntries_len = 0;
2808 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2810 fprintf(stderr, "Could not get info for volume %lu\n",
2811 (unsigned long)avolid);
2815 strncpy(vname, volumeInfo.volEntries_val[0].name,
2816 VOLSER_OLDMAXVOLNAME - 7);
2817 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2818 strcat(vname, ".clone");
2820 if (volumeInfo.volEntries_val)
2821 free(volumeInfo.volEntries_val);
2825 /* Get a clone id */
2826 VPRINT1("Allocating new volume id for clone of volume %u ...",
2828 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &acloneid);
2830 "Could not get an ID for the clone of volume %u from the VLDB\n",
2835 /* Test to see if the clone volume exists by trying to create
2836 * a transaction on the clone volume. We've assumed the clone exists.
2838 /* XXX I wonder what happens if the clone has some other parent... */
2839 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2841 if (code != VNOVOL) {
2842 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2843 (unsigned long)acloneid);
2847 backexists = 0; /* backup volume does not exist */
2850 code = AFSVolEndTrans(aconn, btid, &rcode);
2852 if (code || rcode) {
2854 "Could not end transaction on the previous clone volume %lu\n",
2855 (unsigned long)acloneid);
2856 error = (code ? code : rcode);
2861 /* Now go ahead and try to clone the RW volume.
2862 * First start a transaction on the RW volume
2864 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2866 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2867 (unsigned long)avolid);
2872 /* Clone or reclone the volume, depending on whether the backup
2873 * volume exists or not
2876 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2878 code = AFSVolReClone(aconn, ttid, acloneid);
2880 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2881 (unsigned long)acloneid);
2886 VPRINT1("Creating a new clone %u ...", acloneid);
2888 code = AFSVolClone(aconn, ttid, 0,
2889 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2892 fprintf(STDERR, "Failed to clone the volume %lu\n",
2893 (unsigned long)avolid);
2899 /* End the transaction on the RW volume */
2900 code = AFSVolEndTrans(aconn, ttid, &rcode);
2902 if (code || rcode) {
2904 "Failed to end the transaction on the rw volume %lu\n",
2905 (unsigned long)avolid);
2906 error = (code ? code : rcode);
2910 /* Now go back to the backup volume and bring it on line */
2911 if (!(flags & RV_OFFLINE)) {
2912 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2915 "Failed to start a transaction on the clone volume %lu\n",
2916 (unsigned long)acloneid);
2921 code = AFSVolSetFlags(aconn, btid, 0);
2923 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2924 (unsigned long)acloneid);
2929 code = AFSVolEndTrans(aconn, btid, &rcode);
2931 if (code || rcode) {
2933 "Failed to end the transaction on the clone volume %lu\n",
2934 (unsigned long)acloneid);
2935 error = (code ? code : rcode);
2944 code = AFSVolEndTrans(aconn, ttid, &rcode);
2945 if (code || rcode) {
2946 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2947 (unsigned long)avolid);
2949 error = (code ? code : rcode);
2954 code = AFSVolEndTrans(aconn, btid, &rcode);
2955 if (code || rcode) {
2957 "Could not end transaction on the clone volume %lu\n",
2958 (unsigned long)acloneid);
2960 error = (code ? code : rcode);
2965 rx_DestroyConnection(aconn);
2967 PrintError("", error);
2972 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2975 afs_int32 acode, ccode, rcode, tid;
2976 ccode = rcode = tid = 0;
2978 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2979 if (!acode) { /* It really was there */
2980 acode = AFSVolDeleteVolume(conn, tid);
2982 fprintf(STDERR, "Failed to delete volume %lu.\n",
2983 (unsigned long)vid);
2984 PrintError("", acode);
2986 ccode = AFSVolEndTrans(conn, tid, &rcode);
2990 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
2991 (unsigned long)vid);
2992 PrintError("", ccode);
2999 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3000 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3002 /* Get a "transaction" on this replica. Create the volume
3003 * if necessary. Return the time from which a dump should
3004 * be made (0 if it's a new volume)
3007 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3008 struct rx_connection **connPtr, afs_int32 * transPtr,
3009 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3012 struct volser_status tstatus;
3013 int code, rcode, tcode;
3015 *connPtr = (struct rx_connection *)0;
3020 /* get connection to the replication site */
3021 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3023 goto fail; /* server is down */
3025 volid = vldbEntryPtr->volumeId[ROVOL];
3028 AFSVolTransCreate(*connPtr, volid,
3029 vldbEntryPtr->serverPartition[index], ITOffline,
3032 /* If the volume does not exist, create it */
3033 if (!volid || code) {
3036 if (volid && (code != VNOVOL)) {
3037 PrintError("Failed to start a transaction on the RO volume.\n",
3042 strcpy(volname, vldbEntryPtr->name);
3043 strcat(volname, ".readonly");
3047 "Creating new volume %lu on replication site %s: ",
3048 (unsigned long)volid,
3049 hostutil_GetNameByINet(vldbEntryPtr->
3050 serverNumber[index]));
3055 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3057 vldbEntryPtr->volumeId[RWVOL], &volid,
3060 PrintError("Failed to create the ro volume: ", code);
3063 vldbEntryPtr->volumeId[ROVOL] = volid;
3067 /* The following is a bit redundant, since create sets these flags by default */
3069 AFSVolSetFlags(*connPtr, *transPtr,
3070 VTDeleteOnSalvage | VTOutOfService);
3072 PrintError("Failed to set flags on the ro volume: ", code);
3077 /* Otherwise, the transaction did succeed, so get the creation date of the
3078 * latest RO volume on the replication site
3081 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3082 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3084 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3086 PrintError("Failed to get status of volume on destination: ",
3090 *crtimePtr = tstatus.creationDate - CLOCKSKEW;
3091 *uptimePtr = tstatus.updateDate - CLOCKSKEW;
3098 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3103 PrintError("Could not end transaction on a ro volume: ", tcode);
3110 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3111 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3112 void *cookie, manyResults * results)
3116 for (i = 0; i < tr->manyDests_len; i++) {
3117 results->manyResults_val[i] =
3118 AFSVolForward(fromconn, fromtid, fromdate,
3119 &(tr->manyDests_val[i].server),
3120 tr->manyDests_val[i].trans, cookie);
3126 /* UV_ReleaseVolume()
3127 * Release volume <afromvol> on <afromserver> <afrompart> to all
3128 * its RO sites (full release). Unless the previous release was
3129 * incomplete: in which case we bring the remaining incomplete
3130 * volumes up to date with the volumes that were released
3132 * forceflag: Performs a full release.
3134 * Will create a clone from the RW, then dump the clone out to
3135 * the remaining replicas. If there is more than 1 RO sites,
3136 * ensure that the VLDB says at least one RO is available all
3137 * the time: Influences when we write back the VLDB entry.
3141 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
3142 afs_int32 afrompart, int forceflag)
3145 afs_int32 code, vcode, rcode, tcode;
3146 afs_int32 cloneVolId, roVolId;
3147 struct replica *replicas = 0;
3148 struct nvldbentry entry, storeEntry;
3149 int i, volcount, m, fullrelease, vldbindex;
3151 struct restoreCookie cookie;
3152 struct rx_connection **toconns = 0;
3153 struct release *times = 0;
3155 struct rx_connection *fromconn = (struct rx_connection *)0;
3156 afs_int32 error = 0;
3158 afs_int32 clonetid = 0, onlinetid;
3159 afs_int32 fromtid = 0;
3160 afs_uint32 fromdate, thisdate;
3163 manyResults results;
3164 int rwindex, roindex, roclone, roexists;
3165 afs_int32 rwcrdate, rwupdate, clcrdate;
3169 } remembertime[NMAXNSERVERS];
3170 int releasecount = 0;
3171 struct volser_status volstatus;
3173 memset((char *)remembertime, 0, sizeof(remembertime));
3174 memset((char *)&results, 0, sizeof(results));
3176 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3177 if (vcode != VL_RERELEASE)
3178 ONERROR(vcode, afromvol,
3179 "Could not lock the VLDB entry for the volume %u.\n");
3182 /* Get the vldb entry in readable format */
3183 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3184 ONERROR(vcode, afromvol,
3185 "Could not fetch the entry for the volume %u from the VLDB.\n");
3186 MapHostToNetwork(&entry);
3189 EnumerateEntry(&entry);
3191 if (!ISNAMEVALID(entry.name))
3192 ONERROR(VOLSERBADOP, entry.name,
3193 "Volume name %s is too long, rename before releasing.\n");
3194 if (entry.volumeId[RWVOL] != afromvol)
3195 ONERROR(VOLSERBADOP, afromvol,
3196 "The volume %u being released is not a read-write volume.\n");
3197 if (entry.nServers <= 1)
3198 ONERROR(VOLSERBADOP, afromvol,
3199 "Volume %u has no replicas - release operation is meaningless!\n");
3200 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3201 ONERROR(VOLSERBADOP, entry.name,
3202 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3204 /* roclone is true if one of the RO volumes is on the same
3205 * partition as the RW volume. In this case, we make the RO volume
3206 * on the same partition a clone instead of a complete copy.
3209 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3210 roclone = ((roindex == -1) ? 0 : 1);
3211 rwindex = Lp_GetRwIndex(&entry);
3213 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3215 /* Make sure we have a RO volume id to work with */
3216 if (entry.volumeId[ROVOL] == INVALID_BID) {
3217 /* need to get a new RO volume id */
3218 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &roVolId);
3219 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3221 entry.volumeId[ROVOL] = roVolId;
3222 MapNetworkToHost(&entry, &storeEntry);
3223 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3224 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3227 /* Will we be completing a previously unfinished release. -force overrides */
3228 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3229 if (entry.serverFlags[i] & ITSROVOL) {
3231 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3234 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3237 /* Determine which volume id to use and see if it exists */
3240 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3241 code = VolumeExists(afromserver, afrompart, cloneVolId);
3242 roexists = ((code == ENODEV) ? 0 : 1);
3244 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3246 ONERROR(-1, afromserver,
3247 "Cannot establish connection with server 0x%x\n");
3251 fullrelease = 1; /* Do a full release if RO clone does not exist */
3253 /* Begin transaction on RW and mark it busy while we query it */
3254 code = AFSVolTransCreate(
3255 fromconn, afromvol, afrompart, ITBusy, &fromtid
3257 ONERROR(code, afromvol,
3258 "Failed to start transaction on RW volume %u\n");
3260 /* Query the creation date for the RW */
3261 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3262 ONERROR(code, afromvol,
3263 "Failed to get the status of RW volume %u\n");
3264 rwcrdate = volstatus.creationDate;
3265 rwupdate = volstatus.updateDate;
3267 /* End transaction on RW */
3268 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3270 ONERROR((code ? code : rcode), afromvol,
3271 "Failed to end transaction on RW volume %u\n");
3273 /* Begin transaction on clone and mark it busy while we query it */
3274 code = AFSVolTransCreate(
3275 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3277 ONERROR(code, cloneVolId,
3278 "Failed to start transaction on RW clone %u\n");
3280 /* Query the creation date for the clone */
3281 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3282 ONERROR(code, cloneVolId,
3283 "Failed to get the status of RW clone %u\n");
3284 clcrdate = volstatus.creationDate;
3286 /* End transaction on clone */
3287 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3289 ONERROR((code ? code : rcode), cloneVolId,
3290 "Failed to end transaction on RW clone %u\n");
3292 if (rwcrdate > clcrdate)
3293 fullrelease = 2;/* Do a full release if RO clone older than RW */
3298 switch (fullrelease) {
3300 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3301 (unsigned long)afromvol);
3304 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3305 (unsigned long)afromvol);
3308 fprintf(STDOUT, "This is a completion of a previous release\n");
3314 /* If the RO clone exists, then if the clone is a temporary
3315 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3316 * (it was recently added), then also delete it. We do not
3317 * want to "reclone" a temporary RO clone.
3320 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3321 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3322 if (code && (code != VNOVOL))
3327 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3328 * write this entry out to the vlserver until after the first
3329 * RO volume is released (temp RO clones don't count).
3331 for (i = 0; i < entry.nServers; i++) {
3332 entry.serverFlags[i] &= ~NEW_REPSITE;
3333 entry.serverFlags[i] |= RO_DONTUSE;
3335 entry.serverFlags[rwindex] |= NEW_REPSITE;
3336 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3338 /* Begin transaction on RW and mark it busy while we clone it */
3340 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3342 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3344 /* Clone or reclone the volume */
3346 VPRINT1("Recloning RW volume %u...", cloneVolId);
3347 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3348 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3352 strcpy(vname, entry.name);
3353 strcat(vname, ".readonly");
3354 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3356 strcpy(vname, "readonly-clone-temp");
3357 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3360 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3362 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3366 /* Get the time the RW was created for future information */
3367 VPRINT1("Getting status of RW volume %u...", afromvol);
3368 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3369 ONERROR(code, afromvol,
3370 "Failed to get the status of the RW volume %u\n");
3372 rwcrdate = volstatus.creationDate;
3373 rwupdate = volstatus.updateDate;
3375 /* End the transaction on the RW volume */
3376 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3377 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3379 ONERROR((code ? code : rcode), afromvol,
3380 "Failed to end cloning transaction on RW %u\n");
3383 /* Remember clone volume ID in case we fail or are interrupted */
3384 entry.cloneId = cloneVolId;
3387 /* Bring the RO clone online - though not if it's a temporary clone */
3388 VPRINT1("Starting transaction on RO clone volume %u...",
3391 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3393 ONERROR(code, cloneVolId,
3394 "Failed to start transaction on volume %u\n");
3397 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3398 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3401 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3402 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3403 ONERROR((code ? code : rcode), cloneVolId,
3404 "Failed to end transaction on RO clone %u\n");
3407 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3409 /* Sleep so that a client searching for an online volume won't
3410 * find the clone offline and then the next RO offline while the
3411 * release brings the clone online and the next RO offline (race).
3412 * There is a fix in the 3.4 client that does not need this sleep
3413 * anymore, but we don't know what clients we have.
3415 if (entry.nServers > 2)
3418 /* Mark the RO clone in the VLDB as a good site (already released) */
3419 entry.serverFlags[roindex] |= NEW_REPSITE;
3420 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3421 entry.flags |= RO_EXISTS;
3425 /* Write out the VLDB entry only if the clone is not a temporary
3426 * clone. If we did this to a temporary clone then we would end
3427 * up marking all the ROs as "old release" making the ROs
3428 * temporarily unavailable.
3430 MapNetworkToHost(&entry, &storeEntry);
3431 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3432 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3433 ONERROR(vcode, entry.name,
3434 "Could not update vldb entry for %s.\n");
3439 /* Now we will release from the clone to the remaining RO replicas.
3440 * The first 2 ROs (counting the non-temporary RO clone) are released
3441 * individually: releasecount. This is to reduce the race condition
3442 * of clients trying to find an on-line RO volume. The remaining ROs
3443 * are released in parallel but no more than half the number of ROs
3444 * (rounded up) at a time: nservers.
3447 strcpy(vname, entry.name);
3448 strcat(vname, ".readonly");
3449 memset(&cookie, 0, sizeof(cookie));
3450 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3451 cookie.type = ROVOL;
3452 cookie.parent = entry.volumeId[RWVOL];
3455 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3457 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3458 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3460 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3462 results.manyResults_val =
3463 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3464 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3466 "Failed to create transaction on the release clone\n");
3468 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3469 memset(times, 0, (sizeof(struct release) * nservers + 1));
3470 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3471 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3473 /* Create a transaction on the cloned volume */
3474 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3476 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3477 if (!fullrelease && code)
3478 ONERROR(VOLSERNOVOL, afromvol,
3479 "Old clone is inaccessible. Try vos release -f %u.\n");
3480 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3483 /* For each index in the VLDB */
3484 for (vldbindex = 0; vldbindex < entry.nServers;) {
3486 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3488 ((volcount < nservers) && (vldbindex < entry.nServers));
3490 /* The first two RO volumes will be released individually.
3491 * The rest are then released in parallel. This is a hack
3492 * for clients not recognizing right away when a RO volume
3493 * comes back on-line.
3495 if ((volcount == 1) && (releasecount < 2))
3498 if (vldbindex == roindex)
3499 continue; /* the clone */
3500 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3501 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3503 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3504 continue; /* not a RO vol */
3507 /* Get a Transaction on this replica. Get a new connection if
3508 * necessary. Create the volume if necessary. Return the
3509 * time from which the dump should be made (0 if it's a new
3510 * volume). Each volume might have a different time.
3512 replicas[volcount].server.destHost =
3513 ntohl(entry.serverNumber[vldbindex]);
3514 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3515 replicas[volcount].server.destSSID = 1;
3516 times[volcount].vldbEntryIndex = vldbindex;
3519 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3520 &(replicas[volcount].trans),
3521 &(times[volcount].crtime),
3522 &(times[volcount].uptime));
3526 /* Thisdate is the date from which we want to pick up all changes */
3527 if (forceflag || !fullrelease
3528 || (rwcrdate > times[volcount].crtime)) {
3529 /* If the forceflag is set, then we want to do a full dump.
3530 * If it's not a full release, we can't be sure that the creation
3531 * date is good (so we also do a full dump).
3532 * If the RW volume was replaced (its creation date is newer than
3533 * the last release), then we can't be sure what has changed (so
3534 * we do a full dump).
3537 } else if (remembertime[vldbindex].validtime) {
3538 /* Trans was prev ended. Use the time from the prev trans
3539 * because, prev trans may have created the volume. In which
3540 * case time[volcount].time would be now instead of 0.
3543 (remembertime[vldbindex].uptime < times[volcount].uptime)
3544 ? remembertime[vldbindex].uptime
3545 : times[volcount].uptime;
3547 thisdate = times[volcount].uptime;
3549 remembertime[vldbindex].validtime = 1;
3550 remembertime[vldbindex].uptime = thisdate;
3552 if (volcount == 0) {
3553 fromdate = thisdate;
3555 /* Include this volume if it is within 15 minutes of the earliest */
3557 thisdate) ? (fromdate - thisdate) : (thisdate -
3559 AFSVolEndTrans(toconns[volcount],
3560 replicas[volcount].trans, &rcode);
3561 replicas[volcount].trans = 0;
3564 if (thisdate < fromdate)
3565 fromdate = thisdate;
3573 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3574 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3575 hostutil_GetNameByINet(entry.
3576 serverNumber[times[0].
3579 for (s = 1; s < volcount; s++) {
3580 fprintf(STDOUT, " and %s",
3581 hostutil_GetNameByINet(entry.
3582 serverNumber[times[s].
3587 fprintf(STDOUT, " (full release)");
3589 fprintf(STDOUT, " (as of %.24s)", ctime((time_t *)&fromdate));
3590 fprintf(STDOUT, ".\n");
3594 /* Release the ones we have collected */
3595 tr.manyDests_val = &(replicas[0]);
3596 tr.manyDests_len = results.manyResults_len = volcount;
3598 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3599 0 /*spare */ , &cookie, &results);
3600 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3602 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3603 0 /*spare */ , &cookie, &results);
3608 PrintError("Release failed: ", code);
3610 for (m = 0; m < volcount; m++) {
3611 if (results.manyResults_val[m]) {
3612 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3613 /* we retry timed out transaction. When it is
3614 * not the first volume and the transaction wasn't found
3615 * (assume it timed out and was garbage collected by volser).
3618 ("Failed to dump volume from clone to a ro site: ",
3619 results.manyResults_val[m]);
3625 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3626 ROVOL, entry.volumeId[RWVOL], 0, 0);
3628 if ((m == 0) || (code != ENOENT)) {
3629 PrintError("Failed to set correct names and ids: ",
3635 /* have to clear dest. flags to ensure new vol goes online:
3636 * because the restore (forwarded) operation copied
3637 * the V_inService(=0) flag over to the destination.
3639 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3641 if ((m == 0) || (code != ENOENT)) {
3642 PrintError("Failed to set flags on ro volume: ",
3648 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3649 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3650 entry.flags |= RO_EXISTS;
3655 /* End the transactions and destroy the connections */
3656 for (s = 0; s < volcount; s++) {
3657 if (replicas[s].trans)
3658 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3659 replicas[s].trans = 0;
3663 if ((s == 0) || (code != ENOENT)) {
3664 PrintError("Could not end transaction on a ro volume: ",
3668 ("Transaction timed out on a ro volume. Will retry.\n",
3670 if (times[s].vldbEntryIndex < vldbindex)
3671 vldbindex = times[s].vldbEntryIndex;
3676 rx_DestroyConnection(toconns[s]);
3680 MapNetworkToHost(&entry, &storeEntry);
3681 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3682 ONERROR(vcode, afromvol,
3683 " Could not update VLDB entry for volume %u\n");
3684 } /* for each index in the vldb */
3686 /* End the transaction on the cloned volume */
3687 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3692 PrintError("Failed to end transaction on rw volume: ", code);
3694 /* Figure out if any volume were not released and say so */
3695 for (failure = 0, i = 0; i < entry.nServers; i++) {
3696 if (!(entry.serverFlags[i] & NEW_REPSITE))
3702 "The volume %lu could not be released to the following %d sites:\n",
3703 (unsigned long)afromvol, failure);
3704 for (i = 0; i < entry.nServers; i++) {
3705 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3706 MapPartIdIntoName(entry.serverPartition[i], pname);
3707 fprintf(STDERR, "\t%35s %s\n",
3708 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3712 MapNetworkToHost(&entry, &storeEntry);
3714 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3716 ONERROR(vcode, afromvol,
3717 " Could not update VLDB entry for volume %u\n");
3719 ERROREXIT(VOLSERBADRELEASE);
3722 /* All the ROs were release successfully. Remove the temporary clone */
3725 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3726 (unsigned long)cloneVolId);
3729 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3730 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3735 for (i = 0; i < entry.nServers; i++)
3736 entry.serverFlags[i] &= ~NEW_REPSITE;
3738 /* Update the VLDB */
3739 VPRINT("updating VLDB ...");
3741 MapNetworkToHost(&entry, &storeEntry);
3743 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3744 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3745 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3750 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3754 "Failed to end cloning transaction on the RW volume %lu\n",
3755 (unsigned long)afromvol);
3761 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3765 "Failed to end transaction on the release clone %lu\n",
3766 (unsigned long)cloneVolId);
3771 for (i = 0; i < nservers; i++) {
3772 if (replicas && replicas[i].trans) {
3773 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3774 replicas[i].trans = 0;
3777 "Failed to end transaction on ro volume %u at server %s\n",
3778 entry.volumeId[ROVOL],
3779 hostutil_GetNameByINet(htonl
3780 (replicas[i].server.
3786 if (toconns && toconns[i]) {
3787 rx_DestroyConnection(toconns[i]);
3793 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, RWVOL,
3794 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3797 "Could not release lock on the VLDB entry for volume %lu\n",
3798 (unsigned long)afromvol);
3804 PrintError("", error);
3807 rx_DestroyConnection(fromconn);
3808 if (results.manyResults_val)
3809 free(results.manyResults_val);
3821 dump_sig_handler(int x)
3823 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3827 /* Dump the volume <afromvol> on <afromserver> and
3828 * <afrompart> to <afilename> starting from <fromdate>.
3829 * DumpFunction does the real work behind the scenes after
3830 * extracting parameters from the rock
3833 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3834 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock)
3836 struct rx_connection *fromconn = (struct rx_connection *)0;
3837 struct rx_call *fromcall = (struct rx_call *)0;
3838 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3839 afs_int32 code, error = 0;
3843 #ifndef AFS_NT40_ENV
3844 (void)signal(SIGPIPE, dump_sig_handler);
3846 (void)signal(SIGINT, dump_sig_handler);
3849 VPRINT("Full Dump ...\n");
3851 VPRINT1("Incremental Dump (as of %.24s)...\n",
3852 ctime((time_t *) & fromdate));
3855 /* get connections to the servers */
3856 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3858 VPRINT1("Starting transaction on volume %u...", afromvol);
3859 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3860 EGOTO1(error_exit, code,
3861 "Could not start transaction on the volume %u to be dumped\n",
3865 fromcall = rx_NewCall(fromconn);
3867 VPRINT1("Starting volume dump on volume %u...", afromvol);
3868 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3869 EGOTO(error_exit, code, "Could not start the dump process \n");
3872 VPRINT1("Dumping volume %u...", afromvol);
3873 code = DumpFunction(fromcall, rock);
3874 EGOTO(error_exit, code, "Error while dumping volume \n");
3879 code = rx_EndCall(fromcall, rxError);
3881 fprintf(STDERR, "Error in rx_EndCall\n");
3887 VPRINT1("Ending transaction on volume %u...", afromvol);
3888 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3889 if (code || rcode) {
3890 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3891 (unsigned long)afromvol);
3893 error = (code ? code : rcode);
3898 rx_DestroyConnection(fromconn);
3900 PrintError("", error);
3904 /* Clone the volume <afromvol> on <afromserver> and
3905 * <afrompart>, and then dump the clone volume to
3906 * <afilename> starting from <fromdate>.
3907 * DumpFunction does the real work behind the scenes after
3908 * extracting parameters from the rock
3911 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3912 afs_int32 afrompart, afs_int32 fromdate,
3913 afs_int32(*DumpFunction) (), char *rock)
3915 struct rx_connection *fromconn = (struct rx_connection *)0;
3916 struct rx_call *fromcall = (struct rx_call *)0;
3917 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3918 afs_int32 clonetid = 0;
3919 afs_int32 code = 0, vcode = 0, error = 0;
3920 afs_int32 clonevol = 0;
3925 #ifndef AFS_NT40_ENV
3926 (void)signal(SIGPIPE, dump_sig_handler);
3928 (void)signal(SIGINT, dump_sig_handler);
3931 VPRINT("Full Dump ...\n");
3933 VPRINT1("Incremental Dump (as of %.24s)...\n",
3934 ctime((time_t *) & fromdate));
3937 /* get connections to the servers */
3938 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3940 VPRINT1("Starting transaction on volume %u...", afromvol);
3941 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3942 EGOTO1(error_exit, code,
3943 "Could not start transaction on the volume %u to be dumped\n",
3947 /* Get a clone id */
3948 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3949 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &clonevol);
3950 EGOTO1(error_exit, code,
3951 "Could not get an ID for the clone of volume %u from the VLDB\n",
3955 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3956 VPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3958 strcpy(vname, "dump-clone-temp");
3960 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3961 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3965 VPRINT1("Ending the transaction on the volume %u ...", afromvol);
3967 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3971 EGOTO1(error_exit, code,
3972 "Failed to end the transaction on the volume %u\n", afromvol);
3976 VPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
3978 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
3980 EGOTO1(error_exit, code,
3981 "Failed to start a transaction on the cloned volume%u\n",
3985 VPRINT1("Setting flags on cloned volume %u ...", clonevol);
3986 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
3987 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
3992 fromcall = rx_NewCall(fromconn);
3994 VPRINT1("Starting volume dump from cloned volume %u...", clonevol);
3995 code = StartAFSVolDump(fromcall, clonetid, fromdate);
3996 EGOTO(error_exit, code, "Could not start the dump process \n");
3999 VPRINT1("Dumping volume %u...", afromvol);
4000 code = DumpFunction(fromcall, rock);
4001 EGOTO(error_exit, code, "Error while dumping volume \n");
4005 /* now delete the clone */
4006 VPRINT1("Deleting the cloned volume %u ...", clonevol);
4007 code = AFSVolDeleteVolume(fromconn, clonetid);
4009 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4010 (unsigned long)clonevol);
4016 code = rx_EndCall(fromcall, rxError);
4018 fprintf(STDERR, "Error in rx_EndCall\n");
4024 VPRINT1("Ending transaction on cloned volume %u...", clonevol);
4025 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4026 if (code || rcode) {
4028 "Could not end transaction on the cloned volume %lu\n",
4029 (unsigned long)clonevol);
4031 error = (code ? code : rcode);
4036 rx_DestroyConnection(fromconn);
4038 PrintError("", error);
4045 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4046 * the dump file <afilename>. WriteData does all the real work
4047 * after extracting params from the rock
4050 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4051 afs_int32 toparentid, char tovolname[], int flags,
4052 afs_int32(*WriteData) (), char *rock)
4054 struct rx_connection *toconn, *tempconn;
4055 struct rx_call *tocall;
4056 afs_int32 totid, code, rcode, vcode, terror = 0;
4057 afs_int32 rxError = 0;
4058 struct volser_status tstatus;
4059 struct volintInfo vinfo;
4061 afs_int32 pvolid, pparentid;
4064 struct nvldbentry entry, storeEntry;
4067 struct restoreCookie cookie;
4069 afs_int32 volflag, voltype, volsertype;
4070 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4071 int index, same, errcode;
4075 memset(&cookie, 0, sizeof(cookie));
4080 tocall = (struct rx_call *)0;
4081 toconn = (struct rx_connection *)0;
4082 tempconn = (struct rx_connection *)0;
4086 if (flags & RV_RDONLY) {
4088 volsertype = volser_RO;
4091 volsertype = volser_RW;
4095 pparentid = toparentid;
4096 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4097 if (pvolid == 0) { /*alot a new id if needed */
4098 vcode = VLDB_GetEntryByName(tovolname, &entry);
4099 if (vcode == VL_NOENT) {
4100 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &pvolid);
4102 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4108 } else if (flags & RV_RDONLY) {
4109 if (entry.flags & RW_EXISTS) {
4111 "Entry for ReadWrite volume %s already exists!\n",
4113 error = VOLSERBADOP;
4116 if (!entry.volumeId[ROVOL]) {
4118 "Existing entry for volume %s has no ReadOnly ID\n",
4120 error = VOLSERBADOP;
4123 pvolid = entry.volumeId[ROVOL];
4124 pparentid = entry.volumeId[RWVOL];
4126 pvolid = entry.volumeId[RWVOL];
4127 pparentid = entry.volumeId[RWVOL];
4130 if (!pparentid) pparentid = pvolid;
4131 /* at this point we have a volume id to use/reuse for the volume to be restored */
4132 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4133 EGOTO1(refail, VOLSERBADOP,
4134 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4137 MapPartIdIntoName(topart, partName);
4138 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4139 tovolname, (unsigned long)pvolid,
4140 hostutil_GetNameByINet(toserver), partName);
4143 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid, &pvolid,
4146 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4147 VPRINT1("Deleting the previous volume %u ...", pvolid);
4150 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4151 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4154 code = AFSVolGetStatus(toconn, totid, &tstatus);
4155 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4158 oldCreateDate = tstatus.creationDate;
4159 oldUpdateDate = tstatus.updateDate;
4162 AFSVolSetFlags(toconn, totid,
4163 VTDeleteOnSalvage | VTOutOfService);
4164 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4167 code = AFSVolDeleteVolume(toconn, totid);
4168 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4170 code = AFSVolEndTrans(toconn, totid, &rcode);
4174 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4179 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid,
4181 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4184 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4185 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4188 code = AFSVolGetStatus(toconn, totid, &tstatus);
4189 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4192 oldCreateDate = tstatus.creationDate;
4193 oldUpdateDate = tstatus.updateDate;
4200 cookie.parent = pparentid;
4201 cookie.type = voltype;
4203 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
4205 tocall = rx_NewCall(toconn);
4206 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4208 fprintf(STDERR, "Volume restore Failed \n");
4212 code = WriteData(tocall, rock);
4214 fprintf(STDERR, "Could not transmit data\n");
4218 terror = rx_EndCall(tocall, rxError);
4219 tocall = (struct rx_call *)0;
4221 fprintf(STDERR, "rx_EndCall Failed \n");
4225 code = AFSVolGetStatus(toconn, totid, &tstatus);
4228 "Could not get status information about the volume %lu\n",
4229 (unsigned long)pvolid);
4233 code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pparentid, 0, 0);
4235 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4236 (unsigned long)pvolid);
4241 if (flags & RV_CRDUMP)
4242 newCreateDate = tstatus.creationDate;
4243 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4244 newCreateDate = oldCreateDate;
4246 newCreateDate = time(0);
4247 if (flags & RV_LUDUMP)
4248 newUpdateDate = tstatus.updateDate;
4249 else if (flags & RV_LUKEEP)
4250 newUpdateDate = oldUpdateDate;
4252 newUpdateDate = time(0);
4253 code = AFSVolSetDate(toconn,totid, newCreateDate);
4255 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4260 init_volintInfo(&vinfo);
4261 vinfo.creationDate = newCreateDate;
4262 vinfo.updateDate = newUpdateDate;
4263 code = AFSVolSetInfo(toconn, totid, &vinfo);
4265 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4271 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4272 code = AFSVolSetFlags(toconn, totid, volflag);
4274 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4279 /* It isn't handled right in refail */
4280 code = AFSVolEndTrans(toconn, totid, &rcode);
4285 fprintf(STDERR, "Could not end transaction on %lu\n",
4286 (unsigned long)pvolid);
4292 fprintf(STDOUT, " done\n");
4294 if (success && (!reuseID || (flags & RV_FULLRST))) {
4295 /* Volume was restored on the file server, update the
4296 * VLDB to reflect the change.
4298 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4299 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4301 "Could not fetch the entry for volume number %lu from VLDB \n",
4302 (unsigned long)pvolid);
4307 MapHostToNetwork(&entry);
4308 if (vcode == VL_NOENT) { /* it doesnot exist already */
4309 /*make the vldb return this indication specifically */
4310 VPRINT("------- Creating a new VLDB entry ------- \n");
4311 strcpy(entry.name, tovolname);
4313 entry.serverNumber[0] = toserver; /*should be indirect */
4314 entry.serverPartition[0] = topart;
4315 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4316 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4317 if (flags & RV_RDONLY)
4318 entry.volumeId[ROVOL] = pvolid;
4319 else if (tstatus.cloneID != 0) {
4320 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4322 entry.volumeId[ROVOL] = INVALID_BID;
4323 entry.volumeId[RWVOL] = pparentid;
4325 if (tstatus.backupID != 0) {
4326 entry.volumeId[BACKVOL] = tstatus.backupID;
4327 /*this should come from status info on the volume if non zero */
4329 entry.volumeId[BACKVOL] = INVALID_BID;
4330 MapNetworkToHost(&entry, &storeEntry);
4331 vcode = VLDB_CreateEntry(&storeEntry);
4334 "Could not create the VLDB entry for volume number %lu \n",
4335 (unsigned long)pvolid);
4341 EnumerateEntry(&entry);
4342 } else { /*update the existing entry */
4344 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4345 fprintf(STDOUT, "------- Old entry -------\n");
4346 EnumerateEntry(&entry);
4347 fprintf(STDOUT, "------- New entry -------\n");
4350 ubik_Call(VL_SetLock, cstruct, 0, pvolid, voltype,
4354 "Could not lock the entry for volume number %lu \n",
4355 (unsigned long)pvolid);
4360 strcpy(entry.name, tovolname);
4362 /* Update the vlentry with the new information */
4363 if (flags & RV_RDONLY)
4364 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4366 index = Lp_GetRwIndex(&entry);
4368 /* Add the new site for the volume being restored */
4369 entry.serverNumber[entry.nServers] = toserver;
4370 entry.serverPartition[entry.nServers] = topart;
4371 entry.serverFlags[entry.nServers] =
4372 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4375 /* This volume should be deleted on the old site
4376 * if its different from new site.
4379 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4382 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4384 if ((!errcode && !same)
4385 || (entry.serverPartition[index] != topart)) {
4387 UV_Bind(entry.serverNumber[index],
4388 AFSCONF_VOLUMEPORT);
4390 MapPartIdIntoName(entry.serverPartition[index],
4393 ("Deleting the previous volume %u on server %s, partition %s ...",
4395 hostutil_GetNameByINet(entry.serverNumber[index]),
4398 AFSVolTransCreate(tempconn, pvolid,
4399 entry.serverPartition[index],
4400 ITOffline, &temptid);
4403 AFSVolSetFlags(tempconn, temptid,
4408 "Could not set flags on volume %lu on the older site\n",
4409 (unsigned long)pvolid);
4413 code = AFSVolDeleteVolume(tempconn, temptid);
4416 "Could not delete volume %lu on the older site\n",
4417 (unsigned long)pvolid);
4421 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4427 "Could not end transaction on volume %lu on the older site\n",
4428 (unsigned long)pvolid);
4433 MapPartIdIntoName(entry.serverPartition[index],
4437 entry.serverNumber[index] = toserver;
4438 entry.serverPartition[index] = topart;
4441 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4442 MapNetworkToHost(&entry, &storeEntry);
4444 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4445 LOCKREL_OPCODE | LOCKREL_AFSID |
4449 "Could not update the entry for volume number %lu \n",
4450 (unsigned long)pvolid);
4456 EnumerateEntry(&entry);
4463 code = rx_EndCall(tocall, rxError);
4469 ubik_Call(VL_ReleaseLock, cstruct, 0, pvolid, voltype,
4470 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4473 "Could not release lock on the VLDB entry for the volume %lu\n",
4474 (unsigned long)pvolid);
4480 code = AFSVolEndTrans(toconn, totid, &rcode);
4484 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4485 (unsigned long)pvolid);
4491 code = AFSVolEndTrans(toconn, temptid, &rcode);
4495 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4496 (unsigned long)pvolid);
4502 rx_DestroyConnection(tempconn);
4504 rx_DestroyConnection(toconn);
4505 PrintError("", error);
4510 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4511 char tovolname[], int flags, afs_int32(*WriteData) (),
4514 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4519 /*unlocks the vldb entry associated with <volid> */
4521 UV_LockRelease(afs_int32 volid)
4527 VPRINT("Binding to the VLDB server\n");
4529 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4530 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4533 "Could not unlock the entry for volume number %lu in VLDB \n",
4534 (unsigned long)volid);
4535 PrintError("", vcode);
4538 VPRINT("VLDB updated\n");
4543 /*adds <server> and <part> as a readonly replication site for <volid>
4546 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4548 int j, nro = 0, islocked = 0;
4549 struct nvldbentry entry, storeEntry;
4550 afs_int32 vcode, error = 0;
4553 error = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4556 " Could not lock the VLDB entry for the volume %lu \n",
4557 (unsigned long)volid);
4562 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4565 "Could not fetch the VLDB entry for volume number %lu \n",
4566 (unsigned long)volid);
4570 if (!ISNAMEVALID(entry.name)) {
4572 "Volume name %s is too long, rename before adding site\n",
4574 error = VOLSERBADOP;
4577 MapHostToNetwork(&entry);
4579 /* See if it's too many entries */
4580 if (entry.nServers >= NMAXNSERVERS) {
4581 fprintf(STDERR, "Total number of entries will exceed %u\n",
4583 error = VOLSERBADOP;
4587 /* See if it's on the same server */
4588 for (j = 0; j < entry.nServers; j++) {
4589 if (entry.serverFlags[j] & ITSROVOL) {
4591 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4594 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4597 MapPartIdIntoName(entry.serverPartition[j], apartName);
4599 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4601 error = VOLSERBADOP;
4608 /* See if it's too many RO sites - leave one for the RW */
4609 if (nro >= NMAXNSERVERS - 1) {
4610 fprintf(STDERR, "Total number of sites will exceed %u\n",
4612 error = VOLSERBADOP;
4616 VPRINT("Adding a new site ...");
4617 entry.serverNumber[entry.nServers] = server;
4618 entry.serverPartition[entry.nServers] = part;
4619 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4622 MapNetworkToHost(&entry, &storeEntry);
4624 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4625 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4627 fprintf(STDERR, "Could not update entry for volume %lu \n",
4628 (unsigned long)volid);
4637 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4638 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4641 "Could not release lock on volume entry for %lu \n",
4642 (unsigned long)volid);
4643 PrintError("", vcode);
4647 PrintError("", error);
4651 /*removes <server> <part> as read only site for <volid> from the vldb */
4653 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4656 struct nvldbentry entry, storeEntry;
4659 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4661 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4662 (unsigned long)volid);
4663 PrintError("", vcode);
4667 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4670 "Could not fetch the entry for volume number %lu from VLDB \n",
4671 (unsigned long)volid);
4672 PrintError("", vcode);
4675 MapHostToNetwork(&entry);
4676 if (!Lp_ROMatch(server, part, &entry)) {
4677 /*this site doesnot exist */
4678 fprintf(STDERR, "This site is not a replication site \n");
4680 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4681 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4683 fprintf(STDERR, "Could not update entry for volume %lu \n",
4684 (unsigned long)volid);
4685 PrintError("", vcode);
4686 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4687 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4691 } else { /*remove the rep site */
4692 Lp_SetROValue(&entry, server, part, 0, 0);
4694 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4695 entry.flags &= ~RO_EXISTS;
4696 if (entry.nServers < 1) { /*this is the last ref */
4697 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4699 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, volid, ROVOL);
4702 "Could not delete VLDB entry for volume %lu \n",
4703 (unsigned long)volid);
4704 PrintError("", vcode);
4709 MapNetworkToHost(&entry, &storeEntry);
4710 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4711 (unsigned long)volid);
4714 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4715 LOCKREL_OPCODE | LOCKREL_AFSID |
4719 "Could not release lock on volume entry for %lu \n",
4720 (unsigned long)volid);
4721 PrintError("", vcode);
4722 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4723 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4731 /*sets <server> <part> as read/write site for <volid> in the vldb */
4733 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4736 struct nvldbentry entry, storeEntry;
4739 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4741 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4742 (unsigned long)volid);
4743 PrintError("", vcode);
4746 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4749 "Could not fetch the entry for volume number %lu from VLDB \n",
4750 (unsigned long)volid);
4751 PrintError("", vcode);
4754 MapHostToNetwork(&entry);
4755 index = Lp_GetRwIndex(&entry);
4757 /* no RW site exists */
4758 fprintf(STDERR, "No existing RW site for volume %lu",
4759 (unsigned long)volid);
4761 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4762 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4765 "Could not release lock on entry for volume %lu \n",
4766 (unsigned long)volid);
4767 PrintError("", vcode);
4771 } else { /* change the RW site */
4772 entry.serverNumber[index] = server;
4773 entry.serverPartition[index] = part;
4774 MapNetworkToHost(&entry, &storeEntry);
4776 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4777 LOCKREL_OPCODE | LOCKREL_AFSID |
4780 fprintf(STDERR, "Could not update entry for volume %lu \n",
4781 (unsigned long)volid);
4782 PrintError("", vcode);
4783 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4784 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4792 /*list all the partitions on <aserver> */
4794 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4797 struct rx_connection *aconn;
4798 struct pIDs partIds;
4799 struct partEntries partEnts;
4800 register int i, j = 0, code;
4803 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4805 partEnts.partEntries_len = 0;
4806 partEnts.partEntries_val = NULL;
4807 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4808 if (code == RXGEN_OPCODE) {
4809 for (i = 0; i < 26; i++) /* try old interface */
4810 partIds.partIds[i] = -1;
4811 code = AFSVolListPartitions(aconn, &partIds);
4813 for (i = 0; i < 26; i++) {
4814 if ((partIds.partIds[i]) != -1) {
4815 ptrPartList->partId[j] = partIds.partIds[i];
4816 ptrPartList->partFlags[j] = PARTVALID;
4819 ptrPartList->partFlags[i] = 0;
4824 *cntp = partEnts.partEntries_len;
4825 if (*cntp > VOLMAXPARTS) {
4827 "Warning: number of partitions on the server too high %d (process only %d)\n",
4828 *cntp, VOLMAXPARTS);
4829 *cntp = VOLMAXPARTS;
4831 for (i = 0; i < *cntp; i++) {
4832 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4833 ptrPartList->partFlags[i] = PARTVALID;
4835 free(partEnts.partEntries_val);
4841 "Could not fetch the list of partitions from the server\n");
4842 PrintError("", code);
4844 rx_DestroyConnection(aconn);
4849 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4850 This is used by the backup system */
4852 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4853 struct volDescription *volPtr, afs_int32 arraySize)
4855 struct rx_connection *aconn;
4856 struct volDescription *curPtr;
4859 afs_int32 rcode = 0;
4860 afs_int32 success = 1;
4863 aconn = (struct rx_connection *)0;
4864 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4866 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4867 if (curPtr->volFlags & CLONEVALID) {
4868 curPtr->volFlags &= ~CLONEZAPPED;
4871 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4876 code = AFSVolDeleteVolume(aconn, tid);
4879 code = AFSVolEndTrans(aconn, tid, &rcode);
4884 curPtr->volFlags |= CLONEZAPPED;
4886 fprintf(STDERR, "Could not zap volume %lu\n",
4887 (unsigned long)curPtr->volCloneId);
4889 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4890 curPtr->volCloneId);
4896 rx_DestroyConnection(aconn);
4900 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4903 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4904 struct volDescription *volPtr, afs_int32 arraySize)
4906 struct rx_connection *aconn;
4907 struct volDescription *curPtr;
4910 afs_int32 rcode = 0;
4912 int reuseCloneId = 0;
4913 afs_int32 curCloneId = 0;
4914 char cloneName[256]; /*max vol name */
4916 aconn = (struct rx_connection *)0;
4917 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4919 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4921 else { /*get a bunch of id's from vldb */
4923 ubik_Call(VL_GetNewVolumeId, cstruct, 0, arraySize, &curCloneId);
4925 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4926 PrintError("", code);
4931 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4932 if (curPtr->volFlags & ENTRYVALID) {
4934 curPtr->volFlags |= CLONEVALID;
4935 /*make a clone of curParentId and record as curPtr->volCloneId */
4937 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4940 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4943 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
4947 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
4948 strcpy(cloneName, curPtr->volName);
4949 strcat(cloneName, "-tmpClone-");
4951 strcpy(cloneName, "-tmpClone");
4953 curPtr->volCloneId = curCloneId;
4958 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
4959 &(curPtr->volCloneId));
4961 curPtr->volFlags &= ~CLONEVALID;
4963 fprintf(STDERR, "Could not clone %s due to error %lu\n",
4964 curPtr->volName, (unsigned long)code);
4965 code = AFSVolEndTrans(aconn, tid, &rcode);
4967 fprintf(STDERR, "WARNING: could not end transaction\n");
4970 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
4971 curPtr->volCloneId);
4972 code = AFSVolEndTrans(aconn, tid, &rcode);
4973 if (code || rcode) {
4974 curPtr->volFlags &= ~CLONEVALID;
4983 rx_DestroyConnection(aconn);
4988 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
4989 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
4991 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
4992 struct volintInfo **resultPtr, afs_int32 * size)
4994 struct rx_connection *aconn;
4996 volEntries volumeInfo;
5000 *resultPtr = (volintInfo *) 0;
5001 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5002 volumeInfo.volEntries_len = 0;
5004 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5005 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5008 "Could not fetch the list of volumes from the server\n");
5010 *resultPtr = volumeInfo.volEntries_val;
5011 *size = volumeInfo.volEntries_len;
5015 rx_DestroyConnection(aconn);
5016 PrintError("", code);
5020 /*------------------------------------------------------------------------
5021 * EXPORTED UV_XListVolumes
5024 * List the extended information for all the volumes on a particular
5025 * File Server and partition. We may either return the volume's ID
5026 * or all of its extended information.
5029 * a_serverID : Address of the File Server for which we want
5030 * extended volume info.
5031 * a_partID : Partition for which we want the extended
5033 * a_all : If non-zero, fetch ALL the volume info,
5034 * otherwise just the volume ID.
5035 * a_resultPP : Ptr to the address of the area containing
5036 * the returned volume info.
5037 * a_numEntsInResultP : Ptr for the value we set for the number of
5042 * Otherise, the return value of AFSVolXListVolumes.
5045 * This routine is closely related to UV_ListVolumes, which returns
5046 * only the standard level of detail on AFS volumes. It is a
5047 * heavyweight operation, zipping through all the volume entries for
5048 * a given server/partition.
5052 *------------------------------------------------------------------------*/
5055 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5056 struct volintXInfo **a_resultPP,
5057 afs_int32 * a_numEntsInResultP)
5059 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5060 afs_int32 code; /*Error code to return */
5061 volXEntries volumeXInfo; /*Area for returned extended vol info */
5064 * Set up our error code and the area for returned extended volume info.
5065 * We set the val field to a null pointer as a hint for the stub to
5069 *a_numEntsInResultP = 0;
5070 *a_resultPP = (volintXInfo *) 0;
5071 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5072 volumeXInfo.volXEntries_len = 0;
5075 * Bind to the Volume Server port on the File Server machine in question,
5078 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5079 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5081 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5084 * We got the info; pull out the pointer to where the results lie
5085 * and how many entries are there.
5087 *a_resultPP = volumeXInfo.volXEntries_val;
5088 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5092 * If we got an Rx connection, throw it away.
5095 rx_DestroyConnection(rxConnP);
5097 PrintError("", code);
5099 } /*UV_XListVolumes */
5101 /* get all the information about volume <volid> on <aserver> and <apart> */
5103 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
5104 struct volintInfo **resultPtr)
5106 struct rx_connection *aconn;
5108 volEntries volumeInfo;
5112 *resultPtr = (volintInfo *) 0;
5113 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5114 volumeInfo.volEntries_len = 0;
5116 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5117 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5120 "Could not fetch the information about volume %lu from the server\n",
5121 (unsigned long)volid);
5123 *resultPtr = volumeInfo.volEntries_val;
5128 rx_DestroyConnection(aconn);
5129 PrintError("", code);
5133 /*------------------------------------------------------------------------
5134 * EXPORTED UV_XListOneVolume
5137 * List the extended information for a volume on a particular File
5138 * Server and partition.
5141 * a_serverID : Address of the File Server for which we want
5142 * extended volume info.
5143 * a_partID : Partition for which we want the extended
5145 * a_volID : Volume ID for which we want the info.
5146 * a_resultPP : Ptr to the address of the area containing
5147 * the returned volume info.
5151 * Otherise, the return value of AFSVolXListOneVolume.
5154 * This routine is closely related to UV_ListOneVolume, which returns
5155 * only the standard level of detail on the chosen AFS volume.
5159 *------------------------------------------------------------------------*/
5162 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
5163 struct volintXInfo **a_resultPP)
5165 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5166 afs_int32 code; /*Error code */
5167 volXEntries volumeXInfo; /*Area for returned info */
5170 * Set up our error code, and the area we're in which we are returning
5171 * the info. Setting the val field to a null pointer tells the stub
5172 * to allocate space for us.
5175 *a_resultPP = (volintXInfo *) 0;
5176 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5177 volumeXInfo.volXEntries_len = 0;
5180 * Bind to the Volume Server port on the File Server machine in question,
5183 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5184 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5187 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5190 * We got the info; pull out the pointer to where the results lie.
5192 *a_resultPP = volumeXInfo.volXEntries_val;
5195 * If we got an Rx connection, throw it away.
5198 rx_DestroyConnection(rxConnP);
5200 PrintError("", code);
5205 * Given a volume we read from a partition, check if it is
5206 * represented in the VLDB correctly.
5208 * The VLDB is looked up by the RW volume id (not its name).
5209 * The RW contains the true name of the volume (BK and RO set
5210 * the name in the VLDB only on creation of the VLDB entry).
5211 * We want rules strict enough that when we check all volumes
5212 * on one partition, it does not need to be done again. IE:
5213 * two volumes on different partitions won't constantly
5214 * change a VLDB entry away from what the other set.
5215 * For RW and BK volumes, we will always check the VLDB to see
5216 * if the two exist on the server/partition. May seem redundant,
5217 * but this is an easy check of the VLDB. IE: if the VLDB entry
5218 * says the BK exists but no BK volume is there, we will detect
5219 * this when we check the RW volume.
5220 * VLDB entries are locked only when a change needs to be done.
5221 * Output changed to look a lot like the "vos syncserv" otuput.
5224 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5225 afs_int32 * modentry, afs_uint32 * maxvolid)
5228 afs_int32 code, error = 0;
5229 struct nvldbentry entry, storeEntry;
5231 int pass = 0, islocked = 0, createentry, addvolume, modified, mod;
5237 ((volumeinfo->type ==
5238 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5241 /* Check to see if the VLDB is ok without locking it (pass 1).
5242 * If it will change, then lock the VLDB entry, read it again,
5243 * then make the changes to it (pass 2).
5246 code = ubik_Call(VL_SetLock, cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5248 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5249 (unsigned long)rwvolid);
5255 createentry = 0; /* Do we need to create a VLDB entry */
5256 addvolume = 0; /* Add this volume to the VLDB entry */
5257 modified = 0; /* The VLDB entry was modified */
5259 /* Read the entry from VLDB by its RW volume id */
5260 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5262 if (code != VL_NOENT) {
5264 "Could not retreive the VLDB entry for volume %lu \n",
5265 (unsigned long)rwvolid);
5269 memset(&entry, 0, sizeof(entry));
5270 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5274 MapHostToNetwork(&entry);
5277 if (verbose && (pass == 1)) {
5278 fprintf(STDOUT, "_______________________________\n");
5279 fprintf(STDOUT, "\n-- status before -- \n");
5281 fprintf(STDOUT, "\n**does not exist**\n");
5283 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5284 || (entry.flags & BACK_EXISTS))
5285 EnumerateEntry(&entry);
5287 fprintf(STDOUT, "\n");
5290 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5296 /* Check existence of RW and BK volumes */
5297 code = CheckVldbRWBK(&entry, &mod);
5303 idx = Lp_GetRwIndex(&entry);
5304 if (idx == -1) { /* RW index not found in the VLDB entry */
5305 idx = entry.nServers; /* put it into next index */
5308 } else { /* RW index found in the VLDB entry. */
5309 /* Verify if this volume's location matches where the VLDB says it is */
5310 if (!Lp_Match(aserver, apart, &entry)) {
5311 if (entry.flags & RW_EXISTS) {
5312 /* The RW volume exists elsewhere - report this one a duplicate */
5314 MapPartIdIntoName(apart, pname);
5316 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5317 (unsigned long)rwvolid,
5318 hostutil_GetNameByINet(aserver), pname);
5319 MapPartIdIntoName(entry.serverPartition[idx],
5322 " VLDB reports RW volume %lu exists on %s %s\n",
5323 (unsigned long)rwvolid,
5324 hostutil_GetNameByINet(entry.
5329 /* The RW volume does not exist - have VLDB point to this one */
5332 /* Check for orphaned BK volume on old partition */
5333 if (entry.flags & BACK_EXISTS) {
5335 MapPartIdIntoName(entry.serverPartition[idx],
5338 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5339 entry.volumeId[BACKVOL],
5340 hostutil_GetNameByINet(entry.
5343 MapPartIdIntoName(apart, pname);
5345 " VLDB reports its RW volume %lu exists on %s %s\n",
5346 (unsigned long)rwvolid,
5347 hostutil_GetNameByINet(aserver),
5353 /* Volume location matches the VLDB location */
5354 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5355 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5358 (entry.name, volumeinfo->name,
5359 VOLSER_OLDMAXVOLNAME) != 0)) {
5367 entry.flags |= RW_EXISTS;
5368 entry.volumeId[RWVOL] = rwvolid;
5369 if (!entry.volumeId[BACKVOL])
5370 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5371 if (!entry.volumeId[ROVOL])
5372 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5374 entry.serverFlags[idx] = ITSRWVOL;
5375 entry.serverNumber[idx] = aserver;
5376 entry.serverPartition[idx] = apart;
5377 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5381 /* One last check - to update BK if need to */
5382 code = CheckVldbRWBK(&entry, &mod);
5390 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5396 /* Check existence of RW and BK volumes */
5397 code = CheckVldbRWBK(&entry, &mod);
5403 idx = Lp_GetRwIndex(&entry);
5404 if (idx == -1) { /* RW index not found in the VLDB entry */
5405 idx = entry.nServers; /* Put it into next index */
5408 } else { /* RW index found in the VLDB entry */
5409 /* Verify if this volume's location matches where the VLDB says it is */
5410 if (!Lp_Match(aserver, apart, &entry)) {
5411 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5413 MapPartIdIntoName(apart, pname);
5415 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5416 (unsigned long)volumeinfo->volid,
5417 hostutil_GetNameByINet(aserver), pname);
5418 MapPartIdIntoName(entry.serverPartition[idx], pname);
5420 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5421 (unsigned long)rwvolid,
5422 hostutil_GetNameByINet(entry.
5427 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5428 if (!(entry.flags & BACK_EXISTS)) {
5430 } else if (volumeinfo->volid >
5431 entry.volumeId[BACKVOL]) {
5435 MapPartIdIntoName(entry.serverPartition[idx],
5438 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5439 entry.volumeId[BACKVOL],
5440 hostutil_GetNameByINet(aserver),
5443 " VLDB reports its BK volume ID is %lu\n",
5444 (unsigned long)volumeinfo->volid);
5448 MapPartIdIntoName(entry.serverPartition[idx],
5451 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5452 (unsigned long)volumeinfo->volid,
5453 hostutil_GetNameByINet(aserver),
5456 " VLDB reports its BK volume ID is %u\n",
5457 entry.volumeId[BACKVOL]);
5460 } else if (!entry.volumeId[BACKVOL]) {
5467 entry.flags |= BACK_EXISTS;
5468 entry.volumeId[RWVOL] = rwvolid;
5469 entry.volumeId[BACKVOL] = volumeinfo->volid;
5471 entry.serverNumber[idx] = aserver;
5472 entry.serverPartition[idx] = apart;
5473 entry.serverFlags[idx] = ITSRWVOL;
5479 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5480 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5481 /* This is a quick check to see if the RO entry exists in the
5482 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5483 * RO volume listed in the VLDB exists).
5485 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5487 idx = entry.nServers;
5491 if (!(entry.flags & RO_EXISTS)) {
5496 /* Before we correct the VLDB entry, make sure all the
5497 * ROs listed in the VLDB exist.
5499 code = CheckVldbRO(&entry, &mod);
5505 if (!(entry.flags & RO_EXISTS)) {
5506 /* No RO exists in the VLDB entry - add this one */
5507 idx = entry.nServers;
5510 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5511 /* The volume headers's RO ID does not match that in the VLDB entry,
5512 * and the vol hdr's ID is greater (implies more recent). So delete
5513 * all the RO volumes listed in VLDB entry and add this volume.
5515 for (j = 0; j < entry.nServers; j++) {
5516 if (entry.serverFlags[j] & ITSROVOL) {
5517 /* Verify this volume exists and print message we are orphaning it */
5519 MapPartIdIntoName(apart, pname);
5521 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5522 entry.volumeId[ROVOL],
5523 hostutil_GetNameByINet(entry.
5527 " VLDB reports its RO volume ID is %lu\n",
5528 (unsigned long)volumeinfo->volid);
5531 Lp_SetRWValue(entry, entry.serverNumber[idx],
5532 entry.serverPartition[idx], 0L, 0L);
5539 idx = entry.nServers;
5542 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5543 /* The volume headers's RO ID does not match that in the VLDB entry,
5544 * and the vol hdr's ID is lower (implies its older). So orphan it.
5547 MapPartIdIntoName(apart, pname);
5549 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5550 (unsigned long)volumeinfo->volid,
5551 hostutil_GetNameByINet(aserver), pname);
5553 " VLDB reports its RO volume ID is %u\n",
5554 entry.volumeId[ROVOL]);
5557 /* The RO volume ID in the volume header match that in the VLDB entry,
5558 * and there exist RO volumes in the VLDB entry. See if any of them
5559 * are this one. If not, then we add it.
5561 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5563 idx = entry.nServers;
5571 entry.flags |= RO_EXISTS;
5572 entry.volumeId[RWVOL] = rwvolid;
5573 entry.volumeId[ROVOL] = volumeinfo->volid;
5575 entry.serverNumber[idx] = aserver;
5576 entry.serverPartition[idx] = apart;
5577 entry.serverFlags[idx] = ITSROVOL;
5583 /* Remember largest volume id */
5584 if (entry.volumeId[ROVOL] > *maxvolid)
5585 *maxvolid = entry.volumeId[ROVOL];
5586 if (entry.volumeId[BACKVOL] > *maxvolid)
5587 *maxvolid = entry.volumeId[BACKVOL];
5588 if (entry.volumeId[RWVOL] > *maxvolid)
5589 *maxvolid = entry.volumeId[RWVOL];
5592 MapNetworkToHost(&entry, &storeEntry);
5595 code = VLDB_CreateEntry(&storeEntry);
5598 "Could not create a VLDB entry for the volume %lu\n",
5599 (unsigned long)rwvolid);
5606 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5607 LOCKREL_OPCODE | LOCKREL_AFSID |
5610 fprintf(STDERR, "Could not update entry for %lu\n",
5611 (unsigned long)rwvolid);
5616 *modentry = modified;
5617 } else if (pass == 2) {
5619 ubik_Call(VL_ReleaseLock, cstruct, 0, rwvolid, RWVOL,
5620 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5622 PrintError("Could not unlock VLDB entry ", code);
5627 fprintf(STDOUT, "-- status after --\n");
5629 EnumerateEntry(&entry);
5631 fprintf(STDOUT, "\n**no change**\n");
5635 VPRINT("\n_______________________________\n");
5640 sortVolumes(const void *a, const void *b)
5642 volintInfo *v1 = (volintInfo *) a;
5643 volintInfo *v2 = (volintInfo *) b;
5644 afs_int32 rwvolid1, rwvolid2;
5646 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5647 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5649 if (rwvolid1 > rwvolid2)
5650 return -1; /* lower RW id goes first */
5651 if (rwvolid1 < rwvolid2)
5654 if (v1->type == RWVOL)
5655 return -1; /* RW vols go first */
5656 if (v2->type == RWVOL)
5659 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5660 return -1; /* BK vols next */
5661 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5664 if (v1->volid < v2->volid)
5665 return 1; /* larger volids first */
5666 if (v1->volid > v2->volid)
5672 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5673 * Synchronize an individual volume against a sever and partition.
5674 * Checks the VLDB entry (similar to syncserv) as well as checks
5675 * if the volume exists on specified servers (similar to syncvldb).
5678 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5680 struct rx_connection *aconn = 0;
5681 afs_int32 j, k, code, vcode, error = 0;
5682 afs_int32 tverbose, mod, modified = 0;
5683 struct nvldbentry vldbentry;
5684 afs_int32 volumeid = 0;
5685 volEntries volumeInfo;
5686 struct partList PartList;
5688 afs_int32 maxvolid = 0;
5690 volumeInfo.volEntries_val = (volintInfo *) 0;
5691 volumeInfo.volEntries_len = 0;
5693 if (!aserver && flags) {
5694 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5698 /* Turn verbose logging off and do our own verbose logging */
5702 /* Read the VLDB entry */
5703 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5704 if (vcode && (vcode != VL_NOENT)) {
5705 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5708 } else if (!vcode) {
5709 MapHostToNetwork(&vldbentry);
5713 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5714 fprintf(STDOUT, "_______________________________\n");
5715 fprintf(STDOUT, "\n-- status before -- \n");
5717 fprintf(STDOUT, "\n**does not exist**\n");
5719 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5720 || (vldbentry.flags & BACK_EXISTS))
5721 EnumerateEntry(&vldbentry);
5723 fprintf(STDOUT, "\n");
5726 /* Verify that all of the VLDB entries exist on the repective servers
5727 * and partitions (this does not require that avolname be a volume ID).
5728 * Equivalent to a syncserv.
5731 code = CheckVldb(&vldbentry, &mod);
5733 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5741 /* If aserver is given, we will search for the desired volume on it */
5743 /* Generate array of partitions on the server that we will check */
5745 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5748 "Could not fetch the list of partitions from the server\n");
5752 PartList.partId[0] = apart;
5756 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5758 /* If a volume ID were given, search for it on each partition */
5759 if ((volumeid = atol(avolname))) {
5760 for (j = 0; j < pcnt; j++) {
5762 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5765 if (code != ENODEV) {
5766 fprintf(STDERR, "Could not query server\n");
5770 /* Found one, sync it with VLDB entry */
5772 CheckVolume(volumeInfo.volEntries_val, aserver,
5773 PartList.partId[j], &mod, &maxvolid);
5780 if (volumeInfo.volEntries_val)
5781 free(volumeInfo.volEntries_val);
5782 volumeInfo.volEntries_val = (volintInfo *) 0;
5783 volumeInfo.volEntries_len = 0;
5787 /* Check to see if the RW, BK, and RO IDs exist on any
5788 * partitions. We get the volume IDs from the VLDB.
5790 rv = 1; /* Read the VLDB entry ? */
5791 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5793 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5795 if (vcode == VL_NOENT)
5798 "Could not access the VLDB for volume %s\n",
5805 if (vldbentry.volumeId[j] == 0)
5808 for (k = 0; k < pcnt; k++) { /* For each partition */
5809 volumeInfo.volEntries_val = (volintInfo *) 0;
5810 volumeInfo.volEntries_len = 0;
5812 AFSVolListOneVolume(aconn, PartList.partId[k],
5813 vldbentry.volumeId[j], &volumeInfo);
5815 if (code != ENODEV) {
5816 fprintf(STDERR, "Could not query server\n");
5820 /* Found one, sync it with VLDB entry */
5822 CheckVolume(volumeInfo.volEntries_val, aserver,
5823 PartList.partId[k], &mod, &maxvolid);
5830 if (volumeInfo.volEntries_val)
5831 free(volumeInfo.volEntries_val);
5832 volumeInfo.volEntries_val = (volintInfo *) 0;
5833 volumeInfo.volEntries_len = 0;
5839 /* If verbose output, print a summary of what changed */
5841 fprintf(STDOUT, "-- status after --\n");
5842 code = VLDB_GetEntryByName(avolname, &vldbentry);
5843 if (code && (code != VL_NOENT)) {
5844 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5848 if (modified && (code == VL_NOENT)) {
5849 fprintf(STDOUT, "\n**entry deleted**\n");
5850 } else if (modified) {
5851 EnumerateEntry(&vldbentry);
5853 fprintf(STDOUT, "\n**no change**\n");
5855 fprintf(STDOUT, "\n_______________________________\n");
5859 /* Now check if the maxvolid is larger than that stored in the VLDB */
5861 afs_int32 maxvldbid = 0;
5862 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
5865 "Could not get the highest allocated volume id from the VLDB\n");
5868 } else if (maxvolid > maxvldbid) {
5870 id = maxvolid - maxvldbid + 1;
5871 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
5874 "Error in increasing highest allocated volume id in VLDB\n");
5884 fprintf(STDOUT, "...error encountered");
5886 fprintf(STDOUT, "...done entry\n");
5889 rx_DestroyConnection(aconn);
5890 if (volumeInfo.volEntries_val)
5891 free(volumeInfo.volEntries_val);
5893 PrintError("", error);
5898 * Synchronise vldb with the file server <aserver> and,
5899 * optionally, <apart>.
5902 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5904 struct rx_connection *aconn;
5905 afs_int32 code, error = 0;
5907 volEntries volumeInfo;
5908 struct partList PartList;
5912 afs_int32 failures = 0, modifications = 0, tentries = 0;
5914 afs_uint32 maxvolid = 0;
5916 volumeInfo.volEntries_val = (volintInfo *) 0;
5917 volumeInfo.volEntries_len = 0;
5919 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5921 /* Generate array of partitions to check */
5923 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5926 "Could not fetch the list of partitions from the server\n");
5930 PartList.partId[0] = apart;
5934 VPRINT("Processing volume entries ...\n");
5936 /* Step through the array of partitions */
5937 for (i = 0; i < pcnt; i++) {
5938 apart = PartList.partId[i];
5939 MapPartIdIntoName(apart, pname);
5941 volumeInfo.volEntries_val = (volintInfo *) 0;
5942 volumeInfo.volEntries_len = 0;
5943 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
5946 "Could not fetch the list of volumes from the server\n");
5950 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
5951 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
5952 sizeof(volintInfo), sortVolumes);
5955 for (vi = volumeInfo.volEntries_val, j = 0;
5956 j < volumeInfo.volEntries_len; j++, vi++) {
5964 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
5965 j + 1, vi->name, (unsigned long)vi->volid,
5966 hostutil_GetNameByINet(aserver), pname);
5970 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
5972 PrintError("", code);
5975 } else if (modified) {
5981 fprintf(STDOUT, "...error encountered\n\n");
5983 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
5990 "Could not process entries on server %s partition %s\n",
5991 hostutil_GetNameByINet(aserver), pname);
5993 if (volumeInfo.volEntries_val) {
5994 free(volumeInfo.volEntries_val);
5995 volumeInfo.volEntries_val = 0;
5998 } /* thru all partitions */
6000 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6001 failures, modifications);
6004 /* Now check if the maxvolid is larger than that stored in the VLDB */
6006 afs_uint32 maxvldbid = 0;
6007 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
6010 "Could not get the highest allocated volume id from the VLDB\n");
6013 } else if (maxvolid > maxvldbid) {
6015 id = maxvolid - maxvldbid + 1;
6016 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
6019 "Error in increasing highest allocated volume id in VLDB\n");
6027 rx_DestroyConnection(aconn);
6028 if (volumeInfo.volEntries_val)
6029 free(volumeInfo.volEntries_val);
6030 PrintError("", error);
6035 * Determine if a volume exists on a server and partition.
6036 * Try creating a transaction on the volume. If we can,
6037 * the volume exists, if not, then return the error code.
6038 * Some error codes mean the volume is unavailable but
6039 * still exists - so we catch these error codes.
6042 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
6044 struct rx_connection *conn = (struct rx_connection *)0;
6045 afs_int32 code = -1;
6046 volEntries volumeInfo;
6048 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6050 volumeInfo.volEntries_val = (volintInfo *) 0;
6051 volumeInfo.volEntries_len = 0;
6052 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6053 if (volumeInfo.volEntries_val)
6054 free(volumeInfo.volEntries_val);
6055 if (code == VOLSERILLEGAL_PARTITION)
6057 rx_DestroyConnection(conn);
6066 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6070 afs_int32 code, error = 0;
6075 idx = Lp_GetRwIndex(entry);
6077 /* Check to see if the RW volume exists and set the RW_EXISTS
6080 if (idx == -1) { /* Did not find a RW entry */
6081 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6082 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6087 VolumeExists(entry->serverNumber[idx],
6088 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6089 if (code == 0) { /* RW volume exists */
6090 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6091 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6094 } else if (code == ENODEV) { /* RW volume does not exist */
6095 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6096 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6100 /* If VLDB says it didn't exist, then ignore error */
6101 if (entry->flags & RW_EXISTS) {
6102 MapPartIdIntoName(entry->serverPartition[idx], pname);
6104 "Transaction call failed for RW volume %u on server %s %s\n",
6105 entry->volumeId[RWVOL],
6106 hostutil_GetNameByINet(entry->serverNumber[idx]),
6113 /* Check to see if the BK volume exists and set the BACK_EXISTS
6114 * flag accordingly. idx already ponts to the RW entry.
6116 if (idx == -1) { /* Did not find a RW entry */
6117 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6118 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6121 } else { /* Found a RW entry */
6123 VolumeExists(entry->serverNumber[idx],
6124 entry->serverPartition[idx],
6125 entry->volumeId[BACKVOL]);
6126 if (code == 0) { /* BK volume exists */
6127 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6128 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6131 } else if (code == ENODEV) { /* BK volume does not exist */
6132 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6133 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6137 /* If VLDB says it didn't exist, then ignore error */
6138 if (entry->flags & BACK_EXISTS) {
6139 MapPartIdIntoName(entry->serverPartition[idx], pname);
6141 "Transaction call failed for BK volume %u on server %s %s\n",
6142 entry->volumeId[BACKVOL],
6143 hostutil_GetNameByINet(entry->serverNumber[idx]),
6150 /* If there is an idx but the BK and RW volumes no
6151 * longer exist, then remove the RW entry.
6153 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6154 && !(entry->flags & BACK_EXISTS)) {
6155 Lp_SetRWValue(entry, entry->serverNumber[idx],
6156 entry->serverPartition[idx], 0L, 0L);
6163 *modified = modentry;
6168 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6171 int foundro = 0, modentry = 0;
6172 afs_int32 code, error = 0;
6178 /* Check to see if the RO volumes exist and set the RO_EXISTS
6181 for (idx = 0; idx < entry->nServers; idx++) {
6182 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6183 continue; /* not a RO */
6187 VolumeExists(entry->serverNumber[idx],
6188 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6189 if (code == 0) { /* RO volume exists */
6191 } else if (code == ENODEV) { /* RW volume does not exist */
6192 Lp_SetROValue(entry, entry->serverNumber[idx],
6193 entry->serverPartition[idx], 0L, 0L);
6198 MapPartIdIntoName(entry->serverPartition[idx], pname);
6200 "Transaction call failed for RO %u on server %s %s\n",
6201 entry->volumeId[ROVOL],
6202 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6207 if (foundro) { /* A RO volume exists */
6208 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6209 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6212 } else { /* A RO volume does not exist */
6213 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6214 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6221 *modified = modentry;
6226 * Ensure that <entry> matches with the info on file servers
6229 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6231 afs_int32 code, error = 0;
6232 struct nvldbentry storeEntry;
6233 int islocked = 0, mod, modentry, delentry = 0;
6239 fprintf(STDOUT, "_______________________________\n");
6240 fprintf(STDOUT, "\n-- status before -- \n");
6241 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6242 || (entry->flags & BACK_EXISTS))
6243 EnumerateEntry(entry);
6244 fprintf(STDOUT, "\n");
6247 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6248 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6249 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6253 /* Check to see if the VLDB is ok without locking it (pass 1).
6254 * If it will change, then lock the VLDB entry, read it again,
6255 * then make the changes to it (pass 2).
6259 ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6262 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6263 entry->volumeId[RWVOL]);
6268 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6270 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6274 MapHostToNetwork(entry);
6280 /* Check if the RW and BK entries are ok */
6281 code = CheckVldbRWBK(entry, &mod);
6284 if (mod && (pass == 1))
6289 /* Check if the RO volumes entries are ok */
6290 code = CheckVldbRO(entry, &mod);
6293 if (mod && (pass == 1))
6298 /* The VLDB entry has been updated. If it as been modified, then
6299 * write the entry back out the the VLDB.
6305 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6306 && !(entry->flags & RO_EXISTS)) {
6307 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6309 ubik_Call(VL_DeleteEntry, cstruct, 0, entry->volumeId[RWVOL],
6313 "Could not delete VLDB entry for volume %u \n",
6314 entry->volumeId[RWVOL]);
6319 /* Replace old entry with our new one */
6320 MapNetworkToHost(entry, &storeEntry);
6322 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6323 (LOCKREL_OPCODE | LOCKREL_AFSID |
6324 LOCKREL_TIMESTAMP));
6326 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6327 entry->volumeId[RWVOL]);
6337 fprintf(STDOUT, "-- status after --\n");
6339 fprintf(STDOUT, "\n**entry deleted**\n");
6341 EnumerateEntry(entry);
6343 fprintf(STDOUT, "\n**no change**\n");
6347 VPRINT("\n_______________________________\n");
6351 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
6353 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6356 "Could not release lock on VLDB entry for volume %u\n",
6357 entry->volumeId[RWVOL]);
6366 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6369 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6371 struct rx_connection *aconn;
6372 afs_int32 code, error = 0;
6373 afs_int32 nentries, tentries = 0;
6374 struct VldbListByAttributes attributes;
6375 nbulkentries arrayEntries;
6376 afs_int32 failures = 0, modified, modifications = 0;
6377 struct nvldbentry *vlentry;
6378 afs_int32 si, nsi, j;
6380 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6382 /* Set up attributes to search VLDB */
6383 attributes.server = ntohl(aserver);
6384 attributes.Mask = VLLIST_SERVER;
6386 attributes.partition = apart;
6387 attributes.Mask |= VLLIST_PARTITION;
6390 VPRINT("Processing VLDB entries ...\n");
6392 /* While we need to collect more VLDB entries */
6393 for (si = 0; si != -1; si = nsi) {
6394 memset(&arrayEntries, 0, sizeof(arrayEntries));
6396 /* Collect set of VLDB entries */
6398 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6399 &arrayEntries, &nsi);
6400 if (code == RXGEN_OPCODE) {
6401 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6405 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6408 tentries += nentries;
6410 for (j = 0; j < nentries; j++) {
6411 vlentry = &arrayEntries.nbulkentries_val[j];
6412 MapHostToNetwork(vlentry);
6414 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6416 code = CheckVldb(vlentry, &modified);
6418 PrintError("", code);
6420 "Could not process VLDB entry for volume %s\n",
6423 } else if (modified) {
6429 fprintf(STDOUT, "...error encountered\n\n");
6431 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6436 if (arrayEntries.nbulkentries_val) {
6437 free(arrayEntries.nbulkentries_val);
6438 arrayEntries.nbulkentries_val = 0;
6442 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6443 failures, modifications);
6447 rx_DestroyConnection(aconn);
6448 if (arrayEntries.nbulkentries_val)
6449 free(arrayEntries.nbulkentries_val);
6452 error = VOLSERFAILEDOP;
6456 /*rename volume <oldname> to <newname>, changing the names of the related
6457 *readonly and backup volumes. This operation is also idempotent.
6458 *salvager is capable of recovering from rename operation stopping halfway.
6459 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6461 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6463 struct nvldbentry storeEntry;
6464 afs_int32 vcode, code, rcode, error;
6466 char nameBuffer[256];
6468 struct rx_connection *aconn;
6472 aconn = (struct rx_connection *)0;
6476 vcode = ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6479 " Could not lock the VLDB entry for the volume %u \n",
6480 entry->volumeId[RWVOL]);
6485 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6486 MapNetworkToHost(entry, &storeEntry);
6487 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6489 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6490 entry->volumeId[RWVOL]);
6494 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6495 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6496 * is concerned, oldname is lost */
6497 if (entry->flags & RW_EXISTS) {
6498 index = Lp_GetRwIndex(entry);
6499 if (index == -1) { /* there is a serious discrepancy */
6501 "There is a serious discrepancy in VLDB entry for volume %u\n",
6502 entry->volumeId[RWVOL]);
6503 fprintf(STDERR, "try building VLDB from scratch\n");
6504 error = VOLSERVLDB_ERROR;
6507 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6509 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6510 entry->serverPartition[index], ITOffline, &tid);
6511 if (code) { /*volume doesnot exist */
6513 "Could not start transaction on the rw volume %u\n",
6514 entry->volumeId[RWVOL]);
6517 } else { /*volume exists, process it */
6520 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6521 entry->volumeId[RWVOL],
6522 entry->volumeId[ROVOL],
6523 entry->volumeId[BACKVOL]);
6525 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6526 code = AFSVolEndTrans(aconn, tid, &rcode);
6530 "Could not end transaction on volume %s %u\n",
6531 entry->name, entry->volumeId[RWVOL]);
6536 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6537 entry->name, entry->volumeId[RWVOL]);
6543 rx_DestroyConnection(aconn);
6544 aconn = (struct rx_connection *)0;
6546 /*end rw volume processing */
6547 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6548 index = Lp_GetRwIndex(entry);
6549 if (index == -1) { /* there is a serious discrepancy */
6551 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6552 entry->volumeId[BACKVOL]);
6553 fprintf(STDERR, "try building VLDB from scratch\n");
6554 error = VOLSERVLDB_ERROR;
6557 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6559 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6560 entry->serverPartition[index], ITOffline, &tid);
6561 if (code) { /*volume doesnot exist */
6563 "Could not start transaction on the backup volume %u\n",
6564 entry->volumeId[BACKVOL]);
6567 } else { /*volume exists, process it */
6568 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6570 "Volume name %s.backup exceeds the limit of %u characters\n",
6571 newname, VOLSER_OLDMAXVOLNAME);
6575 strcpy(nameBuffer, newname);
6576 strcat(nameBuffer, ".backup");
6579 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6580 entry->volumeId[RWVOL], 0, 0);
6582 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6583 code = AFSVolEndTrans(aconn, tid, &rcode);
6587 "Could not end transaction on the backup volume %u\n",
6588 entry->volumeId[BACKVOL]);
6594 "Could not set parameters on the backup volume %u\n",
6595 entry->volumeId[BACKVOL]);
6600 } /* end backup processing */
6602 rx_DestroyConnection(aconn);
6603 aconn = (struct rx_connection *)0;
6604 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6605 for (i = 0; i < entry->nServers; i++) {
6606 if (entry->serverFlags[i] & ITSROVOL) {
6607 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6609 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6610 entry->serverPartition[i], ITOffline,
6612 if (code) { /*volume doesnot exist */
6614 "Could not start transaction on the ro volume %u\n",
6615 entry->volumeId[ROVOL]);
6618 } else { /*volume exists, process it */
6619 strcpy(nameBuffer, newname);
6620 strcat(nameBuffer, ".readonly");
6621 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6623 "Volume name %s exceeds the limit of %u characters\n",
6624 nameBuffer, VOLSER_OLDMAXVOLNAME);
6629 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6630 entry->volumeId[RWVOL], 0, 0);
6632 VPRINT2("Renamed RO volume %s on host %s\n",
6634 hostutil_GetNameByINet(entry->
6636 code = AFSVolEndTrans(aconn, tid, &rcode);
6640 "Could not end transaction on volume %u\n",
6641 entry->volumeId[ROVOL]);
6647 "Could not set parameters on the ro volume %u\n",
6648 entry->volumeId[ROVOL]);
6654 rx_DestroyConnection(aconn);
6655 aconn = (struct rx_connection *)0;
6662 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
6664 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6667 "Could not unlock the VLDB entry for the volume %s %u\n",
6668 entry->name, entry->volumeId[RWVOL]);
6674 code = AFSVolEndTrans(aconn, tid, &rcode);
6678 fprintf(STDERR, "Failed to end transaction on a volume \n");
6684 rx_DestroyConnection(aconn);
6685 PrintError("", error);
6690 /*report on all the active transactions on volser */
6692 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6694 struct rx_connection *aconn;
6695 transDebugEntries transInfo;
6698 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6699 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6700 transInfo.transDebugEntries_len = 0;
6701 code = AFSVolMonitor(aconn, &transInfo);
6704 "Could not access status information about the server\n");
6705 PrintError("", code);
6706 if (transInfo.transDebugEntries_val)
6707 free(transInfo.transDebugEntries_val);
6709 rx_DestroyConnection(aconn);
6712 *rcount = transInfo.transDebugEntries_len;
6713 *rpntr = transInfo.transDebugEntries_val;
6715 rx_DestroyConnection(aconn);
6722 /*delete the volume without interacting with the vldb */
6724 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6726 afs_int32 rcode, ttid, error, code;
6727 struct rx_connection *aconn;
6733 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6734 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6736 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6737 (unsigned long)volid);
6741 code = AFSVolDeleteVolume(aconn, ttid);
6743 fprintf(STDERR, "Could not delete volume %lu\n",
6744 (unsigned long)volid);
6748 code = AFSVolEndTrans(aconn, ttid, &rcode);
6753 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6754 (unsigned long)volid);
6760 code = AFSVolEndTrans(aconn, ttid, &rcode);
6766 PrintError("", error);
6768 rx_DestroyConnection(aconn);
6773 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6774 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6776 struct rx_connection *conn = 0;
6778 afs_int32 code, error = 0, rcode;
6780 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6782 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6786 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6788 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6792 code = AFSVolSetFlags(conn, tid, setflag);
6794 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6799 #ifdef AFS_PTHREAD_ENV
6802 IOMGR_Sleep(sleeptime);
6809 code = AFSVolEndTrans(conn, tid, &rcode);
6810 if (code || rcode) {
6811 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6813 error = (code ? code : rcode);
6818 rx_DestroyConnection(conn);
6823 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6826 struct rx_connection *conn = 0;
6828 afs_int32 code, error = 0, rcode;
6830 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6832 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6836 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6838 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6842 code = AFSVolSetInfo(conn, tid, infop);
6844 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6851 code = AFSVolEndTrans(conn, tid, &rcode);
6852 if (code || rcode) {
6853 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6855 error = (code ? code : rcode);
6860 rx_DestroyConnection(conn);
6865 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6866 afs_int32 fromdate, struct volintSize *vol_size)
6868 struct rx_connection *aconn = (struct rx_connection *)0;
6869 afs_int32 tid = 0, rcode = 0;
6870 afs_int32 code, error = 0;
6873 /* get connections to the servers */
6874 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6876 VPRINT1("Starting transaction on volume %u...", afromvol);
6877 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6878 EGOTO1(error_exit, code,
6879 "Could not start transaction on the volume %u to be measured\n",
6883 VPRINT1("Getting size of volume on volume %u...", afromvol);
6884 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6885 EGOTO(error_exit, code, "Could not start the measurement process \n");
6890 VPRINT1("Ending transaction on volume %u...", afromvol);
6891 code = AFSVolEndTrans(aconn, tid, &rcode);
6892 if (code || rcode) {
6893 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6895 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6897 error = (code ? code : rcode);
6902 rx_DestroyConnection(aconn);
6904 PrintError("", error);
6908 /*maps the host addresses in <old > (present in network byte order) to
6909 that in< new> (present in host byte order )*/
6911 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
6915 /*copy all the fields */
6916 strcpy(new->name, old->name);
6917 /* new->volumeType = old->volumeType;*/
6918 new->nServers = old->nServers;
6919 count = old->nServers;
6920 if (count < NMAXNSERVERS)
6922 for (i = 0; i < count; i++) {
6923 new->serverNumber[i] = ntohl(old->serverNumber[i]);
6924 new->serverPartition[i] = old->serverPartition[i];
6925 new->serverFlags[i] = old->serverFlags[i];
6927 new->volumeId[RWVOL] = old->volumeId[RWVOL];
6928 new->volumeId[ROVOL] = old->volumeId[ROVOL];
6929 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
6930 new->cloneId = old->cloneId;
6931 new->flags = old->flags;
6934 /*maps the host entries in <entry> which are present in host byte order to network byte order */
6936 MapHostToNetwork(struct nvldbentry *entry)
6940 count = entry->nServers;
6941 if (count < NMAXNSERVERS)
6943 for (i = 0; i < count; i++) {
6944 entry->serverNumber[i] = htonl(entry->serverNumber[i]);