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
;
33 template <typename
> struct Threads
;
35 namespace image_replayer
{
37 template <typename ImageCtxT
= librbd::ImageCtx
>
38 class BootstrapRequest
: public BaseRequest
{
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
;
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
,
57 cls::journal::ClientState
*client_state
,
58 MirrorPeerClientMeta
*client_meta
,
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
,
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
;
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 * * * * * * * * * * * * |
110 * | | * (duplicate image id) * * |
112 * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * * |
115 * | (remote image primary) * * |
116 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * * |
118 * | | . (image doesn't exist) * * |
119 * | | . . > UNREGISTER_CLIENT * * * * * * * |
122 * | | REGISTER_CLIENT * * * * * * * * |
124 * | | \-----------------------*---*---/
126 * | v (skip if not needed) * *
127 * | GET_REMOTE_TAGS * * * * * * * * *
129 * | v (skip if not needed) v * *
130 * | IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE * *
132 * | \-----------------\ /-----/ * *
135 * | (skip if not needed) | * *
136 * \----> UPDATE_CLIENT_STATE *|* * * * * * * * * * *
138 * /-----------/----------------/ * *
141 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * *
144 * <finish> < * * * * * * * * * * * * * * * * * * * * * * *
148 typedef std::list
<cls::journal::Tag
> Tags
;
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
;
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;
177 uint64_t m_local_tag_tid
= 0;
178 librbd::journal::TagData m_local_tag_data
;
182 void get_remote_tag_class();
183 void handle_get_remote_tag_class(int r
);
185 void open_remote_image();
186 void handle_open_remote_image(int r
);
189 void handle_is_primary(int r
);
191 void update_client_state();
192 void handle_update_client_state(int r
);
194 void open_local_image();
195 void handle_open_local_image(int r
);
197 void unregister_client();
198 void handle_unregister_client(int r
);
200 void register_client();
201 void handle_register_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 void update_progress(const std::string
&description
);
224 } // namespace image_replayer
225 } // namespace mirror
228 extern template class rbd::mirror::image_replayer::BootstrapRequest
<librbd::ImageCtx
>;
230 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H