From d3d26875a3409397579394db6189a43273e95359 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Mon, 5 Sep 2016 16:14:52 +0000 Subject: [PATCH] fio: use ref counting for Engine instance Signed-off-by: Igor Fedotov --- src/test/fio/fio_ceph_objectstore.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/test/fio/fio_ceph_objectstore.cc b/src/test/fio/fio_ceph_objectstore.cc index ca86ec3731b4..2929374a04c8 100644 --- a/src/test/fio/fio_ceph_objectstore.cc +++ b/src/test/fio/fio_ceph_objectstore.cc @@ -66,6 +66,9 @@ struct Engine { boost::intrusive_ptr cct; std::unique_ptr os; + std::mutex lock; + int ref_count; + Engine(const thread_data* td); ~Engine(); @@ -74,9 +77,21 @@ struct Engine { static Engine engine(td); return &engine; } + + void ref() { + std::lock_guard l(lock); + ++ref_count; + } + void deref() { + std::lock_guard l(lock); + --ref_count; + if (!ref_count) { + os->umount(); + } + } }; -Engine::Engine(const thread_data* td) +Engine::Engine(const thread_data* td) : ref_count(0) { // add the ceph command line arguments auto o = static_cast(td->eo); @@ -119,7 +134,7 @@ Engine::Engine(const thread_data* td) Engine::~Engine() { - os->umount(); + assert(!ref_count); } @@ -161,6 +176,7 @@ Job::Job(Engine* engine, const thread_data* td) events(td->o.iodepth), unlink(td->o.unlink) { + engine->ref(); // use the fio thread_number for our unique pool id const uint64_t pool = Collection::MIN_POOL_ID + td->thread_number; @@ -205,8 +221,10 @@ Job::Job(Engine* engine, const thread_data* td) // apply the entire transaction synchronously ObjectStore::Sequencer sequencer("job init"); int r = engine->os->apply_transaction(&sequencer, std::move(t)); - if (r) + if (r) { + engine->deref(); throw std::system_error(r, std::system_category(), "job init"); + } } Job::~Job() @@ -226,6 +244,7 @@ Job::~Job() if (r) derr << "job cleanup failed with " << cpp_strerror(-r) << dendl; } + engine->deref(); } -- 2.47.3