]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/managed_lock/ReleaseRequest.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / 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
3
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"
11
12 #include "librbd/ImageCtx.h"
13
14 #define dout_subsys ceph_subsys_rbd
15 #undef dout_prefix
16 #define dout_prefix *_dout << "librbd::managed_lock::ReleaseRequest: " \
17 << this << " " << __func__ << ": "
18
19 namespace librbd {
20 namespace managed_lock {
21
22 using util::detail::C_AsyncCallback;
23 using util::create_context_callback;
24 using util::create_rados_callback;
25
26 template <typename I>
27 ReleaseRequest<I>* ReleaseRequest<I>::create(librados::IoCtx& ioctx,
28 Watcher *watcher,
29 ContextWQ *work_queue,
30 const string& oid,
31 const string& cookie,
32 Context *on_finish) {
33 return new ReleaseRequest(ioctx, watcher, work_queue, oid, cookie,
34 on_finish);
35 }
36
37 template <typename I>
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)) {
43 }
44
45 template <typename I>
46 ReleaseRequest<I>::~ReleaseRequest() {
47 }
48
49
50 template <typename I>
51 void ReleaseRequest<I>::send() {
52 send_unlock();
53 }
54
55 template <typename I>
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;
60
61 librados::ObjectWriteOperation op;
62 rados::cls::lock::unlock(&op, RBD_LOCK_NAME, m_cookie);
63
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);
68 ceph_assert(r == 0);
69 rados_completion->release();
70 }
71
72 template <typename I>
73 void ReleaseRequest<I>::handle_unlock(int r) {
74 CephContext *cct = reinterpret_cast<CephContext *>(m_ioctx.cct());
75 ldout(cct, 10) << "r=" << r << dendl;
76
77 if (r < 0 && r != -ENOENT) {
78 lderr(cct) << "failed to unlock: " << cpp_strerror(r) << dendl;
79 }
80
81 finish();
82 }
83
84 template <typename I>
85 void ReleaseRequest<I>::finish() {
86 m_on_finish->complete(0);
87 delete this;
88 }
89
90 } // namespace managed_lock
91 } // namespace librbd
92
93 template class librbd::managed_lock::ReleaseRequest<librbd::ImageCtx>;
94