]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/GetMirrorImageIdRequest.cc
update sources to v12.1.3
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / GetMirrorImageIdRequest.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/GetMirrorImageIdRequest.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
11 #define dout_context g_ceph_context
12 #define dout_subsys ceph_subsys_rbd_mirror
13 #undef dout_prefix
14 #define dout_prefix *_dout << "rbd::mirror::image_replayer::" \
15 << "GetMirrorImageIdRequest: " << this << " " \
16 << __func__ << ": "
17
18 namespace rbd {
19 namespace mirror {
20 namespace image_replayer {
21
22 using librbd::util::create_rados_callback;
23
24 template <typename I>
25 void GetMirrorImageIdRequest<I>::send() {
26 dout(20) << dendl;
27 get_image_id();
28 }
29
30 template <typename I>
31 void GetMirrorImageIdRequest<I>::get_image_id() {
32 dout(20) << dendl;
33
34 // attempt to cross-reference a image id by the global image id
35 librados::ObjectReadOperation op;
36 librbd::cls_client::mirror_image_get_image_id_start(&op, m_global_image_id);
37
38 librados::AioCompletion *aio_comp = create_rados_callback<
39 GetMirrorImageIdRequest<I>,
40 &GetMirrorImageIdRequest<I>::handle_get_image_id>(
41 this);
42 int r = m_io_ctx.aio_operate(RBD_MIRRORING, aio_comp, &op, &m_out_bl);
43 assert(r == 0);
44 aio_comp->release();
45 }
46
47 template <typename I>
48 void GetMirrorImageIdRequest<I>::handle_get_image_id(int r) {
49 if (r == 0) {
50 bufferlist::iterator iter = m_out_bl.begin();
51 r = librbd::cls_client::mirror_image_get_image_id_finish(
52 &iter, m_image_id);
53 }
54
55 dout(20) << "r=" << r << ", "
56 << "image_id=" << *m_image_id << dendl;
57
58 if (r < 0) {
59 if (r == -ENOENT) {
60 dout(10) << "global image " << m_global_image_id << " not registered"
61 << dendl;
62 } else {
63 derr << "failed to retrieve image id: " << cpp_strerror(r) << dendl;
64 }
65 finish(r);
66 return;
67 }
68
69 finish(0);
70 }
71
72 template <typename I>
73 void GetMirrorImageIdRequest<I>::finish(int r) {
74 dout(20) << "r=" << r << dendl;
75
76 m_on_finish->complete(r);
77 delete this;
78 }
79
80 } // namespace image_replayer
81 } // namespace mirror
82 } // namespace rbd
83
84 template class rbd::mirror::image_replayer::GetMirrorImageIdRequest<librbd::ImageCtx>;