Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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/Mutex.h"
13 #include "common/Timer.h"
14 #include "include/rados/librados.hpp"
15 #include "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   typedef std::set<peer_t> Peers;
33   typedef std::map<int64_t, Peers>  PoolPeers;
34   typedef std::set<std::string> PoolNames;
35
36   ClusterWatcher(RadosRef cluster, Mutex &lock,
37                  ServiceDaemon<librbd::ImageCtx>* service_daemon);
38   ~ClusterWatcher() = default;
39   ClusterWatcher(const ClusterWatcher&) = delete;
40   ClusterWatcher& operator=(const ClusterWatcher&) = delete;
41
42   // Caller controls frequency of calls
43   void refresh_pools();
44   const PoolPeers& get_pool_peers() const;
45
46 private:
47   typedef std::unordered_map<int64_t, service_daemon::CalloutId> ServicePools;
48
49   RadosRef m_cluster;
50   Mutex &m_lock;
51   ServiceDaemon<librbd::ImageCtx>* m_service_daemon;
52
53   ServicePools m_service_pools;
54   PoolPeers m_pool_peers;
55
56   void read_pool_peers(PoolPeers *pool_peers, PoolNames *pool_names);
57 };
58
59 } // namespace mirror
60 } // namespace rbd
61
62 #endif // CEPH_RBD_MIRROR_CLUSTER_WATCHER_H