Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tools / rbd_mirror / ServiceDaemon.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_SERVICE_DAEMON_H
5 #define CEPH_RBD_MIRROR_SERVICE_DAEMON_H
6
7 #include "common/Mutex.h"
8 #include "tools/rbd_mirror/types.h"
9 #include "tools/rbd_mirror/service_daemon/Types.h"
10 #include <map>
11 #include <string>
12
13 struct CephContext;
14 struct Context;
15 namespace librbd { struct ImageCtx; }
16
17 namespace rbd {
18 namespace mirror {
19
20 template <typename> struct Threads;
21
22 template <typename ImageCtxT = librbd::ImageCtx>
23 class ServiceDaemon {
24 public:
25   ServiceDaemon(CephContext *cct, RadosRef rados, Threads<ImageCtxT>* threads);
26   ~ServiceDaemon();
27
28   int init();
29
30   void add_pool(int64_t pool_id, const std::string& pool_name);
31   void remove_pool(int64_t pool_id);
32
33   uint64_t add_or_update_callout(int64_t pool_id, uint64_t callout_id,
34                                  service_daemon::CalloutLevel callout_level,
35                                  const std::string& text);
36   void remove_callout(int64_t pool_id, uint64_t callout_id);
37
38   void add_or_update_attribute(int64_t pool_id, const std::string& key,
39                                const service_daemon::AttributeValue& value);
40   void remove_attribute(int64_t pool_id, const std::string& key);
41
42 private:
43   struct Callout {
44     service_daemon::CalloutLevel level;
45     std::string text;
46
47     Callout() : level(service_daemon::CALLOUT_LEVEL_INFO) {
48     }
49     Callout(service_daemon::CalloutLevel level, const std::string& text)
50       : level(level), text(text) {
51     }
52   };
53   typedef std::map<uint64_t, Callout> Callouts;
54   typedef std::map<std::string, service_daemon::AttributeValue> Attributes;
55
56   struct Pool {
57     std::string name;
58     Callouts callouts;
59     Attributes attributes;
60
61     Pool(const std::string& name) : name(name) {
62     }
63   };
64
65   typedef std::map<int64_t, Pool> Pools;
66
67   CephContext *m_cct;
68   RadosRef m_rados;
69   Threads<ImageCtxT>* m_threads;
70
71   Mutex m_lock;
72   Pools m_pools;
73   uint64_t m_callout_id = service_daemon::CALLOUT_ID_NONE;
74
75   Context* m_timer_ctx = nullptr;
76
77   void schedule_update_status();
78   void update_status();
79 };
80
81 } // namespace mirror
82 } // namespace rbd
83
84 extern template class rbd::mirror::ServiceDaemon<librbd::ImageCtx>;
85
86 #endif // CEPH_RBD_MIRROR_SERVICE_DAEMON_H