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 <mgolub@suse.com>
This commit is contained in:
Mykola Golub 2019-12-04 09:31:48 +00:00
parent fe550f5e52
commit 3c78082282
2 changed files with 15 additions and 8 deletions

View File

@ -29,6 +29,8 @@ ListWatchersRequest<I>::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<typename I>
@ -75,8 +77,8 @@ void ListWatchersRequest<I>::handle_list_image_watchers(int r) {
template<typename I>
void ListWatchersRequest<I>::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<I>::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);
}

View File

@ -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<typename ImageCtxT = ImageCtx>