]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/rbd_mirror/ClusterWatcher.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / tools / rbd_mirror / ClusterWatcher.h
CommitLineData
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"
12#include "common/Mutex.h"
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
19namespace librbd { struct ImageCtx; }
7c673cae
FG
20
21namespace rbd {
22namespace mirror {
23
c07f9fc5
FG
24template <typename> class ServiceDaemon;
25
7c673cae
FG
26/**
27 * Tracks mirroring configuration for pools in a single
28 * cluster.
29 */
30class ClusterWatcher {
31public:
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
c07f9fc5
FG
40 ClusterWatcher(RadosRef cluster, Mutex &lock,
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;
49
50private:
c07f9fc5
FG
51 typedef std::unordered_map<int64_t, service_daemon::CalloutId> ServicePools;
52
7c673cae 53 RadosRef m_cluster;
c07f9fc5
FG
54 Mutex &m_lock;
55 ServiceDaemon<librbd::ImageCtx>* m_service_daemon;
56
57 ServicePools m_service_pools;
7c673cae
FG
58 PoolPeers m_pool_peers;
59
11fdf7f2
TL
60 void read_pool_peers(PoolPeers *pool_peers);
61
62 int resolve_peer_config_keys(int64_t pool_id, const std::string& pool_name,
63 PeerSpec* peer);
7c673cae
FG
64};
65
66} // namespace mirror
67} // namespace rbd
68
69#endif // CEPH_RBD_MIRROR_CLUSTER_WATCHER_H