1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
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"
13 #define dout_subsys ceph_subsys_rbd
15 #define dout_prefix *_dout << "librbd::mirror::GetInfoRequest: " << this \
16 << " " << __func__ << ": "
21 using librbd::util::create_context_callback
;
22 using librbd::util::create_rados_callback
;
25 void GetInfoRequest
<I
>::send() {
30 void GetInfoRequest
<I
>::refresh_image() {
31 if (!m_image_ctx
.state
->is_refresh_required()) {
36 CephContext
*cct
= m_image_ctx
.cct
;
37 ldout(cct
, 20) << dendl
;
39 auto ctx
= create_context_callback
<
40 GetInfoRequest
<I
>, &GetInfoRequest
<I
>::handle_refresh_image
>(this);
41 m_image_ctx
.state
->refresh(ctx
);
45 void GetInfoRequest
<I
>::handle_refresh_image(int r
) {
46 CephContext
*cct
= m_image_ctx
.cct
;
47 ldout(cct
, 20) << "r=" << r
<< dendl
;
50 lderr(cct
) << "failed to refresh image: " << cpp_strerror(r
) << dendl
;
59 void GetInfoRequest
<I
>::get_mirror_image() {
60 CephContext
*cct
= m_image_ctx
.cct
;
61 ldout(cct
, 20) << dendl
;
63 librados::ObjectReadOperation op
;
64 cls_client::mirror_image_get_start(&op
, m_image_ctx
.id
);
66 librados::AioCompletion
*comp
= create_rados_callback
<
67 GetInfoRequest
<I
>, &GetInfoRequest
<I
>::handle_get_mirror_image
>(this);
68 int r
= m_image_ctx
.md_ctx
.aio_operate(RBD_MIRRORING
, comp
, &op
, &m_out_bl
);
74 void GetInfoRequest
<I
>::handle_get_mirror_image(int r
) {
75 CephContext
*cct
= m_image_ctx
.cct
;
76 ldout(cct
, 20) << "r=" << r
<< dendl
;
78 m_mirror_image
->state
= cls::rbd::MIRROR_IMAGE_STATE_DISABLED
;
79 *m_promotion_state
= PROMOTION_STATE_NON_PRIMARY
;
81 auto iter
= m_out_bl
.cbegin();
82 r
= cls_client::mirror_image_get_finish(&iter
, m_mirror_image
);
86 m_mirror_image
->state
!= cls::rbd::MIRROR_IMAGE_STATE_ENABLED
) {
87 ldout(cct
, 20) << "mirroring is disabled" << dendl
;
91 lderr(cct
) << "failed to retrieve mirroring state: " << cpp_strerror(r
)
100 template <typename I
>
101 void GetInfoRequest
<I
>::get_tag_owner() {
102 CephContext
*cct
= m_image_ctx
.cct
;
103 ldout(cct
, 20) << dendl
;
105 auto ctx
= create_context_callback
<
106 GetInfoRequest
<I
>, &GetInfoRequest
<I
>::handle_get_tag_owner
>(this);
107 Journal
<I
>::get_tag_owner(m_image_ctx
.md_ctx
, m_image_ctx
.id
,
108 &m_mirror_uuid
, m_image_ctx
.op_work_queue
, ctx
);
111 template <typename I
>
112 void GetInfoRequest
<I
>::handle_get_tag_owner(int r
) {
113 CephContext
*cct
= m_image_ctx
.cct
;
114 ldout(cct
, 20) << "r=" << r
<< dendl
;
117 lderr(cct
) << "failed to determine tag ownership: " << cpp_strerror(r
)
123 if (m_mirror_uuid
== Journal
<>::LOCAL_MIRROR_UUID
) {
124 *m_promotion_state
= PROMOTION_STATE_PRIMARY
;
125 } else if (m_mirror_uuid
== Journal
<>::ORPHAN_MIRROR_UUID
) {
126 *m_promotion_state
= PROMOTION_STATE_ORPHAN
;
132 template <typename I
>
133 void GetInfoRequest
<I
>::finish(int r
) {
134 CephContext
*cct
= m_image_ctx
.cct
;
135 ldout(cct
, 20) << "r=" << r
<< dendl
;
137 m_on_finish
->complete(r
);
141 } // namespace mirror
142 } // namespace librbd
144 template class librbd::mirror::GetInfoRequest
<librbd::ImageCtx
>;