1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RBD_MIRROR_CLUSTER_WATCHER_H
5 #define CEPH_RBD_MIRROR_CLUSTER_WATCHER_H
11 #include "common/ceph_context.h"
12 #include "common/ceph_mutex.h"
13 #include "common/Timer.h"
14 #include "include/rados/librados.hpp"
15 #include "tools/rbd_mirror/Types.h"
16 #include "tools/rbd_mirror/service_daemon/Types.h"
17 #include <unordered_map>
19 namespace librbd
{ struct ImageCtx
; }
24 template <typename
> class ServiceDaemon
;
27 * Tracks mirroring configuration for pools in a single
30 class ClusterWatcher
{
32 struct PeerSpecCompare
{
33 bool operator()(const PeerSpec
& lhs
, const PeerSpec
& rhs
) const {
34 return (lhs
.uuid
< rhs
.uuid
);
37 typedef std::set
<PeerSpec
, PeerSpecCompare
> Peers
;
38 typedef std::map
<int64_t, Peers
> PoolPeers
;
40 ClusterWatcher(RadosRef cluster
, ceph::mutex
&lock
,
41 ServiceDaemon
<librbd::ImageCtx
>* service_daemon
);
42 ~ClusterWatcher() = default;
43 ClusterWatcher(const ClusterWatcher
&) = delete;
44 ClusterWatcher
& operator=(const ClusterWatcher
&) = delete;
46 // Caller controls frequency of calls
48 const PoolPeers
& get_pool_peers() const;
49 std::string
get_site_name() const;
52 typedef std::unordered_map
<int64_t, service_daemon::CalloutId
> ServicePools
;
56 ServiceDaemon
<librbd::ImageCtx
>* m_service_daemon
;
58 ServicePools m_service_pools
;
59 PoolPeers m_pool_peers
;
60 std::string m_site_name
;
62 void read_pool_peers(PoolPeers
*pool_peers
);
64 int read_site_name(std::string
* site_name
);
66 int resolve_peer_site_config_keys(
67 int64_t pool_id
, const std::string
& pool_name
, PeerSpec
* peer
);
73 #endif // CEPH_RBD_MIRROR_CLUSTER_WATCHER_H