]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
fio: use ref counting for Engine instance 10267/head
authorIgor Fedotov <ifedotov@mirantis.com>
Mon, 5 Sep 2016 16:14:52 +0000 (16:14 +0000)
committerCasey Bodley <cbodley@redhat.com>
Tue, 13 Sep 2016 15:07:04 +0000 (11:07 -0400)
Signed-off-by: Igor Fedotov <ifedotov@mirantis.com>
src/test/fio/fio_ceph_objectstore.cc

index ca86ec3731b4ac72510b63c286ef34cd67dbd037..2929374a04c8a93377617a57653f1fe0c528d906 100644 (file)
@@ -66,6 +66,9 @@ struct Engine {
   boost::intrusive_ptr<CephContext> cct;
   std::unique_ptr<ObjectStore> 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<std::mutex> l(lock);
+    ++ref_count;
+  }
+  void deref() {
+    std::lock_guard<std::mutex> 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<const Options*>(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();
 }