From 5cd074be9cee4e359894ae434a7b8e89168a5104 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 27 Feb 2020 14:49:11 -0500 Subject: [PATCH] librbd: fixed issue with deep-copy incorrectly setting parent spec When not syncing the full image, the destination image would receive the incorrect source parent spec instead of the expected destination parent spec. Signed-off-by: Jason Dillaman --- src/cls/rbd/cls_rbd_types.cc | 19 +++++++++++++++++++ src/cls/rbd/cls_rbd_types.h | 4 ++++ src/librbd/deep_copy/SnapshotCopyRequest.cc | 6 +++--- src/librbd/image/AttachParentRequest.cc | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/cls/rbd/cls_rbd_types.cc b/src/cls/rbd/cls_rbd_types.cc index b6e1cd9b0dd..9071f3457fe 100644 --- a/src/cls/rbd/cls_rbd_types.cc +++ b/src/cls/rbd/cls_rbd_types.cc @@ -524,6 +524,16 @@ void ParentImageSpec::generate_test_instances(std::list& o) { o.push_back(new ParentImageSpec{1, "ns", "foo", 3}); } +std::ostream& operator<<(std::ostream& os, const ParentImageSpec& rhs) { + os << "[" + << "pool_id=" << rhs.pool_id << ", " + << "pool_namespace=" << rhs.pool_namespace << ", " + << "image_id=" << rhs.image_id << ", " + << "snap_id=" << rhs.snap_id + << "]"; + return os; +} + void ChildImageSpec::encode(bufferlist &bl) const { ENCODE_START(2, 1, bl); encode(pool_id, bl); @@ -554,6 +564,15 @@ void ChildImageSpec::generate_test_instances(std::list &o) { o.push_back(new ChildImageSpec(123, "ns", "abc")); } +std::ostream& operator<<(std::ostream& os, const ChildImageSpec& rhs) { + os << "[" + << "pool_id=" << rhs.pool_id << ", " + << "pool_namespace=" << rhs.pool_namespace << ", " + << "image_id=" << rhs.image_id + << "]"; + return os; +} + void GroupImageSpec::encode(bufferlist &bl) const { ENCODE_START(1, 1, bl); encode(image_id, bl); diff --git a/src/cls/rbd/cls_rbd_types.h b/src/cls/rbd/cls_rbd_types.h index 081540d8e79..b2c155eb864 100644 --- a/src/cls/rbd/cls_rbd_types.h +++ b/src/cls/rbd/cls_rbd_types.h @@ -315,6 +315,8 @@ struct ParentImageSpec { WRITE_CLASS_ENCODER(ParentImageSpec); +std::ostream& operator<<(std::ostream& os, const ParentImageSpec& rhs); + struct ChildImageSpec { int64_t pool_id = -1; std::string pool_namespace; @@ -349,6 +351,8 @@ struct ChildImageSpec { }; WRITE_CLASS_ENCODER(ChildImageSpec); +std::ostream& operator<<(std::ostream& os, const ChildImageSpec& rhs); + typedef std::set ChildImageSpecs; struct GroupImageSpec { diff --git a/src/librbd/deep_copy/SnapshotCopyRequest.cc b/src/librbd/deep_copy/SnapshotCopyRequest.cc index b7262e30daf..8ac59308873 100644 --- a/src/librbd/deep_copy/SnapshotCopyRequest.cc +++ b/src/librbd/deep_copy/SnapshotCopyRequest.cc @@ -568,14 +568,14 @@ void SnapshotCopyRequest::send_set_head() { if (snap_info_it != m_src_image_ctx->snap_info.end()) { auto& snap_info = snap_info_it->second; size = snap_info.size; - if (!m_flatten) { - parent_spec = snap_info.parent.spec; + if (!m_flatten && snap_info.parent.spec.pool_id != -1) { + parent_spec = m_dst_parent_spec; parent_overlap = snap_info.parent.overlap; } } else { size = m_src_image_ctx->size; if (!m_flatten) { - parent_spec = m_src_image_ctx->parent_md.spec; + parent_spec = m_dst_image_ctx->parent_md.spec; parent_overlap = m_src_image_ctx->parent_md.overlap; } } diff --git a/src/librbd/image/AttachParentRequest.cc b/src/librbd/image/AttachParentRequest.cc index 19e69594749..116ef7ffada 100644 --- a/src/librbd/image/AttachParentRequest.cc +++ b/src/librbd/image/AttachParentRequest.cc @@ -27,7 +27,7 @@ void AttachParentRequest::send() { template void AttachParentRequest::attach_parent() { auto cct = m_image_ctx.cct; - ldout(cct, 5) << dendl; + ldout(cct, 5) << "parent_image_spec=" << m_parent_image_spec << dendl; librados::ObjectWriteOperation op; if (!m_legacy_parent) { -- 2.39.5