]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: make common options override krbd-specific options 37407/head
authorIlya Dryomov <idryomov@gmail.com>
Fri, 25 Sep 2020 07:55:04 +0000 (09:55 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 25 Sep 2020 07:55:04 +0000 (09:55 +0200)
ceph-csi has added support for passing custom map and unmap options via
mapOptions and unmapOptions storage class parameters.  However, it also
uses --read-only for implementing ROX (ReadOnlyMany) PVs.  If the user
supplies "mapOptions: rw", they will get around the intended read-only
restriction (at least on the block device).

ceph-csi could be patched to use "-o ro", but it actually makes sense
for common options to win over device type-specific equivalents.

Fixes: https://tracker.ceph.com/issues/47625
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit a107c47360ecdb8c09768ca9eab2341100245711)

Conflicts:
src/tools/rbd/action/Kernel.cc [ snapshot quiesce support and
  commit 34f539d8af33 ("rbd: delay parsing of default kernel map
  options") not in nautilus ]

doc/man/8/rbd.rst
qa/rbd/krbd_blkroset.t
src/tools/rbd/action/Kernel.cc

index 8ae247f77fb0d905012607018b213848334b705c..a3222661b930702858d5c7e350c42d9bdeae1f78 100644 (file)
@@ -734,7 +734,7 @@ Per client instance `rbd device map` options:
 
 Per mapping (block device) `rbd device map` options:
 
-* rw - Map the image read-write (default).
+* rw - Map the image read-write (default).  Overridden by --read-only.
 
 * ro - Map the image read-only.  Equivalent to --read-only.
 
@@ -744,6 +744,7 @@ Per mapping (block device) `rbd device map` options:
   discards (since 4.9).
 
 * exclusive - Disable automatic exclusive lock transitions (since 4.12).
+  Equivalent to --exclusive.
 
 * lock_timeout=x - A timeout on waiting for the acquisition of exclusive lock
   (since 4.17, default is 0 seconds, meaning no timeout).
index cbbd06ce2aef5040fbd5427b8c18049be17b89bb..bbbd26aac53b96563c5e1df0e3bdd2d91b73c710 100644 (file)
@@ -343,6 +343,15 @@ rw -> ro with open_count > 0
   $ sudo rbd unmap $DEV
 
 
+"-o rw --read-only" should result in read-only mapping
+======================================================
+
+  $ DEV=$(sudo rbd map -o rw --read-only img)
+  $ blockdev --getro $DEV
+  1
+  $ sudo rbd unmap $DEV
+
+
 Teardown
 ========
 
index bac0bda10f1651f7888c6a4111d8d88bcefd97fe..91eb184bef7ff3b113a37c86fca7a5dd639022bf 100644 (file)
@@ -452,13 +452,6 @@ int execute_map(const po::variables_map &vm,
     return r;
   }
 
-  if (vm["read-only"].as<bool>()) {
-    put_map_option("rw", "ro");
-  }
-  if (vm["exclusive"].as<bool>()) {
-    put_map_option("exclusive", "exclusive");
-  }
-
   // parse default options first so they can be overwritten by cli options
   r = parse_map_options(
       g_conf().get_val<std::string>("rbd_default_map_options"));
@@ -477,6 +470,16 @@ int execute_map(const po::variables_map &vm,
     }
   }
 
+  // parse options common to all device types after parsing krbd-specific
+  // options so that common options win (in particular "-o rw --read-only"
+  // should result in read-only mapping)
+  if (vm["read-only"].as<bool>()) {
+    put_map_option("rw", "ro");
+  }
+  if (vm["exclusive"].as<bool>()) {
+    put_map_option("exclusive", "exclusive");
+  }
+
   utils::init_context();
 
   r = do_kernel_map(pool_name.c_str(), nspace_name.c_str(), image_name.c_str(),