]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: rbd-mirror: PoolWatcher watches for mirroring enabled images 8162/head
authorRicardo Dias <rdias@suse.com>
Wed, 16 Mar 2016 14:46:46 +0000 (14:46 +0000)
committerRicardo Dias <rdias@suse.com>
Wed, 16 Mar 2016 16:02:58 +0000 (16:02 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
Fixes: #15142
src/test/rbd_mirror/test_PoolWatcher.cc
src/tools/rbd_mirror/PoolWatcher.cc

index 278421d3ccb85f42dd6a37c1fa914fa2f41d3db6..5cb68058b2276e4335bb12261c47169ee8c2ed9b 100644 (file)
@@ -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);
index 8029c07f8040bb0e78578e32d78a3f149cb677ee..74b54cd544f5c70bb9246f5bd816d48a0fd6c8b5 100644 (file)
@@ -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<string> 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<string, string> 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<std::string> 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<std::string> image_set(image_ids.begin(), image_ids.end());
+      images[pool_id] = std::move(image_set);
     }
   }