]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/managed_lock/ReleaseRequest.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/managed_lock/ReleaseRequest.h"
5 #include "librbd/Watcher.h"
6 #include "cls/lock/cls_lock_client.h"
7 #include "cls/lock/cls_lock_types.h"
8 #include "common/dout.h"
9 #include "common/errno.h"
10 #include "librbd/Utils.h"
12 #include "librbd/ImageCtx.h"
14 #define dout_subsys ceph_subsys_rbd
16 #define dout_prefix *_dout << "librbd::managed_lock::ReleaseRequest: " \
17 << this << " " << __func__ << ": "
20 namespace managed_lock
{
22 using util::detail::C_AsyncCallback
;
23 using util::create_context_callback
;
24 using util::create_rados_callback
;
27 ReleaseRequest
<I
>* ReleaseRequest
<I
>::create(librados::IoCtx
& ioctx
,
29 ContextWQ
*work_queue
,
33 return new ReleaseRequest(ioctx
, watcher
, work_queue
, oid
, cookie
,
38 ReleaseRequest
<I
>::ReleaseRequest(librados::IoCtx
& ioctx
, Watcher
*watcher
,
39 ContextWQ
*work_queue
, const string
& oid
,
40 const string
& cookie
, Context
*on_finish
)
41 : m_ioctx(ioctx
), m_watcher(watcher
), m_oid(oid
), m_cookie(cookie
),
42 m_on_finish(new C_AsyncCallback
<ContextWQ
>(work_queue
, on_finish
)) {
46 ReleaseRequest
<I
>::~ReleaseRequest() {
51 void ReleaseRequest
<I
>::send() {
56 void ReleaseRequest
<I
>::send_unlock() {
57 CephContext
*cct
= reinterpret_cast<CephContext
*>(m_ioctx
.cct());
58 ldout(cct
, 10) << "entity=client." << m_ioctx
.get_instance_id() << ", "
59 << "cookie=" << m_cookie
<< dendl
;
61 librados::ObjectWriteOperation op
;
62 rados::cls::lock::unlock(&op
, RBD_LOCK_NAME
, m_cookie
);
64 using klass
= ReleaseRequest
;
65 librados::AioCompletion
*rados_completion
=
66 create_rados_callback
<klass
, &klass::handle_unlock
>(this);
67 int r
= m_ioctx
.aio_operate(m_oid
, rados_completion
, &op
);
69 rados_completion
->release();
73 void ReleaseRequest
<I
>::handle_unlock(int r
) {
74 CephContext
*cct
= reinterpret_cast<CephContext
*>(m_ioctx
.cct());
75 ldout(cct
, 10) << "r=" << r
<< dendl
;
77 if (r
< 0 && r
!= -ENOENT
) {
78 lderr(cct
) << "failed to unlock: " << cpp_strerror(r
) << dendl
;
85 void ReleaseRequest
<I
>::finish() {
86 m_on_finish
->complete(0);
90 } // namespace managed_lock
93 template class librbd::managed_lock::ReleaseRequest
<librbd::ImageCtx
>;