]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/image/DetachParentRequest.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / librbd / image / DetachParentRequest.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/image/DetachParentRequest.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "common/WorkQueue.h"
8 #include "cls/rbd/cls_rbd_client.h"
9 #include "librbd/ImageCtx.h"
10 #include "librbd/Utils.h"
11
12 #define dout_subsys ceph_subsys_rbd
13 #undef dout_prefix
14 #define dout_prefix *_dout << "librbd::image::DetachParentRequest: " << this \
15 << " " << __func__ << ": "
16
17 namespace librbd {
18 namespace image {
19
20 using util::create_context_callback;
21 using util::create_rados_callback;
22
23 template <typename I>
24 void DetachParentRequest<I>::send() {
25 detach_parent();
26 }
27
28 template <typename I>
29 void DetachParentRequest<I>::detach_parent() {
30 auto cct = m_image_ctx.cct;
31 ldout(cct, 5) << dendl;
32
33 librados::ObjectWriteOperation op;
34 if (!m_legacy_parent) {
35 librbd::cls_client::parent_detach(&op);
36 } else {
37 librbd::cls_client::remove_parent(&op);
38 }
39
40 auto aio_comp = create_rados_callback<
41 DetachParentRequest<I>,
42 &DetachParentRequest<I>::handle_detach_parent>(this);
43 int r = m_image_ctx.md_ctx.aio_operate(m_image_ctx.header_oid, aio_comp, &op);
44 ceph_assert(r == 0);
45 aio_comp->release();
46 }
47
48 template <typename I>
49 void DetachParentRequest<I>::handle_detach_parent(int r) {
50 auto cct = m_image_ctx.cct;
51 ldout(cct, 5) << dendl;
52
53 if (!m_legacy_parent && r == -EOPNOTSUPP) {
54 ldout(cct, 10) << "retrying using legacy parent method" << dendl;
55 m_legacy_parent = true;
56 detach_parent();
57 return;
58 }
59
60 if (r < 0 && r != -ENOENT) {
61 lderr(cct) << "detach parent encountered an error: " << cpp_strerror(r)
62 << dendl;
63 finish(r);
64 return;
65 }
66
67 finish(0);
68 }
69
70 template <typename I>
71 void DetachParentRequest<I>::finish(int r) {
72 auto cct = m_image_ctx.cct;
73 ldout(cct, 5) << "r=" << r << dendl;
74
75 m_on_finish->complete(r);
76 delete this;
77 }
78
79 } // namespace image
80 } // namespace librbd
81
82 template class librbd::image::DetachParentRequest<librbd::ImageCtx>;