]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc
update sources to v12.1.3
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / PrepareRemoteImageRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h"
5 #include "include/rados/librados.hpp"
6 #include "cls/rbd/cls_rbd_client.h"
7 #include "common/errno.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/Utils.h"
10 #include "tools/rbd_mirror/image_replayer/GetMirrorImageIdRequest.h"
11
12 #define dout_context g_ceph_context
13 #define dout_subsys ceph_subsys_rbd_mirror
14 #undef dout_prefix
15 #define dout_prefix *_dout << "rbd::mirror::image_replayer::" \
16 << "PrepareRemoteImageRequest: " << this << " " \
17 << __func__ << ": "
18
19 namespace rbd {
20 namespace mirror {
21 namespace image_replayer {
22
23 using librbd::util::create_context_callback;
24 using librbd::util::create_rados_callback;
25
26 template <typename I>
27 void PrepareRemoteImageRequest<I>::send() {
28 get_remote_mirror_uuid();
29 }
30
31 template <typename I>
32 void PrepareRemoteImageRequest<I>::get_remote_mirror_uuid() {
33 dout(20) << dendl;
34
35 librados::ObjectReadOperation op;
36 librbd::cls_client::mirror_uuid_get_start(&op);
37
38 librados::AioCompletion *aio_comp = create_rados_callback<
39 PrepareRemoteImageRequest<I>,
40 &PrepareRemoteImageRequest<I>::handle_get_remote_mirror_uuid>(this);
41 int r = m_io_ctx.aio_operate(RBD_MIRRORING, aio_comp, &op, &m_out_bl);
42 assert(r == 0);
43 aio_comp->release();
44 }
45
46 template <typename I>
47 void PrepareRemoteImageRequest<I>::handle_get_remote_mirror_uuid(int r) {
48 if (r >= 0) {
49 bufferlist::iterator it = m_out_bl.begin();
50 r = librbd::cls_client::mirror_uuid_get_finish(&it, m_remote_mirror_uuid);
51 if (r >= 0 && m_remote_mirror_uuid->empty()) {
52 r = -ENOENT;
53 }
54 }
55
56 dout(20) << "r=" << r << dendl;
57 if (r < 0) {
58 if (r == -ENOENT) {
59 dout(5) << "remote mirror uuid missing" << dendl;
60 } else {
61 derr << "failed to retrieve remote mirror uuid: " << cpp_strerror(r)
62 << dendl;
63 }
64 finish(r);
65 return;
66 }
67
68 get_remote_image_id();
69 }
70
71 template <typename I>
72 void PrepareRemoteImageRequest<I>::get_remote_image_id() {
73 dout(20) << dendl;
74
75 Context *ctx = create_context_callback<
76 PrepareRemoteImageRequest<I>,
77 &PrepareRemoteImageRequest<I>::handle_get_remote_image_id>(this);
78 auto req = GetMirrorImageIdRequest<I>::create(m_io_ctx, m_global_image_id,
79 m_remote_image_id, ctx);
80 req->send();
81 }
82
83 template <typename I>
84 void PrepareRemoteImageRequest<I>::handle_get_remote_image_id(int r) {
85 dout(20) << "r=" << r << ", "
86 << "remote_image_id=" << *m_remote_image_id << dendl;
87
88 if (r < 0) {
89 finish(r);
90 return;
91 }
92
93 finish(0);
94 }
95
96 template <typename I>
97 void PrepareRemoteImageRequest<I>::finish(int r) {
98 dout(20) << "r=" << r << dendl;
99
100 m_on_finish->complete(r);
101 delete this;
102 }
103
104 } // namespace image_replayer
105 } // namespace mirror
106 } // namespace rbd
107
108 template class rbd::mirror::image_replayer::PrepareRemoteImageRequest<librbd::ImageCtx>;