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