]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add skip-quiesce and ignore-quiesce-error options
authorMykola Golub <mgolub@suse.com>
Fri, 5 Jun 2020 13:23:26 +0000 (14:23 +0100)
committerMykola Golub <mgolub@suse.com>
Tue, 9 Jun 2020 12:41:17 +0000 (13:41 +0100)
to `snap create` and `mirror image snapshot` commands.

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/test/cli/rbd/help.t
src/tools/rbd/ArgumentTypes.cc
src/tools/rbd/ArgumentTypes.h
src/tools/rbd/Utils.cc
src/tools/rbd/Utils.h
src/tools/rbd/action/Device.cc
src/tools/rbd/action/MirrorImage.cc
src/tools/rbd/action/Snap.cc

index 18d40de6724363951488247bfbf6cc56b1788830..5cf761e7526f84a4c2c8da340bfaacc31286b9bd 100644 (file)
     --snap arg               snapshot name
     --read-only              map read-only
     --exclusive              disable automatic exclusive lock transitions
-    --quiesce                use quiesce callbacks
+    --quiesce                use quiesce hooks
     --quiesce-hook arg       quiesce hook path
     -o [ --options ] arg     device specific options
   
   
   rbd help mirror image snapshot
   usage: rbd mirror image snapshot [--pool <pool>] [--namespace <namespace>] 
-                                   [--image <image>] 
+                                   [--image <image>] [--skip-quiesce] 
+                                   [--ignore-quiesce-error] 
                                    <image-spec> 
   
   Create RBD mirroring image snapshot.
   
   Positional arguments
-    <image-spec>         image specification
-                         (example: [<pool-name>/[<namespace>/]]<image-name>)
+    <image-spec>            image specification
+                            (example: [<pool-name>/[<namespace>/]]<image-name>)
   
   Optional arguments
-    -p [ --pool ] arg    pool name
-    --namespace arg      namespace name
-    --image arg          image name
+    -p [ --pool ] arg       pool name
+    --namespace arg         namespace name
+    --image arg             image name
+    --skip-quiesce          do not run quiesce hooks
+    --ignore-quiesce-error  ignore quiesce hook error
   
   rbd help mirror image status
   usage: rbd mirror image status [--pool <pool>] [--namespace <namespace>] 
   
   rbd help snap create
   usage: rbd snap create [--pool <pool>] [--namespace <namespace>] 
-                         [--image <image>] [--snap <snap>] 
+                         [--image <image>] [--snap <snap>] [--skip-quiesce] 
+                         [--ignore-quiesce-error] [--no-progress] 
                          <snap-spec> 
   
   Create a snapshot.
   
   Positional arguments
-    <snap-spec>          snapshot specification
-                         (example:
-                         [<pool-name>/[<namespace>/]]<image-name>@<snapshot-name>)
+    <snap-spec>             snapshot specification
+                            (example:
+                            [<pool-name>/[<namespace>/]]<image-name>@<snapshot-nam
+                            e>)
   
   Optional arguments
-    -p [ --pool ] arg    pool name
-    --namespace arg      namespace name
-    --image arg          image name
-    --snap arg           snapshot name
+    -p [ --pool ] arg       pool name
+    --namespace arg         namespace name
+    --image arg             image name
+    --snap arg              snapshot name
+    --skip-quiesce          do not run quiesce hooks
+    --ignore-quiesce-error  ignore quiesce hook error
+    --no-progress           disable progress output
   
   rbd help snap limit clear
   usage: rbd snap limit clear [--pool <pool>] [--namespace <namespace>] 
index 74a460fcf1e81c08bf750e42199c2d558104e7d2..f9c1d7cd6e94d143d8f2dd2b417f7077544a707c 100644 (file)
@@ -321,6 +321,13 @@ void add_flatten_option(boost::program_options::options_description *opt) {
      "fill clone with parent data (make it independent)");
 }
 
+void add_snap_create_options(po::options_description *opt) {
+  opt->add_options()
+    (SKIP_QUIESCE.c_str(), po::bool_switch(), "do not run quiesce hooks")
+    (IGNORE_QUIESCE_ERROR.c_str(), po::bool_switch(),
+     "ignore quiesce hook error");
+}
+
 std::string get_short_features_help(bool append_suffix) {
   std::ostringstream oss;
   bool first_feature = true;
index 0554acceee967a8c3c398787ca5c28a5d998ebde..793f12bbdb08a7131bf98da24a072cbbacd46913 100644 (file)
@@ -83,8 +83,13 @@ static const std::string NO_ERROR("no-error");
 
 static const std::string LIMIT("limit");
 
+static const std::string SKIP_QUIESCE("skip-quiesce");
+static const std::string IGNORE_QUIESCE_ERROR("ignore-quiesce-error");
+
 static const std::set<std::string> SWITCH_ARGUMENTS = {
-  WHOLE_OBJECT, NO_PROGRESS, PRETTY_FORMAT, VERBOSE, NO_ERROR};
+  WHOLE_OBJECT, NO_PROGRESS, PRETTY_FORMAT, VERBOSE, NO_ERROR, SKIP_QUIESCE,
+  IGNORE_QUIESCE_ERROR
+};
 
 struct ImageSize {};
 struct ImageOrder {};
@@ -188,6 +193,8 @@ void add_no_error_option(boost::program_options::options_description *opt);
 
 void add_flatten_option(boost::program_options::options_description *opt);
 
+void add_snap_create_options(boost::program_options::options_description *opt);
+
 std::string get_short_features_help(bool append_suffix);
 std::string get_long_features_help();
 
index 7698dae9a634cc76d1ceed2a9765013b0e461c72..52c569f44feb6f7b462f1aab48a08df2b3f8d8de 100644 (file)
@@ -656,6 +656,24 @@ int get_formatter(const po::variables_map &vm,
   return 0;
 }
 
+int get_snap_create_flags(const po::variables_map &vm, uint32_t *flags) {
+  if (vm[at::SKIP_QUIESCE].as<bool>() &&
+      vm[at::IGNORE_QUIESCE_ERROR].as<bool>()) {
+    std::cerr << "rbd: " << at::IGNORE_QUIESCE_ERROR
+              << " cannot be used together with " << at::SKIP_QUIESCE
+              << std::endl;
+    return -EINVAL;
+  }
+
+  *flags = 0;
+  if (vm[at::SKIP_QUIESCE].as<bool>()) {
+    *flags |= RBD_SNAP_CREATE_SKIP_QUIESCE;
+  } else if (vm[at::IGNORE_QUIESCE_ERROR].as<bool>()) {
+    *flags |= RBD_SNAP_CREATE_IGNORE_QUIESCE_ERROR;
+  }
+  return 0;
+}
+
 void init_context() {
   g_conf().set_val_or_die("rbd_cache_writethrough_until_flush", "false");
   g_conf().apply_changes(nullptr);
index 14e46d5c47886ec8c06ce3e68135a78300990120..9450034061317d9e21307acf369812d4e6434527 100644 (file)
@@ -150,6 +150,9 @@ int get_path(const boost::program_options::variables_map &vm,
 int get_formatter(const boost::program_options::variables_map &vm,
                   argument_types::Format::Formatter *formatter);
 
+int get_snap_create_flags(const boost::program_options::variables_map &vm,
+                          uint32_t *flags);
+
 void init_context();
 
 int init_rados(librados::Rados *rados);
index 94864d04c63ee14808d29ca3411d17d635b27353..75988bd71c17bb62e846571a89b6fa36e131f415 100644 (file)
@@ -137,7 +137,7 @@ void get_map_arguments(po::options_description *positional,
   options->add_options()
     ("read-only", po::bool_switch(), "map read-only")
     ("exclusive", po::bool_switch(), "disable automatic exclusive lock transitions")
-    ("quiesce", po::bool_switch(), "use quiesce callbacks")
+    ("quiesce", po::bool_switch(), "use quiesce hooks")
     ("quiesce-hook", po::value<std::string>(), "quiesce hook path");
   add_device_specific_options(options);
 }
index 02fdbf3a7e0b72f92ee30294b6ab24657100337f..ab037b296e3060ae89c8b22509a190b8008243ad 100644 (file)
@@ -518,6 +518,12 @@ int execute_status(const po::variables_map &vm,
   return 0;
 }
 
+void get_snapshot_arguments(po::options_description *positional,
+                            po::options_description *options) {
+  at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+  at::add_snap_create_options(options);
+}
+
 int execute_snapshot(const po::variables_map &vm,
                      const std::vector<std::string> &ceph_global_init_args) {
   size_t arg_index = 0;
@@ -532,6 +538,12 @@ int execute_snapshot(const po::variables_map &vm,
     return r;
   }
 
+  uint32_t flags;
+  r = utils::get_snap_create_flags(vm, &flags);
+  if (r < 0) {
+    return r;
+  }
+
   librados::Rados rados;
   librados::IoCtx io_ctx;
   librbd::Image image;
@@ -547,7 +559,7 @@ int execute_snapshot(const po::variables_map &vm,
   }
 
   uint64_t snap_id;
-  r = image.mirror_image_create_snapshot(&snap_id);
+  r = image.mirror_image_create_snapshot2(flags, &snap_id);
   if (r < 0) {
     std::cerr << "rbd: error creating snapshot: " << cpp_strerror(r)
               << std::endl;
@@ -585,7 +597,7 @@ Shell::Action action_status(
 Shell::Action action_snapshot(
   {"mirror", "image", "snapshot"}, {},
   "Create RBD mirroring image snapshot.", "",
-  &get_arguments, &execute_snapshot);
+  &get_snapshot_arguments, &execute_snapshot);
 
 } // namespace mirror_image
 } // namespace action
index 03a4f5b065fa28c37dbb1eff6fc2124281a671c1..b2011ebae23f5636b0a67755b0354b68313b883f 100644 (file)
@@ -232,12 +232,18 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
   return 0;
 }
 
-int do_add_snap(librbd::Image& image, const char *snapname)
+int do_add_snap(librbd::Image& image, const char *snapname,
+                uint32_t flags, bool no_progress)
 {
-  int r = image.snap_create(snapname);
-  if (r < 0)
+  utils::ProgressContext pc("Creating snap", no_progress);
+  
+  int r = image.snap_create2(snapname, flags, pc);
+  if (r < 0) {
+    pc.fail();
     return r;
+  }
 
+  pc.finish();
   return 0;
 }
 
@@ -417,6 +423,8 @@ int execute_list(const po::variables_map &vm,
 void get_create_arguments(po::options_description *positional,
                           po::options_description *options) {
   at::add_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+  at::add_snap_create_options(options);
+  at::add_no_progress_option(options);
 }
 
 int execute_create(const po::variables_map &vm,
@@ -434,6 +442,12 @@ int execute_create(const po::variables_map &vm,
     return r;
   }
 
+  uint32_t flags;
+  r = utils::get_snap_create_flags(vm, &flags);
+  if (r < 0) {
+    return r;
+  }
+
   librados::Rados rados;
   librados::IoCtx io_ctx;
   librbd::Image image;
@@ -443,7 +457,8 @@ int execute_create(const po::variables_map &vm,
     return r;
   }
 
-  r = do_add_snap(image, snap_name.c_str());
+  r = do_add_snap(image, snap_name.c_str(), flags,
+                  vm[at::NO_PROGRESS].as<bool>());
   if (r < 0) {
     cerr << "rbd: failed to create snapshot: " << cpp_strerror(r)
          << std::endl;