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/ImageRemoveRequest.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "cls/rbd/cls_rbd_client.h"
8 #include "librbd/MirroringWatcher.h"
9 #include "librbd/Utils.h"
11 #define dout_subsys ceph_subsys_rbd
13 #define dout_prefix *_dout << "librbd::mirror::ImageRemoveRequest: " \
14 << this << " " << __func__ << ": "
19 using util::create_rados_callback
;
22 ImageRemoveRequest
<I
>::ImageRemoveRequest(
23 librados::IoCtx
& io_ctx
, const std::string
& global_image_id
,
24 const std::string
& image_id
, Context
* on_finish
)
25 : m_io_ctx(io_ctx
), m_global_image_id(global_image_id
), m_image_id(image_id
),
26 m_on_finish(on_finish
), m_cct(static_cast<CephContext
*>(m_io_ctx
.cct())) {
30 void ImageRemoveRequest
<I
>::send() {
31 remove_mirror_image();
35 void ImageRemoveRequest
<I
>::remove_mirror_image() {
36 ldout(m_cct
, 10) << dendl
;
38 librados::ObjectWriteOperation op
;
39 cls_client::mirror_image_remove(&op
, m_image_id
);
41 auto comp
= create_rados_callback
<
42 ImageRemoveRequest
<I
>,
43 &ImageRemoveRequest
<I
>::handle_remove_mirror_image
>(this);
44 int r
= m_io_ctx
.aio_operate(RBD_MIRRORING
, comp
, &op
);
50 void ImageRemoveRequest
<I
>::handle_remove_mirror_image(int r
) {
51 ldout(m_cct
, 10) << "r=" << r
<< dendl
;
53 if (r
< 0 && r
!= -ENOENT
) {
54 lderr(m_cct
) << "failed to remove mirroring image: " << cpp_strerror(r
)
60 notify_mirroring_watcher();
64 void ImageRemoveRequest
<I
>::notify_mirroring_watcher() {
65 ldout(m_cct
, 10) << dendl
;
67 auto ctx
= util::create_context_callback
<
68 ImageRemoveRequest
<I
>,
69 &ImageRemoveRequest
<I
>::handle_notify_mirroring_watcher
>(this);
70 MirroringWatcher
<I
>::notify_image_updated(
71 m_io_ctx
, cls::rbd::MIRROR_IMAGE_STATE_DISABLED
,
72 m_image_id
, m_global_image_id
, ctx
);
76 void ImageRemoveRequest
<I
>::handle_notify_mirroring_watcher(int r
) {
77 ldout(m_cct
, 10) << "r=" << r
<< dendl
;
80 lderr(m_cct
) << "failed to notify mirror image update: " << cpp_strerror(r
)
88 void ImageRemoveRequest
<I
>::finish(int r
) {
89 ldout(m_cct
, 10) << "r=" << r
<< dendl
;
91 m_on_finish
->complete(r
);
98 template class librbd::mirror::ImageRemoveRequest
<librbd::ImageCtx
>;