]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
vol: allow non-dafs volume utils to attach with V_READONLY again
authorMichael Meffie <mmeffie@sinenomine.net>
Tue, 30 Oct 2012 14:22:40 +0000 (10:22 -0400)
committerKen Dreyer <ktdreyer@ktdreyer.com>
Tue, 20 Nov 2012 02:43:25 +0000 (18:43 -0800)
Allow non-fileserver, non-dafs, programs to attach volumes with the
V_READONLY mode again. This was lost during the code changes for
dafs.

The caller sends a fssync request to the fileserver, which updates the
on-disk contents of the volume headers, before the caller reads the
volume headers, allowing the caller to have the most recent info about
the volume. The fileserver still has the volume in use.

Later in the attachment process, the inUse check is skipped for the case
of a non-fileserver process which is attaching the volume using the
V_READONLY mode, otherwise the attachment would incorrectly mark the
volume as needing to be salvaged.

Note: The mode checks in VMustCheckOutVolume() are correct. We must
checkout the volume when attaching with the V_READONLY mode. This
fix updates the VShouldCheckInUse(), in which an additional
exception was added to cover the case for V_READONLY mode from a non-
fileserver process.

Note: A check is added in the dafs version of attach to avoid overwriting the
inUse field when a volume utility is attaching a volume in V_READONLY mode.
Currently, V_READONLY is not used by dafs, but this was done to avoid future
errors.

Reviewed-on: http://gerrit.openafs.org/8339
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
(cherry picked from commit 0eaa0d1baa8b8fe115301f188ce32176acc7b065)

Change-Id: I584027e2104fd4928b16b591a2ab9e2613e49ec7
Reviewed-on: http://gerrit.openafs.org/8458
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
src/vol/volume.c
src/vol/volume_inline.h

index e11e6c4d124e3eeb81e56ecc02249ef7cc8bab0c..c8884db1365fa1d4986a7528f8831a51511a32a4 100644 (file)
@@ -3442,7 +3442,7 @@ attach2(Error * ec, VolId volumeId, char *path, struct DiskPartition64 *partp,
        }
     } else {
 #ifdef AFS_DEMAND_ATTACH_FS
-       if ((mode != V_PEEK) && (mode != V_SECRETLY))
+       if ((mode != V_PEEK) && (mode != V_SECRETLY) && (mode != V_READONLY))
            V_inUse(vp) = programType;
 #endif /* AFS_DEMAND_ATTACH_FS */
        V_checkoutMode(vp) = mode;
index 571f3084b2d4aa369eed757e8320b32f12c2674e..c6df3a510436b533f9201062b1460fc6544640bc 100644 (file)
@@ -125,8 +125,8 @@ VMustCheckoutVolume(int mode)
  * (or put it in an error state) if we detect that another program
  * claims to be using the volume when we try to attach. We don't always
  * want to do that, since sometimes we know that the volume may be in
- * use by another program, e.g. when we are attaching with V_PEEK, and
- * we don't care.
+ * use by another program, e.g. when we are attaching with V_PEEK
+ * or attaching for only reading (V_READONLY).
  *
  * @param mode  the mode of attachment for the volume
  *
@@ -144,9 +144,24 @@ VShouldCheckInUse(int mode)
        return 1;
     }
     if (VMustCheckoutVolume(mode)) {
-       /* assume we checked out the volume from the fileserver, so inUse
-        * should not be set */
-       return 1;
+       /*
+        * Before VShouldCheckInUse() was called, the caller checked out the
+        * volume from the fileserver. The volume may not be in use by the
+        * fileserver, or another program, at this point. The caller should
+        * verify by checking inUse is not set, otherwise the volume state
+        * is in error.
+        *
+        * However, an exception is made for the V_READONLY attach mode.  The
+        * volume may still be in use by the fileserver when a caller has
+        * checked out the volume from the fileserver with the V_READONLY
+        * attach mode, and so it is not an error for the inUse field to be set
+        * at this point. The caller should not check the inUse and may
+        * not change any volume state.
+        */
+       if (mode == V_READONLY) {
+           return 0; /* allowed to be inUse; do not check */
+       }
+       return 1; /* may not be inUse; check */
     }
     return 0;
 }