]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/librbd/ImageWatcher.cc
import 15.2.5
[ceph.git] / ceph / src / librbd / ImageWatcher.cc
index 073123094d265c3f49af7ec02480f1da66ca60a8..c46549a78d3d57479732cb3bad6279f69801842e 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,16 @@ 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);
+      m_async_op_tracker.finish_op();
+      return;
     }
-  } else {
-    std::unique_lock async_request_locker{m_async_request_lock};
-    m_async_pending.erase(request);
   }
+
+  std::unique_lock async_request_locker{m_async_request_lock};
+  m_async_pending.erase(request);
+  m_async_op_tracker.finish_op();
 }
 
 template <typename I>