]> git.proxmox.com Git - ceph.git/blame - 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
CommitLineData
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
7#include "include/buffer.h"
b32b8144
FG
8#include "cls/journal/cls_journal_types.h"
9#include "librbd/journal/TypeTraits.h"
d2e6a577
FG
10#include <string>
11
b32b8144 12namespace journal { class Journaler; }
d2e6a577
FG
13namespace librados { struct IoCtx; }
14namespace librbd { struct ImageCtx; }
b32b8144 15namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
d2e6a577
FG
16
17struct Context;
18struct ContextWQ;
19
20namespace rbd {
21namespace mirror {
b32b8144
FG
22
23template <typename> struct Threads;
24
d2e6a577
FG
25namespace image_replayer {
26
27template <typename ImageCtxT = librbd::ImageCtx>
28class PrepareRemoteImageRequest {
29public:
b32b8144
FG
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,
d2e6a577 36 const std::string &global_image_id,
b32b8144
FG
37 const std::string &local_mirror_uuid,
38 const std::string &local_image_id,
d2e6a577
FG
39 std::string *remote_mirror_uuid,
40 std::string *remote_image_id,
b32b8144
FG
41 Journaler **remote_journaler,
42 cls::journal::ClientState *client_state,
43 MirrorPeerClientMeta *client_meta,
d2e6a577 44 Context *on_finish) {
b32b8144
FG
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);
d2e6a577
FG
50 }
51
b32b8144
FG
52 PrepareRemoteImageRequest(Threads<ImageCtxT> *threads,
53 librados::IoCtx &remote_io_ctx,
d2e6a577 54 const std::string &global_image_id,
b32b8144
FG
55 const std::string &local_mirror_uuid,
56 const std::string &local_image_id,
d2e6a577
FG
57 std::string *remote_mirror_uuid,
58 std::string *remote_image_id,
b32b8144
FG
59 Journaler **remote_journaler,
60 cls::journal::ClientState *client_state,
61 MirrorPeerClientMeta *client_meta,
d2e6a577 62 Context *on_finish)
b32b8144
FG
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),
d2e6a577
FG
66 m_remote_mirror_uuid(remote_mirror_uuid),
67 m_remote_image_id(remote_image_id),
b32b8144
FG
68 m_remote_journaler(remote_journaler), m_client_state(client_state),
69 m_client_meta(client_meta), m_on_finish(on_finish) {
d2e6a577
FG
70 }
71
72 void send();
73
74private:
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
b32b8144
FG
87 * GET_CLIENT
88 * |
89 * v (skip if not needed)
90 * REGISTER_CLIENT
91 * |
92 * v
d2e6a577
FG
93 * <finish>
94
95 * @endverbatim
96 */
97
b32b8144
FG
98 Threads<ImageCtxT> *m_threads;
99 librados::IoCtx &m_remote_io_ctx;
d2e6a577 100 std::string m_global_image_id;
b32b8144
FG
101 std::string m_local_mirror_uuid;
102 std::string m_local_image_id;
d2e6a577
FG
103 std::string *m_remote_mirror_uuid;
104 std::string *m_remote_image_id;
b32b8144
FG
105 Journaler **m_remote_journaler;
106 cls::journal::ClientState *m_client_state;
107 MirrorPeerClientMeta *m_client_meta;
d2e6a577
FG
108 Context *m_on_finish;
109
110 bufferlist m_out_bl;
b32b8144 111 cls::journal::Client m_client;
d2e6a577
FG
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
b32b8144
FG
119 void get_client();
120 void handle_get_client(int r);
121
122 void register_client();
123 void handle_register_client(int r);
124
d2e6a577
FG
125 void finish(int r);
126
b32b8144 127 bool decode_client_meta();
d2e6a577
FG
128};
129
130} // namespace image_replayer
131} // namespace mirror
132} // namespace rbd
133
134extern template class rbd::mirror::image_replayer::PrepareRemoteImageRequest<librbd::ImageCtx>;
135
136#endif // RBD_MIRROR_IMAGE_REPLAYER_PREPARE_REMOTE_IMAGE_REQUEST_H