]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/PoolWatcher.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / tools / rbd_mirror / PoolWatcher.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_POOL_WATCHER_H
5 #define CEPH_RBD_MIRROR_POOL_WATCHER_H
6
7 #include <map>
8 #include <memory>
9 #include <set>
10 #include <string>
11
12 #include "common/AsyncOpTracker.h"
13 #include "common/ceph_context.h"
14 #include "common/Mutex.h"
15 #include "include/rados/librados.hpp"
16 #include "types.h"
17 #include <boost/functional/hash.hpp>
18 #include <boost/optional.hpp>
19 #include "include/assert.h"
20
21 namespace librbd { struct ImageCtx; }
22
23 namespace rbd {
24 namespace mirror {
25
26 template <typename> struct Threads;
27
28 /**
29 * Keeps track of images that have mirroring enabled within all
30 * pools.
31 */
32 template <typename ImageCtxT = librbd::ImageCtx>
33 class PoolWatcher {
34 public:
35 struct Listener {
36 virtual ~Listener() {
37 }
38
39 virtual void handle_update(const std::string &mirror_uuid,
40 ImageIds &&added_image_ids,
41 ImageIds &&removed_image_ids) = 0;
42 };
43
44 PoolWatcher(Threads<ImageCtxT> *threads, librados::IoCtx &remote_io_ctx,
45 Listener &listener);
46 ~PoolWatcher();
47 PoolWatcher(const PoolWatcher&) = delete;
48 PoolWatcher& operator=(const PoolWatcher&) = delete;
49
50 bool is_blacklisted() const;
51
52 void init(Context *on_finish = nullptr);
53 void shut_down(Context *on_finish);
54
55 private:
56 /**
57 * @verbatim
58 *
59 * <start>
60 * |
61 * v
62 * INIT
63 * |
64 * v
65 * REGISTER_WATCHER
66 * |
67 * |/--------------------------------\
68 * | |
69 * v |
70 * REFRESH_IMAGES |
71 * | |
72 * |/----------------------------\ |
73 * | | |
74 * v | |
75 * GET_MIRROR_UUID | |
76 * | | |
77 * v | |
78 * NOTIFY_LISTENER | |
79 * | | |
80 * v | |
81 * IDLE ---\ | |
82 * | | | |
83 * | |\---> IMAGE_UPDATED | |
84 * | | | | |
85 * | | v | |
86 * | | GET_IMAGE_NAME --/ |
87 * | | |
88 * | \----> WATCH_ERROR ---------/
89 * v
90 * SHUT_DOWN
91 * |
92 * v
93 * UNREGISTER_WATCHER
94 * |
95 * v
96 * <finish>
97 *
98 * @endverbatim
99 */
100 class MirroringWatcher;
101
102 Threads<ImageCtxT> *m_threads;
103 librados::IoCtx m_remote_io_ctx;
104 Listener &m_listener;
105
106 ImageIds m_refresh_image_ids;
107 bufferlist m_out_bl;
108
109 mutable Mutex m_lock;
110
111 Context *m_on_init_finish = nullptr;
112
113 ImageIds m_image_ids;
114 std::string m_mirror_uuid;
115
116 bool m_pending_updates = false;
117 bool m_notify_listener_in_progress = false;
118 ImageIds m_pending_image_ids;
119 ImageIds m_pending_added_image_ids;
120 ImageIds m_pending_removed_image_ids;
121
122 std::string m_pending_mirror_uuid;
123
124 MirroringWatcher *m_mirroring_watcher;
125
126 Context *m_timer_ctx = nullptr;
127
128 AsyncOpTracker m_async_op_tracker;
129 bool m_blacklisted = false;
130 bool m_shutting_down = false;
131 bool m_image_ids_invalid = true;
132 bool m_refresh_in_progress = false;
133 bool m_deferred_refresh = false;
134
135 void register_watcher();
136 void handle_register_watcher(int r);
137 void unregister_watcher();
138
139 void refresh_images();
140 void handle_refresh_images(int r);
141
142 void schedule_refresh_images(double interval);
143 void process_refresh_images();
144
145 void get_mirror_uuid();
146 void handle_get_mirror_uuid(int r);
147
148 void handle_rewatch_complete(int r);
149 void handle_image_updated(const std::string &remote_image_id,
150 const std::string &global_image_id,
151 bool enabled);
152
153 void schedule_listener();
154 void notify_listener();
155
156 };
157
158 } // namespace mirror
159 } // namespace rbd
160
161 extern template class rbd::mirror::PoolWatcher<librbd::ImageCtx>;
162
163 #endif // CEPH_RBD_MIRROR_POOL_WATCHER_H