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.
23 #include "lockprocs.h"
24 #include "../adminutil/afs_AdminInternal.h"
25 #include <afs/afs_AdminErrors.h>
26 #include "afs_vosAdmin.h"
31 static GroupEntries();
35 afs_int32 vldbEntryIndex;
38 static struct rx_connection *UV_Bind(
39 afs_cell_handle_p cellHandle,
43 return rx_GetCachedConnection(htonl(aserver), htons(port), VOLSERVICE_ID,
44 cellHandle->tokens->afs_sc[cellHandle->tokens->sc_index],
45 cellHandle->tokens->sc_index);
49 /* if <okvol> is allright(indicated by beibg able to
50 * start a transaction, delete the <delvol> */
51 static afs_int32 CheckAndDeleteVolume(
52 struct rx_connection *aconn,
57 afs_int32 error,code,tid,rcode;
63 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline,&tid);
64 if(!error && code) error = code;
65 code = AFSVolDeleteVolume(aconn,tid);
66 if(!error && code) error = code;
67 code = AFSVolEndTrans(aconn,tid, &rcode);
68 if(!code) code = rcode;
69 if(!error && code) error = code;
73 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline,&tid);
75 code = AFSVolEndTrans(aconn,tid, &rcode);
76 if(!code) code = rcode;
77 if(!error && code) error = code;
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;
92 /* forcibly remove a volume. Very dangerous call */
94 afs_cell_handle_p cellHandle,
95 struct rx_connection *server,
96 unsigned int partition,
97 unsigned int volumeId,
101 afs_status_t tst = 0;
103 tst = AFSVolNukeVolume(server, partition, volumeId);
115 /* create a volume, given a server, partition number, volume name --> sends
116 * back new vol id in <anewid>*/
118 afs_cell_handle_p cellHandle,
119 struct rx_connection *server,
120 unsigned int partition,
121 const char *volumeName,
123 unsigned int *volumeId,
127 afs_status_t tst = 0;
130 struct nvldbentry entry;
131 struct volintInfo tstatus;
133 memset (&tstatus, 0, sizeof(tstatus));
135 tstatus.maxquota = quota;
137 /* next the next 3 available ids from the VLDB */
138 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 3, volumeId);
140 goto fail_UV_CreateVolume;
143 tst = AFSVolCreateVolume(server, partition, volumeName, volser_RW, 0,
146 goto fail_UV_CreateVolume;
149 AFSVolSetInfo(server, tid, &tstatus);
151 tst = AFSVolSetFlags(server, tid, 0);
153 goto fail_UV_CreateVolume;
156 /* set up the vldb entry for this volume */
157 strncpy(entry.name, volumeName,VOLSER_OLDMAXVOLNAME);
159 entry.serverNumber[0] = ntohl(rx_HostOf(rx_PeerOf(server)));
160 entry.serverPartition[0] = partition;
161 entry.flags = RW_EXISTS;
162 entry.serverFlags[0] = ITSRWVOL;
163 entry.volumeId[RWVOL] = *volumeId;
164 entry.volumeId[ROVOL] = *volumeId + 1;
165 entry.volumeId[BACKVOL] = *volumeId + 2;
168 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
169 AFSVolDeleteVolume(server,tid);
170 goto fail_UV_CreateVolume;
173 tst = AFSVolEndTrans(server, tid, &rcode);
176 goto fail_UV_CreateVolume;
180 fail_UV_CreateVolume:
183 AFSVolEndTrans(server, tid, &rcode);
193 /* Delete the volume <volid>on <aserver> <apart>
194 * the physical entry gets removed from the vldb only if the ref count
198 afs_cell_handle_p cellHandle,
199 struct rx_connection *server,
200 unsigned int partition,
201 unsigned int volumeId,
205 afs_status_t tst = 0;
206 afs_status_t temp = 0;
207 int serverAddr = ntohl(rx_HostOf(rx_PeerOf(server)));
211 struct nvldbentry entry;
213 afs_int32 avoltype = -1, vtype;
214 int notondisk = 0, notinvldb = 0;
216 /* Find and read the VLDB entry for this volume */
217 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, volumeId, avoltype,
220 if (tst != VL_NOENT) {
221 goto fail_UV_DeleteVolume;
227 if (!VLDB_GetEntryByID(cellHandle, volumeId, avoltype, &entry, &tst)) {
228 goto fail_UV_DeleteVolume;
233 /* Whether volume is in the VLDB or not. Delete the volume on disk */
234 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
239 goto fail_UV_DeleteVolume;
243 tst = AFSVolDeleteVolume(server, ttid);
245 goto fail_UV_DeleteVolume;
247 tst = AFSVolEndTrans(server, ttid, &rcode);
248 tst = (tst ? tst : rcode);
251 goto fail_UV_DeleteVolume;
256 goto fail_UV_DeleteVolume;
259 if (volumeId == entry.volumeId[BACKVOL]) {
260 if ( !(entry.flags & BACK_EXISTS) ||
261 !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
263 goto fail_UV_DeleteVolume;
266 entry.flags &= ~BACK_EXISTS;
270 else if (volumeId == entry.volumeId[ROVOL]) {
271 if (!Lp_ROMatch(cellHandle, &entry, serverAddr, partition, &tst)) {
273 goto fail_UV_DeleteVolume;
276 Lp_SetROValue(cellHandle, &entry, serverAddr, partition, 0, 0);
278 if (!Lp_ROMatch(cellHandle, &entry, 0, 0, &tst)) {
279 entry.flags &= ~RO_EXISTS;
284 else if (volumeId == entry.volumeId[RWVOL]) {
285 if (!(entry.flags & RW_EXISTS) ||
286 !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
288 goto fail_UV_DeleteVolume;
291 /* Delete backup if it exists */
292 tst = AFSVolTransCreate(server, entry.volumeId[BACKVOL], partition,
295 tst = AFSVolDeleteVolume(server, ttid);
297 goto fail_UV_DeleteVolume;
299 tst = AFSVolEndTrans(server, ttid, &rcode);
301 tst = (tst ? tst : rcode);
303 goto fail_UV_DeleteVolume;
307 Lp_SetRWValue(cellHandle, &entry, serverAddr, partition, 0L, 0L);
309 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
315 notinvldb = 2; /* Not found on this server and partition */
316 goto fail_UV_DeleteVolume;
319 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
320 tst = ubik_Call(VL_DeleteEntry, cellHandle->vos, 0, volumeId, vtype);
322 goto fail_UV_DeleteVolume;
325 if (!VLDB_ReplaceEntry(cellHandle, volumeId, vtype, &entry,
326 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
328 goto fail_UV_DeleteVolume;
334 fail_UV_DeleteVolume:
336 if (notondisk && notinvldb) {
337 if (!tst) tst = ADMVOSVOLUMENOEXIST;
341 temp = AFSVolEndTrans(server, ttid, &rcode);
342 temp = (temp ? temp : rcode);
344 if (!tst) tst = temp;
349 temp = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, volumeId, -1,
350 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
352 if (!tst) tst = temp;
362 #define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto mfail; }
364 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
365 * <atopart>. The operation is almost idempotent
369 afs_cell_handle_p cellHandle,
371 afs_int32 afromserver,
378 afs_status_t tst = 0;
379 afs_status_t etst = 0;
380 struct rx_connection *toconn, *fromconn ;
381 afs_int32 fromtid, totid, clonetid;
384 char tmpName[VOLSER_MAXVOLNAME +1];
387 struct restoreCookie cookie;
388 afs_int32 newVol, volid, backupId;
389 struct volser_status tstatus;
390 struct destServer destination;
392 struct nvldbentry entry;
396 afs_int32 store_flags;
398 #ifdef ENABLE_BUGFIX_1165
399 volEntries volumeInfo;
400 struct volintInfo *infop = 0;
404 fromconn = (struct rx_connection *)0;
405 toconn = (struct rx_connection *)0;
415 if (!VLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
416 goto fail_UV_MoveVolume;
419 if (entry.volumeId[RWVOL] != afromvol)
421 tst = ADMVOSVOLUMEMOVERWONLY;
422 goto fail_UV_MoveVolume;
425 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,afromvol, RWVOL, VLOP_MOVE);
427 goto fail_UV_MoveVolume;
431 if (!VLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
432 goto fail_UV_MoveVolume;
435 backupId = entry.volumeId[BACKVOL];
437 if ( !Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst) )
439 /* the from server and partition do not exist in the vldb entry corresponding to volid */
440 if ( !Lp_Match(cellHandle, &entry, atoserver, atopart, &tst) )
442 /* the to server and partition do not exist in the vldb entry corresponding to volid */
443 tst = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, afromvol, -1,
444 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
446 goto fail_UV_MoveVolume;
448 tst = VOLSERVOLMOVED;
449 goto fail_UV_MoveVolume;
452 /* delete the volume afromvol on src_server */
453 /* from-info does not exist but to-info does =>
454 * we have already done the move, but the volume
455 * may still be existing physically on from fileserver
457 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
461 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline, &fromtid);
463 { /* volume exists - delete it */
464 tst = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
466 goto fail_UV_MoveVolume;
469 tst = AFSVolDeleteVolume(fromconn,fromtid);
471 goto fail_UV_MoveVolume;
474 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
476 if (!tst) tst = rcode;
478 goto fail_UV_MoveVolume;
482 /*delete the backup volume now */
484 tst = AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
486 { /* backup volume exists - delete it */
487 tst = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
489 goto fail_UV_MoveVolume;
492 tst = AFSVolDeleteVolume(fromconn,fromtid);
494 goto fail_UV_MoveVolume;
497 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
499 if (!tst) tst = rcode;
501 goto fail_UV_MoveVolume;
507 goto fail_UV_MoveVolume;
510 /* From-info matches the vldb info about volid,
511 * its ok start the move operation, the backup volume
512 * on the old site is deleted in the process
514 if (afrompart == atopart)
516 if (!VLDB_IsSameAddrs(cellHandle, afromserver, atoserver, &same, &tst)) {
517 goto fail_UV_MoveVolume;
520 tst = VOLSERVOLMOVED;
521 goto fail_UV_MoveVolume;
526 toconn = UV_Bind(cellHandle, atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
527 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
528 fromtid = totid = 0; /* initialize to uncreated */
531 * clone the read/write volume locally.
534 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
536 goto fail_UV_MoveVolume;
541 tst = ubik_Call (VL_GetNewVolumeId, cellHandle->vos, 0, 1, &newVol);
543 goto fail_UV_MoveVolume;
546 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
547 strcpy(vname, "move-clone-temp");
548 tst = AFSVolClone(fromconn, fromtid, 0,readonlyVolume, vname, &newVol);
550 goto fail_UV_MoveVolume;
553 /* lookup the name of the volume we just cloned */
555 tst = AFSVolGetName(fromconn, fromtid, &volName);
557 goto fail_UV_MoveVolume;
561 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
563 if (!tst) tst = rcode;
565 goto fail_UV_MoveVolume;
569 * Create the destination volume
572 tst = AFSVolTransCreate (fromconn, newVol, afrompart, ITOffline, &clonetid);
574 goto fail_UV_MoveVolume;
576 tst = AFSVolSetFlags (fromconn, clonetid, VTDeleteOnSalvage|VTOutOfService); /*redundant */
578 goto fail_UV_MoveVolume;
581 /* remember time from which we've dumped the volume */
582 tst = AFSVolGetStatus (fromconn, clonetid, &tstatus);
584 goto fail_UV_MoveVolume;
587 fromDate = tstatus.creationDate-CLOCKSKEW;
589 #ifdef ENABLE_BUGFIX_1165
591 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
592 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
593 * don't use this information...
595 volumeInfo.volEntries_val = (volintInfo *)0;/*this hints the stub to allocate space*/
596 volumeInfo.volEntries_len = 0;
597 tst = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
599 goto fail_UV_MoveVolume;
602 infop = (volintInfo *) volumeInfo.volEntries_val;
603 infop->maxquota = -1; /* Else it will replace the default quota */
606 /* create a volume on the target machine */
608 tst = AFSVolTransCreate (toconn, volid, atopart, ITOffline, &totid);
610 { /*delete the existing volume */
612 tst = AFSVolDeleteVolume(toconn, totid);
614 goto fail_UV_MoveVolume;
617 tst = AFSVolEndTrans(toconn, totid, &rcode);
619 if (!tst) tst = rcode;
621 goto fail_UV_MoveVolume;
626 tst = AFSVolCreateVolume (toconn, atopart, volName, volser_RW, volid, &volid, &totid);
628 goto fail_UV_MoveVolume;
631 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
633 volName = (char *) 0;
635 tst = AFSVolSetFlags (toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
637 goto fail_UV_MoveVolume;
641 * Now dump the clone to the new volume
644 destination.destHost = atoserver;
645 destination.destPort = AFSCONF_VOLUMEPORT;
646 destination.destSSID = 1;
648 /* Copy the clone to the new volume */
649 strncpy(cookie.name,tmpName,VOLSER_OLDMAXVOLNAME);
651 cookie.parent = entry.volumeId[RWVOL];
653 tst = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
655 goto fail_UV_MoveVolume;
658 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
659 if (!tst) tst = rcode;
662 goto fail_UV_MoveVolume;
666 * reattach to the main-line volume, and incrementally dump it.
669 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
671 goto fail_UV_MoveVolume;
674 /* now do the incremental */
675 tst = AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,&cookie);
677 goto fail_UV_MoveVolume;
680 /* now adjust the flags so that the new volume becomes official */
681 tst = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
683 goto fail_UV_MoveVolume;
686 tst = AFSVolSetFlags(toconn, totid, 0);
688 goto fail_UV_MoveVolume;
691 #ifdef ENABLE_BUGFIX_1165
692 tst = AFSVolSetInfo(toconn, totid, infop);
694 goto fail_UV_MoveVolume;
698 /* put new volume online */
699 tst = AFSVolEndTrans(toconn, totid, &rcode);
701 if (!tst) tst = rcode;
703 goto fail_UV_MoveVolume;
706 Lp_SetRWValue(cellHandle, &entry, afromserver, afrompart,
708 store_flags = entry.flags;
709 entry.flags &= ~BACK_EXISTS;
711 if (!VLDB_ReplaceEntry(cellHandle, afromvol, -1, &entry,
712 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
714 goto fail_UV_MoveVolume;
716 entry.flags = store_flags;
719 if (atoserver != afromserver)
721 /* set forwarding pointer for moved volumes */
722 tst = AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
724 goto fail_UV_MoveVolume;
728 tst = AFSVolDeleteVolume(fromconn,fromtid); /* zap original volume */
730 goto fail_UV_MoveVolume;
733 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
735 if (!tst) tst = rcode;
737 goto fail_UV_MoveVolume;
740 /* Delete the backup volume on the original site */
741 tst = AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
744 tst = AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage | VTOutOfService);
746 goto fail_UV_MoveVolume;
749 tst = AFSVolDeleteVolume(fromconn,fromtid);
751 goto fail_UV_MoveVolume;
754 tst = AFSVolEndTrans(fromconn,fromtid, &rcode);
756 if (!tst) tst = rcode;
758 goto fail_UV_MoveVolume;
762 else tst = 0; /* no backup volume? that's okay */
766 tst = AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
768 goto fail_UV_MoveVolume;
771 /* now delete the clone */
773 tst = AFSVolDeleteVolume(fromconn, clonetid);
775 goto fail_UV_MoveVolume;
778 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
779 if (!tst) tst = rcode;
782 goto fail_UV_MoveVolume;
788 /* normal cleanup code */
792 etst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, afromvol, -1,
793 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
796 if (!tst) tst = etst;
802 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
805 if (!tst) tst = (etst ? etst : rcode);
811 etst = AFSVolEndTrans(fromconn, clonetid, &rcode);
814 if (!tst) tst = (etst ? etst : rcode);
820 etst = AFSVolEndTrans(toconn, totid, &rcode);
823 if (!tst) tst = (etst ? etst : rcode);
826 if (volName) free(volName);
827 #ifdef ENABLE_BUGFIX_1165
828 if (infop) free(infop);
830 if (fromconn) rx_ReleaseCachedConnection(fromconn);
831 if (toconn) rx_ReleaseCachedConnection(toconn);
839 /* come here only when the sky falls */
843 /* unlock VLDB entry */
845 ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, afromvol, -1,
846 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
848 if (clonetid) AFSVolEndTrans(fromconn, clonetid, &rcode);
849 if (totid) AFSVolEndTrans(toconn, totid, &rcode);
851 { /* put it on-line */
852 AFSVolSetFlags(fromconn,fromtid,0);
853 AFSVolEndTrans(fromconn, fromtid, &rcode);
856 if (!VLDB_GetEntryByID (cellHandle, afromvol, -1, &entry, &tst)) {
860 /* Delete either the volume on the source location or the target location.
861 * If the vldb entry still points to the source location, then we know the
862 * volume move didn't finish so we remove the volume from the target
863 * location. Otherwise, we remove the volume from the source location.
865 if (Lp_Match(cellHandle, &entry, afromserver,afrompart,&tst)) { /* didn't move - delete target volume */
867 if (volid && toconn) {
868 tst=AFSVolTransCreate(toconn,volid,atopart, ITOffline,&totid);
870 AFSVolSetFlags(toconn,totid, VTDeleteOnSalvage | VTOutOfService);
871 AFSVolDeleteVolume(toconn,totid);
872 AFSVolEndTrans(toconn,totid,&rcode);
876 /* put source volume on-line */
878 tst=AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
880 AFSVolSetFlags(fromconn,fromtid,0);
881 AFSVolEndTrans(fromconn,fromtid,&rcode);
885 else { /* yep, move complete */
886 /* delete backup volume */
888 tst=AFSVolTransCreate (fromconn,backupId,afrompart, ITOffline,&fromtid);
890 AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService);
891 AFSVolDeleteVolume(fromconn,fromtid);
892 AFSVolEndTrans(fromconn,fromtid,&rcode);
895 /* delete source volume */
896 tst=AFSVolTransCreate (fromconn, afromvol, afrompart, ITBusy, &fromtid);
898 AFSVolSetFlags(fromconn,fromtid, VTDeleteOnSalvage | VTOutOfService);
899 if (atoserver != afromserver)
900 AFSVolSetForwarding(fromconn,fromtid,htonl(atoserver));
901 AFSVolDeleteVolume(fromconn,fromtid);
902 AFSVolEndTrans(fromconn,fromtid,&rcode);
907 /* common cleanup - delete local clone */
909 tst = AFSVolTransCreate (fromconn, newVol, afrompart, ITOffline, &clonetid);
911 AFSVolDeleteVolume(fromconn,clonetid);
912 AFSVolEndTrans(fromconn,clonetid,&rcode);
916 /* unlock VLDB entry */
917 ubik_Call (VL_ReleaseLock, cellHandle->vos, 0, afromvol, -1,
918 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
920 done: /* routine cleanup */
921 if (volName) free(volName);
922 #ifdef ENABLE_BUGFIX_1165
923 if (infop) free(infop);
925 if (fromconn) rx_ReleaseCachedConnection(fromconn);
926 if (toconn) rx_ReleaseCachedConnection(toconn);
934 /* Make a new backup of volume <avolid> on <aserver> and <apart>
935 * if one already exists, update it
939 afs_cell_handle_p cellHandle,
946 afs_status_t tst = 0, temp = 0;
947 afs_int32 ttid = 0, btid = 0;
949 afs_int32 code = 0, rcode = 0;
950 char vname[VOLSER_MAXVOLNAME +1];
951 struct nvldbentry entry;
953 int vldblocked = 0, vldbmod = 0, backexists = 1;
954 struct rx_connection *aconn = UV_Bind(cellHandle, aserver,
958 /* the calls to VLDB will succeed only if avolid is a RW volume,
959 * since we are following the RW hash chain for searching */
960 if(!VLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
961 goto fail_UV_BackupVolume;
964 /* These operations require the VLDB be locked since it means the VLDB
965 * will change or the vldb is already locked.
967 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
968 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
969 (entry.volumeId[BACKVOL] == INVALID_BID)) {
970 /* no assigned backup volume id */
972 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, avolid, RWVOL,
975 goto fail_UV_BackupVolume;
979 /* Reread the vldb entry */
980 if (!VLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
981 goto fail_UV_BackupVolume;
985 if (!ISNAMEVALID(entry.name)) {
987 goto fail_UV_BackupVolume;
990 backupID = entry.volumeId[BACKVOL];
991 if (backupID == INVALID_BID) {
992 /* Get a backup volume id from the VLDB and update the vldb
995 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, &backupID);
997 goto fail_UV_BackupVolume;
999 entry.volumeId[BACKVOL] = backupID;
1003 /* Test to see if the backup volume exists by trying to create
1004 * a transaction on the backup volume. We've assumed the backup exists.
1006 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1008 if (tst != VNOVOL) {
1009 goto fail_UV_BackupVolume;
1011 backexists = 0; /* backup volume does not exist */
1014 tst = AFSVolEndTrans(aconn, btid, &rcode);
1017 tst = (tst ? tst : rcode);
1018 goto fail_UV_BackupVolume;
1022 /* Now go ahead and try to clone the RW volume.
1023 * First start a transaction on the RW volume
1025 tst = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
1027 goto fail_UV_BackupVolume;
1030 /* Clone or reclone the volume, depending on whether the backup
1031 * volume exists or not
1034 tst = AFSVolReClone(aconn, ttid, backupID);
1036 goto fail_UV_BackupVolume;
1040 strcpy(vname, entry.name);
1041 strcat(vname,".backup");
1043 tst = AFSVolClone(aconn, ttid, 0,backupVolume, vname, &backupID);
1045 goto fail_UV_BackupVolume;
1049 /* End transaction on the RW volume */
1050 tst = AFSVolEndTrans(aconn, ttid, &rcode);
1053 tst = (tst ? tst : rcode);
1054 goto fail_UV_BackupVolume;
1057 /* Mork vldb as backup exists */
1058 if (!(entry.flags & BACK_EXISTS)) {
1059 entry.flags |= BACK_EXISTS;
1063 /* Now go back to the backup volume and bring it on line */
1064 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1066 goto fail_UV_BackupVolume;
1069 tst = AFSVolSetFlags(aconn, btid, 0);
1071 goto fail_UV_BackupVolume;
1074 tst = AFSVolEndTrans(aconn, btid, &rcode);
1077 tst = (tst ? tst : rcode);
1078 goto fail_UV_BackupVolume;
1082 /* Will update the vldb below */
1084 fail_UV_BackupVolume:
1087 temp = AFSVolEndTrans(aconn, ttid, &rcode);
1088 if (temp || rcode) {
1090 tst = (temp ? temp : rcode);
1095 temp = AFSVolEndTrans(aconn, btid, &rcode);
1096 if (temp || rcode) {
1098 tst = (temp ? temp : rcode);
1102 /* Now update the vldb - if modified */
1105 if(!VLDB_ReplaceEntry(cellHandle, avolid, RWVOL, &entry,
1106 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &temp)) {
1112 temp = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, avolid, RWVOL,
1113 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
1123 rx_ReleaseCachedConnection(aconn);
1133 struct rx_connection *conn,
1138 afs_int32 acode, ccode, rcode, tid;
1139 ccode = rcode = tid = 0;
1141 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
1142 if (!acode) { /* It really was there */
1143 acode = AFSVolDeleteVolume(conn, tid);
1144 ccode = AFSVolEndTrans(conn, tid, &rcode);
1145 if (!ccode) ccode = rcode;
1151 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
1152 #define ERROREXIT(ec) { error = (ec); goto rfail; }
1154 static int CloneVol (
1155 afs_cell_handle_p cellHandle,
1156 struct rx_connection *conn,
1161 struct nvldbentry *entry,
1162 afs_int32 *vidCreateDate,
1166 afs_status_t tst = 0, etst = 0;
1167 afs_int32 rcode = 0, tid = 0;
1168 struct volser_status volstatus;
1171 /* Begin transaction on RW volume marking it busy (clients will wait) */
1172 tst = AFSVolTransCreate(conn, rwvid, part, ITBusy, &tid);
1177 /* Get the RO volume id. Allocate a new one if need to */
1178 *rovidp = entry->volumeId[ROVOL];
1179 if (*rovidp == INVALID_BID) {
1180 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, rovidp);
1185 entry->volumeId[ROVOL] = *rovidp;
1188 /* If we are creating the ro clone, what are we calling it.
1189 * Depends on whether its a temporary clone or not.
1192 strcpy(vname, entry->name);
1193 strcat(vname, ".readonly");
1195 strcpy(vname, "readonly-clone-temp"); /* Should be unique? */
1198 /* Create the new clone. If it exists, then reclone it */
1199 tst = AFSVolClone(conn, tid, 0, readonlyVolume, vname, rovidp);
1200 if (tst == VVOLEXISTS) {
1201 tst = AFSVolReClone(conn, tid, *rovidp);
1210 /* Bring the volume back on-line as soon as possible */
1212 afs_int32 fromtid=0;
1214 /* Now bring the RO clone on-line */
1215 tst = AFSVolTransCreate(conn, *rovidp, part, ITOffline, &fromtid);
1220 tst = AFSVolSetFlags(conn, fromtid, 0);
1225 tst = AFSVolEndTrans(conn, fromtid, &rcode);
1227 if (!tst) tst = rcode;
1233 /* Get the time the RW was created for return information */
1234 tst = AFSVolGetStatus(conn, tid, &volstatus);
1238 *vidCreateDate = volstatus.creationDate;
1244 tst = AFSVolEndTrans(conn, tid, &rcode);
1246 if (!tst) tst = rcode;
1259 /* Get a "transaction" on this replica. Create the volume
1260 * if necessary. Return the time from which a dump should
1261 * be made (0 if it's a new volume)
1263 static int GetTrans (
1264 afs_cell_handle_p cellHandle,
1265 struct nvldbentry *vldbEntryPtr,
1267 struct rx_connection **connPtr,
1268 afs_int32 *transPtr,
1273 afs_status_t tst = 0, etst = 0;
1275 struct volser_status tstatus;
1278 *connPtr = (struct rx_connection *)0;
1282 /* get connection to the replication site */
1283 *connPtr = UV_Bind(cellHandle, vldbEntryPtr->serverNumber[index],
1284 AFSCONF_VOLUMEPORT);
1286 /* server is down */
1291 volid = vldbEntryPtr->volumeId[ROVOL];
1293 tst = AFSVolTransCreate(*connPtr, volid,
1294 vldbEntryPtr->serverPartition[index],
1295 ITOffline, transPtr);
1298 /* If the volume does not exist, create it */
1299 if (!volid || tst) {
1302 if (volid && (tst != VNOVOL)){
1306 strcpy(volname, vldbEntryPtr->name);
1307 strcat(volname, ".readonly");
1309 tst = AFSVolCreateVolume(*connPtr,
1310 vldbEntryPtr->serverPartition[index],
1312 vldbEntryPtr->volumeId[RWVOL], &volid,
1317 vldbEntryPtr->volumeId[ROVOL] = volid;
1319 /* The following is a bit redundant, since create sets these flags by default */
1320 tst = AFSVolSetFlags(*connPtr, *transPtr,
1321 VTDeleteOnSalvage | VTOutOfService);
1327 /* Otherwise, the transaction did succeed, so get the creation date of the
1328 * latest RO volume on the replication site
1331 tst = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
1335 *timePtr = tstatus.creationDate-CLOCKSKEW;
1341 if ((rc == 0) && (*transPtr)) {
1342 etst = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
1344 if (!etst) etst = rcode;
1353 static int SimulateForwardMultiple(
1354 struct rx_connection *fromconn,
1360 manyResults *results)
1364 for (i=0; i<tr->manyDests_len; i++) {
1365 results->manyResults_val[i] =
1366 AFSVolForward(fromconn, fromtid, fromdate,
1367 &(tr->manyDests_val[i].server),
1368 tr->manyDests_val[i].trans, cookie);
1374 static int rel_compar (
1378 return (r1->time - r2->time);
1382 * Determine if a volume exists on a server and partition.
1383 * Try creating a transaction on the volume. If we can,
1384 * the volume exists, if not, then return the error code.
1385 * Some error codes mean the volume is unavailable but
1386 * still exists - so we catch these error codes.
1388 static afs_int32 VolumeExists(
1389 afs_cell_handle_p cellHandle,
1391 afs_int32 partition,
1396 afs_status_t tst = -1;
1397 struct rx_connection *conn=(struct rx_connection *)0;
1398 volEntries volumeInfo;
1400 conn = UV_Bind(cellHandle, server, AFSCONF_VOLUMEPORT);
1402 volumeInfo.volEntries_val = (volintInfo *)0;
1403 volumeInfo.volEntries_len = 0;
1404 tst = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
1405 if (volumeInfo.volEntries_val)
1406 free(volumeInfo.volEntries_val);
1407 if (tst == VOLSERILLEGAL_PARTITION) {
1410 rx_ReleaseCachedConnection(conn);
1420 /* release volume <afromvol> on <afromserver> <afrompart> to all the
1421 * sites if forceflag is 1.If its 0 complete the release if the previous
1422 * release aborted else start a new release */
1423 int UV_ReleaseVolume(
1424 afs_cell_handle_p cellHandle,
1426 afs_int32 afromserver,
1427 afs_int32 afrompart,
1432 afs_status_t tst = 0, etst = 0;
1436 afs_int32 cloneVolId, roVolId;
1437 struct replica *replicas=0;
1438 struct nvldbentry entry;
1439 int i, volcount, m, fullrelease, vldbindex;
1441 struct restoreCookie cookie;
1442 struct rx_connection **toconns=0;
1443 struct release *times=0;
1445 struct rx_connection *fromconn = (struct rx_connection *)0;
1446 afs_int32 error = 0;
1448 afs_int32 clonetid=0, onlinetid;
1449 afs_int32 fromtid=0;
1450 afs_uint32 fromdate, thisdate;
1453 manyResults results;
1454 int rwindex, roindex, roclone, roexists;
1459 } remembertime[NMAXNSERVERS];
1460 int releasecount = 0;
1461 struct volser_status volstatus;
1463 bzero((char *)remembertime, sizeof(remembertime));
1464 bzero((char *)&results, sizeof(results));
1466 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, afromvol, RWVOL, VLOP_RELEASE);
1467 if ((tst) && (tst != VL_RERELEASE)) {
1468 goto fail_UV_ReleaseVolume;
1472 /* Get the vldb entry in readable format */
1473 if (!VLDB_GetEntryByID (cellHandle, afromvol, RWVOL, &entry, &tst)) {
1474 goto fail_UV_ReleaseVolume;
1477 if (!ISNAMEVALID(entry.name)) {
1478 tst = VOLSERBADNAME;
1479 goto fail_UV_ReleaseVolume;
1482 if (entry.volumeId[RWVOL] != afromvol) {
1483 tst = ADMVOSVOLUMERELEASERWONLY;
1484 goto fail_UV_ReleaseVolume;
1487 if (entry.nServers <= 1) {
1488 tst = ADMVOSVOLUMENOREPLICAS;
1489 goto fail_UV_ReleaseVolume;
1492 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10)) {
1493 tst = VOLSERBADNAME;
1494 goto fail_UV_ReleaseVolume;
1497 /* roclone is true if one of the RO volumes is on the same
1498 * partition as the RW volume. In this case, we make the RO volume
1499 * on the same partition a clone instead of a complete copy.
1502 roindex = Lp_ROMatch(cellHandle, &entry, afromserver, afrompart, &tst) - 1;
1503 roclone = ((roindex == -1) ? 0 : 1);
1504 rwindex = Lp_GetRwIndex(cellHandle, &entry, 0);
1507 goto fail_UV_ReleaseVolume;
1510 /* Make sure we have a RO volume id to work with */
1511 if (entry.volumeId[ROVOL] == INVALID_BID) {
1512 /* need to get a new RO volume id */
1513 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, &roVolId);
1515 goto fail_UV_ReleaseVolume;
1518 entry.volumeId[ROVOL] = roVolId;
1519 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1520 goto fail_UV_ReleaseVolume;
1524 /* Will we be completing a previously unfinished release. -force overrides */
1525 for (fullrelease=1, i=0; (fullrelease && (i<entry.nServers)); i++) {
1526 if (entry.serverFlags[i] & NEW_REPSITE)
1529 if (forceflag && !fullrelease)
1532 /* Determine which volume id to use and see if it exists */
1533 cloneVolId = ((fullrelease || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
1534 VolumeExists(cellHandle, afromserver, afrompart, cloneVolId, &tst);
1535 roexists = ((tst == ENODEV) ? 0 : 1);
1536 if (!roexists && !fullrelease)
1537 fullrelease = 1; /* Do a full release if RO clone does not exist */
1539 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
1542 goto fail_UV_ReleaseVolume;
1546 /* If the RO clone exists, then if the clone is a temporary
1547 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
1548 * (it was recently added), then also delete it. We do not
1549 * want to "reclone" a temporary RO clone.
1552 (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE)) ) {
1553 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1554 if (tst && (tst != VNOVOL)) {
1555 goto fail_UV_ReleaseVolume;
1560 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
1561 * write this entry out to the vlserver until after the first
1562 * RO volume is released (temp RO clones don't count).
1564 for (i=0; i<entry.nServers; i++) {
1565 entry.serverFlags[i] &= ~NEW_REPSITE;
1566 entry.serverFlags[i] |= RO_DONTUSE;
1568 entry.serverFlags[rwindex] |= NEW_REPSITE;
1569 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
1571 /* Begin transaction on RW and mark it busy while we clone it */
1572 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &clonetid);
1574 goto fail_UV_ReleaseVolume;
1577 /* Clone or reclone the volume */
1579 tst = AFSVolReClone(fromconn, clonetid, cloneVolId);
1581 goto fail_UV_ReleaseVolume;
1585 strcpy(vname, entry.name);
1586 strcat(vname, ".readonly");
1588 strcpy(vname, "readonly-clone-temp");
1590 tst = AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname, &cloneVolId);
1592 goto fail_UV_ReleaseVolume;
1596 /* Get the time the RW was created for future information */
1597 tst = AFSVolGetStatus(fromconn, clonetid, &volstatus);
1599 goto fail_UV_ReleaseVolume;
1601 rwcrdate = volstatus.creationDate;
1603 /* End the transaction on the RW volume */
1604 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1606 tst = (tst ? tst : rcode);
1608 goto fail_UV_ReleaseVolume;
1611 /* Remember clone volume ID in case we fail or are interrupted */
1612 entry.cloneId = cloneVolId;
1615 /* Bring the RO clone online - though not if it's a temporary clone */
1616 tst = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline, &onlinetid);
1618 goto fail_UV_ReleaseVolume;
1621 etst = AFSVolSetFlags(fromconn, onlinetid, 0);
1623 tst = AFSVolEndTrans(fromconn, onlinetid, &rcode);
1624 tst = (tst ? tst : rcode);
1626 goto fail_UV_ReleaseVolume;
1630 goto fail_UV_ReleaseVolume;
1633 /* Sleep so that a client searching for an online volume won't
1634 * find the clone offline and then the next RO offline while the
1635 * release brings the clone online and the next RO offline (race).
1636 * There is a fix in the 3.4 client that does not need this sleep
1637 * anymore, but we don't know what clients we have.
1639 if (entry.nServers > 2)
1642 /* Mark the RO clone in the VLDB as a good site (already released)*/
1643 entry.serverFlags[roindex] |= NEW_REPSITE;
1644 entry.serverFlags[roindex] &= ~RO_DONTUSE;
1645 entry.flags |= RO_EXISTS;
1649 /* Write out the VLDB entry only if the clone is not a temporary
1650 * clone. If we did this to a temporary clone then we would end
1651 * up marking all the ROs as "old release" making the ROs
1652 * temporarily unavailable.
1654 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1655 goto fail_UV_ReleaseVolume;
1660 /* Now we will release from the clone to the remaining RO replicas.
1661 * The first 2 ROs (counting the non-temporary RO clone) are released
1662 * individually: releasecount. This is to reduce the race condition
1663 * of clients trying to find an on-line RO volume. The remaining ROs
1664 * are released in parallel but no more than half the number of ROs
1665 * (rounded up) at a time: nservers.
1668 strcpy(vname, entry.name);
1669 strcat(vname, ".readonly");
1670 bzero(&cookie,sizeof(cookie));
1671 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
1672 cookie.type = ROVOL;
1673 cookie.parent = entry.volumeId[RWVOL];
1676 nservers = entry.nServers/2; /* how many to do at once, excluding clone */
1677 replicas = (struct replica *) malloc (sizeof(struct replica)*nservers+1);
1678 times = (struct release *) malloc (sizeof(struct release)*nservers+1);
1679 toconns = (struct rx_connection **) malloc (sizeof(struct rx_connection *)*nservers+1);
1680 results.manyResults_val = (afs_int32 *) malloc (sizeof(afs_int32)*nservers+1);
1681 if ( !replicas || !times || !! !results.manyResults_val || !toconns ) {
1683 goto fail_UV_ReleaseVolume;
1686 bzero (replicas, (sizeof(struct replica)*nservers+1));
1687 bzero (times, (sizeof(struct release)*nservers+1));
1688 bzero (toconns, (sizeof(struct rx_connection *)*nservers+1));
1689 bzero (results.manyResults_val, (sizeof(afs_int32)*nservers+1));
1691 /* Create a transaction on the cloned volume */
1692 tst = AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
1694 goto fail_UV_ReleaseVolume;
1697 /* For each index in the VLDB */
1698 for (vldbindex=0; vldbindex<entry.nServers; ) {
1700 /* Get a transaction on the replicas. Pick replacas which have an old release. */
1701 for (volcount=0; ((volcount<nservers) && (vldbindex<entry.nServers)); vldbindex++) {
1702 /* The first two RO volumes will be released individually.
1703 * The rest are then released in parallel. This is a hack
1704 * for clients not recognizing right away when a RO volume
1705 * comes back on-line.
1707 if ((volcount == 1) && (releasecount < 2))
1710 if (vldbindex == roindex) continue; /* the clone */
1711 if ( (entry.serverFlags[vldbindex] & NEW_REPSITE) &&
1712 !(entry.serverFlags[vldbindex] & RO_DONTUSE) ) continue;
1713 if (!(entry.serverFlags[vldbindex] & ITSROVOL)) continue; /* not a RO vol */
1716 /* Get a Transaction on this replica. Get a new connection if
1717 * necessary. Create the volume if necessary. Return the
1718 * time from which the dump should be made (0 if it's a new
1719 * volume). Each volume might have a different time.
1721 replicas[volcount].server.destHost = entry.serverNumber[vldbindex];
1722 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
1723 replicas[volcount].server.destSSID = 1;
1724 times[volcount].vldbEntryIndex = vldbindex;
1726 if(!GetTrans(cellHandle, &entry, vldbindex, &(toconns[volcount]),
1727 &(replicas[volcount].trans), &(times[volcount].time),
1732 /* Thisdate is the date from which we want to pick up all changes */
1733 if (forceflag || !fullrelease || (rwcrdate > times[volcount].time)) {
1734 /* If the forceflag is set, then we want to do a full dump.
1735 * If it's not a full release, we can't be sure that the creation
1736 * date is good (so we also do a full dump).
1737 * If the RW volume was replaced (its creation date is newer than
1738 * the last release), then we can't be sure what has changed (so
1739 * we do a full dump).
1742 } else if (remembertime[vldbindex].validtime) {
1743 /* Trans was prev ended. Use the time from the prev trans
1744 * because, prev trans may have created the volume. In which
1745 * case time[volcount].time would be now instead of 0.
1747 thisdate = (remembertime[vldbindex].time < times[volcount].time) ?
1748 remembertime[vldbindex].time : times[volcount].time;
1750 thisdate = times[volcount].time;
1752 remembertime[vldbindex].validtime = 1;
1753 remembertime[vldbindex].time = thisdate;
1755 if (volcount == 0) {
1756 fromdate = thisdate;
1758 /* Include this volume if it is within 15 minutes of the earliest */
1759 if (((fromdate>thisdate)?(fromdate-thisdate):(thisdate-fromdate)) > 900) {
1760 AFSVolEndTrans(toconns[volcount], replicas[volcount].trans, &rcode);
1761 replicas[volcount].trans = 0;
1764 if (thisdate < fromdate)
1765 fromdate = thisdate;
1769 if (!volcount) continue;
1771 /* Release the ones we have collected */
1772 tr.manyDests_val = &(replicas[0]);
1773 tr.manyDests_len = results.manyResults_len = volcount;
1774 tst = AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr, 0/*spare*/, &cookie, &results);
1775 if (tst == RXGEN_OPCODE) { /* RPC Interface Mismatch */
1776 tst = SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr, 0/*spare*/, &cookie, &results);
1781 goto fail_UV_ReleaseVolume;
1783 for (m=0; m<volcount; m++) {
1784 if (results.manyResults_val[m]) {
1788 tst = AFSVolSetIdsTypes(toconns[m], replicas[m].trans,
1789 vname, ROVOL, entry.volumeId[RWVOL], 0, 0);
1794 /* have to clear dest. flags to ensure new vol goes online:
1795 * because the restore (forwarded) operation copied
1796 * the V_inService(=0) flag over to the destination.
1798 tst = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
1803 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
1804 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
1805 entry.flags |= RO_EXISTS;
1810 /* End the transactions and destroy the connections */
1811 for (s=0; s<volcount; s++) {
1812 if (replicas[s].trans)
1813 tst = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
1814 replicas[s].trans = 0;
1815 if (!tst) tst = rcode;
1817 if ((s == 0) || (tst != ENOENT)) {
1819 if (times[s].vldbEntryIndex < vldbindex)
1820 vldbindex = times[s].vldbEntryIndex;
1825 rx_ReleaseCachedConnection(toconns[s]);
1829 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1830 goto fail_UV_ReleaseVolume;
1832 } /* for each index in the vldb */
1834 /* End the transaction on the cloned volume */
1835 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1838 /* Figure out if any volume were not released and say so */
1839 for (failure=0, i=0; i<entry.nServers; i++) {
1840 if (!(entry.serverFlags[i] & NEW_REPSITE))
1844 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry,
1845 LOCKREL_TIMESTAMP, &tst)) {
1846 goto fail_UV_ReleaseVolume;
1849 tst = VOLSERBADRELEASE;
1850 goto fail_UV_ReleaseVolume;
1853 /* All the ROs were release successfully. Remove the temporary clone */
1855 tst = DelVol (fromconn, cloneVolId, afrompart, ITOffline);
1857 goto fail_UV_ReleaseVolume;
1862 for (i=0; i<entry.nServers; i++)
1863 entry.serverFlags[i] &= ~NEW_REPSITE;
1865 /* Update the VLDB */
1866 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry,
1867 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP,
1869 goto fail_UV_ReleaseVolume;
1873 fail_UV_ReleaseVolume:
1876 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1883 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1889 for (i=0; i<nservers; i++) {
1890 if (replicas && replicas[i].trans) {
1891 tst = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
1892 replicas[i].trans = 0;
1897 if (toconns && toconns[i]) {
1898 rx_ReleaseCachedConnection(toconns[i]);
1903 tst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, afromvol, RWVOL,
1904 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
1910 if (fromconn) rx_ReleaseCachedConnection(fromconn);
1911 if (results.manyResults_val) free (results.manyResults_val);
1912 if (replicas) free (replicas);
1913 if (toconns) free (toconns);
1914 if (times) free (times);
1922 static int ReceiveFile(
1924 register struct rx_call *call,
1925 register struct stat *status)
1927 register char *buffer = (char*) 0;
1928 register int blockSize;
1929 afs_int32 bytesread, nbytes, bytesleft, w;
1931 afs_int32 error = 0;
1938 struct statfs tstatfs;
1940 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
1942 fstatfs(fd, &tstatfs);
1943 blockSize = tstatfs.f_bsize;
1945 blockSize = status->st_blksize;
1953 buffer = (char *)malloc(blockSize);
1958 while(!error && (bytesread > 0)) {
1959 bytesread = rx_Read(call, buffer, nbytes);
1960 bytesleft = bytesread;
1961 while (!error && (bytesleft > 0)) {
1964 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
1965 select(fd+1, 0, &out, 0, 0); /* don't timeout if write bl
1968 w = write(fd, &buffer[bytesread-bytesleft], bytesleft);
1970 error = ADMVOSDUMPFILEWRITEFAIL;
1977 if (buffer) free(buffer);
1979 if (!error) fstat(fd, status);
1984 static afs_int32 DumpFunction(
1985 struct rx_call *call,
1986 const char *filename)
1990 afs_int32 error,code;
1995 fd = open(filename,O_CREAT|O_TRUNC|O_WRONLY, 0666);
1996 if (fd < 0 || fstat(fd, &status) < 0){
1997 error = VOLSERBADOP;
2000 code = ReceiveFile(fd,call,&status);
2006 if (fd >= 0) code = close(fd);
2009 if(!error) error = code;
2015 /*dump the volume <afromvol> on <afromserver> and
2016 * <afrompart> to <afilename> starting from <fromdate>.
2017 * DumpFunction does the real work behind the scenes after
2018 * extracting parameters from the rock */
2020 afs_cell_handle_p cellHandle,
2022 afs_int32 afromserver,
2023 afs_int32 afrompart,
2025 const char *filename,
2029 afs_status_t tst = 0;
2030 afs_status_t etst = 0;
2031 struct rx_connection *fromconn;
2032 struct rx_call *fromcall;
2037 struct nvldbentry entry;
2044 fromcall = (struct rx_call *)0;
2045 fromconn = (struct rx_connection *)0;
2047 fromcall = (struct rx_call *)0;
2050 if (!VLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
2051 goto fail_UV_DumpVolume;
2054 /* get connections to the servers */
2055 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
2056 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2058 goto fail_UV_DumpVolume;
2060 fromcall = rx_NewCall(fromconn);
2061 tst = StartAFSVolDump(fromcall,fromtid, fromdate);
2063 goto fail_UV_DumpVolume;
2065 if (tst = DumpFunction(fromcall,filename)) {
2066 goto fail_UV_DumpVolume;
2068 tst = rx_EndCall(fromcall,rxError);
2069 fromcall = (struct rx_call *)0;
2071 goto fail_UV_DumpVolume;
2073 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2075 if (!tst) tst = rcode;
2077 goto fail_UV_DumpVolume;
2084 etst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, afromvol, -1, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2086 if(!tst) tst = etst;
2091 etst = rx_EndCall(fromcall,rxError);
2093 if(!tst) tst = etst;
2098 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2099 if(!tst) tst = etst;
2101 if(!tst) tst = rcode;
2106 rx_ReleaseCachedConnection(fromconn);
2117 register struct rx_call *call,
2118 register struct stat *status)
2120 char *buffer = (char*) 0;
2123 afs_int32 error = 0;
2132 struct statfs tstatfs;
2134 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2136 fstatfs(fd, &tstatfs);
2137 blockSize = tstatfs.f_bsize;
2139 blockSize = status->st_blksize;
2146 buffer = (char *)malloc(blockSize);
2151 while (!error && !done) {
2154 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2155 select(fd+1, &in, 0, 0, 0); /* don't timeout if read blocks */
2157 nbytes = read(fd, buffer, blockSize);
2159 error = ADMVOSRESTOREFILEREADFAIL;
2166 if (rx_Write(call, buffer, nbytes) != nbytes){
2167 error = ADMVOSRESTOREFILEWRITEFAIL;
2171 if (buffer) free(buffer);
2175 static afs_int32 WriteData(
2176 struct rx_call *call,
2177 const char *filename)
2181 afs_int32 error,code;
2186 fd = open(filename,0);
2187 if (fd < 0 || fstat(fd, &status) < 0){
2188 fprintf(STDERR,"Could access file '%s'\n",filename);
2189 error = ADMVOSRESTOREFILEOPENFAIL;
2190 goto fail_WriteData;
2192 code = SendFile(fd,call,&status);
2195 goto fail_WriteData;
2200 if(fd >= 0) code = close(fd);
2203 if(!error) error = ADMVOSRESTOREFILECLOSEFAIL;
2209 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
2210 * the dump file <afilename>. WriteData does all the real work
2211 * after extracting params from the rock
2213 int UV_RestoreVolume(
2214 afs_cell_handle_p cellHandle,
2218 const char *tovolname,
2220 const char *dumpFile,
2224 afs_status_t tst = 0;
2225 afs_status_t etst = 0;
2226 struct rx_connection *toconn,*tempconn;
2227 struct rx_call *tocall;
2228 afs_int32 totid, rcode, terror = 0;
2229 afs_int32 rxError = 0;
2230 struct volser_status tstatus;
2235 struct nvldbentry entry;
2238 struct restoreCookie cookie;
2240 afs_int32 newDate, volflag;
2244 bzero(&cookie,sizeof(cookie));
2249 tocall = (struct rx_call *)0;
2250 toconn = (struct rx_connection *)0;
2251 tempconn = (struct rx_connection *)0;
2256 toconn = UV_Bind(cellHandle, toserver, AFSCONF_VOLUMEPORT);
2257 if(pvolid == 0) {/*alot a new id if needed */
2258 VLDB_GetEntryByName(cellHandle, tovolname, &entry, &tst);
2259 if(tst == VL_NOENT) {
2260 tst = ubik_Call(VL_GetNewVolumeId, cellHandle->vos, 0, 1, &pvolid);
2262 goto fail_UV_RestoreVolume;
2267 pvolid = entry.volumeId[RWVOL];
2272 * at this point we have a volume id to use/reuse for the
2273 * volume to be restored
2275 if(strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
2276 tst = ADMVOSRESTOREVOLUMENAMETOOBIG;
2277 goto fail_UV_RestoreVolume;
2280 if (!vos_PartitionIdToName(topart, partName, &tst)) {
2281 goto fail_UV_RestoreVolume;
2283 /*what should the volume be restored as ? rw or ro or bk ?
2284 right now the default is rw always */
2285 tst = AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,&pvolid, &totid);
2287 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
2288 tst = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2290 goto fail_UV_RestoreVolume;
2292 tst = AFSVolSetFlags(toconn, totid, VTDeleteOnSalvage | VTOutOfService);
2294 goto fail_UV_RestoreVolume;
2296 tst = AFSVolDeleteVolume(toconn,totid);
2298 goto fail_UV_RestoreVolume;
2300 tst = AFSVolEndTrans(toconn, totid, &rcode);
2302 if (!tst) tst = rcode;
2304 goto fail_UV_RestoreVolume;
2306 tst = AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,&pvolid, &totid);
2308 goto fail_UV_RestoreVolume;}
2310 tst = AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2312 goto fail_UV_RestoreVolume;
2316 cookie.parent = pvolid;
2317 cookie.type = RWVOL;
2319 strncpy(cookie.name,tovolname,VOLSER_OLDMAXVOLNAME);
2321 tocall = rx_NewCall(toconn);
2322 tst = StartAFSVolRestore(tocall,totid, 1,&cookie);
2324 goto fail_UV_RestoreVolume;
2326 tst = WriteData(tocall, dumpFile);
2328 goto fail_UV_RestoreVolume;
2330 tst = rx_EndCall(tocall,rxError);
2331 tocall = (struct rx_call *) 0;
2333 goto fail_UV_RestoreVolume;
2335 tst = AFSVolGetStatus(toconn,totid, &tstatus);
2337 goto fail_UV_RestoreVolume;
2339 tst = AFSVolSetIdsTypes(toconn,totid, tovolname, RWVOL, pvolid,0,0);
2341 goto fail_UV_RestoreVolume;
2344 tst = AFSVolSetDate(toconn,totid, newDate);
2346 goto fail_UV_RestoreVolume;
2349 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2350 tst = AFSVolSetFlags(toconn, totid, volflag);
2352 goto fail_UV_RestoreVolume;
2355 /* It isn't handled right in fail_UV_RestoreVolume */
2356 tst = AFSVolEndTrans(toconn, totid, &rcode);
2358 if(!tst) tst = rcode;
2360 goto fail_UV_RestoreVolume;
2364 if (success && (!reuseID || (flags & RV_FULLRST))) {
2365 /* Volume was restored on the file server, update the
2366 * VLDB to reflect the change.
2368 VLDB_GetEntryByID(cellHandle, pvolid, RWVOL, &entry, &tst);
2369 if(tst && tst != VL_NOENT && tst != VL_ENTDELETED) {
2370 goto fail_UV_RestoreVolume;
2372 if(tst == VL_NOENT) { /* it doesnot exist already */
2373 /*make the vldb return this indication specifically*/
2374 strcpy(entry.name, tovolname);
2376 entry.serverNumber[0] = toserver;/*should be indirect */
2377 entry.serverPartition[0] = topart;
2378 entry.serverFlags[0] = ITSRWVOL;
2379 entry.flags = RW_EXISTS;
2380 if(tstatus.cloneID != 0){
2381 entry.volumeId[ROVOL] = tstatus.cloneID;/*this should come from status info on the volume if non zero */
2384 entry.volumeId[ROVOL] = INVALID_BID;
2385 entry.volumeId[RWVOL] = pvolid;
2387 if(tstatus.backupID != 0){
2388 entry.volumeId[BACKVOL] = tstatus.backupID;
2389 /*this should come from status info on the volume if non zero */
2392 entry.volumeId[BACKVOL] = INVALID_BID;
2393 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
2394 goto fail_UV_RestoreVolume;
2398 else { /*update the existing entry */
2399 tst = ubik_Call(VL_SetLock,cellHandle->vos, 0, pvolid, RWVOL, VLOP_RESTORE);
2401 goto fail_UV_RestoreVolume;
2404 strcpy(entry.name, tovolname);
2406 /* Update the vlentry with the new information */
2407 index = Lp_GetRwIndex(cellHandle, &entry, 0);
2409 /* Add the rw site for the volume being restored */
2410 entry.serverNumber[entry.nServers] = toserver;
2411 entry.serverPartition[entry.nServers] = topart;
2412 entry.serverFlags[entry.nServers] = ITSRWVOL;
2415 /* This volume should be deleted on the old site
2416 * if its different from new site.
2418 VLDB_IsSameAddrs(cellHandle, toserver, entry.serverNumber[index], &same, &tst);
2419 if ( (!tst && !same) || (entry.serverPartition[index] != topart) ) {
2420 tempconn = UV_Bind(cellHandle, entry.serverNumber[index], AFSCONF_VOLUMEPORT);
2421 tst = AFSVolTransCreate(tempconn, pvolid, entry.serverPartition[index], ITOffline, &temptid);
2423 tst = AFSVolSetFlags(tempconn, temptid, VTDeleteOnSalvage | VTOutOfService);
2425 goto fail_UV_RestoreVolume;
2427 tst = AFSVolDeleteVolume(tempconn,temptid);
2429 goto fail_UV_RestoreVolume;
2431 tst = AFSVolEndTrans(tempconn, temptid, &rcode);
2433 if(!tst) tst = rcode;
2435 goto fail_UV_RestoreVolume;
2437 vos_PartitionIdToName(entry.serverPartition[index],partName, &tst);
2440 entry.serverNumber[index] = toserver;
2441 entry.serverPartition[index] = topart;
2444 entry.flags |= RW_EXISTS;
2445 if (!VLDB_ReplaceEntry(cellHandle, pvolid, RWVOL, &entry,
2446 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2447 goto fail_UV_RestoreVolume;
2454 fail_UV_RestoreVolume:
2457 etst = rx_EndCall(tocall, rxError);
2458 if (!tst) tst = etst;
2461 etst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, pvolid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2463 if(!tst) tst = etst;
2467 etst = AFSVolEndTrans(toconn, totid, &rcode);
2468 if(!etst) etst = rcode;
2470 if(!tst) tst = etst;
2474 etst = AFSVolEndTrans(toconn, temptid, &rcode);
2475 if(!etst) etst = rcode;
2477 if(!tst) tst = etst;
2481 if(tempconn) rx_ReleaseCachedConnection(tempconn);
2482 if(toconn) rx_ReleaseCachedConnection(toconn);
2490 /*adds <server> and <part> as a readonly replication site for <volid>
2493 afs_cell_handle_p cellHandle,
2500 afs_status_t tst = 0;
2501 int j, nro=0, islocked=0;
2502 struct nvldbentry entry;
2506 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,volid,RWVOL, VLOP_ADDSITE);
2508 goto fail_UV_AddSite;
2512 if (!VLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2513 goto fail_UV_AddSite;
2515 if (!ISNAMEVALID(entry.name)){
2517 goto fail_UV_AddSite;
2520 /* See if it's too many entries */
2521 if (entry.nServers >= NMAXNSERVERS){
2523 goto fail_UV_AddSite;
2526 /* See if it's on the same server */
2527 for (j=0; j < entry.nServers; j++) {
2528 if (entry.serverFlags[j] & ITSROVOL) {
2530 if (!VLDB_IsSameAddrs(cellHandle, server, entry.serverNumber[j], &same, &tst)) {
2531 goto fail_UV_AddSite;
2535 goto fail_UV_AddSite;
2540 /* See if it's too many RO sites - leave one for the RW */
2541 if (nro >= NMAXNSERVERS-1){
2543 goto fail_UV_AddSite;
2546 entry.serverNumber[entry.nServers] = server;
2547 entry.serverPartition[entry.nServers] = part;
2548 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
2551 if (!VLDB_ReplaceEntry(cellHandle, volid, RWVOL, &entry,
2552 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP,
2554 goto fail_UV_AddSite;
2562 tst = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0, volid, RWVOL,
2563 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2572 /*removes <server> <part> as read only site for <volid> from the vldb */
2574 afs_cell_handle_p cellHandle,
2581 afs_status_t tst = 0;
2582 struct nvldbentry entry;
2585 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,volid, RWVOL, VLOP_ADDSITE);
2587 goto fail_UV_RemoveSite;
2591 if (!VLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2592 goto fail_UV_RemoveSite;
2594 if (!Lp_ROMatch(cellHandle, &entry, server, part, &tst)) {
2595 /*this site doesnot exist */
2596 goto fail_UV_RemoveSite;
2598 else { /*remove the rep site */
2599 Lp_SetROValue(cellHandle, &entry, server, part, 0, 0);
2601 if((entry.nServers == 1) && (entry.flags & RW_EXISTS))
2602 entry.flags &= ~RO_EXISTS;
2603 if(entry.nServers < 1) { /*this is the last ref */
2604 tst = ubik_Call(VL_DeleteEntry, cellHandle->vos, 0,volid, ROVOL);
2606 goto fail_UV_RemoveSite;
2609 if (!VLDB_ReplaceEntry(cellHandle, volid, RWVOL, &entry,
2610 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
2612 goto fail_UV_RemoveSite;
2621 t = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0, volid, RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2633 /*list all the partitions on <aserver> */
2634 int UV_ListPartitions(
2635 struct rx_connection *server,
2636 struct partList *ptrPartList,
2641 afs_status_t tst = 0;
2642 struct pIDs partIds;
2643 struct partEntries partEnts;
2644 register int i, j=0;
2648 partEnts.partEntries_len = 0;
2649 partEnts.partEntries_val = (afs_int32 *)0;
2650 /* this is available only on new servers */
2651 tst = AFSVolXListPartitions(server, &partEnts);
2653 /* next, try old interface */
2654 if (tst == RXGEN_OPCODE)
2656 for(i = 0; i < 26; i++)
2657 partIds.partIds[i] = -1;
2658 tst = AFSVolListPartitions(server, &partIds);
2660 for (i = 0;i < 26; i++) {
2661 if((partIds.partIds[i]) != -1) {
2662 ptrPartList->partId[j] = partIds.partIds[i];
2663 ptrPartList->partFlags[j] = PARTVALID;
2666 ptrPartList->partFlags[i] = 0;
2670 goto fail_UV_ListPartitions;
2675 *cntp = partEnts.partEntries_len;
2676 if (*cntp > VOLMAXPARTS) {
2677 *cntp = VOLMAXPARTS;
2679 for (i = 0;i < *cntp; i++) {
2680 ptrPartList->partId[i] = partEnts.partEntries_val[i];
2681 ptrPartList->partFlags[i] = PARTVALID;
2683 free(partEnts.partEntries_val);
2685 goto fail_UV_ListPartitions;
2689 fail_UV_ListPartitions:
2697 /*------------------------------------------------------------------------
2698 * EXPORTED UV_XListVolumes
2701 * List the extended information for all the volumes on a particular
2702 * File Server and partition. We may either return the volume's ID
2703 * or all of its extended information.
2706 * a_serverID : Address of the File Server for which we want
2707 * extended volume info.
2708 * a_partID : Partition for which we want the extended
2710 * a_all : If non-zero, fetch ALL the volume info,
2711 * otherwise just the volume ID.
2712 * a_resultPP : Ptr to the address of the area containing
2713 * the returned volume info.
2714 * a_numEntsInResultP : Ptr for the value we set for the number of
2719 * Otherise, the return value of AFSVolXListVolumes.
2722 * This routine is closely related to UV_ListVolumes, which returns
2723 * only the standard level of detail on AFS volumes. It is a
2724 * heavyweight operation, zipping through all the volume entries for
2725 * a given server/partition.
2729 *------------------------------------------------------------------------*/
2731 int UV_XListVolumes(
2732 struct rx_connection *server,
2735 struct volintXInfo **a_resultPP,
2736 afs_int32 *a_numEntsInResultP,
2740 afs_status_t tst = 0;
2742 volXEntries volumeXInfo; /*Area for returned extended vol info*/
2745 * Set up our error code and the area for returned extended volume info.
2746 * We set the val field to a null pointer as a hint for the stub to
2749 *a_numEntsInResultP = 0;
2750 *a_resultPP = (volintXInfo *)0;
2751 volumeXInfo.volXEntries_val = (volintXInfo *)0;
2752 volumeXInfo.volXEntries_len = 0;
2755 * Bind to the Volume Server port on the File Server machine in question,
2758 tst = AFSVolXListVolumes(server, a_partID, a_all, &volumeXInfo);
2760 goto fail_UV_XListVolumes;
2763 * We got the info; pull out the pointer to where the results lie
2764 * and how many entries are there.
2766 *a_resultPP = volumeXInfo.volXEntries_val;
2767 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
2771 fail_UV_XListVolumes:
2779 /*------------------------------------------------------------------------
2780 * EXPORTED UV_XListOneVolume
2783 * List the extended information for a volume on a particular File
2784 * Server and partition.
2787 * server : a handle to the server where the volume resides.
2788 * a_partID : Partition for which we want the extended
2790 * a_volID : Volume ID for which we want the info.
2791 * a_resultPP : Ptr to the address of the area containing
2792 * the returned volume info.
2796 * Otherise, the return value of AFSVolXListOneVolume.
2799 * This routine is closely related to UV_ListOneVolume, which returns
2800 * only the standard level of detail on the chosen AFS volume.
2804 *------------------------------------------------------------------------*/
2806 int UV_XListOneVolume(
2807 struct rx_connection *server,
2810 struct volintXInfo **a_resultPP,
2814 afs_status_t tst = 0;
2815 volXEntries volumeXInfo; /*Area for returned info*/
2818 * Set the area we're in which we are returning
2819 * the info. Setting the val field to a null pointer tells the stub
2820 * to allocate space for us.
2822 *a_resultPP = (volintXInfo *)0;
2823 volumeXInfo.volXEntries_val = (volintXInfo *)0;
2824 volumeXInfo.volXEntries_len = 0;
2826 tst = AFSVolXListOneVolume(server, a_partID, a_volID, &volumeXInfo);
2829 goto fail_UV_XListOneVolume;
2833 * We got the info; pull out the pointer to where the results lie.
2835 *a_resultPP = volumeXInfo.volXEntries_val;
2839 fail_UV_XListOneVolume:
2846 } /*UV_XListOneVolume*/
2848 /*sync vldb with all the entries on <myQueue> on <aserver> and <apart>*/
2849 static afs_int32 ProcessEntries(
2850 afs_cell_handle_p cellHandle,
2851 struct qHead *myQueue,
2852 struct rx_connection *server,
2857 int success, temp,temp1,temp2;
2858 afs_int32 vcode, maxVolid = 0;
2859 struct nvldbentry entry;
2860 int noError = 1, error, same;
2861 int totalC,totalU,totalCE,totalUE,totalG;
2863 int aserver = ntohl(rx_HostOf(rx_PeerOf(server)));
2866 totalC = totalU = totalCE = totalUE = totalG = 0;
2869 /* get the next available id's from the vldb server */
2870 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, 0, &maxVolid);
2874 totalG = myQueue->count;
2875 if(totalG == 0) return 0;
2877 Lp_QEnumerate(myQueue, &success, &elem, 0);
2878 if (!success) break;
2881 if(!elem.isValid[RWVOL] && !elem.isValid[ROVOL] && !elem.isValid[BACKVOL]){ /*something is wrong with elem */
2885 if(maxVolid <= elem.ids[RWVOL]){
2887 temp2 = elem.ids[RWVOL] - maxVolid + 1 ;
2889 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, temp2, &maxVolid);
2894 if(maxVolid <= elem.ids[ROVOL]){
2897 temp2 = elem.ids[ROVOL] - maxVolid + 1;
2899 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, temp2, &maxVolid);
2903 if(maxVolid <= elem.ids[BACKVOL]){
2905 temp2 = elem.ids[BACKVOL] - temp1 + 1;
2907 vcode = ubik_Call(VL_GetNewVolumeId,cellHandle->vos, 0, temp2, &maxVolid);
2911 VLDB_GetEntryByID(cellHandle, elem.ids[RWVOL], RWVOL, &entry, &tst);
2912 if(tst && (tst != VL_NOENT)){
2916 else if(tst && (tst == VL_NOENT)) { /*entry doesnot exist */
2917 /*set up a vldb entry for elem */
2918 bzero(&entry, sizeof(entry));
2919 strncpy(entry.name,elem.name,VOLSER_OLDMAXVOLNAME);
2920 if(elem.isValid[RWVOL]) { /*rw exists */
2921 entry.flags |= RW_EXISTS;
2922 entry.serverFlags[entry.nServers] = ITSRWVOL;
2923 entry.serverNumber[entry.nServers] = aserver;
2924 entry.serverPartition[entry.nServers] = apart;
2925 entry.nServers += 1;
2926 entry.volumeId[RWVOL] = elem.ids[RWVOL];
2927 entry.volumeId[ROVOL] = elem.ids[ROVOL];
2928 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
2930 if(elem.isValid[ROVOL]) { /*ro volume exists */
2931 entry.flags |= RO_EXISTS;
2932 entry.serverFlags[entry.nServers] = ITSROVOL;
2933 entry.serverNumber[entry.nServers] = aserver;
2934 entry.serverPartition[entry.nServers] = apart;
2935 entry.nServers += 1;
2936 entry.volumeId[RWVOL] = elem.ids[RWVOL];
2937 entry.volumeId[ROVOL] = elem.ids[ROVOL];
2940 if(elem.isValid[BACKVOL]) { /*backup volume exists */
2941 entry.flags |= BACK_EXISTS;
2942 if(! (entry.flags & RW_EXISTS)) {/*this helps to check for a stray backup if parent moves */
2943 entry.serverFlags[entry.nServers] = ITSRWVOL;
2944 entry.serverNumber[entry.nServers] = aserver;
2945 entry.serverPartition[entry.nServers] = apart;
2946 entry.nServers += 1;
2949 entry.volumeId[RWVOL] = elem.ids[RWVOL];
2950 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
2953 VLDB_CreateEntry(cellHandle, &entry, &tst);
2961 else { /* Update the existing entry */
2962 strncpy(entry.name,elem.name,VOLSER_OLDMAXVOLNAME); /*the name Could have changed */
2964 if (elem.isValid[RWVOL]) { /* A RW volume */
2965 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
2967 /* A RW index is not found in the VLDB entry - will add it */
2969 entry.flags |= RW_EXISTS;
2970 entry.serverNumber[entry.nServers] = aserver;
2971 entry.serverPartition[entry.nServers] = apart;
2972 entry.serverFlags[entry.nServers] = ITSRWVOL;
2975 /* A RW index is found in the VLDB entry.
2976 * Verify that the volume location matches the VLDB location.
2977 * Fix the VLDB entry if it is not correct.
2980 error = VLDB_IsSameAddrs(cellHandle, aserver, entry.serverNumber[temp], &same, &tst);
2984 if (!same || (apart != entry.serverPartition[temp])) {
2985 /* VLDB says volume is in another place. Fix the VLDB entry */
2986 entry.serverNumber[temp] = aserver;
2987 entry.serverPartition[temp] = apart;
2990 entry.flags |= RW_EXISTS;
2992 if ((elem.ids[BACKVOL] != 0) && elem.isValid[BACKVOL])
2993 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
2994 if ((elem.ids[ROVOL] != 0) && elem.isValid[ROVOL])
2995 entry.volumeId[ROVOL] = elem.ids[ROVOL];
2998 if (elem.isValid[ROVOL]) {
2999 /*tackle a ro volume */
3001 if(!Lp_ROMatch(cellHandle, &entry, aserver, apart, 0)){
3003 if(elem.ids[ROVOL] > entry.volumeId[ROVOL]) {
3004 /*there is a conflict of ids, keep the later volume */
3005 /*delete all the ro volumes listed in vldb entry since they
3008 int j,count, rwsite;
3011 count = entry.nServers;
3013 for(j = 0 ; j < count; j++){
3014 if(entry.serverFlags[j] & ITSROVOL){
3016 /*delete the site */
3017 entry.serverNumber[j] = 0;
3018 entry.serverPartition[j] = 0;
3019 entry.serverFlags[j] = 0;
3022 else if( entry.serverFlags[j] & ITSRWVOL)
3027 entry.serverNumber[entry.nServers] = entry.serverNumber[rwsite];
3028 entry.serverPartition[entry.nServers] = entry.serverPartition[rwsite];
3029 entry.serverFlags[entry.nServers] = entry.serverFlags[rwsite];
3032 entry.serverNumber[entry.nServers] = aserver;
3033 entry.serverPartition[entry.nServers] = apart;
3034 entry.serverFlags[entry.nServers] = ITSROVOL;
3036 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3037 entry.flags |= RO_EXISTS;
3040 else if (elem.ids[ROVOL] < entry.volumeId[ROVOL] ){
3041 if(!(entry.flags & RO_EXISTS)) {
3042 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3043 entry.serverNumber[entry.nServers] = aserver;
3044 entry.serverPartition[entry.nServers] = apart;
3045 entry.serverFlags[entry.nServers] = ITSROVOL;
3047 entry.flags |= RO_EXISTS;
3052 else if (elem.ids[ROVOL] == entry.volumeId[ROVOL]){
3053 entry.serverNumber[entry.nServers] = aserver;
3054 entry.serverPartition[entry.nServers] = apart;
3055 entry.serverFlags[entry.nServers] = ITSROVOL;
3057 entry.flags |= RO_EXISTS;
3058 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3061 if(entry.volumeId[ROVOL] == INVALID_BID)
3062 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3065 if (elem.isValid[BACKVOL]) {
3066 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3067 if(temp != -1) { /*check if existing backup site matches with the given arguments */
3068 error = VLDB_IsSameAddrs(cellHandle, aserver, entry.serverNumber[temp], &same, &tst);
3074 /*tackle the backup volume */
3075 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3076 entry.flags |= BACK_EXISTS;
3078 if(entry.volumeId[BACKVOL] == INVALID_BID)
3079 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3082 VLDB_ReplaceEntry(cellHandle, elem.ids[RWVOL], RWVOL,
3084 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP,
3090 vcode = ubik_Call(VL_ReleaseLock,cellHandle->vos, 0,
3091 elem.ids[RWVOL], RWVOL,
3092 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3097 } /* else update the existing entry */
3099 } /* End of while(1) */
3101 if(noError) return 0;
3102 else return VOLSERBADOP;
3105 /*synchronise vldb with the file server <aserver> and <apart>(if flags=1).
3106 *else synchronise with all the valid partitions on <aserver>
3109 afs_cell_handle_p cellHandle,
3110 struct rx_connection *server,
3117 afs_status_t tst = 0;
3120 volEntries volumeInfo;
3122 struct qHead myQueue;
3123 struct partList PartList;
3128 /*this hints the stub to allocate space*/
3129 volumeInfo.volEntries_val = (volintInfo *)0;
3130 volumeInfo.volEntries_len = 0;
3132 if(!flags) {/*generate all the valid partitions */
3133 UV_ListPartitions(server, &PartList, &cnt, &tst);
3135 goto fail_UV_SyncVldb;
3138 PartList.partId[0] = apart;
3142 for(i = 0;i < cnt; i++) {
3143 apart = PartList.partId[i];
3144 /*this hints the stub to allocate space*/
3145 volumeInfo.volEntries_val = (volintInfo *)0;
3146 volumeInfo.volEntries_len = 0;
3147 tst = AFSVolListVolumes(server, apart, 1, &volumeInfo);
3149 goto fail_UV_SyncVldb;
3151 count = volumeInfo.volEntries_len;
3152 pntr = volumeInfo.volEntries_val;
3154 if (!vos_PartitionIdToName(apart,pname,&tst)) {
3155 goto fail_UV_SyncVldb;
3157 /*collect all vol entries by their parentid */
3158 tst = GroupEntries(server, pntr, count, &myQueue, apart);
3161 if (volumeInfo.volEntries_val) {
3162 /*free the space allocated by the stub */
3163 free(volumeInfo.volEntries_val);
3164 volumeInfo.volEntries_val = 0;
3168 tst = ProcessEntries(cellHandle, &myQueue, server, apart, force);
3170 tst = VOLSERFAILEDOP;
3171 if (volumeInfo.volEntries_val) {
3172 /*free the space allocated by the stub */
3173 free(volumeInfo.volEntries_val);
3174 volumeInfo.volEntries_val = 0;
3178 if(noError) tst = 0;
3179 else tst = VOLSERFAILEDOP;
3180 }/* thru all partitions */
3185 if (volumeInfo.volEntries_val) free(volumeInfo.volEntries_val);
3197 static afs_int32 CheckVldbRWBK(
3198 afs_cell_handle_p cellHandle,
3199 struct nvldbentry *entry,
3200 afs_int32 *modified,
3204 afs_status_t tst = 0;
3207 afs_int32 error = 0;
3209 if (modified) *modified = 0;
3210 idx = Lp_GetRwIndex(cellHandle, entry, 0);
3212 /* Check to see if the RW volume exists and set the RW_EXISTS
3215 if (idx == -1) { /* Did not find a RW entry */
3216 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
3217 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
3221 if (VolumeExists(cellHandle,
3222 entry->serverNumber[idx],
3223 entry->serverPartition[idx],
3224 entry->volumeId[RWVOL], &tst)) {
3225 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does no
3227 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
3231 else if (tst == ENODEV) { /* RW volume does not exist */
3232 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists
3234 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist
3240 /* If VLDB says it didn't exist, then ignore error */
3241 if (entry->flags & RW_EXISTS) {
3242 goto fail_CheckVldbRWBK;
3247 /* Check to see if the BK volume exists and set the BACK_EXISTS
3248 * flag accordingly. idx already ponts to the RW entry.
3250 if (idx == -1) { /* Did not find a RW entry */
3251 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
3252 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
3256 else { /* Found a RW entry */
3257 if (VolumeExists(cellHandle, entry->serverNumber[idx],
3258 entry->serverPartition[idx],
3259 entry->volumeId[BACKVOL], &tst)) {
3260 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does n
3262 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
3266 else if (tst == ENODEV) { /* BK volume does not exist */
3267 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists
3269 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist
3275 /* If VLDB says it didn't exist, then ignore error */
3276 if (entry->flags & BACK_EXISTS) {
3277 goto fail_CheckVldbRWBK;
3282 /* If there is an idx but the BK and RW volumes no
3283 * longer exist, then remove the RW entry.
3285 if ((idx != -1) && !(entry->flags & RW_EXISTS) &&
3286 !(entry->flags & BACK_EXISTS)) {
3287 Lp_SetRWValue(cellHandle, entry, entry->serverNumber[idx],
3288 entry->serverPartition[idx], 0L, 0L);
3296 if (modified) *modified = modentry;
3305 static int CheckVldbRO(
3306 afs_cell_handle_p cellHandle,
3307 struct nvldbentry *entry,
3308 afs_int32 *modified,
3312 afs_status_t tst = 0;
3314 int foundro = 0, modentry = 0;
3315 afs_int32 error = 0;
3317 if (modified) *modified = 0;
3319 /* Check to see if the RO volumes exist and set the RO_EXISTS
3322 for (idx=0; idx < entry->nServers; idx++) {
3323 if (!(entry->serverFlags[idx] & ITSROVOL)) {
3324 continue; /* not a RO */
3327 if(VolumeExists(cellHandle, entry->serverNumber[idx],
3328 entry->serverPartition[idx], entry->volumeId[ROVOL],
3331 } else if (tst == ENODEV) { /* RW volume does not exist */
3332 Lp_SetROValue(cellHandle, entry, entry->serverNumber[idx],
3333 entry->serverPartition[idx], 0L, 0L);
3339 goto fail_CheckVldbRO;
3343 if (foundro) { /* A RO volume exists */
3344 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not e
3346 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
3349 } else { /* A RO volume does not exist */
3350 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
3351 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
3359 if (modified) *modified = modentry;
3367 /*ensure that <entry> matches with the info on file servers */
3369 afs_cell_handle_p cellHandle,
3370 struct nvldbentry *entry,
3371 afs_int32 *modified,
3375 afs_status_t tst = 0;
3378 struct rx_connection *server = NULL;
3380 afs_int32 modentry = 0;
3381 afs_int32 delentry = 0;
3387 if(strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
3389 goto fail_CheckVldb;
3394 /* Check to see if the VLDB is ok without locking it (pass 1).
3395 * If it will change, then lock the VLDB entry, read it again,
3396 * then make the changes to it (pass 2).
3399 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0,
3400 entry->volumeId[RWVOL], RWVOL, VLOP_DELETE);
3402 goto fail_CheckVldb;
3406 if (!VLDB_GetEntryByID(cellHandle, entry->volumeId[RWVOL], RWVOL,
3408 goto fail_CheckVldb;
3414 /* Check if the RW and BK entries are ok */
3415 if (!CheckVldbRWBK(cellHandle, entry, &modentry, &tst)) {
3416 goto fail_CheckVldb;
3418 if (modentry && (pass == 1)) goto retry;
3420 /* Check if the RO volumes entries are ok */
3421 if (!CheckVldbRO(cellHandle, entry, &modentry, &tst)) {
3422 goto fail_CheckVldb;
3424 if (modentry && (pass == 1)) goto retry;
3426 /* The VLDB entry has been updated. If it as been modified, then
3427 * write the entry back out the the VLDB.
3430 if (pass == 1) goto retry;
3432 if (!(entry->flags & RW_EXISTS) &&
3433 !(entry->flags & BACK_EXISTS) &&
3434 !(entry->flags & RO_EXISTS)) {
3435 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
3436 tst = ubik_Call(VL_DeleteEntry, cellHandle->vos, 0,
3437 entry->volumeId[RWVOL], RWVOL);
3439 goto fail_CheckVldb;
3444 /* Replace old entry with our new one */
3445 if (!VLDB_ReplaceEntry(cellHandle, entry->volumeId[RWVOL], RWVOL,
3447 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
3448 goto fail_CheckVldb;
3451 if (modified) *modified = 1;
3459 vcode = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0,
3460 entry->volumeId[RWVOL], RWVOL,
3461 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
3464 if (!tst) tst = vcode;
3474 /*synchronise <aserver> <apart>(if flags = 1) with the vldb .
3475 *if flags = 0, synchronise all the valid partitions on <aserver>*/
3477 afs_cell_handle_p cellHandle,
3478 struct rx_connection *server,
3484 afs_status_t tst = 0;
3485 afs_int32 code, vcode;
3487 afs_int32 nentries, tentries = 0;
3488 struct VldbListByAttributes attributes;
3489 nbulkentries arrayEntries;
3491 register struct nvldbentry *vllist;
3494 afs_int32 modified = 0;
3499 arrayEntries.nbulkentries_val = 0;
3501 /* Set up attributes to search VLDB */
3502 attributes.server = ntohl(rx_HostOf(rx_PeerOf(server)));
3503 attributes.Mask = VLLIST_SERVER;
3505 attributes.partition = apart;
3506 attributes.Mask |= VLLIST_PARTITION;
3509 for(si = 0;si != -1; si=nsi) {
3510 /*initialize to hint the stub to alloc space */
3511 bzero(&arrayEntries, sizeof(arrayEntries));
3512 if (!VLDB_ListAttributes(cellHandle, &attributes, &nentries,
3513 &arrayEntries, &tst)) {
3514 goto fail_UV_SyncServer;
3517 tentries += nentries;
3519 for(j=0;j<nentries;j++) { /* process each entry */
3520 vllist = &arrayEntries.nbulkentries_val[j];
3521 if (!CheckVldb(cellHandle, vllist, &modified, &tst)) {
3526 if(arrayEntries.nbulkentries_val) {
3527 free(arrayEntries.nbulkentries_val);
3528 arrayEntries.nbulkentries_val = 0;
3535 if(arrayEntries.nbulkentries_val) {
3536 free(arrayEntries.nbulkentries_val);
3538 if(!noError) tst = VOLSERFAILEDOP;
3545 /*rename volume <oldname> to <newname>, changing the names of the related
3546 *readonly and backup volumes. This operation is also idempotent.
3547 *salvager is capable of recovering from rename operation stopping halfway.
3548 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
3549 int UV_RenameVolume(
3550 afs_cell_handle_p cellHandle,
3551 struct nvldbentry *entry,
3552 const char *newname,
3556 afs_status_t tst = 0;
3557 afs_status_t etst = 0;
3558 afs_int32 rcode,error;
3560 char nameBuffer[256];
3562 struct rx_connection *aconn;
3566 aconn = (struct rx_connection *)0;
3570 tst = ubik_Call(VL_SetLock, cellHandle->vos, 0, entry->volumeId[RWVOL],
3571 RWVOL, VLOP_ADDSITE);/*last param is dummy*/
3573 goto fail_UV_RenameVolume;
3577 strncpy(entry->name,newname,VOLSER_OLDMAXVOLNAME);
3579 if (!VLDB_ReplaceEntry(cellHandle, entry->volumeId[RWVOL], RWVOL,
3581 goto fail_UV_RenameVolume;
3583 /*at this stage the intent to rename is recorded in the vldb, as far
3585 is concerned, oldname is lost */
3586 if(entry->flags & RW_EXISTS) {
3587 index = Lp_GetRwIndex(cellHandle, entry, 0);
3588 if(index == -1){ /* there is a serious discrepancy */
3589 tst = VOLSERVLDB_ERROR;
3590 goto fail_UV_RenameVolume;
3592 aconn = UV_Bind(cellHandle, entry->serverNumber[index],
3593 AFSCONF_VOLUMEPORT);
3594 tst = AFSVolTransCreate(aconn,entry->volumeId[RWVOL],entry->serverPartition[index], ITOffline, &tid);
3595 if(tst) { /*volume doesnot exist */
3596 goto fail_UV_RenameVolume;
3598 else {/*volume exists, process it */
3600 tst = AFSVolSetIdsTypes(aconn, tid, newname,RWVOL, entry->volumeId[RWVOL],entry->volumeId[ROVOL],entry->volumeId[BACKVOL]);
3602 tst = AFSVolEndTrans(aconn, tid, &rcode);
3605 goto fail_UV_RenameVolume;
3609 goto fail_UV_RenameVolume;
3612 if(aconn) rx_ReleaseCachedConnection(aconn);
3613 aconn = (struct rx_connection *)0;
3614 } /*end rw volume processing */
3616 if(entry->flags & BACK_EXISTS) {/*process the backup volume */
3617 index = Lp_GetRwIndex(cellHandle, entry, 0);
3618 if(index == -1){ /* there is a serious discrepancy */
3619 tst = VOLSERVLDB_ERROR;
3620 goto fail_UV_RenameVolume;
3622 aconn = UV_Bind(cellHandle, entry->serverNumber[index],
3623 AFSCONF_VOLUMEPORT);
3624 tst = AFSVolTransCreate(aconn,entry->volumeId[BACKVOL],entry->serverPartition[index], ITOffline, &tid);
3625 if(tst) { /*volume doesnot exist */
3626 goto fail_UV_RenameVolume;
3628 else {/*volume exists, process it */
3629 if(strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)){
3630 goto fail_UV_RenameVolume;
3632 strcpy(nameBuffer,newname);
3633 strcat(nameBuffer,".backup");
3635 tst = AFSVolSetIdsTypes(aconn, tid,nameBuffer ,BACKVOL, entry->volumeId[RWVOL],0,0);
3637 tst = AFSVolEndTrans(aconn, tid, &rcode);
3640 goto fail_UV_RenameVolume;
3644 goto fail_UV_RenameVolume;
3647 } /* end backup processing */
3648 if(aconn) rx_ReleaseCachedConnection(aconn);
3649 aconn = (struct rx_connection *)0;
3650 if(entry->flags & RO_EXISTS){ /*process the ro volumes */
3651 for(i = 0; i < entry->nServers; i++){
3652 if(entry->serverFlags[i] & ITSROVOL) {
3653 aconn = UV_Bind(cellHandle, entry->serverNumber[i],
3654 AFSCONF_VOLUMEPORT);
3655 tst = AFSVolTransCreate(aconn,entry->volumeId[ROVOL],entry->serverPartition[i], ITOffline, &tid);
3656 if(tst) { /*volume doesnot exist */
3657 goto fail_UV_RenameVolume;
3659 else {/*volume exists, process it */
3660 strcpy(nameBuffer,newname);
3661 strcat(nameBuffer,".readonly");
3662 if(strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)){
3663 goto fail_UV_RenameVolume;
3665 tst = AFSVolSetIdsTypes(aconn, tid, nameBuffer,ROVOL, entry->volumeId[RWVOL],0,0);
3667 tst = AFSVolEndTrans(aconn, tid, &rcode);
3670 goto fail_UV_RenameVolume;
3674 goto fail_UV_RenameVolume;
3677 if(aconn) rx_ReleaseCachedConnection(aconn);
3678 aconn = (struct rx_connection *)0;
3684 fail_UV_RenameVolume:
3687 etst = ubik_Call(VL_ReleaseLock, cellHandle->vos, 0,entry->volumeId[RWVOL] , RWVOL, LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3689 if(!tst) tst = etst;
3693 etst = AFSVolEndTrans(aconn, tid, &rcode);
3695 if(!tst) tst = etst;
3698 if(aconn) rx_ReleaseCachedConnection(aconn);
3706 /*group all the volume entries on< apart >by their parentid or by their ids'
3707 *if the volume is rw. <count> is the number of entries to be processesd.
3708 *<pntr> points to the first entry.< myQueue> is the queue with entries
3710 static int GroupEntries(
3711 struct rx_connection *server,
3714 struct qHead *myQueue,
3717 struct aqueue *qPtr;
3719 afs_int32 curId, code;
3721 afs_int32 error = 0;
3727 for(i = 0; i < count; i++){/*process each entry */
3728 if(pntr->status) {/* entry is valid */
3729 if(pntr->type == RWVOL) curId = pntr->volid;
3730 else curId = pntr->parentID;
3731 Lp_QScan(myQueue,curId, &success, &qPtr, 0);
3732 if(success){ /*entry exists in the queue */
3733 if(pntr->type == RWVOL) {
3734 /*check if the rw exists already, if so hang on the
3735 later version if the present version is ok */
3736 if(qPtr->isValid[RWVOL]) {
3737 /*this should not happen, there is a serious error here*/
3738 if(!error) error = VOLSERMULTIRWVOL;
3741 qPtr->isValid[RWVOL] = 1;
3742 qPtr->copyDate[RWVOL] = pntr->copyDate;
3743 if(!qPtr->isValid[BACKVOL]) qPtr->ids[BACKVOL] = pntr->backupID;
3744 if(!qPtr->isValid[ROVOL]) qPtr->ids[ROVOL] = pntr->cloneID;
3747 else if(pntr->type == BACKVOL) {
3748 if(qPtr->isValid[BACKVOL]){
3749 /*do different checks, delete superflous volume */
3750 if(qPtr->copyDate[BACKVOL] > pntr->copyDate) {
3751 /*delete the present volume .*/
3752 code = CheckAndDeleteVolume(server,apart,0,pntr->volid);
3754 if(!error) error = code;
3759 /*delete the older volume after making sure, current one is ok*/
3760 code = CheckAndDeleteVolume(server,apart,pntr->volid,qPtr->ids[BACKVOL]);
3762 if(!error) error = code;
3765 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3766 qPtr->ids[BACKVOL] = pntr->volid;
3771 qPtr->isValid[BACKVOL] = 1;
3772 qPtr->ids[BACKVOL] = pntr->volid;
3773 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3776 else if(pntr->type == ROVOL) {
3777 if(qPtr->isValid[ROVOL]){
3778 /*do different checks, delete superflous volume */
3779 if(qPtr->copyDate[ROVOL] > pntr->copyDate) {
3780 /*delete the present volume .*/
3782 code = CheckAndDeleteVolume(server,apart,0,pntr->volid);
3784 if(!error) error = code;
3788 /*delete the older volume after making sure, current one is ok*/
3789 code = CheckAndDeleteVolume(server,apart,pntr->volid,qPtr->ids[ROVOL]);
3791 if(!error) error = code;
3794 qPtr->copyDate[ROVOL] = pntr->copyDate;
3795 qPtr->ids[ROVOL] = pntr->volid;
3800 qPtr->isValid[ROVOL] = 1;
3801 qPtr->ids[ROVOL] = pntr->volid;
3802 qPtr->copyDate[ROVOL] = pntr->copyDate;
3806 if(!error) error = VOLSERBADOP;
3809 else { /*create a fresh entry */
3810 qPtr = (struct aqueue *) malloc(sizeof(struct aqueue));
3811 if(pntr->type == RWVOL) {
3812 qPtr->isValid[RWVOL] = 1;
3813 qPtr->isValid[BACKVOL] = 0;
3814 qPtr->isValid[ROVOL] = 0;
3815 qPtr->ids[RWVOL] = pntr->volid;
3816 qPtr->ids[BACKVOL] = pntr->backupID;
3817 qPtr->ids[ROVOL] = pntr->cloneID;
3818 qPtr->copyDate[RWVOL] = pntr->copyDate;
3819 strncpy(qPtr->name, pntr->name,VOLSER_OLDMAXVOLNAME);
3820 qPtr->next = (struct aqueue *)0;
3822 else if(pntr->type == BACKVOL) {
3823 qPtr->isValid[RWVOL] = 0;
3824 qPtr->isValid[BACKVOL] = 1;
3825 qPtr->isValid[ROVOL] = 0;
3826 qPtr->ids[RWVOL] = pntr->parentID;
3827 qPtr->ids[BACKVOL] = pntr->volid;
3828 qPtr->ids[ROVOL] = 0;
3829 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3830 vsu_ExtractName(qPtr->name, pntr->name);
3831 qPtr->next = (struct aqueue *)0;
3833 else if(pntr->type == ROVOL) {
3834 qPtr->isValid[RWVOL] = 0;
3835 qPtr->isValid[BACKVOL] = 0;
3836 qPtr->isValid[ROVOL] = 1;
3837 qPtr->ids[RWVOL] = pntr->parentID;
3838 qPtr->ids[BACKVOL] = 0;
3839 qPtr->ids[ROVOL] = pntr->volid;
3840 qPtr->copyDate[ROVOL] = pntr->copyDate;
3841 vsu_ExtractName(qPtr->name, pntr->name);
3842 qPtr->next = (struct aqueue *)0;
3845 Lp_QAdd(myQueue,qPtr);
3847 pntr++;/*get next entry */
3858 /*report on all the active transactions on volser */
3859 int UV_VolserStatus(
3860 struct rx_connection *server,
3861 transDebugInfo **rpntr,
3866 afs_status_t tst = 0;
3867 transDebugEntries transInfo;
3869 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
3870 transInfo.transDebugEntries_len = 0;
3871 tst = AFSVolMonitor(server,&transInfo);
3873 goto fail_UV_VolserStatus;
3876 *rcount = transInfo.transDebugEntries_len;
3877 *rpntr = transInfo.transDebugEntries_val;
3880 fail_UV_VolserStatus:
3883 if (transInfo.transDebugEntries_val) {
3884 free(transInfo.transDebugEntries_val);
3894 /*delete the volume without interacting with the vldb */
3896 afs_cell_handle_p cellHandle,
3897 struct rx_connection *server,
3898 unsigned int partition,
3899 unsigned int volumeId,
3902 afs_int32 rcode,ttid,error,code;
3904 afs_status_t tst = 0;
3910 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
3912 tst = AFSVolDeleteVolume(server, ttid);
3914 tst = AFSVolEndTrans(server, ttid, &rcode);
3922 * We failed to delete the volume, but we still need
3923 * to end the transaction.
3925 AFSVolEndTrans(server, ttid, &rcode);
3937 struct rx_connection *server,
3938 afs_int32 partition,
3940 afs_int32 transflag,
3942 unsigned int sleepTime,
3946 afs_status_t tst = 0;
3947 afs_status_t etst = 0;
3951 tst = AFSVolTransCreate(server, volid, partition, transflag, &tid);
3953 goto fail_UV_SetVolume;
3956 tst = AFSVolSetFlags(server, tid, setflag);
3958 goto fail_UV_SetVolume;
3969 etst = AFSVolEndTrans(server, tid, &rcode);
3971 if (!tst) tst = (etst ? etst : rcode);