From: Mykola Golub Date: Wed, 8 Jul 2020 15:04:12 +0000 (+0100) Subject: librbd: don't resend async_complete if watcher is unregistered X-Git-Tag: v14.2.12~70^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=02dd07ab4029ea1ae545cd979ba0672dbd094cfb;p=ceph.git 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) Conflicts: src/librbd/ImageWatcher.cc: FunctionContext vs LambdaContext src/librbd/ImageWatcher.h: headers --- diff --git a/src/librbd/ImageWatcher.cc b/src/librbd/ImageWatcher.cc index f73a782dd604..c504df2f55a8 100644 --- a/src/librbd/ImageWatcher.cc +++ b/src/librbd/ImageWatcher.cc @@ -86,6 +86,9 @@ void ImageWatcher::unregister_watch(Context *on_finish) { cancel_async_requests(); + on_finish = new FunctionContext([this, on_finish](int r) { + m_async_op_tracker.wait_for_ops(on_finish); + }); FunctionContext *ctx = new FunctionContext([this, on_finish](int r) { m_task_finisher->cancel_all(on_finish); }); @@ -127,6 +130,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(); FunctionContext *ctx = new FunctionContext( boost::bind(&ImageWatcher::notify_async_complete, this, request, r)); m_task_finisher->queue(ctx); @@ -152,13 +156,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 { RWLock::WLocker 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 441a7d696ad3..7d04f0b4abda 100644 --- a/src/librbd/ImageWatcher.h +++ b/src/librbd/ImageWatcher.h @@ -7,6 +7,7 @@ #include "cls/rbd/cls_rbd_types.h" #include "common/Mutex.h" #include "common/RWLock.h" +#include "common/AsyncOpTracker.h" #include "include/Context.h" #include "include/rbd/librbd.hpp" #include "librbd/Watcher.h" @@ -172,6 +173,8 @@ private: 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();