]>
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, | |
b32b8144 | 56 | cls::journal::ClientState *client_state, |
7c673cae FG |
57 | MirrorPeerClientMeta *client_meta, |
58 | Context *on_finish, | |
59 | bool *do_resync, | |
60 | ProgressContext *progress_ctx = nullptr) { | |
61 | return new BootstrapRequest(local_io_ctx, remote_io_ctx, | |
31f18b77 | 62 | instance_watcher, local_image_ctx, |
7c673cae FG |
63 | local_image_id, remote_image_id, |
64 | global_image_id, work_queue, timer, timer_lock, | |
65 | local_mirror_uuid, remote_mirror_uuid, | |
b32b8144 FG |
66 | journaler, client_state, client_meta, on_finish, |
67 | do_resync, progress_ctx); | |
7c673cae FG |
68 | } |
69 | ||
70 | BootstrapRequest(librados::IoCtx &local_io_ctx, | |
71 | librados::IoCtx &remote_io_ctx, | |
31f18b77 | 72 | InstanceWatcher<ImageCtxT> *instance_watcher, |
7c673cae FG |
73 | ImageCtxT **local_image_ctx, |
74 | const std::string &local_image_id, | |
75 | const std::string &remote_image_id, | |
76 | const std::string &global_image_id, ContextWQ *work_queue, | |
77 | SafeTimer *timer, Mutex *timer_lock, | |
78 | const std::string &local_mirror_uuid, | |
79 | const std::string &remote_mirror_uuid, Journaler *journaler, | |
b32b8144 | 80 | cls::journal::ClientState *client_state, |
7c673cae FG |
81 | MirrorPeerClientMeta *client_meta, Context *on_finish, |
82 | bool *do_resync, ProgressContext *progress_ctx = nullptr); | |
83 | ~BootstrapRequest() override; | |
84 | ||
c07f9fc5 FG |
85 | bool is_syncing() const; |
86 | ||
7c673cae FG |
87 | void send() override; |
88 | void cancel() override; | |
89 | ||
90 | private: | |
91 | /** | |
92 | * @verbatim | |
93 | * | |
94 | * <start> | |
95 | * | | |
96 | * v | |
d2e6a577 FG |
97 | * GET_REMOTE_TAG_CLASS * * * * * * * * * * * * * * * * * * |
98 | * | * (error) | |
99 | * v * | |
100 | * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * * * * | |
101 | * | * | |
b32b8144 FG |
102 | * |/--------------------------------------------------*---\ |
103 | * v * | | |
d2e6a577 FG |
104 | * IS_PRIMARY * * * * * * * * * * * * * * * * * * * * * * | |
105 | * | * * | | |
106 | * | (remote image primary, no local image id) * * | | |
107 | * \----> UPDATE_CLIENT_IMAGE * * * * * * * * * * * * | | |
108 | * | | * * | | |
109 | * | v * * | | |
110 | * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * * | | |
111 | * | | * * | | |
112 | * | v * * | | |
113 | * | (remote image primary) * * | | |
114 | * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * * | | |
115 | * | | . * * | | |
116 | * | | . (image doesn't exist) * * | | |
117 | * | | . . > UNREGISTER_CLIENT * * * * * * * | | |
118 | * | | | * * | | |
b32b8144 FG |
119 | * | | v * * | |
120 | * | | REGISTER_CLIENT * * * * * * * * | | |
121 | * | | | * * | | |
d2e6a577 FG |
122 | * | | \-----------------------*---*---/ |
123 | * | | * * | |
124 | * | v (skip if not needed) * * | |
125 | * | GET_REMOTE_TAGS * * * * * * * * * | |
126 | * | | * * * | |
127 | * | v (skip if not needed) v * * | |
128 | * | IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE * * | |
129 | * | | | * * | |
130 | * | \-----------------\ /-----/ * * | |
131 | * | | * * | |
132 | * | | * * | |
133 | * | (skip if not needed) | * * | |
134 | * \----> UPDATE_CLIENT_STATE *|* * * * * * * * * * * | |
135 | * | | * * | |
136 | * /-----------/----------------/ * * | |
137 | * | * * | |
138 | * v * * | |
139 | * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * * | |
140 | * | * | |
141 | * v * | |
142 | * <finish> < * * * * * * * * * * * * * * * * * * * * * * * | |
7c673cae FG |
143 | * |
144 | * @endverbatim | |
145 | */ | |
146 | typedef std::list<cls::journal::Tag> Tags; | |
147 | ||
148 | librados::IoCtx &m_local_io_ctx; | |
149 | librados::IoCtx &m_remote_io_ctx; | |
31f18b77 | 150 | InstanceWatcher<ImageCtxT> *m_instance_watcher; |
7c673cae FG |
151 | ImageCtxT **m_local_image_ctx; |
152 | std::string m_local_image_id; | |
153 | std::string m_remote_image_id; | |
154 | std::string m_global_image_id; | |
155 | ContextWQ *m_work_queue; | |
156 | SafeTimer *m_timer; | |
157 | Mutex *m_timer_lock; | |
158 | std::string m_local_mirror_uuid; | |
159 | std::string m_remote_mirror_uuid; | |
160 | Journaler *m_journaler; | |
b32b8144 | 161 | cls::journal::ClientState *m_client_state; |
7c673cae FG |
162 | MirrorPeerClientMeta *m_client_meta; |
163 | ProgressContext *m_progress_ctx; | |
164 | bool *m_do_resync; | |
31f18b77 | 165 | |
c07f9fc5 | 166 | mutable Mutex m_lock; |
7c673cae FG |
167 | bool m_canceled = false; |
168 | ||
169 | Tags m_remote_tags; | |
170 | cls::journal::Client m_client; | |
171 | uint64_t m_remote_tag_class = 0; | |
172 | ImageCtxT *m_remote_image_ctx = nullptr; | |
173 | bool m_primary = false; | |
174 | int m_ret_val = 0; | |
31f18b77 | 175 | ImageSync<ImageCtxT> *m_image_sync = nullptr; |
7c673cae FG |
176 | |
177 | bufferlist m_out_bl; | |
178 | ||
179 | void get_remote_tag_class(); | |
180 | void handle_get_remote_tag_class(int r); | |
181 | ||
7c673cae FG |
182 | void open_remote_image(); |
183 | void handle_open_remote_image(int r); | |
184 | ||
185 | void is_primary(); | |
186 | void handle_is_primary(int r); | |
187 | ||
188 | void update_client_state(); | |
189 | void handle_update_client_state(int r); | |
190 | ||
191 | void open_local_image(); | |
192 | void handle_open_local_image(int r); | |
193 | ||
d2e6a577 FG |
194 | void unregister_client(); |
195 | void handle_unregister_client(int r); | |
7c673cae | 196 | |
b32b8144 FG |
197 | void register_client(); |
198 | void handle_register_client(int r); | |
199 | ||
7c673cae FG |
200 | void create_local_image(); |
201 | void handle_create_local_image(int r); | |
202 | ||
203 | void update_client_image(); | |
204 | void handle_update_client_image(int r); | |
205 | ||
206 | void get_remote_tags(); | |
207 | void handle_get_remote_tags(int r); | |
208 | ||
209 | void image_sync(); | |
210 | void handle_image_sync(int r); | |
211 | ||
212 | void close_local_image(); | |
213 | void handle_close_local_image(int r); | |
214 | ||
215 | void close_remote_image(); | |
216 | void handle_close_remote_image(int r); | |
217 | ||
7c673cae FG |
218 | void update_progress(const std::string &description); |
219 | }; | |
220 | ||
221 | } // namespace image_replayer | |
222 | } // namespace mirror | |
223 | } // namespace rbd | |
224 | ||
225 | extern template class rbd::mirror::image_replayer::BootstrapRequest<librbd::ImageCtx>; | |
226 | ||
227 | #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H |