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_watcher/NotifyLockOwner.h"
5 #include "common/errno.h"
6 #include "librbd/ImageCtx.h"
7 #include "librbd/Utils.h"
8 #include "librbd/WatchNotifyTypes.h"
9 #include "librbd/watcher/Notifier.h"
12 #define dout_subsys ceph_subsys_rbd
14 #define dout_prefix *_dout << "librbd::image_watcher::NotifyLockOwner: " \
15 << this << " " << __func__
19 namespace image_watcher
{
21 using namespace watch_notify
;
22 using util::create_context_callback
;
24 NotifyLockOwner::NotifyLockOwner(ImageCtx
&image_ctx
,
25 watcher::Notifier
¬ifier
,
26 bufferlist
&&bl
, Context
*on_finish
)
27 : m_image_ctx(image_ctx
), m_notifier(notifier
), m_bl(std::move(bl
)),
28 m_on_finish(on_finish
) {
31 void NotifyLockOwner::send() {
35 void NotifyLockOwner::send_notify() {
36 CephContext
*cct
= m_image_ctx
.cct
;
37 ldout(cct
, 20) << dendl
;
39 ceph_assert(m_image_ctx
.owner_lock
.is_locked());
40 m_notifier
.notify(m_bl
, &m_notify_response
, create_context_callback
<
41 NotifyLockOwner
, &NotifyLockOwner::handle_notify
>(this));
44 void NotifyLockOwner::handle_notify(int r
) {
45 CephContext
*cct
= m_image_ctx
.cct
;
46 ldout(cct
, 20) << ": r=" << r
<< dendl
;
48 if (r
< 0 && r
!= -ETIMEDOUT
) {
49 lderr(cct
) << ": lock owner notification failed: " << cpp_strerror(r
)
56 bool lock_owner_responded
= false;
57 for (auto &it
: m_notify_response
.acks
) {
58 if (it
.second
.length() > 0) {
59 if (lock_owner_responded
) {
60 lderr(cct
) << ": duplicate lock owners detected" << dendl
;
64 lock_owner_responded
= true;
65 response
.claim(it
.second
);
69 if (!lock_owner_responded
) {
70 ldout(cct
, 1) << ": no lock owners detected" << dendl
;
76 auto iter
= response
.cbegin();
78 ResponseMessage response_message
;
80 decode(response_message
, iter
);
82 r
= response_message
.result
;
83 } catch (const buffer::error
&err
) {
89 void NotifyLockOwner::finish(int r
) {
90 m_on_finish
->complete(r
);
94 } // namespace image_watcher