]>
Commit | Line | Data |
---|---|---|
d2e6a577 FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H | |
5 | #define RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H | |
6 | ||
11fdf7f2 TL |
7 | #include "include/buffer_fwd.h" |
8 | #include "include/rados/librados_fwd.hpp" | |
b32b8144 | 9 | #include "cls/journal/cls_journal_types.h" |
9f95a23c TL |
10 | #include "cls/rbd/cls_rbd_types.h" |
11 | #include "librbd/journal/Types.h" | |
b32b8144 | 12 | #include "librbd/journal/TypeTraits.h" |
9f95a23c TL |
13 | #include "librbd/mirror/Types.h" |
14 | #include "tools/rbd_mirror/Types.h" | |
d2e6a577 FG |
15 | #include <string> |
16 | ||
b32b8144 | 17 | namespace journal { class Journaler; } |
9f95a23c | 18 | namespace journal { struct CacheManagerHandler; } |
d2e6a577 | 19 | namespace librbd { struct ImageCtx; } |
b32b8144 | 20 | namespace librbd { namespace journal { struct MirrorPeerClientMeta; } } |
d2e6a577 FG |
21 | |
22 | struct Context; | |
23 | struct ContextWQ; | |
24 | ||
25 | namespace rbd { | |
26 | namespace mirror { | |
b32b8144 FG |
27 | |
28 | template <typename> struct Threads; | |
29 | ||
d2e6a577 FG |
30 | namespace image_replayer { |
31 | ||
9f95a23c TL |
32 | template <typename> class StateBuilder; |
33 | ||
d2e6a577 FG |
34 | template <typename ImageCtxT = librbd::ImageCtx> |
35 | class PrepareRemoteImageRequest { | |
36 | public: | |
b32b8144 FG |
37 | typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits; |
38 | typedef typename TypeTraits::Journaler Journaler; | |
39 | typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta; | |
40 | ||
9f95a23c TL |
41 | static PrepareRemoteImageRequest *create( |
42 | Threads<ImageCtxT> *threads, | |
43 | librados::IoCtx &local_io_ctx, | |
44 | librados::IoCtx &remote_io_ctx, | |
45 | const std::string &global_image_id, | |
46 | const std::string &local_mirror_uuid, | |
47 | const RemotePoolMeta& remote_pool_meta, | |
48 | ::journal::CacheManagerHandler *cache_manager_handler, | |
49 | StateBuilder<ImageCtxT>** state_builder, | |
50 | Context *on_finish) { | |
51 | return new PrepareRemoteImageRequest(threads, local_io_ctx, remote_io_ctx, | |
b32b8144 | 52 | global_image_id, local_mirror_uuid, |
9f95a23c TL |
53 | remote_pool_meta, |
54 | cache_manager_handler, state_builder, | |
55 | on_finish); | |
d2e6a577 FG |
56 | } |
57 | ||
9f95a23c TL |
58 | PrepareRemoteImageRequest( |
59 | Threads<ImageCtxT> *threads, | |
60 | librados::IoCtx &local_io_ctx, | |
61 | librados::IoCtx &remote_io_ctx, | |
62 | const std::string &global_image_id, | |
63 | const std::string &local_mirror_uuid, | |
64 | const RemotePoolMeta& remote_pool_meta, | |
65 | ::journal::CacheManagerHandler *cache_manager_handler, | |
66 | StateBuilder<ImageCtxT>** state_builder, | |
67 | Context *on_finish) | |
68 | : m_threads(threads), | |
69 | m_local_io_ctx(local_io_ctx), | |
70 | m_remote_io_ctx(remote_io_ctx), | |
b32b8144 | 71 | m_global_image_id(global_image_id), |
9f95a23c TL |
72 | m_local_mirror_uuid(local_mirror_uuid), |
73 | m_remote_pool_meta(remote_pool_meta), | |
74 | m_cache_manager_handler(cache_manager_handler), | |
75 | m_state_builder(state_builder), | |
76 | m_on_finish(on_finish) { | |
d2e6a577 FG |
77 | } |
78 | ||
79 | void send(); | |
80 | ||
81 | private: | |
82 | /** | |
83 | * @verbatim | |
84 | * | |
85 | * <start> | |
86 | * | | |
87 | * v | |
d2e6a577 FG |
88 | * GET_REMOTE_IMAGE_ID |
89 | * | | |
90 | * v | |
9f95a23c | 91 | * GET_REMOTE_MIRROR_INFO |
b32b8144 | 92 | * | |
9f95a23c TL |
93 | * | (journal) |
94 | * \-----------> GET_CLIENT | |
95 | * | | | |
96 | * | v (skip if not needed) | |
97 | * | REGISTER_CLIENT | |
98 | * | | | |
99 | * | | | |
100 | * |/----------------/ | |
b32b8144 FG |
101 | * | |
102 | * v | |
d2e6a577 | 103 | * <finish> |
9f95a23c | 104 | * |
d2e6a577 FG |
105 | * @endverbatim |
106 | */ | |
107 | ||
b32b8144 | 108 | Threads<ImageCtxT> *m_threads; |
9f95a23c | 109 | librados::IoCtx &m_local_io_ctx; |
b32b8144 | 110 | librados::IoCtx &m_remote_io_ctx; |
d2e6a577 | 111 | std::string m_global_image_id; |
b32b8144 | 112 | std::string m_local_mirror_uuid; |
9f95a23c TL |
113 | RemotePoolMeta m_remote_pool_meta; |
114 | ::journal::CacheManagerHandler *m_cache_manager_handler; | |
115 | StateBuilder<ImageCtxT>** m_state_builder; | |
d2e6a577 FG |
116 | Context *m_on_finish; |
117 | ||
118 | bufferlist m_out_bl; | |
9f95a23c TL |
119 | std::string m_remote_image_id; |
120 | cls::rbd::MirrorImage m_mirror_image; | |
121 | librbd::mirror::PromotionState m_promotion_state = | |
122 | librbd::mirror::PROMOTION_STATE_UNKNOWN; | |
123 | std::string m_primary_mirror_uuid; | |
124 | ||
125 | // journal-based mirroring | |
126 | Journaler *m_remote_journaler = nullptr; | |
b32b8144 | 127 | cls::journal::Client m_client; |
d2e6a577 | 128 | |
d2e6a577 FG |
129 | void get_remote_image_id(); |
130 | void handle_get_remote_image_id(int r); | |
131 | ||
9f95a23c TL |
132 | void get_mirror_info(); |
133 | void handle_get_mirror_info(int r); | |
134 | ||
b32b8144 FG |
135 | void get_client(); |
136 | void handle_get_client(int r); | |
137 | ||
138 | void register_client(); | |
139 | void handle_register_client(int r); | |
140 | ||
9f95a23c TL |
141 | void finalize_journal_state_builder(cls::journal::ClientState client_state, |
142 | const MirrorPeerClientMeta& client_meta); | |
143 | void finalize_snapshot_state_builder(int r); | |
144 | ||
d2e6a577 | 145 | void finish(int r); |
d2e6a577 FG |
146 | }; |
147 | ||
148 | } // namespace image_replayer | |
149 | } // namespace mirror | |
150 | } // namespace rbd | |
151 | ||
152 | extern template class rbd::mirror::image_replayer::PrepareRemoteImageRequest<librbd::ImageCtx>; | |
153 | ||
154 | #endif // RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H |