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_PREPARE_REMOTE_IMAGE_REQUEST_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H
7 #include "include/buffer_fwd.h"
8 #include "include/rados/librados_fwd.hpp"
9 #include "cls/journal/cls_journal_types.h"
10 #include "cls/rbd/cls_rbd_types.h"
11 #include "librbd/journal/Types.h"
12 #include "librbd/journal/TypeTraits.h"
13 #include "librbd/mirror/Types.h"
14 #include "tools/rbd_mirror/Types.h"
17 namespace journal
{ class Journaler
; }
18 namespace journal
{ struct CacheManagerHandler
; }
19 namespace librbd
{ struct ImageCtx
; }
20 namespace librbd
{ namespace journal
{ struct MirrorPeerClientMeta
; } }
27 template <typename
> struct Threads
;
29 namespace image_replayer
{
31 template <typename
> class StateBuilder
;
33 template <typename ImageCtxT
= librbd::ImageCtx
>
34 class PrepareRemoteImageRequest
{
36 typedef librbd::journal::TypeTraits
<ImageCtxT
> TypeTraits
;
37 typedef typename
TypeTraits::Journaler Journaler
;
38 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta
;
40 static PrepareRemoteImageRequest
*create(
41 Threads
<ImageCtxT
> *threads
,
42 librados::IoCtx
&local_io_ctx
,
43 librados::IoCtx
&remote_io_ctx
,
44 const std::string
&global_image_id
,
45 const std::string
&local_mirror_uuid
,
46 const RemotePoolMeta
& remote_pool_meta
,
47 ::journal::CacheManagerHandler
*cache_manager_handler
,
48 StateBuilder
<ImageCtxT
>** state_builder
,
50 return new PrepareRemoteImageRequest(threads
, local_io_ctx
, remote_io_ctx
,
51 global_image_id
, local_mirror_uuid
,
53 cache_manager_handler
, state_builder
,
57 PrepareRemoteImageRequest(
58 Threads
<ImageCtxT
> *threads
,
59 librados::IoCtx
&local_io_ctx
,
60 librados::IoCtx
&remote_io_ctx
,
61 const std::string
&global_image_id
,
62 const std::string
&local_mirror_uuid
,
63 const RemotePoolMeta
& remote_pool_meta
,
64 ::journal::CacheManagerHandler
*cache_manager_handler
,
65 StateBuilder
<ImageCtxT
>** state_builder
,
68 m_local_io_ctx(local_io_ctx
),
69 m_remote_io_ctx(remote_io_ctx
),
70 m_global_image_id(global_image_id
),
71 m_local_mirror_uuid(local_mirror_uuid
),
72 m_remote_pool_meta(remote_pool_meta
),
73 m_cache_manager_handler(cache_manager_handler
),
74 m_state_builder(state_builder
),
75 m_on_finish(on_finish
) {
90 * GET_REMOTE_MIRROR_INFO
93 * \-----------> GET_CLIENT
95 * | v (skip if not needed)
107 Threads
<ImageCtxT
> *m_threads
;
108 librados::IoCtx
&m_local_io_ctx
;
109 librados::IoCtx
&m_remote_io_ctx
;
110 std::string m_global_image_id
;
111 std::string m_local_mirror_uuid
;
112 RemotePoolMeta m_remote_pool_meta
;
113 ::journal::CacheManagerHandler
*m_cache_manager_handler
;
114 StateBuilder
<ImageCtxT
>** m_state_builder
;
115 Context
*m_on_finish
;
118 std::string m_remote_image_id
;
119 cls::rbd::MirrorImage m_mirror_image
;
120 librbd::mirror::PromotionState m_promotion_state
=
121 librbd::mirror::PROMOTION_STATE_UNKNOWN
;
122 std::string m_primary_mirror_uuid
;
124 // journal-based mirroring
125 Journaler
*m_remote_journaler
= nullptr;
126 cls::journal::Client m_client
;
128 void get_remote_image_id();
129 void handle_get_remote_image_id(int r
);
131 void get_mirror_info();
132 void handle_get_mirror_info(int r
);
135 void handle_get_client(int r
);
137 void register_client();
138 void handle_register_client(int r
);
140 void finalize_journal_state_builder(cls::journal::ClientState client_state
,
141 const MirrorPeerClientMeta
& client_meta
);
142 void finalize_snapshot_state_builder();
147 } // namespace image_replayer
148 } // namespace mirror
151 extern template class rbd::mirror::image_replayer::PrepareRemoteImageRequest
<librbd::ImageCtx
>;
153 #endif // RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H