]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add mirror image promote/demote/resync commands
authorJason Dillaman <dillaman@redhat.com>
Tue, 15 Mar 2016 18:10:46 +0000 (14:10 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 16 Mar 2016 00:14:45 +0000 (20:14 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd/action/MirrorImage.cc

index 331356adb66913a816626a1cf36e669ec9dcb629..d3a322cf8aed0fded333ef164e1b6c6b2e84d832 100644 (file)
@@ -85,6 +85,108 @@ int execute_enable(const po::variables_map &vm) {
   return execute_enable_disable(vm, true, false);
 }
 
+void get_arguments_promote(po::options_description *positional,
+                           po::options_description *options) {
+  options->add_options()
+    ("force", po::bool_switch(), "promote even if not cleanly demoted by remote cluster");
+  at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+}
+
+int execute_promote(const po::variables_map &vm) {
+  size_t arg_index = 0;
+  std::string pool_name;
+  std::string image_name;
+  std::string snap_name;
+  int r = utils::get_pool_image_snapshot_names(
+      vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &image_name,
+      &snap_name, utils::SNAPSHOT_PRESENCE_NONE);
+  if (r < 0) {
+    return r;
+  }
+
+  bool force = vm["force"].as<bool>();
+
+  librados::Rados rados;
+  librados::IoCtx io_ctx;
+  librbd::Image image;
+  r = utils::init_and_open_image(pool_name, image_name, "", false,
+                                 &rados, &io_ctx, &image);
+  if (r < 0) {
+    return r;
+  }
+
+  r = image.mirror_image_promote(force);
+  if (r < 0) {
+    std::cerr << "rbd: error promoting image to primary" << std::endl;
+    return r;
+  }
+
+  std::cout << "" << std::endl;
+  return 0;
+}
+
+int execute_demote(const po::variables_map &vm) {
+  size_t arg_index = 0;
+  std::string pool_name;
+  std::string image_name;
+  std::string snap_name;
+  int r = utils::get_pool_image_snapshot_names(
+      vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &image_name,
+      &snap_name, utils::SNAPSHOT_PRESENCE_NONE);
+  if (r < 0) {
+    return r;
+  }
+
+  librados::Rados rados;
+  librados::IoCtx io_ctx;
+  librbd::Image image;
+  r = utils::init_and_open_image(pool_name, image_name, "", false,
+                                 &rados, &io_ctx, &image);
+  if (r < 0) {
+    return r;
+  }
+
+  r = image.mirror_image_demote();
+  if (r < 0) {
+    std::cerr << "rbd: error demoting image to secondary" << std::endl;
+    return r;
+  }
+
+  std::cout << "Image demoted to secondary" << std::endl;
+  return 0;
+}
+
+int execute_resync(const po::variables_map &vm) {
+  size_t arg_index = 0;
+  std::string pool_name;
+  std::string image_name;
+  std::string snap_name;
+  int r = utils::get_pool_image_snapshot_names(
+      vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &image_name,
+      &snap_name, utils::SNAPSHOT_PRESENCE_NONE);
+  if (r < 0) {
+    return r;
+  }
+
+  librados::Rados rados;
+  librados::IoCtx io_ctx;
+  librbd::Image image;
+  r = utils::init_and_open_image(pool_name, image_name, "", false,
+                                 &rados, &io_ctx, &image);
+  if (r < 0) {
+    return r;
+  }
+
+  r = image.mirror_image_resync();
+  if (r < 0) {
+    std::cerr << "rbd: error flagging image resync" << std::endl;
+    return r;
+  }
+
+  std::cout << "Flagged image for resync from primary" << std::endl;
+  return 0;
+}
+
 Shell::Action action_enable(
   {"mirror", "image", "enable"}, {},
   "Enable RBD mirroring for an image.", "",
@@ -93,6 +195,18 @@ Shell::Action action_disable(
   {"mirror", "image", "disable"}, {},
   "Disable RBD mirroring for an image.", "",
   &get_arguments_disable, &execute_disable);
+Shell::Action action_promote(
+  {"mirror", "image", "promote"}, {},
+  "Promote an image to primary for RBD mirroring.", "",
+  &get_arguments_promote, &execute_promote);
+Shell::Action action_demote(
+  {"mirror", "image", "demote"}, {},
+  "Demote an image to secondary for RBD mirroring.", "",
+  &get_arguments, &execute_demote);
+Shell::Action action_resync(
+  {"mirror", "image", "resync"}, {},
+  "Force resync to primary image for RBD mirroring.", "",
+  &get_arguments, &execute_resync);
 
 } // namespace mirror_image
 } // namespace action