From dbcba7173126cf999c3cc6247309b470eadf6ce8 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Mon, 22 Feb 2021 12:54:43 +0000 Subject: [PATCH] librbd: use on-disk image name when storing mirror snapshot state Fixes: https://tracker.ceph.com/issues/49115 Signed-off-by: Mykola Golub (cherry picked from commit 813728ae2036231a269be86bcb3dc48951a20f21) --- .../mirror/snapshot/SetImageStateRequest.cc | 40 ++++++++++++++++++- .../mirror/snapshot/SetImageStateRequest.h | 6 +++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/librbd/mirror/snapshot/SetImageStateRequest.cc b/src/librbd/mirror/snapshot/SetImageStateRequest.cc index d0caccdf58aee..5b03d89b31794 100644 --- a/src/librbd/mirror/snapshot/SetImageStateRequest.cc +++ b/src/librbd/mirror/snapshot/SetImageStateRequest.cc @@ -27,6 +27,45 @@ using librbd::util::create_rados_callback; template void SetImageStateRequest::send() { + get_name(); +} + +template +void SetImageStateRequest::get_name() { + CephContext *cct = m_image_ctx->cct; + ldout(cct, 15) << dendl; + + librados::ObjectReadOperation op; + cls_client::dir_get_name_start(&op, m_image_ctx->id); + + librados::AioCompletion *comp = create_rados_callback< + SetImageStateRequest, + &SetImageStateRequest::handle_get_name>(this); + m_bl.clear(); + int r = m_image_ctx->md_ctx.aio_operate(RBD_DIRECTORY, comp, &op, &m_bl); + ceph_assert(r == 0); + comp->release(); +} + +template +void SetImageStateRequest::handle_get_name(int r) { + CephContext *cct = m_image_ctx->cct; + ldout(cct, 15) << "r=" << r << dendl; + + if (r == 0) { + auto it = m_bl.cbegin(); + r = cls_client::dir_get_name_finish(&it, &m_image_state.name); + } + + if (r < 0) { + lderr(cct) << "failed to retrieve image name: " << cpp_strerror(r) + << dendl; + finish(r); + return; + } + + ldout(cct, 15) << "name=" << m_image_state.name << dendl; + get_snap_limit(); } @@ -99,7 +138,6 @@ void SetImageStateRequest::handle_get_metadata(int r) { { std::shared_lock image_locker{m_image_ctx->image_lock}; - m_image_state.name = m_image_ctx->name; m_image_state.features = m_image_ctx->features & ~RBD_FEATURES_IMPLICIT_ENABLE; diff --git a/src/librbd/mirror/snapshot/SetImageStateRequest.h b/src/librbd/mirror/snapshot/SetImageStateRequest.h index df903a279ab87..fd281549489bd 100644 --- a/src/librbd/mirror/snapshot/SetImageStateRequest.h +++ b/src/librbd/mirror/snapshot/SetImageStateRequest.h @@ -40,6 +40,9 @@ private: * * | * v + * GET_NAME + * | + * v * GET_SNAP_LIMIT * | * v @@ -66,6 +69,9 @@ private: bufferlist m_bl; bufferlist m_state_bl; + void get_name(); + void handle_get_name(int r); + void get_snap_limit(); void handle_get_snap_limit(int r); -- 2.39.5