]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add --show-cookie/--cookie option for map/attach commands
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Fri, 18 Jun 2021 06:48:35 +0000 (12:18 +0530)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Tue, 26 Oct 2021 13:54:13 +0000 (19:24 +0530)
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 <prasanna.kalever@redhat.com>
doc/man/8/rbd.rst
src/test/cli/rbd/help.t
src/tools/rbd/action/Device.cc
src/tools/rbd/action/Nbd.cc

index 7c61d0a5dd7a20c04765c429dd2bca5f957c45d6..b5d4e3d1ce69072b8377476c59542c6d21e81e06 100644 (file)
@@ -255,7 +255,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).
@@ -270,7 +270,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
index 22362eb806a1ed0cae38781f2ba35a6a38a06b19..7f3622b4fa03e6952662c6370918319d979babb2 100644 (file)
   rbd help device attach
   usage: rbd device attach [--device-type <device-type>] [--pool <pool>] 
                            [--namespace <namespace>] [--image <image>] 
-                           [--snap <snap>] --device <device> [--read-only
-                           [--force] [--exclusive] [--quiesce] 
+                           [--snap <snap>] --device <device> [--cookie <cookie>
+                           [--read-only] [--force] [--exclusive] [--quiesce] 
                            [--quiesce-hook <quiesce-hook>] [--options <options>] 
                            <image-or-snap-spec> 
   
     --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
   rbd help device map
   usage: rbd device map [--device-type <device-type>] [--pool <pool>] 
                         [--namespace <namespace>] [--image <image>] 
-                        [--snap <snap>] [--read-only] [--exclusive] [--quiesce] 
+                        [--snap <snap>] [--show-cookie] [--read-only] 
+                        [--exclusive] [--quiesce] 
                         [--quiesce-hook <quiesce-hook>] [--options <options>] 
                         <image-or-snap-spec> 
   
     --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
index a9903cfa78c4766adfcc4d33402a84c1248abc7d..350213449551aeae1793702e269a64468b78f0b1 100644 (file)
@@ -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<std::string>()->required(), "specify device path")
+    ("cookie", po::value<std::string>(), "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")
index 117a2592dd1e86aac073bec8a21bce63c4acefd7..fe9a737f9603fc732f55cac237e56b99e92d9f00 100644 (file)
@@ -163,10 +163,13 @@ int execute_attach(const po::variables_map &vm,
     return -EINVAL;
   }
 
-  if (!vm["force"].as<bool>()) {
+  if (vm.count("cookie")) {
+    args.push_back("--cookie");
+    args.push_back(vm["cookie"].as<std::string>());
+  } else if (!vm["force"].as<bool>()) {
     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 <arg> 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<bool>()) {
+    args.push_back("--show-cookie");
+  }
+
   if (vm["read-only"].as<bool>()) {
     args.push_back("--read-only");
   }