]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use pool config overrides for clone state machine
authorJason Dillaman <dillaman@redhat.com>
Mon, 8 Oct 2018 15:18:37 +0000 (11:18 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 8 Oct 2018 17:56:58 +0000 (13:56 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/api/Image.cc
src/librbd/api/Migration.cc
src/librbd/image/CloneRequest.cc
src/librbd/image/CloneRequest.h
src/librbd/internal.cc
src/test/librbd/image/test_mock_CloneRequest.cc
src/test/librbd/test_fixture.cc
src/test/librbd/test_fixture.h
src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc
src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc

index 6fdc0875094330f53f7d6066bb781d64b8520d1e..bf5ad695db96976af78dd1c962d05fe52bd207f0 100644 (file)
@@ -14,6 +14,7 @@
 #include "librbd/image/CloneRequest.h"
 #include "librbd/internal.h"
 #include "librbd/Utils.h"
+#include "librbd/api/Config.h"
 
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
@@ -238,11 +239,14 @@ int Image<I>::deep_copy(I *src, librados::IoCtx& dest_md_ctx,
       return r;
     }
 
+    ConfigProxy config{cct->_conf};
+    api::Config<I>::apply_pool_overrides(dest_md_ctx, &config);
+
     C_SaferCond ctx;
     std::string dest_id = util::generate_image_id(dest_md_ctx);
     auto *req = image::CloneRequest<I>::create(
-      parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id, dest_md_ctx,
-      destname, dest_id, opts, "", "", src->op_work_queue, &ctx);
+      config, parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id,
+      dest_md_ctx, destname, dest_id, opts, "", "", src->op_work_queue, &ctx);
     req->send();
     r = ctx.wait();
   }
index 1e60a3c32226aeebb37f428aa6c524714a565d46..3bd62048ed3f4eb9d66cafdf317dbe8f29278d65 100644 (file)
@@ -12,6 +12,7 @@
 #include "librbd/ImageState.h"
 #include "librbd/Operations.h"
 #include "librbd/Utils.h"
+#include "librbd/api/Config.h"
 #include "librbd/api/Group.h"
 #include "librbd/deep_copy/MetadataCopyRequest.h"
 #include "librbd/deep_copy/SnapshotCopyRequest.h"
@@ -1162,8 +1163,11 @@ int Migration<I>::create_dst_image() {
       return r;
     }
 
+    ConfigProxy config{m_cct->_conf};
+    api::Config<I>::apply_pool_overrides(m_dst_io_ctx, &config);
+
     auto *req = image::CloneRequest<I>::create(
-      parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id,
+      config, parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id,
       m_dst_io_ctx, m_dst_image_name, m_dst_image_id, m_image_options, "", "",
       op_work_queue, &on_create);
     req->send();
index 0606aa0ab246582a6cfa5df00de0912fbb9e965f..c1962649e955eb5f593749d0f9df51aa8732c969 100644 (file)
@@ -29,7 +29,8 @@ using util::create_context_callback;
 using util::create_async_context_callback;
 
 template <typename I>
-CloneRequest<I>::CloneRequest(IoCtx& parent_io_ctx,
+CloneRequest<I>::CloneRequest(ConfigProxy& config,
+                              IoCtx& parent_io_ctx,
                               const std::string& parent_image_id,
                               const std::string& parent_snap_name,
                               uint64_t parent_snap_id,
@@ -40,9 +41,10 @@ CloneRequest<I>::CloneRequest(IoCtx& parent_io_ctx,
                              const std::string &non_primary_global_image_id,
                              const std::string &primary_mirror_uuid,
                              ContextWQ *op_work_queue, Context *on_finish)
-  : m_parent_io_ctx(parent_io_ctx), m_parent_image_id(parent_image_id),
-    m_parent_snap_name(parent_snap_name), m_parent_snap_id(parent_snap_id),
-    m_ioctx(c_ioctx), m_name(c_name), m_id(c_id), m_opts(c_options),
+  : m_config(config), m_parent_io_ctx(parent_io_ctx),
+    m_parent_image_id(parent_image_id), m_parent_snap_name(parent_snap_name),
+    m_parent_snap_id(parent_snap_id), m_ioctx(c_ioctx), m_name(c_name),
+    m_id(c_id), m_opts(c_options),
     m_non_primary_global_image_id(non_primary_global_image_id),
     m_primary_mirror_uuid(primary_mirror_uuid),
     m_op_work_queue(op_work_queue), m_on_finish(on_finish),
@@ -92,7 +94,7 @@ void CloneRequest<I>::validate_options() {
     m_use_p_features = false;
   }
 
-  std::string default_clone_format = m_cct->_conf.get_val<std::string>(
+  std::string default_clone_format = m_config.get_val<std::string>(
     "rbd_default_clone_format");
   if (default_clone_format == "1") {
     m_clone_format = 1;
index e406276bfb2ec596be937b4c1174f2903b296625..7f4c0ee09d715e10966409884b9c22afff026bbc 100644 (file)
@@ -8,6 +8,7 @@
 #include "include/rbd/librbd.hpp"
 #include "librbd/internal.h"
 
+class ConfigProxy;
 class Context;
 
 using librados::IoCtx;
@@ -18,7 +19,7 @@ namespace image {
 template <typename ImageCtxT = ImageCtx>
 class CloneRequest {
 public:
-  static CloneRequest *create(IoCtx& parent_io_ctx,
+  static CloneRequest *create(ConfigProxy& config, IoCtx& parent_io_ctx,
                               const std::string& parent_image_id,
                               const std::string& parent_snap_name,
                               uint64_t parent_snap_id,
@@ -27,13 +28,13 @@ public:
                              const std::string &non_primary_global_image_id,
                              const std::string &primary_mirror_uuid,
                              ContextWQ *op_work_queue, Context *on_finish) {
-    return new CloneRequest(parent_io_ctx, parent_image_id, parent_snap_name,
-                            parent_snap_id, c_ioctx, c_name, c_id, c_options,
-                            non_primary_global_image_id, primary_mirror_uuid,
-                            op_work_queue, on_finish);
+    return new CloneRequest(config, parent_io_ctx, parent_image_id,
+                            parent_snap_name, parent_snap_id, c_ioctx, c_name,
+                            c_id, c_options, non_primary_global_image_id,
+                            primary_mirror_uuid, op_work_queue, on_finish);
   }
 
-  CloneRequest(IoCtx& parent_io_ctx,
+  CloneRequest(ConfigProxy& config, IoCtx& parent_io_ctx,
                const std::string& parent_image_id,
                const std::string& parent_snap_name,
                uint64_t parent_snap_id,
@@ -104,6 +105,7 @@ private:
    * @endverbatim
    */
 
+  ConfigProxy& m_config;
   IoCtx &m_parent_io_ctx;
   std::string m_parent_image_id;
   std::string m_parent_snap_name;
index cbe6574aba1b5f96bf445d685fa9d78bf6f1bdfa..a3499b493190693a74341aae269d1ea3dfd252d1 100644 (file)
@@ -33,6 +33,7 @@
 #include "librbd/TrashWatcher.h"
 #include "librbd/Types.h"
 #include "librbd/Utils.h"
+#include "librbd/api/Config.h"
 #include "librbd/api/Image.h"
 #include "librbd/exclusive_lock/AutomaticPolicy.h"
 #include "librbd/exclusive_lock/StandardPolicy.h"
@@ -999,15 +1000,18 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
                   << "c_id= " << clone_id << ", "
                   << "c_opts=" << c_opts << dendl;
 
+    ConfigProxy config{reinterpret_cast<CephContext *>(c_ioctx.cct())->_conf};
+    api::Config<>::apply_pool_overrides(c_ioctx, &config);
+
     ThreadPool *thread_pool;
     ContextWQ *op_work_queue;
     ImageCtx::get_thread_pool_instance(cct, &thread_pool, &op_work_queue);
 
     C_SaferCond cond;
     auto *req = image::CloneRequest<>::create(
-      p_ioctx, parent_id, p_snap_name, CEPH_NOSNAP, c_ioctx, c_name, clone_id,
-      c_opts, non_primary_global_image_id, primary_mirror_uuid, op_work_queue,
-      &cond);
+      config, p_ioctx, parent_id, p_snap_name, CEPH_NOSNAP, c_ioctx, c_name,
+      clone_id, c_opts, non_primary_global_image_id, primary_mirror_uuid,
+      op_work_queue, &cond);
     req->send();
 
     r = cond.wait();
index 7a103a1ecc2d7150893f4b632a7c2358d3ff6556..59a7b69ce17b99766bc39fb1844651ed4ec2ccfe 100644 (file)
@@ -422,9 +422,9 @@ TEST_F(TestMockImageCloneRequest, SuccessV1) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 }
@@ -470,9 +470,9 @@ TEST_F(TestMockImageCloneRequest, SuccessV2) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 }
@@ -523,9 +523,9 @@ TEST_F(TestMockImageCloneRequest, SuccessAuto) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 }
@@ -541,9 +541,9 @@ TEST_F(TestMockImageCloneRequest, OpenParentError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -567,9 +567,9 @@ TEST_F(TestMockImageCloneRequest, CreateError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -598,9 +598,9 @@ TEST_F(TestMockImageCloneRequest, OpenError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -634,9 +634,9 @@ TEST_F(TestMockImageCloneRequest, AttachParentError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -672,9 +672,9 @@ TEST_F(TestMockImageCloneRequest, AddChildError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -714,9 +714,9 @@ TEST_F(TestMockImageCloneRequest, RefreshError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -759,9 +759,9 @@ TEST_F(TestMockImageCloneRequest, MetadataListError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -801,9 +801,9 @@ TEST_F(TestMockImageCloneRequest, MetadataSetError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -849,9 +849,9 @@ TEST_F(TestMockImageCloneRequest, GetMirrorModeError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -896,9 +896,9 @@ TEST_F(TestMockImageCloneRequest, MirrorEnableError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -938,9 +938,9 @@ TEST_F(TestMockImageCloneRequest, CloseError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -969,9 +969,9 @@ TEST_F(TestMockImageCloneRequest, RemoveError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -1000,9 +1000,9 @@ TEST_F(TestMockImageCloneRequest, CloseParentError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_ioctx, "parent id", "", 123, m_ioctx,
-                                  "clone name", "clone id", clone_opts, "", "",
-                                  image_ctx->op_work_queue, &ctx);
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+                                  m_ioctx, "clone name", "clone id", clone_opts,
+                                  "", "", image_ctx->op_work_queue, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
index ba6076c33754c1380d628b109487c6414055e9ba..27b47eb66c942be9bc9d7e1455604de3d9f026d6 100644 (file)
@@ -57,6 +57,7 @@ std::string TestFixture::get_temp_image_name() {
 
 void TestFixture::SetUp() {
   ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), m_ioctx));
+  m_cct = reinterpret_cast<CephContext*>(m_ioctx.cct());
 
   m_image_name = get_temp_image_name();
   m_image_size = 2 << 20;
index 9bdbfcd27b9c8d5d495d91e7916c1a014e56824b..508e4405c6cf301481b8c645bbafcfc94670a7f4 100644 (file)
@@ -44,6 +44,7 @@ public:
   static uint64_t _image_number;
   static std::string _data_pool;
 
+  CephContext* m_cct = nullptr;
   librados::IoCtx m_ioctx;
   librbd::RBD m_rbd;
 
index ace6db45ce3407a210de08640339ce0f50e10e46..cb34938f6300a953d11d9361116530dd9734eac1 100644 (file)
@@ -73,7 +73,8 @@ struct CloneRequest<librbd::MockTestImageCtx> {
   static CloneRequest *s_instance;
   Context *on_finish = nullptr;
 
-  static CloneRequest *create(IoCtx &p_ioctx, const std::string &p_id,
+  static CloneRequest *create(ConfigProxy& config, IoCtx &p_ioctx,
+                              const std::string &p_id,
                               const std::string &p_snap_name,
                               uint64_t p_snap_id,
                              IoCtx &c_ioctx, const std::string &c_name,
index 27e0895097041198d4bb0559f425c98bcbe1a011..4df226f02f89cf625a4ec9ec4cf6c314b34ab4c2 100644 (file)
@@ -332,13 +332,16 @@ void CreateImageRequest<I>::clone_image() {
   librbd::ImageOptions opts;
   populate_image_options(&opts);
 
+  auto& config{
+    reinterpret_cast<CephContext*>(m_local_io_ctx.cct())->_conf};
+
   using klass = CreateImageRequest<I>;
   Context *ctx = create_context_callback<
     klass, &klass::handle_clone_image>(this);
 
   librbd::image::CloneRequest<I> *req = librbd::image::CloneRequest<I>::create(
-    m_local_parent_io_ctx, m_local_parent_spec.image_id, snap_name, CEPH_NOSNAP,
-    m_local_io_ctx, m_local_image_name, m_local_image_id, opts,
+    config, m_local_parent_io_ctx, m_local_parent_spec.image_id, snap_name,
+    CEPH_NOSNAP, m_local_io_ctx, m_local_image_name, m_local_image_id, opts,
     m_global_image_id, m_remote_mirror_uuid, m_remote_image_ctx->op_work_queue,
     ctx);
   req->send();