]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/mirror/GetInfoRequest.cc
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / librbd / mirror / GetInfoRequest.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 "librbd/mirror/GetInfoRequest.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "cls/rbd/cls_rbd_client.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/ImageState.h"
10 #include "librbd/Journal.h"
11 #include "librbd/Utils.h"
12
13 #define dout_subsys ceph_subsys_rbd
14 #undef dout_prefix
15 #define dout_prefix *_dout << "librbd::mirror::GetInfoRequest: " << this \
16 << " " << __func__ << ": "
17
18 namespace librbd {
19 namespace mirror {
20
21 using librbd::util::create_context_callback;
22 using librbd::util::create_rados_callback;
23
24 template <typename I>
25 void GetInfoRequest<I>::send() {
26 get_mirror_image();
27 }
28
29 template <typename I>
30 void GetInfoRequest<I>::get_mirror_image() {
31 CephContext *cct = m_image_ctx.cct;
32 ldout(cct, 20) << dendl;
33
34 librados::ObjectReadOperation op;
35 cls_client::mirror_image_get_start(&op, m_image_ctx.id);
36
37 librados::AioCompletion *comp = create_rados_callback<
38 GetInfoRequest<I>, &GetInfoRequest<I>::handle_get_mirror_image>(this);
39 int r = m_image_ctx.md_ctx.aio_operate(RBD_MIRRORING, comp, &op, &m_out_bl);
40 ceph_assert(r == 0);
41 comp->release();
42 }
43
44 template <typename I>
45 void GetInfoRequest<I>::handle_get_mirror_image(int r) {
46 CephContext *cct = m_image_ctx.cct;
47 ldout(cct, 20) << "r=" << r << dendl;
48
49 m_mirror_image->state = cls::rbd::MIRROR_IMAGE_STATE_DISABLED;
50 *m_promotion_state = PROMOTION_STATE_NON_PRIMARY;
51 if (r == 0) {
52 auto iter = m_out_bl.cbegin();
53 r = cls_client::mirror_image_get_finish(&iter, m_mirror_image);
54 }
55
56 if (r == -ENOENT ||
57 m_mirror_image->state != cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
58 ldout(cct, 20) << "mirroring is disabled" << dendl;
59 finish(0);
60 return;
61 } else if (r < 0) {
62 lderr(cct) << "failed to retrieve mirroring state: " << cpp_strerror(r)
63 << dendl;
64 finish(r);
65 return;
66 }
67
68 get_tag_owner();
69 }
70
71 template <typename I>
72 void GetInfoRequest<I>::get_tag_owner() {
73 CephContext *cct = m_image_ctx.cct;
74 ldout(cct, 20) << dendl;
75
76 auto ctx = create_context_callback<
77 GetInfoRequest<I>, &GetInfoRequest<I>::handle_get_tag_owner>(this);
78 Journal<I>::get_tag_owner(m_image_ctx.md_ctx, m_image_ctx.id,
79 &m_mirror_uuid, m_image_ctx.op_work_queue, ctx);
80 }
81
82 template <typename I>
83 void GetInfoRequest<I>::handle_get_tag_owner(int r) {
84 CephContext *cct = m_image_ctx.cct;
85 ldout(cct, 20) << "r=" << r << dendl;
86
87 if (r < 0) {
88 lderr(cct) << "failed to determine tag ownership: " << cpp_strerror(r)
89 << dendl;
90 finish(r);
91 return;
92 }
93
94 if (m_mirror_uuid == Journal<>::LOCAL_MIRROR_UUID) {
95 *m_promotion_state = PROMOTION_STATE_PRIMARY;
96 } else if (m_mirror_uuid == Journal<>::ORPHAN_MIRROR_UUID) {
97 *m_promotion_state = PROMOTION_STATE_ORPHAN;
98 }
99
100 finish(0);
101 }
102
103 template <typename I>
104 void GetInfoRequest<I>::finish(int r) {
105 CephContext *cct = m_image_ctx.cct;
106 ldout(cct, 20) << "r=" << r << dendl;
107
108 m_on_finish->complete(r);
109 delete this;
110 }
111
112 } // namespace mirror
113 } // namespace librbd
114
115 template class librbd::mirror::GetInfoRequest<librbd::ImageCtx>;