From 7abfe59ec347cd5b626f1921df2f0c83967a3483 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 8 Oct 2018 11:18:37 -0400 Subject: [PATCH] librbd: use pool config overrides for clone state machine Signed-off-by: Jason Dillaman --- src/librbd/api/Image.cc | 8 +- src/librbd/api/Migration.cc | 6 +- src/librbd/image/CloneRequest.cc | 12 ++- src/librbd/image/CloneRequest.h | 14 +-- src/librbd/internal.cc | 10 +- .../librbd/image/test_mock_CloneRequest.cc | 96 +++++++++---------- src/test/librbd/test_fixture.cc | 1 + src/test/librbd/test_fixture.h | 1 + .../test_mock_CreateImageRequest.cc | 3 +- .../image_replayer/CreateImageRequest.cc | 7 +- 10 files changed, 90 insertions(+), 68 deletions(-) diff --git a/src/librbd/api/Image.cc b/src/librbd/api/Image.cc index 6fdc087509433..bf5ad695db969 100644 --- a/src/librbd/api/Image.cc +++ b/src/librbd/api/Image.cc @@ -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::deep_copy(I *src, librados::IoCtx& dest_md_ctx, return r; } + ConfigProxy config{cct->_conf}; + api::Config::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::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(); } diff --git a/src/librbd/api/Migration.cc b/src/librbd/api/Migration.cc index 1e60a3c32226a..3bd62048ed3f4 100644 --- a/src/librbd/api/Migration.cc +++ b/src/librbd/api/Migration.cc @@ -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::create_dst_image() { return r; } + ConfigProxy config{m_cct->_conf}; + api::Config::apply_pool_overrides(m_dst_io_ctx, &config); + auto *req = image::CloneRequest::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(); diff --git a/src/librbd/image/CloneRequest.cc b/src/librbd/image/CloneRequest.cc index 0606aa0ab2465..c1962649e955e 100644 --- a/src/librbd/image/CloneRequest.cc +++ b/src/librbd/image/CloneRequest.cc @@ -29,7 +29,8 @@ using util::create_context_callback; using util::create_async_context_callback; template -CloneRequest::CloneRequest(IoCtx& parent_io_ctx, +CloneRequest::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::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::validate_options() { m_use_p_features = false; } - std::string default_clone_format = m_cct->_conf.get_val( + std::string default_clone_format = m_config.get_val( "rbd_default_clone_format"); if (default_clone_format == "1") { m_clone_format = 1; diff --git a/src/librbd/image/CloneRequest.h b/src/librbd/image/CloneRequest.h index e406276bfb2ec..7f4c0ee09d715 100644 --- a/src/librbd/image/CloneRequest.h +++ b/src/librbd/image/CloneRequest.h @@ -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 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; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index cbe6574aba1b5..a3499b4931906 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -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(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(); diff --git a/src/test/librbd/image/test_mock_CloneRequest.cc b/src/test/librbd/image/test_mock_CloneRequest.cc index 7a103a1ecc2d7..59a7b69ce17b9 100644 --- a/src/test/librbd/image/test_mock_CloneRequest.cc +++ b/src/test/librbd/image/test_mock_CloneRequest.cc @@ -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()); } diff --git a/src/test/librbd/test_fixture.cc b/src/test/librbd/test_fixture.cc index ba6076c33754c..27b47eb66c942 100644 --- a/src/test/librbd/test_fixture.cc +++ b/src/test/librbd/test_fixture.cc @@ -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(m_ioctx.cct()); m_image_name = get_temp_image_name(); m_image_size = 2 << 20; diff --git a/src/test/librbd/test_fixture.h b/src/test/librbd/test_fixture.h index 9bdbfcd27b9c8..508e4405c6cf3 100644 --- a/src/test/librbd/test_fixture.h +++ b/src/test/librbd/test_fixture.h @@ -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; diff --git a/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc index ace6db45ce340..cb34938f6300a 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc @@ -73,7 +73,8 @@ struct CloneRequest { 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, diff --git a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc index 27e0895097041..4df226f02f89c 100644 --- a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc @@ -332,13 +332,16 @@ void CreateImageRequest::clone_image() { librbd::ImageOptions opts; populate_image_options(&opts); + auto& config{ + reinterpret_cast(m_local_io_ctx.cct())->_conf}; + using klass = CreateImageRequest; Context *ctx = create_context_callback< klass, &klass::handle_clone_image>(this); librbd::image::CloneRequest *req = librbd::image::CloneRequest::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(); -- 2.39.5