From d80e7599c13abcc47efc347a50c5886af9843452 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Wed, 8 Jul 2020 16:04:12 +0100 Subject: [PATCH] librbd: don't resend async_complete if watcher is unregistered Also wait for pending async_complete after unregistering the watcher. Fixes: https://tracker.ceph.com/issues/45268 Signed-off-by: Mykola Golub (cherry picked from commit 5b6804e19a8f524ab1528a638eb286482e12fe48) --- src/librbd/ImageWatcher.cc | 8 +++++++- src/librbd/ImageWatcher.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librbd/ImageWatcher.cc b/src/librbd/ImageWatcher.cc index 073123094d265..69b7f7682d08d 100644 --- a/src/librbd/ImageWatcher.cc +++ b/src/librbd/ImageWatcher.cc @@ -88,6 +88,9 @@ void ImageWatcher::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::notify_async_progress(const AsyncRequestId &request, template void ImageWatcher::schedule_async_complete(const AsyncRequestId &request, int r) { + m_async_op_tracker.start_op(); auto ctx = new LambdaContext( boost::bind(&ImageWatcher::notify_async_complete, this, request, r)); m_task_finisher->queue(ctx); @@ -154,13 +158,15 @@ void ImageWatcher::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 diff --git a/src/librbd/ImageWatcher.h b/src/librbd/ImageWatcher.h index 1ae54d80bfd4b..2d97467617e8d 100644 --- a/src/librbd/ImageWatcher.h +++ b/src/librbd/ImageWatcher.h @@ -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(); -- 2.39.5