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