]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: allow to specify mode on mirror image enable
authorMykola Golub <mgolub@suse.com>
Thu, 12 Dec 2019 14:38:26 +0000 (14:38 +0000)
committerMykola Golub <mgolub@suse.com>
Mon, 16 Dec 2019 08:24:30 +0000 (08:24 +0000)
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/test/cli/rbd/help.t
src/tools/rbd/action/MirrorImage.cc

index 7262ffa88f73ed4707779f6789b7f8a9e564983e..55edf51ac71e699c94343ca7ff04021d0f712fdd 100644 (file)
   rbd help mirror image enable
   usage: rbd mirror image enable [--pool <pool>] [--namespace <namespace>] 
                                  [--image <image>] 
-                                 <image-spec> 
+                                 <image-spec> <mode> 
   
   Enable RBD mirroring for an image.
   
   Positional arguments
     <image-spec>         image specification
                          (example: [<pool-name>/[<namespace>/]]<image-name>)
+    <mode>               mirror image mode (journal or snapshot) [default:
+                         journal]
   
   Optional arguments
     -p [ --pool ] arg    pool name
index e40b4e1ed8f5cc07ca9ede121e6da698f267b0fd..606009e2cdd2ad3152df94d75c0abb24aabf629c 100644 (file)
@@ -73,6 +73,13 @@ void get_arguments(po::options_description *positional,
   at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
 }
 
+void get_arguments_enable(po::options_description *positional,
+                          po::options_description *options) {
+  at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+  positional->add_options()
+    ("mode", "mirror image mode (journal or snapshot) [default: journal]");
+}
+
 void get_arguments_disable(po::options_description *positional,
                            po::options_description *options) {
   options->add_options()
@@ -104,7 +111,21 @@ int execute_enable_disable(const po::variables_map &vm, bool enable,
     return r;
   }
 
-  r = enable ? image.mirror_image_enable() : image.mirror_image_disable(force);
+  if (enable) {
+    librbd::mirror_image_mode_t mode = RBD_MIRROR_IMAGE_MODE_JOURNAL;
+    std::string mode_arg = utils::get_positional_argument(vm, arg_index++);
+    if (mode_arg == "journal") {
+      mode = RBD_MIRROR_IMAGE_MODE_JOURNAL;
+    } else if (mode_arg == "snapshot") {
+      mode = RBD_MIRROR_IMAGE_MODE_SNAPSHOT;
+    } else if (!mode_arg.empty()) {
+      std::cerr << "rbd: invalid mode name: " << mode_arg << std::endl;
+      return -EINVAL;
+    }
+    r = image.mirror_image_enable2(mode);
+  } else {
+    r = image.mirror_image_disable(force);
+  }
   if (r < 0) {
     return r;
   }
@@ -529,7 +550,7 @@ int execute_snapshot(const po::variables_map &vm,
 Shell::Action action_enable(
   {"mirror", "image", "enable"}, {},
   "Enable RBD mirroring for an image.", "",
-  &get_arguments, &execute_enable);
+  &get_arguments_enable, &execute_enable);
 Shell::Action action_disable(
   {"mirror", "image", "disable"}, {},
   "Disable RBD mirroring for an image.", "",