From: Prasanna Kumar Kalever Date: Fri, 18 Jun 2021 06:48:35 +0000 (+0530) Subject: rbd: add --show-cookie/--cookie option for map/attach commands X-Git-Tag: v16.2.8~69^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3884f42d7438e13103fbb0b15e8a9ab99ad908c0;p=ceph.git rbd: add --show-cookie/--cookie option for map/attach commands Example: $ rbd device map rbd-pool/image --show-cookie --try-netlink --device-type nbd $ rbd device attach rbd-pool/image --device /dev/nbd0 \ --cookie 6f85d970-10b2-456b-8baf-676aa4d782e4 --device-type nbd older Kernel versions can use --force to skip the cookie validation Signed-off-by: Prasanna Kumar Kalever (cherry picked from commit 6df06c7a62bdd6e9ce61b26c738dcd1509e68273) Conflicts: src/tools/rbd/action/Device.cc [ commit e1b4811bc324 ("rbd: add missing switch arguments for recognition by get_command_spec()") already in pacific -- re-add show-cookie ] --- diff --git a/doc/man/8/rbd.rst b/doc/man/8/rbd.rst index c4ae2507ef6b..5010d535cd3e 100644 --- a/doc/man/8/rbd.rst +++ b/doc/man/8/rbd.rst @@ -253,7 +253,7 @@ Commands Show the rbd images that are mapped via the rbd kernel module (default) or other supported device. -:command:`device map` [-t | --device-type *device-type*] [--read-only] [--exclusive] [-o | --options *device-options*] *image-spec* | *snap-spec* +:command:`device map` [-t | --device-type *device-type*] [--show-cookie] [--read-only] [--exclusive] [-o | --options *device-options*] *image-spec* | *snap-spec* Map the specified image to a block device via the rbd kernel module (default) or other supported device (*nbd* on Linux or *ggate* on FreeBSD). @@ -268,7 +268,7 @@ Commands The --options argument is a comma separated list of device type specific options (opt1,opt2=val,...). -:command:`device attach` [-t | --device-type *device-type*] --device *device-path* [--read-only] [--exclusive] [--force] [-o | --options *device-options*] *image-spec* | *snap-spec* +:command:`device attach` [-t | --device-type *device-type*] --device *device-path* [--cookie *device-cookie*] [--read-only] [--exclusive] [--force] [-o | --options *device-options*] *image-spec* | *snap-spec* Attach the specified image to the specified block device (currently only `nbd` on Linux). This operation is unsafe and should not be normally used. In particular, specifying the wrong image or the wrong block device may diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index c2ce02e48841..fb419da45fa9 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -575,8 +575,8 @@ rbd help device attach usage: rbd device attach [--device-type ] [--pool ] [--namespace ] [--image ] - [--snap ] --device [--read-only] - [--force] [--exclusive] [--quiesce] + [--snap ] --device [--cookie ] + [--read-only] [--force] [--exclusive] [--quiesce] [--quiesce-hook ] [--options ] @@ -595,6 +595,7 @@ --image arg image name --snap arg snapshot name --device arg specify device path + --cookie arg specify device cookie --read-only attach read-only --force force attach --exclusive disable automatic exclusive lock transitions @@ -636,7 +637,8 @@ rbd help device map usage: rbd device map [--device-type ] [--pool ] [--namespace ] [--image ] - [--snap ] [--read-only] [--exclusive] [--quiesce] + [--snap ] [--show-cookie] [--read-only] + [--exclusive] [--quiesce] [--quiesce-hook ] [--options ] @@ -654,6 +656,7 @@ --namespace arg namespace name --image arg image name --snap arg snapshot name + --show-cookie show device cookie --read-only map read-only --exclusive disable automatic exclusive lock transitions --quiesce use quiesce hooks diff --git a/src/tools/rbd/action/Device.cc b/src/tools/rbd/action/Device.cc index 17d286421d30..99746e0f4951 100644 --- a/src/tools/rbd/action/Device.cc +++ b/src/tools/rbd/action/Device.cc @@ -175,6 +175,7 @@ void get_map_arguments(po::options_description *positional, at::add_image_or_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE); options->add_options() + ("show-cookie", po::bool_switch(), "show device cookie") ("read-only", po::bool_switch(), "map read-only") ("exclusive", po::bool_switch(), "disable automatic exclusive lock transitions") ("quiesce", po::bool_switch(), "use quiesce hooks") @@ -212,6 +213,7 @@ void get_attach_arguments(po::options_description *positional, at::ARGUMENT_MODIFIER_NONE); options->add_options() ("device", po::value()->required(), "specify device path") + ("cookie", po::value(), "specify device cookie") ("read-only", po::bool_switch(), "attach read-only") ("force", po::bool_switch(), "force attach") ("exclusive", po::bool_switch(), "disable automatic exclusive lock transitions") @@ -244,7 +246,7 @@ int execute_detach(const po::variables_map &vm, } Shell::SwitchArguments switched_arguments({"exclusive", "force", "quiesce", - "read-only"}); + "read-only", "show-cookie"}); Shell::Action action_list( {"device", "list"}, {"showmapped"}, "List mapped rbd images.", "", diff --git a/src/tools/rbd/action/Nbd.cc b/src/tools/rbd/action/Nbd.cc index c029d4b0feac..b6662e0842e5 100644 --- a/src/tools/rbd/action/Nbd.cc +++ b/src/tools/rbd/action/Nbd.cc @@ -163,10 +163,13 @@ int execute_attach(const po::variables_map &vm, return -EINVAL; } - if (!vm["force"].as()) { + if (vm.count("cookie")) { + args.push_back("--cookie"); + args.push_back(vm["cookie"].as()); + } else if (!vm["force"].as()) { std::cerr << "rbd: could not validate attach request\n"; std::cerr << "rbd: mismatching the image and the device may lead to data corruption\n"; - std::cerr << "rbd: must specify --force to proceed" << std::endl; + std::cerr << "rbd: must specify --cookie or --force to proceed" << std::endl; return -EINVAL; } @@ -259,6 +262,10 @@ int execute_map(const po::variables_map &vm, args.push_back("--quiesce"); } + if (vm["show-cookie"].as()) { + args.push_back("--show-cookie"); + } + if (vm["read-only"].as()) { args.push_back("--read-only"); }