From: Ilya Dryomov Date: Fri, 25 Sep 2020 07:55:04 +0000 (+0200) Subject: rbd: make common options override krbd-specific options X-Git-Tag: v14.2.12~58^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e3288f74b004d148496b97e9bd8bdd6e3c3c3d3b;p=ceph.git rbd: make common options override krbd-specific options 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 (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 ] --- diff --git a/doc/man/8/rbd.rst b/doc/man/8/rbd.rst index 8ae247f77fb0d..a3222661b9307 100644 --- a/doc/man/8/rbd.rst +++ b/doc/man/8/rbd.rst @@ -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). diff --git a/qa/rbd/krbd_blkroset.t b/qa/rbd/krbd_blkroset.t index cbbd06ce2aef5..bbbd26aac53b9 100644 --- a/qa/rbd/krbd_blkroset.t +++ b/qa/rbd/krbd_blkroset.t @@ -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 ======== diff --git a/src/tools/rbd/action/Kernel.cc b/src/tools/rbd/action/Kernel.cc index bac0bda10f165..91eb184bef7ff 100644 --- a/src/tools/rbd/action/Kernel.cc +++ b/src/tools/rbd/action/Kernel.cc @@ -452,13 +452,6 @@ int execute_map(const po::variables_map &vm, return r; } - if (vm["read-only"].as()) { - put_map_option("rw", "ro"); - } - if (vm["exclusive"].as()) { - 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("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()) { + put_map_option("rw", "ro"); + } + if (vm["exclusive"].as()) { + put_map_option("exclusive", "exclusive"); + } + utils::init_context(); r = do_kernel_map(pool_name.c_str(), nspace_name.c_str(), image_name.c_str(),