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 namespace image_replayer
{
32 template <typename ImageCtxT
= librbd::ImageCtx
>
33 class BootstrapRequest
: public BaseRequest
{
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
;
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
,
50 const std::string
&local_mirror_uuid
,
51 const std::string
&remote_mirror_uuid
,
53 MirrorPeerClientMeta
*client_meta
,
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
,
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
;
81 void cancel() override
;
90 * GET_REMOTE_TAG_CLASS * * * * * * * * * * * * * * * *
93 * GET_CLIENT * * * * * * * * * * * * * * * * * * * * *
95 * v (skip if not needed) * (error)
96 * REGISTER_CLIENT * * * * * * * * * * * * * * * * * *
99 * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * *
102 * IS_PRIMARY * * * * * * * * * * * * * * * * * * * * *
104 * | (remote image primary) *
105 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * *
108 * | | . \-----------------------\ *
110 * | | . (image sync requested) | *
111 * | | . . > REMOVE_LOCAL_IMAGE * * * * *
113 * | | . (image doesn't | | *
115 * | | . . > CREATE_LOCAL_IMAGE * * * * *
117 * | | \-----------------/ *
119 * | v (skip if not needed) *
120 * | UPDATE_CLIENT_IMAGE * * * * * *
122 * | v (skip if not needed) * *
123 * | GET_REMOTE_TAGS * * * * * * * *
125 * | v (skip if not needed) v *
126 * | IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE *
128 * | \-----------------\ /-----/ *
131 * | (skip if not needed) | *
132 * \----> UPDATE_CLIENT_STATE *|* * * * * * * * * *
134 * /-----------/----------------/ *
137 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * *
144 typedef std::list
<cls::journal::Tag
> Tags
;
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
;
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
;
163 bool m_canceled
= false;
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;
174 void get_remote_tag_class();
175 void handle_get_remote_tag_class(int r
);
178 void handle_get_client(int r
);
180 void register_client();
181 void handle_register_client(int r
);
183 void open_remote_image();
184 void handle_open_remote_image(int r
);
187 void handle_is_primary(int r
);
189 void update_client_state();
190 void handle_update_client_state(int r
);
192 void open_local_image();
193 void handle_open_local_image(int r
);
195 void remove_local_image();
196 void handle_remove_local_image(int r
);
198 void create_local_image();
199 void handle_create_local_image(int r
);
201 void update_client_image();
202 void handle_update_client_image(int r
);
204 void get_remote_tags();
205 void handle_get_remote_tags(int r
);
208 void handle_image_sync(int r
);
210 void close_local_image();
211 void handle_close_local_image(int r
);
213 void close_remote_image();
214 void handle_close_remote_image(int r
);
216 bool decode_client_meta();
218 void update_progress(const std::string
&description
);
221 } // namespace image_replayer
222 } // namespace mirror
225 extern template class rbd::mirror::image_replayer::BootstrapRequest
<librbd::ImageCtx
>;
227 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H