]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/ClusterWatcher.h
import ceph quincy 17.2.4
[ceph.git] / ceph / src / tools / rbd_mirror / ClusterWatcher.h
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"
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>
18
19 namespace librbd { struct ImageCtx; }
20
21 namespace rbd {
22 namespace mirror {
23
24 template <typename> class ServiceDaemon;
25
26 /**
27 * Tracks mirroring configuration for pools in a single
28 * cluster.
29 */
30 class ClusterWatcher {
31 public:
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;
38 typedef std::map<int64_t, Peers> PoolPeers;
39
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;
45
46 // Caller controls frequency of calls
47 void refresh_pools();
48 const PoolPeers& get_pool_peers() const;
49 std::string get_site_name() const;
50
51 private:
52 typedef std::unordered_map<int64_t, service_daemon::CalloutId> ServicePools;
53
54 RadosRef m_cluster;
55 ceph::mutex &m_lock;
56 ServiceDaemon<librbd::ImageCtx>* m_service_daemon;
57
58 ServicePools m_service_pools;
59 PoolPeers m_pool_peers;
60 std::string m_site_name;
61
62 void read_pool_peers(PoolPeers *pool_peers);
63
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);
68 };
69
70 } // namespace mirror
71 } // namespace rbd
72
73 #endif // CEPH_RBD_MIRROR_CLUSTER_WATCHER_H