From: Jason Dillaman Date: Wed, 29 Jan 2020 22:27:22 +0000 (-0500) Subject: librbd: clone state machine should accept snapshot namespace X-Git-Tag: v15.1.1~472^2~13 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=667c049de653c982d4605f5a9bb863615ae97312;p=ceph-ci.git librbd: clone state machine should accept snapshot namespace It currently assumes that you can only create snapshots from user snapshot namespaces. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/api/Image.cc b/src/librbd/api/Image.cc index 2df690e25ad..c0bacaf675e 100644 --- a/src/librbd/api/Image.cc +++ b/src/librbd/api/Image.cc @@ -614,7 +614,7 @@ int Image::deep_copy(I *src, librados::IoCtx& dest_md_ctx, C_SaferCond 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, + config, parent_io_ctx, parent_spec.image_id, "", {}, parent_spec.snap_id, dest_md_ctx, destname, dest_id, opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", src->op_work_queue, &ctx); req->send(); diff --git a/src/librbd/api/Migration.cc b/src/librbd/api/Migration.cc index cbdfd5b4666..73294503217 100644 --- a/src/librbd/api/Migration.cc +++ b/src/librbd/api/Migration.cc @@ -1244,7 +1244,7 @@ int Migration::create_dst_image() { } auto *req = image::CloneRequest::create( - config, 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, 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 02793da61f1..cdf1fd7a911 100644 --- a/src/librbd/image/CloneRequest.cc +++ b/src/librbd/image/CloneRequest.cc @@ -30,21 +30,24 @@ using util::create_context_callback; using util::create_async_context_callback; template -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, - 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) +CloneRequest::CloneRequest( + ConfigProxy& config, + IoCtx& parent_io_ctx, + const std::string& parent_image_id, + const std::string& parent_snap_name, + const cls::rbd::SnapshotNamespace& parent_snap_namespace, + 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) : 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_namespace(parent_snap_namespace), m_parent_snap_id(parent_snap_id), m_ioctx(c_ioctx), m_name(c_name), 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), @@ -138,8 +141,10 @@ void CloneRequest::open_parent() { m_parent_io_ctx, true); } else { m_parent_image_ctx = I::create("", m_parent_image_id, - m_parent_snap_name.c_str(), m_parent_io_ctx, + m_parent_snap_name.c_str(), + m_parent_io_ctx, true); + m_parent_image_ctx->snap_namespace = m_parent_snap_namespace; } Context *ctx = create_context_callback< diff --git a/src/librbd/image/CloneRequest.h b/src/librbd/image/CloneRequest.h index 1bad9945da9..c7bfc823c0d 100644 --- a/src/librbd/image/CloneRequest.h +++ b/src/librbd/image/CloneRequest.h @@ -19,26 +19,29 @@ namespace image { template class CloneRequest { public: - 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, - 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) { + static CloneRequest *create( + ConfigProxy& config, IoCtx& parent_io_ctx, + const std::string& parent_image_id, + const std::string& parent_snap_name, + const cls::rbd::SnapshotNamespace& parent_snap_namespace, + 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, mirror_image_mode, - non_primary_global_image_id, primary_mirror_uuid, - op_work_queue, on_finish); + parent_snap_name, parent_snap_namespace, + parent_snap_id, c_ioctx, c_name, 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, const std::string& parent_image_id, const std::string& parent_snap_name, + const cls::rbd::SnapshotNamespace& parent_snap_namespace, uint64_t parent_snap_id, IoCtx &c_ioctx, const std::string &c_name, const std::string &c_id, ImageOptions c_options, @@ -101,6 +104,7 @@ private: IoCtx &m_parent_io_ctx; std::string m_parent_image_id; std::string m_parent_snap_name; + cls::rbd::SnapshotNamespace m_parent_snap_namespace; uint64_t m_parent_snap_id; ImageCtxT *m_parent_image_ctx; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 97f3205e6ef..662bfa18fa6 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -781,7 +781,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, + config, p_ioctx, parent_id, p_snap_name, + {cls::rbd::UserSnapshotNamespace{}}, CEPH_NOSNAP, c_ioctx, c_name, clone_id, c_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, non_primary_global_image_id, primary_mirror_uuid, op_work_queue, &cond); req->send(); diff --git a/src/test/librbd/image/test_mock_CloneRequest.cc b/src/test/librbd/image/test_mock_CloneRequest.cc index c9af674bad0..46c4ce96e86 100644 --- a/src/test/librbd/image/test_mock_CloneRequest.cc +++ b/src/test/librbd/image/test_mock_CloneRequest.cc @@ -399,7 +399,7 @@ TEST_F(TestMockImageCloneRequest, SuccessV1) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -449,7 +449,7 @@ TEST_F(TestMockImageCloneRequest, SuccessV2) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -499,7 +499,7 @@ TEST_F(TestMockImageCloneRequest, SuccessAuto) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -518,7 +518,7 @@ TEST_F(TestMockImageCloneRequest, OpenParentError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -545,7 +545,7 @@ TEST_F(TestMockImageCloneRequest, CreateError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -577,7 +577,7 @@ TEST_F(TestMockImageCloneRequest, OpenError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -614,7 +614,7 @@ TEST_F(TestMockImageCloneRequest, AttachParentError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -654,7 +654,7 @@ TEST_F(TestMockImageCloneRequest, AttachChildError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -696,7 +696,7 @@ TEST_F(TestMockImageCloneRequest, MetadataListError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -739,7 +739,7 @@ TEST_F(TestMockImageCloneRequest, MetadataSetError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -784,7 +784,7 @@ TEST_F(TestMockImageCloneRequest, GetMirrorModeError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -832,7 +832,7 @@ TEST_F(TestMockImageCloneRequest, MirrorEnableError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -875,7 +875,7 @@ TEST_F(TestMockImageCloneRequest, CloseError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -907,7 +907,7 @@ TEST_F(TestMockImageCloneRequest, RemoveError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); @@ -939,7 +939,7 @@ TEST_F(TestMockImageCloneRequest, CloseParentError) { C_SaferCond ctx; ImageOptions clone_opts; - auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123, + auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123, m_ioctx, "clone name", "clone id", clone_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", image_ctx->op_work_queue, &ctx); 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 63419fe4fa0..ab952269d3d 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc @@ -78,6 +78,7 @@ struct CloneRequest { static CloneRequest *create(ConfigProxy& config, IoCtx &p_ioctx, const std::string &p_id, const std::string &p_snap_name, + const cls::rbd::SnapshotNamespace& snap_ns, uint64_t p_snap_id, IoCtx &c_ioctx, const std::string &c_name, const std::string &c_id, ImageOptions c_options, diff --git a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc index f1f9cc42bb4..c023902c209 100644 --- a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc @@ -288,9 +288,9 @@ 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_mirror_image_mode, m_global_image_id, m_remote_mirror_uuid, - m_remote_image_ctx->op_work_queue, ctx); + snap_namespace, CEPH_NOSNAP, m_local_io_ctx, m_local_image_name, + m_local_image_id, opts, m_mirror_image_mode, m_global_image_id, + m_remote_mirror_uuid, m_remote_image_ctx->op_work_queue, ctx); req->send(); }