From: Igor Fedotov Date: Wed, 24 May 2017 13:37:34 +0000 (-0700) Subject: os/bluestore: wrap IOContext::aio_wake with additional stuff to remove copy-paste... X-Git-Tag: v12.1.0~57^2~44^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3cd35b9f99940f6aa1ec4ae0b1832bae7103d38d;p=ceph.git os/bluestore: wrap IOContext::aio_wake with additional stuff to remove copy-paste for its use Signed-off-by: Igor Fedotov --- diff --git a/src/os/bluestore/BlockDevice.h b/src/os/bluestore/BlockDevice.h index 4448b2ef6def..eb783a89269c 100644 --- a/src/os/bluestore/BlockDevice.h +++ b/src/os/bluestore/BlockDevice.h @@ -29,6 +29,11 @@ /// track in-flight io struct IOContext { +private: + std::mutex lock; + std::condition_variable cond; + +public: CephContext* cct; void *priv; #ifdef HAVE_SPDK @@ -36,8 +41,6 @@ struct IOContext { void *nvme_task_last = nullptr; #endif - std::mutex lock; - std::condition_variable cond; std::list pending_aios; ///< not yet submitted std::list running_aios; ///< submitting or submitted @@ -58,11 +61,15 @@ struct IOContext { void aio_wait(); - void aio_wake() { - std::lock_guard l(lock); - cond.notify_all(); - --num_running; - assert(num_running == 0); + void try_aio_wake() { + if (num_running == 1) { + std::lock_guard l(lock); + cond.notify_all(); + --num_running; + assert(num_running == 0); + } else { + --num_running; + } } }; diff --git a/src/os/bluestore/KernelDevice.cc b/src/os/bluestore/KernelDevice.cc index 284f21c76192..0ee44c13a7c8 100644 --- a/src/os/bluestore/KernelDevice.cc +++ b/src/os/bluestore/KernelDevice.cc @@ -380,11 +380,7 @@ void KernelDevice::_aio_thread() aio_callback(aio_callback_priv, ioc->priv); } } else { - if (ioc->num_running == 1) { - ioc->aio_wake(); - } else { - --ioc->num_running; - } + ioc->try_aio_wake(); } } } diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index 89b8b5552a3e..9d1a84066720 100644 --- a/src/os/bluestore/NVMEDevice.cc +++ b/src/os/bluestore/NVMEDevice.cc @@ -816,11 +816,7 @@ void io_complete(void *t, const struct spdk_nvme_cpl *completion) task->device->aio_callback(task->device->aio_callback_priv, ctx->priv); } } else { - if (ctx->num_running == 1) { - ctx->aio_wake(); - } else { - --ctx->num_running; - } + ctx->try_aio_wake(); } task->release_segs(queue); delete task; @@ -837,11 +833,7 @@ void io_complete(void *t, const struct spdk_nvme_cpl *completion) task->device->aio_callback(task->device->aio_callback_priv, ctx->priv); } } else { - if (ctx->num_running == 1) { - ctx->aio_wake(); - } else { - --ctx->num_running; - } + ctx->try_aio_wake(); } delete task; } else {