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 <afs/param.h>
22 #include <afsconfig.h>
28 #include "lockprocs.h"
29 #include "../adminutil/afs_AdminInternal.h"
30 #include <afs/afs_AdminErrors.h>
31 #include "afs_vosAdmin.h"
46 static afs_int32 GroupEntries();
50 afs_int32 vldbEntryIndex;
53 static struct rx_connection *UV_Bind(
54 afs_cell_handle_p cellHandle,
58 return rx_GetCachedConnection(htonl(aserver), htons(port), VOLSERVICE_ID,
59 cellHandle->tokens->afs_sc[cellHandle->tokens->sc_index],
60 cellHandle->tokens->sc_index);
64 /* if <okvol> is allright(indicated by beibg able to
65 * start a transaction, delete the <delvol> */
66 static afs_int32 CheckAndDeleteVolume(
67 struct rx_connection *aconn,
72 afs_int32 error,code,tid,rcode;
78 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline,&tid);
79 if(!error && code) error = code;
80 code = AFSVolDeleteVolume(aconn,tid);
81 if(!error && code) error = code;
82 code = AFSVolEndTrans(aconn,tid, &rcode);
83 if(!code) code = rcode;
84 if(!error && code) error = code;
88 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline,&tid);
90 code = AFSVolEndTrans(aconn,tid, &rcode);
91 if(!code) code = rcode;
92 if(!error && code) error = code;
93 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline,&tid);
94 if(!error && code) error = code;
95 code = AFSVolDeleteVolume(aconn,tid);
96 if(!error && code) error = code;
97 code = AFSVolEndTrans(aconn,tid, &rcode);
98 if(!code) code = rcode;
99 if(!error && code) error = code;
107 /* forcibly remove a volume. Very dangerous call */
109 afs_cell_handle_p cellHandle,
110 struct rx_connection *server,
111 unsigned int partition,
112 unsigned int volumeId,
116 afs_status_t tst = 0;
118 tst = AFSVolNukeVolume(server, partition, volumeId);
130 /* create a volume, given a server, partition number, volume name --> sends
131 * back new vol id in <anewid>*/
133 afs_cell_handle_p cellHandle,
134 struct rx_connection *server,
135 unsigned int partition,
136 const char *volumeName,
138 unsigned int *volumeId,
142 afs_status_t tst = 0;
145 struct nvldbentry entry;
146 struct volintInfo tstatus;
148 memset (&tstatus, 0, sizeof(tstatus));
150 tstatus.maxquota = quota;
152 /* next the next 3 available ids from the VLDB */
153 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 3, volumeId);
155 goto fail_UV_CreateVolume;
158 tst = AFSVolCreateVolume(server, partition, volumeName, volser_RW, 0,
161 goto fail_UV_CreateVolume;
164 AFSVolSetInfo(server, tid, &tstatus);
166 tst = AFSVolSetFlags(server, tid, 0);
168 goto fail_UV_CreateVolume;
171 /* set up the vldb entry for this volume */
172 strncpy(entry.name, volumeName,VOLSER_OLDMAXVOLNAME);
174 entry.serverNumber[0] = ntohl(rx_HostOf(rx_PeerOf(server)));
175 entry.serverPartition[0] = partition;
176 entry.flags = RW_EXISTS;
177 entry.serverFlags[0] = ITSRWVOL;
178 entry.volumeId[RWVOL] = *volumeId;
179 entry.volumeId[ROVOL] = *volumeId + 1;
180 entry.volumeId[BACKVOL] = *volumeId + 2;
183 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
184 AFSVolDeleteVolume(server,tid);
185 goto fail_UV_CreateVolume;
188 tst = AFSVolEndTrans(server, tid, &rcode);
191 goto fail_UV_CreateVolume;
195 fail_UV_CreateVolume:
198 AFSVolEndTrans(server, tid, &rcode);
208 /* Delete the volume <volid>on <aserver> <apart>
209 * the physical entry gets removed from the vldb only if the ref count
213 afs_cell_handle_p cellHandle,
214 struct rx_connection *server,
215 unsigned int partition,
216 unsigned int volumeId,
220 afs_status_t tst = 0;
221 afs_status_t temp = 0;
222 int serverAddr = ntohl(rx_HostOf(rx_PeerOf(server)));
226 struct nvldbentry entry;
228 afs_int32 avoltype = -1, vtype;
229 int notondisk = 0, notinvldb = 0;
231 /* Find and read the VLDB entry for this volume */
232 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, volumeId, avoltype,
235 if (tst != VL_NOENT) {
236 goto fail_UV_DeleteVolume;
242 if (!VLDB_GetEntryByID(cellHandle, volumeId, avoltype, &entry, &tst)) {
243 goto fail_UV_DeleteVolume;
248 /* Whether volume is in the VLDB or not. Delete the volume on disk */
249 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
254 goto fail_UV_DeleteVolume;
258 tst = AFSVolDeleteVolume(server, ttid);
260 goto fail_UV_DeleteVolume;
262 tst = AFSVolEndTrans(server, ttid, &rcode);
263 tst = (tst ? tst : rcode);
266 goto fail_UV_DeleteVolume;
271 goto fail_UV_DeleteVolume;
274 if (volumeId == entry.volumeId[BACKVOL]) {
275 if ( !(entry.flags & BACK_EXISTS) ||
276 !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
278 goto fail_UV_DeleteVolume;
281 entry.flags &= ~BACK_EXISTS;
285 else if (volumeId == entry.volumeId[ROVOL]) {
286 if (!Lp_ROMatch(cellHandle, &entry, serverAddr, partition, &tst)) {
288 goto fail_UV_DeleteVolume;
291 Lp_SetROValue(cellHandle, &entry, serverAddr, partition, 0, 0);
293 if (!Lp_ROMatch(cellHandle, &entry, 0, 0, &tst)) {
294 entry.flags &= ~RO_EXISTS;
299 else if (volumeId == entry.volumeId[RWVOL]) {
300 if (!(entry.flags & RW_EXISTS) ||
301 !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
303 goto fail_UV_DeleteVolume;
306 /* Delete backup if it exists */
307 tst = AFSVolTransCreate(server, entry.volumeId[BACKVOL], partition,
310 tst = AFSVolDeleteVolume(server, ttid);
312 goto fail_UV_DeleteVolume;
314 tst = AFSVolEndTrans(server, ttid, &rcode);
316 tst = (tst ? tst : rcode);
318 goto fail_UV_DeleteVolume;
322 Lp_SetRWValue(cellHandle, &entry, serverAddr, partition, 0L, 0L);
324 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
330 notinvldb = 2; /* Not found on this server and partition */
331 goto fail_UV_DeleteVolume;
334 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
335 tst = ubik_Call(VL_DeleteEntry, cellHandle->vos, 0, volumeId, vtype);
337 goto fail_UV_DeleteVolume;
340 if (!VLDB_ReplaceEntry(cellHandle, volumeId, vtype, &entry,
341 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
343 goto fail_UV_DeleteVolume;
349 fail_UV_DeleteVolume:
351 if (notondisk && notinvldb) {
352 if (!tst) tst = ADMVOSVOLUMENOEXIST;
356 temp = AFSVolEndTrans(server, ttid, &rcode);
357 temp = (temp ? temp : rcode);
359 if (!tst) tst = temp;
364 temp = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, volumeId, -1,
365 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
367 if (!tst) tst = temp;
377 #define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto mfail; }
379 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
380 * <atopart>. The operation is almost idempotent
384 afs_cell_handle_p cellHandle,
386 afs_int32 afromserver,
393 afs_status_t tst = 0;
394 afs_status_t etst = 0;
395 struct rx_connection *toconn, *fromconn ;
396 afs_int32 fromtid, totid, clonetid;
399 char tmpName[VOLSER_MAXVOLNAME +1];
402 struct restoreCookie cookie;
403 afs_int32 newVol, volid, backupId;
404 struct volser_status tstatus;
405 struct destServer destination;
407 struct nvldbentry entry;
411 afs_int32 store_flags;
413 #ifdef ENABLE_BUGFIX_1165
414 volEntries volumeInfo;
415 struct volintInfo *infop = 0;
419 fromconn = (struct rx_connection *)0;
420 toconn = (struct rx_connection *)0;
430 if (!VLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
431 goto fail_UV_MoveVolume;
434 if (entry.volumeId[RWVOL] != afromvol)
436 tst = ADMVOSVOLUMEMOVERWONLY;
437 goto fail_UV_MoveVolume;
440 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,afromvol, RWVOL, VLOP_MOVE);
442 goto fail_UV_MoveVolume;
446 if (!VLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
447 goto fail_UV_MoveVolume;
450 backupId = entry.volumeId[BACKVOL];
452 if ( !Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst) )
454 /* the from server and partition do not exist in the vldb entry corresponding to volid */
455 if ( !Lp_Match(cellHandle, &entry, atoserver, atopart, &tst) )
457 /* the to server and partition do not exist in the vldb entry corresponding to volid */
458 tst = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, afromvol, -1,
459 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
461 goto fail_UV_MoveVolume;
463 tst = VOLSERVOLMOVED;
464 goto fail_UV_MoveVolume;
467 /* delete the volume afromvol on src_server */
468 /* from-info does not exist but to-info does =>
469 * we have already done the move, but the volume
470 * may still be existing physically on from fileserver
472 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
476 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline, &fromtid);
478 { /* volume exists - delete it */
479 tst = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
481 goto fail_UV_MoveVolume;
484 tst = AFSVolDeleteVolume(fromconn,fromtid);
486 goto fail_UV_MoveVolume;
489 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
491 if (!tst) tst = rcode;
493 goto fail_UV_MoveVolume;
497 /*delete the backup volume now */
499 tst = AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
501 { /* backup volume exists - delete it */
502 tst = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
504 goto fail_UV_MoveVolume;
507 tst = AFSVolDeleteVolume(fromconn,fromtid);
509 goto fail_UV_MoveVolume;
512 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
514 if (!tst) tst = rcode;
516 goto fail_UV_MoveVolume;
522 goto fail_UV_MoveVolume;
525 /* From-info matches the vldb info about volid,
526 * its ok start the move operation, the backup volume
527 * on the old site is deleted in the process
529 if (afrompart == atopart)
531 if (!VLDB_IsSameAddrs(cellHandle, afromserver, atoserver, &same, &tst)) {
532 goto fail_UV_MoveVolume;
535 tst = VOLSERVOLMOVED;
536 goto fail_UV_MoveVolume;
541 toconn = UV_Bind(cellHandle, atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
542 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
543 fromtid = totid = 0; /* initialize to uncreated */
546 * clone the read/write volume locally.
549 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
551 goto fail_UV_MoveVolume;
556 tst = ubik_Call (VL_GetNewVolumeId, cellHandle->vos, 0, 1, &newVol);
558 goto fail_UV_MoveVolume;
561 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
562 strcpy(vname, "move-clone-temp");
563 tst = AFSVolClone(fromconn, fromtid, 0,readonlyVolume, vname, &newVol);
565 goto fail_UV_MoveVolume;
568 /* lookup the name of the volume we just cloned */
570 tst = AFSVolGetName(fromconn, fromtid, &volName);
572 goto fail_UV_MoveVolume;
576 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
578 if (!tst) tst = rcode;
580 goto fail_UV_MoveVolume;
584 * Create the destination volume
587 tst = AFSVolTransCreate (fromconn, newVol, afrompart, ITOffline, &clonetid);
589 goto fail_UV_MoveVolume;
591 tst = AFSVolSetFlags (fromconn, clonetid, VTDeleteOnSalvage|VTOutOfService); /*redundant */
593 goto fail_UV_MoveVolume;
596 /* remember time from which we've dumped the volume */
597 tst = AFSVolGetStatus (fromconn, clonetid, &tstatus);
599 goto fail_UV_MoveVolume;
602 fromDate = tstatus.creationDate-CLOCKSKEW;
604 #ifdef ENABLE_BUGFIX_1165
606 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
607 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
608 * don't use this information...
610 volumeInfo.volEntries_val = (volintInfo *)0;/*this hints the stub to allocate space*/
611 volumeInfo.volEntries_len = 0;
612 tst = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
614 goto fail_UV_MoveVolume;
617 infop = (volintInfo *) volumeInfo.volEntries_val;
618 infop->maxquota = -1; /* Else it will replace the default quota */
621 /* create a volume on the target machine */
623 tst = AFSVolTransCreate (toconn, volid, atopart, ITOffline, &totid);
625 { /*delete the existing volume */
627 tst = AFSVolDeleteVolume(toconn, totid);
629 goto fail_UV_MoveVolume;
632 tst = AFSVolEndTrans(toconn, totid, &rcode);
634 if (!tst) tst = rcode;
636 goto fail_UV_MoveVolume;
641 tst = AFSVolCreateVolume (toconn, atopart, volName, volser_RW, volid, &volid, &totid);
643 goto fail_UV_MoveVolume;
646 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
648 volName = (char *) 0;
650 tst = AFSVolSetFlags (toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
652 goto fail_UV_MoveVolume;
656 * Now dump the clone to the new volume
659 destination.destHost = atoserver;
660 destination.destPort = AFSCONF_VOLUMEPORT;
661 destination.destSSID = 1;
663 /* Copy the clone to the new volume */
664 strncpy(cookie.name,tmpName,VOLSER_OLDMAXVOLNAME);
666 cookie.parent = entry.volumeId[RWVOL];
668 tst = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
670 goto fail_UV_MoveVolume;
673 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
674 if (!tst) tst = rcode;
677 goto fail_UV_MoveVolume;
681 * reattach to the main-line volume, and incrementally dump it.
684 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
686 goto fail_UV_MoveVolume;
689 /* now do the incremental */
690 tst = AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,&cookie);
692 goto fail_UV_MoveVolume;
695 /* now adjust the flags so that the new volume becomes official */
696 tst = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
698 goto fail_UV_MoveVolume;
701 tst = AFSVolSetFlags(toconn, totid, 0);
703 goto fail_UV_MoveVolume;
706 #ifdef ENABLE_BUGFIX_1165
707 tst = AFSVolSetInfo(toconn, totid, infop);
709 goto fail_UV_MoveVolume;
713 /* put new volume online */
714 tst = AFSVolEndTrans(toconn, totid, &rcode);
716 if (!tst) tst = rcode;
718 goto fail_UV_MoveVolume;
721 Lp_SetRWValue(cellHandle, &entry, afromserver, afrompart,
723 store_flags = entry.flags;
724 entry.flags &= ~BACK_EXISTS;
726 if (!VLDB_ReplaceEntry(cellHandle, afromvol, -1, &entry,
727 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
729 goto fail_UV_MoveVolume;
731 entry.flags = store_flags;
734 if (atoserver != afromserver)
736 /* set forwarding pointer for moved volumes */
737 tst = AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
739 goto fail_UV_MoveVolume;
743 tst = AFSVolDeleteVolume(fromconn,fromtid); /* zap original volume */
745 goto fail_UV_MoveVolume;
748 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
750 if (!tst) tst = rcode;
752 goto fail_UV_MoveVolume;
755 /* Delete the backup volume on the original site */
756 tst = AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
759 tst = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
761 goto fail_UV_MoveVolume;
764 tst = AFSVolDeleteVolume(fromconn,fromtid);
766 goto fail_UV_MoveVolume;
769 tst = AFSVolEndTrans(fromconn,fromtid, &rcode);
771 if (!tst) tst = rcode;
773 goto fail_UV_MoveVolume;
777 else tst = 0; /* no backup volume? that's okay */
781 tst = 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);
794 if (!tst) tst = rcode;
797 goto fail_UV_MoveVolume;
803 /* normal cleanup code */
807 etst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, afromvol, -1,
808 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
811 if (!tst) tst = etst;
817 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
820 if (!tst) tst = (etst ? etst : rcode);
826 etst = AFSVolEndTrans(fromconn, clonetid, &rcode);
829 if (!tst) tst = (etst ? etst : rcode);
835 etst = AFSVolEndTrans(toconn, totid, &rcode);
838 if (!tst) tst = (etst ? etst : rcode);
841 if (volName) free(volName);
842 #ifdef ENABLE_BUGFIX_1165
843 if (infop) free(infop);
845 if (fromconn) rx_ReleaseCachedConnection(fromconn);
846 if (toconn) rx_ReleaseCachedConnection(toconn);
854 /* come here only when the sky falls */
858 /* unlock VLDB entry */
860 ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, afromvol, -1,
861 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
863 if (clonetid) AFSVolEndTrans(fromconn, clonetid, &rcode);
864 if (totid) AFSVolEndTrans(toconn, totid, &rcode);
866 { /* put it on-line */
867 AFSVolSetFlags(fromconn,fromtid,0);
868 AFSVolEndTrans(fromconn, fromtid, &rcode);
871 if (!VLDB_GetEntryByID (cellHandle, afromvol, -1, &entry, &tst)) {
875 /* Delete either the volume on the source location or the target location.
876 * If the vldb entry still points to the source location, then we know the
877 * volume move didn't finish so we remove the volume from the target
878 * location. Otherwise, we remove the volume from the source location.
880 if (Lp_Match(cellHandle, &entry, afromserver,afrompart,&tst)) { /* didn't move - delete target volume */
882 if (volid && toconn) {
883 tst=AFSVolTransCreate(toconn,volid,atopart, ITOffline,&totid);
885 AFSVolSetFlags(toconn,totid, VTDeleteOnSalvage | VTOutOfService);
886 AFSVolDeleteVolume(toconn,totid);
887 AFSVolEndTrans(toconn,totid,&rcode);
891 /* put source volume on-line */
893 tst=AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
895 AFSVolSetFlags(fromconn,fromtid,0);
896 AFSVolEndTrans(fromconn,fromtid,&rcode);
900 else { /* yep, move complete */
901 /* delete backup volume */
903 tst=AFSVolTransCreate (fromconn,backupId,afrompart, ITOffline,&fromtid);
905 AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService);
906 AFSVolDeleteVolume(fromconn,fromtid);
907 AFSVolEndTrans(fromconn,fromtid,&rcode);
910 /* delete source volume */
911 tst=AFSVolTransCreate (fromconn, afromvol, afrompart, ITBusy, &fromtid);
913 AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService);
914 if (atoserver != afromserver)
915 AFSVolSetForwarding(fromconn,fromtid,htonl(atoserver));
916 AFSVolDeleteVolume(fromconn,fromtid);
917 AFSVolEndTrans(fromconn,fromtid,&rcode);
922 /* common cleanup - delete local clone */
924 tst = AFSVolTransCreate (fromconn, newVol, afrompart, ITOffline, &clonetid);
926 AFSVolDeleteVolume(fromconn,clonetid);
927 AFSVolEndTrans(fromconn,clonetid,&rcode);
931 /* unlock VLDB entry */
932 ubik_Call (VL_ReleaseLock, cellHandle->vos, 0, afromvol, -1,
933 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
935 done: /* routine cleanup */
936 if (volName) free(volName);
937 #ifdef ENABLE_BUGFIX_1165
938 if (infop) free(infop);
940 if (fromconn) rx_ReleaseCachedConnection(fromconn);
941 if (toconn) rx_ReleaseCachedConnection(toconn);
949 /* Make a new backup of volume <avolid> on <aserver> and <apart>
950 * if one already exists, update it
954 afs_cell_handle_p cellHandle,
961 afs_status_t tst = 0, temp = 0;
962 afs_int32 ttid = 0, btid = 0;
965 char vname[VOLSER_MAXVOLNAME +1];
966 struct nvldbentry entry;
967 int vldblocked = 0, vldbmod = 0, backexists = 1;
968 struct rx_connection *aconn = UV_Bind(cellHandle, aserver,
972 /* the calls to VLDB will succeed only if avolid is a RW volume,
973 * since we are following the RW hash chain for searching */
974 if(!VLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
975 goto fail_UV_BackupVolume;
978 /* These operations require the VLDB be locked since it means the VLDB
979 * will change or the vldb is already locked.
981 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
982 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
983 (entry.volumeId[BACKVOL] == INVALID_BID)) {
984 /* no assigned backup volume id */
986 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, avolid, RWVOL,
989 goto fail_UV_BackupVolume;
993 /* Reread the vldb entry */
994 if (!VLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
995 goto fail_UV_BackupVolume;
999 if (!ISNAMEVALID(entry.name)) {
1000 tst = VOLSERBADNAME;
1001 goto fail_UV_BackupVolume;
1004 backupID = entry.volumeId[BACKVOL];
1005 if (backupID == INVALID_BID) {
1006 /* Get a backup volume id from the VLDB and update the vldb
1009 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, &backupID);
1011 goto fail_UV_BackupVolume;
1013 entry.volumeId[BACKVOL] = backupID;
1017 /* Test to see if the backup volume exists by trying to create
1018 * a transaction on the backup volume. We've assumed the backup exists.
1020 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1022 if (tst != VNOVOL) {
1023 goto fail_UV_BackupVolume;
1025 backexists = 0; /* backup volume does not exist */
1028 tst = AFSVolEndTrans(aconn, btid, &rcode);
1031 tst = (tst ? tst : rcode);
1032 goto fail_UV_BackupVolume;
1036 /* Now go ahead and try to clone the RW volume.
1037 * First start a transaction on the RW volume
1039 tst = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
1041 goto fail_UV_BackupVolume;
1044 /* Clone or reclone the volume, depending on whether the backup
1045 * volume exists or not
1048 tst = AFSVolReClone(aconn, ttid, backupID);
1050 goto fail_UV_BackupVolume;
1054 strcpy(vname, entry.name);
1055 strcat(vname,".backup");
1057 tst = AFSVolClone(aconn, ttid, 0,backupVolume, vname, &backupID);
1059 goto fail_UV_BackupVolume;
1063 /* End transaction on the RW volume */
1064 tst = AFSVolEndTrans(aconn, ttid, &rcode);
1067 tst = (tst ? tst : rcode);
1068 goto fail_UV_BackupVolume;
1071 /* Mork vldb as backup exists */
1072 if (!(entry.flags & BACK_EXISTS)) {
1073 entry.flags |= BACK_EXISTS;
1077 /* Now go back to the backup volume and bring it on line */
1078 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1080 goto fail_UV_BackupVolume;
1083 tst = AFSVolSetFlags(aconn, btid, 0);
1085 goto fail_UV_BackupVolume;
1088 tst = AFSVolEndTrans(aconn, btid, &rcode);
1091 tst = (tst ? tst : rcode);
1092 goto fail_UV_BackupVolume;
1096 /* Will update the vldb below */
1098 fail_UV_BackupVolume:
1101 temp = AFSVolEndTrans(aconn, ttid, &rcode);
1102 if (temp || rcode) {
1104 tst = (temp ? temp : rcode);
1109 temp = AFSVolEndTrans(aconn, btid, &rcode);
1110 if (temp || rcode) {
1112 tst = (temp ? temp : rcode);
1116 /* Now update the vldb - if modified */
1119 if(!VLDB_ReplaceEntry(cellHandle, avolid, RWVOL, &entry,
1120 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &temp)) {
1126 temp = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, avolid, RWVOL,
1127 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1137 rx_ReleaseCachedConnection(aconn);
1147 struct rx_connection *conn,
1152 afs_int32 acode, ccode, rcode, tid;
1153 ccode = rcode = tid = 0;
1155 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
1156 if (!acode) { /* It really was there */
1157 acode = AFSVolDeleteVolume(conn, tid);
1158 ccode = AFSVolEndTrans(conn, tid, &rcode);
1159 if (!ccode) ccode = rcode;
1165 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
1166 #define ERROREXIT(ec) { error = (ec); goto rfail; }
1168 #if 0 /* doesn't appear to be used, why compile it */
1169 static int CloneVol (
1170 afs_cell_handle_p cellHandle,
1171 struct rx_connection *conn,
1176 struct nvldbentry *entry,
1177 afs_int32 *vidCreateDate,
1181 afs_status_t tst = 0, etst = 0;
1182 afs_int32 rcode = 0, tid = 0;
1183 struct volser_status volstatus;
1186 /* Begin transaction on RW volume marking it busy (clients will wait) */
1187 tst = AFSVolTransCreate(conn, rwvid, part, ITBusy, &tid);
1192 /* Get the RO volume id. Allocate a new one if need to */
1193 *rovidp = entry->volumeId[ROVOL];
1194 if (*rovidp == INVALID_BID) {
1195 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, rovidp);
1200 entry->volumeId[ROVOL] = *rovidp;
1203 /* If we are creating the ro clone, what are we calling it.
1204 * Depends on whether its a temporary clone or not.
1207 strcpy(vname, entry->name);
1208 strcat(vname, ".readonly");
1210 strcpy(vname, "readonly-clone-temp"); /* Should be unique? */
1213 /* Create the new clone. If it exists, then reclone it */
1214 tst = AFSVolClone(conn, tid, 0, readonlyVolume, vname, rovidp);
1215 if (tst == VVOLEXISTS) {
1216 tst = AFSVolReClone(conn, tid, *rovidp);
1225 /* Bring the volume back on-line as soon as possible */
1227 afs_int32 fromtid=0;
1229 /* Now bring the RO clone on-line */
1230 tst = AFSVolTransCreate(conn, *rovidp, part, ITOffline, &fromtid);
1235 tst = AFSVolSetFlags(conn, fromtid, 0);
1240 tst = AFSVolEndTrans(conn, fromtid, &rcode);
1242 if (!tst) tst = rcode;
1248 /* Get the time the RW was created for return information */
1249 tst = AFSVolGetStatus(conn, tid, &volstatus);
1253 *vidCreateDate = volstatus.creationDate;
1259 tst = AFSVolEndTrans(conn, tid, &rcode);
1261 if (!tst) tst = rcode;
1275 /* Get a "transaction" on this replica. Create the volume
1276 * if necessary. Return the time from which a dump should
1277 * be made (0 if it's a new volume)
1279 static int GetTrans (
1280 afs_cell_handle_p cellHandle,
1281 struct nvldbentry *vldbEntryPtr,
1283 struct rx_connection **connPtr,
1284 afs_int32 *transPtr,
1289 afs_status_t tst = 0, etst = 0;
1291 struct volser_status tstatus;
1294 *connPtr = (struct rx_connection *)0;
1298 /* get connection to the replication site */
1299 *connPtr = UV_Bind(cellHandle, vldbEntryPtr->serverNumber[index],
1300 AFSCONF_VOLUMEPORT);
1302 /* server is down */
1307 volid = vldbEntryPtr->volumeId[ROVOL];
1309 tst = AFSVolTransCreate(*connPtr, volid,
1310 vldbEntryPtr->serverPartition[index],
1311 ITOffline, transPtr);
1314 /* If the volume does not exist, create it */
1315 if (!volid || tst) {
1318 if (volid && (tst != VNOVOL)){
1322 strcpy(volname, vldbEntryPtr->name);
1323 strcat(volname, ".readonly");
1325 tst = AFSVolCreateVolume(*connPtr,
1326 vldbEntryPtr->serverPartition[index],
1328 vldbEntryPtr->volumeId[RWVOL], &volid,
1333 vldbEntryPtr->volumeId[ROVOL] = volid;
1335 /* The following is a bit redundant, since create sets these flags by default */
1336 tst = AFSVolSetFlags(*connPtr, *transPtr,
1337 VTDeleteOnSalvage | VTOutOfService);
1343 /* Otherwise, the transaction did succeed, so get the creation date of the
1344 * latest RO volume on the replication site
1347 tst = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
1351 *timePtr = tstatus.creationDate-CLOCKSKEW;
1357 if ((rc == 0) && (*transPtr)) {
1358 etst = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
1360 if (!etst) etst = rcode;
1369 static int SimulateForwardMultiple(
1370 struct rx_connection *fromconn,
1376 manyResults *results)
1380 for (i=0; i<tr->manyDests_len; i++) {
1381 results->manyResults_val[i] =
1382 AFSVolForward(fromconn, fromtid, fromdate,
1383 &(tr->manyDests_val[i].server),
1384 tr->manyDests_val[i].trans, cookie);
1391 * Determine if a volume exists on a server and partition.
1392 * Try creating a transaction on the volume. If we can,
1393 * the volume exists, if not, then return the error code.
1394 * Some error codes mean the volume is unavailable but
1395 * still exists - so we catch these error codes.
1397 static afs_int32 VolumeExists(
1398 afs_cell_handle_p cellHandle,
1400 afs_int32 partition,
1405 afs_status_t tst = 0;
1406 struct rx_connection *conn=(struct rx_connection *)0;
1407 volEntries volumeInfo;
1409 conn = UV_Bind(cellHandle, server, AFSCONF_VOLUMEPORT);
1411 volumeInfo.volEntries_val = (volintInfo *)0;
1412 volumeInfo.volEntries_len = 0;
1413 tst = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
1414 if (volumeInfo.volEntries_val)
1415 free(volumeInfo.volEntries_val);
1416 if (tst == VOLSERILLEGAL_PARTITION) {
1419 rx_ReleaseCachedConnection(conn);
1429 /* release volume <afromvol> on <afromserver> <afrompart> to all the
1430 * sites if forceflag is 1.If its 0 complete the release if the previous
1431 * release aborted else start a new release */
1432 int UV_ReleaseVolume(
1433 afs_cell_handle_p cellHandle,
1435 afs_int32 afromserver,
1436 afs_int32 afrompart,
1441 afs_status_t tst = 0, etst = 0;
1445 afs_int32 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 bzero((char *)remembertime, sizeof(remembertime));
1472 bzero((char *)&results, sizeof(results));
1474 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, afromvol, RWVOL, VLOP_RELEASE);
1475 if ((tst) && (tst != VL_RERELEASE)) {
1476 goto fail_UV_ReleaseVolume;
1480 /* Get the vldb entry in readable format */
1481 if (!VLDB_GetEntryByID (cellHandle, afromvol, RWVOL, &entry, &tst)) {
1482 goto fail_UV_ReleaseVolume;
1485 if (!ISNAMEVALID(entry.name)) {
1486 tst = VOLSERBADNAME;
1487 goto fail_UV_ReleaseVolume;
1490 if (entry.volumeId[RWVOL] != afromvol) {
1491 tst = ADMVOSVOLUMERELEASERWONLY;
1492 goto fail_UV_ReleaseVolume;
1495 if (entry.nServers <= 1) {
1496 tst = ADMVOSVOLUMENOREPLICAS;
1497 goto fail_UV_ReleaseVolume;
1500 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10)) {
1501 tst = VOLSERBADNAME;
1502 goto fail_UV_ReleaseVolume;
1505 /* roclone is true if one of the RO volumes is on the same
1506 * partition as the RW volume. In this case, we make the RO volume
1507 * on the same partition a clone instead of a complete copy.
1510 roindex = Lp_ROMatch(cellHandle, &entry, afromserver, afrompart, &tst) - 1;
1511 roclone = ((roindex == -1) ? 0 : 1);
1512 rwindex = Lp_GetRwIndex(cellHandle, &entry, 0);
1515 goto fail_UV_ReleaseVolume;
1518 /* Make sure we have a RO volume id to work with */
1519 if (entry.volumeId[ROVOL] == INVALID_BID) {
1520 /* need to get a new RO volume id */
1521 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, &roVolId);
1523 goto fail_UV_ReleaseVolume;
1526 entry.volumeId[ROVOL] = roVolId;
1527 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1528 goto fail_UV_ReleaseVolume;
1532 /* Will we be completing a previously unfinished release. -force overrides */
1533 for (fullrelease=1, i=0; (fullrelease && (i<entry.nServers)); i++) {
1534 if (entry.serverFlags[i] & NEW_REPSITE)
1537 if (forceflag && !fullrelease)
1540 /* Determine which volume id to use and see if it exists */
1541 cloneVolId = ((fullrelease || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
1542 VolumeExists(cellHandle, afromserver, afrompart, cloneVolId, &tst);
1543 roexists = ((tst == ENODEV) ? 0 : 1);
1544 if (!roexists && !fullrelease)
1545 fullrelease = 1; /* Do a full release if RO clone does not exist */
1547 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
1550 goto fail_UV_ReleaseVolume;
1554 /* If the RO clone exists, then if the clone is a temporary
1555 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
1556 * (it was recently added), then also delete it. We do not
1557 * want to "reclone" a temporary RO clone.
1560 (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE)) ) {
1561 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1562 if (tst && (tst != VNOVOL)) {
1563 goto fail_UV_ReleaseVolume;
1568 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
1569 * write this entry out to the vlserver until after the first
1570 * RO volume is released (temp RO clones don't count).
1572 for (i=0; i<entry.nServers; i++) {
1573 entry.serverFlags[i] &= ~NEW_REPSITE;
1574 entry.serverFlags[i] |= RO_DONTUSE;
1576 entry.serverFlags[rwindex] |= NEW_REPSITE;
1577 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
1579 /* Begin transaction on RW and mark it busy while we clone it */
1580 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &clonetid);
1582 goto fail_UV_ReleaseVolume;
1585 /* Clone or reclone the volume */
1587 tst = AFSVolReClone(fromconn, clonetid, cloneVolId);
1589 goto fail_UV_ReleaseVolume;
1593 strcpy(vname, entry.name);
1594 strcat(vname, ".readonly");
1596 strcpy(vname, "readonly-clone-temp");
1598 tst = AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname, &cloneVolId);
1600 goto fail_UV_ReleaseVolume;
1604 /* Get the time the RW was created for future information */
1605 tst = AFSVolGetStatus(fromconn, clonetid, &volstatus);
1607 goto fail_UV_ReleaseVolume;
1609 rwcrdate = volstatus.creationDate;
1611 /* End the transaction on the RW volume */
1612 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1614 tst = (tst ? tst : rcode);
1616 goto fail_UV_ReleaseVolume;
1619 /* Remember clone volume ID in case we fail or are interrupted */
1620 entry.cloneId = cloneVolId;
1623 /* Bring the RO clone online - though not if it's a temporary clone */
1624 tst = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline, &onlinetid);
1626 goto fail_UV_ReleaseVolume;
1629 etst = AFSVolSetFlags(fromconn, onlinetid, 0);
1631 tst = AFSVolEndTrans(fromconn, onlinetid, &rcode);
1632 tst = (tst ? tst : rcode);
1634 goto fail_UV_ReleaseVolume;
1638 goto fail_UV_ReleaseVolume;
1641 /* Sleep so that a client searching for an online volume won't
1642 * find the clone offline and then the next RO offline while the
1643 * release brings the clone online and the next RO offline (race).
1644 * There is a fix in the 3.4 client that does not need this sleep
1645 * anymore, but we don't know what clients we have.
1647 if (entry.nServers > 2)
1650 /* Mark the RO clone in the VLDB as a good site (already released)*/
1651 entry.serverFlags[roindex] |= NEW_REPSITE;
1652 entry.serverFlags[roindex] &= ~RO_DONTUSE;
1653 entry.flags |= RO_EXISTS;
1657 /* Write out the VLDB entry only if the clone is not a temporary
1658 * clone. If we did this to a temporary clone then we would end
1659 * up marking all the ROs as "old release" making the ROs
1660 * temporarily unavailable.
1662 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1663 goto fail_UV_ReleaseVolume;
1668 /* Now we will release from the clone to the remaining RO replicas.
1669 * The first 2 ROs (counting the non-temporary RO clone) are released
1670 * individually: releasecount. This is to reduce the race condition
1671 * of clients trying to find an on-line RO volume. The remaining ROs
1672 * are released in parallel but no more than half the number of ROs
1673 * (rounded up) at a time: nservers.
1676 strcpy(vname, entry.name);
1677 strcat(vname, ".readonly");
1678 bzero(&cookie,sizeof(cookie));
1679 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
1680 cookie.type = ROVOL;
1681 cookie.parent = entry.volumeId[RWVOL];
1684 nservers = entry.nServers/2; /* how many to do at once, excluding clone */
1685 replicas = (struct replica *) malloc (sizeof(struct replica)*nservers+1);
1686 times = (struct release *) malloc (sizeof(struct release)*nservers+1);
1687 toconns = (struct rx_connection **) malloc (sizeof(struct rx_connection *)*nservers+1);
1688 results.manyResults_val = (afs_int32 *) malloc (sizeof(afs_int32)*nservers+1);
1689 if ( !replicas || !times || !! !results.manyResults_val || !toconns ) {
1691 goto fail_UV_ReleaseVolume;
1694 bzero (replicas, (sizeof(struct replica)*nservers+1));
1695 bzero (times, (sizeof(struct release)*nservers+1));
1696 bzero (toconns, (sizeof(struct rx_connection *)*nservers+1));
1697 bzero (results.manyResults_val, (sizeof(afs_int32)*nservers+1));
1699 /* Create a transaction on the cloned volume */
1700 tst = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
1702 goto fail_UV_ReleaseVolume;
1705 /* For each index in the VLDB */
1706 for (vldbindex=0; vldbindex<entry.nServers; ) {
1708 /* Get a transaction on the replicas. Pick replacas which have an old release. */
1709 for (volcount=0; ((volcount<nservers) && (vldbindex<entry.nServers)); vldbindex++) {
1710 /* The first two RO volumes will be released individually.
1711 * The rest are then released in parallel. This is a hack
1712 * for clients not recognizing right away when a RO volume
1713 * comes back on-line.
1715 if ((volcount == 1) && (releasecount < 2))
1718 if (vldbindex == roindex) continue; /* the clone */
1719 if ( (entry.serverFlags[vldbindex] & NEW_REPSITE) &&
1720 !(entry.serverFlags[vldbindex] & RO_DONTUSE) ) continue;
1721 if (!(entry.serverFlags[vldbindex] & ITSROVOL)) continue; /* not a RO vol */
1724 /* Get a Transaction on this replica. Get a new connection if
1725 * necessary. Create the volume if necessary. Return the
1726 * time from which the dump should be made (0 if it's a new
1727 * volume). Each volume might have a different time.
1729 replicas[volcount].server.destHost = entry.serverNumber[vldbindex];
1730 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
1731 replicas[volcount].server.destSSID = 1;
1732 times[volcount].vldbEntryIndex = vldbindex;
1734 if(!GetTrans(cellHandle, &entry, vldbindex, &(toconns[volcount]),
1735 &(replicas[volcount].trans), &(times[volcount].time),
1740 /* Thisdate is the date from which we want to pick up all changes */
1741 if (forceflag || !fullrelease || (rwcrdate > times[volcount].time)) {
1742 /* If the forceflag is set, then we want to do a full dump.
1743 * If it's not a full release, we can't be sure that the creation
1744 * date is good (so we also do a full dump).
1745 * If the RW volume was replaced (its creation date is newer than
1746 * the last release), then we can't be sure what has changed (so
1747 * we do a full dump).
1750 } else if (remembertime[vldbindex].validtime) {
1751 /* Trans was prev ended. Use the time from the prev trans
1752 * because, prev trans may have created the volume. In which
1753 * case time[volcount].time would be now instead of 0.
1755 thisdate = (remembertime[vldbindex].time < times[volcount].time) ?
1756 remembertime[vldbindex].time : times[volcount].time;
1758 thisdate = times[volcount].time;
1760 remembertime[vldbindex].validtime = 1;
1761 remembertime[vldbindex].time = thisdate;
1763 if (volcount == 0) {
1764 fromdate = thisdate;
1766 /* Include this volume if it is within 15 minutes of the earliest */
1767 if (((fromdate>thisdate)?(fromdate-thisdate):(thisdate-fromdate)) > 900) {
1768 AFSVolEndTrans(toconns[volcount], replicas[volcount].trans, &rcode);
1769 replicas[volcount].trans = 0;
1772 if (thisdate < fromdate)
1773 fromdate = thisdate;
1777 if (!volcount) continue;
1779 /* Release the ones we have collected */
1780 tr.manyDests_val = &(replicas[0]);
1781 tr.manyDests_len = results.manyResults_len = volcount;
1782 tst = AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr, 0/*spare*/, &cookie, &results);
1783 if (tst == RXGEN_OPCODE) { /* RPC Interface Mismatch */
1784 tst = SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr, 0/*spare*/, &cookie, &results);
1789 goto fail_UV_ReleaseVolume;
1791 for (m=0; m<volcount; m++) {
1792 if (results.manyResults_val[m]) {
1796 tst = AFSVolSetIdsTypes(toconns[m], replicas[m].trans,
1797 vname, ROVOL, entry.volumeId[RWVOL], 0, 0);
1802 /* have to clear dest. flags to ensure new vol goes online:
1803 * because the restore (forwarded) operation copied
1804 * the V_inService(=0) flag over to the destination.
1806 tst = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
1811 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
1812 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
1813 entry.flags |= RO_EXISTS;
1818 /* End the transactions and destroy the connections */
1819 for (s=0; s<volcount; s++) {
1820 if (replicas[s].trans)
1821 tst = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
1822 replicas[s].trans = 0;
1823 if (!tst) tst = rcode;
1825 if ((s == 0) || (tst != ENOENT)) {
1827 if (times[s].vldbEntryIndex < vldbindex)
1828 vldbindex = times[s].vldbEntryIndex;
1833 rx_ReleaseCachedConnection(toconns[s]);
1837 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1838 goto fail_UV_ReleaseVolume;
1840 } /* for each index in the vldb */
1842 /* End the transaction on the cloned volume */
1843 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1846 /* Figure out if any volume were not released and say so */
1847 for (failure=0, i=0; i<entry.nServers; i++) {
1848 if (!(entry.serverFlags[i] & NEW_REPSITE))
1852 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry,
1853 LOCKREL_TIMESTAMP, &tst)) {
1854 goto fail_UV_ReleaseVolume;
1857 tst = VOLSERBADRELEASE;
1858 goto fail_UV_ReleaseVolume;
1861 /* All the ROs were release successfully. Remove the temporary clone */
1863 tst = DelVol (fromconn, cloneVolId, afrompart, ITOffline);
1865 goto fail_UV_ReleaseVolume;
1870 for (i=0; i<entry.nServers; i++)
1871 entry.serverFlags[i] &= ~NEW_REPSITE;
1873 /* Update the VLDB */
1874 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry,
1875 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP,
1877 goto fail_UV_ReleaseVolume;
1881 fail_UV_ReleaseVolume:
1884 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1891 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1897 for (i=0; i<nservers; i++) {
1898 if (replicas && replicas[i].trans) {
1899 tst = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
1900 replicas[i].trans = 0;
1905 if (toconns && toconns[i]) {
1906 rx_ReleaseCachedConnection(toconns[i]);
1911 tst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, afromvol, RWVOL,
1912 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
1918 if (fromconn) rx_ReleaseCachedConnection(fromconn);
1919 if (results.manyResults_val) free (results.manyResults_val);
1920 if (replicas) free (replicas);
1921 if (toconns) free (toconns);
1922 if (times) free (times);
1930 static int ReceiveFile(
1932 register struct rx_call *call,
1933 register struct stat *status)
1935 register char *buffer = (char*) 0;
1936 register int blockSize;
1937 afs_int32 bytesread, nbytes, bytesleft, w;
1939 afs_int32 error = 0;
1946 struct statfs tstatfs;
1948 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
1950 fstatfs(fd, &tstatfs);
1951 blockSize = tstatfs.f_bsize;
1953 blockSize = status->st_blksize;
1961 buffer = (char *)malloc(blockSize);
1966 while(!error && (bytesread > 0)) {
1967 bytesread = rx_Read(call, buffer, nbytes);
1968 bytesleft = bytesread;
1969 while (!error && (bytesleft > 0)) {
1972 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
1973 select(fd+1, 0, &out, 0, 0); /* don't timeout if write bl
1976 w = write(fd, &buffer[bytesread-bytesleft], bytesleft);
1978 error = ADMVOSDUMPFILEWRITEFAIL;
1985 if (buffer) free(buffer);
1987 if (!error) fstat(fd, status);
1992 static afs_int32 DumpFunction(
1993 struct rx_call *call,
1994 const char *filename)
1998 afs_int32 error,code;
2003 fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY, 0666);
2004 if (fd < 0 || fstat(fd, &status) < 0){
2005 error = VOLSERBADOP;
2008 code = ReceiveFile(fd,call,&status);
2014 if (fd >= 0) code = close(fd);
2017 if(!error) error = code;
2023 /*dump the volume <afromvol> on <afromserver> and
2024 * <afrompart> to <afilename> starting from <fromdate>.
2025 * DumpFunction does the real work behind the scenes after
2026 * extracting parameters from the rock */
2028 afs_cell_handle_p cellHandle,
2030 afs_int32 afromserver,
2031 afs_int32 afrompart,
2033 const char *filename,
2037 afs_status_t tst = 0;
2038 afs_status_t etst = 0;
2039 struct rx_connection *fromconn;
2040 struct rx_call *fromcall;
2045 struct nvldbentry entry;
2052 fromcall = (struct rx_call *)0;
2053 fromconn = (struct rx_connection *)0;
2055 fromcall = (struct rx_call *)0;
2058 if (!VLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
2059 goto fail_UV_DumpVolume;
2062 /* get connections to the servers */
2063 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
2064 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2066 goto fail_UV_DumpVolume;
2068 fromcall = rx_NewCall(fromconn);
2069 tst = StartAFSVolDump(fromcall,fromtid, fromdate);
2071 goto fail_UV_DumpVolume;
2073 if ((tst = DumpFunction(fromcall,filename))) {
2074 goto fail_UV_DumpVolume;
2076 tst = rx_EndCall(fromcall,rxError);
2077 fromcall = (struct rx_call *)0;
2079 goto fail_UV_DumpVolume;
2081 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2083 if (!tst) tst = rcode;
2085 goto fail_UV_DumpVolume;
2092 etst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, afromvol, -1, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2094 if(!tst) tst = etst;
2099 etst = rx_EndCall(fromcall,rxError);
2101 if(!tst) tst = etst;
2106 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2107 if(!tst) tst = etst;
2109 if(!tst) tst = rcode;
2114 rx_ReleaseCachedConnection(fromconn);
2125 register struct rx_call *call,
2126 register struct stat *status)
2128 char *buffer = (char*) 0;
2131 afs_int32 error = 0;
2140 struct statfs tstatfs;
2142 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2144 fstatfs(fd, &tstatfs);
2145 blockSize = tstatfs.f_bsize;
2147 blockSize = status->st_blksize;
2154 buffer = (char *)malloc(blockSize);
2159 while (!error && !done) {
2162 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2163 select(fd+1, &in, 0, 0, 0); /* don't timeout if read blocks */
2165 nbytes = read(fd, buffer, blockSize);
2167 error = ADMVOSRESTOREFILEREADFAIL;
2174 if (rx_Write(call, buffer, nbytes) != nbytes){
2175 error = ADMVOSRESTOREFILEWRITEFAIL;
2179 if (buffer) free(buffer);
2183 static afs_int32 WriteData(
2184 struct rx_call *call,
2185 const char *filename)
2189 afs_int32 error,code;
2194 fd = open(filename,0);
2195 if (fd < 0 || fstat(fd, &status) < 0){
2196 fprintf(STDERR,"Could access file '%s'\n",filename);
2197 error = ADMVOSRESTOREFILEOPENFAIL;
2198 goto fail_WriteData;
2200 code = SendFile(fd,call,&status);
2203 goto fail_WriteData;
2208 if(fd >= 0) code = close(fd);
2211 if(!error) error = ADMVOSRESTOREFILECLOSEFAIL;
2217 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
2218 * the dump file <afilename>. WriteData does all the real work
2219 * after extracting params from the rock
2221 int UV_RestoreVolume(
2222 afs_cell_handle_p cellHandle,
2226 const char *tovolname,
2228 const char *dumpFile,
2232 afs_status_t tst = 0;
2233 afs_status_t etst = 0;
2234 struct rx_connection *toconn,*tempconn;
2235 struct rx_call *tocall;
2236 afs_int32 totid, rcode;
2237 afs_int32 rxError = 0;
2238 struct volser_status tstatus;
2243 struct nvldbentry entry;
2246 struct restoreCookie cookie;
2248 afs_int32 newDate, volflag;
2252 bzero(&cookie,sizeof(cookie));
2257 tocall = (struct rx_call *)0;
2258 toconn = (struct rx_connection *)0;
2259 tempconn = (struct rx_connection *)0;
2264 toconn = UV_Bind(cellHandle, toserver, AFSCONF_VOLUMEPORT);
2265 if(pvolid == 0) {/*alot a new id if needed */
2266 VLDB_GetEntryByName(cellHandle, tovolname, &entry, &tst);
2267 if(tst == VL_NOENT) {
2268 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, &pvolid);
2270 goto fail_UV_RestoreVolume;
2275 pvolid = entry.volumeId[RWVOL];
2280 * at this point we have a volume id to use/reuse for the
2281 * volume to be restored
2283 if(strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
2284 tst = ADMVOSRESTOREVOLUMENAMETOOBIG;
2285 goto fail_UV_RestoreVolume;
2288 if (!vos_PartitionIdToName(topart, partName, &tst)) {
2289 goto fail_UV_RestoreVolume;
2291 /*what should the volume be restored as ? rw or ro or bk ?
2292 right now the default is rw always */
2293 tst = AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,&pvolid, &totid);
2295 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
2296 tst = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2298 goto fail_UV_RestoreVolume;
2300 tst = AFSVolSetFlags(toconn, totid, VTDeleteOnSalvage | VTOutOfService);
2302 goto fail_UV_RestoreVolume;
2304 tst = AFSVolDeleteVolume(toconn,totid);
2306 goto fail_UV_RestoreVolume;
2308 tst = AFSVolEndTrans(toconn, totid, &rcode);
2310 if (!tst) tst = rcode;
2312 goto fail_UV_RestoreVolume;
2314 tst = AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,&pvolid, &totid);
2316 goto fail_UV_RestoreVolume;}
2318 tst = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2320 goto fail_UV_RestoreVolume;
2324 cookie.parent = pvolid;
2325 cookie.type = RWVOL;
2327 strncpy(cookie.name,tovolname,VOLSER_OLDMAXVOLNAME);
2329 tocall = rx_NewCall(toconn);
2330 tst = StartAFSVolRestore(tocall,totid, 1,&cookie);
2332 goto fail_UV_RestoreVolume;
2334 tst = WriteData(tocall, dumpFile);
2336 goto fail_UV_RestoreVolume;
2338 tst = rx_EndCall(tocall,rxError);
2339 tocall = (struct rx_call *) 0;
2341 goto fail_UV_RestoreVolume;
2343 tst = AFSVolGetStatus(toconn,totid, &tstatus);
2345 goto fail_UV_RestoreVolume;
2347 tst = AFSVolSetIdsTypes(toconn,totid, tovolname, RWVOL, pvolid,0,0);
2349 goto fail_UV_RestoreVolume;
2352 tst = AFSVolSetDate(toconn,totid, newDate);
2354 goto fail_UV_RestoreVolume;
2357 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2358 tst = AFSVolSetFlags(toconn, totid, volflag);
2360 goto fail_UV_RestoreVolume;
2363 /* It isn't handled right in fail_UV_RestoreVolume */
2364 tst = AFSVolEndTrans(toconn, totid, &rcode);
2366 if(!tst) tst = rcode;
2368 goto fail_UV_RestoreVolume;
2372 if (success && (!reuseID || (flags & RV_FULLRST))) {
2373 /* Volume was restored on the file server, update the
2374 * VLDB to reflect the change.
2376 VLDB_GetEntryByID(cellHandle, pvolid, RWVOL, &entry, &tst);
2377 if(tst && tst != VL_NOENT && tst != VL_ENTDELETED) {
2378 goto fail_UV_RestoreVolume;
2380 if(tst == VL_NOENT) { /* it doesnot exist already */
2381 /*make the vldb return this indication specifically*/
2382 strcpy(entry.name, tovolname);
2384 entry.serverNumber[0] = toserver;/*should be indirect */
2385 entry.serverPartition[0] = topart;
2386 entry.serverFlags[0] = ITSRWVOL;
2387 entry.flags = RW_EXISTS;
2388 if(tstatus.cloneID != 0){
2389 entry.volumeId[ROVOL] = tstatus.cloneID;/*this should come from status info on the volume if non zero */
2392 entry.volumeId[ROVOL] = INVALID_BID;
2393 entry.volumeId[RWVOL] = pvolid;
2395 if(tstatus.backupID != 0){
2396 entry.volumeId[BACKVOL] = tstatus.backupID;
2397 /*this should come from status info on the volume if non zero */
2400 entry.volumeId[BACKVOL] = INVALID_BID;
2401 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
2402 goto fail_UV_RestoreVolume;
2406 else { /*update the existing entry */
2407 tst = ubik_Call(VL_SetLock,cellHandle->vos, 0, pvolid, RWVOL, VLOP_RESTORE);
2409 goto fail_UV_RestoreVolume;
2412 strcpy(entry.name, tovolname);
2414 /* Update the vlentry with the new information */
2415 index = Lp_GetRwIndex(cellHandle, &entry, 0);
2417 /* Add the rw site for the volume being restored */
2418 entry.serverNumber[entry.nServers] = toserver;
2419 entry.serverPartition[entry.nServers] = topart;
2420 entry.serverFlags[entry.nServers] = ITSRWVOL;
2423 /* This volume should be deleted on the old site
2424 * if its different from new site.
2426 VLDB_IsSameAddrs(cellHandle, toserver, entry.serverNumber[index], &same, &tst);
2427 if ( (!tst && !same) || (entry.serverPartition[index] != topart) ) {
2428 tempconn = UV_Bind(cellHandle, entry.serverNumber[index], AFSCONF_VOLUMEPORT);
2429 tst = AFSVolTransCreate(tempconn, pvolid, entry.serverPartition[index], ITOffline, &temptid);
2431 tst = AFSVolSetFlags(tempconn, temptid, VTDeleteOnSalvage | VTOutOfService);
2433 goto fail_UV_RestoreVolume;
2435 tst = AFSVolDeleteVolume(tempconn,temptid);
2437 goto fail_UV_RestoreVolume;
2439 tst = AFSVolEndTrans(tempconn, temptid, &rcode);
2441 if(!tst) tst = rcode;
2443 goto fail_UV_RestoreVolume;
2445 vos_PartitionIdToName(entry.serverPartition[index],partName, &tst);
2448 entry.serverNumber[index] = toserver;
2449 entry.serverPartition[index] = topart;
2452 entry.flags |= RW_EXISTS;
2453 if (!VLDB_ReplaceEntry(cellHandle, pvolid, RWVOL, &entry,
2454 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2455 goto fail_UV_RestoreVolume;
2462 fail_UV_RestoreVolume:
2465 etst = rx_EndCall(tocall, rxError);
2466 if (!tst) tst = etst;
2469 etst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, pvolid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2471 if(!tst) tst = etst;
2475 etst = AFSVolEndTrans(toconn, totid, &rcode);
2476 if(!etst) etst = rcode;
2478 if(!tst) tst = etst;
2482 etst = AFSVolEndTrans(toconn, temptid, &rcode);
2483 if(!etst) etst = rcode;
2485 if(!tst) tst = etst;
2489 if(tempconn) rx_ReleaseCachedConnection(tempconn);
2490 if(toconn) rx_ReleaseCachedConnection(toconn);
2498 /*adds <server> and <part> as a readonly replication site for <volid>
2501 afs_cell_handle_p cellHandle,
2508 afs_status_t tst = 0;
2509 int j, nro=0, islocked=0;
2510 struct nvldbentry entry;
2513 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,volid,RWVOL, VLOP_ADDSITE);
2515 goto fail_UV_AddSite;
2519 if (!VLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2520 goto fail_UV_AddSite;
2522 if (!ISNAMEVALID(entry.name)){
2524 goto fail_UV_AddSite;
2527 /* See if it's too many entries */
2528 if (entry.nServers >= NMAXNSERVERS){
2530 goto fail_UV_AddSite;
2533 /* See if it's on the same server */
2534 for (j=0; j < entry.nServers; j++) {
2535 if (entry.serverFlags[j] & ITSROVOL) {
2537 if (!VLDB_IsSameAddrs(cellHandle, server, entry.serverNumber[j], &same, &tst)) {
2538 goto fail_UV_AddSite;
2542 goto fail_UV_AddSite;
2547 /* See if it's too many RO sites - leave one for the RW */
2548 if (nro >= NMAXNSERVERS-1){
2550 goto fail_UV_AddSite;
2553 entry.serverNumber[entry.nServers] = server;
2554 entry.serverPartition[entry.nServers] = part;
2555 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
2558 if (!VLDB_ReplaceEntry(cellHandle, volid, RWVOL, &entry,
2559 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP,
2561 goto fail_UV_AddSite;
2569 tst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, volid, RWVOL,
2570 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2579 /*removes <server> <part> as read only site for <volid> from the vldb */
2581 afs_cell_handle_p cellHandle,
2588 afs_status_t tst = 0;
2589 struct nvldbentry entry;
2592 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,volid, RWVOL, VLOP_ADDSITE);
2594 goto fail_UV_RemoveSite;
2598 if (!VLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2599 goto fail_UV_RemoveSite;
2601 if (!Lp_ROMatch(cellHandle, &entry, server, part, &tst)) {
2602 /*this site doesnot exist */
2603 goto fail_UV_RemoveSite;
2605 else { /*remove the rep site */
2606 Lp_SetROValue(cellHandle, &entry, server, part, 0, 0);
2608 if((entry.nServers == 1) && (entry.flags & RW_EXISTS))
2609 entry.flags &= ~RO_EXISTS;
2610 if(entry.nServers < 1) { /*this is the last ref */
2611 tst = ubik_Call(VL_DeleteEntry, cellHandle->vos, 0,volid, ROVOL);
2613 goto fail_UV_RemoveSite;
2616 if (!VLDB_ReplaceEntry(cellHandle, volid, RWVOL, &entry,
2617 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
2619 goto fail_UV_RemoveSite;
2628 t = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2640 /*list all the partitions on <aserver> */
2641 int UV_ListPartitions(
2642 struct rx_connection *server,
2643 struct partList *ptrPartList,
2648 afs_status_t tst = 0;
2649 struct pIDs partIds;
2650 struct partEntries partEnts;
2651 register int i, j=0;
2655 partEnts.partEntries_len = 0;
2656 partEnts.partEntries_val = (afs_int32 *)0;
2657 /* this is available only on new servers */
2658 tst = AFSVolXListPartitions(server, &partEnts);
2660 /* next, try old interface */
2661 if (tst == RXGEN_OPCODE)
2663 for(i = 0; i < 26; i++)
2664 partIds.partIds[i] = -1;
2665 tst = AFSVolListPartitions(server, &partIds);
2667 for (i = 0;i < 26; i++) {
2668 if((partIds.partIds[i]) != -1) {
2669 ptrPartList->partId[j] = partIds.partIds[i];
2670 ptrPartList->partFlags[j] = PARTVALID;
2673 ptrPartList->partFlags[i] = 0;
2677 goto fail_UV_ListPartitions;
2682 *cntp = partEnts.partEntries_len;
2683 if (*cntp > VOLMAXPARTS) {
2684 *cntp = VOLMAXPARTS;
2686 for (i = 0;i < *cntp; i++) {
2687 ptrPartList->partId[i] = partEnts.partEntries_val[i];
2688 ptrPartList->partFlags[i] = PARTVALID;
2690 free(partEnts.partEntries_val);
2692 goto fail_UV_ListPartitions;
2696 fail_UV_ListPartitions:
2704 /*------------------------------------------------------------------------
2705 * EXPORTED UV_XListVolumes
2708 * List the extended information for all the volumes on a particular
2709 * File Server and partition. We may either return the volume's ID
2710 * or all of its extended information.
2713 * a_serverID : Address of the File Server for which we want
2714 * extended volume info.
2715 * a_partID : Partition for which we want the extended
2717 * a_all : If non-zero, fetch ALL the volume info,
2718 * otherwise just the volume ID.
2719 * a_resultPP : Ptr to the address of the area containing
2720 * the returned volume info.
2721 * a_numEntsInResultP : Ptr for the value we set for the number of
2726 * Otherise, the return value of AFSVolXListVolumes.
2729 * This routine is closely related to UV_ListVolumes, which returns
2730 * only the standard level of detail on AFS volumes. It is a
2731 * heavyweight operation, zipping through all the volume entries for
2732 * a given server/partition.
2736 *------------------------------------------------------------------------*/
2738 int UV_XListVolumes(
2739 struct rx_connection *server,
2742 struct volintXInfo **a_resultPP,
2743 afs_int32 *a_numEntsInResultP,
2747 afs_status_t tst = 0;
2749 volXEntries volumeXInfo; /*Area for returned extended vol info*/
2752 * Set up our error code and the area for returned extended volume info.
2753 * We set the val field to a null pointer as a hint for the stub to
2756 *a_numEntsInResultP = 0;
2757 *a_resultPP = (volintXInfo *)0;
2758 volumeXInfo.volXEntries_val = (volintXInfo *)0;
2759 volumeXInfo.volXEntries_len = 0;
2762 * Bind to the Volume Server port on the File Server machine in question,
2765 tst = AFSVolXListVolumes(server, a_partID, a_all, &volumeXInfo);
2767 goto fail_UV_XListVolumes;
2770 * We got the info; pull out the pointer to where the results lie
2771 * and how many entries are there.
2773 *a_resultPP = volumeXInfo.volXEntries_val;
2774 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
2778 fail_UV_XListVolumes:
2786 /*------------------------------------------------------------------------
2787 * EXPORTED UV_XListOneVolume
2790 * List the extended information for a volume on a particular File
2791 * Server and partition.
2794 * server : a handle to the server where the volume resides.
2795 * a_partID : Partition for which we want the extended
2797 * a_volID : Volume ID for which we want the info.
2798 * a_resultPP : Ptr to the address of the area containing
2799 * the returned volume info.
2803 * Otherise, the return value of AFSVolXListOneVolume.
2806 * This routine is closely related to UV_ListOneVolume, which returns
2807 * only the standard level of detail on the chosen AFS volume.
2811 *------------------------------------------------------------------------*/
2813 int UV_XListOneVolume(
2814 struct rx_connection *server,
2817 struct volintXInfo **a_resultPP,
2821 afs_status_t tst = 0;
2822 volXEntries volumeXInfo; /*Area for returned info*/
2825 * Set the area we're in which we are returning
2826 * the info. Setting the val field to a null pointer tells the stub
2827 * to allocate space for us.
2829 *a_resultPP = (volintXInfo *)0;
2830 volumeXInfo.volXEntries_val = (volintXInfo *)0;
2831 volumeXInfo.volXEntries_len = 0;
2833 tst = AFSVolXListOneVolume(server, a_partID, a_volID, &volumeXInfo);
2836 goto fail_UV_XListOneVolume;
2840 * We got the info; pull out the pointer to where the results lie.
2842 *a_resultPP = volumeXInfo.volXEntries_val;
2846 fail_UV_XListOneVolume:
2853 } /*UV_XListOneVolume*/
2855 /*sync vldb with all the entries on <myQueue> on <aserver> and <apart>*/
2856 static afs_int32 ProcessEntries(
2857 afs_cell_handle_p cellHandle,
2858 struct qHead *myQueue,
2859 struct rx_connection *server,
2864 int success, temp,temp1,temp2;
2865 afs_int32 vcode, maxVolid = 0;
2866 struct nvldbentry entry;
2867 int noError = 1, error, same;
2868 int totalC,totalU,totalCE,totalUE,totalG;
2870 int aserver = ntohl(rx_HostOf(rx_PeerOf(server)));
2873 totalC = totalU = totalCE = totalUE = totalG = 0;
2876 /* get the next available id's from the vldb server */
2877 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, 0, &maxVolid);
2881 totalG = myQueue->count;
2882 if(totalG == 0) return 0;
2884 Lp_QEnumerate(myQueue, &success, &elem, 0);
2885 if (!success) break;
2888 if(!elem.isValid[RWVOL] && !elem.isValid[ROVOL] && !elem.isValid[BACKVOL]){ /*something is wrong with elem */
2892 if(maxVolid <= elem.ids[RWVOL]){
2894 temp2 = elem.ids[RWVOL] - maxVolid + 1 ;
2896 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, temp2, &maxVolid);
2901 if(maxVolid <= elem.ids[ROVOL]){
2904 temp2 = elem.ids[ROVOL] - maxVolid + 1;
2906 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, temp2, &maxVolid);
2910 if(maxVolid <= elem.ids[BACKVOL]){
2912 temp2 = elem.ids[BACKVOL] - temp1 + 1;
2914 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, temp2, &maxVolid);
2918 VLDB_GetEntryByID(cellHandle, elem.ids[RWVOL], RWVOL, &entry, &tst);
2919 if(tst && (tst != VL_NOENT)){
2923 else if(tst && (tst == VL_NOENT)) { /*entry doesnot exist */
2924 /*set up a vldb entry for elem */
2925 bzero(&entry, sizeof(entry));
2926 strncpy(entry.name,elem.name,VOLSER_OLDMAXVOLNAME);
2927 if(elem.isValid[RWVOL]) { /*rw exists */
2928 entry.flags |= RW_EXISTS;
2929 entry.serverFlags[entry.nServers] = ITSRWVOL;
2930 entry.serverNumber[entry.nServers] = aserver;
2931 entry.serverPartition[entry.nServers] = apart;
2932 entry.nServers += 1;
2933 entry.volumeId[RWVOL] = elem.ids[RWVOL];
2934 entry.volumeId[ROVOL] = elem.ids[ROVOL];
2935 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
2937 if(elem.isValid[ROVOL]) { /*ro volume exists */
2938 entry.flags |= RO_EXISTS;
2939 entry.serverFlags[entry.nServers] = ITSROVOL;
2940 entry.serverNumber[entry.nServers] = aserver;
2941 entry.serverPartition[entry.nServers] = apart;
2942 entry.nServers += 1;
2943 entry.volumeId[RWVOL] = elem.ids[RWVOL];
2944 entry.volumeId[ROVOL] = elem.ids[ROVOL];
2947 if(elem.isValid[BACKVOL]) { /*backup volume exists */
2948 entry.flags |= BACK_EXISTS;
2949 if(! (entry.flags & RW_EXISTS)) {/*this helps to check for a stray backup if parent moves */
2950 entry.serverFlags[entry.nServers] = ITSRWVOL;
2951 entry.serverNumber[entry.nServers] = aserver;
2952 entry.serverPartition[entry.nServers] = apart;
2953 entry.nServers += 1;
2956 entry.volumeId[RWVOL] = elem.ids[RWVOL];
2957 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
2960 VLDB_CreateEntry(cellHandle, &entry, &tst);
2968 else { /* Update the existing entry */
2969 strncpy(entry.name,elem.name,VOLSER_OLDMAXVOLNAME); /*the name Could have changed */
2971 if (elem.isValid[RWVOL]) { /* A RW volume */
2972 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
2974 /* A RW index is not found in the VLDB entry - will add it */
2976 entry.flags |= RW_EXISTS;
2977 entry.serverNumber[entry.nServers] = aserver;
2978 entry.serverPartition[entry.nServers] = apart;
2979 entry.serverFlags[entry.nServers] = ITSRWVOL;
2982 /* A RW index is found in the VLDB entry.
2983 * Verify that the volume location matches the VLDB location.
2984 * Fix the VLDB entry if it is not correct.
2987 error = VLDB_IsSameAddrs(cellHandle, aserver, entry.serverNumber[temp], &same, &tst);
2991 if (!same || (apart != entry.serverPartition[temp])) {
2992 /* VLDB says volume is in another place. Fix the VLDB entry */
2993 entry.serverNumber[temp] = aserver;
2994 entry.serverPartition[temp] = apart;
2997 entry.flags |= RW_EXISTS;
2999 if ((elem.ids[BACKVOL] != 0) && elem.isValid[BACKVOL])
3000 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3001 if ((elem.ids[ROVOL] != 0) && elem.isValid[ROVOL])
3002 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3005 if (elem.isValid[ROVOL]) {
3006 /*tackle a ro volume */
3008 if(!Lp_ROMatch(cellHandle, &entry, aserver, apart, 0)){
3010 if(elem.ids[ROVOL] > entry.volumeId[ROVOL]) {
3011 /*there is a conflict of ids, keep the later volume */
3012 /*delete all the ro volumes listed in vldb entry since they
3015 int j,count, rwsite;
3018 count = entry.nServers;
3020 for(j = 0 ; j < count; j++){
3021 if(entry.serverFlags[j] & ITSROVOL){
3023 /*delete the site */
3024 entry.serverNumber[j] = 0;
3025 entry.serverPartition[j] = 0;
3026 entry.serverFlags[j] = 0;
3029 else if( entry.serverFlags[j] & ITSRWVOL)
3034 entry.serverNumber[entry.nServers] = entry.serverNumber[rwsite];
3035 entry.serverPartition[entry.nServers] = entry.serverPartition[rwsite];
3036 entry.serverFlags[entry.nServers] = entry.serverFlags[rwsite];
3039 entry.serverNumber[entry.nServers] = aserver;
3040 entry.serverPartition[entry.nServers] = apart;
3041 entry.serverFlags[entry.nServers] = ITSROVOL;
3043 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3044 entry.flags |= RO_EXISTS;
3047 else if (elem.ids[ROVOL] < entry.volumeId[ROVOL] ){
3048 if(!(entry.flags & RO_EXISTS)) {
3049 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3050 entry.serverNumber[entry.nServers] = aserver;
3051 entry.serverPartition[entry.nServers] = apart;
3052 entry.serverFlags[entry.nServers] = ITSROVOL;
3054 entry.flags |= RO_EXISTS;
3059 else if (elem.ids[ROVOL] == entry.volumeId[ROVOL]){
3060 entry.serverNumber[entry.nServers] = aserver;
3061 entry.serverPartition[entry.nServers] = apart;
3062 entry.serverFlags[entry.nServers] = ITSROVOL;
3064 entry.flags |= RO_EXISTS;
3065 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3068 if(entry.volumeId[ROVOL] == INVALID_BID)
3069 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3072 if (elem.isValid[BACKVOL]) {
3073 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3074 if(temp != -1) { /*check if existing backup site matches with the given arguments */
3075 error = VLDB_IsSameAddrs(cellHandle, aserver, entry.serverNumber[temp], &same, &tst);
3081 /*tackle the backup volume */
3082 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3083 entry.flags |= BACK_EXISTS;
3085 if(entry.volumeId[BACKVOL] == INVALID_BID)
3086 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3089 VLDB_ReplaceEntry(cellHandle, elem.ids[RWVOL], RWVOL,
3091 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP,
3097 vcode = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0,
3098 elem.ids[RWVOL], RWVOL,
3099 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3104 } /* else update the existing entry */
3106 } /* End of while(1) */
3108 if(noError) return 0;
3109 else return VOLSERBADOP;
3112 /*synchronise vldb with the file server <aserver> and <apart>(if flags=1).
3113 *else synchronise with all the valid partitions on <aserver>
3116 afs_cell_handle_p cellHandle,
3117 struct rx_connection *server,
3124 afs_status_t tst = 0;
3127 volEntries volumeInfo;
3129 struct qHead myQueue;
3130 struct partList PartList;
3135 /*this hints the stub to allocate space*/
3136 volumeInfo.volEntries_val = (volintInfo *)0;
3137 volumeInfo.volEntries_len = 0;
3139 if(!flags) {/*generate all the valid partitions */
3140 UV_ListPartitions(server, &PartList, &cnt, &tst);
3142 goto fail_UV_SyncVldb;
3145 PartList.partId[0] = apart;
3149 for(i = 0;i < cnt; i++) {
3150 apart = PartList.partId[i];
3151 /*this hints the stub to allocate space*/
3152 volumeInfo.volEntries_val = (volintInfo *)0;
3153 volumeInfo.volEntries_len = 0;
3154 tst = AFSVolListVolumes(server, apart, 1, &volumeInfo);
3156 goto fail_UV_SyncVldb;
3158 count = volumeInfo.volEntries_len;
3159 pntr = volumeInfo.volEntries_val;
3161 if (!vos_PartitionIdToName(apart,pname,&tst)) {
3162 goto fail_UV_SyncVldb;
3164 /*collect all vol entries by their parentid */
3165 tst = GroupEntries(server, pntr, count, &myQueue, apart);
3168 if (volumeInfo.volEntries_val) {
3169 /*free the space allocated by the stub */
3170 free(volumeInfo.volEntries_val);
3171 volumeInfo.volEntries_val = 0;
3175 tst = ProcessEntries(cellHandle, &myQueue, server, apart, force);
3177 tst = VOLSERFAILEDOP;
3178 if (volumeInfo.volEntries_val) {
3179 /*free the space allocated by the stub */
3180 free(volumeInfo.volEntries_val);
3181 volumeInfo.volEntries_val = 0;
3185 if(noError) tst = 0;
3186 else tst = VOLSERFAILEDOP;
3187 }/* thru all partitions */
3192 if (volumeInfo.volEntries_val) free(volumeInfo.volEntries_val);
3204 static afs_int32 CheckVldbRWBK(
3205 afs_cell_handle_p cellHandle,
3206 struct nvldbentry *entry,
3207 afs_int32 *modified,
3211 afs_status_t tst = 0;
3215 if (modified) *modified = 0;
3216 idx = Lp_GetRwIndex(cellHandle, entry, 0);
3218 /* Check to see if the RW volume exists and set the RW_EXISTS
3221 if (idx == -1) { /* Did not find a RW entry */
3222 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
3223 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
3227 if (VolumeExists(cellHandle,
3228 entry->serverNumber[idx],
3229 entry->serverPartition[idx],
3230 entry->volumeId[RWVOL], &tst)) {
3231 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does no
3233 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
3237 else if (tst == ENODEV) { /* RW volume does not exist */
3238 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists
3240 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist
3246 /* If VLDB says it didn't exist, then ignore error */
3247 if (entry->flags & RW_EXISTS) {
3248 goto fail_CheckVldbRWBK;
3253 /* Check to see if the BK volume exists and set the BACK_EXISTS
3254 * flag accordingly. idx already ponts to the RW entry.
3256 if (idx == -1) { /* Did not find a RW entry */
3257 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
3258 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
3262 else { /* Found a RW entry */
3263 if (VolumeExists(cellHandle, entry->serverNumber[idx],
3264 entry->serverPartition[idx],
3265 entry->volumeId[BACKVOL], &tst)) {
3266 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does n
3268 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
3272 else if (tst == ENODEV) { /* BK volume does not exist */
3273 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists
3275 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist
3281 /* If VLDB says it didn't exist, then ignore error */
3282 if (entry->flags & BACK_EXISTS) {
3283 goto fail_CheckVldbRWBK;
3288 /* If there is an idx but the BK and RW volumes no
3289 * longer exist, then remove the RW entry.
3291 if ((idx != -1) && !(entry->flags & RW_EXISTS) &&
3292 !(entry->flags & BACK_EXISTS)) {
3293 Lp_SetRWValue(cellHandle, entry, entry->serverNumber[idx],
3294 entry->serverPartition[idx], 0L, 0L);
3302 if (modified) *modified = modentry;
3311 static int CheckVldbRO(
3312 afs_cell_handle_p cellHandle,
3313 struct nvldbentry *entry,
3314 afs_int32 *modified,
3318 afs_status_t tst = 0;
3320 int foundro = 0, modentry = 0;
3322 if (modified) *modified = 0;
3324 /* Check to see if the RO volumes exist and set the RO_EXISTS
3327 for (idx=0; idx < entry->nServers; idx++) {
3328 if (!(entry->serverFlags[idx] & ITSROVOL)) {
3329 continue; /* not a RO */
3332 if(VolumeExists(cellHandle, entry->serverNumber[idx],
3333 entry->serverPartition[idx], entry->volumeId[ROVOL],
3336 } else if (tst == ENODEV) { /* RW volume does not exist */
3337 Lp_SetROValue(cellHandle, entry, entry->serverNumber[idx],
3338 entry->serverPartition[idx], 0L, 0L);
3344 goto fail_CheckVldbRO;
3348 if (foundro) { /* A RO volume exists */
3349 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not e
3351 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
3354 } else { /* A RO volume does not exist */
3355 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
3356 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
3364 if (modified) *modified = modentry;
3372 /*ensure that <entry> matches with the info on file servers */
3374 afs_cell_handle_p cellHandle,
3375 struct nvldbentry *entry,
3376 afs_int32 *modified,
3380 afs_status_t tst = 0;
3384 afs_int32 modentry = 0;
3385 afs_int32 delentry = 0;
3391 if(strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
3393 goto fail_CheckVldb;
3398 /* Check to see if the VLDB is ok without locking it (pass 1).
3399 * If it will change, then lock the VLDB entry, read it again,
3400 * then make the changes to it (pass 2).
3403 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,
3404 entry->volumeId[RWVOL], RWVOL, VLOP_DELETE);
3406 goto fail_CheckVldb;
3410 if (!VLDB_GetEntryByID(cellHandle, entry->volumeId[RWVOL], RWVOL,
3412 goto fail_CheckVldb;
3418 /* Check if the RW and BK entries are ok */
3419 if (!CheckVldbRWBK(cellHandle, entry, &modentry, &tst)) {
3420 goto fail_CheckVldb;
3422 if (modentry && (pass == 1)) goto retry;
3424 /* Check if the RO volumes entries are ok */
3425 if (!CheckVldbRO(cellHandle, entry, &modentry, &tst)) {
3426 goto fail_CheckVldb;
3428 if (modentry && (pass == 1)) goto retry;
3430 /* The VLDB entry has been updated. If it as been modified, then
3431 * write the entry back out the the VLDB.
3434 if (pass == 1) goto retry;
3436 if (!(entry->flags & RW_EXISTS) &&
3437 !(entry->flags & BACK_EXISTS) &&
3438 !(entry->flags & RO_EXISTS)) {
3439 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
3440 tst = ubik_Call(VL_DeleteEntry, cellHandle->vos, 0,
3441 entry->volumeId[RWVOL], RWVOL);
3443 goto fail_CheckVldb;
3448 /* Replace old entry with our new one */
3449 if (!VLDB_ReplaceEntry(cellHandle, entry->volumeId[RWVOL], RWVOL,
3451 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
3452 goto fail_CheckVldb;
3455 if (modified) *modified = 1;
3463 vcode = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0,
3464 entry->volumeId[RWVOL], RWVOL,
3465 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
3468 if (!tst) tst = vcode;
3478 /*synchronise <aserver> <apart>(if flags = 1) with the vldb .
3479 *if flags = 0, synchronise all the valid partitions on <aserver>*/
3481 afs_cell_handle_p cellHandle,
3482 struct rx_connection *server,
3488 afs_status_t tst = 0;
3489 afs_int32 code, vcode;
3491 afs_int32 nentries, tentries = 0;
3492 struct VldbListByAttributes attributes;
3493 nbulkentries arrayEntries;
3495 register struct nvldbentry *vllist;
3498 afs_int32 modified = 0;
3503 arrayEntries.nbulkentries_val = 0;
3505 /* Set up attributes to search VLDB */
3506 attributes.server = ntohl(rx_HostOf(rx_PeerOf(server)));
3507 attributes.Mask = VLLIST_SERVER;
3509 attributes.partition = apart;
3510 attributes.Mask |= VLLIST_PARTITION;
3513 for(si = 0;si != -1; si=nsi) {
3514 /*initialize to hint the stub to alloc space */
3515 bzero(&arrayEntries, sizeof(arrayEntries));
3516 if (!VLDB_ListAttributes(cellHandle, &attributes, &nentries,
3517 &arrayEntries, &tst)) {
3518 goto fail_UV_SyncServer;
3521 tentries += nentries;
3523 for(j=0;j<nentries;j++) { /* process each entry */
3524 vllist = &arrayEntries.nbulkentries_val[j];
3525 if (!CheckVldb(cellHandle, vllist, &modified, &tst)) {
3530 if(arrayEntries.nbulkentries_val) {
3531 free(arrayEntries.nbulkentries_val);
3532 arrayEntries.nbulkentries_val = 0;
3539 if(arrayEntries.nbulkentries_val) {
3540 free(arrayEntries.nbulkentries_val);
3542 if(!noError) tst = VOLSERFAILEDOP;
3549 /*rename volume <oldname> to <newname>, changing the names of the related
3550 *readonly and backup volumes. This operation is also idempotent.
3551 *salvager is capable of recovering from rename operation stopping halfway.
3552 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
3553 int UV_RenameVolume(
3554 afs_cell_handle_p cellHandle,
3555 struct nvldbentry *entry,
3556 const char *newname,
3560 afs_status_t tst = 0;
3561 afs_status_t etst = 0;
3562 afs_int32 rcode,error;
3564 char nameBuffer[256];
3566 struct rx_connection *aconn;
3570 aconn = (struct rx_connection *)0;
3574 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, entry->volumeId[RWVOL],
3575 RWVOL, VLOP_ADDSITE);/*last param is dummy*/
3577 goto fail_UV_RenameVolume;
3581 strncpy(entry->name,newname,VOLSER_OLDMAXVOLNAME);
3583 if (!VLDB_ReplaceEntry(cellHandle, entry->volumeId[RWVOL], RWVOL,
3585 goto fail_UV_RenameVolume;
3587 /*at this stage the intent to rename is recorded in the vldb, as far
3589 is concerned, oldname is lost */
3590 if(entry->flags & RW_EXISTS) {
3591 index = Lp_GetRwIndex(cellHandle, entry, 0);
3592 if(index == -1){ /* there is a serious discrepancy */
3593 tst = VOLSERVLDB_ERROR;
3594 goto fail_UV_RenameVolume;
3596 aconn = UV_Bind(cellHandle, entry->serverNumber[index],
3597 AFSCONF_VOLUMEPORT);
3598 tst = AFSVolTransCreate(aconn,entry->volumeId[RWVOL],entry->serverPartition[index], ITOffline, &tid);
3599 if(tst) { /*volume doesnot exist */
3600 goto fail_UV_RenameVolume;
3602 else {/*volume exists, process it */
3604 tst = AFSVolSetIdsTypes(aconn, tid, newname,RWVOL, entry->volumeId[RWVOL],entry->volumeId[ROVOL],entry->volumeId[BACKVOL]);
3606 tst = AFSVolEndTrans(aconn, tid, &rcode);
3609 goto fail_UV_RenameVolume;
3613 goto fail_UV_RenameVolume;
3616 if(aconn) rx_ReleaseCachedConnection(aconn);
3617 aconn = (struct rx_connection *)0;
3618 } /*end rw volume processing */
3620 if(entry->flags & BACK_EXISTS) {/*process the backup volume */
3621 index = Lp_GetRwIndex(cellHandle, entry, 0);
3622 if(index == -1){ /* there is a serious discrepancy */
3623 tst = VOLSERVLDB_ERROR;
3624 goto fail_UV_RenameVolume;
3626 aconn = UV_Bind(cellHandle, entry->serverNumber[index],
3627 AFSCONF_VOLUMEPORT);
3628 tst = AFSVolTransCreate(aconn,entry->volumeId[BACKVOL],entry->serverPartition[index], ITOffline, &tid);
3629 if(tst) { /*volume doesnot exist */
3630 goto fail_UV_RenameVolume;
3632 else {/*volume exists, process it */
3633 if(strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)){
3634 goto fail_UV_RenameVolume;
3636 strcpy(nameBuffer,newname);
3637 strcat(nameBuffer,".backup");
3639 tst = AFSVolSetIdsTypes(aconn, tid,nameBuffer ,BACKVOL, entry->volumeId[RWVOL],0,0);
3641 tst = AFSVolEndTrans(aconn, tid, &rcode);
3644 goto fail_UV_RenameVolume;
3648 goto fail_UV_RenameVolume;
3651 } /* end backup processing */
3652 if(aconn) rx_ReleaseCachedConnection(aconn);
3653 aconn = (struct rx_connection *)0;
3654 if(entry->flags & RO_EXISTS){ /*process the ro volumes */
3655 for(i = 0; i < entry->nServers; i++){
3656 if(entry->serverFlags[i] & ITSROVOL) {
3657 aconn = UV_Bind(cellHandle, entry->serverNumber[i],
3658 AFSCONF_VOLUMEPORT);
3659 tst = AFSVolTransCreate(aconn,entry->volumeId[ROVOL],entry->serverPartition[i], ITOffline, &tid);
3660 if(tst) { /*volume doesnot exist */
3661 goto fail_UV_RenameVolume;
3663 else {/*volume exists, process it */
3664 strcpy(nameBuffer,newname);
3665 strcat(nameBuffer,".readonly");
3666 if(strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)){
3667 goto fail_UV_RenameVolume;
3669 tst = AFSVolSetIdsTypes(aconn, tid, nameBuffer,ROVOL, entry->volumeId[RWVOL],0,0);
3671 tst = AFSVolEndTrans(aconn, tid, &rcode);
3674 goto fail_UV_RenameVolume;
3678 goto fail_UV_RenameVolume;
3681 if(aconn) rx_ReleaseCachedConnection(aconn);
3682 aconn = (struct rx_connection *)0;
3688 fail_UV_RenameVolume:
3691 etst = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0,entry->volumeId[RWVOL] , RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3693 if(!tst) tst = etst;
3697 etst = AFSVolEndTrans(aconn, tid, &rcode);
3699 if(!tst) tst = etst;
3702 if(aconn) rx_ReleaseCachedConnection(aconn);
3710 /*group all the volume entries on< apart >by their parentid or by their ids'
3711 *if the volume is rw. <count> is the number of entries to be processesd.
3712 *<pntr> points to the first entry.< myQueue> is the queue with entries
3714 static afs_int32 GroupEntries(
3715 struct rx_connection *server,
3718 struct qHead *myQueue,
3721 struct aqueue *qPtr;
3723 afs_int32 curId, code;
3725 afs_int32 error = 0;
3731 for(i = 0; i < count; i++){/*process each entry */
3732 if(pntr->status) {/* entry is valid */
3733 if(pntr->type == RWVOL) curId = pntr->volid;
3734 else curId = pntr->parentID;
3735 Lp_QScan(myQueue,curId, &success, &qPtr, 0);
3736 if(success){ /*entry exists in the queue */
3737 if(pntr->type == RWVOL) {
3738 /*check if the rw exists already, if so hang on the
3739 later version if the present version is ok */
3740 if(qPtr->isValid[RWVOL]) {
3741 /*this should not happen, there is a serious error here*/
3742 if(!error) error = VOLSERMULTIRWVOL;
3745 qPtr->isValid[RWVOL] = 1;
3746 qPtr->copyDate[RWVOL] = pntr->copyDate;
3747 if(!qPtr->isValid[BACKVOL]) qPtr->ids[BACKVOL] = pntr->backupID;
3748 if(!qPtr->isValid[ROVOL]) qPtr->ids[ROVOL] = pntr->cloneID;
3751 else if(pntr->type == BACKVOL) {
3752 if(qPtr->isValid[BACKVOL]){
3753 /*do different checks, delete superflous volume */
3754 if(qPtr->copyDate[BACKVOL] > pntr->copyDate) {
3755 /*delete the present volume .*/
3756 code = CheckAndDeleteVolume(server,apart,0,pntr->volid);
3758 if(!error) error = code;
3763 /*delete the older volume after making sure, current one is ok*/
3764 code = CheckAndDeleteVolume(server,apart,pntr->volid,qPtr->ids[BACKVOL]);
3766 if(!error) error = code;
3769 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3770 qPtr->ids[BACKVOL] = pntr->volid;
3775 qPtr->isValid[BACKVOL] = 1;
3776 qPtr->ids[BACKVOL] = pntr->volid;
3777 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3780 else if(pntr->type == ROVOL) {
3781 if(qPtr->isValid[ROVOL]){
3782 /*do different checks, delete superflous volume */
3783 if(qPtr->copyDate[ROVOL] > pntr->copyDate) {
3784 /*delete the present volume .*/
3786 code = CheckAndDeleteVolume(server,apart,0,pntr->volid);
3788 if(!error) error = code;
3792 /*delete the older volume after making sure, current one is ok*/
3793 code = CheckAndDeleteVolume(server,apart,pntr->volid,qPtr->ids[ROVOL]);
3795 if(!error) error = code;
3798 qPtr->copyDate[ROVOL] = pntr->copyDate;
3799 qPtr->ids[ROVOL] = pntr->volid;
3804 qPtr->isValid[ROVOL] = 1;
3805 qPtr->ids[ROVOL] = pntr->volid;
3806 qPtr->copyDate[ROVOL] = pntr->copyDate;
3810 if(!error) error = VOLSERBADOP;
3813 else { /*create a fresh entry */
3814 qPtr = (struct aqueue *) malloc(sizeof(struct aqueue));
3815 if(pntr->type == RWVOL) {
3816 qPtr->isValid[RWVOL] = 1;
3817 qPtr->isValid[BACKVOL] = 0;
3818 qPtr->isValid[ROVOL] = 0;
3819 qPtr->ids[RWVOL] = pntr->volid;
3820 qPtr->ids[BACKVOL] = pntr->backupID;
3821 qPtr->ids[ROVOL] = pntr->cloneID;
3822 qPtr->copyDate[RWVOL] = pntr->copyDate;
3823 strncpy(qPtr->name, pntr->name,VOLSER_OLDMAXVOLNAME);
3824 qPtr->next = (struct aqueue *)0;
3826 else if(pntr->type == BACKVOL) {
3827 qPtr->isValid[RWVOL] = 0;
3828 qPtr->isValid[BACKVOL] = 1;
3829 qPtr->isValid[ROVOL] = 0;
3830 qPtr->ids[RWVOL] = pntr->parentID;
3831 qPtr->ids[BACKVOL] = pntr->volid;
3832 qPtr->ids[ROVOL] = 0;
3833 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3834 vsu_ExtractName(qPtr->name, pntr->name);
3835 qPtr->next = (struct aqueue *)0;
3837 else if(pntr->type == ROVOL) {
3838 qPtr->isValid[RWVOL] = 0;
3839 qPtr->isValid[BACKVOL] = 0;
3840 qPtr->isValid[ROVOL] = 1;
3841 qPtr->ids[RWVOL] = pntr->parentID;
3842 qPtr->ids[BACKVOL] = 0;
3843 qPtr->ids[ROVOL] = pntr->volid;
3844 qPtr->copyDate[ROVOL] = pntr->copyDate;
3845 vsu_ExtractName(qPtr->name, pntr->name);
3846 qPtr->next = (struct aqueue *)0;
3849 Lp_QAdd(myQueue,qPtr);
3851 pntr++;/*get next entry */
3862 /*report on all the active transactions on volser */
3863 int UV_VolserStatus(
3864 struct rx_connection *server,
3865 transDebugInfo **rpntr,
3870 afs_status_t tst = 0;
3871 transDebugEntries transInfo;
3873 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
3874 transInfo.transDebugEntries_len = 0;
3875 tst = AFSVolMonitor(server,&transInfo);
3877 goto fail_UV_VolserStatus;
3880 *rcount = transInfo.transDebugEntries_len;
3881 *rpntr = transInfo.transDebugEntries_val;
3884 fail_UV_VolserStatus:
3887 if (transInfo.transDebugEntries_val) {
3888 free(transInfo.transDebugEntries_val);
3898 /*delete the volume without interacting with the vldb */
3900 afs_cell_handle_p cellHandle,
3901 struct rx_connection *server,
3902 unsigned int partition,
3903 unsigned int volumeId,
3906 afs_int32 rcode,ttid,error,code;
3908 afs_status_t tst = 0;
3914 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
3916 tst = AFSVolDeleteVolume(server, ttid);
3918 tst = AFSVolEndTrans(server, ttid, &rcode);
3926 * We failed to delete the volume, but we still need
3927 * to end the transaction.
3929 AFSVolEndTrans(server, ttid, &rcode);
3941 struct rx_connection *server,
3942 afs_int32 partition,
3944 afs_int32 transflag,
3946 unsigned int sleepTime,
3950 afs_status_t tst = 0;
3951 afs_status_t etst = 0;
3955 tst = AFSVolTransCreate(server, volid, partition, transflag, &tid);
3957 goto fail_UV_SetVolume;
3960 tst = AFSVolSetFlags(server, tid, setflag);
3962 goto fail_UV_SetVolume;
3973 etst = AFSVolEndTrans(server, tid, &rcode);
3975 if (!tst) tst = (etst ? etst : rcode);