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>
27 #include "lockprocs.h"
28 #include "../adminutil/afs_AdminInternal.h"
29 #include <afs/afs_AdminErrors.h>
30 #include "afs_vosAdmin.h"
39 static afs_int32 GroupEntries();
43 afs_int32 vldbEntryIndex;
46 static struct rx_connection *
47 UV_Bind(afs_cell_handle_p cellHandle, afs_int32 aserver, afs_int32 port)
49 return rx_GetCachedConnection(htonl(aserver), htons(port), VOLSERVICE_ID,
50 cellHandle->tokens->afs_sc[cellHandle->
53 cellHandle->tokens->sc_index);
57 /* if <okvol> is allright(indicated by beibg able to
58 * start a transaction, delete the <delvol> */
60 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
61 afs_uint32 okvol, afs_uint32 delvol)
63 afs_int32 error, code, tid, rcode;
69 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
72 code = AFSVolDeleteVolume(aconn, tid);
75 code = AFSVolEndTrans(aconn, tid, &rcode);
82 code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
84 code = AFSVolEndTrans(aconn, tid, &rcode);
89 code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
92 code = AFSVolDeleteVolume(aconn, tid);
95 code = AFSVolEndTrans(aconn, tid, &rcode);
106 /* forcibly remove a volume. Very dangerous call */
108 UV_NukeVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
109 unsigned int partition, afs_uint32 volumeId, afs_status_p st)
112 afs_status_t tst = 0;
114 tst = AFSVolNukeVolume(server, partition, volumeId);
126 /* create a volume, given a server, partition number, volume name --> sends
127 * back new vol id in <anewid>*/
129 UV_CreateVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
130 unsigned int partition, const char *volumeName,
131 unsigned int quota, afs_uint32 *volumeId, afs_status_p st)
134 afs_status_t tst = 0;
137 struct nvldbentry entry;
138 struct volintInfo tstatus;
140 memset(&tstatus, 0, sizeof(tstatus));
142 tstatus.maxquota = quota;
144 /* next the next 3 available ids from the VLDB */
145 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 3, volumeId);
147 goto fail_UV_CreateVolume;
151 AFSVolCreateVolume(server, partition, volumeName, volser_RW, 0,
154 goto fail_UV_CreateVolume;
157 AFSVolSetInfo(server, tid, &tstatus);
159 tst = AFSVolSetFlags(server, tid, 0);
161 goto fail_UV_CreateVolume;
164 /* set up the vldb entry for this volume */
165 strncpy(entry.name, volumeName, VOLSER_OLDMAXVOLNAME);
167 entry.serverNumber[0] = ntohl(rx_HostOf(rx_PeerOf(server)));
168 entry.serverPartition[0] = partition;
169 entry.flags = RW_EXISTS;
170 entry.serverFlags[0] = ITSRWVOL;
171 entry.volumeId[RWVOL] = *volumeId;
172 entry.volumeId[ROVOL] = *volumeId + 1;
173 entry.volumeId[BACKVOL] = *volumeId + 2;
176 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
177 AFSVolDeleteVolume(server, tid);
178 goto fail_UV_CreateVolume;
181 tst = AFSVolEndTrans(server, tid, &rcode);
184 goto fail_UV_CreateVolume;
188 fail_UV_CreateVolume:
191 AFSVolEndTrans(server, tid, &rcode);
201 /* Delete the volume <volid>on <aserver> <apart>
202 * the physical entry gets removed from the vldb only if the ref count
206 UV_DeleteVolume(afs_cell_handle_p cellHandle, struct rx_connection *server,
207 unsigned int partition, afs_uint32 volumeId,
211 afs_status_t tst = 0;
212 afs_status_t temp = 0;
213 int serverAddr = ntohl(rx_HostOf(rx_PeerOf(server)));
217 struct nvldbentry entry;
219 afs_int32 avoltype = -1, vtype;
220 int notondisk = 0, notinvldb = 0;
222 /* Find and read the VLDB entry for this volume */
224 ubik_VL_SetLock(cellHandle->vos, 0, volumeId, avoltype,
227 if (tst != VL_NOENT) {
228 goto fail_UV_DeleteVolume;
234 if (!aVLDB_GetEntryByID(cellHandle, volumeId, avoltype, &entry, &tst)) {
235 goto fail_UV_DeleteVolume;
240 /* Whether volume is in the VLDB or not. Delete the volume on disk */
241 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
246 goto fail_UV_DeleteVolume;
249 tst = AFSVolDeleteVolume(server, ttid);
251 goto fail_UV_DeleteVolume;
253 tst = AFSVolEndTrans(server, ttid, &rcode);
254 tst = (tst ? tst : rcode);
257 goto fail_UV_DeleteVolume;
262 goto fail_UV_DeleteVolume;
265 if (volumeId == entry.volumeId[BACKVOL]) {
266 if (!(entry.flags & BACK_EXISTS)
267 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
269 goto fail_UV_DeleteVolume;
272 entry.flags &= ~BACK_EXISTS;
276 else if (volumeId == entry.volumeId[ROVOL]) {
277 if (!Lp_ROMatch(cellHandle, &entry, serverAddr, partition, &tst)) {
279 goto fail_UV_DeleteVolume;
282 Lp_SetROValue(cellHandle, &entry, serverAddr, partition, 0, 0);
284 if (!Lp_ROMatch(cellHandle, &entry, 0, 0, &tst)) {
285 entry.flags &= ~RO_EXISTS;
290 else if (volumeId == entry.volumeId[RWVOL]) {
291 if (!(entry.flags & RW_EXISTS)
292 || !Lp_Match(cellHandle, &entry, serverAddr, partition, &tst)) {
294 goto fail_UV_DeleteVolume;
297 /* Delete backup if it exists */
299 AFSVolTransCreate(server, entry.volumeId[BACKVOL], partition,
302 tst = AFSVolDeleteVolume(server, ttid);
304 goto fail_UV_DeleteVolume;
306 tst = AFSVolEndTrans(server, ttid, &rcode);
308 tst = (tst ? tst : rcode);
310 goto fail_UV_DeleteVolume;
314 Lp_SetRWValue(cellHandle, &entry, serverAddr, partition, 0L, 0L);
316 entry.flags &= ~(BACK_EXISTS | RW_EXISTS);
322 notinvldb = 2; /* Not found on this server and partition */
323 goto fail_UV_DeleteVolume;
326 if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS | RW_EXISTS))) {
327 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volumeId, vtype);
329 goto fail_UV_DeleteVolume;
332 if (!VLDB_ReplaceEntry
333 (cellHandle, volumeId, vtype, &entry,
334 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
335 goto fail_UV_DeleteVolume;
341 fail_UV_DeleteVolume:
343 if (notondisk && notinvldb) {
345 tst = ADMVOSVOLUMENOEXIST;
349 temp = AFSVolEndTrans(server, ttid, &rcode);
350 temp = (temp ? temp : rcode);
359 ubik_VL_ReleaseLock(cellHandle->vos, 0, volumeId, -1,
360 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
373 #define ONERR(ec, es, ep) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto mfail; }
375 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
376 * <atopart>. The operation is almost idempotent
380 UV_MoveVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
381 afs_int32 afromserver, afs_int32 afrompart, afs_int32 atoserver,
382 afs_int32 atopart, afs_status_p st)
385 afs_status_t tst = 0;
386 afs_status_t etst = 0;
387 struct rx_connection *toconn, *fromconn;
388 afs_int32 fromtid, totid, clonetid;
391 char tmpName[VOLSER_MAXVOLNAME + 1];
394 struct restoreCookie cookie;
395 afs_uint32 newVol, volid, backupId;
396 struct volser_status tstatus;
397 struct destServer destination;
399 struct nvldbentry entry;
403 afs_int32 store_flags;
405 #ifdef ENABLE_BUGFIX_1165
406 volEntries volumeInfo;
407 struct volintInfo *infop = 0;
411 fromconn = (struct rx_connection *)0;
412 toconn = (struct rx_connection *)0;
422 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
423 goto fail_UV_MoveVolume;
426 if (entry.volumeId[RWVOL] != afromvol) {
427 tst = ADMVOSVOLUMEMOVERWONLY;
428 goto fail_UV_MoveVolume;
432 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL, VLOP_MOVE);
434 goto fail_UV_MoveVolume;
438 if (!aVLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
439 goto fail_UV_MoveVolume;
442 backupId = entry.volumeId[BACKVOL];
444 if (!Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst)) {
445 /* the from server and partition do not exist in the vldb entry corresponding to volid */
446 if (!Lp_Match(cellHandle, &entry, atoserver, atopart, &tst)) {
447 /* the to server and partition do not exist in the vldb entry corresponding to volid */
449 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
450 (LOCKREL_OPCODE | LOCKREL_AFSID |
453 goto fail_UV_MoveVolume;
455 tst = VOLSERVOLMOVED;
456 goto fail_UV_MoveVolume;
459 /* delete the volume afromvol on src_server */
460 /* from-info does not exist but to-info does =>
461 * we have already done the move, but the volume
462 * may still be existing physically on from fileserver
464 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
469 AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
471 if (!tst) { /* volume exists - delete it */
473 AFSVolSetFlags(fromconn, fromtid,
474 VTDeleteOnSalvage | VTOutOfService);
476 goto fail_UV_MoveVolume;
479 tst = AFSVolDeleteVolume(fromconn, fromtid);
481 goto fail_UV_MoveVolume;
484 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
489 goto fail_UV_MoveVolume;
493 /*delete the backup volume now */
496 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
498 if (!tst) { /* backup volume exists - delete it */
500 AFSVolSetFlags(fromconn, fromtid,
501 VTDeleteOnSalvage | VTOutOfService);
503 goto fail_UV_MoveVolume;
506 tst = AFSVolDeleteVolume(fromconn, fromtid);
508 goto fail_UV_MoveVolume;
511 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
516 goto fail_UV_MoveVolume;
522 goto fail_UV_MoveVolume;
525 /* From-info matches the vldb info about volid,
526 * its ok start the move operation, the backup volume
527 * on the old site is deleted in the process
529 if (afrompart == atopart) {
530 if (!VLDB_IsSameAddrs
531 (cellHandle, afromserver, atoserver, &same, &tst)) {
532 goto fail_UV_MoveVolume;
535 tst = VOLSERVOLMOVED;
536 goto fail_UV_MoveVolume;
541 toconn = UV_Bind(cellHandle, atoserver, AFSCONF_VOLUMEPORT); /* get connections to the servers */
542 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
543 fromtid = totid = 0; /* initialize to uncreated */
546 * clone the read/write volume locally.
549 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
551 goto fail_UV_MoveVolume;
556 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &newVol);
558 goto fail_UV_MoveVolume;
561 /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
562 strcpy(vname, "move-clone-temp");
563 tst = AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
565 goto fail_UV_MoveVolume;
568 /* lookup the name of the volume we just cloned */
570 tst = AFSVolGetName(fromconn, fromtid, &volName);
572 goto fail_UV_MoveVolume;
576 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
581 goto fail_UV_MoveVolume;
585 * Create the destination volume
589 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
591 goto fail_UV_MoveVolume;
593 tst = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
595 goto fail_UV_MoveVolume;
598 /* remember time from which we've dumped the volume */
599 tst = AFSVolGetStatus(fromconn, clonetid, &tstatus);
601 goto fail_UV_MoveVolume;
604 fromDate = tstatus.creationDate - CLOCKSKEW;
606 #ifdef ENABLE_BUGFIX_1165
608 * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse)
609 * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we
610 * don't use this information...
612 volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */
613 volumeInfo.volEntries_len = 0;
614 tst = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo);
616 goto fail_UV_MoveVolume;
619 infop = (volintInfo *) volumeInfo.volEntries_val;
620 infop->maxquota = -1; /* Else it will replace the default quota */
623 /* create a volume on the target machine */
625 tst = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
626 if (!tst) { /*delete the existing volume */
628 tst = AFSVolDeleteVolume(toconn, totid);
630 goto fail_UV_MoveVolume;
633 tst = AFSVolEndTrans(toconn, totid, &rcode);
638 goto fail_UV_MoveVolume;
644 AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
647 goto fail_UV_MoveVolume;
650 strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME);
654 tst = AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage | VTOutOfService));
656 goto fail_UV_MoveVolume;
660 * Now dump the clone to the new volume
663 destination.destHost = atoserver;
664 destination.destPort = AFSCONF_VOLUMEPORT;
665 destination.destSSID = 1;
667 /* Copy the clone to the new volume */
668 strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME);
670 cookie.parent = entry.volumeId[RWVOL];
672 tst = AFSVolForward(fromconn, clonetid, 0, &destination, totid, &cookie);
674 goto fail_UV_MoveVolume;
677 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
682 goto fail_UV_MoveVolume;
686 * reattach to the main-line volume, and incrementally dump it.
689 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
691 goto fail_UV_MoveVolume;
694 /* now do the incremental */
696 AFSVolForward(fromconn, fromtid, fromDate, &destination, totid,
699 goto fail_UV_MoveVolume;
702 /* now adjust the flags so that the new volume becomes official */
703 tst = AFSVolSetFlags(fromconn, fromtid, VTOutOfService);
705 goto fail_UV_MoveVolume;
708 tst = AFSVolSetFlags(toconn, totid, 0);
710 goto fail_UV_MoveVolume;
712 #ifdef ENABLE_BUGFIX_1165
713 tst = AFSVolSetInfo(toconn, totid, infop);
715 goto fail_UV_MoveVolume;
719 /* put new volume online */
720 tst = AFSVolEndTrans(toconn, totid, &rcode);
725 goto fail_UV_MoveVolume;
728 Lp_SetRWValue(cellHandle, &entry, afromserver, afrompart, atoserver,
730 store_flags = entry.flags;
731 entry.flags &= ~BACK_EXISTS;
733 if (!VLDB_ReplaceEntry
734 (cellHandle, afromvol, -1, &entry,
735 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
736 goto fail_UV_MoveVolume;
738 entry.flags = store_flags;
741 if (atoserver != afromserver) {
742 /* set forwarding pointer for moved volumes */
743 tst = AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
745 goto fail_UV_MoveVolume;
749 tst = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */
751 goto fail_UV_MoveVolume;
754 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
759 goto fail_UV_MoveVolume;
762 /* Delete the backup volume on the original site */
764 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
767 AFSVolSetFlags(fromconn, fromtid,
768 VTDeleteOnSalvage | VTOutOfService);
770 goto fail_UV_MoveVolume;
773 tst = AFSVolDeleteVolume(fromconn, fromtid);
775 goto fail_UV_MoveVolume;
778 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
783 goto fail_UV_MoveVolume;
787 tst = 0; /* no backup volume? that's okay */
792 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline, &clonetid);
794 goto fail_UV_MoveVolume;
797 /* now delete the clone */
799 tst = AFSVolDeleteVolume(fromconn, clonetid);
801 goto fail_UV_MoveVolume;
804 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
809 goto fail_UV_MoveVolume;
815 /* normal cleanup code */
819 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
820 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
828 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
831 tst = (etst ? etst : rcode);
836 etst = AFSVolEndTrans(fromconn, clonetid, &rcode);
839 tst = (etst ? etst : rcode);
844 etst = AFSVolEndTrans(toconn, totid, &rcode);
847 tst = (etst ? etst : rcode);
852 #ifdef ENABLE_BUGFIX_1165
857 rx_ReleaseCachedConnection(fromconn);
859 rx_ReleaseCachedConnection(toconn);
867 /* come here only when the sky falls */
871 /* unlock VLDB entry */
873 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
874 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
877 AFSVolEndTrans(fromconn, clonetid, &rcode);
879 AFSVolEndTrans(toconn, totid, &rcode);
880 if (fromtid) { /* put it on-line */
881 AFSVolSetFlags(fromconn, fromtid, 0);
882 AFSVolEndTrans(fromconn, fromtid, &rcode);
885 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
889 /* Delete either the volume on the source location or the target location.
890 * If the vldb entry still points to the source location, then we know the
891 * volume move didn't finish so we remove the volume from the target
892 * location. Otherwise, we remove the volume from the source location.
894 if (Lp_Match(cellHandle, &entry, afromserver, afrompart, &tst)) { /* didn't move - delete target volume */
896 if (volid && toconn) {
898 AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
900 AFSVolSetFlags(toconn, totid,
901 VTDeleteOnSalvage | VTOutOfService);
902 AFSVolDeleteVolume(toconn, totid);
903 AFSVolEndTrans(toconn, totid, &rcode);
907 /* put source volume on-line */
910 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
913 AFSVolSetFlags(fromconn, fromtid, 0);
914 AFSVolEndTrans(fromconn, fromtid, &rcode);
917 } else { /* yep, move complete */
918 /* delete backup volume */
921 AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
924 AFSVolSetFlags(fromconn, fromtid,
925 VTDeleteOnSalvage | VTOutOfService);
926 AFSVolDeleteVolume(fromconn, fromtid);
927 AFSVolEndTrans(fromconn, fromtid, &rcode);
930 /* delete source volume */
932 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
935 AFSVolSetFlags(fromconn, fromtid,
936 VTDeleteOnSalvage | VTOutOfService);
937 if (atoserver != afromserver)
938 AFSVolSetForwarding(fromconn, fromtid, htonl(atoserver));
939 AFSVolDeleteVolume(fromconn, fromtid);
940 AFSVolEndTrans(fromconn, fromtid, &rcode);
945 /* common cleanup - delete local clone */
948 AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
951 AFSVolDeleteVolume(fromconn, clonetid);
952 AFSVolEndTrans(fromconn, clonetid, &rcode);
956 /* unlock VLDB entry */
957 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
958 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
960 done: /* routine cleanup */
963 #ifdef ENABLE_BUGFIX_1165
968 rx_ReleaseCachedConnection(fromconn);
970 rx_ReleaseCachedConnection(toconn);
978 /* Make a new backup of volume <avolid> on <aserver> and <apart>
979 * if one already exists, update it
983 UV_BackupVolume(afs_cell_handle_p cellHandle, afs_int32 aserver,
984 afs_int32 apart, afs_uint32 avolid, afs_status_p st)
987 afs_status_t tst = 0, temp = 0;
988 afs_int32 ttid = 0, btid = 0;
991 char vname[VOLSER_MAXVOLNAME + 1];
992 struct nvldbentry entry;
993 int vldblocked = 0, vldbmod = 0, backexists = 1;
994 struct rx_connection *aconn = UV_Bind(cellHandle, aserver,
998 /* the calls to VLDB will succeed only if avolid is a RW volume,
999 * since we are following the RW hash chain for searching */
1000 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
1001 goto fail_UV_BackupVolume;
1004 /* These operations require the VLDB be locked since it means the VLDB
1005 * will change or the vldb is already locked.
1007 if (!(entry.flags & BACK_EXISTS) || /* backup volume doesnt exist */
1008 (entry.flags & VLOP_ALLOPERS) || /* vldb lock already held */
1009 (entry.volumeId[BACKVOL] == INVALID_BID)) {
1010 /* no assigned backup volume id */
1013 ubik_VL_SetLock(cellHandle->vos, 0, avolid, RWVOL,
1016 goto fail_UV_BackupVolume;
1020 /* Reread the vldb entry */
1021 if (!aVLDB_GetEntryByID(cellHandle, avolid, RWVOL, &entry, &tst)) {
1022 goto fail_UV_BackupVolume;
1026 if (!ISNAMEVALID(entry.name)) {
1027 tst = VOLSERBADNAME;
1028 goto fail_UV_BackupVolume;
1031 backupID = entry.volumeId[BACKVOL];
1032 if (backupID == INVALID_BID) {
1033 /* Get a backup volume id from the VLDB and update the vldb
1036 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &backupID);
1038 goto fail_UV_BackupVolume;
1040 entry.volumeId[BACKVOL] = backupID;
1044 /* Test to see if the backup volume exists by trying to create
1045 * a transaction on the backup volume. We've assumed the backup exists.
1047 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1049 if (tst != VNOVOL) {
1050 goto fail_UV_BackupVolume;
1052 backexists = 0; /* backup volume does not exist */
1055 tst = AFSVolEndTrans(aconn, btid, &rcode);
1058 tst = (tst ? tst : rcode);
1059 goto fail_UV_BackupVolume;
1063 /* Now go ahead and try to clone the RW volume.
1064 * First start a transaction on the RW volume
1066 tst = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
1068 goto fail_UV_BackupVolume;
1071 /* Clone or reclone the volume, depending on whether the backup
1072 * volume exists or not
1075 tst = AFSVolReClone(aconn, ttid, backupID);
1077 goto fail_UV_BackupVolume;
1080 strcpy(vname, entry.name);
1081 strcat(vname, ".backup");
1083 tst = AFSVolClone(aconn, ttid, 0, backupVolume, vname, &backupID);
1085 goto fail_UV_BackupVolume;
1089 /* End transaction on the RW volume */
1090 tst = AFSVolEndTrans(aconn, ttid, &rcode);
1093 tst = (tst ? tst : rcode);
1094 goto fail_UV_BackupVolume;
1097 /* Mork vldb as backup exists */
1098 if (!(entry.flags & BACK_EXISTS)) {
1099 entry.flags |= BACK_EXISTS;
1103 /* Now go back to the backup volume and bring it on line */
1104 tst = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
1106 goto fail_UV_BackupVolume;
1109 tst = AFSVolSetFlags(aconn, btid, 0);
1111 goto fail_UV_BackupVolume;
1114 tst = AFSVolEndTrans(aconn, btid, &rcode);
1117 tst = (tst ? tst : rcode);
1118 goto fail_UV_BackupVolume;
1122 /* Will update the vldb below */
1124 fail_UV_BackupVolume:
1127 temp = AFSVolEndTrans(aconn, ttid, &rcode);
1128 if (temp || rcode) {
1130 tst = (temp ? temp : rcode);
1135 temp = AFSVolEndTrans(aconn, btid, &rcode);
1136 if (temp || rcode) {
1138 tst = (temp ? temp : rcode);
1142 /* Now update the vldb - if modified */
1145 if (!VLDB_ReplaceEntry
1146 (cellHandle, avolid, RWVOL, &entry,
1147 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
1155 ubik_VL_ReleaseLock(cellHandle->vos, 0, avolid, RWVOL,
1156 (LOCKREL_OPCODE | LOCKREL_AFSID |
1157 LOCKREL_TIMESTAMP));
1167 rx_ReleaseCachedConnection(aconn);
1177 DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
1180 afs_int32 acode, ccode, rcode, tid;
1181 ccode = rcode = tid = 0;
1183 acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
1184 if (!acode) { /* It really was there */
1185 acode = AFSVolDeleteVolume(conn, tid);
1186 ccode = AFSVolEndTrans(conn, tid, &rcode);
1194 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
1195 #define ERROREXIT(ec) { error = (ec); goto rfail; }
1197 #if 0 /* doesn't appear to be used, why compile it */
1199 CloneVol(afs_cell_handle_p cellHandle, struct rx_connection *conn,
1200 afs_uint32 rwvid, afs_int32 part, afs_uint32 * rovidp, int nottemp,
1201 struct nvldbentry *entry, afs_int32 * vidCreateDate, afs_status_p st)
1204 afs_status_t tst = 0, etst = 0;
1205 afs_int32 rcode = 0, tid = 0;
1206 struct volser_status volstatus;
1209 /* Begin transaction on RW volume marking it busy (clients will wait) */
1210 tst = AFSVolTransCreate(conn, rwvid, part, ITBusy, &tid);
1215 /* Get the RO volume id. Allocate a new one if need to */
1216 *rovidp = entry->volumeId[ROVOL];
1217 if (*rovidp == INVALID_BID) {
1218 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, rovidp);
1223 entry->volumeId[ROVOL] = *rovidp;
1226 /* If we are creating the ro clone, what are we calling it.
1227 * Depends on whether its a temporary clone or not.
1230 strcpy(vname, entry->name);
1231 strcat(vname, ".readonly");
1233 strcpy(vname, "readonly-clone-temp"); /* Should be unique? */
1236 /* Create the new clone. If it exists, then reclone it */
1237 tst = AFSVolClone(conn, tid, 0, readonlyVolume, vname, rovidp);
1238 if (tst == VVOLEXISTS) {
1239 tst = AFSVolReClone(conn, tid, *rovidp);
1248 /* Bring the volume back on-line as soon as possible */
1250 afs_int32 fromtid = 0;
1252 /* Now bring the RO clone on-line */
1253 tst = AFSVolTransCreate(conn, *rovidp, part, ITOffline, &fromtid);
1258 tst = AFSVolSetFlags(conn, fromtid, 0);
1263 tst = AFSVolEndTrans(conn, fromtid, &rcode);
1272 /* Get the time the RW was created for return information */
1273 tst = AFSVolGetStatus(conn, tid, &volstatus);
1277 *vidCreateDate = volstatus.creationDate;
1283 tst = AFSVolEndTrans(conn, tid, &rcode);
1300 /* Get a "transaction" on this replica. Create the volume
1301 * if necessary. Return the time from which a dump should
1302 * be made (0 if it's a new volume)
1305 GetTrans(afs_cell_handle_p cellHandle, struct nvldbentry *vldbEntryPtr,
1306 afs_int32 index, struct rx_connection **connPtr,
1307 afs_int32 * transPtr, afs_int32 * timePtr, afs_status_p st)
1310 afs_status_t tst = 0, etst = 0;
1312 struct volser_status tstatus;
1315 *connPtr = (struct rx_connection *)0;
1319 /* get connection to the replication site */
1321 UV_Bind(cellHandle, vldbEntryPtr->serverNumber[index],
1322 AFSCONF_VOLUMEPORT);
1324 /* server is down */
1329 volid = vldbEntryPtr->volumeId[ROVOL];
1332 AFSVolTransCreate(*connPtr, volid,
1333 vldbEntryPtr->serverPartition[index], ITOffline,
1337 /* If the volume does not exist, create it */
1338 if (!volid || tst) {
1341 if (volid && (tst != VNOVOL)) {
1345 strcpy(volname, vldbEntryPtr->name);
1346 strcat(volname, ".readonly");
1349 AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index],
1351 vldbEntryPtr->volumeId[RWVOL], &volid,
1356 vldbEntryPtr->volumeId[ROVOL] = volid;
1358 /* The following is a bit redundant, since create sets these flags by default */
1360 AFSVolSetFlags(*connPtr, *transPtr,
1361 VTDeleteOnSalvage | VTOutOfService);
1367 /* Otherwise, the transaction did succeed, so get the creation date of the
1368 * latest RO volume on the replication site
1371 tst = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
1375 *timePtr = tstatus.creationDate - CLOCKSKEW;
1381 if ((rc == 0) && (*transPtr)) {
1382 etst = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
1395 SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
1396 afs_int32 fromdate, manyDests * tr, afs_int32 flags,
1397 void *cookie, manyResults * results)
1401 for (i = 0; i < tr->manyDests_len; i++) {
1402 results->manyResults_val[i] =
1403 AFSVolForward(fromconn, fromtid, fromdate,
1404 &(tr->manyDests_val[i].server),
1405 tr->manyDests_val[i].trans, cookie);
1412 * Determine if a volume exists on a server and partition.
1413 * Try creating a transaction on the volume. If we can,
1414 * the volume exists, if not, then return the error code.
1415 * Some error codes mean the volume is unavailable but
1416 * still exists - so we catch these error codes.
1419 VolumeExists(afs_cell_handle_p cellHandle, afs_int32 server,
1420 afs_int32 partition, afs_int32 volumeid, afs_status_p st)
1423 afs_status_t tst = 0;
1424 struct rx_connection *conn = (struct rx_connection *)0;
1425 volEntries volumeInfo;
1427 conn = UV_Bind(cellHandle, server, AFSCONF_VOLUMEPORT);
1429 volumeInfo.volEntries_val = (volintInfo *) 0;
1430 volumeInfo.volEntries_len = 0;
1431 tst = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo);
1432 if (volumeInfo.volEntries_val)
1433 free(volumeInfo.volEntries_val);
1434 if (tst == VOLSERILLEGAL_PARTITION) {
1437 rx_ReleaseCachedConnection(conn);
1447 /* release volume <afromvol> on <afromserver> <afrompart> to all the
1448 * sites if forceflag is 1.If its 0 complete the release if the previous
1449 * release aborted else start a new release */
1451 UV_ReleaseVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
1452 afs_int32 afromserver, afs_int32 afrompart, int forceflag,
1456 afs_status_t tst = 0, etst = 0;
1460 afs_uint32 cloneVolId, roVolId;
1461 struct replica *replicas = 0;
1462 struct nvldbentry entry;
1463 int i, volcount, m, fullrelease, vldbindex;
1465 struct restoreCookie cookie;
1466 struct rx_connection **toconns = 0;
1467 struct release *times = 0;
1469 struct rx_connection *fromconn = (struct rx_connection *)0;
1471 afs_int32 clonetid = 0, onlinetid;
1472 afs_int32 fromtid = 0;
1473 afs_uint32 fromdate = 0, thisdate;
1476 manyResults results;
1477 int rwindex, roindex, roclone, roexists;
1478 afs_int32 rwcrdate = 0;
1482 } remembertime[NMAXNSERVERS];
1483 int releasecount = 0;
1484 struct volser_status volstatus;
1486 memset((char *)remembertime, 0, sizeof(remembertime));
1487 memset((char *)&results, 0, sizeof(results));
1490 ubik_VL_SetLock(cellHandle->vos, 0, afromvol, RWVOL,
1492 if ((tst) && (tst != VL_RERELEASE)) {
1493 goto fail_UV_ReleaseVolume;
1497 /* Get the vldb entry in readable format */
1498 if (!aVLDB_GetEntryByID(cellHandle, afromvol, RWVOL, &entry, &tst)) {
1499 goto fail_UV_ReleaseVolume;
1502 if (!ISNAMEVALID(entry.name)) {
1503 tst = VOLSERBADNAME;
1504 goto fail_UV_ReleaseVolume;
1507 if (entry.volumeId[RWVOL] != afromvol) {
1508 tst = ADMVOSVOLUMERELEASERWONLY;
1509 goto fail_UV_ReleaseVolume;
1512 if (entry.nServers <= 1) {
1513 tst = ADMVOSVOLUMENOREPLICAS;
1514 goto fail_UV_ReleaseVolume;
1517 if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME - 10)) {
1518 tst = VOLSERBADNAME;
1519 goto fail_UV_ReleaseVolume;
1522 /* roclone is true if one of the RO volumes is on the same
1523 * partition as the RW volume. In this case, we make the RO volume
1524 * on the same partition a clone instead of a complete copy.
1528 Lp_ROMatch(cellHandle, &entry, afromserver, afrompart, &tst) - 1;
1529 roclone = ((roindex == -1) ? 0 : 1);
1530 rwindex = Lp_GetRwIndex(cellHandle, &entry, 0);
1533 goto fail_UV_ReleaseVolume;
1536 /* Make sure we have a RO volume id to work with */
1537 if (entry.volumeId[ROVOL] == INVALID_BID) {
1538 /* need to get a new RO volume id */
1539 tst = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &roVolId);
1541 goto fail_UV_ReleaseVolume;
1544 entry.volumeId[ROVOL] = roVolId;
1545 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1546 goto fail_UV_ReleaseVolume;
1550 /* Will we be completing a previously unfinished release. -force overrides */
1551 for (fullrelease = 1, i = 0; (fullrelease && (i < entry.nServers)); i++) {
1552 if (entry.serverFlags[i] & NEW_REPSITE)
1555 if (forceflag && !fullrelease)
1558 /* Determine which volume id to use and see if it exists */
1561 || (entry.cloneId == 0)) ? entry.volumeId[ROVOL] : entry.cloneId);
1562 VolumeExists(cellHandle, afromserver, afrompart, cloneVolId, &tst);
1563 roexists = ((tst == ENODEV) ? 0 : 1);
1564 if (!roexists && !fullrelease)
1565 fullrelease = 1; /* Do a full release if RO clone does not exist */
1567 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
1570 goto fail_UV_ReleaseVolume;
1574 /* If the RO clone exists, then if the clone is a temporary
1575 * clone, delete it. Or if the RO clone is marked RO_DONTUSE
1576 * (it was recently added), then also delete it. We do not
1577 * want to "reclone" a temporary RO clone.
1580 && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE))) {
1581 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1582 if (tst && (tst != VNOVOL)) {
1583 goto fail_UV_ReleaseVolume;
1588 /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't
1589 * write this entry out to the vlserver until after the first
1590 * RO volume is released (temp RO clones don't count).
1592 for (i = 0; i < entry.nServers; i++) {
1593 entry.serverFlags[i] &= ~NEW_REPSITE;
1594 entry.serverFlags[i] |= RO_DONTUSE;
1596 entry.serverFlags[rwindex] |= NEW_REPSITE;
1597 entry.serverFlags[rwindex] &= ~RO_DONTUSE;
1599 /* Begin transaction on RW and mark it busy while we clone it */
1601 AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
1604 goto fail_UV_ReleaseVolume;
1607 /* Clone or reclone the volume */
1609 tst = AFSVolReClone(fromconn, clonetid, cloneVolId);
1611 goto fail_UV_ReleaseVolume;
1615 strcpy(vname, entry.name);
1616 strcat(vname, ".readonly");
1618 strcpy(vname, "readonly-clone-temp");
1621 AFSVolClone(fromconn, clonetid, 0, readonlyVolume, vname,
1624 goto fail_UV_ReleaseVolume;
1628 /* Get the time the RW was created for future information */
1629 tst = AFSVolGetStatus(fromconn, clonetid, &volstatus);
1631 goto fail_UV_ReleaseVolume;
1633 rwcrdate = volstatus.creationDate;
1635 /* End the transaction on the RW volume */
1636 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1638 tst = (tst ? tst : rcode);
1640 goto fail_UV_ReleaseVolume;
1643 /* Remember clone volume ID in case we fail or are interrupted */
1644 entry.cloneId = cloneVolId;
1647 /* Bring the RO clone online - though not if it's a temporary clone */
1649 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
1652 goto fail_UV_ReleaseVolume;
1655 etst = AFSVolSetFlags(fromconn, onlinetid, 0);
1657 tst = AFSVolEndTrans(fromconn, onlinetid, &rcode);
1658 tst = (tst ? tst : rcode);
1660 goto fail_UV_ReleaseVolume;
1664 goto fail_UV_ReleaseVolume;
1667 /* Sleep so that a client searching for an online volume won't
1668 * find the clone offline and then the next RO offline while the
1669 * release brings the clone online and the next RO offline (race).
1670 * There is a fix in the 3.4 client that does not need this sleep
1671 * anymore, but we don't know what clients we have.
1673 if (entry.nServers > 2)
1676 /* Mark the RO clone in the VLDB as a good site (already released) */
1677 entry.serverFlags[roindex] |= NEW_REPSITE;
1678 entry.serverFlags[roindex] &= ~RO_DONTUSE;
1679 entry.flags |= RO_EXISTS;
1683 /* Write out the VLDB entry only if the clone is not a temporary
1684 * clone. If we did this to a temporary clone then we would end
1685 * up marking all the ROs as "old release" making the ROs
1686 * temporarily unavailable.
1688 if (!VLDB_ReplaceEntry
1689 (cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1690 goto fail_UV_ReleaseVolume;
1695 /* Now we will release from the clone to the remaining RO replicas.
1696 * The first 2 ROs (counting the non-temporary RO clone) are released
1697 * individually: releasecount. This is to reduce the race condition
1698 * of clients trying to find an on-line RO volume. The remaining ROs
1699 * are released in parallel but no more than half the number of ROs
1700 * (rounded up) at a time: nservers.
1703 strcpy(vname, entry.name);
1704 strcat(vname, ".readonly");
1705 memset(&cookie, 0, sizeof(cookie));
1706 strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME);
1707 cookie.type = ROVOL;
1708 cookie.parent = entry.volumeId[RWVOL];
1711 nservers = entry.nServers / 2; /* how many to do at once, excluding clone */
1713 (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
1714 times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
1716 (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
1718 results.manyResults_val =
1719 (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
1720 if (!replicas || !times || !!!results.manyResults_val || !toconns) {
1722 goto fail_UV_ReleaseVolume;
1725 memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
1726 memset(times, 0, (sizeof(struct release) * nservers + 1));
1727 memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
1728 memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
1730 /* Create a transaction on the cloned volume */
1732 AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
1734 goto fail_UV_ReleaseVolume;
1737 /* For each index in the VLDB */
1738 for (vldbindex = 0; vldbindex < entry.nServers;) {
1740 /* Get a transaction on the replicas. Pick replacas which have an old release. */
1742 ((volcount < nservers) && (vldbindex < entry.nServers));
1744 /* The first two RO volumes will be released individually.
1745 * The rest are then released in parallel. This is a hack
1746 * for clients not recognizing right away when a RO volume
1747 * comes back on-line.
1749 if ((volcount == 1) && (releasecount < 2))
1752 if (vldbindex == roindex)
1753 continue; /* the clone */
1754 if ((entry.serverFlags[vldbindex] & NEW_REPSITE)
1755 && !(entry.serverFlags[vldbindex] & RO_DONTUSE))
1757 if (!(entry.serverFlags[vldbindex] & ITSROVOL))
1758 continue; /* not a RO vol */
1761 /* Get a Transaction on this replica. Get a new connection if
1762 * necessary. Create the volume if necessary. Return the
1763 * time from which the dump should be made (0 if it's a new
1764 * volume). Each volume might have a different time.
1766 replicas[volcount].server.destHost =
1767 entry.serverNumber[vldbindex];
1768 replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT;
1769 replicas[volcount].server.destSSID = 1;
1770 times[volcount].vldbEntryIndex = vldbindex;
1773 (cellHandle, &entry, vldbindex, &(toconns[volcount]),
1774 &(replicas[volcount].trans), &(times[volcount].time),
1779 /* Thisdate is the date from which we want to pick up all changes */
1780 if (forceflag || !fullrelease
1781 || (rwcrdate > times[volcount].time)) {
1782 /* If the forceflag is set, then we want to do a full dump.
1783 * If it's not a full release, we can't be sure that the creation
1784 * date is good (so we also do a full dump).
1785 * If the RW volume was replaced (its creation date is newer than
1786 * the last release), then we can't be sure what has changed (so
1787 * we do a full dump).
1790 } else if (remembertime[vldbindex].validtime) {
1791 /* Trans was prev ended. Use the time from the prev trans
1792 * because, prev trans may have created the volume. In which
1793 * case time[volcount].time would be now instead of 0.
1796 (remembertime[vldbindex].time <
1797 times[volcount].time) ? remembertime[vldbindex].
1798 time : times[volcount].time;
1800 thisdate = times[volcount].time;
1802 remembertime[vldbindex].validtime = 1;
1803 remembertime[vldbindex].time = thisdate;
1805 if (volcount == 0) {
1806 fromdate = thisdate;
1808 /* Include this volume if it is within 15 minutes of the earliest */
1810 thisdate) ? (fromdate - thisdate) : (thisdate -
1812 AFSVolEndTrans(toconns[volcount],
1813 replicas[volcount].trans, &rcode);
1814 replicas[volcount].trans = 0;
1817 if (thisdate < fromdate)
1818 fromdate = thisdate;
1825 /* Release the ones we have collected */
1826 tr.manyDests_val = &(replicas[0]);
1827 tr.manyDests_len = results.manyResults_len = volcount;
1829 AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr,
1830 0 /*spare */ , &cookie, &results);
1831 if (tst == RXGEN_OPCODE) { /* RPC Interface Mismatch */
1833 SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr,
1834 0 /*spare */ , &cookie, &results);
1839 goto fail_UV_ReleaseVolume;
1841 for (m = 0; m < volcount; m++) {
1842 if (results.manyResults_val[m]) {
1847 AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname,
1848 ROVOL, entry.volumeId[RWVOL], 0, 0);
1853 /* have to clear dest. flags to ensure new vol goes online:
1854 * because the restore (forwarded) operation copied
1855 * the V_inService(=0) flag over to the destination.
1857 tst = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
1862 entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE;
1863 entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE;
1864 entry.flags |= RO_EXISTS;
1869 /* End the transactions and destroy the connections */
1870 for (s = 0; s < volcount; s++) {
1871 if (replicas[s].trans)
1872 tst = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode);
1873 replicas[s].trans = 0;
1877 if ((s == 0) || (tst != ENOENT)) {
1879 if (times[s].vldbEntryIndex < vldbindex)
1880 vldbindex = times[s].vldbEntryIndex;
1885 rx_ReleaseCachedConnection(toconns[s]);
1889 if (!VLDB_ReplaceEntry(cellHandle, afromvol, RWVOL, &entry, 0, &tst)) {
1890 goto fail_UV_ReleaseVolume;
1892 } /* for each index in the vldb */
1894 /* End the transaction on the cloned volume */
1895 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1898 /* Figure out if any volume were not released and say so */
1899 for (failure = 0, i = 0; i < entry.nServers; i++) {
1900 if (!(entry.serverFlags[i] & NEW_REPSITE))
1904 if (!VLDB_ReplaceEntry
1905 (cellHandle, afromvol, RWVOL, &entry, LOCKREL_TIMESTAMP, &tst)) {
1906 goto fail_UV_ReleaseVolume;
1909 tst = VOLSERBADRELEASE;
1910 goto fail_UV_ReleaseVolume;
1913 /* All the ROs were release successfully. Remove the temporary clone */
1915 tst = DelVol(fromconn, cloneVolId, afrompart, ITOffline);
1917 goto fail_UV_ReleaseVolume;
1922 for (i = 0; i < entry.nServers; i++)
1923 entry.serverFlags[i] &= ~NEW_REPSITE;
1925 /* Update the VLDB */
1926 if (!VLDB_ReplaceEntry
1927 (cellHandle, afromvol, RWVOL, &entry,
1928 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
1929 goto fail_UV_ReleaseVolume;
1933 fail_UV_ReleaseVolume:
1936 tst = AFSVolEndTrans(fromconn, clonetid, &rcode);
1943 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
1949 for (i = 0; i < nservers; i++) {
1950 if (replicas && replicas[i].trans) {
1951 tst = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode);
1952 replicas[i].trans = 0;
1957 if (toconns && toconns[i]) {
1958 rx_ReleaseCachedConnection(toconns[i]);
1964 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, RWVOL,
1965 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
1972 rx_ReleaseCachedConnection(fromconn);
1973 if (results.manyResults_val)
1974 free(results.manyResults_val);
1989 ReceiveFile(register int fd, register struct rx_call *call,
1990 register struct stat *status)
1992 register char *buffer = (char *)0;
1993 register int blockSize;
1994 afs_int32 bytesread, nbytes, bytesleft, w;
1996 afs_int32 error = 0;
2003 struct statfs tstatfs;
2005 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2007 fstatfs(fd, &tstatfs);
2008 blockSize = tstatfs.f_bsize;
2010 blockSize = status->st_blksize;
2017 buffer = (char *)malloc(blockSize);
2022 while (!error && (bytesread > 0)) {
2023 bytesread = rx_Read(call, buffer, nbytes);
2024 bytesleft = bytesread;
2025 while (!error && (bytesleft > 0)) {
2028 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2029 select(fd + 1, 0, &out, 0, 0); /* don't timeout if write bl
2032 w = write(fd, &buffer[bytesread - bytesleft], bytesleft);
2034 error = ADMVOSDUMPFILEWRITEFAIL;
2050 DumpFunction(struct rx_call *call, const char *filename)
2054 afs_int32 error, code;
2059 fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666);
2060 if (fd < 0 || fstat(fd, &status) < 0) {
2061 error = VOLSERBADOP;
2064 code = ReceiveFile(fd, call, &status);
2082 /*dump the volume <afromvol> on <afromserver> and
2083 * <afrompart> to <afilename> starting from <fromdate>.
2084 * DumpFunction does the real work behind the scenes after
2085 * extracting parameters from the rock */
2087 UV_DumpVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
2088 afs_int32 afromserver, afs_int32 afrompart, afs_int32 fromdate,
2089 const char *filename, afs_status_p st)
2092 afs_status_t tst = 0;
2093 afs_status_t etst = 0;
2094 struct rx_connection *fromconn;
2095 struct rx_call *fromcall;
2100 struct nvldbentry entry;
2107 fromcall = (struct rx_call *)0;
2108 fromconn = (struct rx_connection *)0;
2110 fromcall = (struct rx_call *)0;
2113 if (!aVLDB_GetEntryByID(cellHandle, afromvol, -1, &entry, &tst)) {
2114 goto fail_UV_DumpVolume;
2117 /* get connections to the servers */
2118 fromconn = UV_Bind(cellHandle, afromserver, AFSCONF_VOLUMEPORT);
2119 tst = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
2121 goto fail_UV_DumpVolume;
2123 fromcall = rx_NewCall(fromconn);
2124 tst = StartAFSVolDump(fromcall, fromtid, fromdate);
2126 goto fail_UV_DumpVolume;
2128 if ((tst = DumpFunction(fromcall, filename))) {
2129 goto fail_UV_DumpVolume;
2131 tst = rx_EndCall(fromcall, rxError);
2132 fromcall = (struct rx_call *)0;
2134 goto fail_UV_DumpVolume;
2136 tst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2141 goto fail_UV_DumpVolume;
2149 ubik_VL_ReleaseLock(cellHandle->vos, 0, afromvol, -1,
2150 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2158 etst = rx_EndCall(fromcall, rxError);
2166 etst = AFSVolEndTrans(fromconn, fromtid, &rcode);
2176 rx_ReleaseCachedConnection(fromconn);
2186 SendFile(register int fd, register struct rx_call *call,
2187 register struct stat *status)
2189 char *buffer = (char *)0;
2192 afs_int32 error = 0;
2201 struct statfs tstatfs;
2203 /* Unfortunately in AIX valuable fields such as st_blksize are gone from the sta
2205 fstatfs(fd, &tstatfs);
2206 blockSize = tstatfs.f_bsize;
2208 blockSize = status->st_blksize;
2214 buffer = (char *)malloc(blockSize);
2219 while (!error && !done) {
2222 #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */
2223 select(fd + 1, &in, 0, 0, 0); /* don't timeout if read blocks */
2225 nbytes = read(fd, buffer, blockSize);
2227 error = ADMVOSRESTOREFILEREADFAIL;
2234 if (rx_Write(call, buffer, nbytes) != nbytes) {
2235 error = ADMVOSRESTOREFILEWRITEFAIL;
2245 WriteData(struct rx_call *call, const char *filename)
2249 afs_int32 error, code;
2254 fd = open(filename, 0);
2255 if (fd < 0 || fstat(fd, &status) < 0) {
2256 fprintf(STDERR, "Could access file '%s'\n", filename);
2257 error = ADMVOSRESTOREFILEOPENFAIL;
2258 goto fail_WriteData;
2260 code = SendFile(fd, call, &status);
2263 goto fail_WriteData;
2274 error = ADMVOSRESTOREFILECLOSEFAIL;
2280 * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
2281 * the dump file <afilename>. WriteData does all the real work
2282 * after extracting params from the rock
2285 UV_RestoreVolume(afs_cell_handle_p cellHandle, afs_int32 toserver,
2286 afs_int32 topart, afs_uint32 tovolid, const char *tovolname,
2287 int flags, const char *dumpFile, afs_status_p st)
2290 afs_status_t tst = 0;
2291 afs_status_t etst = 0;
2292 struct rx_connection *toconn, *tempconn;
2293 struct rx_call *tocall;
2294 afs_int32 totid, rcode;
2295 afs_int32 rxError = 0;
2296 struct volser_status tstatus;
2301 struct nvldbentry entry;
2304 struct restoreCookie cookie;
2306 afs_int32 newDate, volflag;
2310 memset(&cookie, 0, sizeof(cookie));
2315 tocall = (struct rx_call *)0;
2316 toconn = (struct rx_connection *)0;
2317 tempconn = (struct rx_connection *)0;
2322 toconn = UV_Bind(cellHandle, toserver, AFSCONF_VOLUMEPORT);
2323 if (pvolid == 0) { /*alot a new id if needed */
2324 aVLDB_GetEntryByName(cellHandle, tovolname, &entry, &tst);
2325 if (tst == VL_NOENT) {
2327 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 1, &pvolid);
2329 goto fail_UV_RestoreVolume;
2333 pvolid = entry.volumeId[RWVOL];
2338 * at this point we have a volume id to use/reuse for the
2339 * volume to be restored
2341 if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
2342 tst = ADMVOSRESTOREVOLUMENAMETOOBIG;
2343 goto fail_UV_RestoreVolume;
2346 if (!vos_PartitionIdToName(topart, partName, &tst)) {
2347 goto fail_UV_RestoreVolume;
2349 /*what should the volume be restored as ? rw or ro or bk ?
2350 * right now the default is rw always */
2352 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0, &pvolid,
2355 if (flags & RV_FULLRST) { /* full restore: delete then create anew */
2357 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2359 goto fail_UV_RestoreVolume;
2362 AFSVolSetFlags(toconn, totid,
2363 VTDeleteOnSalvage | VTOutOfService);
2365 goto fail_UV_RestoreVolume;
2367 tst = AFSVolDeleteVolume(toconn, totid);
2369 goto fail_UV_RestoreVolume;
2371 tst = AFSVolEndTrans(toconn, totid, &rcode);
2376 goto fail_UV_RestoreVolume;
2379 AFSVolCreateVolume(toconn, topart, tovolname, volser_RW, 0,
2382 goto fail_UV_RestoreVolume;
2386 AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
2388 goto fail_UV_RestoreVolume;
2392 cookie.parent = pvolid;
2393 cookie.type = RWVOL;
2395 strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
2397 tocall = rx_NewCall(toconn);
2398 tst = StartAFSVolRestore(tocall, totid, 1, &cookie);
2400 goto fail_UV_RestoreVolume;
2402 tst = WriteData(tocall, dumpFile);
2404 goto fail_UV_RestoreVolume;
2406 tst = rx_EndCall(tocall, rxError);
2407 tocall = (struct rx_call *)0;
2409 goto fail_UV_RestoreVolume;
2411 tst = AFSVolGetStatus(toconn, totid, &tstatus);
2413 goto fail_UV_RestoreVolume;
2415 tst = AFSVolSetIdsTypes(toconn, totid, tovolname, RWVOL, pvolid, 0, 0);
2417 goto fail_UV_RestoreVolume;
2420 tst = AFSVolSetDate(toconn, totid, newDate);
2422 goto fail_UV_RestoreVolume;
2425 volflag = ((flags & RV_OFFLINE) ? VTOutOfService : 0); /* off or on-line */
2426 tst = AFSVolSetFlags(toconn, totid, volflag);
2428 goto fail_UV_RestoreVolume;
2431 /* It isn't handled right in fail_UV_RestoreVolume */
2432 tst = AFSVolEndTrans(toconn, totid, &rcode);
2437 goto fail_UV_RestoreVolume;
2441 if (success && (!reuseID || (flags & RV_FULLRST))) {
2442 /* Volume was restored on the file server, update the
2443 * VLDB to reflect the change.
2445 aVLDB_GetEntryByID(cellHandle, pvolid, RWVOL, &entry, &tst);
2446 if (tst && tst != VL_NOENT && tst != VL_ENTDELETED) {
2447 goto fail_UV_RestoreVolume;
2449 if (tst == VL_NOENT) { /* it doesnot exist already */
2450 /*make the vldb return this indication specifically */
2451 strcpy(entry.name, tovolname);
2453 entry.serverNumber[0] = toserver; /*should be indirect */
2454 entry.serverPartition[0] = topart;
2455 entry.serverFlags[0] = ITSRWVOL;
2456 entry.flags = RW_EXISTS;
2457 if (tstatus.cloneID != 0) {
2458 entry.volumeId[ROVOL] = tstatus.cloneID; /*this should come from status info on the volume if non zero */
2460 entry.volumeId[ROVOL] = INVALID_BID;
2461 entry.volumeId[RWVOL] = pvolid;
2463 if (tstatus.backupID != 0) {
2464 entry.volumeId[BACKVOL] = tstatus.backupID;
2465 /*this should come from status info on the volume if non zero */
2467 entry.volumeId[BACKVOL] = INVALID_BID;
2468 if (!VLDB_CreateEntry(cellHandle, &entry, &tst)) {
2469 goto fail_UV_RestoreVolume;
2472 } else { /*update the existing entry */
2474 ubik_VL_SetLock(cellHandle->vos, 0, pvolid, RWVOL,
2477 goto fail_UV_RestoreVolume;
2480 strcpy(entry.name, tovolname);
2482 /* Update the vlentry with the new information */
2483 index = Lp_GetRwIndex(cellHandle, &entry, 0);
2485 /* Add the rw site for the volume being restored */
2486 entry.serverNumber[entry.nServers] = toserver;
2487 entry.serverPartition[entry.nServers] = topart;
2488 entry.serverFlags[entry.nServers] = ITSRWVOL;
2491 /* This volume should be deleted on the old site
2492 * if its different from new site.
2494 VLDB_IsSameAddrs(cellHandle, toserver,
2495 entry.serverNumber[index], &same, &tst);
2497 || (entry.serverPartition[index] != topart)) {
2499 UV_Bind(cellHandle, entry.serverNumber[index],
2500 AFSCONF_VOLUMEPORT);
2502 AFSVolTransCreate(tempconn, pvolid,
2503 entry.serverPartition[index],
2504 ITOffline, &temptid);
2507 AFSVolSetFlags(tempconn, temptid,
2511 goto fail_UV_RestoreVolume;
2513 tst = AFSVolDeleteVolume(tempconn, temptid);
2515 goto fail_UV_RestoreVolume;
2517 tst = AFSVolEndTrans(tempconn, temptid, &rcode);
2522 goto fail_UV_RestoreVolume;
2524 vos_PartitionIdToName(entry.serverPartition[index],
2528 entry.serverNumber[index] = toserver;
2529 entry.serverPartition[index] = topart;
2532 entry.flags |= RW_EXISTS;
2533 if (!VLDB_ReplaceEntry
2534 (cellHandle, pvolid, RWVOL, &entry,
2535 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2536 goto fail_UV_RestoreVolume;
2543 fail_UV_RestoreVolume:
2546 etst = rx_EndCall(tocall, rxError);
2552 ubik_VL_ReleaseLock(cellHandle->vos, 0, pvolid, RWVOL,
2553 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2560 etst = AFSVolEndTrans(toconn, totid, &rcode);
2569 etst = AFSVolEndTrans(toconn, temptid, &rcode);
2579 rx_ReleaseCachedConnection(tempconn);
2581 rx_ReleaseCachedConnection(toconn);
2589 /*adds <server> and <part> as a readonly replication site for <volid>
2592 UV_AddSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2593 afs_uint32 volid, afs_status_p st)
2596 afs_status_t tst = 0;
2597 int j, nro = 0, islocked = 0;
2598 struct nvldbentry entry;
2602 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2604 goto fail_UV_AddSite;
2608 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2609 goto fail_UV_AddSite;
2611 if (!ISNAMEVALID(entry.name)) {
2613 goto fail_UV_AddSite;
2616 /* See if it's too many entries */
2617 if (entry.nServers >= NMAXNSERVERS) {
2619 goto fail_UV_AddSite;
2622 /* See if it's on the same server */
2623 for (j = 0; j < entry.nServers; j++) {
2624 if (entry.serverFlags[j] & ITSROVOL) {
2626 if (!VLDB_IsSameAddrs
2627 (cellHandle, server, entry.serverNumber[j], &same, &tst)) {
2628 goto fail_UV_AddSite;
2632 goto fail_UV_AddSite;
2637 /* See if it's too many RO sites - leave one for the RW */
2638 if (nro >= NMAXNSERVERS - 1) {
2640 goto fail_UV_AddSite;
2643 entry.serverNumber[entry.nServers] = server;
2644 entry.serverPartition[entry.nServers] = part;
2645 entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
2648 if (!VLDB_ReplaceEntry
2649 (cellHandle, volid, RWVOL, &entry,
2650 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP, &tst)) {
2651 goto fail_UV_AddSite;
2660 ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2661 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2670 /*removes <server> <part> as read only site for <volid> from the vldb */
2672 UV_RemoveSite(afs_cell_handle_p cellHandle, afs_int32 server, afs_int32 part,
2673 afs_uint32 volid, afs_status_p st)
2676 afs_status_t tst = 0;
2677 struct nvldbentry entry;
2681 ubik_VL_SetLock(cellHandle->vos, 0, volid, RWVOL, VLOP_ADDSITE);
2683 goto fail_UV_RemoveSite;
2687 if (!aVLDB_GetEntryByID(cellHandle, volid, RWVOL, &entry, &tst)) {
2688 goto fail_UV_RemoveSite;
2690 if (!Lp_ROMatch(cellHandle, &entry, server, part, &tst)) {
2691 /*this site doesnot exist */
2692 goto fail_UV_RemoveSite;
2693 } else { /*remove the rep site */
2694 Lp_SetROValue(cellHandle, &entry, server, part, 0, 0);
2696 if ((entry.nServers == 1) && (entry.flags & RW_EXISTS))
2697 entry.flags &= ~RO_EXISTS;
2698 if (entry.nServers < 1) { /*this is the last ref */
2699 tst = ubik_VL_DeleteEntry(cellHandle->vos, 0, volid, ROVOL);
2701 goto fail_UV_RemoveSite;
2704 if (!VLDB_ReplaceEntry
2705 (cellHandle, volid, RWVOL, &entry,
2706 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP), &tst)) {
2707 goto fail_UV_RemoveSite;
2716 t = ubik_VL_ReleaseLock(cellHandle->vos, 0, volid, RWVOL,
2717 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
2729 /*list all the partitions on <aserver> */
2731 UV_ListPartitions(struct rx_connection *server, struct partList *ptrPartList,
2732 afs_int32 * cntp, afs_status_p st)
2735 afs_status_t tst = 0;
2736 struct pIDs partIds;
2737 struct partEntries partEnts;
2738 register int i, j = 0;
2742 partEnts.partEntries_len = 0;
2743 partEnts.partEntries_val = NULL;
2744 /* this is available only on new servers */
2745 tst = AFSVolXListPartitions(server, &partEnts);
2747 /* next, try old interface */
2748 if (tst == RXGEN_OPCODE) {
2749 for (i = 0; i < 26; i++)
2750 partIds.partIds[i] = -1;
2751 tst = AFSVolListPartitions(server, &partIds);
2753 for (i = 0; i < 26; i++) {
2754 if ((partIds.partIds[i]) != -1) {
2755 ptrPartList->partId[j] = partIds.partIds[i];
2756 ptrPartList->partFlags[j] = PARTVALID;
2759 ptrPartList->partFlags[i] = 0;
2763 goto fail_UV_ListPartitions;
2766 *cntp = partEnts.partEntries_len;
2767 if (*cntp > VOLMAXPARTS) {
2768 *cntp = VOLMAXPARTS;
2770 for (i = 0; i < *cntp; i++) {
2771 ptrPartList->partId[i] = partEnts.partEntries_val[i];
2772 ptrPartList->partFlags[i] = PARTVALID;
2774 free(partEnts.partEntries_val);
2776 goto fail_UV_ListPartitions;
2780 fail_UV_ListPartitions:
2788 /*------------------------------------------------------------------------
2789 * EXPORTED UV_XListVolumes
2792 * List the extended information for all the volumes on a particular
2793 * File Server and partition. We may either return the volume's ID
2794 * or all of its extended information.
2797 * a_serverID : Address of the File Server for which we want
2798 * extended volume info.
2799 * a_partID : Partition for which we want the extended
2801 * a_all : If non-zero, fetch ALL the volume info,
2802 * otherwise just the volume ID.
2803 * a_resultPP : Ptr to the address of the area containing
2804 * the returned volume info.
2805 * a_numEntsInResultP : Ptr for the value we set for the number of
2810 * Otherise, the return value of AFSVolXListVolumes.
2813 * This routine is closely related to UV_ListVolumes, which returns
2814 * only the standard level of detail on AFS volumes. It is a
2815 * heavyweight operation, zipping through all the volume entries for
2816 * a given server/partition.
2820 *------------------------------------------------------------------------*/
2823 UV_XListVolumes(struct rx_connection *server, afs_int32 a_partID, int a_all,
2824 struct volintXInfo **a_resultPP,
2825 afs_int32 * a_numEntsInResultP, afs_status_p st)
2828 afs_status_t tst = 0;
2830 volXEntries volumeXInfo; /*Area for returned extended vol info */
2833 * Set up our error code and the area for returned extended volume info.
2834 * We set the val field to a null pointer as a hint for the stub to
2837 *a_numEntsInResultP = 0;
2838 *a_resultPP = (volintXInfo *) 0;
2839 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2840 volumeXInfo.volXEntries_len = 0;
2843 * Bind to the Volume Server port on the File Server machine in question,
2846 tst = AFSVolXListVolumes(server, a_partID, a_all, &volumeXInfo);
2848 goto fail_UV_XListVolumes;
2851 * We got the info; pull out the pointer to where the results lie
2852 * and how many entries are there.
2854 *a_resultPP = volumeXInfo.volXEntries_val;
2855 *a_numEntsInResultP = volumeXInfo.volXEntries_len;
2859 fail_UV_XListVolumes:
2867 /*------------------------------------------------------------------------
2868 * EXPORTED UV_XListOneVolume
2871 * List the extended information for a volume on a particular File
2872 * Server and partition.
2875 * server : a handle to the server where the volume resides.
2876 * a_partID : Partition for which we want the extended
2878 * a_volID : Volume ID for which we want the info.
2879 * a_resultPP : Ptr to the address of the area containing
2880 * the returned volume info.
2884 * Otherise, the return value of AFSVolXListOneVolume.
2887 * This routine is closely related to UV_ListOneVolume, which returns
2888 * only the standard level of detail on the chosen AFS volume.
2892 *------------------------------------------------------------------------*/
2895 UV_XListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2896 afs_uint32 a_volID, struct volintXInfo **a_resultPP,
2900 afs_status_t tst = 0;
2901 volXEntries volumeXInfo; /*Area for returned info */
2904 * Set the area we're in which we are returning
2905 * the info. Setting the val field to a null pointer tells the stub
2906 * to allocate space for us.
2908 *a_resultPP = (volintXInfo *) 0;
2909 volumeXInfo.volXEntries_val = (volintXInfo *) 0;
2910 volumeXInfo.volXEntries_len = 0;
2912 tst = AFSVolXListOneVolume(server, a_partID, a_volID, &volumeXInfo);
2915 goto fail_UV_XListOneVolume;
2918 * We got the info; pull out the pointer to where the results lie.
2920 *a_resultPP = volumeXInfo.volXEntries_val;
2924 fail_UV_XListOneVolume:
2931 } /*UV_XListOneVolume */
2933 /*------------------------------------------------------------------------
2934 * EXPORTED UV_ListOneVolume
2937 * List the volume information for a volume on a particular File
2938 * Server and partition.
2941 * server : a handle to the server where the volume resides.
2942 * a_partID : Partition for which we want the extended
2944 * a_volID : Volume ID for which we want the info.
2945 * a_resultPP : Ptr to the address of the area containing
2946 * the returned volume info.
2950 * Otherise, the return value of AFSVolXListOneVolume.
2954 *------------------------------------------------------------------------*/
2956 int UV_ListOneVolume(struct rx_connection *server, afs_int32 a_partID,
2957 afs_uint32 a_volID, struct volintInfo **a_resultPP,
2961 afs_status_t tst = 0;
2962 volEntries volumeInfo; /*Area for returned info */
2965 * Set the area we're in which we are returning
2966 * the info. Setting the val field to a null pointer tells the stub
2967 * to allocate space for us.
2969 *a_resultPP = (volintInfo *) 0;
2970 volumeInfo.volEntries_val = (volintInfo *) 0;
2971 volumeInfo.volEntries_len = 0;
2973 tst = AFSVolListOneVolume(server, a_partID, a_volID, &volumeInfo);
2976 goto fail_UV_ListOneVolume;
2979 * We got the info; pull out the pointer to where the results lie.
2981 *a_resultPP = volumeInfo.volEntries_val;
2985 fail_UV_ListOneVolume:
2991 }/*UV_ListOneVolume*/
2993 /*sync vldb with all the entries on <myQueue> on <aserver> and <apart>*/
2995 ProcessEntries(afs_cell_handle_p cellHandle, struct qHead *myQueue,
2996 struct rx_connection *server, afs_int32 apart, afs_int32 force)
3000 afs_uint32 temp1, temp2;
3002 afs_uint32 maxVolid = 0;
3003 struct nvldbentry entry;
3004 int noError = 1, error, same;
3005 int totalC, totalU, totalCE, totalUE, totalG;
3007 int aserver = ntohl(rx_HostOf(rx_PeerOf(server)));
3010 totalC = totalU = totalCE = totalUE = totalG = 0;
3013 /* get the next available id's from the vldb server */
3014 vcode = ubik_VL_GetNewVolumeId(cellHandle->vos, 0, 0, &maxVolid);
3018 totalG = myQueue->count;
3022 Lp_QEnumerate(myQueue, &success, &elem, 0);
3027 if (!elem.isValid[RWVOL] && !elem.isValid[ROVOL] && !elem.isValid[BACKVOL]) { /*something is wrong with elem */
3031 if (maxVolid <= elem.ids[RWVOL]) {
3033 temp2 = elem.ids[RWVOL] - maxVolid + 1;
3036 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3040 if (maxVolid <= elem.ids[ROVOL]) {
3042 temp2 = elem.ids[ROVOL] - maxVolid + 1;
3045 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3049 if (maxVolid <= elem.ids[BACKVOL]) {
3051 temp2 = elem.ids[BACKVOL] - temp1 + 1;
3054 ubik_VL_GetNewVolumeId(cellHandle->vos, 0, temp2,
3058 aVLDB_GetEntryByID(cellHandle, elem.ids[RWVOL], RWVOL, &entry, &tst);
3059 if (tst && (tst != VL_NOENT)) {
3062 } else if (tst && (tst == VL_NOENT)) { /*entry doesnot exist */
3063 /*set up a vldb entry for elem */
3064 memset(&entry, 0, sizeof(entry));
3065 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME);
3066 if (elem.isValid[RWVOL]) { /*rw exists */
3067 entry.flags |= RW_EXISTS;
3068 entry.serverFlags[entry.nServers] = ITSRWVOL;
3069 entry.serverNumber[entry.nServers] = aserver;
3070 entry.serverPartition[entry.nServers] = apart;
3071 entry.nServers += 1;
3072 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3073 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3074 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3076 if (elem.isValid[ROVOL]) { /*ro volume exists */
3077 entry.flags |= RO_EXISTS;
3078 entry.serverFlags[entry.nServers] = ITSROVOL;
3079 entry.serverNumber[entry.nServers] = aserver;
3080 entry.serverPartition[entry.nServers] = apart;
3081 entry.nServers += 1;
3082 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3083 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3086 if (elem.isValid[BACKVOL]) { /*backup volume exists */
3087 entry.flags |= BACK_EXISTS;
3088 if (!(entry.flags & RW_EXISTS)) { /*this helps to check for a stray backup if parent moves */
3089 entry.serverFlags[entry.nServers] = ITSRWVOL;
3090 entry.serverNumber[entry.nServers] = aserver;
3091 entry.serverPartition[entry.nServers] = apart;
3092 entry.nServers += 1;
3095 entry.volumeId[RWVOL] = elem.ids[RWVOL];
3096 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3099 VLDB_CreateEntry(cellHandle, &entry, &tst);
3105 } else { /* Update the existing entry */
3106 strncpy(entry.name, elem.name, VOLSER_OLDMAXVOLNAME); /*the name Could have changed */
3108 if (elem.isValid[RWVOL]) { /* A RW volume */
3109 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3111 /* A RW index is not found in the VLDB entry - will add it */
3113 entry.flags |= RW_EXISTS;
3114 entry.serverNumber[entry.nServers] = aserver;
3115 entry.serverPartition[entry.nServers] = apart;
3116 entry.serverFlags[entry.nServers] = ITSRWVOL;
3119 /* A RW index is found in the VLDB entry.
3120 * Verify that the volume location matches the VLDB location.
3121 * Fix the VLDB entry if it is not correct.
3125 VLDB_IsSameAddrs(cellHandle, aserver,
3126 entry.serverNumber[temp], &same,
3131 if (!same || (apart != entry.serverPartition[temp])) {
3132 /* VLDB says volume is in another place. Fix the VLDB entry */
3133 entry.serverNumber[temp] = aserver;
3134 entry.serverPartition[temp] = apart;
3137 entry.flags |= RW_EXISTS;
3139 if ((elem.ids[BACKVOL] != 0) && elem.isValid[BACKVOL])
3140 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3141 if ((elem.ids[ROVOL] != 0) && elem.isValid[ROVOL])
3142 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3145 if (elem.isValid[ROVOL]) {
3146 /*tackle a ro volume */
3148 if (!Lp_ROMatch(cellHandle, &entry, aserver, apart, 0)) {
3150 if (elem.ids[ROVOL] > entry.volumeId[ROVOL]) {
3151 /*there is a conflict of ids, keep the later volume */
3152 /*delete all the ro volumes listed in vldb entry since they
3155 int j, count, rwsite;
3158 count = entry.nServers;
3160 for (j = 0; j < count; j++) {
3161 if (entry.serverFlags[j] & ITSROVOL) {
3163 /*delete the site */
3164 entry.serverNumber[j] = 0;
3165 entry.serverPartition[j] = 0;
3166 entry.serverFlags[j] = 0;
3168 } else if (entry.serverFlags[j] & ITSRWVOL)
3173 entry.serverNumber[entry.nServers] =
3174 entry.serverNumber[rwsite];
3175 entry.serverPartition[entry.nServers] =
3176 entry.serverPartition[rwsite];
3177 entry.serverFlags[entry.nServers] =
3178 entry.serverFlags[rwsite];
3181 entry.serverNumber[entry.nServers] = aserver;
3182 entry.serverPartition[entry.nServers] = apart;
3183 entry.serverFlags[entry.nServers] = ITSROVOL;
3185 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3186 entry.flags |= RO_EXISTS;
3188 } else if (elem.ids[ROVOL] < entry.volumeId[ROVOL]) {
3189 if (!(entry.flags & RO_EXISTS)) {
3190 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3191 entry.serverNumber[entry.nServers] = aserver;
3192 entry.serverPartition[entry.nServers] = apart;
3193 entry.serverFlags[entry.nServers] = ITSROVOL;
3195 entry.flags |= RO_EXISTS;
3200 else if (elem.ids[ROVOL] == entry.volumeId[ROVOL]) {
3201 entry.serverNumber[entry.nServers] = aserver;
3202 entry.serverPartition[entry.nServers] = apart;
3203 entry.serverFlags[entry.nServers] = ITSROVOL;
3205 entry.flags |= RO_EXISTS;
3206 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3209 if (entry.volumeId[ROVOL] == INVALID_BID)
3210 entry.volumeId[ROVOL] = elem.ids[ROVOL];
3213 if (elem.isValid[BACKVOL]) {
3214 temp = Lp_GetRwIndex(cellHandle, &entry, 0);
3215 if (temp != -1) { /*check if existing backup site matches with the given arguments */
3217 VLDB_IsSameAddrs(cellHandle, aserver,
3218 entry.serverNumber[temp], &same,
3224 /*tackle the backup volume */
3225 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3226 entry.flags |= BACK_EXISTS;
3228 if (entry.volumeId[BACKVOL] == INVALID_BID)
3229 entry.volumeId[BACKVOL] = elem.ids[BACKVOL];
3232 VLDB_ReplaceEntry(cellHandle, elem.ids[RWVOL], RWVOL, &entry,
3233 LOCKREL_OPCODE | LOCKREL_AFSID |
3234 LOCKREL_TIMESTAMP, &tst);
3240 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3241 elem.ids[RWVOL], RWVOL,
3242 LOCKREL_OPCODE | LOCKREL_AFSID |
3248 } /* else update the existing entry */
3250 } /* End of while(1) */
3258 /*synchronise vldb with the file server <aserver> and <apart>(if flags=1).
3259 *else synchronise with all the valid partitions on <aserver>
3262 UV_SyncVldb(afs_cell_handle_p cellHandle, struct rx_connection *server,
3263 afs_int32 apart, int flags, int force, afs_status_p st)
3266 afs_status_t tst = 0;
3269 volEntries volumeInfo;
3271 struct qHead myQueue;
3272 struct partList PartList;
3277 /*this hints the stub to allocate space */
3278 volumeInfo.volEntries_val = (volintInfo *) 0;
3279 volumeInfo.volEntries_len = 0;
3281 if (!flags) { /*generate all the valid partitions */
3282 UV_ListPartitions(server, &PartList, &cnt, &tst);
3284 goto fail_UV_SyncVldb;
3287 PartList.partId[0] = apart;
3291 for (i = 0; i < cnt; i++) {
3292 apart = PartList.partId[i];
3293 /*this hints the stub to allocate space */
3294 volumeInfo.volEntries_val = (volintInfo *) 0;
3295 volumeInfo.volEntries_len = 0;
3296 tst = AFSVolListVolumes(server, apart, 1, &volumeInfo);
3298 goto fail_UV_SyncVldb;
3300 count = volumeInfo.volEntries_len;
3301 pntr = volumeInfo.volEntries_val;
3303 if (!vos_PartitionIdToName(apart, pname, &tst)) {
3304 goto fail_UV_SyncVldb;
3306 /*collect all vol entries by their parentid */
3307 tst = GroupEntries(server, pntr, count, &myQueue, apart);
3310 if (volumeInfo.volEntries_val) {
3311 /*free the space allocated by the stub */
3312 free(volumeInfo.volEntries_val);
3313 volumeInfo.volEntries_val = 0;
3317 tst = ProcessEntries(cellHandle, &myQueue, server, apart, force);
3319 tst = VOLSERFAILEDOP;
3320 if (volumeInfo.volEntries_val) {
3321 /*free the space allocated by the stub */
3322 free(volumeInfo.volEntries_val);
3323 volumeInfo.volEntries_val = 0;
3330 tst = VOLSERFAILEDOP;
3331 } /* thru all partitions */
3336 if (volumeInfo.volEntries_val)
3337 free(volumeInfo.volEntries_val);
3350 CheckVldbRWBK(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3351 afs_int32 * modified, afs_status_p st)
3354 afs_status_t tst = 0;
3360 idx = Lp_GetRwIndex(cellHandle, entry, 0);
3362 /* Check to see if the RW volume exists and set the RW_EXISTS
3365 if (idx == -1) { /* Did not find a RW entry */
3366 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists */
3367 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist */
3372 (cellHandle, entry->serverNumber[idx],
3373 entry->serverPartition[idx], entry->volumeId[RWVOL], &tst)) {
3374 if (!(entry->flags & RW_EXISTS)) { /* ... yet entry says RW does no
3376 entry->flags |= RW_EXISTS; /* ... so say RW does exist */
3379 } else if (tst == ENODEV) { /* RW volume does not exist */
3380 if (entry->flags & RW_EXISTS) { /* ... yet entry says RW exists
3382 entry->flags &= ~RW_EXISTS; /* ... so say RW does not exist
3387 /* If VLDB says it didn't exist, then ignore error */
3388 if (entry->flags & RW_EXISTS) {
3389 goto fail_CheckVldbRWBK;
3394 /* Check to see if the BK volume exists and set the BACK_EXISTS
3395 * flag accordingly. idx already ponts to the RW entry.
3397 if (idx == -1) { /* Did not find a RW entry */
3398 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists */
3399 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist */
3402 } else { /* Found a RW entry */
3404 (cellHandle, entry->serverNumber[idx],
3405 entry->serverPartition[idx], entry->volumeId[BACKVOL], &tst)) {
3406 if (!(entry->flags & BACK_EXISTS)) { /* ... yet entry says BK does n
3408 entry->flags |= BACK_EXISTS; /* ... so say BK does exist */
3411 } else if (tst == ENODEV) { /* BK volume does not exist */
3412 if (entry->flags & BACK_EXISTS) { /* ... yet entry says BK exists
3414 entry->flags &= ~BACK_EXISTS; /* ... so say BK does not exist
3419 /* If VLDB says it didn't exist, then ignore error */
3420 if (entry->flags & BACK_EXISTS) {
3421 goto fail_CheckVldbRWBK;
3426 /* If there is an idx but the BK and RW volumes no
3427 * longer exist, then remove the RW entry.
3429 if ((idx != -1) && !(entry->flags & RW_EXISTS)
3430 && !(entry->flags & BACK_EXISTS)) {
3431 Lp_SetRWValue(cellHandle, entry, entry->serverNumber[idx],
3432 entry->serverPartition[idx], 0L, 0L);
3441 *modified = modentry;
3451 CheckVldbRO(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3452 afs_int32 * modified, afs_status_p st)
3455 afs_status_t tst = 0;
3457 int foundro = 0, modentry = 0;
3462 /* Check to see if the RO volumes exist and set the RO_EXISTS
3465 for (idx = 0; idx < entry->nServers; idx++) {
3466 if (!(entry->serverFlags[idx] & ITSROVOL)) {
3467 continue; /* not a RO */
3471 (cellHandle, entry->serverNumber[idx],
3472 entry->serverPartition[idx], entry->volumeId[ROVOL], &tst)) {
3474 } else if (tst == ENODEV) { /* RW volume does not exist */
3475 Lp_SetROValue(cellHandle, entry, entry->serverNumber[idx],
3476 entry->serverPartition[idx], 0L, 0L);
3481 goto fail_CheckVldbRO;
3485 if (foundro) { /* A RO volume exists */
3486 if (!(entry->flags & RO_EXISTS)) { /* ... yet entry says RW does not e
3488 entry->flags |= RO_EXISTS; /* ... so say RW does exist */
3491 } else { /* A RO volume does not exist */
3492 if (entry->flags & RO_EXISTS) { /* ... yet entry says RO exists */
3493 entry->flags &= ~RO_EXISTS; /* ... so say RO does not exist */
3502 *modified = modentry;
3510 /*ensure that <entry> matches with the info on file servers */
3512 CheckVldb(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3513 afs_int32 * modified, afs_status_p st)
3516 afs_status_t tst = 0;
3520 afs_int32 modentry = 0;
3521 afs_int32 delentry = 0;
3527 if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME - 10)) {
3529 goto fail_CheckVldb;
3534 /* Check to see if the VLDB is ok without locking it (pass 1).
3535 * If it will change, then lock the VLDB entry, read it again,
3536 * then make the changes to it (pass 2).
3540 ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL],
3541 RWVOL, VLOP_DELETE);
3543 goto fail_CheckVldb;
3547 if (!aVLDB_GetEntryByID
3548 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, &tst)) {
3549 goto fail_CheckVldb;
3555 /* Check if the RW and BK entries are ok */
3556 if (!CheckVldbRWBK(cellHandle, entry, &modentry, &tst)) {
3557 goto fail_CheckVldb;
3559 if (modentry && (pass == 1))
3562 /* Check if the RO volumes entries are ok */
3563 if (!CheckVldbRO(cellHandle, entry, &modentry, &tst)) {
3564 goto fail_CheckVldb;
3566 if (modentry && (pass == 1))
3569 /* The VLDB entry has been updated. If it as been modified, then
3570 * write the entry back out the the VLDB.
3576 if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
3577 && !(entry->flags & RO_EXISTS)) {
3578 /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
3580 ubik_VL_DeleteEntry(cellHandle->vos, 0,
3581 entry->volumeId[RWVOL], RWVOL);
3583 goto fail_CheckVldb;
3587 /* Replace old entry with our new one */
3588 if (!VLDB_ReplaceEntry
3589 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry,
3590 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP),
3592 goto fail_CheckVldb;
3605 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3606 entry->volumeId[RWVOL], RWVOL,
3607 (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
3620 /*synchronise <aserver> <apart>(if flags = 1) with the vldb .
3621 *if flags = 0, synchronise all the valid partitions on <aserver>*/
3623 UV_SyncServer(afs_cell_handle_p cellHandle, struct rx_connection *server,
3624 afs_int32 apart, int flags, afs_status_p st)
3627 afs_status_t tst = 0;
3628 afs_int32 code, vcode;
3630 afs_int32 nentries, tentries = 0;
3631 struct VldbListByAttributes attributes;
3632 nbulkentries arrayEntries;
3634 register struct nvldbentry *vllist;
3637 afs_int32 modified = 0;
3642 arrayEntries.nbulkentries_val = 0;
3644 /* Set up attributes to search VLDB */
3645 attributes.server = ntohl(rx_HostOf(rx_PeerOf(server)));
3646 attributes.Mask = VLLIST_SERVER;
3648 attributes.partition = apart;
3649 attributes.Mask |= VLLIST_PARTITION;
3652 for (si = 0; si != -1; si = nsi) {
3653 /*initialize to hint the stub to alloc space */
3654 memset(&arrayEntries, 0, sizeof(arrayEntries));
3655 if (!VLDB_ListAttributes
3656 (cellHandle, &attributes, &nentries, &arrayEntries, &tst)) {
3657 goto fail_UV_SyncServer;
3660 tentries += nentries;
3662 for (j = 0; j < nentries; j++) { /* process each entry */
3663 vllist = &arrayEntries.nbulkentries_val[j];
3664 if (!CheckVldb(cellHandle, vllist, &modified, &tst)) {
3669 if (arrayEntries.nbulkentries_val) {
3670 free(arrayEntries.nbulkentries_val);
3671 arrayEntries.nbulkentries_val = 0;
3678 if (arrayEntries.nbulkentries_val) {
3679 free(arrayEntries.nbulkentries_val);
3682 tst = VOLSERFAILEDOP;
3689 /*rename volume <oldname> to <newname>, changing the names of the related
3690 *readonly and backup volumes. This operation is also idempotent.
3691 *salvager is capable of recovering from rename operation stopping halfway.
3692 *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
3694 UV_RenameVolume(afs_cell_handle_p cellHandle, struct nvldbentry *entry,
3695 const char *newname, afs_status_p st)
3698 afs_status_t tst = 0;
3699 afs_status_t etst = 0;
3700 afs_int32 rcode, error;
3702 char nameBuffer[256];
3704 struct rx_connection *aconn;
3708 aconn = (struct rx_connection *)0;
3712 tst = ubik_VL_SetLock(cellHandle->vos, 0, entry->volumeId[RWVOL], RWVOL, VLOP_ADDSITE); /*last param is dummy */
3714 goto fail_UV_RenameVolume;
3718 strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME);
3720 if (!VLDB_ReplaceEntry
3721 (cellHandle, entry->volumeId[RWVOL], RWVOL, entry, 0, &tst)) {
3722 goto fail_UV_RenameVolume;
3724 /*at this stage the intent to rename is recorded in the vldb, as far
3726 * is concerned, oldname is lost */
3727 if (entry->flags & RW_EXISTS) {
3728 index = Lp_GetRwIndex(cellHandle, entry, 0);
3729 if (index == -1) { /* there is a serious discrepancy */
3730 tst = VOLSERVLDB_ERROR;
3731 goto fail_UV_RenameVolume;
3734 UV_Bind(cellHandle, entry->serverNumber[index],
3735 AFSCONF_VOLUMEPORT);
3737 AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
3738 entry->serverPartition[index], ITOffline, &tid);
3739 if (tst) { /*volume doesnot exist */
3740 goto fail_UV_RenameVolume;
3741 } else { /*volume exists, process it */
3744 AFSVolSetIdsTypes(aconn, tid, newname, RWVOL,
3745 entry->volumeId[RWVOL],
3746 entry->volumeId[ROVOL],
3747 entry->volumeId[BACKVOL]);
3749 tst = AFSVolEndTrans(aconn, tid, &rcode);
3752 goto fail_UV_RenameVolume;
3755 goto fail_UV_RenameVolume;
3759 rx_ReleaseCachedConnection(aconn);
3760 aconn = (struct rx_connection *)0;
3762 /*end rw volume processing */
3763 if (entry->flags & BACK_EXISTS) { /*process the backup volume */
3764 index = Lp_GetRwIndex(cellHandle, entry, 0);
3765 if (index == -1) { /* there is a serious discrepancy */
3766 tst = VOLSERVLDB_ERROR;
3767 goto fail_UV_RenameVolume;
3770 UV_Bind(cellHandle, entry->serverNumber[index],
3771 AFSCONF_VOLUMEPORT);
3773 AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
3774 entry->serverPartition[index], ITOffline, &tid);
3775 if (tst) { /*volume doesnot exist */
3776 goto fail_UV_RenameVolume;
3777 } else { /*volume exists, process it */
3778 if (strlen(newname) > (VOLSER_OLDMAXVOLNAME - 8)) {
3779 goto fail_UV_RenameVolume;
3781 strcpy(nameBuffer, newname);
3782 strcat(nameBuffer, ".backup");
3785 AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL,
3786 entry->volumeId[RWVOL], 0, 0);
3788 tst = AFSVolEndTrans(aconn, tid, &rcode);
3791 goto fail_UV_RenameVolume;
3794 goto fail_UV_RenameVolume;
3797 } /* end backup processing */
3799 rx_ReleaseCachedConnection(aconn);
3800 aconn = (struct rx_connection *)0;
3801 if (entry->flags & RO_EXISTS) { /*process the ro volumes */
3802 for (i = 0; i < entry->nServers; i++) {
3803 if (entry->serverFlags[i] & ITSROVOL) {
3805 UV_Bind(cellHandle, entry->serverNumber[i],
3806 AFSCONF_VOLUMEPORT);
3808 AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
3809 entry->serverPartition[i], ITOffline,
3811 if (tst) { /*volume doesnot exist */
3812 goto fail_UV_RenameVolume;
3813 } else { /*volume exists, process it */
3814 strcpy(nameBuffer, newname);
3815 strcat(nameBuffer, ".readonly");
3816 if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME - 1)) {
3817 goto fail_UV_RenameVolume;
3820 AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL,
3821 entry->volumeId[RWVOL], 0, 0);
3823 tst = AFSVolEndTrans(aconn, tid, &rcode);
3826 goto fail_UV_RenameVolume;
3829 goto fail_UV_RenameVolume;
3833 rx_ReleaseCachedConnection(aconn);
3834 aconn = (struct rx_connection *)0;
3840 fail_UV_RenameVolume:
3844 ubik_VL_ReleaseLock(cellHandle->vos, 0,
3845 entry->volumeId[RWVOL], RWVOL,
3846 LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
3853 etst = AFSVolEndTrans(aconn, tid, &rcode);
3860 rx_ReleaseCachedConnection(aconn);
3868 /*group all the volume entries on< apart >by their parentid or by their ids'
3869 *if the volume is rw. <count> is the number of entries to be processesd.
3870 *<pntr> points to the first entry.< myQueue> is the queue with entries
3873 GroupEntries(struct rx_connection *server, volintInfo * pntr, afs_int32 count,
3874 struct qHead *myQueue, afs_int32 apart)
3876 struct aqueue *qPtr;
3878 afs_int32 curId, code;
3880 afs_int32 error = 0;
3886 for (i = 0; i < count; i++) { /*process each entry */
3887 if (pntr->status) { /* entry is valid */
3888 if (pntr->type == RWVOL)
3889 curId = pntr->volid;
3891 curId = pntr->parentID;
3892 Lp_QScan(myQueue, curId, &success, &qPtr, 0);
3893 if (success) { /*entry exists in the queue */
3894 if (pntr->type == RWVOL) {
3895 /*check if the rw exists already, if so hang on the
3896 * later version if the present version is ok */
3897 if (qPtr->isValid[RWVOL]) {
3898 /*this should not happen, there is a serious error here */
3900 error = VOLSERMULTIRWVOL;
3902 qPtr->isValid[RWVOL] = 1;
3903 qPtr->copyDate[RWVOL] = pntr->copyDate;
3904 if (!qPtr->isValid[BACKVOL])
3905 qPtr->ids[BACKVOL] = pntr->backupID;
3906 if (!qPtr->isValid[ROVOL])
3907 qPtr->ids[ROVOL] = pntr->cloneID;
3909 } else if (pntr->type == BACKVOL) {
3910 if (qPtr->isValid[BACKVOL]) {
3911 /*do different checks, delete superflous volume */
3912 if (qPtr->copyDate[BACKVOL] > pntr->copyDate) {
3913 /*delete the present volume . */
3915 CheckAndDeleteVolume(server, apart, 0,
3923 /*delete the older volume after making sure, current one is ok */
3925 CheckAndDeleteVolume(server, apart,
3927 qPtr->ids[BACKVOL]);
3933 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3934 qPtr->ids[BACKVOL] = pntr->volid;
3938 qPtr->isValid[BACKVOL] = 1;
3939 qPtr->ids[BACKVOL] = pntr->volid;
3940 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3942 } else if (pntr->type == ROVOL) {
3943 if (qPtr->isValid[ROVOL]) {
3944 /*do different checks, delete superflous volume */
3945 if (qPtr->copyDate[ROVOL] > pntr->copyDate) {
3946 /*delete the present volume . */
3949 CheckAndDeleteVolume(server, apart, 0,
3956 /*delete the older volume after making sure, current one is ok */
3958 CheckAndDeleteVolume(server, apart,
3966 qPtr->copyDate[ROVOL] = pntr->copyDate;
3967 qPtr->ids[ROVOL] = pntr->volid;
3971 qPtr->isValid[ROVOL] = 1;
3972 qPtr->ids[ROVOL] = pntr->volid;
3973 qPtr->copyDate[ROVOL] = pntr->copyDate;
3977 error = VOLSERBADOP;
3979 } else { /*create a fresh entry */
3980 qPtr = (struct aqueue *)malloc(sizeof(struct aqueue));
3981 if (pntr->type == RWVOL) {
3982 qPtr->isValid[RWVOL] = 1;
3983 qPtr->isValid[BACKVOL] = 0;
3984 qPtr->isValid[ROVOL] = 0;
3985 qPtr->ids[RWVOL] = pntr->volid;
3986 qPtr->ids[BACKVOL] = pntr->backupID;
3987 qPtr->ids[ROVOL] = pntr->cloneID;
3988 qPtr->copyDate[RWVOL] = pntr->copyDate;
3989 strncpy(qPtr->name, pntr->name, VOLSER_OLDMAXVOLNAME);
3991 } else if (pntr->type == BACKVOL) {
3992 qPtr->isValid[RWVOL] = 0;
3993 qPtr->isValid[BACKVOL] = 1;
3994 qPtr->isValid[ROVOL] = 0;
3995 qPtr->ids[RWVOL] = pntr->parentID;
3996 qPtr->ids[BACKVOL] = pntr->volid;
3997 qPtr->ids[ROVOL] = 0;
3998 qPtr->copyDate[BACKVOL] = pntr->copyDate;
3999 vsu_ExtractName(qPtr->name, pntr->name);
4001 } else if (pntr->type == ROVOL) {
4002 qPtr->isValid[RWVOL] = 0;
4003 qPtr->isValid[BACKVOL] = 0;
4004 qPtr->isValid[ROVOL] = 1;
4005 qPtr->ids[RWVOL] = pntr->parentID;
4006 qPtr->ids[BACKVOL] = 0;
4007 qPtr->ids[ROVOL] = pntr->volid;
4008 qPtr->copyDate[ROVOL] = pntr->copyDate;
4009 vsu_ExtractName(qPtr->name, pntr->name);
4013 Lp_QAdd(myQueue, qPtr);
4015 pntr++; /*get next entry */
4025 /*report on all the active transactions on volser */
4027 UV_VolserStatus(struct rx_connection *server, transDebugInfo ** rpntr,
4028 afs_int32 * rcount, afs_status_p st)
4031 afs_status_t tst = 0;
4032 transDebugEntries transInfo;
4034 transInfo.transDebugEntries_val = (transDebugInfo *) 0;
4035 transInfo.transDebugEntries_len = 0;
4036 tst = AFSVolMonitor(server, &transInfo);
4038 goto fail_UV_VolserStatus;
4041 *rcount = transInfo.transDebugEntries_len;
4042 *rpntr = transInfo.transDebugEntries_val;
4045 fail_UV_VolserStatus:
4048 if (transInfo.transDebugEntries_val) {
4049 free(transInfo.transDebugEntries_val);
4059 /*delete the volume without interacting with the vldb */
4061 UV_VolumeZap(afs_cell_handle_p cellHandle, struct rx_connection *server,
4062 unsigned int partition, afs_uint32 volumeId, afs_status_p st)
4064 afs_int32 rcode, ttid, error, code;
4066 afs_status_t tst = 0;
4072 tst = AFSVolTransCreate(server, volumeId, partition, ITOffline, &ttid);
4074 tst = AFSVolDeleteVolume(server, ttid);
4076 tst = AFSVolEndTrans(server, ttid, &rcode);
4084 * We failed to delete the volume, but we still need
4085 * to end the transaction.
4087 AFSVolEndTrans(server, ttid, &rcode);
4099 UV_SetVolume(struct rx_connection *server, afs_int32 partition,
4100 afs_uint32 volid, afs_int32 transflag, afs_int32 setflag,
4101 unsigned int sleepTime, afs_status_p st)
4104 afs_status_t tst = 0;
4105 afs_status_t etst = 0;
4109 tst = AFSVolTransCreate(server, volid, partition, transflag, &tid);
4111 goto fail_UV_SetVolume;
4114 tst = AFSVolSetFlags(server, tid, setflag);
4116 goto fail_UV_SetVolume;
4127 etst = AFSVolEndTrans(server, tid, &rcode);
4128 /* FIXME: this looks like a typo */
4131 tst = (etst ? etst : rcode);