From 6c06fbc4e2547b0a402e179af0c4371bd537cbcc Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 8 Dec 2020 14:16:49 -0500 Subject: [PATCH] librbd/deep_copy: added new migrating flag to object copy The migration operation and the copyup state machine will set this flag when attempting to perform a deep-copy due to a live-migration. This flag will prevent a possible race condition between the start of the object deep-copy when migration was enabled and the writing portion of the deep-copy when migration might have completed via external means. Fixes: https://tracker.ceph.com/issues/45694 Signed-off-by: Jason Dillaman (cherry picked from commit 1baba64e213cb808804796575d3f7969cf37a3c6) Conflicts: src/librbd/deep_copy/ObjectCopyRequest.cc (trivial) --- src/librbd/deep_copy/ObjectCopyRequest.cc | 6 ++++-- src/librbd/deep_copy/Types.h | 3 ++- src/librbd/io/CopyupRequest.cc | 2 +- src/librbd/operation/MigrateRequest.cc | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/librbd/deep_copy/ObjectCopyRequest.cc b/src/librbd/deep_copy/ObjectCopyRequest.cc index 682bdf24ed3f9..17723cdd2baa5 100644 --- a/src/librbd/deep_copy/ObjectCopyRequest.cc +++ b/src/librbd/deep_copy/ObjectCopyRequest.cc @@ -342,7 +342,9 @@ void ObjectCopyRequest::send_write_object() { librados::ObjectWriteOperation op; uint64_t buffer_offset; - if (!m_dst_image_ctx->migration_info.empty()) { + bool migration = ((m_flags & OBJECT_COPY_REQUEST_FLAG_MIGRATION) != 0); + if (migration) { + ldout(m_cct, 20) << "assert_snapc_seq=" << dst_snap_seq << dendl; cls_client::assert_snapc_seq(&op, dst_snap_seq, cls::rbd::ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ); } @@ -384,7 +386,7 @@ void ObjectCopyRequest::send_write_object() { } } - if (op.size() == (m_dst_image_ctx->migration_info.empty() ? 0 : 1)) { + if (op.size() == (migration ? 1 : 0)) { handle_write_object(0); return; } diff --git a/src/librbd/deep_copy/Types.h b/src/librbd/deep_copy/Types.h index 0b24dae2bec1d..e6aa980494b12 100644 --- a/src/librbd/deep_copy/Types.h +++ b/src/librbd/deep_copy/Types.h @@ -12,7 +12,8 @@ namespace librbd { namespace deep_copy { enum { - OBJECT_COPY_REQUEST_FLAG_FLATTEN = 1U << 0, + OBJECT_COPY_REQUEST_FLAG_FLATTEN = 1U << 0, + OBJECT_COPY_REQUEST_FLAG_MIGRATION = 1U << 1, }; typedef std::vector SnapIds; diff --git a/src/librbd/io/CopyupRequest.cc b/src/librbd/io/CopyupRequest.cc index f2422af526067..fb630cec72344 100644 --- a/src/librbd/io/CopyupRequest.cc +++ b/src/librbd/io/CopyupRequest.cc @@ -232,7 +232,7 @@ void CopyupRequest::deep_copy() { ldout(cct, 20) << "oid=" << m_oid << ", flatten=" << m_flatten << dendl; - uint32_t flags = 0; + uint32_t flags = deep_copy::OBJECT_COPY_REQUEST_FLAG_MIGRATION; if (m_flatten) { flags |= deep_copy::OBJECT_COPY_REQUEST_FLAG_FLATTEN; } diff --git a/src/librbd/operation/MigrateRequest.cc b/src/librbd/operation/MigrateRequest.cc index ddfd216c90e01..c6a14d6e9f607 100644 --- a/src/librbd/operation/MigrateRequest.cc +++ b/src/librbd/operation/MigrateRequest.cc @@ -130,7 +130,7 @@ private: } else { ceph_assert(image_ctx.parent != nullptr); - uint32_t flags = 0; + uint32_t flags = deep_copy::OBJECT_COPY_REQUEST_FLAG_MIGRATION; if (image_ctx.migration_info.flatten) { flags |= deep_copy::OBJECT_COPY_REQUEST_FLAG_FLATTEN; } -- 2.39.5