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