]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: clear Image::list_watchers() list before populating it
authorIlya Dryomov <idryomov@gmail.com>
Thu, 30 Mar 2023 11:58:20 +0000 (13:58 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 6 Apr 2023 15:07:41 +0000 (17:07 +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>
(cherry picked from commit e11097bc4cf82b997ad1e8e21a8cd9400767f40d)

PendingReleaseNotes
src/librbd/internal.cc
src/test/librbd/test_librbd.cc

index fc7abbe533e8e3b907d26a51d8fada6d5972b8e7..464f7c46133849b49b3677b33cda4513e3ba17a2 100644 (file)
 * `ceph mgr dump` command now outputs `last_failure_osd_epoch` and
   `active_clients` fields at the top level.  Previously, these fields were
   output under `always_on_modules` field.
+* `ceph mgr dump` command now displays the name of the mgr module that
+  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) {