From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/tools/rbd_mirror/ClusterWatcher.h | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/tools/rbd_mirror/ClusterWatcher.h (limited to 'src/tools/rbd_mirror/ClusterWatcher.h') diff --git a/src/tools/rbd_mirror/ClusterWatcher.h b/src/tools/rbd_mirror/ClusterWatcher.h new file mode 100644 index 000000000..93356fec6 --- /dev/null +++ b/src/tools/rbd_mirror/ClusterWatcher.h @@ -0,0 +1,73 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_RBD_MIRROR_CLUSTER_WATCHER_H +#define CEPH_RBD_MIRROR_CLUSTER_WATCHER_H + +#include +#include +#include + +#include "common/ceph_context.h" +#include "common/ceph_mutex.h" +#include "common/Timer.h" +#include "include/rados/librados.hpp" +#include "tools/rbd_mirror/Types.h" +#include "tools/rbd_mirror/service_daemon/Types.h" +#include + +namespace librbd { struct ImageCtx; } + +namespace rbd { +namespace mirror { + +template class ServiceDaemon; + +/** + * Tracks mirroring configuration for pools in a single + * cluster. + */ +class ClusterWatcher { +public: + struct PeerSpecCompare { + bool operator()(const PeerSpec& lhs, const PeerSpec& rhs) const { + return (lhs.uuid < rhs.uuid); + } + }; + typedef std::set Peers; + typedef std::map PoolPeers; + + ClusterWatcher(RadosRef cluster, ceph::mutex &lock, + ServiceDaemon* service_daemon); + ~ClusterWatcher() = default; + ClusterWatcher(const ClusterWatcher&) = delete; + ClusterWatcher& operator=(const ClusterWatcher&) = delete; + + // Caller controls frequency of calls + void refresh_pools(); + const PoolPeers& get_pool_peers() const; + std::string get_site_name() const; + +private: + typedef std::unordered_map ServicePools; + + RadosRef m_cluster; + ceph::mutex &m_lock; + ServiceDaemon* m_service_daemon; + + ServicePools m_service_pools; + PoolPeers m_pool_peers; + std::string m_site_name; + + void read_pool_peers(PoolPeers *pool_peers); + + int read_site_name(std::string* site_name); + + int resolve_peer_site_config_keys( + int64_t pool_id, const std::string& pool_name, PeerSpec* peer); +}; + +} // namespace mirror +} // namespace rbd + +#endif // CEPH_RBD_MIRROR_CLUSTER_WATCHER_H -- cgit v1.2.3