]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h
update sources to ceph Nautilus 14.2.1
[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 template <typename> struct Threads;
34
35 namespace image_replayer {
36
37 template <typename ImageCtxT = librbd::ImageCtx>
38 class BootstrapRequest : public BaseRequest {
39 public:
40 typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
41 typedef typename TypeTraits::Journaler Journaler;
42 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
43 typedef rbd::mirror::ProgressContext ProgressContext;
44
45 static BootstrapRequest* create(
46 Threads<ImageCtxT>* threads,
47 librados::IoCtx &local_io_ctx,
48 librados::IoCtx &remote_io_ctx,
49 InstanceWatcher<ImageCtxT> *instance_watcher,
50 ImageCtxT **local_image_ctx,
51 const std::string &local_image_id,
52 const std::string &remote_image_id,
53 const std::string &global_image_id,
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(threads, local_io_ctx, remote_io_ctx,
63 instance_watcher, local_image_ctx,
64 local_image_id, remote_image_id,
65 global_image_id, local_mirror_uuid,
66 remote_mirror_uuid, journaler, client_state,
67 client_meta, on_finish, do_resync,
68 progress_ctx);
69 }
70
71 BootstrapRequest(Threads<ImageCtxT>* threads,
72 librados::IoCtx &local_io_ctx,
73 librados::IoCtx &remote_io_ctx,
74 InstanceWatcher<ImageCtxT> *instance_watcher,
75 ImageCtxT **local_image_ctx,
76 const std::string &local_image_id,
77 const std::string &remote_image_id,
78 const std::string &global_image_id,
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 * | | * (duplicate image id) * * |
111 * | v * * * |
112 * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * * |
113 * | | * * |
114 * | v * * |
115 * | (remote image primary) * * |
116 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * * |
117 * | | . * * |
118 * | | . (image doesn't exist) * * |
119 * | | . . > UNREGISTER_CLIENT * * * * * * * |
120 * | | | * * |
121 * | | v * * |
122 * | | REGISTER_CLIENT * * * * * * * * |
123 * | | | * * |
124 * | | \-----------------------*---*---/
125 * | | * *
126 * | v (skip if not needed) * *
127 * | GET_REMOTE_TAGS * * * * * * * * *
128 * | | * * *
129 * | v (skip if not needed) v * *
130 * | IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE * *
131 * | | | * *
132 * | \-----------------\ /-----/ * *
133 * | | * *
134 * | | * *
135 * | (skip if not needed) | * *
136 * \----> UPDATE_CLIENT_STATE *|* * * * * * * * * * *
137 * | | * *
138 * /-----------/----------------/ * *
139 * | * *
140 * v * *
141 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * *
142 * | *
143 * v *
144 * <finish> < * * * * * * * * * * * * * * * * * * * * * * *
145 *
146 * @endverbatim
147 */
148 typedef std::list<cls::journal::Tag> Tags;
149
150 Threads<ImageCtxT>* m_threads;
151 librados::IoCtx &m_local_io_ctx;
152 librados::IoCtx &m_remote_io_ctx;
153 InstanceWatcher<ImageCtxT> *m_instance_watcher;
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 std::string m_local_mirror_uuid;
159 std::string m_remote_mirror_uuid;
160 Journaler *m_journaler;
161 cls::journal::ClientState *m_client_state;
162 MirrorPeerClientMeta *m_client_meta;
163 ProgressContext *m_progress_ctx;
164 bool *m_do_resync;
165
166 mutable Mutex m_lock;
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;
175 ImageSync<ImageCtxT> *m_image_sync = nullptr;
176
177 uint64_t m_local_tag_tid = 0;
178 librbd::journal::TagData m_local_tag_data;
179
180 bufferlist m_out_bl;
181
182 void get_remote_tag_class();
183 void handle_get_remote_tag_class(int r);
184
185 void open_remote_image();
186 void handle_open_remote_image(int r);
187
188 void is_primary();
189 void handle_is_primary(int r);
190
191 void update_client_state();
192 void handle_update_client_state(int r);
193
194 void open_local_image();
195 void handle_open_local_image(int r);
196
197 void unregister_client();
198 void handle_unregister_client(int r);
199
200 void register_client();
201 void handle_register_client(int r);
202
203 void create_local_image();
204 void handle_create_local_image(int r);
205
206 void update_client_image();
207 void handle_update_client_image(int r);
208
209 void get_remote_tags();
210 void handle_get_remote_tags(int r);
211
212 void image_sync();
213 void handle_image_sync(int r);
214
215 void close_local_image();
216 void handle_close_local_image(int r);
217
218 void close_remote_image();
219 void handle_close_remote_image(int r);
220
221 void update_progress(const std::string &description);
222 };
223
224 } // namespace image_replayer
225 } // namespace mirror
226 } // namespace rbd
227
228 extern template class rbd::mirror::image_replayer::BootstrapRequest<librbd::ImageCtx>;
229
230 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H