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 afs_int32 VolumeExists(), CheckVldbRWBK(), CheckVldb();
69 struct ubik_client *cstruct;
71 extern int VL_GetNewVolumeId();
72 extern int VL_SetLock();
73 extern int VL_ReleaseLock();
74 extern int VL_DeleteEntry();
76 void MapNetworkToHost();
77 void MapHostToNetwork();
81 afs_int32 vldbEntryIndex;
84 /* Utility macros used by rest of this source file */
85 #define EPRINT(ec, es) \
87 fprintf(STDERR, "\n"); \
88 fprintf(STDERR, (es)); \
92 #define EPRINT1(ec, es, ep1) \
94 fprintf(STDERR, "\n"); \
95 fprintf(STDERR, (es), (ep1)); \
99 #define EPRINT2(ec, es, ep1, ep2) \
101 fprintf(STDERR, "\n"); \
102 fprintf(STDERR, (es), (ep1), (ep2)); \
103 PrintError(" ",ec); \
106 #define EPRINT3(ec, es, ep1, ep2, ep3) \
108 fprintf(STDERR, "\n"); \
109 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
110 PrintError(" ",ec); \
113 #define EGOTO(where, ec, es) \
122 #define EGOTO1(where, ec, es, ep1) \
125 EPRINT1((ec),(es),(ep1)); \
131 #define EGOTO2(where, ec, es, ep1, ep2) \
134 EPRINT2((ec),(es),(ep1),(ep2)); \
140 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
143 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
150 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
151 #define VPRINT1(es, p) \
152 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
153 #define VPRINT2(es, p1, p2) \
154 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
155 #define VPRINT3(es, p1, p2, p3) \
156 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
158 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
162 /* getting rid of this */
163 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
166 /* Protos for static routines */
167 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
168 afs_int32 apart, afs_int32 okvol,
170 static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
172 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
173 struct rx_connection **connPtr, afs_int32 * transPtr,
174 afs_int32 * timePtr);
175 static int SimulateForwardMultiple(struct rx_connection *fromconn,
176 afs_int32 fromtid, afs_int32 fromdate,
177 manyDests * tr, afs_int32 flags,
178 void *cookie, manyResults * results);
179 static int rel_compar(struct release *r1, struct release *r2);
180 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
181 afs_int32 apart, afs_int32 * modentry,
182 afs_uint32 * maxvolid);
185 /*map the partition <partId> into partition name <partName>*/
187 MapPartIdIntoName(afs_int32 partId, char *partName)
189 if (partId < 26) { /* what if partId > = 26 ? */
190 strcpy(partName, "/vicep");
191 partName[6] = partId + 'a';
194 } else if (partId < VOLMAXPARTS) {
195 strcpy(partName, "/vicep");
197 partName[6] = 'a' + (partId / 26);
198 partName[7] = 'a' + (partId % 26);
210 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
211 response = c = getchar();
212 while (!(c == EOF || c == '\n'))
213 c = getchar(); /*skip to end of line */
214 code = (response == 'y' || response == 'Y');
220 PrintError(char *msg, afs_int32 errcode)
222 fprintf(STDERR, msg);
223 /*replace by a big switch statement */
228 fprintf(STDERR, "Possible communication failure\n");
231 fprintf(STDERR, "Volume needs to be salvaged\n");
234 fprintf(STDERR, "Bad vnode number quoted\n");
238 "Volume not attached, does not exist, or not on line\n");
241 fprintf(STDERR, "Volume already exists\n");
244 fprintf(STDERR, "Volume is not in service\n");
247 fprintf(STDERR, "Volume is off line\n");
250 fprintf(STDERR, "Volume is already on line\n");
253 fprintf(STDERR, "Partition is full\n");
256 fprintf(STDERR, "Volume max quota exceeded\n");
259 fprintf(STDERR, "Volume temporarily unavailable\n");
262 fprintf(STDERR, "Volume has moved to another server\n");
265 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
268 fprintf(STDERR, "VLDB: a read terminated too early\n");
271 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
274 fprintf(STDERR, "VLDB: internal creation failure\n");
277 fprintf(STDERR, "VLDB: no such entry\n");
280 fprintf(STDERR, "VLDB: vldb database is empty\n");
283 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
286 fprintf(STDERR, "VLDB: volume name is illegal\n");
289 fprintf(STDERR, "VLDB: index was out of range\n");
292 fprintf(STDERR, "VLDB: bad volume type\n");
295 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
297 case VL_BADPARTITION:
298 fprintf(STDERR, "VLDB: bad partition number\n");
301 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
304 fprintf(STDERR, "VLDB: no such repsite server exists\n");
306 case VL_DUPREPSERVER:
307 fprintf(STDERR, "VLDB: replication site server already exists\n");
310 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
313 fprintf(STDERR, "VLDB: illegal reference count number\n");
315 case VL_SIZEEXCEEDED:
316 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
319 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
321 case VL_BADVOLIDBUMP:
322 fprintf(STDERR, "VLDB: illegal max volid increment\n");
324 case VL_IDALREADYHASHED:
325 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
328 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
331 fprintf(STDERR, "VLDB: bad volume operation code\n");
333 case VL_BADRELLOCKTYPE:
334 fprintf(STDERR, "VLDB: bad release lock type\n");
337 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
339 case VL_BADSERVERFLAG:
340 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
343 fprintf(STDERR, "VLDB: no permission access for call\n");
345 case VOLSERREAD_DUMPERROR:
347 "VOLSER: Problems encountered in reading the dump file !\n");
349 case VOLSERDUMPERROR:
350 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
352 case VOLSERATTACH_ERROR:
353 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
355 case VOLSERDETACH_ERROR:
356 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
358 case VOLSERILLEGAL_PARTITION:
359 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
361 case VOLSERBAD_ACCESS:
362 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
364 case VOLSERVLDB_ERROR:
365 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
368 fprintf(STDERR, "VOLSER: error in volume name\n");
371 fprintf(STDERR, "VOLSER: volume has moved\n");
374 fprintf(STDERR, "VOLSER: illegal operation\n");
376 case VOLSERBADRELEASE:
377 fprintf(STDERR, "VOLSER: release could not be completed\n");
380 fprintf(STDERR, "VOLSER: volume is busy\n");
382 case VOLSERNO_MEMORY:
383 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
387 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
389 case VOLSERMULTIRWVOL:
391 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
395 "VOLSER: not all entries were successfully processed\n");
402 initialize_KA_error_table();
403 initialize_RXK_error_table();
404 initialize_KTC_error_table();
405 initialize_ACFG_error_table();
406 initialize_CMD_error_table();
407 initialize_VL_error_table();
409 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
410 fprintf(STDERR, "%s: %s\n", error_table_name(errcode),
411 error_message(errcode));
419 static struct rx_securityClass *uvclass = 0;
420 static int uvindex = -1;
421 /* called by VLDBClient_Init to set the security module to be used in the RPC */
423 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
429 /* bind to volser on <port> <aserver> */
430 /* takes server address in network order, port in host order. dumb */
431 struct rx_connection *
432 UV_Bind(afs_int32 aserver, afs_int32 port)
434 register struct rx_connection *tc;
436 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
441 /* if <okvol> is allright(indicated by beibg able to
442 * start a transaction, delete the <delvol> */
444 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
445 afs_int32 okvol, afs_int32 delvol)
447 afs_int32 error, code, tid, rcode;
453 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
456 code = AFSVolDeleteVolume(aconn, tid);
459 code = AFSVolEndTrans(aconn, tid, &rcode);
466 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
468 code = AFSVolEndTrans(aconn, tid, &rcode);
473 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
476 code = AFSVolDeleteVolume(aconn, tid);
479 code = AFSVolEndTrans(aconn, tid, &rcode);
490 /* called by EmuerateEntry, show vldb entry in a reasonable format */
492 SubEnumerateEntry(struct nvldbentry *entry)
499 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
500 if (entry->flags & RW_EXISTS)
501 fprintf(STDOUT, " valid \n");
503 fprintf(STDOUT, " invalid \n");
504 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
505 if (entry->flags & RO_EXISTS)
506 fprintf(STDOUT, " valid \n");
508 fprintf(STDOUT, " invalid \n");
509 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
510 if (entry->flags & BACK_EXISTS)
511 fprintf(STDOUT, " valid \n");
513 fprintf(STDOUT, " invalid \n");
514 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
515 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
517 if (entry->flags & RW_EXISTS)
518 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
519 if (entry->flags & RO_EXISTS)
520 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
521 if (entry->flags & BACK_EXISTS)
522 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
523 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
524 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
525 fprintf(STDOUT, "\n");
527 fprintf(STDOUT, " number of sites -> %lu\n",
528 (unsigned long)entry->nServers);
529 for (i = 0; i < entry->nServers; i++) {
530 if (entry->serverFlags[i] & NEW_REPSITE)
533 for (i = 0; i < entry->nServers; i++) {
534 MapPartIdIntoName(entry->serverPartition[i], pname);
535 fprintf(STDOUT, " server %s partition %s ",
536 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
537 if (entry->serverFlags[i] & ITSRWVOL)
538 fprintf(STDOUT, "RW Site ");
540 fprintf(STDOUT, "RO Site ");
542 if (entry->serverFlags[i] & NEW_REPSITE)
543 fprintf(STDOUT, " -- New release");
545 fprintf(STDOUT, " -- Old release");
547 if (entry->serverFlags[i] & RO_DONTUSE)
548 fprintf(STDOUT, " -- Not released");
550 fprintf(STDOUT, "\n");
557 /*enumerate the vldb entry corresponding to <entry> */
559 EnumerateEntry(struct nvldbentry *entry)
562 fprintf(STDOUT, "\n");
563 fprintf(STDOUT, "%s \n", entry->name);
564 SubEnumerateEntry(entry);
568 /* forcibly remove a volume. Very dangerous call */
570 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
572 register struct rx_connection *tconn;
573 register afs_int32 code;
575 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
577 code = AFSVolNukeVolume(tconn, partid, volid);
578 rx_DestroyConnection(tconn);
584 /* like df. Return usage of <pname> on <server> in <partition> */
586 UV_PartitionInfo(afs_int32 server, char *pname,
587 struct diskPartition *partition)
589 register struct rx_connection *aconn;
593 aconn = (struct rx_connection *)0;
594 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
595 code = AFSVolPartitionInfo(aconn, pname, partition);
597 fprintf(STDERR, "Could not get information on partition %s\n", pname);
598 PrintError("", code);
601 rx_DestroyConnection(aconn);
605 /* old interface to create volume */
607 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
611 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
615 /* create a volume, given a server, partition number, volume name --> sends
616 * back new vol id in <anewid>*/
618 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
619 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
620 afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
623 register struct rx_connection *aconn;
625 register afs_int32 code;
627 afs_int32 rcode, vcode;
628 struct nvldbentry entry, storeEntry; /*the new vldb entry */
629 struct volintInfo tstatus;
632 aconn = (struct rx_connection *)0;
634 memset(&tstatus, 0, sizeof(struct volintInfo));
636 tstatus.maxquota = aquota;
638 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
639 /* next the next 3 available ids from the VLDB */
640 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 3, anewid);
641 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
644 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
645 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
648 code = AFSVolSetInfo(aconn, tid, &tstatus);
650 EPRINT(code, "Could not change quota (error %d), continuing...\n");
652 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
653 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
656 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
658 /* set up the vldb entry for this volume */
659 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
661 entry.serverNumber[0] = aserver; /* this should have another
662 * level of indirection later */
663 entry.serverPartition[0] = apart; /* this should also have
664 * another indirection level */
665 entry.flags = RW_EXISTS; /* this records that rw volume exists */
666 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
667 entry.volumeId[RWVOL] = *anewid;
668 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
669 entry.volumeId[BACKVOL] = *anewid + 2;
671 /*map into right byte order, before passing to xdr, the stuff has to be in host
672 * byte order. Xdr converts it into network order */
673 MapNetworkToHost(&entry, &storeEntry);
674 /* create the vldb entry */
675 vcode = VLDB_CreateEntry(&storeEntry);
678 "Could not create a VLDB entry for the volume %s %lu\n",
679 aname, (unsigned long)*anewid);
680 /*destroy the created volume */
681 VPRINT1("Deleting the newly created volume %u\n", *anewid);
682 AFSVolDeleteVolume(aconn, tid);
686 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
687 /* volume created, now terminate the transaction and release the connection */
688 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
689 * the volume will come online anyway when transaction timesout , so if
690 * vldb entry exists then the volume is guaranteed to exist too wrt create */
694 "Failed to end the transaction on the volume %s %lu\n", aname,
695 (unsigned long)*anewid);
702 code = AFSVolEndTrans(aconn, tid, &rcode);
704 fprintf(STDERR, "WARNING: could not end transaction\n");
707 rx_DestroyConnection(aconn);
708 PrintError("", error);
714 /* create a volume, given a server, partition number, volume name --> sends
715 * back new vol id in <anewid>*/
717 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
720 register struct rx_connection *aconn;
723 struct nvldbentry entry, storeEntry; /*the new vldb entry */
725 aconn = (struct rx_connection *)0;
728 /* set up the vldb entry for this volume */
729 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
731 entry.serverNumber[0] = aserver; /* this should have another
732 * level of indirection later */
733 entry.serverPartition[0] = apart; /* this should also have
734 * another indirection level */
735 entry.flags = RW_EXISTS; /* this records that rw volume exists */
736 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
737 entry.volumeId[RWVOL] = aid;
739 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
740 entry.volumeId[BACKVOL] = *anewid + 2;
742 entry.volumeId[ROVOL] = 0;
743 entry.volumeId[BACKVOL] = 0;
746 /*map into right byte order, before passing to xdr, the stuff has to be in host
747 * byte order. Xdr converts it into network order */
748 MapNetworkToHost(&entry, &storeEntry);
749 /* create the vldb entry */
750 vcode = VLDB_CreateEntry(&storeEntry);
753 "Could not create a VLDB entry for the volume %s %lu\n",
754 aname, (unsigned long)aid);
758 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
762 rx_DestroyConnection(aconn);
763 PrintError("", error);
767 /* Delete the volume <volid>on <aserver> <apart>
768 * the physical entry gets removed from the vldb only if the ref count
772 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
774 struct rx_connection *aconn = (struct rx_connection *)0;
776 afs_int32 code, rcode;
778 struct nvldbentry entry, storeEntry;
780 afs_int32 avoltype = -1, vtype;
781 int notondisk = 0, notinvldb = 0;
783 /* Find and read bhe VLDB entry for this volume */
784 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, avoltype, VLOP_DELETE);
786 if (code != VL_NOENT) {
787 EGOTO1(error_exit, code,
788 "Could not lock VLDB entry for the volume %u\n", avolid);
794 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
795 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
797 MapHostToNetwork(&entry);
800 EnumerateEntry(&entry);
803 /* Whether volume is in the VLDB or not. Delete the volume on disk */
804 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
805 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
807 if (code == VNOVOL) {
810 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
814 VPRINT1("Trying to delete the volume %u ...", avolid);
816 code = AFSVolDeleteVolume(aconn, ttid);
817 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
819 code = AFSVolEndTrans(aconn, ttid, &rcode);
820 code = (code ? code : rcode);
822 EGOTO1(error_exit, code,
823 "Could not end the transaction for the volume %u \n", avolid);
827 /* Now update the VLDB entry.
828 * But first, verify we have a VLDB entry.
829 * Whether volume is on disk or not. Delete the volume in VLDB.
834 if (avolid == entry.volumeId[BACKVOL]) {
835 /* Its a backup volume, modify the VLDB entry. Check that the
836 * backup volume is on the server/partition we asked to delete.
838 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
839 notinvldb = 2; /* Not on this server and partition */
843 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
845 entry.flags &= ~BACK_EXISTS;
849 else if (avolid == entry.volumeId[ROVOL]) {
850 /* Its a read-only volume, modify the VLDB entry. Check that the
851 * readonly volume is on the server/partition we asked to delete.
852 * If flags does not have RO_EIXSTS set, then this may mean the RO
853 * hasn't been released (and could exist in VLDB).
855 if (!Lp_ROMatch(aserver, apart, &entry)) {
856 notinvldb = 2; /* Not found on this server and partition */
862 "Marking the readonly volume %lu deleted in the VLDB\n",
863 (unsigned long)avolid);
865 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
867 if (!Lp_ROMatch(0, 0, &entry))
868 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
872 else if (avolid == entry.volumeId[RWVOL]) {
873 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
874 * Check that the readwrite volumes is on the server/partition we
877 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
878 notinvldb = 2; /* Not found on this server and partition */
882 /* Delete backup if it exists */
884 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
888 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
889 entry.volumeId[BACKVOL]);
892 code = AFSVolDeleteVolume(aconn, ttid);
893 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
894 entry.volumeId[BACKVOL]);
896 code = AFSVolEndTrans(aconn, ttid, &rcode);
898 code = (code ? code : rcode);
899 EGOTO1(error_exit, code,
900 "Could not end the transaction for the volume %u \n",
901 entry.volumeId[BACKVOL]);
903 fprintf(STDOUT, " done\n");
908 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
909 (unsigned long)avolid,
911 flags & BACK_EXISTS) ? ", and its backup volume," :
914 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
916 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
919 if (entry.flags & RO_EXISTS)
920 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
924 notinvldb = 2; /* Not found on this server and partition */
928 /* Either delete or replace the VLDB entry */
929 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
932 "Last reference to the VLDB entry for %lu - deleting entry\n",
933 (unsigned long)avolid);
934 code = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, vtype);
935 EGOTO1(error_exit, code,
936 "Could not delete the VLDB entry for the volume %u \n",
939 MapNetworkToHost(&entry, &storeEntry);
941 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
942 (LOCKREL_OPCODE | LOCKREL_AFSID |
944 EGOTO1(error_exit, code,
945 "Could not update the VLDB entry for the volume %u \n",
954 if (notondisk && notinvldb) {
955 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
956 ((notinvldb == 2) ? "on server and partition" : ""));
959 } else if (notondisk) {
961 "WARNING: Volume %lu did not exist on the partition\n",
962 (unsigned long)avolid);
963 } else if (notinvldb) {
964 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
965 (unsigned long)avolid,
966 ((notinvldb == 2) ? "on server and partition" : ""));
970 code = AFSVolEndTrans(aconn, ttid, &rcode);
971 code = (code ? code : rcode);
973 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
974 (unsigned long)avolid);
975 PrintError("", code);
983 ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, -1,
984 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
987 "Could not release the lock on the VLDB entry for the volume %u \n",
995 rx_DestroyConnection(aconn);
999 /* add recovery to UV_MoveVolume */
1001 #define TESTC 0 /* set to test recovery code, clear for production */
1007 sigint_handler(int x)
1012 fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
1014 "WARNING: may leave AFS storage and metadata in indeterminate state\n");
1015 fprintf(STDOUT, "enter second control-c to exit\n");
1019 (void)signal(SIGINT, sigint_handler);
1024 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1025 * <atopart>. The operation is almost idempotent
1029 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1030 afs_int32 atoserver, afs_int32 atopart)
1032 struct rx_connection *toconn, *fromconn;
1033 afs_int32 fromtid, totid, clonetid;
1036 char tmpName[VOLSER_MAXVOLNAME + 1];
1039 struct restoreCookie cookie;
1040 register afs_int32 vcode, code;
1041 afs_int32 newVol, volid, backupId;
1042 struct volser_status tstatus;
1043 struct destServer destination;
1045 struct nvldbentry entry, storeEntry;
1046 int i, islocked, pntg;
1048 char in, lf; /* for test code */
1051 #ifdef ENABLE_BUGFIX_1165
1052 volEntries volumeInfo;
1053 struct volintInfo *infop = 0;
1057 fromconn = (struct rx_connection *)0;
1058 toconn = (struct rx_connection *)0;
1068 /* support control-c processing */
1071 (void)signal(SIGINT, sigint_handler);
1075 "\nThere are three tests points - verifies all code paths through recovery.\n");
1076 fprintf(STDOUT, "First test point - operation not started.\n");
1077 fprintf(STDOUT, "...test here (y, n)? ");
1079 fscanf(stdin, "%c", &in);
1080 fscanf(stdin, "%c", &lf); /* toss away */
1082 fprintf(STDOUT, "type control-c\n");
1084 fprintf(stdout, ".");
1089 /* or drop through */
1092 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1093 EGOTO1(mfail, vcode,
1094 "Could not fetch the entry for the volume %u from the VLDB \n",
1097 if (entry.volumeId[RWVOL] != afromvol) {
1098 fprintf(STDERR, "Only RW volume can be moved\n");
1102 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1103 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1106 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1107 EGOTO1(mfail, vcode,
1108 "Could not fetch the entry for the volume %u from the VLDB \n",
1111 backupId = entry.volumeId[BACKVOL];
1112 MapHostToNetwork(&entry);
1114 if (!Lp_Match(afromserver, afrompart, &entry)) {
1115 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1116 if (!Lp_Match(atoserver, atopart, &entry)) {
1117 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1118 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1119 (unsigned long)afromvol);
1120 fprintf(STDERR, "The current site is :");
1121 for (i = 0; i < entry.nServers; i++) {
1122 if (entry.serverFlags[i] == ITSRWVOL) {
1124 MapPartIdIntoName(entry.serverPartition[i], pname);
1125 fprintf(STDERR, " server %s partition %s \n",
1126 hostutil_GetNameByINet(entry.serverNumber[i]),
1131 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1132 (LOCKREL_OPCODE | LOCKREL_AFSID |
1133 LOCKREL_TIMESTAMP));
1134 EGOTO1(mfail, vcode,
1135 " Could not release lock on the VLDB entry for the volume %u \n",
1138 return VOLSERVOLMOVED;
1141 /* delete the volume afromvol on src_server */
1142 /* from-info does not exist but to-info does =>
1143 * we have already done the move, but the volume
1144 * may still be existing physically on from fileserver
1146 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1151 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1153 if (!code) { /* volume exists - delete it */
1154 VPRINT1("Setting flags on leftover source volume %u ...",
1157 AFSVolSetFlags(fromconn, fromtid,
1158 VTDeleteOnSalvage | VTOutOfService);
1160 "Failed to set flags on the leftover source volume %u\n",
1164 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1165 code = AFSVolDeleteVolume(fromconn, fromtid);
1167 "Failed to delete the leftover source volume %u\n",
1171 VPRINT1("Ending transaction on leftover source volume %u ...",
1173 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1178 "Could not end the transaction for the leftover source volume %u \n",
1183 /*delete the backup volume now */
1186 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1188 if (!code) { /* backup volume exists - delete it */
1189 VPRINT1("Setting flags on leftover backup volume %u ...",
1192 AFSVolSetFlags(fromconn, fromtid,
1193 VTDeleteOnSalvage | VTOutOfService);
1195 "Failed to set flags on the backup volume %u\n", backupId);
1198 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1199 code = AFSVolDeleteVolume(fromconn, fromtid);
1201 "Could not delete the leftover backup volume %u\n",
1205 VPRINT1("Ending transaction on leftover backup volume %u ...",
1207 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1212 "Could not end the transaction for the leftover backup volume %u\n",
1222 /* From-info matches the vldb info about volid,
1223 * its ok start the move operation, the backup volume
1224 * on the old site is deleted in the process
1226 if (afrompart == atopart) {
1227 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1228 EGOTO2(mfail, error,
1229 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1230 afromserver, error);
1233 EGOTO1(mfail, VOLSERVOLMOVED,
1234 "Warning: Moving volume %u to its home partition ignored!\n",
1240 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1241 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1242 fromtid = totid = 0; /* initialize to uncreated */
1245 * clone the read/write volume locally.
1248 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1249 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1250 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1254 /* Get a clone id */
1255 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
1257 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
1258 EGOTO1(mfail, vcode,
1259 "Could not get an ID for the clone of volume %u from the VLDB\n",
1263 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1264 VPRINT1("Cloning source volume %u ...", afromvol);
1265 strcpy(vname, "move-clone-temp");
1266 code = AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1267 EGOTO1(mfail, code, "Failed to clone the source volume %u\n", afromvol);
1270 /* lookup the name of the volume we just cloned */
1272 code = AFSVolGetName(fromconn, fromtid, &volName);
1273 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n", newVol);
1275 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1277 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1282 "Failed to end the transaction on the source volume %u\n",
1287 * Create the destination volume
1290 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1292 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
1294 "Failed to start a transaction on the cloned volume%u\n", newVol);
1297 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1298 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
1299 EGOTO1(mfail, code, "Could not set falgs on the cloned volume %u\n",
1303 /* remember time from which we've dumped the volume */
1304 VPRINT1("Getting status of cloned volume %u ...", newVol);
1305 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1306 EGOTO1(mfail, code, "Failed to get the status of the cloned volume %u\n",
1310 fromDate = tstatus.creationDate - CLOCKSKEW;
1312 #ifdef ENABLE_BUGFIX_1165
1314 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1315 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1316 * don't use this information...
1318 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1319 volumeInfo.volEntries_len = 0;
1320 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1322 "Failed to get the volint Info of the cloned volume %u\n",
1325 infop = (volintInfo *) volumeInfo.volEntries_val;
1326 infop->maxquota = -1; /* Else it will replace the default quota */
1329 /* create a volume on the target machine */
1331 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1333 /* Delete the existing volume.
1334 * While we are deleting the volume in these steps, the transaction
1335 * we started against the cloned volume (clonetid above) will be
1336 * sitting idle. It will get cleaned up after 600 seconds
1338 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1339 code = AFSVolDeleteVolume(toconn, totid);
1341 "Could not delete the pre-existing volume %u on destination\n",
1346 ("Ending transaction on pre-existing volume %u on destination ...",
1348 code = AFSVolEndTrans(toconn, totid, &rcode);
1353 "Could not end the transaction on pre-existing volume %u on destination\n",
1358 VPRINT1("Creating the destination volume %u ...", volid);
1360 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1362 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1366 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1370 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1372 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1374 "Failed to set the flags on the destination volume %u\n", volid);
1378 * Now dump the clone to the new volume
1381 destination.destHost = ntohl(atoserver);
1382 destination.destPort = AFSCONF_VOLUMEPORT;
1383 destination.destSSID = 1;
1385 /* Copy the clone to the new volume */
1386 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1388 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1389 cookie.type = RWVOL;
1390 cookie.parent = entry.volumeId[RWVOL];
1392 code = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
1393 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1396 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1397 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1402 "Failed to end the transaction on the cloned volume %u\n", newVol);
1406 * reattach to the main-line volume, and incrementally dump it.
1409 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1410 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1412 "Failed to create a transaction on the source volume %u\n",
1416 /* now do the incremental */
1418 ("Doing the incremental dump from source to destination for volume %u ... ",
1421 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1424 "Failed to do the incremental dump from rw volume on old site to rw volume on newsite\n");
1427 /* now adjust the flags so that the new volume becomes official */
1428 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1429 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1431 "Failed to set the flags to make old source volume offline\n");
1434 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1435 code = AFSVolSetFlags(toconn, totid, 0);
1437 "Failed to set the flags to make new source volume online\n");
1440 #ifdef ENABLE_BUGFIX_1165
1441 VPRINT1("Setting volume status on destination volume %u ...", volid);
1442 code = AFSVolSetInfo(toconn, totid, infop);
1444 "Failed to set volume status on the destination volume %u\n",
1449 /* put new volume online */
1450 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1451 code = AFSVolEndTrans(toconn, totid, &rcode);
1456 "Failed to end the transaction on the volume %u on the new site\n",
1460 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1461 MapNetworkToHost(&entry, &storeEntry);
1462 storeEntry.flags &= ~BACK_EXISTS;
1466 "Second test point - operation in progress but not complete.\n");
1467 fprintf(STDOUT, "...test here (y, n)? ");
1469 fscanf(stdin, "%c", &in);
1470 fscanf(stdin, "%c", &lf); /* toss away */
1472 fprintf(STDOUT, "type control-c\n");
1474 fprintf(stdout, ".");
1479 /* or drop through */
1482 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1484 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1485 (LOCKREL_OPCODE | LOCKREL_AFSID |
1486 LOCKREL_TIMESTAMP));
1489 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1490 storeEntry.name, (unsigned long)afromvol);
1499 "Third test point - operation complete but no cleanup.\n");
1500 fprintf(STDOUT, "...test here (y, n)? ");
1502 fscanf(stdin, "%c", &in);
1503 fscanf(stdin, "%c", &lf); /* toss away */
1505 fprintf(STDOUT, "type control-c\n");
1507 fprintf(stdout, ".");
1512 /* or drop through */
1515 /* This is tricky. File server is very stupid, and if you mark the volume
1516 * as VTOutOfService, it may mark the *good* instance (if you're moving
1517 * between partitions on the same machine) as out of service. Since
1518 * we're cleaning this code up in DEcorum, we're just going to kludge around
1519 * it for now by removing this call. */
1520 /* already out of service, just zap it now */
1522 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1525 "Failed to set the flags to make the old source volume offline\n");
1529 if (atoserver != afromserver) {
1530 /* set forwarding pointer for moved volumes */
1531 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1532 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1534 "Failed to set the forwarding pointer for the volume %u\n",
1539 VPRINT1("Deleting old volume %u on source ...", afromvol);
1540 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1541 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1545 VPRINT1("Ending transaction on old volume %u on the source ...",
1547 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1552 "Failed to end the transaction on the old volume %u on the source\n",
1556 /* Delete the backup volume on the original site */
1557 VPRINT1("Creating transaction for backup volume %u on source ...",
1560 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1563 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1565 AFSVolSetFlags(fromconn, fromtid,
1566 VTDeleteOnSalvage | VTOutOfService);
1568 "Failed to set the flags on the backup volume %u on the source\n",
1572 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1573 code = AFSVolDeleteVolume(fromconn, fromtid);
1575 "Failed to delete the backup volume %u on the source\n",
1579 VPRINT1("Ending transaction on backup volume %u on source ...",
1581 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1586 "Failed to end the transaction on the backup volume %u on the source\n",
1590 code = 0; /* no backup volume? that's okay */
1593 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1595 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
1597 "Failed to start a transaction on the cloned volume%u\n", newVol);
1600 /* now delete the clone */
1601 VPRINT1("Deleting the cloned volume %u ...", newVol);
1602 code = AFSVolDeleteVolume(fromconn, clonetid);
1603 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n", newVol);
1606 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1607 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1612 "Failed to end the transaction on the cloned volume %u\n", newVol);
1619 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1620 fprintf(STDOUT, "...test here (y, n)? ");
1622 fscanf(stdin, "%c", &in);
1623 fscanf(stdin, "%c", &lf); /* toss away */
1625 fprintf(STDOUT, "type control-c\n");
1627 fprintf(stdout, ".");
1632 /* or drop through */
1635 /* normal cleanup code */
1637 if (entry.flags & RO_EXISTS)
1638 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1641 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1643 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1644 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1648 " Could not release the lock on the VLDB entry for the volume %lu \n",
1649 (unsigned long)afromvol);
1657 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1659 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1660 if (code || rcode) {
1663 "Could not end transaction on the source's clone volume %lu\n",
1664 (unsigned long)newVol);
1666 error = (code ? code : rcode);
1672 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1673 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1674 if (code || rcode) {
1677 "Could not end transaction on the source's clone volume %lu\n",
1678 (unsigned long)newVol);
1680 error = (code ? code : rcode);
1686 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1688 code = AFSVolEndTrans(toconn, totid, &rcode);
1692 "Could not end transaction on destination volume %lu\n",
1693 (unsigned long)afromvol);
1695 error = (code ? code : rcode);
1701 #ifdef ENABLE_BUGFIX_1165
1706 rx_DestroyConnection(fromconn);
1708 rx_DestroyConnection(toconn);
1709 PrintError("", error);
1712 /* come here only when the sky falls */
1717 "vos move: operation interrupted, cleanup in progress...\n");
1718 fprintf(STDOUT, "clear transaction contexts\n");
1722 /* unlock VLDB entry */
1724 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1725 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1726 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1731 VPRINT("Recovery: Ending transaction on clone volume ...");
1732 AFSVolEndTrans(fromconn, clonetid, &rcode);
1736 VPRINT("Recovery: Ending transaction on destination volume ...");
1737 AFSVolEndTrans(toconn, totid, &rcode);
1740 if (fromtid) { /* put it on-line */
1741 VPRINT("Recovery: Setting volume flags on source volume ...");
1742 AFSVolSetFlags(fromconn, fromtid, 0);
1745 VPRINT("Recovery: Ending transaction on source volume ...");
1746 AFSVolEndTrans(fromconn, fromtid, &rcode);
1750 VPRINT("Recovery: Accessing VLDB.\n");
1751 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1753 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1757 MapHostToNetwork(&entry);
1759 /* Delete either the volume on the source location or the target location.
1760 * If the vldb entry still points to the source location, then we know the
1761 * volume move didn't finish so we remove the volume from the target
1762 * location. Otherwise, we remove the volume from the source location.
1764 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1767 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1771 if (volid && toconn) {
1773 ("Recovery: Creating transaction for destination volume %u ...",
1776 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1782 ("Recovery: Setting flags on destination volume %u ...",
1784 AFSVolSetFlags(toconn, totid,
1785 VTDeleteOnSalvage | VTOutOfService);
1788 VPRINT1("Recovery: Deleting destination volume %u ...",
1790 AFSVolDeleteVolume(toconn, totid);
1794 ("Recovery: Ending transaction on destination volume %u ...",
1796 AFSVolEndTrans(toconn, totid, &rcode);
1800 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1805 /* put source volume on-line */
1807 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1810 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1815 VPRINT1("Recovery: Setting flags on source volume %u ...",
1817 AFSVolSetFlags(fromconn, fromtid, 0);
1821 ("Recovery: Ending transaction on source volume %u ...",
1823 AFSVolEndTrans(fromconn, fromtid, &rcode);
1827 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1831 } else { /* yep, move complete */
1834 "move complete - attempt cleanup of source partition - no guarantee\n");
1838 /* delete backup volume */
1840 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1843 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1848 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1850 AFSVolSetFlags(fromconn, fromtid,
1851 VTDeleteOnSalvage | VTOutOfService);
1854 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1855 AFSVolDeleteVolume(fromconn, fromtid);
1859 ("Recovery: Ending transaction on backup volume %u ...",
1861 AFSVolEndTrans(fromconn, fromtid, &rcode);
1865 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1869 /* delete source volume */
1870 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1873 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1878 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1880 AFSVolSetFlags(fromconn, fromtid,
1881 VTDeleteOnSalvage | VTOutOfService);
1884 if (atoserver != afromserver) {
1885 VPRINT("Recovery: Setting volume forwarding pointer ...");
1886 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1890 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1891 AFSVolDeleteVolume(fromconn, fromtid);
1895 ("Recovery: Ending transaction on source volume %u ...",
1897 AFSVolEndTrans(fromconn, fromtid, &rcode);
1901 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1907 /* common cleanup - delete local clone */
1909 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1912 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1917 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1918 AFSVolDeleteVolume(fromconn, clonetid);
1921 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1923 AFSVolEndTrans(fromconn, clonetid, &rcode);
1927 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1932 /* unlock VLDB entry */
1933 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
1935 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
1936 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1939 done: /* routine cleanup */
1942 #ifdef ENABLE_BUGFIX_1165
1947 rx_DestroyConnection(fromconn);
1949 rx_DestroyConnection(toconn);
1952 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
1959 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
1960 * <atopart>. The operation is almost idempotent
1964 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1965 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
1967 struct rx_connection *toconn, *fromconn;
1968 afs_int32 fromtid, totid, clonetid;
1970 char tmpName[VOLSER_MAXVOLNAME + 1];
1973 struct restoreCookie cookie;
1974 register afs_int32 vcode, code;
1975 afs_int32 cloneVol, newVol;
1976 struct volser_status tstatus;
1977 struct destServer destination;
1979 struct nvldbentry entry, newentry, storeEntry;
1980 int i, islocked, pntg;
1982 char in, lf; /* for test code */
1987 fromconn = (struct rx_connection *)0;
1988 toconn = (struct rx_connection *)0;
1996 /* support control-c processing */
1999 (void)signal(SIGINT, sigint_handler);
2001 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2002 EGOTO1(mfail, vcode,
2003 "Could not fetch the entry for the volume %u from the VLDB \n",
2005 MapHostToNetwork(&entry);
2008 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2009 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2010 fromtid = totid = 0; /* initialize to uncreated */
2013 /* check if we can shortcut and use a local clone instead of a full copy */
2014 if (afromserver == atoserver && afrompart == atopart) {
2019 * clone the read/write volume locally.
2022 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2023 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2024 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2028 /* Get a clone id */
2029 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
2031 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &cloneVol);
2032 EGOTO1(mfail, vcode,
2033 "Could not get an ID for the clone of volume %u from the VLDB\n",
2037 /* Get a new volume id */
2038 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2040 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
2041 EGOTO1(mfail, vcode,
2042 "Could not get an ID for the copy of volume %u from the VLDB\n",
2046 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2047 VPRINT1("Cloning source volume %u ...", afromvol);
2048 strcpy(vname, "copy-clone-temp");
2050 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &cloneVol);
2051 EGOTO1(mfail, code, "Failed to clone the source volume %u\n", afromvol);
2054 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2056 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2061 "Failed to end the transaction on the source volume %u\n",
2066 * Create the destination volume
2069 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2071 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2074 "Failed to start a transaction on the cloned volume%u\n",
2078 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2079 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
2080 EGOTO1(mfail, code, "Could not set falgs on the cloned volume %u\n",
2084 /* remember time from which we've dumped the volume */
2085 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2086 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2087 EGOTO1(mfail, code, "Failed to get the status of the cloned volume %u\n",
2091 fromDate = tstatus.creationDate - CLOCKSKEW;
2093 /* create a volume on the target machine */
2094 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2096 /* Delete the existing volume.
2097 * While we are deleting the volume in these steps, the transaction
2098 * we started against the cloned volume (clonetid above) will be
2099 * sitting idle. It will get cleaned up after 600 seconds
2101 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2102 code = AFSVolDeleteVolume(toconn, totid);
2104 "Could not delete the pre-existing volume %u on destination\n",
2109 ("Ending transaction on pre-existing volume %u on destination ...",
2111 code = AFSVolEndTrans(toconn, totid, &rcode);
2116 "Could not end the transaction on pre-existing volume %u on destination\n",
2121 VPRINT1("Creating the destination volume %u ...", newVol);
2123 AFSVolCreateVolume(toconn, atopart, atovolname, volser_RW, newVol,
2125 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2129 strncpy(tmpName, atovolname, VOLSER_OLDMAXVOLNAME);
2131 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2133 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2135 "Failed to set the flags on the destination volume %u\n", newVol);
2139 * Now dump the clone to the new volume
2142 destination.destHost = ntohl(atoserver);
2143 destination.destPort = AFSCONF_VOLUMEPORT;
2144 destination.destSSID = 1;
2147 /* probably should have some code here that checks to see if we are copying to same server
2148 and partition - if so, just use a clone to save disk space */
2150 /* Copy the clone to the new volume */
2151 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2153 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
2154 cookie.type = RWVOL;
2157 code = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
2158 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", newVol);
2161 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2162 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2167 "Failed to end the transaction on the cloned volume %u\n",
2172 * reattach to the main-line volume, and incrementally dump it.
2175 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2176 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2178 "Failed to create a transaction on the source volume %u\n",
2182 /* now do the incremental */
2184 ("Doing the incremental dump from source to destination for volume %u ... ",
2187 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2190 "Failed to do the incremental dump from rw volume on old site to rw volume on newsite\n");
2193 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2194 code = AFSVolSetFlags(toconn, totid, 0);
2196 "Failed to set the flags to make destination volume online\n");
2199 /* put new volume online */
2200 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2201 code = AFSVolEndTrans(toconn, totid, &rcode);
2206 "Failed to end the transaction on the destination volume %u\n",
2210 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2211 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2216 "Failed to end the transaction on the source volume %u\n",
2221 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2223 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2226 "Failed to start a transaction on the cloned volume%u\n",
2230 /* now delete the clone */
2231 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2232 code = AFSVolDeleteVolume(fromconn, clonetid);
2233 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n", cloneVol);
2236 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2237 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2242 "Failed to end the transaction on the cloned volume %u\n",
2246 /* create the vldb entry for the copied volume */
2247 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2248 newentry.nServers = 1;
2249 newentry.serverNumber[0] = atoserver;
2250 newentry.serverPartition[0] = atopart;
2251 newentry.flags = RW_EXISTS; /* this records that rw volume exists */
2252 newentry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
2253 newentry.volumeId[RWVOL] = newVol;
2254 newentry.volumeId[ROVOL] = 0;
2255 newentry.volumeId[BACKVOL] = 0;
2256 newentry.cloneId = 0;
2257 /*map into right byte order, before passing to xdr, the stuff has to be in host
2258 * byte order. Xdr converts it into network order */
2259 MapNetworkToHost(&newentry, &storeEntry);
2260 /* create the vldb entry */
2261 vcode = VLDB_CreateEntry(&storeEntry);
2264 "Could not create a VLDB entry for the volume %s %lu\n",
2265 atovolname, (unsigned long)newVol);
2266 /*destroy the created volume */
2267 VPRINT1("Deleting the newly created volume %u\n", newVol);
2268 AFSVolDeleteVolume(toconn, totid);
2272 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2275 /* normal cleanup code */
2278 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2280 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2281 if (code || rcode) {
2284 "Could not end transaction on the source volume %lu\n",
2285 (unsigned long)afromvol);
2287 error = (code ? code : rcode);
2293 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2295 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2296 if (code || rcode) {
2299 "Could not end transaction on the source's clone volume %lu\n",
2300 (unsigned long)cloneVol);
2302 error = (code ? code : rcode);
2308 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2310 code = AFSVolEndTrans(toconn, totid, &rcode);
2314 "Could not end transaction on destination volume %lu\n",
2315 (unsigned long)newVol);
2317 error = (code ? code : rcode);
2322 rx_DestroyConnection(fromconn);
2324 rx_DestroyConnection(toconn);
2325 PrintError("", error);
2328 /* come here only when the sky falls */
2333 "vos copy: operation interrupted, cleanup in progress...\n");
2334 fprintf(STDOUT, "clear transaction contexts\n");
2339 VPRINT("Recovery: Ending transaction on clone volume ...");
2340 AFSVolEndTrans(fromconn, clonetid, &rcode);
2344 VPRINT("Recovery: Ending transaction on destination volume ...");
2345 AFSVolEndTrans(toconn, totid, &rcode);
2348 if (fromtid) { /* put it on-line */
2349 VPRINT("Recovery: Ending transaction on source volume ...");
2350 AFSVolEndTrans(fromconn, fromtid, &rcode);
2354 VPRINT("Recovery: Accessing VLDB.\n");
2355 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2357 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2361 MapHostToNetwork(&entry);
2363 /* common cleanup - delete local clone */
2365 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2368 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
2373 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2374 AFSVolDeleteVolume(fromconn, clonetid);
2377 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2379 AFSVolEndTrans(fromconn, clonetid, &rcode);
2383 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2388 done: /* routine cleanup */
2390 rx_DestroyConnection(fromconn);
2392 rx_DestroyConnection(toconn);
2395 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2405 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2406 * if one already exists, update it
2410 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2412 struct rx_connection *aconn = (struct rx_connection *)0;
2413 afs_int32 ttid = 0, btid = 0;
2415 afs_int32 code = 0, rcode = 0;
2416 char vname[VOLSER_MAXVOLNAME + 1];
2417 struct nvldbentry entry, storeEntry;
2418 afs_int32 error = 0;
2419 int vldblocked = 0, vldbmod = 0, backexists = 1;
2421 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2423 /* the calls to VLDB will succeed only if avolid is a RW volume,
2424 * since we are following the RW hash chain for searching */
2425 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2428 "Could not fetch the entry for the volume %lu from the VLDB \n",
2429 (unsigned long)avolid);
2433 MapHostToNetwork(&entry);
2435 /* These operations require the VLDB be locked since it means the VLDB
2436 * will change or the vldb is already locked.
2438 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2439 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2440 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2442 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2445 "Could not lock the VLDB entry for the volume %lu\n",
2446 (unsigned long)avolid);
2452 /* Reread the vldb entry */
2453 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2456 "Could not fetch the entry for the volume %lu from the VLDB \n",
2457 (unsigned long)avolid);
2461 MapHostToNetwork(&entry);
2464 if (!ISNAMEVALID(entry.name)) {
2465 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2467 error = VOLSERBADNAME;
2471 backupID = entry.volumeId[BACKVOL];
2472 if (backupID == INVALID_BID) {
2473 /* Get a backup volume id from the VLDB and update the vldb
2476 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &backupID);
2479 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2480 (unsigned long)avolid);
2484 entry.volumeId[BACKVOL] = backupID;
2488 /* Test to see if the backup volume exists by trying to create
2489 * a transaction on the backup volume. We've assumed the backup exists.
2491 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2493 if (code != VNOVOL) {
2494 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2495 (unsigned long)backupID);
2499 backexists = 0; /* backup volume does not exist */
2502 code = AFSVolEndTrans(aconn, btid, &rcode);
2504 if (code || rcode) {
2506 "Could not end transaction on the previous backup volume %lu\n",
2507 (unsigned long)backupID);
2508 error = (code ? code : rcode);
2513 /* Now go ahead and try to clone the RW volume.
2514 * First start a transaction on the RW volume
2516 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2518 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2519 (unsigned long)avolid);
2524 /* Clone or reclone the volume, depending on whether the backup
2525 * volume exists or not
2528 VPRINT1("Re-cloning backup volume %u ...", backupID);
2530 code = AFSVolReClone(aconn, ttid, backupID);
2532 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2533 (unsigned long)backupID);
2538 VPRINT1("Creating a new backup clone %u ...", backupID);
2540 strcpy(vname, entry.name);
2541 strcat(vname, ".backup");
2543 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2545 fprintf(STDERR, "Failed to clone the volume %lu\n",
2546 (unsigned long)avolid);
2552 /* End the transaction on the RW volume */
2553 code = AFSVolEndTrans(aconn, ttid, &rcode);
2555 if (code || rcode) {
2557 "Failed to end the transaction on the rw volume %lu\n",
2558 (unsigned long)avolid);
2559 error = (code ? code : rcode);
2563 /* Mork vldb as backup exists */
2564 if (!(entry.flags & BACK_EXISTS)) {
2565 entry.flags |= BACK_EXISTS;
2569 /* Now go back to the backup volume and bring it on line */
2570 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2573 "Failed to start a transaction on the backup volume %lu\n",
2574 (unsigned long)backupID);
2579 code = AFSVolSetFlags(aconn, btid, 0);
2581 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2582 (unsigned long)backupID);
2587 code = AFSVolEndTrans(aconn, btid, &rcode);
2589 if (code || rcode) {
2591 "Failed to end the transaction on the backup volume %lu\n",
2592 (unsigned long)backupID);
2593 error = (code ? code : rcode);
2599 /* Will update the vldb below */
2603 code = AFSVolEndTrans(aconn, ttid, &rcode);
2604 if (code || rcode) {
2605 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2606 (unsigned long)avolid);
2608 error = (code ? code : rcode);
2613 code = AFSVolEndTrans(aconn, btid, &rcode);
2614 if (code || rcode) {
2616 "Could not end transaction the backup volume %lu\n",
2617 (unsigned long)backupID);
2619 error = (code ? code : rcode);
2623 /* Now update the vldb - if modified */
2626 MapNetworkToHost(&entry, &storeEntry);
2628 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2629 (LOCKREL_OPCODE | LOCKREL_AFSID |
2630 LOCKREL_TIMESTAMP));
2633 "Could not update the VLDB entry for the volume %lu \n",
2634 (unsigned long)avolid);
2640 ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, RWVOL,
2641 (LOCKREL_OPCODE | LOCKREL_AFSID |
2642 LOCKREL_TIMESTAMP));
2645 "Could not unlock the VLDB entry for the volume %lu \n",
2646 (unsigned long)avolid);
2654 rx_DestroyConnection(aconn);
2656 PrintError("", error);
2661 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2664 afs_int32 acode, ccode, rcode, tid;
2665 ccode = rcode = tid = 0;
2667 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2668 if (!acode) { /* It really was there */
2669 acode = AFSVolDeleteVolume(conn, tid);
2671 fprintf(STDERR, "Failed to delete volume %lu.\n",
2672 (unsigned long)vid);
2673 PrintError("", acode);
2675 ccode = AFSVolEndTrans(conn, tid, &rcode);
2679 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
2680 (unsigned long)vid);
2681 PrintError("", ccode);
2688 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
2689 #define ERROREXIT(ec) { error = (ec); goto rfail; }
2691 /* Get a "transaction" on this replica. Create the volume
2692 * if necessary. Return the time from which a dump should
2693 * be made (0 if it's a new volume)
2696 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
2697 struct rx_connection **connPtr, afs_int32 * transPtr,
2698 afs_int32 * timePtr)
2701 struct volser_status tstatus;
2702 int code, rcode, tcode;
2704 *connPtr = (struct rx_connection *)0;
2708 /* get connection to the replication site */
2709 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
2711 goto fail; /* server is down */
2713 volid = vldbEntryPtr->volumeId[ROVOL];
2716 AFSVolTransCreate(*connPtr, volid,
2717 vldbEntryPtr->serverPartition[index], ITOffline,
2720 /* If the volume does not exist, create it */
2721 if (!volid || code) {
2724 if (volid && (code != VNOVOL)) {
2725 PrintError("Failed to start a transaction on the RO volume.\n",
2730 strcpy(volname, vldbEntryPtr->name);
2731 strcat(volname, ".readonly");
2735 "Creating new volume %lu on replication site %s: ",
2736 (unsigned long)volid,
2737 hostutil_GetNameByINet(vldbEntryPtr->
2738 serverNumber[index]));
2743 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
2745 vldbEntryPtr->volumeId[RWVOL], &volid,
2748 PrintError("Failed to create the ro volume: ", code);
2751 vldbEntryPtr->volumeId[ROVOL] = volid;
2755 /* The following is a bit redundant, since create sets these flags by default */
2757 AFSVolSetFlags(*connPtr, *transPtr,
2758 VTDeleteOnSalvage | VTOutOfService);
2760 PrintError("Failed to set flags on the ro volume: ", code);
2765 /* Otherwise, the transaction did succeed, so get the creation date of the
2766 * latest RO volume on the replication site
2769 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
2770 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
2772 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
2774 PrintError("Failed to get status of volume on destination: ",
2778 *timePtr = tstatus.creationDate - CLOCKSKEW;
2785 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
2790 PrintError("Could not end transaction on a ro volume: ", tcode);
2797 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
2798 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
2799 void *cookie, manyResults * results)
2803 for (i = 0; i < tr->manyDests_len; i++) {
2804 results->manyResults_val[i] =
2805 AFSVolForward(fromconn, fromtid, fromdate,
2806 &(tr->manyDests_val[i].server),
2807 tr->manyDests_val[i].trans, cookie);
2814 rel_compar(struct release *r1, struct release *r2)
2816 return (r1->time - r2->time);
2819 /* UV_ReleaseVolume()
2820 * Release volume <afromvol> on <afromserver> <afrompart> to all
2821 * its RO sites (full release). Unless the previous release was
2822 * incomplete: in which case we bring the remaining incomplete
2823 * volumes up to date with the volumes that were released
2825 * forceflag: Performs a full release.
2827 * Will create a clone from the RW, then dump the clone out to
2828 * the remaining replicas. If there is more than 1 RO sites,
2829 * ensure that the VLDB says at least one RO is available all
2830 * the time: Influences when we write back the VLDB entry.
2834 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
2835 afs_int32 afrompart, int forceflag)
2838 afs_int32 code, vcode, rcode, tcode;
2839 afs_int32 cloneVolId, roVolId;
2840 struct replica *replicas = 0;
2841 struct nvldbentry entry, storeEntry;
2842 int i, volcount, m, fullrelease, vldbindex;
2844 struct restoreCookie cookie;
2845 struct rx_connection **toconns = 0;
2846 struct release *times = 0;
2848 struct rx_connection *fromconn = (struct rx_connection *)0;
2849 afs_int32 error = 0;
2851 afs_int32 clonetid = 0, onlinetid;
2852 afs_int32 fromtid = 0;
2853 afs_uint32 fromdate, thisdate;
2856 manyResults results;
2857 int rwindex, roindex, roclone, roexists;
2862 } remembertime[NMAXNSERVERS];
2863 int releasecount = 0;
2864 struct volser_status volstatus;
2866 memset((char *)remembertime, 0, sizeof(remembertime));
2867 memset((char *)&results, 0, sizeof(results));
2869 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
2870 if (vcode != VL_RERELEASE)
2871 ONERROR(vcode, afromvol,
2872 "Could not lock the VLDB entry for the volume %u.\n");
2875 /* Get the vldb entry in readable format */
2876 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
2877 ONERROR(vcode, afromvol,
2878 "Could not fetch the entry for the volume %u from the VLDB.\n");
2879 MapHostToNetwork(&entry);
2882 EnumerateEntry(&entry);
2884 if (!ISNAMEVALID(entry.name))
2885 ONERROR(VOLSERBADOP, entry.name,
2886 "Volume name %s is too long, rename before releasing.\n");
2887 if (entry.volumeId[RWVOL] != afromvol)
2888 ONERROR(VOLSERBADOP, afromvol,
2889 "The volume %u being released is not a read-write volume.\n");
2890 if (entry.nServers <= 1)
2891 ONERROR(VOLSERBADOP, afromvol,
2892 "Volume %u has no replicas - release operation is meaningless!\n");
2893 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
2894 ONERROR(VOLSERBADOP, entry.name,
2895 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
2897 /* roclone is true if one of the RO volumes is on the same
2898 * partition as the RW volume. In this case, we make the RO volume
2899 * on the same partition a clone instead of a complete copy.
2902 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
2903 roclone = ((roindex == -1) ? 0 : 1);
2904 rwindex = Lp_GetRwIndex(&entry);
2906 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
2908 /* Make sure we have a RO volume id to work with */
2909 if (entry.volumeId[ROVOL] == INVALID_BID) {
2910 /* need to get a new RO volume id */
2911 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &roVolId);
2912 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
2914 entry.volumeId[ROVOL] = roVolId;
2915 MapNetworkToHost(&entry, &storeEntry);
2916 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
2917 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
2920 /* Will we be completing a previously unfinished release. -force overrides */
2921 for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) {
2922 if (entry.serverFlags[i] & NEW_REPSITE)
2925 if (forceflag && !fullrelease)
2928 /* Determine which volume id to use and see if it exists */
2931 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
2932 code = VolumeExists(afromserver, afrompart, cloneVolId);
2933 roexists = ((code == ENODEV) ? 0 : 1);
2934 if (!roexists && !fullrelease)
2935 fullrelease = 1; /* Do a full release if RO clone does not exist */
2939 fprintf(STDOUT, "This is a complete release of the volume %lu\n",
2940 (unsigned long)afromvol);
2942 fprintf(STDOUT, "This is a completion of the previous release\n");
2946 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2948 ONERROR(-1, afromserver,
2949 "Cannot establish connection with server 0x%x\n");
2952 /* If the RO clone exists, then if the clone is a temporary
2953 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
2954 * (it was recently added), then also delete it. We do not
2955 * want to "reclone" a temporary RO clone.
2958 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
2959 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
2960 if (code && (code != VNOVOL))
2965 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
2966 * write this entry out to the vlserver until after the first
2967 * RO volume is released (temp RO clones don't count).
2969 for (i = 0; i < entry.nServers; i++) {
2970 entry.serverFlags[i] &= ~NEW_REPSITE;
2971 entry.serverFlags[i] |= RO_DONTUSE;
2973 entry.serverFlags[rwindex] |= NEW_REPSITE;
2974 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
2976 /* Begin transaction on RW and mark it busy while we clone it */
2978 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2980 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
2982 /* Clone or reclone the volume */
2984 VPRINT1("Recloning RW volume %u...", cloneVolId);
2985 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
2986 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
2990 strcpy(vname, entry.name);
2991 strcat(vname, ".readonly");
2992 VPRINT("Cloning RW volume %u to permanent RO...");
2994 strcpy(vname, "readonly-clone-temp");
2995 VPRINT("Cloning RW volume %u to temporary RO...");
2998 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3000 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3004 /* Get the time the RW was created for future information */
3005 VPRINT1("Getting status of RW volume %u...", cloneVolId);
3006 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3007 ONERROR(code, cloneVolId,
3008 "Failed to get the status of the RW volume %u\n");
3010 rwcrdate = volstatus.creationDate;
3012 /* End the transaction on the RW volume */
3013 VPRINT1("Ending cloning transaction on RW volume %u...", cloneVolId);
3014 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3016 ONERROR((code ? code : rcode), cloneVolId,
3017 "Failed to end cloning transaction on RW %u\n");
3020 /* Remember clone volume ID in case we fail or are interrupted */
3021 entry.cloneId = cloneVolId;
3024 /* Bring the RO clone online - though not if it's a temporary clone */
3025 VPRINT1("Starting transaction on RO clone volume %u...",
3028 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3030 ONERROR(code, cloneVolId,
3031 "Failed to start transaction on volume %u\n");
3034 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3035 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3038 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3039 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3040 ONERROR((code ? code : rcode), cloneVolId,
3041 "Failed to end transaction on RO clone %u\n");
3044 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3046 /* Sleep so that a client searching for an online volume won't
3047 * find the clone offline and then the next RO offline while the
3048 * release brings the clone online and the next RO offline (race).
3049 * There is a fix in the 3.4 client that does not need this sleep
3050 * anymore, but we don't know what clients we have.
3052 if (entry.nServers > 2)
3055 /* Mark the RO clone in the VLDB as a good site (already released) */
3056 entry.serverFlags[roindex] |= NEW_REPSITE;
3057 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3058 entry.flags |= RO_EXISTS;
3062 /* Write out the VLDB entry only if the clone is not a temporary
3063 * clone. If we did this to a temporary clone then we would end
3064 * up marking all the ROs as "old release" making the ROs
3065 * temporarily unavailable.
3067 MapNetworkToHost(&entry, &storeEntry);
3068 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3069 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3070 ONERROR(vcode, entry.name,
3071 "Could not update vldb entry for %s.\n");
3076 /* Now we will release from the clone to the remaining RO replicas.
3077 * The first 2 ROs (counting the non-temporary RO clone) are released
3078 * individually: releasecount. This is to reduce the race condition
3079 * of clients trying to find an on-line RO volume. The remaining ROs
3080 * are released in parallel but no more than half the number of ROs
3081 * (rounded up) at a time: nservers.
3084 strcpy(vname, entry.name);
3085 strcat(vname, ".readonly");
3086 memset(&cookie, 0, sizeof(cookie));
3087 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3088 cookie.type = ROVOL;
3089 cookie.parent = entry.volumeId[RWVOL];
3092 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3094 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3095 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3097 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3099 results.manyResults_val =
3100 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3101 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3103 "Failed to create transaction on the release clone\n");
3105 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3106 memset(times, 0, (sizeof(struct release) * nservers + 1));
3107 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3108 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3110 /* Create a transaction on the cloned volume */
3111 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3113 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3114 if (!fullrelease && code)
3115 ONERROR(VOLSERNOVOL, afromvol,
3116 "Old clone is inaccessible. Try vos release -f %u.\n");
3117 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3120 /* For each index in the VLDB */
3121 for (vldbindex = 0; vldbindex < entry.nServers;) {
3123 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3125 ((volcount < nservers) && (vldbindex < entry.nServers));
3127 /* The first two RO volumes will be released individually.
3128 * The rest are then released in parallel. This is a hack
3129 * for clients not recognizing right away when a RO volume
3130 * comes back on-line.
3132 if ((volcount == 1) && (releasecount < 2))
3135 if (vldbindex == roindex)
3136 continue; /* the clone */
3137 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3138 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3140 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3141 continue; /* not a RO vol */
3144 /* Get a Transaction on this replica. Get a new connection if
3145 * necessary. Create the volume if necessary. Return the
3146 * time from which the dump should be made (0 if it's a new
3147 * volume). Each volume might have a different time.
3149 replicas[volcount].server.destHost =
3150 ntohl(entry.serverNumber[vldbindex]);
3151 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3152 replicas[volcount].server.destSSID = 1;
3153 times[volcount].vldbEntryIndex = vldbindex;
3156 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3157 &(replicas[volcount].trans),
3158 &(times[volcount].time));
3162 /* Thisdate is the date from which we want to pick up all changes */
3163 if (forceflag || !fullrelease
3164 || (rwcrdate > times[volcount].time)) {
3165 /* If the forceflag is set, then we want to do a full dump.
3166 * If it's not a full release, we can't be sure that the creation
3167 * date is good (so we also do a full dump).
3168 * If the RW volume was replaced (its creation date is newer than
3169 * the last release), then we can't be sure what has changed (so
3170 * we do a full dump).
3173 } else if (remembertime[vldbindex].validtime) {
3174 /* Trans was prev ended. Use the time from the prev trans
3175 * because, prev trans may have created the volume. In which
3176 * case time[volcount].time would be now instead of 0.
3179 (remembertime[vldbindex].time <
3180 times[volcount].time) ? remembertime[vldbindex].
3181 time : times[volcount].time;
3183 thisdate = times[volcount].time;
3185 remembertime[vldbindex].validtime = 1;
3186 remembertime[vldbindex].time = thisdate;
3188 if (volcount == 0) {
3189 fromdate = thisdate;
3191 /* Include this volume if it is within 15 minutes of the earliest */
3193 thisdate) ? (fromdate - thisdate) : (thisdate -
3195 AFSVolEndTrans(toconns[volcount],
3196 replicas[volcount].trans, &rcode);
3197 replicas[volcount].trans = 0;
3200 if (thisdate < fromdate)
3201 fromdate = thisdate;
3209 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3210 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3211 hostutil_GetNameByINet(entry.
3212 serverNumber[times[0].
3215 for (s = 1; s < volcount; s++) {
3216 fprintf(STDOUT, " and %s",
3217 hostutil_GetNameByINet(entry.
3218 serverNumber[times[s].
3223 fprintf(STDOUT, " (full release)");
3224 fprintf(STDOUT, ".\n");
3228 /* Release the ones we have collected */
3229 tr.manyDests_val = &(replicas[0]);
3230 tr.manyDests_len = results.manyResults_len = volcount;
3232 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3233 0 /*spare */ , &cookie, &results);
3234 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3236 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3237 0 /*spare */ , &cookie, &results);
3242 PrintError("Release failed: ", code);
3244 for (m = 0; m < volcount; m++) {
3245 if (results.manyResults_val[m]) {
3246 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3247 /* we retry timed out transaction. When it is
3248 * not the first volume and the transaction wasn't found
3249 * (assume it timed out and was garbage collected by volser).
3252 ("Failed to dump volume from clone to a ro site: ",
3253 results.manyResults_val[m]);
3259 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3260 ROVOL, entry.volumeId[RWVOL], 0, 0);
3262 if ((m == 0) || (code != ENOENT)) {
3263 PrintError("Failed to set correct names and ids: ",
3269 /* have to clear dest. flags to ensure new vol goes online:
3270 * because the restore (forwarded) operation copied
3271 * the V_inService(=0) flag over to the destination.
3273 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3275 if ((m == 0) || (code != ENOENT)) {
3276 PrintError("Failed to set flags on ro volume: ",
3282 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3283 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3284 entry.flags |= RO_EXISTS;
3289 /* End the transactions and destroy the connections */
3290 for (s = 0; s < volcount; s++) {
3291 if (replicas[s].trans)
3292 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3293 replicas[s].trans = 0;
3297 if ((s == 0) || (code != ENOENT)) {
3298 PrintError("Could not end transaction on a ro volume: ",
3302 ("Transaction timed out on a ro volume. Will retry.\n",
3304 if (times[s].vldbEntryIndex < vldbindex)
3305 vldbindex = times[s].vldbEntryIndex;
3310 rx_DestroyConnection(toconns[s]);
3314 MapNetworkToHost(&entry, &storeEntry);
3315 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3316 ONERROR(vcode, afromvol,
3317 " Could not update VLDB entry for volume %u\n");
3318 } /* for each index in the vldb */
3320 /* End the transaction on the cloned volume */
3321 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3326 PrintError("Failed to end transaction on rw volume: ", code);
3328 /* Figure out if any volume were not released and say so */
3329 for (failure = 0, i = 0; i < entry.nServers; i++) {
3330 if (!(entry.serverFlags[i] & NEW_REPSITE))
3336 "The volume %lu could not be released to the following %d sites:\n",
3337 (unsigned long)afromvol, failure);
3338 for (i = 0; i < entry.nServers; i++) {
3339 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3340 MapPartIdIntoName(entry.serverPartition[i], pname);
3341 fprintf(STDERR, "\t%35s %s\n",
3342 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3346 MapNetworkToHost(&entry, &storeEntry);
3348 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3350 ONERROR(vcode, afromvol,
3351 " Could not update VLDB entry for volume %u\n");
3353 ERROREXIT(VOLSERBADRELEASE);
3356 /* All the ROs were release successfully. Remove the temporary clone */
3359 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3360 (unsigned long)cloneVolId);
3363 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3364 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3369 for (i = 0; i < entry.nServers; i++)
3370 entry.serverFlags[i] &= ~NEW_REPSITE;
3372 /* Update the VLDB */
3373 VPRINT("updating VLDB ...");
3375 MapNetworkToHost(&entry, &storeEntry);
3377 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3378 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3379 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3384 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3388 "Failed to end cloning transaction on the RW volume %lu\n",
3389 (unsigned long)afromvol);
3395 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3399 "Failed to end transaction on the release clone %lu\n",
3400 (unsigned long)cloneVolId);
3405 for (i = 0; i < nservers; i++) {
3406 if (replicas && replicas[i].trans) {
3407 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3408 replicas[i].trans = 0;
3411 "Failed to end transaction on ro volume %u at server 0x%x\n",
3412 entry.volumeId[ROVOL],
3413 hostutil_GetNameByINet(htonl
3414 (replicas[i].server.
3420 if (toconns && toconns[i]) {
3421 rx_DestroyConnection(toconns[i]);
3427 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, RWVOL,
3428 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3431 "Could not release lock on the VLDB entry for volume %lu\n",
3432 (unsigned long)afromvol);
3438 PrintError("", error);
3441 rx_DestroyConnection(fromconn);
3442 if (results.manyResults_val)
3443 free(results.manyResults_val);
3455 dump_sig_handler(int x)
3457 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3461 /* Dump the volume <afromvol> on <afromserver> and
3462 * <afrompart> to <afilename> starting from <fromdate>.
3463 * DumpFunction does the real work behind the scenes after
3464 * extracting parameters from the rock
3467 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3468 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock)
3470 struct rx_connection *fromconn = (struct rx_connection *)0;
3471 struct rx_call *fromcall = (struct rx_call *)0;
3472 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3473 afs_int32 code, error = 0;
3477 #ifndef AFS_NT40_ENV
3478 (void)signal(SIGPIPE, dump_sig_handler);
3480 (void)signal(SIGINT, dump_sig_handler);
3483 VPRINT("Full Dump ...\n");
3485 VPRINT1("Incremental Dump (as of %.24s)...\n",
3486 ctime((time_t *) & fromdate));
3489 /* get connections to the servers */
3490 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3492 VPRINT1("Starting transaction on volume %u...", afromvol);
3493 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3494 EGOTO1(error_exit, code,
3495 "Could not start transaction on the volume %u to be dumped\n",
3499 fromcall = rx_NewCall(fromconn);
3501 VPRINT1("Starting volume dump on volume %u...", afromvol);
3502 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3503 EGOTO(error_exit, code, "Could not start the dump process \n");
3506 VPRINT1("Dumping volume %u...", afromvol);
3507 code = DumpFunction(fromcall, rock);
3508 EGOTO(error_exit, code, "Error while dumping volume \n");
3513 code = rx_EndCall(fromcall, rxError);
3515 fprintf(STDERR, "Error in rx_EndCall\n");
3521 VPRINT1("Ending transaction on volume %u...", afromvol);
3522 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3523 if (code || rcode) {
3524 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3525 (unsigned long)afromvol);
3527 error = (code ? code : rcode);
3532 rx_DestroyConnection(fromconn);
3534 PrintError("", error);
3538 /* Clone the volume <afromvol> on <afromserver> and
3539 * <afrompart>, and then dump the clone volume to
3540 * <afilename> starting from <fromdate>.
3541 * DumpFunction does the real work behind the scenes after
3542 * extracting parameters from the rock
3545 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3546 afs_int32 afrompart, afs_int32 fromdate,
3547 afs_int32(*DumpFunction) (), char *rock)
3549 struct rx_connection *fromconn = (struct rx_connection *)0;
3550 struct rx_call *fromcall = (struct rx_call *)0;
3551 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3552 afs_int32 clonetid = 0;
3553 afs_int32 code = 0, vcode = 0, error = 0;
3554 afs_int32 clonevol = 0;
3559 #ifndef AFS_NT40_ENV
3560 (void)signal(SIGPIPE, dump_sig_handler);
3562 (void)signal(SIGINT, dump_sig_handler);
3565 VPRINT("Full Dump ...\n");
3567 VPRINT1("Incremental Dump (as of %.24s)...\n",
3568 ctime((time_t *) & fromdate));
3571 /* get connections to the servers */
3572 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3574 VPRINT1("Starting transaction on volume %u...", afromvol);
3575 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3576 EGOTO1(error_exit, code,
3577 "Could not start transaction on the volume %u to be dumped\n",
3581 /* Get a clone id */
3582 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3583 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &clonevol);
3584 EGOTO1(error_exit, code,
3585 "Could not get an ID for the clone of volume %u from the VLDB\n",
3589 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3590 VPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3592 strcpy(vname, "dump-clone-temp");
3594 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3595 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3599 VPRINT1("Ending the transaction on the volume %u ...", afromvol);
3601 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3605 EGOTO1(error_exit, code,
3606 "Failed to end the transaction on the volume %u\n", afromvol);
3610 VPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
3612 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
3614 EGOTO1(error_exit, code,
3615 "Failed to start a transaction on the cloned volume%u\n",
3619 VPRINT1("Setting flags on cloned volume %u ...", clonevol);
3620 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
3621 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
3626 fromcall = rx_NewCall(fromconn);
3628 VPRINT1("Starting volume dump from cloned volume %u...", clonevol);
3629 code = StartAFSVolDump(fromcall, clonetid, fromdate);
3630 EGOTO(error_exit, code, "Could not start the dump process \n");
3633 VPRINT1("Dumping volume %u...", afromvol);
3634 code = DumpFunction(fromcall, rock);
3635 EGOTO(error_exit, code, "Error while dumping volume \n");
3639 /* now delete the clone */
3640 VPRINT1("Deleting the cloned volume %u ...", clonevol);
3641 code = AFSVolDeleteVolume(fromconn, clonetid);
3643 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
3644 (unsigned long)clonevol);
3650 code = rx_EndCall(fromcall, rxError);
3652 fprintf(STDERR, "Error in rx_EndCall\n");
3658 VPRINT1("Ending transaction on cloned volume %u...", clonevol);
3659 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3660 if (code || rcode) {
3662 "Could not end transaction on the cloned volume %lu\n",
3663 (unsigned long)clonevol);
3665 error = (code ? code : rcode);
3670 rx_DestroyConnection(fromconn);
3672 PrintError("", error);
3679 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
3680 * the dump file <afilename>. WriteData does all the real work
3681 * after extracting params from the rock
3684 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
3685 char tovolname[], int flags, afs_int32(*WriteData) (),
3688 struct rx_connection *toconn, *tempconn;
3689 struct rx_call *tocall;
3690 afs_int32 totid, code, rcode, vcode, terror = 0;
3691 afs_int32 rxError = 0;
3692 struct volser_status tstatus;
3697 struct nvldbentry entry, storeEntry;
3700 struct restoreCookie cookie;
3702 afs_int32 newDate, volflag, voltype, volsertype;
3703 int index, same, errcode;
3707 memset(&cookie, 0, sizeof(cookie));
3712 tocall = (struct rx_call *)0;
3713 toconn = (struct rx_connection *)0;
3714 tempconn = (struct rx_connection *)0;
3718 if (flags & RV_RDONLY) {
3720 volsertype = volser_RO;
3723 volsertype = volser_RW;
3727 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
3728 if (pvolid == 0) { /*alot a new id if needed */
3729 vcode = VLDB_GetEntryByName(tovolname, &entry);
3730 if (vcode == VL_NOENT) {
3731 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &pvolid);
3733 fprintf(STDERR, "Could not get an Id for the volume %s\n",
3739 } else if (flags & RV_RDONLY) {
3740 if (entry.flags & RW_EXISTS) {
3742 "Entry for ReadWrite volume %s already exists!\n",
3744 error = VOLSERBADOP;
3747 if (!entry.volumeId[ROVOL]) {
3749 "Existing entry for volume %s has no ReadOnly ID\n",
3751 error = VOLSERBADOP;
3754 pvolid = entry.volumeId[ROVOL];
3756 pvolid = entry.volumeId[RWVOL];
3759 /* at this point we have a volume id to use/reuse for the volume to be restored */
3760 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
3761 EGOTO1(refail, VOLSERBADOP,
3762 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
3765 MapPartIdIntoName(topart, partName);
3766 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
3767 tovolname, (unsigned long)pvolid,
3768 hostutil_GetNameByINet(toserver), partName);
3771 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0, &pvolid,
3774 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
3775 VPRINT1("Deleting the previous volume %u ...", pvolid);
3778 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
3779 EGOTO1(refail, code, "Failed to start transaction on %u\n",
3783 AFSVolSetFlags(toconn, totid,
3784 VTDeleteOnSalvage | VTOutOfService);
3785 EGOTO1(refail, code, "Could not set flags on volume %u \n",
3788 code = AFSVolDeleteVolume(toconn, totid);
3789 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
3791 code = AFSVolEndTrans(toconn, totid, &rcode);
3795 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
3800 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0,
3802 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
3805 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
3806 EGOTO1(refail, code, "Failed to start transaction on %u\n",
3810 cookie.parent = pvolid;
3811 cookie.type = voltype;
3813 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
3815 tocall = rx_NewCall(toconn);
3816 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
3818 fprintf(STDERR, "Volume restore Failed \n");
3822 code = WriteData(tocall, rock);
3824 fprintf(STDERR, "Could not transmit data\n");
3828 terror = rx_EndCall(tocall, rxError);
3829 tocall = (struct rx_call *)0;
3831 fprintf(STDERR, "rx_EndCall Failed \n");
3835 code = AFSVolGetStatus(toconn, totid, &tstatus);
3838 "Could not get status information about the volume %lu\n",
3839 (unsigned long)pvolid);
3843 code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pvolid, 0, 0);
3845 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
3846 (unsigned long)pvolid);
3851 code = AFSVolSetDate(toconn, totid, newDate);
3853 fprintf(STDERR, "Could not set the date on %lu\n",
3854 (unsigned long)pvolid);
3859 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
3860 code = AFSVolSetFlags(toconn, totid, volflag);
3862 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
3867 /* It isn't handled right in refail */
3868 code = AFSVolEndTrans(toconn, totid, &rcode);
3873 fprintf(STDERR, "Could not end transaction on %lu\n",
3874 (unsigned long)pvolid);
3880 fprintf(STDOUT, " done\n");
3882 if (success && (!reuseID || (flags & RV_FULLRST))) {
3883 /* Volume was restored on the file server, update the
3884 * VLDB to reflect the change.
3886 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
3887 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
3889 "Could not fetch the entry for volume number %lu from VLDB \n",
3890 (unsigned long)pvolid);
3895 MapHostToNetwork(&entry);
3896 if (vcode == VL_NOENT) { /* it doesnot exist already */
3897 /*make the vldb return this indication specifically */
3898 VPRINT("------- Creating a new VLDB entry ------- \n");
3899 strcpy(entry.name, tovolname);
3901 entry.serverNumber[0] = toserver; /*should be indirect */
3902 entry.serverPartition[0] = topart;
3903 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
3904 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
3905 if (flags & RV_RDONLY)
3906 entry.volumeId[ROVOL] = pvolid;
3907 else if (tstatus.cloneID != 0) {
3908 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
3910 entry.volumeId[ROVOL] = INVALID_BID;
3911 entry.volumeId[RWVOL] = pvolid;
3913 if (tstatus.backupID != 0) {
3914 entry.volumeId[BACKVOL] = tstatus.backupID;
3915 /*this should come from status info on the volume if non zero */
3917 entry.volumeId[BACKVOL] = INVALID_BID;
3918 MapNetworkToHost(&entry, &storeEntry);
3919 vcode = VLDB_CreateEntry(&storeEntry);
3922 "Could not create the VLDB entry for volume number %lu \n",
3923 (unsigned long)pvolid);
3929 EnumerateEntry(&entry);
3930 } else { /*update the existing entry */
3932 fprintf(STDOUT, "Updating the existing VLDB entry\n");
3933 fprintf(STDOUT, "------- Old entry -------\n");
3934 EnumerateEntry(&entry);
3935 fprintf(STDOUT, "------- New entry -------\n");
3938 ubik_Call(VL_SetLock, cstruct, 0, pvolid, voltype,
3942 "Could not lock the entry for volume number %lu \n",
3943 (unsigned long)pvolid);
3948 strcpy(entry.name, tovolname);
3950 /* Update the vlentry with the new information */
3951 if (flags & RV_RDONLY)
3952 index = Lp_ROMatch(toserver, topart, &entry) - 1;
3954 index = Lp_GetRwIndex(&entry);
3956 /* Add the new site for the volume being restored */
3957 entry.serverNumber[entry.nServers] = toserver;
3958 entry.serverPartition[entry.nServers] = topart;
3959 entry.serverFlags[entry.nServers] =
3960 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
3963 /* This volume should be deleted on the old site
3964 * if its different from new site.
3967 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
3970 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
3972 if ((!errcode && !same)
3973 || (entry.serverPartition[index] != topart)) {
3975 UV_Bind(entry.serverNumber[index],
3976 AFSCONF_VOLUMEPORT);
3978 MapPartIdIntoName(entry.serverPartition[index],
3981 ("Deleting the previous volume %u on server %s, partition %s ...",
3983 hostutil_GetNameByINet(entry.serverNumber[index]),
3986 AFSVolTransCreate(tempconn, pvolid,
3987 entry.serverPartition[index],
3988 ITOffline, &temptid);
3991 AFSVolSetFlags(tempconn, temptid,
3996 "Could not set flags on volume %lu on the older site\n",
3997 (unsigned long)pvolid);
4001 code = AFSVolDeleteVolume(tempconn, temptid);
4004 "Could not delete volume %lu on the older site\n",
4005 (unsigned long)pvolid);
4009 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4015 "Could not end transaction on volume %lu on the older site\n",
4016 (unsigned long)pvolid);
4021 MapPartIdIntoName(entry.serverPartition[index],
4025 entry.serverNumber[index] = toserver;
4026 entry.serverPartition[index] = topart;
4029 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4030 MapNetworkToHost(&entry, &storeEntry);
4032 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4033 LOCKREL_OPCODE | LOCKREL_AFSID |
4037 "Could not update the entry for volume number %lu \n",
4038 (unsigned long)pvolid);
4044 EnumerateEntry(&entry);
4051 code = rx_EndCall(tocall, rxError);
4057 ubik_Call(VL_ReleaseLock, cstruct, 0, pvolid, voltype,
4058 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4061 "Could not release lock on the VLDB entry for the volume %lu\n",
4062 (unsigned long)pvolid);
4068 code = AFSVolEndTrans(toconn, totid, &rcode);
4072 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4073 (unsigned long)pvolid);
4079 code = AFSVolEndTrans(toconn, temptid, &rcode);
4083 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4084 (unsigned long)pvolid);
4090 rx_DestroyConnection(tempconn);
4092 rx_DestroyConnection(toconn);
4093 PrintError("", error);
4098 /*unlocks the vldb entry associated with <volid> */
4100 UV_LockRelease(afs_int32 volid)
4106 VPRINT("Binding to the VLDB server\n");
4108 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4109 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4112 "Could not unlock the entry for volume number %lu in VLDB \n",
4113 (unsigned long)volid);
4114 PrintError("", vcode);
4117 VPRINT("VLDB updated\n");
4122 /*adds <server> and <part> as a readonly replication site for <volid>
4125 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4127 int j, nro = 0, islocked = 0;
4128 struct nvldbentry entry, storeEntry;
4129 afs_int32 vcode, error = 0;
4132 error = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4135 " Could not lock the VLDB entry for the volume %lu \n",
4136 (unsigned long)volid);
4141 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4144 "Could not fetch the VLDB entry for volume number %lu \n",
4145 (unsigned long)volid);
4149 if (!ISNAMEVALID(entry.name)) {
4151 "Volume name %s is too long, rename before adding site\n",
4153 error = VOLSERBADOP;
4156 MapHostToNetwork(&entry);
4158 /* See if it's too many entries */
4159 if (entry.nServers >= NMAXNSERVERS) {
4160 fprintf(STDERR, "Total number of entries will exceed %u\n",
4162 error = VOLSERBADOP;
4166 /* See if it's on the same server */
4167 for (j = 0; j < entry.nServers; j++) {
4168 if (entry.serverFlags[j] & ITSROVOL) {
4170 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4173 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4176 MapPartIdIntoName(entry.serverPartition[j], apartName);
4178 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4180 error = VOLSERBADOP;
4187 /* See if it's too many RO sites - leave one for the RW */
4188 if (nro >= NMAXNSERVERS - 1) {
4189 fprintf(STDERR, "Total number of sites will exceed %u\n",
4191 error = VOLSERBADOP;
4195 VPRINT("Adding a new site ...");
4196 entry.serverNumber[entry.nServers] = server;
4197 entry.serverPartition[entry.nServers] = part;
4198 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4201 MapNetworkToHost(&entry, &storeEntry);
4203 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4204 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4206 fprintf(STDERR, "Could not update entry for volume %lu \n",
4207 (unsigned long)volid);
4216 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4217 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4220 "Could not release lock on volume entry for %lu \n",
4221 (unsigned long)volid);
4222 PrintError("", vcode);
4226 PrintError("", error);
4230 /*removes <server> <part> as read only site for <volid> from the vldb */
4232 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4235 struct nvldbentry entry, storeEntry;
4238 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4240 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4241 (unsigned long)volid);
4242 PrintError("", vcode);
4246 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4249 "Could not fetch the entry for volume number %lu from VLDB \n",
4250 (unsigned long)volid);
4251 PrintError("", vcode);
4254 MapHostToNetwork(&entry);
4255 if (!Lp_ROMatch(server, part, &entry)) {
4256 /*this site doesnot exist */
4257 fprintf(STDERR, "This site is not a replication site \n");
4259 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4260 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4262 fprintf(STDERR, "Could not update entry for volume %lu \n",
4263 (unsigned long)volid);
4264 PrintError("", vcode);
4265 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4266 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4270 } else { /*remove the rep site */
4271 Lp_SetROValue(&entry, server, part, 0, 0);
4273 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4274 entry.flags &= ~RO_EXISTS;
4275 if (entry.nServers < 1) { /*this is the last ref */
4276 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4278 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, volid, ROVOL);
4281 "Could not delete VLDB entry for volume %lu \n",
4282 (unsigned long)volid);
4283 PrintError("", vcode);
4288 MapNetworkToHost(&entry, &storeEntry);
4289 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4290 (unsigned long)volid);
4293 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4294 LOCKREL_OPCODE | LOCKREL_AFSID |
4298 "Could not release lock on volume entry for %lu \n",
4299 (unsigned long)volid);
4300 PrintError("", vcode);
4301 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4302 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4310 /*sets <server> <part> as read/write site for <volid> in the vldb */
4312 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4315 struct nvldbentry entry, storeEntry;
4318 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4320 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4321 (unsigned long)volid);
4322 PrintError("", vcode);
4325 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4328 "Could not fetch the entry for volume number %lu from VLDB \n",
4329 (unsigned long)volid);
4330 PrintError("", vcode);
4333 MapHostToNetwork(&entry);
4334 index = Lp_GetRwIndex(&entry);
4336 /* no RW site exists */
4337 fprintf(STDERR, "No existing RW site for volume %lu",
4338 (unsigned long)volid);
4340 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4341 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4344 "Could not release lock on entry for volume %lu \n",
4345 (unsigned long)volid);
4346 PrintError("", vcode);
4350 } else { /* change the RW site */
4351 entry.serverNumber[index] = server;
4352 entry.serverPartition[index] = part;
4353 MapNetworkToHost(&entry, &storeEntry);
4355 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4356 LOCKREL_OPCODE | LOCKREL_AFSID |
4359 fprintf(STDERR, "Could not update entry for volume %lu \n",
4360 (unsigned long)volid);
4361 PrintError("", vcode);
4362 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4363 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4371 /*list all the partitions on <aserver> */
4373 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4376 struct rx_connection *aconn;
4377 struct pIDs partIds;
4378 struct partEntries partEnts;
4379 register int i, j = 0, code;
4382 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4384 partEnts.partEntries_len = 0;
4385 partEnts.partEntries_val = NULL;
4386 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4387 if (code == RXGEN_OPCODE) {
4388 for (i = 0; i < 26; i++) /* try old interface */
4389 partIds.partIds[i] = -1;
4390 code = AFSVolListPartitions(aconn, &partIds);
4392 for (i = 0; i < 26; i++) {
4393 if ((partIds.partIds[i]) != -1) {
4394 ptrPartList->partId[j] = partIds.partIds[i];
4395 ptrPartList->partFlags[j] = PARTVALID;
4398 ptrPartList->partFlags[i] = 0;
4403 *cntp = partEnts.partEntries_len;
4404 if (*cntp > VOLMAXPARTS) {
4406 "Warning: number of partitions on the server too high %d (process only %d)\n",
4407 *cntp, VOLMAXPARTS);
4408 *cntp = VOLMAXPARTS;
4410 for (i = 0; i < *cntp; i++) {
4411 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4412 ptrPartList->partFlags[i] = PARTVALID;
4414 free(partEnts.partEntries_val);
4419 "Could not fetch the list of partitions from the server\n");
4420 PrintError("", code);
4422 rx_DestroyConnection(aconn);
4427 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4428 This is used by the backup system */
4430 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4431 struct volDescription *volPtr, afs_int32 arraySize)
4433 struct rx_connection *aconn;
4434 struct volDescription *curPtr;
4437 afs_int32 rcode = 0;
4438 afs_int32 success = 1;
4441 aconn = (struct rx_connection *)0;
4442 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4444 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4445 if (curPtr->volFlags & CLONEVALID) {
4446 curPtr->volFlags &= ~CLONEZAPPED;
4449 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4454 code = AFSVolDeleteVolume(aconn, tid);
4457 code = AFSVolEndTrans(aconn, tid, &rcode);
4462 curPtr->volFlags |= CLONEZAPPED;
4464 fprintf(STDERR, "Could not zap volume %lu\n",
4465 (unsigned long)curPtr->volCloneId);
4467 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4468 curPtr->volCloneId);
4474 rx_DestroyConnection(aconn);
4478 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4481 UV_GenerateVolumeClones(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;
4490 int reuseCloneId = 0;
4491 afs_int32 curCloneId = 0;
4492 char cloneName[256]; /*max vol name */
4494 aconn = (struct rx_connection *)0;
4495 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4497 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4499 else { /*get a bunch of id's from vldb */
4501 ubik_Call(VL_GetNewVolumeId, cstruct, 0, arraySize, &curCloneId);
4503 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4504 PrintError("", code);
4509 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4510 if (curPtr->volFlags & ENTRYVALID) {
4512 curPtr->volFlags |= CLONEVALID;
4513 /*make a clone of curParentId and record as curPtr->volCloneId */
4515 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4518 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4521 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
4525 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
4526 strcpy(cloneName, curPtr->volName);
4527 strcat(cloneName, "-tmpClone-");
4529 strcpy(cloneName, "-tmpClone");
4531 curPtr->volCloneId = curCloneId;
4536 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
4537 &(curPtr->volCloneId));
4539 curPtr->volFlags &= ~CLONEVALID;
4541 fprintf(STDERR, "Could not clone %s due to error %lu\n",
4542 curPtr->volName, (unsigned long)code);
4543 code = AFSVolEndTrans(aconn, tid, &rcode);
4545 fprintf(STDERR, "WARNING: could not end transaction\n");
4548 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
4549 curPtr->volCloneId);
4550 code = AFSVolEndTrans(aconn, tid, &rcode);
4551 if (code || rcode) {
4552 curPtr->volFlags &= ~CLONEVALID;
4561 rx_DestroyConnection(aconn);
4566 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
4567 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
4569 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
4570 struct volintInfo **resultPtr, afs_int32 * size)
4572 struct rx_connection *aconn;
4574 volEntries volumeInfo;
4578 *resultPtr = (volintInfo *) 0;
4579 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
4580 volumeInfo.volEntries_len = 0;
4582 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4583 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
4586 "Could not fetch the list of volumes from the server\n");
4588 *resultPtr = volumeInfo.volEntries_val;
4589 *size = volumeInfo.volEntries_len;
4593 rx_DestroyConnection(aconn);
4594 PrintError("", code);
4598 /*------------------------------------------------------------------------
4599 * EXPORTED UV_XListVolumes
4602 * List the extended information for all the volumes on a particular
4603 * File Server and partition. We may either return the volume's ID
4604 * or all of its extended information.
4607 * a_serverID : Address of the File Server for which we want
4608 * extended volume info.
4609 * a_partID : Partition for which we want the extended
4611 * a_all : If non-zero, fetch ALL the volume info,
4612 * otherwise just the volume ID.
4613 * a_resultPP : Ptr to the address of the area containing
4614 * the returned volume info.
4615 * a_numEntsInResultP : Ptr for the value we set for the number of
4620 * Otherise, the return value of AFSVolXListVolumes.
4623 * This routine is closely related to UV_ListVolumes, which returns
4624 * only the standard level of detail on AFS volumes. It is a
4625 * heavyweight operation, zipping through all the volume entries for
4626 * a given server/partition.
4630 *------------------------------------------------------------------------*/
4633 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
4634 struct volintXInfo **a_resultPP,
4635 afs_int32 * a_numEntsInResultP)
4637 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
4638 afs_int32 code; /*Error code to return */
4639 volXEntries volumeXInfo; /*Area for returned extended vol info */
4642 * Set up our error code and the area for returned extended volume info.
4643 * We set the val field to a null pointer as a hint for the stub to
4647 *a_numEntsInResultP = 0;
4648 *a_resultPP = (volintXInfo *) 0;
4649 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
4650 volumeXInfo.volXEntries_len = 0;
4653 * Bind to the Volume Server port on the File Server machine in question,
4656 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
4657 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
4659 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
4662 * We got the info; pull out the pointer to where the results lie
4663 * and how many entries are there.
4665 *a_resultPP = volumeXInfo.volXEntries_val;
4666 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
4670 * If we got an Rx connection, throw it away.
4673 rx_DestroyConnection(rxConnP);
4675 PrintError("", code);
4677 } /*UV_XListVolumes */
4679 /* get all the information about volume <volid> on <aserver> and <apart> */
4681 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
4682 struct volintInfo **resultPtr)
4684 struct rx_connection *aconn;
4686 volEntries volumeInfo;
4690 *resultPtr = (volintInfo *) 0;
4691 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
4692 volumeInfo.volEntries_len = 0;
4694 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4695 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
4698 "Could not fetch the information about volume %lu from the server\n",
4699 (unsigned long)volid);
4701 *resultPtr = volumeInfo.volEntries_val;
4706 rx_DestroyConnection(aconn);
4707 PrintError("", code);
4711 /*------------------------------------------------------------------------
4712 * EXPORTED UV_XListOneVolume
4715 * List the extended information for a volume on a particular File
4716 * Server and partition.
4719 * a_serverID : Address of the File Server for which we want
4720 * extended volume info.
4721 * a_partID : Partition for which we want the extended
4723 * a_volID : Volume ID for which we want the info.
4724 * a_resultPP : Ptr to the address of the area containing
4725 * the returned volume info.
4729 * Otherise, the return value of AFSVolXListOneVolume.
4732 * This routine is closely related to UV_ListOneVolume, which returns
4733 * only the standard level of detail on the chosen AFS volume.
4737 *------------------------------------------------------------------------*/
4740 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
4741 struct volintXInfo **a_resultPP)
4743 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
4744 afs_int32 code; /*Error code */
4745 volXEntries volumeXInfo; /*Area for returned info */
4748 * Set up our error code, and the area we're in which we are returning
4749 * the info. Setting the val field to a null pointer tells the stub
4750 * to allocate space for us.
4753 *a_resultPP = (volintXInfo *) 0;
4754 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
4755 volumeXInfo.volXEntries_len = 0;
4758 * Bind to the Volume Server port on the File Server machine in question,
4761 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
4762 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
4765 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
4768 * We got the info; pull out the pointer to where the results lie.
4770 *a_resultPP = volumeXInfo.volXEntries_val;
4773 * If we got an Rx connection, throw it away.
4776 rx_DestroyConnection(rxConnP);
4778 PrintError("", code);
4783 * Given a volume we read from a partition, check if it is
4784 * represented in the VLDB correctly.
4786 * The VLDB is looked up by the RW volume id (not its name).
4787 * The RW contains the true name of the volume (BK and RO set
4788 * the name in the VLDB only on creation of the VLDB entry).
4789 * We want rules strict enough that when we check all volumes
4790 * on one partition, it does not need to be done again. IE:
4791 * two volumes on different partitions won't constantly
4792 * change a VLDB entry away from what the other set.
4793 * For RW and BK volumes, we will always check the VLDB to see
4794 * if the two exist on the server/partition. May seem redundant,
4795 * but this is an easy check of the VLDB. IE: if the VLDB entry
4796 * says the BK exists but no BK volume is there, we will detect
4797 * this when we check the RW volume.
4798 * VLDB entries are locked only when a change needs to be done.
4799 * Output changed to look a lot like the "vos syncserv" otuput.
4802 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
4803 afs_int32 * modentry, afs_uint32 * maxvolid)
4806 afs_int32 code, error = 0;
4807 struct nvldbentry entry, storeEntry;
4809 int pass = 0, islocked = 0, createentry, addvolume, modified, mod;
4815 ((volumeinfo->type ==
4816 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
4819 /* Check to see if the VLDB is ok without locking it (pass 1).
4820 * If it will change, then lock the VLDB entry, read it again,
4821 * then make the changes to it (pass 2).
4824 code = ubik_Call(VL_SetLock, cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
4826 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
4827 (unsigned long)rwvolid);
4833 createentry = 0; /* Do we need to create a VLDB entry */
4834 addvolume = 0; /* Add this volume to the VLDB entry */
4835 modified = 0; /* The VLDB entry was modified */
4837 /* Read the entry from VLDB by its RW volume id */
4838 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
4840 if (code != VL_NOENT) {
4842 "Could not retreive the VLDB entry for volume %lu \n",
4843 (unsigned long)rwvolid);
4847 memset(&entry, 0, sizeof(entry));
4848 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
4852 MapHostToNetwork(&entry);
4855 if (verbose && (pass == 1)) {
4856 fprintf(STDOUT, "_______________________________\n");
4857 fprintf(STDOUT, "\n-- status before -- \n");
4859 fprintf(STDOUT, "\n**does not exist**\n");
4861 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
4862 || (entry.flags & BACK_EXISTS))
4863 EnumerateEntry(&entry);
4865 fprintf(STDOUT, "\n");
4868 if (volumeinfo->type == RWVOL) { /* RW volume exists */
4874 /* Check existence of RW and BK volumes */
4875 code = CheckVldbRWBK(&entry, &mod);
4881 idx = Lp_GetRwIndex(&entry);
4882 if (idx == -1) { /* RW index not found in the VLDB entry */
4883 idx = entry.nServers; /* put it into next index */
4886 } else { /* RW index found in the VLDB entry. */
4887 /* Verify if this volume's location matches where the VLDB says it is */
4888 if (!Lp_Match(aserver, apart, &entry)) {
4889 if (entry.flags & RW_EXISTS) {
4890 /* The RW volume exists elsewhere - report this one a duplicate */
4892 MapPartIdIntoName(apart, pname);
4894 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
4895 (unsigned long)rwvolid,
4896 hostutil_GetNameByINet(aserver), pname);
4897 MapPartIdIntoName(entry.serverPartition[idx],
4900 " VLDB reports RW volume %lu exists on %s %s\n",
4901 (unsigned long)rwvolid,
4902 hostutil_GetNameByINet(entry.
4907 /* The RW volume does not exist - have VLDB point to this one */
4910 /* Check for orphaned BK volume on old partition */
4911 if (entry.flags & BACK_EXISTS) {
4913 MapPartIdIntoName(entry.serverPartition[idx],
4916 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
4917 entry.volumeId[BACKVOL],
4918 hostutil_GetNameByINet(entry.
4921 MapPartIdIntoName(apart, pname);
4923 " VLDB reports its RW volume %lu exists on %s %s\n",
4924 (unsigned long)rwvolid,
4925 hostutil_GetNameByINet(aserver),
4931 /* Volume location matches the VLDB location */
4932 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
4933 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
4936 (entry.name, volumeinfo->name,
4937 VOLSER_OLDMAXVOLNAME) != 0)) {
4945 entry.flags |= RW_EXISTS;
4946 entry.volumeId[RWVOL] = rwvolid;
4947 if (!entry.volumeId[BACKVOL])
4948 entry.volumeId[BACKVOL] = volumeinfo->backupID;
4949 if (!entry.volumeId[ROVOL])
4950 entry.volumeId[ROVOL] = volumeinfo->cloneID;
4952 entry.serverFlags[idx] = ITSRWVOL;
4953 entry.serverNumber[idx] = aserver;
4954 entry.serverPartition[idx] = apart;
4955 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
4959 /* One last check - to update BK if need to */
4960 code = CheckVldbRWBK(&entry, &mod);
4968 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
4974 /* Check existence of RW and BK volumes */
4975 code = CheckVldbRWBK(&entry, &mod);
4981 idx = Lp_GetRwIndex(&entry);
4982 if (idx == -1) { /* RW index not found in the VLDB entry */
4983 idx = entry.nServers; /* Put it into next index */
4986 } else { /* RW index found in the VLDB entry */
4987 /* Verify if this volume's location matches where the VLDB says it is */
4988 if (!Lp_Match(aserver, apart, &entry)) {
4989 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
4991 MapPartIdIntoName(apart, pname);
4993 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
4994 (unsigned long)volumeinfo->volid,
4995 hostutil_GetNameByINet(aserver), pname);
4996 MapPartIdIntoName(entry.serverPartition[idx], pname);
4998 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
4999 (unsigned long)rwvolid,
5000 hostutil_GetNameByINet(entry.
5005 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5006 if (!(entry.flags & BACK_EXISTS)) {
5008 } else if (volumeinfo->volid >
5009 entry.volumeId[BACKVOL]) {
5013 MapPartIdIntoName(entry.serverPartition[idx],
5016 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5017 entry.volumeId[BACKVOL],
5018 hostutil_GetNameByINet(aserver),
5021 " VLDB reports its BK volume ID is %lu\n",
5022 (unsigned long)volumeinfo->volid);
5026 MapPartIdIntoName(entry.serverPartition[idx],
5029 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5030 (unsigned long)volumeinfo->volid,
5031 hostutil_GetNameByINet(aserver),
5034 " VLDB reports its BK volume ID is %u\n",
5035 entry.volumeId[BACKVOL]);
5038 } else if (!entry.volumeId[BACKVOL]) {
5045 entry.flags |= BACK_EXISTS;
5046 entry.volumeId[RWVOL] = rwvolid;
5047 entry.volumeId[BACKVOL] = volumeinfo->volid;
5049 entry.serverNumber[idx] = aserver;
5050 entry.serverPartition[idx] = apart;
5051 entry.serverFlags[idx] = ITSRWVOL;
5057 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5058 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5059 /* This is a quick check to see if the RO entry exists in the
5060 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5061 * RO volume listed in the VLDB exists).
5063 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5065 idx = entry.nServers;
5069 if (!(entry.flags & RO_EXISTS)) {
5074 /* Before we correct the VLDB entry, make sure all the
5075 * ROs listed in the VLDB exist.
5077 code = CheckVldbRO(&entry, &mod);
5083 if (!(entry.flags & RO_EXISTS)) {
5084 /* No RO exists in the VLDB entry - add this one */
5085 idx = entry.nServers;
5088 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5089 /* The volume headers's RO ID does not match that in the VLDB entry,
5090 * and the vol hdr's ID is greater (implies more recent). So delete
5091 * all the RO volumes listed in VLDB entry and add this volume.
5093 for (j = 0; j < entry.nServers; j++) {
5094 if (entry.serverFlags[j] & ITSROVOL) {
5095 /* Verify this volume exists and print message we are orphaning it */
5097 MapPartIdIntoName(apart, pname);
5099 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5100 entry.volumeId[ROVOL],
5101 hostutil_GetNameByINet(entry.
5105 " VLDB reports its RO volume ID is %lu\n",
5106 (unsigned long)volumeinfo->volid);
5109 Lp_SetRWValue(entry, entry.serverNumber[idx],
5110 entry.serverPartition[idx], 0L, 0L);
5117 idx = entry.nServers;
5120 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5121 /* The volume headers's RO ID does not match that in the VLDB entry,
5122 * and the vol hdr's ID is lower (implies its older). So orphan it.
5125 MapPartIdIntoName(apart, pname);
5127 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5128 (unsigned long)volumeinfo->volid,
5129 hostutil_GetNameByINet(aserver), pname);
5131 " VLDB reports its RO volume ID is %u\n",
5132 entry.volumeId[ROVOL]);
5135 /* The RO volume ID in the volume header match that in the VLDB entry,
5136 * and there exist RO volumes in the VLDB entry. See if any of them
5137 * are this one. If not, then we add it.
5139 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5141 idx = entry.nServers;
5149 entry.flags |= RO_EXISTS;
5150 entry.volumeId[RWVOL] = rwvolid;
5151 entry.volumeId[ROVOL] = volumeinfo->volid;
5153 entry.serverNumber[idx] = aserver;
5154 entry.serverPartition[idx] = apart;
5155 entry.serverFlags[idx] = ITSROVOL;
5161 /* Remember largest volume id */
5162 if (entry.volumeId[ROVOL] > *maxvolid)
5163 *maxvolid = entry.volumeId[ROVOL];
5164 if (entry.volumeId[BACKVOL] > *maxvolid)
5165 *maxvolid = entry.volumeId[BACKVOL];
5166 if (entry.volumeId[RWVOL] > *maxvolid)
5167 *maxvolid = entry.volumeId[RWVOL];
5170 MapNetworkToHost(&entry, &storeEntry);
5173 code = VLDB_CreateEntry(&storeEntry);
5176 "Could not create a VLDB entry for the volume %lu\n",
5177 (unsigned long)rwvolid);
5184 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5185 LOCKREL_OPCODE | LOCKREL_AFSID |
5188 fprintf(STDERR, "Could not update entry for %lu\n",
5189 (unsigned long)rwvolid);
5194 *modentry = modified;
5195 } else if (pass == 2) {
5197 ubik_Call(VL_ReleaseLock, cstruct, 0, rwvolid, RWVOL,
5198 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5200 PrintError("Could not unlock VLDB entry ", code);
5205 fprintf(STDOUT, "-- status after --\n");
5207 EnumerateEntry(&entry);
5209 fprintf(STDOUT, "\n**no change**\n");
5213 VPRINT("\n_______________________________\n");
5218 sortVolumes(const void *a, const void *b)
5220 volintInfo *v1 = (volintInfo *) a;
5221 volintInfo *v2 = (volintInfo *) b;
5222 afs_int32 rwvolid1, rwvolid2;
5224 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5225 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5227 if (rwvolid1 > rwvolid2)
5228 return -1; /* lower RW id goes first */
5229 if (rwvolid1 < rwvolid2)
5232 if (v1->type == RWVOL)
5233 return -1; /* RW vols go first */
5234 if (v2->type == RWVOL)
5237 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5238 return -1; /* BK vols next */
5239 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5242 if (v1->volid < v2->volid)
5243 return 1; /* larger volids first */
5244 if (v1->volid > v2->volid)
5250 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5251 * Synchronize an individual volume against a sever and partition.
5252 * Checks the VLDB entry (similar to syncserv) as well as checks
5253 * if the volume exists on specified servers (similar to syncvldb).
5256 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5258 struct rx_connection *aconn = 0;
5259 afs_int32 j, k, code, vcode, error = 0;
5260 afs_int32 tverbose, mod, modified = 0;
5261 struct nvldbentry vldbentry;
5262 afs_int32 volumeid = 0;
5263 volEntries volumeInfo;
5264 struct partList PartList;
5266 afs_int32 maxvolid = 0;
5268 volumeInfo.volEntries_val = (volintInfo *) 0;
5269 volumeInfo.volEntries_len = 0;
5271 if (!aserver && flags) {
5272 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5276 /* Turn verbose logging off and do our own verbose logging */
5280 /* Read the VLDB entry */
5281 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5282 if (vcode && (vcode != VL_NOENT)) {
5283 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5286 } else if (!vcode) {
5287 MapHostToNetwork(&vldbentry);
5291 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5292 fprintf(STDOUT, "_______________________________\n");
5293 fprintf(STDOUT, "\n-- status before -- \n");
5295 fprintf(STDOUT, "\n**does not exist**\n");
5297 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5298 || (vldbentry.flags & BACK_EXISTS))
5299 EnumerateEntry(&vldbentry);
5301 fprintf(STDOUT, "\n");
5304 /* Verify that all of the VLDB entries exist on the repective servers
5305 * and partitions (this does not require that avolname be a volume ID).
5306 * Equivalent to a syncserv.
5309 code = CheckVldb(&vldbentry, &mod);
5311 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5319 /* If aserver is given, we will search for the desired volume on it */
5321 /* Generate array of partitions on the server that we will check */
5323 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5326 "Could not fetch the list of partitions from the server\n");
5330 PartList.partId[0] = apart;
5334 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5336 /* If a volume ID were given, search for it on each partition */
5337 if ((volumeid = atol(avolname))) {
5338 for (j = 0; j < pcnt; j++) {
5340 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5343 if (code != ENODEV) {
5344 fprintf(STDERR, "Could not query server\n");
5348 /* Found one, sync it with VLDB entry */
5350 CheckVolume(volumeInfo.volEntries_val, aserver,
5351 PartList.partId[j], &mod, &maxvolid);
5358 if (volumeInfo.volEntries_val)
5359 free(volumeInfo.volEntries_val);
5360 volumeInfo.volEntries_val = (volintInfo *) 0;
5361 volumeInfo.volEntries_len = 0;
5365 /* Check to see if the RW, BK, and RO IDs exist on any
5366 * partitions. We get the volume IDs from the VLDB.
5368 rv = 1; /* Read the VLDB entry ? */
5369 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5371 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5373 if (vcode == VL_NOENT)
5376 "Could not access the VLDB for volume %s\n",
5383 if (vldbentry.volumeId[j] == 0)
5386 for (k = 0; k < pcnt; k++) { /* For each partition */
5387 volumeInfo.volEntries_val = (volintInfo *) 0;
5388 volumeInfo.volEntries_len = 0;
5390 AFSVolListOneVolume(aconn, PartList.partId[k],
5391 vldbentry.volumeId[j], &volumeInfo);
5393 if (code != ENODEV) {
5394 fprintf(STDERR, "Could not query server\n");
5398 /* Found one, sync it with VLDB entry */
5400 CheckVolume(volumeInfo.volEntries_val, aserver,
5401 PartList.partId[k], &mod, &maxvolid);
5408 if (volumeInfo.volEntries_val)
5409 free(volumeInfo.volEntries_val);
5410 volumeInfo.volEntries_val = (volintInfo *) 0;
5411 volumeInfo.volEntries_len = 0;
5417 /* If verbose output, print a summary of what changed */
5419 fprintf(STDOUT, "-- status after --\n");
5420 code = VLDB_GetEntryByName(avolname, &vldbentry);
5421 if (code && (code != VL_NOENT)) {
5422 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5426 if (modified && (code == VL_NOENT)) {
5427 fprintf(STDOUT, "\n**entry deleted**\n");
5428 } else if (modified) {
5429 EnumerateEntry(&vldbentry);
5431 fprintf(STDOUT, "\n**no change**\n");
5433 fprintf(STDOUT, "\n_______________________________\n");
5437 /* Now check if the maxvolid is larger than that stored in the VLDB */
5439 afs_int32 maxvldbid = 0;
5440 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
5443 "Could not get the highest allocated volume id from the VLDB\n");
5446 } else if (maxvolid > maxvldbid) {
5448 id = maxvolid - maxvldbid + 1;
5449 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
5452 "Error in increasing highest allocated volume id in VLDB\n");
5462 fprintf(STDOUT, "...error encountered");
5464 fprintf(STDOUT, "...done entry\n");
5467 rx_DestroyConnection(aconn);
5468 if (volumeInfo.volEntries_val)
5469 free(volumeInfo.volEntries_val);
5471 PrintError("", error);
5476 * Synchronise vldb with the file server <aserver> and,
5477 * optionally, <apart>.
5480 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5482 struct rx_connection *aconn;
5483 afs_int32 code, error = 0;
5485 volEntries volumeInfo;
5486 struct partList PartList;
5490 afs_int32 failures = 0, modifications = 0, tentries = 0;
5492 afs_uint32 maxvolid = 0;
5494 volumeInfo.volEntries_val = (volintInfo *) 0;
5495 volumeInfo.volEntries_len = 0;
5497 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5499 /* Generate array of partitions to check */
5501 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5504 "Could not fetch the list of partitions from the server\n");
5508 PartList.partId[0] = apart;
5512 VPRINT("Processing volume entries ...\n");
5514 /* Step through the array of partitions */
5515 for (i = 0; i < pcnt; i++) {
5516 apart = PartList.partId[i];
5517 MapPartIdIntoName(apart, pname);
5519 volumeInfo.volEntries_val = (volintInfo *) 0;
5520 volumeInfo.volEntries_len = 0;
5521 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
5524 "Could not fetch the list of volumes from the server\n");
5528 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
5529 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
5530 sizeof(volintInfo), sortVolumes);
5533 for (vi = volumeInfo.volEntries_val, j = 0;
5534 j < volumeInfo.volEntries_len; j++, vi++) {
5542 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
5543 j + 1, vi->name, (unsigned long)vi->volid,
5544 hostutil_GetNameByINet(aserver), pname);
5548 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
5550 PrintError("", code);
5553 } else if (modified) {
5559 fprintf(STDOUT, "...error encountered\n\n");
5561 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
5568 "Could not process entries on server %s partition %s\n",
5569 hostutil_GetNameByINet(aserver), pname);
5571 if (volumeInfo.volEntries_val) {
5572 free(volumeInfo.volEntries_val);
5573 volumeInfo.volEntries_val = 0;
5576 } /* thru all partitions */
5578 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
5579 failures, modifications);
5582 /* Now check if the maxvolid is larger than that stored in the VLDB */
5584 afs_uint32 maxvldbid = 0;
5585 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
5588 "Could not get the highest allocated volume id from the VLDB\n");
5591 } else if (maxvolid > maxvldbid) {
5593 id = maxvolid - maxvldbid + 1;
5594 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
5597 "Error in increasing highest allocated volume id in VLDB\n");
5605 rx_DestroyConnection(aconn);
5606 if (volumeInfo.volEntries_val)
5607 free(volumeInfo.volEntries_val);
5608 PrintError("", error);
5613 * Determine if a volume exists on a server and partition.
5614 * Try creating a transaction on the volume. If we can,
5615 * the volume exists, if not, then return the error code.
5616 * Some error codes mean the volume is unavailable but
5617 * still exists - so we catch these error codes.
5620 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
5622 struct rx_connection *conn = (struct rx_connection *)0;
5623 afs_int32 code = -1;
5624 volEntries volumeInfo;
5626 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5628 volumeInfo.volEntries_val = (volintInfo *) 0;
5629 volumeInfo.volEntries_len = 0;
5630 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
5631 if (volumeInfo.volEntries_val)
5632 free(volumeInfo.volEntries_val);
5633 if (code == VOLSERILLEGAL_PARTITION)
5635 rx_DestroyConnection(conn);
5644 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
5648 afs_int32 code, error = 0;
5653 idx = Lp_GetRwIndex(entry);
5655 /* Check to see if the RW volume exists and set the RW_EXISTS
5658 if (idx == -1) { /* Did not find a RW entry */
5659 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
5660 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
5665 VolumeExists(entry->serverNumber[idx],
5666 entry->serverPartition[idx], entry->volumeId[RWVOL]);
5667 if (code == 0) { /* RW volume exists */
5668 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
5669 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
5672 } else if (code == ENODEV) { /* RW volume does not exist */
5673 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
5674 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
5678 /* If VLDB says it didn't exist, then ignore error */
5679 if (entry->flags & RW_EXISTS) {
5680 MapPartIdIntoName(entry->serverPartition[idx], pname);
5682 "Transaction call failed for RW volume %u on server %s %s\n",
5683 entry->volumeId[RWVOL],
5684 hostutil_GetNameByINet(entry->serverNumber[idx]),
5691 /* Check to see if the BK volume exists and set the BACK_EXISTS
5692 * flag accordingly. idx already ponts to the RW entry.
5694 if (idx == -1) { /* Did not find a RW entry */
5695 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
5696 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
5699 } else { /* Found a RW entry */
5701 VolumeExists(entry->serverNumber[idx],
5702 entry->serverPartition[idx],
5703 entry->volumeId[BACKVOL]);
5704 if (code == 0) { /* BK volume exists */
5705 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
5706 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
5709 } else if (code == ENODEV) { /* BK volume does not exist */
5710 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
5711 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
5715 /* If VLDB says it didn't exist, then ignore error */
5716 if (entry->flags & BACK_EXISTS) {
5717 MapPartIdIntoName(entry->serverPartition[idx], pname);
5719 "Transaction call failed for BK volume %u on server %s %s\n",
5720 entry->volumeId[BACKVOL],
5721 hostutil_GetNameByINet(entry->serverNumber[idx]),
5728 /* If there is an idx but the BK and RW volumes no
5729 * longer exist, then remove the RW entry.
5731 if ((idx != -1) && !(entry->flags & RW_EXISTS)
5732 && !(entry->flags & BACK_EXISTS)) {
5733 Lp_SetRWValue(entry, entry->serverNumber[idx],
5734 entry->serverPartition[idx], 0L, 0L);
5741 *modified = modentry;
5746 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
5749 int foundro = 0, modentry = 0;
5750 afs_int32 code, error = 0;
5756 /* Check to see if the RO volumes exist and set the RO_EXISTS
5759 for (idx = 0; idx < entry->nServers; idx++) {
5760 if (!(entry->serverFlags[idx] & ITSROVOL)) {
5761 continue; /* not a RO */
5765 VolumeExists(entry->serverNumber[idx],
5766 entry->serverPartition[idx], entry->volumeId[ROVOL]);
5767 if (code == 0) { /* RO volume exists */
5769 } else if (code == ENODEV) { /* RW volume does not exist */
5770 Lp_SetROValue(entry, entry->serverNumber[idx],
5771 entry->serverPartition[idx], 0L, 0L);
5776 MapPartIdIntoName(entry->serverPartition[idx], pname);
5778 "Transaction call failed for RO %u on server %s %s\n",
5779 entry->volumeId[ROVOL],
5780 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
5785 if (foundro) { /* A RO volume exists */
5786 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
5787 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
5790 } else { /* A RO volume does not exist */
5791 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
5792 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
5799 *modified = modentry;
5804 * Ensure that <entry> matches with the info on file servers
5807 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
5809 afs_int32 code, error = 0;
5810 struct nvldbentry storeEntry;
5811 int islocked = 0, mod, modentry, delentry = 0;
5817 fprintf(STDOUT, "_______________________________\n");
5818 fprintf(STDOUT, "\n-- status before -- \n");
5819 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
5820 || (entry->flags & BACK_EXISTS))
5821 EnumerateEntry(entry);
5822 fprintf(STDOUT, "\n");
5825 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
5826 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
5827 entry->name, VOLSER_OLDMAXVOLNAME - 10);
5831 /* Check to see if the VLDB is ok without locking it (pass 1).
5832 * If it will change, then lock the VLDB entry, read it again,
5833 * then make the changes to it (pass 2).
5837 ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL,
5840 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
5841 entry->volumeId[RWVOL]);
5846 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
5848 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
5852 MapHostToNetwork(entry);
5858 /* Check if the RW and BK entries are ok */
5859 code = CheckVldbRWBK(entry, &mod);
5862 if (mod && (pass == 1))
5867 /* Check if the RO volumes entries are ok */
5868 code = CheckVldbRO(entry, &mod);
5871 if (mod && (pass == 1))
5876 /* The VLDB entry has been updated. If it as been modified, then
5877 * write the entry back out the the VLDB.
5883 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
5884 && !(entry->flags & RO_EXISTS)) {
5885 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
5887 ubik_Call(VL_DeleteEntry, cstruct, 0, entry->volumeId[RWVOL],
5891 "Could not delete VLDB entry for volume %u \n",
5892 entry->volumeId[RWVOL]);
5897 /* Replace old entry with our new one */
5898 MapNetworkToHost(entry, &storeEntry);
5900 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
5901 (LOCKREL_OPCODE | LOCKREL_AFSID |
5902 LOCKREL_TIMESTAMP));
5904 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
5905 entry->volumeId[RWVOL]);
5915 fprintf(STDOUT, "-- status after --\n");
5917 fprintf(STDOUT, "\n**entry deleted**\n");
5919 EnumerateEntry(entry);
5921 fprintf(STDOUT, "\n**no change**\n");
5925 VPRINT("\n_______________________________\n");
5929 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
5931 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
5934 "Could not release lock on VLDB entry for volume %u\n",
5935 entry->volumeId[RWVOL]);
5944 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
5947 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
5949 struct rx_connection *aconn;
5950 afs_int32 code, error = 0;
5951 afs_int32 nentries, tentries = 0;
5952 struct VldbListByAttributes attributes;
5953 nbulkentries arrayEntries;
5954 afs_int32 failures = 0, modified, modifications = 0;
5955 struct nvldbentry *vlentry;
5956 afs_int32 si, nsi, j;
5958 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5960 /* Set up attributes to search VLDB */
5961 attributes.server = ntohl(aserver);
5962 attributes.Mask = VLLIST_SERVER;
5964 attributes.partition = apart;
5965 attributes.Mask |= VLLIST_PARTITION;
5968 VPRINT("Processing VLDB entries ...\n");
5970 /* While we need to collect more VLDB entries */
5971 for (si = 0; si != -1; si = nsi) {
5972 memset(&arrayEntries, 0, sizeof(arrayEntries));
5974 /* Collect set of VLDB entries */
5976 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
5977 &arrayEntries, &nsi);
5978 if (code == RXGEN_OPCODE) {
5979 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
5983 fprintf(STDERR, "Could not access the VLDB for attributes\n");
5986 tentries += nentries;
5988 for (j = 0; j < nentries; j++) {
5989 vlentry = &arrayEntries.nbulkentries_val[j];
5990 MapHostToNetwork(vlentry);
5992 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
5994 code = CheckVldb(vlentry, &modified);
5996 PrintError("", code);
5998 "Could not process VLDB entry for volume %s\n",
6001 } else if (modified) {
6007 fprintf(STDOUT, "...error encountered\n\n");
6009 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6014 if (arrayEntries.nbulkentries_val) {
6015 free(arrayEntries.nbulkentries_val);
6016 arrayEntries.nbulkentries_val = 0;
6020 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6021 failures, modifications);
6025 rx_DestroyConnection(aconn);
6026 if (arrayEntries.nbulkentries_val)
6027 free(arrayEntries.nbulkentries_val);
6030 error = VOLSERFAILEDOP;
6034 /*rename volume <oldname> to <newname>, changing the names of the related
6035 *readonly and backup volumes. This operation is also idempotent.
6036 *salvager is capable of recovering from rename operation stopping halfway.
6037 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6039 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6041 struct nvldbentry storeEntry;
6042 afs_int32 vcode, code, rcode, error;
6044 char nameBuffer[256];
6046 struct rx_connection *aconn;
6050 aconn = (struct rx_connection *)0;
6054 vcode = ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6057 " Could not lock the VLDB entry for the volume %u \n",
6058 entry->volumeId[RWVOL]);
6063 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6064 MapNetworkToHost(entry, &storeEntry);
6065 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6067 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6068 entry->volumeId[RWVOL]);
6072 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6073 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6074 * is concerned, oldname is lost */
6075 if (entry->flags & RW_EXISTS) {
6076 index = Lp_GetRwIndex(entry);
6077 if (index == -1) { /* there is a serious discrepancy */
6079 "There is a serious discrepancy in VLDB entry for volume %u\n",
6080 entry->volumeId[RWVOL]);
6081 fprintf(STDERR, "try building VLDB from scratch\n");
6082 error = VOLSERVLDB_ERROR;
6085 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6087 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6088 entry->serverPartition[index], ITOffline, &tid);
6089 if (code) { /*volume doesnot exist */
6091 "Could not start transaction on the rw volume %u\n",
6092 entry->volumeId[RWVOL]);
6095 } else { /*volume exists, process it */
6098 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6099 entry->volumeId[RWVOL],
6100 entry->volumeId[ROVOL],
6101 entry->volumeId[BACKVOL]);
6103 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6104 code = AFSVolEndTrans(aconn, tid, &rcode);
6108 "Could not end transaction on volume %s %u\n",
6109 entry->name, entry->volumeId[RWVOL]);
6114 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6115 entry->name, entry->volumeId[RWVOL]);
6121 rx_DestroyConnection(aconn);
6122 aconn = (struct rx_connection *)0;
6124 /*end rw volume processing */
6125 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6126 index = Lp_GetRwIndex(entry);
6127 if (index == -1) { /* there is a serious discrepancy */
6129 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6130 entry->volumeId[BACKVOL]);
6131 fprintf(STDERR, "try building VLDB from scratch\n");
6132 error = VOLSERVLDB_ERROR;
6135 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6137 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6138 entry->serverPartition[index], ITOffline, &tid);
6139 if (code) { /*volume doesnot exist */
6141 "Could not start transaction on the backup volume %u\n",
6142 entry->volumeId[BACKVOL]);
6145 } else { /*volume exists, process it */
6146 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6148 "Volume name %s.backup exceeds the limit of %u characters\n",
6149 newname, VOLSER_OLDMAXVOLNAME);
6153 strcpy(nameBuffer, newname);
6154 strcat(nameBuffer, ".backup");
6157 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6158 entry->volumeId[RWVOL], 0, 0);
6160 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6161 code = AFSVolEndTrans(aconn, tid, &rcode);
6165 "Could not end transaction on the backup volume %u\n",
6166 entry->volumeId[BACKVOL]);
6172 "Could not set parameters on the backup volume %u\n",
6173 entry->volumeId[BACKVOL]);
6178 } /* end backup processing */
6180 rx_DestroyConnection(aconn);
6181 aconn = (struct rx_connection *)0;
6182 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6183 for (i = 0; i < entry->nServers; i++) {
6184 if (entry->serverFlags[i] & ITSROVOL) {
6185 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6187 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6188 entry->serverPartition[i], ITOffline,
6190 if (code) { /*volume doesnot exist */
6192 "Could not start transaction on the ro volume %u\n",
6193 entry->volumeId[ROVOL]);
6196 } else { /*volume exists, process it */
6197 strcpy(nameBuffer, newname);
6198 strcat(nameBuffer, ".readonly");
6199 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6201 "Volume name %s exceeds the limit of %u characters\n",
6202 nameBuffer, VOLSER_OLDMAXVOLNAME);
6207 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6208 entry->volumeId[RWVOL], 0, 0);
6210 VPRINT2("Renamed RO volume %s on host %s\n",
6212 hostutil_GetNameByINet(entry->
6214 code = AFSVolEndTrans(aconn, tid, &rcode);
6218 "Could not end transaction on volume %u\n",
6219 entry->volumeId[ROVOL]);
6225 "Could not set parameters on the ro volume %u\n",
6226 entry->volumeId[ROVOL]);
6232 rx_DestroyConnection(aconn);
6233 aconn = (struct rx_connection *)0;
6240 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
6242 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6245 "Could not unlock the VLDB entry for the volume %s %u\n",
6246 entry->name, entry->volumeId[RWVOL]);
6252 code = AFSVolEndTrans(aconn, tid, &rcode);
6256 fprintf(STDERR, "Failed to end transaction on a volume \n");
6262 rx_DestroyConnection(aconn);
6263 PrintError("", error);
6268 /*report on all the active transactions on volser */
6270 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6272 struct rx_connection *aconn;
6273 transDebugEntries transInfo;
6276 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6277 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6278 transInfo.transDebugEntries_len = 0;
6279 code = AFSVolMonitor(aconn, &transInfo);
6282 "Could not access status information about the server\n");
6283 PrintError("", code);
6284 if (transInfo.transDebugEntries_val)
6285 free(transInfo.transDebugEntries_val);
6287 rx_DestroyConnection(aconn);
6290 *rcount = transInfo.transDebugEntries_len;
6291 *rpntr = transInfo.transDebugEntries_val;
6293 rx_DestroyConnection(aconn);
6300 /*delete the volume without interacting with the vldb */
6302 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6304 afs_int32 rcode, ttid, error, code;
6305 struct rx_connection *aconn;
6311 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6312 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6314 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6315 (unsigned long)volid);
6319 code = AFSVolDeleteVolume(aconn, ttid);
6321 fprintf(STDERR, "Could not delete volume %lu\n",
6322 (unsigned long)volid);
6326 code = AFSVolEndTrans(aconn, ttid, &rcode);
6331 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6332 (unsigned long)volid);
6338 code = AFSVolEndTrans(aconn, ttid, &rcode);
6344 PrintError("", error);
6346 rx_DestroyConnection(aconn);
6351 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6352 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6354 struct rx_connection *conn = 0;
6356 afs_int32 code, error = 0, rcode;
6358 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6360 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6364 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6366 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6370 code = AFSVolSetFlags(conn, tid, setflag);
6372 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6377 #ifdef AFS_PTHREAD_ENV
6380 IOMGR_Sleep(sleeptime);
6387 code = AFSVolEndTrans(conn, tid, &rcode);
6388 if (code || rcode) {
6389 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6391 error = (code ? code : rcode);
6396 rx_DestroyConnection(conn);
6401 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6404 struct rx_connection *conn = 0;
6406 afs_int32 code, error = 0, rcode;
6408 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6410 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6414 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6416 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6420 code = AFSVolSetInfo(conn, tid, infop);
6422 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6429 code = AFSVolEndTrans(conn, tid, &rcode);
6430 if (code || rcode) {
6431 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6433 error = (code ? code : rcode);
6438 rx_DestroyConnection(conn);
6443 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6444 afs_int32 fromdate, struct volintSize *vol_size)
6446 struct rx_connection *aconn = (struct rx_connection *)0;
6447 afs_int32 tid = 0, rcode = 0;
6448 afs_int32 code, error = 0;
6451 /* get connections to the servers */
6452 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6454 VPRINT1("Starting transaction on volume %u...", afromvol);
6455 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6456 EGOTO1(error_exit, code,
6457 "Could not start transaction on the volume %u to be measured\n",
6461 VPRINT1("Getting size of volume on volume %u...", afromvol);
6462 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6463 EGOTO(error_exit, code, "Could not start the measurement process \n");
6468 VPRINT1("Ending transaction on volume %u...", afromvol);
6469 code = AFSVolEndTrans(aconn, tid, &rcode);
6470 if (code || rcode) {
6471 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6473 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6475 error = (code ? code : rcode);
6480 rx_DestroyConnection(aconn);
6482 PrintError("", error);
6486 /*maps the host addresses in <old > (present in network byte order) to
6487 that in< new> (present in host byte order )*/
6489 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
6493 /*copy all the fields */
6494 strcpy(new->name, old->name);
6495 /* new->volumeType = old->volumeType;*/
6496 new->nServers = old->nServers;
6497 count = old->nServers;
6498 if (count < NMAXNSERVERS)
6500 for (i = 0; i < count; i++) {
6501 new->serverNumber[i] = ntohl(old->serverNumber[i]);
6502 new->serverPartition[i] = old->serverPartition[i];
6503 new->serverFlags[i] = old->serverFlags[i];
6505 new->volumeId[RWVOL] = old->volumeId[RWVOL];
6506 new->volumeId[ROVOL] = old->volumeId[ROVOL];
6507 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
6508 new->cloneId = old->cloneId;
6509 new->flags = old->flags;
6512 /*maps the host entries in <entry> which are present in host byte order to network byte order */
6514 MapHostToNetwork(struct nvldbentry *entry)
6518 count = entry->nServers;
6519 if (count < NMAXNSERVERS)
6521 for (i = 0; i < count; i++) {
6522 entry->serverNumber[i] = htonl(entry->serverNumber[i]);