From a162fe62d36d8fba2cc7924ceb97da0faeddf2d8 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 28 Jan 2020 12:10:03 -0500 Subject: [PATCH] librbd: pass mirror image mode to create/clone image state machines The rbd-mirror daemon will need to be able to create images using snapshot-based mirroring. Signed-off-by: Jason Dillaman --- src/librbd/api/Image.cc | 3 +- src/librbd/api/Migration.cc | 8 ++-- src/librbd/image/CloneRequest.cc | 19 ++++---- src/librbd/image/CloneRequest.h | 8 +++- src/librbd/image/CreateRequest.cc | 8 ++-- src/librbd/image/CreateRequest.h | 15 +++--- src/librbd/internal.cc | 9 ++-- .../librbd/image/test_mock_CloneRequest.cc | 48 ++++++++++++------- .../test_mock_CreateImageRequest.cc | 4 +- .../image_replayer/CreateImageRequest.cc | 9 ++-- 10 files changed, 79 insertions(+), 52 deletions(-) diff --git a/src/librbd/api/Image.cc b/src/librbd/api/Image.cc index 6ebe78ff7e8..2df690e25ad 100644 --- a/src/librbd/api/Image.cc +++ b/src/librbd/api/Image.cc @@ -615,7 +615,8 @@ int Image::deep_copy(I *src, librados::IoCtx& dest_md_ctx, std::string dest_id = util::generate_image_id(dest_md_ctx); auto *req = image::CloneRequest::create( config, parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id, - dest_md_ctx, destname, dest_id, opts, "", "", src->op_work_queue, &ctx); + dest_md_ctx, destname, dest_id, opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, + "", "", 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 1319eb23753..cbdfd5b4666 100644 --- a/src/librbd/api/Migration.cc +++ b/src/librbd/api/Migration.cc @@ -1232,8 +1232,8 @@ int Migration::create_dst_image() { if (parent_spec.pool_id == -1) { auto *req = image::CreateRequest::create( config, m_dst_io_ctx, m_dst_image_name, m_dst_image_id, size, - m_image_options, "", "", true /* skip_mirror_enable */, op_work_queue, - &on_create); + m_image_options, true /* skip_mirror_enable */, + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", op_work_queue, &on_create); req->send(); } else { r = util::create_ioctx(m_src_image_ctx->md_ctx, "destination image", @@ -1245,8 +1245,8 @@ int Migration::create_dst_image() { auto *req = image::CloneRequest::create( 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); + m_dst_io_ctx, m_dst_image_name, m_dst_image_id, m_image_options, + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", op_work_queue, &on_create); req->send(); } diff --git a/src/librbd/image/CloneRequest.cc b/src/librbd/image/CloneRequest.cc index 45ea1749526..02793da61f1 100644 --- a/src/librbd/image/CloneRequest.cc +++ b/src/librbd/image/CloneRequest.cc @@ -39,13 +39,14 @@ CloneRequest::CloneRequest(ConfigProxy& config, const std::string &c_name, const std::string &c_id, ImageOptions c_options, + cls::rbd::MirrorImageMode mirror_image_mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, ContextWQ *op_work_queue, Context *on_finish) : 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_id(c_id), m_opts(c_options), m_mirror_image_mode(mirror_image_mode), 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), @@ -278,11 +279,10 @@ void CloneRequest::create_child() { Context *ctx = create_context_callback< klass, &klass::handle_create_child>(this); - std::shared_lock image_locker{m_parent_image_ctx->image_lock}; CreateRequest *req = CreateRequest::create( - m_config, m_ioctx, m_name, m_id, m_size, m_opts, - m_non_primary_global_image_id, m_primary_mirror_uuid, true, - m_op_work_queue, ctx); + m_config, m_ioctx, m_name, m_id, m_size, m_opts, true, + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, m_non_primary_global_image_id, + m_primary_mirror_uuid, m_op_work_queue, ctx); req->send(); } @@ -525,12 +525,9 @@ void CloneRequest::enable_mirror() { using klass = CloneRequest; Context *ctx = create_context_callback< klass, &klass::handle_enable_mirror>(this); - - // TODO: in future rbd-mirror will want to enable mirroring - // not only in journal mode. - mirror::EnableRequest *req = mirror::EnableRequest::create( - m_imctx->md_ctx, m_id, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, - m_non_primary_global_image_id, m_imctx->op_work_queue, ctx); + auto req = mirror::EnableRequest::create( + m_imctx->md_ctx, m_id, m_mirror_image_mode, m_non_primary_global_image_id, + m_imctx->op_work_queue, ctx); req->send(); } diff --git a/src/librbd/image/CloneRequest.h b/src/librbd/image/CloneRequest.h index 640de9fe0da..1bad9945da9 100644 --- a/src/librbd/image/CloneRequest.h +++ b/src/librbd/image/CloneRequest.h @@ -25,13 +25,15 @@ public: uint64_t parent_snap_id, IoCtx &c_ioctx, const std::string &c_name, const std::string &c_id, ImageOptions c_options, + cls::rbd::MirrorImageMode mirror_image_mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, ContextWQ *op_work_queue, Context *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); + c_id, c_options, mirror_image_mode, + non_primary_global_image_id, primary_mirror_uuid, + op_work_queue, on_finish); } CloneRequest(ConfigProxy& config, IoCtx& parent_io_ctx, @@ -40,6 +42,7 @@ public: uint64_t parent_snap_id, IoCtx &c_ioctx, const std::string &c_name, const std::string &c_id, ImageOptions c_options, + cls::rbd::MirrorImageMode mirror_image_mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, ContextWQ *op_work_queue, Context *on_finish); @@ -108,6 +111,7 @@ private: cls::rbd::ParentImageSpec m_pspec; ImageCtxT *m_imctx; cls::rbd::MirrorMode m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED; + cls::rbd::MirrorImageMode m_mirror_image_mode; const std::string m_non_primary_global_image_id; const std::string m_primary_mirror_uuid; NoOpProgressContext m_no_op; diff --git a/src/librbd/image/CreateRequest.cc b/src/librbd/image/CreateRequest.cc index 2c497bb1573..791fc6254e4 100644 --- a/src/librbd/image/CreateRequest.cc +++ b/src/librbd/image/CreateRequest.cc @@ -118,14 +118,16 @@ CreateRequest::CreateRequest(const ConfigProxy& config, IoCtx &ioctx, const std::string &image_name, const std::string &image_id, uint64_t size, const ImageOptions &image_options, + bool skip_mirror_enable, + cls::rbd::MirrorImageMode mirror_image_mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, - bool skip_mirror_enable, ContextWQ *op_work_queue, Context *on_finish) : m_config(config), m_image_name(image_name), m_image_id(image_id), - m_size(size), m_non_primary_global_image_id(non_primary_global_image_id), + m_size(size), m_skip_mirror_enable(skip_mirror_enable), + m_mirror_image_mode(mirror_image_mode), + m_non_primary_global_image_id(non_primary_global_image_id), m_primary_mirror_uuid(primary_mirror_uuid), - m_skip_mirror_enable(skip_mirror_enable), m_op_work_queue(op_work_queue), m_on_finish(on_finish) { m_io_ctx.dup(ioctx); diff --git a/src/librbd/image/CreateRequest.h b/src/librbd/image/CreateRequest.h index 6d5b641de99..688e5c632a2 100644 --- a/src/librbd/image/CreateRequest.h +++ b/src/librbd/image/CreateRequest.h @@ -29,14 +29,15 @@ public: const std::string &image_name, const std::string &image_id, uint64_t size, const ImageOptions &image_options, + bool skip_mirror_enable, + cls::rbd::MirrorImageMode mirror_image_mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, - bool skip_mirror_enable, ContextWQ *op_work_queue, Context *on_finish) { return new CreateRequest(config, ioctx, image_name, image_id, size, - image_options, non_primary_global_image_id, - primary_mirror_uuid, skip_mirror_enable, - op_work_queue, on_finish); + image_options, skip_mirror_enable, + mirror_image_mode, non_primary_global_image_id, + primary_mirror_uuid, op_work_queue, on_finish); } static int validate_order(CephContext *cct, uint8_t order); @@ -90,9 +91,10 @@ private: const std::string &image_name, const std::string &image_id, uint64_t size, const ImageOptions &image_options, + bool skip_mirror_enable, + cls::rbd::MirrorImageMode mirror_image_mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, - bool skip_mirror_enable, ContextWQ *op_work_queue, Context *on_finish); const ConfigProxy& m_config; @@ -110,9 +112,10 @@ private: std::string m_journal_pool; std::string m_data_pool; int64_t m_data_pool_id = -1; + bool m_skip_mirror_enable; + cls::rbd::MirrorImageMode m_mirror_image_mode; const std::string m_non_primary_global_image_id; const std::string m_primary_mirror_uuid; - bool m_skip_mirror_enable; bool m_negotiate_features = false; ContextWQ *m_op_work_queue; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 62c4d461c48..97f3205e6ef 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -687,8 +687,9 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { C_SaferCond cond; image::CreateRequest<> *req = image::CreateRequest<>::create( - config, io_ctx, image_name, id, size, opts, non_primary_global_image_id, - primary_mirror_uuid, skip_mirror_enable, op_work_queue, &cond); + config, io_ctx, image_name, id, size, opts, skip_mirror_enable, + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, non_primary_global_image_id, + primary_mirror_uuid, op_work_queue, &cond); req->send(); r = cond.wait(); @@ -781,8 +782,8 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { C_SaferCond cond; auto *req = image::CloneRequest<>::create( 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); + clone_id, c_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, + 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 1246836e07a..c9af674bad0 100644 --- a/src/test/librbd/image/test_mock_CloneRequest.cc +++ b/src/test/librbd/image/test_mock_CloneRequest.cc @@ -106,9 +106,10 @@ struct CreateRequest { const std::string &image_name, const std::string &image_id, uint64_t size, const ImageOptions &image_options, + bool skip_mirror_enable, + cls::rbd::MirrorImageMode mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, - bool skip_mirror_enable, ContextWQ *op_work_queue, Context *on_finish) { ceph_assert(s_instance != nullptr); @@ -400,7 +401,8 @@ TEST_F(TestMockImageCloneRequest, SuccessV1) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); } @@ -449,7 +451,8 @@ TEST_F(TestMockImageCloneRequest, SuccessV2) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); } @@ -498,7 +501,8 @@ TEST_F(TestMockImageCloneRequest, SuccessAuto) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); } @@ -516,7 +520,8 @@ TEST_F(TestMockImageCloneRequest, OpenParentError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -542,7 +547,8 @@ TEST_F(TestMockImageCloneRequest, CreateError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -573,7 +579,8 @@ TEST_F(TestMockImageCloneRequest, OpenError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -609,7 +616,8 @@ TEST_F(TestMockImageCloneRequest, AttachParentError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -648,7 +656,8 @@ TEST_F(TestMockImageCloneRequest, AttachChildError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -689,7 +698,8 @@ TEST_F(TestMockImageCloneRequest, MetadataListError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -731,7 +741,8 @@ TEST_F(TestMockImageCloneRequest, MetadataSetError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -775,7 +786,8 @@ TEST_F(TestMockImageCloneRequest, GetMirrorModeError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -822,7 +834,8 @@ TEST_F(TestMockImageCloneRequest, MirrorEnableError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -864,7 +877,8 @@ TEST_F(TestMockImageCloneRequest, CloseError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -895,7 +909,8 @@ TEST_F(TestMockImageCloneRequest, RemoveError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -926,7 +941,8 @@ TEST_F(TestMockImageCloneRequest, CloseParentError) { ImageOptions clone_opts; 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", + image_ctx->op_work_queue, &ctx); req->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } 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 ac014be831d..896aa03e7d7 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc @@ -40,9 +40,10 @@ struct CreateRequest { const std::string &imgname, const std::string &imageid, uint64_t size, const librbd::ImageOptions &image_options, + bool skip_mirror_enable, + cls::rbd::MirrorImageMode mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, - bool skip_mirror_enable, MockContextWQ *op_work_queue, Context *on_finish) { ceph_assert(s_instance != nullptr); @@ -80,6 +81,7 @@ struct CloneRequest { uint64_t p_snap_id, IoCtx &c_ioctx, const std::string &c_name, const std::string &c_id, ImageOptions c_options, + cls::rbd::MirrorImageMode mode, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, MockContextWQ *op_work_queue, diff --git a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc index 84973676edc..23dde23ec99 100644 --- a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc @@ -83,8 +83,9 @@ void CreateImageRequest::create_image() { auto req = librbd::image::CreateRequest::create( config, m_local_io_ctx, m_local_image_name, m_local_image_id, - m_remote_image_ctx->size, image_options, m_global_image_id, - m_remote_mirror_uuid, false, m_remote_image_ctx->op_work_queue, ctx); + m_remote_image_ctx->size, image_options, false, + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, m_global_image_id, + m_remote_mirror_uuid, m_remote_image_ctx->op_work_queue, ctx); req->send(); } @@ -345,8 +346,8 @@ void CreateImageRequest::clone_image() { librbd::image::CloneRequest *req = librbd::image::CloneRequest::create( 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); + cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, m_global_image_id, + m_remote_mirror_uuid, m_remote_image_ctx->op_work_queue, ctx); req->send(); } -- 2.39.5