]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: rbd-mirroring: Added mirror image enable/disable commands to RBD CLI
authorRicardo Dias <rdias@suse.com>
Thu, 10 Mar 2016 13:36:06 +0000 (13:36 +0000)
committerRicardo Dias <rdias@suse.com>
Mon, 14 Mar 2016 17:56:38 +0000 (17:56 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/CMakeLists.txt
src/tools/Makefile-client.am
src/tools/rbd/action/MirrorImage.cc [new file with mode: 0644]

index 1fd3c935efb122ea00b7ecc09235e837d418e85a..06cca427c9838c3ff74b787e2e67e23ef3216e1a 100644 (file)
@@ -1092,6 +1092,7 @@ if(${WITH_RBD})
     tools/rbd/action/Lock.cc
     tools/rbd/action/MergeDiff.cc
     tools/rbd/action/MirrorPool.cc
+    tools/rbd/action/MirrorImage.cc
     tools/rbd/action/Nbd.cc
     tools/rbd/action/ObjectMap.cc
     tools/rbd/action/Remove.cc
index 2a1f994a5a29db077a6e7d8d221ff8a25135b18d..c970e266ee0656780b47c3ccb22676efbbc14af4 100644 (file)
@@ -50,6 +50,7 @@ rbd_SOURCES = \
        tools/rbd/action/Lock.cc \
        tools/rbd/action/MergeDiff.cc \
        tools/rbd/action/MirrorPool.cc \
+       tools/rbd/action/MirrorImage.cc \
        tools/rbd/action/ObjectMap.cc \
        tools/rbd/action/Remove.cc \
        tools/rbd/action/Rename.cc \
diff --git a/src/tools/rbd/action/MirrorImage.cc b/src/tools/rbd/action/MirrorImage.cc
new file mode 100644 (file)
index 0000000..331356a
--- /dev/null
@@ -0,0 +1,99 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 SUSE LINUX GmbH
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+#include "tools/rbd/ArgumentTypes.h"
+#include "tools/rbd/Shell.h"
+#include "tools/rbd/Utils.h"
+#include "include/stringify.h"
+#include "common/config.h"
+#include "common/errno.h"
+#include "common/Formatter.h"
+#include "common/TextTable.h"
+#include "global/global_context.h"
+#include <iostream>
+#include <boost/program_options.hpp>
+#include <boost/regex.hpp>
+
+namespace rbd {
+namespace action {
+namespace mirror_image {
+
+namespace at = argument_types;
+namespace po = boost::program_options;
+
+
+void get_arguments(po::options_description *positional,
+                           po::options_description *options) {
+  at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+}
+
+void get_arguments_disable(po::options_description *positional,
+                           po::options_description *options) {
+  options->add_options()
+    ("force", po::bool_switch(), "disable even if not primary");
+  at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+}
+
+int execute_enable_disable(const po::variables_map &vm, bool enable,
+                           bool force) {
+  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 = enable ? image.mirror_image_enable() : image.mirror_image_disable(force);
+  if (r < 0) {
+    return r;
+  }
+
+  std::cout << (enable ? "Mirroring enabled" : "Mirroring disabled")
+    << std::endl;
+
+  return 0;
+}
+
+int execute_disable(const po::variables_map &vm) {
+  return execute_enable_disable(vm, false, vm["force"].as<bool>());
+}
+
+int execute_enable(const po::variables_map &vm) {
+  return execute_enable_disable(vm, true, false);
+}
+
+Shell::Action action_enable(
+  {"mirror", "image", "enable"}, {},
+  "Enable RBD mirroring for an image.", "",
+  &get_arguments, &execute_enable);
+Shell::Action action_disable(
+  {"mirror", "image", "disable"}, {},
+  "Disable RBD mirroring for an image.", "",
+  &get_arguments_disable, &execute_disable);
+
+} // namespace mirror_image
+} // namespace action
+} // namespace rbd