From bcb7d6698bba0906f35199b55808944f98119df3 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 27 Feb 2020 14:52:06 -0500 Subject: [PATCH] librbd: refresh image after creating primary mirror snapshot If RPC was used to create the snapshot, the local image context will not yet have the snapshot id and will therefore return CEPH_NOSNAP. Signed-off-by: Jason Dillaman --- .../mirror/snapshot/CreatePrimaryRequest.cc | 34 ++++++++++++++++++- .../mirror/snapshot/CreatePrimaryRequest.h | 6 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc b/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc index 3d9481d5240..6c5cb5d9d50 100644 --- a/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc +++ b/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc @@ -134,7 +134,39 @@ void CreatePrimaryRequest::handle_create_snapshot(int r) { return; } - if (m_snap_id != nullptr) { + refresh_image(); +} + +template +void CreatePrimaryRequest::refresh_image() { + // if snapshot created via remote RPC, refresh is required to retrieve + // the snapshot id + if (m_snap_id == nullptr) { + unlink_peer(); + return; + } + + CephContext *cct = m_image_ctx->cct; + ldout(cct, 20) << dendl; + + auto ctx = create_context_callback< + CreatePrimaryRequest, + &CreatePrimaryRequest::handle_refresh_image>(this); + m_image_ctx->state->refresh(ctx); +} + +template +void CreatePrimaryRequest::handle_refresh_image(int r) { + CephContext *cct = m_image_ctx->cct; + ldout(cct, 20) << "r=" << r << dendl; + + if (r < 0) { + lderr(cct) << "failed to refresh image: " << cpp_strerror(r) << dendl; + finish(r); + return; + } + + { std::shared_lock image_locker{m_image_ctx->image_lock}; *m_snap_id = m_image_ctx->get_snap_id( cls::rbd::MirrorSnapshotNamespace{}, m_snap_name); diff --git a/src/librbd/mirror/snapshot/CreatePrimaryRequest.h b/src/librbd/mirror/snapshot/CreatePrimaryRequest.h index aa00abe0284..69c0ed44701 100644 --- a/src/librbd/mirror/snapshot/CreatePrimaryRequest.h +++ b/src/librbd/mirror/snapshot/CreatePrimaryRequest.h @@ -51,6 +51,9 @@ private: * CREATE_SNAPSHOT * | * v + * REFRESH_IMAGE + * | + * v * UNLINK_PEER (skip if not needed, * | repeat if needed) * v @@ -77,6 +80,9 @@ private: void create_snapshot(); void handle_create_snapshot(int r); + void refresh_image(); + void handle_refresh_image(int r); + void unlink_peer(); void handle_unlink_peer(int r); -- 2.39.5