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 * GET_CLIENT * * * * * * * * * * * * * * * * * * * * *
100 * v (skip if not needed) * (error)
101 * REGISTER_CLIENT * * * * * * * * * * * * * * * * * *
104 * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * *
107 * IS_PRIMARY * * * * * * * * * * * * * * * * * * * * *
109 * | (remote image primary) *
110 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * *
113 * | | . \-----------------------\ *
115 * | | . (image sync requested) | *
116 * | | . . > REMOVE_LOCAL_IMAGE * * * * *
118 * | | . (image doesn't | | *
120 * | | . . > CREATE_LOCAL_IMAGE * * * * *
122 * | | \-----------------/ *
124 * | v (skip if not needed) *
125 * | UPDATE_CLIENT_IMAGE * * * * * *
127 * | v (skip if not needed) * *
128 * | GET_REMOTE_TAGS * * * * * * * *
130 * | v (skip if not needed) v *
131 * | IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE *
133 * | \-----------------\ /-----/ *
136 * | (skip if not needed) | *
137 * \----> UPDATE_CLIENT_STATE *|* * * * * * * * * *
139 * /-----------/----------------/ *
142 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * *
149 typedef std::list
<cls::journal::Tag
> Tags
;
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 ContextWQ
*m_work_queue
;
161 std::string m_local_mirror_uuid
;
162 std::string m_remote_mirror_uuid
;
163 Journaler
*m_journaler
;
164 MirrorPeerClientMeta
*m_client_meta
;
165 ProgressContext
*m_progress_ctx
;
168 mutable Mutex m_lock
;
169 bool m_canceled
= false;
172 cls::journal::Client m_client
;
173 uint64_t m_remote_tag_class
= 0;
174 ImageCtxT
*m_remote_image_ctx
= nullptr;
175 bool m_primary
= false;
177 ImageSync
<ImageCtxT
> *m_image_sync
= nullptr;
181 void get_remote_tag_class();
182 void handle_get_remote_tag_class(int r
);
185 void handle_get_client(int r
);
187 void register_client();
188 void handle_register_client(int r
);
190 void open_remote_image();
191 void handle_open_remote_image(int r
);
194 void handle_is_primary(int r
);
196 void update_client_state();
197 void handle_update_client_state(int r
);
199 void open_local_image();
200 void handle_open_local_image(int r
);
202 void remove_local_image();
203 void handle_remove_local_image(int r
);
205 void create_local_image();
206 void handle_create_local_image(int r
);
208 void update_client_image();
209 void handle_update_client_image(int r
);
211 void get_remote_tags();
212 void handle_get_remote_tags(int r
);
215 void handle_image_sync(int r
);
217 void close_local_image();
218 void handle_close_local_image(int r
);
220 void close_remote_image();
221 void handle_close_remote_image(int r
);
223 bool decode_client_meta();
225 void update_progress(const std::string
&description
);
228 } // namespace image_replayer
229 } // namespace mirror
232 extern template class rbd::mirror::image_replayer::BootstrapRequest
<librbd::ImageCtx
>;
234 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H