]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados_test_stub: add support for new aio_notify API
authorJason Dillaman <dillaman@redhat.com>
Wed, 24 Jun 2015 22:35:58 +0000 (18:35 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 6 Nov 2015 01:42:40 +0000 (20:42 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librados_test_stub/LibradosTestStub.cc
src/test/librados_test_stub/TestIoCtxImpl.cc
src/test/librados_test_stub/TestIoCtxImpl.h
src/test/librados_test_stub/TestRadosClient.cc
src/test/librados_test_stub/TestRadosClient.h
src/test/librados_test_stub/TestWatchNotify.cc
src/test/librados_test_stub/TestWatchNotify.h

index 2a0006e662d25324d76c555185bdd60c957971b6..80690897af1acd8d7f7d95970fd873d4b484716e 100644 (file)
@@ -354,6 +354,13 @@ int IoCtx::aio_flush_async(AioCompletion *c) {
   return 0;
 }
 
+int IoCtx::aio_notify(const std::string& oid, AioCompletion *c, bufferlist& bl,
+                      uint64_t timeout_ms, bufferlist *pbl) {
+  TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl);
+  ctx->aio_notify(oid, c->pc, bl, timeout_ms, pbl);
+  return 0;
+}
+
 int IoCtx::aio_operate(const std::string& oid, AioCompletion *c,
                        ObjectReadOperation *op, bufferlist *pbl) {
   return aio_operate(oid, c, op, 0, pbl);
index 30c1e13a3811ef79c0d873d4180e759ea585e765..ebb5d745232c31f16c536b33a36d3d9da8e077bf 100644 (file)
@@ -90,6 +90,15 @@ void TestIoCtxImpl::aio_flush_async(AioCompletionImpl *c) {
   m_client->flush_aio_operations(c);
 }
 
+void TestIoCtxImpl::aio_notify(const std::string& oid, AioCompletionImpl *c,
+                               bufferlist& bl, uint64_t timeout_ms,
+                               bufferlist *pbl) {
+  m_pending_ops.inc();
+  c->get();
+  C_AioNotify *ctx = new C_AioNotify(this, c);
+  m_client->get_watch_notify().aio_notify(oid, bl, timeout_ms, pbl, ctx);
+}
+
 int TestIoCtxImpl::aio_operate(const std::string& oid, TestObjectOperationImpl &ops,
                                AioCompletionImpl *c, SnapContext *snap_context,
                                int flags) {
@@ -274,4 +283,10 @@ int TestIoCtxImpl::execute_aio_operations(const std::string& oid,
   return ret;
 }
 
+void TestIoCtxImpl::handle_aio_notify_complete(AioCompletionImpl *c, int r) {
+  m_pending_ops.dec();
+
+  m_client->finish_aio_completion(c, r);
+}
+
 } // namespace librados
index 450ee59d7132e038d60736c79dc75503be01ae0d..4d924f4988381f6d6ffb0c1eba6b8c619bfa4161 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "include/rados/librados.hpp"
 #include "include/atomic.h"
+#include "include/Context.h"
 #include "common/snap_types.h"
 #include <boost/function.hpp>
 #include <list>
@@ -71,6 +72,8 @@ public:
 
   virtual int aio_flush();
   virtual void aio_flush_async(AioCompletionImpl *c);
+  virtual void aio_notify(const std::string& oid, AioCompletionImpl *c,
+                          bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl);
   virtual int aio_operate(const std::string& oid, TestObjectOperationImpl &ops,
                           AioCompletionImpl *c, SnapContext *snap_context,
                           int flags);
@@ -150,6 +153,16 @@ protected:
                              bufferlist *pbl, const SnapContext &snapc);
 
 private:
+  struct C_AioNotify : public Context {
+    TestIoCtxImpl *io_ctx;
+    AioCompletionImpl *aio_comp;
+    C_AioNotify(TestIoCtxImpl *_io_ctx, AioCompletionImpl *_aio_comp)
+      : io_ctx(_io_ctx), aio_comp(_aio_comp) {
+    }
+    virtual void finish(int r) {
+      io_ctx->handle_aio_notify_complete(aio_comp, r);
+    }
+  };
 
   TestRadosClient *m_client;
   int64_t m_pool_id;
@@ -158,6 +171,7 @@ private:
   SnapContext m_snapc;
   atomic_t m_refcount;
 
+  void handle_aio_notify_complete(AioCompletionImpl *aio_comp, int r);
 };
 
 } // namespace librados
index 46437ac8657e329aba6dd59b48988d3a7010e758..1a9792c6e0209f3ae4eae839192830ba44d00274 100644 (file)
@@ -221,6 +221,10 @@ void TestRadosClient::flush_aio_operations(AioCompletionImpl *c) {
   }
 }
 
+void TestRadosClient::finish_aio_completion(AioCompletionImpl *c, int r) {
+  librados::finish_aio_completion(c, r);
+}
+
 Finisher *TestRadosClient::get_finisher(const std::string &oid) {
   std::size_t h = m_hash(oid);
   return m_finishers[h % m_finishers.size()];
index ad0cf676dd04f188049ce25f74843be122886321..d3c20349e74dba438aefbb0710532f396c193767 100644 (file)
@@ -99,6 +99,8 @@ public:
   void flush_aio_operations();
   void flush_aio_operations(AioCompletionImpl *c);
 
+  void finish_aio_completion(AioCompletionImpl *c, int r);
+
 protected:
   virtual ~TestRadosClient();
 
index 14a43bc58cb1cf7bc56b3a1201e4995e82a42fce..ef8f5378fae9c8b88c6bcd620f1c8611426d173a 100644 (file)
@@ -58,38 +58,31 @@ int TestWatchNotify::list_watchers(const std::string& o,
   return 0;
 }
 
+void TestWatchNotify::aio_notify(const std::string& oid, bufferlist& bl,
+                                 uint64_t timeout_ms, bufferlist *pbl,
+                                 Context *on_notify) {
+  SharedWatcher watcher = get_watcher(oid);
+  RWLock::WLocker watcher_locker(watcher->lock);
+  Mutex::Locker file_watcher_lock(m_file_watcher_lock);
+  ++m_pending_notifies;
+  uint64_t notify_id = ++m_notify_id;
+
+  SharedNotifyHandle notify_handle(new NotifyHandle());
+  notify_handle->pbl = pbl;
+
+  watcher->notify_handles[notify_id] = notify_handle;
+
+  FunctionContext *ctx = new FunctionContext(
+      boost::bind(&TestWatchNotify::execute_notify, this,
+                  oid, bl, notify_id, on_notify));
+  m_finisher->queue(ctx);
+}
+
 int TestWatchNotify::notify(const std::string& oid, bufferlist& bl,
                             uint64_t timeout_ms, bufferlist *pbl) {
-  Mutex lock("TestRadosClient::watcher_notify::lock");
-  Cond cond;
-  bool done = false;
-
-  {
-    SharedWatcher watcher = get_watcher(oid);
-    RWLock::WLocker l(watcher->lock);
-    {
-      Mutex::Locker l2(m_file_watcher_lock);
-      ++m_pending_notifies;
-      uint64_t notify_id = ++m_notify_id;
-
-      SharedNotifyHandle notify_handle(new NotifyHandle());
-      notify_handle->pbl = pbl;
-
-      watcher->notify_handles[notify_id] = notify_handle;
-
-      FunctionContext *ctx = new FunctionContext(
-          boost::bind(&TestWatchNotify::execute_notify, this,
-                      oid, bl, notify_id, &lock, &cond, &done));
-      m_finisher->queue(ctx);
-    }
-  }
-
-  lock.Lock();
-  while (!done) {
-    cond.Wait(lock);
-  }
-  lock.Unlock();
-  return 0;
+  C_SaferCond cond;
+  aio_notify(oid, bl, timeout_ms, pbl, &cond);
+  return cond.wait();
 }
 
 void TestWatchNotify::notify_ack(const std::string& o, uint64_t notify_id,
@@ -169,8 +162,7 @@ TestWatchNotify::SharedWatcher TestWatchNotify::_get_watcher(
 
 void TestWatchNotify::execute_notify(const std::string &oid,
                                      bufferlist &bl, uint64_t notify_id,
-                                     Mutex *lock, Cond *cond,
-                                     bool *done) {
+                                     Context *on_notify) {
   WatchHandles watch_handles;
   SharedNotifyHandle notify_handle;
 
@@ -218,15 +210,11 @@ void TestWatchNotify::execute_notify(const std::string &oid,
     }
   }
 
-  Mutex::Locker l3(*lock);
-  *done = true;
-  cond->Signal();
+  on_notify->complete(0);
 
-  {
-    Mutex::Locker file_watcher_locker(m_file_watcher_lock);
-    if (--m_pending_notifies == 0) {
-      m_file_watcher_cond.Signal();
-    }
+  Mutex::Locker file_watcher_locker(m_file_watcher_lock);
+  if (--m_pending_notifies == 0) {
+    m_file_watcher_cond.Signal();
   }
 }
 
index 1761302bbf37bde86e16895f4fc1ccb263d22a22..6f99704784eb1809a87b89ac1cd7a4f2e8f14ffd 100644 (file)
@@ -57,6 +57,8 @@ public:
   void flush();
   int list_watchers(const std::string& o,
                     std::list<obj_watch_t> *out_watchers);
+  void aio_notify(const std::string& oid, bufferlist& bl, uint64_t timeout_ms,
+                  bufferlist *pbl, Context *on_notify);
   int notify(const std::string& o, bufferlist& bl,
              uint64_t timeout_ms, bufferlist *pbl);
   void notify_ack(const std::string& o, uint64_t notify_id,
@@ -84,7 +86,7 @@ private:
   SharedWatcher get_watcher(const std::string& oid);
   SharedWatcher _get_watcher(const std::string& oid);
   void execute_notify(const std::string &oid, bufferlist &bl,
-                      uint64_t notify_id, Mutex *lock, Cond *cond, bool *done);
+                      uint64_t notify_id, Context *on_notify);
 
 };