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/Types.h"
12 #include "librbd/journal/TypeTraits.h"
13 #include "tools/rbd_mirror/BaseRequest.h"
14 #include "tools/rbd_mirror/types.h"
22 namespace journal
{ class Journaler
; }
23 namespace librbd
{ class ImageCtx
; }
24 namespace librbd
{ namespace journal
{ struct MirrorPeerClientMeta
; } }
29 class ProgressContext
;
31 template <typename
> class ImageSync
;
32 template <typename
> class InstanceWatcher
;
34 namespace image_replayer
{
36 template <typename ImageCtxT
= librbd::ImageCtx
>
37 class BootstrapRequest
: public BaseRequest
{
39 typedef librbd::journal::TypeTraits
<ImageCtxT
> TypeTraits
;
40 typedef typename
TypeTraits::Journaler Journaler
;
41 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta
;
42 typedef rbd::mirror::ProgressContext ProgressContext
;
44 static BootstrapRequest
* create(
45 librados::IoCtx
&local_io_ctx
,
46 librados::IoCtx
&remote_io_ctx
,
47 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
48 ImageCtxT
**local_image_ctx
,
49 const std::string
&local_image_id
,
50 const std::string
&remote_image_id
,
51 const std::string
&global_image_id
,
52 ContextWQ
*work_queue
, SafeTimer
*timer
,
54 const std::string
&local_mirror_uuid
,
55 const std::string
&remote_mirror_uuid
,
57 cls::journal::ClientState
*client_state
,
58 MirrorPeerClientMeta
*client_meta
,
61 ProgressContext
*progress_ctx
= nullptr) {
62 return new BootstrapRequest(local_io_ctx
, remote_io_ctx
,
63 instance_watcher
, local_image_ctx
,
64 local_image_id
, remote_image_id
,
65 global_image_id
, work_queue
, timer
, timer_lock
,
66 local_mirror_uuid
, remote_mirror_uuid
,
67 journaler
, client_state
, client_meta
, on_finish
,
68 do_resync
, progress_ctx
);
71 BootstrapRequest(librados::IoCtx
&local_io_ctx
,
72 librados::IoCtx
&remote_io_ctx
,
73 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
74 ImageCtxT
**local_image_ctx
,
75 const std::string
&local_image_id
,
76 const std::string
&remote_image_id
,
77 const std::string
&global_image_id
, ContextWQ
*work_queue
,
78 SafeTimer
*timer
, Mutex
*timer_lock
,
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
;
86 bool is_syncing() const;
89 void cancel() override
;
98 * GET_REMOTE_TAG_CLASS * * * * * * * * * * * * * * * * * *
101 * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * * * *
103 * |/--------------------------------------------------*---\
105 * IS_PRIMARY * * * * * * * * * * * * * * * * * * * * * * |
107 * | (remote image primary, no local image id) * * |
108 * \----> UPDATE_CLIENT_IMAGE * * * * * * * * * * * * |
111 * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * * |
114 * | (remote image primary) * * |
115 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * * |
117 * | | . (image doesn't exist) * * |
118 * | | . . > UNREGISTER_CLIENT * * * * * * * |
121 * | | REGISTER_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 cls::journal::ClientState
*m_client_state
;
163 MirrorPeerClientMeta
*m_client_meta
;
164 ProgressContext
*m_progress_ctx
;
167 mutable Mutex m_lock
;
168 bool m_canceled
= false;
171 cls::journal::Client m_client
;
172 uint64_t m_remote_tag_class
= 0;
173 ImageCtxT
*m_remote_image_ctx
= nullptr;
174 bool m_primary
= false;
176 ImageSync
<ImageCtxT
> *m_image_sync
= nullptr;
178 uint64_t m_local_tag_tid
= 0;
179 librbd::journal::TagData m_local_tag_data
;
183 void get_remote_tag_class();
184 void handle_get_remote_tag_class(int r
);
186 void open_remote_image();
187 void handle_open_remote_image(int r
);
190 void handle_is_primary(int r
);
192 void update_client_state();
193 void handle_update_client_state(int r
);
195 void open_local_image();
196 void handle_open_local_image(int r
);
198 void unregister_client();
199 void handle_unregister_client(int r
);
201 void register_client();
202 void handle_register_client(int r
);
204 void create_local_image();
205 void handle_create_local_image(int r
);
207 void update_client_image();
208 void handle_update_client_image(int r
);
210 void get_remote_tags();
211 void handle_get_remote_tags(int r
);
214 void handle_image_sync(int r
);
216 void close_local_image();
217 void handle_close_local_image(int r
);
219 void close_remote_image();
220 void handle_close_remote_image(int r
);
222 void update_progress(const std::string
&description
);
225 } // namespace image_replayer
226 } // namespace mirror
229 extern template class rbd::mirror::image_replayer::BootstrapRequest
<librbd::ImageCtx
>;
231 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H