]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: don't resend async_complete if watcher is unregistered
authorMykola Golub <mgolub@suse.com>
Wed, 8 Jul 2020 15:04:12 +0000 (16:04 +0100)
committerNathan Cutler <ncutler@suse.com>
Sat, 15 Aug 2020 13:17:05 +0000 (15:17 +0200)
Also wait for pending async_complete after unregistering the
watcher.

Fixes: https://tracker.ceph.com/issues/45268
Signed-off-by: Mykola Golub <mgolub@suse.com>
(cherry picked from commit 5b6804e19a8f524ab1528a638eb286482e12fe48)

src/librbd/ImageWatcher.cc
src/librbd/ImageWatcher.h

index 073123094d265c3f49af7ec02480f1da66ca60a8..69b7f7682d08d44a7fe9f4ae7e98d02b0f7ebbb2 100644 (file)
@@ -88,6 +88,9 @@ void ImageWatcher<I>::unregister_watch(Context *on_finish) {
 
   cancel_async_requests();
 
+  on_finish = new LambdaContext([this, on_finish](int r) {
+    m_async_op_tracker.wait_for_ops(on_finish);
+  });
   auto ctx = new LambdaContext([this, on_finish](int r) {
     m_task_finisher->cancel_all(on_finish);
   });
@@ -129,6 +132,7 @@ int ImageWatcher<I>::notify_async_progress(const AsyncRequestId &request,
 template <typename I>
 void ImageWatcher<I>::schedule_async_complete(const AsyncRequestId &request,
                                               int r) {
+  m_async_op_tracker.start_op();
   auto ctx = new LambdaContext(
     boost::bind(&ImageWatcher<I>::notify_async_complete, this, request, r));
   m_task_finisher->queue(ctx);
@@ -154,13 +158,15 @@ void ImageWatcher<I>::handle_async_complete(const AsyncRequestId &request,
   if (ret_val < 0) {
     lderr(m_image_ctx.cct) << this << " failed to notify async complete: "
                           << cpp_strerror(ret_val) << dendl;
-    if (ret_val == -ETIMEDOUT) {
+    if (ret_val == -ETIMEDOUT && !is_unregistered()) {
       schedule_async_complete(request, r);
     }
   } else {
     std::unique_lock async_request_locker{m_async_request_lock};
     m_async_pending.erase(request);
   }
+
+  m_async_op_tracker.finish_op();
 }
 
 template <typename I>
index 1ae54d80bfd4b5fd099762323f6bc97c93467030..2d97467617e8dfb3f8ad219bee324e7780517bfb 100644 (file)
@@ -5,6 +5,7 @@
 #define CEPH_LIBRBD_IMAGE_WATCHER_H
 
 #include "cls/rbd/cls_rbd_types.h"
+#include "common/AsyncOpTracker.h"
 #include "common/ceph_mutex.h"
 #include "include/Context.h"
 #include "include/rbd/librbd.hpp"
@@ -171,6 +172,8 @@ private:
   ceph::mutex m_owner_client_id_lock;
   watch_notify::ClientId m_owner_client_id;
 
+  AsyncOpTracker m_async_op_tracker;
+
   void handle_register_watch(int r);
 
   void schedule_cancel_async_requests();