]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-mirror: remove image name retrieval from pool watcher
authorJason Dillaman <dillaman@redhat.com>
Fri, 21 Apr 2017 01:23:43 +0000 (21:23 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 21 Apr 2017 02:38:19 +0000 (22:38 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/pool_watcher/test_mock_RefreshImagesRequest.cc
src/test/rbd_mirror/test_PoolWatcher.cc
src/test/rbd_mirror/test_mock_PoolWatcher.cc
src/tools/rbd_mirror/PoolWatcher.cc
src/tools/rbd_mirror/PoolWatcher.h
src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.cc
src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h
src/tools/rbd_mirror/types.cc
src/tools/rbd_mirror/types.h

index 1e92670d8a57ae95dd39bb301695e03a1d1441dd..0795fcdd445985037091a797a4f53ffb8f7e38f4 100644 (file)
@@ -54,24 +54,11 @@ public:
                       Return(r)));
   }
 
-  void expect_dir_list(librados::IoCtx &io_ctx,
-                       const std::map<std::string, std::string> &ids, int r) {
-    bufferlist bl;
-    ::encode(ids, bl);
-
-    EXPECT_CALL(get_mock_io_ctx(io_ctx),
-                exec(RBD_DIRECTORY, _, StrEq("rbd"), StrEq("dir_list"), _, _, _))
-      .WillOnce(DoAll(WithArg<5>(Invoke([bl](bufferlist *out_bl) {
-                                          *out_bl = bl;
-                                        })),
-                      Return(r)));
-  }
 };
 
 TEST_F(TestMockPoolWatcherRefreshImagesRequest, Success) {
   InSequence seq;
   expect_mirror_image_list(m_remote_io_ctx, {{"local id", "global id"}}, 0);
-  expect_dir_list(m_remote_io_ctx, {{"image name", "local id"}}, 0);
 
   C_SaferCond ctx;
   ImageIds image_ids;
@@ -81,29 +68,23 @@ TEST_F(TestMockPoolWatcherRefreshImagesRequest, Success) {
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  ImageIds expected_image_ids = {{"global id", "local id", "image name"}};
+  ImageIds expected_image_ids = {{"global id", "local id"}};
   ASSERT_EQ(expected_image_ids, image_ids);
 }
 
 TEST_F(TestMockPoolWatcherRefreshImagesRequest, LargeDirectory) {
   InSequence seq;
   std::map<std::string, std::string> mirror_list;
-  std::map<std::string, std::string> dir_list;
   ImageIds expected_image_ids;
   for (uint32_t idx = 1; idx <= 1024; ++idx) {
     mirror_list.insert(std::make_pair("local id " + stringify(idx),
                                       "global id " + stringify(idx)));
-    dir_list.insert(std::make_pair("image " + stringify(idx),
-                                   "local id " + stringify(idx)));
     expected_image_ids.insert({{"global id " + stringify(idx),
-                                "local id " + stringify(idx),
-                                "image " + stringify(idx)}});
+                                "local id " + stringify(idx)}});
   }
 
   expect_mirror_image_list(m_remote_io_ctx, mirror_list, 0);
   expect_mirror_image_list(m_remote_io_ctx, {{"local id", "global id"}}, 0);
-  expect_dir_list(m_remote_io_ctx, dir_list, 0);
-  expect_dir_list(m_remote_io_ctx, {{"image name", "local id"}}, 0);
 
   C_SaferCond ctx;
   ImageIds image_ids;
@@ -113,7 +94,7 @@ TEST_F(TestMockPoolWatcherRefreshImagesRequest, LargeDirectory) {
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  expected_image_ids.insert({"global id", "local id", "image name"});
+  expected_image_ids.insert({"global id", "local id"});
   ASSERT_EQ(expected_image_ids, image_ids);
 }
 
@@ -130,20 +111,6 @@ TEST_F(TestMockPoolWatcherRefreshImagesRequest, MirrorImageListError) {
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
 
-TEST_F(TestMockPoolWatcherRefreshImagesRequest, DirListError) {
-  InSequence seq;
-  expect_mirror_image_list(m_remote_io_ctx, {{"local id", "global id"}}, 0);
-  expect_dir_list(m_remote_io_ctx, {{"image name", "local id"}}, -EINVAL);
-
-  C_SaferCond ctx;
-  ImageIds image_ids;
-  MockRefreshImagesRequest *req = new MockRefreshImagesRequest(
-    m_remote_io_ctx, &image_ids, &ctx);
-
-  req->send();
-  ASSERT_EQ(-EINVAL, ctx.wait());
-}
-
 } // namespace pool_watcher
 } // namespace mirror
 } // namespace rbd
index dd857423ee08fe3fad91d6b21de0a35a248b1719..9d11c715638ba27a54457b20609ea51f2f518e2b 100644 (file)
@@ -148,7 +148,7 @@ public:
       image.close();
 
       m_mirrored_images.insert(ImageId(
-        mirror_image_info.global_id, get_image_id(&ioctx, name), name));
+        mirror_image_info.global_id, get_image_id(&ioctx, name)));
     }
     if (image_name != nullptr)
       *image_name = name;
@@ -195,7 +195,7 @@ public:
       image.close();
 
       m_mirrored_images.insert(ImageId(
-        mirror_image_info.global_id, get_image_id(&cioctx, name), name));
+        mirror_image_info.global_id, get_image_id(&cioctx, name)));
     }
     if (image_name != nullptr)
       *image_name = name;
index ebb26b9f22329ff708acd7cc75cf1b60bcbfc3aa..b6e61516dce7c7fc466e426869a50b249af2db10 100644 (file)
@@ -231,26 +231,6 @@ public:
                       Return(r)));
   }
 
-  void expect_dir_list(librados::IoCtx &io_ctx,
-                       const std::string &id, const std::string &name, int r) {
-    bufferlist in_bl;
-    ::encode(id, in_bl);
-
-    bufferlist out_bl;
-    ::encode(name, out_bl);
-
-    EXPECT_CALL(get_mock_io_ctx(io_ctx),
-                exec(RBD_DIRECTORY, _, StrEq("rbd"), StrEq("dir_get_name"),
-                     ContentsEqual(in_bl), _, _))
-      .WillOnce(DoAll(WithArg<5>(Invoke([this, out_bl](bufferlist *bl) {
-                          *bl = out_bl;
-                          Mutex::Locker locker(m_lock);
-                          ++m_get_name_count;
-                          m_cond.Signal();
-                        })),
-                      Return(r)));
-  }
-
   void expect_timer_add_event(MockThreads &mock_threads) {
     EXPECT_CALL(*mock_threads.timer, add_event_after(_, _))
       .WillOnce(WithArg<1>(Invoke([this](Context *ctx) {
@@ -283,25 +263,9 @@ public:
     return true;
   }
 
-  bool wait_for_get_name(uint32_t count) {
-    Mutex::Locker locker(m_lock);
-    while (m_get_name_count < count) {
-      if (m_cond.WaitInterval(m_lock, utime_t(10, 0)) != 0) {
-        break;
-      }
-    }
-    if (m_get_name_count < count) {
-      return false;
-    }
-
-    m_get_name_count -= count;
-    return true;
-  }
-
   Mutex m_lock;
   Cond m_cond;
   uint32_t m_update_count = 0;
-  uint32_t m_get_name_count = 0;
 };
 
 TEST_F(TestMockPoolWatcher, EmptyPool) {
@@ -341,8 +305,8 @@ TEST_F(TestMockPoolWatcher, NonEmptyPool) {
   expect_mirroring_watcher_register(mock_mirroring_watcher, 0);
 
   ImageIds image_ids{
-    {"global id 1", "remote id 1", "image name 1"},
-    {"global id 2", "remote id 2", "image name 2"}};
+    {"global id 1", "remote id 1"},
+    {"global id 2", "remote id 2"}};
   MockRefreshImagesRequest mock_refresh_images_request;
   expect_refresh_images(mock_refresh_images_request, image_ids, 0);
   expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
@@ -371,8 +335,8 @@ TEST_F(TestMockPoolWatcher, NotifyDuringRefresh) {
   expect_mirroring_watcher_register(mock_mirroring_watcher, 0);
 
   ImageIds image_ids{
-    {"global id 1", "remote id 1", "image name 1"},
-    {"global id 2", "remote id 2", "image name 2"}};
+    {"global id 1", "remote id 1"},
+    {"global id 2", "remote id 2"}};
   MockRefreshImagesRequest mock_refresh_images_request;
   bool refresh_sent = false;
   EXPECT_CALL(mock_refresh_images_request, send())
@@ -385,16 +349,12 @@ TEST_F(TestMockPoolWatcher, NotifyDuringRefresh) {
         m_cond.Signal();
       }));
 
-  expect_dir_list(m_remote_io_ctx, "remote id 1a", "image name 1a", 0);
-  expect_dir_list(m_remote_io_ctx, "remote id 3", "image name 3", 0);
-  expect_dir_list(m_remote_io_ctx, "dummy", "", -ENOENT);
-
   expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
 
   MockListener mock_listener(this);
   image_ids = {
-    {"global id 1", "remote id 1a", "image name 1a"},
-    {"global id 3", "remote id 3", "image name 3"}};
+    {"global id 1", "remote id 1a"},
+    {"global id 3", "remote id 3"}};
   expect_listener_handle_update(mock_listener, "remote uuid", image_ids, {});
 
   MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx,
@@ -414,9 +374,6 @@ TEST_F(TestMockPoolWatcher, NotifyDuringRefresh) {
     cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 1a", "global id 1");
   MirroringWatcher::get_instance().handle_image_updated(
     cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 3", "global id 3");
-  MirroringWatcher::get_instance().handle_image_updated(
-    cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "dummy", "dummy");
-  wait_for_get_name(3);
 
   mock_refresh_images_request.on_finish->complete(0);
   ASSERT_TRUE(wait_for_update(1));
@@ -434,8 +391,8 @@ TEST_F(TestMockPoolWatcher, Notify) {
   expect_mirroring_watcher_register(mock_mirroring_watcher, 0);
 
   ImageIds image_ids{
-    {"global id 1", "remote id 1", "image name 1"},
-    {"global id 2", "remote id 2", "image name 2"}};
+    {"global id 1", "remote id 1"},
+    {"global id 2", "remote id 2"}};
   MockRefreshImagesRequest mock_refresh_images_request;
   expect_refresh_images(mock_refresh_images_request, image_ids, 0);
   expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
@@ -456,15 +413,10 @@ TEST_F(TestMockPoolWatcher, Notify) {
         notify_ctx = ctx;
         m_cond.Signal();
       }));
-  expect_dir_list(m_remote_io_ctx, "remote id 1a", "image name 1a", 0);
-  expect_dir_list(m_remote_io_ctx, "remote id 3", "image name 3", 0);
-  expect_dir_list(m_remote_io_ctx, "dummy", "", -ENOENT);
   expect_listener_handle_update(
     mock_listener, "remote uuid",
-    {{"global id 1", "remote id 1a", "image name 1a"},
-     {"global id 3", "remote id 3", "image name 3"}},
-    {{"global id 1", "remote id 1", "image name 1"},
-     {"global id 2", "remote id 2", "image name 2"}});
+    {{"global id 1", "remote id 1a"}, {"global id 3", "remote id 3"}},
+    {{"global id 1", "remote id 1"}, {"global id 2", "remote id 2"}});
 
   MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx,
                                     mock_listener);
@@ -485,9 +437,6 @@ TEST_F(TestMockPoolWatcher, Notify) {
     cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 1a", "global id 1");
   MirroringWatcher::get_instance().handle_image_updated(
     cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 3", "global id 3");
-  MirroringWatcher::get_instance().handle_image_updated(
-    cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "dummy", "dummy");
-  ASSERT_TRUE(wait_for_get_name(3));
   notify_ctx->complete(0);
 
   ASSERT_TRUE(wait_for_update(1));
@@ -768,10 +717,10 @@ TEST_F(TestMockPoolWatcher, Rewatch) {
 
   expect_timer_add_event(mock_threads);
   expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false);
-  expect_refresh_images(mock_refresh_images_request, {{"global id", "image id", "name"}}, 0);
+  expect_refresh_images(mock_refresh_images_request, {{"global id", "image id"}}, 0);
   expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
   expect_listener_handle_update(mock_listener, "remote uuid",
-                                {{"global id", "image id", "name"}}, {});
+                                {{"global id", "image id"}}, {});
 
   MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx,
                                     mock_listener);
@@ -835,10 +784,10 @@ TEST_F(TestMockPoolWatcher, RewatchError) {
 
   expect_timer_add_event(mock_threads);
   expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false);
-  expect_refresh_images(mock_refresh_images_request, {{"global id", "image id", "name"}}, 0);
+  expect_refresh_images(mock_refresh_images_request, {{"global id", "image id"}}, 0);
   expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
   expect_listener_handle_update(mock_listener, "remote uuid",
-                                {{"global id", "image id", "name"}}, {});
+                                {{"global id", "image id"}}, {});
 
   MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx,
                                     mock_listener);
@@ -854,86 +803,6 @@ TEST_F(TestMockPoolWatcher, RewatchError) {
   ASSERT_EQ(0, when_shut_down(mock_pool_watcher));
 }
 
-TEST_F(TestMockPoolWatcher, GetImageNameBlacklist) {
-  MockThreads mock_threads(m_threads);
-  expect_work_queue(mock_threads);
-
-  InSequence seq;
-  MockMirroringWatcher mock_mirroring_watcher;
-  expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, true);
-  expect_mirroring_watcher_register(mock_mirroring_watcher, 0);
-
-  MockRefreshImagesRequest mock_refresh_images_request;
-  expect_refresh_images(mock_refresh_images_request, {}, 0);
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
-
-  MockListener mock_listener(this);
-  expect_listener_handle_update(mock_listener, "remote uuid", {}, {});
-
-  expect_dir_list(m_remote_io_ctx, "remote id", "image name", -EBLACKLISTED);
-
-  MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx,
-                                    mock_listener);
-  C_SaferCond ctx;
-  mock_pool_watcher.init(&ctx);
-  ASSERT_EQ(0, ctx.wait());
-  ASSERT_TRUE(wait_for_update(1));
-
-  MirroringWatcher::get_instance().handle_image_updated(
-    cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id", "global id");
-  ASSERT_TRUE(wait_for_get_name(1));
-  while (true) {
-    if (mock_pool_watcher.is_blacklisted()) {
-      break;
-    }
-    usleep(1000);
-  }
-
-  expect_mirroring_watcher_unregister(mock_mirroring_watcher, 0);
-  ASSERT_EQ(0, when_shut_down(mock_pool_watcher));
-}
-
-TEST_F(TestMockPoolWatcher, GetImageNameError) {
-  MockThreads mock_threads(m_threads);
-  expect_work_queue(mock_threads);
-
-  InSequence seq;
-  MockMirroringWatcher mock_mirroring_watcher;
-  expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, true);
-  expect_mirroring_watcher_register(mock_mirroring_watcher, 0);
-
-  MockRefreshImagesRequest mock_refresh_images_request;
-  expect_refresh_images(mock_refresh_images_request, {}, 0);
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
-
-  MockListener mock_listener(this);
-  expect_listener_handle_update(mock_listener, "remote uuid", {}, {});
-
-  expect_dir_list(m_remote_io_ctx, "remote id", "image name", -EINVAL);
-  expect_timer_add_event(mock_threads);
-
-  expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false);
-  expect_refresh_images(mock_refresh_images_request, {{"global id", "remote id", "name"}}, 0);
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
-  expect_listener_handle_update(mock_listener, "remote uuid",
-                                {{"global id", "remote id", "name"}}, {});
-
-  MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx,
-                                    mock_listener);
-  C_SaferCond ctx;
-  mock_pool_watcher.init(&ctx);
-  ASSERT_EQ(0, ctx.wait());
-  ASSERT_TRUE(wait_for_update(1));
-
-  MirroringWatcher::get_instance().handle_image_updated(
-    cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id", "global id");
-  ASSERT_TRUE(wait_for_get_name(1));
-  ASSERT_TRUE(wait_for_update(1));
-
-  expect_mirroring_watcher_unregister(mock_mirroring_watcher, 0);
-  ASSERT_EQ(0, when_shut_down(mock_pool_watcher));
-}
-
 TEST_F(TestMockPoolWatcher, DeferredRefresh) {
   MockThreads mock_threads(m_threads);
   expect_work_queue(mock_threads);
@@ -982,8 +851,8 @@ TEST_F(TestMockPoolWatcher, MirrorUuidUpdated) {
   expect_mirroring_watcher_register(mock_mirroring_watcher, 0);
 
   ImageIds image_ids{
-    {"global id 1", "remote id 1", "image name 1"},
-    {"global id 2", "remote id 2", "image name 2"}};
+    {"global id 1", "remote id 1"},
+    {"global id 2", "remote id 2"}};
   MockRefreshImagesRequest mock_refresh_images_request;
   expect_refresh_images(mock_refresh_images_request, image_ids, 0);
   expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0);
@@ -1001,7 +870,7 @@ TEST_F(TestMockPoolWatcher, MirrorUuidUpdated) {
 
   expect_timer_add_event(mock_threads);
   ImageIds new_image_ids{
-    {"global id 1", "remote id 1", "image name 1"}};
+    {"global id 1", "remote id 1"}};
   expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false);
   expect_refresh_images(mock_refresh_images_request, new_image_ids, 0);
   expect_mirror_uuid_get(m_remote_io_ctx, "updated uuid", 0);
@@ -1015,5 +884,6 @@ TEST_F(TestMockPoolWatcher, MirrorUuidUpdated) {
   expect_mirroring_watcher_unregister(mock_mirroring_watcher, 0);
   ASSERT_EQ(0, when_shut_down(mock_pool_watcher));
 }
+
 } // namespace mirror
 } // namespace rbd
index 7bdd8cdb09ec283e9c5537bb8ec98d08cbba9bdd..6a855ff2185309a2fb1381eb18f1c0d4a59ee2cf 100644 (file)
@@ -217,18 +217,6 @@ void PoolWatcher<I>::refresh_images() {
     // a full image list refresh
     m_pending_added_image_ids.clear();
     m_pending_removed_image_ids.clear();
-    if (!m_updated_images.empty()) {
-      auto it = m_updated_images.begin();
-      it->invalid = true;
-
-      // only have a single in-flight request -- remove the rest
-      ++it;
-      while (it != m_updated_images.end()) {
-        m_id_to_updated_images.erase({it->global_image_id,
-                                      it->remote_image_id});
-        it = m_updated_images.erase(it);
-      }
-    }
   }
 
   m_async_op_tracker.start_op();
@@ -413,110 +401,15 @@ void PoolWatcher<I>::handle_image_updated(const std::string &remote_image_id,
   m_pending_added_image_ids.erase(image_id);
   m_pending_removed_image_ids.erase(image_id);
 
-  auto id = std::make_pair(global_image_id, remote_image_id);
-  auto id_it = m_id_to_updated_images.find(id);
-  if (id_it != m_id_to_updated_images.end()) {
-    id_it->second->enabled = enabled;
-    id_it->second->invalid = false;
-  } else if (enabled) {
-    // need to resolve the image name before notifying listener
-    auto it = m_updated_images.emplace(m_updated_images.end(),
-                                       global_image_id, remote_image_id);
-    m_id_to_updated_images[id] = it;
-    schedule_get_image_name();
+  if (enabled) {
+    m_pending_added_image_ids.insert(image_id);
+    schedule_listener();
   } else {
-    // delete image w/ if no resolve name in-flight
     m_pending_removed_image_ids.insert(image_id);
     schedule_listener();
   }
 }
 
-template <typename I>
-void PoolWatcher<I>::schedule_get_image_name() {
-  assert(m_lock.is_locked());
-  if (m_shutting_down || m_blacklisted || m_updated_images.empty() ||
-      m_get_name_in_progress) {
-    return;
-  }
-  m_get_name_in_progress = true;
-
-  auto &updated_image = m_updated_images.front();
-  dout(10) << "global_image_id=" << updated_image.global_image_id << ", "
-           << "remote_image_id=" << updated_image.remote_image_id << dendl;
-
-  librados::ObjectReadOperation op;
-  librbd::cls_client::dir_get_name_start(&op, updated_image.remote_image_id);
-
-  m_async_op_tracker.start_op();
-
-  m_out_bl.clear();
-  librados::AioCompletion *aio_comp = create_rados_callback<
-    PoolWatcher, &PoolWatcher<I>::handle_get_image_name>(this);
-  int r = m_remote_io_ctx.aio_operate(RBD_DIRECTORY, aio_comp, &op, &m_out_bl);
-  assert(r == 0);
-  aio_comp->release();
-}
-
-template <typename I>
-void PoolWatcher<I>::handle_get_image_name(int r) {
-  dout(10) << "r=" << r << dendl;
-
-  std::string name;
-  if (r == 0) {
-    bufferlist::iterator it = m_out_bl.begin();
-    r = librbd::cls_client::dir_get_name_finish(&it, &name);
-  }
-
-  bool image_ids_invalid = false;
-  {
-    Mutex::Locker locker(m_lock);
-    assert(!m_updated_images.empty());
-    m_get_name_in_progress = false;
-
-    auto updated_image = m_updated_images.front();
-    m_updated_images.pop_front();
-    m_id_to_updated_images.erase(std::make_pair(updated_image.global_image_id,
-                                                updated_image.remote_image_id));
-
-    if (r == 0) {
-      // since names are resolved in event order -- the current update is
-      // the latest state
-      ImageId image_id(updated_image.global_image_id,
-                       updated_image.remote_image_id, name);
-      m_pending_added_image_ids.erase(image_id);
-      m_pending_removed_image_ids.erase(image_id);
-      if (!updated_image.invalid) {
-        if (updated_image.enabled) {
-          m_pending_added_image_ids.insert(image_id);
-        } else {
-          m_pending_removed_image_ids.insert(image_id);
-        }
-        schedule_listener();
-      }
-    } else if (r == -EBLACKLISTED) {
-      dout(0) << "detected client is blacklisted" << dendl;
-
-      m_blacklisted = true;
-    } else if (r == -ENOENT) {
-      dout(10) << "image removed after add notification" << dendl;
-    } else {
-      derr << "error resolving image name " << updated_image.remote_image_id
-           << " (" << updated_image.global_image_id << "): " << cpp_strerror(r)
-           << dendl;
-      image_ids_invalid = true;
-    }
-
-    if (!image_ids_invalid) {
-      schedule_get_image_name();
-    }
-  }
-
-  if (image_ids_invalid) {
-    schedule_refresh_images(5);
-  }
-  m_async_op_tracker.finish_op();
-}
-
 template <typename I>
 void PoolWatcher<I>::process_refresh_images() {
   assert(m_threads->timer_lock.is_locked());
@@ -603,24 +496,9 @@ void PoolWatcher<I>::notify_listener() {
 
     // merge add/remove notifications into pending set (a given image
     // can only be in one set or another)
-    for (auto it = m_pending_removed_image_ids.begin();
-         it != m_pending_removed_image_ids.end(); ) {
-      if (std::find_if(m_updated_images.begin(), m_updated_images.end(),
-                       [&it](const UpdatedImage &updated_image) {
-              return (it->id == updated_image.remote_image_id);
-            }) != m_updated_images.end()) {
-        // still resolving the name -- so keep it in the pending set
-        auto image_id_it = m_image_ids.find(*it);
-        if (image_id_it != m_image_ids.end()) {
-          m_pending_image_ids.insert(*image_id_it);
-        }
-        ++it;
-        continue;
-      }
-
-      // merge the remove event into the pending set
-      m_pending_image_ids.erase(*it);
-      it = m_pending_removed_image_ids.erase(it);
+    for (auto &image_id : m_pending_removed_image_ids) {
+      dout(20) << "image_id=" << image_id << dendl;
+      m_pending_image_ids.erase(image_id);
     }
 
     for (auto &image_id : m_pending_added_image_ids) {
index 747a0ee5dc882f0180635a0003174abcf625e4fa..aebd981b864530d4b4077cd87aae112eba6ed728 100644 (file)
@@ -14,8 +14,6 @@
 #include "common/Mutex.h"
 #include "include/rados/librados.hpp"
 #include "types.h"
-#include <list>
-#include <unordered_map>
 #include <boost/functional/hash.hpp>
 #include <boost/optional.hpp>
 #include "include/assert.h"
@@ -101,31 +99,6 @@ private:
    */
   class MirroringWatcher;
 
-  struct UpdatedImage {
-    std::string global_image_id;
-    std::string remote_image_id;
-    bool enabled = true;
-    bool invalid = false;
-
-    UpdatedImage(const std::string &global_image_id,
-                 const std::string &remote_image_id)
-      : global_image_id(global_image_id), remote_image_id(remote_image_id) {
-    }
-  };
-
-  typedef std::pair<std::string, std::string> GlobalRemoteIds;
-  typedef std::list<UpdatedImage> UpdatedImages;
-  typedef std::unordered_map<GlobalRemoteIds, typename UpdatedImages::iterator,
-                             boost::hash<GlobalRemoteIds> > IdToUpdatedImages;
-
-  struct StrictImageIdCompare {
-    bool operator()(const ImageId &lhs, const ImageId &rhs) const {
-      if (lhs.global_id != rhs.global_id) {
-        return lhs.global_id < rhs.global_id;
-      }
-      return lhs.id < rhs.id;
-    }
-  };
   Threads<ImageCtxT> *m_threads;
   librados::IoCtx m_remote_io_ctx;
   Listener &m_listener;
@@ -159,10 +132,6 @@ private:
   bool m_refresh_in_progress = false;
   bool m_deferred_refresh = false;
 
-  UpdatedImages m_updated_images;
-  IdToUpdatedImages m_id_to_updated_images;
-  bool m_get_name_in_progress = false;
-
   void register_watcher();
   void handle_register_watcher(int r);
   void unregister_watcher();
@@ -181,9 +150,6 @@ private:
                             const std::string &global_image_id,
                             bool enabled);
 
-  void schedule_get_image_name();
-  void handle_get_image_name(int r);
-
   void schedule_listener();
   void notify_listener();
 
index c387ecea789a1ccdffc5653d6fcf11cb5fd470f0..1a6ed8c0541a7b2ec5d941aeae2f8273fedc7e49 100644 (file)
@@ -24,6 +24,7 @@ using librbd::util::create_rados_callback;
 
 template <typename I>
 void RefreshImagesRequest<I>::send() {
+  m_image_ids->clear();
   mirror_image_list();
 }
 
@@ -58,69 +59,17 @@ void RefreshImagesRequest<I>::handle_mirror_image_list(int r) {
     return;
   }
 
-  if (!ids.empty()) {
-    m_local_to_global_ids.insert(ids.begin(), ids.end());
-    if (ids.size() == MAX_RETURN) {
-      m_start_after = ids.rbegin()->first;
-      mirror_image_list();
-      return;
-    }
+  // store as global -> local image ids
+  for (auto &id : ids) {
+    m_image_ids->emplace(id.second, id.first);
   }
 
-  dir_list();
-}
-
-template <typename I>
-void RefreshImagesRequest<I>::dir_list() {
-  dout(10) << dendl;
-
-  m_out_bl.clear();
-  m_start_after = "";
-
-  librados::ObjectReadOperation op;
-  librbd::cls_client::dir_list_start(&op, m_start_after, MAX_RETURN);
-
-  librados::AioCompletion *aio_comp = create_rados_callback<
-    RefreshImagesRequest<I>,
-    &RefreshImagesRequest<I>::handle_dir_list>(this);
-  int r = m_remote_io_ctx.aio_operate(RBD_DIRECTORY, aio_comp, &op, &m_out_bl);
-  assert(r == 0);
-  aio_comp->release();
-}
-
-template <typename I>
-void RefreshImagesRequest<I>::handle_dir_list(int r) {
-  dout(10) << "r=" << r << dendl;
-
-  std::map<std::string, std::string> name_to_ids;
-  if (r == 0) {
-    bufferlist::iterator it = m_out_bl.begin();
-    r = librbd::cls_client::dir_list_finish(&it, &name_to_ids);
-  }
-
-  if (r < 0 && r != -ENOENT) {
-    derr << "failed to list images: " << cpp_strerror(r) << dendl;
-    finish(r);
+  if (ids.size() == MAX_RETURN) {
+    m_start_after = ids.rbegin()->first;
+    mirror_image_list();
     return;
   }
 
-  if (!name_to_ids.empty()) {
-    for (auto &pair : name_to_ids) {
-      auto it = m_local_to_global_ids.find(pair.second);
-      if (it != m_local_to_global_ids.end()) {
-        // mirrored image must exist within directory to be treated as
-        // a valid image
-        m_image_ids->insert(ImageId(it->second, it->first, pair.first));
-      }
-    }
-
-    if (name_to_ids.size() == MAX_RETURN) {
-      m_start_after = name_to_ids.rbegin()->first;
-      dir_list();
-      return;
-    }
-  }
-
   finish(0);
 }
 
index 79a327cd6c7dea82a636b10bee592004de06c99c..35ed6b3301480bd227ed335812ed3e09bd4463f5 100644 (file)
@@ -8,7 +8,6 @@
 #include "include/rados/librados.hpp"
 #include "tools/rbd_mirror/types.h"
 #include <string>
-#include <unordered_map>
 
 struct Context;
 
@@ -45,33 +44,22 @@ private:
    *    v   v             | (more images)
    * MIRROR_IMAGE_LIST ---/
    *    |
-   *    |   /-------------\
-   *    |   |             |
-   *    v   v             | (more images)
-   * DIR_LIST ------------/
-   *    |
    *    v
    * <finish>
    *
    * @endverbatim
    */
 
-  typedef std::unordered_map<std::string, std::string> LocalToGlobalIds;
-
   librados::IoCtx &m_remote_io_ctx;
   ImageIds *m_image_ids;
   Context *m_on_finish;
 
   bufferlist m_out_bl;
   std::string m_start_after;
-  LocalToGlobalIds m_local_to_global_ids;
 
   void mirror_image_list();
   void handle_mirror_image_list(int r);
 
-  void dir_list();
-  void handle_dir_list(int r);
-
   void finish(int r);
 
 };
index 52bf9de20fcdc46ade5c92fcf7c8ec54ca00d91c..4cd1e490f3dfeccc5735d8b5b7890f088d10c57b 100644 (file)
@@ -8,8 +8,7 @@ namespace mirror {
 
 std::ostream &operator<<(std::ostream &os, const ImageId &image_id) {
   return os << "global id=" << image_id.global_id << ", "
-            << "id=" << image_id.id << ", "
-            << "name=" << image_id.name;
+            << "id=" << image_id.id;
 }
 
 std::ostream& operator<<(std::ostream& lhs, const peer_t &peer) {
index 617effd21cf0df0052864a7f8ea965b80219e9be..829998d74e9a088435ca560ca471e7c1449bc9aa 100644 (file)
@@ -9,7 +9,6 @@
 #include <set>
 #include <string>
 #include <vector>
-#include <boost/optional.hpp>
 
 #include "include/rbd/librbd.hpp"
 #include "ImageSyncThrottler.h"
@@ -27,20 +26,15 @@ using ImageSyncThrottlerRef = std::shared_ptr<ImageSyncThrottler<I>>;
 struct ImageId {
   std::string global_id;
   std::string id;
-  boost::optional<std::string> name;
 
   explicit ImageId(const std::string &global_id) : global_id(global_id) {
   }
   ImageId(const std::string &global_id, const std::string &id)
     : global_id(global_id), id(id) {
   }
-  ImageId(const std::string &global_id, const std::string &id,
-          const std::string &name)
-    : global_id(global_id), id(id), name(name) {
-  }
 
   inline bool operator==(const ImageId &rhs) const {
-    return (global_id == rhs.global_id && id == rhs.id && name == rhs.name);
+    return (global_id == rhs.global_id && id == rhs.id);
   }
   inline bool operator<(const ImageId &rhs) const {
     return global_id < rhs.global_id;