]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: clear Image::list_watchers() list before populating it 50816/head
authorIlya Dryomov <idryomov@gmail.com>
Thu, 30 Mar 2023 11:58:20 +0000 (13:58 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 31 Mar 2023 10:23:45 +0000 (12:23 +0200)
The "append to the passed list" behavior is confusing and not what the
corresponding C API (rbd_watchers_list) or other similar C++ APIs (e.g.
list_lockers) do.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
PendingReleaseNotes
src/librbd/internal.cc
src/test/librbd/test_librbd.cc

index cfc8c40cac498fc646ca026f38b8121a3e4f9f57..0c55a8972310e10a9db9f0792d2f239b8b786886 100644 (file)
   registered a RADOS client in the `name` field added to elements of the
   `active_clients` array. Previously, only the address of a module's RADOS
   client was shown in the `active_clients` array.
+* RBD: list-watchers C++ API (`Image::list_watchers`) now clears the passed
+  `std::list` before potentially appending to it, aligning with the semantics
+  of the corresponding C API (`rbd_watchers_list`).
 
 >=17.2.1
 
index c9c1167608ca41820809aca7eea09508bd86898d..3cd699b2c81426df7c882e3f0892da67ebf9b02f 100644 (file)
@@ -1699,6 +1699,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
       return r;
     }
 
+    watchers.clear();
     for (auto i = obj_watchers.begin(); i != obj_watchers.end(); ++i) {
       librbd::image_watcher_t watcher;
       watcher.addr = i->addr;
index c45cf989af8088d295b403df4f124fa4891452dd..8c7eb2ba4ca8b6df78ffa81bafb24ecc26bdda62 100644 (file)
@@ -10885,7 +10885,18 @@ TEST_F(TestLibRBD, TestListWatchers) {
   ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), nullptr));
   ASSERT_EQ(0, image.list_watchers(watchers));
   ASSERT_EQ(1U, watchers.size());
+  auto watcher1 = watchers.front();
   ASSERT_EQ(0, image.close());
+
+  // (Still) one watcher
+  ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), nullptr));
+  ASSERT_EQ(0, image.list_watchers(watchers));
+  ASSERT_EQ(1U, watchers.size());
+  auto watcher2 = watchers.front();
+  ASSERT_EQ(0, image.close());
+
+  EXPECT_EQ(watcher1.addr, watcher2.addr);
+  EXPECT_EQ(watcher1.id, watcher2.id);
 }
 
 TEST_F(TestLibRBD, TestSetSnapById) {