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>
29 #include "lockprocs.h"
30 #include "../adminutil/afs_AdminInternal.h"
31 #include <afs/afs_AdminErrors.h>
32 #include "afs_vosAdmin.h"
47 static afs_int32 GroupEntries();
51 afs_int32 vldbEntryIndex;
54 static struct rx_connection *
55 UV_Bind(afs_cell_handle_p cellHandle, afs_int32 aserver, afs_int32 port)
57 return rx_GetCachedConnection(htonl(aserver), htons(port), VOLSERVICE_ID,
58 cellHandle->tokens->afs_sc[cellHandle->
61 cellHandle->tokens->sc_index);
65 /* if <okvol> is allright(indicated by beibg able to
66 * start a transaction, delete the <delvol> */
68 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
69 afs_int32 okvol, afs_int32 delvol)
71 afs_int32 error, code, tid, rcode;
77 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
80 code = AFSVolDeleteVolume(aconn, tid);
83 code = AFSVolEndTrans(aconn, tid, &rcode);
90 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
92 code = AFSVolEndTrans(aconn, tid, &rcode);
97 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
100 code = AFSVolDeleteVolume(aconn, tid);
103 code = AFSVolEndTrans(aconn, tid, &rcode);
114 /* forcibly remove a volume. Very dangerous call */
116 UV_NukeVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
117 unsigned int partition, unsigned int volumeId, afs_status_p st)
120 afs_status_t tst = 0;
122 tst = AFSVolNukeVolume(server, partition, volumeId);
134 /* create a volume, given a server, partition number, volume name --> sends
135 * back new vol id in <anewid>*/
137 UV_CreateVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
138 unsigned int partition, const char *volumeName,
139 unsigned int quota, unsigned int *volumeId, afs_status_p st)
142 afs_status_t tst = 0;
145 struct nvldbentry entry;
146 struct volintInfo tstatus;
148 memset(&tstatus, 0, sizeof(tstatus));
150 tstatus.maxquota = quota;
152 /* next the next 3 available ids from the VLDB */
153 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 3, volumeId);
155 goto fail_UV_CreateVolume;
159 AFSVolCreateVolume(server, partition, volumeName, volser_RW, 0,
162 goto fail_UV_CreateVolume;
165 AFSVolSetInfo(server, tid, &tstatus);
167 tst = AFSVolSetFlags(server, tid, 0);
169 goto fail_UV_CreateVolume;
172 /* set up the vldb entry for this volume */
173 strncpy(entry.name, volumeName, VOLSER_OLDMAXVOLNAME);
175 entry.serverNumber[0] = ntohl(rx_HostOf(rx_PeerOf(server)));
176 entry.serverPartition[0] = partition;
177 entry.flags = RW_EXISTS;
178 entry.serverFlags[0] = ITSRWVOL;
179 entry.volumeId[RWVOL] = *volumeId;
180 entry.volumeId[ROVOL] = *volumeId + 1;
181 entry.volumeId[BACKVOL] = *volumeId + 2;
184 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
185 AFSVolDeleteVolume(server, tid);
186 goto fail_UV_CreateVolume;
189 tst = AFSVolEndTrans(server, tid, &rcode);
192 goto fail_UV_CreateVolume;
196 fail_UV_CreateVolume:
199 AFSVolEndTrans(server, tid, &rcode);
209 /* Delete the volume <volid>on <aserver> <apart>
210 * the physical entry gets removed from the vldb only if the ref count
214 UV_DeleteVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
215 unsigned int partition, unsigned int volumeId,
219 afs_status_t tst = 0;
220 afs_status_t temp = 0;
221 int serverAddr = ntohl(rx_HostOf(rx_PeerOf(server)));
225 struct nvldbentry entry;
227 afs_int32 avoltype = -1, vtype;
228 int notondisk = 0, notinvldb = 0;
230 /* Find and read the VLDB entry for this volume */
232 ubik_VL_SetLock(cellHandle->vos, 0, volumeId, avoltype,
235 if (tst != VL_NOENT) {
236 goto fail_UV_DeleteVolume;
242 if (!aVLDB_GetEntryByID(cellHandle, volumeId, avoltype, &entry, &tst)) {
243 goto fail_UV_DeleteVolume;
248 /* Whether volume is in the VLDB or not. Delete the volume on disk */
249 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
254 goto fail_UV_DeleteVolume;
257 tst = AFSVolDeleteVolume(server, ttid);
259 goto fail_UV_DeleteVolume;
261 tst = AFSVolEndTrans(server, ttid, &rcode);
262 tst = (tst ? tst : rcode);
265 goto fail_UV_DeleteVolume;
270 goto fail_UV_DeleteVolume;
273 if (volumeId == entry.volumeId[BACKVOL]) {
274 if (!(entry.flags & BACK_EXISTS)
275 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
277 goto fail_UV_DeleteVolume;
280 entry.flags &= ~BACK_EXISTS;
284 else if (volumeId == entry.volumeId[ROVOL]) {
285 if (!Lp_ROMatch(cellHandle, &entry, serverAddr, partition, &tst)) {
287 goto fail_UV_DeleteVolume;
290 Lp_SetROValue(cellHandle, &entry, serverAddr, partition, 0, 0);
292 if (!Lp_ROMatch(cellHandle, &entry, 0, 0, &tst)) {
293 entry.flags &= ~RO_EXISTS;
298 else if (volumeId == entry.volumeId[RWVOL]) {
299 if (!(entry.flags & RW_EXISTS)
300 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
302 goto fail_UV_DeleteVolume;
305 /* Delete backup if it exists */
307 AFSVolTransCreate(server, entry.volumeId[BACKVOL], partition,
310 tst = AFSVolDeleteVolume(server, ttid);
312 goto fail_UV_DeleteVolume;
314 tst = AFSVolEndTrans(server, ttid, &rcode);
316 tst = (tst ? tst : rcode);
318 goto fail_UV_DeleteVolume;
322 Lp_SetRWValue(cellHandle, &entry, serverAddr, partition, 0L, 0L);
324 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
330 notinvldb = 2; /* Not found on this server and partition */
331 goto fail_UV_DeleteVolume;
334 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
335 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volumeId, vtype);
337 goto fail_UV_DeleteVolume;
340 if (!VLDB_ReplaceEntry
341 (cellHandle, volumeId, vtype, &entry,
342 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
343 goto fail_UV_DeleteVolume;
349 fail_UV_DeleteVolume:
351 if (notondisk && notinvldb) {
353 tst = ADMVOSVOLUMENOEXIST;
357 temp = AFSVolEndTrans(server, ttid, &rcode);
358 temp = (temp ? temp : rcode);
367 ubik_VL_ReleaseLock(cellHandle->vos, 0, volumeId, -1,
368 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
381 #define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto mfail; }
383 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
384 * <atopart>. The operation is almost idempotent
388 UV_MoveVolume(afs_cell_handle_p cellHandle, afs_int32 afromvol,
389 afs_int32 afromserver, afs_int32 afrompart, afs_int32 atoserver,
390 afs_int32 atopart, afs_status_p st)
393 afs_status_t tst = 0;
394 afs_status_t etst = 0;
395 struct rx_connection *toconn, *fromconn;
396 afs_int32 fromtid, totid, clonetid;
399 char tmpName[VOLSER_MAXVOLNAME + 1];
402 struct restoreCookie cookie;
403 afs_int32 newVol, volid, backupId;
404 struct volser_status tstatus;
405 struct destServer destination;
407 struct nvldbentry entry;
411 afs_int32 store_flags;
413 #ifdef ENABLE_BUGFIX_1165
414 volEntries volumeInfo;
415 struct volintInfo *infop = 0;
419 fromconn = (struct rx_connection *)0;
420 toconn = (struct rx_connection *)0;
430 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
431 goto fail_UV_MoveVolume;
434 if (entry.volumeId[RWVOL] != afromvol) {
435 tst = ADMVOSVOLUMEMOVERWONLY;
436 goto fail_UV_MoveVolume;
440 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL, VLOP_MOVE);
442 goto fail_UV_MoveVolume;
446 if (!aVLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
447 goto fail_UV_MoveVolume;
450 backupId = entry.volumeId[BACKVOL];
452 if (!Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst)) {
453 /* the from server and partition do not exist in the vldb entry corresponding to volid */
454 if (!Lp_Match(cellHandle, &entry, atoserver, atopart, &tst)) {
455 /* the to server and partition do not exist in the vldb entry corresponding to volid */
457 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
458 (LOCKREL_OPCODE | LOCKREL_AFSID |
461 goto fail_UV_MoveVolume;
463 tst = VOLSERVOLMOVED;
464 goto fail_UV_MoveVolume;
467 /* delete the volume afromvol on src_server */
468 /* from-info does not exist but to-info does =>
469 * we have already done the move, but the volume
470 * may still be existing physically on from fileserver
472 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
477 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
479 if (!tst) { /* volume exists - delete it */
481 AFSVolSetFlags(fromconn, fromtid,
482 VTDeleteOnSalvage | VTOutOfService);
484 goto fail_UV_MoveVolume;
487 tst = AFSVolDeleteVolume(fromconn, fromtid);
489 goto fail_UV_MoveVolume;
492 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
497 goto fail_UV_MoveVolume;
501 /*delete the backup volume now */
504 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
506 if (!tst) { /* backup volume exists - delete it */
508 AFSVolSetFlags(fromconn, fromtid,
509 VTDeleteOnSalvage | VTOutOfService);
511 goto fail_UV_MoveVolume;
514 tst = AFSVolDeleteVolume(fromconn, fromtid);
516 goto fail_UV_MoveVolume;
519 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
524 goto fail_UV_MoveVolume;
530 goto fail_UV_MoveVolume;
533 /* From-info matches the vldb info about volid,
534 * its ok start the move operation, the backup volume
535 * on the old site is deleted in the process
537 if (afrompart == atopart) {
538 if (!VLDB_IsSameAddrs
539 (cellHandle, afromserver, atoserver, &same, &tst)) {
540 goto fail_UV_MoveVolume;
543 tst = VOLSERVOLMOVED;
544 goto fail_UV_MoveVolume;
549 toconn = UV_Bind(cellHandle, atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
550 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
551 fromtid = totid = 0; /* initialize to uncreated */
554 * clone the read/write volume locally.
557 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
559 goto fail_UV_MoveVolume;
564 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &newVol);
566 goto fail_UV_MoveVolume;
569 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
570 strcpy(vname, "move-clone-temp");
571 tst = AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
573 goto fail_UV_MoveVolume;
576 /* lookup the name of the volume we just cloned */
578 tst = AFSVolGetName(fromconn, fromtid, &volName);
580 goto fail_UV_MoveVolume;
584 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
589 goto fail_UV_MoveVolume;
593 * Create the destination volume
597 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
599 goto fail_UV_MoveVolume;
601 tst = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
603 goto fail_UV_MoveVolume;
606 /* remember time from which we've dumped the volume */
607 tst = AFSVolGetStatus(fromconn, clonetid, &tstatus);
609 goto fail_UV_MoveVolume;
612 fromDate = tstatus.creationDate - CLOCKSKEW;
614 #ifdef ENABLE_BUGFIX_1165
616 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
617 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
618 * don't use this information...
620 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
621 volumeInfo.volEntries_len = 0;
622 tst = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
624 goto fail_UV_MoveVolume;
627 infop = (volintInfo *) volumeInfo.volEntries_val;
628 infop->maxquota = -1; /* Else it will replace the default quota */
631 /* create a volume on the target machine */
633 tst = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
634 if (!tst) { /*delete the existing volume */
636 tst = AFSVolDeleteVolume(toconn, totid);
638 goto fail_UV_MoveVolume;
641 tst = AFSVolEndTrans(toconn, totid, &rcode);
646 goto fail_UV_MoveVolume;
652 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
655 goto fail_UV_MoveVolume;
658 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
662 tst = AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
664 goto fail_UV_MoveVolume;
668 * Now dump the clone to the new volume
671 destination.destHost = atoserver;
672 destination.destPort = AFSCONF_VOLUMEPORT;
673 destination.destSSID = 1;
675 /* Copy the clone to the new volume */
676 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
678 cookie.parent = entry.volumeId[RWVOL];
680 tst = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
682 goto fail_UV_MoveVolume;
685 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
690 goto fail_UV_MoveVolume;
694 * reattach to the main-line volume, and incrementally dump it.
697 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
699 goto fail_UV_MoveVolume;
702 /* now do the incremental */
704 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
707 goto fail_UV_MoveVolume;
710 /* now adjust the flags so that the new volume becomes official */
711 tst = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
713 goto fail_UV_MoveVolume;
716 tst = AFSVolSetFlags(toconn, totid, 0);
718 goto fail_UV_MoveVolume;
720 #ifdef ENABLE_BUGFIX_1165
721 tst = AFSVolSetInfo(toconn, totid, infop);
723 goto fail_UV_MoveVolume;
727 /* put new volume online */
728 tst = AFSVolEndTrans(toconn, totid, &rcode);
733 goto fail_UV_MoveVolume;
736 Lp_SetRWValue(cellHandle, &entry, afromserver, afrompart, atoserver,
738 store_flags = entry.flags;
739 entry.flags &= ~BACK_EXISTS;
741 if (!VLDB_ReplaceEntry
742 (cellHandle, afromvol, -1, &entry,
743 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
744 goto fail_UV_MoveVolume;
746 entry.flags = store_flags;
749 if (atoserver != afromserver) {
750 /* set forwarding pointer for moved volumes */
751 tst = AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
753 goto fail_UV_MoveVolume;
757 tst = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
759 goto fail_UV_MoveVolume;
762 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
767 goto fail_UV_MoveVolume;
770 /* Delete the backup volume on the original site */
772 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
775 AFSVolSetFlags(fromconn, fromtid,
776 VTDeleteOnSalvage | VTOutOfService);
778 goto fail_UV_MoveVolume;
781 tst = AFSVolDeleteVolume(fromconn, fromtid);
783 goto fail_UV_MoveVolume;
786 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
791 goto fail_UV_MoveVolume;
795 tst = 0; /* no backup volume? that's okay */
800 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
802 goto fail_UV_MoveVolume;
805 /* now delete the clone */
807 tst = AFSVolDeleteVolume(fromconn, clonetid);
809 goto fail_UV_MoveVolume;
812 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
817 goto fail_UV_MoveVolume;
823 /* normal cleanup code */
827 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
828 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
836 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
839 tst = (etst ? etst : rcode);
844 etst = AFSVolEndTrans(fromconn, clonetid, &rcode);
847 tst = (etst ? etst : rcode);
852 etst = AFSVolEndTrans(toconn, totid, &rcode);
855 tst = (etst ? etst : rcode);
860 #ifdef ENABLE_BUGFIX_1165
865 rx_ReleaseCachedConnection(fromconn);
867 rx_ReleaseCachedConnection(toconn);
875 /* come here only when the sky falls */
879 /* unlock VLDB entry */
881 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
882 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
885 AFSVolEndTrans(fromconn, clonetid, &rcode);
887 AFSVolEndTrans(toconn, totid, &rcode);
888 if (fromtid) { /* put it on-line */
889 AFSVolSetFlags(fromconn, fromtid, 0);
890 AFSVolEndTrans(fromconn, fromtid, &rcode);
893 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
897 /* Delete either the volume on the source location or the target location.
898 * If the vldb entry still points to the source location, then we know the
899 * volume move didn't finish so we remove the volume from the target
900 * location. Otherwise, we remove the volume from the source location.
902 if (Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst)) { /* didn't move - delete target volume */
904 if (volid && toconn) {
906 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
908 AFSVolSetFlags(toconn, totid,
909 VTDeleteOnSalvage | VTOutOfService);
910 AFSVolDeleteVolume(toconn, totid);
911 AFSVolEndTrans(toconn, totid, &rcode);
915 /* put source volume on-line */
918 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
921 AFSVolSetFlags(fromconn, fromtid, 0);
922 AFSVolEndTrans(fromconn, fromtid, &rcode);
925 } else { /* yep, move complete */
926 /* delete backup volume */
929 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
932 AFSVolSetFlags(fromconn, fromtid,
933 VTDeleteOnSalvage | VTOutOfService);
934 AFSVolDeleteVolume(fromconn, fromtid);
935 AFSVolEndTrans(fromconn, fromtid, &rcode);
938 /* delete source volume */
940 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
943 AFSVolSetFlags(fromconn, fromtid,
944 VTDeleteOnSalvage | VTOutOfService);
945 if (atoserver != afromserver)
946 AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
947 AFSVolDeleteVolume(fromconn, fromtid);
948 AFSVolEndTrans(fromconn, fromtid, &rcode);
953 /* common cleanup - delete local clone */
956 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
959 AFSVolDeleteVolume(fromconn, clonetid);
960 AFSVolEndTrans(fromconn, clonetid, &rcode);
964 /* unlock VLDB entry */
965 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
966 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
968 done: /* routine cleanup */
971 #ifdef ENABLE_BUGFIX_1165
976 rx_ReleaseCachedConnection(fromconn);
978 rx_ReleaseCachedConnection(toconn);
986 /* Make a new backup of volume <avolid> on <aserver> and <apart>
987 * if one already exists, update it
991 UV_BackupVolume(afs_cell_handle_p cellHandle, afs_int32 aserver,
992 afs_int32 apart, afs_int32 avolid, afs_status_p st)
995 afs_status_t tst = 0, temp = 0;
996 afs_int32 ttid = 0, btid = 0;
999 char vname[VOLSER_MAXVOLNAME + 1];
1000 struct nvldbentry entry;
1001 int vldblocked = 0, vldbmod = 0, backexists = 1;
1002 struct rx_connection *aconn = UV_Bind(cellHandle, aserver,
1003 AFSCONF_VOLUMEPORT);
1006 /* the calls to VLDB will succeed only if avolid is a RW volume,
1007 * since we are following the RW hash chain for searching */
1008 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
1009 goto fail_UV_BackupVolume;
1012 /* These operations require the VLDB be locked since it means the VLDB
1013 * will change or the vldb is already locked.
1015 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
1016 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
1017 (entry.volumeId[BACKVOL] == INVALID_BID)) {
1018 /* no assigned backup volume id */
1021 ubik_VL_SetLock(cellHandle->vos, 0, avolid, RWVOL,
1024 goto fail_UV_BackupVolume;
1028 /* Reread the vldb entry */
1029 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
1030 goto fail_UV_BackupVolume;
1034 if (!ISNAMEVALID(entry.name)) {
1035 tst = VOLSERBADNAME;
1036 goto fail_UV_BackupVolume;
1039 backupID = entry.volumeId[BACKVOL];
1040 if (backupID == INVALID_BID) {
1041 /* Get a backup volume id from the VLDB and update the vldb
1044 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &backupID);
1046 goto fail_UV_BackupVolume;
1048 entry.volumeId[BACKVOL] = backupID;
1052 /* Test to see if the backup volume exists by trying to create
1053 * a transaction on the backup volume. We've assumed the backup exists.
1055 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1057 if (tst != VNOVOL) {
1058 goto fail_UV_BackupVolume;
1060 backexists = 0; /* backup volume does not exist */
1063 tst = AFSVolEndTrans(aconn, btid, &rcode);
1066 tst = (tst ? tst : rcode);
1067 goto fail_UV_BackupVolume;
1071 /* Now go ahead and try to clone the RW volume.
1072 * First start a transaction on the RW volume
1074 tst = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
1076 goto fail_UV_BackupVolume;
1079 /* Clone or reclone the volume, depending on whether the backup
1080 * volume exists or not
1083 tst = AFSVolReClone(aconn, ttid, backupID);
1085 goto fail_UV_BackupVolume;
1088 strcpy(vname, entry.name);
1089 strcat(vname, ".backup");
1091 tst = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
1093 goto fail_UV_BackupVolume;
1097 /* End transaction on the RW volume */
1098 tst = AFSVolEndTrans(aconn, ttid, &rcode);
1101 tst = (tst ? tst : rcode);
1102 goto fail_UV_BackupVolume;
1105 /* Mork vldb as backup exists */
1106 if (!(entry.flags & BACK_EXISTS)) {
1107 entry.flags |= BACK_EXISTS;
1111 /* Now go back to the backup volume and bring it on line */
1112 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1114 goto fail_UV_BackupVolume;
1117 tst = AFSVolSetFlags(aconn, btid, 0);
1119 goto fail_UV_BackupVolume;
1122 tst = AFSVolEndTrans(aconn, btid, &rcode);
1125 tst = (tst ? tst : rcode);
1126 goto fail_UV_BackupVolume;
1130 /* Will update the vldb below */
1132 fail_UV_BackupVolume:
1135 temp = AFSVolEndTrans(aconn, ttid, &rcode);
1136 if (temp || rcode) {
1138 tst = (temp ? temp : rcode);
1143 temp = AFSVolEndTrans(aconn, btid, &rcode);
1144 if (temp || rcode) {
1146 tst = (temp ? temp : rcode);
1150 /* Now update the vldb - if modified */
1153 if (!VLDB_ReplaceEntry
1154 (cellHandle, avolid, RWVOL, &entry,
1155 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
1163 ubik_VL_ReleaseLock(cellHandle->vos, 0, avolid, RWVOL,
1164 (LOCKREL_OPCODE | LOCKREL_AFSID |
1165 LOCKREL_TIMESTAMP));
1175 rx_ReleaseCachedConnection(aconn);
1185 DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
1188 afs_int32 acode, ccode, rcode, tid;
1189 ccode = rcode = tid = 0;
1191 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
1192 if (!acode) { /* It really was there */
1193 acode = AFSVolDeleteVolume(conn, tid);
1194 ccode = AFSVolEndTrans(conn, tid, &rcode);
1202 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
1203 #define ERROREXIT(ec) { error = (ec); goto rfail; }
1205 #if 0 /* doesn't appear to be used, why compile it */
1207 CloneVol(afs_cell_handle_p cellHandle, struct rx_connection *conn,
1208 afs_int32 rwvid, afs_int32 part, afs_int32 * rovidp, int nottemp,
1209 struct nvldbentry *entry, afs_int32 * vidCreateDate, afs_status_p st)
1212 afs_status_t tst = 0, etst = 0;
1213 afs_int32 rcode = 0, tid = 0;
1214 struct volser_status volstatus;
1217 /* Begin transaction on RW volume marking it busy (clients will wait) */
1218 tst = AFSVolTransCreate(conn, rwvid, part, ITBusy, &tid);
1223 /* Get the RO volume id. Allocate a new one if need to */
1224 *rovidp = entry->volumeId[ROVOL];
1225 if (*rovidp == INVALID_BID) {
1226 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, rovidp);
1231 entry->volumeId[ROVOL] = *rovidp;
1234 /* If we are creating the ro clone, what are we calling it.
1235 * Depends on whether its a temporary clone or not.
1238 strcpy(vname, entry->name);
1239 strcat(vname, ".readonly");
1241 strcpy(vname, "readonly-clone-temp"); /* Should be unique? */
1244 /* Create the new clone. If it exists, then reclone it */
1245 tst = AFSVolClone(conn, tid, 0, readonlyVolume, vname, rovidp);
1246 if (tst == VVOLEXISTS) {
1247 tst = AFSVolReClone(conn, tid, *rovidp);
1256 /* Bring the volume back on-line as soon as possible */
1258 afs_int32 fromtid = 0;
1260 /* Now bring the RO clone on-line */
1261 tst = AFSVolTransCreate(conn, *rovidp, part, ITOffline, &fromtid);
1266 tst = AFSVolSetFlags(conn, fromtid, 0);
1271 tst = AFSVolEndTrans(conn, fromtid, &rcode);
1280 /* Get the time the RW was created for return information */
1281 tst = AFSVolGetStatus(conn, tid, &volstatus);
1285 *vidCreateDate = volstatus.creationDate;
1291 tst = AFSVolEndTrans(conn, tid, &rcode);
1308 /* Get a "transaction" on this replica. Create the volume
1309 * if necessary. Return the time from which a dump should
1310 * be made (0 if it's a new volume)
1313 GetTrans(afs_cell_handle_p cellHandle, struct nvldbentry *vldbEntryPtr,
1314 afs_int32 index, struct rx_connection **connPtr,
1315 afs_int32 * transPtr, afs_int32 * timePtr, afs_status_p st)
1318 afs_status_t tst = 0, etst = 0;
1320 struct volser_status tstatus;
1323 *connPtr = (struct rx_connection *)0;
1327 /* get connection to the replication site */
1329 UV_Bind(cellHandle, vldbEntryPtr->serverNumber[index],
1330 AFSCONF_VOLUMEPORT);
1332 /* server is down */
1337 volid = vldbEntryPtr->volumeId[ROVOL];
1340 AFSVolTransCreate(*connPtr, volid,
1341 vldbEntryPtr->serverPartition[index], ITOffline,
1345 /* If the volume does not exist, create it */
1346 if (!volid || tst) {
1349 if (volid && (tst != VNOVOL)) {
1353 strcpy(volname, vldbEntryPtr->name);
1354 strcat(volname, ".readonly");
1357 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
1359 vldbEntryPtr->volumeId[RWVOL], &volid,
1364 vldbEntryPtr->volumeId[ROVOL] = volid;
1366 /* The following is a bit redundant, since create sets these flags by default */
1368 AFSVolSetFlags(*connPtr, *transPtr,
1369 VTDeleteOnSalvage | VTOutOfService);
1375 /* Otherwise, the transaction did succeed, so get the creation date of the
1376 * latest RO volume on the replication site
1379 tst = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
1383 *timePtr = tstatus.creationDate - CLOCKSKEW;
1389 if ((rc == 0) && (*transPtr)) {
1390 etst = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
1403 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
1404 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
1405 void *cookie, manyResults * results)
1409 for (i = 0; i < tr->manyDests_len; i++) {
1410 results->manyResults_val[i] =
1411 AFSVolForward(fromconn, fromtid, fromdate,
1412 &(tr->manyDests_val[i].server),
1413 tr->manyDests_val[i].trans, cookie);
1420 * Determine if a volume exists on a server and partition.
1421 * Try creating a transaction on the volume. If we can,
1422 * the volume exists, if not, then return the error code.
1423 * Some error codes mean the volume is unavailable but
1424 * still exists - so we catch these error codes.
1427 VolumeExists(afs_cell_handle_p cellHandle, afs_int32 server,
1428 afs_int32 partition, afs_int32 volumeid, afs_status_p st)
1431 afs_status_t tst = 0;
1432 struct rx_connection *conn = (struct rx_connection *)0;
1433 volEntries volumeInfo;
1435 conn = UV_Bind(cellHandle, server, AFSCONF_VOLUMEPORT);
1437 volumeInfo.volEntries_val = (volintInfo *) 0;
1438 volumeInfo.volEntries_len = 0;
1439 tst = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
1440 if (volumeInfo.volEntries_val)
1441 free(volumeInfo.volEntries_val);
1442 if (tst == VOLSERILLEGAL_PARTITION) {
1445 rx_ReleaseCachedConnection(conn);
1455 /* release volume <afromvol> on <afromserver> <afrompart> to all the
1456 * sites if forceflag is 1.If its 0 complete the release if the previous
1457 * release aborted else start a new release */
1459 UV_ReleaseVolume(afs_cell_handle_p cellHandle, afs_int32 afromvol,
1460 afs_int32 afromserver, afs_int32 afrompart, int forceflag,
1464 afs_status_t tst = 0, etst = 0;
1468 afs_int32 cloneVolId, roVolId;
1469 struct replica *replicas = 0;
1470 struct nvldbentry entry;
1471 int i, volcount, m, fullrelease, vldbindex;
1473 struct restoreCookie cookie;
1474 struct rx_connection **toconns = 0;
1475 struct release *times = 0;
1477 struct rx_connection *fromconn = (struct rx_connection *)0;
1479 afs_int32 clonetid = 0, onlinetid;
1480 afs_int32 fromtid = 0;
1481 afs_uint32 fromdate = 0, thisdate;
1484 manyResults results;
1485 int rwindex, roindex, roclone, roexists;
1486 afs_int32 rwcrdate = 0;
1490 } remembertime[NMAXNSERVERS];
1491 int releasecount = 0;
1492 struct volser_status volstatus;
1494 memset((char *)remembertime, 0, sizeof(remembertime));
1495 memset((char *)&results, 0, sizeof(results));
1498 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL,
1500 if ((tst) && (tst != VL_RERELEASE)) {
1501 goto fail_UV_ReleaseVolume;
1505 /* Get the vldb entry in readable format */
1506 if (!aVLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
1507 goto fail_UV_ReleaseVolume;
1510 if (!ISNAMEVALID(entry.name)) {
1511 tst = VOLSERBADNAME;
1512 goto fail_UV_ReleaseVolume;
1515 if (entry.volumeId[RWVOL] != afromvol) {
1516 tst = ADMVOSVOLUMERELEASERWONLY;
1517 goto fail_UV_ReleaseVolume;
1520 if (entry.nServers <= 1) {
1521 tst = ADMVOSVOLUMENOREPLICAS;
1522 goto fail_UV_ReleaseVolume;
1525 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10)) {
1526 tst = VOLSERBADNAME;
1527 goto fail_UV_ReleaseVolume;
1530 /* roclone is true if one of the RO volumes is on the same
1531 * partition as the RW volume. In this case, we make the RO volume
1532 * on the same partition a clone instead of a complete copy.
1536 Lp_ROMatch(cellHandle, &entry, afromserver, afrompart, &tst) - 1;
1537 roclone = ((roindex == -1) ? 0 : 1);
1538 rwindex = Lp_GetRwIndex(cellHandle, &entry, 0);
1541 goto fail_UV_ReleaseVolume;
1544 /* Make sure we have a RO volume id to work with */
1545 if (entry.volumeId[ROVOL] == INVALID_BID) {
1546 /* need to get a new RO volume id */
1547 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &roVolId);
1549 goto fail_UV_ReleaseVolume;
1552 entry.volumeId[ROVOL] = roVolId;
1553 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1554 goto fail_UV_ReleaseVolume;
1558 /* Will we be completing a previously unfinished release. -force overrides */
1559 for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) {
1560 if (entry.serverFlags[i] & NEW_REPSITE)
1563 if (forceflag && !fullrelease)
1566 /* Determine which volume id to use and see if it exists */
1569 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
1570 VolumeExists(cellHandle, afromserver, afrompart, cloneVolId, &tst);
1571 roexists = ((tst == ENODEV) ? 0 : 1);
1572 if (!roexists && !fullrelease)
1573 fullrelease = 1; /* Do a full release if RO clone does not exist */
1575 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
1578 goto fail_UV_ReleaseVolume;
1582 /* If the RO clone exists, then if the clone is a temporary
1583 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
1584 * (it was recently added), then also delete it. We do not
1585 * want to "reclone" a temporary RO clone.
1588 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
1589 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1590 if (tst && (tst != VNOVOL)) {
1591 goto fail_UV_ReleaseVolume;
1596 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
1597 * write this entry out to the vlserver until after the first
1598 * RO volume is released (temp RO clones don't count).
1600 for (i = 0; i < entry.nServers; i++) {
1601 entry.serverFlags[i] &= ~NEW_REPSITE;
1602 entry.serverFlags[i] |= RO_DONTUSE;
1604 entry.serverFlags[rwindex] |= NEW_REPSITE;
1605 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
1607 /* Begin transaction on RW and mark it busy while we clone it */
1609 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1612 goto fail_UV_ReleaseVolume;
1615 /* Clone or reclone the volume */
1617 tst = AFSVolReClone(fromconn, clonetid, cloneVolId);
1619 goto fail_UV_ReleaseVolume;
1623 strcpy(vname, entry.name);
1624 strcat(vname, ".readonly");
1626 strcpy(vname, "readonly-clone-temp");
1629 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
1632 goto fail_UV_ReleaseVolume;
1636 /* Get the time the RW was created for future information */
1637 tst = AFSVolGetStatus(fromconn, clonetid, &volstatus);
1639 goto fail_UV_ReleaseVolume;
1641 rwcrdate = volstatus.creationDate;
1643 /* End the transaction on the RW volume */
1644 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1646 tst = (tst ? tst : rcode);
1648 goto fail_UV_ReleaseVolume;
1651 /* Remember clone volume ID in case we fail or are interrupted */
1652 entry.cloneId = cloneVolId;
1655 /* Bring the RO clone online - though not if it's a temporary clone */
1657 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
1660 goto fail_UV_ReleaseVolume;
1663 etst = AFSVolSetFlags(fromconn, onlinetid, 0);
1665 tst = AFSVolEndTrans(fromconn, onlinetid, &rcode);
1666 tst = (tst ? tst : rcode);
1668 goto fail_UV_ReleaseVolume;
1672 goto fail_UV_ReleaseVolume;
1675 /* Sleep so that a client searching for an online volume won't
1676 * find the clone offline and then the next RO offline while the
1677 * release brings the clone online and the next RO offline (race).
1678 * There is a fix in the 3.4 client that does not need this sleep
1679 * anymore, but we don't know what clients we have.
1681 if (entry.nServers > 2)
1684 /* Mark the RO clone in the VLDB as a good site (already released) */
1685 entry.serverFlags[roindex] |= NEW_REPSITE;
1686 entry.serverFlags[roindex] &= ~RO_DONTUSE;
1687 entry.flags |= RO_EXISTS;
1691 /* Write out the VLDB entry only if the clone is not a temporary
1692 * clone. If we did this to a temporary clone then we would end
1693 * up marking all the ROs as "old release" making the ROs
1694 * temporarily unavailable.
1696 if (!VLDB_ReplaceEntry
1697 (cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1698 goto fail_UV_ReleaseVolume;
1703 /* Now we will release from the clone to the remaining RO replicas.
1704 * The first 2 ROs (counting the non-temporary RO clone) are released
1705 * individually: releasecount. This is to reduce the race condition
1706 * of clients trying to find an on-line RO volume. The remaining ROs
1707 * are released in parallel but no more than half the number of ROs
1708 * (rounded up) at a time: nservers.
1711 strcpy(vname, entry.name);
1712 strcat(vname, ".readonly");
1713 memset(&cookie, 0, sizeof(cookie));
1714 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
1715 cookie.type = ROVOL;
1716 cookie.parent = entry.volumeId[RWVOL];
1719 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
1721 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
1722 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
1724 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
1726 results.manyResults_val =
1727 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
1728 if (!replicas || !times || !!!results.manyResults_val || !toconns) {
1730 goto fail_UV_ReleaseVolume;
1733 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
1734 memset(times, 0, (sizeof(struct release) * nservers + 1));
1735 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
1736 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
1738 /* Create a transaction on the cloned volume */
1740 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
1742 goto fail_UV_ReleaseVolume;
1745 /* For each index in the VLDB */
1746 for (vldbindex = 0; vldbindex < entry.nServers;) {
1748 /* Get a transaction on the replicas. Pick replacas which have an old release. */
1750 ((volcount < nservers) && (vldbindex < entry.nServers));
1752 /* The first two RO volumes will be released individually.
1753 * The rest are then released in parallel. This is a hack
1754 * for clients not recognizing right away when a RO volume
1755 * comes back on-line.
1757 if ((volcount == 1) && (releasecount < 2))
1760 if (vldbindex == roindex)
1761 continue; /* the clone */
1762 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
1763 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
1765 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
1766 continue; /* not a RO vol */
1769 /* Get a Transaction on this replica. Get a new connection if
1770 * necessary. Create the volume if necessary. Return the
1771 * time from which the dump should be made (0 if it's a new
1772 * volume). Each volume might have a different time.
1774 replicas[volcount].server.destHost =
1775 entry.serverNumber[vldbindex];
1776 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
1777 replicas[volcount].server.destSSID = 1;
1778 times[volcount].vldbEntryIndex = vldbindex;
1781 (cellHandle, &entry, vldbindex, &(toconns[volcount]),
1782 &(replicas[volcount].trans), &(times[volcount].time),
1787 /* Thisdate is the date from which we want to pick up all changes */
1788 if (forceflag || !fullrelease
1789 || (rwcrdate > times[volcount].time)) {
1790 /* If the forceflag is set, then we want to do a full dump.
1791 * If it's not a full release, we can't be sure that the creation
1792 * date is good (so we also do a full dump).
1793 * If the RW volume was replaced (its creation date is newer than
1794 * the last release), then we can't be sure what has changed (so
1795 * we do a full dump).
1798 } else if (remembertime[vldbindex].validtime) {
1799 /* Trans was prev ended. Use the time from the prev trans
1800 * because, prev trans may have created the volume. In which
1801 * case time[volcount].time would be now instead of 0.
1804 (remembertime[vldbindex].time <
1805 times[volcount].time) ? remembertime[vldbindex].
1806 time : times[volcount].time;
1808 thisdate = times[volcount].time;
1810 remembertime[vldbindex].validtime = 1;
1811 remembertime[vldbindex].time = thisdate;
1813 if (volcount == 0) {
1814 fromdate = thisdate;
1816 /* Include this volume if it is within 15 minutes of the earliest */
1818 thisdate) ? (fromdate - thisdate) : (thisdate -
1820 AFSVolEndTrans(toconns[volcount],
1821 replicas[volcount].trans, &rcode);
1822 replicas[volcount].trans = 0;
1825 if (thisdate < fromdate)
1826 fromdate = thisdate;
1833 /* Release the ones we have collected */
1834 tr.manyDests_val = &(replicas[0]);
1835 tr.manyDests_len = results.manyResults_len = volcount;
1837 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
1838 0 /*spare */ , &cookie, &results);
1839 if (tst == RXGEN_OPCODE) { /* RPC Interface Mismatch */
1841 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
1842 0 /*spare */ , &cookie, &results);
1847 goto fail_UV_ReleaseVolume;
1849 for (m = 0; m < volcount; m++) {
1850 if (results.manyResults_val[m]) {
1855 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
1856 ROVOL, entry.volumeId[RWVOL], 0, 0);
1861 /* have to clear dest. flags to ensure new vol goes online:
1862 * because the restore (forwarded) operation copied
1863 * the V_inService(=0) flag over to the destination.
1865 tst = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
1870 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
1871 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
1872 entry.flags |= RO_EXISTS;
1877 /* End the transactions and destroy the connections */
1878 for (s = 0; s < volcount; s++) {
1879 if (replicas[s].trans)
1880 tst = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
1881 replicas[s].trans = 0;
1885 if ((s == 0) || (tst != ENOENT)) {
1887 if (times[s].vldbEntryIndex < vldbindex)
1888 vldbindex = times[s].vldbEntryIndex;
1893 rx_ReleaseCachedConnection(toconns[s]);
1897 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1898 goto fail_UV_ReleaseVolume;
1900 } /* for each index in the vldb */
1902 /* End the transaction on the cloned volume */
1903 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1906 /* Figure out if any volume were not released and say so */
1907 for (failure = 0, i = 0; i < entry.nServers; i++) {
1908 if (!(entry.serverFlags[i] & NEW_REPSITE))
1912 if (!VLDB_ReplaceEntry
1913 (cellHandle, afromvol, RWVOL, &entry, LOCKREL_TIMESTAMP, &tst)) {
1914 goto fail_UV_ReleaseVolume;
1917 tst = VOLSERBADRELEASE;
1918 goto fail_UV_ReleaseVolume;
1921 /* All the ROs were release successfully. Remove the temporary clone */
1923 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1925 goto fail_UV_ReleaseVolume;
1930 for (i = 0; i < entry.nServers; i++)
1931 entry.serverFlags[i] &= ~NEW_REPSITE;
1933 /* Update the VLDB */
1934 if (!VLDB_ReplaceEntry
1935 (cellHandle, afromvol, RWVOL, &entry,
1936 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
1937 goto fail_UV_ReleaseVolume;
1941 fail_UV_ReleaseVolume:
1944 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1951 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1957 for (i = 0; i < nservers; i++) {
1958 if (replicas && replicas[i].trans) {
1959 tst = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
1960 replicas[i].trans = 0;
1965 if (toconns && toconns[i]) {
1966 rx_ReleaseCachedConnection(toconns[i]);
1972 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, RWVOL,
1973 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
1980 rx_ReleaseCachedConnection(fromconn);
1981 if (results.manyResults_val)
1982 free(results.manyResults_val);
1997 ReceiveFile(register int fd, register struct rx_call *call,
1998 register struct stat *status)
2000 register char *buffer = (char *)0;
2001 register int blockSize;
2002 afs_int32 bytesread, nbytes, bytesleft, w;
2004 afs_int32 error = 0;
2011 struct statfs tstatfs;
2013 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2015 fstatfs(fd, &tstatfs);
2016 blockSize = tstatfs.f_bsize;
2018 blockSize = status->st_blksize;
2025 buffer = (char *)malloc(blockSize);
2030 while (!error && (bytesread > 0)) {
2031 bytesread = rx_Read(call, buffer, nbytes);
2032 bytesleft = bytesread;
2033 while (!error && (bytesleft > 0)) {
2036 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2037 select(fd + 1, 0, &out, 0, 0); /* don't timeout if write bl
2040 w = write(fd, &buffer[bytesread - bytesleft], bytesleft);
2042 error = ADMVOSDUMPFILEWRITEFAIL;
2058 DumpFunction(struct rx_call *call, const char *filename)
2062 afs_int32 error, code;
2067 fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666);
2068 if (fd < 0 || fstat(fd, &status) < 0) {
2069 error = VOLSERBADOP;
2072 code = ReceiveFile(fd, call, &status);
2090 /*dump the volume <afromvol> on <afromserver> and
2091 * <afrompart> to <afilename> starting from <fromdate>.
2092 * DumpFunction does the real work behind the scenes after
2093 * extracting parameters from the rock */
2095 UV_DumpVolume(afs_cell_handle_p cellHandle, afs_int32 afromvol,
2096 afs_int32 afromserver, afs_int32 afrompart, afs_int32 fromdate,
2097 const char *filename, afs_status_p st)
2100 afs_status_t tst = 0;
2101 afs_status_t etst = 0;
2102 struct rx_connection *fromconn;
2103 struct rx_call *fromcall;
2108 struct nvldbentry entry;
2115 fromcall = (struct rx_call *)0;
2116 fromconn = (struct rx_connection *)0;
2118 fromcall = (struct rx_call *)0;
2121 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
2122 goto fail_UV_DumpVolume;
2125 /* get connections to the servers */
2126 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
2127 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2129 goto fail_UV_DumpVolume;
2131 fromcall = rx_NewCall(fromconn);
2132 tst = StartAFSVolDump(fromcall, fromtid, fromdate);
2134 goto fail_UV_DumpVolume;
2136 if ((tst = DumpFunction(fromcall, filename))) {
2137 goto fail_UV_DumpVolume;
2139 tst = rx_EndCall(fromcall, rxError);
2140 fromcall = (struct rx_call *)0;
2142 goto fail_UV_DumpVolume;
2144 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2149 goto fail_UV_DumpVolume;
2157 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
2158 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2166 etst = rx_EndCall(fromcall, rxError);
2174 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2184 rx_ReleaseCachedConnection(fromconn);
2194 SendFile(register int fd, register struct rx_call *call,
2195 register struct stat *status)
2197 char *buffer = (char *)0;
2200 afs_int32 error = 0;
2209 struct statfs tstatfs;
2211 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2213 fstatfs(fd, &tstatfs);
2214 blockSize = tstatfs.f_bsize;
2216 blockSize = status->st_blksize;
2222 buffer = (char *)malloc(blockSize);
2227 while (!error && !done) {
2230 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2231 select(fd + 1, &in, 0, 0, 0); /* don't timeout if read blocks */
2233 nbytes = read(fd, buffer, blockSize);
2235 error = ADMVOSRESTOREFILEREADFAIL;
2242 if (rx_Write(call, buffer, nbytes) != nbytes) {
2243 error = ADMVOSRESTOREFILEWRITEFAIL;
2253 WriteData(struct rx_call *call, const char *filename)
2257 afs_int32 error, code;
2262 fd = open(filename, 0);
2263 if (fd < 0 || fstat(fd, &status) < 0) {
2264 fprintf(STDERR, "Could access file '%s'\n", filename);
2265 error = ADMVOSRESTOREFILEOPENFAIL;
2266 goto fail_WriteData;
2268 code = SendFile(fd, call, &status);
2271 goto fail_WriteData;
2282 error = ADMVOSRESTOREFILECLOSEFAIL;
2288 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
2289 * the dump file <afilename>. WriteData does all the real work
2290 * after extracting params from the rock
2293 UV_RestoreVolume(afs_cell_handle_p cellHandle, afs_int32 toserver,
2294 afs_int32 topart, afs_int32 tovolid, const char *tovolname,
2295 int flags, const char *dumpFile, afs_status_p st)
2298 afs_status_t tst = 0;
2299 afs_status_t etst = 0;
2300 struct rx_connection *toconn, *tempconn;
2301 struct rx_call *tocall;
2302 afs_int32 totid, rcode;
2303 afs_int32 rxError = 0;
2304 struct volser_status tstatus;
2309 struct nvldbentry entry;
2312 struct restoreCookie cookie;
2314 afs_int32 newDate, volflag;
2318 memset(&cookie, 0, sizeof(cookie));
2323 tocall = (struct rx_call *)0;
2324 toconn = (struct rx_connection *)0;
2325 tempconn = (struct rx_connection *)0;
2330 toconn = UV_Bind(cellHandle, toserver, AFSCONF_VOLUMEPORT);
2331 if (pvolid == 0) { /*alot a new id if needed */
2332 aVLDB_GetEntryByName(cellHandle, tovolname, &entry, &tst);
2333 if (tst == VL_NOENT) {
2335 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &pvolid);
2337 goto fail_UV_RestoreVolume;
2341 pvolid = entry.volumeId[RWVOL];
2346 * at this point we have a volume id to use/reuse for the
2347 * volume to be restored
2349 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
2350 tst = ADMVOSRESTOREVOLUMENAMETOOBIG;
2351 goto fail_UV_RestoreVolume;
2354 if (!vos_PartitionIdToName(topart, partName, &tst)) {
2355 goto fail_UV_RestoreVolume;
2357 /*what should the volume be restored as ? rw or ro or bk ?
2358 * right now the default is rw always */
2360 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0, &pvolid,
2363 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
2365 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2367 goto fail_UV_RestoreVolume;
2370 AFSVolSetFlags(toconn, totid,
2371 VTDeleteOnSalvage | VTOutOfService);
2373 goto fail_UV_RestoreVolume;
2375 tst = AFSVolDeleteVolume(toconn, totid);
2377 goto fail_UV_RestoreVolume;
2379 tst = AFSVolEndTrans(toconn, totid, &rcode);
2384 goto fail_UV_RestoreVolume;
2387 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,
2390 goto fail_UV_RestoreVolume;
2394 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2396 goto fail_UV_RestoreVolume;
2400 cookie.parent = pvolid;
2401 cookie.type = RWVOL;
2403 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
2405 tocall = rx_NewCall(toconn);
2406 tst = StartAFSVolRestore(tocall, totid, 1, &cookie);
2408 goto fail_UV_RestoreVolume;
2410 tst = WriteData(tocall, dumpFile);
2412 goto fail_UV_RestoreVolume;
2414 tst = rx_EndCall(tocall, rxError);
2415 tocall = (struct rx_call *)0;
2417 goto fail_UV_RestoreVolume;
2419 tst = AFSVolGetStatus(toconn, totid, &tstatus);
2421 goto fail_UV_RestoreVolume;
2423 tst = AFSVolSetIdsTypes(toconn, totid, tovolname, RWVOL, pvolid, 0, 0);
2425 goto fail_UV_RestoreVolume;
2428 tst = AFSVolSetDate(toconn, totid, newDate);
2430 goto fail_UV_RestoreVolume;
2433 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2434 tst = AFSVolSetFlags(toconn, totid, volflag);
2436 goto fail_UV_RestoreVolume;
2439 /* It isn't handled right in fail_UV_RestoreVolume */
2440 tst = AFSVolEndTrans(toconn, totid, &rcode);
2445 goto fail_UV_RestoreVolume;
2449 if (success && (!reuseID || (flags & RV_FULLRST))) {
2450 /* Volume was restored on the file server, update the
2451 * VLDB to reflect the change.
2453 aVLDB_GetEntryByID(cellHandle, pvolid, RWVOL, &entry, &tst);
2454 if (tst && tst != VL_NOENT && tst != VL_ENTDELETED) {
2455 goto fail_UV_RestoreVolume;
2457 if (tst == VL_NOENT) { /* it doesnot exist already */
2458 /*make the vldb return this indication specifically */
2459 strcpy(entry.name, tovolname);
2461 entry.serverNumber[0] = toserver; /*should be indirect */
2462 entry.serverPartition[0] = topart;
2463 entry.serverFlags[0] = ITSRWVOL;
2464 entry.flags = RW_EXISTS;
2465 if (tstatus.cloneID != 0) {
2466 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
2468 entry.volumeId[ROVOL] = INVALID_BID;
2469 entry.volumeId[RWVOL] = pvolid;
2471 if (tstatus.backupID != 0) {
2472 entry.volumeId[BACKVOL] = tstatus.backupID;
2473 /*this should come from status info on the volume if non zero */
2475 entry.volumeId[BACKVOL] = INVALID_BID;
2476 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
2477 goto fail_UV_RestoreVolume;
2480 } else { /*update the existing entry */
2482 ubik_VL_SetLock(cellHandle->vos, 0, pvolid, RWVOL,
2485 goto fail_UV_RestoreVolume;
2488 strcpy(entry.name, tovolname);
2490 /* Update the vlentry with the new information */
2491 index = Lp_GetRwIndex(cellHandle, &entry, 0);
2493 /* Add the rw site for the volume being restored */
2494 entry.serverNumber[entry.nServers] = toserver;
2495 entry.serverPartition[entry.nServers] = topart;
2496 entry.serverFlags[entry.nServers] = ITSRWVOL;
2499 /* This volume should be deleted on the old site
2500 * if its different from new site.
2502 VLDB_IsSameAddrs(cellHandle, toserver,
2503 entry.serverNumber[index], &same, &tst);
2505 || (entry.serverPartition[index] != topart)) {
2507 UV_Bind(cellHandle, entry.serverNumber[index],
2508 AFSCONF_VOLUMEPORT);
2510 AFSVolTransCreate(tempconn, pvolid,
2511 entry.serverPartition[index],
2512 ITOffline, &temptid);
2515 AFSVolSetFlags(tempconn, temptid,
2519 goto fail_UV_RestoreVolume;
2521 tst = AFSVolDeleteVolume(tempconn, temptid);
2523 goto fail_UV_RestoreVolume;
2525 tst = AFSVolEndTrans(tempconn, temptid, &rcode);
2530 goto fail_UV_RestoreVolume;
2532 vos_PartitionIdToName(entry.serverPartition[index],
2536 entry.serverNumber[index] = toserver;
2537 entry.serverPartition[index] = topart;
2540 entry.flags |= RW_EXISTS;
2541 if (!VLDB_ReplaceEntry
2542 (cellHandle, pvolid, RWVOL, &entry,
2543 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2544 goto fail_UV_RestoreVolume;
2551 fail_UV_RestoreVolume:
2554 etst = rx_EndCall(tocall, rxError);
2560 ubik_VL_ReleaseLock(cellHandle->vos, 0, pvolid, RWVOL,
2561 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2568 etst = AFSVolEndTrans(toconn, totid, &rcode);
2577 etst = AFSVolEndTrans(toconn, temptid, &rcode);
2587 rx_ReleaseCachedConnection(tempconn);
2589 rx_ReleaseCachedConnection(toconn);
2597 /*adds <server> and <part> as a readonly replication site for <volid>
2600 UV_AddSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2601 afs_int32 volid, afs_status_p st)
2604 afs_status_t tst = 0;
2605 int j, nro = 0, islocked = 0;
2606 struct nvldbentry entry;
2610 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2612 goto fail_UV_AddSite;
2616 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2617 goto fail_UV_AddSite;
2619 if (!ISNAMEVALID(entry.name)) {
2621 goto fail_UV_AddSite;
2624 /* See if it's too many entries */
2625 if (entry.nServers >= NMAXNSERVERS) {
2627 goto fail_UV_AddSite;
2630 /* See if it's on the same server */
2631 for (j = 0; j < entry.nServers; j++) {
2632 if (entry.serverFlags[j] & ITSROVOL) {
2634 if (!VLDB_IsSameAddrs
2635 (cellHandle, server, entry.serverNumber[j], &same, &tst)) {
2636 goto fail_UV_AddSite;
2640 goto fail_UV_AddSite;
2645 /* See if it's too many RO sites - leave one for the RW */
2646 if (nro >= NMAXNSERVERS - 1) {
2648 goto fail_UV_AddSite;
2651 entry.serverNumber[entry.nServers] = server;
2652 entry.serverPartition[entry.nServers] = part;
2653 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
2656 if (!VLDB_ReplaceEntry
2657 (cellHandle, volid, RWVOL, &entry,
2658 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2659 goto fail_UV_AddSite;
2668 ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2669 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2678 /*removes <server> <part> as read only site for <volid> from the vldb */
2680 UV_RemoveSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2681 afs_int32 volid, afs_status_p st)
2684 afs_status_t tst = 0;
2685 struct nvldbentry entry;
2689 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2691 goto fail_UV_RemoveSite;
2695 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2696 goto fail_UV_RemoveSite;
2698 if (!Lp_ROMatch(cellHandle, &entry, server, part, &tst)) {
2699 /*this site doesnot exist */
2700 goto fail_UV_RemoveSite;
2701 } else { /*remove the rep site */
2702 Lp_SetROValue(cellHandle, &entry, server, part, 0, 0);
2704 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
2705 entry.flags &= ~RO_EXISTS;
2706 if (entry.nServers < 1) { /*this is the last ref */
2707 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volid, ROVOL);
2709 goto fail_UV_RemoveSite;
2712 if (!VLDB_ReplaceEntry
2713 (cellHandle, volid, RWVOL, &entry,
2714 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
2715 goto fail_UV_RemoveSite;
2724 t = ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2725 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2737 /*list all the partitions on <aserver> */
2739 UV_ListPartitions(struct rx_connection *server, struct partList *ptrPartList,
2740 afs_int32 * cntp, afs_status_p st)
2743 afs_status_t tst = 0;
2744 struct pIDs partIds;
2745 struct partEntries partEnts;
2746 register int i, j = 0;
2750 partEnts.partEntries_len = 0;
2751 partEnts.partEntries_val = NULL;
2752 /* this is available only on new servers */
2753 tst = AFSVolXListPartitions(server, &partEnts);
2755 /* next, try old interface */
2756 if (tst == RXGEN_OPCODE) {
2757 for (i = 0; i < 26; i++)
2758 partIds.partIds[i] = -1;
2759 tst = AFSVolListPartitions(server, &partIds);
2761 for (i = 0; i < 26; i++) {
2762 if ((partIds.partIds[i]) != -1) {
2763 ptrPartList->partId[j] = partIds.partIds[i];
2764 ptrPartList->partFlags[j] = PARTVALID;
2767 ptrPartList->partFlags[i] = 0;
2771 goto fail_UV_ListPartitions;
2774 *cntp = partEnts.partEntries_len;
2775 if (*cntp > VOLMAXPARTS) {
2776 *cntp = VOLMAXPARTS;
2778 for (i = 0; i < *cntp; i++) {
2779 ptrPartList->partId[i] = partEnts.partEntries_val[i];
2780 ptrPartList->partFlags[i] = PARTVALID;
2782 free(partEnts.partEntries_val);
2784 goto fail_UV_ListPartitions;
2788 fail_UV_ListPartitions:
2796 /*------------------------------------------------------------------------
2797 * EXPORTED UV_XListVolumes
2800 * List the extended information for all the volumes on a particular
2801 * File Server and partition. We may either return the volume's ID
2802 * or all of its extended information.
2805 * a_serverID : Address of the File Server for which we want
2806 * extended volume info.
2807 * a_partID : Partition for which we want the extended
2809 * a_all : If non-zero, fetch ALL the volume info,
2810 * otherwise just the volume ID.
2811 * a_resultPP : Ptr to the address of the area containing
2812 * the returned volume info.
2813 * a_numEntsInResultP : Ptr for the value we set for the number of
2818 * Otherise, the return value of AFSVolXListVolumes.
2821 * This routine is closely related to UV_ListVolumes, which returns
2822 * only the standard level of detail on AFS volumes. It is a
2823 * heavyweight operation, zipping through all the volume entries for
2824 * a given server/partition.
2828 *------------------------------------------------------------------------*/
2831 UV_XListVolumes(struct rx_connection *server, afs_int32 a_partID, int a_all,
2832 struct volintXInfo **a_resultPP,
2833 afs_int32 * a_numEntsInResultP, afs_status_p st)
2836 afs_status_t tst = 0;
2838 volXEntries volumeXInfo; /*Area for returned extended vol info */
2841 * Set up our error code and the area for returned extended volume info.
2842 * We set the val field to a null pointer as a hint for the stub to
2845 *a_numEntsInResultP = 0;
2846 *a_resultPP = (volintXInfo *) 0;
2847 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2848 volumeXInfo.volXEntries_len = 0;
2851 * Bind to the Volume Server port on the File Server machine in question,
2854 tst = AFSVolXListVolumes(server, a_partID, a_all, &volumeXInfo);
2856 goto fail_UV_XListVolumes;
2859 * We got the info; pull out the pointer to where the results lie
2860 * and how many entries are there.
2862 *a_resultPP = volumeXInfo.volXEntries_val;
2863 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
2867 fail_UV_XListVolumes:
2875 /*------------------------------------------------------------------------
2876 * EXPORTED UV_XListOneVolume
2879 * List the extended information for a volume on a particular File
2880 * Server and partition.
2883 * server : a handle to the server where the volume resides.
2884 * a_partID : Partition for which we want the extended
2886 * a_volID : Volume ID for which we want the info.
2887 * a_resultPP : Ptr to the address of the area containing
2888 * the returned volume info.
2892 * Otherise, the return value of AFSVolXListOneVolume.
2895 * This routine is closely related to UV_ListOneVolume, which returns
2896 * only the standard level of detail on the chosen AFS volume.
2900 *------------------------------------------------------------------------*/
2903 UV_XListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2904 afs_int32 a_volID, struct volintXInfo **a_resultPP,
2908 afs_status_t tst = 0;
2909 volXEntries volumeXInfo; /*Area for returned info */
2912 * Set the area we're in which we are returning
2913 * the info. Setting the val field to a null pointer tells the stub
2914 * to allocate space for us.
2916 *a_resultPP = (volintXInfo *) 0;
2917 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2918 volumeXInfo.volXEntries_len = 0;
2920 tst = AFSVolXListOneVolume(server, a_partID, a_volID, &volumeXInfo);
2923 goto fail_UV_XListOneVolume;
2926 * We got the info; pull out the pointer to where the results lie.
2928 *a_resultPP = volumeXInfo.volXEntries_val;
2932 fail_UV_XListOneVolume:
2939 } /*UV_XListOneVolume */
2941 /*------------------------------------------------------------------------
2942 * EXPORTED UV_ListOneVolume
2945 * List the volume information for a volume on a particular File
2946 * Server and partition.
2949 * server : a handle to the server where the volume resides.
2950 * a_partID : Partition for which we want the extended
2952 * a_volID : Volume ID for which we want the info.
2953 * a_resultPP : Ptr to the address of the area containing
2954 * the returned volume info.
2958 * Otherise, the return value of AFSVolXListOneVolume.
2962 *------------------------------------------------------------------------*/
2964 int UV_ListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2965 afs_int32 a_volID, struct volintInfo **a_resultPP,
2969 afs_status_t tst = 0;
2970 volEntries volumeInfo; /*Area for returned info */
2973 * Set the area we're in which we are returning
2974 * the info. Setting the val field to a null pointer tells the stub
2975 * to allocate space for us.
2977 *a_resultPP = (volintInfo *) 0;
2978 volumeInfo.volEntries_val = (volintInfo *) 0;
2979 volumeInfo.volEntries_len = 0;
2981 tst = AFSVolListOneVolume(server, a_partID, a_volID, &volumeInfo);
2984 goto fail_UV_ListOneVolume;
2987 * We got the info; pull out the pointer to where the results lie.
2989 *a_resultPP = volumeInfo.volEntries_val;
2993 fail_UV_ListOneVolume:
2999 }/*UV_ListOneVolume*/
3001 /*sync vldb with all the entries on <myQueue> on <aserver> and <apart>*/
3003 ProcessEntries(afs_cell_handle_p cellHandle, struct qHead *myQueue,
3004 struct rx_connection *server, afs_int32 apart, afs_int32 force)
3007 int success, temp, temp1, temp2;
3008 afs_int32 vcode, maxVolid = 0;
3009 struct nvldbentry entry;
3010 int noError = 1, error, same;
3011 int totalC, totalU, totalCE, totalUE, totalG;
3013 int aserver = ntohl(rx_HostOf(rx_PeerOf(server)));
3016 totalC = totalU = totalCE = totalUE = totalG = 0;
3019 /* get the next available id's from the vldb server */
3020 vcode = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 0, &maxVolid);
3024 totalG = myQueue->count;
3028 Lp_QEnumerate(myQueue, &success, &elem, 0);
3033 if (!elem.isValid[RWVOL] && !elem.isValid[ROVOL] && !elem.isValid[BACKVOL]) { /*something is wrong with elem */
3037 if (maxVolid <= elem.ids[RWVOL]) {
3039 temp2 = elem.ids[RWVOL] - maxVolid + 1;
3042 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3048 if (maxVolid <= elem.ids[ROVOL]) {
3051 temp2 = elem.ids[ROVOL] - maxVolid + 1;
3054 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3059 if (maxVolid <= elem.ids[BACKVOL]) {
3061 temp2 = elem.ids[BACKVOL] - temp1 + 1;
3064 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3069 aVLDB_GetEntryByID(cellHandle, elem.ids[RWVOL], RWVOL, &entry, &tst);
3070 if (tst && (tst != VL_NOENT)) {
3073 } else if (tst && (tst == VL_NOENT)) { /*entry doesnot exist */
3074 /*set up a vldb entry for elem */
3075 memset(&entry, 0, sizeof(entry));
3076 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME);
3077 if (elem.isValid[RWVOL]) { /*rw exists */
3078 entry.flags |= RW_EXISTS;
3079 entry.serverFlags[entry.nServers] = ITSRWVOL;
3080 entry.serverNumber[entry.nServers] = aserver;
3081 entry.serverPartition[entry.nServers] = apart;
3082 entry.nServers += 1;
3083 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3084 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3085 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3087 if (elem.isValid[ROVOL]) { /*ro volume exists */
3088 entry.flags |= RO_EXISTS;
3089 entry.serverFlags[entry.nServers] = ITSROVOL;
3090 entry.serverNumber[entry.nServers] = aserver;
3091 entry.serverPartition[entry.nServers] = apart;
3092 entry.nServers += 1;
3093 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3094 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3097 if (elem.isValid[BACKVOL]) { /*backup volume exists */
3098 entry.flags |= BACK_EXISTS;
3099 if (!(entry.flags & RW_EXISTS)) { /*this helps to check for a stray backup if parent moves */
3100 entry.serverFlags[entry.nServers] = ITSRWVOL;
3101 entry.serverNumber[entry.nServers] = aserver;
3102 entry.serverPartition[entry.nServers] = apart;
3103 entry.nServers += 1;
3106 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3107 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3110 VLDB_CreateEntry(cellHandle, &entry, &tst);
3116 } else { /* Update the existing entry */
3117 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME); /*the name Could have changed */
3119 if (elem.isValid[RWVOL]) { /* A RW volume */
3120 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3122 /* A RW index is not found in the VLDB entry - will add it */
3124 entry.flags |= RW_EXISTS;
3125 entry.serverNumber[entry.nServers] = aserver;
3126 entry.serverPartition[entry.nServers] = apart;
3127 entry.serverFlags[entry.nServers] = ITSRWVOL;
3130 /* A RW index is found in the VLDB entry.
3131 * Verify that the volume location matches the VLDB location.
3132 * Fix the VLDB entry if it is not correct.
3136 VLDB_IsSameAddrs(cellHandle, aserver,
3137 entry.serverNumber[temp], &same,
3142 if (!same || (apart != entry.serverPartition[temp])) {
3143 /* VLDB says volume is in another place. Fix the VLDB entry */
3144 entry.serverNumber[temp] = aserver;
3145 entry.serverPartition[temp] = apart;
3148 entry.flags |= RW_EXISTS;
3150 if ((elem.ids[BACKVOL] != 0) && elem.isValid[BACKVOL])
3151 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3152 if ((elem.ids[ROVOL] != 0) && elem.isValid[ROVOL])
3153 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3156 if (elem.isValid[ROVOL]) {
3157 /*tackle a ro volume */
3159 if (!Lp_ROMatch(cellHandle, &entry, aserver, apart, 0)) {
3161 if (elem.ids[ROVOL] > entry.volumeId[ROVOL]) {
3162 /*there is a conflict of ids, keep the later volume */
3163 /*delete all the ro volumes listed in vldb entry since they
3166 int j, count, rwsite;
3169 count = entry.nServers;
3171 for (j = 0; j < count; j++) {
3172 if (entry.serverFlags[j] & ITSROVOL) {
3174 /*delete the site */
3175 entry.serverNumber[j] = 0;
3176 entry.serverPartition[j] = 0;
3177 entry.serverFlags[j] = 0;
3179 } else if (entry.serverFlags[j] & ITSRWVOL)
3184 entry.serverNumber[entry.nServers] =
3185 entry.serverNumber[rwsite];
3186 entry.serverPartition[entry.nServers] =
3187 entry.serverPartition[rwsite];
3188 entry.serverFlags[entry.nServers] =
3189 entry.serverFlags[rwsite];
3192 entry.serverNumber[entry.nServers] = aserver;
3193 entry.serverPartition[entry.nServers] = apart;
3194 entry.serverFlags[entry.nServers] = ITSROVOL;
3196 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3197 entry.flags |= RO_EXISTS;
3199 } else if (elem.ids[ROVOL] < entry.volumeId[ROVOL]) {
3200 if (!(entry.flags & RO_EXISTS)) {
3201 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3202 entry.serverNumber[entry.nServers] = aserver;
3203 entry.serverPartition[entry.nServers] = apart;
3204 entry.serverFlags[entry.nServers] = ITSROVOL;
3206 entry.flags |= RO_EXISTS;
3211 else if (elem.ids[ROVOL] == entry.volumeId[ROVOL]) {
3212 entry.serverNumber[entry.nServers] = aserver;
3213 entry.serverPartition[entry.nServers] = apart;
3214 entry.serverFlags[entry.nServers] = ITSROVOL;
3216 entry.flags |= RO_EXISTS;
3217 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3220 if (entry.volumeId[ROVOL] == INVALID_BID)
3221 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3224 if (elem.isValid[BACKVOL]) {
3225 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3226 if (temp != -1) { /*check if existing backup site matches with the given arguments */
3228 VLDB_IsSameAddrs(cellHandle, aserver,
3229 entry.serverNumber[temp], &same,
3235 /*tackle the backup volume */
3236 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3237 entry.flags |= BACK_EXISTS;
3239 if (entry.volumeId[BACKVOL] == INVALID_BID)
3240 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3243 VLDB_ReplaceEntry(cellHandle, elem.ids[RWVOL], RWVOL, &entry,
3244 LOCKREL_OPCODE | LOCKREL_AFSID |
3245 LOCKREL_TIMESTAMP, &tst);
3251 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3252 elem.ids[RWVOL], RWVOL,
3253 LOCKREL_OPCODE | LOCKREL_AFSID |
3259 } /* else update the existing entry */
3261 } /* End of while(1) */
3269 /*synchronise vldb with the file server <aserver> and <apart>(if flags=1).
3270 *else synchronise with all the valid partitions on <aserver>
3273 UV_SyncVldb(afs_cell_handle_p cellHandle, struct rx_connection *server,
3274 afs_int32 apart, int flags, int force, afs_status_p st)
3277 afs_status_t tst = 0;
3280 volEntries volumeInfo;
3282 struct qHead myQueue;
3283 struct partList PartList;
3288 /*this hints the stub to allocate space */
3289 volumeInfo.volEntries_val = (volintInfo *) 0;
3290 volumeInfo.volEntries_len = 0;
3292 if (!flags) { /*generate all the valid partitions */
3293 UV_ListPartitions(server, &PartList, &cnt, &tst);
3295 goto fail_UV_SyncVldb;
3298 PartList.partId[0] = apart;
3302 for (i = 0; i < cnt; i++) {
3303 apart = PartList.partId[i];
3304 /*this hints the stub to allocate space */
3305 volumeInfo.volEntries_val = (volintInfo *) 0;
3306 volumeInfo.volEntries_len = 0;
3307 tst = AFSVolListVolumes(server, apart, 1, &volumeInfo);
3309 goto fail_UV_SyncVldb;
3311 count = volumeInfo.volEntries_len;
3312 pntr = volumeInfo.volEntries_val;
3314 if (!vos_PartitionIdToName(apart, pname, &tst)) {
3315 goto fail_UV_SyncVldb;
3317 /*collect all vol entries by their parentid */
3318 tst = GroupEntries(server, pntr, count, &myQueue, apart);
3321 if (volumeInfo.volEntries_val) {
3322 /*free the space allocated by the stub */
3323 free(volumeInfo.volEntries_val);
3324 volumeInfo.volEntries_val = 0;
3328 tst = ProcessEntries(cellHandle, &myQueue, server, apart, force);
3330 tst = VOLSERFAILEDOP;
3331 if (volumeInfo.volEntries_val) {
3332 /*free the space allocated by the stub */
3333 free(volumeInfo.volEntries_val);
3334 volumeInfo.volEntries_val = 0;
3341 tst = VOLSERFAILEDOP;
3342 } /* thru all partitions */
3347 if (volumeInfo.volEntries_val)
3348 free(volumeInfo.volEntries_val);
3361 CheckVldbRWBK(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3362 afs_int32 * modified, afs_status_p st)
3365 afs_status_t tst = 0;
3371 idx = Lp_GetRwIndex(cellHandle, entry, 0);
3373 /* Check to see if the RW volume exists and set the RW_EXISTS
3376 if (idx == -1) { /* Did not find a RW entry */
3377 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
3378 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
3383 (cellHandle, entry->serverNumber[idx],
3384 entry->serverPartition[idx], entry->volumeId[RWVOL], &tst)) {
3385 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does no
3387 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
3390 } else if (tst == ENODEV) { /* RW volume does not exist */
3391 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists
3393 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist
3398 /* If VLDB says it didn't exist, then ignore error */
3399 if (entry->flags & RW_EXISTS) {
3400 goto fail_CheckVldbRWBK;
3405 /* Check to see if the BK volume exists and set the BACK_EXISTS
3406 * flag accordingly. idx already ponts to the RW entry.
3408 if (idx == -1) { /* Did not find a RW entry */
3409 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
3410 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
3413 } else { /* Found a RW entry */
3415 (cellHandle, entry->serverNumber[idx],
3416 entry->serverPartition[idx], entry->volumeId[BACKVOL], &tst)) {
3417 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does n
3419 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
3422 } else if (tst == ENODEV) { /* BK volume does not exist */
3423 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists
3425 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist
3430 /* If VLDB says it didn't exist, then ignore error */
3431 if (entry->flags & BACK_EXISTS) {
3432 goto fail_CheckVldbRWBK;
3437 /* If there is an idx but the BK and RW volumes no
3438 * longer exist, then remove the RW entry.
3440 if ((idx != -1) && !(entry->flags & RW_EXISTS)
3441 && !(entry->flags & BACK_EXISTS)) {
3442 Lp_SetRWValue(cellHandle, entry, entry->serverNumber[idx],
3443 entry->serverPartition[idx], 0L, 0L);
3452 *modified = modentry;
3462 CheckVldbRO(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3463 afs_int32 * modified, afs_status_p st)
3466 afs_status_t tst = 0;
3468 int foundro = 0, modentry = 0;
3473 /* Check to see if the RO volumes exist and set the RO_EXISTS
3476 for (idx = 0; idx < entry->nServers; idx++) {
3477 if (!(entry->serverFlags[idx] & ITSROVOL)) {
3478 continue; /* not a RO */
3482 (cellHandle, entry->serverNumber[idx],
3483 entry->serverPartition[idx], entry->volumeId[ROVOL], &tst)) {
3485 } else if (tst == ENODEV) { /* RW volume does not exist */
3486 Lp_SetROValue(cellHandle, entry, entry->serverNumber[idx],
3487 entry->serverPartition[idx], 0L, 0L);
3492 goto fail_CheckVldbRO;
3496 if (foundro) { /* A RO volume exists */
3497 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not e
3499 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
3502 } else { /* A RO volume does not exist */
3503 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
3504 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
3513 *modified = modentry;
3521 /*ensure that <entry> matches with the info on file servers */
3523 CheckVldb(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3524 afs_int32 * modified, afs_status_p st)
3527 afs_status_t tst = 0;
3531 afs_int32 modentry = 0;
3532 afs_int32 delentry = 0;
3538 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
3540 goto fail_CheckVldb;
3545 /* Check to see if the VLDB is ok without locking it (pass 1).
3546 * If it will change, then lock the VLDB entry, read it again,
3547 * then make the changes to it (pass 2).
3551 ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL],
3552 RWVOL, VLOP_DELETE);
3554 goto fail_CheckVldb;
3558 if (!aVLDB_GetEntryByID
3559 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, &tst)) {
3560 goto fail_CheckVldb;
3566 /* Check if the RW and BK entries are ok */
3567 if (!CheckVldbRWBK(cellHandle, entry, &modentry, &tst)) {
3568 goto fail_CheckVldb;
3570 if (modentry && (pass == 1))
3573 /* Check if the RO volumes entries are ok */
3574 if (!CheckVldbRO(cellHandle, entry, &modentry, &tst)) {
3575 goto fail_CheckVldb;
3577 if (modentry && (pass == 1))
3580 /* The VLDB entry has been updated. If it as been modified, then
3581 * write the entry back out the the VLDB.
3587 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
3588 && !(entry->flags & RO_EXISTS)) {
3589 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
3591 ubik_VL_DeleteEntry(cellHandle->vos, 0,
3592 entry->volumeId[RWVOL], RWVOL);
3594 goto fail_CheckVldb;
3598 /* Replace old entry with our new one */
3599 if (!VLDB_ReplaceEntry
3600 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry,
3601 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
3603 goto fail_CheckVldb;
3616 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3617 entry->volumeId[RWVOL], RWVOL,
3618 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
3631 /*synchronise <aserver> <apart>(if flags = 1) with the vldb .
3632 *if flags = 0, synchronise all the valid partitions on <aserver>*/
3634 UV_SyncServer(afs_cell_handle_p cellHandle, struct rx_connection *server,
3635 afs_int32 apart, int flags, afs_status_p st)
3638 afs_status_t tst = 0;
3639 afs_int32 code, vcode;
3641 afs_int32 nentries, tentries = 0;
3642 struct VldbListByAttributes attributes;
3643 nbulkentries arrayEntries;
3645 register struct nvldbentry *vllist;
3648 afs_int32 modified = 0;
3653 arrayEntries.nbulkentries_val = 0;
3655 /* Set up attributes to search VLDB */
3656 attributes.server = ntohl(rx_HostOf(rx_PeerOf(server)));
3657 attributes.Mask = VLLIST_SERVER;
3659 attributes.partition = apart;
3660 attributes.Mask |= VLLIST_PARTITION;
3663 for (si = 0; si != -1; si = nsi) {
3664 /*initialize to hint the stub to alloc space */
3665 memset(&arrayEntries, 0, sizeof(arrayEntries));
3666 if (!VLDB_ListAttributes
3667 (cellHandle, &attributes, &nentries, &arrayEntries, &tst)) {
3668 goto fail_UV_SyncServer;
3671 tentries += nentries;
3673 for (j = 0; j < nentries; j++) { /* process each entry */
3674 vllist = &arrayEntries.nbulkentries_val[j];
3675 if (!CheckVldb(cellHandle, vllist, &modified, &tst)) {
3680 if (arrayEntries.nbulkentries_val) {
3681 free(arrayEntries.nbulkentries_val);
3682 arrayEntries.nbulkentries_val = 0;
3689 if (arrayEntries.nbulkentries_val) {
3690 free(arrayEntries.nbulkentries_val);
3693 tst = VOLSERFAILEDOP;
3700 /*rename volume <oldname> to <newname>, changing the names of the related
3701 *readonly and backup volumes. This operation is also idempotent.
3702 *salvager is capable of recovering from rename operation stopping halfway.
3703 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
3705 UV_RenameVolume(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3706 const char *newname, afs_status_p st)
3709 afs_status_t tst = 0;
3710 afs_status_t etst = 0;
3711 afs_int32 rcode, error;
3713 char nameBuffer[256];
3715 struct rx_connection *aconn;
3719 aconn = (struct rx_connection *)0;
3723 tst = ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
3725 goto fail_UV_RenameVolume;
3729 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
3731 if (!VLDB_ReplaceEntry
3732 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, 0, &tst)) {
3733 goto fail_UV_RenameVolume;
3735 /*at this stage the intent to rename is recorded in the vldb, as far
3737 * is concerned, oldname is lost */
3738 if (entry->flags & RW_EXISTS) {
3739 index = Lp_GetRwIndex(cellHandle, entry, 0);
3740 if (index == -1) { /* there is a serious discrepancy */
3741 tst = VOLSERVLDB_ERROR;
3742 goto fail_UV_RenameVolume;
3745 UV_Bind(cellHandle, entry->serverNumber[index],
3746 AFSCONF_VOLUMEPORT);
3748 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
3749 entry->serverPartition[index], ITOffline, &tid);
3750 if (tst) { /*volume doesnot exist */
3751 goto fail_UV_RenameVolume;
3752 } else { /*volume exists, process it */
3755 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
3756 entry->volumeId[RWVOL],
3757 entry->volumeId[ROVOL],
3758 entry->volumeId[BACKVOL]);
3760 tst = AFSVolEndTrans(aconn, tid, &rcode);
3763 goto fail_UV_RenameVolume;
3766 goto fail_UV_RenameVolume;
3770 rx_ReleaseCachedConnection(aconn);
3771 aconn = (struct rx_connection *)0;
3773 /*end rw volume processing */
3774 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
3775 index = Lp_GetRwIndex(cellHandle, entry, 0);
3776 if (index == -1) { /* there is a serious discrepancy */
3777 tst = VOLSERVLDB_ERROR;
3778 goto fail_UV_RenameVolume;
3781 UV_Bind(cellHandle, entry->serverNumber[index],
3782 AFSCONF_VOLUMEPORT);
3784 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
3785 entry->serverPartition[index], ITOffline, &tid);
3786 if (tst) { /*volume doesnot exist */
3787 goto fail_UV_RenameVolume;
3788 } else { /*volume exists, process it */
3789 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
3790 goto fail_UV_RenameVolume;
3792 strcpy(nameBuffer, newname);
3793 strcat(nameBuffer, ".backup");
3796 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
3797 entry->volumeId[RWVOL], 0, 0);
3799 tst = AFSVolEndTrans(aconn, tid, &rcode);
3802 goto fail_UV_RenameVolume;
3805 goto fail_UV_RenameVolume;
3808 } /* end backup processing */
3810 rx_ReleaseCachedConnection(aconn);
3811 aconn = (struct rx_connection *)0;
3812 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
3813 for (i = 0; i < entry->nServers; i++) {
3814 if (entry->serverFlags[i] & ITSROVOL) {
3816 UV_Bind(cellHandle, entry->serverNumber[i],
3817 AFSCONF_VOLUMEPORT);
3819 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
3820 entry->serverPartition[i], ITOffline,
3822 if (tst) { /*volume doesnot exist */
3823 goto fail_UV_RenameVolume;
3824 } else { /*volume exists, process it */
3825 strcpy(nameBuffer, newname);
3826 strcat(nameBuffer, ".readonly");
3827 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
3828 goto fail_UV_RenameVolume;
3831 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
3832 entry->volumeId[RWVOL], 0, 0);
3834 tst = AFSVolEndTrans(aconn, tid, &rcode);
3837 goto fail_UV_RenameVolume;
3840 goto fail_UV_RenameVolume;
3844 rx_ReleaseCachedConnection(aconn);
3845 aconn = (struct rx_connection *)0;
3851 fail_UV_RenameVolume:
3855 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3856 entry->volumeId[RWVOL], RWVOL,
3857 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3864 etst = AFSVolEndTrans(aconn, tid, &rcode);
3871 rx_ReleaseCachedConnection(aconn);
3879 /*group all the volume entries on< apart >by their parentid or by their ids'
3880 *if the volume is rw. <count> is the number of entries to be processesd.
3881 *<pntr> points to the first entry.< myQueue> is the queue with entries
3884 GroupEntries(struct rx_connection *server, volintInfo * pntr, afs_int32 count,
3885 struct qHead *myQueue, afs_int32 apart)
3887 struct aqueue *qPtr;
3889 afs_int32 curId, code;
3891 afs_int32 error = 0;
3897 for (i = 0; i < count; i++) { /*process each entry */
3898 if (pntr->status) { /* entry is valid */
3899 if (pntr->type == RWVOL)
3900 curId = pntr->volid;
3902 curId = pntr->parentID;
3903 Lp_QScan(myQueue, curId, &success, &qPtr, 0);
3904 if (success) { /*entry exists in the queue */
3905 if (pntr->type == RWVOL) {
3906 /*check if the rw exists already, if so hang on the
3907 * later version if the present version is ok */
3908 if (qPtr->isValid[RWVOL]) {
3909 /*this should not happen, there is a serious error here */
3911 error = VOLSERMULTIRWVOL;
3913 qPtr->isValid[RWVOL] = 1;
3914 qPtr->copyDate[RWVOL] = pntr->copyDate;
3915 if (!qPtr->isValid[BACKVOL])
3916 qPtr->ids[BACKVOL] = pntr->backupID;
3917 if (!qPtr->isValid[ROVOL])
3918 qPtr->ids[ROVOL] = pntr->cloneID;
3920 } else if (pntr->type == BACKVOL) {
3921 if (qPtr->isValid[BACKVOL]) {
3922 /*do different checks, delete superflous volume */
3923 if (qPtr->copyDate[BACKVOL] > pntr->copyDate) {
3924 /*delete the present volume . */
3926 CheckAndDeleteVolume(server, apart, 0,
3934 /*delete the older volume after making sure, current one is ok */
3936 CheckAndDeleteVolume(server, apart,
3938 qPtr->ids[BACKVOL]);
3944 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3945 qPtr->ids[BACKVOL] = pntr->volid;
3949 qPtr->isValid[BACKVOL] = 1;
3950 qPtr->ids[BACKVOL] = pntr->volid;
3951 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3953 } else if (pntr->type == ROVOL) {
3954 if (qPtr->isValid[ROVOL]) {
3955 /*do different checks, delete superflous volume */
3956 if (qPtr->copyDate[ROVOL] > pntr->copyDate) {
3957 /*delete the present volume . */
3960 CheckAndDeleteVolume(server, apart, 0,
3967 /*delete the older volume after making sure, current one is ok */
3969 CheckAndDeleteVolume(server, apart,
3977 qPtr->copyDate[ROVOL] = pntr->copyDate;
3978 qPtr->ids[ROVOL] = pntr->volid;
3982 qPtr->isValid[ROVOL] = 1;
3983 qPtr->ids[ROVOL] = pntr->volid;
3984 qPtr->copyDate[ROVOL] = pntr->copyDate;
3988 error = VOLSERBADOP;
3990 } else { /*create a fresh entry */
3991 qPtr = (struct aqueue *)malloc(sizeof(struct aqueue));
3992 if (pntr->type == RWVOL) {
3993 qPtr->isValid[RWVOL] = 1;
3994 qPtr->isValid[BACKVOL] = 0;
3995 qPtr->isValid[ROVOL] = 0;
3996 qPtr->ids[RWVOL] = pntr->volid;
3997 qPtr->ids[BACKVOL] = pntr->backupID;
3998 qPtr->ids[ROVOL] = pntr->cloneID;
3999 qPtr->copyDate[RWVOL] = pntr->copyDate;
4000 strncpy(qPtr->name, pntr->name, VOLSER_OLDMAXVOLNAME);
4002 } else if (pntr->type == BACKVOL) {
4003 qPtr->isValid[RWVOL] = 0;
4004 qPtr->isValid[BACKVOL] = 1;
4005 qPtr->isValid[ROVOL] = 0;
4006 qPtr->ids[RWVOL] = pntr->parentID;
4007 qPtr->ids[BACKVOL] = pntr->volid;
4008 qPtr->ids[ROVOL] = 0;
4009 qPtr->copyDate[BACKVOL] = pntr->copyDate;
4010 vsu_ExtractName(qPtr->name, pntr->name);
4012 } else if (pntr->type == ROVOL) {
4013 qPtr->isValid[RWVOL] = 0;
4014 qPtr->isValid[BACKVOL] = 0;
4015 qPtr->isValid[ROVOL] = 1;
4016 qPtr->ids[RWVOL] = pntr->parentID;
4017 qPtr->ids[BACKVOL] = 0;
4018 qPtr->ids[ROVOL] = pntr->volid;
4019 qPtr->copyDate[ROVOL] = pntr->copyDate;
4020 vsu_ExtractName(qPtr->name, pntr->name);
4024 Lp_QAdd(myQueue, qPtr);
4026 pntr++; /*get next entry */
4036 /*report on all the active transactions on volser */
4038 UV_VolserStatus(struct rx_connection *server, transDebugInfo ** rpntr,
4039 afs_int32 * rcount, afs_status_p st)
4042 afs_status_t tst = 0;
4043 transDebugEntries transInfo;
4045 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
4046 transInfo.transDebugEntries_len = 0;
4047 tst = AFSVolMonitor(server, &transInfo);
4049 goto fail_UV_VolserStatus;
4052 *rcount = transInfo.transDebugEntries_len;
4053 *rpntr = transInfo.transDebugEntries_val;
4056 fail_UV_VolserStatus:
4059 if (transInfo.transDebugEntries_val) {
4060 free(transInfo.transDebugEntries_val);
4070 /*delete the volume without interacting with the vldb */
4072 UV_VolumeZap(afs_cell_handle_p cellHandle, struct rx_connection *server,
4073 unsigned int partition, unsigned int volumeId, afs_status_p st)
4075 afs_int32 rcode, ttid, error, code;
4077 afs_status_t tst = 0;
4083 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
4085 tst = AFSVolDeleteVolume(server, ttid);
4087 tst = AFSVolEndTrans(server, ttid, &rcode);
4095 * We failed to delete the volume, but we still need
4096 * to end the transaction.
4098 AFSVolEndTrans(server, ttid, &rcode);
4110 UV_SetVolume(struct rx_connection *server, afs_int32 partition,
4111 afs_int32 volid, afs_int32 transflag, afs_int32 setflag,
4112 unsigned int sleepTime, afs_status_p st)
4115 afs_status_t tst = 0;
4116 afs_status_t etst = 0;
4120 tst = AFSVolTransCreate(server, volid, partition, transflag, &tid);
4122 goto fail_UV_SetVolume;
4125 tst = AFSVolSetFlags(server, tid, setflag);
4127 goto fail_UV_SetVolume;
4138 etst = AFSVolEndTrans(server, tid, &rcode);
4139 /* FIXME: this looks like a typo */
4142 tst = (etst ? etst : rcode);