]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add rbd_default_snapshot_quiesce_mode option
authorMykola Golub <mgolub@suse.com>
Fri, 5 Jun 2020 18:47:39 +0000 (19:47 +0100)
committerMykola Golub <mgolub@suse.com>
Tue, 9 Jun 2020 12:41:17 +0000 (13:41 +0100)
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/common/options.cc
src/librbd/Utils.cc
src/librbd/Utils.h
src/librbd/librbd.cc
src/librbd/mirror/EnableRequest.cc

index 495dc5273c136ffc552476d6ab76fa925ee2a4ff..e4a55aaada882df70ad9aca03e747ae9bfa4dffa 100644 (file)
@@ -7580,6 +7580,11 @@ static std::vector<Option> get_rbd_options() {
     .set_min(1)
     .set_description("the number of quiesce notification attempts"),
 
+    Option("rbd_default_snapshot_quiesce_mode", Option::TYPE_STR, Option::LEVEL_ADVANCED)
+    .set_default("required")
+    .set_enum_allowed({"required", "ignore-error", "skip"})
+    .set_description("default snapshot quiesce mode"),
+
     Option("rbd_plugins", Option::TYPE_STR, Option::LEVEL_ADVANCED)
     .set_default("")
     .set_description("comma-delimited list of librbd plugins to enable"),
index 4d3bde47acec6ce91f50cafaa4f82b14659cd803..044839c944620c9d108cf7ade69c3ce6e222a11d 100644 (file)
@@ -164,5 +164,20 @@ int snap_create_flags_api_to_internal(CephContext *cct, uint32_t api_flags,
   return 0;
 }
 
+uint32_t get_default_snap_create_flags(ImageCtx *ictx) {
+  auto mode = ictx->config.get_val<std::string>(
+      "rbd_default_snapshot_quiesce_mode");
+
+  if (mode == "required") {
+    return 0;
+  } else if (mode == "ignore-error") {
+    return RBD_SNAP_CREATE_IGNORE_QUIESCE_ERROR;
+  } else if (mode == "skip") {
+    return RBD_SNAP_CREATE_SKIP_QUIESCE;
+  } else {
+    ceph_abort_msg("invalid rbd_default_snapshot_quiesce_mode");
+  }
+}
+
 } // namespace util
 } // namespace librbd
index 9e95e692f70511a24510719a50a01f6ba58dc783..9c1d9a547f4a962beab05c9be91d0f37a7c534e8 100644 (file)
@@ -263,6 +263,8 @@ int create_ioctx(librados::IoCtx& src_io_ctx, const std::string& pool_desc,
 int snap_create_flags_api_to_internal(CephContext *cct, uint32_t api_flags,
                                       uint64_t *internal_flags);
 
+uint32_t get_default_snap_create_flags(ImageCtx *ictx);
+
 } // namespace util
 } // namespace librbd
 
index 8468a26dca92c1777a459031409aa27f87cc11d2..83722258971a794157f06d8904e9b3eccb6a6bce 100644 (file)
@@ -28,6 +28,7 @@
 #include "librbd/ImageState.h"
 #include "librbd/internal.h"
 #include "librbd/Operations.h"
+#include "librbd/Utils.h"
 #include "librbd/api/Config.h"
 #include "librbd/api/DiffIterate.h"
 #include "librbd/api/Group.h"
@@ -2180,8 +2181,9 @@ namespace librbd {
   {
     ImageCtx *ictx = (ImageCtx *)ctx;
     tracepoint(librbd, snap_create_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, snap_name);
+    auto flags = librbd::util::get_default_snap_create_flags(ictx);
     librbd::NoOpProgressContext prog_ctx;
-    int r = librbd::api::Snapshot<>::create(ictx, snap_name, 0, prog_ctx);
+    int r = librbd::api::Snapshot<>::create(ictx, snap_name, flags, prog_ctx);
     tracepoint(librbd, snap_create_exit, r);
     return r;
   }
@@ -2846,7 +2848,8 @@ namespace librbd {
   int Image::mirror_image_create_snapshot(uint64_t *snap_id)
   {
     ImageCtx *ictx = (ImageCtx *)ctx;
-    return librbd::api::Mirror<>::image_snapshot_create(ictx, 0, snap_id);
+    auto flags = librbd::util::get_default_snap_create_flags(ictx);
+    return librbd::api::Mirror<>::image_snapshot_create(ictx, flags, snap_id);
   }
 
   int Image::mirror_image_create_snapshot2(uint32_t flags, uint64_t *snap_id)
@@ -5237,8 +5240,9 @@ extern "C" int rbd_snap_create(rbd_image_t image, const char *snap_name)
 {
   librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
   tracepoint(librbd, snap_create_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, snap_name);
+  auto flags = librbd::util::get_default_snap_create_flags(ictx);
   librbd::NoOpProgressContext prog_ctx;
-  int r = librbd::api::Snapshot<>::create(ictx, snap_name, 0, prog_ctx);
+  int r = librbd::api::Snapshot<>::create(ictx, snap_name, flags, prog_ctx);
   tracepoint(librbd, snap_create_exit, r);
   return r;
 }
@@ -6335,7 +6339,8 @@ extern "C" int rbd_mirror_image_create_snapshot(rbd_image_t image,
                                                 uint64_t *snap_id)
 {
   librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
-  return librbd::api::Mirror<>::image_snapshot_create(ictx, 0, snap_id);
+  auto flags = librbd::util::get_default_snap_create_flags(ictx);
+  return librbd::api::Mirror<>::image_snapshot_create(ictx, flags, snap_id);
 }
 
 extern "C" int rbd_mirror_image_create_snapshot2(rbd_image_t image,
index 13b69c02328d454722926f221c844087771c45a1..8953a261e2eb45e18ddf13d62ca628c29f4a8e38 100644 (file)
@@ -186,13 +186,17 @@ void EnableRequest<I>::create_primary_snapshot() {
   ldout(m_cct, 10) << dendl;
 
   ceph_assert(m_image_ctx != nullptr);
+  uint64_t snap_create_flags;
+  int r = util::snap_create_flags_api_to_internal(
+      m_cct, util::get_default_snap_create_flags(m_image_ctx),
+      &snap_create_flags);
+  ceph_assert(r == 0);
   auto ctx = create_context_callback<
     EnableRequest<I>,
     &EnableRequest<I>::handle_create_primary_snapshot>(this);
   auto req = snapshot::CreatePrimaryRequest<I>::create(
     m_image_ctx, m_mirror_image.global_image_id,
-    (m_image_clean ? 0 : CEPH_NOSNAP),
-    SNAP_CREATE_FLAG_IGNORE_NOTIFY_QUIESCE_ERROR,
+    (m_image_clean ? 0 : CEPH_NOSNAP), snap_create_flags,
     snapshot::CREATE_PRIMARY_FLAG_IGNORE_EMPTY_PEERS, &m_snap_id, ctx);
   req->send();
 }