]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: fix race between replay shutdown and notification
authorJason Dillaman <dillaman@redhat.com>
Sun, 22 Dec 2019 22:56:59 +0000 (17:56 -0500)
committerJason Dillaman <dillaman@redhat.com>
Tue, 24 Dec 2019 14:35:43 +0000 (09:35 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd_mirror/ImageReplayer.cc

index f75d2962f50d3a5211a4e13324737f3608490a87..e993e55507db7bdaa62c601e120b06303d1b18cc 100644 (file)
@@ -961,26 +961,27 @@ template <typename I>
 void ImageReplayer<I>::handle_replayer_notification() {
   dout(10) << dendl;
 
-  // detect a rename of the local image
-  std::string local_image_name;
-  {
-    std::shared_lock image_locker{m_local_image_ctx->image_lock};
-    local_image_name = m_local_image_ctx->name;
+  std::unique_lock locker{m_lock};
+  if (m_state != STATE_REPLAYING) {
+    // might be attempting to shut down
+    return;
   }
 
   {
-    std::unique_lock locker{m_lock};
-    ceph_assert(m_state == STATE_REPLAYING);
-    ceph_assert(m_replayer != nullptr);
-
-    if (m_local_image_name != local_image_name) {
+    // detect a rename of the local image
+    ceph_assert(m_local_image_ctx != nullptr);
+    std::shared_lock image_locker{m_local_image_ctx->image_lock};
+    if (m_local_image_name != m_local_image_ctx->name) {
       // will re-register with new name after next status update
       dout(10) << "image renamed" << dendl;
-      m_local_image_name = local_image_name;
+      m_local_image_name = m_local_image_ctx->name;
     }
   }
 
   // replayer cannot be shut down while notification is in-flight
+  ceph_assert(m_replayer != nullptr);
+  locker.unlock();
+
   if (m_replayer->is_resync_requested()) {
     dout(10) << "resync requested" << dendl;
     m_resync_requested = true;