]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / PrepareRemoteImageRequest.h
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
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"
15 #include <string>
16
17 namespace journal { class Journaler; }
18 namespace journal { struct CacheManagerHandler; }
19 namespace librbd { struct ImageCtx; }
20 namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
21
22 struct Context;
23
24 namespace rbd {
25 namespace mirror {
26
27 template <typename> struct Threads;
28
29 namespace image_replayer {
30
31 template <typename> class StateBuilder;
32
33 template <typename ImageCtxT = librbd::ImageCtx>
34 class PrepareRemoteImageRequest {
35 public:
36 typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
37 typedef typename TypeTraits::Journaler Journaler;
38 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
39
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,
49 Context *on_finish) {
50 return new PrepareRemoteImageRequest(threads, local_io_ctx, remote_io_ctx,
51 global_image_id, local_mirror_uuid,
52 remote_pool_meta,
53 cache_manager_handler, state_builder,
54 on_finish);
55 }
56
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,
66 Context *on_finish)
67 : m_threads(threads),
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) {
76 }
77
78 void send();
79
80 private:
81 /**
82 * @verbatim
83 *
84 * <start>
85 * |
86 * v
87 * GET_REMOTE_IMAGE_ID
88 * |
89 * v
90 * GET_REMOTE_MIRROR_INFO
91 * |
92 * | (journal)
93 * \-----------> GET_CLIENT
94 * | |
95 * | v (skip if not needed)
96 * | REGISTER_CLIENT
97 * | |
98 * | |
99 * |/----------------/
100 * |
101 * v
102 * <finish>
103 *
104 * @endverbatim
105 */
106
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;
116
117 bufferlist m_out_bl;
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;
123
124 // journal-based mirroring
125 Journaler *m_remote_journaler = nullptr;
126 cls::journal::Client m_client;
127
128 void get_remote_image_id();
129 void handle_get_remote_image_id(int r);
130
131 void get_mirror_info();
132 void handle_get_mirror_info(int r);
133
134 void get_client();
135 void handle_get_client(int r);
136
137 void register_client();
138 void handle_register_client(int r);
139
140 void finalize_journal_state_builder(cls::journal::ClientState client_state,
141 const MirrorPeerClientMeta& client_meta);
142 void finalize_snapshot_state_builder();
143
144 void finish(int r);
145 };
146
147 } // namespace image_replayer
148 } // namespace mirror
149 } // namespace rbd
150
151 extern template class rbd::mirror::image_replayer::PrepareRemoteImageRequest<librbd::ImageCtx>;
152
153 #endif // RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H