]>
git.proxmox.com Git - ceph.git/blob - 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
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"
12 #define dout_subsys ceph_subsys_rbd
14 #define dout_prefix *_dout << "librbd::image::AttachParentRequest: " << this \
15 << " " << __func__ << ": "
20 using util::create_rados_callback
;
23 void AttachParentRequest
<I
>::send() {
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
;
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
);
37 librbd::cls_client::set_parent(&op
, m_parent_image_spec
, m_parent_overlap
);
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
);
49 void AttachParentRequest
<I
>::handle_attach_parent(int r
) {
50 auto cct
= m_image_ctx
.cct
;
51 ldout(cct
, 5) << dendl
;
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
= "";
58 if (m_parent_image_spec
.pool_namespace
.empty()) {
59 ldout(cct
, 10) << "retrying using legacy parent method" << dendl
;
60 m_legacy_parent
= true;
65 // namespaces require newer OSDs
70 lderr(cct
) << "attach parent encountered an error: " << cpp_strerror(r
)
80 void AttachParentRequest
<I
>::finish(int r
) {
81 auto cct
= m_image_ctx
.cct
;
82 ldout(cct
, 5) << "r=" << r
<< dendl
;
84 m_on_finish
->complete(r
);
91 template class librbd::image::AttachParentRequest
<librbd::ImageCtx
>;