]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/mirror/ImageRemoveRequest.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / mirror / ImageRemoveRequest.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/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"
10
11 #define dout_subsys ceph_subsys_rbd
12 #undef dout_prefix
13 #define dout_prefix *_dout << "librbd::mirror::ImageRemoveRequest: " \
14 << this << " " << __func__ << ": "
15
16 namespace librbd {
17 namespace mirror {
18
19 using util::create_rados_callback;
20
21 template <typename I>
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())) {
27 }
28
29 template <typename I>
30 void ImageRemoveRequest<I>::send() {
31 remove_mirror_image();
32 }
33
34 template <typename I>
35 void ImageRemoveRequest<I>::remove_mirror_image() {
36 ldout(m_cct, 10) << dendl;
37
38 librados::ObjectWriteOperation op;
39 cls_client::mirror_image_remove(&op, m_image_id);
40
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);
45 ceph_assert(r == 0);
46 comp->release();
47 }
48
49 template <typename I>
50 void ImageRemoveRequest<I>::handle_remove_mirror_image(int r) {
51 ldout(m_cct, 10) << "r=" << r << dendl;
52
53 if (r < 0 && r != -ENOENT) {
54 lderr(m_cct) << "failed to remove mirroring image: " << cpp_strerror(r)
55 << dendl;
56 finish(r);
57 return;
58 }
59
60 notify_mirroring_watcher();
61 }
62
63 template <typename I>
64 void ImageRemoveRequest<I>::notify_mirroring_watcher() {
65 ldout(m_cct, 10) << dendl;
66
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);
73 }
74
75 template <typename I>
76 void ImageRemoveRequest<I>::handle_notify_mirroring_watcher(int r) {
77 ldout(m_cct, 10) << "r=" << r << dendl;
78
79 if (r < 0) {
80 lderr(m_cct) << "failed to notify mirror image update: " << cpp_strerror(r)
81 << dendl;
82 }
83
84 finish(0);
85 }
86
87 template <typename I>
88 void ImageRemoveRequest<I>::finish(int r) {
89 ldout(m_cct, 10) << "r=" << r << dendl;
90
91 m_on_finish->complete(r);
92 delete this;
93 }
94
95 } // namespace mirror
96 } // namespace librbd
97
98 template class librbd::mirror::ImageRemoveRequest<librbd::ImageCtx>;