]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add --snap-id option to "rbd device map|unmap|attach|detach"
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Mon, 31 Oct 2022 06:23:10 +0000 (11:53 +0530)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 2 Dec 2022 14:34:59 +0000 (15:34 +0100)
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
(cherry picked from commit 614c91c0054f0ad81de268adf91ef32fd8905ad4)

doc/man/8/rbd.rst
src/test/cli/rbd/help.t
src/tools/rbd/action/Device.cc
src/tools/rbd/action/Nbd.cc
src/tools/rbd_nbd/rbd-nbd.cc

index 28ab9dcf9e129785a702281e94ddd70e37028d78..227cef16646cd6272c27ece847ba12eee8a83879 100644 (file)
@@ -258,7 +258,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*] [--cookie *device-cookie*] [--show-cookie] [--read-only] [--exclusive] [-o | --options *device-options*] *image-spec* | *snap-spec*
+:command:`device map` [-t | --device-type *device-type*] [--cookie *device-cookie*] [--show-cookie] [--snap-id *snap-id*] [--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).
@@ -266,14 +266,14 @@ Commands
   The --options argument is a comma separated list of device type
   specific options (opt1,opt2=val,...).
 
-:command:`device unmap` [-t | --device-type *device-type*] [-o | --options *device-options*] *image-spec* | *snap-spec* | *device-path*
+:command:`device unmap` [-t | --device-type *device-type*] [-o | --options *device-options*] [--snap-id *snap-id*] *image-spec* | *snap-spec* | *device-path*
   Unmap the block device that was mapped via the rbd kernel module
   (default) or other supported device.
 
   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* [--cookie *device-cookie*] [--show-cookie] [--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*] [--show-cookie] [--snap-id *snap-id*] [--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
@@ -282,7 +282,7 @@ Commands
   The --options argument is a comma separated list of device type
   specific options (opt1,opt2=val,...).
 
-:command:`device detach` [-t | --device-type *device-type*] [-o | --options *device-options*] *image-spec* | *snap-spec* | *device-path*
+:command:`device detach` [-t | --device-type *device-type*] [-o | --options *device-options*] [--snap-id *snap-id*] *image-spec* | *snap-spec* | *device-path*
   Detach the block device that was mapped or attached (currently only `nbd`
   on Linux). This operation is unsafe and should not be normally used.
 
index ddb72186c77bc5093cc6c69e3865a310d4d32e6e..e8b2c0db21d6f487cf6446230cba5f7f3c81c4c6 100644 (file)
                            [--snap <snap>] --device <device> [--show-cookie] 
                            [--cookie <cookie>] [--read-only] [--force] 
                            [--exclusive] [--quiesce] 
-                           [--quiesce-hook <quiesce-hook>] [--options <options>] 
+                           [--quiesce-hook <quiesce-hook>] [--snap-id <snap-id>] 
+                           [--options <options>] 
                            <image-or-snap-spec> 
   
   Attach image to device.
     --exclusive              disable automatic exclusive lock transitions
     --quiesce                use quiesce hooks
     --quiesce-hook arg       quiesce hook path
+    --snap-id arg            snapshot id
     -o [ --options ] arg     device specific options
   
   rbd help device detach
   usage: rbd device detach [--device-type <device-type>] [--pool <pool>] 
                            [--namespace <namespace>] [--image <image>] 
-                           [--snap <snap>] [--options <options>] 
+                           [--snap <snap>] [--snap-id <snap-id>] 
+                           [--options <options>] 
                            <image-or-snap-or-device-spec> 
   
   Detach image from device.
     --namespace arg                 namespace name
     --image arg                     image name
     --snap arg                      snapshot name
+    --snap-id arg                   snapshot id
     -o [ --options ] arg            device specific options
   
   rbd help device list
                         [--namespace <namespace>] [--image <image>] 
                         [--snap <snap>] [--show-cookie] [--cookie <cookie>] 
                         [--read-only] [--exclusive] [--quiesce] 
-                        [--quiesce-hook <quiesce-hook>] [--options <options>] 
+                        [--quiesce-hook <quiesce-hook>] [--snap-id <snap-id>] 
+                        [--options <options>] 
                         <image-or-snap-spec> 
   
   Map an image to a block device.
     --exclusive              disable automatic exclusive lock transitions
     --quiesce                use quiesce hooks
     --quiesce-hook arg       quiesce hook path
+    --snap-id arg            snapshot id
     -o [ --options ] arg     device specific options
   
   rbd help device unmap
   usage: rbd device unmap [--device-type <device-type>] [--pool <pool>] 
                           [--namespace <namespace>] [--image <image>] 
-                          [--snap <snap>] [--options <options>] 
+                          [--snap <snap>] [--snap-id <snap-id>] 
+                          [--options <options>] 
                           <image-or-snap-or-device-spec> 
   
   Unmap a rbd device.
     --namespace arg                 namespace name
     --image arg                     image name
     --snap arg                      snapshot name
+    --snap-id arg                   snapshot id
     -o [ --options ] arg            device specific options
   
   rbd help diff
index 022abef9011e97f98ad80a66aa3bcc88376385de..878081438377c651dee24442b17ab7ac4d433eb3 100644 (file)
@@ -181,6 +181,7 @@ void get_map_arguments(po::options_description *positional,
     ("exclusive", po::bool_switch(), "disable automatic exclusive lock transitions")
     ("quiesce", po::bool_switch(), "use quiesce hooks")
     ("quiesce-hook", po::value<std::string>(), "quiesce hook path");
+  at::add_snap_id_option(options);
   add_device_specific_options(options);
 }
 
@@ -200,6 +201,7 @@ void get_unmap_arguments(po::options_description *positional,
   at::add_namespace_option(options, at::ARGUMENT_MODIFIER_NONE);
   at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE);
   at::add_snap_option(options, at::ARGUMENT_MODIFIER_NONE);
+  at::add_snap_id_option(options);
   add_device_specific_options(options);
 }
 
@@ -222,6 +224,7 @@ void get_attach_arguments(po::options_description *positional,
     ("exclusive", po::bool_switch(), "disable automatic exclusive lock transitions")
     ("quiesce", po::bool_switch(), "use quiesce hooks")
     ("quiesce-hook", po::value<std::string>(), "quiesce hook path");
+  at::add_snap_id_option(options);
   add_device_specific_options(options);
 }
 
@@ -241,6 +244,7 @@ void get_detach_arguments(po::options_description *positional,
   at::add_namespace_option(options, at::ARGUMENT_MODIFIER_NONE);
   at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE);
   at::add_snap_option(options, at::ARGUMENT_MODIFIER_NONE);
+  at::add_snap_id_option(options);
   add_device_specific_options(options);
 }
 
index 061fdfa306a66c5df9f493079c18e02ce53a12db..dd5ef3290cfd6300d660e19faaf48953dc8f0d6e 100644 (file)
@@ -122,6 +122,11 @@ int execute_attach(const po::variables_map &vm,
     return -EINVAL;
   }
 
+  if (vm.count(at::SNAPSHOT_ID)) {
+    args.push_back("--snap-id");
+    args.push_back(std::to_string(vm[at::SNAPSHOT_ID].as<uint64_t>()));
+  }
+
   if (vm["quiesce"].as<bool>()) {
     args.push_back("--quiesce");
   }
@@ -159,23 +164,28 @@ int execute_detach(const po::variables_map &vm,
     device_name.clear();
   }
 
+  std::vector<std::string> args;
+
+  args.push_back("detach");
   std::string image_name;
   if (device_name.empty()) {
     int r = utils::get_image_or_snap_spec(vm, &image_name);
     if (r < 0) {
       return r;
     }
-  }
 
-  if (device_name.empty() && image_name.empty()) {
-    std::cerr << "rbd: detach requires either image name or device path"
-              << std::endl;
-    return -EINVAL;
-  }
+    if (image_name.empty()) {
+      std::cerr << "rbd: detach requires either image name or device path"
+                << std::endl;
+      return -EINVAL;
+    }
 
-  std::vector<std::string> args;
+    if (vm.count(at::SNAPSHOT_ID)) {
+      args.push_back("--snap-id");
+      args.push_back(std::to_string(vm[at::SNAPSHOT_ID].as<uint64_t>()));
+    }
+  }
 
-  args.push_back("detach");
   args.push_back(device_name.empty() ? image_name : device_name);
 
   if (vm.count("options")) {
@@ -216,6 +226,11 @@ int execute_map(const po::variables_map &vm,
     args.push_back(vm["cookie"].as<std::string>());
   }
 
+  if (vm.count(at::SNAPSHOT_ID)) {
+    args.push_back("--snap-id");
+    args.push_back(std::to_string(vm[at::SNAPSHOT_ID].as<uint64_t>()));
+  }
+
   if (vm["read-only"].as<bool>()) {
     args.push_back("--read-only");
   }
@@ -249,23 +264,28 @@ int execute_unmap(const po::variables_map &vm,
     device_name.clear();
   }
 
+  std::vector<std::string> args;
+
+  args.push_back("unmap");
   std::string image_name;
   if (device_name.empty()) {
     int r = utils::get_image_or_snap_spec(vm, &image_name);
     if (r < 0) {
       return r;
     }
-  }
 
-  if (device_name.empty() && image_name.empty()) {
-    std::cerr << "rbd: unmap requires either image name or device path"
-              << std::endl;
-    return -EINVAL;
-  }
+    if (image_name.empty()) {
+      std::cerr << "rbd: unmap requires either image name or device path"
+                << std::endl;
+      return -EINVAL;
+    }
 
-  std::vector<std::string> args;
+    if (vm.count(at::SNAPSHOT_ID)) {
+      args.push_back("--snap-id");
+      args.push_back(std::to_string(vm[at::SNAPSHOT_ID].as<uint64_t>()));
+    }
+  }
 
-  args.push_back("unmap");
   args.push_back(device_name.empty() ? image_name : device_name);
 
   if (vm.count("options")) {
index 80eeff564d4076e73a9f08fbbe1b1108d13073a5..55ef9d1595d299105b799ec2070912e4e012ddd0 100644 (file)
@@ -2227,6 +2227,11 @@ static int parse_args(vector<const char*>& args, std::ostream *err_msg,
       break;
   }
 
+  if (cfg->snapid != CEPH_NOSNAP && !cfg->snapname.empty()) {
+    *err_msg << "rbd-nbd: use either snapname or snapid, not both";
+    return -EINVAL;
+  }
+
   if (args.begin() != args.end()) {
     *err_msg << "rbd-nbd: unknown args: " << *args.begin();
     return -EINVAL;