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
11 * This file is a reimplementation of volser/vsproc.s. Every attempt
12 * has been made to keep it as similar as possible to aid comprehension
13 * of the code. For most functions, two parameters have been added
14 * the cell handle, and a status variable. For those functions that
15 * require one, a server handle may also be added.
17 * Other changes were made to provide thread safe functions and
18 * eliminate the practice of reporting errors to STDOUT.
21 #include <afsconfig.h>
22 #include <afs/param.h>
26 #include <afs/afs_AdminErrors.h>
30 #include "lockprocs.h"
31 #include "../adminutil/afs_AdminInternal.h"
32 #include "afs_vosAdmin.h"
34 static afs_int32 GroupEntries(struct rx_connection *server, volintInfo * pntr, afs_int32 count,
35 struct qHead *myQueue, afs_int32 apart);
39 afs_int32 vldbEntryIndex;
42 static struct rx_connection *
43 UV_Bind(afs_cell_handle_p cellHandle, afs_int32 aserver, afs_int32 port)
45 return rx_GetCachedConnection(htonl(aserver), htons(port), VOLSERVICE_ID,
46 cellHandle->tokens->afs_sc[cellHandle->
49 cellHandle->tokens->sc_index);
53 /* if <okvol> is allright(indicated by beibg able to
54 * start a transaction, delete the <delvol> */
56 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
57 afs_uint32 okvol, afs_uint32 delvol)
59 afs_int32 error, code, tid, rcode;
64 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
67 code = AFSVolDeleteVolume(aconn, tid);
70 code = AFSVolEndTrans(aconn, tid, &rcode);
77 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
79 code = AFSVolEndTrans(aconn, tid, &rcode);
84 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
87 code = AFSVolDeleteVolume(aconn, tid);
90 code = AFSVolEndTrans(aconn, tid, &rcode);
101 /* forcibly remove a volume. Very dangerous call */
103 UV_NukeVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
104 unsigned int partition, afs_uint32 volumeId, afs_status_p st)
107 afs_status_t tst = 0;
109 tst = AFSVolNukeVolume(server, partition, volumeId);
121 /* create a volume, given a server, partition number, volume name --> sends
122 * back new vol id in <anewid>*/
124 UV_CreateVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
125 unsigned int partition, char *volumeName,
126 unsigned int quota, afs_uint32 *volumeId, afs_status_p st)
129 afs_status_t tst = 0;
132 struct nvldbentry entry;
133 struct volintInfo tstatus;
135 memset(&tstatus, 0, sizeof(tstatus));
137 tstatus.maxquota = quota;
139 /* next the next 3 available ids from the VLDB */
140 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 3, volumeId);
142 goto fail_UV_CreateVolume;
146 AFSVolCreateVolume(server, partition, volumeName, volser_RW, 0,
149 goto fail_UV_CreateVolume;
152 AFSVolSetInfo(server, tid, &tstatus);
154 tst = AFSVolSetFlags(server, tid, 0);
156 goto fail_UV_CreateVolume;
159 /* set up the vldb entry for this volume */
160 strncpy(entry.name, volumeName, VOLSER_OLDMAXVOLNAME);
162 entry.serverNumber[0] = ntohl(rx_HostOf(rx_PeerOf(server)));
163 entry.serverPartition[0] = partition;
164 entry.flags = RW_EXISTS;
165 entry.serverFlags[0] = ITSRWVOL;
166 entry.volumeId[RWVOL] = *volumeId;
167 entry.volumeId[ROVOL] = *volumeId + 1;
168 entry.volumeId[BACKVOL] = *volumeId + 2;
171 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
172 AFSVolDeleteVolume(server, tid);
173 goto fail_UV_CreateVolume;
176 tst = AFSVolEndTrans(server, tid, &rcode);
179 goto fail_UV_CreateVolume;
183 fail_UV_CreateVolume:
186 AFSVolEndTrans(server, tid, &rcode);
196 /* Delete the volume <volid>on <aserver> <apart>
197 * the physical entry gets removed from the vldb only if the ref count
201 UV_DeleteVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
202 unsigned int partition, afs_uint32 volumeId,
206 afs_status_t tst = 0;
207 afs_status_t temp = 0;
208 int serverAddr = ntohl(rx_HostOf(rx_PeerOf(server)));
212 struct nvldbentry entry;
214 afs_int32 avoltype = -1, vtype;
215 int notondisk = 0, notinvldb = 0;
217 /* Find and read the VLDB entry for this volume */
219 ubik_VL_SetLock(cellHandle->vos, 0, volumeId, avoltype,
222 if (tst != VL_NOENT) {
223 goto fail_UV_DeleteVolume;
229 if (!aVLDB_GetEntryByID(cellHandle, volumeId, avoltype, &entry, &tst)) {
230 goto fail_UV_DeleteVolume;
235 /* Whether volume is in the VLDB or not. Delete the volume on disk */
236 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
241 goto fail_UV_DeleteVolume;
244 tst = AFSVolDeleteVolume(server, ttid);
246 goto fail_UV_DeleteVolume;
248 tst = AFSVolEndTrans(server, ttid, &rcode);
249 tst = (tst ? tst : rcode);
252 goto fail_UV_DeleteVolume;
257 goto fail_UV_DeleteVolume;
260 if (volumeId == entry.volumeId[BACKVOL]) {
261 if (!(entry.flags & BACK_EXISTS)
262 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
264 goto fail_UV_DeleteVolume;
267 entry.flags &= ~BACK_EXISTS;
271 else if (volumeId == entry.volumeId[ROVOL]) {
272 if (!Lp_ROMatch(cellHandle, &entry, serverAddr, partition, &tst)) {
274 goto fail_UV_DeleteVolume;
277 Lp_SetROValue(cellHandle, &entry, serverAddr, partition, 0, 0);
279 if (!Lp_ROMatch(cellHandle, &entry, 0, 0, &tst)) {
280 entry.flags &= ~RO_EXISTS;
285 else if (volumeId == entry.volumeId[RWVOL]) {
286 if (!(entry.flags & RW_EXISTS)
287 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
289 goto fail_UV_DeleteVolume;
292 /* Delete backup if it exists */
294 AFSVolTransCreate(server, entry.volumeId[BACKVOL], partition,
297 tst = AFSVolDeleteVolume(server, ttid);
299 goto fail_UV_DeleteVolume;
301 tst = AFSVolEndTrans(server, ttid, &rcode);
303 tst = (tst ? tst : rcode);
305 goto fail_UV_DeleteVolume;
309 Lp_SetRWValue(cellHandle, &entry, serverAddr, partition, 0L, 0L);
311 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
317 notinvldb = 2; /* Not found on this server and partition */
318 goto fail_UV_DeleteVolume;
321 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
322 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volumeId, vtype);
324 goto fail_UV_DeleteVolume;
327 if (!VLDB_ReplaceEntry
328 (cellHandle, volumeId, vtype, &entry,
329 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
330 goto fail_UV_DeleteVolume;
336 fail_UV_DeleteVolume:
338 if (notondisk && notinvldb) {
340 tst = ADMVOSVOLUMENOEXIST;
344 temp = AFSVolEndTrans(server, ttid, &rcode);
345 temp = (temp ? temp : rcode);
354 ubik_VL_ReleaseLock(cellHandle->vos, 0, volumeId, -1,
355 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
368 #define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto mfail; }
370 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
371 * <atopart>. The operation is almost idempotent
375 UV_MoveVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
376 afs_int32 afromserver, afs_int32 afrompart, afs_int32 atoserver,
377 afs_int32 atopart, afs_status_p st)
380 afs_status_t tst = 0;
381 afs_status_t etst = 0;
382 struct rx_connection *toconn, *fromconn;
383 afs_int32 fromtid, totid, clonetid;
386 char tmpName[VOLSER_MAXVOLNAME + 1];
389 struct restoreCookie cookie;
390 afs_uint32 newVol, volid, backupId;
391 struct volser_status tstatus;
392 struct destServer destination;
394 struct nvldbentry entry;
397 afs_int32 store_flags;
399 #ifdef ENABLE_BUGFIX_1165
400 volEntries volumeInfo;
401 struct volintInfo *infop = 0;
405 fromconn = (struct rx_connection *)0;
406 toconn = (struct rx_connection *)0;
414 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
415 goto fail_UV_MoveVolume;
418 if (entry.volumeId[RWVOL] != afromvol) {
419 tst = ADMVOSVOLUMEMOVERWONLY;
420 goto fail_UV_MoveVolume;
424 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL, VLOP_MOVE);
426 goto fail_UV_MoveVolume;
430 if (!aVLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
431 goto fail_UV_MoveVolume;
434 backupId = entry.volumeId[BACKVOL];
436 if (!Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst)) {
437 /* the from server and partition do not exist in the vldb entry corresponding to volid */
438 if (!Lp_Match(cellHandle, &entry, atoserver, atopart, &tst)) {
439 /* the to server and partition do not exist in the vldb entry corresponding to volid */
441 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
442 (LOCKREL_OPCODE | LOCKREL_AFSID |
445 goto fail_UV_MoveVolume;
447 tst = VOLSERVOLMOVED;
448 goto fail_UV_MoveVolume;
451 /* delete the volume afromvol on src_server */
452 /* from-info does not exist but to-info does =>
453 * we have already done the move, but the volume
454 * may still be existing physically on from fileserver
456 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
460 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
462 if (!tst) { /* volume exists - delete it */
464 AFSVolSetFlags(fromconn, fromtid,
465 VTDeleteOnSalvage | VTOutOfService);
467 goto fail_UV_MoveVolume;
470 tst = AFSVolDeleteVolume(fromconn, fromtid);
472 goto fail_UV_MoveVolume;
475 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
480 goto fail_UV_MoveVolume;
484 /*delete the backup volume now */
487 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
489 if (!tst) { /* backup volume exists - delete it */
491 AFSVolSetFlags(fromconn, fromtid,
492 VTDeleteOnSalvage | VTOutOfService);
494 goto fail_UV_MoveVolume;
497 tst = AFSVolDeleteVolume(fromconn, fromtid);
499 goto fail_UV_MoveVolume;
502 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
507 goto fail_UV_MoveVolume;
512 goto fail_UV_MoveVolume;
515 /* From-info matches the vldb info about volid,
516 * its ok start the move operation, the backup volume
517 * on the old site is deleted in the process
519 if (afrompart == atopart) {
520 if (!VLDB_IsSameAddrs
521 (cellHandle, afromserver, atoserver, &same, &tst)) {
522 goto fail_UV_MoveVolume;
525 tst = VOLSERVOLMOVED;
526 goto fail_UV_MoveVolume;
530 toconn = UV_Bind(cellHandle, atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
531 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
532 fromtid = totid = 0; /* initialize to uncreated */
535 * clone the read/write volume locally.
538 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
540 goto fail_UV_MoveVolume;
545 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &newVol);
547 goto fail_UV_MoveVolume;
550 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
551 strcpy(vname, "move-clone-temp");
552 tst = AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
554 goto fail_UV_MoveVolume;
557 /* lookup the name of the volume we just cloned */
559 tst = AFSVolGetName(fromconn, fromtid, &volName);
561 goto fail_UV_MoveVolume;
565 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
570 goto fail_UV_MoveVolume;
574 * Create the destination volume
578 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
580 goto fail_UV_MoveVolume;
582 tst = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
584 goto fail_UV_MoveVolume;
587 /* remember time from which we've dumped the volume */
588 tst = AFSVolGetStatus(fromconn, clonetid, &tstatus);
590 goto fail_UV_MoveVolume;
593 fromDate = tstatus.creationDate - CLOCKSKEW;
595 #ifdef ENABLE_BUGFIX_1165
597 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
598 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
599 * don't use this information...
601 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
602 volumeInfo.volEntries_len = 0;
603 tst = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
605 goto fail_UV_MoveVolume;
608 infop = (volintInfo *) volumeInfo.volEntries_val;
609 infop->maxquota = -1; /* Else it will replace the default quota */
612 /* create a volume on the target machine */
614 tst = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
615 if (!tst) { /*delete the existing volume */
617 tst = AFSVolDeleteVolume(toconn, totid);
619 goto fail_UV_MoveVolume;
622 tst = AFSVolEndTrans(toconn, totid, &rcode);
627 goto fail_UV_MoveVolume;
633 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
636 goto fail_UV_MoveVolume;
639 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
643 tst = AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
645 goto fail_UV_MoveVolume;
649 * Now dump the clone to the new volume
652 destination.destHost = atoserver;
653 destination.destPort = AFSCONF_VOLUMEPORT;
654 destination.destSSID = 1;
656 /* Copy the clone to the new volume */
657 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
659 cookie.parent = entry.volumeId[RWVOL];
661 tst = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
663 goto fail_UV_MoveVolume;
666 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
671 goto fail_UV_MoveVolume;
675 * reattach to the main-line volume, and incrementally dump it.
678 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
680 goto fail_UV_MoveVolume;
683 /* now do the incremental */
685 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
688 goto fail_UV_MoveVolume;
691 /* now adjust the flags so that the new volume becomes official */
692 tst = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
694 goto fail_UV_MoveVolume;
697 tst = AFSVolSetFlags(toconn, totid, 0);
699 goto fail_UV_MoveVolume;
701 #ifdef ENABLE_BUGFIX_1165
702 tst = AFSVolSetInfo(toconn, totid, infop);
704 goto fail_UV_MoveVolume;
708 /* put new volume online */
709 tst = AFSVolEndTrans(toconn, totid, &rcode);
714 goto fail_UV_MoveVolume;
717 Lp_SetRWValue(cellHandle, &entry, afromserver, afrompart, atoserver,
719 store_flags = entry.flags;
720 entry.flags &= ~BACK_EXISTS;
722 if (!VLDB_ReplaceEntry
723 (cellHandle, afromvol, -1, &entry,
724 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
725 goto fail_UV_MoveVolume;
727 entry.flags = store_flags;
730 if (atoserver != afromserver) {
731 /* set forwarding pointer for moved volumes */
732 tst = AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
734 goto fail_UV_MoveVolume;
738 tst = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
740 goto fail_UV_MoveVolume;
743 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
748 goto fail_UV_MoveVolume;
751 /* Delete the backup volume on the original site */
753 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
756 AFSVolSetFlags(fromconn, fromtid,
757 VTDeleteOnSalvage | VTOutOfService);
759 goto fail_UV_MoveVolume;
762 tst = AFSVolDeleteVolume(fromconn, fromtid);
764 goto fail_UV_MoveVolume;
767 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
772 goto fail_UV_MoveVolume;
776 tst = 0; /* no backup volume? that's okay */
781 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
783 goto fail_UV_MoveVolume;
786 /* now delete the clone */
788 tst = AFSVolDeleteVolume(fromconn, clonetid);
790 goto fail_UV_MoveVolume;
793 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
798 goto fail_UV_MoveVolume;
804 /* normal cleanup code */
808 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
809 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
817 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
820 tst = (etst ? etst : rcode);
825 etst = AFSVolEndTrans(fromconn, clonetid, &rcode);
828 tst = (etst ? etst : rcode);
833 etst = AFSVolEndTrans(toconn, totid, &rcode);
836 tst = (etst ? etst : rcode);
841 #ifdef ENABLE_BUGFIX_1165
846 rx_ReleaseCachedConnection(fromconn);
848 rx_ReleaseCachedConnection(toconn);
856 /* come here only when the sky falls */
860 /* unlock VLDB entry */
862 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
863 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
866 AFSVolEndTrans(fromconn, clonetid, &rcode);
868 AFSVolEndTrans(toconn, totid, &rcode);
869 if (fromtid) { /* put it on-line */
870 AFSVolSetFlags(fromconn, fromtid, 0);
871 AFSVolEndTrans(fromconn, fromtid, &rcode);
874 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
878 /* Delete either the volume on the source location or the target location.
879 * If the vldb entry still points to the source location, then we know the
880 * volume move didn't finish so we remove the volume from the target
881 * location. Otherwise, we remove the volume from the source location.
883 if (Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst)) { /* didn't move - delete target volume */
885 if (volid && toconn) {
887 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
889 AFSVolSetFlags(toconn, totid,
890 VTDeleteOnSalvage | VTOutOfService);
891 AFSVolDeleteVolume(toconn, totid);
892 AFSVolEndTrans(toconn, totid, &rcode);
896 /* put source volume on-line */
899 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
902 AFSVolSetFlags(fromconn, fromtid, 0);
903 AFSVolEndTrans(fromconn, fromtid, &rcode);
906 } else { /* yep, move complete */
907 /* delete backup volume */
910 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
913 AFSVolSetFlags(fromconn, fromtid,
914 VTDeleteOnSalvage | VTOutOfService);
915 AFSVolDeleteVolume(fromconn, fromtid);
916 AFSVolEndTrans(fromconn, fromtid, &rcode);
919 /* delete source volume */
921 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
924 AFSVolSetFlags(fromconn, fromtid,
925 VTDeleteOnSalvage | VTOutOfService);
926 if (atoserver != afromserver)
927 AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
928 AFSVolDeleteVolume(fromconn, fromtid);
929 AFSVolEndTrans(fromconn, fromtid, &rcode);
934 /* common cleanup - delete local clone */
937 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
940 AFSVolDeleteVolume(fromconn, clonetid);
941 AFSVolEndTrans(fromconn, clonetid, &rcode);
945 /* unlock VLDB entry */
946 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
947 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
949 done: /* routine cleanup */
952 #ifdef ENABLE_BUGFIX_1165
957 rx_ReleaseCachedConnection(fromconn);
959 rx_ReleaseCachedConnection(toconn);
967 /* Make a new backup of volume <avolid> on <aserver> and <apart>
968 * if one already exists, update it
972 UV_BackupVolume(afs_cell_handle_p cellHandle, afs_int32 aserver,
973 afs_int32 apart, afs_uint32 avolid, afs_status_p st)
976 afs_status_t tst = 0, temp = 0;
977 afs_int32 ttid = 0, btid = 0;
980 char vname[VOLSER_MAXVOLNAME + 1];
981 struct nvldbentry entry;
982 int vldblocked = 0, vldbmod = 0, backexists = 1;
983 struct rx_connection *aconn = UV_Bind(cellHandle, aserver,
987 /* the calls to VLDB will succeed only if avolid is a RW volume,
988 * since we are following the RW hash chain for searching */
989 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
990 goto fail_UV_BackupVolume;
993 /* These operations require the VLDB be locked since it means the VLDB
994 * will change or the vldb is already locked.
996 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
997 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
998 (entry.volumeId[BACKVOL] == INVALID_BID)) {
999 /* no assigned backup volume id */
1002 ubik_VL_SetLock(cellHandle->vos, 0, avolid, RWVOL,
1005 goto fail_UV_BackupVolume;
1009 /* Reread the vldb entry */
1010 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
1011 goto fail_UV_BackupVolume;
1015 if (!ISNAMEVALID(entry.name)) {
1016 tst = VOLSERBADNAME;
1017 goto fail_UV_BackupVolume;
1020 backupID = entry.volumeId[BACKVOL];
1021 if (backupID == INVALID_BID) {
1022 /* Get a backup volume id from the VLDB and update the vldb
1025 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &backupID);
1027 goto fail_UV_BackupVolume;
1029 entry.volumeId[BACKVOL] = backupID;
1033 /* Test to see if the backup volume exists by trying to create
1034 * a transaction on the backup volume. We've assumed the backup exists.
1036 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1038 if (tst != VNOVOL) {
1039 goto fail_UV_BackupVolume;
1041 backexists = 0; /* backup volume does not exist */
1044 tst = AFSVolEndTrans(aconn, btid, &rcode);
1047 tst = (tst ? tst : rcode);
1048 goto fail_UV_BackupVolume;
1052 /* Now go ahead and try to clone the RW volume.
1053 * First start a transaction on the RW volume
1055 tst = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
1057 goto fail_UV_BackupVolume;
1060 /* Clone or reclone the volume, depending on whether the backup
1061 * volume exists or not
1064 tst = AFSVolReClone(aconn, ttid, backupID);
1066 goto fail_UV_BackupVolume;
1069 strcpy(vname, entry.name);
1070 strcat(vname, ".backup");
1072 tst = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
1074 goto fail_UV_BackupVolume;
1078 /* End transaction on the RW volume */
1079 tst = AFSVolEndTrans(aconn, ttid, &rcode);
1082 tst = (tst ? tst : rcode);
1083 goto fail_UV_BackupVolume;
1086 /* Mork vldb as backup exists */
1087 if (!(entry.flags & BACK_EXISTS)) {
1088 entry.flags |= BACK_EXISTS;
1092 /* Now go back to the backup volume and bring it on line */
1093 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1095 goto fail_UV_BackupVolume;
1098 tst = AFSVolSetFlags(aconn, btid, 0);
1100 goto fail_UV_BackupVolume;
1103 tst = AFSVolEndTrans(aconn, btid, &rcode);
1106 tst = (tst ? tst : rcode);
1107 goto fail_UV_BackupVolume;
1111 /* Will update the vldb below */
1113 fail_UV_BackupVolume:
1116 temp = AFSVolEndTrans(aconn, ttid, &rcode);
1117 if (temp || rcode) {
1119 tst = (temp ? temp : rcode);
1124 temp = AFSVolEndTrans(aconn, btid, &rcode);
1125 if (temp || rcode) {
1127 tst = (temp ? temp : rcode);
1131 /* Now update the vldb - if modified */
1134 if (!VLDB_ReplaceEntry
1135 (cellHandle, avolid, RWVOL, &entry,
1136 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
1144 ubik_VL_ReleaseLock(cellHandle->vos, 0, avolid, RWVOL,
1145 (LOCKREL_OPCODE | LOCKREL_AFSID |
1146 LOCKREL_TIMESTAMP));
1156 rx_ReleaseCachedConnection(aconn);
1166 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
1169 afs_int32 acode, rcode, tid;
1172 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
1173 if (!acode) { /* It really was there */
1174 acode = AFSVolDeleteVolume(conn, tid);
1175 AFSVolEndTrans(conn, tid, &rcode);
1181 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
1182 #define ERROREXIT(ec) { error = (ec); goto rfail; }
1184 #if 0 /* doesn't appear to be used, why compile it */
1186 CloneVol(afs_cell_handle_p cellHandle, struct rx_connection *conn,
1187 afs_uint32 rwvid, afs_int32 part, afs_uint32 * rovidp, int nottemp,
1188 struct nvldbentry *entry, afs_int32 * vidCreateDate, afs_status_p st)
1191 afs_status_t tst = 0, etst = 0;
1192 afs_int32 rcode = 0, tid = 0;
1193 struct volser_status volstatus;
1196 /* Begin transaction on RW volume marking it busy (clients will wait) */
1197 tst = AFSVolTransCreate(conn, rwvid, part, ITBusy, &tid);
1202 /* Get the RO volume id. Allocate a new one if need to */
1203 *rovidp = entry->volumeId[ROVOL];
1204 if (*rovidp == INVALID_BID) {
1205 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, rovidp);
1210 entry->volumeId[ROVOL] = *rovidp;
1213 /* If we are creating the ro clone, what are we calling it.
1214 * Depends on whether its a temporary clone or not.
1217 strcpy(vname, entry->name);
1218 strcat(vname, ".readonly");
1220 strcpy(vname, "readonly-clone-temp"); /* Should be unique? */
1223 /* Create the new clone. If it exists, then reclone it */
1224 tst = AFSVolClone(conn, tid, 0, readonlyVolume, vname, rovidp);
1225 if (tst == VVOLEXISTS) {
1226 tst = AFSVolReClone(conn, tid, *rovidp);
1235 /* Bring the volume back on-line as soon as possible */
1237 afs_int32 fromtid = 0;
1239 /* Now bring the RO clone on-line */
1240 tst = AFSVolTransCreate(conn, *rovidp, part, ITOffline, &fromtid);
1245 tst = AFSVolSetFlags(conn, fromtid, 0);
1250 tst = AFSVolEndTrans(conn, fromtid, &rcode);
1259 /* Get the time the RW was created for return information */
1260 tst = AFSVolGetStatus(conn, tid, &volstatus);
1264 *vidCreateDate = volstatus.creationDate;
1270 tst = AFSVolEndTrans(conn, tid, &rcode);
1287 /* Get a "transaction" on this replica. Create the volume
1288 * if necessary. Return the time from which a dump should
1289 * be made (0 if it's a new volume)
1292 GetTrans(afs_cell_handle_p cellHandle, struct nvldbentry *vldbEntryPtr,
1293 afs_int32 index, struct rx_connection **connPtr,
1294 afs_int32 * transPtr, afs_int32 * timePtr, afs_status_p st)
1297 afs_status_t tst = 0;
1299 struct volser_status tstatus;
1302 *connPtr = (struct rx_connection *)0;
1306 /* get connection to the replication site */
1308 UV_Bind(cellHandle, vldbEntryPtr->serverNumber[index],
1309 AFSCONF_VOLUMEPORT);
1311 /* server is down */
1316 volid = vldbEntryPtr->volumeId[ROVOL];
1319 AFSVolTransCreate(*connPtr, volid,
1320 vldbEntryPtr->serverPartition[index], ITOffline,
1324 /* If the volume does not exist, create it */
1325 if (!volid || tst) {
1328 if (volid && (tst != VNOVOL)) {
1332 strcpy(volname, vldbEntryPtr->name);
1333 strcat(volname, ".readonly");
1336 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
1338 vldbEntryPtr->volumeId[RWVOL], &volid,
1343 vldbEntryPtr->volumeId[ROVOL] = volid;
1345 /* The following is a bit redundant, since create sets these flags by default */
1347 AFSVolSetFlags(*connPtr, *transPtr,
1348 VTDeleteOnSalvage | VTOutOfService);
1354 /* Otherwise, the transaction did succeed, so get the creation date of the
1355 * latest RO volume on the replication site
1358 tst = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
1362 *timePtr = tstatus.creationDate - CLOCKSKEW;
1368 if ((rc == 0) && (*transPtr)) {
1369 AFSVolEndTrans(*connPtr, *transPtr, &rcode);
1380 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
1381 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
1382 void *cookie, manyResults * results)
1386 for (i = 0; i < tr->manyDests_len; i++) {
1387 results->manyResults_val[i] =
1388 AFSVolForward(fromconn, fromtid, fromdate,
1389 &(tr->manyDests_val[i].server),
1390 tr->manyDests_val[i].trans, cookie);
1397 * Determine if a volume exists on a server and partition.
1398 * Try creating a transaction on the volume. If we can,
1399 * the volume exists, if not, then return the error code.
1400 * Some error codes mean the volume is unavailable but
1401 * still exists - so we catch these error codes.
1404 VolumeExists(afs_cell_handle_p cellHandle, afs_int32 server,
1405 afs_int32 partition, afs_int32 volumeid, afs_status_p st)
1408 afs_status_t tst = 0;
1409 struct rx_connection *conn = (struct rx_connection *)0;
1410 volEntries volumeInfo;
1412 conn = UV_Bind(cellHandle, server, AFSCONF_VOLUMEPORT);
1414 volumeInfo.volEntries_val = (volintInfo *) 0;
1415 volumeInfo.volEntries_len = 0;
1416 tst = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
1417 if (volumeInfo.volEntries_val)
1418 free(volumeInfo.volEntries_val);
1419 if (tst == VOLSERILLEGAL_PARTITION) {
1422 rx_ReleaseCachedConnection(conn);
1432 /* release volume <afromvol> on <afromserver> <afrompart> to all the
1433 * sites if forceflag is 1.If its 0 complete the release if the previous
1434 * release aborted else start a new release */
1436 UV_ReleaseVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
1437 afs_int32 afromserver, afs_int32 afrompart, int forceflag,
1441 afs_status_t tst = 0, etst = 0;
1445 afs_uint32 cloneVolId, roVolId;
1446 struct replica *replicas = 0;
1447 struct nvldbentry entry;
1448 int i, volcount, m, fullrelease, vldbindex;
1450 struct restoreCookie cookie;
1451 struct rx_connection **toconns = 0;
1452 struct release *times = 0;
1454 struct rx_connection *fromconn = (struct rx_connection *)0;
1456 afs_int32 clonetid = 0, onlinetid;
1457 afs_int32 fromtid = 0;
1458 afs_uint32 fromdate = 0, thisdate;
1461 manyResults results;
1462 int rwindex, roindex, roclone, roexists;
1463 afs_int32 rwcrdate = 0;
1467 } remembertime[NMAXNSERVERS];
1468 int releasecount = 0;
1469 struct volser_status volstatus;
1471 memset(remembertime, 0, sizeof(remembertime));
1472 memset(&results, 0, sizeof(results));
1475 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL,
1477 if ((tst) && (tst != VL_RERELEASE)) {
1478 goto fail_UV_ReleaseVolume;
1482 /* Get the vldb entry in readable format */
1483 if (!aVLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
1484 goto fail_UV_ReleaseVolume;
1487 if (!ISNAMEVALID(entry.name)) {
1488 tst = VOLSERBADNAME;
1489 goto fail_UV_ReleaseVolume;
1492 if (entry.volumeId[RWVOL] != afromvol) {
1493 tst = ADMVOSVOLUMERELEASERWONLY;
1494 goto fail_UV_ReleaseVolume;
1497 if (entry.nServers <= 1) {
1498 tst = ADMVOSVOLUMENOREPLICAS;
1499 goto fail_UV_ReleaseVolume;
1502 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10)) {
1503 tst = VOLSERBADNAME;
1504 goto fail_UV_ReleaseVolume;
1507 /* roclone is true if one of the RO volumes is on the same
1508 * partition as the RW volume. In this case, we make the RO volume
1509 * on the same partition a clone instead of a complete copy.
1513 Lp_ROMatch(cellHandle, &entry, afromserver, afrompart, &tst) - 1;
1514 roclone = ((roindex == -1) ? 0 : 1);
1515 rwindex = Lp_GetRwIndex(cellHandle, &entry, 0);
1518 goto fail_UV_ReleaseVolume;
1521 /* Make sure we have a RO volume id to work with */
1522 if (entry.volumeId[ROVOL] == INVALID_BID) {
1523 /* need to get a new RO volume id */
1524 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &roVolId);
1526 goto fail_UV_ReleaseVolume;
1529 entry.volumeId[ROVOL] = roVolId;
1530 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1531 goto fail_UV_ReleaseVolume;
1535 /* Will we be completing a previously unfinished release. -force overrides */
1536 for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) {
1537 if (entry.serverFlags[i] & NEW_REPSITE)
1540 if (forceflag && !fullrelease)
1543 /* Determine which volume id to use and see if it exists */
1546 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
1547 VolumeExists(cellHandle, afromserver, afrompart, cloneVolId, &tst);
1548 roexists = ((tst == ENODEV) ? 0 : 1);
1549 if (!roexists && !fullrelease)
1550 fullrelease = 1; /* Do a full release if RO clone does not exist */
1552 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
1555 goto fail_UV_ReleaseVolume;
1559 /* If the RO clone exists, then if the clone is a temporary
1560 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
1561 * (it was recently added), then also delete it. We do not
1562 * want to "reclone" a temporary RO clone.
1565 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
1566 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1567 if (tst && (tst != VNOVOL)) {
1568 goto fail_UV_ReleaseVolume;
1573 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
1574 * write this entry out to the vlserver until after the first
1575 * RO volume is released (temp RO clones don't count).
1577 for (i = 0; i < entry.nServers; i++) {
1578 entry.serverFlags[i] &= ~NEW_REPSITE;
1579 entry.serverFlags[i] |= RO_DONTUSE;
1581 entry.serverFlags[rwindex] |= NEW_REPSITE;
1582 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
1584 /* Begin transaction on RW and mark it busy while we clone it */
1586 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1589 goto fail_UV_ReleaseVolume;
1592 /* Clone or reclone the volume */
1594 tst = AFSVolReClone(fromconn, clonetid, cloneVolId);
1596 goto fail_UV_ReleaseVolume;
1600 strcpy(vname, entry.name);
1601 strcat(vname, ".readonly");
1603 strcpy(vname, "readonly-clone-temp");
1606 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
1609 goto fail_UV_ReleaseVolume;
1613 /* Get the time the RW was created for future information */
1614 tst = AFSVolGetStatus(fromconn, clonetid, &volstatus);
1616 goto fail_UV_ReleaseVolume;
1618 rwcrdate = volstatus.creationDate;
1620 /* End the transaction on the RW volume */
1621 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1623 tst = (tst ? tst : rcode);
1625 goto fail_UV_ReleaseVolume;
1628 /* Remember clone volume ID in case we fail or are interrupted */
1629 entry.cloneId = cloneVolId;
1632 /* Bring the RO clone online - though not if it's a temporary clone */
1634 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
1637 goto fail_UV_ReleaseVolume;
1640 etst = AFSVolSetFlags(fromconn, onlinetid, 0);
1642 tst = AFSVolEndTrans(fromconn, onlinetid, &rcode);
1643 tst = (tst ? tst : rcode);
1645 goto fail_UV_ReleaseVolume;
1649 goto fail_UV_ReleaseVolume;
1652 /* Sleep so that a client searching for an online volume won't
1653 * find the clone offline and then the next RO offline while the
1654 * release brings the clone online and the next RO offline (race).
1655 * There is a fix in the 3.4 client that does not need this sleep
1656 * anymore, but we don't know what clients we have.
1658 if (entry.nServers > 2)
1661 /* Mark the RO clone in the VLDB as a good site (already released) */
1662 entry.serverFlags[roindex] |= NEW_REPSITE;
1663 entry.serverFlags[roindex] &= ~RO_DONTUSE;
1664 entry.flags |= RO_EXISTS;
1668 /* Write out the VLDB entry only if the clone is not a temporary
1669 * clone. If we did this to a temporary clone then we would end
1670 * up marking all the ROs as "old release" making the ROs
1671 * temporarily unavailable.
1673 if (!VLDB_ReplaceEntry
1674 (cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1675 goto fail_UV_ReleaseVolume;
1680 /* Now we will release from the clone to the remaining RO replicas.
1681 * The first 2 ROs (counting the non-temporary RO clone) are released
1682 * individually: releasecount. This is to reduce the race condition
1683 * of clients trying to find an on-line RO volume. The remaining ROs
1684 * are released in parallel but no more than half the number of ROs
1685 * (rounded up) at a time: nservers.
1688 strcpy(vname, entry.name);
1689 strcat(vname, ".readonly");
1690 memset(&cookie, 0, sizeof(cookie));
1691 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
1692 cookie.type = ROVOL;
1693 cookie.parent = entry.volumeId[RWVOL];
1696 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
1697 replicas = calloc(nservers + 1, sizeof(struct replica));
1698 times = calloc(nservers + 1, sizeof(struct release));
1699 toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
1700 results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
1701 if (!replicas || !times || !!!results.manyResults_val || !toconns) {
1703 goto fail_UV_ReleaseVolume;
1706 /* Create a transaction on the cloned volume */
1708 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
1710 goto fail_UV_ReleaseVolume;
1713 /* For each index in the VLDB */
1714 for (vldbindex = 0; vldbindex < entry.nServers;) {
1716 /* Get a transaction on the replicas. Pick replacas which have an old release. */
1718 ((volcount < nservers) && (vldbindex < entry.nServers));
1720 /* The first two RO volumes will be released individually.
1721 * The rest are then released in parallel. This is a hack
1722 * for clients not recognizing right away when a RO volume
1723 * comes back on-line.
1725 if ((volcount == 1) && (releasecount < 2))
1728 if (vldbindex == roindex)
1729 continue; /* the clone */
1730 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
1731 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
1733 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
1734 continue; /* not a RO vol */
1737 /* Get a Transaction on this replica. Get a new connection if
1738 * necessary. Create the volume if necessary. Return the
1739 * time from which the dump should be made (0 if it's a new
1740 * volume). Each volume might have a different time.
1742 replicas[volcount].server.destHost =
1743 entry.serverNumber[vldbindex];
1744 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
1745 replicas[volcount].server.destSSID = 1;
1746 times[volcount].vldbEntryIndex = vldbindex;
1749 (cellHandle, &entry, vldbindex, &(toconns[volcount]),
1750 &(replicas[volcount].trans), &(times[volcount].time),
1755 /* Thisdate is the date from which we want to pick up all changes */
1756 if (forceflag || !fullrelease
1757 || (rwcrdate > times[volcount].time)) {
1758 /* If the forceflag is set, then we want to do a full dump.
1759 * If it's not a full release, we can't be sure that the creation
1760 * date is good (so we also do a full dump).
1761 * If the RW volume was replaced (its creation date is newer than
1762 * the last release), then we can't be sure what has changed (so
1763 * we do a full dump).
1766 } else if (remembertime[vldbindex].validtime) {
1767 /* Trans was prev ended. Use the time from the prev trans
1768 * because, prev trans may have created the volume. In which
1769 * case time[volcount].time would be now instead of 0.
1772 (remembertime[vldbindex].time <
1773 times[volcount].time) ? remembertime[vldbindex].
1774 time : times[volcount].time;
1776 thisdate = times[volcount].time;
1778 remembertime[vldbindex].validtime = 1;
1779 remembertime[vldbindex].time = thisdate;
1781 if (volcount == 0) {
1782 fromdate = thisdate;
1784 /* Include this volume if it is within 15 minutes of the earliest */
1786 thisdate) ? (fromdate - thisdate) : (thisdate -
1788 AFSVolEndTrans(toconns[volcount],
1789 replicas[volcount].trans, &rcode);
1790 replicas[volcount].trans = 0;
1793 if (thisdate < fromdate)
1794 fromdate = thisdate;
1801 /* Release the ones we have collected */
1802 tr.manyDests_val = &(replicas[0]);
1803 tr.manyDests_len = results.manyResults_len = volcount;
1805 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
1806 0 /*spare */ , &cookie, &results);
1807 if (tst == RXGEN_OPCODE) { /* RPC Interface Mismatch */
1809 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
1810 0 /*spare */ , &cookie, &results);
1815 goto fail_UV_ReleaseVolume;
1817 for (m = 0; m < volcount; m++) {
1818 if (results.manyResults_val[m]) {
1823 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
1824 ROVOL, entry.volumeId[RWVOL], 0, 0);
1829 /* have to clear dest. flags to ensure new vol goes online:
1830 * because the restore (forwarded) operation copied
1831 * the V_inService(=0) flag over to the destination.
1833 tst = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
1838 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
1839 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
1840 entry.flags |= RO_EXISTS;
1845 /* End the transactions and destroy the connections */
1846 for (s = 0; s < volcount; s++) {
1847 if (replicas[s].trans)
1848 tst = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
1849 replicas[s].trans = 0;
1853 if ((s == 0) || (tst != ENOENT)) {
1855 if (times[s].vldbEntryIndex < vldbindex)
1856 vldbindex = times[s].vldbEntryIndex;
1861 rx_ReleaseCachedConnection(toconns[s]);
1865 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1866 goto fail_UV_ReleaseVolume;
1868 } /* for each index in the vldb */
1870 /* End the transaction on the cloned volume */
1871 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1874 /* Figure out if any volume were not released and say so */
1875 for (failure = 0, i = 0; i < entry.nServers; i++) {
1876 if (!(entry.serverFlags[i] & NEW_REPSITE))
1880 if (!VLDB_ReplaceEntry
1881 (cellHandle, afromvol, RWVOL, &entry, LOCKREL_TIMESTAMP, &tst)) {
1882 goto fail_UV_ReleaseVolume;
1885 tst = VOLSERBADRELEASE;
1886 goto fail_UV_ReleaseVolume;
1889 /* All the ROs were release successfully. Remove the temporary clone */
1891 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1893 goto fail_UV_ReleaseVolume;
1898 for (i = 0; i < entry.nServers; i++)
1899 entry.serverFlags[i] &= ~NEW_REPSITE;
1901 /* Update the VLDB */
1902 if (!VLDB_ReplaceEntry
1903 (cellHandle, afromvol, RWVOL, &entry,
1904 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
1905 goto fail_UV_ReleaseVolume;
1909 fail_UV_ReleaseVolume:
1912 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1919 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1925 for (i = 0; i < nservers; i++) {
1926 if (replicas && replicas[i].trans) {
1927 tst = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
1928 replicas[i].trans = 0;
1933 if (toconns && toconns[i]) {
1934 rx_ReleaseCachedConnection(toconns[i]);
1940 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, RWVOL,
1941 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
1948 rx_ReleaseCachedConnection(fromconn);
1949 if (results.manyResults_val)
1950 free(results.manyResults_val);
1965 ReceiveFile(int fd, struct rx_call *call,
1966 struct stat *status)
1968 char *buffer = (char *)0;
1970 afs_int32 bytesread, nbytes, bytesleft, w;
1972 afs_int32 error = 0;
1979 struct statfs tstatfs;
1981 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
1983 fstatfs(fd, &tstatfs);
1984 blockSize = tstatfs.f_bsize;
1986 blockSize = status->st_blksize;
1993 buffer = malloc(blockSize);
1998 while (!error && (bytesread > 0)) {
1999 bytesread = rx_Read(call, buffer, nbytes);
2000 bytesleft = bytesread;
2001 while (!error && (bytesleft > 0)) {
2004 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2005 select(fd + 1, 0, &out, 0, 0); /* don't timeout if write bl
2008 w = write(fd, &buffer[bytesread - bytesleft], bytesleft);
2010 error = ADMVOSDUMPFILEWRITEFAIL;
2026 DumpFunction(struct rx_call *call, const char *filename)
2030 afs_int32 error, code;
2034 fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666);
2035 if (fd < 0 || fstat(fd, &status) < 0) {
2036 error = VOLSERBADOP;
2039 code = ReceiveFile(fd, call, &status);
2057 /*dump the volume <afromvol> on <afromserver> and
2058 * <afrompart> to <afilename> starting from <fromdate>.
2059 * DumpFunction does the real work behind the scenes after
2060 * extracting parameters from the rock */
2062 UV_DumpVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
2063 afs_int32 afromserver, afs_int32 afrompart, afs_int32 fromdate,
2064 const char *filename, afs_status_p st)
2067 afs_status_t tst = 0;
2068 afs_status_t etst = 0;
2069 struct rx_connection *fromconn;
2070 struct rx_call *fromcall;
2075 struct nvldbentry entry;
2080 fromconn = (struct rx_connection *)0;
2082 fromcall = (struct rx_call *)0;
2084 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
2085 goto fail_UV_DumpVolume;
2088 /* get connections to the servers */
2089 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
2090 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2092 goto fail_UV_DumpVolume;
2094 fromcall = rx_NewCall(fromconn);
2095 tst = StartAFSVolDump(fromcall, fromtid, fromdate);
2097 goto fail_UV_DumpVolume;
2099 if ((tst = DumpFunction(fromcall, filename))) {
2100 goto fail_UV_DumpVolume;
2102 tst = rx_EndCall(fromcall, rxError);
2103 fromcall = (struct rx_call *)0;
2105 goto fail_UV_DumpVolume;
2107 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2112 goto fail_UV_DumpVolume;
2120 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
2121 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2129 etst = rx_EndCall(fromcall, rxError);
2137 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2147 rx_ReleaseCachedConnection(fromconn);
2157 SendFile(int fd, struct rx_call *call,
2158 struct stat *status)
2160 char *buffer = (char *)0;
2163 afs_int32 error = 0;
2171 struct statfs tstatfs;
2173 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2175 fstatfs(fd, &tstatfs);
2176 blockSize = tstatfs.f_bsize;
2178 blockSize = status->st_blksize;
2184 buffer = malloc(blockSize);
2192 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2193 select(fd + 1, &in, 0, 0, 0); /* don't timeout if read blocks */
2195 nbytes = read(fd, buffer, blockSize);
2197 error = ADMVOSRESTOREFILEREADFAIL;
2204 if (rx_Write(call, buffer, nbytes) != nbytes) {
2205 error = ADMVOSRESTOREFILEWRITEFAIL;
2215 WriteData(struct rx_call *call, const char *filename)
2219 afs_int32 error, code;
2223 fd = open(filename, 0);
2224 if (fd < 0 || fstat(fd, &status) < 0) {
2225 fprintf(STDERR, "Could access file '%s'\n", filename);
2226 error = ADMVOSRESTOREFILEOPENFAIL;
2227 goto fail_WriteData;
2229 code = SendFile(fd, call, &status);
2232 goto fail_WriteData;
2243 error = ADMVOSRESTOREFILECLOSEFAIL;
2249 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
2250 * the dump file <afilename>. WriteData does all the real work
2251 * after extracting params from the rock
2254 UV_RestoreVolume(afs_cell_handle_p cellHandle, afs_int32 toserver,
2255 afs_int32 topart, afs_uint32 tovolid, char *tovolname,
2256 int flags, const char *dumpFile, afs_status_p st)
2259 afs_status_t tst = 0;
2260 afs_status_t etst = 0;
2261 struct rx_connection *toconn, *tempconn;
2262 struct rx_call *tocall;
2263 afs_int32 totid, rcode;
2264 afs_int32 rxError = 0;
2265 struct volser_status tstatus;
2270 struct nvldbentry entry;
2272 struct restoreCookie cookie;
2274 afs_int32 newDate, volflag;
2278 memset(&cookie, 0, sizeof(cookie));
2281 tocall = (struct rx_call *)0;
2282 tempconn = (struct rx_connection *)0;
2287 toconn = UV_Bind(cellHandle, toserver, AFSCONF_VOLUMEPORT);
2288 if (pvolid == 0) { /*alot a new id if needed */
2289 aVLDB_GetEntryByName(cellHandle, tovolname, &entry, &tst);
2290 if (tst == VL_NOENT) {
2292 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &pvolid);
2294 goto fail_UV_RestoreVolume;
2298 pvolid = entry.volumeId[RWVOL];
2303 * at this point we have a volume id to use/reuse for the
2304 * volume to be restored
2306 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
2307 tst = ADMVOSRESTOREVOLUMENAMETOOBIG;
2308 goto fail_UV_RestoreVolume;
2311 if (!vos_PartitionIdToName(topart, partName, &tst)) {
2312 goto fail_UV_RestoreVolume;
2314 /*what should the volume be restored as ? rw or ro or bk ?
2315 * right now the default is rw always */
2317 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0, &pvolid,
2320 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
2322 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2324 goto fail_UV_RestoreVolume;
2327 AFSVolSetFlags(toconn, totid,
2328 VTDeleteOnSalvage | VTOutOfService);
2330 goto fail_UV_RestoreVolume;
2332 tst = AFSVolDeleteVolume(toconn, totid);
2334 goto fail_UV_RestoreVolume;
2336 tst = AFSVolEndTrans(toconn, totid, &rcode);
2341 goto fail_UV_RestoreVolume;
2344 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,
2347 goto fail_UV_RestoreVolume;
2351 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2353 goto fail_UV_RestoreVolume;
2357 cookie.parent = pvolid;
2358 cookie.type = RWVOL;
2360 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
2362 tocall = rx_NewCall(toconn);
2363 tst = StartAFSVolRestore(tocall, totid, 1, &cookie);
2365 goto fail_UV_RestoreVolume;
2367 tst = WriteData(tocall, dumpFile);
2369 goto fail_UV_RestoreVolume;
2371 tst = rx_EndCall(tocall, rxError);
2372 tocall = (struct rx_call *)0;
2374 goto fail_UV_RestoreVolume;
2376 tst = AFSVolGetStatus(toconn, totid, &tstatus);
2378 goto fail_UV_RestoreVolume;
2380 tst = AFSVolSetIdsTypes(toconn, totid, tovolname, RWVOL, pvolid, 0, 0);
2382 goto fail_UV_RestoreVolume;
2385 tst = AFSVolSetDate(toconn, totid, newDate);
2387 goto fail_UV_RestoreVolume;
2390 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2391 tst = AFSVolSetFlags(toconn, totid, volflag);
2393 goto fail_UV_RestoreVolume;
2396 /* It isn't handled right in fail_UV_RestoreVolume */
2397 tst = AFSVolEndTrans(toconn, totid, &rcode);
2402 goto fail_UV_RestoreVolume;
2406 if (success && (!reuseID || (flags & RV_FULLRST))) {
2407 /* Volume was restored on the file server, update the
2408 * VLDB to reflect the change.
2410 aVLDB_GetEntryByID(cellHandle, pvolid, RWVOL, &entry, &tst);
2411 if (tst && tst != VL_NOENT && tst != VL_ENTDELETED) {
2412 goto fail_UV_RestoreVolume;
2414 if (tst == VL_NOENT) { /* it doesnot exist already */
2415 /*make the vldb return this indication specifically */
2416 strcpy(entry.name, tovolname);
2418 entry.serverNumber[0] = toserver; /*should be indirect */
2419 entry.serverPartition[0] = topart;
2420 entry.serverFlags[0] = ITSRWVOL;
2421 entry.flags = RW_EXISTS;
2422 if (tstatus.cloneID != 0) {
2423 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
2425 entry.volumeId[ROVOL] = INVALID_BID;
2426 entry.volumeId[RWVOL] = pvolid;
2428 if (tstatus.backupID != 0) {
2429 entry.volumeId[BACKVOL] = tstatus.backupID;
2430 /*this should come from status info on the volume if non zero */
2432 entry.volumeId[BACKVOL] = INVALID_BID;
2433 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
2434 goto fail_UV_RestoreVolume;
2437 } else { /*update the existing entry */
2439 ubik_VL_SetLock(cellHandle->vos, 0, pvolid, RWVOL,
2442 goto fail_UV_RestoreVolume;
2445 strcpy(entry.name, tovolname);
2447 /* Update the vlentry with the new information */
2448 index = Lp_GetRwIndex(cellHandle, &entry, 0);
2450 /* Add the rw site for the volume being restored */
2451 entry.serverNumber[entry.nServers] = toserver;
2452 entry.serverPartition[entry.nServers] = topart;
2453 entry.serverFlags[entry.nServers] = ITSRWVOL;
2456 /* This volume should be deleted on the old site
2457 * if its different from new site.
2459 VLDB_IsSameAddrs(cellHandle, toserver,
2460 entry.serverNumber[index], &same, &tst);
2462 || (entry.serverPartition[index] != topart)) {
2464 UV_Bind(cellHandle, entry.serverNumber[index],
2465 AFSCONF_VOLUMEPORT);
2467 AFSVolTransCreate(tempconn, pvolid,
2468 entry.serverPartition[index],
2469 ITOffline, &temptid);
2472 AFSVolSetFlags(tempconn, temptid,
2476 goto fail_UV_RestoreVolume;
2478 tst = AFSVolDeleteVolume(tempconn, temptid);
2480 goto fail_UV_RestoreVolume;
2482 tst = AFSVolEndTrans(tempconn, temptid, &rcode);
2487 goto fail_UV_RestoreVolume;
2489 vos_PartitionIdToName(entry.serverPartition[index],
2493 entry.serverNumber[index] = toserver;
2494 entry.serverPartition[index] = topart;
2497 entry.flags |= RW_EXISTS;
2498 if (!VLDB_ReplaceEntry
2499 (cellHandle, pvolid, RWVOL, &entry,
2500 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2501 goto fail_UV_RestoreVolume;
2508 fail_UV_RestoreVolume:
2511 etst = rx_EndCall(tocall, rxError);
2517 ubik_VL_ReleaseLock(cellHandle->vos, 0, pvolid, RWVOL,
2518 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2525 etst = AFSVolEndTrans(toconn, totid, &rcode);
2534 etst = AFSVolEndTrans(toconn, temptid, &rcode);
2544 rx_ReleaseCachedConnection(tempconn);
2546 rx_ReleaseCachedConnection(toconn);
2554 /*adds <server> and <part> as a readonly replication site for <volid>
2557 UV_AddSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2558 afs_uint32 volid, afs_status_p st)
2561 afs_status_t tst = 0;
2562 int j, nro = 0, islocked = 0;
2563 struct nvldbentry entry;
2567 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2569 goto fail_UV_AddSite;
2573 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2574 goto fail_UV_AddSite;
2576 if (!ISNAMEVALID(entry.name)) {
2578 goto fail_UV_AddSite;
2581 /* See if it's too many entries */
2582 if (entry.nServers >= NMAXNSERVERS) {
2584 goto fail_UV_AddSite;
2587 /* See if it's on the same server */
2588 for (j = 0; j < entry.nServers; j++) {
2589 if (entry.serverFlags[j] & ITSROVOL) {
2591 if (!VLDB_IsSameAddrs
2592 (cellHandle, server, entry.serverNumber[j], &same, &tst)) {
2593 goto fail_UV_AddSite;
2597 goto fail_UV_AddSite;
2602 /* See if it's too many RO sites - leave one for the RW */
2603 if (nro >= NMAXNSERVERS - 1) {
2605 goto fail_UV_AddSite;
2608 entry.serverNumber[entry.nServers] = server;
2609 entry.serverPartition[entry.nServers] = part;
2610 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
2613 if (!VLDB_ReplaceEntry
2614 (cellHandle, volid, RWVOL, &entry,
2615 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2616 goto fail_UV_AddSite;
2625 ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2626 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2635 /*removes <server> <part> as read only site for <volid> from the vldb */
2637 UV_RemoveSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2638 afs_uint32 volid, afs_status_p st)
2641 afs_status_t tst = 0;
2642 struct nvldbentry entry;
2646 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2648 goto fail_UV_RemoveSite;
2652 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2653 goto fail_UV_RemoveSite;
2655 if (!Lp_ROMatch(cellHandle, &entry, server, part, &tst)) {
2656 /*this site doesnot exist */
2657 goto fail_UV_RemoveSite;
2658 } else { /*remove the rep site */
2659 Lp_SetROValue(cellHandle, &entry, server, part, 0, 0);
2661 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
2662 entry.flags &= ~RO_EXISTS;
2663 if (entry.nServers < 1) { /*this is the last ref */
2664 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volid, ROVOL);
2666 goto fail_UV_RemoveSite;
2669 if (!VLDB_ReplaceEntry
2670 (cellHandle, volid, RWVOL, &entry,
2671 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
2672 goto fail_UV_RemoveSite;
2681 t = ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2682 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2694 /*list all the partitions on <aserver> */
2696 UV_ListPartitions(struct rx_connection *server, struct partList *ptrPartList,
2697 afs_int32 * cntp, afs_status_p st)
2700 afs_status_t tst = 0;
2701 struct pIDs partIds;
2702 struct partEntries partEnts;
2707 partEnts.partEntries_len = 0;
2708 partEnts.partEntries_val = NULL;
2709 /* this is available only on new servers */
2710 tst = AFSVolXListPartitions(server, &partEnts);
2712 /* next, try old interface */
2713 if (tst == RXGEN_OPCODE) {
2714 for (i = 0; i < 26; i++)
2715 partIds.partIds[i] = -1;
2716 tst = AFSVolListPartitions(server, &partIds);
2718 for (i = 0; i < 26; i++) {
2719 if ((partIds.partIds[i]) != -1) {
2720 ptrPartList->partId[j] = partIds.partIds[i];
2721 ptrPartList->partFlags[j] = PARTVALID;
2724 ptrPartList->partFlags[i] = 0;
2728 goto fail_UV_ListPartitions;
2731 *cntp = partEnts.partEntries_len;
2732 if (*cntp > VOLMAXPARTS) {
2733 *cntp = VOLMAXPARTS;
2735 for (i = 0; i < *cntp; i++) {
2736 ptrPartList->partId[i] = partEnts.partEntries_val[i];
2737 ptrPartList->partFlags[i] = PARTVALID;
2739 free(partEnts.partEntries_val);
2741 goto fail_UV_ListPartitions;
2745 fail_UV_ListPartitions:
2753 /*------------------------------------------------------------------------
2754 * EXPORTED UV_XListVolumes
2757 * List the extended information for all the volumes on a particular
2758 * File Server and partition. We may either return the volume's ID
2759 * or all of its extended information.
2762 * a_serverID : Address of the File Server for which we want
2763 * extended volume info.
2764 * a_partID : Partition for which we want the extended
2766 * a_all : If non-zero, fetch ALL the volume info,
2767 * otherwise just the volume ID.
2768 * a_resultPP : Ptr to the address of the area containing
2769 * the returned volume info.
2770 * a_numEntsInResultP : Ptr for the value we set for the number of
2775 * Otherise, the return value of AFSVolXListVolumes.
2778 * This routine is closely related to UV_ListVolumes, which returns
2779 * only the standard level of detail on AFS volumes. It is a
2780 * heavyweight operation, zipping through all the volume entries for
2781 * a given server/partition.
2785 *------------------------------------------------------------------------*/
2788 UV_XListVolumes(struct rx_connection *server, afs_int32 a_partID, int a_all,
2789 struct volintXInfo **a_resultPP,
2790 afs_int32 * a_numEntsInResultP, afs_status_p st)
2793 afs_status_t tst = 0;
2795 volXEntries volumeXInfo; /*Area for returned extended vol info */
2798 * Set up our error code and the area for returned extended volume info.
2799 * We set the val field to a null pointer as a hint for the stub to
2802 *a_numEntsInResultP = 0;
2803 *a_resultPP = (volintXInfo *) 0;
2804 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2805 volumeXInfo.volXEntries_len = 0;
2808 * Bind to the Volume Server port on the File Server machine in question,
2811 tst = AFSVolXListVolumes(server, a_partID, a_all, &volumeXInfo);
2813 goto fail_UV_XListVolumes;
2816 * We got the info; pull out the pointer to where the results lie
2817 * and how many entries are there.
2819 *a_resultPP = volumeXInfo.volXEntries_val;
2820 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
2824 fail_UV_XListVolumes:
2832 /*------------------------------------------------------------------------
2833 * EXPORTED UV_XListOneVolume
2836 * List the extended information for a volume on a particular File
2837 * Server and partition.
2840 * server : a handle to the server where the volume resides.
2841 * a_partID : Partition for which we want the extended
2843 * a_volID : Volume ID for which we want the info.
2844 * a_resultPP : Ptr to the address of the area containing
2845 * the returned volume info.
2849 * Otherise, the return value of AFSVolXListOneVolume.
2852 * This routine is closely related to UV_ListOneVolume, which returns
2853 * only the standard level of detail on the chosen AFS volume.
2857 *------------------------------------------------------------------------*/
2860 UV_XListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2861 afs_uint32 a_volID, struct volintXInfo **a_resultPP,
2865 afs_status_t tst = 0;
2866 volXEntries volumeXInfo; /*Area for returned info */
2869 * Set the area we're in which we are returning
2870 * the info. Setting the val field to a null pointer tells the stub
2871 * to allocate space for us.
2873 *a_resultPP = (volintXInfo *) 0;
2874 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2875 volumeXInfo.volXEntries_len = 0;
2877 tst = AFSVolXListOneVolume(server, a_partID, a_volID, &volumeXInfo);
2880 goto fail_UV_XListOneVolume;
2883 * We got the info; pull out the pointer to where the results lie.
2885 *a_resultPP = volumeXInfo.volXEntries_val;
2889 fail_UV_XListOneVolume:
2896 } /*UV_XListOneVolume */
2898 /*------------------------------------------------------------------------
2899 * EXPORTED UV_ListOneVolume
2902 * List the volume information for a volume on a particular File
2903 * Server and partition.
2906 * server : a handle to the server where the volume resides.
2907 * a_partID : Partition for which we want the extended
2909 * a_volID : Volume ID for which we want the info.
2910 * a_resultPP : Ptr to the address of the area containing
2911 * the returned volume info.
2915 * Otherise, the return value of AFSVolXListOneVolume.
2919 *------------------------------------------------------------------------*/
2921 int UV_ListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2922 afs_uint32 a_volID, struct volintInfo **a_resultPP,
2926 afs_status_t tst = 0;
2927 volEntries volumeInfo; /*Area for returned info */
2930 * Set the area we're in which we are returning
2931 * the info. Setting the val field to a null pointer tells the stub
2932 * to allocate space for us.
2934 *a_resultPP = (volintInfo *) 0;
2935 volumeInfo.volEntries_val = (volintInfo *) 0;
2936 volumeInfo.volEntries_len = 0;
2938 tst = AFSVolListOneVolume(server, a_partID, a_volID, &volumeInfo);
2941 goto fail_UV_ListOneVolume;
2944 * We got the info; pull out the pointer to where the results lie.
2946 *a_resultPP = volumeInfo.volEntries_val;
2950 fail_UV_ListOneVolume:
2956 }/*UV_ListOneVolume*/
2958 /*sync vldb with all the entries on <myQueue> on <aserver> and <apart>*/
2960 ProcessEntries(afs_cell_handle_p cellHandle, struct qHead *myQueue,
2961 struct rx_connection *server, afs_int32 apart, afs_int32 force)
2967 afs_uint32 maxVolid = 0;
2968 struct nvldbentry entry;
2969 int noError = 1, error, same;
2970 int totalC, totalU, totalCE, totalUE, totalG;
2972 int aserver = ntohl(rx_HostOf(rx_PeerOf(server)));
2975 totalC = totalU = totalCE = totalUE = totalG = 0;
2978 /* get the next available id's from the vldb server */
2979 vcode = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 0, &maxVolid);
2983 totalG = myQueue->count;
2987 Lp_QEnumerate(myQueue, &success, &elem, 0);
2992 if (!elem.isValid[RWVOL] && !elem.isValid[ROVOL] && !elem.isValid[BACKVOL]) { /*something is wrong with elem */
2996 if (maxVolid <= elem.ids[RWVOL]) {
2997 temp2 = elem.ids[RWVOL] - maxVolid + 1;
2999 vcode = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3006 if (maxVolid <= elem.ids[ROVOL]) {
3007 temp2 = elem.ids[ROVOL] - maxVolid + 1;
3009 vcode = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3016 if (maxVolid <= elem.ids[BACKVOL]) {
3017 temp2 = elem.ids[BACKVOL] - maxVolid + 1;
3019 vcode = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3026 aVLDB_GetEntryByID(cellHandle, elem.ids[RWVOL], RWVOL, &entry, &tst);
3027 if (tst && (tst != VL_NOENT)) {
3030 } else if (tst && (tst == VL_NOENT)) { /*entry doesnot exist */
3031 /*set up a vldb entry for elem */
3032 memset(&entry, 0, sizeof(entry));
3033 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME);
3034 if (elem.isValid[RWVOL]) { /*rw exists */
3035 entry.flags |= RW_EXISTS;
3036 entry.serverFlags[entry.nServers] = ITSRWVOL;
3037 entry.serverNumber[entry.nServers] = aserver;
3038 entry.serverPartition[entry.nServers] = apart;
3039 entry.nServers += 1;
3040 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3041 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3042 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3044 if (elem.isValid[ROVOL]) { /*ro volume exists */
3045 entry.flags |= RO_EXISTS;
3046 entry.serverFlags[entry.nServers] = ITSROVOL;
3047 entry.serverNumber[entry.nServers] = aserver;
3048 entry.serverPartition[entry.nServers] = apart;
3049 entry.nServers += 1;
3050 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3051 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3054 if (elem.isValid[BACKVOL]) { /*backup volume exists */
3055 entry.flags |= BACK_EXISTS;
3056 if (!(entry.flags & RW_EXISTS)) { /*this helps to check for a stray backup if parent moves */
3057 entry.serverFlags[entry.nServers] = ITSRWVOL;
3058 entry.serverNumber[entry.nServers] = aserver;
3059 entry.serverPartition[entry.nServers] = apart;
3060 entry.nServers += 1;
3063 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3064 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3067 VLDB_CreateEntry(cellHandle, &entry, &tst);
3073 } else { /* Update the existing entry */
3074 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME); /*the name Could have changed */
3076 if (elem.isValid[RWVOL]) { /* A RW volume */
3077 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3079 /* A RW index is not found in the VLDB entry - will add it */
3081 entry.flags |= RW_EXISTS;
3082 entry.serverNumber[entry.nServers] = aserver;
3083 entry.serverPartition[entry.nServers] = apart;
3084 entry.serverFlags[entry.nServers] = ITSRWVOL;
3087 /* A RW index is found in the VLDB entry.
3088 * Verify that the volume location matches the VLDB location.
3089 * Fix the VLDB entry if it is not correct.
3093 VLDB_IsSameAddrs(cellHandle, aserver,
3094 entry.serverNumber[temp], &same,
3099 if (!same || (apart != entry.serverPartition[temp])) {
3100 /* VLDB says volume is in another place. Fix the VLDB entry */
3101 entry.serverNumber[temp] = aserver;
3102 entry.serverPartition[temp] = apart;
3105 entry.flags |= RW_EXISTS;
3107 if ((elem.ids[BACKVOL] != 0) && elem.isValid[BACKVOL])
3108 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3109 if ((elem.ids[ROVOL] != 0) && elem.isValid[ROVOL])
3110 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3113 if (elem.isValid[ROVOL]) {
3114 /*tackle a ro volume */
3116 if (!Lp_ROMatch(cellHandle, &entry, aserver, apart, 0)) {
3118 if (elem.ids[ROVOL] > entry.volumeId[ROVOL]) {
3119 /*there is a conflict of ids, keep the later volume */
3120 /*delete all the ro volumes listed in vldb entry since they
3123 int j, count, rwsite;
3126 count = entry.nServers;
3128 for (j = 0; j < count; j++) {
3129 if (entry.serverFlags[j] & ITSROVOL) {
3131 /*delete the site */
3132 entry.serverNumber[j] = 0;
3133 entry.serverPartition[j] = 0;
3134 entry.serverFlags[j] = 0;
3136 } else if (entry.serverFlags[j] & ITSRWVOL)
3141 entry.serverNumber[entry.nServers] =
3142 entry.serverNumber[rwsite];
3143 entry.serverPartition[entry.nServers] =
3144 entry.serverPartition[rwsite];
3145 entry.serverFlags[entry.nServers] =
3146 entry.serverFlags[rwsite];
3149 entry.serverNumber[entry.nServers] = aserver;
3150 entry.serverPartition[entry.nServers] = apart;
3151 entry.serverFlags[entry.nServers] = ITSROVOL;
3153 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3154 entry.flags |= RO_EXISTS;
3156 } else if (elem.ids[ROVOL] < entry.volumeId[ROVOL]) {
3157 if (!(entry.flags & RO_EXISTS)) {
3158 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3159 entry.serverNumber[entry.nServers] = aserver;
3160 entry.serverPartition[entry.nServers] = apart;
3161 entry.serverFlags[entry.nServers] = ITSROVOL;
3163 entry.flags |= RO_EXISTS;
3168 else if (elem.ids[ROVOL] == entry.volumeId[ROVOL]) {
3169 entry.serverNumber[entry.nServers] = aserver;
3170 entry.serverPartition[entry.nServers] = apart;
3171 entry.serverFlags[entry.nServers] = ITSROVOL;
3173 entry.flags |= RO_EXISTS;
3174 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3177 if (entry.volumeId[ROVOL] == INVALID_BID)
3178 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3181 if (elem.isValid[BACKVOL]) {
3182 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3183 if (temp != -1) { /*check if existing backup site matches with the given arguments */
3185 VLDB_IsSameAddrs(cellHandle, aserver,
3186 entry.serverNumber[temp], &same,
3192 /*tackle the backup volume */
3193 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3194 entry.flags |= BACK_EXISTS;
3196 if (entry.volumeId[BACKVOL] == INVALID_BID)
3197 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3200 VLDB_ReplaceEntry(cellHandle, elem.ids[RWVOL], RWVOL, &entry,
3201 LOCKREL_OPCODE | LOCKREL_AFSID |
3202 LOCKREL_TIMESTAMP, &tst);
3208 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3209 elem.ids[RWVOL], RWVOL,
3210 LOCKREL_OPCODE | LOCKREL_AFSID |
3216 } /* else update the existing entry */
3218 } /* End of while(1) */
3226 /*synchronise vldb with the file server <aserver> and <apart>(if flags=1).
3227 *else synchronise with all the valid partitions on <aserver>
3230 UV_SyncVldb(afs_cell_handle_p cellHandle, struct rx_connection *server,
3231 afs_int32 apart, int flags, int force, afs_status_p st)
3234 afs_status_t tst = 0;
3237 volEntries volumeInfo;
3239 struct qHead myQueue;
3240 struct partList PartList;
3245 /*this hints the stub to allocate space */
3246 volumeInfo.volEntries_val = (volintInfo *) 0;
3247 volumeInfo.volEntries_len = 0;
3249 if (!flags) { /*generate all the valid partitions */
3250 UV_ListPartitions(server, &PartList, &cnt, &tst);
3252 goto fail_UV_SyncVldb;
3255 PartList.partId[0] = apart;
3259 for (i = 0; i < cnt; i++) {
3260 apart = PartList.partId[i];
3261 /*this hints the stub to allocate space */
3262 volumeInfo.volEntries_val = (volintInfo *) 0;
3263 volumeInfo.volEntries_len = 0;
3264 tst = AFSVolListVolumes(server, apart, 1, &volumeInfo);
3266 goto fail_UV_SyncVldb;
3268 count = volumeInfo.volEntries_len;
3269 pntr = volumeInfo.volEntries_val;
3271 if (!vos_PartitionIdToName(apart, pname, &tst)) {
3272 goto fail_UV_SyncVldb;
3274 /*collect all vol entries by their parentid */
3275 tst = GroupEntries(server, pntr, count, &myQueue, apart);
3278 if (volumeInfo.volEntries_val) {
3279 /*free the space allocated by the stub */
3280 free(volumeInfo.volEntries_val);
3281 volumeInfo.volEntries_val = 0;
3285 tst = ProcessEntries(cellHandle, &myQueue, server, apart, force);
3287 tst = VOLSERFAILEDOP;
3288 if (volumeInfo.volEntries_val) {
3289 /*free the space allocated by the stub */
3290 free(volumeInfo.volEntries_val);
3291 volumeInfo.volEntries_val = 0;
3298 tst = VOLSERFAILEDOP;
3299 } /* thru all partitions */
3304 if (volumeInfo.volEntries_val)
3305 free(volumeInfo.volEntries_val);
3318 CheckVldbRWBK(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3319 afs_int32 * modified, afs_status_p st)
3322 afs_status_t tst = 0;
3328 idx = Lp_GetRwIndex(cellHandle, entry, 0);
3330 /* Check to see if the RW volume exists and set the RW_EXISTS
3333 if (idx == -1) { /* Did not find a RW entry */
3334 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
3335 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
3340 (cellHandle, entry->serverNumber[idx],
3341 entry->serverPartition[idx], entry->volumeId[RWVOL], &tst)) {
3342 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does no
3344 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
3347 } else if (tst == ENODEV) { /* RW volume does not exist */
3348 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists
3350 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist
3355 /* If VLDB says it didn't exist, then ignore error */
3356 if (entry->flags & RW_EXISTS) {
3357 goto fail_CheckVldbRWBK;
3362 /* Check to see if the BK volume exists and set the BACK_EXISTS
3363 * flag accordingly. idx already ponts to the RW entry.
3365 if (idx == -1) { /* Did not find a RW entry */
3366 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
3367 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
3370 } else { /* Found a RW entry */
3372 (cellHandle, entry->serverNumber[idx],
3373 entry->serverPartition[idx], entry->volumeId[BACKVOL], &tst)) {
3374 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does n
3376 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
3379 } else if (tst == ENODEV) { /* BK volume does not exist */
3380 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists
3382 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist
3387 /* If VLDB says it didn't exist, then ignore error */
3388 if (entry->flags & BACK_EXISTS) {
3389 goto fail_CheckVldbRWBK;
3394 /* If there is an idx but the BK and RW volumes no
3395 * longer exist, then remove the RW entry.
3397 if ((idx != -1) && !(entry->flags & RW_EXISTS)
3398 && !(entry->flags & BACK_EXISTS)) {
3399 Lp_SetRWValue(cellHandle, entry, entry->serverNumber[idx],
3400 entry->serverPartition[idx], 0L, 0L);
3409 *modified = modentry;
3419 CheckVldbRO(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3420 afs_int32 * modified, afs_status_p st)
3423 afs_status_t tst = 0;
3425 int foundro = 0, modentry = 0;
3430 /* Check to see if the RO volumes exist and set the RO_EXISTS
3433 for (idx = 0; idx < entry->nServers; idx++) {
3434 if (!(entry->serverFlags[idx] & ITSROVOL)) {
3435 continue; /* not a RO */
3439 (cellHandle, entry->serverNumber[idx],
3440 entry->serverPartition[idx], entry->volumeId[ROVOL], &tst)) {
3442 } else if (tst == ENODEV) { /* RW volume does not exist */
3443 Lp_SetROValue(cellHandle, entry, entry->serverNumber[idx],
3444 entry->serverPartition[idx], 0L, 0L);
3449 goto fail_CheckVldbRO;
3453 if (foundro) { /* A RO volume exists */
3454 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not e
3456 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
3459 } else { /* A RO volume does not exist */
3460 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
3461 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
3470 *modified = modentry;
3478 /*ensure that <entry> matches with the info on file servers */
3480 CheckVldb(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3481 afs_int32 * modified, afs_status_p st)
3484 afs_status_t tst = 0;
3488 afs_int32 modentry = 0;
3494 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
3496 goto fail_CheckVldb;
3501 /* Check to see if the VLDB is ok without locking it (pass 1).
3502 * If it will change, then lock the VLDB entry, read it again,
3503 * then make the changes to it (pass 2).
3507 ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL],
3508 RWVOL, VLOP_DELETE);
3510 goto fail_CheckVldb;
3514 if (!aVLDB_GetEntryByID
3515 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, &tst)) {
3516 goto fail_CheckVldb;
3522 /* Check if the RW and BK entries are ok */
3523 if (!CheckVldbRWBK(cellHandle, entry, &modentry, &tst)) {
3524 goto fail_CheckVldb;
3526 if (modentry && (pass == 1))
3529 /* Check if the RO volumes entries are ok */
3530 if (!CheckVldbRO(cellHandle, entry, &modentry, &tst)) {
3531 goto fail_CheckVldb;
3533 if (modentry && (pass == 1))
3536 /* The VLDB entry has been updated. If it as been modified, then
3537 * write the entry back out the the VLDB.
3543 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
3544 && !(entry->flags & RO_EXISTS)) {
3545 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
3547 ubik_VL_DeleteEntry(cellHandle->vos, 0,
3548 entry->volumeId[RWVOL], RWVOL);
3550 goto fail_CheckVldb;
3553 /* Replace old entry with our new one */
3554 if (!VLDB_ReplaceEntry
3555 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry,
3556 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
3558 goto fail_CheckVldb;
3571 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3572 entry->volumeId[RWVOL], RWVOL,
3573 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
3586 /*synchronise <aserver> <apart>(if flags = 1) with the vldb .
3587 *if flags = 0, synchronise all the valid partitions on <aserver>*/
3589 UV_SyncServer(afs_cell_handle_p cellHandle, struct rx_connection *server,
3590 afs_int32 apart, int flags, afs_status_p st)
3593 afs_status_t tst = 0;
3595 afs_int32 nentries, tentries = 0;
3596 struct VldbListByAttributes attributes;
3597 nbulkentries arrayEntries;
3599 struct nvldbentry *vllist;
3602 afs_int32 modified = 0;
3605 arrayEntries.nbulkentries_val = 0;
3607 /* Set up attributes to search VLDB */
3608 attributes.server = ntohl(rx_HostOf(rx_PeerOf(server)));
3609 attributes.Mask = VLLIST_SERVER;
3611 attributes.partition = apart;
3612 attributes.Mask |= VLLIST_PARTITION;
3615 for (si = 0; si != -1; si = nsi) {
3616 /*initialize to hint the stub to alloc space */
3617 memset(&arrayEntries, 0, sizeof(arrayEntries));
3618 if (!VLDB_ListAttributes
3619 (cellHandle, &attributes, &nentries, &arrayEntries, &tst)) {
3620 goto fail_UV_SyncServer;
3623 tentries += nentries;
3625 for (j = 0; j < nentries; j++) { /* process each entry */
3626 vllist = &arrayEntries.nbulkentries_val[j];
3627 if (!CheckVldb(cellHandle, vllist, &modified, &tst)) {
3632 if (arrayEntries.nbulkentries_val) {
3633 free(arrayEntries.nbulkentries_val);
3634 arrayEntries.nbulkentries_val = 0;
3641 if (arrayEntries.nbulkentries_val) {
3642 free(arrayEntries.nbulkentries_val);
3645 tst = VOLSERFAILEDOP;
3652 /* rename volume <oldname> to <newname>, changing the names of the related
3653 * readonly and backup volumes. This operation is also idempotent.
3654 * salvager is capable of recovering from rename operation stopping halfway.
3655 * to recover run syncserver on the affected machines,it will force
3656 * renaming to completion. name clashes should have been detected before
3660 UV_RenameVolume(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3661 char *newname, afs_status_p st)
3664 afs_status_t tst = 0;
3665 afs_status_t etst = 0;
3668 char nameBuffer[256];
3670 struct rx_connection *aconn;
3673 aconn = (struct rx_connection *)0;
3677 tst = ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
3679 goto fail_UV_RenameVolume;
3683 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
3685 if (!VLDB_ReplaceEntry
3686 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, 0, &tst)) {
3687 goto fail_UV_RenameVolume;
3689 /*at this stage the intent to rename is recorded in the vldb, as far
3691 * is concerned, oldname is lost */
3692 if (entry->flags & RW_EXISTS) {
3693 index = Lp_GetRwIndex(cellHandle, entry, 0);
3694 if (index == -1) { /* there is a serious discrepancy */
3695 tst = VOLSERVLDB_ERROR;
3696 goto fail_UV_RenameVolume;
3699 UV_Bind(cellHandle, entry->serverNumber[index],
3700 AFSCONF_VOLUMEPORT);
3702 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
3703 entry->serverPartition[index], ITOffline, &tid);
3704 if (tst) { /*volume doesnot exist */
3705 goto fail_UV_RenameVolume;
3706 } else { /*volume exists, process it */
3709 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
3710 entry->volumeId[RWVOL],
3711 entry->volumeId[ROVOL],
3712 entry->volumeId[BACKVOL]);
3714 tst = AFSVolEndTrans(aconn, tid, &rcode);
3717 goto fail_UV_RenameVolume;
3720 goto fail_UV_RenameVolume;
3724 rx_ReleaseCachedConnection(aconn);
3725 aconn = (struct rx_connection *)0;
3727 /*end rw volume processing */
3728 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
3729 index = Lp_GetRwIndex(cellHandle, entry, 0);
3730 if (index == -1) { /* there is a serious discrepancy */
3731 tst = VOLSERVLDB_ERROR;
3732 goto fail_UV_RenameVolume;
3735 UV_Bind(cellHandle, entry->serverNumber[index],
3736 AFSCONF_VOLUMEPORT);
3738 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
3739 entry->serverPartition[index], ITOffline, &tid);
3740 if (tst) { /*volume doesnot exist */
3741 goto fail_UV_RenameVolume;
3742 } else { /*volume exists, process it */
3743 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
3744 goto fail_UV_RenameVolume;
3746 strcpy(nameBuffer, newname);
3747 strcat(nameBuffer, ".backup");
3750 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
3751 entry->volumeId[RWVOL], 0, 0);
3753 tst = AFSVolEndTrans(aconn, tid, &rcode);
3756 goto fail_UV_RenameVolume;
3759 goto fail_UV_RenameVolume;
3762 } /* end backup processing */
3764 rx_ReleaseCachedConnection(aconn);
3765 aconn = (struct rx_connection *)0;
3766 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
3767 for (i = 0; i < entry->nServers; i++) {
3768 if (entry->serverFlags[i] & ITSROVOL) {
3770 UV_Bind(cellHandle, entry->serverNumber[i],
3771 AFSCONF_VOLUMEPORT);
3773 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
3774 entry->serverPartition[i], ITOffline,
3776 if (tst) { /*volume doesnot exist */
3777 goto fail_UV_RenameVolume;
3778 } else { /*volume exists, process it */
3779 strcpy(nameBuffer, newname);
3780 strcat(nameBuffer, ".readonly");
3781 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
3782 goto fail_UV_RenameVolume;
3785 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
3786 entry->volumeId[RWVOL], 0, 0);
3788 tst = AFSVolEndTrans(aconn, tid, &rcode);
3791 goto fail_UV_RenameVolume;
3794 goto fail_UV_RenameVolume;
3798 rx_ReleaseCachedConnection(aconn);
3799 aconn = (struct rx_connection *)0;
3805 fail_UV_RenameVolume:
3809 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3810 entry->volumeId[RWVOL], RWVOL,
3811 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3818 etst = AFSVolEndTrans(aconn, tid, &rcode);
3825 rx_ReleaseCachedConnection(aconn);
3833 /*group all the volume entries on< apart >by their parentid or by their ids'
3834 *if the volume is rw. <count> is the number of entries to be processesd.
3835 *<pntr> points to the first entry.< myQueue> is the queue with entries
3838 GroupEntries(struct rx_connection *server, volintInfo * pntr, afs_int32 count,
3839 struct qHead *myQueue, afs_int32 apart)
3841 struct aqueue *qPtr;
3843 afs_int32 curId, code;
3845 afs_int32 error = 0;
3851 for (i = 0; i < count; i++) { /*process each entry */
3852 if (pntr->status) { /* entry is valid */
3853 if (pntr->type == RWVOL)
3854 curId = pntr->volid;
3856 curId = pntr->parentID;
3857 Lp_QScan(myQueue, curId, &success, &qPtr, 0);
3858 if (success) { /*entry exists in the queue */
3859 if (pntr->type == RWVOL) {
3860 /*check if the rw exists already, if so hang on the
3861 * later version if the present version is ok */
3862 if (qPtr->isValid[RWVOL]) {
3863 /*this should not happen, there is a serious error here */
3865 error = VOLSERMULTIRWVOL;
3867 qPtr->isValid[RWVOL] = 1;
3868 qPtr->copyDate[RWVOL] = pntr->copyDate;
3869 if (!qPtr->isValid[BACKVOL])
3870 qPtr->ids[BACKVOL] = pntr->backupID;
3871 if (!qPtr->isValid[ROVOL])
3872 qPtr->ids[ROVOL] = pntr->cloneID;
3874 } else if (pntr->type == BACKVOL) {
3875 if (qPtr->isValid[BACKVOL]) {
3876 /*do different checks, delete superflous volume */
3877 if (qPtr->copyDate[BACKVOL] > pntr->copyDate) {
3878 /*delete the present volume . */
3880 CheckAndDeleteVolume(server, apart, 0,
3888 /*delete the older volume after making sure, current one is ok */
3890 CheckAndDeleteVolume(server, apart,
3892 qPtr->ids[BACKVOL]);
3898 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3899 qPtr->ids[BACKVOL] = pntr->volid;
3903 qPtr->isValid[BACKVOL] = 1;
3904 qPtr->ids[BACKVOL] = pntr->volid;
3905 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3907 } else if (pntr->type == ROVOL) {
3908 if (qPtr->isValid[ROVOL]) {
3909 /*do different checks, delete superflous volume */
3910 if (qPtr->copyDate[ROVOL] > pntr->copyDate) {
3911 /*delete the present volume . */
3914 CheckAndDeleteVolume(server, apart, 0,
3921 /*delete the older volume after making sure, current one is ok */
3923 CheckAndDeleteVolume(server, apart,
3931 qPtr->copyDate[ROVOL] = pntr->copyDate;
3932 qPtr->ids[ROVOL] = pntr->volid;
3936 qPtr->isValid[ROVOL] = 1;
3937 qPtr->ids[ROVOL] = pntr->volid;
3938 qPtr->copyDate[ROVOL] = pntr->copyDate;
3942 error = VOLSERBADOP;
3944 } else { /*create a fresh entry */
3945 qPtr = malloc(sizeof(struct aqueue));
3946 if (pntr->type == RWVOL) {
3947 qPtr->isValid[RWVOL] = 1;
3948 qPtr->isValid[BACKVOL] = 0;
3949 qPtr->isValid[ROVOL] = 0;
3950 qPtr->ids[RWVOL] = pntr->volid;
3951 qPtr->ids[BACKVOL] = pntr->backupID;
3952 qPtr->ids[ROVOL] = pntr->cloneID;
3953 qPtr->copyDate[RWVOL] = pntr->copyDate;
3954 strncpy(qPtr->name, pntr->name, VOLSER_OLDMAXVOLNAME);
3956 } else if (pntr->type == BACKVOL) {
3957 qPtr->isValid[RWVOL] = 0;
3958 qPtr->isValid[BACKVOL] = 1;
3959 qPtr->isValid[ROVOL] = 0;
3960 qPtr->ids[RWVOL] = pntr->parentID;
3961 qPtr->ids[BACKVOL] = pntr->volid;
3962 qPtr->ids[ROVOL] = 0;
3963 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3964 vsu_ExtractName(qPtr->name, pntr->name);
3966 } else if (pntr->type == ROVOL) {
3967 qPtr->isValid[RWVOL] = 0;
3968 qPtr->isValid[BACKVOL] = 0;
3969 qPtr->isValid[ROVOL] = 1;
3970 qPtr->ids[RWVOL] = pntr->parentID;
3971 qPtr->ids[BACKVOL] = 0;
3972 qPtr->ids[ROVOL] = pntr->volid;
3973 qPtr->copyDate[ROVOL] = pntr->copyDate;
3974 vsu_ExtractName(qPtr->name, pntr->name);
3978 Lp_QAdd(myQueue, qPtr);
3980 pntr++; /*get next entry */
3990 /*report on all the active transactions on volser */
3992 UV_VolserStatus(struct rx_connection *server, transDebugInfo ** rpntr,
3993 afs_int32 * rcount, afs_status_p st)
3996 afs_status_t tst = 0;
3997 transDebugEntries transInfo;
3999 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
4000 transInfo.transDebugEntries_len = 0;
4001 tst = AFSVolMonitor(server, &transInfo);
4003 goto fail_UV_VolserStatus;
4006 *rcount = transInfo.transDebugEntries_len;
4007 *rpntr = transInfo.transDebugEntries_val;
4010 fail_UV_VolserStatus:
4013 if (transInfo.transDebugEntries_val) {
4014 free(transInfo.transDebugEntries_val);
4024 /*delete the volume without interacting with the vldb */
4026 UV_VolumeZap(afs_cell_handle_p cellHandle, struct rx_connection *server,
4027 unsigned int partition, afs_uint32 volumeId, afs_status_p st)
4029 afs_int32 rcode, ttid;
4031 afs_status_t tst = 0;
4035 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
4037 tst = AFSVolDeleteVolume(server, ttid);
4039 tst = AFSVolEndTrans(server, ttid, &rcode);
4047 * We failed to delete the volume, but we still need
4048 * to end the transaction.
4050 AFSVolEndTrans(server, ttid, &rcode);
4062 UV_SetVolume(struct rx_connection *server, afs_int32 partition,
4063 afs_uint32 volid, afs_int32 transflag, afs_int32 setflag,
4064 unsigned int sleepTime, afs_status_p st)
4067 afs_status_t tst = 0;
4068 afs_status_t etst = 0;
4072 tst = AFSVolTransCreate(server, volid, partition, transflag, &tid);
4074 goto fail_UV_SetVolume;
4077 tst = AFSVolSetFlags(server, tid, setflag);
4079 goto fail_UV_SetVolume;
4090 etst = AFSVolEndTrans(server, tid, &rcode);
4091 /* FIXME: this looks like a typo */
4094 tst = (etst ? etst : rcode);