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>
21 #include <sys/statfs.h>
28 #include <netinet/in.h>
32 #include <afs/voldefs.h>
35 #include <afs/vlserver.h>
37 #include <afs/cellconfig.h>
40 #include <afs/afsint.h>
44 #include <afs/com_err.h>
46 #include <afs/kautils.h>
49 #define ERRCODE_RANGE 8 /* from error_table.h */
50 #define CLOCKSKEW 2 /* not really skew, but resolution */
51 #define CLOCKADJ(x) (((x) < CLOCKSKEW) ? 0 : (x) - CLOCKSKEW)
53 /* for UV_MoveVolume() recovery */
55 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
58 #include <volser_prototypes.h>
60 struct ubik_client *cstruct;
66 afs_int32 vldbEntryIndex;
69 /* Utility macros used by rest of this source file */
70 #define EPRINT(ec, es) \
72 fprintf(STDERR, "\n"); \
73 fprintf(STDERR, (es)); \
77 #define EPRINT1(ec, es, ep1) \
79 fprintf(STDERR, "\n"); \
80 fprintf(STDERR, (es), (ep1)); \
84 #define EPRINT2(ec, es, ep1, ep2) \
86 fprintf(STDERR, "\n"); \
87 fprintf(STDERR, (es), (ep1), (ep2)); \
91 #define EPRINT3(ec, es, ep1, ep2, ep3) \
93 fprintf(STDERR, "\n"); \
94 fprintf(STDERR, (es), (ep1), (ep2), (ep3)); \
98 #define EGOTO(where, ec, es) \
107 #define EGOTO1(where, ec, es, ep1) \
110 EPRINT1((ec),(es),(ep1)); \
116 #define EGOTO2(where, ec, es, ep1, ep2) \
119 EPRINT2((ec),(es),(ep1),(ep2)); \
125 #define EGOTO3(where, ec, es, ep1, ep2, ep3) \
128 EPRINT3((ec),(es),(ep1),(ep2),(ep3)); \
135 { if (verbose) { fprintf(STDOUT, (es)); fflush(STDOUT); } }
136 #define VPRINT1(es, p) \
137 { if (verbose) { fprintf(STDOUT, (es), (p)); fflush(STDOUT); } }
138 #define VPRINT2(es, p1, p2) \
139 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2)); fflush(STDOUT); } }
140 #define VPRINT3(es, p1, p2, p3) \
141 { if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
143 { if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
147 /* getting rid of this */
148 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
151 /* Protos for static routines */
152 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
153 afs_int32 apart, afs_int32 okvol,
155 static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
157 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
158 struct rx_connection **connPtr, afs_int32 * transPtr,
159 afs_int32 * crtimePtr, afs_int32 * uptimePtr);
160 static int SimulateForwardMultiple(struct rx_connection *fromconn,
161 afs_int32 fromtid, afs_int32 fromdate,
162 manyDests * tr, afs_int32 flags,
163 void *cookie, manyResults * results);
164 static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
165 afs_int32 apart, afs_int32 * modentry,
166 afs_uint32 * maxvolid);
169 /*map the partition <partId> into partition name <partName>*/
171 MapPartIdIntoName(afs_int32 partId, char *partName)
173 if (partId < 26) { /* what if partId > = 26 ? */
174 strcpy(partName, "/vicep");
175 partName[6] = partId + 'a';
178 } else if (partId < VOLMAXPARTS) {
179 strcpy(partName, "/vicep");
181 partName[6] = 'a' + (partId / 26);
182 partName[7] = 'a' + (partId % 26);
194 fprintf(STDERR, "Do you want to %s? [yn](n): ", str);
195 response = c = getchar();
196 while (!(c == EOF || c == '\n'))
197 c = getchar(); /*skip to end of line */
198 code = (response == 'y' || response == 'Y');
204 PrintError(char *msg, afs_int32 errcode)
206 fprintf(STDERR, msg);
207 /*replace by a big switch statement */
212 fprintf(STDERR, "Possible communication failure\n");
215 fprintf(STDERR, "Volume needs to be salvaged\n");
218 fprintf(STDERR, "Bad vnode number quoted\n");
222 "Volume not attached, does not exist, or not on line\n");
225 fprintf(STDERR, "Volume already exists\n");
228 fprintf(STDERR, "Volume is not in service\n");
231 fprintf(STDERR, "Volume is off line\n");
234 fprintf(STDERR, "Volume is already on line\n");
237 fprintf(STDERR, "Partition is full\n");
240 fprintf(STDERR, "Volume max quota exceeded\n");
243 fprintf(STDERR, "Volume temporarily unavailable\n");
246 fprintf(STDERR, "Volume has moved to another server\n");
249 fprintf(STDERR, "VLDB: volume Id exists in the vldb\n");
252 fprintf(STDERR, "VLDB: a read terminated too early\n");
255 fprintf(STDERR, "VLDB: volume entry exists in the vldb\n");
258 fprintf(STDERR, "VLDB: internal creation failure\n");
261 fprintf(STDERR, "VLDB: no such entry\n");
264 fprintf(STDERR, "VLDB: vldb database is empty\n");
267 fprintf(STDERR, "VLDB: entry is deleted (soft delete)\n");
270 fprintf(STDERR, "VLDB: volume name is illegal\n");
273 fprintf(STDERR, "VLDB: index was out of range\n");
276 fprintf(STDERR, "VLDB: bad volume type\n");
279 fprintf(STDERR, "VLDB: illegal server number (not within limits)\n");
281 case VL_BADPARTITION:
282 fprintf(STDERR, "VLDB: bad partition number\n");
285 fprintf(STDERR, "VLDB: run out of space for replication sites\n");
288 fprintf(STDERR, "VLDB: no such repsite server exists\n");
290 case VL_DUPREPSERVER:
291 fprintf(STDERR, "VLDB: replication site server already exists\n");
294 fprintf(STDERR, "VLDB: parent r/w entry not found\n");
297 fprintf(STDERR, "VLDB: illegal reference count number\n");
299 case VL_SIZEEXCEEDED:
300 fprintf(STDERR, "VLDB: vldb size for attributes exceeded\n");
303 fprintf(STDERR, "VLDB: bad incoming vldb entry\n");
305 case VL_BADVOLIDBUMP:
306 fprintf(STDERR, "VLDB: illegal max volid increment\n");
308 case VL_IDALREADYHASHED:
309 fprintf(STDERR, "VLDB: (RO/BACK) Id already hashed\n");
312 fprintf(STDERR, "VLDB: vldb entry is already locked\n");
315 fprintf(STDERR, "VLDB: bad volume operation code\n");
317 case VL_BADRELLOCKTYPE:
318 fprintf(STDERR, "VLDB: bad release lock type\n");
321 fprintf(STDERR, "VLDB: status report: last release was aborted\n");
323 case VL_BADSERVERFLAG:
324 fprintf(STDERR, "VLDB: invalid replication site server flag\n");
327 fprintf(STDERR, "VLDB: no permission access for call\n");
329 case VOLSERREAD_DUMPERROR:
331 "VOLSER: Problems encountered in reading the dump file !\n");
333 case VOLSERDUMPERROR:
334 fprintf(STDERR, "VOLSER: Problems encountered in doing the dump !\n");
336 case VOLSERATTACH_ERROR:
337 fprintf(STDERR, "VOLSER: Could not attach the volume\n");
339 case VOLSERDETACH_ERROR:
340 fprintf(STDERR, "VOLSER: Could not detach the volume\n");
342 case VOLSERILLEGAL_PARTITION:
343 fprintf(STDERR, "VOLSER: encountered illegal partition number\n");
345 case VOLSERBAD_ACCESS:
346 fprintf(STDERR, "VOLSER: permission denied, not a super user\n");
348 case VOLSERVLDB_ERROR:
349 fprintf(STDERR, "VOLSER: error detected in the VLDB\n");
352 fprintf(STDERR, "VOLSER: error in volume name\n");
355 fprintf(STDERR, "VOLSER: volume has moved\n");
358 fprintf(STDERR, "VOLSER: illegal operation\n");
360 case VOLSERBADRELEASE:
361 fprintf(STDERR, "VOLSER: release could not be completed\n");
364 fprintf(STDERR, "VOLSER: volume is busy\n");
366 case VOLSERNO_MEMORY:
367 fprintf(STDERR, "VOLSER: volume server is out of memory\n");
371 "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
373 case VOLSERMULTIRWVOL:
375 "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
379 "VOLSER: not all entries were successfully processed\n");
386 initialize_KA_error_table();
387 initialize_RXK_error_table();
388 initialize_KTC_error_table();
389 initialize_ACFG_error_table();
390 initialize_CMD_error_table();
391 initialize_VL_error_table();
393 offset = errcode & ((1 << ERRCODE_RANGE) - 1);
394 fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
395 afs_error_message(errcode));
402 void init_volintInfo(struct volintInfo *vinfo) {
403 memset(vinfo, 0, sizeof(struct volintInfo));
405 vinfo->maxquota = -1;
407 vinfo->creationDate = -1;
408 vinfo->updateDate = -1;
416 static struct rx_securityClass *uvclass = 0;
417 static int uvindex = -1;
418 /* called by VLDBClient_Init to set the security module to be used in the RPC */
420 UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
427 /* bind to volser on <port> <aserver> */
428 /* takes server address in network order, port in host order. dumb */
429 struct rx_connection *
430 UV_Bind(afs_int32 aserver, afs_int32 port)
432 register struct rx_connection *tc;
434 tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
439 /* if <okvol> is allright(indicated by beibg able to
440 * start a transaction, delete the <delvol> */
442 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
443 afs_int32 okvol, afs_int32 delvol)
445 afs_int32 error, code, tid, rcode;
451 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
454 code = AFSVolDeleteVolume(aconn, tid);
457 code = AFSVolEndTrans(aconn, tid, &rcode);
464 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
466 code = AFSVolEndTrans(aconn, tid, &rcode);
471 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
474 code = AFSVolDeleteVolume(aconn, tid);
477 code = AFSVolEndTrans(aconn, tid, &rcode);
488 /* called by EmuerateEntry, show vldb entry in a reasonable format */
490 SubEnumerateEntry(struct nvldbentry *entry)
497 fprintf(STDOUT, " readWriteID %-10u ", entry->volumeId[RWVOL]);
498 if (entry->flags & RW_EXISTS)
499 fprintf(STDOUT, " valid \n");
501 fprintf(STDOUT, " invalid \n");
502 fprintf(STDOUT, " readOnlyID %-10u ", entry->volumeId[ROVOL]);
503 if (entry->flags & RO_EXISTS)
504 fprintf(STDOUT, " valid \n");
506 fprintf(STDOUT, " invalid \n");
507 fprintf(STDOUT, " backUpID %-10u ", entry->volumeId[BACKVOL]);
508 if (entry->flags & BACK_EXISTS)
509 fprintf(STDOUT, " valid \n");
511 fprintf(STDOUT, " invalid \n");
512 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
513 fprintf(STDOUT, " releaseClone %-10u \n", entry->cloneId);
515 if (entry->flags & RW_EXISTS)
516 fprintf(STDOUT, " RWrite: %-10u", entry->volumeId[RWVOL]);
517 if (entry->flags & RO_EXISTS)
518 fprintf(STDOUT, " ROnly: %-10u", entry->volumeId[ROVOL]);
519 if (entry->flags & BACK_EXISTS)
520 fprintf(STDOUT, " Backup: %-10u", entry->volumeId[BACKVOL]);
521 if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
522 fprintf(STDOUT, " RClone: %-10lu", (unsigned long)entry->cloneId);
523 fprintf(STDOUT, "\n");
525 fprintf(STDOUT, " number of sites -> %lu\n",
526 (unsigned long)entry->nServers);
527 for (i = 0; i < entry->nServers; i++) {
528 if (entry->serverFlags[i] & NEW_REPSITE)
531 for (i = 0; i < entry->nServers; i++) {
532 MapPartIdIntoName(entry->serverPartition[i], pname);
533 fprintf(STDOUT, " server %s partition %s ",
534 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
535 if (entry->serverFlags[i] & ITSRWVOL)
536 fprintf(STDOUT, "RW Site ");
538 fprintf(STDOUT, "RO Site ");
540 if (entry->serverFlags[i] & NEW_REPSITE)
541 fprintf(STDOUT," -- New release");
543 if (!(entry->serverFlags[i] & ITSRWVOL))
544 fprintf(STDOUT," -- Old release");
546 if (entry->serverFlags[i] & RO_DONTUSE)
547 fprintf(STDOUT, " -- Not released");
549 fprintf(STDOUT, "\n");
556 /*enumerate the vldb entry corresponding to <entry> */
558 EnumerateEntry(struct nvldbentry *entry)
561 fprintf(STDOUT, "\n");
562 fprintf(STDOUT, "%s \n", entry->name);
563 SubEnumerateEntry(entry);
567 /* forcibly remove a volume. Very dangerous call */
569 UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
571 register struct rx_connection *tconn;
572 register afs_int32 code;
574 tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
576 code = AFSVolNukeVolume(tconn, partid, volid);
577 rx_DestroyConnection(tconn);
583 /* like df. Return usage of <pname> on <server> in <partition> */
585 UV_PartitionInfo(afs_int32 server, char *pname,
586 struct diskPartition *partition)
588 register struct rx_connection *aconn;
592 aconn = (struct rx_connection *)0;
593 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
594 code = AFSVolPartitionInfo(aconn, pname, partition);
596 fprintf(STDERR, "Could not get information on partition %s\n", pname);
597 PrintError("", code);
600 rx_DestroyConnection(aconn);
604 /* old interface to create volume */
606 UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
610 code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
614 /* create a volume, given a server, partition number, volume name --> sends
615 * back new vol id in <anewid>*/
617 UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
618 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
619 afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
622 register struct rx_connection *aconn;
624 register afs_int32 code;
626 afs_int32 rcode, vcode;
627 struct nvldbentry entry, storeEntry; /*the new vldb entry */
628 struct volintInfo tstatus;
631 aconn = (struct rx_connection *)0;
634 init_volintInfo(&tstatus);
635 tstatus.maxquota = aquota;
637 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
638 /* next the next 3 available ids from the VLDB */
639 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 3, anewid);
640 EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
643 AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
644 EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
647 code = AFSVolSetInfo(aconn, tid, &tstatus);
649 EPRINT(code, "Could not change quota (error %d), continuing...\n");
651 code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
652 EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
655 VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
657 /* set up the vldb entry for this volume */
658 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
660 entry.serverNumber[0] = aserver; /* this should have another
661 * level of indirection later */
662 entry.serverPartition[0] = apart; /* this should also have
663 * another indirection level */
664 entry.flags = RW_EXISTS; /* this records that rw volume exists */
665 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
666 entry.volumeId[RWVOL] = *anewid;
667 entry.volumeId[ROVOL] = *anewid + 1; /* rw,ro, bk id are related in the default case */
668 entry.volumeId[BACKVOL] = *anewid + 2;
670 /*map into right byte order, before passing to xdr, the stuff has to be in host
671 * byte order. Xdr converts it into network order */
672 MapNetworkToHost(&entry, &storeEntry);
673 /* create the vldb entry */
674 vcode = VLDB_CreateEntry(&storeEntry);
677 "Could not create a VLDB entry for the volume %s %lu\n",
678 aname, (unsigned long)*anewid);
679 /*destroy the created volume */
680 VPRINT1("Deleting the newly created volume %u\n", *anewid);
681 AFSVolDeleteVolume(aconn, tid);
685 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid);
686 /* volume created, now terminate the transaction and release the connection */
687 code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this
688 * the volume will come online anyway when transaction timesout , so if
689 * vldb entry exists then the volume is guaranteed to exist too wrt create */
693 "Failed to end the transaction on the volume %s %lu\n", aname,
694 (unsigned long)*anewid);
701 code = AFSVolEndTrans(aconn, tid, &rcode);
703 fprintf(STDERR, "WARNING: could not end transaction\n");
706 rx_DestroyConnection(aconn);
707 PrintError("", error);
713 /* create a volume, given a server, partition number, volume name --> sends
714 * back new vol id in <anewid>*/
716 UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
719 register struct rx_connection *aconn;
722 struct nvldbentry entry, storeEntry; /*the new vldb entry */
724 aconn = (struct rx_connection *)0;
727 /* set up the vldb entry for this volume */
728 strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
730 entry.serverNumber[0] = aserver; /* this should have another
731 * level of indirection later */
732 entry.serverPartition[0] = apart; /* this should also have
733 * another indirection level */
734 entry.flags = RW_EXISTS; /* this records that rw volume exists */
735 entry.serverFlags[0] = ITSRWVOL; /*this rep site has rw vol */
736 entry.volumeId[RWVOL] = aid;
738 entry.volumeId[ROVOL] = anewid + 1; /* rw,ro, bk id are related in the default case */
739 entry.volumeId[BACKVOL] = *anewid + 2;
741 entry.volumeId[ROVOL] = 0;
742 entry.volumeId[BACKVOL] = 0;
745 /*map into right byte order, before passing to xdr, the stuff has to be in host
746 * byte order. Xdr converts it into network order */
747 MapNetworkToHost(&entry, &storeEntry);
748 /* create the vldb entry */
749 vcode = VLDB_CreateEntry(&storeEntry);
752 "Could not create a VLDB entry for the volume %s %lu\n",
753 aname, (unsigned long)aid);
757 VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid);
761 rx_DestroyConnection(aconn);
762 PrintError("", error);
766 /* Delete the volume <volid>on <aserver> <apart>
767 * the physical entry gets removed from the vldb only if the ref count
771 UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
773 struct rx_connection *aconn = (struct rx_connection *)0;
775 afs_int32 code, rcode;
777 struct nvldbentry entry, storeEntry;
779 afs_int32 avoltype = -1, vtype;
780 int notondisk = 0, notinvldb = 0;
782 /* Find and read bhe VLDB entry for this volume */
783 code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE);
785 if (code != VL_NOENT) {
786 EGOTO1(error_exit, code,
787 "Could not lock VLDB entry for the volume %u\n", avolid);
793 code = VLDB_GetEntryByID(avolid, avoltype, &entry);
794 EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",
796 MapHostToNetwork(&entry);
799 EnumerateEntry(&entry);
802 /* Whether volume is in the VLDB or not. Delete the volume on disk */
803 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
804 code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
806 if (code == VNOVOL) {
809 EGOTO1(error_exit, code, "Transaction on volume %u failed\n",
813 VPRINT1("Trying to delete the volume %u ...", avolid);
815 code = AFSVolDeleteVolume(aconn, ttid);
816 EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid);
818 code = AFSVolEndTrans(aconn, ttid, &rcode);
819 code = (code ? code : rcode);
821 EGOTO1(error_exit, code,
822 "Could not end the transaction for the volume %u \n", avolid);
826 /* Now update the VLDB entry.
827 * But first, verify we have a VLDB entry.
828 * Whether volume is on disk or not. Delete the volume in VLDB.
833 if (avolid == entry.volumeId[BACKVOL]) {
834 /* Its a backup volume, modify the VLDB entry. Check that the
835 * backup volume is on the server/partition we asked to delete.
837 if (!(entry.flags & BACK_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
838 notinvldb = 2; /* Not on this server and partition */
842 VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid);
844 entry.flags &= ~BACK_EXISTS;
848 else if (avolid == entry.volumeId[ROVOL]) {
849 /* Its a read-only volume, modify the VLDB entry. Check that the
850 * readonly volume is on the server/partition we asked to delete.
851 * If flags does not have RO_EIXSTS set, then this may mean the RO
852 * hasn't been released (and could exist in VLDB).
854 if (!Lp_ROMatch(aserver, apart, &entry)) {
855 notinvldb = 2; /* Not found on this server and partition */
861 "Marking the readonly volume %lu deleted in the VLDB\n",
862 (unsigned long)avolid);
864 Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */
866 if (!Lp_ROMatch(0, 0, &entry))
867 entry.flags &= ~RO_EXISTS; /* This was the last ro volume */
871 else if (avolid == entry.volumeId[RWVOL]) {
872 /* It's a rw volume, delete the backup volume, modify the VLDB entry.
873 * Check that the readwrite volumes is on the server/partition we
876 if (!(entry.flags & RW_EXISTS) || !Lp_Match(aserver, apart, &entry)) {
877 notinvldb = 2; /* Not found on this server and partition */
881 /* Delete backup if it exists */
883 AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
887 fprintf(STDOUT, "Trying to delete the backup volume %u ...",
888 entry.volumeId[BACKVOL]);
891 code = AFSVolDeleteVolume(aconn, ttid);
892 EGOTO1(error_exit, code, "Could not delete the volume %u \n",
893 entry.volumeId[BACKVOL]);
895 code = AFSVolEndTrans(aconn, ttid, &rcode);
897 code = (code ? code : rcode);
898 EGOTO1(error_exit, code,
899 "Could not end the transaction for the volume %u \n",
900 entry.volumeId[BACKVOL]);
902 fprintf(STDOUT, " done\n");
907 "Marking the readwrite volume %lu%s deleted in the VLDB\n",
908 (unsigned long)avolid,
910 flags & BACK_EXISTS) ? ", and its backup volume," :
913 Lp_SetRWValue(&entry, aserver, apart, 0L, 0L);
915 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
918 if (entry.flags & RO_EXISTS)
919 fprintf(STDERR, "WARNING: ReadOnly copy(s) may still exist\n");
923 notinvldb = 2; /* Not found on this server and partition */
927 /* Either delete or replace the VLDB entry */
928 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
931 "Last reference to the VLDB entry for %lu - deleting entry\n",
932 (unsigned long)avolid);
933 code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype);
934 EGOTO1(error_exit, code,
935 "Could not delete the VLDB entry for the volume %u \n",
938 MapNetworkToHost(&entry, &storeEntry);
940 VLDB_ReplaceEntry(avolid, vtype, &storeEntry,
941 (LOCKREL_OPCODE | LOCKREL_AFSID |
943 EGOTO1(error_exit, code,
944 "Could not update the VLDB entry for the volume %u \n",
953 if (notondisk && notinvldb) {
954 EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,
955 ((notinvldb == 2) ? "on server and partition" : ""));
958 } else if (notondisk) {
960 "WARNING: Volume %lu did not exist on the partition\n",
961 (unsigned long)avolid);
962 } else if (notinvldb) {
963 fprintf(STDERR, "WARNING: Volume %lu does not exist in VLDB %s\n",
964 (unsigned long)avolid,
965 ((notinvldb == 2) ? "on server and partition" : ""));
969 code = AFSVolEndTrans(aconn, ttid, &rcode);
970 code = (code ? code : rcode);
972 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
973 (unsigned long)avolid);
974 PrintError("", code);
982 ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
983 (LOCKREL_OPCODE | LOCKREL_AFSID |
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. The following
1026 * flags are recognized:
1028 * RV_NOCLONE - don't use a copy clone
1032 UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1033 afs_int32 atoserver, afs_int32 atopart, int flags)
1035 struct rx_connection *toconn, *fromconn;
1036 afs_int32 fromtid, totid, clonetid;
1039 char tmpName[VOLSER_MAXVOLNAME + 1];
1042 struct restoreCookie cookie;
1043 register afs_int32 vcode, code;
1044 afs_int32 newVol, volid, backupId;
1045 struct volser_status tstatus;
1046 struct destServer destination;
1048 struct nvldbentry entry, storeEntry;
1049 int i, islocked, pntg;
1051 char in, lf; /* for test code */
1054 #ifdef ENABLE_BUGFIX_1165
1055 volEntries volumeInfo;
1056 struct volintInfo *infop = 0;
1060 fromconn = (struct rx_connection *)0;
1061 toconn = (struct rx_connection *)0;
1071 /* support control-c processing */
1074 (void)signal(SIGINT, sigint_handler);
1078 "\nThere are three tests points - verifies all code paths through recovery.\n");
1079 fprintf(STDOUT, "First test point - operation not started.\n");
1080 fprintf(STDOUT, "...test here (y, n)? ");
1082 fscanf(stdin, "%c", &in);
1083 fscanf(stdin, "%c", &lf); /* toss away */
1085 fprintf(STDOUT, "type control-c\n");
1087 fprintf(stdout, ".");
1092 /* or drop through */
1095 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1096 EGOTO1(mfail, vcode,
1097 "Could not fetch the entry for the volume %u from the VLDB \n",
1100 if (entry.volumeId[RWVOL] != afromvol) {
1101 fprintf(STDERR, "Only RW volume can be moved\n");
1105 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_MOVE);
1106 EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol);
1109 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
1110 EGOTO1(mfail, vcode,
1111 "Could not fetch the entry for the volume %u from the VLDB \n",
1114 backupId = entry.volumeId[BACKVOL];
1115 MapHostToNetwork(&entry);
1117 if (!Lp_Match(afromserver, afrompart, &entry)) {
1118 /* the from server and partition do not exist in the vldb entry corresponding to volid */
1119 if (!Lp_Match(atoserver, atopart, &entry)) {
1120 /* the to server and partition do not exist in the vldb entry corresponding to volid */
1121 fprintf(STDERR, "The volume %lu is not on the specified site. \n",
1122 (unsigned long)afromvol);
1123 fprintf(STDERR, "The current site is :");
1124 for (i = 0; i < entry.nServers; i++) {
1125 if (entry.serverFlags[i] == ITSRWVOL) {
1127 MapPartIdIntoName(entry.serverPartition[i], pname);
1128 fprintf(STDERR, " server %s partition %s \n",
1129 hostutil_GetNameByINet(entry.serverNumber[i]),
1134 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1135 (LOCKREL_OPCODE | LOCKREL_AFSID |
1136 LOCKREL_TIMESTAMP));
1137 EGOTO1(mfail, vcode,
1138 " Could not release lock on the VLDB entry for the volume %u \n",
1141 return VOLSERVOLMOVED;
1144 /* delete the volume afromvol on src_server */
1145 /* from-info does not exist but to-info does =>
1146 * we have already done the move, but the volume
1147 * may still be existing physically on from fileserver
1149 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1154 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
1156 if (!code) { /* volume exists - delete it */
1157 VPRINT1("Setting flags on leftover source volume %u ...",
1160 AFSVolSetFlags(fromconn, fromtid,
1161 VTDeleteOnSalvage | VTOutOfService);
1163 "Failed to set flags on the leftover source volume %u\n",
1167 VPRINT1("Deleting leftover source volume %u ...", afromvol);
1168 code = AFSVolDeleteVolume(fromconn, fromtid);
1170 "Failed to delete the leftover source volume %u\n",
1174 VPRINT1("Ending transaction on leftover source volume %u ...",
1176 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1181 "Could not end the transaction for the leftover source volume %u \n",
1186 /*delete the backup volume now */
1189 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1191 if (!code) { /* backup volume exists - delete it */
1192 VPRINT1("Setting flags on leftover backup volume %u ...",
1195 AFSVolSetFlags(fromconn, fromtid,
1196 VTDeleteOnSalvage | VTOutOfService);
1198 "Failed to set flags on the backup volume %u\n", backupId);
1201 VPRINT1("Deleting leftover backup volume %u ...", backupId);
1202 code = AFSVolDeleteVolume(fromconn, fromtid);
1204 "Could not delete the leftover backup volume %u\n",
1208 VPRINT1("Ending transaction on leftover backup volume %u ...",
1210 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1215 "Could not end the transaction for the leftover backup volume %u\n",
1225 /* From-info matches the vldb info about volid,
1226 * its ok start the move operation, the backup volume
1227 * on the old site is deleted in the process
1229 if (afrompart == atopart) {
1230 same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
1231 EGOTO2(mfail, error,
1232 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
1233 afromserver, error);
1236 EGOTO1(mfail, VOLSERVOLMOVED,
1237 "Warning: Moving volume %u to its home partition ignored!\n",
1243 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
1244 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
1245 fromtid = totid = 0; /* initialize to uncreated */
1248 * clone the read/write volume locally.
1251 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1252 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1253 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
1257 if (!(flags & RV_NOCLONE)) {
1258 /* Get a clone id */
1259 VPRINT1("Allocating new volume id for clone of volume %u ...",
1262 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
1263 EGOTO1(mfail, vcode,
1264 "Could not get an ID for the clone of volume %u from the VLDB\n",
1268 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
1269 VPRINT1("Cloning source volume %u ...", afromvol);
1270 strcpy(vname, "move-clone-temp");
1272 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
1273 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
1278 /* lookup the name of the volume we just cloned */
1280 code = AFSVolGetName(fromconn, fromtid, &volName);
1281 EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",
1284 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
1286 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1291 "Failed to end the transaction on the source volume %u\n",
1296 * Create the destination volume
1299 if (!(flags & RV_NOCLONE)) {
1300 /* All of this is to get the fromDate */
1301 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1303 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1306 "Failed to start a transaction on the cloned volume%u\n",
1310 VPRINT1("Setting flags on cloned volume %u ...", newVol);
1312 AFSVolSetFlags(fromconn, clonetid,
1313 VTDeleteOnSalvage | VTOutOfService); /*redundant */
1314 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
1318 /* remember time from which we've dumped the volume */
1319 VPRINT1("Getting status of cloned volume %u ...", newVol);
1320 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
1322 "Failed to get the status of the cloned volume %u\n",
1326 fromDate = CLOCKADJ(tstatus.creationDate);
1328 /* With RV_NOCLONE, just do a full copy from the source */
1333 #ifdef ENABLE_BUGFIX_1165
1335 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
1336 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
1337 * don't use this information...
1339 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
1340 volumeInfo.volEntries_len = 0;
1341 code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
1343 "Failed to get the volint Info of the cloned volume %u\n",
1346 infop = (volintInfo *) volumeInfo.volEntries_val;
1347 infop->maxquota = -1; /* Else it will replace the default quota */
1348 infop->creationDate = -1; /* Else it will use the source creation date */
1349 infop->updateDate = -1; /* Else it will use the source update date */
1352 /* create a volume on the target machine */
1354 code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1356 /* Delete the existing volume.
1357 * While we are deleting the volume in these steps, the transaction
1358 * we started against the cloned volume (clonetid above) will be
1359 * sitting idle. It will get cleaned up after 600 seconds
1361 VPRINT1("Deleting pre-existing volume %u on destination ...", volid);
1362 code = AFSVolDeleteVolume(toconn, totid);
1364 "Could not delete the pre-existing volume %u on destination\n",
1369 ("Ending transaction on pre-existing volume %u on destination ...",
1371 code = AFSVolEndTrans(toconn, totid, &rcode);
1376 "Could not end the transaction on pre-existing volume %u on destination\n",
1381 VPRINT1("Creating the destination volume %u ...", volid);
1383 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
1385 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
1389 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
1393 VPRINT1("Setting volume flags on destination volume %u ...", volid);
1395 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
1397 "Failed to set the flags on the destination volume %u\n", volid);
1401 * Now dump the clone to the new volume
1404 destination.destHost = ntohl(atoserver);
1405 destination.destPort = AFSCONF_VOLUMEPORT;
1406 destination.destSSID = 1;
1408 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
1409 cookie.type = RWVOL;
1410 cookie.parent = entry.volumeId[RWVOL];
1413 if (!(flags & RV_NOCLONE)) {
1414 /* Copy the clone to the new volume */
1415 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
1418 AFSVolForward(fromconn, clonetid, 0, &destination, totid,
1420 EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid);
1423 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1424 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1429 "Failed to end the transaction on the cloned volume %u\n",
1435 * reattach to the main-line volume, and incrementally dump it.
1438 VPRINT1("Starting transaction on source volume %u ...", afromvol);
1439 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
1441 "Failed to create a transaction on the source volume %u\n",
1445 /* now do the incremental */
1447 ("Doing the%s dump from source to destination for volume %u ... ",
1448 (flags & RV_NOCLONE) ? "" : " incremental",
1451 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
1454 "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",
1455 (flags & RV_NOCLONE) ? "" : " incremental");
1458 /* now adjust the flags so that the new volume becomes official */
1459 VPRINT1("Setting volume flags on old source volume %u ...", afromvol);
1460 code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
1462 "Failed to set the flags to make old source volume offline\n");
1465 VPRINT1("Setting volume flags on new source volume %u ...", afromvol);
1466 code = AFSVolSetFlags(toconn, totid, 0);
1468 "Failed to set the flags to make new source volume online\n");
1471 #ifdef ENABLE_BUGFIX_1165
1472 VPRINT1("Setting volume status on destination volume %u ...", volid);
1473 code = AFSVolSetInfo(toconn, totid, infop);
1475 "Failed to set volume status on the destination volume %u\n",
1480 /* put new volume online */
1481 VPRINT1("Ending transaction on destination volume %u ...", afromvol);
1482 code = AFSVolEndTrans(toconn, totid, &rcode);
1487 "Failed to end the transaction on the volume %u on the new site\n",
1491 Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart);
1492 MapNetworkToHost(&entry, &storeEntry);
1493 storeEntry.flags &= ~BACK_EXISTS;
1497 "Second test point - operation in progress but not complete.\n");
1498 fprintf(STDOUT, "...test here (y, n)? ");
1500 fscanf(stdin, "%c", &in);
1501 fscanf(stdin, "%c", &lf); /* toss away */
1503 fprintf(STDOUT, "type control-c\n");
1505 fprintf(stdout, ".");
1510 /* or drop through */
1513 VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol);
1515 VLDB_ReplaceEntry(afromvol, -1, &storeEntry,
1516 (LOCKREL_OPCODE | LOCKREL_AFSID |
1517 LOCKREL_TIMESTAMP));
1520 " Could not release the lock on the VLDB entry for the volume %s %lu \n",
1521 storeEntry.name, (unsigned long)afromvol);
1530 "Third test point - operation complete but no cleanup.\n");
1531 fprintf(STDOUT, "...test here (y, n)? ");
1533 fscanf(stdin, "%c", &in);
1534 fscanf(stdin, "%c", &lf); /* toss away */
1536 fprintf(STDOUT, "type control-c\n");
1538 fprintf(stdout, ".");
1543 /* or drop through */
1546 /* This is tricky. File server is very stupid, and if you mark the volume
1547 * as VTOutOfService, it may mark the *good* instance (if you're moving
1548 * between partitions on the same machine) as out of service. Since
1549 * we're cleaning this code up in DEcorum, we're just going to kludge around
1550 * it for now by removing this call. */
1551 /* already out of service, just zap it now */
1553 AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
1556 "Failed to set the flags to make the old source volume offline\n");
1560 if (atoserver != afromserver) {
1561 /* set forwarding pointer for moved volumes */
1562 VPRINT1("Setting forwarding pointer for volume %u ...", afromvol);
1563 code = AFSVolSetForwarding(fromconn, fromtid, atoserver);
1565 "Failed to set the forwarding pointer for the volume %u\n",
1570 VPRINT1("Deleting old volume %u on source ...", afromvol);
1571 code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
1572 EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",
1576 VPRINT1("Ending transaction on old volume %u on the source ...",
1578 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1583 "Failed to end the transaction on the old volume %u on the source\n",
1587 /* Delete the backup volume on the original site */
1588 VPRINT1("Creating transaction for backup volume %u on source ...",
1591 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
1594 VPRINT1("Setting flags on backup volume %u on source ...", backupId);
1596 AFSVolSetFlags(fromconn, fromtid,
1597 VTDeleteOnSalvage | VTOutOfService);
1599 "Failed to set the flags on the backup volume %u on the source\n",
1603 VPRINT1("Deleting the backup volume %u on the source ...", backupId);
1604 code = AFSVolDeleteVolume(fromconn, fromtid);
1606 "Failed to delete the backup volume %u on the source\n",
1610 VPRINT1("Ending transaction on backup volume %u on source ...",
1612 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1617 "Failed to end the transaction on the backup volume %u on the source\n",
1621 code = 0; /* no backup volume? that's okay */
1624 if (!(flags & RV_NOCLONE)) {
1625 VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
1627 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1630 "Failed to start a transaction on the cloned volume%u\n",
1634 /* now delete the clone */
1635 VPRINT1("Deleting the cloned volume %u ...", newVol);
1636 code = AFSVolDeleteVolume(fromconn, clonetid);
1637 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
1641 VPRINT1("Ending transaction on cloned volume %u ...", newVol);
1642 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1647 "Failed to end the transaction on the cloned volume %u\n",
1656 fprintf(STDOUT, "Fourth test point - operation complete.\n");
1657 fprintf(STDOUT, "...test here (y, n)? ");
1659 fscanf(stdin, "%c", &in);
1660 fscanf(stdin, "%c", &lf); /* toss away */
1662 fprintf(STDOUT, "type control-c\n");
1664 fprintf(stdout, ".");
1669 /* or drop through */
1672 /* normal cleanup code */
1674 if (entry.flags & RO_EXISTS)
1675 fprintf(STDERR, "WARNING : readOnly copies still exist \n");
1678 VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol);
1680 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1681 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1685 " Could not release the lock on the VLDB entry for the volume %lu \n",
1686 (unsigned long)afromvol);
1694 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
1696 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
1697 if (code || rcode) {
1700 "Could not end transaction on the source volume %lu\n",
1701 (unsigned long)afromvol);
1703 error = (code ? code : rcode);
1709 VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol);
1710 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
1711 if (code || rcode) {
1714 "Could not end transaction on the source's clone volume %lu\n",
1715 (unsigned long)newVol);
1717 error = (code ? code : rcode);
1723 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
1725 code = AFSVolEndTrans(toconn, totid, &rcode);
1729 "Could not end transaction on destination volume %lu\n",
1730 (unsigned long)afromvol);
1732 error = (code ? code : rcode);
1738 #ifdef ENABLE_BUGFIX_1165
1743 rx_DestroyConnection(fromconn);
1745 rx_DestroyConnection(toconn);
1746 PrintError("", error);
1749 /* come here only when the sky falls */
1754 "vos move: operation interrupted, cleanup in progress...\n");
1755 fprintf(STDOUT, "clear transaction contexts\n");
1759 /* unlock VLDB entry */
1761 VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol);
1762 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1763 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1768 VPRINT("Recovery: Ending transaction on clone volume ...");
1769 AFSVolEndTrans(fromconn, clonetid, &rcode);
1773 VPRINT("Recovery: Ending transaction on destination volume ...");
1774 AFSVolEndTrans(toconn, totid, &rcode);
1777 if (fromtid) { /* put it on-line */
1778 VPRINT("Recovery: Setting volume flags on source volume ...");
1779 AFSVolSetFlags(fromconn, fromtid, 0);
1782 VPRINT("Recovery: Ending transaction on source volume ...");
1783 AFSVolEndTrans(fromconn, fromtid, &rcode);
1787 VPRINT("Recovery: Accessing VLDB.\n");
1788 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
1790 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
1794 MapHostToNetwork(&entry);
1796 /* Delete either the volume on the source location or the target location.
1797 * If the vldb entry still points to the source location, then we know the
1798 * volume move didn't finish so we remove the volume from the target
1799 * location. Otherwise, we remove the volume from the source location.
1801 if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */
1804 "move incomplete - attempt cleanup of target partition - no guarantee\n");
1808 if (volid && toconn) {
1810 ("Recovery: Creating transaction for destination volume %u ...",
1813 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
1819 ("Recovery: Setting flags on destination volume %u ...",
1821 AFSVolSetFlags(toconn, totid,
1822 VTDeleteOnSalvage | VTOutOfService);
1825 VPRINT1("Recovery: Deleting destination volume %u ...",
1827 AFSVolDeleteVolume(toconn, totid);
1831 ("Recovery: Ending transaction on destination volume %u ...",
1833 AFSVolEndTrans(toconn, totid, &rcode);
1837 ("\nRecovery: Unable to start transaction on destination volume %u.\n",
1842 /* put source volume on-line */
1844 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1847 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1852 VPRINT1("Recovery: Setting flags on source volume %u ...",
1854 AFSVolSetFlags(fromconn, fromtid, 0);
1858 ("Recovery: Ending transaction on source volume %u ...",
1860 AFSVolEndTrans(fromconn, fromtid, &rcode);
1864 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1868 } else { /* yep, move complete */
1871 "move complete - attempt cleanup of source partition - no guarantee\n");
1875 /* delete backup volume */
1877 VPRINT1("Recovery: Creating transaction on backup volume %u ...",
1880 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
1885 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1887 AFSVolSetFlags(fromconn, fromtid,
1888 VTDeleteOnSalvage | VTOutOfService);
1891 VPRINT1("Recovery: Deleting backup volume %u ...", backupId);
1892 AFSVolDeleteVolume(fromconn, fromtid);
1896 ("Recovery: Ending transaction on backup volume %u ...",
1898 AFSVolEndTrans(fromconn, fromtid, &rcode);
1902 ("\nRecovery: Unable to start transaction on backup volume %u.\n",
1906 /* delete source volume */
1907 VPRINT1("Recovery: Creating transaction on source volume %u ...",
1910 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1915 VPRINT1("Recovery: Setting flags on backup volume %u ...",
1917 AFSVolSetFlags(fromconn, fromtid,
1918 VTDeleteOnSalvage | VTOutOfService);
1921 if (atoserver != afromserver) {
1922 VPRINT("Recovery: Setting volume forwarding pointer ...");
1923 AFSVolSetForwarding(fromconn, fromtid, atoserver);
1927 VPRINT1("Recovery: Deleting source volume %u ...", afromvol);
1928 AFSVolDeleteVolume(fromconn, fromtid);
1932 ("Recovery: Ending transaction on source volume %u ...",
1934 AFSVolEndTrans(fromconn, fromtid, &rcode);
1938 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1944 /* common cleanup - delete local clone */
1946 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
1949 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
1954 VPRINT1("Recovery: Deleting clone volume %u ...", newVol);
1955 AFSVolDeleteVolume(fromconn, clonetid);
1958 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
1960 AFSVolEndTrans(fromconn, clonetid, &rcode);
1964 ("\nRecovery: Unable to start transaction on source volume %u.\n",
1969 /* unlock VLDB entry */
1970 VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
1972 ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
1973 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1976 done: /* routine cleanup */
1979 #ifdef ENABLE_BUGFIX_1165
1984 rx_DestroyConnection(fromconn);
1986 rx_DestroyConnection(toconn);
1989 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
1997 UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
1998 afs_int32 atoserver, afs_int32 atopart)
2000 return UV_MoveVolume2(afromvol, afromserver, afrompart,
2001 atoserver, atopart, 0);
2005 /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver>
2006 * <atopart>. The new volume is named by <atovolname>. The new volume
2007 * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
2008 * from the VLDB. the following flags are supported:
2010 * RV_RDONLY - target volume is RO
2011 * RV_OFFLINE - leave target volume offline
2012 * RV_CPINCR - do incremental dump if target exists
2013 * RV_NOVLDB - don't create/update VLDB entry
2014 * RV_NOCLONE - don't use a copy clone
2017 UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2018 char *atovolname, afs_int32 atoserver, afs_int32 atopart,
2019 afs_int32 atovolid, int flags)
2021 struct rx_connection *toconn, *fromconn;
2022 afs_int32 fromtid, totid, clonetid;
2025 afs_int32 fromDate, cloneFromDate;
2026 struct restoreCookie cookie;
2027 register afs_int32 vcode, code;
2028 afs_int32 cloneVol, newVol, volflag;
2029 struct volser_status tstatus;
2030 struct destServer destination;
2032 struct nvldbentry entry, newentry, storeEntry;
2038 fromconn = (struct rx_connection *)0;
2039 toconn = (struct rx_connection *)0;
2047 /* support control-c processing */
2050 (void)signal(SIGINT, sigint_handler);
2052 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2053 EGOTO1(mfail, vcode,
2054 "Could not fetch the entry for the volume %u from the VLDB \n",
2056 MapHostToNetwork(&entry);
2059 toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
2060 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
2061 fromtid = totid = 0; /* initialize to uncreated */
2064 /* check if we can shortcut and use a local clone instead of a full copy */
2065 if (afromserver == atoserver && afrompart == atopart) {
2070 * clone the read/write volume locally.
2074 if (!(flags & RV_NOCLONE)) {
2075 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2076 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
2078 EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
2082 /* Get a clone id */
2083 VPRINT1("Allocating new volume id for clone of volume %u ...",
2086 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
2087 EGOTO1(mfail, vcode,
2088 "Could not get an ID for the clone of volume %u from the VLDB\n",
2096 /* Get a new volume id */
2097 VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol);
2099 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
2100 EGOTO1(mfail, vcode,
2101 "Could not get an ID for the copy of volume %u from the VLDB\n",
2106 if (!(flags & RV_NOCLONE)) {
2107 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
2108 VPRINT1("Cloning source volume %u ...", afromvol);
2109 strcpy(vname, "copy-clone-temp");
2111 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
2113 EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
2117 VPRINT1("Ending the transaction on the source volume %u ...", afromvol);
2119 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2124 "Failed to end the transaction on the source volume %u\n",
2130 * Create the destination volume
2133 if (!(flags & RV_NOCLONE)) {
2134 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2136 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2139 "Failed to start a transaction on the cloned volume%u\n",
2143 VPRINT1("Setting flags on cloned volume %u ...", cloneVol);
2145 AFSVolSetFlags(fromconn, clonetid,
2146 VTDeleteOnSalvage | VTOutOfService); /*redundant */
2147 EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",
2151 /* remember time from which we've dumped the volume */
2152 VPRINT1("Getting status of cloned volume %u ...", cloneVol);
2153 code = AFSVolGetStatus(fromconn, clonetid, &tstatus);
2155 "Failed to get the status of the cloned volume %u\n",
2159 fromDate = CLOCKADJ(tstatus.creationDate);
2164 /* create a volume on the target machine */
2166 code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
2168 if ((flags & RV_CPINCR)) {
2169 VPRINT1("Getting status of pre-existing volume %u ...", newVol);
2170 code = AFSVolGetStatus(toconn, totid, &tstatus);
2172 "Failed to get the status of the pre-existing volume %u\n",
2176 /* Using the update date should be OK here, but add some fudge */
2177 cloneFromDate = CLOCKADJ(tstatus.updateDate);
2178 if ((flags & RV_NOCLONE))
2179 fromDate = cloneFromDate;
2181 /* XXX We should check that the source volume's creationDate is
2182 * XXX not newer than the existing target volume, and if not,
2183 * XXX throw away the existing target and do a full dump. */
2188 /* Delete the existing volume.
2189 * While we are deleting the volume in these steps, the transaction
2190 * we started against the cloned volume (clonetid above) will be
2191 * sitting idle. It will get cleaned up after 600 seconds
2193 VPRINT1("Deleting pre-existing volume %u on destination ...", newVol);
2194 code = AFSVolDeleteVolume(toconn, totid);
2196 "Could not delete the pre-existing volume %u on destination\n",
2201 ("Ending transaction on pre-existing volume %u on destination ...",
2203 code = AFSVolEndTrans(toconn, totid, &rcode);
2208 "Could not end the transaction on pre-existing volume %u on destination\n",
2213 VPRINT1("Creating the destination volume %u ...", newVol);
2215 AFSVolCreateVolume(toconn, atopart, atovolname,
2216 (flags & RV_RDONLY) ? volser_RO : volser_RW,
2217 newVol, &newVol, &totid);
2218 EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
2222 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2224 AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
2226 "Failed to set the flags on the destination volume %u\n", newVol);
2231 destination.destHost = ntohl(atoserver);
2232 destination.destPort = AFSCONF_VOLUMEPORT;
2233 destination.destSSID = 1;
2235 strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME);
2236 cookie.type = (flags & RV_RDONLY) ? ROVOL : RWVOL;
2241 * Now dump the clone to the new volume
2244 if (!(flags & RV_NOCLONE)) {
2245 /* XXX probably should have some code here that checks to see if
2246 * XXX we are copying to same server and partition - if so, just
2247 * XXX use a clone to save disk space */
2249 /* Copy the clone to the new volume */
2250 VPRINT2("Dumping from clone %u on source to volume %u on destination ...",
2253 AFSVolForward(fromconn, clonetid, cloneFromDate, &destination,
2255 EGOTO1(mfail, code, "Failed to move data for the volume %u\n",
2259 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2260 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2265 "Failed to end the transaction on the cloned volume %u\n",
2271 * reattach to the main-line volume, and incrementally dump it.
2274 VPRINT1("Starting transaction on source volume %u ...", afromvol);
2275 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2277 "Failed to create a transaction on the source volume %u\n",
2281 /* now do the incremental */
2283 ("Doing the%s dump from source to destination for volume %u ... ",
2284 (flags & RV_NOCLONE) ? "" : " incremental",
2287 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
2290 "Failed to do the%s dump from old site to new site\n",
2294 VPRINT1("Setting volume flags on destination volume %u ...", newVol);
2295 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2296 code = AFSVolSetFlags(toconn, totid, volflag);
2298 "Failed to set the flags to make destination volume online\n");
2301 /* put new volume online */
2302 VPRINT1("Ending transaction on destination volume %u ...", newVol);
2303 code = AFSVolEndTrans(toconn, totid, &rcode);
2308 "Failed to end the transaction on the destination volume %u\n",
2312 VPRINT1("Ending transaction on source volume %u ...", afromvol);
2313 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2318 "Failed to end the transaction on the source volume %u\n",
2324 if (!(flags & RV_NOCLONE)) {
2325 VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
2327 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2330 "Failed to start a transaction on the cloned volume%u\n",
2334 /* now delete the clone */
2335 VPRINT1("Deleting the cloned volume %u ...", cloneVol);
2336 code = AFSVolDeleteVolume(fromconn, clonetid);
2337 EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",
2341 VPRINT1("Ending transaction on cloned volume %u ...", cloneVol);
2342 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2347 "Failed to end the transaction on the cloned volume %u\n",
2352 if (!(flags & RV_NOVLDB)) {
2353 /* create the vldb entry for the copied volume */
2354 strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME);
2355 newentry.nServers = 1;
2356 newentry.serverNumber[0] = atoserver;
2357 newentry.serverPartition[0] = atopart;
2358 newentry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
2359 newentry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
2360 newentry.volumeId[RWVOL] = newVol;
2361 newentry.volumeId[ROVOL] = (flags & RV_RDONLY) ? newVol : 0;
2362 newentry.volumeId[BACKVOL] = 0;
2363 newentry.cloneId = 0;
2364 /*map into right byte order, before passing to xdr, the stuff has to be in host
2365 * byte order. Xdr converts it into network order */
2366 MapNetworkToHost(&newentry, &storeEntry);
2367 /* create the vldb entry */
2368 vcode = VLDB_CreateEntry(&storeEntry);
2371 "Could not create a VLDB entry for the volume %s %lu\n",
2372 atovolname, (unsigned long)newVol);
2373 /*destroy the created volume */
2374 VPRINT1("Deleting the newly created volume %u\n", newVol);
2375 AFSVolDeleteVolume(toconn, totid);
2379 VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,
2383 /* normal cleanup code */
2386 VPRINT1("Cleanup: Ending transaction on source volume %u ...",
2388 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
2389 if (code || rcode) {
2392 "Could not end transaction on the source volume %lu\n",
2393 (unsigned long)afromvol);
2395 error = (code ? code : rcode);
2401 VPRINT1("Cleanup: Ending transaction on clone volume %u ...",
2403 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
2404 if (code || rcode) {
2407 "Could not end transaction on the source's clone volume %lu\n",
2408 (unsigned long)cloneVol);
2410 error = (code ? code : rcode);
2416 VPRINT1("Cleanup: Ending transaction on destination volume %u ...",
2418 code = AFSVolEndTrans(toconn, totid, &rcode);
2422 "Could not end transaction on destination volume %lu\n",
2423 (unsigned long)newVol);
2425 error = (code ? code : rcode);
2430 rx_DestroyConnection(fromconn);
2432 rx_DestroyConnection(toconn);
2433 PrintError("", error);
2436 /* come here only when the sky falls */
2441 "vos copy: operation interrupted, cleanup in progress...\n");
2442 fprintf(STDOUT, "clear transaction contexts\n");
2447 VPRINT("Recovery: Ending transaction on clone volume ...");
2448 AFSVolEndTrans(fromconn, clonetid, &rcode);
2452 VPRINT("Recovery: Ending transaction on destination volume ...");
2453 AFSVolEndTrans(toconn, totid, &rcode);
2456 if (fromtid) { /* put it on-line */
2457 VPRINT("Recovery: Ending transaction on source volume ...");
2458 AFSVolEndTrans(fromconn, fromtid, &rcode);
2462 VPRINT("Recovery: Accessing VLDB.\n");
2463 vcode = VLDB_GetEntryByID(afromvol, -1, &entry);
2465 fprintf(STDOUT, "FATAL: VLDB access error: abort cleanup\n");
2469 MapHostToNetwork(&entry);
2471 /* common cleanup - delete local clone */
2473 VPRINT1("Recovery: Creating transaction on clone volume %u ...",
2476 AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
2481 VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol);
2482 AFSVolDeleteVolume(fromconn, clonetid);
2485 VPRINT1("Recovery: Ending transaction on clone volume %u ...",
2487 AFSVolEndTrans(fromconn, clonetid, &rcode);
2491 ("\nRecovery: Unable to start transaction on clone volume %u.\n",
2496 done: /* routine cleanup */
2498 rx_DestroyConnection(fromconn);
2500 rx_DestroyConnection(toconn);
2503 fprintf(STDOUT, "cleanup complete - user verify desired result\n");
2511 UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
2512 char *atovolname, afs_int32 atoserver, afs_int32 atopart)
2514 return UV_CopyVolume2(afromvol, afromserver, afrompart,
2515 atovolname, atoserver, atopart, 0, 0);
2520 /* Make a new backup of volume <avolid> on <aserver> and <apart>
2521 * if one already exists, update it
2525 UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
2527 struct rx_connection *aconn = (struct rx_connection *)0;
2528 afs_int32 ttid = 0, btid = 0;
2530 afs_int32 code = 0, rcode = 0;
2531 char vname[VOLSER_MAXVOLNAME + 1];
2532 struct nvldbentry entry, storeEntry;
2533 afs_int32 error = 0;
2534 int vldblocked = 0, vldbmod = 0, backexists = 1;
2536 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2538 /* the calls to VLDB will succeed only if avolid is a RW volume,
2539 * since we are following the RW hash chain for searching */
2540 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2543 "Could not fetch the entry for the volume %lu from the VLDB \n",
2544 (unsigned long)avolid);
2548 MapHostToNetwork(&entry);
2550 /* These operations require the VLDB be locked since it means the VLDB
2551 * will change or the vldb is already locked.
2553 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
2554 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
2555 (entry.volumeId[BACKVOL] == INVALID_BID)) { /* no assigned backup volume id */
2557 code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL, VLOP_BACKUP);
2560 "Could not lock the VLDB entry for the volume %lu\n",
2561 (unsigned long)avolid);
2567 /* Reread the vldb entry */
2568 code = VLDB_GetEntryByID(avolid, RWVOL, &entry);
2571 "Could not fetch the entry for the volume %lu from the VLDB \n",
2572 (unsigned long)avolid);
2576 MapHostToNetwork(&entry);
2579 if (!ISNAMEVALID(entry.name)) {
2580 fprintf(STDERR, "Name of the volume %s exceeds the size limit\n",
2582 error = VOLSERBADNAME;
2586 backupID = entry.volumeId[BACKVOL];
2587 if (backupID == INVALID_BID) {
2588 /* Get a backup volume id from the VLDB and update the vldb
2591 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
2594 "Could not allocate ID for the backup volume of %lu from the VLDB\n",
2595 (unsigned long)avolid);
2599 entry.volumeId[BACKVOL] = backupID;
2603 /* Test to see if the backup volume exists by trying to create
2604 * a transaction on the backup volume. We've assumed the backup exists.
2606 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2608 if (code != VNOVOL) {
2609 fprintf(STDERR, "Could not reach the backup volume %lu\n",
2610 (unsigned long)backupID);
2614 backexists = 0; /* backup volume does not exist */
2617 code = AFSVolEndTrans(aconn, btid, &rcode);
2619 if (code || rcode) {
2621 "Could not end transaction on the previous backup volume %lu\n",
2622 (unsigned long)backupID);
2623 error = (code ? code : rcode);
2628 /* Now go ahead and try to clone the RW volume.
2629 * First start a transaction on the RW volume
2631 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2633 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2634 (unsigned long)avolid);
2639 /* Clone or reclone the volume, depending on whether the backup
2640 * volume exists or not
2643 VPRINT1("Re-cloning backup volume %u ...", backupID);
2645 code = AFSVolReClone(aconn, ttid, backupID);
2647 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2648 (unsigned long)backupID);
2653 VPRINT1("Creating a new backup clone %u ...", backupID);
2655 strcpy(vname, entry.name);
2656 strcat(vname, ".backup");
2658 code = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
2660 fprintf(STDERR, "Failed to clone the volume %lu\n",
2661 (unsigned long)avolid);
2667 /* End the transaction on the RW volume */
2668 code = AFSVolEndTrans(aconn, ttid, &rcode);
2670 if (code || rcode) {
2672 "Failed to end the transaction on the rw volume %lu\n",
2673 (unsigned long)avolid);
2674 error = (code ? code : rcode);
2678 /* Mork vldb as backup exists */
2679 if (!(entry.flags & BACK_EXISTS)) {
2680 entry.flags |= BACK_EXISTS;
2684 /* Now go back to the backup volume and bring it on line */
2685 code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
2688 "Failed to start a transaction on the backup volume %lu\n",
2689 (unsigned long)backupID);
2694 code = AFSVolSetFlags(aconn, btid, 0);
2696 fprintf(STDERR, "Could not mark the backup volume %lu on line \n",
2697 (unsigned long)backupID);
2702 code = AFSVolEndTrans(aconn, btid, &rcode);
2704 if (code || rcode) {
2706 "Failed to end the transaction on the backup volume %lu\n",
2707 (unsigned long)backupID);
2708 error = (code ? code : rcode);
2714 /* Will update the vldb below */
2718 code = AFSVolEndTrans(aconn, ttid, &rcode);
2719 if (code || rcode) {
2720 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2721 (unsigned long)avolid);
2723 error = (code ? code : rcode);
2728 code = AFSVolEndTrans(aconn, btid, &rcode);
2729 if (code || rcode) {
2731 "Could not end transaction the backup volume %lu\n",
2732 (unsigned long)backupID);
2734 error = (code ? code : rcode);
2738 /* Now update the vldb - if modified */
2741 MapNetworkToHost(&entry, &storeEntry);
2743 VLDB_ReplaceEntry(avolid, RWVOL, &storeEntry,
2744 (LOCKREL_OPCODE | LOCKREL_AFSID |
2745 LOCKREL_TIMESTAMP));
2748 "Could not update the VLDB entry for the volume %lu \n",
2749 (unsigned long)avolid);
2755 ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL,
2756 (LOCKREL_OPCODE | LOCKREL_AFSID |
2757 LOCKREL_TIMESTAMP));
2760 "Could not unlock the VLDB entry for the volume %lu \n",
2761 (unsigned long)avolid);
2769 rx_DestroyConnection(aconn);
2771 PrintError("", error);
2775 /* Make a new clone of volume <avolid> on <aserver> and <apart>
2776 * using volume ID <acloneid>, or a new ID allocated from the VLDB.
2777 * The new volume is named by <aname>, or by appending ".clone" to
2778 * the existing name if <aname> is NULL. The following flags are
2781 * RV_RDONLY - target volume is RO
2782 * RV_OFFLINE - leave target volume offline
2786 UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
2787 afs_int32 acloneid, char *aname, int flags)
2789 struct rx_connection *aconn = (struct rx_connection *)0;
2790 afs_int32 ttid = 0, btid = 0;
2791 afs_int32 code = 0, rcode = 0;
2792 char vname[VOLSER_MAXVOLNAME + 1];
2793 afs_int32 error = 0;
2795 volEntries volumeInfo;
2797 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
2800 volumeInfo.volEntries_val = (volintInfo *) 0;
2801 volumeInfo.volEntries_len = 0;
2802 code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo);
2804 fprintf(stderr, "Could not get info for volume %lu\n",
2805 (unsigned long)avolid);
2809 strncpy(vname, volumeInfo.volEntries_val[0].name,
2810 VOLSER_OLDMAXVOLNAME - 7);
2811 vname[VOLSER_OLDMAXVOLNAME - 7] = 0;
2812 strcat(vname, ".clone");
2814 if (volumeInfo.volEntries_val)
2815 free(volumeInfo.volEntries_val);
2819 /* Get a clone id */
2820 VPRINT1("Allocating new volume id for clone of volume %u ...",
2822 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid);
2824 "Could not get an ID for the clone of volume %u from the VLDB\n",
2829 /* Test to see if the clone volume exists by trying to create
2830 * a transaction on the clone volume. We've assumed the clone exists.
2832 /* XXX I wonder what happens if the clone has some other parent... */
2833 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2835 if (code != VNOVOL) {
2836 fprintf(STDERR, "Could not reach the clone volume %lu\n",
2837 (unsigned long)acloneid);
2841 backexists = 0; /* backup volume does not exist */
2844 code = AFSVolEndTrans(aconn, btid, &rcode);
2846 if (code || rcode) {
2848 "Could not end transaction on the previous clone volume %lu\n",
2849 (unsigned long)acloneid);
2850 error = (code ? code : rcode);
2855 /* Now go ahead and try to clone the RW volume.
2856 * First start a transaction on the RW volume
2858 code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
2860 fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
2861 (unsigned long)avolid);
2866 /* Clone or reclone the volume, depending on whether the backup
2867 * volume exists or not
2870 VPRINT1("Re-cloning clone volume %u ...", acloneid);
2872 code = AFSVolReClone(aconn, ttid, acloneid);
2874 fprintf(STDERR, "Could not re-clone backup volume %lu\n",
2875 (unsigned long)acloneid);
2880 VPRINT1("Creating a new clone %u ...", acloneid);
2882 code = AFSVolClone(aconn, ttid, 0,
2883 (flags & RV_RDONLY) ? readonlyVolume : backupVolume,
2886 fprintf(STDERR, "Failed to clone the volume %lu\n",
2887 (unsigned long)avolid);
2893 /* End the transaction on the RW volume */
2894 code = AFSVolEndTrans(aconn, ttid, &rcode);
2896 if (code || rcode) {
2898 "Failed to end the transaction on the rw volume %lu\n",
2899 (unsigned long)avolid);
2900 error = (code ? code : rcode);
2904 /* Now go back to the backup volume and bring it on line */
2905 if (!(flags & RV_OFFLINE)) {
2906 code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
2909 "Failed to start a transaction on the clone volume %lu\n",
2910 (unsigned long)acloneid);
2915 code = AFSVolSetFlags(aconn, btid, 0);
2917 fprintf(STDERR, "Could not mark the clone volume %lu on line \n",
2918 (unsigned long)acloneid);
2923 code = AFSVolEndTrans(aconn, btid, &rcode);
2925 if (code || rcode) {
2927 "Failed to end the transaction on the clone volume %lu\n",
2928 (unsigned long)acloneid);
2929 error = (code ? code : rcode);
2938 code = AFSVolEndTrans(aconn, ttid, &rcode);
2939 if (code || rcode) {
2940 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
2941 (unsigned long)avolid);
2943 error = (code ? code : rcode);
2948 code = AFSVolEndTrans(aconn, btid, &rcode);
2949 if (code || rcode) {
2951 "Could not end transaction on the clone volume %lu\n",
2952 (unsigned long)acloneid);
2954 error = (code ? code : rcode);
2959 rx_DestroyConnection(aconn);
2961 PrintError("", error);
2966 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
2969 afs_int32 acode, ccode, rcode, tid;
2970 ccode = rcode = tid = 0;
2972 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
2973 if (!acode) { /* It really was there */
2974 acode = AFSVolDeleteVolume(conn, tid);
2976 fprintf(STDERR, "Failed to delete volume %lu.\n",
2977 (unsigned long)vid);
2978 PrintError("", acode);
2980 ccode = AFSVolEndTrans(conn, tid, &rcode);
2984 fprintf(STDERR, "Failed to end transaction on volume %lu.\n",
2985 (unsigned long)vid);
2986 PrintError("", ccode);
2993 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
2994 #define ERROREXIT(ec) { error = (ec); goto rfail; }
2996 /* Get a "transaction" on this replica. Create the volume
2997 * if necessary. Return the time from which a dump should
2998 * be made (0 if it's a new volume)
3001 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
3002 struct rx_connection **connPtr, afs_int32 * transPtr,
3003 afs_int32 * crtimePtr, afs_int32 * uptimePtr)
3006 struct volser_status tstatus;
3007 int code, rcode, tcode;
3009 *connPtr = (struct rx_connection *)0;
3014 /* get connection to the replication site */
3015 *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT);
3017 goto fail; /* server is down */
3019 volid = vldbEntryPtr->volumeId[ROVOL];
3022 AFSVolTransCreate(*connPtr, volid,
3023 vldbEntryPtr->serverPartition[index], ITOffline,
3026 /* If the volume does not exist, create it */
3027 if (!volid || code) {
3030 if (volid && (code != VNOVOL)) {
3031 PrintError("Failed to start a transaction on the RO volume.\n",
3036 strcpy(volname, vldbEntryPtr->name);
3037 strcat(volname, ".readonly");
3041 "Creating new volume %lu on replication site %s: ",
3042 (unsigned long)volid,
3043 hostutil_GetNameByINet(vldbEntryPtr->
3044 serverNumber[index]));
3049 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
3051 vldbEntryPtr->volumeId[RWVOL], &volid,
3054 PrintError("Failed to create the ro volume: ", code);
3057 vldbEntryPtr->volumeId[ROVOL] = volid;
3061 /* The following is a bit redundant, since create sets these flags by default */
3063 AFSVolSetFlags(*connPtr, *transPtr,
3064 VTDeleteOnSalvage | VTOutOfService);
3066 PrintError("Failed to set flags on the ro volume: ", code);
3071 /* Otherwise, the transaction did succeed, so get the creation date of the
3072 * latest RO volume on the replication site
3075 VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
3076 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
3078 code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
3080 PrintError("Failed to get status of volume on destination: ",
3084 *crtimePtr = CLOCKADJ(tstatus.creationDate);
3085 *uptimePtr = CLOCKADJ(tstatus.updateDate);
3092 tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
3097 PrintError("Could not end transaction on a ro volume: ", tcode);
3104 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
3105 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
3106 void *cookie, manyResults * results)
3110 for (i = 0; i < tr->manyDests_len; i++) {
3111 results->manyResults_val[i] =
3112 AFSVolForward(fromconn, fromtid, fromdate,
3113 &(tr->manyDests_val[i].server),
3114 tr->manyDests_val[i].trans, cookie);
3120 /* UV_ReleaseVolume()
3121 * Release volume <afromvol> on <afromserver> <afrompart> to all
3122 * its RO sites (full release). Unless the previous release was
3123 * incomplete: in which case we bring the remaining incomplete
3124 * volumes up to date with the volumes that were released
3126 * forceflag: Performs a full release.
3128 * Will create a clone from the RW, then dump the clone out to
3129 * the remaining replicas. If there is more than 1 RO sites,
3130 * ensure that the VLDB says at least one RO is available all
3131 * the time: Influences when we write back the VLDB entry.
3135 UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
3136 afs_int32 afrompart, int forceflag)
3139 afs_int32 code, vcode, rcode, tcode;
3140 afs_int32 cloneVolId, roVolId;
3141 struct replica *replicas = 0;
3142 struct nvldbentry entry, storeEntry;
3143 int i, volcount, m, fullrelease, vldbindex;
3145 struct restoreCookie cookie;
3146 struct rx_connection **toconns = 0;
3147 struct release *times = 0;
3149 struct rx_connection *fromconn = (struct rx_connection *)0;
3150 afs_int32 error = 0;
3152 afs_int32 clonetid = 0, onlinetid;
3153 afs_int32 fromtid = 0;
3154 afs_uint32 fromdate, thisdate;
3158 manyResults results;
3159 int rwindex, roindex, roclone, roexists;
3160 afs_int32 rwcrdate, rwupdate, clcrdate;
3164 } remembertime[NMAXNSERVERS];
3165 int releasecount = 0;
3166 struct volser_status volstatus;
3168 memset((char *)remembertime, 0, sizeof(remembertime));
3169 memset((char *)&results, 0, sizeof(results));
3171 vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
3172 if (vcode != VL_RERELEASE)
3173 ONERROR(vcode, afromvol,
3174 "Could not lock the VLDB entry for the volume %u.\n");
3177 /* Get the vldb entry in readable format */
3178 vcode = VLDB_GetEntryByID(afromvol, RWVOL, &entry);
3179 ONERROR(vcode, afromvol,
3180 "Could not fetch the entry for the volume %u from the VLDB.\n");
3181 MapHostToNetwork(&entry);
3184 EnumerateEntry(&entry);
3186 if (!ISNAMEVALID(entry.name))
3187 ONERROR(VOLSERBADOP, entry.name,
3188 "Volume name %s is too long, rename before releasing.\n");
3189 if (entry.volumeId[RWVOL] != afromvol)
3190 ONERROR(VOLSERBADOP, afromvol,
3191 "The volume %u being released is not a read-write volume.\n");
3192 if (entry.nServers <= 1)
3193 ONERROR(VOLSERBADOP, afromvol,
3194 "Volume %u has no replicas - release operation is meaningless!\n");
3195 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10))
3196 ONERROR(VOLSERBADOP, entry.name,
3197 "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n");
3199 /* roclone is true if one of the RO volumes is on the same
3200 * partition as the RW volume. In this case, we make the RO volume
3201 * on the same partition a clone instead of a complete copy.
3204 roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1;
3205 roclone = ((roindex == -1) ? 0 : 1);
3206 rwindex = Lp_GetRwIndex(&entry);
3208 ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
3210 /* Make sure we have a RO volume id to work with */
3211 if (entry.volumeId[ROVOL] == INVALID_BID) {
3212 /* need to get a new RO volume id */
3213 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId);
3214 ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n");
3216 entry.volumeId[ROVOL] = roVolId;
3217 MapNetworkToHost(&entry, &storeEntry);
3218 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3219 ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n");
3222 /* Will we be completing a previously unfinished release. -force overrides */
3223 for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) {
3224 if (entry.serverFlags[i] & ITSROVOL) {
3226 if (entry.serverFlags[i] & NEW_REPSITE) s++;
3229 if ((forceflag && !fullrelease) || (s == m) || (s == 0))
3232 /* Determine which volume id to use and see if it exists */
3235 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
3236 code = VolumeExists(afromserver, afrompart, cloneVolId);
3237 roexists = ((code == ENODEV) ? 0 : 1);
3239 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3241 ONERROR(-1, afromserver,
3242 "Cannot establish connection with server 0x%x\n");
3246 fullrelease = 1; /* Do a full release if RO clone does not exist */
3248 /* Begin transaction on RW and mark it busy while we query it */
3249 code = AFSVolTransCreate(
3250 fromconn, afromvol, afrompart, ITBusy, &fromtid
3252 ONERROR(code, afromvol,
3253 "Failed to start transaction on RW volume %u\n");
3255 /* Query the creation date for the RW */
3256 code = AFSVolGetStatus(fromconn, fromtid, &volstatus);
3257 ONERROR(code, afromvol,
3258 "Failed to get the status of RW volume %u\n");
3259 rwcrdate = volstatus.creationDate;
3260 rwupdate = volstatus.updateDate;
3262 /* End transaction on RW */
3263 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3265 ONERROR((code ? code : rcode), afromvol,
3266 "Failed to end transaction on RW volume %u\n");
3268 /* Begin transaction on clone and mark it busy while we query it */
3269 code = AFSVolTransCreate(
3270 fromconn, cloneVolId, afrompart, ITBusy, &clonetid
3272 ONERROR(code, cloneVolId,
3273 "Failed to start transaction on RW clone %u\n");
3275 /* Query the creation date for the clone */
3276 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3277 ONERROR(code, cloneVolId,
3278 "Failed to get the status of RW clone %u\n");
3279 clcrdate = volstatus.creationDate;
3281 /* End transaction on clone */
3282 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3284 ONERROR((code ? code : rcode), cloneVolId,
3285 "Failed to end transaction on RW clone %u\n");
3287 if (rwcrdate > clcrdate)
3288 fullrelease = 2;/* Do a full release if RO clone older than RW */
3293 switch (fullrelease) {
3295 fprintf(STDOUT, "RW %lu changed, doing a complete release\n",
3296 (unsigned long)afromvol);
3299 fprintf(STDOUT, "This is a complete release of volume %lu\n",
3300 (unsigned long)afromvol);
3303 fprintf(STDOUT, "This is a completion of a previous release\n");
3309 /* If the RO clone exists, then if the clone is a temporary
3310 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
3311 * (it was recently added), then also delete it. We do not
3312 * want to "reclone" a temporary RO clone.
3315 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
3316 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3317 if (code && (code != VNOVOL))
3322 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
3323 * write this entry out to the vlserver until after the first
3324 * RO volume is released (temp RO clones don't count).
3326 for (i = 0; i < entry.nServers; i++) {
3327 entry.serverFlags[i] &= ~NEW_REPSITE;
3328 entry.serverFlags[i] |= RO_DONTUSE;
3330 entry.serverFlags[rwindex] |= NEW_REPSITE;
3331 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
3333 /* Begin transaction on RW and mark it busy while we clone it */
3335 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
3337 ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
3339 /* Clone or reclone the volume */
3341 VPRINT1("Recloning RW volume %u...", cloneVolId);
3342 code = AFSVolReClone(fromconn, clonetid, cloneVolId);
3343 ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n");
3347 strcpy(vname, entry.name);
3348 strcat(vname, ".readonly");
3349 VPRINT1("Cloning RW volume %u to permanent RO...", afromvol);
3351 strcpy(vname, "readonly-clone-temp");
3352 VPRINT1("Cloning RW volume %u to temporary RO...", afromvol);
3355 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
3357 ONERROR(code, afromvol, "Failed to clone the RW volume %u\n");
3361 /* Get the time the RW was created for future information */
3362 VPRINT1("Getting status of RW volume %u...", afromvol);
3363 code = AFSVolGetStatus(fromconn, clonetid, &volstatus);
3364 ONERROR(code, afromvol,
3365 "Failed to get the status of the RW volume %u\n");
3367 rwcrdate = volstatus.creationDate;
3368 rwupdate = volstatus.updateDate;
3370 /* End the transaction on the RW volume */
3371 VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
3372 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3374 ONERROR((code ? code : rcode), afromvol,
3375 "Failed to end cloning transaction on RW %u\n");
3378 /* Remember clone volume ID in case we fail or are interrupted */
3379 entry.cloneId = cloneVolId;
3382 /* Bring the RO clone online - though not if it's a temporary clone */
3383 VPRINT1("Starting transaction on RO clone volume %u...",
3386 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
3388 ONERROR(code, cloneVolId,
3389 "Failed to start transaction on volume %u\n");
3392 VPRINT1("Setting volume flags for volume %u...", cloneVolId);
3393 tcode = AFSVolSetFlags(fromconn, onlinetid, 0);
3396 VPRINT1("Ending transaction on volume %u...", cloneVolId);
3397 code = AFSVolEndTrans(fromconn, onlinetid, &rcode);
3398 ONERROR((code ? code : rcode), cloneVolId,
3399 "Failed to end transaction on RO clone %u\n");
3402 ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
3404 /* Sleep so that a client searching for an online volume won't
3405 * find the clone offline and then the next RO offline while the
3406 * release brings the clone online and the next RO offline (race).
3407 * There is a fix in the 3.4 client that does not need this sleep
3408 * anymore, but we don't know what clients we have.
3410 if (entry.nServers > 2)
3413 /* Mark the RO clone in the VLDB as a good site (already released) */
3414 entry.serverFlags[roindex] |= NEW_REPSITE;
3415 entry.serverFlags[roindex] &= ~RO_DONTUSE;
3416 entry.flags |= RO_EXISTS;
3420 /* Write out the VLDB entry only if the clone is not a temporary
3421 * clone. If we did this to a temporary clone then we would end
3422 * up marking all the ROs as "old release" making the ROs
3423 * temporarily unavailable.
3425 MapNetworkToHost(&entry, &storeEntry);
3426 VPRINT1("Replacing VLDB entry for %s...", entry.name);
3427 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3428 ONERROR(vcode, entry.name,
3429 "Could not update vldb entry for %s.\n");
3434 /* Now we will release from the clone to the remaining RO replicas.
3435 * The first 2 ROs (counting the non-temporary RO clone) are released
3436 * individually: releasecount. This is to reduce the race condition
3437 * of clients trying to find an on-line RO volume. The remaining ROs
3438 * are released in parallel but no more than half the number of ROs
3439 * (rounded up) at a time: nservers.
3442 strcpy(vname, entry.name);
3443 strcat(vname, ".readonly");
3444 memset(&cookie, 0, sizeof(cookie));
3445 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
3446 cookie.type = ROVOL;
3447 cookie.parent = entry.volumeId[RWVOL];
3450 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
3452 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
3453 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
3455 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
3457 results.manyResults_val =
3458 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
3459 if (!replicas || !times || !!!results.manyResults_val || !toconns)
3461 "Failed to create transaction on the release clone\n");
3463 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
3464 memset(times, 0, (sizeof(struct release) * nservers + 1));
3465 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
3466 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
3468 /* Create a transaction on the cloned volume */
3469 VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
3471 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
3472 if (!fullrelease && code)
3473 ONERROR(VOLSERNOVOL, afromvol,
3474 "Old clone is inaccessible. Try vos release -f %u.\n");
3475 ONERROR(code, 0, "Failed to create transaction on the release clone\n");
3478 /* For each index in the VLDB */
3479 for (vldbindex = 0; vldbindex < entry.nServers;) {
3481 /* Get a transaction on the replicas. Pick replacas which have an old release. */
3483 ((volcount < nservers) && (vldbindex < entry.nServers));
3485 /* The first two RO volumes will be released individually.
3486 * The rest are then released in parallel. This is a hack
3487 * for clients not recognizing right away when a RO volume
3488 * comes back on-line.
3490 if ((volcount == 1) && (releasecount < 2))
3493 if (vldbindex == roindex)
3494 continue; /* the clone */
3495 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
3496 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
3498 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
3499 continue; /* not a RO vol */
3502 /* Get a Transaction on this replica. Get a new connection if
3503 * necessary. Create the volume if necessary. Return the
3504 * time from which the dump should be made (0 if it's a new
3505 * volume). Each volume might have a different time.
3507 replicas[volcount].server.destHost =
3508 ntohl(entry.serverNumber[vldbindex]);
3509 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
3510 replicas[volcount].server.destSSID = 1;
3511 times[volcount].vldbEntryIndex = vldbindex;
3514 GetTrans(&entry, vldbindex, &(toconns[volcount]),
3515 &(replicas[volcount].trans),
3516 &(times[volcount].crtime),
3517 &(times[volcount].uptime));
3521 /* Thisdate is the date from which we want to pick up all changes */
3522 if (forceflag || !fullrelease
3523 || (rwcrdate > times[volcount].crtime)) {
3524 /* If the forceflag is set, then we want to do a full dump.
3525 * If it's not a full release, we can't be sure that the creation
3526 * date is good (so we also do a full dump).
3527 * If the RW volume was replaced (its creation date is newer than
3528 * the last release), then we can't be sure what has changed (so
3529 * we do a full dump).
3532 } else if (remembertime[vldbindex].validtime) {
3533 /* Trans was prev ended. Use the time from the prev trans
3534 * because, prev trans may have created the volume. In which
3535 * case time[volcount].time would be now instead of 0.
3538 (remembertime[vldbindex].uptime < times[volcount].uptime)
3539 ? remembertime[vldbindex].uptime
3540 : times[volcount].uptime;
3542 thisdate = times[volcount].uptime;
3544 remembertime[vldbindex].validtime = 1;
3545 remembertime[vldbindex].uptime = thisdate;
3547 if (volcount == 0) {
3548 fromdate = thisdate;
3550 /* Include this volume if it is within 15 minutes of the earliest */
3552 thisdate) ? (fromdate - thisdate) : (thisdate -
3554 AFSVolEndTrans(toconns[volcount],
3555 replicas[volcount].trans, &rcode);
3556 replicas[volcount].trans = 0;
3559 if (thisdate < fromdate)
3560 fromdate = thisdate;
3568 fprintf(STDOUT, "Starting ForwardMulti from %lu to %u on %s",
3569 (unsigned long)cloneVolId, entry.volumeId[ROVOL],
3570 hostutil_GetNameByINet(entry.
3571 serverNumber[times[0].
3574 for (s = 1; s < volcount; s++) {
3575 fprintf(STDOUT, " and %s",
3576 hostutil_GetNameByINet(entry.
3577 serverNumber[times[s].
3582 fprintf(STDOUT, " (full release)");
3585 fprintf(STDOUT, " (as of %.24s)", ctime(&tmv));
3587 fprintf(STDOUT, ".\n");
3591 /* Release the ones we have collected */
3592 tr.manyDests_val = &(replicas[0]);
3593 tr.manyDests_len = results.manyResults_len = volcount;
3595 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
3596 0 /*spare */ , &cookie, &results);
3597 if (code == RXGEN_OPCODE) { /* RPC Interface Mismatch */
3599 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
3600 0 /*spare */ , &cookie, &results);
3605 PrintError("Release failed: ", code);
3607 for (m = 0; m < volcount; m++) {
3608 if (results.manyResults_val[m]) {
3609 if ((m == 0) || (results.manyResults_val[m] != ENOENT)) {
3610 /* we retry timed out transaction. When it is
3611 * not the first volume and the transaction wasn't found
3612 * (assume it timed out and was garbage collected by volser).
3615 ("Failed to dump volume from clone to a ro site: ",
3616 results.manyResults_val[m]);
3622 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
3623 ROVOL, entry.volumeId[RWVOL], 0, 0);
3625 if ((m == 0) || (code != ENOENT)) {
3626 PrintError("Failed to set correct names and ids: ",
3632 /* have to clear dest. flags to ensure new vol goes online:
3633 * because the restore (forwarded) operation copied
3634 * the V_inService(=0) flag over to the destination.
3636 code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
3638 if ((m == 0) || (code != ENOENT)) {
3639 PrintError("Failed to set flags on ro volume: ",
3645 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
3646 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
3647 entry.flags |= RO_EXISTS;
3652 /* End the transactions and destroy the connections */
3653 for (s = 0; s < volcount; s++) {
3654 if (replicas[s].trans)
3655 code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
3656 replicas[s].trans = 0;
3660 if ((s == 0) || (code != ENOENT)) {
3661 PrintError("Could not end transaction on a ro volume: ",
3665 ("Transaction timed out on a ro volume. Will retry.\n",
3667 if (times[s].vldbEntryIndex < vldbindex)
3668 vldbindex = times[s].vldbEntryIndex;
3673 rx_DestroyConnection(toconns[s]);
3677 MapNetworkToHost(&entry, &storeEntry);
3678 vcode = VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry, 0);
3679 ONERROR(vcode, afromvol,
3680 " Could not update VLDB entry for volume %u\n");
3681 } /* for each index in the vldb */
3683 /* End the transaction on the cloned volume */
3684 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3689 PrintError("Failed to end transaction on rw volume: ", code);
3691 /* Figure out if any volume were not released and say so */
3692 for (failure = 0, i = 0; i < entry.nServers; i++) {
3693 if (!(entry.serverFlags[i] & NEW_REPSITE))
3699 "The volume %lu could not be released to the following %d sites:\n",
3700 (unsigned long)afromvol, failure);
3701 for (i = 0; i < entry.nServers; i++) {
3702 if (!(entry.serverFlags[i] & NEW_REPSITE)) {
3703 MapPartIdIntoName(entry.serverPartition[i], pname);
3704 fprintf(STDERR, "\t%35s %s\n",
3705 hostutil_GetNameByINet(entry.serverNumber[i]), pname);
3709 MapNetworkToHost(&entry, &storeEntry);
3711 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3713 ONERROR(vcode, afromvol,
3714 " Could not update VLDB entry for volume %u\n");
3716 ERROREXIT(VOLSERBADRELEASE);
3719 /* All the ROs were release successfully. Remove the temporary clone */
3722 fprintf(STDOUT, "Deleting the releaseClone %lu ...",
3723 (unsigned long)cloneVolId);
3726 code = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
3727 ONERROR(code, cloneVolId, "Failed to delete volume %u.\n");
3732 for (i = 0; i < entry.nServers; i++)
3733 entry.serverFlags[i] &= ~NEW_REPSITE;
3735 /* Update the VLDB */
3736 VPRINT("updating VLDB ...");
3738 MapNetworkToHost(&entry, &storeEntry);
3740 VLDB_ReplaceEntry(afromvol, RWVOL, &storeEntry,
3741 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3742 ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n");
3747 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
3751 "Failed to end cloning transaction on the RW volume %lu\n",
3752 (unsigned long)afromvol);
3758 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3762 "Failed to end transaction on the release clone %lu\n",
3763 (unsigned long)cloneVolId);
3768 for (i = 0; i < nservers; i++) {
3769 if (replicas && replicas[i].trans) {
3770 code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
3771 replicas[i].trans = 0;
3774 "Failed to end transaction on ro volume %u at server %s\n",
3775 entry.volumeId[ROVOL],
3776 hostutil_GetNameByINet(htonl
3777 (replicas[i].server.
3783 if (toconns && toconns[i]) {
3784 rx_DestroyConnection(toconns[i]);
3790 ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL,
3791 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3794 "Could not release lock on the VLDB entry for volume %lu\n",
3795 (unsigned long)afromvol);
3801 PrintError("", error);
3804 rx_DestroyConnection(fromconn);
3805 if (results.manyResults_val)
3806 free(results.manyResults_val);
3818 dump_sig_handler(int x)
3820 fprintf(STDERR, "\nSignal handler: vos dump operation\n");
3824 /* Dump the volume <afromvol> on <afromserver> and
3825 * <afrompart> to <afilename> starting from <fromdate>.
3826 * DumpFunction does the real work behind the scenes after
3827 * extracting parameters from the rock
3830 UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
3831 afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock,
3834 struct rx_connection *fromconn = (struct rx_connection *)0;
3835 struct rx_call *fromcall = (struct rx_call *)0;
3836 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3837 afs_int32 code, error = 0, retry = 0;
3838 time_t tmv = fromdate;
3842 #ifndef AFS_NT40_ENV
3843 (void)signal(SIGPIPE, dump_sig_handler);
3845 (void)signal(SIGINT, dump_sig_handler);
3848 VPRINT("Full Dump ...\n");
3850 VPRINT1("Incremental Dump (as of %.24s)...\n",
3854 /* get connections to the servers */
3855 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3857 VPRINT1("Starting transaction on volume %u...", afromvol);
3858 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3859 EGOTO1(error_exit, code,
3860 "Could not start transaction on the volume %u to be dumped\n",
3864 fromcall = rx_NewCall(fromconn);
3866 VPRINT1("Starting volume dump on volume %u...", afromvol);
3867 if (flags & VOLDUMPV2_OMITDIRS)
3868 code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
3871 code = StartAFSVolDump(fromcall, fromtid, fromdate);
3872 EGOTO(error_exit, code, "Could not start the dump process \n");
3875 VPRINT1("Dumping volume %u...", afromvol);
3876 code = DumpFunction(fromcall, rock);
3877 if (code == RXGEN_OPCODE)
3879 EGOTO(error_exit, code, "Error while dumping volume \n");
3884 code = rx_EndCall(fromcall, rxError);
3885 if (code && code != RXGEN_OPCODE)
3886 fprintf(STDERR, "Error in rx_EndCall\n");
3891 VPRINT1("Ending transaction on volume %u...", afromvol);
3892 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3893 if (code || rcode) {
3894 fprintf(STDERR, "Could not end transaction on the volume %lu\n",
3895 (unsigned long)afromvol);
3897 error = (code ? code : rcode);
3902 rx_DestroyConnection(fromconn);
3906 if (error != RXGEN_OPCODE)
3907 PrintError("", error);
3911 /* Clone the volume <afromvol> on <afromserver> and
3912 * <afrompart>, and then dump the clone volume to
3913 * <afilename> starting from <fromdate>.
3914 * DumpFunction does the real work behind the scenes after
3915 * extracting parameters from the rock
3918 UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
3919 afs_int32 afrompart, afs_int32 fromdate,
3920 afs_int32(*DumpFunction) (), char *rock, afs_int32 flags)
3922 struct rx_connection *fromconn = (struct rx_connection *)0;
3923 struct rx_call *fromcall = (struct rx_call *)0;
3924 afs_int32 fromtid = 0, rxError = 0, rcode = 0;
3925 afs_int32 clonetid = 0;
3926 afs_int32 code = 0, vcode = 0, error = 0;
3927 afs_int32 clonevol = 0;
3929 time_t tmv = fromdate;
3933 #ifndef AFS_NT40_ENV
3934 (void)signal(SIGPIPE, dump_sig_handler);
3936 (void)signal(SIGINT, dump_sig_handler);
3939 VPRINT("Full Dump ...\n");
3941 VPRINT1("Incremental Dump (as of %.24s)...\n",
3945 /* get connections to the servers */
3946 fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
3948 VPRINT1("Starting transaction on volume %u...", afromvol);
3949 code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
3950 EGOTO1(error_exit, code,
3951 "Could not start transaction on the volume %u to be dumped\n",
3955 /* Get a clone id */
3956 VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
3957 code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
3958 EGOTO1(error_exit, code,
3959 "Could not get an ID for the clone of volume %u from the VLDB\n",
3963 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
3964 VPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
3966 strcpy(vname, "dump-clone-temp");
3968 AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
3969 EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
3973 VPRINT1("Ending the transaction on the volume %u ...", afromvol);
3975 code = AFSVolEndTrans(fromconn, fromtid, &rcode);
3979 EGOTO1(error_exit, code,
3980 "Failed to end the transaction on the volume %u\n", afromvol);
3984 VPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
3986 AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
3988 EGOTO1(error_exit, code,
3989 "Failed to start a transaction on the cloned volume%u\n",
3993 VPRINT1("Setting flags on cloned volume %u ...", clonevol);
3994 code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
3995 EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
4000 fromcall = rx_NewCall(fromconn);
4002 VPRINT1("Starting volume dump from cloned volume %u...", clonevol);
4003 if (flags & VOLDUMPV2_OMITDIRS)
4004 code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
4006 code = StartAFSVolDump(fromcall, clonetid, fromdate);
4007 EGOTO(error_exit, code, "Could not start the dump process \n");
4010 VPRINT1("Dumping volume %u...", afromvol);
4011 code = DumpFunction(fromcall, rock);
4012 EGOTO(error_exit, code, "Error while dumping volume \n");
4016 /* now delete the clone */
4017 VPRINT1("Deleting the cloned volume %u ...", clonevol);
4018 code = AFSVolDeleteVolume(fromconn, clonetid);
4020 fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
4021 (unsigned long)clonevol);
4027 code = rx_EndCall(fromcall, rxError);
4029 fprintf(STDERR, "Error in rx_EndCall\n");
4035 VPRINT1("Ending transaction on cloned volume %u...", clonevol);
4036 code = AFSVolEndTrans(fromconn, clonetid, &rcode);
4037 if (code || rcode) {
4039 "Could not end transaction on the cloned volume %lu\n",
4040 (unsigned long)clonevol);
4042 error = (code ? code : rcode);
4047 rx_DestroyConnection(fromconn);
4049 PrintError("", error);
4056 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
4057 * the dump file <afilename>. WriteData does all the real work
4058 * after extracting params from the rock
4061 UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4062 afs_int32 toparentid, char tovolname[], int flags,
4063 afs_int32(*WriteData) (), char *rock)
4065 struct rx_connection *toconn, *tempconn;
4066 struct rx_call *tocall;
4067 afs_int32 totid, code, rcode, vcode, terror = 0;
4068 afs_int32 rxError = 0;
4069 struct volser_status tstatus;
4070 struct volintInfo vinfo;
4072 afs_int32 pvolid, pparentid;
4075 struct nvldbentry entry, storeEntry;
4078 struct restoreCookie cookie;
4080 afs_int32 volflag, voltype, volsertype;
4081 afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate;
4082 int index, same, errcode;
4086 memset(&cookie, 0, sizeof(cookie));
4091 tocall = (struct rx_call *)0;
4092 toconn = (struct rx_connection *)0;
4093 tempconn = (struct rx_connection *)0;
4097 if (flags & RV_RDONLY) {
4099 volsertype = volser_RO;
4102 volsertype = volser_RW;
4106 pparentid = toparentid;
4107 toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT);
4108 if (pvolid == 0) { /*alot a new id if needed */
4109 vcode = VLDB_GetEntryByName(tovolname, &entry);
4110 if (vcode == VL_NOENT) {
4111 vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid);
4113 fprintf(STDERR, "Could not get an Id for the volume %s\n",
4119 } else if (flags & RV_RDONLY) {
4120 if (entry.flags & RW_EXISTS) {
4122 "Entry for ReadWrite volume %s already exists!\n",
4124 error = VOLSERBADOP;
4127 if (!entry.volumeId[ROVOL]) {
4129 "Existing entry for volume %s has no ReadOnly ID\n",
4131 error = VOLSERBADOP;
4134 pvolid = entry.volumeId[ROVOL];
4135 pparentid = entry.volumeId[RWVOL];
4137 pvolid = entry.volumeId[RWVOL];
4138 pparentid = entry.volumeId[RWVOL];
4141 if (!pparentid) pparentid = pvolid;
4142 /* at this point we have a volume id to use/reuse for the volume to be restored */
4143 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
4144 EGOTO1(refail, VOLSERBADOP,
4145 "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
4148 MapPartIdIntoName(topart, partName);
4149 fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
4150 tovolname, (unsigned long)pvolid,
4151 hostutil_GetNameByINet(toserver), partName);
4154 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid, &pvolid,
4157 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
4158 VPRINT1("Deleting the previous volume %u ...", pvolid);
4161 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4162 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4165 code = AFSVolGetStatus(toconn, totid, &tstatus);
4166 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4169 oldCreateDate = tstatus.creationDate;
4170 oldUpdateDate = tstatus.updateDate;
4173 AFSVolSetFlags(toconn, totid,
4174 VTDeleteOnSalvage | VTOutOfService);
4175 EGOTO1(refail, code, "Could not set flags on volume %u \n",
4178 code = AFSVolDeleteVolume(toconn, totid);
4179 EGOTO1(refail, code, "Could not delete volume %u\n", pvolid);
4181 code = AFSVolEndTrans(toconn, totid, &rcode);
4185 EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid);
4190 AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid,
4192 EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
4195 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
4196 EGOTO1(refail, code, "Failed to start transaction on %u\n",
4199 code = AFSVolGetStatus(toconn, totid, &tstatus);
4200 EGOTO1(refail, code, "Could not get timestamp from volume %u\n",
4203 oldCreateDate = tstatus.creationDate;
4204 oldUpdateDate = tstatus.updateDate;
4211 cookie.parent = pparentid;
4212 cookie.type = voltype;
4214 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
4216 tocall = rx_NewCall(toconn);
4217 terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
4219 fprintf(STDERR, "Volume restore Failed \n");
4223 code = WriteData(tocall, rock);
4225 fprintf(STDERR, "Could not transmit data\n");
4229 terror = rx_EndCall(tocall, rxError);
4230 tocall = (struct rx_call *)0;
4232 fprintf(STDERR, "rx_EndCall Failed \n");
4236 code = AFSVolGetStatus(toconn, totid, &tstatus);
4239 "Could not get status information about the volume %lu\n",
4240 (unsigned long)pvolid);
4244 code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pparentid, 0, 0);
4246 fprintf(STDERR, "Could not set the right type and ID on %lu\n",
4247 (unsigned long)pvolid);
4252 if (flags & RV_CRDUMP)
4253 newCreateDate = tstatus.creationDate;
4254 else if (flags & RV_CRKEEP && oldCreateDate != 0)
4255 newCreateDate = oldCreateDate;
4257 newCreateDate = time(0);
4258 if (flags & RV_LUDUMP)
4259 newUpdateDate = tstatus.updateDate;
4260 else if (flags & RV_LUKEEP)
4261 newUpdateDate = oldUpdateDate;
4263 newUpdateDate = time(0);
4264 code = AFSVolSetDate(toconn,totid, newCreateDate);
4266 fprintf(STDERR, "Could not set the 'creation' date on %u\n", pvolid);
4271 init_volintInfo(&vinfo);
4272 vinfo.creationDate = newCreateDate;
4273 vinfo.updateDate = newUpdateDate;
4274 code = AFSVolSetInfo(toconn, totid, &vinfo);
4276 fprintf(STDERR, "Could not set the 'last updated' date on %u\n",
4282 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
4283 code = AFSVolSetFlags(toconn, totid, volflag);
4285 fprintf(STDERR, "Could not mark %lu online\n", (unsigned long)pvolid);
4290 /* It isn't handled right in refail */
4291 code = AFSVolEndTrans(toconn, totid, &rcode);
4296 fprintf(STDERR, "Could not end transaction on %lu\n",
4297 (unsigned long)pvolid);
4303 fprintf(STDOUT, " done\n");
4305 if (success && (!reuseID || (flags & RV_FULLRST))) {
4306 /* Volume was restored on the file server, update the
4307 * VLDB to reflect the change.
4309 vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
4310 if (vcode && vcode != VL_NOENT && vcode != VL_ENTDELETED) {
4312 "Could not fetch the entry for volume number %lu from VLDB \n",
4313 (unsigned long)pvolid);
4318 MapHostToNetwork(&entry);
4319 if (vcode == VL_NOENT) { /* it doesnot exist already */
4320 /*make the vldb return this indication specifically */
4321 VPRINT("------- Creating a new VLDB entry ------- \n");
4322 strcpy(entry.name, tovolname);
4324 entry.serverNumber[0] = toserver; /*should be indirect */
4325 entry.serverPartition[0] = topart;
4326 entry.serverFlags[0] = (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4327 entry.flags = (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4328 if (flags & RV_RDONLY)
4329 entry.volumeId[ROVOL] = pvolid;
4330 else if (tstatus.cloneID != 0) {
4331 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
4333 entry.volumeId[ROVOL] = INVALID_BID;
4334 entry.volumeId[RWVOL] = pparentid;
4336 if (tstatus.backupID != 0) {
4337 entry.volumeId[BACKVOL] = tstatus.backupID;
4338 /*this should come from status info on the volume if non zero */
4340 entry.volumeId[BACKVOL] = INVALID_BID;
4341 MapNetworkToHost(&entry, &storeEntry);
4342 vcode = VLDB_CreateEntry(&storeEntry);
4345 "Could not create the VLDB entry for volume number %lu \n",
4346 (unsigned long)pvolid);
4352 EnumerateEntry(&entry);
4353 } else { /*update the existing entry */
4355 fprintf(STDOUT, "Updating the existing VLDB entry\n");
4356 fprintf(STDOUT, "------- Old entry -------\n");
4357 EnumerateEntry(&entry);
4358 fprintf(STDOUT, "------- New entry -------\n");
4361 ubik_VL_SetLock(cstruct, 0, pvolid, voltype,
4365 "Could not lock the entry for volume number %lu \n",
4366 (unsigned long)pvolid);
4371 strcpy(entry.name, tovolname);
4373 /* Update the vlentry with the new information */
4374 if (flags & RV_RDONLY)
4375 index = Lp_ROMatch(toserver, topart, &entry) - 1;
4377 index = Lp_GetRwIndex(&entry);
4379 /* Add the new site for the volume being restored */
4380 entry.serverNumber[entry.nServers] = toserver;
4381 entry.serverPartition[entry.nServers] = topart;
4382 entry.serverFlags[entry.nServers] =
4383 (flags & RV_RDONLY) ? ITSROVOL : ITSRWVOL;
4386 /* This volume should be deleted on the old site
4387 * if its different from new site.
4390 VLDB_IsSameAddrs(toserver, entry.serverNumber[index],
4394 "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",
4396 if ((!errcode && !same)
4397 || (entry.serverPartition[index] != topart)) {
4399 UV_Bind(entry.serverNumber[index],
4400 AFSCONF_VOLUMEPORT);
4402 MapPartIdIntoName(entry.serverPartition[index],
4405 ("Deleting the previous volume %u on server %s, partition %s ...",
4407 hostutil_GetNameByINet(entry.serverNumber[index]),
4410 AFSVolTransCreate(tempconn, pvolid,
4411 entry.serverPartition[index],
4412 ITOffline, &temptid);
4415 AFSVolSetFlags(tempconn, temptid,
4420 "Could not set flags on volume %lu on the older site\n",
4421 (unsigned long)pvolid);
4425 code = AFSVolDeleteVolume(tempconn, temptid);
4428 "Could not delete volume %lu on the older site\n",
4429 (unsigned long)pvolid);
4433 code = AFSVolEndTrans(tempconn, temptid, &rcode);
4439 "Could not end transaction on volume %lu on the older site\n",
4440 (unsigned long)pvolid);
4445 MapPartIdIntoName(entry.serverPartition[index],
4449 entry.serverNumber[index] = toserver;
4450 entry.serverPartition[index] = topart;
4453 entry.flags |= (flags & RV_RDONLY) ? RO_EXISTS : RW_EXISTS;
4454 MapNetworkToHost(&entry, &storeEntry);
4456 VLDB_ReplaceEntry(pvolid, voltype, &storeEntry,
4457 LOCKREL_OPCODE | LOCKREL_AFSID |
4461 "Could not update the entry for volume number %lu \n",
4462 (unsigned long)pvolid);
4468 EnumerateEntry(&entry);
4475 code = rx_EndCall(tocall, rxError);
4481 ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype,
4482 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4485 "Could not release lock on the VLDB entry for the volume %lu\n",
4486 (unsigned long)pvolid);
4492 code = AFSVolEndTrans(toconn, totid, &rcode);
4496 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4497 (unsigned long)pvolid);
4503 code = AFSVolEndTrans(toconn, temptid, &rcode);
4507 fprintf(STDERR, "Could not end transaction on the volume %lu \n",
4508 (unsigned long)pvolid);
4514 rx_DestroyConnection(tempconn);
4516 rx_DestroyConnection(toconn);
4517 PrintError("", error);
4522 UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
4523 char tovolname[], int flags, afs_int32(*WriteData) (),
4526 return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
4531 /*unlocks the vldb entry associated with <volid> */
4533 UV_LockRelease(afs_int32 volid)
4539 VPRINT("Binding to the VLDB server\n");
4541 ubik_VL_ReleaseLock(cstruct, 0, volid, -1,
4542 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4545 "Could not unlock the entry for volume number %lu in VLDB \n",
4546 (unsigned long)volid);
4547 PrintError("", vcode);
4550 VPRINT("VLDB updated\n");
4555 /*adds <server> and <part> as a readonly replication site for <volid>
4558 UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4560 int j, nro = 0, islocked = 0;
4561 struct nvldbentry entry, storeEntry;
4562 afs_int32 vcode, error = 0;
4565 error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4568 " Could not lock the VLDB entry for the volume %lu \n",
4569 (unsigned long)volid);
4574 error = VLDB_GetEntryByID(volid, RWVOL, &entry);
4577 "Could not fetch the VLDB entry for volume number %lu \n",
4578 (unsigned long)volid);
4582 if (!ISNAMEVALID(entry.name)) {
4584 "Volume name %s is too long, rename before adding site\n",
4586 error = VOLSERBADOP;
4589 MapHostToNetwork(&entry);
4591 /* See if it's too many entries */
4592 if (entry.nServers >= NMAXNSERVERS) {
4593 fprintf(STDERR, "Total number of entries will exceed %u\n",
4595 error = VOLSERBADOP;
4599 /* See if it's on the same server */
4600 for (j = 0; j < entry.nServers; j++) {
4601 if (entry.serverFlags[j] & ITSROVOL) {
4603 if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) {
4606 "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
4609 MapPartIdIntoName(entry.serverPartition[j], apartName);
4611 "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n",
4613 error = VOLSERBADOP;
4620 /* See if it's too many RO sites - leave one for the RW */
4621 if (nro >= NMAXNSERVERS - 1) {
4622 fprintf(STDERR, "Total number of sites will exceed %u\n",
4624 error = VOLSERBADOP;
4628 VPRINT("Adding a new site ...");
4629 entry.serverNumber[entry.nServers] = server;
4630 entry.serverPartition[entry.nServers] = part;
4631 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
4634 MapNetworkToHost(&entry, &storeEntry);
4636 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4637 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4639 fprintf(STDERR, "Could not update entry for volume %lu \n",
4640 (unsigned long)volid);
4649 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4650 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4653 "Could not release lock on volume entry for %lu \n",
4654 (unsigned long)volid);
4655 PrintError("", vcode);
4659 PrintError("", error);
4663 /*removes <server> <part> as read only site for <volid> from the vldb */
4665 UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
4668 struct nvldbentry entry, storeEntry;
4671 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4673 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4674 (unsigned long)volid);
4675 PrintError("", vcode);
4679 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4682 "Could not fetch the entry for volume number %lu from VLDB \n",
4683 (unsigned long)volid);
4684 PrintError("", vcode);
4687 MapHostToNetwork(&entry);
4688 if (!Lp_ROMatch(server, part, &entry)) {
4689 /*this site doesnot exist */
4690 fprintf(STDERR, "This site is not a replication site \n");
4692 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4693 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4695 fprintf(STDERR, "Could not update entry for volume %lu \n",
4696 (unsigned long)volid);
4697 PrintError("", vcode);
4698 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4699 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4703 } else { /*remove the rep site */
4704 Lp_SetROValue(&entry, server, part, 0, 0);
4706 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
4707 entry.flags &= ~RO_EXISTS;
4708 if (entry.nServers < 1) { /*this is the last ref */
4709 VPRINT1("Deleting the VLDB entry for %u ...", volid);
4711 vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL);
4714 "Could not delete VLDB entry for volume %lu \n",
4715 (unsigned long)volid);
4716 PrintError("", vcode);
4721 MapNetworkToHost(&entry, &storeEntry);
4722 fprintf(STDOUT, "Deleting the replication site for volume %lu ...",
4723 (unsigned long)volid);
4726 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4727 LOCKREL_OPCODE | LOCKREL_AFSID |
4731 "Could not release lock on volume entry for %lu \n",
4732 (unsigned long)volid);
4733 PrintError("", vcode);
4734 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4735 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4743 /*sets <server> <part> as read/write site for <volid> in the vldb */
4745 UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
4748 struct nvldbentry entry, storeEntry;
4751 vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
4753 fprintf(STDERR, " Could not lock the VLDB entry for volume %lu \n",
4754 (unsigned long)volid);
4755 PrintError("", vcode);
4758 vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
4761 "Could not fetch the entry for volume number %lu from VLDB \n",
4762 (unsigned long)volid);
4763 PrintError("", vcode);
4766 MapHostToNetwork(&entry);
4767 index = Lp_GetRwIndex(&entry);
4769 /* no RW site exists */
4770 fprintf(STDERR, "No existing RW site for volume %lu",
4771 (unsigned long)volid);
4773 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4774 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4777 "Could not release lock on entry for volume %lu \n",
4778 (unsigned long)volid);
4779 PrintError("", vcode);
4783 } else { /* change the RW site */
4784 entry.serverNumber[index] = server;
4785 entry.serverPartition[index] = part;
4786 MapNetworkToHost(&entry, &storeEntry);
4788 VLDB_ReplaceEntry(volid, RWVOL, &storeEntry,
4789 LOCKREL_OPCODE | LOCKREL_AFSID |
4792 fprintf(STDERR, "Could not update entry for volume %lu \n",
4793 (unsigned long)volid);
4794 PrintError("", vcode);
4795 ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL,
4796 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
4804 /*list all the partitions on <aserver> */
4806 UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
4809 struct rx_connection *aconn;
4810 struct pIDs partIds;
4811 struct partEntries partEnts;
4812 register int i, j = 0, code;
4815 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4817 partEnts.partEntries_len = 0;
4818 partEnts.partEntries_val = NULL;
4819 code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */
4820 if (code == RXGEN_OPCODE) {
4821 for (i = 0; i < 26; i++) /* try old interface */
4822 partIds.partIds[i] = -1;
4823 code = AFSVolListPartitions(aconn, &partIds);
4825 for (i = 0; i < 26; i++) {
4826 if ((partIds.partIds[i]) != -1) {
4827 ptrPartList->partId[j] = partIds.partIds[i];
4828 ptrPartList->partFlags[j] = PARTVALID;
4831 ptrPartList->partFlags[i] = 0;
4836 *cntp = partEnts.partEntries_len;
4837 if (*cntp > VOLMAXPARTS) {
4839 "Warning: number of partitions on the server too high %d (process only %d)\n",
4840 *cntp, VOLMAXPARTS);
4841 *cntp = VOLMAXPARTS;
4843 for (i = 0; i < *cntp; i++) {
4844 ptrPartList->partId[i] = partEnts.partEntries_val[i];
4845 ptrPartList->partFlags[i] = PARTVALID;
4847 free(partEnts.partEntries_val);
4853 "Could not fetch the list of partitions from the server\n");
4854 PrintError("", code);
4856 rx_DestroyConnection(aconn);
4861 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
4862 This is used by the backup system */
4864 UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
4865 struct volDescription *volPtr, afs_int32 arraySize)
4867 struct rx_connection *aconn;
4868 struct volDescription *curPtr;
4871 afs_int32 rcode = 0;
4872 afs_int32 success = 1;
4875 aconn = (struct rx_connection *)0;
4876 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4878 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4879 if (curPtr->volFlags & CLONEVALID) {
4880 curPtr->volFlags &= ~CLONEZAPPED;
4883 AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
4888 code = AFSVolDeleteVolume(aconn, tid);
4891 code = AFSVolEndTrans(aconn, tid, &rcode);
4896 curPtr->volFlags |= CLONEZAPPED;
4898 fprintf(STDERR, "Could not zap volume %lu\n",
4899 (unsigned long)curPtr->volCloneId);
4901 VPRINT2("Clone of %s %u deleted\n", curPtr->volName,
4902 curPtr->volCloneId);
4908 rx_DestroyConnection(aconn);
4912 /*return a list of clones of the volumes specified by volPtrArray. Used by the
4915 UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
4916 struct volDescription *volPtr, afs_int32 arraySize)
4918 struct rx_connection *aconn;
4919 struct volDescription *curPtr;
4922 afs_int32 rcode = 0;
4924 int reuseCloneId = 0;
4925 afs_int32 curCloneId = 0;
4926 char cloneName[256]; /*max vol name */
4928 aconn = (struct rx_connection *)0;
4929 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
4931 if ((volPtr->volFlags & REUSECLONEID) && (volPtr->volFlags & ENTRYVALID))
4933 else { /*get a bunch of id's from vldb */
4935 ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId);
4937 fprintf(STDERR, "Could not get ID's for the clone from VLDB\n");
4938 PrintError("", code);
4943 for (curPtr = volPtr; curPos < arraySize; curPtr++) {
4944 if (curPtr->volFlags & ENTRYVALID) {
4946 curPtr->volFlags |= CLONEVALID;
4947 /*make a clone of curParentId and record as curPtr->volCloneId */
4949 AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
4952 VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
4955 curPtr->volFlags &= ~CLONEVALID; /*cant clone */
4959 if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME - 9)) {
4960 strcpy(cloneName, curPtr->volName);
4961 strcat(cloneName, "-tmpClone-");
4963 strcpy(cloneName, "-tmpClone");
4965 curPtr->volCloneId = curCloneId;
4970 AFSVolClone(aconn, tid, 0, readonlyVolume, cloneName,
4971 &(curPtr->volCloneId));
4973 curPtr->volFlags &= ~CLONEVALID;
4975 fprintf(STDERR, "Could not clone %s due to error %lu\n",
4976 curPtr->volName, (unsigned long)code);
4977 code = AFSVolEndTrans(aconn, tid, &rcode);
4979 fprintf(STDERR, "WARNING: could not end transaction\n");
4982 VPRINT2("********** Cloned %s temporary %u\n", cloneName,
4983 curPtr->volCloneId);
4984 code = AFSVolEndTrans(aconn, tid, &rcode);
4985 if (code || rcode) {
4986 curPtr->volFlags &= ~CLONEVALID;
4995 rx_DestroyConnection(aconn);
5000 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
5001 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
5003 UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
5004 struct volintInfo **resultPtr, afs_int32 * size)
5006 struct rx_connection *aconn;
5008 volEntries volumeInfo;
5012 *resultPtr = (volintInfo *) 0;
5013 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5014 volumeInfo.volEntries_len = 0;
5016 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5017 code = AFSVolListVolumes(aconn, apart, all, &volumeInfo);
5020 "Could not fetch the list of volumes from the server\n");
5022 *resultPtr = volumeInfo.volEntries_val;
5023 *size = volumeInfo.volEntries_len;
5027 rx_DestroyConnection(aconn);
5028 PrintError("", code);
5032 /*------------------------------------------------------------------------
5033 * EXPORTED UV_XListVolumes
5036 * List the extended information for all the volumes on a particular
5037 * File Server and partition. We may either return the volume's ID
5038 * or all of its extended information.
5041 * a_serverID : Address of the File Server for which we want
5042 * extended volume info.
5043 * a_partID : Partition for which we want the extended
5045 * a_all : If non-zero, fetch ALL the volume info,
5046 * otherwise just the volume ID.
5047 * a_resultPP : Ptr to the address of the area containing
5048 * the returned volume info.
5049 * a_numEntsInResultP : Ptr for the value we set for the number of
5054 * Otherise, the return value of AFSVolXListVolumes.
5057 * This routine is closely related to UV_ListVolumes, which returns
5058 * only the standard level of detail on AFS volumes. It is a
5059 * heavyweight operation, zipping through all the volume entries for
5060 * a given server/partition.
5064 *------------------------------------------------------------------------*/
5067 UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
5068 struct volintXInfo **a_resultPP,
5069 afs_int32 * a_numEntsInResultP)
5071 struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */
5072 afs_int32 code; /*Error code to return */
5073 volXEntries volumeXInfo; /*Area for returned extended vol info */
5076 * Set up our error code and the area for returned extended volume info.
5077 * We set the val field to a null pointer as a hint for the stub to
5081 *a_numEntsInResultP = 0;
5082 *a_resultPP = (volintXInfo *) 0;
5083 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5084 volumeXInfo.volXEntries_len = 0;
5087 * Bind to the Volume Server port on the File Server machine in question,
5090 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5091 code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo);
5093 fprintf(STDERR, "[UV_XListVolumes] Couldn't fetch volume list\n");
5096 * We got the info; pull out the pointer to where the results lie
5097 * and how many entries are there.
5099 *a_resultPP = volumeXInfo.volXEntries_val;
5100 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
5104 * If we got an Rx connection, throw it away.
5107 rx_DestroyConnection(rxConnP);
5109 PrintError("", code);
5111 } /*UV_XListVolumes */
5113 /* get all the information about volume <volid> on <aserver> and <apart> */
5115 UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
5116 struct volintInfo **resultPtr)
5118 struct rx_connection *aconn;
5120 volEntries volumeInfo;
5124 *resultPtr = (volintInfo *) 0;
5125 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
5126 volumeInfo.volEntries_len = 0;
5128 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5129 code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo);
5132 "Could not fetch the information about volume %lu from the server\n",
5133 (unsigned long)volid);
5135 *resultPtr = volumeInfo.volEntries_val;
5140 rx_DestroyConnection(aconn);
5141 PrintError("", code);
5145 /*------------------------------------------------------------------------
5146 * EXPORTED UV_XListOneVolume
5149 * List the extended information for a volume on a particular File
5150 * Server and partition.
5153 * a_serverID : Address of the File Server for which we want
5154 * extended volume info.
5155 * a_partID : Partition for which we want the extended
5157 * a_volID : Volume ID for which we want the info.
5158 * a_resultPP : Ptr to the address of the area containing
5159 * the returned volume info.
5163 * Otherise, the return value of AFSVolXListOneVolume.
5166 * This routine is closely related to UV_ListOneVolume, which returns
5167 * only the standard level of detail on the chosen AFS volume.
5171 *------------------------------------------------------------------------*/
5174 UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
5175 struct volintXInfo **a_resultPP)
5177 struct rx_connection *rxConnP; /*Rx connection to Volume Server */
5178 afs_int32 code; /*Error code */
5179 volXEntries volumeXInfo; /*Area for returned info */
5182 * Set up our error code, and the area we're in which we are returning
5183 * the info. Setting the val field to a null pointer tells the stub
5184 * to allocate space for us.
5187 *a_resultPP = (volintXInfo *) 0;
5188 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
5189 volumeXInfo.volXEntries_len = 0;
5192 * Bind to the Volume Server port on the File Server machine in question,
5195 rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT);
5196 code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo);
5199 "[UV_XListOneVolume] Couldn't fetch the volume information\n");
5202 * We got the info; pull out the pointer to where the results lie.
5204 *a_resultPP = volumeXInfo.volXEntries_val;
5207 * If we got an Rx connection, throw it away.
5210 rx_DestroyConnection(rxConnP);
5212 PrintError("", code);
5217 * Given a volume we read from a partition, check if it is
5218 * represented in the VLDB correctly.
5220 * The VLDB is looked up by the RW volume id (not its name).
5221 * The RW contains the true name of the volume (BK and RO set
5222 * the name in the VLDB only on creation of the VLDB entry).
5223 * We want rules strict enough that when we check all volumes
5224 * on one partition, it does not need to be done again. IE:
5225 * two volumes on different partitions won't constantly
5226 * change a VLDB entry away from what the other set.
5227 * For RW and BK volumes, we will always check the VLDB to see
5228 * if the two exist on the server/partition. May seem redundant,
5229 * but this is an easy check of the VLDB. IE: if the VLDB entry
5230 * says the BK exists but no BK volume is there, we will detect
5231 * this when we check the RW volume.
5232 * VLDB entries are locked only when a change needs to be done.
5233 * Output changed to look a lot like the "vos syncserv" otuput.
5236 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
5237 afs_int32 * modentry, afs_uint32 * maxvolid)
5240 afs_int32 code, error = 0;
5241 struct nvldbentry entry, storeEntry;
5243 int pass = 0, islocked = 0, createentry, addvolume, modified, mod;
5249 ((volumeinfo->type ==
5250 RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
5253 /* Check to see if the VLDB is ok without locking it (pass 1).
5254 * If it will change, then lock the VLDB entry, read it again,
5255 * then make the changes to it (pass 2).
5258 code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL, VLOP_DELETE);
5260 fprintf(STDERR, "Could not lock VLDB entry for %lu\n",
5261 (unsigned long)rwvolid);
5267 createentry = 0; /* Do we need to create a VLDB entry */
5268 addvolume = 0; /* Add this volume to the VLDB entry */
5269 modified = 0; /* The VLDB entry was modified */
5271 /* Read the entry from VLDB by its RW volume id */
5272 code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
5274 if (code != VL_NOENT) {
5276 "Could not retreive the VLDB entry for volume %lu \n",
5277 (unsigned long)rwvolid);
5281 memset(&entry, 0, sizeof(entry));
5282 vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */
5286 MapHostToNetwork(&entry);
5289 if (verbose && (pass == 1)) {
5290 fprintf(STDOUT, "_______________________________\n");
5291 fprintf(STDOUT, "\n-- status before -- \n");
5293 fprintf(STDOUT, "\n**does not exist**\n");
5295 if ((entry.flags & RW_EXISTS) || (entry.flags & RO_EXISTS)
5296 || (entry.flags & BACK_EXISTS))
5297 EnumerateEntry(&entry);
5299 fprintf(STDOUT, "\n");
5302 if (volumeinfo->type == RWVOL) { /* RW volume exists */
5308 /* Check existence of RW and BK volumes */
5309 code = CheckVldbRWBK(&entry, &mod);
5315 idx = Lp_GetRwIndex(&entry);
5316 if (idx == -1) { /* RW index not found in the VLDB entry */
5317 idx = entry.nServers; /* put it into next index */
5320 } else { /* RW index found in the VLDB entry. */
5321 /* Verify if this volume's location matches where the VLDB says it is */
5322 if (!Lp_Match(aserver, apart, &entry)) {
5323 if (entry.flags & RW_EXISTS) {
5324 /* The RW volume exists elsewhere - report this one a duplicate */
5326 MapPartIdIntoName(apart, pname);
5328 "*** Warning: Orphaned RW volume %lu exists on %s %s\n",
5329 (unsigned long)rwvolid,
5330 hostutil_GetNameByINet(aserver), pname);
5331 MapPartIdIntoName(entry.serverPartition[idx],
5334 " VLDB reports RW volume %lu exists on %s %s\n",
5335 (unsigned long)rwvolid,
5336 hostutil_GetNameByINet(entry.
5341 /* The RW volume does not exist - have VLDB point to this one */
5344 /* Check for orphaned BK volume on old partition */
5345 if (entry.flags & BACK_EXISTS) {
5347 MapPartIdIntoName(entry.serverPartition[idx],
5350 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5351 entry.volumeId[BACKVOL],
5352 hostutil_GetNameByINet(entry.
5355 MapPartIdIntoName(apart, pname);
5357 " VLDB reports its RW volume %lu exists on %s %s\n",
5358 (unsigned long)rwvolid,
5359 hostutil_GetNameByINet(aserver),
5365 /* Volume location matches the VLDB location */
5366 if ((volumeinfo->backupID && !entry.volumeId[BACKVOL])
5367 || (volumeinfo->cloneID && !entry.volumeId[ROVOL])
5370 (entry.name, volumeinfo->name,
5371 VOLSER_OLDMAXVOLNAME) != 0)) {
5379 entry.flags |= RW_EXISTS;
5380 entry.volumeId[RWVOL] = rwvolid;
5381 if (!entry.volumeId[BACKVOL])
5382 entry.volumeId[BACKVOL] = volumeinfo->backupID;
5383 if (!entry.volumeId[ROVOL])
5384 entry.volumeId[ROVOL] = volumeinfo->cloneID;
5386 entry.serverFlags[idx] = ITSRWVOL;
5387 entry.serverNumber[idx] = aserver;
5388 entry.serverPartition[idx] = apart;
5389 strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME);
5393 /* One last check - to update BK if need to */
5394 code = CheckVldbRWBK(&entry, &mod);
5402 else if (volumeinfo->type == BACKVOL) { /* A BK volume */
5408 /* Check existence of RW and BK volumes */
5409 code = CheckVldbRWBK(&entry, &mod);
5415 idx = Lp_GetRwIndex(&entry);
5416 if (idx == -1) { /* RW index not found in the VLDB entry */
5417 idx = entry.nServers; /* Put it into next index */
5420 } else { /* RW index found in the VLDB entry */
5421 /* Verify if this volume's location matches where the VLDB says it is */
5422 if (!Lp_Match(aserver, apart, &entry)) {
5423 /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */
5425 MapPartIdIntoName(apart, pname);
5427 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5428 (unsigned long)volumeinfo->volid,
5429 hostutil_GetNameByINet(aserver), pname);
5430 MapPartIdIntoName(entry.serverPartition[idx], pname);
5432 " VLDB reports its RW/BK volume %lu exists on %s %s\n",
5433 (unsigned long)rwvolid,
5434 hostutil_GetNameByINet(entry.
5439 if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
5440 if (!(entry.flags & BACK_EXISTS)) {
5442 } else if (volumeinfo->volid >
5443 entry.volumeId[BACKVOL]) {
5447 MapPartIdIntoName(entry.serverPartition[idx],
5450 "*** Warning: Orphaned BK volume %u exists on %s %s\n",
5451 entry.volumeId[BACKVOL],
5452 hostutil_GetNameByINet(aserver),
5455 " VLDB reports its BK volume ID is %lu\n",
5456 (unsigned long)volumeinfo->volid);
5460 MapPartIdIntoName(entry.serverPartition[idx],
5463 "*** Warning: Orphaned BK volume %lu exists on %s %s\n",
5464 (unsigned long)volumeinfo->volid,
5465 hostutil_GetNameByINet(aserver),
5468 " VLDB reports its BK volume ID is %u\n",
5469 entry.volumeId[BACKVOL]);
5472 } else if (!entry.volumeId[BACKVOL]) {
5479 entry.flags |= BACK_EXISTS;
5480 entry.volumeId[RWVOL] = rwvolid;
5481 entry.volumeId[BACKVOL] = volumeinfo->volid;
5483 entry.serverNumber[idx] = aserver;
5484 entry.serverPartition[idx] = apart;
5485 entry.serverFlags[idx] = ITSRWVOL;
5491 else if (volumeinfo->type == ROVOL) { /* A RO volume */
5492 if (volumeinfo->volid == entry.volumeId[ROVOL]) {
5493 /* This is a quick check to see if the RO entry exists in the
5494 * VLDB so we avoid the CheckVldbRO() call (which checks if each
5495 * RO volume listed in the VLDB exists).
5497 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5499 idx = entry.nServers;
5503 if (!(entry.flags & RO_EXISTS)) {
5508 /* Before we correct the VLDB entry, make sure all the
5509 * ROs listed in the VLDB exist.
5511 code = CheckVldbRO(&entry, &mod);
5517 if (!(entry.flags & RO_EXISTS)) {
5518 /* No RO exists in the VLDB entry - add this one */
5519 idx = entry.nServers;
5522 } else if (volumeinfo->volid > entry.volumeId[ROVOL]) {
5523 /* The volume headers's RO ID does not match that in the VLDB entry,
5524 * and the vol hdr's ID is greater (implies more recent). So delete
5525 * all the RO volumes listed in VLDB entry and add this volume.
5527 for (j = 0; j < entry.nServers; j++) {
5528 if (entry.serverFlags[j] & ITSROVOL) {
5529 /* Verify this volume exists and print message we are orphaning it */
5531 MapPartIdIntoName(apart, pname);
5533 "*** Warning: Orphaned RO volume %u exists on %s %s\n",
5534 entry.volumeId[ROVOL],
5535 hostutil_GetNameByINet(entry.
5539 " VLDB reports its RO volume ID is %lu\n",
5540 (unsigned long)volumeinfo->volid);
5543 Lp_SetRWValue(entry, entry.serverNumber[idx],
5544 entry.serverPartition[idx], 0L, 0L);
5551 idx = entry.nServers;
5554 } else if (volumeinfo->volid < entry.volumeId[ROVOL]) {
5555 /* The volume headers's RO ID does not match that in the VLDB entry,
5556 * and the vol hdr's ID is lower (implies its older). So orphan it.
5559 MapPartIdIntoName(apart, pname);
5561 "*** Warning: Orphaned RO volume %lu exists on %s %s\n",
5562 (unsigned long)volumeinfo->volid,
5563 hostutil_GetNameByINet(aserver), pname);
5565 " VLDB reports its RO volume ID is %u\n",
5566 entry.volumeId[ROVOL]);
5569 /* The RO volume ID in the volume header match that in the VLDB entry,
5570 * and there exist RO volumes in the VLDB entry. See if any of them
5571 * are this one. If not, then we add it.
5573 idx = Lp_ROMatch(aserver, apart, &entry) - 1;
5575 idx = entry.nServers;
5583 entry.flags |= RO_EXISTS;
5584 entry.volumeId[RWVOL] = rwvolid;
5585 entry.volumeId[ROVOL] = volumeinfo->volid;
5587 entry.serverNumber[idx] = aserver;
5588 entry.serverPartition[idx] = apart;
5589 entry.serverFlags[idx] = ITSROVOL;
5595 /* Remember largest volume id */
5596 if (entry.volumeId[ROVOL] > *maxvolid)
5597 *maxvolid = entry.volumeId[ROVOL];
5598 if (entry.volumeId[BACKVOL] > *maxvolid)
5599 *maxvolid = entry.volumeId[BACKVOL];
5600 if (entry.volumeId[RWVOL] > *maxvolid)
5601 *maxvolid = entry.volumeId[RWVOL];
5604 MapNetworkToHost(&entry, &storeEntry);
5607 code = VLDB_CreateEntry(&storeEntry);
5610 "Could not create a VLDB entry for the volume %lu\n",
5611 (unsigned long)rwvolid);
5618 VLDB_ReplaceEntry(rwvolid, RWVOL, &storeEntry,
5619 LOCKREL_OPCODE | LOCKREL_AFSID |
5622 fprintf(STDERR, "Could not update entry for %lu\n",
5623 (unsigned long)rwvolid);
5628 *modentry = modified;
5629 } else if (pass == 2) {
5631 ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
5632 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
5634 PrintError("Could not unlock VLDB entry ", code);
5639 fprintf(STDOUT, "-- status after --\n");
5641 EnumerateEntry(&entry);
5643 fprintf(STDOUT, "\n**no change**\n");
5647 VPRINT("\n_______________________________\n");
5652 sortVolumes(const void *a, const void *b)
5654 volintInfo *v1 = (volintInfo *) a;
5655 volintInfo *v2 = (volintInfo *) b;
5656 afs_int32 rwvolid1, rwvolid2;
5658 rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
5659 rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
5661 if (rwvolid1 > rwvolid2)
5662 return -1; /* lower RW id goes first */
5663 if (rwvolid1 < rwvolid2)
5666 if (v1->type == RWVOL)
5667 return -1; /* RW vols go first */
5668 if (v2->type == RWVOL)
5671 if ((v1->type == BACKVOL) && (v2->type == ROVOL))
5672 return -1; /* BK vols next */
5673 if ((v1->type == ROVOL) && (v2->type == BACKVOL))
5676 if (v1->volid < v2->volid)
5677 return 1; /* larger volids first */
5678 if (v1->volid > v2->volid)
5684 * Synchronise <aserver> <apart>(if flags = 1) <avolid>.
5685 * Synchronize an individual volume against a sever and partition.
5686 * Checks the VLDB entry (similar to syncserv) as well as checks
5687 * if the volume exists on specified servers (similar to syncvldb).
5690 UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
5692 struct rx_connection *aconn = 0;
5693 afs_int32 j, k, code, vcode, error = 0;
5694 afs_int32 tverbose, mod, modified = 0;
5695 struct nvldbentry vldbentry;
5696 afs_int32 volumeid = 0;
5697 volEntries volumeInfo;
5698 struct partList PartList;
5700 afs_int32 maxvolid = 0;
5702 volumeInfo.volEntries_val = (volintInfo *) 0;
5703 volumeInfo.volEntries_len = 0;
5705 if (!aserver && flags) {
5706 /* fprintf(STDERR,"Partition option requires a server option\n"); */
5710 /* Turn verbose logging off and do our own verbose logging */
5714 /* Read the VLDB entry */
5715 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5716 if (vcode && (vcode != VL_NOENT)) {
5717 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5720 } else if (!vcode) {
5721 MapHostToNetwork(&vldbentry);
5725 fprintf(STDOUT, "Processing VLDB entry %s ...\n", avolname);
5726 fprintf(STDOUT, "_______________________________\n");
5727 fprintf(STDOUT, "\n-- status before -- \n");
5729 fprintf(STDOUT, "\n**does not exist**\n");
5731 if ((vldbentry.flags & RW_EXISTS) || (vldbentry.flags & RO_EXISTS)
5732 || (vldbentry.flags & BACK_EXISTS))
5733 EnumerateEntry(&vldbentry);
5735 fprintf(STDOUT, "\n");
5738 /* Verify that all of the VLDB entries exist on the repective servers
5739 * and partitions (this does not require that avolname be a volume ID).
5740 * Equivalent to a syncserv.
5743 code = CheckVldb(&vldbentry, &mod);
5745 fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
5753 /* If aserver is given, we will search for the desired volume on it */
5755 /* Generate array of partitions on the server that we will check */
5757 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5760 "Could not fetch the list of partitions from the server\n");
5764 PartList.partId[0] = apart;
5768 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5770 /* If a volume ID were given, search for it on each partition */
5771 if ((volumeid = atol(avolname))) {
5772 for (j = 0; j < pcnt; j++) {
5774 AFSVolListOneVolume(aconn, PartList.partId[j], volumeid,
5777 if (code != ENODEV) {
5778 fprintf(STDERR, "Could not query server\n");
5782 /* Found one, sync it with VLDB entry */
5784 CheckVolume(volumeInfo.volEntries_val, aserver,
5785 PartList.partId[j], &mod, &maxvolid);
5792 if (volumeInfo.volEntries_val)
5793 free(volumeInfo.volEntries_val);
5794 volumeInfo.volEntries_val = (volintInfo *) 0;
5795 volumeInfo.volEntries_len = 0;
5799 /* Check to see if the RW, BK, and RO IDs exist on any
5800 * partitions. We get the volume IDs from the VLDB.
5802 rv = 1; /* Read the VLDB entry ? */
5803 for (j = 0; j < MAXTYPES; j++) { /* for RW, RO, and BK IDs */
5805 vcode = VLDB_GetEntryByName(avolname, &vldbentry);
5807 if (vcode == VL_NOENT)
5810 "Could not access the VLDB for volume %s\n",
5817 if (vldbentry.volumeId[j] == 0)
5820 for (k = 0; k < pcnt; k++) { /* For each partition */
5821 volumeInfo.volEntries_val = (volintInfo *) 0;
5822 volumeInfo.volEntries_len = 0;
5824 AFSVolListOneVolume(aconn, PartList.partId[k],
5825 vldbentry.volumeId[j], &volumeInfo);
5827 if (code != ENODEV) {
5828 fprintf(STDERR, "Could not query server\n");
5832 /* Found one, sync it with VLDB entry */
5834 CheckVolume(volumeInfo.volEntries_val, aserver,
5835 PartList.partId[k], &mod, &maxvolid);
5842 if (volumeInfo.volEntries_val)
5843 free(volumeInfo.volEntries_val);
5844 volumeInfo.volEntries_val = (volintInfo *) 0;
5845 volumeInfo.volEntries_len = 0;
5851 /* If verbose output, print a summary of what changed */
5853 fprintf(STDOUT, "-- status after --\n");
5854 code = VLDB_GetEntryByName(avolname, &vldbentry);
5855 if (code && (code != VL_NOENT)) {
5856 fprintf(STDERR, "Could not access the VLDB for volume %s\n",
5860 if (modified && (code == VL_NOENT)) {
5861 fprintf(STDOUT, "\n**entry deleted**\n");
5862 } else if (modified) {
5863 EnumerateEntry(&vldbentry);
5865 fprintf(STDOUT, "\n**no change**\n");
5867 fprintf(STDOUT, "\n_______________________________\n");
5871 /* Now check if the maxvolid is larger than that stored in the VLDB */
5873 afs_int32 maxvldbid = 0;
5874 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
5877 "Could not get the highest allocated volume id from the VLDB\n");
5880 } else if (maxvolid > maxvldbid) {
5882 id = maxvolid - maxvldbid + 1;
5883 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
5886 "Error in increasing highest allocated volume id in VLDB\n");
5896 fprintf(STDOUT, "...error encountered");
5898 fprintf(STDOUT, "...done entry\n");
5901 rx_DestroyConnection(aconn);
5902 if (volumeInfo.volEntries_val)
5903 free(volumeInfo.volEntries_val);
5905 PrintError("", error);
5910 * Synchronise vldb with the file server <aserver> and,
5911 * optionally, <apart>.
5914 UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
5916 struct rx_connection *aconn;
5917 afs_int32 code, error = 0;
5919 volEntries volumeInfo;
5920 struct partList PartList;
5924 afs_int32 failures = 0, modifications = 0, tentries = 0;
5926 afs_uint32 maxvolid = 0;
5928 volumeInfo.volEntries_val = (volintInfo *) 0;
5929 volumeInfo.volEntries_len = 0;
5931 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
5933 /* Generate array of partitions to check */
5935 code = UV_ListPartitions(aserver, &PartList, &pcnt);
5938 "Could not fetch the list of partitions from the server\n");
5942 PartList.partId[0] = apart;
5946 VPRINT("Processing volume entries ...\n");
5948 /* Step through the array of partitions */
5949 for (i = 0; i < pcnt; i++) {
5950 apart = PartList.partId[i];
5951 MapPartIdIntoName(apart, pname);
5953 volumeInfo.volEntries_val = (volintInfo *) 0;
5954 volumeInfo.volEntries_len = 0;
5955 code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo);
5958 "Could not fetch the list of volumes from the server\n");
5962 /* May want to sort the entries: RW, BK (high to low), RO (high to low) */
5963 qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len,
5964 sizeof(volintInfo), sortVolumes);
5967 for (vi = volumeInfo.volEntries_val, j = 0;
5968 j < volumeInfo.volEntries_len; j++, vi++) {
5976 "Processing volume entry %d: %s (%lu) on server %s %s...\n",
5977 j + 1, vi->name, (unsigned long)vi->volid,
5978 hostutil_GetNameByINet(aserver), pname);
5982 code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
5984 PrintError("", code);
5987 } else if (modified) {
5993 fprintf(STDOUT, "...error encountered\n\n");
5995 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6002 "Could not process entries on server %s partition %s\n",
6003 hostutil_GetNameByINet(aserver), pname);
6005 if (volumeInfo.volEntries_val) {
6006 free(volumeInfo.volEntries_val);
6007 volumeInfo.volEntries_val = 0;
6010 } /* thru all partitions */
6012 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6013 failures, modifications);
6016 /* Now check if the maxvolid is larger than that stored in the VLDB */
6018 afs_int32 maxvldbid = 0;
6019 code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
6022 "Could not get the highest allocated volume id from the VLDB\n");
6025 } else if (maxvolid > maxvldbid) {
6027 id = maxvolid - maxvldbid + 1;
6028 code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
6031 "Error in increasing highest allocated volume id in VLDB\n");
6039 rx_DestroyConnection(aconn);
6040 if (volumeInfo.volEntries_val)
6041 free(volumeInfo.volEntries_val);
6042 PrintError("", error);
6047 * Determine if a volume exists on a server and partition.
6048 * Try creating a transaction on the volume. If we can,
6049 * the volume exists, if not, then return the error code.
6050 * Some error codes mean the volume is unavailable but
6051 * still exists - so we catch these error codes.
6054 VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
6056 struct rx_connection *conn = (struct rx_connection *)0;
6057 afs_int32 code = -1;
6058 volEntries volumeInfo;
6060 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6062 volumeInfo.volEntries_val = (volintInfo *) 0;
6063 volumeInfo.volEntries_len = 0;
6064 code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
6065 if (volumeInfo.volEntries_val)
6066 free(volumeInfo.volEntries_val);
6067 if (code == VOLSERILLEGAL_PARTITION)
6069 rx_DestroyConnection(conn);
6078 CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified)
6082 afs_int32 code, error = 0;
6087 idx = Lp_GetRwIndex(entry);
6089 /* Check to see if the RW volume exists and set the RW_EXISTS
6092 if (idx == -1) { /* Did not find a RW entry */
6093 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6094 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6099 VolumeExists(entry->serverNumber[idx],
6100 entry->serverPartition[idx], entry->volumeId[RWVOL]);
6101 if (code == 0) { /* RW volume exists */
6102 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does not exist */
6103 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
6106 } else if (code == ENODEV) { /* RW volume does not exist */
6107 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
6108 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
6112 /* If VLDB says it didn't exist, then ignore error */
6113 if (entry->flags & RW_EXISTS) {
6114 MapPartIdIntoName(entry->serverPartition[idx], pname);
6116 "Transaction call failed for RW volume %u on server %s %s\n",
6117 entry->volumeId[RWVOL],
6118 hostutil_GetNameByINet(entry->serverNumber[idx]),
6125 /* Check to see if the BK volume exists and set the BACK_EXISTS
6126 * flag accordingly. idx already ponts to the RW entry.
6128 if (idx == -1) { /* Did not find a RW entry */
6129 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6130 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6133 } else { /* Found a RW entry */
6135 VolumeExists(entry->serverNumber[idx],
6136 entry->serverPartition[idx],
6137 entry->volumeId[BACKVOL]);
6138 if (code == 0) { /* BK volume exists */
6139 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does not exist */
6140 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
6143 } else if (code == ENODEV) { /* BK volume does not exist */
6144 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
6145 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
6149 /* If VLDB says it didn't exist, then ignore error */
6150 if (entry->flags & BACK_EXISTS) {
6151 MapPartIdIntoName(entry->serverPartition[idx], pname);
6153 "Transaction call failed for BK volume %u on server %s %s\n",
6154 entry->volumeId[BACKVOL],
6155 hostutil_GetNameByINet(entry->serverNumber[idx]),
6162 /* If there is an idx but the BK and RW volumes no
6163 * longer exist, then remove the RW entry.
6165 if ((idx != -1) && !(entry->flags & RW_EXISTS)
6166 && !(entry->flags & BACK_EXISTS)) {
6167 Lp_SetRWValue(entry, entry->serverNumber[idx],
6168 entry->serverPartition[idx], 0L, 0L);
6175 *modified = modentry;
6180 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
6183 int foundro = 0, modentry = 0;
6184 afs_int32 code, error = 0;
6190 /* Check to see if the RO volumes exist and set the RO_EXISTS
6193 for (idx = 0; idx < entry->nServers; idx++) {
6194 if (!(entry->serverFlags[idx] & ITSROVOL)) {
6195 continue; /* not a RO */
6199 VolumeExists(entry->serverNumber[idx],
6200 entry->serverPartition[idx], entry->volumeId[ROVOL]);
6201 if (code == 0) { /* RO volume exists */
6203 } else if (code == ENODEV) { /* RW volume does not exist */
6204 Lp_SetROValue(entry, entry->serverNumber[idx],
6205 entry->serverPartition[idx], 0L, 0L);
6210 MapPartIdIntoName(entry->serverPartition[idx], pname);
6212 "Transaction call failed for RO %u on server %s %s\n",
6213 entry->volumeId[ROVOL],
6214 hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
6219 if (foundro) { /* A RO volume exists */
6220 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not exist */
6221 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
6224 } else { /* A RO volume does not exist */
6225 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
6226 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
6233 *modified = modentry;
6238 * Ensure that <entry> matches with the info on file servers
6241 CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
6243 afs_int32 code, error = 0;
6244 struct nvldbentry storeEntry;
6245 int islocked = 0, mod, modentry, delentry = 0;
6251 fprintf(STDOUT, "_______________________________\n");
6252 fprintf(STDOUT, "\n-- status before -- \n");
6253 if ((entry->flags & RW_EXISTS) || (entry->flags & RO_EXISTS)
6254 || (entry->flags & BACK_EXISTS))
6255 EnumerateEntry(entry);
6256 fprintf(STDOUT, "\n");
6259 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
6260 fprintf(STDERR, "Volume name %s exceeds limit of %d characters\n",
6261 entry->name, VOLSER_OLDMAXVOLNAME - 10);
6265 /* Check to see if the VLDB is ok without locking it (pass 1).
6266 * If it will change, then lock the VLDB entry, read it again,
6267 * then make the changes to it (pass 2).
6271 ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL,
6274 fprintf(STDERR, "Could not lock VLDB entry for %u \n",
6275 entry->volumeId[RWVOL]);
6280 code = VLDB_GetEntryByID(entry->volumeId[RWVOL], RWVOL, entry);
6282 fprintf(STDERR, "Could not read VLDB entry for volume %s\n",
6286 MapHostToNetwork(entry);
6292 /* Check if the RW and BK entries are ok */
6293 code = CheckVldbRWBK(entry, &mod);
6296 if (mod && (pass == 1))
6301 /* Check if the RO volumes entries are ok */
6302 code = CheckVldbRO(entry, &mod);
6305 if (mod && (pass == 1))
6310 /* The VLDB entry has been updated. If it as been modified, then
6311 * write the entry back out the the VLDB.
6317 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
6318 && !(entry->flags & RO_EXISTS)) {
6319 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
6321 ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
6325 "Could not delete VLDB entry for volume %u \n",
6326 entry->volumeId[RWVOL]);
6331 /* Replace old entry with our new one */
6332 MapNetworkToHost(entry, &storeEntry);
6334 VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry,
6335 (LOCKREL_OPCODE | LOCKREL_AFSID |
6336 LOCKREL_TIMESTAMP));
6338 fprintf(STDERR, "Could not update VLDB entry for volume %u\n",
6339 entry->volumeId[RWVOL]);
6349 fprintf(STDOUT, "-- status after --\n");
6351 fprintf(STDOUT, "\n**entry deleted**\n");
6353 EnumerateEntry(entry);
6355 fprintf(STDOUT, "\n**no change**\n");
6359 VPRINT("\n_______________________________\n");
6363 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6365 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
6368 "Could not release lock on VLDB entry for volume %u\n",
6369 entry->volumeId[RWVOL]);
6378 * Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
6381 UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
6383 struct rx_connection *aconn;
6384 afs_int32 code, error = 0;
6385 afs_int32 nentries, tentries = 0;
6386 struct VldbListByAttributes attributes;
6387 nbulkentries arrayEntries;
6388 afs_int32 failures = 0, modified, modifications = 0;
6389 struct nvldbentry *vlentry;
6390 afs_int32 si, nsi, j;
6392 aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
6394 /* Set up attributes to search VLDB */
6395 attributes.server = ntohl(aserver);
6396 attributes.Mask = VLLIST_SERVER;
6398 attributes.partition = apart;
6399 attributes.Mask |= VLLIST_PARTITION;
6402 VPRINT("Processing VLDB entries ...\n");
6404 /* While we need to collect more VLDB entries */
6405 for (si = 0; si != -1; si = nsi) {
6406 memset(&arrayEntries, 0, sizeof(arrayEntries));
6408 /* Collect set of VLDB entries */
6410 VLDB_ListAttributesN2(&attributes, 0, si, &nentries,
6411 &arrayEntries, &nsi);
6412 if (code == RXGEN_OPCODE) {
6413 code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
6417 fprintf(STDERR, "Could not access the VLDB for attributes\n");
6420 tentries += nentries;
6422 for (j = 0; j < nentries; j++) {
6423 vlentry = &arrayEntries.nbulkentries_val[j];
6424 MapHostToNetwork(vlentry);
6426 VPRINT1("Processing VLDB entry %d ...\n", j + 1);
6428 code = CheckVldb(vlentry, &modified);
6430 PrintError("", code);
6432 "Could not process VLDB entry for volume %s\n",
6435 } else if (modified) {
6441 fprintf(STDOUT, "...error encountered\n\n");
6443 fprintf(STDOUT, "...done entry %d\n\n", j + 1);
6448 if (arrayEntries.nbulkentries_val) {
6449 free(arrayEntries.nbulkentries_val);
6450 arrayEntries.nbulkentries_val = 0;
6454 VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
6455 failures, modifications);
6459 rx_DestroyConnection(aconn);
6460 if (arrayEntries.nbulkentries_val)
6461 free(arrayEntries.nbulkentries_val);
6464 error = VOLSERFAILEDOP;
6468 /*rename volume <oldname> to <newname>, changing the names of the related
6469 *readonly and backup volumes. This operation is also idempotent.
6470 *salvager is capable of recovering from rename operation stopping halfway.
6471 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
6473 UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
6475 struct nvldbentry storeEntry;
6476 afs_int32 vcode, code, rcode, error;
6478 char nameBuffer[256];
6480 struct rx_connection *aconn;
6484 aconn = (struct rx_connection *)0;
6488 vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
6491 " Could not lock the VLDB entry for the volume %u \n",
6492 entry->volumeId[RWVOL]);
6497 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
6498 MapNetworkToHost(entry, &storeEntry);
6499 vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL], RWVOL, &storeEntry, 0);
6501 fprintf(STDERR, "Could not update VLDB entry for %u\n",
6502 entry->volumeId[RWVOL]);
6506 VPRINT1("Recorded the new name %s in VLDB\n", newname);
6507 /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
6508 * is concerned, oldname is lost */
6509 if (entry->flags & RW_EXISTS) {
6510 index = Lp_GetRwIndex(entry);
6511 if (index == -1) { /* there is a serious discrepancy */
6513 "There is a serious discrepancy in VLDB entry for volume %u\n",
6514 entry->volumeId[RWVOL]);
6515 fprintf(STDERR, "try building VLDB from scratch\n");
6516 error = VOLSERVLDB_ERROR;
6519 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6521 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
6522 entry->serverPartition[index], ITOffline, &tid);
6523 if (code) { /*volume doesnot exist */
6525 "Could not start transaction on the rw volume %u\n",
6526 entry->volumeId[RWVOL]);
6529 } else { /*volume exists, process it */
6532 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
6533 entry->volumeId[RWVOL],
6534 entry->volumeId[ROVOL],
6535 entry->volumeId[BACKVOL]);
6537 VPRINT2("Renamed rw volume %s to %s\n", oldname, newname);
6538 code = AFSVolEndTrans(aconn, tid, &rcode);
6542 "Could not end transaction on volume %s %u\n",
6543 entry->name, entry->volumeId[RWVOL]);
6548 fprintf(STDERR, "Could not set parameters on volume %s %u\n",
6549 entry->name, entry->volumeId[RWVOL]);
6555 rx_DestroyConnection(aconn);
6556 aconn = (struct rx_connection *)0;
6558 /*end rw volume processing */
6559 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
6560 index = Lp_GetRwIndex(entry);
6561 if (index == -1) { /* there is a serious discrepancy */
6563 "There is a serious discrepancy in the VLDB entry for the backup volume %u\n",
6564 entry->volumeId[BACKVOL]);
6565 fprintf(STDERR, "try building VLDB from scratch\n");
6566 error = VOLSERVLDB_ERROR;
6569 aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
6571 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
6572 entry->serverPartition[index], ITOffline, &tid);
6573 if (code) { /*volume doesnot exist */
6575 "Could not start transaction on the backup volume %u\n",
6576 entry->volumeId[BACKVOL]);
6579 } else { /*volume exists, process it */
6580 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
6582 "Volume name %s.backup exceeds the limit of %u characters\n",
6583 newname, VOLSER_OLDMAXVOLNAME);
6587 strcpy(nameBuffer, newname);
6588 strcat(nameBuffer, ".backup");
6591 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
6592 entry->volumeId[RWVOL], 0, 0);
6594 VPRINT1("Renamed backup volume to %s \n", nameBuffer);
6595 code = AFSVolEndTrans(aconn, tid, &rcode);
6599 "Could not end transaction on the backup volume %u\n",
6600 entry->volumeId[BACKVOL]);
6606 "Could not set parameters on the backup volume %u\n",
6607 entry->volumeId[BACKVOL]);
6612 } /* end backup processing */
6614 rx_DestroyConnection(aconn);
6615 aconn = (struct rx_connection *)0;
6616 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
6617 for (i = 0; i < entry->nServers; i++) {
6618 if (entry->serverFlags[i] & ITSROVOL) {
6619 aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
6621 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
6622 entry->serverPartition[i], ITOffline,
6624 if (code) { /*volume doesnot exist */
6626 "Could not start transaction on the ro volume %u\n",
6627 entry->volumeId[ROVOL]);
6630 } else { /*volume exists, process it */
6631 strcpy(nameBuffer, newname);
6632 strcat(nameBuffer, ".readonly");
6633 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
6635 "Volume name %s exceeds the limit of %u characters\n",
6636 nameBuffer, VOLSER_OLDMAXVOLNAME);
6641 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
6642 entry->volumeId[RWVOL], 0, 0);
6644 VPRINT2("Renamed RO volume %s on host %s\n",
6646 hostutil_GetNameByINet(entry->
6648 code = AFSVolEndTrans(aconn, tid, &rcode);
6652 "Could not end transaction on volume %u\n",
6653 entry->volumeId[ROVOL]);
6659 "Could not set parameters on the ro volume %u\n",
6660 entry->volumeId[ROVOL]);
6666 rx_DestroyConnection(aconn);
6667 aconn = (struct rx_connection *)0;
6674 ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL],
6676 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
6679 "Could not unlock the VLDB entry for the volume %s %u\n",
6680 entry->name, entry->volumeId[RWVOL]);
6686 code = AFSVolEndTrans(aconn, tid, &rcode);
6690 fprintf(STDERR, "Failed to end transaction on a volume \n");
6696 rx_DestroyConnection(aconn);
6697 PrintError("", error);
6702 /*report on all the active transactions on volser */
6704 UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
6706 struct rx_connection *aconn;
6707 transDebugEntries transInfo;
6710 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6711 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
6712 transInfo.transDebugEntries_len = 0;
6713 code = AFSVolMonitor(aconn, &transInfo);
6716 "Could not access status information about the server\n");
6717 PrintError("", code);
6718 if (transInfo.transDebugEntries_val)
6719 free(transInfo.transDebugEntries_val);
6721 rx_DestroyConnection(aconn);
6724 *rcount = transInfo.transDebugEntries_len;
6725 *rpntr = transInfo.transDebugEntries_val;
6727 rx_DestroyConnection(aconn);
6734 /*delete the volume without interacting with the vldb */
6736 UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
6738 afs_int32 rcode, ttid, error, code;
6739 struct rx_connection *aconn;
6745 aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6746 code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
6748 fprintf(STDERR, "Could not start transaction on volume %lu\n",
6749 (unsigned long)volid);
6753 code = AFSVolDeleteVolume(aconn, ttid);
6755 fprintf(STDERR, "Could not delete volume %lu\n",
6756 (unsigned long)volid);
6760 code = AFSVolEndTrans(aconn, ttid, &rcode);
6765 fprintf(STDERR, "Could not end transaction on volume %lu\n",
6766 (unsigned long)volid);
6772 code = AFSVolEndTrans(aconn, ttid, &rcode);
6778 PrintError("", error);
6780 rx_DestroyConnection(aconn);
6785 UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
6786 afs_int32 transflag, afs_int32 setflag, int sleeptime)
6788 struct rx_connection *conn = 0;
6790 afs_int32 code, error = 0, rcode;
6792 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6794 fprintf(STDERR, "SetVolumeStatus: Bind Failed");
6798 code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
6800 fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
6804 code = AFSVolSetFlags(conn, tid, setflag);
6806 fprintf(STDERR, "SetVolumeStatus: SetFlags Failed\n");
6811 #ifdef AFS_PTHREAD_ENV
6814 IOMGR_Sleep(sleeptime);
6821 code = AFSVolEndTrans(conn, tid, &rcode);
6822 if (code || rcode) {
6823 fprintf(STDERR, "SetVolumeStatus: EndTrans Failed\n");
6825 error = (code ? code : rcode);
6830 rx_DestroyConnection(conn);
6835 UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
6838 struct rx_connection *conn = 0;
6840 afs_int32 code, error = 0, rcode;
6842 conn = UV_Bind(server, AFSCONF_VOLUMEPORT);
6844 fprintf(STDERR, "SetVolumeInfo: Bind Failed");
6848 code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
6850 fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
6854 code = AFSVolSetInfo(conn, tid, infop);
6856 fprintf(STDERR, "SetVolumeInfo: SetInfo Failed\n");
6863 code = AFSVolEndTrans(conn, tid, &rcode);
6864 if (code || rcode) {
6865 fprintf(STDERR, "SetVolumeInfo: EndTrans Failed\n");
6867 error = (code ? code : rcode);
6872 rx_DestroyConnection(conn);
6877 UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
6878 afs_int32 fromdate, struct volintSize *vol_size)
6880 struct rx_connection *aconn = (struct rx_connection *)0;
6881 afs_int32 tid = 0, rcode = 0;
6882 afs_int32 code, error = 0;
6885 /* get connections to the servers */
6886 aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
6888 VPRINT1("Starting transaction on volume %u...", afromvol);
6889 code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
6890 EGOTO1(error_exit, code,
6891 "Could not start transaction on the volume %u to be measured\n",
6895 VPRINT1("Getting size of volume on volume %u...", afromvol);
6896 code = AFSVolGetSize(aconn, tid, fromdate, vol_size);
6897 EGOTO(error_exit, code, "Could not start the measurement process \n");
6902 VPRINT1("Ending transaction on volume %u...", afromvol);
6903 code = AFSVolEndTrans(aconn, tid, &rcode);
6904 if (code || rcode) {
6905 fprintf(STDERR, "Could not end transaction on the volume %u\n",
6907 fprintf(STDERR, "error codes: %d and %d\n", code, rcode);
6909 error = (code ? code : rcode);
6914 rx_DestroyConnection(aconn);
6916 PrintError("", error);
6920 /*maps the host addresses in <old > (present in network byte order) to
6921 that in< new> (present in host byte order )*/
6923 MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new)
6927 /*copy all the fields */
6928 strcpy(new->name, old->name);
6929 /* new->volumeType = old->volumeType;*/
6930 new->nServers = old->nServers;
6931 count = old->nServers;
6932 if (count < NMAXNSERVERS)
6934 for (i = 0; i < count; i++) {
6935 new->serverNumber[i] = ntohl(old->serverNumber[i]);
6936 new->serverPartition[i] = old->serverPartition[i];
6937 new->serverFlags[i] = old->serverFlags[i];
6939 new->volumeId[RWVOL] = old->volumeId[RWVOL];
6940 new->volumeId[ROVOL] = old->volumeId[ROVOL];
6941 new->volumeId[BACKVOL] = old->volumeId[BACKVOL];
6942 new->cloneId = old->cloneId;
6943 new->flags = old->flags;
6946 /*maps the host entries in <entry> which are present in host byte order to network byte order */
6948 MapHostToNetwork(struct nvldbentry *entry)
6952 count = entry->nServers;
6953 if (count < NMAXNSERVERS)
6955 for (i = 0; i < count; i++) {
6956 entry->serverNumber[i] = htonl(entry->serverNumber[i]);