From: Igor Fedotov Date: Mon, 5 Sep 2016 16:14:52 +0000 (+0000) Subject: fio: use ref counting for Engine instance X-Git-Tag: v11.0.1~218^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F10267%2Fhead;p=ceph.git fio: use ref counting for Engine instance Signed-off-by: Igor Fedotov --- 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(); }