]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/image/AttachParentRequest.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / image / AttachParentRequest.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/AttachParentRequest.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::AttachParentRequest: " << this \
15 << " " << __func__ << ": "
16
17 namespace librbd {
18 namespace image {
19
20 using util::create_rados_callback;
21
22 template <typename I>
23 void AttachParentRequest<I>::send() {
24 attach_parent();
25 }
26
27 template <typename I>
28 void AttachParentRequest<I>::attach_parent() {
29 auto cct = m_image_ctx.cct;
30 ldout(cct, 5) << "parent_image_spec=" << m_parent_image_spec << dendl;
31
32 librados::ObjectWriteOperation op;
33 if (!m_legacy_parent) {
34 librbd::cls_client::parent_attach(&op, m_parent_image_spec,
35 m_parent_overlap, m_reattach);
36 } else {
37 librbd::cls_client::set_parent(&op, m_parent_image_spec, m_parent_overlap);
38 }
39
40 auto aio_comp = create_rados_callback<
41 AttachParentRequest<I>,
42 &AttachParentRequest<I>::handle_attach_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 AttachParentRequest<I>::handle_attach_parent(int r) {
50 auto cct = m_image_ctx.cct;
51 ldout(cct, 5) << dendl;
52
53 if (!m_legacy_parent && r == -EOPNOTSUPP && !m_reattach) {
54 if (m_parent_image_spec.pool_namespace ==
55 m_image_ctx.md_ctx.get_namespace()) {
56 m_parent_image_spec.pool_namespace = "";
57 }
58 if (m_parent_image_spec.pool_namespace.empty()) {
59 ldout(cct, 10) << "retrying using legacy parent method" << dendl;
60 m_legacy_parent = true;
61 attach_parent();
62 return;
63 }
64
65 // namespaces require newer OSDs
66 r = -EXDEV;
67 }
68
69 if (r < 0) {
70 lderr(cct) << "attach parent encountered an error: " << cpp_strerror(r)
71 << dendl;
72 finish(r);
73 return;
74 }
75
76 finish(0);
77 }
78
79 template <typename I>
80 void AttachParentRequest<I>::finish(int r) {
81 auto cct = m_image_ctx.cct;
82 ldout(cct, 5) << "r=" << r << dendl;
83
84 m_on_finish->complete(r);
85 delete this;
86 }
87
88 } // namespace image
89 } // namespace librbd
90
91 template class librbd::image::AttachParentRequest<librbd::ImageCtx>;