]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/librados_test_stub: aio_watch/aio_unwatch should be asynchronous
authorJason Dillaman <dillaman@redhat.com>
Tue, 10 Apr 2018 15:47:40 +0000 (11:47 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 12 Apr 2018 14:03:17 +0000 (10:03 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librados_test_stub/TestIoCtxImpl.cc
src/test/librados_test_stub/TestWatchNotify.cc
src/test/librados_test_stub/TestWatchNotify.h

index 6cfde3cdcac330d08c1ffca7041b39bd6e3c3f93..54c558ae5900d8830036ec3e9e02c1520c60d973 100644 (file)
@@ -136,7 +136,7 @@ int TestIoCtxImpl::aio_watch(const std::string& o, AioCompletionImpl *c,
     m_client->get_aio_finisher()->queue(ctx, -EBLACKLISTED);
   } else {
     m_client->get_watch_notify()->aio_watch(m_client, o, get_instance_id(),
-                                            handle, watch_ctx, ctx);
+                                            handle, nullptr, watch_ctx, ctx);
   }
   return 0;
 }
index 492c5a8dbc86a7e589a711ae1ba8ec8cafe81ad7..a2f2f69e24a6662197322f488206fd6d884c0513 100644 (file)
@@ -61,19 +61,41 @@ void TestWatchNotify::aio_flush(TestRadosClient *rados_client,
   rados_client->get_aio_finisher()->queue(on_finish);
 }
 
+int TestWatchNotify::watch(TestRadosClient *rados_client,
+                           const std::string& o, uint64_t gid,
+                           uint64_t *handle, librados::WatchCtx *ctx,
+                           librados::WatchCtx2 *ctx2) {
+  C_SaferCond cond;
+  aio_watch(rados_client, o, gid, handle, ctx, ctx2, &cond);
+  return cond.wait();
+}
+
 void TestWatchNotify::aio_watch(TestRadosClient *rados_client,
                                 const std::string& o, uint64_t gid,
                                 uint64_t *handle,
-                                librados::WatchCtx2 *watch_ctx,
+                                librados::WatchCtx *watch_ctx,
+                                librados::WatchCtx2 *watch_ctx2,
                                 Context *on_finish) {
-  int r = watch(rados_client, o, gid, handle, nullptr, watch_ctx);
-  rados_client->get_aio_finisher()->queue(on_finish, r);
+  auto ctx = new FunctionContext([=](int) {
+      execute_watch(rados_client, o, gid, handle, watch_ctx, watch_ctx2,
+                    on_finish);
+    });
+  rados_client->get_aio_finisher()->queue(ctx);
+}
+
+int TestWatchNotify::unwatch(TestRadosClient *rados_client,
+                             uint64_t handle) {
+  C_SaferCond ctx;
+  aio_unwatch(rados_client, handle, &ctx);
+  return ctx.wait();
 }
 
 void TestWatchNotify::aio_unwatch(TestRadosClient *rados_client,
                                   uint64_t handle, Context *on_finish) {
-  unwatch(rados_client, handle);
-  rados_client->get_aio_finisher()->queue(on_finish);
+  auto ctx = new FunctionContext([this, rados_client, handle, on_finish](int) {
+      execute_unwatch(rados_client, handle, on_finish);
+    });
+  rados_client->get_aio_finisher()->queue(ctx);
 }
 
 void TestWatchNotify::aio_notify(TestRadosClient *rados_client,
@@ -128,13 +150,14 @@ void TestWatchNotify::notify_ack(TestRadosClient *rados_client,
   finish_notify(rados_client, o, notify_id);
 }
 
-int TestWatchNotify::watch(TestRadosClient *rados_client,
-                           const std::string& o, uint64_t gid,
-                           uint64_t *handle, librados::WatchCtx *ctx,
-                           librados::WatchCtx2 *ctx2) {
+void TestWatchNotify::execute_watch(TestRadosClient *rados_client,
+                                    const std::string& o, uint64_t gid,
+                                    uint64_t *handle, librados::WatchCtx *ctx,
+                                    librados::WatchCtx2 *ctx2,
+                                    Context* on_finish) {
   CephContext *cct = rados_client->cct();
 
-  Mutex::Locker lock(m_lock);
+  m_lock.Lock();
   SharedWatcher watcher = get_watcher(o);
 
   WatchHandle watch_handle;
@@ -151,29 +174,33 @@ int TestWatchNotify::watch(TestRadosClient *rados_client,
 
   ldout(cct, 20) << "oid=" << o << ", gid=" << gid << ": handle=" << *handle
                 << dendl;
-  return 0;
+  m_lock.Unlock();
+
+  on_finish->complete(0);
 }
 
-int TestWatchNotify::unwatch(TestRadosClient *rados_client,
-                             uint64_t handle) {
+void TestWatchNotify::execute_unwatch(TestRadosClient *rados_client,
+                                      uint64_t handle, Context* on_finish) {
   CephContext *cct = rados_client->cct();
 
   ldout(cct, 20) << "handle=" << handle << dendl;
-  Mutex::Locker locker(m_lock);
-  for (FileWatchers::iterator it = m_file_watchers.begin();
-       it != m_file_watchers.end(); ++it) {
-    SharedWatcher watcher = it->second;
-
-    WatchHandles::iterator w_it = watcher->watch_handles.find(handle);
-    if (w_it != watcher->watch_handles.end()) {
-      watcher->watch_handles.erase(w_it);
-      if (watcher->watch_handles.empty() && watcher->notify_handles.empty()) {
-        m_file_watchers.erase(it);
+  {
+    Mutex::Locker locker(m_lock);
+    for (FileWatchers::iterator it = m_file_watchers.begin();
+         it != m_file_watchers.end(); ++it) {
+      SharedWatcher watcher = it->second;
+
+      WatchHandles::iterator w_it = watcher->watch_handles.find(handle);
+      if (w_it != watcher->watch_handles.end()) {
+        watcher->watch_handles.erase(w_it);
+        if (watcher->watch_handles.empty() && watcher->notify_handles.empty()) {
+          m_file_watchers.erase(it);
+        }
+        break;
       }
-      break;
     }
   }
-  return 0;
+  on_finish->complete(0);
 }
 
 TestWatchNotify::SharedWatcher TestWatchNotify::get_watcher(
index baf56cb7e1af45de1d10ca09d5f046011d1b9b49..04d37c2358d58135c87a7e51dbb5f88f7f0f13aa 100644 (file)
@@ -60,8 +60,8 @@ public:
 
   void aio_flush(TestRadosClient *rados_client, Context *on_finish);
   void aio_watch(TestRadosClient *rados_client, const std::string& o,
-                 uint64_t gid, uint64_t *handle, librados::WatchCtx2 *watch_ctx,
-                 Context *on_finish);
+                 uint64_t gid, uint64_t *handle, librados::WatchCtx *watch_ctx,
+                 librados::WatchCtx2 *watch_ctx2, Context *on_finish);
   void aio_unwatch(TestRadosClient *rados_client, uint64_t handle,
                    Context *on_finish);
   void aio_notify(TestRadosClient *rados_client, const std::string& oid,
@@ -96,6 +96,14 @@ private:
 
   SharedWatcher get_watcher(const std::string& oid);
 
+  void execute_watch(TestRadosClient *rados_client, const std::string& o,
+                     uint64_t gid, uint64_t *handle,
+                     librados::WatchCtx *watch_ctx,
+                     librados::WatchCtx2 *watch_ctx2,
+                     Context *on_finish);
+  void execute_unwatch(TestRadosClient *rados_client, uint64_t handle,
+                       Context *on_finish);
+
   void execute_notify(TestRadosClient *rados_client, const std::string &oid,
                       bufferlist &bl, uint64_t notify_id);
   void ack_notify(TestRadosClient *rados_client, const std::string &oid,