From: Jason Dillaman Date: Thu, 27 Feb 2020 19:52:06 +0000 (-0500) Subject: librbd: refresh image after creating primary mirror snapshot X-Git-Tag: v15.1.1~153^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bcb7d6698bba0906f35199b55808944f98119df3;p=ceph.git 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 --- diff --git a/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc b/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc index 3d9481d5240e..6c5cb5d9d50c 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 aa00abe02847..69c0ed447019 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);