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/snapshot/DemoteRequest.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/Operations.h"
11 #include "librbd/Utils.h"
12 #include "librbd/mirror/snapshot/CreatePrimaryRequest.h"
14 #define dout_subsys ceph_subsys_rbd
16 #define dout_prefix *_dout << "librbd::mirror::snapshot::DemoteRequest: " \
17 << this << " " << __func__ << ": "
23 using librbd::util::create_context_callback
;
24 using librbd::util::create_rados_callback
;
27 void DemoteRequest
<I
>::send() {
28 enable_non_primary_feature();
32 void DemoteRequest
<I
>::enable_non_primary_feature() {
33 CephContext
*cct
= m_image_ctx
->cct
;
34 ldout(cct
, 10) << dendl
;
36 // ensure image is flagged with non-primary feature so that
37 // standard RBD clients cannot write to it.
38 librados::ObjectWriteOperation op
;
39 cls_client::set_features(&op
, RBD_FEATURE_NON_PRIMARY
,
40 RBD_FEATURE_NON_PRIMARY
);
42 auto aio_comp
= create_rados_callback
<
44 &DemoteRequest
<I
>::handle_enable_non_primary_feature
>(this);
45 int r
= m_image_ctx
->md_ctx
.aio_operate(m_image_ctx
->header_oid
, aio_comp
,
52 void DemoteRequest
<I
>::handle_enable_non_primary_feature(int r
) {
53 CephContext
*cct
= m_image_ctx
->cct
;
54 ldout(cct
, 10) << "r=" << r
<< dendl
;
57 lderr(cct
) << "failed to enable non-primary feature: "
58 << cpp_strerror(r
) << dendl
;
67 void DemoteRequest
<I
>::create_snapshot() {
68 CephContext
*cct
= m_image_ctx
->cct
;
69 ldout(cct
, 20) << dendl
;
71 auto ctx
= create_context_callback
<
72 DemoteRequest
<I
>, &DemoteRequest
<I
>::handle_create_snapshot
>(this);
74 auto req
= CreatePrimaryRequest
<I
>::create(
75 m_image_ctx
, m_global_image_id
,
76 (snapshot::CREATE_PRIMARY_FLAG_IGNORE_EMPTY_PEERS
|
77 snapshot::CREATE_PRIMARY_FLAG_DEMOTED
), nullptr, ctx
);
82 void DemoteRequest
<I
>::handle_create_snapshot(int r
) {
83 CephContext
*cct
= m_image_ctx
->cct
;
84 ldout(cct
, 20) << "r=" << r
<< dendl
;
87 lderr(cct
) << "failed to create mirror snapshot: " << cpp_strerror(r
)
97 void DemoteRequest
<I
>::finish(int r
) {
98 CephContext
*cct
= m_image_ctx
->cct
;
99 ldout(cct
, 20) << "r=" << r
<< dendl
;
101 m_on_finish
->complete(r
);
105 } // namespace snapshot
106 } // namespace mirror
107 } // namespace librbd
109 template class librbd::mirror::snapshot::DemoteRequest
<librbd::ImageCtx
>;