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>
44 #include <afs/cellconfig.h>
47 #include <afs/afsint.h>
51 #include <afs/com_err.h>
53 #include <afs/kautils.h>
56 #define ERRCODE_RANGE 8 /* from error_table.h */
57 #define CLOCKSKEW 2 /* not really skew, but resolution */
58 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
60 /* for UV_MoveVolume() recovery */
62 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
65 #include <volser_prototypes.h>
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", afs_error_table_name(errcode),
402 afs_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_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_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_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_VL_ReleaseLock(cstruct, 0, avolid, -1,
990 (LOCKREL_OPCODE | LOCKREL_AFSID |
994 "Could not release the lock on the VLDB entry for the volume %u \n",
1002 rx_DestroyConnection(aconn);
1006 /* add recovery to UV_MoveVolume */
1008 #define TESTC 0 /* set to test recovery code, clear for production */
1014 sigint_handler(int x)
1019 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1021 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1022 fprintf(STDOUT, "enter second control-c to exit\n");
1026 (void)signal(SIGINT, sigint_handler);
1031 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1032 * <atopart>. The operation is almost idempotent. The following
1033 * flags are recognized:
1035 * RV_NOCLONE - don't use a copy clone
1039 UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1040 afs_int32 atoserver, afs_int32 atopart, int flags)
1042 struct rx_connection *toconn, *fromconn;
1043 afs_int32 fromtid, totid, clonetid;
1046 char tmpName[VOLSER_MAXVOLNAME + 1];
1049 struct restoreCookie cookie;
1050 register afs_int32 vcode, code;
1051 afs_int32 newVol, volid, backupId;
1052 struct volser_status tstatus;
1053 struct destServer destination;
1055 struct nvldbentry entry, storeEntry;
1056 int i, islocked, pntg;
1058 char in, lf; /* for test code */
1061 #ifdef ENABLE_BUGFIX_1165
1062 volEntries volumeInfo;
1063 struct volintInfo *infop = 0;
1067 fromconn = (struct rx_connection *)0;
1068 toconn = (struct rx_connection *)0;
1078 /* support control-c processing */
1081 (void)signal(SIGINT, sigint_handler);
1085 "\nThere are three tests points - verifies all code paths through recovery.\n");
1086 fprintf(STDOUT, "First test point - operation not started.\n");
1087 fprintf(STDOUT, "...test here (y, n)? ");
1089 fscanf(stdin, "%c", &in);
1090 fscanf(stdin, "%c", &lf); /* toss away */
1092 fprintf(STDOUT, "type control-c\n");
1094 fprintf(stdout, ".");
1099 /* or drop through */
1102 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1103 EGOTO1(mfail, vcode,
1104 "Could not fetch the entry for the volume %u from the VLDB \n",
1107 if (entry.volumeId[RWVOL] != afromvol) {
1108 fprintf(STDERR, "Only RW volume can be moved\n");
1112 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1113 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1116 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1117 EGOTO1(mfail, vcode,
1118 "Could not fetch the entry for the volume %u from the VLDB \n",
1121 backupId = entry.volumeId[BACKVOL];
1122 MapHostToNetwork(&entry);
1124 if (!Lp_Match(afromserver, afrompart, &entry)) {
1125 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1126 if (!Lp_Match(atoserver, atopart, &entry)) {
1127 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1128 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1129 (unsigned long)afromvol);
1130 fprintf(STDERR, "The current site is :");
1131 for (i = 0; i < entry.nServers; i++) {
1132 if (entry.serverFlags[i] == ITSRWVOL) {
1134 MapPartIdIntoName(entry.serverPartition[i], pname);
1135 fprintf(STDERR, " server %s partition %s \n",
1136 hostutil_GetNameByINet(entry.serverNumber[i]),
1141 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1142 (LOCKREL_OPCODE | LOCKREL_AFSID |
1143 LOCKREL_TIMESTAMP));
1144 EGOTO1(mfail, vcode,
1145 " Could not release lock on the VLDB entry for the volume %u \n",
1148 return VOLSERVOLMOVED;
1151 /* delete the volume afromvol on src_server */
1152 /* from-info does not exist but to-info does =>
1153 * we have already done the move, but the volume
1154 * may still be existing physically on from fileserver
1156 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1161 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1163 if (!code) { /* volume exists - delete it */
1164 VPRINT1("Setting flags on leftover source volume %u ...",
1167 AFSVolSetFlags(fromconn, fromtid,
1168 VTDeleteOnSalvage | VTOutOfService);
1170 "Failed to set flags on the leftover source volume %u\n",
1174 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1175 code = AFSVolDeleteVolume(fromconn, fromtid);
1177 "Failed to delete the leftover source volume %u\n",
1181 VPRINT1("Ending transaction on leftover source volume %u ...",
1183 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1188 "Could not end the transaction for the leftover source volume %u \n",
1193 /*delete the backup volume now */
1196 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1198 if (!code) { /* backup volume exists - delete it */
1199 VPRINT1("Setting flags on leftover backup volume %u ...",
1202 AFSVolSetFlags(fromconn, fromtid,
1203 VTDeleteOnSalvage | VTOutOfService);
1205 "Failed to set flags on the backup volume %u\n", backupId);
1208 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1209 code = AFSVolDeleteVolume(fromconn, fromtid);
1211 "Could not delete the leftover backup volume %u\n",
1215 VPRINT1("Ending transaction on leftover backup volume %u ...",
1217 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1222 "Could not end the transaction for the leftover backup volume %u\n",
1232 /* From-info matches the vldb info about volid,
1233 * its ok start the move operation, the backup volume
1234 * on the old site is deleted in the process
1236 if (afrompart == atopart) {
1237 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1238 EGOTO2(mfail, error,
1239 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1240 afromserver, error);
1243 EGOTO1(mfail, VOLSERVOLMOVED,
1244 "Warning: Moving volume %u to its home partition ignored!\n",
1250 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1251 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1252 fromtid = totid = 0; /* initialize to uncreated */
1255 * clone the read/write volume locally.
1258 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1259 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1260 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1264 if (!(flags & RV_NOCLONE)) {
1265 /* Get a clone id */
1266 VPRINT1("Allocating new volume id for clone of volume %u ...",
1269 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1270 EGOTO1(mfail, vcode,
1271 "Could not get an ID for the clone of volume %u from the VLDB\n",
1275 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1276 VPRINT1("Cloning source volume %u ...", afromvol);
1277 strcpy(vname, "move-clone-temp");
1279 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1280 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1285 /* lookup the name of the volume we just cloned */
1287 code = AFSVolGetName(fromconn, fromtid, &volName);
1288 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1291 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1293 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1298 "Failed to end the transaction on the source volume %u\n",
1303 * Create the destination volume
1306 if (!(flags & RV_NOCLONE)) {
1307 /* All of this is to get the fromDate */
1308 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1310 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1313 "Failed to start a transaction on the cloned volume%u\n",
1317 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1319 AFSVolSetFlags(fromconn, clonetid,
1320 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1321 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1325 /* remember time from which we've dumped the volume */
1326 VPRINT1("Getting status of cloned volume %u ...", newVol);
1327 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1329 "Failed to get the status of the cloned volume %u\n",
1333 fromDate = CLOCKADJ(tstatus.creationDate);
1335 /* With RV_NOCLONE, just do a full copy from the source */
1340 #ifdef ENABLE_BUGFIX_1165
1342 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1343 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1344 * don't use this information...
1346 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1347 volumeInfo.volEntries_len = 0;
1348 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1350 "Failed to get the volint Info of the cloned volume %u\n",
1353 infop = (volintInfo *) volumeInfo.volEntries_val;
1354 infop->maxquota = -1; /* Else it will replace the default quota */
1355 infop->creationDate = -1; /* Else it will use the source creation date */
1356 infop->updateDate = -1; /* Else it will use the source update date */
1359 /* create a volume on the target machine */
1361 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1363 /* Delete the existing volume.
1364 * While we are deleting the volume in these steps, the transaction
1365 * we started against the cloned volume (clonetid above) will be
1366 * sitting idle. It will get cleaned up after 600 seconds
1368 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1369 code = AFSVolDeleteVolume(toconn, totid);
1371 "Could not delete the pre-existing volume %u on destination\n",
1376 ("Ending transaction on pre-existing volume %u on destination ...",
1378 code = AFSVolEndTrans(toconn, totid, &rcode);
1383 "Could not end the transaction on pre-existing volume %u on destination\n",
1388 VPRINT1("Creating the destination volume %u ...", volid);
1390 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1392 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1396 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1400 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1402 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1404 "Failed to set the flags on the destination volume %u\n", volid);
1408 * Now dump the clone to the new volume
1411 destination.destHost = ntohl(atoserver);
1412 destination.destPort = AFSCONF_VOLUMEPORT;
1413 destination.destSSID = 1;
1415 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1416 cookie.type = RWVOL;
1417 cookie.parent = entry.volumeId[RWVOL];
1420 if (!(flags & RV_NOCLONE)) {
1421 /* Copy the clone to the new volume */
1422 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1425 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1427 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1430 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1431 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1436 "Failed to end the transaction on the cloned volume %u\n",
1442 * reattach to the main-line volume, and incrementally dump it.
1445 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1446 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1448 "Failed to create a transaction on the source volume %u\n",
1452 /* now do the incremental */
1454 ("Doing the%s dump from source to destination for volume %u ... ",
1455 (flags & RV_NOCLONE) ? "" : " incremental",
1458 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1461 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1462 (flags & RV_NOCLONE) ? "" : " incremental");
1465 /* now adjust the flags so that the new volume becomes official */
1466 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1467 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1469 "Failed to set the flags to make old source volume offline\n");
1472 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1473 code = AFSVolSetFlags(toconn, totid, 0);
1475 "Failed to set the flags to make new source volume online\n");
1478 #ifdef ENABLE_BUGFIX_1165
1479 VPRINT1("Setting volume status on destination volume %u ...", volid);
1480 code = AFSVolSetInfo(toconn, totid, infop);
1482 "Failed to set volume status on the destination volume %u\n",
1487 /* put new volume online */
1488 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1489 code = AFSVolEndTrans(toconn, totid, &rcode);
1494 "Failed to end the transaction on the volume %u on the new site\n",
1498 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1499 MapNetworkToHost(&entry, &storeEntry);
1500 storeEntry.flags &= ~BACK_EXISTS;
1504 "Second test point - operation in progress but not complete.\n");
1505 fprintf(STDOUT, "...test here (y, n)? ");
1507 fscanf(stdin, "%c", &in);
1508 fscanf(stdin, "%c", &lf); /* toss away */
1510 fprintf(STDOUT, "type control-c\n");
1512 fprintf(stdout, ".");
1517 /* or drop through */
1520 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1522 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1523 (LOCKREL_OPCODE | LOCKREL_AFSID |
1524 LOCKREL_TIMESTAMP));
1527 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1528 storeEntry.name, (unsigned long)afromvol);
1537 "Third test point - operation complete but no cleanup.\n");
1538 fprintf(STDOUT, "...test here (y, n)? ");
1540 fscanf(stdin, "%c", &in);
1541 fscanf(stdin, "%c", &lf); /* toss away */
1543 fprintf(STDOUT, "type control-c\n");
1545 fprintf(stdout, ".");
1550 /* or drop through */
1553 /* This is tricky. File server is very stupid, and if you mark the volume
1554 * as VTOutOfService, it may mark the *good* instance (if you're moving
1555 * between partitions on the same machine) as out of service. Since
1556 * we're cleaning this code up in DEcorum, we're just going to kludge around
1557 * it for now by removing this call. */
1558 /* already out of service, just zap it now */
1560 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1563 "Failed to set the flags to make the old source volume offline\n");
1567 if (atoserver != afromserver) {
1568 /* set forwarding pointer for moved volumes */
1569 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1570 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1572 "Failed to set the forwarding pointer for the volume %u\n",
1577 VPRINT1("Deleting old volume %u on source ...", afromvol);
1578 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1579 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1583 VPRINT1("Ending transaction on old volume %u on the source ...",
1585 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1590 "Failed to end the transaction on the old volume %u on the source\n",
1594 /* Delete the backup volume on the original site */
1595 VPRINT1("Creating transaction for backup volume %u on source ...",
1598 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1601 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1603 AFSVolSetFlags(fromconn, fromtid,
1604 VTDeleteOnSalvage | VTOutOfService);
1606 "Failed to set the flags on the backup volume %u on the source\n",
1610 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1611 code = AFSVolDeleteVolume(fromconn, fromtid);
1613 "Failed to delete the backup volume %u on the source\n",
1617 VPRINT1("Ending transaction on backup volume %u on source ...",
1619 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1624 "Failed to end the transaction on the backup volume %u on the source\n",
1628 code = 0; /* no backup volume? that's okay */
1631 if (!(flags & RV_NOCLONE)) {
1632 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1634 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1637 "Failed to start a transaction on the cloned volume%u\n",
1641 /* now delete the clone */
1642 VPRINT1("Deleting the cloned volume %u ...", newVol);
1643 code = AFSVolDeleteVolume(fromconn, clonetid);
1644 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1648 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1649 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1654 "Failed to end the transaction on the cloned volume %u\n",
1663 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1664 fprintf(STDOUT, "...test here (y, n)? ");
1666 fscanf(stdin, "%c", &in);
1667 fscanf(stdin, "%c", &lf); /* toss away */
1669 fprintf(STDOUT, "type control-c\n");
1671 fprintf(stdout, ".");
1676 /* or drop through */
1679 /* normal cleanup code */
1681 if (entry.flags & RO_EXISTS)
1682 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1685 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1687 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1688 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1692 " Could not release the lock on the VLDB entry for the volume %lu \n",
1693 (unsigned long)afromvol);
1701 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1703 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1704 if (code || rcode) {
1707 "Could not end transaction on the source volume %lu\n",
1708 (unsigned long)afromvol);
1710 error = (code ? code : rcode);
1716 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1717 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1718 if (code || rcode) {
1721 "Could not end transaction on the source's clone volume %lu\n",
1722 (unsigned long)newVol);
1724 error = (code ? code : rcode);
1730 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1732 code = AFSVolEndTrans(toconn, totid, &rcode);
1736 "Could not end transaction on destination volume %lu\n",
1737 (unsigned long)afromvol);
1739 error = (code ? code : rcode);
1745 #ifdef ENABLE_BUGFIX_1165
1750 rx_DestroyConnection(fromconn);
1752 rx_DestroyConnection(toconn);
1753 PrintError("", error);
1756 /* come here only when the sky falls */
1761 "vos move: operation interrupted, cleanup in progress...\n");
1762 fprintf(STDOUT, "clear transaction contexts\n");
1766 /* unlock VLDB entry */
1768 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1769 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1770 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1775 VPRINT("Recovery: Ending transaction on clone volume ...");
1776 AFSVolEndTrans(fromconn, clonetid, &rcode);
1780 VPRINT("Recovery: Ending transaction on destination volume ...");
1781 AFSVolEndTrans(toconn, totid, &rcode);
1784 if (fromtid) { /* put it on-line */
1785 VPRINT("Recovery: Setting volume flags on source volume ...");
1786 AFSVolSetFlags(fromconn, fromtid, 0);
1789 VPRINT("Recovery: Ending transaction on source volume ...");
1790 AFSVolEndTrans(fromconn, fromtid, &rcode);
1794 VPRINT("Recovery: Accessing VLDB.\n");
1795 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1797 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1801 MapHostToNetwork(&entry);
1803 /* Delete either the volume on the source location or the target location.
1804 * If the vldb entry still points to the source location, then we know the
1805 * volume move didn't finish so we remove the volume from the target
1806 * location. Otherwise, we remove the volume from the source location.
1808 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1811 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1815 if (volid && toconn) {
1817 ("Recovery: Creating transaction for destination volume %u ...",
1820 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1826 ("Recovery: Setting flags on destination volume %u ...",
1828 AFSVolSetFlags(toconn, totid,
1829 VTDeleteOnSalvage | VTOutOfService);
1832 VPRINT1("Recovery: Deleting destination volume %u ...",
1834 AFSVolDeleteVolume(toconn, totid);
1838 ("Recovery: Ending transaction on destination volume %u ...",
1840 AFSVolEndTrans(toconn, totid, &rcode);
1844 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1849 /* put source volume on-line */
1851 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1854 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1859 VPRINT1("Recovery: Setting flags on source volume %u ...",
1861 AFSVolSetFlags(fromconn, fromtid, 0);
1865 ("Recovery: Ending transaction on source volume %u ...",
1867 AFSVolEndTrans(fromconn, fromtid, &rcode);
1871 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1875 } else { /* yep, move complete */
1878 "move complete - attempt cleanup of source partition - no guarantee\n");
1882 /* delete backup volume */
1884 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1887 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1892 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1894 AFSVolSetFlags(fromconn, fromtid,
1895 VTDeleteOnSalvage | VTOutOfService);
1898 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1899 AFSVolDeleteVolume(fromconn, fromtid);
1903 ("Recovery: Ending transaction on backup volume %u ...",
1905 AFSVolEndTrans(fromconn, fromtid, &rcode);
1909 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1913 /* delete source volume */
1914 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1917 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1922 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1924 AFSVolSetFlags(fromconn, fromtid,
1925 VTDeleteOnSalvage | VTOutOfService);
1928 if (atoserver != afromserver) {
1929 VPRINT("Recovery: Setting volume forwarding pointer ...");
1930 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1934 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1935 AFSVolDeleteVolume(fromconn, fromtid);
1939 ("Recovery: Ending transaction on source volume %u ...",
1941 AFSVolEndTrans(fromconn, fromtid, &rcode);
1945 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1951 /* common cleanup - delete local clone */
1953 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1956 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1961 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1962 AFSVolDeleteVolume(fromconn, clonetid);
1965 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1967 AFSVolEndTrans(fromconn, clonetid, &rcode);
1971 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1976 /* unlock VLDB entry */
1977 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
1979 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1980 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1983 done: /* routine cleanup */
1986 #ifdef ENABLE_BUGFIX_1165
1991 rx_DestroyConnection(fromconn);
1993 rx_DestroyConnection(toconn);
1996 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2004 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2005 afs_int32 atoserver, afs_int32 atopart)
2007 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2008 atoserver, atopart, 0);
2012 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2013 * <atopart>. The new volume is named by <atovolname>. The new volume
2014 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2015 * from the VLDB. the following flags are supported:
2017 * RV_RDONLY - target volume is RO
2018 * RV_OFFLINE - leave target volume offline
2019 * RV_CPINCR - do incremental dump if target exists
2020 * RV_NOVLDB - don't create/update VLDB entry
2021 * RV_NOCLONE - don't use a copy clone
2024 UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2025 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2026 afs_int32 atovolid, int flags)
2028 struct rx_connection *toconn, *fromconn;
2029 afs_int32 fromtid, totid, clonetid;
2032 afs_int32 fromDate, cloneFromDate;
2033 struct restoreCookie cookie;
2034 register afs_int32 vcode, code;
2035 afs_int32 cloneVol, newVol, volflag;
2036 struct volser_status tstatus;
2037 struct destServer destination;
2039 struct nvldbentry entry, newentry, storeEntry;
2045 fromconn = (struct rx_connection *)0;
2046 toconn = (struct rx_connection *)0;
2054 /* support control-c processing */
2057 (void)signal(SIGINT, sigint_handler);
2059 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2060 EGOTO1(mfail, vcode,
2061 "Could not fetch the entry for the volume %u from the VLDB \n",
2063 MapHostToNetwork(&entry);
2066 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2067 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2068 fromtid = totid = 0; /* initialize to uncreated */
2071 /* check if we can shortcut and use a local clone instead of a full copy */
2072 if (afromserver == atoserver && afrompart == atopart) {
2077 * clone the read/write volume locally.
2081 if (!(flags & RV_NOCLONE)) {
2082 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2083 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2085 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2089 /* Get a clone id */
2090 VPRINT1("Allocating new volume id for clone of volume %u ...",
2093 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2094 EGOTO1(mfail, vcode,
2095 "Could not get an ID for the clone of volume %u from the VLDB\n",
2103 /* Get a new volume id */
2104 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2106 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2107 EGOTO1(mfail, vcode,
2108 "Could not get an ID for the copy of volume %u from the VLDB\n",
2113 if (!(flags & RV_NOCLONE)) {
2114 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2115 VPRINT1("Cloning source volume %u ...", afromvol);
2116 strcpy(vname, "copy-clone-temp");
2118 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2120 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2124 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2126 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2131 "Failed to end the transaction on the source volume %u\n",
2137 * Create the destination volume
2140 if (!(flags & RV_NOCLONE)) {
2141 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2143 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2146 "Failed to start a transaction on the cloned volume%u\n",
2150 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2152 AFSVolSetFlags(fromconn, clonetid,
2153 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2154 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2158 /* remember time from which we've dumped the volume */
2159 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2160 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2162 "Failed to get the status of the cloned volume %u\n",
2166 fromDate = CLOCKADJ(tstatus.creationDate);
2171 /* create a volume on the target machine */
2173 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2175 if ((flags & RV_CPINCR)) {
2176 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2177 code = AFSVolGetStatus(toconn, totid, &tstatus);
2179 "Failed to get the status of the pre-existing volume %u\n",
2183 /* Using the update date should be OK here, but add some fudge */
2184 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2185 if ((flags & RV_NOCLONE))
2186 fromDate = cloneFromDate;
2188 /* XXX We should check that the source volume's creationDate is
2189 * XXX not newer than the existing target volume, and if not,
2190 * XXX throw away the existing target and do a full dump. */
2195 /* Delete the existing volume.
2196 * While we are deleting the volume in these steps, the transaction
2197 * we started against the cloned volume (clonetid above) will be
2198 * sitting idle. It will get cleaned up after 600 seconds
2200 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2201 code = AFSVolDeleteVolume(toconn, totid);
2203 "Could not delete the pre-existing volume %u on destination\n",
2208 ("Ending transaction on pre-existing volume %u on destination ...",
2210 code = AFSVolEndTrans(toconn, totid, &rcode);
2215 "Could not end the transaction on pre-existing volume %u on destination\n",
2220 VPRINT1("Creating the destination volume %u ...", newVol);
2222 AFSVolCreateVolume(toconn, atopart, atovolname,
2223 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2224 newVol, &newVol, &totid);
2225 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2229 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2231 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2233 "Failed to set the flags on the destination volume %u\n", newVol);
2238 destination.destHost = ntohl(atoserver);
2239 destination.destPort = AFSCONF_VOLUMEPORT;
2240 destination.destSSID = 1;
2242 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2243 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2248 * Now dump the clone to the new volume
2251 if (!(flags & RV_NOCLONE)) {
2252 /* XXX probably should have some code here that checks to see if
2253 * XXX we are copying to same server and partition - if so, just
2254 * XXX use a clone to save disk space */
2256 /* Copy the clone to the new volume */
2257 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2260 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2262 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2266 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2267 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2272 "Failed to end the transaction on the cloned volume %u\n",
2278 * reattach to the main-line volume, and incrementally dump it.
2281 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2282 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2284 "Failed to create a transaction on the source volume %u\n",
2288 /* now do the incremental */
2290 ("Doing the%s dump from source to destination for volume %u ... ",
2291 (flags & RV_NOCLONE) ? "" : " incremental",
2294 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2297 "Failed to do the%s dump from old site to new site\n",
2301 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2302 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2303 code = AFSVolSetFlags(toconn, totid, volflag);
2305 "Failed to set the flags to make destination volume online\n");
2308 /* put new volume online */
2309 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2310 code = AFSVolEndTrans(toconn, totid, &rcode);
2315 "Failed to end the transaction on the destination volume %u\n",
2319 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2320 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2325 "Failed to end the transaction on the source volume %u\n",
2331 if (!(flags & RV_NOCLONE)) {
2332 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2334 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2337 "Failed to start a transaction on the cloned volume%u\n",
2341 /* now delete the clone */
2342 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2343 code = AFSVolDeleteVolume(fromconn, clonetid);
2344 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2348 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2349 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2354 "Failed to end the transaction on the cloned volume %u\n",
2359 if (!(flags & RV_NOVLDB)) {
2360 /* create the vldb entry for the copied volume */
2361 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2362 newentry.nServers = 1;
2363 newentry.serverNumber[0] = atoserver;
2364 newentry.serverPartition[0] = atopart;
2365 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2366 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2367 newentry.volumeId[RWVOL] = newVol;
2368 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2369 newentry.volumeId[BACKVOL] = 0;
2370 newentry.cloneId = 0;
2371 /*map into right byte order, before passing to xdr, the stuff has to be in host
2372 * byte order. Xdr converts it into network order */
2373 MapNetworkToHost(&newentry, &storeEntry);
2374 /* create the vldb entry */
2375 vcode = VLDB_CreateEntry(&storeEntry);
2378 "Could not create a VLDB entry for the volume %s %lu\n",
2379 atovolname, (unsigned long)newVol);
2380 /*destroy the created volume */
2381 VPRINT1("Deleting the newly created volume %u\n", newVol);
2382 AFSVolDeleteVolume(toconn, totid);
2386 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2390 /* normal cleanup code */
2393 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2395 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2396 if (code || rcode) {
2399 "Could not end transaction on the source volume %lu\n",
2400 (unsigned long)afromvol);
2402 error = (code ? code : rcode);
2408 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2410 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2411 if (code || rcode) {
2414 "Could not end transaction on the source's clone volume %lu\n",
2415 (unsigned long)cloneVol);
2417 error = (code ? code : rcode);
2423 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2425 code = AFSVolEndTrans(toconn, totid, &rcode);
2429 "Could not end transaction on destination volume %lu\n",
2430 (unsigned long)newVol);
2432 error = (code ? code : rcode);
2437 rx_DestroyConnection(fromconn);
2439 rx_DestroyConnection(toconn);
2440 PrintError("", error);
2443 /* come here only when the sky falls */
2448 "vos copy: operation interrupted, cleanup in progress...\n");
2449 fprintf(STDOUT, "clear transaction contexts\n");
2454 VPRINT("Recovery: Ending transaction on clone volume ...");
2455 AFSVolEndTrans(fromconn, clonetid, &rcode);
2459 VPRINT("Recovery: Ending transaction on destination volume ...");
2460 AFSVolEndTrans(toconn, totid, &rcode);
2463 if (fromtid) { /* put it on-line */
2464 VPRINT("Recovery: Ending transaction on source volume ...");
2465 AFSVolEndTrans(fromconn, fromtid, &rcode);
2469 VPRINT("Recovery: Accessing VLDB.\n");
2470 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2472 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2476 MapHostToNetwork(&entry);
2478 /* common cleanup - delete local clone */
2480 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2483 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2488 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2489 AFSVolDeleteVolume(fromconn, clonetid);
2492 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2494 AFSVolEndTrans(fromconn, clonetid, &rcode);
2498 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2503 done: /* routine cleanup */
2505 rx_DestroyConnection(fromconn);
2507 rx_DestroyConnection(toconn);
2510 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2518 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2519 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2521 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2522 atovolname, atoserver, atopart, 0, 0);
2527 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2528 * if one already exists, update it
2532 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2534 struct rx_connection *aconn = (struct rx_connection *)0;
2535 afs_int32 ttid = 0, btid = 0;
2537 afs_int32 code = 0, rcode = 0;
2538 char vname[VOLSER_MAXVOLNAME + 1];
2539 struct nvldbentry entry, storeEntry;
2540 afs_int32 error = 0;
2541 int vldblocked = 0, vldbmod = 0, backexists = 1;
2543 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2545 /* the calls to VLDB will succeed only if avolid is a RW volume,
2546 * since we are following the RW hash chain for searching */
2547 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2550 "Could not fetch the entry for the volume %lu from the VLDB \n",
2551 (unsigned long)avolid);
2555 MapHostToNetwork(&entry);
2557 /* These operations require the VLDB be locked since it means the VLDB
2558 * will change or the vldb is already locked.
2560 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2561 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2562 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2564 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2567 "Could not lock the VLDB entry for the volume %lu\n",
2568 (unsigned long)avolid);
2574 /* Reread the vldb entry */
2575 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2578 "Could not fetch the entry for the volume %lu from the VLDB \n",
2579 (unsigned long)avolid);
2583 MapHostToNetwork(&entry);
2586 if (!ISNAMEVALID(entry.name)) {
2587 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2589 error = VOLSERBADNAME;
2593 backupID = entry.volumeId[BACKVOL];
2594 if (backupID == INVALID_BID) {
2595 /* Get a backup volume id from the VLDB and update the vldb
2598 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2601 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2602 (unsigned long)avolid);
2606 entry.volumeId[BACKVOL] = backupID;
2610 /* Test to see if the backup volume exists by trying to create
2611 * a transaction on the backup volume. We've assumed the backup exists.
2613 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2615 if (code != VNOVOL) {
2616 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2617 (unsigned long)backupID);
2621 backexists = 0; /* backup volume does not exist */
2624 code = AFSVolEndTrans(aconn, btid, &rcode);
2626 if (code || rcode) {
2628 "Could not end transaction on the previous backup volume %lu\n",
2629 (unsigned long)backupID);
2630 error = (code ? code : rcode);
2635 /* Now go ahead and try to clone the RW volume.
2636 * First start a transaction on the RW volume
2638 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2640 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2641 (unsigned long)avolid);
2646 /* Clone or reclone the volume, depending on whether the backup
2647 * volume exists or not
2650 VPRINT1("Re-cloning backup volume %u ...", backupID);
2652 code = AFSVolReClone(aconn, ttid, backupID);
2654 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2655 (unsigned long)backupID);
2660 VPRINT1("Creating a new backup clone %u ...", backupID);
2662 strcpy(vname, entry.name);
2663 strcat(vname, ".backup");
2665 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2667 fprintf(STDERR, "Failed to clone the volume %lu\n",
2668 (unsigned long)avolid);
2674 /* End the transaction on the RW volume */
2675 code = AFSVolEndTrans(aconn, ttid, &rcode);
2677 if (code || rcode) {
2679 "Failed to end the transaction on the rw volume %lu\n",
2680 (unsigned long)avolid);
2681 error = (code ? code : rcode);
2685 /* Mork vldb as backup exists */
2686 if (!(entry.flags & BACK_EXISTS)) {
2687 entry.flags |= BACK_EXISTS;
2691 /* Now go back to the backup volume and bring it on line */
2692 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2695 "Failed to start a transaction on the backup volume %lu\n",
2696 (unsigned long)backupID);
2701 code = AFSVolSetFlags(aconn, btid, 0);
2703 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2704 (unsigned long)backupID);
2709 code = AFSVolEndTrans(aconn, btid, &rcode);
2711 if (code || rcode) {
2713 "Failed to end the transaction on the backup volume %lu\n",
2714 (unsigned long)backupID);
2715 error = (code ? code : rcode);
2721 /* Will update the vldb below */
2725 code = AFSVolEndTrans(aconn, ttid, &rcode);
2726 if (code || rcode) {
2727 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2728 (unsigned long)avolid);
2730 error = (code ? code : rcode);
2735 code = AFSVolEndTrans(aconn, btid, &rcode);
2736 if (code || rcode) {
2738 "Could not end transaction the backup volume %lu\n",
2739 (unsigned long)backupID);
2741 error = (code ? code : rcode);
2745 /* Now update the vldb - if modified */
2748 MapNetworkToHost(&entry, &storeEntry);
2750 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2751 (LOCKREL_OPCODE | LOCKREL_AFSID |
2752 LOCKREL_TIMESTAMP));
2755 "Could not update the VLDB entry for the volume %lu \n",
2756 (unsigned long)avolid);
2762 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2763 (LOCKREL_OPCODE | LOCKREL_AFSID |
2764 LOCKREL_TIMESTAMP));
2767 "Could not unlock the VLDB entry for the volume %lu \n",
2768 (unsigned long)avolid);
2776 rx_DestroyConnection(aconn);
2778 PrintError("", error);
2782 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2783 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2784 * The new volume is named by <aname>, or by appending ".clone" to
2785 * the existing name if <aname> is NULL. The following flags are
2788 * RV_RDONLY - target volume is RO
2789 * RV_OFFLINE - leave target volume offline
2793 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
2794 afs_int32 acloneid, char *aname, int flags)
2796 struct rx_connection *aconn = (struct rx_connection *)0;
2797 afs_int32 ttid = 0, btid = 0;
2798 afs_int32 code = 0, rcode = 0;
2799 char vname[VOLSER_MAXVOLNAME + 1];
2800 afs_int32 error = 0;
2802 volEntries volumeInfo;
2804 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2807 volumeInfo.volEntries_val = (volintInfo *) 0;
2808 volumeInfo.volEntries_len = 0;
2809 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2811 fprintf(stderr, "Could not get info for volume %lu\n",
2812 (unsigned long)avolid);
2816 strncpy(vname, volumeInfo.volEntries_val[0].name,
2817 VOLSER_OLDMAXVOLNAME - 7);
2818 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2819 strcat(vname, ".clone");
2821 if (volumeInfo.volEntries_val)
2822 free(volumeInfo.volEntries_val);
2826 /* Get a clone id */
2827 VPRINT1("Allocating new volume id for clone of volume %u ...",
2829 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2831 "Could not get an ID for the clone of volume %u from the VLDB\n",
2836 /* Test to see if the clone volume exists by trying to create
2837 * a transaction on the clone volume. We've assumed the clone exists.
2839 /* XXX I wonder what happens if the clone has some other parent... */
2840 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2842 if (code != VNOVOL) {
2843 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2844 (unsigned long)acloneid);
2848 backexists = 0; /* backup volume does not exist */
2851 code = AFSVolEndTrans(aconn, btid, &rcode);
2853 if (code || rcode) {
2855 "Could not end transaction on the previous clone volume %lu\n",
2856 (unsigned long)acloneid);
2857 error = (code ? code : rcode);
2862 /* Now go ahead and try to clone the RW volume.
2863 * First start a transaction on the RW volume
2865 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2867 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2868 (unsigned long)avolid);
2873 /* Clone or reclone the volume, depending on whether the backup
2874 * volume exists or not
2877 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2879 code = AFSVolReClone(aconn, ttid, acloneid);
2881 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2882 (unsigned long)acloneid);
2887 VPRINT1("Creating a new clone %u ...", acloneid);
2889 code = AFSVolClone(aconn, ttid, 0,
2890 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2893 fprintf(STDERR, "Failed to clone the volume %lu\n",
2894 (unsigned long)avolid);
2900 /* End the transaction on the RW volume */
2901 code = AFSVolEndTrans(aconn, ttid, &rcode);
2903 if (code || rcode) {
2905 "Failed to end the transaction on the rw volume %lu\n",
2906 (unsigned long)avolid);
2907 error = (code ? code : rcode);
2911 /* Now go back to the backup volume and bring it on line */
2912 if (!(flags & RV_OFFLINE)) {
2913 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2916 "Failed to start a transaction on the clone volume %lu\n",
2917 (unsigned long)acloneid);
2922 code = AFSVolSetFlags(aconn, btid, 0);
2924 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2925 (unsigned long)acloneid);
2930 code = AFSVolEndTrans(aconn, btid, &rcode);
2932 if (code || rcode) {
2934 "Failed to end the transaction on the clone volume %lu\n",
2935 (unsigned long)acloneid);
2936 error = (code ? code : rcode);
2945 code = AFSVolEndTrans(aconn, ttid, &rcode);
2946 if (code || rcode) {
2947 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2948 (unsigned long)avolid);
2950 error = (code ? code : rcode);
2955 code = AFSVolEndTrans(aconn, btid, &rcode);
2956 if (code || rcode) {
2958 "Could not end transaction on the clone volume %lu\n",
2959 (unsigned long)acloneid);
2961 error = (code ? code : rcode);
2966 rx_DestroyConnection(aconn);
2968 PrintError("", error);
2973 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2976 afs_int32 acode, ccode, rcode, tid;
2977 ccode = rcode = tid = 0;
2979 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2980 if (!acode) { /* It really was there */
2981 acode = AFSVolDeleteVolume(conn, tid);
2983 fprintf(STDERR, "Failed to delete volume %lu.\n",
2984 (unsigned long)vid);
2985 PrintError("", acode);
2987 ccode = AFSVolEndTrans(conn, tid, &rcode);
2991 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
2992 (unsigned long)vid);
2993 PrintError("", ccode);
3000 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
3001 #define ERROREXIT(ec) { error = (ec); goto rfail; }
3003 /* Get a "transaction" on this replica. Create the volume
3004 * if necessary. Return the time from which a dump should
3005 * be made (0 if it's a new volume)
3008 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3009 struct rx_connection **connPtr, afs_int32 * transPtr,
3010 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3013 struct volser_status tstatus;
3014 int code, rcode, tcode;
3016 *connPtr = (struct rx_connection *)0;
3021 /* get connection to the replication site */
3022 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3024 goto fail; /* server is down */
3026 volid = vldbEntryPtr->volumeId[ROVOL];
3029 AFSVolTransCreate(*connPtr, volid,
3030 vldbEntryPtr->serverPartition[index], ITOffline,
3033 /* If the volume does not exist, create it */
3034 if (!volid || code) {
3037 if (volid && (code != VNOVOL)) {
3038 PrintError("Failed to start a transaction on the RO volume.\n",
3043 strcpy(volname, vldbEntryPtr->name);
3044 strcat(volname, ".readonly");
3048 "Creating new volume %lu on replication site %s: ",
3049 (unsigned long)volid,
3050 hostutil_GetNameByINet(vldbEntryPtr->
3051 serverNumber[index]));
3056 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3058 vldbEntryPtr->volumeId[RWVOL], &volid,
3061 PrintError("Failed to create the ro volume: ", code);
3064 vldbEntryPtr->volumeId[ROVOL] = volid;
3068 /* The following is a bit redundant, since create sets these flags by default */
3070 AFSVolSetFlags(*connPtr, *transPtr,
3071 VTDeleteOnSalvage | VTOutOfService);
3073 PrintError("Failed to set flags on the ro volume: ", code);
3078 /* Otherwise, the transaction did succeed, so get the creation date of the
3079 * latest RO volume on the replication site
3082 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3083 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3085 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3087 PrintError("Failed to get status of volume on destination: ",
3091 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3092 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3099 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3104 PrintError("Could not end transaction on a ro volume: ", tcode);
3111 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3112 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3113 void *cookie, manyResults * results)
3117 for (i = 0; i < tr->manyDests_len; i++) {
3118 results->manyResults_val[i] =
3119 AFSVolForward(fromconn, fromtid, fromdate,
3120 &(tr->manyDests_val[i].server),
3121 tr->manyDests_val[i].trans, cookie);
3127 /* UV_ReleaseVolume()
3128 * Release volume <afromvol> on <afromserver> <afrompart> to all
3129 * its RO sites (full release). Unless the previous release was
3130 * incomplete: in which case we bring the remaining incomplete
3131 * volumes up to date with the volumes that were released
3133 * forceflag: Performs a full release.
3135 * Will create a clone from the RW, then dump the clone out to
3136 * the remaining replicas. If there is more than 1 RO sites,
3137 * ensure that the VLDB says at least one RO is available all
3138 * the time: Influences when we write back the VLDB entry.
3142 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
3143 afs_int32 afrompart, int forceflag)
3146 afs_int32 code, vcode, rcode, tcode;
3147 afs_int32 cloneVolId, roVolId;
3148 struct replica *replicas = 0;
3149 struct nvldbentry entry, storeEntry;
3150 int i, volcount, m, fullrelease, vldbindex;
3152 struct restoreCookie cookie;
3153 struct rx_connection **toconns = 0;
3154 struct release *times = 0;
3156 struct rx_connection *fromconn = (struct rx_connection *)0;
3157 afs_int32 error = 0;
3159 afs_int32 clonetid = 0, onlinetid;
3160 afs_int32 fromtid = 0;
3161 afs_uint32 fromdate, thisdate;
3165 manyResults results;
3166 int rwindex, roindex, roclone, roexists;
3167 afs_int32 rwcrdate, rwupdate, clcrdate;
3171 } remembertime[NMAXNSERVERS];
3172 int releasecount = 0;
3173 struct volser_status volstatus;
3175 memset((char *)remembertime, 0, sizeof(remembertime));
3176 memset((char *)&results, 0, sizeof(results));
3178 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3179 if (vcode != VL_RERELEASE)
3180 ONERROR(vcode, afromvol,
3181 "Could not lock the VLDB entry for the volume %u.\n");
3184 /* Get the vldb entry in readable format */
3185 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3186 ONERROR(vcode, afromvol,
3187 "Could not fetch the entry for the volume %u from the VLDB.\n");
3188 MapHostToNetwork(&entry);
3191 EnumerateEntry(&entry);
3193 if (!ISNAMEVALID(entry.name))
3194 ONERROR(VOLSERBADOP, entry.name,
3195 "Volume name %s is too long, rename before releasing.\n");
3196 if (entry.volumeId[RWVOL] != afromvol)
3197 ONERROR(VOLSERBADOP, afromvol,
3198 "The volume %u being released is not a read-write volume.\n");
3199 if (entry.nServers <= 1)
3200 ONERROR(VOLSERBADOP, afromvol,
3201 "Volume %u has no replicas - release operation is meaningless!\n");
3202 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3203 ONERROR(VOLSERBADOP, entry.name,
3204 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3206 /* roclone is true if one of the RO volumes is on the same
3207 * partition as the RW volume. In this case, we make the RO volume
3208 * on the same partition a clone instead of a complete copy.
3211 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3212 roclone = ((roindex == -1) ? 0 : 1);
3213 rwindex = Lp_GetRwIndex(&entry);
3215 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3217 /* Make sure we have a RO volume id to work with */
3218 if (entry.volumeId[ROVOL] == INVALID_BID) {
3219 /* need to get a new RO volume id */
3220 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3221 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3223 entry.volumeId[ROVOL] = roVolId;
3224 MapNetworkToHost(&entry, &storeEntry);
3225 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3226 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3229 /* Will we be completing a previously unfinished release. -force overrides */
3230 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3231 if (entry.serverFlags[i] & ITSROVOL) {
3233 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3236 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3239 /* Determine which volume id to use and see if it exists */
3242 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3243 code = VolumeExists(afromserver, afrompart, cloneVolId);
3244 roexists = ((code == ENODEV) ? 0 : 1);
3246 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3248 ONERROR(-1, afromserver,
3249 "Cannot establish connection with server 0x%x\n");
3253 fullrelease = 1; /* Do a full release if RO clone does not exist */
3255 /* Begin transaction on RW and mark it busy while we query it */
3256 code = AFSVolTransCreate(
3257 fromconn, afromvol, afrompart, ITBusy, &fromtid
3259 ONERROR(code, afromvol,
3260 "Failed to start transaction on RW volume %u\n");
3262 /* Query the creation date for the RW */
3263 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3264 ONERROR(code, afromvol,
3265 "Failed to get the status of RW volume %u\n");
3266 rwcrdate = volstatus.creationDate;
3267 rwupdate = volstatus.updateDate;
3269 /* End transaction on RW */
3270 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3272 ONERROR((code ? code : rcode), afromvol,
3273 "Failed to end transaction on RW volume %u\n");
3275 /* Begin transaction on clone and mark it busy while we query it */
3276 code = AFSVolTransCreate(
3277 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3279 ONERROR(code, cloneVolId,
3280 "Failed to start transaction on RW clone %u\n");
3282 /* Query the creation date for the clone */
3283 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3284 ONERROR(code, cloneVolId,
3285 "Failed to get the status of RW clone %u\n");
3286 clcrdate = volstatus.creationDate;
3288 /* End transaction on clone */
3289 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3291 ONERROR((code ? code : rcode), cloneVolId,
3292 "Failed to end transaction on RW clone %u\n");
3294 if (rwcrdate > clcrdate)
3295 fullrelease = 2;/* Do a full release if RO clone older than RW */
3300 switch (fullrelease) {
3302 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3303 (unsigned long)afromvol);
3306 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3307 (unsigned long)afromvol);
3310 fprintf(STDOUT, "This is a completion of a previous release\n");
3316 /* If the RO clone exists, then if the clone is a temporary
3317 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3318 * (it was recently added), then also delete it. We do not
3319 * want to "reclone" a temporary RO clone.
3322 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3323 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3324 if (code && (code != VNOVOL))
3329 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3330 * write this entry out to the vlserver until after the first
3331 * RO volume is released (temp RO clones don't count).
3333 for (i = 0; i < entry.nServers; i++) {
3334 entry.serverFlags[i] &= ~NEW_REPSITE;
3335 entry.serverFlags[i] |= RO_DONTUSE;
3337 entry.serverFlags[rwindex] |= NEW_REPSITE;
3338 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3340 /* Begin transaction on RW and mark it busy while we clone it */
3342 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3344 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3346 /* Clone or reclone the volume */
3348 VPRINT1("Recloning RW volume %u...", cloneVolId);
3349 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3350 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3354 strcpy(vname, entry.name);
3355 strcat(vname, ".readonly");
3356 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3358 strcpy(vname, "readonly-clone-temp");
3359 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3362 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3364 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3368 /* Get the time the RW was created for future information */
3369 VPRINT1("Getting status of RW volume %u...", afromvol);
3370 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3371 ONERROR(code, afromvol,
3372 "Failed to get the status of the RW volume %u\n");
3374 rwcrdate = volstatus.creationDate;
3375 rwupdate = volstatus.updateDate;
3377 /* End the transaction on the RW volume */
3378 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3379 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3381 ONERROR((code ? code : rcode), afromvol,
3382 "Failed to end cloning transaction on RW %u\n");
3385 /* Remember clone volume ID in case we fail or are interrupted */
3386 entry.cloneId = cloneVolId;
3389 /* Bring the RO clone online - though not if it's a temporary clone */
3390 VPRINT1("Starting transaction on RO clone volume %u...",
3393 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3395 ONERROR(code, cloneVolId,
3396 "Failed to start transaction on volume %u\n");
3399 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3400 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3403 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3404 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3405 ONERROR((code ? code : rcode), cloneVolId,
3406 "Failed to end transaction on RO clone %u\n");
3409 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3411 /* Sleep so that a client searching for an online volume won't
3412 * find the clone offline and then the next RO offline while the
3413 * release brings the clone online and the next RO offline (race).
3414 * There is a fix in the 3.4 client that does not need this sleep
3415 * anymore, but we don't know what clients we have.
3417 if (entry.nServers > 2)
3420 /* Mark the RO clone in the VLDB as a good site (already released) */
3421 entry.serverFlags[roindex] |= NEW_REPSITE;
3422 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3423 entry.flags |= RO_EXISTS;
3427 /* Write out the VLDB entry only if the clone is not a temporary
3428 * clone. If we did this to a temporary clone then we would end
3429 * up marking all the ROs as "old release" making the ROs
3430 * temporarily unavailable.
3432 MapNetworkToHost(&entry, &storeEntry);
3433 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3434 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3435 ONERROR(vcode, entry.name,
3436 "Could not update vldb entry for %s.\n");
3441 /* Now we will release from the clone to the remaining RO replicas.
3442 * The first 2 ROs (counting the non-temporary RO clone) are released
3443 * individually: releasecount. This is to reduce the race condition
3444 * of clients trying to find an on-line RO volume. The remaining ROs
3445 * are released in parallel but no more than half the number of ROs
3446 * (rounded up) at a time: nservers.
3449 strcpy(vname, entry.name);
3450 strcat(vname, ".readonly");
3451 memset(&cookie, 0, sizeof(cookie));
3452 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3453 cookie.type = ROVOL;
3454 cookie.parent = entry.volumeId[RWVOL];
3457 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3459 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3460 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3462 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3464 results.manyResults_val =
3465 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3466 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3468 "Failed to create transaction on the release clone\n");
3470 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3471 memset(times, 0, (sizeof(struct release) * nservers + 1));
3472 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3473 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3475 /* Create a transaction on the cloned volume */
3476 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3478 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3479 if (!fullrelease && code)
3480 ONERROR(VOLSERNOVOL, afromvol,
3481 "Old clone is inaccessible. Try vos release -f %u.\n");
3482 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3485 /* For each index in the VLDB */
3486 for (vldbindex = 0; vldbindex < entry.nServers;) {
3488 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3490 ((volcount < nservers) && (vldbindex < entry.nServers));
3492 /* The first two RO volumes will be released individually.
3493 * The rest are then released in parallel. This is a hack
3494 * for clients not recognizing right away when a RO volume
3495 * comes back on-line.
3497 if ((volcount == 1) && (releasecount < 2))
3500 if (vldbindex == roindex)
3501 continue; /* the clone */
3502 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3503 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3505 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3506 continue; /* not a RO vol */
3509 /* Get a Transaction on this replica. Get a new connection if
3510 * necessary. Create the volume if necessary. Return the
3511 * time from which the dump should be made (0 if it's a new
3512 * volume). Each volume might have a different time.
3514 replicas[volcount].server.destHost =
3515 ntohl(entry.serverNumber[vldbindex]);
3516 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3517 replicas[volcount].server.destSSID = 1;
3518 times[volcount].vldbEntryIndex = vldbindex;
3521 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3522 &(replicas[volcount].trans),
3523 &(times[volcount].crtime),
3524 &(times[volcount].uptime));
3528 /* Thisdate is the date from which we want to pick up all changes */
3529 if (forceflag || !fullrelease
3530 || (rwcrdate > times[volcount].crtime)) {
3531 /* If the forceflag is set, then we want to do a full dump.
3532 * If it's not a full release, we can't be sure that the creation
3533 * date is good (so we also do a full dump).
3534 * If the RW volume was replaced (its creation date is newer than
3535 * the last release), then we can't be sure what has changed (so
3536 * we do a full dump).
3539 } else if (remembertime[vldbindex].validtime) {
3540 /* Trans was prev ended. Use the time from the prev trans
3541 * because, prev trans may have created the volume. In which
3542 * case time[volcount].time would be now instead of 0.
3545 (remembertime[vldbindex].uptime < times[volcount].uptime)
3546 ? remembertime[vldbindex].uptime
3547 : times[volcount].uptime;
3549 thisdate = times[volcount].uptime;
3551 remembertime[vldbindex].validtime = 1;
3552 remembertime[vldbindex].uptime = thisdate;
3554 if (volcount == 0) {
3555 fromdate = thisdate;
3557 /* Include this volume if it is within 15 minutes of the earliest */
3559 thisdate) ? (fromdate - thisdate) : (thisdate -
3561 AFSVolEndTrans(toconns[volcount],
3562 replicas[volcount].trans, &rcode);
3563 replicas[volcount].trans = 0;
3566 if (thisdate < fromdate)
3567 fromdate = thisdate;
3575 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3576 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3577 hostutil_GetNameByINet(entry.
3578 serverNumber[times[0].
3581 for (s = 1; s < volcount; s++) {
3582 fprintf(STDOUT, " and %s",
3583 hostutil_GetNameByINet(entry.
3584 serverNumber[times[s].
3589 fprintf(STDOUT, " (full release)");
3592 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3594 fprintf(STDOUT, ".\n");
3598 /* Release the ones we have collected */
3599 tr.manyDests_val = &(replicas[0]);
3600 tr.manyDests_len = results.manyResults_len = volcount;
3602 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3603 0 /*spare */ , &cookie, &results);
3604 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3606 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3607 0 /*spare */ , &cookie, &results);
3612 PrintError("Release failed: ", code);
3614 for (m = 0; m < volcount; m++) {
3615 if (results.manyResults_val[m]) {
3616 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3617 /* we retry timed out transaction. When it is
3618 * not the first volume and the transaction wasn't found
3619 * (assume it timed out and was garbage collected by volser).
3622 ("Failed to dump volume from clone to a ro site: ",
3623 results.manyResults_val[m]);
3629 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3630 ROVOL, entry.volumeId[RWVOL], 0, 0);
3632 if ((m == 0) || (code != ENOENT)) {
3633 PrintError("Failed to set correct names and ids: ",
3639 /* have to clear dest. flags to ensure new vol goes online:
3640 * because the restore (forwarded) operation copied
3641 * the V_inService(=0) flag over to the destination.
3643 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3645 if ((m == 0) || (code != ENOENT)) {
3646 PrintError("Failed to set flags on ro volume: ",
3652 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3653 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3654 entry.flags |= RO_EXISTS;
3659 /* End the transactions and destroy the connections */
3660 for (s = 0; s < volcount; s++) {
3661 if (replicas[s].trans)
3662 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3663 replicas[s].trans = 0;
3667 if ((s == 0) || (code != ENOENT)) {
3668 PrintError("Could not end transaction on a ro volume: ",
3672 ("Transaction timed out on a ro volume. Will retry.\n",
3674 if (times[s].vldbEntryIndex < vldbindex)
3675 vldbindex = times[s].vldbEntryIndex;
3680 rx_DestroyConnection(toconns[s]);
3684 MapNetworkToHost(&entry, &storeEntry);
3685 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3686 ONERROR(vcode, afromvol,
3687 " Could not update VLDB entry for volume %u\n");
3688 } /* for each index in the vldb */
3690 /* End the transaction on the cloned volume */
3691 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3696 PrintError("Failed to end transaction on rw volume: ", code);
3698 /* Figure out if any volume were not released and say so */
3699 for (failure = 0, i = 0; i < entry.nServers; i++) {
3700 if (!(entry.serverFlags[i] & NEW_REPSITE))
3706 "The volume %lu could not be released to the following %d sites:\n",
3707 (unsigned long)afromvol, failure);
3708 for (i = 0; i < entry.nServers; i++) {
3709 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3710 MapPartIdIntoName(entry.serverPartition[i], pname);
3711 fprintf(STDERR, "\t%35s %s\n",
3712 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3716 MapNetworkToHost(&entry, &storeEntry);
3718 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3720 ONERROR(vcode, afromvol,
3721 " Could not update VLDB entry for volume %u\n");
3723 ERROREXIT(VOLSERBADRELEASE);
3726 /* All the ROs were release successfully. Remove the temporary clone */
3729 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3730 (unsigned long)cloneVolId);
3733 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3734 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3739 for (i = 0; i < entry.nServers; i++)
3740 entry.serverFlags[i] &= ~NEW_REPSITE;
3742 /* Update the VLDB */
3743 VPRINT("updating VLDB ...");
3745 MapNetworkToHost(&entry, &storeEntry);
3747 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3748 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3749 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3754 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3758 "Failed to end cloning transaction on the RW volume %lu\n",
3759 (unsigned long)afromvol);
3765 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3769 "Failed to end transaction on the release clone %lu\n",
3770 (unsigned long)cloneVolId);
3775 for (i = 0; i < nservers; i++) {
3776 if (replicas && replicas[i].trans) {
3777 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3778 replicas[i].trans = 0;
3781 "Failed to end transaction on ro volume %u at server %s\n",
3782 entry.volumeId[ROVOL],
3783 hostutil_GetNameByINet(htonl
3784 (replicas[i].server.
3790 if (toconns && toconns[i]) {
3791 rx_DestroyConnection(toconns[i]);
3797 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3798 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3801 "Could not release lock on the VLDB entry for volume %lu\n",
3802 (unsigned long)afromvol);
3808 PrintError("", error);
3811 rx_DestroyConnection(fromconn);
3812 if (results.manyResults_val)
3813 free(results.manyResults_val);
3825 dump_sig_handler(int x)
3827 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3831 /* Dump the volume <afromvol> on <afromserver> and
3832 * <afrompart> to <afilename> starting from <fromdate>.
3833 * DumpFunction does the real work behind the scenes after
3834 * extracting parameters from the rock
3837 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3838 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock,
3841 struct rx_connection *fromconn = (struct rx_connection *)0;
3842 struct rx_call *fromcall = (struct rx_call *)0;
3843 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3844 afs_int32 code, error = 0, retry = 0;
3845 time_t tmv = fromdate;
3849 #ifndef AFS_NT40_ENV
3850 (void)signal(SIGPIPE, dump_sig_handler);
3852 (void)signal(SIGINT, dump_sig_handler);
3855 VPRINT("Full Dump ...\n");
3857 VPRINT1("Incremental Dump (as of %.24s)...\n",
3861 /* get connections to the servers */
3862 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3864 VPRINT1("Starting transaction on volume %u...", afromvol);
3865 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3866 EGOTO1(error_exit, code,
3867 "Could not start transaction on the volume %u to be dumped\n",
3871 fromcall = rx_NewCall(fromconn);
3873 VPRINT1("Starting volume dump on volume %u...", afromvol);
3874 if (flags & VOLDUMPV2_OMITDIRS)
3875 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
3878 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3879 EGOTO(error_exit, code, "Could not start the dump process \n");
3882 VPRINT1("Dumping volume %u...", afromvol);
3883 code = DumpFunction(fromcall, rock);
3884 if (code == RXGEN_OPCODE)
3886 EGOTO(error_exit, code, "Error while dumping volume \n");
3891 code = rx_EndCall(fromcall, rxError);
3892 if (code && code != RXGEN_OPCODE)
3893 fprintf(STDERR, "Error in rx_EndCall\n");
3898 VPRINT1("Ending transaction on volume %u...", afromvol);
3899 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3900 if (code || rcode) {
3901 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3902 (unsigned long)afromvol);
3904 error = (code ? code : rcode);
3909 rx_DestroyConnection(fromconn);
3913 if (error != RXGEN_OPCODE)
3914 PrintError("", error);
3918 /* Clone the volume <afromvol> on <afromserver> and
3919 * <afrompart>, and then dump the clone volume to
3920 * <afilename> starting from <fromdate>.
3921 * DumpFunction does the real work behind the scenes after
3922 * extracting parameters from the rock
3925 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3926 afs_int32 afrompart, afs_int32 fromdate,
3927 afs_int32(*DumpFunction) (), char *rock, afs_int32 flags)
3929 struct rx_connection *fromconn = (struct rx_connection *)0;
3930 struct rx_call *fromcall = (struct rx_call *)0;
3931 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3932 afs_int32 clonetid = 0;
3933 afs_int32 code = 0, vcode = 0, error = 0;
3934 afs_int32 clonevol = 0;
3936 time_t tmv = fromdate;
3940 #ifndef AFS_NT40_ENV
3941 (void)signal(SIGPIPE, dump_sig_handler);
3943 (void)signal(SIGINT, dump_sig_handler);
3946 VPRINT("Full Dump ...\n");
3948 VPRINT1("Incremental Dump (as of %.24s)...\n",
3952 /* get connections to the servers */
3953 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3955 VPRINT1("Starting transaction on volume %u...", afromvol);
3956 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3957 EGOTO1(error_exit, code,
3958 "Could not start transaction on the volume %u to be dumped\n",
3962 /* Get a clone id */
3963 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3964 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
3965 EGOTO1(error_exit, code,
3966 "Could not get an ID for the clone of volume %u from the VLDB\n",
3970 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3971 VPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3973 strcpy(vname, "dump-clone-temp");
3975 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3976 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3980 VPRINT1("Ending the transaction on the volume %u ...", afromvol);
3982 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3986 EGOTO1(error_exit, code,
3987 "Failed to end the transaction on the volume %u\n", afromvol);
3991 VPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
3993 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
3995 EGOTO1(error_exit, code,
3996 "Failed to start a transaction on the cloned volume%u\n",
4000 VPRINT1("Setting flags on cloned volume %u ...", clonevol);
4001 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
4002 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4007 fromcall = rx_NewCall(fromconn);
4009 VPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4010 if (flags & VOLDUMPV2_OMITDIRS)
4011 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4013 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4014 EGOTO(error_exit, code, "Could not start the dump process \n");
4017 VPRINT1("Dumping volume %u...", afromvol);
4018 code = DumpFunction(fromcall, rock);
4019 EGOTO(error_exit, code, "Error while dumping volume \n");
4023 /* now delete the clone */
4024 VPRINT1("Deleting the cloned volume %u ...", clonevol);
4025 code = AFSVolDeleteVolume(fromconn, clonetid);
4027 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4028 (unsigned long)clonevol);
4034 code = rx_EndCall(fromcall, rxError);
4036 fprintf(STDERR, "Error in rx_EndCall\n");
4042 VPRINT1("Ending transaction on cloned volume %u...", clonevol);
4043 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4044 if (code || rcode) {
4046 "Could not end transaction on the cloned volume %lu\n",
4047 (unsigned long)clonevol);
4049 error = (code ? code : rcode);
4054 rx_DestroyConnection(fromconn);
4056 PrintError("", error);
4063 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4064 * the dump file <afilename>. WriteData does all the real work
4065 * after extracting params from the rock
4068 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4069 afs_int32 toparentid, char tovolname[], int flags,
4070 afs_int32(*WriteData) (), char *rock)
4072 struct rx_connection *toconn, *tempconn;
4073 struct rx_call *tocall;
4074 afs_int32 totid, code, rcode, vcode, terror = 0;
4075 afs_int32 rxError = 0;
4076 struct volser_status tstatus;
4077 struct volintInfo vinfo;
4079 afs_int32 pvolid, pparentid;
4082 struct nvldbentry entry, storeEntry;
4085 struct restoreCookie cookie;
4087 afs_int32 volflag, voltype, volsertype;
4088 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4089 int index, same, errcode;
4093 memset(&cookie, 0, sizeof(cookie));
4098 tocall = (struct rx_call *)0;
4099 toconn = (struct rx_connection *)0;
4100 tempconn = (struct rx_connection *)0;
4104 if (flags & RV_RDONLY) {
4106 volsertype = volser_RO;
4109 volsertype = volser_RW;
4113 pparentid = toparentid;
4114 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4115 if (pvolid == 0) { /*alot a new id if needed */
4116 vcode = VLDB_GetEntryByName(tovolname, &entry);
4117 if (vcode == VL_NOENT) {
4118 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4120 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4126 } else if (flags & RV_RDONLY) {
4127 if (entry.flags & RW_EXISTS) {
4129 "Entry for ReadWrite volume %s already exists!\n",
4131 error = VOLSERBADOP;
4134 if (!entry.volumeId[ROVOL]) {
4136 "Existing entry for volume %s has no ReadOnly ID\n",
4138 error = VOLSERBADOP;
4141 pvolid = entry.volumeId[ROVOL];
4142 pparentid = entry.volumeId[RWVOL];
4144 pvolid = entry.volumeId[RWVOL];
4145 pparentid = entry.volumeId[RWVOL];
4148 if (!pparentid) pparentid = pvolid;
4149 /* at this point we have a volume id to use/reuse for the volume to be restored */
4150 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4151 EGOTO1(refail, VOLSERBADOP,
4152 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4155 MapPartIdIntoName(topart, partName);
4156 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4157 tovolname, (unsigned long)pvolid,
4158 hostutil_GetNameByINet(toserver), partName);
4161 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid, &pvolid,
4164 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4165 VPRINT1("Deleting the previous volume %u ...", pvolid);
4168 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4169 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4172 code = AFSVolGetStatus(toconn, totid, &tstatus);
4173 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4176 oldCreateDate = tstatus.creationDate;
4177 oldUpdateDate = tstatus.updateDate;
4180 AFSVolSetFlags(toconn, totid,
4181 VTDeleteOnSalvage | VTOutOfService);
4182 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4185 code = AFSVolDeleteVolume(toconn, totid);
4186 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4188 code = AFSVolEndTrans(toconn, totid, &rcode);
4192 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4197 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid,
4199 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4202 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4203 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4206 code = AFSVolGetStatus(toconn, totid, &tstatus);
4207 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4210 oldCreateDate = tstatus.creationDate;
4211 oldUpdateDate = tstatus.updateDate;
4218 cookie.parent = pparentid;
4219 cookie.type = voltype;
4221 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
4223 tocall = rx_NewCall(toconn);
4224 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4226 fprintf(STDERR, "Volume restore Failed \n");
4230 code = WriteData(tocall, rock);
4232 fprintf(STDERR, "Could not transmit data\n");
4236 terror = rx_EndCall(tocall, rxError);
4237 tocall = (struct rx_call *)0;
4239 fprintf(STDERR, "rx_EndCall Failed \n");
4243 code = AFSVolGetStatus(toconn, totid, &tstatus);
4246 "Could not get status information about the volume %lu\n",
4247 (unsigned long)pvolid);
4251 code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pparentid, 0, 0);
4253 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4254 (unsigned long)pvolid);
4259 if (flags & RV_CRDUMP)
4260 newCreateDate = tstatus.creationDate;
4261 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4262 newCreateDate = oldCreateDate;
4264 newCreateDate = time(0);
4265 if (flags & RV_LUDUMP)
4266 newUpdateDate = tstatus.updateDate;
4267 else if (flags & RV_LUKEEP)
4268 newUpdateDate = oldUpdateDate;
4270 newUpdateDate = time(0);
4271 code = AFSVolSetDate(toconn,totid, newCreateDate);
4273 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4278 init_volintInfo(&vinfo);
4279 vinfo.creationDate = newCreateDate;
4280 vinfo.updateDate = newUpdateDate;
4281 code = AFSVolSetInfo(toconn, totid, &vinfo);
4283 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4289 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4290 code = AFSVolSetFlags(toconn, totid, volflag);
4292 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4297 /* It isn't handled right in refail */
4298 code = AFSVolEndTrans(toconn, totid, &rcode);
4303 fprintf(STDERR, "Could not end transaction on %lu\n",
4304 (unsigned long)pvolid);
4310 fprintf(STDOUT, " done\n");
4312 if (success && (!reuseID || (flags & RV_FULLRST))) {
4313 /* Volume was restored on the file server, update the
4314 * VLDB to reflect the change.
4316 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4317 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4319 "Could not fetch the entry for volume number %lu from VLDB \n",
4320 (unsigned long)pvolid);
4325 MapHostToNetwork(&entry);
4326 if (vcode == VL_NOENT) { /* it doesnot exist already */
4327 /*make the vldb return this indication specifically */
4328 VPRINT("------- Creating a new VLDB entry ------- \n");
4329 strcpy(entry.name, tovolname);
4331 entry.serverNumber[0] = toserver; /*should be indirect */
4332 entry.serverPartition[0] = topart;
4333 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4334 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4335 if (flags & RV_RDONLY)
4336 entry.volumeId[ROVOL] = pvolid;
4337 else if (tstatus.cloneID != 0) {
4338 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4340 entry.volumeId[ROVOL] = INVALID_BID;
4341 entry.volumeId[RWVOL] = pparentid;
4343 if (tstatus.backupID != 0) {
4344 entry.volumeId[BACKVOL] = tstatus.backupID;
4345 /*this should come from status info on the volume if non zero */
4347 entry.volumeId[BACKVOL] = INVALID_BID;
4348 MapNetworkToHost(&entry, &storeEntry);
4349 vcode = VLDB_CreateEntry(&storeEntry);
4352 "Could not create the VLDB entry for volume number %lu \n",
4353 (unsigned long)pvolid);
4359 EnumerateEntry(&entry);
4360 } else { /*update the existing entry */
4362 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4363 fprintf(STDOUT, "------- Old entry -------\n");
4364 EnumerateEntry(&entry);
4365 fprintf(STDOUT, "------- New entry -------\n");
4368 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4372 "Could not lock the entry for volume number %lu \n",
4373 (unsigned long)pvolid);
4378 strcpy(entry.name, tovolname);
4380 /* Update the vlentry with the new information */
4381 if (flags & RV_RDONLY)
4382 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4384 index = Lp_GetRwIndex(&entry);
4386 /* Add the new site for the volume being restored */
4387 entry.serverNumber[entry.nServers] = toserver;
4388 entry.serverPartition[entry.nServers] = topart;
4389 entry.serverFlags[entry.nServers] =
4390 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4393 /* This volume should be deleted on the old site
4394 * if its different from new site.
4397 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4401 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4403 if ((!errcode && !same)
4404 || (entry.serverPartition[index] != topart)) {
4406 UV_Bind(entry.serverNumber[index],
4407 AFSCONF_VOLUMEPORT);
4409 MapPartIdIntoName(entry.serverPartition[index],
4412 ("Deleting the previous volume %u on server %s, partition %s ...",
4414 hostutil_GetNameByINet(entry.serverNumber[index]),
4417 AFSVolTransCreate(tempconn, pvolid,
4418 entry.serverPartition[index],
4419 ITOffline, &temptid);
4422 AFSVolSetFlags(tempconn, temptid,
4427 "Could not set flags on volume %lu on the older site\n",
4428 (unsigned long)pvolid);
4432 code = AFSVolDeleteVolume(tempconn, temptid);
4435 "Could not delete volume %lu on the older site\n",
4436 (unsigned long)pvolid);
4440 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4446 "Could not end transaction on volume %lu on the older site\n",
4447 (unsigned long)pvolid);
4452 MapPartIdIntoName(entry.serverPartition[index],
4456 entry.serverNumber[index] = toserver;
4457 entry.serverPartition[index] = topart;
4460 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4461 MapNetworkToHost(&entry, &storeEntry);
4463 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4464 LOCKREL_OPCODE | LOCKREL_AFSID |
4468 "Could not update the entry for volume number %lu \n",
4469 (unsigned long)pvolid);
4475 EnumerateEntry(&entry);
4482 code = rx_EndCall(tocall, rxError);
4488 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4489 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4492 "Could not release lock on the VLDB entry for the volume %lu\n",
4493 (unsigned long)pvolid);
4499 code = AFSVolEndTrans(toconn, totid, &rcode);
4503 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4504 (unsigned long)pvolid);
4510 code = AFSVolEndTrans(toconn, temptid, &rcode);
4514 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4515 (unsigned long)pvolid);
4521 rx_DestroyConnection(tempconn);
4523 rx_DestroyConnection(toconn);
4524 PrintError("", error);
4529 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4530 char tovolname[], int flags, afs_int32(*WriteData) (),
4533 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4538 /*unlocks the vldb entry associated with <volid> */
4540 UV_LockRelease(afs_int32 volid)
4546 VPRINT("Binding to the VLDB server\n");
4548 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4549 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4552 "Could not unlock the entry for volume number %lu in VLDB \n",
4553 (unsigned long)volid);
4554 PrintError("", vcode);
4557 VPRINT("VLDB updated\n");
4562 /*adds <server> and <part> as a readonly replication site for <volid>
4565 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4567 int j, nro = 0, islocked = 0;
4568 struct nvldbentry entry, storeEntry;
4569 afs_int32 vcode, error = 0;
4572 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4575 " Could not lock the VLDB entry for the volume %lu \n",
4576 (unsigned long)volid);
4581 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4584 "Could not fetch the VLDB entry for volume number %lu \n",
4585 (unsigned long)volid);
4589 if (!ISNAMEVALID(entry.name)) {
4591 "Volume name %s is too long, rename before adding site\n",
4593 error = VOLSERBADOP;
4596 MapHostToNetwork(&entry);
4598 /* See if it's too many entries */
4599 if (entry.nServers >= NMAXNSERVERS) {
4600 fprintf(STDERR, "Total number of entries will exceed %u\n",
4602 error = VOLSERBADOP;
4606 /* See if it's on the same server */
4607 for (j = 0; j < entry.nServers; j++) {
4608 if (entry.serverFlags[j] & ITSROVOL) {
4610 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4613 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4616 MapPartIdIntoName(entry.serverPartition[j], apartName);
4618 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4620 error = VOLSERBADOP;
4627 /* See if it's too many RO sites - leave one for the RW */
4628 if (nro >= NMAXNSERVERS - 1) {
4629 fprintf(STDERR, "Total number of sites will exceed %u\n",
4631 error = VOLSERBADOP;
4635 VPRINT("Adding a new site ...");
4636 entry.serverNumber[entry.nServers] = server;
4637 entry.serverPartition[entry.nServers] = part;
4638 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4641 MapNetworkToHost(&entry, &storeEntry);
4643 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4644 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4646 fprintf(STDERR, "Could not update entry for volume %lu \n",
4647 (unsigned long)volid);
4656 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4657 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4660 "Could not release lock on volume entry for %lu \n",
4661 (unsigned long)volid);
4662 PrintError("", vcode);
4666 PrintError("", error);
4670 /*removes <server> <part> as read only site for <volid> from the vldb */
4672 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4675 struct nvldbentry entry, storeEntry;
4678 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4680 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4681 (unsigned long)volid);
4682 PrintError("", vcode);
4686 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4689 "Could not fetch the entry for volume number %lu from VLDB \n",
4690 (unsigned long)volid);
4691 PrintError("", vcode);
4694 MapHostToNetwork(&entry);
4695 if (!Lp_ROMatch(server, part, &entry)) {
4696 /*this site doesnot exist */
4697 fprintf(STDERR, "This site is not a replication site \n");
4699 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4700 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4702 fprintf(STDERR, "Could not update entry for volume %lu \n",
4703 (unsigned long)volid);
4704 PrintError("", vcode);
4705 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4706 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4710 } else { /*remove the rep site */
4711 Lp_SetROValue(&entry, server, part, 0, 0);
4713 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4714 entry.flags &= ~RO_EXISTS;
4715 if (entry.nServers < 1) { /*this is the last ref */
4716 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4718 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4721 "Could not delete VLDB entry for volume %lu \n",
4722 (unsigned long)volid);
4723 PrintError("", vcode);
4728 MapNetworkToHost(&entry, &storeEntry);
4729 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4730 (unsigned long)volid);
4733 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4734 LOCKREL_OPCODE | LOCKREL_AFSID |
4738 "Could not release lock on volume entry for %lu \n",
4739 (unsigned long)volid);
4740 PrintError("", vcode);
4741 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4742 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4750 /*sets <server> <part> as read/write site for <volid> in the vldb */
4752 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4755 struct nvldbentry entry, storeEntry;
4758 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4760 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4761 (unsigned long)volid);
4762 PrintError("", vcode);
4765 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4768 "Could not fetch the entry for volume number %lu from VLDB \n",
4769 (unsigned long)volid);
4770 PrintError("", vcode);
4773 MapHostToNetwork(&entry);
4774 index = Lp_GetRwIndex(&entry);
4776 /* no RW site exists */
4777 fprintf(STDERR, "No existing RW site for volume %lu",
4778 (unsigned long)volid);
4780 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4781 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4784 "Could not release lock on entry for volume %lu \n",
4785 (unsigned long)volid);
4786 PrintError("", vcode);
4790 } else { /* change the RW site */
4791 entry.serverNumber[index] = server;
4792 entry.serverPartition[index] = part;
4793 MapNetworkToHost(&entry, &storeEntry);
4795 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4796 LOCKREL_OPCODE | LOCKREL_AFSID |
4799 fprintf(STDERR, "Could not update entry for volume %lu \n",
4800 (unsigned long)volid);
4801 PrintError("", vcode);
4802 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4803 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4811 /*list all the partitions on <aserver> */
4813 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4816 struct rx_connection *aconn;
4817 struct pIDs partIds;
4818 struct partEntries partEnts;
4819 register int i, j = 0, code;
4822 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4824 partEnts.partEntries_len = 0;
4825 partEnts.partEntries_val = NULL;
4826 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4827 if (code == RXGEN_OPCODE) {
4828 for (i = 0; i < 26; i++) /* try old interface */
4829 partIds.partIds[i] = -1;
4830 code = AFSVolListPartitions(aconn, &partIds);
4832 for (i = 0; i < 26; i++) {
4833 if ((partIds.partIds[i]) != -1) {
4834 ptrPartList->partId[j] = partIds.partIds[i];
4835 ptrPartList->partFlags[j] = PARTVALID;
4838 ptrPartList->partFlags[i] = 0;
4843 *cntp = partEnts.partEntries_len;
4844 if (*cntp > VOLMAXPARTS) {
4846 "Warning: number of partitions on the server too high %d (process only %d)\n",
4847 *cntp, VOLMAXPARTS);
4848 *cntp = VOLMAXPARTS;
4850 for (i = 0; i < *cntp; i++) {
4851 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4852 ptrPartList->partFlags[i] = PARTVALID;
4854 free(partEnts.partEntries_val);
4860 "Could not fetch the list of partitions from the server\n");
4861 PrintError("", code);
4863 rx_DestroyConnection(aconn);
4868 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4869 This is used by the backup system */
4871 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4872 struct volDescription *volPtr, afs_int32 arraySize)
4874 struct rx_connection *aconn;
4875 struct volDescription *curPtr;
4878 afs_int32 rcode = 0;
4879 afs_int32 success = 1;
4882 aconn = (struct rx_connection *)0;
4883 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4885 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4886 if (curPtr->volFlags & CLONEVALID) {
4887 curPtr->volFlags &= ~CLONEZAPPED;
4890 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4895 code = AFSVolDeleteVolume(aconn, tid);
4898 code = AFSVolEndTrans(aconn, tid, &rcode);
4903 curPtr->volFlags |= CLONEZAPPED;
4905 fprintf(STDERR, "Could not zap volume %lu\n",
4906 (unsigned long)curPtr->volCloneId);
4908 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4909 curPtr->volCloneId);
4915 rx_DestroyConnection(aconn);
4919 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4922 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4923 struct volDescription *volPtr, afs_int32 arraySize)
4925 struct rx_connection *aconn;
4926 struct volDescription *curPtr;
4929 afs_int32 rcode = 0;
4931 int reuseCloneId = 0;
4932 afs_int32 curCloneId = 0;
4933 char cloneName[256]; /*max vol name */
4935 aconn = (struct rx_connection *)0;
4936 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4938 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4940 else { /*get a bunch of id's from vldb */
4942 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
4944 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4945 PrintError("", code);
4950 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4951 if (curPtr->volFlags & ENTRYVALID) {
4953 curPtr->volFlags |= CLONEVALID;
4954 /*make a clone of curParentId and record as curPtr->volCloneId */
4956 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4959 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4962 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
4966 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
4967 strcpy(cloneName, curPtr->volName);
4968 strcat(cloneName, "-tmpClone-");
4970 strcpy(cloneName, "-tmpClone");
4972 curPtr->volCloneId = curCloneId;
4977 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
4978 &(curPtr->volCloneId));
4980 curPtr->volFlags &= ~CLONEVALID;
4982 fprintf(STDERR, "Could not clone %s due to error %lu\n",
4983 curPtr->volName, (unsigned long)code);
4984 code = AFSVolEndTrans(aconn, tid, &rcode);
4986 fprintf(STDERR, "WARNING: could not end transaction\n");
4989 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
4990 curPtr->volCloneId);
4991 code = AFSVolEndTrans(aconn, tid, &rcode);
4992 if (code || rcode) {
4993 curPtr->volFlags &= ~CLONEVALID;
5002 rx_DestroyConnection(aconn);
5007 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5008 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5010 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5011 struct volintInfo **resultPtr, afs_int32 * size)
5013 struct rx_connection *aconn;
5015 volEntries volumeInfo;
5019 *resultPtr = (volintInfo *) 0;
5020 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5021 volumeInfo.volEntries_len = 0;
5023 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5024 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5027 "Could not fetch the list of volumes from the server\n");
5029 *resultPtr = volumeInfo.volEntries_val;
5030 *size = volumeInfo.volEntries_len;
5034 rx_DestroyConnection(aconn);
5035 PrintError("", code);
5039 /*------------------------------------------------------------------------
5040 * EXPORTED UV_XListVolumes
5043 * List the extended information for all the volumes on a particular
5044 * File Server and partition. We may either return the volume's ID
5045 * or all of its extended information.
5048 * a_serverID : Address of the File Server for which we want
5049 * extended volume info.
5050 * a_partID : Partition for which we want the extended
5052 * a_all : If non-zero, fetch ALL the volume info,
5053 * otherwise just the volume ID.
5054 * a_resultPP : Ptr to the address of the area containing
5055 * the returned volume info.
5056 * a_numEntsInResultP : Ptr for the value we set for the number of
5061 * Otherise, the return value of AFSVolXListVolumes.
5064 * This routine is closely related to UV_ListVolumes, which returns
5065 * only the standard level of detail on AFS volumes. It is a
5066 * heavyweight operation, zipping through all the volume entries for
5067 * a given server/partition.
5071 *------------------------------------------------------------------------*/
5074 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5075 struct volintXInfo **a_resultPP,
5076 afs_int32 * a_numEntsInResultP)
5078 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5079 afs_int32 code; /*Error code to return */
5080 volXEntries volumeXInfo; /*Area for returned extended vol info */
5083 * Set up our error code and the area for returned extended volume info.
5084 * We set the val field to a null pointer as a hint for the stub to
5088 *a_numEntsInResultP = 0;
5089 *a_resultPP = (volintXInfo *) 0;
5090 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5091 volumeXInfo.volXEntries_len = 0;
5094 * Bind to the Volume Server port on the File Server machine in question,
5097 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5098 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5100 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5103 * We got the info; pull out the pointer to where the results lie
5104 * and how many entries are there.
5106 *a_resultPP = volumeXInfo.volXEntries_val;
5107 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5111 * If we got an Rx connection, throw it away.
5114 rx_DestroyConnection(rxConnP);
5116 PrintError("", code);
5118 } /*UV_XListVolumes */
5120 /* get all the information about volume <volid> on <aserver> and <apart> */
5122 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
5123 struct volintInfo **resultPtr)
5125 struct rx_connection *aconn;
5127 volEntries volumeInfo;
5131 *resultPtr = (volintInfo *) 0;
5132 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5133 volumeInfo.volEntries_len = 0;
5135 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5136 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5139 "Could not fetch the information about volume %lu from the server\n",
5140 (unsigned long)volid);
5142 *resultPtr = volumeInfo.volEntries_val;
5147 rx_DestroyConnection(aconn);
5148 PrintError("", code);
5152 /*------------------------------------------------------------------------
5153 * EXPORTED UV_XListOneVolume
5156 * List the extended information for a volume on a particular File
5157 * Server and partition.
5160 * a_serverID : Address of the File Server for which we want
5161 * extended volume info.
5162 * a_partID : Partition for which we want the extended
5164 * a_volID : Volume ID for which we want the info.
5165 * a_resultPP : Ptr to the address of the area containing
5166 * the returned volume info.
5170 * Otherise, the return value of AFSVolXListOneVolume.
5173 * This routine is closely related to UV_ListOneVolume, which returns
5174 * only the standard level of detail on the chosen AFS volume.
5178 *------------------------------------------------------------------------*/
5181 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
5182 struct volintXInfo **a_resultPP)
5184 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5185 afs_int32 code; /*Error code */
5186 volXEntries volumeXInfo; /*Area for returned info */
5189 * Set up our error code, and the area we're in which we are returning
5190 * the info. Setting the val field to a null pointer tells the stub
5191 * to allocate space for us.
5194 *a_resultPP = (volintXInfo *) 0;
5195 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5196 volumeXInfo.volXEntries_len = 0;
5199 * Bind to the Volume Server port on the File Server machine in question,
5202 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5203 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5206 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5209 * We got the info; pull out the pointer to where the results lie.
5211 *a_resultPP = volumeXInfo.volXEntries_val;
5214 * If we got an Rx connection, throw it away.
5217 rx_DestroyConnection(rxConnP);
5219 PrintError("", code);
5224 * Given a volume we read from a partition, check if it is
5225 * represented in the VLDB correctly.
5227 * The VLDB is looked up by the RW volume id (not its name).
5228 * The RW contains the true name of the volume (BK and RO set
5229 * the name in the VLDB only on creation of the VLDB entry).
5230 * We want rules strict enough that when we check all volumes
5231 * on one partition, it does not need to be done again. IE:
5232 * two volumes on different partitions won't constantly
5233 * change a VLDB entry away from what the other set.
5234 * For RW and BK volumes, we will always check the VLDB to see
5235 * if the two exist on the server/partition. May seem redundant,
5236 * but this is an easy check of the VLDB. IE: if the VLDB entry
5237 * says the BK exists but no BK volume is there, we will detect
5238 * this when we check the RW volume.
5239 * VLDB entries are locked only when a change needs to be done.
5240 * Output changed to look a lot like the "vos syncserv" otuput.
5243 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5244 afs_int32 * modentry, afs_uint32 * maxvolid)
5247 afs_int32 code, error = 0;
5248 struct nvldbentry entry, storeEntry;
5250 int pass = 0, islocked = 0, createentry, addvolume, modified, mod;
5256 ((volumeinfo->type ==
5257 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5260 /* Check to see if the VLDB is ok without locking it (pass 1).
5261 * If it will change, then lock the VLDB entry, read it again,
5262 * then make the changes to it (pass 2).
5265 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5267 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5268 (unsigned long)rwvolid);
5274 createentry = 0; /* Do we need to create a VLDB entry */
5275 addvolume = 0; /* Add this volume to the VLDB entry */
5276 modified = 0; /* The VLDB entry was modified */
5278 /* Read the entry from VLDB by its RW volume id */
5279 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5281 if (code != VL_NOENT) {
5283 "Could not retreive the VLDB entry for volume %lu \n",
5284 (unsigned long)rwvolid);
5288 memset(&entry, 0, sizeof(entry));
5289 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5293 MapHostToNetwork(&entry);
5296 if (verbose && (pass == 1)) {
5297 fprintf(STDOUT, "_______________________________\n");
5298 fprintf(STDOUT, "\n-- status before -- \n");
5300 fprintf(STDOUT, "\n**does not exist**\n");
5302 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5303 || (entry.flags & BACK_EXISTS))
5304 EnumerateEntry(&entry);
5306 fprintf(STDOUT, "\n");
5309 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5315 /* Check existence of RW and BK volumes */
5316 code = CheckVldbRWBK(&entry, &mod);
5322 idx = Lp_GetRwIndex(&entry);
5323 if (idx == -1) { /* RW index not found in the VLDB entry */
5324 idx = entry.nServers; /* put it into next index */
5327 } else { /* RW index found in the VLDB entry. */
5328 /* Verify if this volume's location matches where the VLDB says it is */
5329 if (!Lp_Match(aserver, apart, &entry)) {
5330 if (entry.flags & RW_EXISTS) {
5331 /* The RW volume exists elsewhere - report this one a duplicate */
5333 MapPartIdIntoName(apart, pname);
5335 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5336 (unsigned long)rwvolid,
5337 hostutil_GetNameByINet(aserver), pname);
5338 MapPartIdIntoName(entry.serverPartition[idx],
5341 " VLDB reports RW volume %lu exists on %s %s\n",
5342 (unsigned long)rwvolid,
5343 hostutil_GetNameByINet(entry.
5348 /* The RW volume does not exist - have VLDB point to this one */
5351 /* Check for orphaned BK volume on old partition */
5352 if (entry.flags & BACK_EXISTS) {
5354 MapPartIdIntoName(entry.serverPartition[idx],
5357 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5358 entry.volumeId[BACKVOL],
5359 hostutil_GetNameByINet(entry.
5362 MapPartIdIntoName(apart, pname);
5364 " VLDB reports its RW volume %lu exists on %s %s\n",
5365 (unsigned long)rwvolid,
5366 hostutil_GetNameByINet(aserver),
5372 /* Volume location matches the VLDB location */
5373 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5374 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5377 (entry.name, volumeinfo->name,
5378 VOLSER_OLDMAXVOLNAME) != 0)) {
5386 entry.flags |= RW_EXISTS;
5387 entry.volumeId[RWVOL] = rwvolid;
5388 if (!entry.volumeId[BACKVOL])
5389 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5390 if (!entry.volumeId[ROVOL])
5391 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5393 entry.serverFlags[idx] = ITSRWVOL;
5394 entry.serverNumber[idx] = aserver;
5395 entry.serverPartition[idx] = apart;
5396 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5400 /* One last check - to update BK if need to */
5401 code = CheckVldbRWBK(&entry, &mod);
5409 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5415 /* Check existence of RW and BK volumes */
5416 code = CheckVldbRWBK(&entry, &mod);
5422 idx = Lp_GetRwIndex(&entry);
5423 if (idx == -1) { /* RW index not found in the VLDB entry */
5424 idx = entry.nServers; /* Put it into next index */
5427 } else { /* RW index found in the VLDB entry */
5428 /* Verify if this volume's location matches where the VLDB says it is */
5429 if (!Lp_Match(aserver, apart, &entry)) {
5430 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5432 MapPartIdIntoName(apart, pname);
5434 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5435 (unsigned long)volumeinfo->volid,
5436 hostutil_GetNameByINet(aserver), pname);
5437 MapPartIdIntoName(entry.serverPartition[idx], pname);
5439 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5440 (unsigned long)rwvolid,
5441 hostutil_GetNameByINet(entry.
5446 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5447 if (!(entry.flags & BACK_EXISTS)) {
5449 } else if (volumeinfo->volid >
5450 entry.volumeId[BACKVOL]) {
5454 MapPartIdIntoName(entry.serverPartition[idx],
5457 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5458 entry.volumeId[BACKVOL],
5459 hostutil_GetNameByINet(aserver),
5462 " VLDB reports its BK volume ID is %lu\n",
5463 (unsigned long)volumeinfo->volid);
5467 MapPartIdIntoName(entry.serverPartition[idx],
5470 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5471 (unsigned long)volumeinfo->volid,
5472 hostutil_GetNameByINet(aserver),
5475 " VLDB reports its BK volume ID is %u\n",
5476 entry.volumeId[BACKVOL]);
5479 } else if (!entry.volumeId[BACKVOL]) {
5486 entry.flags |= BACK_EXISTS;
5487 entry.volumeId[RWVOL] = rwvolid;
5488 entry.volumeId[BACKVOL] = volumeinfo->volid;
5490 entry.serverNumber[idx] = aserver;
5491 entry.serverPartition[idx] = apart;
5492 entry.serverFlags[idx] = ITSRWVOL;
5498 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5499 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5500 /* This is a quick check to see if the RO entry exists in the
5501 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5502 * RO volume listed in the VLDB exists).
5504 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5506 idx = entry.nServers;
5510 if (!(entry.flags & RO_EXISTS)) {
5515 /* Before we correct the VLDB entry, make sure all the
5516 * ROs listed in the VLDB exist.
5518 code = CheckVldbRO(&entry, &mod);
5524 if (!(entry.flags & RO_EXISTS)) {
5525 /* No RO exists in the VLDB entry - add this one */
5526 idx = entry.nServers;
5529 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5530 /* The volume headers's RO ID does not match that in the VLDB entry,
5531 * and the vol hdr's ID is greater (implies more recent). So delete
5532 * all the RO volumes listed in VLDB entry and add this volume.
5534 for (j = 0; j < entry.nServers; j++) {
5535 if (entry.serverFlags[j] & ITSROVOL) {
5536 /* Verify this volume exists and print message we are orphaning it */
5538 MapPartIdIntoName(apart, pname);
5540 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5541 entry.volumeId[ROVOL],
5542 hostutil_GetNameByINet(entry.
5546 " VLDB reports its RO volume ID is %lu\n",
5547 (unsigned long)volumeinfo->volid);
5550 Lp_SetRWValue(entry, entry.serverNumber[idx],
5551 entry.serverPartition[idx], 0L, 0L);
5558 idx = entry.nServers;
5561 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5562 /* The volume headers's RO ID does not match that in the VLDB entry,
5563 * and the vol hdr's ID is lower (implies its older). So orphan it.
5566 MapPartIdIntoName(apart, pname);
5568 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5569 (unsigned long)volumeinfo->volid,
5570 hostutil_GetNameByINet(aserver), pname);
5572 " VLDB reports its RO volume ID is %u\n",
5573 entry.volumeId[ROVOL]);
5576 /* The RO volume ID in the volume header match that in the VLDB entry,
5577 * and there exist RO volumes in the VLDB entry. See if any of them
5578 * are this one. If not, then we add it.
5580 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5582 idx = entry.nServers;
5590 entry.flags |= RO_EXISTS;
5591 entry.volumeId[RWVOL] = rwvolid;
5592 entry.volumeId[ROVOL] = volumeinfo->volid;
5594 entry.serverNumber[idx] = aserver;
5595 entry.serverPartition[idx] = apart;
5596 entry.serverFlags[idx] = ITSROVOL;
5602 /* Remember largest volume id */
5603 if (entry.volumeId[ROVOL] > *maxvolid)
5604 *maxvolid = entry.volumeId[ROVOL];
5605 if (entry.volumeId[BACKVOL] > *maxvolid)
5606 *maxvolid = entry.volumeId[BACKVOL];
5607 if (entry.volumeId[RWVOL] > *maxvolid)
5608 *maxvolid = entry.volumeId[RWVOL];
5611 MapNetworkToHost(&entry, &storeEntry);
5614 code = VLDB_CreateEntry(&storeEntry);
5617 "Could not create a VLDB entry for the volume %lu\n",
5618 (unsigned long)rwvolid);
5625 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5626 LOCKREL_OPCODE | LOCKREL_AFSID |
5629 fprintf(STDERR, "Could not update entry for %lu\n",
5630 (unsigned long)rwvolid);
5635 *modentry = modified;
5636 } else if (pass == 2) {
5638 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5639 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5641 PrintError("Could not unlock VLDB entry ", code);
5646 fprintf(STDOUT, "-- status after --\n");
5648 EnumerateEntry(&entry);
5650 fprintf(STDOUT, "\n**no change**\n");
5654 VPRINT("\n_______________________________\n");
5659 sortVolumes(const void *a, const void *b)
5661 volintInfo *v1 = (volintInfo *) a;
5662 volintInfo *v2 = (volintInfo *) b;
5663 afs_int32 rwvolid1, rwvolid2;
5665 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5666 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5668 if (rwvolid1 > rwvolid2)
5669 return -1; /* lower RW id goes first */
5670 if (rwvolid1 < rwvolid2)
5673 if (v1->type == RWVOL)
5674 return -1; /* RW vols go first */
5675 if (v2->type == RWVOL)
5678 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5679 return -1; /* BK vols next */
5680 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5683 if (v1->volid < v2->volid)
5684 return 1; /* larger volids first */
5685 if (v1->volid > v2->volid)
5691 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5692 * Synchronize an individual volume against a sever and partition.
5693 * Checks the VLDB entry (similar to syncserv) as well as checks
5694 * if the volume exists on specified servers (similar to syncvldb).
5697 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5699 struct rx_connection *aconn = 0;
5700 afs_int32 j, k, code, vcode, error = 0;
5701 afs_int32 tverbose, mod, modified = 0;
5702 struct nvldbentry vldbentry;
5703 afs_int32 volumeid = 0;
5704 volEntries volumeInfo;
5705 struct partList PartList;
5707 afs_int32 maxvolid = 0;
5709 volumeInfo.volEntries_val = (volintInfo *) 0;
5710 volumeInfo.volEntries_len = 0;
5712 if (!aserver && flags) {
5713 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5717 /* Turn verbose logging off and do our own verbose logging */
5721 /* Read the VLDB entry */
5722 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5723 if (vcode && (vcode != VL_NOENT)) {
5724 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5727 } else if (!vcode) {
5728 MapHostToNetwork(&vldbentry);
5732 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5733 fprintf(STDOUT, "_______________________________\n");
5734 fprintf(STDOUT, "\n-- status before -- \n");
5736 fprintf(STDOUT, "\n**does not exist**\n");
5738 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5739 || (vldbentry.flags & BACK_EXISTS))
5740 EnumerateEntry(&vldbentry);
5742 fprintf(STDOUT, "\n");
5745 /* Verify that all of the VLDB entries exist on the repective servers
5746 * and partitions (this does not require that avolname be a volume ID).
5747 * Equivalent to a syncserv.
5750 code = CheckVldb(&vldbentry, &mod);
5752 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5760 /* If aserver is given, we will search for the desired volume on it */
5762 /* Generate array of partitions on the server that we will check */
5764 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5767 "Could not fetch the list of partitions from the server\n");
5771 PartList.partId[0] = apart;
5775 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5777 /* If a volume ID were given, search for it on each partition */
5778 if ((volumeid = atol(avolname))) {
5779 for (j = 0; j < pcnt; j++) {
5781 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5784 if (code != ENODEV) {
5785 fprintf(STDERR, "Could not query server\n");
5789 /* Found one, sync it with VLDB entry */
5791 CheckVolume(volumeInfo.volEntries_val, aserver,
5792 PartList.partId[j], &mod, &maxvolid);
5799 if (volumeInfo.volEntries_val)
5800 free(volumeInfo.volEntries_val);
5801 volumeInfo.volEntries_val = (volintInfo *) 0;
5802 volumeInfo.volEntries_len = 0;
5806 /* Check to see if the RW, BK, and RO IDs exist on any
5807 * partitions. We get the volume IDs from the VLDB.
5809 rv = 1; /* Read the VLDB entry ? */
5810 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5812 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5814 if (vcode == VL_NOENT)
5817 "Could not access the VLDB for volume %s\n",
5824 if (vldbentry.volumeId[j] == 0)
5827 for (k = 0; k < pcnt; k++) { /* For each partition */
5828 volumeInfo.volEntries_val = (volintInfo *) 0;
5829 volumeInfo.volEntries_len = 0;
5831 AFSVolListOneVolume(aconn, PartList.partId[k],
5832 vldbentry.volumeId[j], &volumeInfo);
5834 if (code != ENODEV) {
5835 fprintf(STDERR, "Could not query server\n");
5839 /* Found one, sync it with VLDB entry */
5841 CheckVolume(volumeInfo.volEntries_val, aserver,
5842 PartList.partId[k], &mod, &maxvolid);
5849 if (volumeInfo.volEntries_val)
5850 free(volumeInfo.volEntries_val);
5851 volumeInfo.volEntries_val = (volintInfo *) 0;
5852 volumeInfo.volEntries_len = 0;
5858 /* If verbose output, print a summary of what changed */
5860 fprintf(STDOUT, "-- status after --\n");
5861 code = VLDB_GetEntryByName(avolname, &vldbentry);
5862 if (code && (code != VL_NOENT)) {
5863 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5867 if (modified && (code == VL_NOENT)) {
5868 fprintf(STDOUT, "\n**entry deleted**\n");
5869 } else if (modified) {
5870 EnumerateEntry(&vldbentry);
5872 fprintf(STDOUT, "\n**no change**\n");
5874 fprintf(STDOUT, "\n_______________________________\n");
5878 /* Now check if the maxvolid is larger than that stored in the VLDB */
5880 afs_int32 maxvldbid = 0;
5881 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
5884 "Could not get the highest allocated volume id from the VLDB\n");
5887 } else if (maxvolid > maxvldbid) {
5889 id = maxvolid - maxvldbid + 1;
5890 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
5893 "Error in increasing highest allocated volume id in VLDB\n");
5903 fprintf(STDOUT, "...error encountered");
5905 fprintf(STDOUT, "...done entry\n");
5908 rx_DestroyConnection(aconn);
5909 if (volumeInfo.volEntries_val)
5910 free(volumeInfo.volEntries_val);
5912 PrintError("", error);
5917 * Synchronise vldb with the file server <aserver> and,
5918 * optionally, <apart>.
5921 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5923 struct rx_connection *aconn;
5924 afs_int32 code, error = 0;
5926 volEntries volumeInfo;
5927 struct partList PartList;
5931 afs_int32 failures = 0, modifications = 0, tentries = 0;
5933 afs_uint32 maxvolid = 0;
5935 volumeInfo.volEntries_val = (volintInfo *) 0;
5936 volumeInfo.volEntries_len = 0;
5938 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5940 /* Generate array of partitions to check */
5942 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5945 "Could not fetch the list of partitions from the server\n");
5949 PartList.partId[0] = apart;
5953 VPRINT("Processing volume entries ...\n");
5955 /* Step through the array of partitions */
5956 for (i = 0; i < pcnt; i++) {
5957 apart = PartList.partId[i];
5958 MapPartIdIntoName(apart, pname);
5960 volumeInfo.volEntries_val = (volintInfo *) 0;
5961 volumeInfo.volEntries_len = 0;
5962 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
5965 "Could not fetch the list of volumes from the server\n");
5969 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
5970 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
5971 sizeof(volintInfo), sortVolumes);
5974 for (vi = volumeInfo.volEntries_val, j = 0;
5975 j < volumeInfo.volEntries_len; j++, vi++) {
5983 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
5984 j + 1, vi->name, (unsigned long)vi->volid,
5985 hostutil_GetNameByINet(aserver), pname);
5989 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
5991 PrintError("", code);
5994 } else if (modified) {
6000 fprintf(STDOUT, "...error encountered\n\n");
6002 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6009 "Could not process entries on server %s partition %s\n",
6010 hostutil_GetNameByINet(aserver), pname);
6012 if (volumeInfo.volEntries_val) {
6013 free(volumeInfo.volEntries_val);
6014 volumeInfo.volEntries_val = 0;
6017 } /* thru all partitions */
6019 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6020 failures, modifications);
6023 /* Now check if the maxvolid is larger than that stored in the VLDB */
6025 afs_int32 maxvldbid = 0;
6026 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6029 "Could not get the highest allocated volume id from the VLDB\n");
6032 } else if (maxvolid > maxvldbid) {
6034 id = maxvolid - maxvldbid + 1;
6035 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6038 "Error in increasing highest allocated volume id in VLDB\n");
6046 rx_DestroyConnection(aconn);
6047 if (volumeInfo.volEntries_val)
6048 free(volumeInfo.volEntries_val);
6049 PrintError("", error);
6054 * Determine if a volume exists on a server and partition.
6055 * Try creating a transaction on the volume. If we can,
6056 * the volume exists, if not, then return the error code.
6057 * Some error codes mean the volume is unavailable but
6058 * still exists - so we catch these error codes.
6061 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
6063 struct rx_connection *conn = (struct rx_connection *)0;
6064 afs_int32 code = -1;
6065 volEntries volumeInfo;
6067 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6069 volumeInfo.volEntries_val = (volintInfo *) 0;
6070 volumeInfo.volEntries_len = 0;
6071 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6072 if (volumeInfo.volEntries_val)
6073 free(volumeInfo.volEntries_val);
6074 if (code == VOLSERILLEGAL_PARTITION)
6076 rx_DestroyConnection(conn);
6085 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6089 afs_int32 code, error = 0;
6094 idx = Lp_GetRwIndex(entry);
6096 /* Check to see if the RW volume exists and set the RW_EXISTS
6099 if (idx == -1) { /* Did not find a RW entry */
6100 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6101 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6106 VolumeExists(entry->serverNumber[idx],
6107 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6108 if (code == 0) { /* RW volume exists */
6109 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6110 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6113 } else if (code == ENODEV) { /* RW volume does not exist */
6114 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6115 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6119 /* If VLDB says it didn't exist, then ignore error */
6120 if (entry->flags & RW_EXISTS) {
6121 MapPartIdIntoName(entry->serverPartition[idx], pname);
6123 "Transaction call failed for RW volume %u on server %s %s\n",
6124 entry->volumeId[RWVOL],
6125 hostutil_GetNameByINet(entry->serverNumber[idx]),
6132 /* Check to see if the BK volume exists and set the BACK_EXISTS
6133 * flag accordingly. idx already ponts to the RW entry.
6135 if (idx == -1) { /* Did not find a RW entry */
6136 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6137 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6140 } else { /* Found a RW entry */
6142 VolumeExists(entry->serverNumber[idx],
6143 entry->serverPartition[idx],
6144 entry->volumeId[BACKVOL]);
6145 if (code == 0) { /* BK volume exists */
6146 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6147 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6150 } else if (code == ENODEV) { /* BK volume does not exist */
6151 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6152 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6156 /* If VLDB says it didn't exist, then ignore error */
6157 if (entry->flags & BACK_EXISTS) {
6158 MapPartIdIntoName(entry->serverPartition[idx], pname);
6160 "Transaction call failed for BK volume %u on server %s %s\n",
6161 entry->volumeId[BACKVOL],
6162 hostutil_GetNameByINet(entry->serverNumber[idx]),
6169 /* If there is an idx but the BK and RW volumes no
6170 * longer exist, then remove the RW entry.
6172 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6173 && !(entry->flags & BACK_EXISTS)) {
6174 Lp_SetRWValue(entry, entry->serverNumber[idx],
6175 entry->serverPartition[idx], 0L, 0L);
6182 *modified = modentry;
6187 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6190 int foundro = 0, modentry = 0;
6191 afs_int32 code, error = 0;
6197 /* Check to see if the RO volumes exist and set the RO_EXISTS
6200 for (idx = 0; idx < entry->nServers; idx++) {
6201 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6202 continue; /* not a RO */
6206 VolumeExists(entry->serverNumber[idx],
6207 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6208 if (code == 0) { /* RO volume exists */
6210 } else if (code == ENODEV) { /* RW volume does not exist */
6211 Lp_SetROValue(entry, entry->serverNumber[idx],
6212 entry->serverPartition[idx], 0L, 0L);
6217 MapPartIdIntoName(entry->serverPartition[idx], pname);
6219 "Transaction call failed for RO %u on server %s %s\n",
6220 entry->volumeId[ROVOL],
6221 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6226 if (foundro) { /* A RO volume exists */
6227 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6228 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6231 } else { /* A RO volume does not exist */
6232 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6233 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6240 *modified = modentry;
6245 * Ensure that <entry> matches with the info on file servers
6248 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6250 afs_int32 code, error = 0;
6251 struct nvldbentry storeEntry;
6252 int islocked = 0, mod, modentry, delentry = 0;
6258 fprintf(STDOUT, "_______________________________\n");
6259 fprintf(STDOUT, "\n-- status before -- \n");
6260 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6261 || (entry->flags & BACK_EXISTS))
6262 EnumerateEntry(entry);
6263 fprintf(STDOUT, "\n");
6266 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6267 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6268 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6272 /* Check to see if the VLDB is ok without locking it (pass 1).
6273 * If it will change, then lock the VLDB entry, read it again,
6274 * then make the changes to it (pass 2).
6278 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6281 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6282 entry->volumeId[RWVOL]);
6287 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6289 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6293 MapHostToNetwork(entry);
6299 /* Check if the RW and BK entries are ok */
6300 code = CheckVldbRWBK(entry, &mod);
6303 if (mod && (pass == 1))
6308 /* Check if the RO volumes entries are ok */
6309 code = CheckVldbRO(entry, &mod);
6312 if (mod && (pass == 1))
6317 /* The VLDB entry has been updated. If it as been modified, then
6318 * write the entry back out the the VLDB.
6324 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6325 && !(entry->flags & RO_EXISTS)) {
6326 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6328 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6332 "Could not delete VLDB entry for volume %u \n",
6333 entry->volumeId[RWVOL]);
6338 /* Replace old entry with our new one */
6339 MapNetworkToHost(entry, &storeEntry);
6341 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6342 (LOCKREL_OPCODE | LOCKREL_AFSID |
6343 LOCKREL_TIMESTAMP));
6345 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6346 entry->volumeId[RWVOL]);
6356 fprintf(STDOUT, "-- status after --\n");
6358 fprintf(STDOUT, "\n**entry deleted**\n");
6360 EnumerateEntry(entry);
6362 fprintf(STDOUT, "\n**no change**\n");
6366 VPRINT("\n_______________________________\n");
6370 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6372 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6375 "Could not release lock on VLDB entry for volume %u\n",
6376 entry->volumeId[RWVOL]);
6385 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6388 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6390 struct rx_connection *aconn;
6391 afs_int32 code, error = 0;
6392 afs_int32 nentries, tentries = 0;
6393 struct VldbListByAttributes attributes;
6394 nbulkentries arrayEntries;
6395 afs_int32 failures = 0, modified, modifications = 0;
6396 struct nvldbentry *vlentry;
6397 afs_int32 si, nsi, j;
6399 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6401 /* Set up attributes to search VLDB */
6402 attributes.server = ntohl(aserver);
6403 attributes.Mask = VLLIST_SERVER;
6405 attributes.partition = apart;
6406 attributes.Mask |= VLLIST_PARTITION;
6409 VPRINT("Processing VLDB entries ...\n");
6411 /* While we need to collect more VLDB entries */
6412 for (si = 0; si != -1; si = nsi) {
6413 memset(&arrayEntries, 0, sizeof(arrayEntries));
6415 /* Collect set of VLDB entries */
6417 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6418 &arrayEntries, &nsi);
6419 if (code == RXGEN_OPCODE) {
6420 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6424 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6427 tentries += nentries;
6429 for (j = 0; j < nentries; j++) {
6430 vlentry = &arrayEntries.nbulkentries_val[j];
6431 MapHostToNetwork(vlentry);
6433 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6435 code = CheckVldb(vlentry, &modified);
6437 PrintError("", code);
6439 "Could not process VLDB entry for volume %s\n",
6442 } else if (modified) {
6448 fprintf(STDOUT, "...error encountered\n\n");
6450 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6455 if (arrayEntries.nbulkentries_val) {
6456 free(arrayEntries.nbulkentries_val);
6457 arrayEntries.nbulkentries_val = 0;
6461 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6462 failures, modifications);
6466 rx_DestroyConnection(aconn);
6467 if (arrayEntries.nbulkentries_val)
6468 free(arrayEntries.nbulkentries_val);
6471 error = VOLSERFAILEDOP;
6475 /*rename volume <oldname> to <newname>, changing the names of the related
6476 *readonly and backup volumes. This operation is also idempotent.
6477 *salvager is capable of recovering from rename operation stopping halfway.
6478 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6480 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6482 struct nvldbentry storeEntry;
6483 afs_int32 vcode, code, rcode, error;
6485 char nameBuffer[256];
6487 struct rx_connection *aconn;
6491 aconn = (struct rx_connection *)0;
6495 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6498 " Could not lock the VLDB entry for the volume %u \n",
6499 entry->volumeId[RWVOL]);
6504 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6505 MapNetworkToHost(entry, &storeEntry);
6506 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6508 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6509 entry->volumeId[RWVOL]);
6513 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6514 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6515 * is concerned, oldname is lost */
6516 if (entry->flags & RW_EXISTS) {
6517 index = Lp_GetRwIndex(entry);
6518 if (index == -1) { /* there is a serious discrepancy */
6520 "There is a serious discrepancy in VLDB entry for volume %u\n",
6521 entry->volumeId[RWVOL]);
6522 fprintf(STDERR, "try building VLDB from scratch\n");
6523 error = VOLSERVLDB_ERROR;
6526 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6528 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6529 entry->serverPartition[index], ITOffline, &tid);
6530 if (code) { /*volume doesnot exist */
6532 "Could not start transaction on the rw volume %u\n",
6533 entry->volumeId[RWVOL]);
6536 } else { /*volume exists, process it */
6539 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6540 entry->volumeId[RWVOL],
6541 entry->volumeId[ROVOL],
6542 entry->volumeId[BACKVOL]);
6544 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6545 code = AFSVolEndTrans(aconn, tid, &rcode);
6549 "Could not end transaction on volume %s %u\n",
6550 entry->name, entry->volumeId[RWVOL]);
6555 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6556 entry->name, entry->volumeId[RWVOL]);
6562 rx_DestroyConnection(aconn);
6563 aconn = (struct rx_connection *)0;
6565 /*end rw volume processing */
6566 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6567 index = Lp_GetRwIndex(entry);
6568 if (index == -1) { /* there is a serious discrepancy */
6570 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6571 entry->volumeId[BACKVOL]);
6572 fprintf(STDERR, "try building VLDB from scratch\n");
6573 error = VOLSERVLDB_ERROR;
6576 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6578 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6579 entry->serverPartition[index], ITOffline, &tid);
6580 if (code) { /*volume doesnot exist */
6582 "Could not start transaction on the backup volume %u\n",
6583 entry->volumeId[BACKVOL]);
6586 } else { /*volume exists, process it */
6587 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6589 "Volume name %s.backup exceeds the limit of %u characters\n",
6590 newname, VOLSER_OLDMAXVOLNAME);
6594 strcpy(nameBuffer, newname);
6595 strcat(nameBuffer, ".backup");
6598 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6599 entry->volumeId[RWVOL], 0, 0);
6601 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6602 code = AFSVolEndTrans(aconn, tid, &rcode);
6606 "Could not end transaction on the backup volume %u\n",
6607 entry->volumeId[BACKVOL]);
6613 "Could not set parameters on the backup volume %u\n",
6614 entry->volumeId[BACKVOL]);
6619 } /* end backup processing */
6621 rx_DestroyConnection(aconn);
6622 aconn = (struct rx_connection *)0;
6623 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6624 for (i = 0; i < entry->nServers; i++) {
6625 if (entry->serverFlags[i] & ITSROVOL) {
6626 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6628 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6629 entry->serverPartition[i], ITOffline,
6631 if (code) { /*volume doesnot exist */
6633 "Could not start transaction on the ro volume %u\n",
6634 entry->volumeId[ROVOL]);
6637 } else { /*volume exists, process it */
6638 strcpy(nameBuffer, newname);
6639 strcat(nameBuffer, ".readonly");
6640 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6642 "Volume name %s exceeds the limit of %u characters\n",
6643 nameBuffer, VOLSER_OLDMAXVOLNAME);
6648 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6649 entry->volumeId[RWVOL], 0, 0);
6651 VPRINT2("Renamed RO volume %s on host %s\n",
6653 hostutil_GetNameByINet(entry->
6655 code = AFSVolEndTrans(aconn, tid, &rcode);
6659 "Could not end transaction on volume %u\n",
6660 entry->volumeId[ROVOL]);
6666 "Could not set parameters on the ro volume %u\n",
6667 entry->volumeId[ROVOL]);
6673 rx_DestroyConnection(aconn);
6674 aconn = (struct rx_connection *)0;
6681 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6683 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6686 "Could not unlock the VLDB entry for the volume %s %u\n",
6687 entry->name, entry->volumeId[RWVOL]);
6693 code = AFSVolEndTrans(aconn, tid, &rcode);
6697 fprintf(STDERR, "Failed to end transaction on a volume \n");
6703 rx_DestroyConnection(aconn);
6704 PrintError("", error);
6709 /*report on all the active transactions on volser */
6711 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6713 struct rx_connection *aconn;
6714 transDebugEntries transInfo;
6717 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6718 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6719 transInfo.transDebugEntries_len = 0;
6720 code = AFSVolMonitor(aconn, &transInfo);
6723 "Could not access status information about the server\n");
6724 PrintError("", code);
6725 if (transInfo.transDebugEntries_val)
6726 free(transInfo.transDebugEntries_val);
6728 rx_DestroyConnection(aconn);
6731 *rcount = transInfo.transDebugEntries_len;
6732 *rpntr = transInfo.transDebugEntries_val;
6734 rx_DestroyConnection(aconn);
6741 /*delete the volume without interacting with the vldb */
6743 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6745 afs_int32 rcode, ttid, error, code;
6746 struct rx_connection *aconn;
6752 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6753 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6755 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6756 (unsigned long)volid);
6760 code = AFSVolDeleteVolume(aconn, ttid);
6762 fprintf(STDERR, "Could not delete volume %lu\n",
6763 (unsigned long)volid);
6767 code = AFSVolEndTrans(aconn, ttid, &rcode);
6772 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6773 (unsigned long)volid);
6779 code = AFSVolEndTrans(aconn, ttid, &rcode);
6785 PrintError("", error);
6787 rx_DestroyConnection(aconn);
6792 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6793 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6795 struct rx_connection *conn = 0;
6797 afs_int32 code, error = 0, rcode;
6799 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6801 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6805 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6807 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6811 code = AFSVolSetFlags(conn, tid, setflag);
6813 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6818 #ifdef AFS_PTHREAD_ENV
6821 IOMGR_Sleep(sleeptime);
6828 code = AFSVolEndTrans(conn, tid, &rcode);
6829 if (code || rcode) {
6830 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6832 error = (code ? code : rcode);
6837 rx_DestroyConnection(conn);
6842 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6845 struct rx_connection *conn = 0;
6847 afs_int32 code, error = 0, rcode;
6849 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6851 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6855 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6857 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6861 code = AFSVolSetInfo(conn, tid, infop);
6863 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6870 code = AFSVolEndTrans(conn, tid, &rcode);
6871 if (code || rcode) {
6872 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6874 error = (code ? code : rcode);
6879 rx_DestroyConnection(conn);
6884 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6885 afs_int32 fromdate, struct volintSize *vol_size)
6887 struct rx_connection *aconn = (struct rx_connection *)0;
6888 afs_int32 tid = 0, rcode = 0;
6889 afs_int32 code, error = 0;
6892 /* get connections to the servers */
6893 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6895 VPRINT1("Starting transaction on volume %u...", afromvol);
6896 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6897 EGOTO1(error_exit, code,
6898 "Could not start transaction on the volume %u to be measured\n",
6902 VPRINT1("Getting size of volume on volume %u...", afromvol);
6903 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6904 EGOTO(error_exit, code, "Could not start the measurement process \n");
6909 VPRINT1("Ending transaction on volume %u...", afromvol);
6910 code = AFSVolEndTrans(aconn, tid, &rcode);
6911 if (code || rcode) {
6912 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6914 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6916 error = (code ? code : rcode);
6921 rx_DestroyConnection(aconn);
6923 PrintError("", error);
6927 /*maps the host addresses in <old > (present in network byte order) to
6928 that in< new> (present in host byte order )*/
6930 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
6934 /*copy all the fields */
6935 strcpy(new->name, old->name);
6936 /* new->volumeType = old->volumeType;*/
6937 new->nServers = old->nServers;
6938 count = old->nServers;
6939 if (count < NMAXNSERVERS)
6941 for (i = 0; i < count; i++) {
6942 new->serverNumber[i] = ntohl(old->serverNumber[i]);
6943 new->serverPartition[i] = old->serverPartition[i];
6944 new->serverFlags[i] = old->serverFlags[i];
6946 new->volumeId[RWVOL] = old->volumeId[RWVOL];
6947 new->volumeId[ROVOL] = old->volumeId[ROVOL];
6948 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
6949 new->cloneId = old->cloneId;
6950 new->flags = old->flags;
6953 /*maps the host entries in <entry> which are present in host byte order to network byte order */
6955 MapHostToNetwork(struct nvldbentry *entry)
6959 count = entry->nServers;
6960 if (count < NMAXNSERVERS)
6962 for (i = 0; i < count; i++) {
6963 entry->serverNumber[i] = htonl(entry->serverNumber[i]);