1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
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"
21 namespace journal
{ class Journaler
; }
22 namespace librbd
{ class ImageCtx
; }
23 namespace librbd
{ namespace journal
{ struct MirrorPeerClientMeta
; } }
28 class ProgressContext
;
30 template <typename
> class ImageSync
;
31 template <typename
> class InstanceWatcher
;
33 namespace image_replayer
{
35 template <typename ImageCtxT
= librbd::ImageCtx
>
36 class BootstrapRequest
: public BaseRequest
{
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
;
43 static BootstrapRequest
* create(
44 librados::IoCtx
&local_io_ctx
,
45 librados::IoCtx
&remote_io_ctx
,
46 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
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
,
53 const std::string
&local_mirror_uuid
,
54 const std::string
&remote_mirror_uuid
,
56 MirrorPeerClientMeta
*client_meta
,
59 ProgressContext
*progress_ctx
= nullptr) {
60 return new BootstrapRequest(local_io_ctx
, remote_io_ctx
,
61 instance_watcher
, local_image_ctx
,
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
,
69 BootstrapRequest(librados::IoCtx
&local_io_ctx
,
70 librados::IoCtx
&remote_io_ctx
,
71 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
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
;
83 bool is_syncing() const;
86 void cancel() override
;
95 * GET_REMOTE_TAG_CLASS * * * * * * * * * * * * * * * * * *
98 * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * * * *
101 * GET_CLIENT * * * * * * * * * * * * * * * * * * * * * *
103 * |/----------------------------------------------*---*---\
104 * v (skip if not needed) * * |
105 * REGISTER_CLIENT * * * * * * * * * * * * * * * * * * * |
108 * IS_PRIMARY * * * * * * * * * * * * * * * * * * * * * * |
110 * | (remote image primary, no local image id) * * |
111 * \----> UPDATE_CLIENT_IMAGE * * * * * * * * * * * * |
114 * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * * |
117 * | (remote image primary) * * |
118 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * * |
120 * | | . (image doesn't exist) * * |
121 * | | . . > UNREGISTER_CLIENT * * * * * * * |
123 * | | \-----------------------*---*---/
125 * | v (skip if not needed) * *
126 * | GET_REMOTE_TAGS * * * * * * * * *
128 * | v (skip if not needed) v * *
129 * | IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE * *
131 * | \-----------------\ /-----/ * *
134 * | (skip if not needed) | * *
135 * \----> UPDATE_CLIENT_STATE *|* * * * * * * * * * *
137 * /-----------/----------------/ * *
140 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * *
143 * <finish> < * * * * * * * * * * * * * * * * * * * * * * *
147 typedef std::list
<cls::journal::Tag
> Tags
;
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
;
159 std::string m_local_mirror_uuid
;
160 std::string m_remote_mirror_uuid
;
161 Journaler
*m_journaler
;
162 MirrorPeerClientMeta
*m_client_meta
;
163 ProgressContext
*m_progress_ctx
;
166 mutable Mutex m_lock
;
167 bool m_canceled
= false;
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;
175 ImageSync
<ImageCtxT
> *m_image_sync
= nullptr;
179 void get_remote_tag_class();
180 void handle_get_remote_tag_class(int r
);
183 void handle_get_client(int r
);
185 void register_client();
186 void handle_register_client(int r
);
188 void open_remote_image();
189 void handle_open_remote_image(int r
);
192 void handle_is_primary(int r
);
194 void update_client_state();
195 void handle_update_client_state(int r
);
197 void open_local_image();
198 void handle_open_local_image(int r
);
200 void unregister_client();
201 void handle_unregister_client(int r
);
203 void create_local_image();
204 void handle_create_local_image(int r
);
206 void update_client_image();
207 void handle_update_client_image(int r
);
209 void get_remote_tags();
210 void handle_get_remote_tags(int r
);
213 void handle_image_sync(int r
);
215 void close_local_image();
216 void handle_close_local_image(int r
);
218 void close_remote_image();
219 void handle_close_remote_image(int r
);
221 bool decode_client_meta();
223 void update_progress(const std::string
&description
);
226 } // namespace image_replayer
227 } // namespace mirror
230 extern template class rbd::mirror::image_replayer::BootstrapRequest
<librbd::ImageCtx
>;
232 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H