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;
1985 fromconn = (struct rx_connection *)0;
1986 toconn = (struct rx_connection *)0;
1994 /* support control-c processing */
1997 (void)signal(SIGINT, sigint_handler);
1999 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2000 EGOTO1(mfail, vcode,
2001 "Could not fetch the entry for the volume %u from the VLDB \n",
2003 MapHostToNetwork(&entry);
2006 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2007 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2008 fromtid = totid = 0; /* initialize to uncreated */
2011 /* check if we can shortcut and use a local clone instead of a full copy */
2012 if (afromserver == atoserver && afrompart == atopart) {
2017 * clone the read/write volume locally.
2020 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2021 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2022 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2026 /* Get a clone id */
2027 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
2029 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &cloneVol);
2030 EGOTO1(mfail, vcode,
2031 "Could not get an ID for the clone of volume %u from the VLDB\n",
2035 /* Get a new volume id */
2036 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2038 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &newVol);
2039 EGOTO1(mfail, vcode,
2040 "Could not get an ID for the copy of volume %u from the VLDB\n",
2044 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2045 VPRINT1("Cloning source volume %u ...", afromvol);
2046 strcpy(vname, "copy-clone-temp");
2048 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &cloneVol);
2049 EGOTO1(mfail, code, "Failed to clone the source volume %u\n", afromvol);
2052 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2054 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2059 "Failed to end the transaction on the source volume %u\n",
2064 * Create the destination volume
2067 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2069 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2072 "Failed to start a transaction on the cloned volume%u\n",
2076 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2077 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
2078 EGOTO1(mfail, code, "Could not set falgs on the cloned volume %u\n",
2082 /* remember time from which we've dumped the volume */
2083 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2084 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2085 EGOTO1(mfail, code, "Failed to get the status of the cloned volume %u\n",
2089 fromDate = tstatus.creationDate - CLOCKSKEW;
2091 /* create a volume on the target machine */
2092 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2094 /* Delete the existing volume.
2095 * While we are deleting the volume in these steps, the transaction
2096 * we started against the cloned volume (clonetid above) will be
2097 * sitting idle. It will get cleaned up after 600 seconds
2099 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2100 code = AFSVolDeleteVolume(toconn, totid);
2102 "Could not delete the pre-existing volume %u on destination\n",
2107 ("Ending transaction on pre-existing volume %u on destination ...",
2109 code = AFSVolEndTrans(toconn, totid, &rcode);
2114 "Could not end the transaction on pre-existing volume %u on destination\n",
2119 VPRINT1("Creating the destination volume %u ...", newVol);
2121 AFSVolCreateVolume(toconn, atopart, atovolname, volser_RW, newVol,
2123 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2127 strncpy(tmpName, atovolname, VOLSER_OLDMAXVOLNAME);
2129 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2131 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2133 "Failed to set the flags on the destination volume %u\n", newVol);
2137 * Now dump the clone to the new volume
2140 destination.destHost = ntohl(atoserver);
2141 destination.destPort = AFSCONF_VOLUMEPORT;
2142 destination.destSSID = 1;
2145 /* probably should have some code here that checks to see if we are copying to same server
2146 and partition - if so, just use a clone to save disk space */
2148 /* Copy the clone to the new volume */
2149 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2151 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
2152 cookie.type = RWVOL;
2155 code = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
2156 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", newVol);
2159 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2160 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2165 "Failed to end the transaction on the cloned volume %u\n",
2170 * reattach to the main-line volume, and incrementally dump it.
2173 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2174 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2176 "Failed to create a transaction on the source volume %u\n",
2180 /* now do the incremental */
2182 ("Doing the incremental dump from source to destination for volume %u ... ",
2185 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2188 "Failed to do the incremental dump from rw volume on old site to rw volume on newsite\n");
2191 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2192 code = AFSVolSetFlags(toconn, totid, 0);
2194 "Failed to set the flags to make destination volume online\n");
2197 /* put new volume online */
2198 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2199 code = AFSVolEndTrans(toconn, totid, &rcode);
2204 "Failed to end the transaction on the destination volume %u\n",
2208 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2209 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2214 "Failed to end the transaction on the source volume %u\n",
2219 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2221 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2224 "Failed to start a transaction on the cloned volume%u\n",
2228 /* now delete the clone */
2229 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2230 code = AFSVolDeleteVolume(fromconn, clonetid);
2231 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n", cloneVol);
2234 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2235 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2240 "Failed to end the transaction on the cloned volume %u\n",
2244 /* create the vldb entry for the copied volume */
2245 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2246 newentry.nServers = 1;
2247 newentry.serverNumber[0] = atoserver;
2248 newentry.serverPartition[0] = atopart;
2249 newentry.flags = RW_EXISTS; /* this records that rw volume exists */
2250 newentry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
2251 newentry.volumeId[RWVOL] = newVol;
2252 newentry.volumeId[ROVOL] = 0;
2253 newentry.volumeId[BACKVOL] = 0;
2254 newentry.cloneId = 0;
2255 /*map into right byte order, before passing to xdr, the stuff has to be in host
2256 * byte order. Xdr converts it into network order */
2257 MapNetworkToHost(&newentry, &storeEntry);
2258 /* create the vldb entry */
2259 vcode = VLDB_CreateEntry(&storeEntry);
2262 "Could not create a VLDB entry for the volume %s %lu\n",
2263 atovolname, (unsigned long)newVol);
2264 /*destroy the created volume */
2265 VPRINT1("Deleting the newly created volume %u\n", newVol);
2266 AFSVolDeleteVolume(toconn, totid);
2270 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2273 /* normal cleanup code */
2276 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2278 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2279 if (code || rcode) {
2282 "Could not end transaction on the source volume %lu\n",
2283 (unsigned long)afromvol);
2285 error = (code ? code : rcode);
2291 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2293 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2294 if (code || rcode) {
2297 "Could not end transaction on the source's clone volume %lu\n",
2298 (unsigned long)cloneVol);
2300 error = (code ? code : rcode);
2306 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2308 code = AFSVolEndTrans(toconn, totid, &rcode);
2312 "Could not end transaction on destination volume %lu\n",
2313 (unsigned long)newVol);
2315 error = (code ? code : rcode);
2320 rx_DestroyConnection(fromconn);
2322 rx_DestroyConnection(toconn);
2323 PrintError("", error);
2326 /* come here only when the sky falls */
2331 "vos copy: operation interrupted, cleanup in progress...\n");
2332 fprintf(STDOUT, "clear transaction contexts\n");
2337 VPRINT("Recovery: Ending transaction on clone volume ...");
2338 AFSVolEndTrans(fromconn, clonetid, &rcode);
2342 VPRINT("Recovery: Ending transaction on destination volume ...");
2343 AFSVolEndTrans(toconn, totid, &rcode);
2346 if (fromtid) { /* put it on-line */
2347 VPRINT("Recovery: Ending transaction on source volume ...");
2348 AFSVolEndTrans(fromconn, fromtid, &rcode);
2352 VPRINT("Recovery: Accessing VLDB.\n");
2353 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2355 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2359 MapHostToNetwork(&entry);
2361 /* common cleanup - delete local clone */
2363 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2366 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
2371 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2372 AFSVolDeleteVolume(fromconn, clonetid);
2375 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2377 AFSVolEndTrans(fromconn, clonetid, &rcode);
2381 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2386 done: /* routine cleanup */
2388 rx_DestroyConnection(fromconn);
2390 rx_DestroyConnection(toconn);
2393 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2403 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2404 * if one already exists, update it
2408 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2410 struct rx_connection *aconn = (struct rx_connection *)0;
2411 afs_int32 ttid = 0, btid = 0;
2413 afs_int32 code = 0, rcode = 0;
2414 char vname[VOLSER_MAXVOLNAME + 1];
2415 struct nvldbentry entry, storeEntry;
2416 afs_int32 error = 0;
2417 int vldblocked = 0, vldbmod = 0, backexists = 1;
2419 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2421 /* the calls to VLDB will succeed only if avolid is a RW volume,
2422 * since we are following the RW hash chain for searching */
2423 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2426 "Could not fetch the entry for the volume %lu from the VLDB \n",
2427 (unsigned long)avolid);
2431 MapHostToNetwork(&entry);
2433 /* These operations require the VLDB be locked since it means the VLDB
2434 * will change or the vldb is already locked.
2436 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2437 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2438 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2440 code = ubik_Call(VL_SetLock, cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2443 "Could not lock the VLDB entry for the volume %lu\n",
2444 (unsigned long)avolid);
2450 /* Reread the vldb entry */
2451 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2454 "Could not fetch the entry for the volume %lu from the VLDB \n",
2455 (unsigned long)avolid);
2459 MapHostToNetwork(&entry);
2462 if (!ISNAMEVALID(entry.name)) {
2463 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2465 error = VOLSERBADNAME;
2469 backupID = entry.volumeId[BACKVOL];
2470 if (backupID == INVALID_BID) {
2471 /* Get a backup volume id from the VLDB and update the vldb
2474 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &backupID);
2477 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2478 (unsigned long)avolid);
2482 entry.volumeId[BACKVOL] = backupID;
2486 /* Test to see if the backup volume exists by trying to create
2487 * a transaction on the backup volume. We've assumed the backup exists.
2489 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2491 if (code != VNOVOL) {
2492 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2493 (unsigned long)backupID);
2497 backexists = 0; /* backup volume does not exist */
2500 code = AFSVolEndTrans(aconn, btid, &rcode);
2502 if (code || rcode) {
2504 "Could not end transaction on the previous backup volume %lu\n",
2505 (unsigned long)backupID);
2506 error = (code ? code : rcode);
2511 /* Now go ahead and try to clone the RW volume.
2512 * First start a transaction on the RW volume
2514 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2516 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2517 (unsigned long)avolid);
2522 /* Clone or reclone the volume, depending on whether the backup
2523 * volume exists or not
2526 VPRINT1("Re-cloning backup volume %u ...", backupID);
2528 code = AFSVolReClone(aconn, ttid, backupID);
2530 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2531 (unsigned long)backupID);
2536 VPRINT1("Creating a new backup clone %u ...", backupID);
2538 strcpy(vname, entry.name);
2539 strcat(vname, ".backup");
2541 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2543 fprintf(STDERR, "Failed to clone the volume %lu\n",
2544 (unsigned long)avolid);
2550 /* End the transaction on the RW volume */
2551 code = AFSVolEndTrans(aconn, ttid, &rcode);
2553 if (code || rcode) {
2555 "Failed to end the transaction on the rw volume %lu\n",
2556 (unsigned long)avolid);
2557 error = (code ? code : rcode);
2561 /* Mork vldb as backup exists */
2562 if (!(entry.flags & BACK_EXISTS)) {
2563 entry.flags |= BACK_EXISTS;
2567 /* Now go back to the backup volume and bring it on line */
2568 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2571 "Failed to start a transaction on the backup volume %lu\n",
2572 (unsigned long)backupID);
2577 code = AFSVolSetFlags(aconn, btid, 0);
2579 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2580 (unsigned long)backupID);
2585 code = AFSVolEndTrans(aconn, btid, &rcode);
2587 if (code || rcode) {
2589 "Failed to end the transaction on the backup volume %lu\n",
2590 (unsigned long)backupID);
2591 error = (code ? code : rcode);
2597 /* Will update the vldb below */
2601 code = AFSVolEndTrans(aconn, ttid, &rcode);
2602 if (code || rcode) {
2603 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2604 (unsigned long)avolid);
2606 error = (code ? code : rcode);
2611 code = AFSVolEndTrans(aconn, btid, &rcode);
2612 if (code || rcode) {
2614 "Could not end transaction the backup volume %lu\n",
2615 (unsigned long)backupID);
2617 error = (code ? code : rcode);
2621 /* Now update the vldb - if modified */
2624 MapNetworkToHost(&entry, &storeEntry);
2626 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2627 (LOCKREL_OPCODE | LOCKREL_AFSID |
2628 LOCKREL_TIMESTAMP));
2631 "Could not update the VLDB entry for the volume %lu \n",
2632 (unsigned long)avolid);
2638 ubik_Call(VL_ReleaseLock, cstruct, 0, avolid, RWVOL,
2639 (LOCKREL_OPCODE | LOCKREL_AFSID |
2640 LOCKREL_TIMESTAMP));
2643 "Could not unlock the VLDB entry for the volume %lu \n",
2644 (unsigned long)avolid);
2652 rx_DestroyConnection(aconn);
2654 PrintError("", error);
2659 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2662 afs_int32 acode, ccode, rcode, tid;
2663 ccode = rcode = tid = 0;
2665 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2666 if (!acode) { /* It really was there */
2667 acode = AFSVolDeleteVolume(conn, tid);
2669 fprintf(STDERR, "Failed to delete volume %lu.\n",
2670 (unsigned long)vid);
2671 PrintError("", acode);
2673 ccode = AFSVolEndTrans(conn, tid, &rcode);
2677 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
2678 (unsigned long)vid);
2679 PrintError("", ccode);
2686 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
2687 #define ERROREXIT(ec) { error = (ec); goto rfail; }
2689 /* Get a "transaction" on this replica. Create the volume
2690 * if necessary. Return the time from which a dump should
2691 * be made (0 if it's a new volume)
2694 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
2695 struct rx_connection **connPtr, afs_int32 * transPtr,
2696 afs_int32 * timePtr)
2699 struct volser_status tstatus;
2700 int code, rcode, tcode;
2702 *connPtr = (struct rx_connection *)0;
2706 /* get connection to the replication site */
2707 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
2709 goto fail; /* server is down */
2711 volid = vldbEntryPtr->volumeId[ROVOL];
2714 AFSVolTransCreate(*connPtr, volid,
2715 vldbEntryPtr->serverPartition[index], ITOffline,
2718 /* If the volume does not exist, create it */
2719 if (!volid || code) {
2722 if (volid && (code != VNOVOL)) {
2723 PrintError("Failed to start a transaction on the RO volume.\n",
2728 strcpy(volname, vldbEntryPtr->name);
2729 strcat(volname, ".readonly");
2733 "Creating new volume %lu on replication site %s: ",
2734 (unsigned long)volid,
2735 hostutil_GetNameByINet(vldbEntryPtr->
2736 serverNumber[index]));
2741 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
2743 vldbEntryPtr->volumeId[RWVOL], &volid,
2746 PrintError("Failed to create the ro volume: ", code);
2749 vldbEntryPtr->volumeId[ROVOL] = volid;
2753 /* The following is a bit redundant, since create sets these flags by default */
2755 AFSVolSetFlags(*connPtr, *transPtr,
2756 VTDeleteOnSalvage | VTOutOfService);
2758 PrintError("Failed to set flags on the ro volume: ", code);
2763 /* Otherwise, the transaction did succeed, so get the creation date of the
2764 * latest RO volume on the replication site
2767 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
2768 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
2770 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
2772 PrintError("Failed to get status of volume on destination: ",
2776 *timePtr = tstatus.creationDate - CLOCKSKEW;
2783 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
2788 PrintError("Could not end transaction on a ro volume: ", tcode);
2795 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
2796 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
2797 void *cookie, manyResults * results)
2801 for (i = 0; i < tr->manyDests_len; i++) {
2802 results->manyResults_val[i] =
2803 AFSVolForward(fromconn, fromtid, fromdate,
2804 &(tr->manyDests_val[i].server),
2805 tr->manyDests_val[i].trans, cookie);
2812 rel_compar(struct release *r1, struct release *r2)
2814 return (r1->time - r2->time);
2817 /* UV_ReleaseVolume()
2818 * Release volume <afromvol> on <afromserver> <afrompart> to all
2819 * its RO sites (full release). Unless the previous release was
2820 * incomplete: in which case we bring the remaining incomplete
2821 * volumes up to date with the volumes that were released
2823 * forceflag: Performs a full release.
2825 * Will create a clone from the RW, then dump the clone out to
2826 * the remaining replicas. If there is more than 1 RO sites,
2827 * ensure that the VLDB says at least one RO is available all
2828 * the time: Influences when we write back the VLDB entry.
2832 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
2833 afs_int32 afrompart, int forceflag)
2836 afs_int32 code, vcode, rcode, tcode;
2837 afs_int32 cloneVolId, roVolId;
2838 struct replica *replicas = 0;
2839 struct nvldbentry entry, storeEntry;
2840 int i, volcount, m, fullrelease, vldbindex;
2842 struct restoreCookie cookie;
2843 struct rx_connection **toconns = 0;
2844 struct release *times = 0;
2846 struct rx_connection *fromconn = (struct rx_connection *)0;
2847 afs_int32 error = 0;
2849 afs_int32 clonetid = 0, onlinetid;
2850 afs_int32 fromtid = 0;
2851 afs_uint32 fromdate, thisdate;
2854 manyResults results;
2855 int rwindex, roindex, roclone, roexists;
2856 afs_int32 rwcrdate, clcrdate;
2860 } remembertime[NMAXNSERVERS];
2861 int releasecount = 0;
2862 struct volser_status volstatus;
2864 memset((char *)remembertime, 0, sizeof(remembertime));
2865 memset((char *)&results, 0, sizeof(results));
2867 vcode = ubik_Call(VL_SetLock, cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
2868 if (vcode != VL_RERELEASE)
2869 ONERROR(vcode, afromvol,
2870 "Could not lock the VLDB entry for the volume %u.\n");
2873 /* Get the vldb entry in readable format */
2874 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
2875 ONERROR(vcode, afromvol,
2876 "Could not fetch the entry for the volume %u from the VLDB.\n");
2877 MapHostToNetwork(&entry);
2880 EnumerateEntry(&entry);
2882 if (!ISNAMEVALID(entry.name))
2883 ONERROR(VOLSERBADOP, entry.name,
2884 "Volume name %s is too long, rename before releasing.\n");
2885 if (entry.volumeId[RWVOL] != afromvol)
2886 ONERROR(VOLSERBADOP, afromvol,
2887 "The volume %u being released is not a read-write volume.\n");
2888 if (entry.nServers <= 1)
2889 ONERROR(VOLSERBADOP, afromvol,
2890 "Volume %u has no replicas - release operation is meaningless!\n");
2891 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
2892 ONERROR(VOLSERBADOP, entry.name,
2893 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
2895 /* roclone is true if one of the RO volumes is on the same
2896 * partition as the RW volume. In this case, we make the RO volume
2897 * on the same partition a clone instead of a complete copy.
2900 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
2901 roclone = ((roindex == -1) ? 0 : 1);
2902 rwindex = Lp_GetRwIndex(&entry);
2904 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
2906 /* Make sure we have a RO volume id to work with */
2907 if (entry.volumeId[ROVOL] == INVALID_BID) {
2908 /* need to get a new RO volume id */
2909 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &roVolId);
2910 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
2912 entry.volumeId[ROVOL] = roVolId;
2913 MapNetworkToHost(&entry, &storeEntry);
2914 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
2915 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
2918 /* Will we be completing a previously unfinished release. -force overrides */
2919 for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) {
2920 if (entry.serverFlags[i] & NEW_REPSITE)
2923 if (forceflag && !fullrelease)
2926 /* Determine which volume id to use and see if it exists */
2929 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
2930 code = VolumeExists(afromserver, afrompart, cloneVolId);
2931 roexists = ((code == ENODEV) ? 0 : 1);
2933 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2935 ONERROR(-1, afromserver,
2936 "Cannot establish connection with server 0x%x\n");
2940 fullrelease = 1; /* Do a full release if RO clone does not exist */
2942 /* Begin transaction on RW and mark it busy while we query it */
2943 code = AFSVolTransCreate(
2944 fromconn, afromvol, afrompart, ITBusy, &fromtid
2946 ONERROR(code, afromvol,
2947 "Failed to start transaction on RW volume %u\n");
2949 /* Query the creation date for the RW */
2950 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
2951 ONERROR(code, afromvol,
2952 "Failed to get the status of RW volume %u\n");
2953 rwcrdate = volstatus.creationDate;
2955 /* End transaction on RW */
2956 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2958 ONERROR((code ? code : rcode), afromvol,
2959 "Failed to end transaction on RW volume %u\n");
2961 /* Begin transaction on clone and mark it busy while we query it */
2962 code = AFSVolTransCreate(
2963 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
2965 ONERROR(code, cloneVolId,
2966 "Failed to start transaction on RW clone %u\n");
2968 /* Query the creation date for the clone */
2969 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
2970 ONERROR(code, cloneVolId,
2971 "Failed to get the status of RW clone %u\n");
2972 clcrdate = volstatus.creationDate;
2974 /* End transaction on RW */
2975 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2977 ONERROR((code ? code : rcode), cloneVolId,
2978 "Failed to end transaction on RW volume %u\n");
2980 if (rwcrdate > clcrdate)
2981 fullrelease = 2;/* Do a full release if RO clone older than RW */
2986 switch (fullrelease) {
2988 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
2989 (unsigned long)afromvol);
2992 fprintf(STDOUT, "This is a complete release of volume %lu\n",
2993 (unsigned long)afromvol);
2996 fprintf(STDOUT, "This is a completion of a previous release\n");
3002 /* If the RO clone exists, then if the clone is a temporary
3003 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3004 * (it was recently added), then also delete it. We do not
3005 * want to "reclone" a temporary RO clone.
3008 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3009 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3010 if (code && (code != VNOVOL))
3015 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3016 * write this entry out to the vlserver until after the first
3017 * RO volume is released (temp RO clones don't count).
3019 for (i = 0; i < entry.nServers; i++) {
3020 entry.serverFlags[i] &= ~NEW_REPSITE;
3021 entry.serverFlags[i] |= RO_DONTUSE;
3023 entry.serverFlags[rwindex] |= NEW_REPSITE;
3024 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3026 /* Begin transaction on RW and mark it busy while we clone it */
3028 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3030 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3032 /* Clone or reclone the volume */
3034 VPRINT1("Recloning RW volume %u...", cloneVolId);
3035 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3036 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3040 strcpy(vname, entry.name);
3041 strcat(vname, ".readonly");
3042 VPRINT("Cloning RW volume %u to permanent RO...");
3044 strcpy(vname, "readonly-clone-temp");
3045 VPRINT("Cloning RW volume %u to temporary RO...");
3048 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3050 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3054 /* Get the time the RW was created for future information */
3055 VPRINT1("Getting status of RW volume %u...", cloneVolId);
3056 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3057 ONERROR(code, cloneVolId,
3058 "Failed to get the status of the RW volume %u\n");
3060 rwcrdate = volstatus.creationDate;
3062 /* End the transaction on the RW volume */
3063 VPRINT1("Ending cloning transaction on RW volume %u...", cloneVolId);
3064 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3066 ONERROR((code ? code : rcode), cloneVolId,
3067 "Failed to end cloning transaction on RW %u\n");
3070 /* Remember clone volume ID in case we fail or are interrupted */
3071 entry.cloneId = cloneVolId;
3074 /* Bring the RO clone online - though not if it's a temporary clone */
3075 VPRINT1("Starting transaction on RO clone volume %u...",
3078 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3080 ONERROR(code, cloneVolId,
3081 "Failed to start transaction on volume %u\n");
3084 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3085 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3088 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3089 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3090 ONERROR((code ? code : rcode), cloneVolId,
3091 "Failed to end transaction on RO clone %u\n");
3094 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3096 /* Sleep so that a client searching for an online volume won't
3097 * find the clone offline and then the next RO offline while the
3098 * release brings the clone online and the next RO offline (race).
3099 * There is a fix in the 3.4 client that does not need this sleep
3100 * anymore, but we don't know what clients we have.
3102 if (entry.nServers > 2)
3105 /* Mark the RO clone in the VLDB as a good site (already released) */
3106 entry.serverFlags[roindex] |= NEW_REPSITE;
3107 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3108 entry.flags |= RO_EXISTS;
3112 /* Write out the VLDB entry only if the clone is not a temporary
3113 * clone. If we did this to a temporary clone then we would end
3114 * up marking all the ROs as "old release" making the ROs
3115 * temporarily unavailable.
3117 MapNetworkToHost(&entry, &storeEntry);
3118 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3119 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3120 ONERROR(vcode, entry.name,
3121 "Could not update vldb entry for %s.\n");
3126 /* Now we will release from the clone to the remaining RO replicas.
3127 * The first 2 ROs (counting the non-temporary RO clone) are released
3128 * individually: releasecount. This is to reduce the race condition
3129 * of clients trying to find an on-line RO volume. The remaining ROs
3130 * are released in parallel but no more than half the number of ROs
3131 * (rounded up) at a time: nservers.
3134 strcpy(vname, entry.name);
3135 strcat(vname, ".readonly");
3136 memset(&cookie, 0, sizeof(cookie));
3137 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3138 cookie.type = ROVOL;
3139 cookie.parent = entry.volumeId[RWVOL];
3142 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3144 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3145 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3147 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3149 results.manyResults_val =
3150 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3151 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3153 "Failed to create transaction on the release clone\n");
3155 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3156 memset(times, 0, (sizeof(struct release) * nservers + 1));
3157 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3158 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3160 /* Create a transaction on the cloned volume */
3161 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3163 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3164 if (!fullrelease && code)
3165 ONERROR(VOLSERNOVOL, afromvol,
3166 "Old clone is inaccessible. Try vos release -f %u.\n");
3167 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3170 /* For each index in the VLDB */
3171 for (vldbindex = 0; vldbindex < entry.nServers;) {
3173 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3175 ((volcount < nservers) && (vldbindex < entry.nServers));
3177 /* The first two RO volumes will be released individually.
3178 * The rest are then released in parallel. This is a hack
3179 * for clients not recognizing right away when a RO volume
3180 * comes back on-line.
3182 if ((volcount == 1) && (releasecount < 2))
3185 if (vldbindex == roindex)
3186 continue; /* the clone */
3187 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3188 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3190 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3191 continue; /* not a RO vol */
3194 /* Get a Transaction on this replica. Get a new connection if
3195 * necessary. Create the volume if necessary. Return the
3196 * time from which the dump should be made (0 if it's a new
3197 * volume). Each volume might have a different time.
3199 replicas[volcount].server.destHost =
3200 ntohl(entry.serverNumber[vldbindex]);
3201 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3202 replicas[volcount].server.destSSID = 1;
3203 times[volcount].vldbEntryIndex = vldbindex;
3206 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3207 &(replicas[volcount].trans),
3208 &(times[volcount].time));
3212 /* Thisdate is the date from which we want to pick up all changes */
3213 if (forceflag || !fullrelease
3214 || (rwcrdate > times[volcount].time)) {
3215 /* If the forceflag is set, then we want to do a full dump.
3216 * If it's not a full release, we can't be sure that the creation
3217 * date is good (so we also do a full dump).
3218 * If the RW volume was replaced (its creation date is newer than
3219 * the last release), then we can't be sure what has changed (so
3220 * we do a full dump).
3223 } else if (remembertime[vldbindex].validtime) {
3224 /* Trans was prev ended. Use the time from the prev trans
3225 * because, prev trans may have created the volume. In which
3226 * case time[volcount].time would be now instead of 0.
3229 (remembertime[vldbindex].time <
3230 times[volcount].time) ? remembertime[vldbindex].
3231 time : times[volcount].time;
3233 thisdate = times[volcount].time;
3235 remembertime[vldbindex].validtime = 1;
3236 remembertime[vldbindex].time = thisdate;
3238 if (volcount == 0) {
3239 fromdate = thisdate;
3241 /* Include this volume if it is within 15 minutes of the earliest */
3243 thisdate) ? (fromdate - thisdate) : (thisdate -
3245 AFSVolEndTrans(toconns[volcount],
3246 replicas[volcount].trans, &rcode);
3247 replicas[volcount].trans = 0;
3250 if (thisdate < fromdate)
3251 fromdate = thisdate;
3259 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3260 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3261 hostutil_GetNameByINet(entry.
3262 serverNumber[times[0].
3265 for (s = 1; s < volcount; s++) {
3266 fprintf(STDOUT, " and %s",
3267 hostutil_GetNameByINet(entry.
3268 serverNumber[times[s].
3273 fprintf(STDOUT, " (full release)");
3274 fprintf(STDOUT, ".\n");
3278 /* Release the ones we have collected */
3279 tr.manyDests_val = &(replicas[0]);
3280 tr.manyDests_len = results.manyResults_len = volcount;
3282 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3283 0 /*spare */ , &cookie, &results);
3284 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3286 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3287 0 /*spare */ , &cookie, &results);
3292 PrintError("Release failed: ", code);
3294 for (m = 0; m < volcount; m++) {
3295 if (results.manyResults_val[m]) {
3296 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3297 /* we retry timed out transaction. When it is
3298 * not the first volume and the transaction wasn't found
3299 * (assume it timed out and was garbage collected by volser).
3302 ("Failed to dump volume from clone to a ro site: ",
3303 results.manyResults_val[m]);
3309 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3310 ROVOL, entry.volumeId[RWVOL], 0, 0);
3312 if ((m == 0) || (code != ENOENT)) {
3313 PrintError("Failed to set correct names and ids: ",
3319 /* have to clear dest. flags to ensure new vol goes online:
3320 * because the restore (forwarded) operation copied
3321 * the V_inService(=0) flag over to the destination.
3323 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3325 if ((m == 0) || (code != ENOENT)) {
3326 PrintError("Failed to set flags on ro volume: ",
3332 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3333 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3334 entry.flags |= RO_EXISTS;
3339 /* End the transactions and destroy the connections */
3340 for (s = 0; s < volcount; s++) {
3341 if (replicas[s].trans)
3342 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3343 replicas[s].trans = 0;
3347 if ((s == 0) || (code != ENOENT)) {
3348 PrintError("Could not end transaction on a ro volume: ",
3352 ("Transaction timed out on a ro volume. Will retry.\n",
3354 if (times[s].vldbEntryIndex < vldbindex)
3355 vldbindex = times[s].vldbEntryIndex;
3360 rx_DestroyConnection(toconns[s]);
3364 MapNetworkToHost(&entry, &storeEntry);
3365 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3366 ONERROR(vcode, afromvol,
3367 " Could not update VLDB entry for volume %u\n");
3368 } /* for each index in the vldb */
3370 /* End the transaction on the cloned volume */
3371 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3376 PrintError("Failed to end transaction on rw volume: ", code);
3378 /* Figure out if any volume were not released and say so */
3379 for (failure = 0, i = 0; i < entry.nServers; i++) {
3380 if (!(entry.serverFlags[i] & NEW_REPSITE))
3386 "The volume %lu could not be released to the following %d sites:\n",
3387 (unsigned long)afromvol, failure);
3388 for (i = 0; i < entry.nServers; i++) {
3389 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3390 MapPartIdIntoName(entry.serverPartition[i], pname);
3391 fprintf(STDERR, "\t%35s %s\n",
3392 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3396 MapNetworkToHost(&entry, &storeEntry);
3398 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3400 ONERROR(vcode, afromvol,
3401 " Could not update VLDB entry for volume %u\n");
3403 ERROREXIT(VOLSERBADRELEASE);
3406 /* All the ROs were release successfully. Remove the temporary clone */
3409 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3410 (unsigned long)cloneVolId);
3413 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3414 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3419 for (i = 0; i < entry.nServers; i++)
3420 entry.serverFlags[i] &= ~NEW_REPSITE;
3422 /* Update the VLDB */
3423 VPRINT("updating VLDB ...");
3425 MapNetworkToHost(&entry, &storeEntry);
3427 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3428 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3429 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3434 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3438 "Failed to end cloning transaction on the RW volume %lu\n",
3439 (unsigned long)afromvol);
3445 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3449 "Failed to end transaction on the release clone %lu\n",
3450 (unsigned long)cloneVolId);
3455 for (i = 0; i < nservers; i++) {
3456 if (replicas && replicas[i].trans) {
3457 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3458 replicas[i].trans = 0;
3461 "Failed to end transaction on ro volume %u at server %s\n",
3462 entry.volumeId[ROVOL],
3463 hostutil_GetNameByINet(htonl
3464 (replicas[i].server.
3470 if (toconns && toconns[i]) {
3471 rx_DestroyConnection(toconns[i]);
3477 ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, RWVOL,
3478 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3481 "Could not release lock on the VLDB entry for volume %lu\n",
3482 (unsigned long)afromvol);
3488 PrintError("", error);
3491 rx_DestroyConnection(fromconn);
3492 if (results.manyResults_val)
3493 free(results.manyResults_val);
3505 dump_sig_handler(int x)
3507 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3511 /* Dump the volume <afromvol> on <afromserver> and
3512 * <afrompart> to <afilename> starting from <fromdate>.
3513 * DumpFunction does the real work behind the scenes after
3514 * extracting parameters from the rock
3517 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3518 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock)
3520 struct rx_connection *fromconn = (struct rx_connection *)0;
3521 struct rx_call *fromcall = (struct rx_call *)0;
3522 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3523 afs_int32 code, error = 0;
3527 #ifndef AFS_NT40_ENV
3528 (void)signal(SIGPIPE, dump_sig_handler);
3530 (void)signal(SIGINT, dump_sig_handler);
3533 VPRINT("Full Dump ...\n");
3535 VPRINT1("Incremental Dump (as of %.24s)...\n",
3536 ctime((time_t *) & fromdate));
3539 /* get connections to the servers */
3540 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3542 VPRINT1("Starting transaction on volume %u...", afromvol);
3543 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3544 EGOTO1(error_exit, code,
3545 "Could not start transaction on the volume %u to be dumped\n",
3549 fromcall = rx_NewCall(fromconn);
3551 VPRINT1("Starting volume dump on volume %u...", afromvol);
3552 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3553 EGOTO(error_exit, code, "Could not start the dump process \n");
3556 VPRINT1("Dumping volume %u...", afromvol);
3557 code = DumpFunction(fromcall, rock);
3558 EGOTO(error_exit, code, "Error while dumping volume \n");
3563 code = rx_EndCall(fromcall, rxError);
3565 fprintf(STDERR, "Error in rx_EndCall\n");
3571 VPRINT1("Ending transaction on volume %u...", afromvol);
3572 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3573 if (code || rcode) {
3574 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3575 (unsigned long)afromvol);
3577 error = (code ? code : rcode);
3582 rx_DestroyConnection(fromconn);
3584 PrintError("", error);
3588 /* Clone the volume <afromvol> on <afromserver> and
3589 * <afrompart>, and then dump the clone volume to
3590 * <afilename> starting from <fromdate>.
3591 * DumpFunction does the real work behind the scenes after
3592 * extracting parameters from the rock
3595 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3596 afs_int32 afrompart, afs_int32 fromdate,
3597 afs_int32(*DumpFunction) (), char *rock)
3599 struct rx_connection *fromconn = (struct rx_connection *)0;
3600 struct rx_call *fromcall = (struct rx_call *)0;
3601 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3602 afs_int32 clonetid = 0;
3603 afs_int32 code = 0, vcode = 0, error = 0;
3604 afs_int32 clonevol = 0;
3609 #ifndef AFS_NT40_ENV
3610 (void)signal(SIGPIPE, dump_sig_handler);
3612 (void)signal(SIGINT, dump_sig_handler);
3615 VPRINT("Full Dump ...\n");
3617 VPRINT1("Incremental Dump (as of %.24s)...\n",
3618 ctime((time_t *) & fromdate));
3621 /* get connections to the servers */
3622 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3624 VPRINT1("Starting transaction on volume %u...", afromvol);
3625 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3626 EGOTO1(error_exit, code,
3627 "Could not start transaction on the volume %u to be dumped\n",
3631 /* Get a clone id */
3632 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3633 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &clonevol);
3634 EGOTO1(error_exit, code,
3635 "Could not get an ID for the clone of volume %u from the VLDB\n",
3639 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3640 VPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3642 strcpy(vname, "dump-clone-temp");
3644 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3645 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3649 VPRINT1("Ending the transaction on the volume %u ...", afromvol);
3651 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3655 EGOTO1(error_exit, code,
3656 "Failed to end the transaction on the volume %u\n", afromvol);
3660 VPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
3662 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
3664 EGOTO1(error_exit, code,
3665 "Failed to start a transaction on the cloned volume%u\n",
3669 VPRINT1("Setting flags on cloned volume %u ...", clonevol);
3670 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
3671 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
3676 fromcall = rx_NewCall(fromconn);
3678 VPRINT1("Starting volume dump from cloned volume %u...", clonevol);
3679 code = StartAFSVolDump(fromcall, clonetid, fromdate);
3680 EGOTO(error_exit, code, "Could not start the dump process \n");
3683 VPRINT1("Dumping volume %u...", afromvol);
3684 code = DumpFunction(fromcall, rock);
3685 EGOTO(error_exit, code, "Error while dumping volume \n");
3689 /* now delete the clone */
3690 VPRINT1("Deleting the cloned volume %u ...", clonevol);
3691 code = AFSVolDeleteVolume(fromconn, clonetid);
3693 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
3694 (unsigned long)clonevol);
3700 code = rx_EndCall(fromcall, rxError);
3702 fprintf(STDERR, "Error in rx_EndCall\n");
3708 VPRINT1("Ending transaction on cloned volume %u...", clonevol);
3709 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3710 if (code || rcode) {
3712 "Could not end transaction on the cloned volume %lu\n",
3713 (unsigned long)clonevol);
3715 error = (code ? code : rcode);
3720 rx_DestroyConnection(fromconn);
3722 PrintError("", error);
3729 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
3730 * the dump file <afilename>. WriteData does all the real work
3731 * after extracting params from the rock
3734 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
3735 char tovolname[], int flags, afs_int32(*WriteData) (),
3738 struct rx_connection *toconn, *tempconn;
3739 struct rx_call *tocall;
3740 afs_int32 totid, code, rcode, vcode, terror = 0;
3741 afs_int32 rxError = 0;
3742 struct volser_status tstatus;
3747 struct nvldbentry entry, storeEntry;
3750 struct restoreCookie cookie;
3752 afs_int32 newDate, volflag, voltype, volsertype;
3753 int index, same, errcode;
3757 memset(&cookie, 0, sizeof(cookie));
3762 tocall = (struct rx_call *)0;
3763 toconn = (struct rx_connection *)0;
3764 tempconn = (struct rx_connection *)0;
3768 if (flags & RV_RDONLY) {
3770 volsertype = volser_RO;
3773 volsertype = volser_RW;
3777 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
3778 if (pvolid == 0) { /*alot a new id if needed */
3779 vcode = VLDB_GetEntryByName(tovolname, &entry);
3780 if (vcode == VL_NOENT) {
3781 vcode = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 1, &pvolid);
3783 fprintf(STDERR, "Could not get an Id for the volume %s\n",
3789 } else if (flags & RV_RDONLY) {
3790 if (entry.flags & RW_EXISTS) {
3792 "Entry for ReadWrite volume %s already exists!\n",
3794 error = VOLSERBADOP;
3797 if (!entry.volumeId[ROVOL]) {
3799 "Existing entry for volume %s has no ReadOnly ID\n",
3801 error = VOLSERBADOP;
3804 pvolid = entry.volumeId[ROVOL];
3806 pvolid = entry.volumeId[RWVOL];
3809 /* at this point we have a volume id to use/reuse for the volume to be restored */
3810 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
3811 EGOTO1(refail, VOLSERBADOP,
3812 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
3815 MapPartIdIntoName(topart, partName);
3816 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
3817 tovolname, (unsigned long)pvolid,
3818 hostutil_GetNameByINet(toserver), partName);
3821 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0, &pvolid,
3824 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
3825 VPRINT1("Deleting the previous volume %u ...", pvolid);
3828 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
3829 EGOTO1(refail, code, "Failed to start transaction on %u\n",
3833 AFSVolSetFlags(toconn, totid,
3834 VTDeleteOnSalvage | VTOutOfService);
3835 EGOTO1(refail, code, "Could not set flags on volume %u \n",
3838 code = AFSVolDeleteVolume(toconn, totid);
3839 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
3841 code = AFSVolEndTrans(toconn, totid, &rcode);
3845 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
3850 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0,
3852 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
3857 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
3858 EGOTO1(refail, code, "Failed to start transaction on %u\n",
3861 code = AFSVolGetStatus(toconn, totid, &tstatus);
3862 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
3864 newDate = tstatus.creationDate;
3867 cookie.parent = pvolid;
3868 cookie.type = voltype;
3870 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
3872 tocall = rx_NewCall(toconn);
3873 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
3875 fprintf(STDERR, "Volume restore Failed \n");
3879 code = WriteData(tocall, rock);
3881 fprintf(STDERR, "Could not transmit data\n");
3885 terror = rx_EndCall(tocall, rxError);
3886 tocall = (struct rx_call *)0;
3888 fprintf(STDERR, "rx_EndCall Failed \n");
3892 code = AFSVolGetStatus(toconn, totid, &tstatus);
3895 "Could not get status information about the volume %lu\n",
3896 (unsigned long)pvolid);
3900 code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pvolid, 0, 0);
3902 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
3903 (unsigned long)pvolid);
3909 code = AFSVolSetDate(toconn, totid, newDate);
3911 fprintf(STDERR, "Could not set the date on %lu\n",
3912 (unsigned long)pvolid);
3917 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
3918 code = AFSVolSetFlags(toconn, totid, volflag);
3920 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
3925 /* It isn't handled right in refail */
3926 code = AFSVolEndTrans(toconn, totid, &rcode);
3931 fprintf(STDERR, "Could not end transaction on %lu\n",
3932 (unsigned long)pvolid);
3938 fprintf(STDOUT, " done\n");
3940 if (success && (!reuseID || (flags & RV_FULLRST))) {
3941 /* Volume was restored on the file server, update the
3942 * VLDB to reflect the change.
3944 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
3945 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
3947 "Could not fetch the entry for volume number %lu from VLDB \n",
3948 (unsigned long)pvolid);
3953 MapHostToNetwork(&entry);
3954 if (vcode == VL_NOENT) { /* it doesnot exist already */
3955 /*make the vldb return this indication specifically */
3956 VPRINT("------- Creating a new VLDB entry ------- \n");
3957 strcpy(entry.name, tovolname);
3959 entry.serverNumber[0] = toserver; /*should be indirect */
3960 entry.serverPartition[0] = topart;
3961 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
3962 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
3963 if (flags & RV_RDONLY)
3964 entry.volumeId[ROVOL] = pvolid;
3965 else if (tstatus.cloneID != 0) {
3966 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
3968 entry.volumeId[ROVOL] = INVALID_BID;
3969 entry.volumeId[RWVOL] = pvolid;
3971 if (tstatus.backupID != 0) {
3972 entry.volumeId[BACKVOL] = tstatus.backupID;
3973 /*this should come from status info on the volume if non zero */
3975 entry.volumeId[BACKVOL] = INVALID_BID;
3976 MapNetworkToHost(&entry, &storeEntry);
3977 vcode = VLDB_CreateEntry(&storeEntry);
3980 "Could not create the VLDB entry for volume number %lu \n",
3981 (unsigned long)pvolid);
3987 EnumerateEntry(&entry);
3988 } else { /*update the existing entry */
3990 fprintf(STDOUT, "Updating the existing VLDB entry\n");
3991 fprintf(STDOUT, "------- Old entry -------\n");
3992 EnumerateEntry(&entry);
3993 fprintf(STDOUT, "------- New entry -------\n");
3996 ubik_Call(VL_SetLock, cstruct, 0, pvolid, voltype,
4000 "Could not lock the entry for volume number %lu \n",
4001 (unsigned long)pvolid);
4006 strcpy(entry.name, tovolname);
4008 /* Update the vlentry with the new information */
4009 if (flags & RV_RDONLY)
4010 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4012 index = Lp_GetRwIndex(&entry);
4014 /* Add the new site for the volume being restored */
4015 entry.serverNumber[entry.nServers] = toserver;
4016 entry.serverPartition[entry.nServers] = topart;
4017 entry.serverFlags[entry.nServers] =
4018 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4021 /* This volume should be deleted on the old site
4022 * if its different from new site.
4025 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4028 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4030 if ((!errcode && !same)
4031 || (entry.serverPartition[index] != topart)) {
4033 UV_Bind(entry.serverNumber[index],
4034 AFSCONF_VOLUMEPORT);
4036 MapPartIdIntoName(entry.serverPartition[index],
4039 ("Deleting the previous volume %u on server %s, partition %s ...",
4041 hostutil_GetNameByINet(entry.serverNumber[index]),
4044 AFSVolTransCreate(tempconn, pvolid,
4045 entry.serverPartition[index],
4046 ITOffline, &temptid);
4049 AFSVolSetFlags(tempconn, temptid,
4054 "Could not set flags on volume %lu on the older site\n",
4055 (unsigned long)pvolid);
4059 code = AFSVolDeleteVolume(tempconn, temptid);
4062 "Could not delete volume %lu on the older site\n",
4063 (unsigned long)pvolid);
4067 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4073 "Could not end transaction on volume %lu on the older site\n",
4074 (unsigned long)pvolid);
4079 MapPartIdIntoName(entry.serverPartition[index],
4083 entry.serverNumber[index] = toserver;
4084 entry.serverPartition[index] = topart;
4087 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4088 MapNetworkToHost(&entry, &storeEntry);
4090 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4091 LOCKREL_OPCODE | LOCKREL_AFSID |
4095 "Could not update the entry for volume number %lu \n",
4096 (unsigned long)pvolid);
4102 EnumerateEntry(&entry);
4109 code = rx_EndCall(tocall, rxError);
4115 ubik_Call(VL_ReleaseLock, cstruct, 0, pvolid, voltype,
4116 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4119 "Could not release lock on the VLDB entry for the volume %lu\n",
4120 (unsigned long)pvolid);
4126 code = AFSVolEndTrans(toconn, totid, &rcode);
4130 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4131 (unsigned long)pvolid);
4137 code = AFSVolEndTrans(toconn, temptid, &rcode);
4141 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4142 (unsigned long)pvolid);
4148 rx_DestroyConnection(tempconn);
4150 rx_DestroyConnection(toconn);
4151 PrintError("", error);
4156 /*unlocks the vldb entry associated with <volid> */
4158 UV_LockRelease(afs_int32 volid)
4164 VPRINT("Binding to the VLDB server\n");
4166 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
4167 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4170 "Could not unlock the entry for volume number %lu in VLDB \n",
4171 (unsigned long)volid);
4172 PrintError("", vcode);
4175 VPRINT("VLDB updated\n");
4180 /*adds <server> and <part> as a readonly replication site for <volid>
4183 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4185 int j, nro = 0, islocked = 0;
4186 struct nvldbentry entry, storeEntry;
4187 afs_int32 vcode, error = 0;
4190 error = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4193 " Could not lock the VLDB entry for the volume %lu \n",
4194 (unsigned long)volid);
4199 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4202 "Could not fetch the VLDB entry for volume number %lu \n",
4203 (unsigned long)volid);
4207 if (!ISNAMEVALID(entry.name)) {
4209 "Volume name %s is too long, rename before adding site\n",
4211 error = VOLSERBADOP;
4214 MapHostToNetwork(&entry);
4216 /* See if it's too many entries */
4217 if (entry.nServers >= NMAXNSERVERS) {
4218 fprintf(STDERR, "Total number of entries will exceed %u\n",
4220 error = VOLSERBADOP;
4224 /* See if it's on the same server */
4225 for (j = 0; j < entry.nServers; j++) {
4226 if (entry.serverFlags[j] & ITSROVOL) {
4228 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4231 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4234 MapPartIdIntoName(entry.serverPartition[j], apartName);
4236 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4238 error = VOLSERBADOP;
4245 /* See if it's too many RO sites - leave one for the RW */
4246 if (nro >= NMAXNSERVERS - 1) {
4247 fprintf(STDERR, "Total number of sites will exceed %u\n",
4249 error = VOLSERBADOP;
4253 VPRINT("Adding a new site ...");
4254 entry.serverNumber[entry.nServers] = server;
4255 entry.serverPartition[entry.nServers] = part;
4256 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4259 MapNetworkToHost(&entry, &storeEntry);
4261 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4262 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4264 fprintf(STDERR, "Could not update entry for volume %lu \n",
4265 (unsigned long)volid);
4274 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4275 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4278 "Could not release lock on volume entry for %lu \n",
4279 (unsigned long)volid);
4280 PrintError("", vcode);
4284 PrintError("", error);
4288 /*removes <server> <part> as read only site for <volid> from the vldb */
4290 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4293 struct nvldbentry entry, storeEntry;
4296 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4298 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4299 (unsigned long)volid);
4300 PrintError("", vcode);
4304 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4307 "Could not fetch the entry for volume number %lu from VLDB \n",
4308 (unsigned long)volid);
4309 PrintError("", vcode);
4312 MapHostToNetwork(&entry);
4313 if (!Lp_ROMatch(server, part, &entry)) {
4314 /*this site doesnot exist */
4315 fprintf(STDERR, "This site is not a replication site \n");
4317 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4318 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4320 fprintf(STDERR, "Could not update entry for volume %lu \n",
4321 (unsigned long)volid);
4322 PrintError("", vcode);
4323 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4324 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4328 } else { /*remove the rep site */
4329 Lp_SetROValue(&entry, server, part, 0, 0);
4331 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4332 entry.flags &= ~RO_EXISTS;
4333 if (entry.nServers < 1) { /*this is the last ref */
4334 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4336 vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, volid, ROVOL);
4339 "Could not delete VLDB entry for volume %lu \n",
4340 (unsigned long)volid);
4341 PrintError("", vcode);
4346 MapNetworkToHost(&entry, &storeEntry);
4347 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4348 (unsigned long)volid);
4351 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4352 LOCKREL_OPCODE | LOCKREL_AFSID |
4356 "Could not release lock on volume entry for %lu \n",
4357 (unsigned long)volid);
4358 PrintError("", vcode);
4359 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4360 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4368 /*sets <server> <part> as read/write site for <volid> in the vldb */
4370 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4373 struct nvldbentry entry, storeEntry;
4376 vcode = ubik_Call(VL_SetLock, cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4378 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4379 (unsigned long)volid);
4380 PrintError("", vcode);
4383 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4386 "Could not fetch the entry for volume number %lu from VLDB \n",
4387 (unsigned long)volid);
4388 PrintError("", vcode);
4391 MapHostToNetwork(&entry);
4392 index = Lp_GetRwIndex(&entry);
4394 /* no RW site exists */
4395 fprintf(STDERR, "No existing RW site for volume %lu",
4396 (unsigned long)volid);
4398 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4399 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4402 "Could not release lock on entry for volume %lu \n",
4403 (unsigned long)volid);
4404 PrintError("", vcode);
4408 } else { /* change the RW site */
4409 entry.serverNumber[index] = server;
4410 entry.serverPartition[index] = part;
4411 MapNetworkToHost(&entry, &storeEntry);
4413 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4414 LOCKREL_OPCODE | LOCKREL_AFSID |
4417 fprintf(STDERR, "Could not update entry for volume %lu \n",
4418 (unsigned long)volid);
4419 PrintError("", vcode);
4420 ubik_Call(VL_ReleaseLock, cstruct, 0, volid, RWVOL,
4421 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4429 /*list all the partitions on <aserver> */
4431 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4434 struct rx_connection *aconn;
4435 struct pIDs partIds;
4436 struct partEntries partEnts;
4437 register int i, j = 0, code;
4440 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4442 partEnts.partEntries_len = 0;
4443 partEnts.partEntries_val = NULL;
4444 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4445 if (code == RXGEN_OPCODE) {
4446 for (i = 0; i < 26; i++) /* try old interface */
4447 partIds.partIds[i] = -1;
4448 code = AFSVolListPartitions(aconn, &partIds);
4450 for (i = 0; i < 26; i++) {
4451 if ((partIds.partIds[i]) != -1) {
4452 ptrPartList->partId[j] = partIds.partIds[i];
4453 ptrPartList->partFlags[j] = PARTVALID;
4456 ptrPartList->partFlags[i] = 0;
4461 *cntp = partEnts.partEntries_len;
4462 if (*cntp > VOLMAXPARTS) {
4464 "Warning: number of partitions on the server too high %d (process only %d)\n",
4465 *cntp, VOLMAXPARTS);
4466 *cntp = VOLMAXPARTS;
4468 for (i = 0; i < *cntp; i++) {
4469 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4470 ptrPartList->partFlags[i] = PARTVALID;
4472 free(partEnts.partEntries_val);
4478 "Could not fetch the list of partitions from the server\n");
4479 PrintError("", code);
4481 rx_DestroyConnection(aconn);
4486 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4487 This is used by the backup system */
4489 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4490 struct volDescription *volPtr, afs_int32 arraySize)
4492 struct rx_connection *aconn;
4493 struct volDescription *curPtr;
4496 afs_int32 rcode = 0;
4497 afs_int32 success = 1;
4500 aconn = (struct rx_connection *)0;
4501 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4503 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4504 if (curPtr->volFlags & CLONEVALID) {
4505 curPtr->volFlags &= ~CLONEZAPPED;
4508 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4513 code = AFSVolDeleteVolume(aconn, tid);
4516 code = AFSVolEndTrans(aconn, tid, &rcode);
4521 curPtr->volFlags |= CLONEZAPPED;
4523 fprintf(STDERR, "Could not zap volume %lu\n",
4524 (unsigned long)curPtr->volCloneId);
4526 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4527 curPtr->volCloneId);
4533 rx_DestroyConnection(aconn);
4537 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4540 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4541 struct volDescription *volPtr, afs_int32 arraySize)
4543 struct rx_connection *aconn;
4544 struct volDescription *curPtr;
4547 afs_int32 rcode = 0;
4549 int reuseCloneId = 0;
4550 afs_int32 curCloneId = 0;
4551 char cloneName[256]; /*max vol name */
4553 aconn = (struct rx_connection *)0;
4554 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4556 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4558 else { /*get a bunch of id's from vldb */
4560 ubik_Call(VL_GetNewVolumeId, cstruct, 0, arraySize, &curCloneId);
4562 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4563 PrintError("", code);
4568 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4569 if (curPtr->volFlags & ENTRYVALID) {
4571 curPtr->volFlags |= CLONEVALID;
4572 /*make a clone of curParentId and record as curPtr->volCloneId */
4574 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4577 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4580 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
4584 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
4585 strcpy(cloneName, curPtr->volName);
4586 strcat(cloneName, "-tmpClone-");
4588 strcpy(cloneName, "-tmpClone");
4590 curPtr->volCloneId = curCloneId;
4595 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
4596 &(curPtr->volCloneId));
4598 curPtr->volFlags &= ~CLONEVALID;
4600 fprintf(STDERR, "Could not clone %s due to error %lu\n",
4601 curPtr->volName, (unsigned long)code);
4602 code = AFSVolEndTrans(aconn, tid, &rcode);
4604 fprintf(STDERR, "WARNING: could not end transaction\n");
4607 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
4608 curPtr->volCloneId);
4609 code = AFSVolEndTrans(aconn, tid, &rcode);
4610 if (code || rcode) {
4611 curPtr->volFlags &= ~CLONEVALID;
4620 rx_DestroyConnection(aconn);
4625 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
4626 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
4628 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
4629 struct volintInfo **resultPtr, afs_int32 * size)
4631 struct rx_connection *aconn;
4633 volEntries volumeInfo;
4637 *resultPtr = (volintInfo *) 0;
4638 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
4639 volumeInfo.volEntries_len = 0;
4641 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4642 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
4645 "Could not fetch the list of volumes from the server\n");
4647 *resultPtr = volumeInfo.volEntries_val;
4648 *size = volumeInfo.volEntries_len;
4652 rx_DestroyConnection(aconn);
4653 PrintError("", code);
4657 /*------------------------------------------------------------------------
4658 * EXPORTED UV_XListVolumes
4661 * List the extended information for all the volumes on a particular
4662 * File Server and partition. We may either return the volume's ID
4663 * or all of its extended information.
4666 * a_serverID : Address of the File Server for which we want
4667 * extended volume info.
4668 * a_partID : Partition for which we want the extended
4670 * a_all : If non-zero, fetch ALL the volume info,
4671 * otherwise just the volume ID.
4672 * a_resultPP : Ptr to the address of the area containing
4673 * the returned volume info.
4674 * a_numEntsInResultP : Ptr for the value we set for the number of
4679 * Otherise, the return value of AFSVolXListVolumes.
4682 * This routine is closely related to UV_ListVolumes, which returns
4683 * only the standard level of detail on AFS volumes. It is a
4684 * heavyweight operation, zipping through all the volume entries for
4685 * a given server/partition.
4689 *------------------------------------------------------------------------*/
4692 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
4693 struct volintXInfo **a_resultPP,
4694 afs_int32 * a_numEntsInResultP)
4696 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
4697 afs_int32 code; /*Error code to return */
4698 volXEntries volumeXInfo; /*Area for returned extended vol info */
4701 * Set up our error code and the area for returned extended volume info.
4702 * We set the val field to a null pointer as a hint for the stub to
4706 *a_numEntsInResultP = 0;
4707 *a_resultPP = (volintXInfo *) 0;
4708 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
4709 volumeXInfo.volXEntries_len = 0;
4712 * Bind to the Volume Server port on the File Server machine in question,
4715 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
4716 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
4718 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
4721 * We got the info; pull out the pointer to where the results lie
4722 * and how many entries are there.
4724 *a_resultPP = volumeXInfo.volXEntries_val;
4725 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
4729 * If we got an Rx connection, throw it away.
4732 rx_DestroyConnection(rxConnP);
4734 PrintError("", code);
4736 } /*UV_XListVolumes */
4738 /* get all the information about volume <volid> on <aserver> and <apart> */
4740 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
4741 struct volintInfo **resultPtr)
4743 struct rx_connection *aconn;
4745 volEntries volumeInfo;
4749 *resultPtr = (volintInfo *) 0;
4750 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
4751 volumeInfo.volEntries_len = 0;
4753 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4754 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
4757 "Could not fetch the information about volume %lu from the server\n",
4758 (unsigned long)volid);
4760 *resultPtr = volumeInfo.volEntries_val;
4765 rx_DestroyConnection(aconn);
4766 PrintError("", code);
4770 /*------------------------------------------------------------------------
4771 * EXPORTED UV_XListOneVolume
4774 * List the extended information for a volume on a particular File
4775 * Server and partition.
4778 * a_serverID : Address of the File Server for which we want
4779 * extended volume info.
4780 * a_partID : Partition for which we want the extended
4782 * a_volID : Volume ID for which we want the info.
4783 * a_resultPP : Ptr to the address of the area containing
4784 * the returned volume info.
4788 * Otherise, the return value of AFSVolXListOneVolume.
4791 * This routine is closely related to UV_ListOneVolume, which returns
4792 * only the standard level of detail on the chosen AFS volume.
4796 *------------------------------------------------------------------------*/
4799 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
4800 struct volintXInfo **a_resultPP)
4802 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
4803 afs_int32 code; /*Error code */
4804 volXEntries volumeXInfo; /*Area for returned info */
4807 * Set up our error code, and the area we're in which we are returning
4808 * the info. Setting the val field to a null pointer tells the stub
4809 * to allocate space for us.
4812 *a_resultPP = (volintXInfo *) 0;
4813 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
4814 volumeXInfo.volXEntries_len = 0;
4817 * Bind to the Volume Server port on the File Server machine in question,
4820 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
4821 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
4824 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
4827 * We got the info; pull out the pointer to where the results lie.
4829 *a_resultPP = volumeXInfo.volXEntries_val;
4832 * If we got an Rx connection, throw it away.
4835 rx_DestroyConnection(rxConnP);
4837 PrintError("", code);
4842 * Given a volume we read from a partition, check if it is
4843 * represented in the VLDB correctly.
4845 * The VLDB is looked up by the RW volume id (not its name).
4846 * The RW contains the true name of the volume (BK and RO set
4847 * the name in the VLDB only on creation of the VLDB entry).
4848 * We want rules strict enough that when we check all volumes
4849 * on one partition, it does not need to be done again. IE:
4850 * two volumes on different partitions won't constantly
4851 * change a VLDB entry away from what the other set.
4852 * For RW and BK volumes, we will always check the VLDB to see
4853 * if the two exist on the server/partition. May seem redundant,
4854 * but this is an easy check of the VLDB. IE: if the VLDB entry
4855 * says the BK exists but no BK volume is there, we will detect
4856 * this when we check the RW volume.
4857 * VLDB entries are locked only when a change needs to be done.
4858 * Output changed to look a lot like the "vos syncserv" otuput.
4861 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
4862 afs_int32 * modentry, afs_uint32 * maxvolid)
4865 afs_int32 code, error = 0;
4866 struct nvldbentry entry, storeEntry;
4868 int pass = 0, islocked = 0, createentry, addvolume, modified, mod;
4874 ((volumeinfo->type ==
4875 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
4878 /* Check to see if the VLDB is ok without locking it (pass 1).
4879 * If it will change, then lock the VLDB entry, read it again,
4880 * then make the changes to it (pass 2).
4883 code = ubik_Call(VL_SetLock, cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
4885 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
4886 (unsigned long)rwvolid);
4892 createentry = 0; /* Do we need to create a VLDB entry */
4893 addvolume = 0; /* Add this volume to the VLDB entry */
4894 modified = 0; /* The VLDB entry was modified */
4896 /* Read the entry from VLDB by its RW volume id */
4897 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
4899 if (code != VL_NOENT) {
4901 "Could not retreive the VLDB entry for volume %lu \n",
4902 (unsigned long)rwvolid);
4906 memset(&entry, 0, sizeof(entry));
4907 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
4911 MapHostToNetwork(&entry);
4914 if (verbose && (pass == 1)) {
4915 fprintf(STDOUT, "_______________________________\n");
4916 fprintf(STDOUT, "\n-- status before -- \n");
4918 fprintf(STDOUT, "\n**does not exist**\n");
4920 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
4921 || (entry.flags & BACK_EXISTS))
4922 EnumerateEntry(&entry);
4924 fprintf(STDOUT, "\n");
4927 if (volumeinfo->type == RWVOL) { /* RW volume exists */
4933 /* Check existence of RW and BK volumes */
4934 code = CheckVldbRWBK(&entry, &mod);
4940 idx = Lp_GetRwIndex(&entry);
4941 if (idx == -1) { /* RW index not found in the VLDB entry */
4942 idx = entry.nServers; /* put it into next index */
4945 } else { /* RW index found in the VLDB entry. */
4946 /* Verify if this volume's location matches where the VLDB says it is */
4947 if (!Lp_Match(aserver, apart, &entry)) {
4948 if (entry.flags & RW_EXISTS) {
4949 /* The RW volume exists elsewhere - report this one a duplicate */
4951 MapPartIdIntoName(apart, pname);
4953 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
4954 (unsigned long)rwvolid,
4955 hostutil_GetNameByINet(aserver), pname);
4956 MapPartIdIntoName(entry.serverPartition[idx],
4959 " VLDB reports RW volume %lu exists on %s %s\n",
4960 (unsigned long)rwvolid,
4961 hostutil_GetNameByINet(entry.
4966 /* The RW volume does not exist - have VLDB point to this one */
4969 /* Check for orphaned BK volume on old partition */
4970 if (entry.flags & BACK_EXISTS) {
4972 MapPartIdIntoName(entry.serverPartition[idx],
4975 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
4976 entry.volumeId[BACKVOL],
4977 hostutil_GetNameByINet(entry.
4980 MapPartIdIntoName(apart, pname);
4982 " VLDB reports its RW volume %lu exists on %s %s\n",
4983 (unsigned long)rwvolid,
4984 hostutil_GetNameByINet(aserver),
4990 /* Volume location matches the VLDB location */
4991 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
4992 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
4995 (entry.name, volumeinfo->name,
4996 VOLSER_OLDMAXVOLNAME) != 0)) {
5004 entry.flags |= RW_EXISTS;
5005 entry.volumeId[RWVOL] = rwvolid;
5006 if (!entry.volumeId[BACKVOL])
5007 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5008 if (!entry.volumeId[ROVOL])
5009 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5011 entry.serverFlags[idx] = ITSRWVOL;
5012 entry.serverNumber[idx] = aserver;
5013 entry.serverPartition[idx] = apart;
5014 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5018 /* One last check - to update BK if need to */
5019 code = CheckVldbRWBK(&entry, &mod);
5027 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5033 /* Check existence of RW and BK volumes */
5034 code = CheckVldbRWBK(&entry, &mod);
5040 idx = Lp_GetRwIndex(&entry);
5041 if (idx == -1) { /* RW index not found in the VLDB entry */
5042 idx = entry.nServers; /* Put it into next index */
5045 } else { /* RW index found in the VLDB entry */
5046 /* Verify if this volume's location matches where the VLDB says it is */
5047 if (!Lp_Match(aserver, apart, &entry)) {
5048 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5050 MapPartIdIntoName(apart, pname);
5052 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5053 (unsigned long)volumeinfo->volid,
5054 hostutil_GetNameByINet(aserver), pname);
5055 MapPartIdIntoName(entry.serverPartition[idx], pname);
5057 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5058 (unsigned long)rwvolid,
5059 hostutil_GetNameByINet(entry.
5064 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5065 if (!(entry.flags & BACK_EXISTS)) {
5067 } else if (volumeinfo->volid >
5068 entry.volumeId[BACKVOL]) {
5072 MapPartIdIntoName(entry.serverPartition[idx],
5075 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5076 entry.volumeId[BACKVOL],
5077 hostutil_GetNameByINet(aserver),
5080 " VLDB reports its BK volume ID is %lu\n",
5081 (unsigned long)volumeinfo->volid);
5085 MapPartIdIntoName(entry.serverPartition[idx],
5088 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5089 (unsigned long)volumeinfo->volid,
5090 hostutil_GetNameByINet(aserver),
5093 " VLDB reports its BK volume ID is %u\n",
5094 entry.volumeId[BACKVOL]);
5097 } else if (!entry.volumeId[BACKVOL]) {
5104 entry.flags |= BACK_EXISTS;
5105 entry.volumeId[RWVOL] = rwvolid;
5106 entry.volumeId[BACKVOL] = volumeinfo->volid;
5108 entry.serverNumber[idx] = aserver;
5109 entry.serverPartition[idx] = apart;
5110 entry.serverFlags[idx] = ITSRWVOL;
5116 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5117 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5118 /* This is a quick check to see if the RO entry exists in the
5119 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5120 * RO volume listed in the VLDB exists).
5122 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5124 idx = entry.nServers;
5128 if (!(entry.flags & RO_EXISTS)) {
5133 /* Before we correct the VLDB entry, make sure all the
5134 * ROs listed in the VLDB exist.
5136 code = CheckVldbRO(&entry, &mod);
5142 if (!(entry.flags & RO_EXISTS)) {
5143 /* No RO exists in the VLDB entry - add this one */
5144 idx = entry.nServers;
5147 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5148 /* The volume headers's RO ID does not match that in the VLDB entry,
5149 * and the vol hdr's ID is greater (implies more recent). So delete
5150 * all the RO volumes listed in VLDB entry and add this volume.
5152 for (j = 0; j < entry.nServers; j++) {
5153 if (entry.serverFlags[j] & ITSROVOL) {
5154 /* Verify this volume exists and print message we are orphaning it */
5156 MapPartIdIntoName(apart, pname);
5158 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5159 entry.volumeId[ROVOL],
5160 hostutil_GetNameByINet(entry.
5164 " VLDB reports its RO volume ID is %lu\n",
5165 (unsigned long)volumeinfo->volid);
5168 Lp_SetRWValue(entry, entry.serverNumber[idx],
5169 entry.serverPartition[idx], 0L, 0L);
5176 idx = entry.nServers;
5179 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5180 /* The volume headers's RO ID does not match that in the VLDB entry,
5181 * and the vol hdr's ID is lower (implies its older). So orphan it.
5184 MapPartIdIntoName(apart, pname);
5186 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5187 (unsigned long)volumeinfo->volid,
5188 hostutil_GetNameByINet(aserver), pname);
5190 " VLDB reports its RO volume ID is %u\n",
5191 entry.volumeId[ROVOL]);
5194 /* The RO volume ID in the volume header match that in the VLDB entry,
5195 * and there exist RO volumes in the VLDB entry. See if any of them
5196 * are this one. If not, then we add it.
5198 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5200 idx = entry.nServers;
5208 entry.flags |= RO_EXISTS;
5209 entry.volumeId[RWVOL] = rwvolid;
5210 entry.volumeId[ROVOL] = volumeinfo->volid;
5212 entry.serverNumber[idx] = aserver;
5213 entry.serverPartition[idx] = apart;
5214 entry.serverFlags[idx] = ITSROVOL;
5220 /* Remember largest volume id */
5221 if (entry.volumeId[ROVOL] > *maxvolid)
5222 *maxvolid = entry.volumeId[ROVOL];
5223 if (entry.volumeId[BACKVOL] > *maxvolid)
5224 *maxvolid = entry.volumeId[BACKVOL];
5225 if (entry.volumeId[RWVOL] > *maxvolid)
5226 *maxvolid = entry.volumeId[RWVOL];
5229 MapNetworkToHost(&entry, &storeEntry);
5232 code = VLDB_CreateEntry(&storeEntry);
5235 "Could not create a VLDB entry for the volume %lu\n",
5236 (unsigned long)rwvolid);
5243 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5244 LOCKREL_OPCODE | LOCKREL_AFSID |
5247 fprintf(STDERR, "Could not update entry for %lu\n",
5248 (unsigned long)rwvolid);
5253 *modentry = modified;
5254 } else if (pass == 2) {
5256 ubik_Call(VL_ReleaseLock, cstruct, 0, rwvolid, RWVOL,
5257 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5259 PrintError("Could not unlock VLDB entry ", code);
5264 fprintf(STDOUT, "-- status after --\n");
5266 EnumerateEntry(&entry);
5268 fprintf(STDOUT, "\n**no change**\n");
5272 VPRINT("\n_______________________________\n");
5277 sortVolumes(const void *a, const void *b)
5279 volintInfo *v1 = (volintInfo *) a;
5280 volintInfo *v2 = (volintInfo *) b;
5281 afs_int32 rwvolid1, rwvolid2;
5283 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5284 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5286 if (rwvolid1 > rwvolid2)
5287 return -1; /* lower RW id goes first */
5288 if (rwvolid1 < rwvolid2)
5291 if (v1->type == RWVOL)
5292 return -1; /* RW vols go first */
5293 if (v2->type == RWVOL)
5296 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5297 return -1; /* BK vols next */
5298 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5301 if (v1->volid < v2->volid)
5302 return 1; /* larger volids first */
5303 if (v1->volid > v2->volid)
5309 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5310 * Synchronize an individual volume against a sever and partition.
5311 * Checks the VLDB entry (similar to syncserv) as well as checks
5312 * if the volume exists on specified servers (similar to syncvldb).
5315 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5317 struct rx_connection *aconn = 0;
5318 afs_int32 j, k, code, vcode, error = 0;
5319 afs_int32 tverbose, mod, modified = 0;
5320 struct nvldbentry vldbentry;
5321 afs_int32 volumeid = 0;
5322 volEntries volumeInfo;
5323 struct partList PartList;
5325 afs_int32 maxvolid = 0;
5327 volumeInfo.volEntries_val = (volintInfo *) 0;
5328 volumeInfo.volEntries_len = 0;
5330 if (!aserver && flags) {
5331 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5335 /* Turn verbose logging off and do our own verbose logging */
5339 /* Read the VLDB entry */
5340 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5341 if (vcode && (vcode != VL_NOENT)) {
5342 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5345 } else if (!vcode) {
5346 MapHostToNetwork(&vldbentry);
5350 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5351 fprintf(STDOUT, "_______________________________\n");
5352 fprintf(STDOUT, "\n-- status before -- \n");
5354 fprintf(STDOUT, "\n**does not exist**\n");
5356 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5357 || (vldbentry.flags & BACK_EXISTS))
5358 EnumerateEntry(&vldbentry);
5360 fprintf(STDOUT, "\n");
5363 /* Verify that all of the VLDB entries exist on the repective servers
5364 * and partitions (this does not require that avolname be a volume ID).
5365 * Equivalent to a syncserv.
5368 code = CheckVldb(&vldbentry, &mod);
5370 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5378 /* If aserver is given, we will search for the desired volume on it */
5380 /* Generate array of partitions on the server that we will check */
5382 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5385 "Could not fetch the list of partitions from the server\n");
5389 PartList.partId[0] = apart;
5393 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5395 /* If a volume ID were given, search for it on each partition */
5396 if ((volumeid = atol(avolname))) {
5397 for (j = 0; j < pcnt; j++) {
5399 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5402 if (code != ENODEV) {
5403 fprintf(STDERR, "Could not query server\n");
5407 /* Found one, sync it with VLDB entry */
5409 CheckVolume(volumeInfo.volEntries_val, aserver,
5410 PartList.partId[j], &mod, &maxvolid);
5417 if (volumeInfo.volEntries_val)
5418 free(volumeInfo.volEntries_val);
5419 volumeInfo.volEntries_val = (volintInfo *) 0;
5420 volumeInfo.volEntries_len = 0;
5424 /* Check to see if the RW, BK, and RO IDs exist on any
5425 * partitions. We get the volume IDs from the VLDB.
5427 rv = 1; /* Read the VLDB entry ? */
5428 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5430 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5432 if (vcode == VL_NOENT)
5435 "Could not access the VLDB for volume %s\n",
5442 if (vldbentry.volumeId[j] == 0)
5445 for (k = 0; k < pcnt; k++) { /* For each partition */
5446 volumeInfo.volEntries_val = (volintInfo *) 0;
5447 volumeInfo.volEntries_len = 0;
5449 AFSVolListOneVolume(aconn, PartList.partId[k],
5450 vldbentry.volumeId[j], &volumeInfo);
5452 if (code != ENODEV) {
5453 fprintf(STDERR, "Could not query server\n");
5457 /* Found one, sync it with VLDB entry */
5459 CheckVolume(volumeInfo.volEntries_val, aserver,
5460 PartList.partId[k], &mod, &maxvolid);
5467 if (volumeInfo.volEntries_val)
5468 free(volumeInfo.volEntries_val);
5469 volumeInfo.volEntries_val = (volintInfo *) 0;
5470 volumeInfo.volEntries_len = 0;
5476 /* If verbose output, print a summary of what changed */
5478 fprintf(STDOUT, "-- status after --\n");
5479 code = VLDB_GetEntryByName(avolname, &vldbentry);
5480 if (code && (code != VL_NOENT)) {
5481 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5485 if (modified && (code == VL_NOENT)) {
5486 fprintf(STDOUT, "\n**entry deleted**\n");
5487 } else if (modified) {
5488 EnumerateEntry(&vldbentry);
5490 fprintf(STDOUT, "\n**no change**\n");
5492 fprintf(STDOUT, "\n_______________________________\n");
5496 /* Now check if the maxvolid is larger than that stored in the VLDB */
5498 afs_int32 maxvldbid = 0;
5499 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
5502 "Could not get the highest allocated volume id from the VLDB\n");
5505 } else if (maxvolid > maxvldbid) {
5507 id = maxvolid - maxvldbid + 1;
5508 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
5511 "Error in increasing highest allocated volume id in VLDB\n");
5521 fprintf(STDOUT, "...error encountered");
5523 fprintf(STDOUT, "...done entry\n");
5526 rx_DestroyConnection(aconn);
5527 if (volumeInfo.volEntries_val)
5528 free(volumeInfo.volEntries_val);
5530 PrintError("", error);
5535 * Synchronise vldb with the file server <aserver> and,
5536 * optionally, <apart>.
5539 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5541 struct rx_connection *aconn;
5542 afs_int32 code, error = 0;
5544 volEntries volumeInfo;
5545 struct partList PartList;
5549 afs_int32 failures = 0, modifications = 0, tentries = 0;
5551 afs_uint32 maxvolid = 0;
5553 volumeInfo.volEntries_val = (volintInfo *) 0;
5554 volumeInfo.volEntries_len = 0;
5556 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5558 /* Generate array of partitions to check */
5560 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5563 "Could not fetch the list of partitions from the server\n");
5567 PartList.partId[0] = apart;
5571 VPRINT("Processing volume entries ...\n");
5573 /* Step through the array of partitions */
5574 for (i = 0; i < pcnt; i++) {
5575 apart = PartList.partId[i];
5576 MapPartIdIntoName(apart, pname);
5578 volumeInfo.volEntries_val = (volintInfo *) 0;
5579 volumeInfo.volEntries_len = 0;
5580 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
5583 "Could not fetch the list of volumes from the server\n");
5587 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
5588 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
5589 sizeof(volintInfo), sortVolumes);
5592 for (vi = volumeInfo.volEntries_val, j = 0;
5593 j < volumeInfo.volEntries_len; j++, vi++) {
5601 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
5602 j + 1, vi->name, (unsigned long)vi->volid,
5603 hostutil_GetNameByINet(aserver), pname);
5607 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
5609 PrintError("", code);
5612 } else if (modified) {
5618 fprintf(STDOUT, "...error encountered\n\n");
5620 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
5627 "Could not process entries on server %s partition %s\n",
5628 hostutil_GetNameByINet(aserver), pname);
5630 if (volumeInfo.volEntries_val) {
5631 free(volumeInfo.volEntries_val);
5632 volumeInfo.volEntries_val = 0;
5635 } /* thru all partitions */
5637 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
5638 failures, modifications);
5641 /* Now check if the maxvolid is larger than that stored in the VLDB */
5643 afs_uint32 maxvldbid = 0;
5644 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, 0, &maxvldbid);
5647 "Could not get the highest allocated volume id from the VLDB\n");
5650 } else if (maxvolid > maxvldbid) {
5652 id = maxvolid - maxvldbid + 1;
5653 code = ubik_Call(VL_GetNewVolumeId, cstruct, 0, id, &nid);
5656 "Error in increasing highest allocated volume id in VLDB\n");
5664 rx_DestroyConnection(aconn);
5665 if (volumeInfo.volEntries_val)
5666 free(volumeInfo.volEntries_val);
5667 PrintError("", error);
5672 * Determine if a volume exists on a server and partition.
5673 * Try creating a transaction on the volume. If we can,
5674 * the volume exists, if not, then return the error code.
5675 * Some error codes mean the volume is unavailable but
5676 * still exists - so we catch these error codes.
5679 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
5681 struct rx_connection *conn = (struct rx_connection *)0;
5682 afs_int32 code = -1;
5683 volEntries volumeInfo;
5685 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
5687 volumeInfo.volEntries_val = (volintInfo *) 0;
5688 volumeInfo.volEntries_len = 0;
5689 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
5690 if (volumeInfo.volEntries_val)
5691 free(volumeInfo.volEntries_val);
5692 if (code == VOLSERILLEGAL_PARTITION)
5694 rx_DestroyConnection(conn);
5703 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
5707 afs_int32 code, error = 0;
5712 idx = Lp_GetRwIndex(entry);
5714 /* Check to see if the RW volume exists and set the RW_EXISTS
5717 if (idx == -1) { /* Did not find a RW entry */
5718 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
5719 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
5724 VolumeExists(entry->serverNumber[idx],
5725 entry->serverPartition[idx], entry->volumeId[RWVOL]);
5726 if (code == 0) { /* RW volume exists */
5727 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
5728 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
5731 } else if (code == ENODEV) { /* RW volume does not exist */
5732 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
5733 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
5737 /* If VLDB says it didn't exist, then ignore error */
5738 if (entry->flags & RW_EXISTS) {
5739 MapPartIdIntoName(entry->serverPartition[idx], pname);
5741 "Transaction call failed for RW volume %u on server %s %s\n",
5742 entry->volumeId[RWVOL],
5743 hostutil_GetNameByINet(entry->serverNumber[idx]),
5750 /* Check to see if the BK volume exists and set the BACK_EXISTS
5751 * flag accordingly. idx already ponts to the RW entry.
5753 if (idx == -1) { /* Did not find a RW entry */
5754 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
5755 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
5758 } else { /* Found a RW entry */
5760 VolumeExists(entry->serverNumber[idx],
5761 entry->serverPartition[idx],
5762 entry->volumeId[BACKVOL]);
5763 if (code == 0) { /* BK volume exists */
5764 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
5765 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
5768 } else if (code == ENODEV) { /* BK volume does not exist */
5769 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
5770 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
5774 /* If VLDB says it didn't exist, then ignore error */
5775 if (entry->flags & BACK_EXISTS) {
5776 MapPartIdIntoName(entry->serverPartition[idx], pname);
5778 "Transaction call failed for BK volume %u on server %s %s\n",
5779 entry->volumeId[BACKVOL],
5780 hostutil_GetNameByINet(entry->serverNumber[idx]),
5787 /* If there is an idx but the BK and RW volumes no
5788 * longer exist, then remove the RW entry.
5790 if ((idx != -1) && !(entry->flags & RW_EXISTS)
5791 && !(entry->flags & BACK_EXISTS)) {
5792 Lp_SetRWValue(entry, entry->serverNumber[idx],
5793 entry->serverPartition[idx], 0L, 0L);
5800 *modified = modentry;
5805 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
5808 int foundro = 0, modentry = 0;
5809 afs_int32 code, error = 0;
5815 /* Check to see if the RO volumes exist and set the RO_EXISTS
5818 for (idx = 0; idx < entry->nServers; idx++) {
5819 if (!(entry->serverFlags[idx] & ITSROVOL)) {
5820 continue; /* not a RO */
5824 VolumeExists(entry->serverNumber[idx],
5825 entry->serverPartition[idx], entry->volumeId[ROVOL]);
5826 if (code == 0) { /* RO volume exists */
5828 } else if (code == ENODEV) { /* RW volume does not exist */
5829 Lp_SetROValue(entry, entry->serverNumber[idx],
5830 entry->serverPartition[idx], 0L, 0L);
5835 MapPartIdIntoName(entry->serverPartition[idx], pname);
5837 "Transaction call failed for RO %u on server %s %s\n",
5838 entry->volumeId[ROVOL],
5839 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
5844 if (foundro) { /* A RO volume exists */
5845 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
5846 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
5849 } else { /* A RO volume does not exist */
5850 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
5851 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
5858 *modified = modentry;
5863 * Ensure that <entry> matches with the info on file servers
5866 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
5868 afs_int32 code, error = 0;
5869 struct nvldbentry storeEntry;
5870 int islocked = 0, mod, modentry, delentry = 0;
5876 fprintf(STDOUT, "_______________________________\n");
5877 fprintf(STDOUT, "\n-- status before -- \n");
5878 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
5879 || (entry->flags & BACK_EXISTS))
5880 EnumerateEntry(entry);
5881 fprintf(STDOUT, "\n");
5884 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
5885 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
5886 entry->name, VOLSER_OLDMAXVOLNAME - 10);
5890 /* Check to see if the VLDB is ok without locking it (pass 1).
5891 * If it will change, then lock the VLDB entry, read it again,
5892 * then make the changes to it (pass 2).
5896 ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL,
5899 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
5900 entry->volumeId[RWVOL]);
5905 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
5907 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
5911 MapHostToNetwork(entry);
5917 /* Check if the RW and BK entries are ok */
5918 code = CheckVldbRWBK(entry, &mod);
5921 if (mod && (pass == 1))
5926 /* Check if the RO volumes entries are ok */
5927 code = CheckVldbRO(entry, &mod);
5930 if (mod && (pass == 1))
5935 /* The VLDB entry has been updated. If it as been modified, then
5936 * write the entry back out the the VLDB.
5942 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
5943 && !(entry->flags & RO_EXISTS)) {
5944 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
5946 ubik_Call(VL_DeleteEntry, cstruct, 0, entry->volumeId[RWVOL],
5950 "Could not delete VLDB entry for volume %u \n",
5951 entry->volumeId[RWVOL]);
5956 /* Replace old entry with our new one */
5957 MapNetworkToHost(entry, &storeEntry);
5959 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
5960 (LOCKREL_OPCODE | LOCKREL_AFSID |
5961 LOCKREL_TIMESTAMP));
5963 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
5964 entry->volumeId[RWVOL]);
5974 fprintf(STDOUT, "-- status after --\n");
5976 fprintf(STDOUT, "\n**entry deleted**\n");
5978 EnumerateEntry(entry);
5980 fprintf(STDOUT, "\n**no change**\n");
5984 VPRINT("\n_______________________________\n");
5988 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
5990 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
5993 "Could not release lock on VLDB entry for volume %u\n",
5994 entry->volumeId[RWVOL]);
6003 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6006 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6008 struct rx_connection *aconn;
6009 afs_int32 code, error = 0;
6010 afs_int32 nentries, tentries = 0;
6011 struct VldbListByAttributes attributes;
6012 nbulkentries arrayEntries;
6013 afs_int32 failures = 0, modified, modifications = 0;
6014 struct nvldbentry *vlentry;
6015 afs_int32 si, nsi, j;
6017 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6019 /* Set up attributes to search VLDB */
6020 attributes.server = ntohl(aserver);
6021 attributes.Mask = VLLIST_SERVER;
6023 attributes.partition = apart;
6024 attributes.Mask |= VLLIST_PARTITION;
6027 VPRINT("Processing VLDB entries ...\n");
6029 /* While we need to collect more VLDB entries */
6030 for (si = 0; si != -1; si = nsi) {
6031 memset(&arrayEntries, 0, sizeof(arrayEntries));
6033 /* Collect set of VLDB entries */
6035 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6036 &arrayEntries, &nsi);
6037 if (code == RXGEN_OPCODE) {
6038 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6042 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6045 tentries += nentries;
6047 for (j = 0; j < nentries; j++) {
6048 vlentry = &arrayEntries.nbulkentries_val[j];
6049 MapHostToNetwork(vlentry);
6051 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6053 code = CheckVldb(vlentry, &modified);
6055 PrintError("", code);
6057 "Could not process VLDB entry for volume %s\n",
6060 } else if (modified) {
6066 fprintf(STDOUT, "...error encountered\n\n");
6068 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6073 if (arrayEntries.nbulkentries_val) {
6074 free(arrayEntries.nbulkentries_val);
6075 arrayEntries.nbulkentries_val = 0;
6079 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6080 failures, modifications);
6084 rx_DestroyConnection(aconn);
6085 if (arrayEntries.nbulkentries_val)
6086 free(arrayEntries.nbulkentries_val);
6089 error = VOLSERFAILEDOP;
6093 /*rename volume <oldname> to <newname>, changing the names of the related
6094 *readonly and backup volumes. This operation is also idempotent.
6095 *salvager is capable of recovering from rename operation stopping halfway.
6096 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6098 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6100 struct nvldbentry storeEntry;
6101 afs_int32 vcode, code, rcode, error;
6103 char nameBuffer[256];
6105 struct rx_connection *aconn;
6109 aconn = (struct rx_connection *)0;
6113 vcode = ubik_Call(VL_SetLock, cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6116 " Could not lock the VLDB entry for the volume %u \n",
6117 entry->volumeId[RWVOL]);
6122 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6123 MapNetworkToHost(entry, &storeEntry);
6124 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6126 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6127 entry->volumeId[RWVOL]);
6131 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6132 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6133 * is concerned, oldname is lost */
6134 if (entry->flags & RW_EXISTS) {
6135 index = Lp_GetRwIndex(entry);
6136 if (index == -1) { /* there is a serious discrepancy */
6138 "There is a serious discrepancy in VLDB entry for volume %u\n",
6139 entry->volumeId[RWVOL]);
6140 fprintf(STDERR, "try building VLDB from scratch\n");
6141 error = VOLSERVLDB_ERROR;
6144 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6146 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6147 entry->serverPartition[index], ITOffline, &tid);
6148 if (code) { /*volume doesnot exist */
6150 "Could not start transaction on the rw volume %u\n",
6151 entry->volumeId[RWVOL]);
6154 } else { /*volume exists, process it */
6157 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6158 entry->volumeId[RWVOL],
6159 entry->volumeId[ROVOL],
6160 entry->volumeId[BACKVOL]);
6162 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6163 code = AFSVolEndTrans(aconn, tid, &rcode);
6167 "Could not end transaction on volume %s %u\n",
6168 entry->name, entry->volumeId[RWVOL]);
6173 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6174 entry->name, entry->volumeId[RWVOL]);
6180 rx_DestroyConnection(aconn);
6181 aconn = (struct rx_connection *)0;
6183 /*end rw volume processing */
6184 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6185 index = Lp_GetRwIndex(entry);
6186 if (index == -1) { /* there is a serious discrepancy */
6188 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6189 entry->volumeId[BACKVOL]);
6190 fprintf(STDERR, "try building VLDB from scratch\n");
6191 error = VOLSERVLDB_ERROR;
6194 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6196 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6197 entry->serverPartition[index], ITOffline, &tid);
6198 if (code) { /*volume doesnot exist */
6200 "Could not start transaction on the backup volume %u\n",
6201 entry->volumeId[BACKVOL]);
6204 } else { /*volume exists, process it */
6205 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6207 "Volume name %s.backup exceeds the limit of %u characters\n",
6208 newname, VOLSER_OLDMAXVOLNAME);
6212 strcpy(nameBuffer, newname);
6213 strcat(nameBuffer, ".backup");
6216 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6217 entry->volumeId[RWVOL], 0, 0);
6219 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6220 code = AFSVolEndTrans(aconn, tid, &rcode);
6224 "Could not end transaction on the backup volume %u\n",
6225 entry->volumeId[BACKVOL]);
6231 "Could not set parameters on the backup volume %u\n",
6232 entry->volumeId[BACKVOL]);
6237 } /* end backup processing */
6239 rx_DestroyConnection(aconn);
6240 aconn = (struct rx_connection *)0;
6241 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6242 for (i = 0; i < entry->nServers; i++) {
6243 if (entry->serverFlags[i] & ITSROVOL) {
6244 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6246 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6247 entry->serverPartition[i], ITOffline,
6249 if (code) { /*volume doesnot exist */
6251 "Could not start transaction on the ro volume %u\n",
6252 entry->volumeId[ROVOL]);
6255 } else { /*volume exists, process it */
6256 strcpy(nameBuffer, newname);
6257 strcat(nameBuffer, ".readonly");
6258 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6260 "Volume name %s exceeds the limit of %u characters\n",
6261 nameBuffer, VOLSER_OLDMAXVOLNAME);
6266 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6267 entry->volumeId[RWVOL], 0, 0);
6269 VPRINT2("Renamed RO volume %s on host %s\n",
6271 hostutil_GetNameByINet(entry->
6273 code = AFSVolEndTrans(aconn, tid, &rcode);
6277 "Could not end transaction on volume %u\n",
6278 entry->volumeId[ROVOL]);
6284 "Could not set parameters on the ro volume %u\n",
6285 entry->volumeId[ROVOL]);
6291 rx_DestroyConnection(aconn);
6292 aconn = (struct rx_connection *)0;
6299 ubik_Call(VL_ReleaseLock, cstruct, 0, entry->volumeId[RWVOL],
6301 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6304 "Could not unlock the VLDB entry for the volume %s %u\n",
6305 entry->name, entry->volumeId[RWVOL]);
6311 code = AFSVolEndTrans(aconn, tid, &rcode);
6315 fprintf(STDERR, "Failed to end transaction on a volume \n");
6321 rx_DestroyConnection(aconn);
6322 PrintError("", error);
6327 /*report on all the active transactions on volser */
6329 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6331 struct rx_connection *aconn;
6332 transDebugEntries transInfo;
6335 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6336 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6337 transInfo.transDebugEntries_len = 0;
6338 code = AFSVolMonitor(aconn, &transInfo);
6341 "Could not access status information about the server\n");
6342 PrintError("", code);
6343 if (transInfo.transDebugEntries_val)
6344 free(transInfo.transDebugEntries_val);
6346 rx_DestroyConnection(aconn);
6349 *rcount = transInfo.transDebugEntries_len;
6350 *rpntr = transInfo.transDebugEntries_val;
6352 rx_DestroyConnection(aconn);
6359 /*delete the volume without interacting with the vldb */
6361 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6363 afs_int32 rcode, ttid, error, code;
6364 struct rx_connection *aconn;
6370 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6371 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6373 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6374 (unsigned long)volid);
6378 code = AFSVolDeleteVolume(aconn, ttid);
6380 fprintf(STDERR, "Could not delete volume %lu\n",
6381 (unsigned long)volid);
6385 code = AFSVolEndTrans(aconn, ttid, &rcode);
6390 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6391 (unsigned long)volid);
6397 code = AFSVolEndTrans(aconn, ttid, &rcode);
6403 PrintError("", error);
6405 rx_DestroyConnection(aconn);
6410 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6411 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6413 struct rx_connection *conn = 0;
6415 afs_int32 code, error = 0, rcode;
6417 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6419 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6423 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6425 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6429 code = AFSVolSetFlags(conn, tid, setflag);
6431 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6436 #ifdef AFS_PTHREAD_ENV
6439 IOMGR_Sleep(sleeptime);
6446 code = AFSVolEndTrans(conn, tid, &rcode);
6447 if (code || rcode) {
6448 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6450 error = (code ? code : rcode);
6455 rx_DestroyConnection(conn);
6460 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6463 struct rx_connection *conn = 0;
6465 afs_int32 code, error = 0, rcode;
6467 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6469 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6473 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6475 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6479 code = AFSVolSetInfo(conn, tid, infop);
6481 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6488 code = AFSVolEndTrans(conn, tid, &rcode);
6489 if (code || rcode) {
6490 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6492 error = (code ? code : rcode);
6497 rx_DestroyConnection(conn);
6502 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6503 afs_int32 fromdate, struct volintSize *vol_size)
6505 struct rx_connection *aconn = (struct rx_connection *)0;
6506 afs_int32 tid = 0, rcode = 0;
6507 afs_int32 code, error = 0;
6510 /* get connections to the servers */
6511 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6513 VPRINT1("Starting transaction on volume %u...", afromvol);
6514 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6515 EGOTO1(error_exit, code,
6516 "Could not start transaction on the volume %u to be measured\n",
6520 VPRINT1("Getting size of volume on volume %u...", afromvol);
6521 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6522 EGOTO(error_exit, code, "Could not start the measurement process \n");
6527 VPRINT1("Ending transaction on volume %u...", afromvol);
6528 code = AFSVolEndTrans(aconn, tid, &rcode);
6529 if (code || rcode) {
6530 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6532 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6534 error = (code ? code : rcode);
6539 rx_DestroyConnection(aconn);
6541 PrintError("", error);
6545 /*maps the host addresses in <old > (present in network byte order) to
6546 that in< new> (present in host byte order )*/
6548 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
6552 /*copy all the fields */
6553 strcpy(new->name, old->name);
6554 /* new->volumeType = old->volumeType;*/
6555 new->nServers = old->nServers;
6556 count = old->nServers;
6557 if (count < NMAXNSERVERS)
6559 for (i = 0; i < count; i++) {
6560 new->serverNumber[i] = ntohl(old->serverNumber[i]);
6561 new->serverPartition[i] = old->serverPartition[i];
6562 new->serverFlags[i] = old->serverFlags[i];
6564 new->volumeId[RWVOL] = old->volumeId[RWVOL];
6565 new->volumeId[ROVOL] = old->volumeId[ROVOL];
6566 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
6567 new->cloneId = old->cloneId;
6568 new->flags = old->flags;
6571 /*maps the host entries in <entry> which are present in host byte order to network byte order */
6573 MapHostToNetwork(struct nvldbentry *entry)
6577 count = entry->nServers;
6578 if (count < NMAXNSERVERS)
6580 for (i = 0; i < count; i++) {
6581 entry->serverNumber[i] = htonl(entry->serverNumber[i]);