From: Ricardo Dias Date: Wed, 16 Mar 2016 14:46:46 +0000 (+0000) Subject: rbd: rbd-mirror: PoolWatcher watches for mirroring enabled images X-Git-Tag: v10.1.0~18^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F8162%2Fhead;p=ceph.git rbd: rbd-mirror: PoolWatcher watches for mirroring enabled images Signed-off-by: Ricardo Dias Fixes: #15142 --- diff --git a/src/test/rbd_mirror/test_PoolWatcher.cc b/src/test/rbd_mirror/test_PoolWatcher.cc index 278421d3ccb8..5cb68058b227 100644 --- a/src/test/rbd_mirror/test_PoolWatcher.cc +++ b/src/test/rbd_mirror/test_PoolWatcher.cc @@ -135,8 +135,14 @@ TestPoolWatcher() : m_lock("TestPoolWatcherLock"), int order = 0; ASSERT_EQ(0, librbd::create(ioctx, name.c_str(), 1 << 22, false, features, &order, 0, 0)); - if (mirrored) + if (mirrored) { + librbd::Image image; + librbd::RBD rbd; + rbd.open(ioctx, image, name.c_str()); + image.mirror_image_enable(); + image.close(); m_mirrored_images[ioctx.get_id()].insert(get_image_id(&ioctx, name)); + } if (image_name != nullptr) *image_name = name; } @@ -168,8 +174,14 @@ TestPoolWatcher() : m_lock("TestPoolWatcherLock"), int order = 0; librbd::clone(pioctx, parent_image_name.c_str(), snap_name.c_str(), cioctx, name.c_str(), features, &order, 0, 0); - if (mirrored) + if (mirrored) { + librbd::Image image; + librbd::RBD rbd; + rbd.open(cioctx, image, name.c_str()); + image.mirror_image_enable(); + image.close(); m_mirrored_images[cioctx.get_id()].insert(get_image_id(&cioctx, name)); + } if (image_name != nullptr) *image_name = name; } @@ -214,6 +226,8 @@ TEST_F(TestPoolWatcher, ReplicatedPools) { check_images(); clone_image(first_pool, parent_image, first_pool, true, &parent_image2); check_images(); + create_image(first_pool, false); + check_images(); create_pool(false, peer_t(), &local_pool); check_images(); @@ -249,6 +263,8 @@ TEST_F(TestPoolWatcher, CachePools) { check_images(); create_image(base1); check_images(); + create_image(base1, false); + check_images(); create_pool(false, peer_t(), &base2); create_cache_pool(base2, &cache2); diff --git a/src/tools/rbd_mirror/PoolWatcher.cc b/src/tools/rbd_mirror/PoolWatcher.cc index 8029c07f8040..74b54cd544f5 100644 --- a/src/tools/rbd_mirror/PoolWatcher.cc +++ b/src/tools/rbd_mirror/PoolWatcher.cc @@ -25,7 +25,7 @@ using std::vector; using librados::Rados; using librados::IoCtx; -using librbd::cls_client::dir_list; +using librbd::cls_client::mirror_image_list; namespace rbd { namespace mirror { @@ -93,8 +93,6 @@ void PoolWatcher::refresh_images(bool reschedule) continue; } - // TODO: read mirrored images from mirroring settings object. For - // now just treat all images in a pool with mirroring enabled as mirrored rbd_mirror_mode_t mirror_mode; r = librbd::mirror_mode_get(ioctx, &mirror_mode); if (r < 0) { @@ -107,34 +105,19 @@ void PoolWatcher::refresh_images(bool reschedule) continue; } - set image_ids; - // only format 2 images can be mirrored, so only check the format // 2 rbd_directory structure - int max_read = 1024; - string last_read = ""; - do { - map pool_images; - r = dir_list(&ioctx, RBD_DIRECTORY, - last_read, max_read, &pool_images); - if (r == -ENOENT) - r = 0; - if (r < 0) { - derr << "error listing images in pool " << pool_name << ": " - << cpp_strerror(r) << dendl; - continue; - } - for (auto& pair : pool_images) { - image_ids.insert(pair.second); - } - if (!pool_images.empty()) { - last_read = pool_images.rbegin()->first; - } - r = pool_images.size(); - } while (r == max_read); - - if (r > 0) { - images[pool_id] = std::move(image_ids); + std::vector image_ids; + r = mirror_image_list(&ioctx, &image_ids); + if (r < 0) { + derr << "error listing mirrored images in pool " << pool_name << ": " + << cpp_strerror(r) << dendl; + continue; + } + + if (!image_ids.empty()) { + std::set image_set(image_ids.begin(), image_ids.end()); + images[pool_id] = std::move(image_set); } }