]>
Commit | Line | Data |
---|---|---|
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 RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H | |
5 | #define RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include "include/rados/librados.hpp" | |
9 | #include "common/Mutex.h" | |
10 | #include "cls/journal/cls_journal_types.h" | |
11 | #include "librbd/journal/TypeTraits.h" | |
12 | #include "tools/rbd_mirror/BaseRequest.h" | |
13 | #include "tools/rbd_mirror/types.h" | |
14 | #include <list> | |
15 | #include <string> | |
16 | ||
17 | class Context; | |
18 | class ContextWQ; | |
19 | class Mutex; | |
20 | class SafeTimer; | |
21 | namespace journal { class Journaler; } | |
22 | namespace librbd { class ImageCtx; } | |
23 | namespace librbd { namespace journal { struct MirrorPeerClientMeta; } } | |
24 | ||
25 | namespace rbd { | |
26 | namespace mirror { | |
27 | ||
28 | class ProgressContext; | |
29 | ||
31f18b77 FG |
30 | template <typename> class ImageSync; |
31 | template <typename> class InstanceWatcher; | |
32 | ||
7c673cae FG |
33 | namespace image_replayer { |
34 | ||
35 | template <typename ImageCtxT = librbd::ImageCtx> | |
36 | class BootstrapRequest : public BaseRequest { | |
37 | public: | |
38 | typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits; | |
39 | typedef typename TypeTraits::Journaler Journaler; | |
40 | typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta; | |
41 | typedef rbd::mirror::ProgressContext ProgressContext; | |
42 | ||
43 | static BootstrapRequest* create( | |
44 | librados::IoCtx &local_io_ctx, | |
45 | librados::IoCtx &remote_io_ctx, | |
31f18b77 | 46 | InstanceWatcher<ImageCtxT> *instance_watcher, |
7c673cae FG |
47 | ImageCtxT **local_image_ctx, |
48 | const std::string &local_image_id, | |
49 | const std::string &remote_image_id, | |
50 | const std::string &global_image_id, | |
51 | ContextWQ *work_queue, SafeTimer *timer, | |
52 | Mutex *timer_lock, | |
53 | const std::string &local_mirror_uuid, | |
54 | const std::string &remote_mirror_uuid, | |
55 | Journaler *journaler, | |
56 | MirrorPeerClientMeta *client_meta, | |
57 | Context *on_finish, | |
58 | bool *do_resync, | |
59 | ProgressContext *progress_ctx = nullptr) { | |
60 | return new BootstrapRequest(local_io_ctx, remote_io_ctx, | |
31f18b77 | 61 | instance_watcher, local_image_ctx, |
7c673cae FG |
62 | local_image_id, remote_image_id, |
63 | global_image_id, work_queue, timer, timer_lock, | |
64 | local_mirror_uuid, remote_mirror_uuid, | |
65 | journaler, client_meta, on_finish, do_resync, | |
66 | progress_ctx); | |
67 | } | |
68 | ||
69 | BootstrapRequest(librados::IoCtx &local_io_ctx, | |
70 | librados::IoCtx &remote_io_ctx, | |
31f18b77 | 71 | InstanceWatcher<ImageCtxT> *instance_watcher, |
7c673cae FG |
72 | ImageCtxT **local_image_ctx, |
73 | const std::string &local_image_id, | |
74 | const std::string &remote_image_id, | |
75 | const std::string &global_image_id, ContextWQ *work_queue, | |
76 | SafeTimer *timer, Mutex *timer_lock, | |
77 | const std::string &local_mirror_uuid, | |
78 | const std::string &remote_mirror_uuid, Journaler *journaler, | |
79 | MirrorPeerClientMeta *client_meta, Context *on_finish, | |
80 | bool *do_resync, ProgressContext *progress_ctx = nullptr); | |
81 | ~BootstrapRequest() override; | |
82 | ||
c07f9fc5 FG |
83 | bool is_syncing() const; |
84 | ||
7c673cae FG |
85 | void send() override; |
86 | void cancel() override; | |
87 | ||
88 | private: | |
89 | /** | |
90 | * @verbatim | |
91 | * | |
92 | * <start> | |
93 | * | | |
94 | * v | |
95 | * GET_REMOTE_TAG_CLASS * * * * * * * * * * * * * * * * | |
96 | * | * | |
97 | * v * | |
98 | * GET_CLIENT * * * * * * * * * * * * * * * * * * * * * | |
99 | * | * | |
100 | * v (skip if not needed) * (error) | |
101 | * REGISTER_CLIENT * * * * * * * * * * * * * * * * * * | |
102 | * | * | |
103 | * v * | |
104 | * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * * | |
105 | * | * | |
106 | * v * | |
107 | * IS_PRIMARY * * * * * * * * * * * * * * * * * * * * * | |
108 | * | * | |
109 | * | (remote image primary) * | |
110 | * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * | |
111 | * | | . ^ * | |
112 | * | | . | * | |
113 | * | | . \-----------------------\ * | |
114 | * | | . | * | |
115 | * | | . (image sync requested) | * | |
116 | * | | . . > REMOVE_LOCAL_IMAGE * * * * * | |
117 | * | | . | | * | |
118 | * | | . (image doesn't | | * | |
119 | * | | . exist) v | * | |
120 | * | | . . > CREATE_LOCAL_IMAGE * * * * * | |
121 | * | | | | * | |
122 | * | | \-----------------/ * | |
123 | * | | * | |
124 | * | v (skip if not needed) * | |
125 | * | UPDATE_CLIENT_IMAGE * * * * * * | |
126 | * | | * * | |
127 | * | v (skip if not needed) * * | |
128 | * | GET_REMOTE_TAGS * * * * * * * * | |
129 | * | | * * | |
130 | * | v (skip if not needed) v * | |
131 | * | IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE * | |
132 | * | | | * | |
133 | * | \-----------------\ /-----/ * | |
134 | * | | * | |
135 | * | | * | |
136 | * | (skip if not needed) | * | |
137 | * \----> UPDATE_CLIENT_STATE *|* * * * * * * * * * | |
138 | * | | * | |
139 | * /-----------/----------------/ * | |
140 | * | * | |
141 | * v * | |
142 | * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * | |
143 | * | | |
144 | * v | |
145 | * <finish> | |
146 | * | |
147 | * @endverbatim | |
148 | */ | |
149 | typedef std::list<cls::journal::Tag> Tags; | |
150 | ||
151 | librados::IoCtx &m_local_io_ctx; | |
152 | librados::IoCtx &m_remote_io_ctx; | |
31f18b77 | 153 | InstanceWatcher<ImageCtxT> *m_instance_watcher; |
7c673cae FG |
154 | ImageCtxT **m_local_image_ctx; |
155 | std::string m_local_image_id; | |
156 | std::string m_remote_image_id; | |
157 | std::string m_global_image_id; | |
158 | ContextWQ *m_work_queue; | |
159 | SafeTimer *m_timer; | |
160 | Mutex *m_timer_lock; | |
161 | std::string m_local_mirror_uuid; | |
162 | std::string m_remote_mirror_uuid; | |
163 | Journaler *m_journaler; | |
164 | MirrorPeerClientMeta *m_client_meta; | |
165 | ProgressContext *m_progress_ctx; | |
166 | bool *m_do_resync; | |
31f18b77 | 167 | |
c07f9fc5 | 168 | mutable Mutex m_lock; |
7c673cae FG |
169 | bool m_canceled = false; |
170 | ||
171 | Tags m_remote_tags; | |
172 | cls::journal::Client m_client; | |
173 | uint64_t m_remote_tag_class = 0; | |
174 | ImageCtxT *m_remote_image_ctx = nullptr; | |
175 | bool m_primary = false; | |
176 | int m_ret_val = 0; | |
31f18b77 | 177 | ImageSync<ImageCtxT> *m_image_sync = nullptr; |
7c673cae FG |
178 | |
179 | bufferlist m_out_bl; | |
180 | ||
181 | void get_remote_tag_class(); | |
182 | void handle_get_remote_tag_class(int r); | |
183 | ||
184 | void get_client(); | |
185 | void handle_get_client(int r); | |
186 | ||
187 | void register_client(); | |
188 | void handle_register_client(int r); | |
189 | ||
190 | void open_remote_image(); | |
191 | void handle_open_remote_image(int r); | |
192 | ||
193 | void is_primary(); | |
194 | void handle_is_primary(int r); | |
195 | ||
196 | void update_client_state(); | |
197 | void handle_update_client_state(int r); | |
198 | ||
199 | void open_local_image(); | |
200 | void handle_open_local_image(int r); | |
201 | ||
202 | void remove_local_image(); | |
203 | void handle_remove_local_image(int r); | |
204 | ||
205 | void create_local_image(); | |
206 | void handle_create_local_image(int r); | |
207 | ||
208 | void update_client_image(); | |
209 | void handle_update_client_image(int r); | |
210 | ||
211 | void get_remote_tags(); | |
212 | void handle_get_remote_tags(int r); | |
213 | ||
214 | void image_sync(); | |
215 | void handle_image_sync(int r); | |
216 | ||
217 | void close_local_image(); | |
218 | void handle_close_local_image(int r); | |
219 | ||
220 | void close_remote_image(); | |
221 | void handle_close_remote_image(int r); | |
222 | ||
223 | bool decode_client_meta(); | |
224 | ||
225 | void update_progress(const std::string &description); | |
226 | }; | |
227 | ||
228 | } // namespace image_replayer | |
229 | } // namespace mirror | |
230 | } // namespace rbd | |
231 | ||
232 | extern template class rbd::mirror::image_replayer::BootstrapRequest<librbd::ImageCtx>; | |
233 | ||
234 | #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H |