]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h
update sources to v12.2.3
[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.h"
8 #include "cls/journal/cls_journal_types.h"
9 #include "librbd/journal/TypeTraits.h"
10 #include <string>
11
12 namespace journal { class Journaler; }
13 namespace librados { struct IoCtx; }
14 namespace librbd { struct ImageCtx; }
15 namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
16
17 struct Context;
18 struct ContextWQ;
19
20 namespace rbd {
21 namespace mirror {
22
23 template <typename> struct Threads;
24
25 namespace image_replayer {
26
27 template <typename ImageCtxT = librbd::ImageCtx>
28 class PrepareRemoteImageRequest {
29 public:
30 typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
31 typedef typename TypeTraits::Journaler Journaler;
32 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
33
34 static PrepareRemoteImageRequest *create(Threads<ImageCtxT> *threads,
35 librados::IoCtx &remote_io_ctx,
36 const std::string &global_image_id,
37 const std::string &local_mirror_uuid,
38 const std::string &local_image_id,
39 std::string *remote_mirror_uuid,
40 std::string *remote_image_id,
41 Journaler **remote_journaler,
42 cls::journal::ClientState *client_state,
43 MirrorPeerClientMeta *client_meta,
44 Context *on_finish) {
45 return new PrepareRemoteImageRequest(threads, remote_io_ctx,
46 global_image_id, local_mirror_uuid,
47 local_image_id, remote_mirror_uuid,
48 remote_image_id, remote_journaler,
49 client_state, client_meta, on_finish);
50 }
51
52 PrepareRemoteImageRequest(Threads<ImageCtxT> *threads,
53 librados::IoCtx &remote_io_ctx,
54 const std::string &global_image_id,
55 const std::string &local_mirror_uuid,
56 const std::string &local_image_id,
57 std::string *remote_mirror_uuid,
58 std::string *remote_image_id,
59 Journaler **remote_journaler,
60 cls::journal::ClientState *client_state,
61 MirrorPeerClientMeta *client_meta,
62 Context *on_finish)
63 : m_threads(threads), m_remote_io_ctx(remote_io_ctx),
64 m_global_image_id(global_image_id),
65 m_local_mirror_uuid(local_mirror_uuid), m_local_image_id(local_image_id),
66 m_remote_mirror_uuid(remote_mirror_uuid),
67 m_remote_image_id(remote_image_id),
68 m_remote_journaler(remote_journaler), m_client_state(client_state),
69 m_client_meta(client_meta), m_on_finish(on_finish) {
70 }
71
72 void send();
73
74 private:
75 /**
76 * @verbatim
77 *
78 * <start>
79 * |
80 * v
81 * GET_REMOTE_MIRROR_UUID
82 * |
83 * v
84 * GET_REMOTE_IMAGE_ID
85 * |
86 * v
87 * GET_CLIENT
88 * |
89 * v (skip if not needed)
90 * REGISTER_CLIENT
91 * |
92 * v
93 * <finish>
94
95 * @endverbatim
96 */
97
98 Threads<ImageCtxT> *m_threads;
99 librados::IoCtx &m_remote_io_ctx;
100 std::string m_global_image_id;
101 std::string m_local_mirror_uuid;
102 std::string m_local_image_id;
103 std::string *m_remote_mirror_uuid;
104 std::string *m_remote_image_id;
105 Journaler **m_remote_journaler;
106 cls::journal::ClientState *m_client_state;
107 MirrorPeerClientMeta *m_client_meta;
108 Context *m_on_finish;
109
110 bufferlist m_out_bl;
111 cls::journal::Client m_client;
112
113 void get_remote_mirror_uuid();
114 void handle_get_remote_mirror_uuid(int r);
115
116 void get_remote_image_id();
117 void handle_get_remote_image_id(int r);
118
119 void get_client();
120 void handle_get_client(int r);
121
122 void register_client();
123 void handle_register_client(int r);
124
125 void finish(int r);
126
127 bool decode_client_meta();
128 };
129
130 } // namespace image_replayer
131 } // namespace mirror
132 } // namespace rbd
133
134 extern template class rbd::mirror::image_replayer::PrepareRemoteImageRequest<librbd::ImageCtx>;
135
136 #endif // RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H