]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: refresh image after creating primary mirror snapshot
authorJason Dillaman <dillaman@redhat.com>
Thu, 27 Feb 2020 19:52:06 +0000 (14:52 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 2 Mar 2020 15:53:44 +0000 (10:53 -0500)
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 <dillaman@redhat.com>
src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
src/librbd/mirror/snapshot/CreatePrimaryRequest.h

index 3d9481d5240ee82cdf7d7be8b4f07c802d9ffc75..6c5cb5d9d50c3e975dd686dc1308e80d8040cfb4 100644 (file)
@@ -134,7 +134,39 @@ void CreatePrimaryRequest<I>::handle_create_snapshot(int r) {
     return;
   }
 
-  if (m_snap_id != nullptr) {
+  refresh_image();
+}
+
+template <typename I>
+void CreatePrimaryRequest<I>::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<I>,
+    &CreatePrimaryRequest<I>::handle_refresh_image>(this);
+  m_image_ctx->state->refresh(ctx);
+}
+
+template <typename I>
+void CreatePrimaryRequest<I>::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);
index aa00abe028470b203818727740def12aa9f1e49a..69c0ed4470198423a80bad74b558599d657f4a14 100644 (file)
@@ -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);