From c7c15b681c83173fce141f1408a3efcef9990771 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 19 Dec 2017 10:23:44 -0500 Subject: [PATCH] librbd: permit creation of clones against non-primary images Fixes: http://tracker.ceph.com/issues/18480 Signed-off-by: Jason Dillaman --- qa/workunits/rbd/rbd_mirror.sh | 3 +-- src/librbd/image/CloneRequest.cc | 34 ++------------------------------ src/librbd/image/CloneRequest.h | 25 +++++++++++------------ 3 files changed, 14 insertions(+), 48 deletions(-) diff --git a/qa/workunits/rbd/rbd_mirror.sh b/qa/workunits/rbd/rbd_mirror.sh index 3e7f844faea..233c06dd3f3 100755 --- a/qa/workunits/rbd/rbd_mirror.sh +++ b/qa/workunits/rbd/rbd_mirror.sh @@ -229,8 +229,7 @@ wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${clone_image} wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${clone_image} 'up+replaying' 'master_position' compare_images ${POOL} ${clone_image} -expect_failure "is non-primary" clone_image ${CLUSTER1} ${PARENT_POOL} \ - ${parent_image} ${parent_snap} ${POOL} ${clone_image}1 +clone_image ${CLUSTER1} ${PARENT_POOL} ${parent_image} ${parent_snap} ${POOL} ${clone_image}1 testlog "TEST: data pool" dp_image=test_data_pool diff --git a/src/librbd/image/CloneRequest.cc b/src/librbd/image/CloneRequest.cc index a1c30c187db..5ececb2c8c6 100644 --- a/src/librbd/image/CloneRequest.cc +++ b/src/librbd/image/CloneRequest.cc @@ -7,7 +7,6 @@ #include "common/errno.h" #include "include/assert.h" #include "librbd/ImageState.h" -#include "librbd/Journal.h" #include "librbd/image/CloneRequest.h" #include "librbd/image/CreateRequest.h" #include "librbd/image/RemoveRequest.h" @@ -122,36 +121,6 @@ void CloneRequest::send_validate_parent() { return complete(-EINVAL); } - if ((m_p_features & RBD_FEATURE_JOURNALING) != 0) { - m_force_non_primary = !m_non_primary_global_image_id.empty(); - using klass = CloneRequest; - Context *ctx = create_context_callback< - klass, &klass::handle_validate_parent>(this); - - Journal::is_tag_owner(m_p_imctx, &m_is_primary, ctx); - return; - } - - send_validate_child(); -} - -template -void CloneRequest::handle_validate_parent(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; - - if (r < 0) { - lderr(m_cct) << "failed to determine tag ownership: " << cpp_strerror(r) - << dendl; - return complete(r); - } - - if ((m_p_features & RBD_FEATURE_JOURNALING) != 0) { - if (!m_is_primary && !m_force_non_primary) { - lderr(m_cct) << "parent is non-primary mirrored image" << dendl; - return complete(-EINVAL); - } - } - send_validate_child(); } @@ -464,7 +433,8 @@ void CloneRequest::send_enable_mirror() { ldout(m_cct, 20) << this << " " << __func__ << dendl; using klass = CloneRequest; - Context *ctx = create_context_callback(this); + Context *ctx = create_context_callback< + klass, &klass::handle_enable_mirror>(this); mirror::EnableRequest *req = mirror::EnableRequest::create( m_imctx->md_ctx, m_id, m_non_primary_global_image_id, diff --git a/src/librbd/image/CloneRequest.h b/src/librbd/image/CloneRequest.h index 01d7750c39e..851a2021e16 100644 --- a/src/librbd/image/CloneRequest.h +++ b/src/librbd/image/CloneRequest.h @@ -18,16 +18,23 @@ namespace image { template class CloneRequest { public: - static CloneRequest *create(ImageCtxT *p_imctx, IoCtx &c_ioctx, const std::string &c_name, - const std::string &c_id, ImageOptions c_options, + static CloneRequest *create(ImageCtxT *p_imctx, IoCtx &c_ioctx, + const std::string &c_name, + const std::string &c_id, ImageOptions c_options, const std::string &non_primary_global_image_id, const std::string &primary_mirror_uuid, ContextWQ *op_work_queue, Context *on_finish) { return new CloneRequest(p_imctx, c_ioctx, c_name, c_id, c_options, - non_primary_global_image_id, primary_mirror_uuid, - op_work_queue, on_finish); + non_primary_global_image_id, primary_mirror_uuid, + op_work_queue, on_finish); } + CloneRequest(ImageCtxT *p_imctx, IoCtx &c_ioctx, const std::string &c_name, + const std::string &c_id, ImageOptions c_options, + const std::string &non_primary_global_image_id, + const std::string &primary_mirror_uuid, + ContextWQ *op_work_queue, Context *on_finish); + void send(); private: /** @@ -77,13 +84,6 @@ private: * @endverbatim */ - CloneRequest(ImageCtxT *p_imctx, IoCtx &c_ioctx, const std::string &c_name, - const std::string &c_id, - ImageOptions c_options, - const std::string &non_primary_global_image_id, - const std::string &primary_mirror_uuid, - ContextWQ *op_work_queue, Context *on_finish); - ImageCtxT *m_p_imctx; IoCtx &m_ioctx; std::string m_name; @@ -107,13 +107,10 @@ private: bufferlist m_out_bl; uint64_t m_size; int m_r_saved = 0; - bool m_is_primary; - bool m_force_non_primary; void validate_options(); void send_validate_parent(); - void handle_validate_parent(int r); void send_validate_child(); void handle_validate_child(int r); -- 2.39.5