2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * This file is a reimplementation of volser/vsproc.s. Every attempt
12 * has been made to keep it as similar as possible to aid comprehension
13 * of the code. For most functions, two parameters have been added
14 * the cell handle, and a status variable. For those functions that
15 * require one, a server handle may also be added.
17 * Other changes were made to provide thread safe functions and
18 * eliminate the practice of reporting errors to STDOUT.
21 #include <afsconfig.h>
22 #include <afs/param.h>
26 #include <afs/afs_AdminErrors.h>
30 #include "lockprocs.h"
31 #include "../adminutil/afs_AdminInternal.h"
32 #include "afs_vosAdmin.h"
34 static afs_int32 GroupEntries(struct rx_connection *server, volintInfo * pntr, afs_int32 count,
35 struct qHead *myQueue, afs_int32 apart);
39 afs_int32 vldbEntryIndex;
42 static struct rx_connection *
43 UV_Bind(afs_cell_handle_p cellHandle, afs_int32 aserver, afs_int32 port)
45 return rx_GetCachedConnection(htonl(aserver), htons(port), VOLSERVICE_ID,
46 cellHandle->tokens->afs_sc[cellHandle->
49 cellHandle->tokens->sc_index);
53 /* if <okvol> is allright(indicated by beibg able to
54 * start a transaction, delete the <delvol> */
56 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
57 afs_uint32 okvol, afs_uint32 delvol)
59 afs_int32 error, code, tid, rcode;
65 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
68 code = AFSVolDeleteVolume(aconn, tid);
71 code = AFSVolEndTrans(aconn, tid, &rcode);
78 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
80 code = AFSVolEndTrans(aconn, tid, &rcode);
85 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
88 code = AFSVolDeleteVolume(aconn, tid);
91 code = AFSVolEndTrans(aconn, tid, &rcode);
102 /* forcibly remove a volume. Very dangerous call */
104 UV_NukeVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
105 unsigned int partition, afs_uint32 volumeId, afs_status_p st)
108 afs_status_t tst = 0;
110 tst = AFSVolNukeVolume(server, partition, volumeId);
122 /* create a volume, given a server, partition number, volume name --> sends
123 * back new vol id in <anewid>*/
125 UV_CreateVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
126 unsigned int partition, char *volumeName,
127 unsigned int quota, afs_uint32 *volumeId, afs_status_p st)
130 afs_status_t tst = 0;
133 struct nvldbentry entry;
134 struct volintInfo tstatus;
136 memset(&tstatus, 0, sizeof(tstatus));
138 tstatus.maxquota = quota;
140 /* next the next 3 available ids from the VLDB */
141 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 3, volumeId);
143 goto fail_UV_CreateVolume;
147 AFSVolCreateVolume(server, partition, volumeName, volser_RW, 0,
150 goto fail_UV_CreateVolume;
153 AFSVolSetInfo(server, tid, &tstatus);
155 tst = AFSVolSetFlags(server, tid, 0);
157 goto fail_UV_CreateVolume;
160 /* set up the vldb entry for this volume */
161 strncpy(entry.name, volumeName, VOLSER_OLDMAXVOLNAME);
163 entry.serverNumber[0] = ntohl(rx_HostOf(rx_PeerOf(server)));
164 entry.serverPartition[0] = partition;
165 entry.flags = RW_EXISTS;
166 entry.serverFlags[0] = ITSRWVOL;
167 entry.volumeId[RWVOL] = *volumeId;
168 entry.volumeId[ROVOL] = *volumeId + 1;
169 entry.volumeId[BACKVOL] = *volumeId + 2;
172 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
173 AFSVolDeleteVolume(server, tid);
174 goto fail_UV_CreateVolume;
177 tst = AFSVolEndTrans(server, tid, &rcode);
180 goto fail_UV_CreateVolume;
184 fail_UV_CreateVolume:
187 AFSVolEndTrans(server, tid, &rcode);
197 /* Delete the volume <volid>on <aserver> <apart>
198 * the physical entry gets removed from the vldb only if the ref count
202 UV_DeleteVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
203 unsigned int partition, afs_uint32 volumeId,
207 afs_status_t tst = 0;
208 afs_status_t temp = 0;
209 int serverAddr = ntohl(rx_HostOf(rx_PeerOf(server)));
213 struct nvldbentry entry;
215 afs_int32 avoltype = -1, vtype;
216 int notondisk = 0, notinvldb = 0;
218 /* Find and read the VLDB entry for this volume */
220 ubik_VL_SetLock(cellHandle->vos, 0, volumeId, avoltype,
223 if (tst != VL_NOENT) {
224 goto fail_UV_DeleteVolume;
230 if (!aVLDB_GetEntryByID(cellHandle, volumeId, avoltype, &entry, &tst)) {
231 goto fail_UV_DeleteVolume;
236 /* Whether volume is in the VLDB or not. Delete the volume on disk */
237 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
242 goto fail_UV_DeleteVolume;
245 tst = AFSVolDeleteVolume(server, ttid);
247 goto fail_UV_DeleteVolume;
249 tst = AFSVolEndTrans(server, ttid, &rcode);
250 tst = (tst ? tst : rcode);
253 goto fail_UV_DeleteVolume;
258 goto fail_UV_DeleteVolume;
261 if (volumeId == entry.volumeId[BACKVOL]) {
262 if (!(entry.flags & BACK_EXISTS)
263 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
265 goto fail_UV_DeleteVolume;
268 entry.flags &= ~BACK_EXISTS;
272 else if (volumeId == entry.volumeId[ROVOL]) {
273 if (!Lp_ROMatch(cellHandle, &entry, serverAddr, partition, &tst)) {
275 goto fail_UV_DeleteVolume;
278 Lp_SetROValue(cellHandle, &entry, serverAddr, partition, 0, 0);
280 if (!Lp_ROMatch(cellHandle, &entry, 0, 0, &tst)) {
281 entry.flags &= ~RO_EXISTS;
286 else if (volumeId == entry.volumeId[RWVOL]) {
287 if (!(entry.flags & RW_EXISTS)
288 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
290 goto fail_UV_DeleteVolume;
293 /* Delete backup if it exists */
295 AFSVolTransCreate(server, entry.volumeId[BACKVOL], partition,
298 tst = AFSVolDeleteVolume(server, ttid);
300 goto fail_UV_DeleteVolume;
302 tst = AFSVolEndTrans(server, ttid, &rcode);
304 tst = (tst ? tst : rcode);
306 goto fail_UV_DeleteVolume;
310 Lp_SetRWValue(cellHandle, &entry, serverAddr, partition, 0L, 0L);
312 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
318 notinvldb = 2; /* Not found on this server and partition */
319 goto fail_UV_DeleteVolume;
322 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
323 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volumeId, vtype);
325 goto fail_UV_DeleteVolume;
328 if (!VLDB_ReplaceEntry
329 (cellHandle, volumeId, vtype, &entry,
330 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
331 goto fail_UV_DeleteVolume;
337 fail_UV_DeleteVolume:
339 if (notondisk && notinvldb) {
341 tst = ADMVOSVOLUMENOEXIST;
345 temp = AFSVolEndTrans(server, ttid, &rcode);
346 temp = (temp ? temp : rcode);
355 ubik_VL_ReleaseLock(cellHandle->vos, 0, volumeId, -1,
356 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
369 #define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto mfail; }
371 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
372 * <atopart>. The operation is almost idempotent
376 UV_MoveVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
377 afs_int32 afromserver, afs_int32 afrompart, afs_int32 atoserver,
378 afs_int32 atopart, afs_status_p st)
381 afs_status_t tst = 0;
382 afs_status_t etst = 0;
383 struct rx_connection *toconn, *fromconn;
384 afs_int32 fromtid, totid, clonetid;
387 char tmpName[VOLSER_MAXVOLNAME + 1];
390 struct restoreCookie cookie;
391 afs_uint32 newVol, volid, backupId;
392 struct volser_status tstatus;
393 struct destServer destination;
395 struct nvldbentry entry;
398 afs_int32 store_flags;
400 #ifdef ENABLE_BUGFIX_1165
401 volEntries volumeInfo;
402 struct volintInfo *infop = 0;
406 fromconn = (struct rx_connection *)0;
407 toconn = (struct rx_connection *)0;
415 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
416 goto fail_UV_MoveVolume;
419 if (entry.volumeId[RWVOL] != afromvol) {
420 tst = ADMVOSVOLUMEMOVERWONLY;
421 goto fail_UV_MoveVolume;
425 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL, VLOP_MOVE);
427 goto fail_UV_MoveVolume;
431 if (!aVLDB_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)) {
438 /* the from server and partition do not exist in the vldb entry corresponding to volid */
439 if (!Lp_Match(cellHandle, &entry, atoserver, atopart, &tst)) {
440 /* the to server and partition do not exist in the vldb entry corresponding to volid */
442 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
443 (LOCKREL_OPCODE | LOCKREL_AFSID |
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 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
463 if (!tst) { /* volume exists - delete it */
465 AFSVolSetFlags(fromconn, fromtid,
466 VTDeleteOnSalvage | VTOutOfService);
468 goto fail_UV_MoveVolume;
471 tst = AFSVolDeleteVolume(fromconn, fromtid);
473 goto fail_UV_MoveVolume;
476 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
481 goto fail_UV_MoveVolume;
485 /*delete the backup volume now */
488 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
490 if (!tst) { /* backup volume exists - delete it */
492 AFSVolSetFlags(fromconn, fromtid,
493 VTDeleteOnSalvage | VTOutOfService);
495 goto fail_UV_MoveVolume;
498 tst = AFSVolDeleteVolume(fromconn, fromtid);
500 goto fail_UV_MoveVolume;
503 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
508 goto fail_UV_MoveVolume;
513 goto fail_UV_MoveVolume;
516 /* From-info matches the vldb info about volid,
517 * its ok start the move operation, the backup volume
518 * on the old site is deleted in the process
520 if (afrompart == atopart) {
521 if (!VLDB_IsSameAddrs
522 (cellHandle, afromserver, atoserver, &same, &tst)) {
523 goto fail_UV_MoveVolume;
526 tst = VOLSERVOLMOVED;
527 goto fail_UV_MoveVolume;
531 toconn = UV_Bind(cellHandle, atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
532 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
533 fromtid = totid = 0; /* initialize to uncreated */
536 * clone the read/write volume locally.
539 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
541 goto fail_UV_MoveVolume;
546 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &newVol);
548 goto fail_UV_MoveVolume;
551 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
552 strcpy(vname, "move-clone-temp");
553 tst = AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
555 goto fail_UV_MoveVolume;
558 /* lookup the name of the volume we just cloned */
560 tst = AFSVolGetName(fromconn, fromtid, &volName);
562 goto fail_UV_MoveVolume;
566 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
571 goto fail_UV_MoveVolume;
575 * Create the destination volume
579 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
581 goto fail_UV_MoveVolume;
583 tst = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
585 goto fail_UV_MoveVolume;
588 /* remember time from which we've dumped the volume */
589 tst = AFSVolGetStatus(fromconn, clonetid, &tstatus);
591 goto fail_UV_MoveVolume;
594 fromDate = tstatus.creationDate - CLOCKSKEW;
596 #ifdef ENABLE_BUGFIX_1165
598 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
599 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
600 * don't use this information...
602 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
603 volumeInfo.volEntries_len = 0;
604 tst = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
606 goto fail_UV_MoveVolume;
609 infop = (volintInfo *) volumeInfo.volEntries_val;
610 infop->maxquota = -1; /* Else it will replace the default quota */
613 /* create a volume on the target machine */
615 tst = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
616 if (!tst) { /*delete the existing volume */
618 tst = AFSVolDeleteVolume(toconn, totid);
620 goto fail_UV_MoveVolume;
623 tst = AFSVolEndTrans(toconn, totid, &rcode);
628 goto fail_UV_MoveVolume;
634 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
637 goto fail_UV_MoveVolume;
640 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
644 tst = AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
646 goto fail_UV_MoveVolume;
650 * Now dump the clone to the new volume
653 destination.destHost = atoserver;
654 destination.destPort = AFSCONF_VOLUMEPORT;
655 destination.destSSID = 1;
657 /* Copy the clone to the new volume */
658 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
660 cookie.parent = entry.volumeId[RWVOL];
662 tst = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
664 goto fail_UV_MoveVolume;
667 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
672 goto fail_UV_MoveVolume;
676 * reattach to the main-line volume, and incrementally dump it.
679 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
681 goto fail_UV_MoveVolume;
684 /* now do the incremental */
686 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
689 goto fail_UV_MoveVolume;
692 /* now adjust the flags so that the new volume becomes official */
693 tst = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
695 goto fail_UV_MoveVolume;
698 tst = AFSVolSetFlags(toconn, totid, 0);
700 goto fail_UV_MoveVolume;
702 #ifdef ENABLE_BUGFIX_1165
703 tst = AFSVolSetInfo(toconn, totid, infop);
705 goto fail_UV_MoveVolume;
709 /* put new volume online */
710 tst = AFSVolEndTrans(toconn, totid, &rcode);
715 goto fail_UV_MoveVolume;
718 Lp_SetRWValue(cellHandle, &entry, afromserver, afrompart, atoserver,
720 store_flags = entry.flags;
721 entry.flags &= ~BACK_EXISTS;
723 if (!VLDB_ReplaceEntry
724 (cellHandle, afromvol, -1, &entry,
725 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
726 goto fail_UV_MoveVolume;
728 entry.flags = store_flags;
731 if (atoserver != afromserver) {
732 /* set forwarding pointer for moved volumes */
733 tst = AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
735 goto fail_UV_MoveVolume;
739 tst = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
741 goto fail_UV_MoveVolume;
744 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
749 goto fail_UV_MoveVolume;
752 /* Delete the backup volume on the original site */
754 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
757 AFSVolSetFlags(fromconn, fromtid,
758 VTDeleteOnSalvage | VTOutOfService);
760 goto fail_UV_MoveVolume;
763 tst = AFSVolDeleteVolume(fromconn, fromtid);
765 goto fail_UV_MoveVolume;
768 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
773 goto fail_UV_MoveVolume;
777 tst = 0; /* no backup volume? that's okay */
782 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
784 goto fail_UV_MoveVolume;
787 /* now delete the clone */
789 tst = AFSVolDeleteVolume(fromconn, clonetid);
791 goto fail_UV_MoveVolume;
794 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
799 goto fail_UV_MoveVolume;
805 /* normal cleanup code */
809 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
810 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
818 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
821 tst = (etst ? etst : rcode);
826 etst = AFSVolEndTrans(fromconn, clonetid, &rcode);
829 tst = (etst ? etst : rcode);
834 etst = AFSVolEndTrans(toconn, totid, &rcode);
837 tst = (etst ? etst : rcode);
842 #ifdef ENABLE_BUGFIX_1165
847 rx_ReleaseCachedConnection(fromconn);
849 rx_ReleaseCachedConnection(toconn);
857 /* come here only when the sky falls */
861 /* unlock VLDB entry */
863 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
864 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
867 AFSVolEndTrans(fromconn, clonetid, &rcode);
869 AFSVolEndTrans(toconn, totid, &rcode);
870 if (fromtid) { /* put it on-line */
871 AFSVolSetFlags(fromconn, fromtid, 0);
872 AFSVolEndTrans(fromconn, fromtid, &rcode);
875 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
879 /* Delete either the volume on the source location or the target location.
880 * If the vldb entry still points to the source location, then we know the
881 * volume move didn't finish so we remove the volume from the target
882 * location. Otherwise, we remove the volume from the source location.
884 if (Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst)) { /* didn't move - delete target volume */
886 if (volid && toconn) {
888 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
890 AFSVolSetFlags(toconn, totid,
891 VTDeleteOnSalvage | VTOutOfService);
892 AFSVolDeleteVolume(toconn, totid);
893 AFSVolEndTrans(toconn, totid, &rcode);
897 /* put source volume on-line */
900 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
903 AFSVolSetFlags(fromconn, fromtid, 0);
904 AFSVolEndTrans(fromconn, fromtid, &rcode);
907 } else { /* yep, move complete */
908 /* delete backup volume */
911 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
914 AFSVolSetFlags(fromconn, fromtid,
915 VTDeleteOnSalvage | VTOutOfService);
916 AFSVolDeleteVolume(fromconn, fromtid);
917 AFSVolEndTrans(fromconn, fromtid, &rcode);
920 /* delete source volume */
922 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
925 AFSVolSetFlags(fromconn, fromtid,
926 VTDeleteOnSalvage | VTOutOfService);
927 if (atoserver != afromserver)
928 AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
929 AFSVolDeleteVolume(fromconn, fromtid);
930 AFSVolEndTrans(fromconn, fromtid, &rcode);
935 /* common cleanup - delete local clone */
938 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
941 AFSVolDeleteVolume(fromconn, clonetid);
942 AFSVolEndTrans(fromconn, clonetid, &rcode);
946 /* unlock VLDB entry */
947 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
948 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
950 done: /* routine cleanup */
953 #ifdef ENABLE_BUGFIX_1165
958 rx_ReleaseCachedConnection(fromconn);
960 rx_ReleaseCachedConnection(toconn);
968 /* Make a new backup of volume <avolid> on <aserver> and <apart>
969 * if one already exists, update it
973 UV_BackupVolume(afs_cell_handle_p cellHandle, afs_int32 aserver,
974 afs_int32 apart, afs_uint32 avolid, afs_status_p st)
977 afs_status_t tst = 0, temp = 0;
978 afs_int32 ttid = 0, btid = 0;
981 char vname[VOLSER_MAXVOLNAME + 1];
982 struct nvldbentry entry;
983 int vldblocked = 0, vldbmod = 0, backexists = 1;
984 struct rx_connection *aconn = UV_Bind(cellHandle, aserver,
988 /* the calls to VLDB will succeed only if avolid is a RW volume,
989 * since we are following the RW hash chain for searching */
990 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
991 goto fail_UV_BackupVolume;
994 /* These operations require the VLDB be locked since it means the VLDB
995 * will change or the vldb is already locked.
997 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
998 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
999 (entry.volumeId[BACKVOL] == INVALID_BID)) {
1000 /* no assigned backup volume id */
1003 ubik_VL_SetLock(cellHandle->vos, 0, avolid, RWVOL,
1006 goto fail_UV_BackupVolume;
1010 /* Reread the vldb entry */
1011 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
1012 goto fail_UV_BackupVolume;
1016 if (!ISNAMEVALID(entry.name)) {
1017 tst = VOLSERBADNAME;
1018 goto fail_UV_BackupVolume;
1021 backupID = entry.volumeId[BACKVOL];
1022 if (backupID == INVALID_BID) {
1023 /* Get a backup volume id from the VLDB and update the vldb
1026 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &backupID);
1028 goto fail_UV_BackupVolume;
1030 entry.volumeId[BACKVOL] = backupID;
1034 /* Test to see if the backup volume exists by trying to create
1035 * a transaction on the backup volume. We've assumed the backup exists.
1037 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1039 if (tst != VNOVOL) {
1040 goto fail_UV_BackupVolume;
1042 backexists = 0; /* backup volume does not exist */
1045 tst = AFSVolEndTrans(aconn, btid, &rcode);
1048 tst = (tst ? tst : rcode);
1049 goto fail_UV_BackupVolume;
1053 /* Now go ahead and try to clone the RW volume.
1054 * First start a transaction on the RW volume
1056 tst = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
1058 goto fail_UV_BackupVolume;
1061 /* Clone or reclone the volume, depending on whether the backup
1062 * volume exists or not
1065 tst = AFSVolReClone(aconn, ttid, backupID);
1067 goto fail_UV_BackupVolume;
1070 strcpy(vname, entry.name);
1071 strcat(vname, ".backup");
1073 tst = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
1075 goto fail_UV_BackupVolume;
1079 /* End transaction on the RW volume */
1080 tst = AFSVolEndTrans(aconn, ttid, &rcode);
1083 tst = (tst ? tst : rcode);
1084 goto fail_UV_BackupVolume;
1087 /* Mork vldb as backup exists */
1088 if (!(entry.flags & BACK_EXISTS)) {
1089 entry.flags |= BACK_EXISTS;
1093 /* Now go back to the backup volume and bring it on line */
1094 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1096 goto fail_UV_BackupVolume;
1099 tst = AFSVolSetFlags(aconn, btid, 0);
1101 goto fail_UV_BackupVolume;
1104 tst = AFSVolEndTrans(aconn, btid, &rcode);
1107 tst = (tst ? tst : rcode);
1108 goto fail_UV_BackupVolume;
1112 /* Will update the vldb below */
1114 fail_UV_BackupVolume:
1117 temp = AFSVolEndTrans(aconn, ttid, &rcode);
1118 if (temp || rcode) {
1120 tst = (temp ? temp : rcode);
1125 temp = AFSVolEndTrans(aconn, btid, &rcode);
1126 if (temp || rcode) {
1128 tst = (temp ? temp : rcode);
1132 /* Now update the vldb - if modified */
1135 if (!VLDB_ReplaceEntry
1136 (cellHandle, avolid, RWVOL, &entry,
1137 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
1145 ubik_VL_ReleaseLock(cellHandle->vos, 0, avolid, RWVOL,
1146 (LOCKREL_OPCODE | LOCKREL_AFSID |
1147 LOCKREL_TIMESTAMP));
1157 rx_ReleaseCachedConnection(aconn);
1167 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
1170 afs_int32 acode, ccode, rcode, tid;
1171 ccode = rcode = tid = 0;
1173 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
1174 if (!acode) { /* It really was there */
1175 acode = AFSVolDeleteVolume(conn, tid);
1176 ccode = AFSVolEndTrans(conn, tid, &rcode);
1184 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
1185 #define ERROREXIT(ec) { error = (ec); goto rfail; }
1187 #if 0 /* doesn't appear to be used, why compile it */
1189 CloneVol(afs_cell_handle_p cellHandle, struct rx_connection *conn,
1190 afs_uint32 rwvid, afs_int32 part, afs_uint32 * rovidp, int nottemp,
1191 struct nvldbentry *entry, afs_int32 * vidCreateDate, afs_status_p st)
1194 afs_status_t tst = 0, etst = 0;
1195 afs_int32 rcode = 0, tid = 0;
1196 struct volser_status volstatus;
1199 /* Begin transaction on RW volume marking it busy (clients will wait) */
1200 tst = AFSVolTransCreate(conn, rwvid, part, ITBusy, &tid);
1205 /* Get the RO volume id. Allocate a new one if need to */
1206 *rovidp = entry->volumeId[ROVOL];
1207 if (*rovidp == INVALID_BID) {
1208 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, rovidp);
1213 entry->volumeId[ROVOL] = *rovidp;
1216 /* If we are creating the ro clone, what are we calling it.
1217 * Depends on whether its a temporary clone or not.
1220 strcpy(vname, entry->name);
1221 strcat(vname, ".readonly");
1223 strcpy(vname, "readonly-clone-temp"); /* Should be unique? */
1226 /* Create the new clone. If it exists, then reclone it */
1227 tst = AFSVolClone(conn, tid, 0, readonlyVolume, vname, rovidp);
1228 if (tst == VVOLEXISTS) {
1229 tst = AFSVolReClone(conn, tid, *rovidp);
1238 /* Bring the volume back on-line as soon as possible */
1240 afs_int32 fromtid = 0;
1242 /* Now bring the RO clone on-line */
1243 tst = AFSVolTransCreate(conn, *rovidp, part, ITOffline, &fromtid);
1248 tst = AFSVolSetFlags(conn, fromtid, 0);
1253 tst = AFSVolEndTrans(conn, fromtid, &rcode);
1262 /* Get the time the RW was created for return information */
1263 tst = AFSVolGetStatus(conn, tid, &volstatus);
1267 *vidCreateDate = volstatus.creationDate;
1273 tst = AFSVolEndTrans(conn, tid, &rcode);
1290 /* Get a "transaction" on this replica. Create the volume
1291 * if necessary. Return the time from which a dump should
1292 * be made (0 if it's a new volume)
1295 GetTrans(afs_cell_handle_p cellHandle, struct nvldbentry *vldbEntryPtr,
1296 afs_int32 index, struct rx_connection **connPtr,
1297 afs_int32 * transPtr, afs_int32 * timePtr, afs_status_p st)
1300 afs_status_t tst = 0, etst = 0;
1302 struct volser_status tstatus;
1305 *connPtr = (struct rx_connection *)0;
1309 /* get connection to the replication site */
1311 UV_Bind(cellHandle, vldbEntryPtr->serverNumber[index],
1312 AFSCONF_VOLUMEPORT);
1314 /* server is down */
1319 volid = vldbEntryPtr->volumeId[ROVOL];
1322 AFSVolTransCreate(*connPtr, volid,
1323 vldbEntryPtr->serverPartition[index], ITOffline,
1327 /* If the volume does not exist, create it */
1328 if (!volid || tst) {
1331 if (volid && (tst != VNOVOL)) {
1335 strcpy(volname, vldbEntryPtr->name);
1336 strcat(volname, ".readonly");
1339 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
1341 vldbEntryPtr->volumeId[RWVOL], &volid,
1346 vldbEntryPtr->volumeId[ROVOL] = volid;
1348 /* The following is a bit redundant, since create sets these flags by default */
1350 AFSVolSetFlags(*connPtr, *transPtr,
1351 VTDeleteOnSalvage | VTOutOfService);
1357 /* Otherwise, the transaction did succeed, so get the creation date of the
1358 * latest RO volume on the replication site
1361 tst = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
1365 *timePtr = tstatus.creationDate - CLOCKSKEW;
1371 if ((rc == 0) && (*transPtr)) {
1372 etst = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
1385 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
1386 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
1387 void *cookie, manyResults * results)
1391 for (i = 0; i < tr->manyDests_len; i++) {
1392 results->manyResults_val[i] =
1393 AFSVolForward(fromconn, fromtid, fromdate,
1394 &(tr->manyDests_val[i].server),
1395 tr->manyDests_val[i].trans, cookie);
1402 * Determine if a volume exists on a server and partition.
1403 * Try creating a transaction on the volume. If we can,
1404 * the volume exists, if not, then return the error code.
1405 * Some error codes mean the volume is unavailable but
1406 * still exists - so we catch these error codes.
1409 VolumeExists(afs_cell_handle_p cellHandle, afs_int32 server,
1410 afs_int32 partition, afs_int32 volumeid, afs_status_p st)
1413 afs_status_t tst = 0;
1414 struct rx_connection *conn = (struct rx_connection *)0;
1415 volEntries volumeInfo;
1417 conn = UV_Bind(cellHandle, server, AFSCONF_VOLUMEPORT);
1419 volumeInfo.volEntries_val = (volintInfo *) 0;
1420 volumeInfo.volEntries_len = 0;
1421 tst = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
1422 if (volumeInfo.volEntries_val)
1423 free(volumeInfo.volEntries_val);
1424 if (tst == VOLSERILLEGAL_PARTITION) {
1427 rx_ReleaseCachedConnection(conn);
1437 /* release volume <afromvol> on <afromserver> <afrompart> to all the
1438 * sites if forceflag is 1.If its 0 complete the release if the previous
1439 * release aborted else start a new release */
1441 UV_ReleaseVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
1442 afs_int32 afromserver, afs_int32 afrompart, int forceflag,
1446 afs_status_t tst = 0, etst = 0;
1450 afs_uint32 cloneVolId, roVolId;
1451 struct replica *replicas = 0;
1452 struct nvldbentry entry;
1453 int i, volcount, m, fullrelease, vldbindex;
1455 struct restoreCookie cookie;
1456 struct rx_connection **toconns = 0;
1457 struct release *times = 0;
1459 struct rx_connection *fromconn = (struct rx_connection *)0;
1461 afs_int32 clonetid = 0, onlinetid;
1462 afs_int32 fromtid = 0;
1463 afs_uint32 fromdate = 0, thisdate;
1466 manyResults results;
1467 int rwindex, roindex, roclone, roexists;
1468 afs_int32 rwcrdate = 0;
1472 } remembertime[NMAXNSERVERS];
1473 int releasecount = 0;
1474 struct volser_status volstatus;
1476 memset(remembertime, 0, sizeof(remembertime));
1477 memset(&results, 0, sizeof(results));
1480 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL,
1482 if ((tst) && (tst != VL_RERELEASE)) {
1483 goto fail_UV_ReleaseVolume;
1487 /* Get the vldb entry in readable format */
1488 if (!aVLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
1489 goto fail_UV_ReleaseVolume;
1492 if (!ISNAMEVALID(entry.name)) {
1493 tst = VOLSERBADNAME;
1494 goto fail_UV_ReleaseVolume;
1497 if (entry.volumeId[RWVOL] != afromvol) {
1498 tst = ADMVOSVOLUMERELEASERWONLY;
1499 goto fail_UV_ReleaseVolume;
1502 if (entry.nServers <= 1) {
1503 tst = ADMVOSVOLUMENOREPLICAS;
1504 goto fail_UV_ReleaseVolume;
1507 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10)) {
1508 tst = VOLSERBADNAME;
1509 goto fail_UV_ReleaseVolume;
1512 /* roclone is true if one of the RO volumes is on the same
1513 * partition as the RW volume. In this case, we make the RO volume
1514 * on the same partition a clone instead of a complete copy.
1518 Lp_ROMatch(cellHandle, &entry, afromserver, afrompart, &tst) - 1;
1519 roclone = ((roindex == -1) ? 0 : 1);
1520 rwindex = Lp_GetRwIndex(cellHandle, &entry, 0);
1523 goto fail_UV_ReleaseVolume;
1526 /* Make sure we have a RO volume id to work with */
1527 if (entry.volumeId[ROVOL] == INVALID_BID) {
1528 /* need to get a new RO volume id */
1529 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &roVolId);
1531 goto fail_UV_ReleaseVolume;
1534 entry.volumeId[ROVOL] = roVolId;
1535 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1536 goto fail_UV_ReleaseVolume;
1540 /* Will we be completing a previously unfinished release. -force overrides */
1541 for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) {
1542 if (entry.serverFlags[i] & NEW_REPSITE)
1545 if (forceflag && !fullrelease)
1548 /* Determine which volume id to use and see if it exists */
1551 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
1552 VolumeExists(cellHandle, afromserver, afrompart, cloneVolId, &tst);
1553 roexists = ((tst == ENODEV) ? 0 : 1);
1554 if (!roexists && !fullrelease)
1555 fullrelease = 1; /* Do a full release if RO clone does not exist */
1557 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
1560 goto fail_UV_ReleaseVolume;
1564 /* If the RO clone exists, then if the clone is a temporary
1565 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
1566 * (it was recently added), then also delete it. We do not
1567 * want to "reclone" a temporary RO clone.
1570 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
1571 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1572 if (tst && (tst != VNOVOL)) {
1573 goto fail_UV_ReleaseVolume;
1578 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
1579 * write this entry out to the vlserver until after the first
1580 * RO volume is released (temp RO clones don't count).
1582 for (i = 0; i < entry.nServers; i++) {
1583 entry.serverFlags[i] &= ~NEW_REPSITE;
1584 entry.serverFlags[i] |= RO_DONTUSE;
1586 entry.serverFlags[rwindex] |= NEW_REPSITE;
1587 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
1589 /* Begin transaction on RW and mark it busy while we clone it */
1591 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1594 goto fail_UV_ReleaseVolume;
1597 /* Clone or reclone the volume */
1599 tst = AFSVolReClone(fromconn, clonetid, cloneVolId);
1601 goto fail_UV_ReleaseVolume;
1605 strcpy(vname, entry.name);
1606 strcat(vname, ".readonly");
1608 strcpy(vname, "readonly-clone-temp");
1611 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
1614 goto fail_UV_ReleaseVolume;
1618 /* Get the time the RW was created for future information */
1619 tst = AFSVolGetStatus(fromconn, clonetid, &volstatus);
1621 goto fail_UV_ReleaseVolume;
1623 rwcrdate = volstatus.creationDate;
1625 /* End the transaction on the RW volume */
1626 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1628 tst = (tst ? tst : rcode);
1630 goto fail_UV_ReleaseVolume;
1633 /* Remember clone volume ID in case we fail or are interrupted */
1634 entry.cloneId = cloneVolId;
1637 /* Bring the RO clone online - though not if it's a temporary clone */
1639 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
1642 goto fail_UV_ReleaseVolume;
1645 etst = AFSVolSetFlags(fromconn, onlinetid, 0);
1647 tst = AFSVolEndTrans(fromconn, onlinetid, &rcode);
1648 tst = (tst ? tst : rcode);
1650 goto fail_UV_ReleaseVolume;
1654 goto fail_UV_ReleaseVolume;
1657 /* Sleep so that a client searching for an online volume won't
1658 * find the clone offline and then the next RO offline while the
1659 * release brings the clone online and the next RO offline (race).
1660 * There is a fix in the 3.4 client that does not need this sleep
1661 * anymore, but we don't know what clients we have.
1663 if (entry.nServers > 2)
1666 /* Mark the RO clone in the VLDB as a good site (already released) */
1667 entry.serverFlags[roindex] |= NEW_REPSITE;
1668 entry.serverFlags[roindex] &= ~RO_DONTUSE;
1669 entry.flags |= RO_EXISTS;
1673 /* Write out the VLDB entry only if the clone is not a temporary
1674 * clone. If we did this to a temporary clone then we would end
1675 * up marking all the ROs as "old release" making the ROs
1676 * temporarily unavailable.
1678 if (!VLDB_ReplaceEntry
1679 (cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1680 goto fail_UV_ReleaseVolume;
1685 /* Now we will release from the clone to the remaining RO replicas.
1686 * The first 2 ROs (counting the non-temporary RO clone) are released
1687 * individually: releasecount. This is to reduce the race condition
1688 * of clients trying to find an on-line RO volume. The remaining ROs
1689 * are released in parallel but no more than half the number of ROs
1690 * (rounded up) at a time: nservers.
1693 strcpy(vname, entry.name);
1694 strcat(vname, ".readonly");
1695 memset(&cookie, 0, sizeof(cookie));
1696 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
1697 cookie.type = ROVOL;
1698 cookie.parent = entry.volumeId[RWVOL];
1701 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
1703 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
1704 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
1706 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
1708 results.manyResults_val =
1709 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
1710 if (!replicas || !times || !!!results.manyResults_val || !toconns) {
1712 goto fail_UV_ReleaseVolume;
1715 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
1716 memset(times, 0, (sizeof(struct release) * nservers + 1));
1717 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
1718 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
1720 /* Create a transaction on the cloned volume */
1722 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
1724 goto fail_UV_ReleaseVolume;
1727 /* For each index in the VLDB */
1728 for (vldbindex = 0; vldbindex < entry.nServers;) {
1730 /* Get a transaction on the replicas. Pick replacas which have an old release. */
1732 ((volcount < nservers) && (vldbindex < entry.nServers));
1734 /* The first two RO volumes will be released individually.
1735 * The rest are then released in parallel. This is a hack
1736 * for clients not recognizing right away when a RO volume
1737 * comes back on-line.
1739 if ((volcount == 1) && (releasecount < 2))
1742 if (vldbindex == roindex)
1743 continue; /* the clone */
1744 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
1745 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
1747 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
1748 continue; /* not a RO vol */
1751 /* Get a Transaction on this replica. Get a new connection if
1752 * necessary. Create the volume if necessary. Return the
1753 * time from which the dump should be made (0 if it's a new
1754 * volume). Each volume might have a different time.
1756 replicas[volcount].server.destHost =
1757 entry.serverNumber[vldbindex];
1758 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
1759 replicas[volcount].server.destSSID = 1;
1760 times[volcount].vldbEntryIndex = vldbindex;
1763 (cellHandle, &entry, vldbindex, &(toconns[volcount]),
1764 &(replicas[volcount].trans), &(times[volcount].time),
1769 /* Thisdate is the date from which we want to pick up all changes */
1770 if (forceflag || !fullrelease
1771 || (rwcrdate > times[volcount].time)) {
1772 /* If the forceflag is set, then we want to do a full dump.
1773 * If it's not a full release, we can't be sure that the creation
1774 * date is good (so we also do a full dump).
1775 * If the RW volume was replaced (its creation date is newer than
1776 * the last release), then we can't be sure what has changed (so
1777 * we do a full dump).
1780 } else if (remembertime[vldbindex].validtime) {
1781 /* Trans was prev ended. Use the time from the prev trans
1782 * because, prev trans may have created the volume. In which
1783 * case time[volcount].time would be now instead of 0.
1786 (remembertime[vldbindex].time <
1787 times[volcount].time) ? remembertime[vldbindex].
1788 time : times[volcount].time;
1790 thisdate = times[volcount].time;
1792 remembertime[vldbindex].validtime = 1;
1793 remembertime[vldbindex].time = thisdate;
1795 if (volcount == 0) {
1796 fromdate = thisdate;
1798 /* Include this volume if it is within 15 minutes of the earliest */
1800 thisdate) ? (fromdate - thisdate) : (thisdate -
1802 AFSVolEndTrans(toconns[volcount],
1803 replicas[volcount].trans, &rcode);
1804 replicas[volcount].trans = 0;
1807 if (thisdate < fromdate)
1808 fromdate = thisdate;
1815 /* Release the ones we have collected */
1816 tr.manyDests_val = &(replicas[0]);
1817 tr.manyDests_len = results.manyResults_len = volcount;
1819 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
1820 0 /*spare */ , &cookie, &results);
1821 if (tst == RXGEN_OPCODE) { /* RPC Interface Mismatch */
1823 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
1824 0 /*spare */ , &cookie, &results);
1829 goto fail_UV_ReleaseVolume;
1831 for (m = 0; m < volcount; m++) {
1832 if (results.manyResults_val[m]) {
1837 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
1838 ROVOL, entry.volumeId[RWVOL], 0, 0);
1843 /* have to clear dest. flags to ensure new vol goes online:
1844 * because the restore (forwarded) operation copied
1845 * the V_inService(=0) flag over to the destination.
1847 tst = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
1852 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
1853 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
1854 entry.flags |= RO_EXISTS;
1859 /* End the transactions and destroy the connections */
1860 for (s = 0; s < volcount; s++) {
1861 if (replicas[s].trans)
1862 tst = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
1863 replicas[s].trans = 0;
1867 if ((s == 0) || (tst != ENOENT)) {
1869 if (times[s].vldbEntryIndex < vldbindex)
1870 vldbindex = times[s].vldbEntryIndex;
1875 rx_ReleaseCachedConnection(toconns[s]);
1879 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1880 goto fail_UV_ReleaseVolume;
1882 } /* for each index in the vldb */
1884 /* End the transaction on the cloned volume */
1885 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1888 /* Figure out if any volume were not released and say so */
1889 for (failure = 0, i = 0; i < entry.nServers; i++) {
1890 if (!(entry.serverFlags[i] & NEW_REPSITE))
1894 if (!VLDB_ReplaceEntry
1895 (cellHandle, afromvol, RWVOL, &entry, LOCKREL_TIMESTAMP, &tst)) {
1896 goto fail_UV_ReleaseVolume;
1899 tst = VOLSERBADRELEASE;
1900 goto fail_UV_ReleaseVolume;
1903 /* All the ROs were release successfully. Remove the temporary clone */
1905 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1907 goto fail_UV_ReleaseVolume;
1912 for (i = 0; i < entry.nServers; i++)
1913 entry.serverFlags[i] &= ~NEW_REPSITE;
1915 /* Update the VLDB */
1916 if (!VLDB_ReplaceEntry
1917 (cellHandle, afromvol, RWVOL, &entry,
1918 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
1919 goto fail_UV_ReleaseVolume;
1923 fail_UV_ReleaseVolume:
1926 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1933 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1939 for (i = 0; i < nservers; i++) {
1940 if (replicas && replicas[i].trans) {
1941 tst = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
1942 replicas[i].trans = 0;
1947 if (toconns && toconns[i]) {
1948 rx_ReleaseCachedConnection(toconns[i]);
1954 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, RWVOL,
1955 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
1962 rx_ReleaseCachedConnection(fromconn);
1963 if (results.manyResults_val)
1964 free(results.manyResults_val);
1979 ReceiveFile(int fd, struct rx_call *call,
1980 struct stat *status)
1982 char *buffer = (char *)0;
1984 afs_int32 bytesread, nbytes, bytesleft, w;
1986 afs_int32 error = 0;
1993 struct statfs tstatfs;
1995 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
1997 fstatfs(fd, &tstatfs);
1998 blockSize = tstatfs.f_bsize;
2000 blockSize = status->st_blksize;
2007 buffer = (char *)malloc(blockSize);
2012 while (!error && (bytesread > 0)) {
2013 bytesread = rx_Read(call, buffer, nbytes);
2014 bytesleft = bytesread;
2015 while (!error && (bytesleft > 0)) {
2018 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2019 select(fd + 1, 0, &out, 0, 0); /* don't timeout if write bl
2022 w = write(fd, &buffer[bytesread - bytesleft], bytesleft);
2024 error = ADMVOSDUMPFILEWRITEFAIL;
2040 DumpFunction(struct rx_call *call, const char *filename)
2044 afs_int32 error, code;
2049 fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666);
2050 if (fd < 0 || fstat(fd, &status) < 0) {
2051 error = VOLSERBADOP;
2054 code = ReceiveFile(fd, call, &status);
2072 /*dump the volume <afromvol> on <afromserver> and
2073 * <afrompart> to <afilename> starting from <fromdate>.
2074 * DumpFunction does the real work behind the scenes after
2075 * extracting parameters from the rock */
2077 UV_DumpVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
2078 afs_int32 afromserver, afs_int32 afrompart, afs_int32 fromdate,
2079 const char *filename, afs_status_p st)
2082 afs_status_t tst = 0;
2083 afs_status_t etst = 0;
2084 struct rx_connection *fromconn;
2085 struct rx_call *fromcall;
2090 struct nvldbentry entry;
2095 fromcall = (struct rx_call *)0;
2096 fromconn = (struct rx_connection *)0;
2098 fromcall = (struct rx_call *)0;
2101 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
2102 goto fail_UV_DumpVolume;
2105 /* get connections to the servers */
2106 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
2107 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2109 goto fail_UV_DumpVolume;
2111 fromcall = rx_NewCall(fromconn);
2112 tst = StartAFSVolDump(fromcall, fromtid, fromdate);
2114 goto fail_UV_DumpVolume;
2116 if ((tst = DumpFunction(fromcall, filename))) {
2117 goto fail_UV_DumpVolume;
2119 tst = rx_EndCall(fromcall, rxError);
2120 fromcall = (struct rx_call *)0;
2122 goto fail_UV_DumpVolume;
2124 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2129 goto fail_UV_DumpVolume;
2137 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
2138 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2146 etst = rx_EndCall(fromcall, rxError);
2154 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2164 rx_ReleaseCachedConnection(fromconn);
2174 SendFile(int fd, struct rx_call *call,
2175 struct stat *status)
2177 char *buffer = (char *)0;
2180 afs_int32 error = 0;
2189 struct statfs tstatfs;
2191 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2193 fstatfs(fd, &tstatfs);
2194 blockSize = tstatfs.f_bsize;
2196 blockSize = status->st_blksize;
2202 buffer = (char *)malloc(blockSize);
2207 while (!error && !done) {
2210 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2211 select(fd + 1, &in, 0, 0, 0); /* don't timeout if read blocks */
2213 nbytes = read(fd, buffer, blockSize);
2215 error = ADMVOSRESTOREFILEREADFAIL;
2222 if (rx_Write(call, buffer, nbytes) != nbytes) {
2223 error = ADMVOSRESTOREFILEWRITEFAIL;
2233 WriteData(struct rx_call *call, const char *filename)
2237 afs_int32 error, code;
2242 fd = open(filename, 0);
2243 if (fd < 0 || fstat(fd, &status) < 0) {
2244 fprintf(STDERR, "Could access file '%s'\n", filename);
2245 error = ADMVOSRESTOREFILEOPENFAIL;
2246 goto fail_WriteData;
2248 code = SendFile(fd, call, &status);
2251 goto fail_WriteData;
2262 error = ADMVOSRESTOREFILECLOSEFAIL;
2268 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
2269 * the dump file <afilename>. WriteData does all the real work
2270 * after extracting params from the rock
2273 UV_RestoreVolume(afs_cell_handle_p cellHandle, afs_int32 toserver,
2274 afs_int32 topart, afs_uint32 tovolid, char *tovolname,
2275 int flags, const char *dumpFile, afs_status_p st)
2278 afs_status_t tst = 0;
2279 afs_status_t etst = 0;
2280 struct rx_connection *toconn, *tempconn;
2281 struct rx_call *tocall;
2282 afs_int32 totid, rcode;
2283 afs_int32 rxError = 0;
2284 struct volser_status tstatus;
2289 struct nvldbentry entry;
2291 struct restoreCookie cookie;
2293 afs_int32 newDate, volflag;
2297 memset(&cookie, 0, sizeof(cookie));
2301 tocall = (struct rx_call *)0;
2302 toconn = (struct rx_connection *)0;
2303 tempconn = (struct rx_connection *)0;
2308 toconn = UV_Bind(cellHandle, toserver, AFSCONF_VOLUMEPORT);
2309 if (pvolid == 0) { /*alot a new id if needed */
2310 aVLDB_GetEntryByName(cellHandle, tovolname, &entry, &tst);
2311 if (tst == VL_NOENT) {
2313 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &pvolid);
2315 goto fail_UV_RestoreVolume;
2319 pvolid = entry.volumeId[RWVOL];
2324 * at this point we have a volume id to use/reuse for the
2325 * volume to be restored
2327 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
2328 tst = ADMVOSRESTOREVOLUMENAMETOOBIG;
2329 goto fail_UV_RestoreVolume;
2332 if (!vos_PartitionIdToName(topart, partName, &tst)) {
2333 goto fail_UV_RestoreVolume;
2335 /*what should the volume be restored as ? rw or ro or bk ?
2336 * right now the default is rw always */
2338 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0, &pvolid,
2341 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
2343 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2345 goto fail_UV_RestoreVolume;
2348 AFSVolSetFlags(toconn, totid,
2349 VTDeleteOnSalvage | VTOutOfService);
2351 goto fail_UV_RestoreVolume;
2353 tst = AFSVolDeleteVolume(toconn, totid);
2355 goto fail_UV_RestoreVolume;
2357 tst = AFSVolEndTrans(toconn, totid, &rcode);
2362 goto fail_UV_RestoreVolume;
2365 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,
2368 goto fail_UV_RestoreVolume;
2372 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2374 goto fail_UV_RestoreVolume;
2378 cookie.parent = pvolid;
2379 cookie.type = RWVOL;
2381 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
2383 tocall = rx_NewCall(toconn);
2384 tst = StartAFSVolRestore(tocall, totid, 1, &cookie);
2386 goto fail_UV_RestoreVolume;
2388 tst = WriteData(tocall, dumpFile);
2390 goto fail_UV_RestoreVolume;
2392 tst = rx_EndCall(tocall, rxError);
2393 tocall = (struct rx_call *)0;
2395 goto fail_UV_RestoreVolume;
2397 tst = AFSVolGetStatus(toconn, totid, &tstatus);
2399 goto fail_UV_RestoreVolume;
2401 tst = AFSVolSetIdsTypes(toconn, totid, tovolname, RWVOL, pvolid, 0, 0);
2403 goto fail_UV_RestoreVolume;
2406 tst = AFSVolSetDate(toconn, totid, newDate);
2408 goto fail_UV_RestoreVolume;
2411 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2412 tst = AFSVolSetFlags(toconn, totid, volflag);
2414 goto fail_UV_RestoreVolume;
2417 /* It isn't handled right in fail_UV_RestoreVolume */
2418 tst = AFSVolEndTrans(toconn, totid, &rcode);
2423 goto fail_UV_RestoreVolume;
2427 if (success && (!reuseID || (flags & RV_FULLRST))) {
2428 /* Volume was restored on the file server, update the
2429 * VLDB to reflect the change.
2431 aVLDB_GetEntryByID(cellHandle, pvolid, RWVOL, &entry, &tst);
2432 if (tst && tst != VL_NOENT && tst != VL_ENTDELETED) {
2433 goto fail_UV_RestoreVolume;
2435 if (tst == VL_NOENT) { /* it doesnot exist already */
2436 /*make the vldb return this indication specifically */
2437 strcpy(entry.name, tovolname);
2439 entry.serverNumber[0] = toserver; /*should be indirect */
2440 entry.serverPartition[0] = topart;
2441 entry.serverFlags[0] = ITSRWVOL;
2442 entry.flags = RW_EXISTS;
2443 if (tstatus.cloneID != 0) {
2444 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
2446 entry.volumeId[ROVOL] = INVALID_BID;
2447 entry.volumeId[RWVOL] = pvolid;
2449 if (tstatus.backupID != 0) {
2450 entry.volumeId[BACKVOL] = tstatus.backupID;
2451 /*this should come from status info on the volume if non zero */
2453 entry.volumeId[BACKVOL] = INVALID_BID;
2454 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
2455 goto fail_UV_RestoreVolume;
2458 } else { /*update the existing entry */
2460 ubik_VL_SetLock(cellHandle->vos, 0, pvolid, RWVOL,
2463 goto fail_UV_RestoreVolume;
2466 strcpy(entry.name, tovolname);
2468 /* Update the vlentry with the new information */
2469 index = Lp_GetRwIndex(cellHandle, &entry, 0);
2471 /* Add the rw site for the volume being restored */
2472 entry.serverNumber[entry.nServers] = toserver;
2473 entry.serverPartition[entry.nServers] = topart;
2474 entry.serverFlags[entry.nServers] = ITSRWVOL;
2477 /* This volume should be deleted on the old site
2478 * if its different from new site.
2480 VLDB_IsSameAddrs(cellHandle, toserver,
2481 entry.serverNumber[index], &same, &tst);
2483 || (entry.serverPartition[index] != topart)) {
2485 UV_Bind(cellHandle, entry.serverNumber[index],
2486 AFSCONF_VOLUMEPORT);
2488 AFSVolTransCreate(tempconn, pvolid,
2489 entry.serverPartition[index],
2490 ITOffline, &temptid);
2493 AFSVolSetFlags(tempconn, temptid,
2497 goto fail_UV_RestoreVolume;
2499 tst = AFSVolDeleteVolume(tempconn, temptid);
2501 goto fail_UV_RestoreVolume;
2503 tst = AFSVolEndTrans(tempconn, temptid, &rcode);
2508 goto fail_UV_RestoreVolume;
2510 vos_PartitionIdToName(entry.serverPartition[index],
2514 entry.serverNumber[index] = toserver;
2515 entry.serverPartition[index] = topart;
2518 entry.flags |= RW_EXISTS;
2519 if (!VLDB_ReplaceEntry
2520 (cellHandle, pvolid, RWVOL, &entry,
2521 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2522 goto fail_UV_RestoreVolume;
2529 fail_UV_RestoreVolume:
2532 etst = rx_EndCall(tocall, rxError);
2538 ubik_VL_ReleaseLock(cellHandle->vos, 0, pvolid, RWVOL,
2539 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2546 etst = AFSVolEndTrans(toconn, totid, &rcode);
2555 etst = AFSVolEndTrans(toconn, temptid, &rcode);
2565 rx_ReleaseCachedConnection(tempconn);
2567 rx_ReleaseCachedConnection(toconn);
2575 /*adds <server> and <part> as a readonly replication site for <volid>
2578 UV_AddSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2579 afs_uint32 volid, afs_status_p st)
2582 afs_status_t tst = 0;
2583 int j, nro = 0, islocked = 0;
2584 struct nvldbentry entry;
2588 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2590 goto fail_UV_AddSite;
2594 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2595 goto fail_UV_AddSite;
2597 if (!ISNAMEVALID(entry.name)) {
2599 goto fail_UV_AddSite;
2602 /* See if it's too many entries */
2603 if (entry.nServers >= NMAXNSERVERS) {
2605 goto fail_UV_AddSite;
2608 /* See if it's on the same server */
2609 for (j = 0; j < entry.nServers; j++) {
2610 if (entry.serverFlags[j] & ITSROVOL) {
2612 if (!VLDB_IsSameAddrs
2613 (cellHandle, server, entry.serverNumber[j], &same, &tst)) {
2614 goto fail_UV_AddSite;
2618 goto fail_UV_AddSite;
2623 /* See if it's too many RO sites - leave one for the RW */
2624 if (nro >= NMAXNSERVERS - 1) {
2626 goto fail_UV_AddSite;
2629 entry.serverNumber[entry.nServers] = server;
2630 entry.serverPartition[entry.nServers] = part;
2631 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
2634 if (!VLDB_ReplaceEntry
2635 (cellHandle, volid, RWVOL, &entry,
2636 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2637 goto fail_UV_AddSite;
2646 ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2647 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2656 /*removes <server> <part> as read only site for <volid> from the vldb */
2658 UV_RemoveSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2659 afs_uint32 volid, afs_status_p st)
2662 afs_status_t tst = 0;
2663 struct nvldbentry entry;
2667 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2669 goto fail_UV_RemoveSite;
2673 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2674 goto fail_UV_RemoveSite;
2676 if (!Lp_ROMatch(cellHandle, &entry, server, part, &tst)) {
2677 /*this site doesnot exist */
2678 goto fail_UV_RemoveSite;
2679 } else { /*remove the rep site */
2680 Lp_SetROValue(cellHandle, &entry, server, part, 0, 0);
2682 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
2683 entry.flags &= ~RO_EXISTS;
2684 if (entry.nServers < 1) { /*this is the last ref */
2685 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volid, ROVOL);
2687 goto fail_UV_RemoveSite;
2690 if (!VLDB_ReplaceEntry
2691 (cellHandle, volid, RWVOL, &entry,
2692 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
2693 goto fail_UV_RemoveSite;
2702 t = ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2703 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2715 /*list all the partitions on <aserver> */
2717 UV_ListPartitions(struct rx_connection *server, struct partList *ptrPartList,
2718 afs_int32 * cntp, afs_status_p st)
2721 afs_status_t tst = 0;
2722 struct pIDs partIds;
2723 struct partEntries partEnts;
2728 partEnts.partEntries_len = 0;
2729 partEnts.partEntries_val = NULL;
2730 /* this is available only on new servers */
2731 tst = AFSVolXListPartitions(server, &partEnts);
2733 /* next, try old interface */
2734 if (tst == RXGEN_OPCODE) {
2735 for (i = 0; i < 26; i++)
2736 partIds.partIds[i] = -1;
2737 tst = AFSVolListPartitions(server, &partIds);
2739 for (i = 0; i < 26; i++) {
2740 if ((partIds.partIds[i]) != -1) {
2741 ptrPartList->partId[j] = partIds.partIds[i];
2742 ptrPartList->partFlags[j] = PARTVALID;
2745 ptrPartList->partFlags[i] = 0;
2749 goto fail_UV_ListPartitions;
2752 *cntp = partEnts.partEntries_len;
2753 if (*cntp > VOLMAXPARTS) {
2754 *cntp = VOLMAXPARTS;
2756 for (i = 0; i < *cntp; i++) {
2757 ptrPartList->partId[i] = partEnts.partEntries_val[i];
2758 ptrPartList->partFlags[i] = PARTVALID;
2760 free(partEnts.partEntries_val);
2762 goto fail_UV_ListPartitions;
2766 fail_UV_ListPartitions:
2774 /*------------------------------------------------------------------------
2775 * EXPORTED UV_XListVolumes
2778 * List the extended information for all the volumes on a particular
2779 * File Server and partition. We may either return the volume's ID
2780 * or all of its extended information.
2783 * a_serverID : Address of the File Server for which we want
2784 * extended volume info.
2785 * a_partID : Partition for which we want the extended
2787 * a_all : If non-zero, fetch ALL the volume info,
2788 * otherwise just the volume ID.
2789 * a_resultPP : Ptr to the address of the area containing
2790 * the returned volume info.
2791 * a_numEntsInResultP : Ptr for the value we set for the number of
2796 * Otherise, the return value of AFSVolXListVolumes.
2799 * This routine is closely related to UV_ListVolumes, which returns
2800 * only the standard level of detail on AFS volumes. It is a
2801 * heavyweight operation, zipping through all the volume entries for
2802 * a given server/partition.
2806 *------------------------------------------------------------------------*/
2809 UV_XListVolumes(struct rx_connection *server, afs_int32 a_partID, int a_all,
2810 struct volintXInfo **a_resultPP,
2811 afs_int32 * a_numEntsInResultP, afs_status_p st)
2814 afs_status_t tst = 0;
2816 volXEntries volumeXInfo; /*Area for returned extended vol info */
2819 * Set up our error code and the area for returned extended volume info.
2820 * We set the val field to a null pointer as a hint for the stub to
2823 *a_numEntsInResultP = 0;
2824 *a_resultPP = (volintXInfo *) 0;
2825 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2826 volumeXInfo.volXEntries_len = 0;
2829 * Bind to the Volume Server port on the File Server machine in question,
2832 tst = AFSVolXListVolumes(server, a_partID, a_all, &volumeXInfo);
2834 goto fail_UV_XListVolumes;
2837 * We got the info; pull out the pointer to where the results lie
2838 * and how many entries are there.
2840 *a_resultPP = volumeXInfo.volXEntries_val;
2841 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
2845 fail_UV_XListVolumes:
2853 /*------------------------------------------------------------------------
2854 * EXPORTED UV_XListOneVolume
2857 * List the extended information for a volume on a particular File
2858 * Server and partition.
2861 * server : a handle to the server where the volume resides.
2862 * a_partID : Partition for which we want the extended
2864 * a_volID : Volume ID for which we want the info.
2865 * a_resultPP : Ptr to the address of the area containing
2866 * the returned volume info.
2870 * Otherise, the return value of AFSVolXListOneVolume.
2873 * This routine is closely related to UV_ListOneVolume, which returns
2874 * only the standard level of detail on the chosen AFS volume.
2878 *------------------------------------------------------------------------*/
2881 UV_XListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2882 afs_uint32 a_volID, struct volintXInfo **a_resultPP,
2886 afs_status_t tst = 0;
2887 volXEntries volumeXInfo; /*Area for returned info */
2890 * Set the area we're in which we are returning
2891 * the info. Setting the val field to a null pointer tells the stub
2892 * to allocate space for us.
2894 *a_resultPP = (volintXInfo *) 0;
2895 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2896 volumeXInfo.volXEntries_len = 0;
2898 tst = AFSVolXListOneVolume(server, a_partID, a_volID, &volumeXInfo);
2901 goto fail_UV_XListOneVolume;
2904 * We got the info; pull out the pointer to where the results lie.
2906 *a_resultPP = volumeXInfo.volXEntries_val;
2910 fail_UV_XListOneVolume:
2917 } /*UV_XListOneVolume */
2919 /*------------------------------------------------------------------------
2920 * EXPORTED UV_ListOneVolume
2923 * List the volume information for a volume on a particular File
2924 * Server and partition.
2927 * server : a handle to the server where the volume resides.
2928 * a_partID : Partition for which we want the extended
2930 * a_volID : Volume ID for which we want the info.
2931 * a_resultPP : Ptr to the address of the area containing
2932 * the returned volume info.
2936 * Otherise, the return value of AFSVolXListOneVolume.
2940 *------------------------------------------------------------------------*/
2942 int UV_ListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2943 afs_uint32 a_volID, struct volintInfo **a_resultPP,
2947 afs_status_t tst = 0;
2948 volEntries volumeInfo; /*Area for returned info */
2951 * Set the area we're in which we are returning
2952 * the info. Setting the val field to a null pointer tells the stub
2953 * to allocate space for us.
2955 *a_resultPP = (volintInfo *) 0;
2956 volumeInfo.volEntries_val = (volintInfo *) 0;
2957 volumeInfo.volEntries_len = 0;
2959 tst = AFSVolListOneVolume(server, a_partID, a_volID, &volumeInfo);
2962 goto fail_UV_ListOneVolume;
2965 * We got the info; pull out the pointer to where the results lie.
2967 *a_resultPP = volumeInfo.volEntries_val;
2971 fail_UV_ListOneVolume:
2977 }/*UV_ListOneVolume*/
2979 /*sync vldb with all the entries on <myQueue> on <aserver> and <apart>*/
2981 ProcessEntries(afs_cell_handle_p cellHandle, struct qHead *myQueue,
2982 struct rx_connection *server, afs_int32 apart, afs_int32 force)
2986 afs_uint32 temp1, temp2;
2988 afs_uint32 maxVolid = 0;
2989 struct nvldbentry entry;
2990 int noError = 1, error, same;
2991 int totalC, totalU, totalCE, totalUE, totalG;
2993 int aserver = ntohl(rx_HostOf(rx_PeerOf(server)));
2996 totalC = totalU = totalCE = totalUE = totalG = 0;
2999 /* get the next available id's from the vldb server */
3000 vcode = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 0, &maxVolid);
3004 totalG = myQueue->count;
3008 Lp_QEnumerate(myQueue, &success, &elem, 0);
3013 if (!elem.isValid[RWVOL] && !elem.isValid[ROVOL] && !elem.isValid[BACKVOL]) { /*something is wrong with elem */
3017 if (maxVolid <= elem.ids[RWVOL]) {
3019 temp2 = elem.ids[RWVOL] - maxVolid + 1;
3022 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3026 if (maxVolid <= elem.ids[ROVOL]) {
3028 temp2 = elem.ids[ROVOL] - maxVolid + 1;
3031 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3035 if (maxVolid <= elem.ids[BACKVOL]) {
3037 temp2 = elem.ids[BACKVOL] - temp1 + 1;
3040 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3044 aVLDB_GetEntryByID(cellHandle, elem.ids[RWVOL], RWVOL, &entry, &tst);
3045 if (tst && (tst != VL_NOENT)) {
3048 } else if (tst && (tst == VL_NOENT)) { /*entry doesnot exist */
3049 /*set up a vldb entry for elem */
3050 memset(&entry, 0, sizeof(entry));
3051 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME);
3052 if (elem.isValid[RWVOL]) { /*rw exists */
3053 entry.flags |= RW_EXISTS;
3054 entry.serverFlags[entry.nServers] = ITSRWVOL;
3055 entry.serverNumber[entry.nServers] = aserver;
3056 entry.serverPartition[entry.nServers] = apart;
3057 entry.nServers += 1;
3058 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3059 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3060 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3062 if (elem.isValid[ROVOL]) { /*ro volume exists */
3063 entry.flags |= RO_EXISTS;
3064 entry.serverFlags[entry.nServers] = ITSROVOL;
3065 entry.serverNumber[entry.nServers] = aserver;
3066 entry.serverPartition[entry.nServers] = apart;
3067 entry.nServers += 1;
3068 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3069 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3072 if (elem.isValid[BACKVOL]) { /*backup volume exists */
3073 entry.flags |= BACK_EXISTS;
3074 if (!(entry.flags & RW_EXISTS)) { /*this helps to check for a stray backup if parent moves */
3075 entry.serverFlags[entry.nServers] = ITSRWVOL;
3076 entry.serverNumber[entry.nServers] = aserver;
3077 entry.serverPartition[entry.nServers] = apart;
3078 entry.nServers += 1;
3081 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3082 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3085 VLDB_CreateEntry(cellHandle, &entry, &tst);
3091 } else { /* Update the existing entry */
3092 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME); /*the name Could have changed */
3094 if (elem.isValid[RWVOL]) { /* A RW volume */
3095 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3097 /* A RW index is not found in the VLDB entry - will add it */
3099 entry.flags |= RW_EXISTS;
3100 entry.serverNumber[entry.nServers] = aserver;
3101 entry.serverPartition[entry.nServers] = apart;
3102 entry.serverFlags[entry.nServers] = ITSRWVOL;
3105 /* A RW index is found in the VLDB entry.
3106 * Verify that the volume location matches the VLDB location.
3107 * Fix the VLDB entry if it is not correct.
3111 VLDB_IsSameAddrs(cellHandle, aserver,
3112 entry.serverNumber[temp], &same,
3117 if (!same || (apart != entry.serverPartition[temp])) {
3118 /* VLDB says volume is in another place. Fix the VLDB entry */
3119 entry.serverNumber[temp] = aserver;
3120 entry.serverPartition[temp] = apart;
3123 entry.flags |= RW_EXISTS;
3125 if ((elem.ids[BACKVOL] != 0) && elem.isValid[BACKVOL])
3126 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3127 if ((elem.ids[ROVOL] != 0) && elem.isValid[ROVOL])
3128 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3131 if (elem.isValid[ROVOL]) {
3132 /*tackle a ro volume */
3134 if (!Lp_ROMatch(cellHandle, &entry, aserver, apart, 0)) {
3136 if (elem.ids[ROVOL] > entry.volumeId[ROVOL]) {
3137 /*there is a conflict of ids, keep the later volume */
3138 /*delete all the ro volumes listed in vldb entry since they
3141 int j, count, rwsite;
3144 count = entry.nServers;
3146 for (j = 0; j < count; j++) {
3147 if (entry.serverFlags[j] & ITSROVOL) {
3149 /*delete the site */
3150 entry.serverNumber[j] = 0;
3151 entry.serverPartition[j] = 0;
3152 entry.serverFlags[j] = 0;
3154 } else if (entry.serverFlags[j] & ITSRWVOL)
3159 entry.serverNumber[entry.nServers] =
3160 entry.serverNumber[rwsite];
3161 entry.serverPartition[entry.nServers] =
3162 entry.serverPartition[rwsite];
3163 entry.serverFlags[entry.nServers] =
3164 entry.serverFlags[rwsite];
3167 entry.serverNumber[entry.nServers] = aserver;
3168 entry.serverPartition[entry.nServers] = apart;
3169 entry.serverFlags[entry.nServers] = ITSROVOL;
3171 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3172 entry.flags |= RO_EXISTS;
3174 } else if (elem.ids[ROVOL] < entry.volumeId[ROVOL]) {
3175 if (!(entry.flags & RO_EXISTS)) {
3176 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3177 entry.serverNumber[entry.nServers] = aserver;
3178 entry.serverPartition[entry.nServers] = apart;
3179 entry.serverFlags[entry.nServers] = ITSROVOL;
3181 entry.flags |= RO_EXISTS;
3186 else if (elem.ids[ROVOL] == entry.volumeId[ROVOL]) {
3187 entry.serverNumber[entry.nServers] = aserver;
3188 entry.serverPartition[entry.nServers] = apart;
3189 entry.serverFlags[entry.nServers] = ITSROVOL;
3191 entry.flags |= RO_EXISTS;
3192 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3195 if (entry.volumeId[ROVOL] == INVALID_BID)
3196 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3199 if (elem.isValid[BACKVOL]) {
3200 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3201 if (temp != -1) { /*check if existing backup site matches with the given arguments */
3203 VLDB_IsSameAddrs(cellHandle, aserver,
3204 entry.serverNumber[temp], &same,
3210 /*tackle the backup volume */
3211 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3212 entry.flags |= BACK_EXISTS;
3214 if (entry.volumeId[BACKVOL] == INVALID_BID)
3215 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3218 VLDB_ReplaceEntry(cellHandle, elem.ids[RWVOL], RWVOL, &entry,
3219 LOCKREL_OPCODE | LOCKREL_AFSID |
3220 LOCKREL_TIMESTAMP, &tst);
3226 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3227 elem.ids[RWVOL], RWVOL,
3228 LOCKREL_OPCODE | LOCKREL_AFSID |
3234 } /* else update the existing entry */
3236 } /* End of while(1) */
3244 /*synchronise vldb with the file server <aserver> and <apart>(if flags=1).
3245 *else synchronise with all the valid partitions on <aserver>
3248 UV_SyncVldb(afs_cell_handle_p cellHandle, struct rx_connection *server,
3249 afs_int32 apart, int flags, int force, afs_status_p st)
3252 afs_status_t tst = 0;
3255 volEntries volumeInfo;
3257 struct qHead myQueue;
3258 struct partList PartList;
3263 /*this hints the stub to allocate space */
3264 volumeInfo.volEntries_val = (volintInfo *) 0;
3265 volumeInfo.volEntries_len = 0;
3267 if (!flags) { /*generate all the valid partitions */
3268 UV_ListPartitions(server, &PartList, &cnt, &tst);
3270 goto fail_UV_SyncVldb;
3273 PartList.partId[0] = apart;
3277 for (i = 0; i < cnt; i++) {
3278 apart = PartList.partId[i];
3279 /*this hints the stub to allocate space */
3280 volumeInfo.volEntries_val = (volintInfo *) 0;
3281 volumeInfo.volEntries_len = 0;
3282 tst = AFSVolListVolumes(server, apart, 1, &volumeInfo);
3284 goto fail_UV_SyncVldb;
3286 count = volumeInfo.volEntries_len;
3287 pntr = volumeInfo.volEntries_val;
3289 if (!vos_PartitionIdToName(apart, pname, &tst)) {
3290 goto fail_UV_SyncVldb;
3292 /*collect all vol entries by their parentid */
3293 tst = GroupEntries(server, pntr, count, &myQueue, apart);
3296 if (volumeInfo.volEntries_val) {
3297 /*free the space allocated by the stub */
3298 free(volumeInfo.volEntries_val);
3299 volumeInfo.volEntries_val = 0;
3303 tst = ProcessEntries(cellHandle, &myQueue, server, apart, force);
3305 tst = VOLSERFAILEDOP;
3306 if (volumeInfo.volEntries_val) {
3307 /*free the space allocated by the stub */
3308 free(volumeInfo.volEntries_val);
3309 volumeInfo.volEntries_val = 0;
3316 tst = VOLSERFAILEDOP;
3317 } /* thru all partitions */
3322 if (volumeInfo.volEntries_val)
3323 free(volumeInfo.volEntries_val);
3336 CheckVldbRWBK(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3337 afs_int32 * modified, afs_status_p st)
3340 afs_status_t tst = 0;
3346 idx = Lp_GetRwIndex(cellHandle, entry, 0);
3348 /* Check to see if the RW volume exists and set the RW_EXISTS
3351 if (idx == -1) { /* Did not find a RW entry */
3352 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
3353 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
3358 (cellHandle, entry->serverNumber[idx],
3359 entry->serverPartition[idx], entry->volumeId[RWVOL], &tst)) {
3360 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does no
3362 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
3365 } else if (tst == ENODEV) { /* RW volume does not exist */
3366 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists
3368 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist
3373 /* If VLDB says it didn't exist, then ignore error */
3374 if (entry->flags & RW_EXISTS) {
3375 goto fail_CheckVldbRWBK;
3380 /* Check to see if the BK volume exists and set the BACK_EXISTS
3381 * flag accordingly. idx already ponts to the RW entry.
3383 if (idx == -1) { /* Did not find a RW entry */
3384 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
3385 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
3388 } else { /* Found a RW entry */
3390 (cellHandle, entry->serverNumber[idx],
3391 entry->serverPartition[idx], entry->volumeId[BACKVOL], &tst)) {
3392 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does n
3394 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
3397 } else if (tst == ENODEV) { /* BK volume does not exist */
3398 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists
3400 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist
3405 /* If VLDB says it didn't exist, then ignore error */
3406 if (entry->flags & BACK_EXISTS) {
3407 goto fail_CheckVldbRWBK;
3412 /* If there is an idx but the BK and RW volumes no
3413 * longer exist, then remove the RW entry.
3415 if ((idx != -1) && !(entry->flags & RW_EXISTS)
3416 && !(entry->flags & BACK_EXISTS)) {
3417 Lp_SetRWValue(cellHandle, entry, entry->serverNumber[idx],
3418 entry->serverPartition[idx], 0L, 0L);
3427 *modified = modentry;
3437 CheckVldbRO(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3438 afs_int32 * modified, afs_status_p st)
3441 afs_status_t tst = 0;
3443 int foundro = 0, modentry = 0;
3448 /* Check to see if the RO volumes exist and set the RO_EXISTS
3451 for (idx = 0; idx < entry->nServers; idx++) {
3452 if (!(entry->serverFlags[idx] & ITSROVOL)) {
3453 continue; /* not a RO */
3457 (cellHandle, entry->serverNumber[idx],
3458 entry->serverPartition[idx], entry->volumeId[ROVOL], &tst)) {
3460 } else if (tst == ENODEV) { /* RW volume does not exist */
3461 Lp_SetROValue(cellHandle, entry, entry->serverNumber[idx],
3462 entry->serverPartition[idx], 0L, 0L);
3467 goto fail_CheckVldbRO;
3471 if (foundro) { /* A RO volume exists */
3472 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not e
3474 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
3477 } else { /* A RO volume does not exist */
3478 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
3479 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
3488 *modified = modentry;
3496 /*ensure that <entry> matches with the info on file servers */
3498 CheckVldb(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3499 afs_int32 * modified, afs_status_p st)
3502 afs_status_t tst = 0;
3506 afs_int32 modentry = 0;
3512 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
3514 goto fail_CheckVldb;
3519 /* Check to see if the VLDB is ok without locking it (pass 1).
3520 * If it will change, then lock the VLDB entry, read it again,
3521 * then make the changes to it (pass 2).
3525 ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL],
3526 RWVOL, VLOP_DELETE);
3528 goto fail_CheckVldb;
3532 if (!aVLDB_GetEntryByID
3533 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, &tst)) {
3534 goto fail_CheckVldb;
3540 /* Check if the RW and BK entries are ok */
3541 if (!CheckVldbRWBK(cellHandle, entry, &modentry, &tst)) {
3542 goto fail_CheckVldb;
3544 if (modentry && (pass == 1))
3547 /* Check if the RO volumes entries are ok */
3548 if (!CheckVldbRO(cellHandle, entry, &modentry, &tst)) {
3549 goto fail_CheckVldb;
3551 if (modentry && (pass == 1))
3554 /* The VLDB entry has been updated. If it as been modified, then
3555 * write the entry back out the the VLDB.
3561 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
3562 && !(entry->flags & RO_EXISTS)) {
3563 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
3565 ubik_VL_DeleteEntry(cellHandle->vos, 0,
3566 entry->volumeId[RWVOL], RWVOL);
3568 goto fail_CheckVldb;
3571 /* Replace old entry with our new one */
3572 if (!VLDB_ReplaceEntry
3573 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry,
3574 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
3576 goto fail_CheckVldb;
3589 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3590 entry->volumeId[RWVOL], RWVOL,
3591 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
3604 /*synchronise <aserver> <apart>(if flags = 1) with the vldb .
3605 *if flags = 0, synchronise all the valid partitions on <aserver>*/
3607 UV_SyncServer(afs_cell_handle_p cellHandle, struct rx_connection *server,
3608 afs_int32 apart, int flags, afs_status_p st)
3611 afs_status_t tst = 0;
3613 afs_int32 nentries, tentries = 0;
3614 struct VldbListByAttributes attributes;
3615 nbulkentries arrayEntries;
3617 struct nvldbentry *vllist;
3620 afs_int32 modified = 0;
3623 arrayEntries.nbulkentries_val = 0;
3625 /* Set up attributes to search VLDB */
3626 attributes.server = ntohl(rx_HostOf(rx_PeerOf(server)));
3627 attributes.Mask = VLLIST_SERVER;
3629 attributes.partition = apart;
3630 attributes.Mask |= VLLIST_PARTITION;
3633 for (si = 0; si != -1; si = nsi) {
3634 /*initialize to hint the stub to alloc space */
3635 memset(&arrayEntries, 0, sizeof(arrayEntries));
3636 if (!VLDB_ListAttributes
3637 (cellHandle, &attributes, &nentries, &arrayEntries, &tst)) {
3638 goto fail_UV_SyncServer;
3641 tentries += nentries;
3643 for (j = 0; j < nentries; j++) { /* process each entry */
3644 vllist = &arrayEntries.nbulkentries_val[j];
3645 if (!CheckVldb(cellHandle, vllist, &modified, &tst)) {
3650 if (arrayEntries.nbulkentries_val) {
3651 free(arrayEntries.nbulkentries_val);
3652 arrayEntries.nbulkentries_val = 0;
3659 if (arrayEntries.nbulkentries_val) {
3660 free(arrayEntries.nbulkentries_val);
3663 tst = VOLSERFAILEDOP;
3670 /* rename volume <oldname> to <newname>, changing the names of the related
3671 * readonly and backup volumes. This operation is also idempotent.
3672 * salvager is capable of recovering from rename operation stopping halfway.
3673 * to recover run syncserver on the affected machines,it will force
3674 * renaming to completion. name clashes should have been detected before
3678 UV_RenameVolume(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3679 char *newname, afs_status_p st)
3682 afs_status_t tst = 0;
3683 afs_status_t etst = 0;
3686 char nameBuffer[256];
3688 struct rx_connection *aconn;
3691 aconn = (struct rx_connection *)0;
3695 tst = ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
3697 goto fail_UV_RenameVolume;
3701 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
3703 if (!VLDB_ReplaceEntry
3704 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, 0, &tst)) {
3705 goto fail_UV_RenameVolume;
3707 /*at this stage the intent to rename is recorded in the vldb, as far
3709 * is concerned, oldname is lost */
3710 if (entry->flags & RW_EXISTS) {
3711 index = Lp_GetRwIndex(cellHandle, entry, 0);
3712 if (index == -1) { /* there is a serious discrepancy */
3713 tst = VOLSERVLDB_ERROR;
3714 goto fail_UV_RenameVolume;
3717 UV_Bind(cellHandle, entry->serverNumber[index],
3718 AFSCONF_VOLUMEPORT);
3720 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
3721 entry->serverPartition[index], ITOffline, &tid);
3722 if (tst) { /*volume doesnot exist */
3723 goto fail_UV_RenameVolume;
3724 } else { /*volume exists, process it */
3727 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
3728 entry->volumeId[RWVOL],
3729 entry->volumeId[ROVOL],
3730 entry->volumeId[BACKVOL]);
3732 tst = AFSVolEndTrans(aconn, tid, &rcode);
3735 goto fail_UV_RenameVolume;
3738 goto fail_UV_RenameVolume;
3742 rx_ReleaseCachedConnection(aconn);
3743 aconn = (struct rx_connection *)0;
3745 /*end rw volume processing */
3746 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
3747 index = Lp_GetRwIndex(cellHandle, entry, 0);
3748 if (index == -1) { /* there is a serious discrepancy */
3749 tst = VOLSERVLDB_ERROR;
3750 goto fail_UV_RenameVolume;
3753 UV_Bind(cellHandle, entry->serverNumber[index],
3754 AFSCONF_VOLUMEPORT);
3756 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
3757 entry->serverPartition[index], ITOffline, &tid);
3758 if (tst) { /*volume doesnot exist */
3759 goto fail_UV_RenameVolume;
3760 } else { /*volume exists, process it */
3761 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
3762 goto fail_UV_RenameVolume;
3764 strcpy(nameBuffer, newname);
3765 strcat(nameBuffer, ".backup");
3768 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
3769 entry->volumeId[RWVOL], 0, 0);
3771 tst = AFSVolEndTrans(aconn, tid, &rcode);
3774 goto fail_UV_RenameVolume;
3777 goto fail_UV_RenameVolume;
3780 } /* end backup processing */
3782 rx_ReleaseCachedConnection(aconn);
3783 aconn = (struct rx_connection *)0;
3784 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
3785 for (i = 0; i < entry->nServers; i++) {
3786 if (entry->serverFlags[i] & ITSROVOL) {
3788 UV_Bind(cellHandle, entry->serverNumber[i],
3789 AFSCONF_VOLUMEPORT);
3791 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
3792 entry->serverPartition[i], ITOffline,
3794 if (tst) { /*volume doesnot exist */
3795 goto fail_UV_RenameVolume;
3796 } else { /*volume exists, process it */
3797 strcpy(nameBuffer, newname);
3798 strcat(nameBuffer, ".readonly");
3799 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
3800 goto fail_UV_RenameVolume;
3803 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
3804 entry->volumeId[RWVOL], 0, 0);
3806 tst = AFSVolEndTrans(aconn, tid, &rcode);
3809 goto fail_UV_RenameVolume;
3812 goto fail_UV_RenameVolume;
3816 rx_ReleaseCachedConnection(aconn);
3817 aconn = (struct rx_connection *)0;
3823 fail_UV_RenameVolume:
3827 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3828 entry->volumeId[RWVOL], RWVOL,
3829 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3836 etst = AFSVolEndTrans(aconn, tid, &rcode);
3843 rx_ReleaseCachedConnection(aconn);
3851 /*group all the volume entries on< apart >by their parentid or by their ids'
3852 *if the volume is rw. <count> is the number of entries to be processesd.
3853 *<pntr> points to the first entry.< myQueue> is the queue with entries
3856 GroupEntries(struct rx_connection *server, volintInfo * pntr, afs_int32 count,
3857 struct qHead *myQueue, afs_int32 apart)
3859 struct aqueue *qPtr;
3861 afs_int32 curId, code;
3863 afs_int32 error = 0;
3869 for (i = 0; i < count; i++) { /*process each entry */
3870 if (pntr->status) { /* entry is valid */
3871 if (pntr->type == RWVOL)
3872 curId = pntr->volid;
3874 curId = pntr->parentID;
3875 Lp_QScan(myQueue, curId, &success, &qPtr, 0);
3876 if (success) { /*entry exists in the queue */
3877 if (pntr->type == RWVOL) {
3878 /*check if the rw exists already, if so hang on the
3879 * later version if the present version is ok */
3880 if (qPtr->isValid[RWVOL]) {
3881 /*this should not happen, there is a serious error here */
3883 error = VOLSERMULTIRWVOL;
3885 qPtr->isValid[RWVOL] = 1;
3886 qPtr->copyDate[RWVOL] = pntr->copyDate;
3887 if (!qPtr->isValid[BACKVOL])
3888 qPtr->ids[BACKVOL] = pntr->backupID;
3889 if (!qPtr->isValid[ROVOL])
3890 qPtr->ids[ROVOL] = pntr->cloneID;
3892 } else if (pntr->type == BACKVOL) {
3893 if (qPtr->isValid[BACKVOL]) {
3894 /*do different checks, delete superflous volume */
3895 if (qPtr->copyDate[BACKVOL] > pntr->copyDate) {
3896 /*delete the present volume . */
3898 CheckAndDeleteVolume(server, apart, 0,
3906 /*delete the older volume after making sure, current one is ok */
3908 CheckAndDeleteVolume(server, apart,
3910 qPtr->ids[BACKVOL]);
3916 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3917 qPtr->ids[BACKVOL] = pntr->volid;
3921 qPtr->isValid[BACKVOL] = 1;
3922 qPtr->ids[BACKVOL] = pntr->volid;
3923 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3925 } else if (pntr->type == ROVOL) {
3926 if (qPtr->isValid[ROVOL]) {
3927 /*do different checks, delete superflous volume */
3928 if (qPtr->copyDate[ROVOL] > pntr->copyDate) {
3929 /*delete the present volume . */
3932 CheckAndDeleteVolume(server, apart, 0,
3939 /*delete the older volume after making sure, current one is ok */
3941 CheckAndDeleteVolume(server, apart,
3949 qPtr->copyDate[ROVOL] = pntr->copyDate;
3950 qPtr->ids[ROVOL] = pntr->volid;
3954 qPtr->isValid[ROVOL] = 1;
3955 qPtr->ids[ROVOL] = pntr->volid;
3956 qPtr->copyDate[ROVOL] = pntr->copyDate;
3960 error = VOLSERBADOP;
3962 } else { /*create a fresh entry */
3963 qPtr = (struct aqueue *)malloc(sizeof(struct aqueue));
3964 if (pntr->type == RWVOL) {
3965 qPtr->isValid[RWVOL] = 1;
3966 qPtr->isValid[BACKVOL] = 0;
3967 qPtr->isValid[ROVOL] = 0;
3968 qPtr->ids[RWVOL] = pntr->volid;
3969 qPtr->ids[BACKVOL] = pntr->backupID;
3970 qPtr->ids[ROVOL] = pntr->cloneID;
3971 qPtr->copyDate[RWVOL] = pntr->copyDate;
3972 strncpy(qPtr->name, pntr->name, VOLSER_OLDMAXVOLNAME);
3974 } else if (pntr->type == BACKVOL) {
3975 qPtr->isValid[RWVOL] = 0;
3976 qPtr->isValid[BACKVOL] = 1;
3977 qPtr->isValid[ROVOL] = 0;
3978 qPtr->ids[RWVOL] = pntr->parentID;
3979 qPtr->ids[BACKVOL] = pntr->volid;
3980 qPtr->ids[ROVOL] = 0;
3981 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3982 vsu_ExtractName(qPtr->name, pntr->name);
3984 } else if (pntr->type == ROVOL) {
3985 qPtr->isValid[RWVOL] = 0;
3986 qPtr->isValid[BACKVOL] = 0;
3987 qPtr->isValid[ROVOL] = 1;
3988 qPtr->ids[RWVOL] = pntr->parentID;
3989 qPtr->ids[BACKVOL] = 0;
3990 qPtr->ids[ROVOL] = pntr->volid;
3991 qPtr->copyDate[ROVOL] = pntr->copyDate;
3992 vsu_ExtractName(qPtr->name, pntr->name);
3996 Lp_QAdd(myQueue, qPtr);
3998 pntr++; /*get next entry */
4008 /*report on all the active transactions on volser */
4010 UV_VolserStatus(struct rx_connection *server, transDebugInfo ** rpntr,
4011 afs_int32 * rcount, afs_status_p st)
4014 afs_status_t tst = 0;
4015 transDebugEntries transInfo;
4017 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
4018 transInfo.transDebugEntries_len = 0;
4019 tst = AFSVolMonitor(server, &transInfo);
4021 goto fail_UV_VolserStatus;
4024 *rcount = transInfo.transDebugEntries_len;
4025 *rpntr = transInfo.transDebugEntries_val;
4028 fail_UV_VolserStatus:
4031 if (transInfo.transDebugEntries_val) {
4032 free(transInfo.transDebugEntries_val);
4042 /*delete the volume without interacting with the vldb */
4044 UV_VolumeZap(afs_cell_handle_p cellHandle, struct rx_connection *server,
4045 unsigned int partition, afs_uint32 volumeId, afs_status_p st)
4047 afs_int32 rcode, ttid;
4049 afs_status_t tst = 0;
4053 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
4055 tst = AFSVolDeleteVolume(server, ttid);
4057 tst = AFSVolEndTrans(server, ttid, &rcode);
4065 * We failed to delete the volume, but we still need
4066 * to end the transaction.
4068 AFSVolEndTrans(server, ttid, &rcode);
4080 UV_SetVolume(struct rx_connection *server, afs_int32 partition,
4081 afs_uint32 volid, afs_int32 transflag, afs_int32 setflag,
4082 unsigned int sleepTime, afs_status_p st)
4085 afs_status_t tst = 0;
4086 afs_status_t etst = 0;
4090 tst = AFSVolTransCreate(server, volid, partition, transflag, &tid);
4092 goto fail_UV_SetVolume;
4095 tst = AFSVolSetFlags(server, tid, setflag);
4097 goto fail_UV_SetVolume;
4108 etst = AFSVolEndTrans(server, tid, &rcode);
4109 /* FIXME: this looks like a typo */
4112 tst = (etst ? etst : rcode);