]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_RBD_MIRROR_CLUSTER_WATCHER_H | |
5 | #define CEPH_RBD_MIRROR_CLUSTER_WATCHER_H | |
6 | ||
7 | #include <map> | |
8 | #include <memory> | |
9 | #include <set> | |
10 | ||
11 | #include "common/ceph_context.h" | |
9f95a23c | 12 | #include "common/ceph_mutex.h" |
7c673cae FG |
13 | #include "common/Timer.h" |
14 | #include "include/rados/librados.hpp" | |
11fdf7f2 | 15 | #include "tools/rbd_mirror/Types.h" |
c07f9fc5 FG |
16 | #include "tools/rbd_mirror/service_daemon/Types.h" |
17 | #include <unordered_map> | |
18 | ||
19 | namespace librbd { struct ImageCtx; } | |
7c673cae FG |
20 | |
21 | namespace rbd { | |
22 | namespace mirror { | |
23 | ||
c07f9fc5 FG |
24 | template <typename> class ServiceDaemon; |
25 | ||
7c673cae FG |
26 | /** |
27 | * Tracks mirroring configuration for pools in a single | |
28 | * cluster. | |
29 | */ | |
30 | class ClusterWatcher { | |
31 | public: | |
11fdf7f2 TL |
32 | struct PeerSpecCompare { |
33 | bool operator()(const PeerSpec& lhs, const PeerSpec& rhs) const { | |
34 | return (lhs.uuid < rhs.uuid); | |
35 | } | |
36 | }; | |
37 | typedef std::set<PeerSpec, PeerSpecCompare> Peers; | |
7c673cae | 38 | typedef std::map<int64_t, Peers> PoolPeers; |
7c673cae | 39 | |
9f95a23c | 40 | ClusterWatcher(RadosRef cluster, ceph::mutex &lock, |
c07f9fc5 | 41 | ServiceDaemon<librbd::ImageCtx>* service_daemon); |
7c673cae FG |
42 | ~ClusterWatcher() = default; |
43 | ClusterWatcher(const ClusterWatcher&) = delete; | |
44 | ClusterWatcher& operator=(const ClusterWatcher&) = delete; | |
45 | ||
46 | // Caller controls frequency of calls | |
47 | void refresh_pools(); | |
48 | const PoolPeers& get_pool_peers() const; | |
9f95a23c | 49 | std::string get_site_name() const; |
7c673cae FG |
50 | |
51 | private: | |
c07f9fc5 FG |
52 | typedef std::unordered_map<int64_t, service_daemon::CalloutId> ServicePools; |
53 | ||
7c673cae | 54 | RadosRef m_cluster; |
9f95a23c | 55 | ceph::mutex &m_lock; |
c07f9fc5 FG |
56 | ServiceDaemon<librbd::ImageCtx>* m_service_daemon; |
57 | ||
58 | ServicePools m_service_pools; | |
7c673cae | 59 | PoolPeers m_pool_peers; |
9f95a23c | 60 | std::string m_site_name; |
7c673cae | 61 | |
11fdf7f2 TL |
62 | void read_pool_peers(PoolPeers *pool_peers); |
63 | ||
9f95a23c TL |
64 | int read_site_name(std::string* site_name); |
65 | ||
66 | int resolve_peer_site_config_keys( | |
67 | int64_t pool_id, const std::string& pool_name, PeerSpec* peer); | |
7c673cae FG |
68 | }; |
69 | ||
70 | } // namespace mirror | |
71 | } // namespace rbd | |
72 | ||
73 | #endif // CEPH_RBD_MIRROR_CLUSTER_WATCHER_H |