From: Haomai Wang Date: Fri, 21 Aug 2015 06:54:56 +0000 (+0800) Subject: librbd: Add ictx check to avoid AIO_TYPE_NONE completion X-Git-Tag: v10.0.2~142^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d19deacc018df08fe3491e820b53138cfa2eb6a7;p=ceph.git librbd: Add ictx check to avoid AIO_TYPE_NONE completion Signed-off-by: Haomai Wang --- diff --git a/src/librbd/AioCompletion.cc b/src/librbd/AioCompletion.cc index 9d25c0bd61fb..2c58046a9547 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 5094f64fc9f3..975c916fe6e0 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 69fc596421ff..c42c6fd57ef5 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 c0d4e5fe1f18..fdebf8943eb6 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 543837a5b682..94f27ed14796 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 0e450c734217..53ed8b80bb66 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()