From d19deacc018df08fe3491e820b53138cfa2eb6a7 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Fri, 21 Aug 2015 14:54:56 +0800 Subject: [PATCH] librbd: Add ictx check to avoid AIO_TYPE_NONE completion Signed-off-by: Haomai Wang --- src/librbd/AioCompletion.cc | 2 +- src/librbd/AioCompletion.h | 6 +++--- src/librbd/ImageCtx.cc | 15 +++++++++++++++ src/librbd/ImageCtx.h | 1 + src/librbd/internal.cc | 1 + src/librbd/librbd.cc | 1 - 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/librbd/AioCompletion.cc b/src/librbd/AioCompletion.cc index 9d25c0bd61f..2c58046a954 100644 --- a/src/librbd/AioCompletion.cc +++ b/src/librbd/AioCompletion.cc @@ -105,7 +105,7 @@ namespace librbd { lock.Lock(); done = true; - if (event_notify && ictx->event_socket.is_valid()) { + if (ictx && event_notify && ictx->event_socket.is_valid()) { ictx->completed_reqs_lock.Lock(); ictx->completed_reqs.push_back(&m_xlist_item); ictx->completed_reqs_lock.Unlock(); diff --git a/src/librbd/AioCompletion.h b/src/librbd/AioCompletion.h index 5094f64fc9f..975c916fe6e 100644 --- a/src/librbd/AioCompletion.h +++ b/src/librbd/AioCompletion.h @@ -132,7 +132,7 @@ namespace librbd { int n = --ref; lock.Unlock(); if (!n) { - if (event_notify) { + if (ictx && event_notify) { ictx->completed_reqs_lock.Lock(); m_xlist_item.remove_myself(); ictx->completed_reqs_lock.Unlock(); @@ -155,9 +155,9 @@ namespace librbd { } } - void enable_event_notify() { + void set_event_notify(bool s) { Mutex::Locker l(lock); - event_notify = true; + event_notify = s; } void *get_arg() { diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 69fc596421f..c42c6fd57ef 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -11,6 +11,7 @@ #include "common/WorkQueue.h" #include "librbd/AioImageRequestWQ.h" +#include "librbd/AioCompletion.h" #include "librbd/AsyncOperation.h" #include "librbd/AsyncRequest.h" #include "librbd/internal.h" @@ -873,6 +874,20 @@ struct C_InvalidateCache : public Context { } } + void ImageCtx::clear_pending_completions() { + Mutex::Locker l(completed_reqs_lock); + ldout(cct, 10) << "clear pending AioCompletion: count=" + << completed_reqs.size() << dendl; + + for (xlist::iterator it = completed_reqs.begin(); + !it.end(); ++it) { + ldout(cct, 10) << "clear pending AioCompletion: " << *it << dendl; + (*it)->set_event_notify(false); + } + completed_reqs.clear(); + } + + bool ImageCtx::_filter_metadata_confs(const string &prefix, map &configs, map &pairs, map *res) { size_t conf_prefix_len = prefix.size(); diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index c0d4e5fe1f1..fdebf8943eb 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -261,6 +261,7 @@ namespace librbd { void open_journal(); int close_journal(bool force); + void clear_pending_completions(); }; } diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 543837a5b68..94f27ed1479 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -2898,6 +2898,7 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type, ictx->aio_work_queue->writes_empty()); ictx->cancel_async_requests(); + ictx->clear_pending_completions(); ictx->flush_async_operations(); ictx->readahead.wait_for_pending(); diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 0e450c73421..53ed8b80bb6 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -283,7 +283,6 @@ namespace librbd { complete_cb); pc = (void *)c; c->rbd_comp = this; - c->enable_event_notify(); } bool RBD::AioCompletion::is_complete() -- 2.47.3