From 3c780822827911d3e61772e89bc91aa1b4c25686 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Wed, 4 Dec 2019 09:31:48 +0000 Subject: [PATCH] librbd: introduce LIST_WATCHERS_MIRROR_INSTANCES_ONLY flag Also, don't skip listing mirror watchers if the image has journaling disabled -- it is not correct for snapshot mirror mode. Signed-off-by: Mykola Golub --- src/librbd/image/ListWatchersRequest.cc | 22 ++++++++++++++-------- src/librbd/image/ListWatchersRequest.h | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/librbd/image/ListWatchersRequest.cc b/src/librbd/image/ListWatchersRequest.cc index 594c14445ee9d..05ae8d1a90e13 100644 --- a/src/librbd/image/ListWatchersRequest.cc +++ b/src/librbd/image/ListWatchersRequest.cc @@ -29,6 +29,8 @@ ListWatchersRequest::ListWatchersRequest(I &image_ctx, int flags, Context *on_finish) : m_image_ctx(image_ctx), m_flags(flags), m_watchers(watchers), m_on_finish(on_finish), m_cct(m_image_ctx.cct) { + ceph_assert((m_flags & LIST_WATCHERS_FILTER_OUT_MIRROR_INSTANCES) == 0 || + (m_flags & LIST_WATCHERS_MIRROR_INSTANCES_ONLY) == 0); } template @@ -75,8 +77,8 @@ void ListWatchersRequest::handle_list_image_watchers(int r) { template void ListWatchersRequest::list_mirror_watchers() { if ((m_object_watchers.empty()) || - (m_flags & LIST_WATCHERS_FILTER_OUT_MIRROR_INSTANCES) == 0 || - (m_image_ctx.features & RBD_FEATURE_JOURNALING) == 0) { + (m_flags & (LIST_WATCHERS_FILTER_OUT_MIRROR_INSTANCES | + LIST_WATCHERS_MIRROR_INSTANCES_ONLY)) == 0) { finish(0); return; } @@ -128,16 +130,20 @@ void ListWatchersRequest::finish(int r) { continue; } } + auto it = std::find_if(m_mirror_watchers.begin(), + m_mirror_watchers.end(), + [w] (obj_watch_t &watcher) { + return (strncmp(w.addr, watcher.addr, + sizeof(w.addr)) == 0); + }); if ((m_flags & LIST_WATCHERS_FILTER_OUT_MIRROR_INSTANCES) != 0) { - auto it = std::find_if(m_mirror_watchers.begin(), - m_mirror_watchers.end(), - [w] (obj_watch_t &watcher) { - return (strncmp(w.addr, watcher.addr, - sizeof(w.addr)) == 0); - }); if (it != m_mirror_watchers.end()) { continue; } + } else if ((m_flags & LIST_WATCHERS_MIRROR_INSTANCES_ONLY) != 0) { + if (it == m_mirror_watchers.end()) { + continue; + } } m_watchers->push_back(w); } diff --git a/src/librbd/image/ListWatchersRequest.h b/src/librbd/image/ListWatchersRequest.h index 941bf728ad6fb..2c77254a7c0b5 100644 --- a/src/librbd/image/ListWatchersRequest.h +++ b/src/librbd/image/ListWatchersRequest.h @@ -19,6 +19,7 @@ namespace image { enum { LIST_WATCHERS_FILTER_OUT_MY_INSTANCE = 1 << 0, LIST_WATCHERS_FILTER_OUT_MIRROR_INSTANCES = 1 << 1, + LIST_WATCHERS_MIRROR_INSTANCES_ONLY = 1 << 3, }; template -- 2.39.5