]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-mirror: abort trash watcher initialization if create blacklisted
authorJason Dillaman <dillaman@redhat.com>
Thu, 21 Feb 2019 17:37:38 +0000 (12:37 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 25 Feb 2019 19:22:24 +0000 (14:22 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/image_deleter/test_mock_TrashWatcher.cc
src/tools/rbd_mirror/image_deleter/TrashWatcher.cc

index adb47c53d800ae7f06411c6711e51cf261fa20c5..034c3e5497dae1eb02d31f2fd5f007f5a7d94a88 100644 (file)
@@ -291,6 +291,44 @@ TEST_F(TestMockImageDeleterTrashWatcher, Notify) {
   ASSERT_EQ(0, when_shut_down(mock_trash_watcher));
 }
 
+TEST_F(TestMockImageDeleterTrashWatcher, CreateBlacklist) {
+  MockThreads mock_threads(m_threads);
+  expect_work_queue(mock_threads);
+
+  InSequence seq;
+  expect_create_trash(m_local_io_ctx, -EBLACKLISTED);
+
+  MockListener mock_listener;
+  MockTrashWatcher mock_trash_watcher(m_local_io_ctx, &mock_threads,
+                                      mock_listener);
+  C_SaferCond ctx;
+  mock_trash_watcher.init(&ctx);
+  ASSERT_EQ(-EBLACKLISTED, ctx.wait());
+
+  MockLibrbdTrashWatcher mock_librbd_trash_watcher;
+  expect_trash_watcher_unregister(mock_librbd_trash_watcher, 0);
+  ASSERT_EQ(0, when_shut_down(mock_trash_watcher));
+}
+
+TEST_F(TestMockImageDeleterTrashWatcher, CreateDNE) {
+  MockThreads mock_threads(m_threads);
+  expect_work_queue(mock_threads);
+
+  InSequence seq;
+  expect_create_trash(m_local_io_ctx, -ENOENT);
+
+  MockListener mock_listener;
+  MockTrashWatcher mock_trash_watcher(m_local_io_ctx, &mock_threads,
+                                      mock_listener);
+  C_SaferCond ctx;
+  mock_trash_watcher.init(&ctx);
+  ASSERT_EQ(-ENOENT, ctx.wait());
+
+  MockLibrbdTrashWatcher mock_librbd_trash_watcher;
+  expect_trash_watcher_unregister(mock_librbd_trash_watcher, 0);
+  ASSERT_EQ(0, when_shut_down(mock_trash_watcher));
+}
+
 TEST_F(TestMockImageDeleterTrashWatcher, CreateError) {
   MockThreads mock_threads(m_threads);
   expect_work_queue(mock_threads);
index cb4f78d94611ee0178a196fc26569d8cf41e5deb..8735dfb7df584b4d567ab50a2c17db7c6c7e6417 100644 (file)
@@ -134,7 +134,18 @@ void TrashWatcher<I>::handle_create_trash(int r) {
     ceph_assert(m_trash_list_in_progress);
   }
 
-  if (r < 0 && r != -EEXIST) {
+  Context* on_init_finish = nullptr;
+  if (r == -EBLACKLISTED || r == -ENOENT) {
+    if (r == -EBLACKLISTED) {
+      dout(0) << "detected client is blacklisted" << dendl;
+    } else {
+      dout(0) << "detected pool no longer exists" << dendl;
+    }
+
+    Mutex::Locker locker(m_lock);
+    std::swap(on_init_finish, m_on_init_finish);
+    m_trash_list_in_progress = false;
+  } else if (r < 0 && r != -EEXIST) {
     derr << "failed to create trash object: " << cpp_strerror(r) << dendl;
     {
       Mutex::Locker locker(m_lock);
@@ -147,6 +158,9 @@ void TrashWatcher<I>::handle_create_trash(int r) {
   }
 
   m_async_op_tracker.finish_op();
+  if (on_init_finish != nullptr) {
+    on_init_finish->complete(r);
+  }
 }
 
 template <typename I>