From 30342ab67ee3c52c40e6e6b236f43c4d5e7b12ca Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Sat, 9 Jan 2016 00:27:49 +0800 Subject: [PATCH] BlockDevice: Move KernelDevice reap ioc to BlockDevice Signed-off-by: Haomai Wang --- src/os/bluestore/BlockDevice.cc | 20 ++++++++++++++++++++ src/os/bluestore/BlockDevice.h | 8 ++++++++ src/os/bluestore/KernelDevice.cc | 18 +----------------- src/os/bluestore/KernelDevice.h | 6 ------ 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/os/bluestore/BlockDevice.cc b/src/os/bluestore/BlockDevice.cc index 69bd64ff72e9b..aed2b80a05eae 100644 --- a/src/os/bluestore/BlockDevice.cc +++ b/src/os/bluestore/BlockDevice.cc @@ -54,3 +54,23 @@ BlockDevice *BlockDevice::create(const string& type, aio_callback_t cb, void *cb return NULL; } +void BlockDevice::queue_reap_ioc(IOContext *ioc) +{ + Mutex::Locker l(ioc_reap_lock); + if (ioc_reap_count.read() == 0) + ioc_reap_count.inc(); + ioc_reap_queue.push_back(ioc); +} + +void BlockDevice::reap_ioc() +{ + if (ioc_reap_count.read()) { + Mutex::Locker l(ioc_reap_lock); + for (auto p : ioc_reap_queue) { + dout(20) << __func__ << " reap ioc " << p << dendl; + delete p; + } + ioc_reap_queue.clear(); + ioc_reap_count.dec(); + } +} diff --git a/src/os/bluestore/BlockDevice.h b/src/os/bluestore/BlockDevice.h index 32b0d617da805..a5057260c5714 100644 --- a/src/os/bluestore/BlockDevice.h +++ b/src/os/bluestore/BlockDevice.h @@ -57,7 +57,12 @@ struct IOContext { class BlockDevice { + Mutex ioc_reap_lock; + vector ioc_reap_queue; + atomic_t ioc_reap_count; + public: + BlockDevice(): ioc_reap_lock("BlockDevice::ioc_reap_lock") {} virtual ~BlockDevice() {} typedef void (*aio_callback_t)(void *handle, void *aio); @@ -77,6 +82,9 @@ public: virtual int aio_zero(uint64_t off, uint64_t len, IOContext *ioc) = 0; virtual int flush() = 0; + void queue_reap_ioc(IOContext *ioc); + void reap_ioc(); + // for managing buffered readers/writers virtual int invalidate_cache(uint64_t off, uint64_t len) = 0; virtual int open(string path) = 0; diff --git a/src/os/bluestore/KernelDevice.cc b/src/os/bluestore/KernelDevice.cc index 03c509039cba7..9dfa820b148ea 100644 --- a/src/os/bluestore/KernelDevice.cc +++ b/src/os/bluestore/KernelDevice.cc @@ -36,7 +36,6 @@ KernelDevice::KernelDevice(aio_callback_t cb, void *cbpriv) size(0), block_size(0), fs(NULL), aio(false), dio(false), debug_lock("KernelDevice::debug_lock"), - ioc_reap_lock("KernelDevice::ioc_reap_lock"), flush_lock("KernelDevice::flush_lock"), aio_queue(g_conf->bdev_aio_max_queue_depth), aio_callback(cb), @@ -257,15 +256,7 @@ void KernelDevice::_aio_thread() } } } - if (ioc_reap_count.read()) { - Mutex::Locker l(ioc_reap_lock); - for (auto p : ioc_reap_queue) { - dout(20) << __func__ << " reap ioc " << p << dendl; - delete p; - } - ioc_reap_queue.clear(); - ioc_reap_count.dec(); - } + reap_ioc(); } dout(10) << __func__ << " end" << dendl; } @@ -532,10 +523,3 @@ int KernelDevice::invalidate_cache(uint64_t off, uint64_t len) return r; } -void KernelDevice::queue_reap_ioc(IOContext *ioc) -{ - Mutex::Locker l(ioc_reap_lock); - if (ioc_reap_count.read() == 0) - ioc_reap_count.inc(); - ioc_reap_queue.push_back(ioc); -} diff --git a/src/os/bluestore/KernelDevice.h b/src/os/bluestore/KernelDevice.h index 454ac825ba046..a61f4e9bfbfdd 100644 --- a/src/os/bluestore/KernelDevice.h +++ b/src/os/bluestore/KernelDevice.h @@ -32,10 +32,6 @@ class KernelDevice : public BlockDevice { Mutex debug_lock; interval_set debug_inflight; - Mutex ioc_reap_lock; - vector ioc_reap_queue; - atomic_t ioc_reap_count; - Mutex flush_lock; atomic_t io_since_flush; @@ -86,8 +82,6 @@ public: IOContext *ioc) override; int flush() override; - void queue_reap_ioc(IOContext *ioc); - // for managing buffered readers/writers int invalidate_cache(uint64_t off, uint64_t len) override; int open(string path) override; -- 2.39.5