From e359189d7289c37f12757b6c70e4329275f40263 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Wed, 22 Mar 2017 11:41:00 +0800 Subject: [PATCH] bluestore, NVMeDevice: use task' own lock for (random) read The reason is that ioc may be reaped in _aio_thread function with the following statements: for (auto &&it : registered_devices) it->reap_ioc(); So if we still use ioc's lock for (random) read, it will cause core dump. Signed-off-by: optimistyzy --- src/os/bluestore/NVMEDevice.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index 72d9b2d6365..beddc18f20d 100644 --- a/src/os/bluestore/NVMEDevice.cc +++ b/src/os/bluestore/NVMEDevice.cc @@ -106,6 +106,8 @@ struct Task { int64_t return_code; ceph::coarse_real_clock::time_point start; IORequest io_request; + std::mutex lock; + std::condition_variable cond; Task(NVMEDevice *dev, IOCommand c, uint64_t off, uint64_t l, int64_t rc = 0) : device(dev), command(c), offset(off), len(l), return_code(rc), @@ -139,6 +141,16 @@ struct Task { copied += need_copy; } } + + void io_wait() { + std::unique_lock l(lock); + cond.wait(l); + } + + void io_wake() { + std::lock_guard l(lock); + cond.notify_all(); + } }; class SharedDriverData { @@ -782,7 +794,7 @@ void io_complete(void *t, const struct spdk_nvme_cpl *completion) } else { task->return_code = 0; if(!--ctx->num_reading) { - ctx->aio_wake(); + task->io_wake(); } } } else { @@ -969,7 +981,7 @@ int NVMEDevice::read(uint64_t off, uint64_t len, bufferlist *pbl, driver->queue_task(t); while(t->return_code > 0) { - ioc->aio_wait(); + t->io_wait(); } pbl->push_back(std::move(p)); r = t->return_code; @@ -1035,7 +1047,7 @@ int NVMEDevice::read_random(uint64_t off, uint64_t len, char *buf, bool buffered driver->queue_task(t); while(t->return_code > 0) { - ioc.aio_wait(); + t->io_wait(); } r = t->return_code; delete t; -- 2.39.5