]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: wrap IOContext::aio_wake with additional stuff to remove copy-paste...
authorIgor Fedotov <ifedotov@mirantis.com>
Wed, 24 May 2017 13:37:34 +0000 (06:37 -0700)
committerIgor Fedotov <ifedotov@mirantis.com>
Wed, 24 May 2017 13:56:34 +0000 (06:56 -0700)
Signed-off-by: Igor Fedotov <ifedotov@mirantis.com>
src/os/bluestore/BlockDevice.h
src/os/bluestore/KernelDevice.cc
src/os/bluestore/NVMEDevice.cc

index 4448b2ef6defaf506d89969f96fed0327d07dee2..eb783a89269c12119f7c149e24a09f056d487a45 100644 (file)
 
 /// 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<aio_t> pending_aios;    ///< not yet submitted
   std::list<aio_t> running_aios;    ///< submitting or submitted
@@ -58,11 +61,15 @@ struct IOContext {
 
   void aio_wait();
 
-  void aio_wake() {
-    std::lock_guard<std::mutex> l(lock);
-    cond.notify_all();
-    --num_running;
-    assert(num_running == 0);
+  void try_aio_wake() {
+    if (num_running == 1) {
+      std::lock_guard<std::mutex> l(lock);
+      cond.notify_all();
+      --num_running;
+      assert(num_running == 0);
+    } else {
+      --num_running;
+    }
   }
 };
 
index 284f21c76192cf305380acb59fb2222240dc7eb7..0ee44c13a7c8ca54f30dc67300b6738536f35605 100644 (file)
@@ -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();
        }
       }
     }
index 89b8b5552a3e26512cb673aac1f2b7fb07c7ee8b..9d1a84066720ca670802b06e8050830a246634a9 100644 (file)
@@ -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 {