2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
20 #include <sys/statfs.h>
27 #include <netinet/in.h>
39 #include <afs/voldefs.h>
42 #include <afs/vlserver.h>
45 #include <afs/cellconfig.h>
48 #include <afs/afsint.h>
52 #include <afs/com_err.h>
54 #include <afs/kautils.h>
57 #define ERRCODE_RANGE 8 /* from error_table.h */
58 #define CLOCKSKEW 2 /* not really skew, but resolution */
60 /* for UV_MoveVolume() recovery */
62 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
65 #include <volser_prototypes.h>
67 struct ubik_client *cstruct;
72 afs_int32 vldbEntryIndex;
75 /* Utility macros used by rest of this source file */
76 #define EPRINT(ec, es) \
78 fprintf(STDERR, "\n"); \
79 fprintf(STDERR, (es)); \
83 #define EPRINT1(ec, es, ep1) \
85 fprintf(STDERR, "\n"); \
86 fprintf(STDERR, (es), (ep1)); \
90 #define EPRINT2(ec, es, ep1, ep2) \
92 fprintf(STDERR, "\n"); \
93 fprintf(STDERR, (es), (ep1), (ep2)); \
97 #define EPRINT3(ec, es, ep1, ep2, ep3) \
99 fprintf(STDERR, "\n"); \
100 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
101 PrintError(" ",ec); \
104 #define EGOTO(where, ec, es) \
113 #define EGOTO1(where, ec, es, ep1) \
116 EPRINT1((ec),(es),(ep1)); \
122 #define EGOTO2(where, ec, es, ep1, ep2) \
125 EPRINT2((ec),(es),(ep1),(ep2)); \
131 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
134 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
141 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
142 #define VPRINT1(es, p) \
143 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
144 #define VPRINT2(es, p1, p2) \
145 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
146 #define VPRINT3(es, p1, p2, p3) \
147 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
149 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
153 /* getting rid of this */
154 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
157 /* Protos for static routines */
158 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
159 afs_int32 apart, afs_int32 okvol,
161 static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
163 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
164 struct rx_connection **connPtr, afs_int32 * transPtr,
165 afs_int32 * timePtr);
166 static int SimulateForwardMultiple(struct rx_connection *fromconn,
167 afs_int32 fromtid, afs_int32 fromdate,
168 manyDests * tr, afs_int32 flags,
169 void *cookie, manyResults * results);
170 static int rel_compar(struct release *r1, struct release *r2);
171 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
172 afs_int32 apart, afs_int32 * modentry,
173 afs_uint32 * maxvolid);
176 /*map the partition <partId> into partition name <partName>*/
178 MapPartIdIntoName(afs_int32 partId, char *partName)
180 if (partId < 26) { /* what if partId > = 26 ? */
181 strcpy(partName, "/vicep");
182 partName[6] = partId + 'a';
185 } else if (partId < VOLMAXPARTS) {
186 strcpy(partName, "/vicep");
188 partName[6] = 'a' + (partId / 26);
189 partName[7] = 'a' + (partId % 26);
201 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
202 response = c = getchar();
203 while (!(c == EOF || c == '\n'))
204 c = getchar(); /*skip to end of line */
205 code = (response == 'y' || response == 'Y');
211 PrintError(char *msg, afs_int32 errcode)
213 fprintf(STDERR, msg);
214 /*replace by a big switch statement */
219 fprintf(STDERR, "Possible communication failure\n");
222 fprintf(STDERR, "Volume needs to be salvaged\n");
225 fprintf(STDERR, "Bad vnode number quoted\n");
229 "Volume not attached, does not exist, or not on line\n");
232 fprintf(STDERR, "Volume already exists\n");
235 fprintf(STDERR, "Volume is not in service\n");
238 fprintf(STDERR, "Volume is off line\n");
241 fprintf(STDERR, "Volume is already on line\n");
244 fprintf(STDERR, "Partition is full\n");
247 fprintf(STDERR, "Volume max quota exceeded\n");
250 fprintf(STDERR, "Volume temporarily unavailable\n");
253 fprintf(STDERR, "Volume has moved to another server\n");
256 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
259 fprintf(STDERR, "VLDB: a read terminated too early\n");
262 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
265 fprintf(STDERR, "VLDB: internal creation failure\n");
268 fprintf(STDERR, "VLDB: no such entry\n");
271 fprintf(STDERR, "VLDB: vldb database is empty\n");
274 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
277 fprintf(STDERR, "VLDB: volume name is illegal\n");
280 fprintf(STDERR, "VLDB: index was out of range\n");
283 fprintf(STDERR, "VLDB: bad volume type\n");
286 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
288 case VL_BADPARTITION:
289 fprintf(STDERR, "VLDB: bad partition number\n");
292 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
295 fprintf(STDERR, "VLDB: no such repsite server exists\n");
297 case VL_DUPREPSERVER:
298 fprintf(STDERR, "VLDB: replication site server already exists\n");
301 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
304 fprintf(STDERR, "VLDB: illegal reference count number\n");
306 case VL_SIZEEXCEEDED:
307 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
310 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
312 case VL_BADVOLIDBUMP:
313 fprintf(STDERR, "VLDB: illegal max volid increment\n");
315 case VL_IDALREADYHASHED:
316 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
319 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
322 fprintf(STDERR, "VLDB: bad volume operation code\n");
324 case VL_BADRELLOCKTYPE:
325 fprintf(STDERR, "VLDB: bad release lock type\n");
328 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
330 case VL_BADSERVERFLAG:
331 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
334 fprintf(STDERR, "VLDB: no permission access for call\n");
336 case VOLSERREAD_DUMPERROR:
338 "VOLSER: Problems encountered in reading the dump file !\n");
340 case VOLSERDUMPERROR:
341 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
343 case VOLSERATTACH_ERROR:
344 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
346 case VOLSERDETACH_ERROR:
347 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
349 case VOLSERILLEGAL_PARTITION:
350 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
352 case VOLSERBAD_ACCESS:
353 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
355 case VOLSERVLDB_ERROR:
356 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
359 fprintf(STDERR, "VOLSER: error in volume name\n");
362 fprintf(STDERR, "VOLSER: volume has moved\n");
365 fprintf(STDERR, "VOLSER: illegal operation\n");
367 case VOLSERBADRELEASE:
368 fprintf(STDERR, "VOLSER: release could not be completed\n");
371 fprintf(STDERR, "VOLSER: volume is busy\n");
373 case VOLSERNO_MEMORY:
374 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
378 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
380 case VOLSERMULTIRWVOL:
382 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
386 "VOLSER: not all entries were successfully processed\n");
393 initialize_KA_error_table();
394 initialize_RXK_error_table();
395 initialize_KTC_error_table();
396 initialize_ACFG_error_table();
397 initialize_CMD_error_table();
398 initialize_VL_error_table();
400 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
401 fprintf(STDERR, "%s: %s\n", error_table_name(errcode),
402 error_message(errcode));
410 static struct rx_securityClass *uvclass = 0;
411 static int uvindex = -1;
412 /* called by VLDBClient_Init to set the security module to be used in the RPC */
414 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
421 /* bind to volser on <port> <aserver> */
422 /* takes server address in network order, port in host order. dumb */
423 struct rx_connection *
424 UV_Bind(afs_int32 aserver, afs_int32 port)
426 register struct rx_connection *tc;
428 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
433 /* if <okvol> is allright(indicated by beibg able to
434 * start a transaction, delete the <delvol> */
436 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
437 afs_int32 okvol, afs_int32 delvol)
439 afs_int32 error, code, tid, rcode;
445 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
448 code = AFSVolDeleteVolume(aconn, tid);
451 code = AFSVolEndTrans(aconn, tid, &rcode);
458 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
460 code = AFSVolEndTrans(aconn, tid, &rcode);
465 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
468 code = AFSVolDeleteVolume(aconn, tid);
471 code = AFSVolEndTrans(aconn, tid, &rcode);
482 /* called by EmuerateEntry, show vldb entry in a reasonable format */
484 SubEnumerateEntry(struct nvldbentry *entry)
491 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
492 if (entry->flags & RW_EXISTS)
493 fprintf(STDOUT, " valid \n");
495 fprintf(STDOUT, " invalid \n");
496 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
497 if (entry->flags & RO_EXISTS)
498 fprintf(STDOUT, " valid \n");
500 fprintf(STDOUT, " invalid \n");
501 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
502 if (entry->flags & BACK_EXISTS)
503 fprintf(STDOUT, " valid \n");
505 fprintf(STDOUT, " invalid \n");
506 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
507 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
509 if (entry->flags & RW_EXISTS)
510 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
511 if (entry->flags & RO_EXISTS)
512 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
513 if (entry->flags & BACK_EXISTS)
514 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
515 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
516 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
517 fprintf(STDOUT, "\n");
519 fprintf(STDOUT, " number of sites -> %lu\n",
520 (unsigned long)entry->nServers);
521 for (i = 0; i < entry->nServers; i++) {
522 if (entry->serverFlags[i] & NEW_REPSITE)
525 for (i = 0; i < entry->nServers; i++) {
526 MapPartIdIntoName(entry->serverPartition[i], pname);
527 fprintf(STDOUT, " server %s partition %s ",
528 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
529 if (entry->serverFlags[i] & ITSRWVOL)
530 fprintf(STDOUT, "RW Site ");
532 fprintf(STDOUT, "RO Site ");
534 if (entry->serverFlags[i] & NEW_REPSITE)
535 fprintf(STDOUT, " -- New release");
537 fprintf(STDOUT, " -- Old release");
539 if (entry->serverFlags[i] & RO_DONTUSE)
540 fprintf(STDOUT, " -- Not released");
542 fprintf(STDOUT, "\n");
549 /*enumerate the vldb entry corresponding to <entry> */
551 EnumerateEntry(struct nvldbentry *entry)
554 fprintf(STDOUT, "\n");
555 fprintf(STDOUT, "%s \n", entry->name);
556 SubEnumerateEntry(entry);
560 /* forcibly remove a volume. Very dangerous call */
562 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
564 register struct rx_connection *tconn;
565 register afs_int32 code;
567 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
569 code = AFSVolNukeVolume(tconn, partid, volid);
570 rx_DestroyConnection(tconn);
576 /* like df. Return usage of <pname> on <server> in <partition> */
578 UV_PartitionInfo(afs_int32 server, char *pname,
579 struct diskPartition *partition)
581 register struct rx_connection *aconn;
585 aconn = (struct rx_connection *)0;
586 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
587 code = AFSVolPartitionInfo(aconn, pname, partition);
589 fprintf(STDERR, "Could not get information on partition %s\n", pname);
590 PrintError("", code);
593 rx_DestroyConnection(aconn);
597 /* old interface to create volume */
599 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
603 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
607 /* create a volume, given a server, partition number, volume name --> sends
608 * back new vol id in <anewid>*/
610 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
611 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
612 afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
615 register struct rx_connection *aconn;
617 register afs_int32 code;
619 afs_int32 rcode, vcode;
620 struct nvldbentry entry, storeEntry; /*the new vldb entry */
621 struct volintInfo tstatus;
624 aconn = (struct rx_connection *)0;
626 memset(&tstatus, 0, sizeof(struct volintInfo));
628 tstatus.maxquota = aquota;
630 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
631 /* next the next 3 available ids from the VLDB */
632 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 3, anewid);
633 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
636 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
637 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
640 code = AFSVolSetInfo(aconn, tid, &tstatus);
642 EPRINT(code, "Could not change quota (error %d), continuing...\n");
644 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
645 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
648 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
650 /* set up the vldb entry for this volume */
651 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
653 entry.serverNumber[0] = aserver; /* this should have another
654 * level of indirection later */
655 entry.serverPartition[0] = apart; /* this should also have
656 * another indirection level */
657 entry.flags = RW_EXISTS; /* this records that rw volume exists */
658 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
659 entry.volumeId[RWVOL] = *anewid;
660 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
661 entry.volumeId[BACKVOL] = *anewid + 2;
663 /*map into right byte order, before passing to xdr, the stuff has to be in host
664 * byte order. Xdr converts it into network order */
665 MapNetworkToHost(&entry, &storeEntry);
666 /* create the vldb entry */
667 vcode = VLDB_CreateEntry(&storeEntry);
670 "Could not create a VLDB entry for the volume %s %lu\n",
671 aname, (unsigned long)*anewid);
672 /*destroy the created volume */
673 VPRINT1("Deleting the newly created volume %u\n", *anewid);
674 AFSVolDeleteVolume(aconn, tid);
678 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
679 /* volume created, now terminate the transaction and release the connection */
680 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
681 * the volume will come online anyway when transaction timesout , so if
682 * vldb entry exists then the volume is guaranteed to exist too wrt create */
686 "Failed to end the transaction on the volume %s %lu\n", aname,
687 (unsigned long)*anewid);
694 code = AFSVolEndTrans(aconn, tid, &rcode);
696 fprintf(STDERR, "WARNING: could not end transaction\n");
699 rx_DestroyConnection(aconn);
700 PrintError("", error);
706 /* create a volume, given a server, partition number, volume name --> sends
707 * back new vol id in <anewid>*/
709 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
712 register struct rx_connection *aconn;
715 struct nvldbentry entry, storeEntry; /*the new vldb entry */
717 aconn = (struct rx_connection *)0;
720 /* set up the vldb entry for this volume */
721 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
723 entry.serverNumber[0] = aserver; /* this should have another
724 * level of indirection later */
725 entry.serverPartition[0] = apart; /* this should also have
726 * another indirection level */
727 entry.flags = RW_EXISTS; /* this records that rw volume exists */
728 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
729 entry.volumeId[RWVOL] = aid;
731 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
732 entry.volumeId[BACKVOL] = *anewid + 2;
734 entry.volumeId[ROVOL] = 0;
735 entry.volumeId[BACKVOL] = 0;
738 /*map into right byte order, before passing to xdr, the stuff has to be in host
739 * byte order. Xdr converts it into network order */
740 MapNetworkToHost(&entry, &storeEntry);
741 /* create the vldb entry */
742 vcode = VLDB_CreateEntry(&storeEntry);
745 "Could not create a VLDB entry for the volume %s %lu\n",
746 aname, (unsigned long)aid);
750 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
754 rx_DestroyConnection(aconn);
755 PrintError("", error);
759 /* Delete the volume <volid>on <aserver> <apart>
760 * the physical entry gets removed from the vldb only if the ref count
764 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
766 struct rx_connection *aconn = (struct rx_connection *)0;
768 afs_int32 code, rcode;
770 struct nvldbentry entry, storeEntry;
772 afs_int32 avoltype = -1, vtype;
773 int notondisk = 0, notinvldb = 0;
775 /* Find and read bhe VLDB entry for this volume */
776 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, avoltype, VLOP_DELETE);
778 if (code != VL_NOENT) {
779 EGOTO1(error_exit, code,
780 "Could not lock VLDB entry for the volume %u\n", avolid);
786 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
787 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
789 MapHostToNetwork(&entry);
792 EnumerateEntry(&entry);
795 /* Whether volume is in the VLDB or not. Delete the volume on disk */
796 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
797 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
799 if (code == VNOVOL) {
802 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
806 VPRINT1("Trying to delete the volume %u ...", avolid);
808 code = AFSVolDeleteVolume(aconn, ttid);
809 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
811 code = AFSVolEndTrans(aconn, ttid, &rcode);
812 code = (code ? code : rcode);
814 EGOTO1(error_exit, code,
815 "Could not end the transaction for the volume %u \n", avolid);
819 /* Now update the VLDB entry.
820 * But first, verify we have a VLDB entry.
821 * Whether volume is on disk or not. Delete the volume in VLDB.
826 if (avolid == entry.volumeId[BACKVOL]) {
827 /* Its a backup volume, modify the VLDB entry. Check that the
828 * backup volume is on the server/partition we asked to delete.
830 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
831 notinvldb = 2; /* Not on this server and partition */
835 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
837 entry.flags &= ~BACK_EXISTS;
841 else if (avolid == entry.volumeId[ROVOL]) {
842 /* Its a read-only volume, modify the VLDB entry. Check that the
843 * readonly volume is on the server/partition we asked to delete.
844 * If flags does not have RO_EIXSTS set, then this may mean the RO
845 * hasn't been released (and could exist in VLDB).
847 if (!Lp_ROMatch(aserver, apart, &entry)) {
848 notinvldb = 2; /* Not found on this server and partition */
854 "Marking the readonly volume %lu deleted in the VLDB\n",
855 (unsigned long)avolid);
857 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
859 if (!Lp_ROMatch(0, 0, &entry))
860 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
864 else if (avolid == entry.volumeId[RWVOL]) {
865 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
866 * Check that the readwrite volumes is on the server/partition we
869 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
870 notinvldb = 2; /* Not found on this server and partition */
874 /* Delete backup if it exists */
876 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
880 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
881 entry.volumeId[BACKVOL]);
884 code = AFSVolDeleteVolume(aconn, ttid);
885 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
886 entry.volumeId[BACKVOL]);
888 code = AFSVolEndTrans(aconn, ttid, &rcode);
890 code = (code ? code : rcode);
891 EGOTO1(error_exit, code,
892 "Could not end the transaction for the volume %u \n",
893 entry.volumeId[BACKVOL]);
895 fprintf(STDOUT, " done\n");
900 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
901 (unsigned long)avolid,
903 flags & BACK_EXISTS) ? ", and its backup volume," :
906 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
908 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
911 if (entry.flags & RO_EXISTS)
912 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
916 notinvldb = 2; /* Not found on this server and partition */
920 /* Either delete or replace the VLDB entry */
921 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
924 "Last reference to the VLDB entry for %lu - deleting entry\n",
925 (unsigned long)avolid);
926 code = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, vtype);
927 EGOTO1(error_exit, code,
928 "Could not delete the VLDB entry for the volume %u \n",
931 MapNetworkToHost(&entry, &storeEntry);
933 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
934 (LOCKREL_OPCODE | LOCKREL_AFSID |
936 EGOTO1(error_exit, code,
937 "Could not update the VLDB entry for the volume %u \n",
946 if (notondisk && notinvldb) {
947 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
948 ((notinvldb == 2) ? "on server and partition" : ""));
951 } else if (notondisk) {
953 "WARNING: Volume %lu did not exist on the partition\n",
954 (unsigned long)avolid);
955 } else if (notinvldb) {
956 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
957 (unsigned long)avolid,
958 ((notinvldb == 2) ? "on server and partition" : ""));
962 code = AFSVolEndTrans(aconn, ttid, &rcode);
963 code = (code ? code : rcode);
965 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
966 (unsigned long)avolid);
967 PrintError("", code);
975 ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, -1,
976 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
979 "Could not release the lock on the VLDB entry for the volume %u \n",
987 rx_DestroyConnection(aconn);
991 /* add recovery to UV_MoveVolume */
993 #define TESTC 0 /* set to test recovery code, clear for production */
999 sigint_handler(int x)
1004 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1006 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1007 fprintf(STDOUT, "enter second control-c to exit\n");
1011 (void)signal(SIGINT, sigint_handler);
1016 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1017 * <atopart>. The operation is almost idempotent
1021 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1022 afs_int32 atoserver, afs_int32 atopart)
1024 struct rx_connection *toconn, *fromconn;
1025 afs_int32 fromtid, totid, clonetid;
1028 char tmpName[VOLSER_MAXVOLNAME + 1];
1031 struct restoreCookie cookie;
1032 register afs_int32 vcode, code;
1033 afs_int32 newVol, volid, backupId;
1034 struct volser_status tstatus;
1035 struct destServer destination;
1037 struct nvldbentry entry, storeEntry;
1038 int i, islocked, pntg;
1040 char in, lf; /* for test code */
1043 #ifdef ENABLE_BUGFIX_1165
1044 volEntries volumeInfo;
1045 struct volintInfo *infop = 0;
1049 fromconn = (struct rx_connection *)0;
1050 toconn = (struct rx_connection *)0;
1060 /* support control-c processing */
1063 (void)signal(SIGINT, sigint_handler);
1067 "\nThere are three tests points - verifies all code paths through recovery.\n");
1068 fprintf(STDOUT, "First test point - operation not started.\n");
1069 fprintf(STDOUT, "...test here (y, n)? ");
1071 fscanf(stdin, "%c", &in);
1072 fscanf(stdin, "%c", &lf); /* toss away */
1074 fprintf(STDOUT, "type control-c\n");
1076 fprintf(stdout, ".");
1081 /* or drop through */
1084 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1085 EGOTO1(mfail, vcode,
1086 "Could not fetch the entry for the volume %u from the VLDB \n",
1089 if (entry.volumeId[RWVOL] != afromvol) {
1090 fprintf(STDERR, "Only RW volume can be moved\n");
1094 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1095 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1098 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1099 EGOTO1(mfail, vcode,
1100 "Could not fetch the entry for the volume %u from the VLDB \n",
1103 backupId = entry.volumeId[BACKVOL];
1104 MapHostToNetwork(&entry);
1106 if (!Lp_Match(afromserver, afrompart, &entry)) {
1107 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1108 if (!Lp_Match(atoserver, atopart, &entry)) {
1109 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1110 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1111 (unsigned long)afromvol);
1112 fprintf(STDERR, "The current site is :");
1113 for (i = 0; i < entry.nServers; i++) {
1114 if (entry.serverFlags[i] == ITSRWVOL) {
1116 MapPartIdIntoName(entry.serverPartition[i], pname);
1117 fprintf(STDERR, " server %s partition %s \n",
1118 hostutil_GetNameByINet(entry.serverNumber[i]),
1123 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1124 (LOCKREL_OPCODE | LOCKREL_AFSID |
1125 LOCKREL_TIMESTAMP));
1126 EGOTO1(mfail, vcode,
1127 " Could not release lock on the VLDB entry for the volume %u \n",
1130 return VOLSERVOLMOVED;
1133 /* delete the volume afromvol on src_server */
1134 /* from-info does not exist but to-info does =>
1135 * we have already done the move, but the volume
1136 * may still be existing physically on from fileserver
1138 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1143 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1145 if (!code) { /* volume exists - delete it */
1146 VPRINT1("Setting flags on leftover source volume %u ...",
1149 AFSVolSetFlags(fromconn, fromtid,
1150 VTDeleteOnSalvage | VTOutOfService);
1152 "Failed to set flags on the leftover source volume %u\n",
1156 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1157 code = AFSVolDeleteVolume(fromconn, fromtid);
1159 "Failed to delete the leftover source volume %u\n",
1163 VPRINT1("Ending transaction on leftover source volume %u ...",
1165 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1170 "Could not end the transaction for the leftover source volume %u \n",
1175 /*delete the backup volume now */
1178 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1180 if (!code) { /* backup volume exists - delete it */
1181 VPRINT1("Setting flags on leftover backup volume %u ...",
1184 AFSVolSetFlags(fromconn, fromtid,
1185 VTDeleteOnSalvage | VTOutOfService);
1187 "Failed to set flags on the backup volume %u\n", backupId);
1190 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1191 code = AFSVolDeleteVolume(fromconn, fromtid);
1193 "Could not delete the leftover backup volume %u\n",
1197 VPRINT1("Ending transaction on leftover backup volume %u ...",
1199 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1204 "Could not end the transaction for the leftover backup volume %u\n",
1214 /* From-info matches the vldb info about volid,
1215 * its ok start the move operation, the backup volume
1216 * on the old site is deleted in the process
1218 if (afrompart == atopart) {
1219 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1220 EGOTO2(mfail, error,
1221 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1222 afromserver, error);
1225 EGOTO1(mfail, VOLSERVOLMOVED,
1226 "Warning: Moving volume %u to its home partition ignored!\n",
1232 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1233 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1234 fromtid = totid = 0; /* initialize to uncreated */
1237 * clone the read/write volume locally.
1240 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1241 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1242 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1246 /* Get a clone id */
1247 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
1249 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
1250 EGOTO1(mfail, vcode,
1251 "Could not get an ID for the clone of volume %u from the VLDB\n",
1255 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1256 VPRINT1("Cloning source volume %u ...", afromvol);
1257 strcpy(vname, "move-clone-temp");
1258 code = AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1259 EGOTO1(mfail, code, "Failed to clone the source volume %u\n", afromvol);
1262 /* lookup the name of the volume we just cloned */
1264 code = AFSVolGetName(fromconn, fromtid, &volName);
1265 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n", newVol);
1267 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1269 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1274 "Failed to end the transaction on the source volume %u\n",
1279 * Create the destination volume
1282 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1284 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
1286 "Failed to start a transaction on the cloned volume%u\n", newVol);
1289 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1290 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
1291 EGOTO1(mfail, code, "Could not set falgs on the cloned volume %u\n",
1295 /* remember time from which we've dumped the volume */
1296 VPRINT1("Getting status of cloned volume %u ...", newVol);
1297 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1298 EGOTO1(mfail, code, "Failed to get the status of the cloned volume %u\n",
1302 fromDate = tstatus.creationDate - CLOCKSKEW;
1304 #ifdef ENABLE_BUGFIX_1165
1306 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1307 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1308 * don't use this information...
1310 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1311 volumeInfo.volEntries_len = 0;
1312 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1314 "Failed to get the volint Info of the cloned volume %u\n",
1317 infop = (volintInfo *) volumeInfo.volEntries_val;
1318 infop->maxquota = -1; /* Else it will replace the default quota */
1321 /* create a volume on the target machine */
1323 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1325 /* Delete the existing volume.
1326 * While we are deleting the volume in these steps, the transaction
1327 * we started against the cloned volume (clonetid above) will be
1328 * sitting idle. It will get cleaned up after 600 seconds
1330 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1331 code = AFSVolDeleteVolume(toconn, totid);
1333 "Could not delete the pre-existing volume %u on destination\n",
1338 ("Ending transaction on pre-existing volume %u on destination ...",
1340 code = AFSVolEndTrans(toconn, totid, &rcode);
1345 "Could not end the transaction on pre-existing volume %u on destination\n",
1350 VPRINT1("Creating the destination volume %u ...", volid);
1352 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1354 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1358 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1362 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1364 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1366 "Failed to set the flags on the destination volume %u\n", volid);
1370 * Now dump the clone to the new volume
1373 destination.destHost = ntohl(atoserver);
1374 destination.destPort = AFSCONF_VOLUMEPORT;
1375 destination.destSSID = 1;
1377 /* Copy the clone to the new volume */
1378 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1380 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1381 cookie.type = RWVOL;
1382 cookie.parent = entry.volumeId[RWVOL];
1384 code = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
1385 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1388 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1389 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1394 "Failed to end the transaction on the cloned volume %u\n", newVol);
1398 * reattach to the main-line volume, and incrementally dump it.
1401 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1402 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1404 "Failed to create a transaction on the source volume %u\n",
1408 /* now do the incremental */
1410 ("Doing the incremental dump from source to destination for volume %u ... ",
1413 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1416 "Failed to do the incremental dump from rw volume on old site to rw volume on newsite\n");
1419 /* now adjust the flags so that the new volume becomes official */
1420 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1421 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1423 "Failed to set the flags to make old source volume offline\n");
1426 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1427 code = AFSVolSetFlags(toconn, totid, 0);
1429 "Failed to set the flags to make new source volume online\n");
1432 #ifdef ENABLE_BUGFIX_1165
1433 VPRINT1("Setting volume status on destination volume %u ...", volid);
1434 code = AFSVolSetInfo(toconn, totid, infop);
1436 "Failed to set volume status on the destination volume %u\n",
1441 /* put new volume online */
1442 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1443 code = AFSVolEndTrans(toconn, totid, &rcode);
1448 "Failed to end the transaction on the volume %u on the new site\n",
1452 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1453 MapNetworkToHost(&entry, &storeEntry);
1454 storeEntry.flags &= ~BACK_EXISTS;
1458 "Second test point - operation in progress but not complete.\n");
1459 fprintf(STDOUT, "...test here (y, n)? ");
1461 fscanf(stdin, "%c", &in);
1462 fscanf(stdin, "%c", &lf); /* toss away */
1464 fprintf(STDOUT, "type control-c\n");
1466 fprintf(stdout, ".");
1471 /* or drop through */
1474 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1476 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1477 (LOCKREL_OPCODE | LOCKREL_AFSID |
1478 LOCKREL_TIMESTAMP));
1481 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1482 storeEntry.name, (unsigned long)afromvol);
1491 "Third test point - operation complete but no cleanup.\n");
1492 fprintf(STDOUT, "...test here (y, n)? ");
1494 fscanf(stdin, "%c", &in);
1495 fscanf(stdin, "%c", &lf); /* toss away */
1497 fprintf(STDOUT, "type control-c\n");
1499 fprintf(stdout, ".");
1504 /* or drop through */
1507 /* This is tricky. File server is very stupid, and if you mark the volume
1508 * as VTOutOfService, it may mark the *good* instance (if you're moving
1509 * between partitions on the same machine) as out of service. Since
1510 * we're cleaning this code up in DEcorum, we're just going to kludge around
1511 * it for now by removing this call. */
1512 /* already out of service, just zap it now */
1514 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1517 "Failed to set the flags to make the old source volume offline\n");
1521 if (atoserver != afromserver) {
1522 /* set forwarding pointer for moved volumes */
1523 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1524 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1526 "Failed to set the forwarding pointer for the volume %u\n",
1531 VPRINT1("Deleting old volume %u on source ...", afromvol);
1532 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1533 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1537 VPRINT1("Ending transaction on old volume %u on the source ...",
1539 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1544 "Failed to end the transaction on the old volume %u on the source\n",
1548 /* Delete the backup volume on the original site */
1549 VPRINT1("Creating transaction for backup volume %u on source ...",
1552 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1555 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1557 AFSVolSetFlags(fromconn, fromtid,
1558 VTDeleteOnSalvage | VTOutOfService);
1560 "Failed to set the flags on the backup volume %u on the source\n",
1564 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1565 code = AFSVolDeleteVolume(fromconn, fromtid);
1567 "Failed to delete the backup volume %u on the source\n",
1571 VPRINT1("Ending transaction on backup volume %u on source ...",
1573 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1578 "Failed to end the transaction on the backup volume %u on the source\n",
1582 code = 0; /* no backup volume? that's okay */
1585 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1587 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
1589 "Failed to start a transaction on the cloned volume%u\n", newVol);
1592 /* now delete the clone */
1593 VPRINT1("Deleting the cloned volume %u ...", newVol);
1594 code = AFSVolDeleteVolume(fromconn, clonetid);
1595 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n", newVol);
1598 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1599 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1604 "Failed to end the transaction on the cloned volume %u\n", newVol);
1611 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1612 fprintf(STDOUT, "...test here (y, n)? ");
1614 fscanf(stdin, "%c", &in);
1615 fscanf(stdin, "%c", &lf); /* toss away */
1617 fprintf(STDOUT, "type control-c\n");
1619 fprintf(stdout, ".");
1624 /* or drop through */
1627 /* normal cleanup code */
1629 if (entry.flags & RO_EXISTS)
1630 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1633 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1635 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1636 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1640 " Could not release the lock on the VLDB entry for the volume %lu \n",
1641 (unsigned long)afromvol);
1649 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1651 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1652 if (code || rcode) {
1655 "Could not end transaction on the source's clone volume %lu\n",
1656 (unsigned long)newVol);
1658 error = (code ? code : rcode);
1664 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1665 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1666 if (code || rcode) {
1669 "Could not end transaction on the source's clone volume %lu\n",
1670 (unsigned long)newVol);
1672 error = (code ? code : rcode);
1678 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1680 code = AFSVolEndTrans(toconn, totid, &rcode);
1684 "Could not end transaction on destination volume %lu\n",
1685 (unsigned long)afromvol);
1687 error = (code ? code : rcode);
1693 #ifdef ENABLE_BUGFIX_1165
1698 rx_DestroyConnection(fromconn);
1700 rx_DestroyConnection(toconn);
1701 PrintError("", error);
1704 /* come here only when the sky falls */
1709 "vos move: operation interrupted, cleanup in progress...\n");
1710 fprintf(STDOUT, "clear transaction contexts\n");
1714 /* unlock VLDB entry */
1716 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1717 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1718 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1723 VPRINT("Recovery: Ending transaction on clone volume ...");
1724 AFSVolEndTrans(fromconn, clonetid, &rcode);
1728 VPRINT("Recovery: Ending transaction on destination volume ...");
1729 AFSVolEndTrans(toconn, totid, &rcode);
1732 if (fromtid) { /* put it on-line */
1733 VPRINT("Recovery: Setting volume flags on source volume ...");
1734 AFSVolSetFlags(fromconn, fromtid, 0);
1737 VPRINT("Recovery: Ending transaction on source volume ...");
1738 AFSVolEndTrans(fromconn, fromtid, &rcode);
1742 VPRINT("Recovery: Accessing VLDB.\n");
1743 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1745 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1749 MapHostToNetwork(&entry);
1751 /* Delete either the volume on the source location or the target location.
1752 * If the vldb entry still points to the source location, then we know the
1753 * volume move didn't finish so we remove the volume from the target
1754 * location. Otherwise, we remove the volume from the source location.
1756 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1759 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1763 if (volid && toconn) {
1765 ("Recovery: Creating transaction for destination volume %u ...",
1768 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1774 ("Recovery: Setting flags on destination volume %u ...",
1776 AFSVolSetFlags(toconn, totid,
1777 VTDeleteOnSalvage | VTOutOfService);
1780 VPRINT1("Recovery: Deleting destination volume %u ...",
1782 AFSVolDeleteVolume(toconn, totid);
1786 ("Recovery: Ending transaction on destination volume %u ...",
1788 AFSVolEndTrans(toconn, totid, &rcode);
1792 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1797 /* put source volume on-line */
1799 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1802 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1807 VPRINT1("Recovery: Setting flags on source volume %u ...",
1809 AFSVolSetFlags(fromconn, fromtid, 0);
1813 ("Recovery: Ending transaction on source volume %u ...",
1815 AFSVolEndTrans(fromconn, fromtid, &rcode);
1819 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1823 } else { /* yep, move complete */
1826 "move complete - attempt cleanup of source partition - no guarantee\n");
1830 /* delete backup volume */
1832 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1835 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1840 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1842 AFSVolSetFlags(fromconn, fromtid,
1843 VTDeleteOnSalvage | VTOutOfService);
1846 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1847 AFSVolDeleteVolume(fromconn, fromtid);
1851 ("Recovery: Ending transaction on backup volume %u ...",
1853 AFSVolEndTrans(fromconn, fromtid, &rcode);
1857 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1861 /* delete source volume */
1862 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1865 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1870 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1872 AFSVolSetFlags(fromconn, fromtid,
1873 VTDeleteOnSalvage | VTOutOfService);
1876 if (atoserver != afromserver) {
1877 VPRINT("Recovery: Setting volume forwarding pointer ...");
1878 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1882 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1883 AFSVolDeleteVolume(fromconn, fromtid);
1887 ("Recovery: Ending transaction on source volume %u ...",
1889 AFSVolEndTrans(fromconn, fromtid, &rcode);
1893 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1899 /* common cleanup - delete local clone */
1901 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1904 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1909 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1910 AFSVolDeleteVolume(fromconn, clonetid);
1913 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1915 AFSVolEndTrans(fromconn, clonetid, &rcode);
1919 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1924 /* unlock VLDB entry */
1925 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
1927 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1928 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1931 done: /* routine cleanup */
1934 #ifdef ENABLE_BUGFIX_1165
1939 rx_DestroyConnection(fromconn);
1941 rx_DestroyConnection(toconn);
1944 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
1951 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1952 * <atopart>. The operation is almost idempotent
1956 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1957 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
1959 struct rx_connection *toconn, *fromconn;
1960 afs_int32 fromtid, totid, clonetid;
1962 char tmpName[VOLSER_MAXVOLNAME + 1];
1965 struct restoreCookie cookie;
1966 register afs_int32 vcode, code;
1967 afs_int32 cloneVol, newVol;
1968 struct volser_status tstatus;
1969 struct destServer destination;
1971 struct nvldbentry entry, newentry, storeEntry;
1977 fromconn = (struct rx_connection *)0;
1978 toconn = (struct rx_connection *)0;
1986 /* support control-c processing */
1989 (void)signal(SIGINT, sigint_handler);
1991 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1992 EGOTO1(mfail, vcode,
1993 "Could not fetch the entry for the volume %u from the VLDB \n",
1995 MapHostToNetwork(&entry);
1998 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1999 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2000 fromtid = totid = 0; /* initialize to uncreated */
2003 /* check if we can shortcut and use a local clone instead of a full copy */
2004 if (afromserver == atoserver && afrompart == atopart) {
2009 * clone the read/write volume locally.
2012 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2013 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2014 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2018 /* Get a clone id */
2019 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
2021 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &cloneVol);
2022 EGOTO1(mfail, vcode,
2023 "Could not get an ID for the clone of volume %u from the VLDB\n",
2027 /* Get a new volume id */
2028 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2030 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
2031 EGOTO1(mfail, vcode,
2032 "Could not get an ID for the copy of volume %u from the VLDB\n",
2036 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2037 VPRINT1("Cloning source volume %u ...", afromvol);
2038 strcpy(vname, "copy-clone-temp");
2040 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &cloneVol);
2041 EGOTO1(mfail, code, "Failed to clone the source volume %u\n", afromvol);
2044 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2046 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2051 "Failed to end the transaction on the source volume %u\n",
2056 * Create the destination volume
2059 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2061 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2064 "Failed to start a transaction on the cloned volume%u\n",
2068 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2069 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
2070 EGOTO1(mfail, code, "Could not set falgs on the cloned volume %u\n",
2074 /* remember time from which we've dumped the volume */
2075 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2076 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2077 EGOTO1(mfail, code, "Failed to get the status of the cloned volume %u\n",
2081 fromDate = tstatus.creationDate - CLOCKSKEW;
2083 /* create a volume on the target machine */
2084 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2086 /* Delete the existing volume.
2087 * While we are deleting the volume in these steps, the transaction
2088 * we started against the cloned volume (clonetid above) will be
2089 * sitting idle. It will get cleaned up after 600 seconds
2091 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2092 code = AFSVolDeleteVolume(toconn, totid);
2094 "Could not delete the pre-existing volume %u on destination\n",
2099 ("Ending transaction on pre-existing volume %u on destination ...",
2101 code = AFSVolEndTrans(toconn, totid, &rcode);
2106 "Could not end the transaction on pre-existing volume %u on destination\n",
2111 VPRINT1("Creating the destination volume %u ...", newVol);
2113 AFSVolCreateVolume(toconn, atopart, atovolname, volser_RW, newVol,
2115 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2119 strncpy(tmpName, atovolname, VOLSER_OLDMAXVOLNAME);
2121 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2123 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2125 "Failed to set the flags on the destination volume %u\n", newVol);
2129 * Now dump the clone to the new volume
2132 destination.destHost = ntohl(atoserver);
2133 destination.destPort = AFSCONF_VOLUMEPORT;
2134 destination.destSSID = 1;
2137 /* probably should have some code here that checks to see if we are copying to same server
2138 and partition - if so, just use a clone to save disk space */
2140 /* Copy the clone to the new volume */
2141 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2143 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
2144 cookie.type = RWVOL;
2147 code = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
2148 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", newVol);
2151 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2152 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2157 "Failed to end the transaction on the cloned volume %u\n",
2162 * reattach to the main-line volume, and incrementally dump it.
2165 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2166 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2168 "Failed to create a transaction on the source volume %u\n",
2172 /* now do the incremental */
2174 ("Doing the incremental dump from source to destination for volume %u ... ",
2177 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2180 "Failed to do the incremental dump from rw volume on old site to rw volume on newsite\n");
2183 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2184 code = AFSVolSetFlags(toconn, totid, 0);
2186 "Failed to set the flags to make destination volume online\n");
2189 /* put new volume online */
2190 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2191 code = AFSVolEndTrans(toconn, totid, &rcode);
2196 "Failed to end the transaction on the destination volume %u\n",
2200 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2201 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2206 "Failed to end the transaction on the source volume %u\n",
2211 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2213 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2216 "Failed to start a transaction on the cloned volume%u\n",
2220 /* now delete the clone */
2221 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2222 code = AFSVolDeleteVolume(fromconn, clonetid);
2223 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n", cloneVol);
2226 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2227 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2232 "Failed to end the transaction on the cloned volume %u\n",
2236 /* create the vldb entry for the copied volume */
2237 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2238 newentry.nServers = 1;
2239 newentry.serverNumber[0] = atoserver;
2240 newentry.serverPartition[0] = atopart;
2241 newentry.flags = RW_EXISTS; /* this records that rw volume exists */
2242 newentry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
2243 newentry.volumeId[RWVOL] = newVol;
2244 newentry.volumeId[ROVOL] = 0;
2245 newentry.volumeId[BACKVOL] = 0;
2246 newentry.cloneId = 0;
2247 /*map into right byte order, before passing to xdr, the stuff has to be in host
2248 * byte order. Xdr converts it into network order */
2249 MapNetworkToHost(&newentry, &storeEntry);
2250 /* create the vldb entry */
2251 vcode = VLDB_CreateEntry(&storeEntry);
2254 "Could not create a VLDB entry for the volume %s %lu\n",
2255 atovolname, (unsigned long)newVol);
2256 /*destroy the created volume */
2257 VPRINT1("Deleting the newly created volume %u\n", newVol);
2258 AFSVolDeleteVolume(toconn, totid);
2262 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2265 /* normal cleanup code */
2268 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2270 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2271 if (code || rcode) {
2274 "Could not end transaction on the source volume %lu\n",
2275 (unsigned long)afromvol);
2277 error = (code ? code : rcode);
2283 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2285 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2286 if (code || rcode) {
2289 "Could not end transaction on the source's clone volume %lu\n",
2290 (unsigned long)cloneVol);
2292 error = (code ? code : rcode);
2298 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2300 code = AFSVolEndTrans(toconn, totid, &rcode);
2304 "Could not end transaction on destination volume %lu\n",
2305 (unsigned long)newVol);
2307 error = (code ? code : rcode);
2312 rx_DestroyConnection(fromconn);
2314 rx_DestroyConnection(toconn);
2315 PrintError("", error);
2318 /* come here only when the sky falls */
2323 "vos copy: operation interrupted, cleanup in progress...\n");
2324 fprintf(STDOUT, "clear transaction contexts\n");
2329 VPRINT("Recovery: Ending transaction on clone volume ...");
2330 AFSVolEndTrans(fromconn, clonetid, &rcode);
2334 VPRINT("Recovery: Ending transaction on destination volume ...");
2335 AFSVolEndTrans(toconn, totid, &rcode);
2338 if (fromtid) { /* put it on-line */
2339 VPRINT("Recovery: Ending transaction on source volume ...");
2340 AFSVolEndTrans(fromconn, fromtid, &rcode);
2344 VPRINT("Recovery: Accessing VLDB.\n");
2345 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2347 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2351 MapHostToNetwork(&entry);
2353 /* common cleanup - delete local clone */
2355 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2358 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
2363 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2364 AFSVolDeleteVolume(fromconn, clonetid);
2367 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2369 AFSVolEndTrans(fromconn, clonetid, &rcode);
2373 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2378 done: /* routine cleanup */
2380 rx_DestroyConnection(fromconn);
2382 rx_DestroyConnection(toconn);
2385 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2395 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2396 * if one already exists, update it
2400 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2402 struct rx_connection *aconn = (struct rx_connection *)0;
2403 afs_int32 ttid = 0, btid = 0;
2405 afs_int32 code = 0, rcode = 0;
2406 char vname[VOLSER_MAXVOLNAME + 1];
2407 struct nvldbentry entry, storeEntry;
2408 afs_int32 error = 0;
2409 int vldblocked = 0, vldbmod = 0, backexists = 1;
2411 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2413 /* the calls to VLDB will succeed only if avolid is a RW volume,
2414 * since we are following the RW hash chain for searching */
2415 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2418 "Could not fetch the entry for the volume %lu from the VLDB \n",
2419 (unsigned long)avolid);
2423 MapHostToNetwork(&entry);
2425 /* These operations require the VLDB be locked since it means the VLDB
2426 * will change or the vldb is already locked.
2428 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2429 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2430 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2432 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2435 "Could not lock the VLDB entry for the volume %lu\n",
2436 (unsigned long)avolid);
2442 /* Reread the vldb entry */
2443 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2446 "Could not fetch the entry for the volume %lu from the VLDB \n",
2447 (unsigned long)avolid);
2451 MapHostToNetwork(&entry);
2454 if (!ISNAMEVALID(entry.name)) {
2455 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2457 error = VOLSERBADNAME;
2461 backupID = entry.volumeId[BACKVOL];
2462 if (backupID == INVALID_BID) {
2463 /* Get a backup volume id from the VLDB and update the vldb
2466 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &backupID);
2469 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2470 (unsigned long)avolid);
2474 entry.volumeId[BACKVOL] = backupID;
2478 /* Test to see if the backup volume exists by trying to create
2479 * a transaction on the backup volume. We've assumed the backup exists.
2481 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2483 if (code != VNOVOL) {
2484 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2485 (unsigned long)backupID);
2489 backexists = 0; /* backup volume does not exist */
2492 code = AFSVolEndTrans(aconn, btid, &rcode);
2494 if (code || rcode) {
2496 "Could not end transaction on the previous backup volume %lu\n",
2497 (unsigned long)backupID);
2498 error = (code ? code : rcode);
2503 /* Now go ahead and try to clone the RW volume.
2504 * First start a transaction on the RW volume
2506 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2508 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2509 (unsigned long)avolid);
2514 /* Clone or reclone the volume, depending on whether the backup
2515 * volume exists or not
2518 VPRINT1("Re-cloning backup volume %u ...", backupID);
2520 code = AFSVolReClone(aconn, ttid, backupID);
2522 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2523 (unsigned long)backupID);
2528 VPRINT1("Creating a new backup clone %u ...", backupID);
2530 strcpy(vname, entry.name);
2531 strcat(vname, ".backup");
2533 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2535 fprintf(STDERR, "Failed to clone the volume %lu\n",
2536 (unsigned long)avolid);
2542 /* End the transaction on the RW volume */
2543 code = AFSVolEndTrans(aconn, ttid, &rcode);
2545 if (code || rcode) {
2547 "Failed to end the transaction on the rw volume %lu\n",
2548 (unsigned long)avolid);
2549 error = (code ? code : rcode);
2553 /* Mork vldb as backup exists */
2554 if (!(entry.flags & BACK_EXISTS)) {
2555 entry.flags |= BACK_EXISTS;
2559 /* Now go back to the backup volume and bring it on line */
2560 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2563 "Failed to start a transaction on the backup volume %lu\n",
2564 (unsigned long)backupID);
2569 code = AFSVolSetFlags(aconn, btid, 0);
2571 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2572 (unsigned long)backupID);
2577 code = AFSVolEndTrans(aconn, btid, &rcode);
2579 if (code || rcode) {
2581 "Failed to end the transaction on the backup volume %lu\n",
2582 (unsigned long)backupID);
2583 error = (code ? code : rcode);
2589 /* Will update the vldb below */
2593 code = AFSVolEndTrans(aconn, ttid, &rcode);
2594 if (code || rcode) {
2595 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2596 (unsigned long)avolid);
2598 error = (code ? code : rcode);
2603 code = AFSVolEndTrans(aconn, btid, &rcode);
2604 if (code || rcode) {
2606 "Could not end transaction the backup volume %lu\n",
2607 (unsigned long)backupID);
2609 error = (code ? code : rcode);
2613 /* Now update the vldb - if modified */
2616 MapNetworkToHost(&entry, &storeEntry);
2618 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2619 (LOCKREL_OPCODE | LOCKREL_AFSID |
2620 LOCKREL_TIMESTAMP));
2623 "Could not update the VLDB entry for the volume %lu \n",
2624 (unsigned long)avolid);
2630 ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, RWVOL,
2631 (LOCKREL_OPCODE | LOCKREL_AFSID |
2632 LOCKREL_TIMESTAMP));
2635 "Could not unlock the VLDB entry for the volume %lu \n",
2636 (unsigned long)avolid);
2644 rx_DestroyConnection(aconn);
2646 PrintError("", error);
2651 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2654 afs_int32 acode, ccode, rcode, tid;
2655 ccode = rcode = tid = 0;
2657 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2658 if (!acode) { /* It really was there */
2659 acode = AFSVolDeleteVolume(conn, tid);
2661 fprintf(STDERR, "Failed to delete volume %lu.\n",
2662 (unsigned long)vid);
2663 PrintError("", acode);
2665 ccode = AFSVolEndTrans(conn, tid, &rcode);
2669 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
2670 (unsigned long)vid);
2671 PrintError("", ccode);
2678 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
2679 #define ERROREXIT(ec) { error = (ec); goto rfail; }
2681 /* Get a "transaction" on this replica. Create the volume
2682 * if necessary. Return the time from which a dump should
2683 * be made (0 if it's a new volume)
2686 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
2687 struct rx_connection **connPtr, afs_int32 * transPtr,
2688 afs_int32 * timePtr)
2691 struct volser_status tstatus;
2692 int code, rcode, tcode;
2694 *connPtr = (struct rx_connection *)0;
2698 /* get connection to the replication site */
2699 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
2701 goto fail; /* server is down */
2703 volid = vldbEntryPtr->volumeId[ROVOL];
2706 AFSVolTransCreate(*connPtr, volid,
2707 vldbEntryPtr->serverPartition[index], ITOffline,
2710 /* If the volume does not exist, create it */
2711 if (!volid || code) {
2714 if (volid && (code != VNOVOL)) {
2715 PrintError("Failed to start a transaction on the RO volume.\n",
2720 strcpy(volname, vldbEntryPtr->name);
2721 strcat(volname, ".readonly");
2725 "Creating new volume %lu on replication site %s: ",
2726 (unsigned long)volid,
2727 hostutil_GetNameByINet(vldbEntryPtr->
2728 serverNumber[index]));
2733 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
2735 vldbEntryPtr->volumeId[RWVOL], &volid,
2738 PrintError("Failed to create the ro volume: ", code);
2741 vldbEntryPtr->volumeId[ROVOL] = volid;
2745 /* The following is a bit redundant, since create sets these flags by default */
2747 AFSVolSetFlags(*connPtr, *transPtr,
2748 VTDeleteOnSalvage | VTOutOfService);
2750 PrintError("Failed to set flags on the ro volume: ", code);
2755 /* Otherwise, the transaction did succeed, so get the creation date of the
2756 * latest RO volume on the replication site
2759 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
2760 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
2762 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
2764 PrintError("Failed to get status of volume on destination: ",
2768 *timePtr = tstatus.creationDate - CLOCKSKEW;
2775 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
2780 PrintError("Could not end transaction on a ro volume: ", tcode);
2787 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
2788 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
2789 void *cookie, manyResults * results)
2793 for (i = 0; i < tr->manyDests_len; i++) {
2794 results->manyResults_val[i] =
2795 AFSVolForward(fromconn, fromtid, fromdate,
2796 &(tr->manyDests_val[i].server),
2797 tr->manyDests_val[i].trans, cookie);
2804 rel_compar(struct release *r1, struct release *r2)
2806 return (r1->time - r2->time);
2809 /* UV_ReleaseVolume()
2810 * Release volume <afromvol> on <afromserver> <afrompart> to all
2811 * its RO sites (full release). Unless the previous release was
2812 * incomplete: in which case we bring the remaining incomplete
2813 * volumes up to date with the volumes that were released
2815 * forceflag: Performs a full release.
2817 * Will create a clone from the RW, then dump the clone out to
2818 * the remaining replicas. If there is more than 1 RO sites,
2819 * ensure that the VLDB says at least one RO is available all
2820 * the time: Influences when we write back the VLDB entry.
2824 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
2825 afs_int32 afrompart, int forceflag)
2828 afs_int32 code, vcode, rcode, tcode;
2829 afs_int32 cloneVolId, roVolId;
2830 struct replica *replicas = 0;
2831 struct nvldbentry entry, storeEntry;
2832 int i, volcount, m, fullrelease, vldbindex;
2834 struct restoreCookie cookie;
2835 struct rx_connection **toconns = 0;
2836 struct release *times = 0;
2838 struct rx_connection *fromconn = (struct rx_connection *)0;
2839 afs_int32 error = 0;
2841 afs_int32 clonetid = 0, onlinetid;
2842 afs_int32 fromtid = 0;
2843 afs_uint32 fromdate, thisdate;
2846 manyResults results;
2847 int rwindex, roindex, roclone, roexists;
2848 afs_int32 rwcrdate, clcrdate;
2852 } remembertime[NMAXNSERVERS];
2853 int releasecount = 0;
2854 struct volser_status volstatus;
2856 memset((char *)remembertime, 0, sizeof(remembertime));
2857 memset((char *)&results, 0, sizeof(results));
2859 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
2860 if (vcode != VL_RERELEASE)
2861 ONERROR(vcode, afromvol,
2862 "Could not lock the VLDB entry for the volume %u.\n");
2865 /* Get the vldb entry in readable format */
2866 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
2867 ONERROR(vcode, afromvol,
2868 "Could not fetch the entry for the volume %u from the VLDB.\n");
2869 MapHostToNetwork(&entry);
2872 EnumerateEntry(&entry);
2874 if (!ISNAMEVALID(entry.name))
2875 ONERROR(VOLSERBADOP, entry.name,
2876 "Volume name %s is too long, rename before releasing.\n");
2877 if (entry.volumeId[RWVOL] != afromvol)
2878 ONERROR(VOLSERBADOP, afromvol,
2879 "The volume %u being released is not a read-write volume.\n");
2880 if (entry.nServers <= 1)
2881 ONERROR(VOLSERBADOP, afromvol,
2882 "Volume %u has no replicas - release operation is meaningless!\n");
2883 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
2884 ONERROR(VOLSERBADOP, entry.name,
2885 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
2887 /* roclone is true if one of the RO volumes is on the same
2888 * partition as the RW volume. In this case, we make the RO volume
2889 * on the same partition a clone instead of a complete copy.
2892 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
2893 roclone = ((roindex == -1) ? 0 : 1);
2894 rwindex = Lp_GetRwIndex(&entry);
2896 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
2898 /* Make sure we have a RO volume id to work with */
2899 if (entry.volumeId[ROVOL] == INVALID_BID) {
2900 /* need to get a new RO volume id */
2901 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &roVolId);
2902 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
2904 entry.volumeId[ROVOL] = roVolId;
2905 MapNetworkToHost(&entry, &storeEntry);
2906 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
2907 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
2910 /* Will we be completing a previously unfinished release. -force overrides */
2911 for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) {
2912 if (entry.serverFlags[i] & NEW_REPSITE)
2915 if (forceflag && !fullrelease)
2918 /* Determine which volume id to use and see if it exists */
2921 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
2922 code = VolumeExists(afromserver, afrompart, cloneVolId);
2923 roexists = ((code == ENODEV) ? 0 : 1);
2925 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2927 ONERROR(-1, afromserver,
2928 "Cannot establish connection with server 0x%x\n");
2932 fullrelease = 1; /* Do a full release if RO clone does not exist */
2934 /* Begin transaction on RW and mark it busy while we query it */
2935 code = AFSVolTransCreate(
2936 fromconn, afromvol, afrompart, ITBusy, &fromtid
2938 ONERROR(code, afromvol,
2939 "Failed to start transaction on RW volume %u\n");
2941 /* Query the creation date for the RW */
2942 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
2943 ONERROR(code, afromvol,
2944 "Failed to get the status of RW volume %u\n");
2945 rwcrdate = volstatus.creationDate;
2947 /* End transaction on RW */
2948 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2950 ONERROR((code ? code : rcode), afromvol,
2951 "Failed to end transaction on RW volume %u\n");
2953 /* Begin transaction on clone and mark it busy while we query it */
2954 code = AFSVolTransCreate(
2955 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
2957 ONERROR(code, cloneVolId,
2958 "Failed to start transaction on RW clone %u\n");
2960 /* Query the creation date for the clone */
2961 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
2962 ONERROR(code, cloneVolId,
2963 "Failed to get the status of RW clone %u\n");
2964 clcrdate = volstatus.creationDate;
2966 /* End transaction on RW */
2967 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2969 ONERROR((code ? code : rcode), cloneVolId,
2970 "Failed to end transaction on RW volume %u\n");
2972 if (rwcrdate > clcrdate)
2973 fullrelease = 2;/* Do a full release if RO clone older than RW */
2978 switch (fullrelease) {
2980 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
2981 (unsigned long)afromvol);
2984 fprintf(STDOUT, "This is a complete release of volume %lu\n",
2985 (unsigned long)afromvol);
2988 fprintf(STDOUT, "This is a completion of a previous release\n");
2994 /* If the RO clone exists, then if the clone is a temporary
2995 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
2996 * (it was recently added), then also delete it. We do not
2997 * want to "reclone" a temporary RO clone.
3000 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3001 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3002 if (code && (code != VNOVOL))
3007 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3008 * write this entry out to the vlserver until after the first
3009 * RO volume is released (temp RO clones don't count).
3011 for (i = 0; i < entry.nServers; i++) {
3012 entry.serverFlags[i] &= ~NEW_REPSITE;
3013 entry.serverFlags[i] |= RO_DONTUSE;
3015 entry.serverFlags[rwindex] |= NEW_REPSITE;
3016 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3018 /* Begin transaction on RW and mark it busy while we clone it */
3020 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3022 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3024 /* Clone or reclone the volume */
3026 VPRINT1("Recloning RW volume %u...", cloneVolId);
3027 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3028 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3032 strcpy(vname, entry.name);
3033 strcat(vname, ".readonly");
3034 VPRINT("Cloning RW volume %u to permanent RO...");
3036 strcpy(vname, "readonly-clone-temp");
3037 VPRINT("Cloning RW volume %u to temporary RO...");
3040 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3042 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3046 /* Get the time the RW was created for future information */
3047 VPRINT1("Getting status of RW volume %u...", cloneVolId);
3048 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3049 ONERROR(code, cloneVolId,
3050 "Failed to get the status of the RW volume %u\n");
3052 rwcrdate = volstatus.creationDate;
3054 /* End the transaction on the RW volume */
3055 VPRINT1("Ending cloning transaction on RW volume %u...", cloneVolId);
3056 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3058 ONERROR((code ? code : rcode), cloneVolId,
3059 "Failed to end cloning transaction on RW %u\n");
3062 /* Remember clone volume ID in case we fail or are interrupted */
3063 entry.cloneId = cloneVolId;
3066 /* Bring the RO clone online - though not if it's a temporary clone */
3067 VPRINT1("Starting transaction on RO clone volume %u...",
3070 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3072 ONERROR(code, cloneVolId,
3073 "Failed to start transaction on volume %u\n");
3076 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3077 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3080 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3081 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3082 ONERROR((code ? code : rcode), cloneVolId,
3083 "Failed to end transaction on RO clone %u\n");
3086 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3088 /* Sleep so that a client searching for an online volume won't
3089 * find the clone offline and then the next RO offline while the
3090 * release brings the clone online and the next RO offline (race).
3091 * There is a fix in the 3.4 client that does not need this sleep
3092 * anymore, but we don't know what clients we have.
3094 if (entry.nServers > 2)
3097 /* Mark the RO clone in the VLDB as a good site (already released) */
3098 entry.serverFlags[roindex] |= NEW_REPSITE;
3099 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3100 entry.flags |= RO_EXISTS;
3104 /* Write out the VLDB entry only if the clone is not a temporary
3105 * clone. If we did this to a temporary clone then we would end
3106 * up marking all the ROs as "old release" making the ROs
3107 * temporarily unavailable.
3109 MapNetworkToHost(&entry, &storeEntry);
3110 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3111 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3112 ONERROR(vcode, entry.name,
3113 "Could not update vldb entry for %s.\n");
3118 /* Now we will release from the clone to the remaining RO replicas.
3119 * The first 2 ROs (counting the non-temporary RO clone) are released
3120 * individually: releasecount. This is to reduce the race condition
3121 * of clients trying to find an on-line RO volume. The remaining ROs
3122 * are released in parallel but no more than half the number of ROs
3123 * (rounded up) at a time: nservers.
3126 strcpy(vname, entry.name);
3127 strcat(vname, ".readonly");
3128 memset(&cookie, 0, sizeof(cookie));
3129 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3130 cookie.type = ROVOL;
3131 cookie.parent = entry.volumeId[RWVOL];
3134 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3136 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3137 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3139 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3141 results.manyResults_val =
3142 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3143 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3145 "Failed to create transaction on the release clone\n");
3147 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3148 memset(times, 0, (sizeof(struct release) * nservers + 1));
3149 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3150 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3152 /* Create a transaction on the cloned volume */
3153 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3155 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3156 if (!fullrelease && code)
3157 ONERROR(VOLSERNOVOL, afromvol,
3158 "Old clone is inaccessible. Try vos release -f %u.\n");
3159 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3162 /* For each index in the VLDB */
3163 for (vldbindex = 0; vldbindex < entry.nServers;) {
3165 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3167 ((volcount < nservers) && (vldbindex < entry.nServers));
3169 /* The first two RO volumes will be released individually.
3170 * The rest are then released in parallel. This is a hack
3171 * for clients not recognizing right away when a RO volume
3172 * comes back on-line.
3174 if ((volcount == 1) && (releasecount < 2))
3177 if (vldbindex == roindex)
3178 continue; /* the clone */
3179 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3180 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3182 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3183 continue; /* not a RO vol */
3186 /* Get a Transaction on this replica. Get a new connection if
3187 * necessary. Create the volume if necessary. Return the
3188 * time from which the dump should be made (0 if it's a new
3189 * volume). Each volume might have a different time.
3191 replicas[volcount].server.destHost =
3192 ntohl(entry.serverNumber[vldbindex]);
3193 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3194 replicas[volcount].server.destSSID = 1;
3195 times[volcount].vldbEntryIndex = vldbindex;
3198 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3199 &(replicas[volcount].trans),
3200 &(times[volcount].time));
3204 /* Thisdate is the date from which we want to pick up all changes */
3205 if (forceflag || !fullrelease
3206 || (rwcrdate > times[volcount].time)) {
3207 /* If the forceflag is set, then we want to do a full dump.
3208 * If it's not a full release, we can't be sure that the creation
3209 * date is good (so we also do a full dump).
3210 * If the RW volume was replaced (its creation date is newer than
3211 * the last release), then we can't be sure what has changed (so
3212 * we do a full dump).
3215 } else if (remembertime[vldbindex].validtime) {
3216 /* Trans was prev ended. Use the time from the prev trans
3217 * because, prev trans may have created the volume. In which
3218 * case time[volcount].time would be now instead of 0.
3221 (remembertime[vldbindex].time <
3222 times[volcount].time) ? remembertime[vldbindex].
3223 time : times[volcount].time;
3225 thisdate = times[volcount].time;
3227 remembertime[vldbindex].validtime = 1;
3228 remembertime[vldbindex].time = thisdate;
3230 if (volcount == 0) {
3231 fromdate = thisdate;
3233 /* Include this volume if it is within 15 minutes of the earliest */
3235 thisdate) ? (fromdate - thisdate) : (thisdate -
3237 AFSVolEndTrans(toconns[volcount],
3238 replicas[volcount].trans, &rcode);
3239 replicas[volcount].trans = 0;
3242 if (thisdate < fromdate)
3243 fromdate = thisdate;
3251 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3252 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3253 hostutil_GetNameByINet(entry.
3254 serverNumber[times[0].
3257 for (s = 1; s < volcount; s++) {
3258 fprintf(STDOUT, " and %s",
3259 hostutil_GetNameByINet(entry.
3260 serverNumber[times[s].
3265 fprintf(STDOUT, " (full release)");
3266 fprintf(STDOUT, ".\n");
3270 /* Release the ones we have collected */
3271 tr.manyDests_val = &(replicas[0]);
3272 tr.manyDests_len = results.manyResults_len = volcount;
3274 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3275 0 /*spare */ , &cookie, &results);
3276 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3278 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3279 0 /*spare */ , &cookie, &results);
3284 PrintError("Release failed: ", code);
3286 for (m = 0; m < volcount; m++) {
3287 if (results.manyResults_val[m]) {
3288 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3289 /* we retry timed out transaction. When it is
3290 * not the first volume and the transaction wasn't found
3291 * (assume it timed out and was garbage collected by volser).
3294 ("Failed to dump volume from clone to a ro site: ",
3295 results.manyResults_val[m]);
3301 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3302 ROVOL, entry.volumeId[RWVOL], 0, 0);
3304 if ((m == 0) || (code != ENOENT)) {
3305 PrintError("Failed to set correct names and ids: ",
3311 /* have to clear dest. flags to ensure new vol goes online:
3312 * because the restore (forwarded) operation copied
3313 * the V_inService(=0) flag over to the destination.
3315 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3317 if ((m == 0) || (code != ENOENT)) {
3318 PrintError("Failed to set flags on ro volume: ",
3324 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3325 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3326 entry.flags |= RO_EXISTS;
3331 /* End the transactions and destroy the connections */
3332 for (s = 0; s < volcount; s++) {
3333 if (replicas[s].trans)
3334 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3335 replicas[s].trans = 0;
3339 if ((s == 0) || (code != ENOENT)) {
3340 PrintError("Could not end transaction on a ro volume: ",
3344 ("Transaction timed out on a ro volume. Will retry.\n",
3346 if (times[s].vldbEntryIndex < vldbindex)
3347 vldbindex = times[s].vldbEntryIndex;
3352 rx_DestroyConnection(toconns[s]);
3356 MapNetworkToHost(&entry, &storeEntry);
3357 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3358 ONERROR(vcode, afromvol,
3359 " Could not update VLDB entry for volume %u\n");
3360 } /* for each index in the vldb */
3362 /* End the transaction on the cloned volume */
3363 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3368 PrintError("Failed to end transaction on rw volume: ", code);
3370 /* Figure out if any volume were not released and say so */
3371 for (failure = 0, i = 0; i < entry.nServers; i++) {
3372 if (!(entry.serverFlags[i] & NEW_REPSITE))
3378 "The volume %lu could not be released to the following %d sites:\n",
3379 (unsigned long)afromvol, failure);
3380 for (i = 0; i < entry.nServers; i++) {
3381 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3382 MapPartIdIntoName(entry.serverPartition[i], pname);
3383 fprintf(STDERR, "\t%35s %s\n",
3384 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3388 MapNetworkToHost(&entry, &storeEntry);
3390 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3392 ONERROR(vcode, afromvol,
3393 " Could not update VLDB entry for volume %u\n");
3395 ERROREXIT(VOLSERBADRELEASE);
3398 /* All the ROs were release successfully. Remove the temporary clone */
3401 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3402 (unsigned long)cloneVolId);
3405 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3406 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3411 for (i = 0; i < entry.nServers; i++)
3412 entry.serverFlags[i] &= ~NEW_REPSITE;
3414 /* Update the VLDB */
3415 VPRINT("updating VLDB ...");
3417 MapNetworkToHost(&entry, &storeEntry);
3419 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3420 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3421 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3426 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3430 "Failed to end cloning transaction on the RW volume %lu\n",
3431 (unsigned long)afromvol);
3437 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3441 "Failed to end transaction on the release clone %lu\n",
3442 (unsigned long)cloneVolId);
3447 for (i = 0; i < nservers; i++) {
3448 if (replicas && replicas[i].trans) {
3449 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3450 replicas[i].trans = 0;
3453 "Failed to end transaction on ro volume %u at server %s\n",
3454 entry.volumeId[ROVOL],
3455 hostutil_GetNameByINet(htonl
3456 (replicas[i].server.
3462 if (toconns && toconns[i]) {
3463 rx_DestroyConnection(toconns[i]);
3469 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, RWVOL,
3470 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3473 "Could not release lock on the VLDB entry for volume %lu\n",
3474 (unsigned long)afromvol);
3480 PrintError("", error);
3483 rx_DestroyConnection(fromconn);
3484 if (results.manyResults_val)
3485 free(results.manyResults_val);
3497 dump_sig_handler(int x)
3499 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3503 /* Dump the volume <afromvol> on <afromserver> and
3504 * <afrompart> to <afilename> starting from <fromdate>.
3505 * DumpFunction does the real work behind the scenes after
3506 * extracting parameters from the rock
3509 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3510 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock)
3512 struct rx_connection *fromconn = (struct rx_connection *)0;
3513 struct rx_call *fromcall = (struct rx_call *)0;
3514 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3515 afs_int32 code, error = 0;
3519 #ifndef AFS_NT40_ENV
3520 (void)signal(SIGPIPE, dump_sig_handler);
3522 (void)signal(SIGINT, dump_sig_handler);
3525 VPRINT("Full Dump ...\n");
3527 VPRINT1("Incremental Dump (as of %.24s)...\n",
3528 ctime((time_t *) & fromdate));
3531 /* get connections to the servers */
3532 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3534 VPRINT1("Starting transaction on volume %u...", afromvol);
3535 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3536 EGOTO1(error_exit, code,
3537 "Could not start transaction on the volume %u to be dumped\n",
3541 fromcall = rx_NewCall(fromconn);
3543 VPRINT1("Starting volume dump on volume %u...", afromvol);
3544 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3545 EGOTO(error_exit, code, "Could not start the dump process \n");
3548 VPRINT1("Dumping volume %u...", afromvol);
3549 code = DumpFunction(fromcall, rock);
3550 EGOTO(error_exit, code, "Error while dumping volume \n");
3555 code = rx_EndCall(fromcall, rxError);
3557 fprintf(STDERR, "Error in rx_EndCall\n");
3563 VPRINT1("Ending transaction on volume %u...", afromvol);
3564 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3565 if (code || rcode) {
3566 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3567 (unsigned long)afromvol);
3569 error = (code ? code : rcode);
3574 rx_DestroyConnection(fromconn);
3576 PrintError("", error);
3580 /* Clone the volume <afromvol> on <afromserver> and
3581 * <afrompart>, and then dump the clone volume to
3582 * <afilename> starting from <fromdate>.
3583 * DumpFunction does the real work behind the scenes after
3584 * extracting parameters from the rock
3587 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3588 afs_int32 afrompart, afs_int32 fromdate,
3589 afs_int32(*DumpFunction) (), char *rock)
3591 struct rx_connection *fromconn = (struct rx_connection *)0;
3592 struct rx_call *fromcall = (struct rx_call *)0;
3593 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3594 afs_int32 clonetid = 0;
3595 afs_int32 code = 0, vcode = 0, error = 0;
3596 afs_int32 clonevol = 0;
3601 #ifndef AFS_NT40_ENV
3602 (void)signal(SIGPIPE, dump_sig_handler);
3604 (void)signal(SIGINT, dump_sig_handler);
3607 VPRINT("Full Dump ...\n");
3609 VPRINT1("Incremental Dump (as of %.24s)...\n",
3610 ctime((time_t *) & fromdate));
3613 /* get connections to the servers */
3614 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3616 VPRINT1("Starting transaction on volume %u...", afromvol);
3617 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3618 EGOTO1(error_exit, code,
3619 "Could not start transaction on the volume %u to be dumped\n",
3623 /* Get a clone id */
3624 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3625 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &clonevol);
3626 EGOTO1(error_exit, code,
3627 "Could not get an ID for the clone of volume %u from the VLDB\n",
3631 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3632 VPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3634 strcpy(vname, "dump-clone-temp");
3636 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3637 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3641 VPRINT1("Ending the transaction on the volume %u ...", afromvol);
3643 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3647 EGOTO1(error_exit, code,
3648 "Failed to end the transaction on the volume %u\n", afromvol);
3652 VPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
3654 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
3656 EGOTO1(error_exit, code,
3657 "Failed to start a transaction on the cloned volume%u\n",
3661 VPRINT1("Setting flags on cloned volume %u ...", clonevol);
3662 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
3663 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
3668 fromcall = rx_NewCall(fromconn);
3670 VPRINT1("Starting volume dump from cloned volume %u...", clonevol);
3671 code = StartAFSVolDump(fromcall, clonetid, fromdate);
3672 EGOTO(error_exit, code, "Could not start the dump process \n");
3675 VPRINT1("Dumping volume %u...", afromvol);
3676 code = DumpFunction(fromcall, rock);
3677 EGOTO(error_exit, code, "Error while dumping volume \n");
3681 /* now delete the clone */
3682 VPRINT1("Deleting the cloned volume %u ...", clonevol);
3683 code = AFSVolDeleteVolume(fromconn, clonetid);
3685 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
3686 (unsigned long)clonevol);
3692 code = rx_EndCall(fromcall, rxError);
3694 fprintf(STDERR, "Error in rx_EndCall\n");
3700 VPRINT1("Ending transaction on cloned volume %u...", clonevol);
3701 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3702 if (code || rcode) {
3704 "Could not end transaction on the cloned volume %lu\n",
3705 (unsigned long)clonevol);
3707 error = (code ? code : rcode);
3712 rx_DestroyConnection(fromconn);
3714 PrintError("", error);
3721 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
3722 * the dump file <afilename>. WriteData does all the real work
3723 * after extracting params from the rock
3726 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
3727 char tovolname[], int flags, afs_int32(*WriteData) (),
3730 struct rx_connection *toconn, *tempconn;
3731 struct rx_call *tocall;
3732 afs_int32 totid, code, rcode, vcode, terror = 0;
3733 afs_int32 rxError = 0;
3734 struct volser_status tstatus;
3739 struct nvldbentry entry, storeEntry;
3742 struct restoreCookie cookie;
3744 afs_int32 newDate, volflag, voltype, volsertype;
3745 int index, same, errcode;
3749 memset(&cookie, 0, sizeof(cookie));
3754 tocall = (struct rx_call *)0;
3755 toconn = (struct rx_connection *)0;
3756 tempconn = (struct rx_connection *)0;
3760 if (flags & RV_RDONLY) {
3762 volsertype = volser_RO;
3765 volsertype = volser_RW;
3769 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
3770 if (pvolid == 0) { /*alot a new id if needed */
3771 vcode = VLDB_GetEntryByName(tovolname, &entry);
3772 if (vcode == VL_NOENT) {
3773 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &pvolid);
3775 fprintf(STDERR, "Could not get an Id for the volume %s\n",
3781 } else if (flags & RV_RDONLY) {
3782 if (entry.flags & RW_EXISTS) {
3784 "Entry for ReadWrite volume %s already exists!\n",
3786 error = VOLSERBADOP;
3789 if (!entry.volumeId[ROVOL]) {
3791 "Existing entry for volume %s has no ReadOnly ID\n",
3793 error = VOLSERBADOP;
3796 pvolid = entry.volumeId[ROVOL];
3798 pvolid = entry.volumeId[RWVOL];
3801 /* at this point we have a volume id to use/reuse for the volume to be restored */
3802 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
3803 EGOTO1(refail, VOLSERBADOP,
3804 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
3807 MapPartIdIntoName(topart, partName);
3808 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
3809 tovolname, (unsigned long)pvolid,
3810 hostutil_GetNameByINet(toserver), partName);
3813 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0, &pvolid,
3816 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
3817 VPRINT1("Deleting the previous volume %u ...", pvolid);
3820 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
3821 EGOTO1(refail, code, "Failed to start transaction on %u\n",
3825 AFSVolSetFlags(toconn, totid,
3826 VTDeleteOnSalvage | VTOutOfService);
3827 EGOTO1(refail, code, "Could not set flags on volume %u \n",
3830 code = AFSVolDeleteVolume(toconn, totid);
3831 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
3833 code = AFSVolEndTrans(toconn, totid, &rcode);
3837 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
3842 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0,
3844 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
3849 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
3850 EGOTO1(refail, code, "Failed to start transaction on %u\n",
3853 code = AFSVolGetStatus(toconn, totid, &tstatus);
3854 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
3856 newDate = tstatus.creationDate;
3859 cookie.parent = pvolid;
3860 cookie.type = voltype;
3862 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
3864 tocall = rx_NewCall(toconn);
3865 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
3867 fprintf(STDERR, "Volume restore Failed \n");
3871 code = WriteData(tocall, rock);
3873 fprintf(STDERR, "Could not transmit data\n");
3877 terror = rx_EndCall(tocall, rxError);
3878 tocall = (struct rx_call *)0;
3880 fprintf(STDERR, "rx_EndCall Failed \n");
3884 code = AFSVolGetStatus(toconn, totid, &tstatus);
3887 "Could not get status information about the volume %lu\n",
3888 (unsigned long)pvolid);
3892 code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pvolid, 0, 0);
3894 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
3895 (unsigned long)pvolid);
3901 code = AFSVolSetDate(toconn, totid, newDate);
3903 fprintf(STDERR, "Could not set the date on %lu\n",
3904 (unsigned long)pvolid);
3909 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
3910 code = AFSVolSetFlags(toconn, totid, volflag);
3912 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
3917 /* It isn't handled right in refail */
3918 code = AFSVolEndTrans(toconn, totid, &rcode);
3923 fprintf(STDERR, "Could not end transaction on %lu\n",
3924 (unsigned long)pvolid);
3930 fprintf(STDOUT, " done\n");
3932 if (success && (!reuseID || (flags & RV_FULLRST))) {
3933 /* Volume was restored on the file server, update the
3934 * VLDB to reflect the change.
3936 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
3937 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
3939 "Could not fetch the entry for volume number %lu from VLDB \n",
3940 (unsigned long)pvolid);
3945 MapHostToNetwork(&entry);
3946 if (vcode == VL_NOENT) { /* it doesnot exist already */
3947 /*make the vldb return this indication specifically */
3948 VPRINT("------- Creating a new VLDB entry ------- \n");
3949 strcpy(entry.name, tovolname);
3951 entry.serverNumber[0] = toserver; /*should be indirect */
3952 entry.serverPartition[0] = topart;
3953 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
3954 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
3955 if (flags & RV_RDONLY)
3956 entry.volumeId[ROVOL] = pvolid;
3957 else if (tstatus.cloneID != 0) {
3958 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
3960 entry.volumeId[ROVOL] = INVALID_BID;
3961 entry.volumeId[RWVOL] = pvolid;
3963 if (tstatus.backupID != 0) {
3964 entry.volumeId[BACKVOL] = tstatus.backupID;
3965 /*this should come from status info on the volume if non zero */
3967 entry.volumeId[BACKVOL] = INVALID_BID;
3968 MapNetworkToHost(&entry, &storeEntry);
3969 vcode = VLDB_CreateEntry(&storeEntry);
3972 "Could not create the VLDB entry for volume number %lu \n",
3973 (unsigned long)pvolid);
3979 EnumerateEntry(&entry);
3980 } else { /*update the existing entry */
3982 fprintf(STDOUT, "Updating the existing VLDB entry\n");
3983 fprintf(STDOUT, "------- Old entry -------\n");
3984 EnumerateEntry(&entry);
3985 fprintf(STDOUT, "------- New entry -------\n");
3988 ubik_Call(VL_SetLock, cstruct, 0, pvolid, voltype,
3992 "Could not lock the entry for volume number %lu \n",
3993 (unsigned long)pvolid);
3998 strcpy(entry.name, tovolname);
4000 /* Update the vlentry with the new information */
4001 if (flags & RV_RDONLY)
4002 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4004 index = Lp_GetRwIndex(&entry);
4006 /* Add the new site for the volume being restored */
4007 entry.serverNumber[entry.nServers] = toserver;
4008 entry.serverPartition[entry.nServers] = topart;
4009 entry.serverFlags[entry.nServers] =
4010 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4013 /* This volume should be deleted on the old site
4014 * if its different from new site.
4017 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4020 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4022 if ((!errcode && !same)
4023 || (entry.serverPartition[index] != topart)) {
4025 UV_Bind(entry.serverNumber[index],
4026 AFSCONF_VOLUMEPORT);
4028 MapPartIdIntoName(entry.serverPartition[index],
4031 ("Deleting the previous volume %u on server %s, partition %s ...",
4033 hostutil_GetNameByINet(entry.serverNumber[index]),
4036 AFSVolTransCreate(tempconn, pvolid,
4037 entry.serverPartition[index],
4038 ITOffline, &temptid);
4041 AFSVolSetFlags(tempconn, temptid,
4046 "Could not set flags on volume %lu on the older site\n",
4047 (unsigned long)pvolid);
4051 code = AFSVolDeleteVolume(tempconn, temptid);
4054 "Could not delete volume %lu on the older site\n",
4055 (unsigned long)pvolid);
4059 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4065 "Could not end transaction on volume %lu on the older site\n",
4066 (unsigned long)pvolid);
4071 MapPartIdIntoName(entry.serverPartition[index],
4075 entry.serverNumber[index] = toserver;
4076 entry.serverPartition[index] = topart;
4079 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4080 MapNetworkToHost(&entry, &storeEntry);
4082 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4083 LOCKREL_OPCODE | LOCKREL_AFSID |
4087 "Could not update the entry for volume number %lu \n",
4088 (unsigned long)pvolid);
4094 EnumerateEntry(&entry);
4101 code = rx_EndCall(tocall, rxError);
4107 ubik_Call(VL_ReleaseLock, cstruct, 0, pvolid, voltype,
4108 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4111 "Could not release lock on the VLDB entry for the volume %lu\n",
4112 (unsigned long)pvolid);
4118 code = AFSVolEndTrans(toconn, totid, &rcode);
4122 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4123 (unsigned long)pvolid);
4129 code = AFSVolEndTrans(toconn, temptid, &rcode);
4133 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4134 (unsigned long)pvolid);
4140 rx_DestroyConnection(tempconn);
4142 rx_DestroyConnection(toconn);
4143 PrintError("", error);
4148 /*unlocks the vldb entry associated with <volid> */
4150 UV_LockRelease(afs_int32 volid)
4156 VPRINT("Binding to the VLDB server\n");
4158 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4159 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4162 "Could not unlock the entry for volume number %lu in VLDB \n",
4163 (unsigned long)volid);
4164 PrintError("", vcode);
4167 VPRINT("VLDB updated\n");
4172 /*adds <server> and <part> as a readonly replication site for <volid>
4175 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4177 int j, nro = 0, islocked = 0;
4178 struct nvldbentry entry, storeEntry;
4179 afs_int32 vcode, error = 0;
4182 error = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4185 " Could not lock the VLDB entry for the volume %lu \n",
4186 (unsigned long)volid);
4191 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4194 "Could not fetch the VLDB entry for volume number %lu \n",
4195 (unsigned long)volid);
4199 if (!ISNAMEVALID(entry.name)) {
4201 "Volume name %s is too long, rename before adding site\n",
4203 error = VOLSERBADOP;
4206 MapHostToNetwork(&entry);
4208 /* See if it's too many entries */
4209 if (entry.nServers >= NMAXNSERVERS) {
4210 fprintf(STDERR, "Total number of entries will exceed %u\n",
4212 error = VOLSERBADOP;
4216 /* See if it's on the same server */
4217 for (j = 0; j < entry.nServers; j++) {
4218 if (entry.serverFlags[j] & ITSROVOL) {
4220 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4223 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4226 MapPartIdIntoName(entry.serverPartition[j], apartName);
4228 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4230 error = VOLSERBADOP;
4237 /* See if it's too many RO sites - leave one for the RW */
4238 if (nro >= NMAXNSERVERS - 1) {
4239 fprintf(STDERR, "Total number of sites will exceed %u\n",
4241 error = VOLSERBADOP;
4245 VPRINT("Adding a new site ...");
4246 entry.serverNumber[entry.nServers] = server;
4247 entry.serverPartition[entry.nServers] = part;
4248 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4251 MapNetworkToHost(&entry, &storeEntry);
4253 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4254 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4256 fprintf(STDERR, "Could not update entry for volume %lu \n",
4257 (unsigned long)volid);
4266 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4267 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4270 "Could not release lock on volume entry for %lu \n",
4271 (unsigned long)volid);
4272 PrintError("", vcode);
4276 PrintError("", error);
4280 /*removes <server> <part> as read only site for <volid> from the vldb */
4282 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4285 struct nvldbentry entry, storeEntry;
4288 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4290 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4291 (unsigned long)volid);
4292 PrintError("", vcode);
4296 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4299 "Could not fetch the entry for volume number %lu from VLDB \n",
4300 (unsigned long)volid);
4301 PrintError("", vcode);
4304 MapHostToNetwork(&entry);
4305 if (!Lp_ROMatch(server, part, &entry)) {
4306 /*this site doesnot exist */
4307 fprintf(STDERR, "This site is not a replication site \n");
4309 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4310 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4312 fprintf(STDERR, "Could not update entry for volume %lu \n",
4313 (unsigned long)volid);
4314 PrintError("", vcode);
4315 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4316 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4320 } else { /*remove the rep site */
4321 Lp_SetROValue(&entry, server, part, 0, 0);
4323 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4324 entry.flags &= ~RO_EXISTS;
4325 if (entry.nServers < 1) { /*this is the last ref */
4326 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4328 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, volid, ROVOL);
4331 "Could not delete VLDB entry for volume %lu \n",
4332 (unsigned long)volid);
4333 PrintError("", vcode);
4338 MapNetworkToHost(&entry, &storeEntry);
4339 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4340 (unsigned long)volid);
4343 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4344 LOCKREL_OPCODE | LOCKREL_AFSID |
4348 "Could not release lock on volume entry for %lu \n",
4349 (unsigned long)volid);
4350 PrintError("", vcode);
4351 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4352 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4360 /*sets <server> <part> as read/write site for <volid> in the vldb */
4362 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4365 struct nvldbentry entry, storeEntry;
4368 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4370 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4371 (unsigned long)volid);
4372 PrintError("", vcode);
4375 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4378 "Could not fetch the entry for volume number %lu from VLDB \n",
4379 (unsigned long)volid);
4380 PrintError("", vcode);
4383 MapHostToNetwork(&entry);
4384 index = Lp_GetRwIndex(&entry);
4386 /* no RW site exists */
4387 fprintf(STDERR, "No existing RW site for volume %lu",
4388 (unsigned long)volid);
4390 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4391 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4394 "Could not release lock on entry for volume %lu \n",
4395 (unsigned long)volid);
4396 PrintError("", vcode);
4400 } else { /* change the RW site */
4401 entry.serverNumber[index] = server;
4402 entry.serverPartition[index] = part;
4403 MapNetworkToHost(&entry, &storeEntry);
4405 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4406 LOCKREL_OPCODE | LOCKREL_AFSID |
4409 fprintf(STDERR, "Could not update entry for volume %lu \n",
4410 (unsigned long)volid);
4411 PrintError("", vcode);
4412 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4413 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4421 /*list all the partitions on <aserver> */
4423 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4426 struct rx_connection *aconn;
4427 struct pIDs partIds;
4428 struct partEntries partEnts;
4429 register int i, j = 0, code;
4432 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4434 partEnts.partEntries_len = 0;
4435 partEnts.partEntries_val = NULL;
4436 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4437 if (code == RXGEN_OPCODE) {
4438 for (i = 0; i < 26; i++) /* try old interface */
4439 partIds.partIds[i] = -1;
4440 code = AFSVolListPartitions(aconn, &partIds);
4442 for (i = 0; i < 26; i++) {
4443 if ((partIds.partIds[i]) != -1) {
4444 ptrPartList->partId[j] = partIds.partIds[i];
4445 ptrPartList->partFlags[j] = PARTVALID;
4448 ptrPartList->partFlags[i] = 0;
4453 *cntp = partEnts.partEntries_len;
4454 if (*cntp > VOLMAXPARTS) {
4456 "Warning: number of partitions on the server too high %d (process only %d)\n",
4457 *cntp, VOLMAXPARTS);
4458 *cntp = VOLMAXPARTS;
4460 for (i = 0; i < *cntp; i++) {
4461 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4462 ptrPartList->partFlags[i] = PARTVALID;
4464 free(partEnts.partEntries_val);
4470 "Could not fetch the list of partitions from the server\n");
4471 PrintError("", code);
4473 rx_DestroyConnection(aconn);
4478 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4479 This is used by the backup system */
4481 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4482 struct volDescription *volPtr, afs_int32 arraySize)
4484 struct rx_connection *aconn;
4485 struct volDescription *curPtr;
4488 afs_int32 rcode = 0;
4489 afs_int32 success = 1;
4492 aconn = (struct rx_connection *)0;
4493 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4495 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4496 if (curPtr->volFlags & CLONEVALID) {
4497 curPtr->volFlags &= ~CLONEZAPPED;
4500 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4505 code = AFSVolDeleteVolume(aconn, tid);
4508 code = AFSVolEndTrans(aconn, tid, &rcode);
4513 curPtr->volFlags |= CLONEZAPPED;
4515 fprintf(STDERR, "Could not zap volume %lu\n",
4516 (unsigned long)curPtr->volCloneId);
4518 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4519 curPtr->volCloneId);
4525 rx_DestroyConnection(aconn);
4529 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4532 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4533 struct volDescription *volPtr, afs_int32 arraySize)
4535 struct rx_connection *aconn;
4536 struct volDescription *curPtr;
4539 afs_int32 rcode = 0;
4541 int reuseCloneId = 0;
4542 afs_int32 curCloneId = 0;
4543 char cloneName[256]; /*max vol name */
4545 aconn = (struct rx_connection *)0;
4546 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4548 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4550 else { /*get a bunch of id's from vldb */
4552 ubik_Call(VL_GetNewVolumeId, cstruct, 0, arraySize, &curCloneId);
4554 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4555 PrintError("", code);
4560 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4561 if (curPtr->volFlags & ENTRYVALID) {
4563 curPtr->volFlags |= CLONEVALID;
4564 /*make a clone of curParentId and record as curPtr->volCloneId */
4566 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4569 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4572 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
4576 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
4577 strcpy(cloneName, curPtr->volName);
4578 strcat(cloneName, "-tmpClone-");
4580 strcpy(cloneName, "-tmpClone");
4582 curPtr->volCloneId = curCloneId;
4587 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
4588 &(curPtr->volCloneId));
4590 curPtr->volFlags &= ~CLONEVALID;
4592 fprintf(STDERR, "Could not clone %s due to error %lu\n",
4593 curPtr->volName, (unsigned long)code);
4594 code = AFSVolEndTrans(aconn, tid, &rcode);
4596 fprintf(STDERR, "WARNING: could not end transaction\n");
4599 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
4600 curPtr->volCloneId);
4601 code = AFSVolEndTrans(aconn, tid, &rcode);
4602 if (code || rcode) {
4603 curPtr->volFlags &= ~CLONEVALID;
4612 rx_DestroyConnection(aconn);
4617 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
4618 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
4620 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
4621 struct volintInfo **resultPtr, afs_int32 * size)
4623 struct rx_connection *aconn;
4625 volEntries volumeInfo;
4629 *resultPtr = (volintInfo *) 0;
4630 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
4631 volumeInfo.volEntries_len = 0;
4633 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4634 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
4637 "Could not fetch the list of volumes from the server\n");
4639 *resultPtr = volumeInfo.volEntries_val;
4640 *size = volumeInfo.volEntries_len;
4644 rx_DestroyConnection(aconn);
4645 PrintError("", code);
4649 /*------------------------------------------------------------------------
4650 * EXPORTED UV_XListVolumes
4653 * List the extended information for all the volumes on a particular
4654 * File Server and partition. We may either return the volume's ID
4655 * or all of its extended information.
4658 * a_serverID : Address of the File Server for which we want
4659 * extended volume info.
4660 * a_partID : Partition for which we want the extended
4662 * a_all : If non-zero, fetch ALL the volume info,
4663 * otherwise just the volume ID.
4664 * a_resultPP : Ptr to the address of the area containing
4665 * the returned volume info.
4666 * a_numEntsInResultP : Ptr for the value we set for the number of
4671 * Otherise, the return value of AFSVolXListVolumes.
4674 * This routine is closely related to UV_ListVolumes, which returns
4675 * only the standard level of detail on AFS volumes. It is a
4676 * heavyweight operation, zipping through all the volume entries for
4677 * a given server/partition.
4681 *------------------------------------------------------------------------*/
4684 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
4685 struct volintXInfo **a_resultPP,
4686 afs_int32 * a_numEntsInResultP)
4688 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
4689 afs_int32 code; /*Error code to return */
4690 volXEntries volumeXInfo; /*Area for returned extended vol info */
4693 * Set up our error code and the area for returned extended volume info.
4694 * We set the val field to a null pointer as a hint for the stub to
4698 *a_numEntsInResultP = 0;
4699 *a_resultPP = (volintXInfo *) 0;
4700 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
4701 volumeXInfo.volXEntries_len = 0;
4704 * Bind to the Volume Server port on the File Server machine in question,
4707 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
4708 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
4710 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
4713 * We got the info; pull out the pointer to where the results lie
4714 * and how many entries are there.
4716 *a_resultPP = volumeXInfo.volXEntries_val;
4717 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
4721 * If we got an Rx connection, throw it away.
4724 rx_DestroyConnection(rxConnP);
4726 PrintError("", code);
4728 } /*UV_XListVolumes */
4730 /* get all the information about volume <volid> on <aserver> and <apart> */
4732 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
4733 struct volintInfo **resultPtr)
4735 struct rx_connection *aconn;
4737 volEntries volumeInfo;
4741 *resultPtr = (volintInfo *) 0;
4742 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
4743 volumeInfo.volEntries_len = 0;
4745 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4746 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
4749 "Could not fetch the information about volume %lu from the server\n",
4750 (unsigned long)volid);
4752 *resultPtr = volumeInfo.volEntries_val;
4757 rx_DestroyConnection(aconn);
4758 PrintError("", code);
4762 /*------------------------------------------------------------------------
4763 * EXPORTED UV_XListOneVolume
4766 * List the extended information for a volume on a particular File
4767 * Server and partition.
4770 * a_serverID : Address of the File Server for which we want
4771 * extended volume info.
4772 * a_partID : Partition for which we want the extended
4774 * a_volID : Volume ID for which we want the info.
4775 * a_resultPP : Ptr to the address of the area containing
4776 * the returned volume info.
4780 * Otherise, the return value of AFSVolXListOneVolume.
4783 * This routine is closely related to UV_ListOneVolume, which returns
4784 * only the standard level of detail on the chosen AFS volume.
4788 *------------------------------------------------------------------------*/
4791 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
4792 struct volintXInfo **a_resultPP)
4794 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
4795 afs_int32 code; /*Error code */
4796 volXEntries volumeXInfo; /*Area for returned info */
4799 * Set up our error code, and the area we're in which we are returning
4800 * the info. Setting the val field to a null pointer tells the stub
4801 * to allocate space for us.
4804 *a_resultPP = (volintXInfo *) 0;
4805 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
4806 volumeXInfo.volXEntries_len = 0;
4809 * Bind to the Volume Server port on the File Server machine in question,
4812 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
4813 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
4816 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
4819 * We got the info; pull out the pointer to where the results lie.
4821 *a_resultPP = volumeXInfo.volXEntries_val;
4824 * If we got an Rx connection, throw it away.
4827 rx_DestroyConnection(rxConnP);
4829 PrintError("", code);
4834 * Given a volume we read from a partition, check if it is
4835 * represented in the VLDB correctly.
4837 * The VLDB is looked up by the RW volume id (not its name).
4838 * The RW contains the true name of the volume (BK and RO set
4839 * the name in the VLDB only on creation of the VLDB entry).
4840 * We want rules strict enough that when we check all volumes
4841 * on one partition, it does not need to be done again. IE:
4842 * two volumes on different partitions won't constantly
4843 * change a VLDB entry away from what the other set.
4844 * For RW and BK volumes, we will always check the VLDB to see
4845 * if the two exist on the server/partition. May seem redundant,
4846 * but this is an easy check of the VLDB. IE: if the VLDB entry
4847 * says the BK exists but no BK volume is there, we will detect
4848 * this when we check the RW volume.
4849 * VLDB entries are locked only when a change needs to be done.
4850 * Output changed to look a lot like the "vos syncserv" otuput.
4853 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
4854 afs_int32 * modentry, afs_uint32 * maxvolid)
4857 afs_int32 code, error = 0;
4858 struct nvldbentry entry, storeEntry;
4860 int pass = 0, islocked = 0, createentry, addvolume, modified, mod;
4866 ((volumeinfo->type ==
4867 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
4870 /* Check to see if the VLDB is ok without locking it (pass 1).
4871 * If it will change, then lock the VLDB entry, read it again,
4872 * then make the changes to it (pass 2).
4875 code = ubik_Call(VL_SetLock, cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
4877 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
4878 (unsigned long)rwvolid);
4884 createentry = 0; /* Do we need to create a VLDB entry */
4885 addvolume = 0; /* Add this volume to the VLDB entry */
4886 modified = 0; /* The VLDB entry was modified */
4888 /* Read the entry from VLDB by its RW volume id */
4889 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
4891 if (code != VL_NOENT) {
4893 "Could not retreive the VLDB entry for volume %lu \n",
4894 (unsigned long)rwvolid);
4898 memset(&entry, 0, sizeof(entry));
4899 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
4903 MapHostToNetwork(&entry);
4906 if (verbose && (pass == 1)) {
4907 fprintf(STDOUT, "_______________________________\n");
4908 fprintf(STDOUT, "\n-- status before -- \n");
4910 fprintf(STDOUT, "\n**does not exist**\n");
4912 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
4913 || (entry.flags & BACK_EXISTS))
4914 EnumerateEntry(&entry);
4916 fprintf(STDOUT, "\n");
4919 if (volumeinfo->type == RWVOL) { /* RW volume exists */
4925 /* Check existence of RW and BK volumes */
4926 code = CheckVldbRWBK(&entry, &mod);
4932 idx = Lp_GetRwIndex(&entry);
4933 if (idx == -1) { /* RW index not found in the VLDB entry */
4934 idx = entry.nServers; /* put it into next index */
4937 } else { /* RW index found in the VLDB entry. */
4938 /* Verify if this volume's location matches where the VLDB says it is */
4939 if (!Lp_Match(aserver, apart, &entry)) {
4940 if (entry.flags & RW_EXISTS) {
4941 /* The RW volume exists elsewhere - report this one a duplicate */
4943 MapPartIdIntoName(apart, pname);
4945 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
4946 (unsigned long)rwvolid,
4947 hostutil_GetNameByINet(aserver), pname);
4948 MapPartIdIntoName(entry.serverPartition[idx],
4951 " VLDB reports RW volume %lu exists on %s %s\n",
4952 (unsigned long)rwvolid,
4953 hostutil_GetNameByINet(entry.
4958 /* The RW volume does not exist - have VLDB point to this one */
4961 /* Check for orphaned BK volume on old partition */
4962 if (entry.flags & BACK_EXISTS) {
4964 MapPartIdIntoName(entry.serverPartition[idx],
4967 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
4968 entry.volumeId[BACKVOL],
4969 hostutil_GetNameByINet(entry.
4972 MapPartIdIntoName(apart, pname);
4974 " VLDB reports its RW volume %lu exists on %s %s\n",
4975 (unsigned long)rwvolid,
4976 hostutil_GetNameByINet(aserver),
4982 /* Volume location matches the VLDB location */
4983 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
4984 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
4987 (entry.name, volumeinfo->name,
4988 VOLSER_OLDMAXVOLNAME) != 0)) {
4996 entry.flags |= RW_EXISTS;
4997 entry.volumeId[RWVOL] = rwvolid;
4998 if (!entry.volumeId[BACKVOL])
4999 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5000 if (!entry.volumeId[ROVOL])
5001 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5003 entry.serverFlags[idx] = ITSRWVOL;
5004 entry.serverNumber[idx] = aserver;
5005 entry.serverPartition[idx] = apart;
5006 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5010 /* One last check - to update BK if need to */
5011 code = CheckVldbRWBK(&entry, &mod);
5019 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5025 /* Check existence of RW and BK volumes */
5026 code = CheckVldbRWBK(&entry, &mod);
5032 idx = Lp_GetRwIndex(&entry);
5033 if (idx == -1) { /* RW index not found in the VLDB entry */
5034 idx = entry.nServers; /* Put it into next index */
5037 } else { /* RW index found in the VLDB entry */
5038 /* Verify if this volume's location matches where the VLDB says it is */
5039 if (!Lp_Match(aserver, apart, &entry)) {
5040 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5042 MapPartIdIntoName(apart, pname);
5044 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5045 (unsigned long)volumeinfo->volid,
5046 hostutil_GetNameByINet(aserver), pname);
5047 MapPartIdIntoName(entry.serverPartition[idx], pname);
5049 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5050 (unsigned long)rwvolid,
5051 hostutil_GetNameByINet(entry.
5056 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5057 if (!(entry.flags & BACK_EXISTS)) {
5059 } else if (volumeinfo->volid >
5060 entry.volumeId[BACKVOL]) {
5064 MapPartIdIntoName(entry.serverPartition[idx],
5067 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5068 entry.volumeId[BACKVOL],
5069 hostutil_GetNameByINet(aserver),
5072 " VLDB reports its BK volume ID is %lu\n",
5073 (unsigned long)volumeinfo->volid);
5077 MapPartIdIntoName(entry.serverPartition[idx],
5080 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5081 (unsigned long)volumeinfo->volid,
5082 hostutil_GetNameByINet(aserver),
5085 " VLDB reports its BK volume ID is %u\n",
5086 entry.volumeId[BACKVOL]);
5089 } else if (!entry.volumeId[BACKVOL]) {
5096 entry.flags |= BACK_EXISTS;
5097 entry.volumeId[RWVOL] = rwvolid;
5098 entry.volumeId[BACKVOL] = volumeinfo->volid;
5100 entry.serverNumber[idx] = aserver;
5101 entry.serverPartition[idx] = apart;
5102 entry.serverFlags[idx] = ITSRWVOL;
5108 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5109 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5110 /* This is a quick check to see if the RO entry exists in the
5111 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5112 * RO volume listed in the VLDB exists).
5114 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5116 idx = entry.nServers;
5120 if (!(entry.flags & RO_EXISTS)) {
5125 /* Before we correct the VLDB entry, make sure all the
5126 * ROs listed in the VLDB exist.
5128 code = CheckVldbRO(&entry, &mod);
5134 if (!(entry.flags & RO_EXISTS)) {
5135 /* No RO exists in the VLDB entry - add this one */
5136 idx = entry.nServers;
5139 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5140 /* The volume headers's RO ID does not match that in the VLDB entry,
5141 * and the vol hdr's ID is greater (implies more recent). So delete
5142 * all the RO volumes listed in VLDB entry and add this volume.
5144 for (j = 0; j < entry.nServers; j++) {
5145 if (entry.serverFlags[j] & ITSROVOL) {
5146 /* Verify this volume exists and print message we are orphaning it */
5148 MapPartIdIntoName(apart, pname);
5150 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5151 entry.volumeId[ROVOL],
5152 hostutil_GetNameByINet(entry.
5156 " VLDB reports its RO volume ID is %lu\n",
5157 (unsigned long)volumeinfo->volid);
5160 Lp_SetRWValue(entry, entry.serverNumber[idx],
5161 entry.serverPartition[idx], 0L, 0L);
5168 idx = entry.nServers;
5171 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5172 /* The volume headers's RO ID does not match that in the VLDB entry,
5173 * and the vol hdr's ID is lower (implies its older). So orphan it.
5176 MapPartIdIntoName(apart, pname);
5178 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5179 (unsigned long)volumeinfo->volid,
5180 hostutil_GetNameByINet(aserver), pname);
5182 " VLDB reports its RO volume ID is %u\n",
5183 entry.volumeId[ROVOL]);
5186 /* The RO volume ID in the volume header match that in the VLDB entry,
5187 * and there exist RO volumes in the VLDB entry. See if any of them
5188 * are this one. If not, then we add it.
5190 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5192 idx = entry.nServers;
5200 entry.flags |= RO_EXISTS;
5201 entry.volumeId[RWVOL] = rwvolid;
5202 entry.volumeId[ROVOL] = volumeinfo->volid;
5204 entry.serverNumber[idx] = aserver;
5205 entry.serverPartition[idx] = apart;
5206 entry.serverFlags[idx] = ITSROVOL;
5212 /* Remember largest volume id */
5213 if (entry.volumeId[ROVOL] > *maxvolid)
5214 *maxvolid = entry.volumeId[ROVOL];
5215 if (entry.volumeId[BACKVOL] > *maxvolid)
5216 *maxvolid = entry.volumeId[BACKVOL];
5217 if (entry.volumeId[RWVOL] > *maxvolid)
5218 *maxvolid = entry.volumeId[RWVOL];
5221 MapNetworkToHost(&entry, &storeEntry);
5224 code = VLDB_CreateEntry(&storeEntry);
5227 "Could not create a VLDB entry for the volume %lu\n",
5228 (unsigned long)rwvolid);
5235 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5236 LOCKREL_OPCODE | LOCKREL_AFSID |
5239 fprintf(STDERR, "Could not update entry for %lu\n",
5240 (unsigned long)rwvolid);
5245 *modentry = modified;
5246 } else if (pass == 2) {
5248 ubik_Call(VL_ReleaseLock, cstruct, 0, rwvolid, RWVOL,
5249 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5251 PrintError("Could not unlock VLDB entry ", code);
5256 fprintf(STDOUT, "-- status after --\n");
5258 EnumerateEntry(&entry);
5260 fprintf(STDOUT, "\n**no change**\n");
5264 VPRINT("\n_______________________________\n");
5269 sortVolumes(const void *a, const void *b)
5271 volintInfo *v1 = (volintInfo *) a;
5272 volintInfo *v2 = (volintInfo *) b;
5273 afs_int32 rwvolid1, rwvolid2;
5275 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5276 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5278 if (rwvolid1 > rwvolid2)
5279 return -1; /* lower RW id goes first */
5280 if (rwvolid1 < rwvolid2)
5283 if (v1->type == RWVOL)
5284 return -1; /* RW vols go first */
5285 if (v2->type == RWVOL)
5288 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5289 return -1; /* BK vols next */
5290 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5293 if (v1->volid < v2->volid)
5294 return 1; /* larger volids first */
5295 if (v1->volid > v2->volid)
5301 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5302 * Synchronize an individual volume against a sever and partition.
5303 * Checks the VLDB entry (similar to syncserv) as well as checks
5304 * if the volume exists on specified servers (similar to syncvldb).
5307 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5309 struct rx_connection *aconn = 0;
5310 afs_int32 j, k, code, vcode, error = 0;
5311 afs_int32 tverbose, mod, modified = 0;
5312 struct nvldbentry vldbentry;
5313 afs_int32 volumeid = 0;
5314 volEntries volumeInfo;
5315 struct partList PartList;
5317 afs_int32 maxvolid = 0;
5319 volumeInfo.volEntries_val = (volintInfo *) 0;
5320 volumeInfo.volEntries_len = 0;
5322 if (!aserver && flags) {
5323 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5327 /* Turn verbose logging off and do our own verbose logging */
5331 /* Read the VLDB entry */
5332 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5333 if (vcode && (vcode != VL_NOENT)) {
5334 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5337 } else if (!vcode) {
5338 MapHostToNetwork(&vldbentry);
5342 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5343 fprintf(STDOUT, "_______________________________\n");
5344 fprintf(STDOUT, "\n-- status before -- \n");
5346 fprintf(STDOUT, "\n**does not exist**\n");
5348 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5349 || (vldbentry.flags & BACK_EXISTS))
5350 EnumerateEntry(&vldbentry);
5352 fprintf(STDOUT, "\n");
5355 /* Verify that all of the VLDB entries exist on the repective servers
5356 * and partitions (this does not require that avolname be a volume ID).
5357 * Equivalent to a syncserv.
5360 code = CheckVldb(&vldbentry, &mod);
5362 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5370 /* If aserver is given, we will search for the desired volume on it */
5372 /* Generate array of partitions on the server that we will check */
5374 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5377 "Could not fetch the list of partitions from the server\n");
5381 PartList.partId[0] = apart;
5385 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5387 /* If a volume ID were given, search for it on each partition */
5388 if ((volumeid = atol(avolname))) {
5389 for (j = 0; j < pcnt; j++) {
5391 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5394 if (code != ENODEV) {
5395 fprintf(STDERR, "Could not query server\n");
5399 /* Found one, sync it with VLDB entry */
5401 CheckVolume(volumeInfo.volEntries_val, aserver,
5402 PartList.partId[j], &mod, &maxvolid);
5409 if (volumeInfo.volEntries_val)
5410 free(volumeInfo.volEntries_val);
5411 volumeInfo.volEntries_val = (volintInfo *) 0;
5412 volumeInfo.volEntries_len = 0;
5416 /* Check to see if the RW, BK, and RO IDs exist on any
5417 * partitions. We get the volume IDs from the VLDB.
5419 rv = 1; /* Read the VLDB entry ? */
5420 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5422 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5424 if (vcode == VL_NOENT)
5427 "Could not access the VLDB for volume %s\n",
5434 if (vldbentry.volumeId[j] == 0)
5437 for (k = 0; k < pcnt; k++) { /* For each partition */
5438 volumeInfo.volEntries_val = (volintInfo *) 0;
5439 volumeInfo.volEntries_len = 0;
5441 AFSVolListOneVolume(aconn, PartList.partId[k],
5442 vldbentry.volumeId[j], &volumeInfo);
5444 if (code != ENODEV) {
5445 fprintf(STDERR, "Could not query server\n");
5449 /* Found one, sync it with VLDB entry */
5451 CheckVolume(volumeInfo.volEntries_val, aserver,
5452 PartList.partId[k], &mod, &maxvolid);
5459 if (volumeInfo.volEntries_val)
5460 free(volumeInfo.volEntries_val);
5461 volumeInfo.volEntries_val = (volintInfo *) 0;
5462 volumeInfo.volEntries_len = 0;
5468 /* If verbose output, print a summary of what changed */
5470 fprintf(STDOUT, "-- status after --\n");
5471 code = VLDB_GetEntryByName(avolname, &vldbentry);
5472 if (code && (code != VL_NOENT)) {
5473 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5477 if (modified && (code == VL_NOENT)) {
5478 fprintf(STDOUT, "\n**entry deleted**\n");
5479 } else if (modified) {
5480 EnumerateEntry(&vldbentry);
5482 fprintf(STDOUT, "\n**no change**\n");
5484 fprintf(STDOUT, "\n_______________________________\n");
5488 /* Now check if the maxvolid is larger than that stored in the VLDB */
5490 afs_int32 maxvldbid = 0;
5491 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
5494 "Could not get the highest allocated volume id from the VLDB\n");
5497 } else if (maxvolid > maxvldbid) {
5499 id = maxvolid - maxvldbid + 1;
5500 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
5503 "Error in increasing highest allocated volume id in VLDB\n");
5513 fprintf(STDOUT, "...error encountered");
5515 fprintf(STDOUT, "...done entry\n");
5518 rx_DestroyConnection(aconn);
5519 if (volumeInfo.volEntries_val)
5520 free(volumeInfo.volEntries_val);
5522 PrintError("", error);
5527 * Synchronise vldb with the file server <aserver> and,
5528 * optionally, <apart>.
5531 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5533 struct rx_connection *aconn;
5534 afs_int32 code, error = 0;
5536 volEntries volumeInfo;
5537 struct partList PartList;
5541 afs_int32 failures = 0, modifications = 0, tentries = 0;
5543 afs_uint32 maxvolid = 0;
5545 volumeInfo.volEntries_val = (volintInfo *) 0;
5546 volumeInfo.volEntries_len = 0;
5548 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5550 /* Generate array of partitions to check */
5552 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5555 "Could not fetch the list of partitions from the server\n");
5559 PartList.partId[0] = apart;
5563 VPRINT("Processing volume entries ...\n");
5565 /* Step through the array of partitions */
5566 for (i = 0; i < pcnt; i++) {
5567 apart = PartList.partId[i];
5568 MapPartIdIntoName(apart, pname);
5570 volumeInfo.volEntries_val = (volintInfo *) 0;
5571 volumeInfo.volEntries_len = 0;
5572 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
5575 "Could not fetch the list of volumes from the server\n");
5579 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
5580 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
5581 sizeof(volintInfo), sortVolumes);
5584 for (vi = volumeInfo.volEntries_val, j = 0;
5585 j < volumeInfo.volEntries_len; j++, vi++) {
5593 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
5594 j + 1, vi->name, (unsigned long)vi->volid,
5595 hostutil_GetNameByINet(aserver), pname);
5599 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
5601 PrintError("", code);
5604 } else if (modified) {
5610 fprintf(STDOUT, "...error encountered\n\n");
5612 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
5619 "Could not process entries on server %s partition %s\n",
5620 hostutil_GetNameByINet(aserver), pname);
5622 if (volumeInfo.volEntries_val) {
5623 free(volumeInfo.volEntries_val);
5624 volumeInfo.volEntries_val = 0;
5627 } /* thru all partitions */
5629 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
5630 failures, modifications);
5633 /* Now check if the maxvolid is larger than that stored in the VLDB */
5635 afs_uint32 maxvldbid = 0;
5636 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
5639 "Could not get the highest allocated volume id from the VLDB\n");
5642 } else if (maxvolid > maxvldbid) {
5644 id = maxvolid - maxvldbid + 1;
5645 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
5648 "Error in increasing highest allocated volume id in VLDB\n");
5656 rx_DestroyConnection(aconn);
5657 if (volumeInfo.volEntries_val)
5658 free(volumeInfo.volEntries_val);
5659 PrintError("", error);
5664 * Determine if a volume exists on a server and partition.
5665 * Try creating a transaction on the volume. If we can,
5666 * the volume exists, if not, then return the error code.
5667 * Some error codes mean the volume is unavailable but
5668 * still exists - so we catch these error codes.
5671 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
5673 struct rx_connection *conn = (struct rx_connection *)0;
5674 afs_int32 code = -1;
5675 volEntries volumeInfo;
5677 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5679 volumeInfo.volEntries_val = (volintInfo *) 0;
5680 volumeInfo.volEntries_len = 0;
5681 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
5682 if (volumeInfo.volEntries_val)
5683 free(volumeInfo.volEntries_val);
5684 if (code == VOLSERILLEGAL_PARTITION)
5686 rx_DestroyConnection(conn);
5695 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
5699 afs_int32 code, error = 0;
5704 idx = Lp_GetRwIndex(entry);
5706 /* Check to see if the RW volume exists and set the RW_EXISTS
5709 if (idx == -1) { /* Did not find a RW entry */
5710 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
5711 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
5716 VolumeExists(entry->serverNumber[idx],
5717 entry->serverPartition[idx], entry->volumeId[RWVOL]);
5718 if (code == 0) { /* RW volume exists */
5719 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
5720 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
5723 } else if (code == ENODEV) { /* RW volume does not exist */
5724 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
5725 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
5729 /* If VLDB says it didn't exist, then ignore error */
5730 if (entry->flags & RW_EXISTS) {
5731 MapPartIdIntoName(entry->serverPartition[idx], pname);
5733 "Transaction call failed for RW volume %u on server %s %s\n",
5734 entry->volumeId[RWVOL],
5735 hostutil_GetNameByINet(entry->serverNumber[idx]),
5742 /* Check to see if the BK volume exists and set the BACK_EXISTS
5743 * flag accordingly. idx already ponts to the RW entry.
5745 if (idx == -1) { /* Did not find a RW entry */
5746 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
5747 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
5750 } else { /* Found a RW entry */
5752 VolumeExists(entry->serverNumber[idx],
5753 entry->serverPartition[idx],
5754 entry->volumeId[BACKVOL]);
5755 if (code == 0) { /* BK volume exists */
5756 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
5757 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
5760 } else if (code == ENODEV) { /* BK volume does not exist */
5761 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
5762 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
5766 /* If VLDB says it didn't exist, then ignore error */
5767 if (entry->flags & BACK_EXISTS) {
5768 MapPartIdIntoName(entry->serverPartition[idx], pname);
5770 "Transaction call failed for BK volume %u on server %s %s\n",
5771 entry->volumeId[BACKVOL],
5772 hostutil_GetNameByINet(entry->serverNumber[idx]),
5779 /* If there is an idx but the BK and RW volumes no
5780 * longer exist, then remove the RW entry.
5782 if ((idx != -1) && !(entry->flags & RW_EXISTS)
5783 && !(entry->flags & BACK_EXISTS)) {
5784 Lp_SetRWValue(entry, entry->serverNumber[idx],
5785 entry->serverPartition[idx], 0L, 0L);
5792 *modified = modentry;
5797 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
5800 int foundro = 0, modentry = 0;
5801 afs_int32 code, error = 0;
5807 /* Check to see if the RO volumes exist and set the RO_EXISTS
5810 for (idx = 0; idx < entry->nServers; idx++) {
5811 if (!(entry->serverFlags[idx] & ITSROVOL)) {
5812 continue; /* not a RO */
5816 VolumeExists(entry->serverNumber[idx],
5817 entry->serverPartition[idx], entry->volumeId[ROVOL]);
5818 if (code == 0) { /* RO volume exists */
5820 } else if (code == ENODEV) { /* RW volume does not exist */
5821 Lp_SetROValue(entry, entry->serverNumber[idx],
5822 entry->serverPartition[idx], 0L, 0L);
5827 MapPartIdIntoName(entry->serverPartition[idx], pname);
5829 "Transaction call failed for RO %u on server %s %s\n",
5830 entry->volumeId[ROVOL],
5831 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
5836 if (foundro) { /* A RO volume exists */
5837 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
5838 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
5841 } else { /* A RO volume does not exist */
5842 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
5843 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
5850 *modified = modentry;
5855 * Ensure that <entry> matches with the info on file servers
5858 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
5860 afs_int32 code, error = 0;
5861 struct nvldbentry storeEntry;
5862 int islocked = 0, mod, modentry, delentry = 0;
5868 fprintf(STDOUT, "_______________________________\n");
5869 fprintf(STDOUT, "\n-- status before -- \n");
5870 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
5871 || (entry->flags & BACK_EXISTS))
5872 EnumerateEntry(entry);
5873 fprintf(STDOUT, "\n");
5876 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
5877 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
5878 entry->name, VOLSER_OLDMAXVOLNAME - 10);
5882 /* Check to see if the VLDB is ok without locking it (pass 1).
5883 * If it will change, then lock the VLDB entry, read it again,
5884 * then make the changes to it (pass 2).
5888 ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL,
5891 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
5892 entry->volumeId[RWVOL]);
5897 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
5899 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
5903 MapHostToNetwork(entry);
5909 /* Check if the RW and BK entries are ok */
5910 code = CheckVldbRWBK(entry, &mod);
5913 if (mod && (pass == 1))
5918 /* Check if the RO volumes entries are ok */
5919 code = CheckVldbRO(entry, &mod);
5922 if (mod && (pass == 1))
5927 /* The VLDB entry has been updated. If it as been modified, then
5928 * write the entry back out the the VLDB.
5934 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
5935 && !(entry->flags & RO_EXISTS)) {
5936 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
5938 ubik_Call(VL_DeleteEntry, cstruct, 0, entry->volumeId[RWVOL],
5942 "Could not delete VLDB entry for volume %u \n",
5943 entry->volumeId[RWVOL]);
5948 /* Replace old entry with our new one */
5949 MapNetworkToHost(entry, &storeEntry);
5951 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
5952 (LOCKREL_OPCODE | LOCKREL_AFSID |
5953 LOCKREL_TIMESTAMP));
5955 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
5956 entry->volumeId[RWVOL]);
5966 fprintf(STDOUT, "-- status after --\n");
5968 fprintf(STDOUT, "\n**entry deleted**\n");
5970 EnumerateEntry(entry);
5972 fprintf(STDOUT, "\n**no change**\n");
5976 VPRINT("\n_______________________________\n");
5980 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
5982 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
5985 "Could not release lock on VLDB entry for volume %u\n",
5986 entry->volumeId[RWVOL]);
5995 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
5998 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6000 struct rx_connection *aconn;
6001 afs_int32 code, error = 0;
6002 afs_int32 nentries, tentries = 0;
6003 struct VldbListByAttributes attributes;
6004 nbulkentries arrayEntries;
6005 afs_int32 failures = 0, modified, modifications = 0;
6006 struct nvldbentry *vlentry;
6007 afs_int32 si, nsi, j;
6009 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6011 /* Set up attributes to search VLDB */
6012 attributes.server = ntohl(aserver);
6013 attributes.Mask = VLLIST_SERVER;
6015 attributes.partition = apart;
6016 attributes.Mask |= VLLIST_PARTITION;
6019 VPRINT("Processing VLDB entries ...\n");
6021 /* While we need to collect more VLDB entries */
6022 for (si = 0; si != -1; si = nsi) {
6023 memset(&arrayEntries, 0, sizeof(arrayEntries));
6025 /* Collect set of VLDB entries */
6027 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6028 &arrayEntries, &nsi);
6029 if (code == RXGEN_OPCODE) {
6030 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6034 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6037 tentries += nentries;
6039 for (j = 0; j < nentries; j++) {
6040 vlentry = &arrayEntries.nbulkentries_val[j];
6041 MapHostToNetwork(vlentry);
6043 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6045 code = CheckVldb(vlentry, &modified);
6047 PrintError("", code);
6049 "Could not process VLDB entry for volume %s\n",
6052 } else if (modified) {
6058 fprintf(STDOUT, "...error encountered\n\n");
6060 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6065 if (arrayEntries.nbulkentries_val) {
6066 free(arrayEntries.nbulkentries_val);
6067 arrayEntries.nbulkentries_val = 0;
6071 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6072 failures, modifications);
6076 rx_DestroyConnection(aconn);
6077 if (arrayEntries.nbulkentries_val)
6078 free(arrayEntries.nbulkentries_val);
6081 error = VOLSERFAILEDOP;
6085 /*rename volume <oldname> to <newname>, changing the names of the related
6086 *readonly and backup volumes. This operation is also idempotent.
6087 *salvager is capable of recovering from rename operation stopping halfway.
6088 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6090 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6092 struct nvldbentry storeEntry;
6093 afs_int32 vcode, code, rcode, error;
6095 char nameBuffer[256];
6097 struct rx_connection *aconn;
6101 aconn = (struct rx_connection *)0;
6105 vcode = ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6108 " Could not lock the VLDB entry for the volume %u \n",
6109 entry->volumeId[RWVOL]);
6114 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6115 MapNetworkToHost(entry, &storeEntry);
6116 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6118 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6119 entry->volumeId[RWVOL]);
6123 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6124 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6125 * is concerned, oldname is lost */
6126 if (entry->flags & RW_EXISTS) {
6127 index = Lp_GetRwIndex(entry);
6128 if (index == -1) { /* there is a serious discrepancy */
6130 "There is a serious discrepancy in VLDB entry for volume %u\n",
6131 entry->volumeId[RWVOL]);
6132 fprintf(STDERR, "try building VLDB from scratch\n");
6133 error = VOLSERVLDB_ERROR;
6136 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6138 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6139 entry->serverPartition[index], ITOffline, &tid);
6140 if (code) { /*volume doesnot exist */
6142 "Could not start transaction on the rw volume %u\n",
6143 entry->volumeId[RWVOL]);
6146 } else { /*volume exists, process it */
6149 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6150 entry->volumeId[RWVOL],
6151 entry->volumeId[ROVOL],
6152 entry->volumeId[BACKVOL]);
6154 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6155 code = AFSVolEndTrans(aconn, tid, &rcode);
6159 "Could not end transaction on volume %s %u\n",
6160 entry->name, entry->volumeId[RWVOL]);
6165 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6166 entry->name, entry->volumeId[RWVOL]);
6172 rx_DestroyConnection(aconn);
6173 aconn = (struct rx_connection *)0;
6175 /*end rw volume processing */
6176 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6177 index = Lp_GetRwIndex(entry);
6178 if (index == -1) { /* there is a serious discrepancy */
6180 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6181 entry->volumeId[BACKVOL]);
6182 fprintf(STDERR, "try building VLDB from scratch\n");
6183 error = VOLSERVLDB_ERROR;
6186 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6188 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6189 entry->serverPartition[index], ITOffline, &tid);
6190 if (code) { /*volume doesnot exist */
6192 "Could not start transaction on the backup volume %u\n",
6193 entry->volumeId[BACKVOL]);
6196 } else { /*volume exists, process it */
6197 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6199 "Volume name %s.backup exceeds the limit of %u characters\n",
6200 newname, VOLSER_OLDMAXVOLNAME);
6204 strcpy(nameBuffer, newname);
6205 strcat(nameBuffer, ".backup");
6208 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6209 entry->volumeId[RWVOL], 0, 0);
6211 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6212 code = AFSVolEndTrans(aconn, tid, &rcode);
6216 "Could not end transaction on the backup volume %u\n",
6217 entry->volumeId[BACKVOL]);
6223 "Could not set parameters on the backup volume %u\n",
6224 entry->volumeId[BACKVOL]);
6229 } /* end backup processing */
6231 rx_DestroyConnection(aconn);
6232 aconn = (struct rx_connection *)0;
6233 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6234 for (i = 0; i < entry->nServers; i++) {
6235 if (entry->serverFlags[i] & ITSROVOL) {
6236 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6238 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6239 entry->serverPartition[i], ITOffline,
6241 if (code) { /*volume doesnot exist */
6243 "Could not start transaction on the ro volume %u\n",
6244 entry->volumeId[ROVOL]);
6247 } else { /*volume exists, process it */
6248 strcpy(nameBuffer, newname);
6249 strcat(nameBuffer, ".readonly");
6250 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6252 "Volume name %s exceeds the limit of %u characters\n",
6253 nameBuffer, VOLSER_OLDMAXVOLNAME);
6258 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6259 entry->volumeId[RWVOL], 0, 0);
6261 VPRINT2("Renamed RO volume %s on host %s\n",
6263 hostutil_GetNameByINet(entry->
6265 code = AFSVolEndTrans(aconn, tid, &rcode);
6269 "Could not end transaction on volume %u\n",
6270 entry->volumeId[ROVOL]);
6276 "Could not set parameters on the ro volume %u\n",
6277 entry->volumeId[ROVOL]);
6283 rx_DestroyConnection(aconn);
6284 aconn = (struct rx_connection *)0;
6291 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
6293 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6296 "Could not unlock the VLDB entry for the volume %s %u\n",
6297 entry->name, entry->volumeId[RWVOL]);
6303 code = AFSVolEndTrans(aconn, tid, &rcode);
6307 fprintf(STDERR, "Failed to end transaction on a volume \n");
6313 rx_DestroyConnection(aconn);
6314 PrintError("", error);
6319 /*report on all the active transactions on volser */
6321 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6323 struct rx_connection *aconn;
6324 transDebugEntries transInfo;
6327 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6328 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6329 transInfo.transDebugEntries_len = 0;
6330 code = AFSVolMonitor(aconn, &transInfo);
6333 "Could not access status information about the server\n");
6334 PrintError("", code);
6335 if (transInfo.transDebugEntries_val)
6336 free(transInfo.transDebugEntries_val);
6338 rx_DestroyConnection(aconn);
6341 *rcount = transInfo.transDebugEntries_len;
6342 *rpntr = transInfo.transDebugEntries_val;
6344 rx_DestroyConnection(aconn);
6351 /*delete the volume without interacting with the vldb */
6353 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6355 afs_int32 rcode, ttid, error, code;
6356 struct rx_connection *aconn;
6362 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6363 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6365 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6366 (unsigned long)volid);
6370 code = AFSVolDeleteVolume(aconn, ttid);
6372 fprintf(STDERR, "Could not delete volume %lu\n",
6373 (unsigned long)volid);
6377 code = AFSVolEndTrans(aconn, ttid, &rcode);
6382 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6383 (unsigned long)volid);
6389 code = AFSVolEndTrans(aconn, ttid, &rcode);
6395 PrintError("", error);
6397 rx_DestroyConnection(aconn);
6402 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6403 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6405 struct rx_connection *conn = 0;
6407 afs_int32 code, error = 0, rcode;
6409 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6411 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6415 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6417 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6421 code = AFSVolSetFlags(conn, tid, setflag);
6423 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6428 #ifdef AFS_PTHREAD_ENV
6431 IOMGR_Sleep(sleeptime);
6438 code = AFSVolEndTrans(conn, tid, &rcode);
6439 if (code || rcode) {
6440 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6442 error = (code ? code : rcode);
6447 rx_DestroyConnection(conn);
6452 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6455 struct rx_connection *conn = 0;
6457 afs_int32 code, error = 0, rcode;
6459 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6461 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6465 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6467 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6471 code = AFSVolSetInfo(conn, tid, infop);
6473 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6480 code = AFSVolEndTrans(conn, tid, &rcode);
6481 if (code || rcode) {
6482 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6484 error = (code ? code : rcode);
6489 rx_DestroyConnection(conn);
6494 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6495 afs_int32 fromdate, struct volintSize *vol_size)
6497 struct rx_connection *aconn = (struct rx_connection *)0;
6498 afs_int32 tid = 0, rcode = 0;
6499 afs_int32 code, error = 0;
6502 /* get connections to the servers */
6503 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6505 VPRINT1("Starting transaction on volume %u...", afromvol);
6506 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6507 EGOTO1(error_exit, code,
6508 "Could not start transaction on the volume %u to be measured\n",
6512 VPRINT1("Getting size of volume on volume %u...", afromvol);
6513 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6514 EGOTO(error_exit, code, "Could not start the measurement process \n");
6519 VPRINT1("Ending transaction on volume %u...", afromvol);
6520 code = AFSVolEndTrans(aconn, tid, &rcode);
6521 if (code || rcode) {
6522 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6524 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6526 error = (code ? code : rcode);
6531 rx_DestroyConnection(aconn);
6533 PrintError("", error);
6537 /*maps the host addresses in <old > (present in network byte order) to
6538 that in< new> (present in host byte order )*/
6540 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
6544 /*copy all the fields */
6545 strcpy(new->name, old->name);
6546 /* new->volumeType = old->volumeType;*/
6547 new->nServers = old->nServers;
6548 count = old->nServers;
6549 if (count < NMAXNSERVERS)
6551 for (i = 0; i < count; i++) {
6552 new->serverNumber[i] = ntohl(old->serverNumber[i]);
6553 new->serverPartition[i] = old->serverPartition[i];
6554 new->serverFlags[i] = old->serverFlags[i];
6556 new->volumeId[RWVOL] = old->volumeId[RWVOL];
6557 new->volumeId[ROVOL] = old->volumeId[ROVOL];
6558 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
6559 new->cloneId = old->cloneId;
6560 new->flags = old->flags;
6563 /*maps the host entries in <entry> which are present in host byte order to network byte order */
6565 MapHostToNetwork(struct nvldbentry *entry)
6569 count = entry->nServers;
6570 if (count < NMAXNSERVERS)
6572 for (i = 0; i < count; i++) {
6573 entry->serverNumber[i] = htonl(entry->serverNumber[i]);