-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
librbd: separate locker query into standalone state machine
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
- Loading branch information
Jason Dillaman
committed
Jan 6, 2017
1 parent
9b430a8
commit 03533b9
Showing
9 changed files
with
511 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#include "librbd/exclusive_lock/GetLockerRequest.h" | ||
#include "cls/lock/cls_lock_client.h" | ||
#include "cls/lock/cls_lock_types.h" | ||
#include "common/dout.h" | ||
#include "common/errno.h" | ||
#include "include/stringify.h" | ||
#include "librbd/ExclusiveLock.h" | ||
#include "librbd/ImageCtx.h" | ||
#include "librbd/Utils.h" | ||
#include "librbd/exclusive_lock/Types.h" | ||
|
||
#define dout_subsys ceph_subsys_rbd | ||
#undef dout_prefix | ||
#define dout_prefix *_dout << "librbd::exclusive_lock::GetLockerRequest: " \ | ||
<< this << " " << __func__ << ": " | ||
|
||
namespace librbd { | ||
namespace exclusive_lock { | ||
|
||
using util::create_rados_ack_callback; | ||
|
||
template <typename I> | ||
void GetLockerRequest<I>::send() { | ||
send_get_lockers(); | ||
} | ||
|
||
template <typename I> | ||
void GetLockerRequest<I>::send_get_lockers() { | ||
CephContext *cct = m_image_ctx.cct; | ||
ldout(cct, 10) << dendl; | ||
|
||
librados::ObjectReadOperation op; | ||
rados::cls::lock::get_lock_info_start(&op, RBD_LOCK_NAME); | ||
|
||
using klass = GetLockerRequest<I>; | ||
librados::AioCompletion *rados_completion = | ||
create_rados_ack_callback<klass, &klass::handle_get_lockers>(this); | ||
m_out_bl.clear(); | ||
int r = m_image_ctx.md_ctx.aio_operate(m_image_ctx.header_oid, | ||
rados_completion, &op, &m_out_bl); | ||
assert(r == 0); | ||
rados_completion->release(); | ||
} | ||
|
||
template <typename I> | ||
void GetLockerRequest<I>::handle_get_lockers(int r) { | ||
CephContext *cct = m_image_ctx.cct; | ||
ldout(cct, 10) << "r=" << r << dendl; | ||
|
||
std::map<rados::cls::lock::locker_id_t, | ||
rados::cls::lock::locker_info_t> lockers; | ||
ClsLockType lock_type = LOCK_NONE; | ||
std::string lock_tag; | ||
if (r == 0) { | ||
bufferlist::iterator it = m_out_bl.begin(); | ||
r = rados::cls::lock::get_lock_info_finish(&it, &lockers, | ||
&lock_type, &lock_tag); | ||
} | ||
|
||
if (r < 0) { | ||
lderr(cct) << "failed to retrieve lockers: " << cpp_strerror(r) << dendl; | ||
finish(r); | ||
return; | ||
} | ||
|
||
if (lockers.empty()) { | ||
ldout(cct, 20) << "no lockers detected" << dendl; | ||
finish(-ENOENT); | ||
return; | ||
} | ||
|
||
if (lock_tag != ExclusiveLock<>::WATCHER_LOCK_TAG) { | ||
ldout(cct, 5) <<"locked by external mechanism: tag=" << lock_tag << dendl; | ||
finish(-EBUSY); | ||
return; | ||
} | ||
|
||
if (lock_type == LOCK_SHARED) { | ||
ldout(cct, 5) << "shared lock type detected" << dendl; | ||
finish(-EBUSY); | ||
return; | ||
} | ||
|
||
std::map<rados::cls::lock::locker_id_t, | ||
rados::cls::lock::locker_info_t>::iterator iter = lockers.begin(); | ||
if (!ExclusiveLock<>::decode_lock_cookie(iter->first.cookie, | ||
&m_locker->handle)) { | ||
ldout(cct, 5) << "locked by external mechanism: " | ||
<< "cookie=" << iter->first.cookie << dendl; | ||
finish(-EBUSY); | ||
return; | ||
} | ||
|
||
m_locker->entity = iter->first.locker; | ||
m_locker->cookie = iter->first.cookie; | ||
m_locker->address = stringify(iter->second.addr); | ||
if (m_locker->cookie.empty() || m_locker->address.empty()) { | ||
ldout(cct, 20) << "no valid lockers detected" << dendl; | ||
finish(-ENOENT); | ||
return; | ||
} | ||
|
||
ldout(cct, 10) << "retrieved exclusive locker: " | ||
<< m_locker->entity << "@" << m_locker->address << dendl; | ||
finish(0); | ||
} | ||
|
||
template <typename I> | ||
void GetLockerRequest<I>::finish(int r) { | ||
CephContext *cct = m_image_ctx.cct; | ||
ldout(cct, 10) << "r=" << r << dendl; | ||
|
||
m_on_finish->complete(r); | ||
delete this; | ||
} | ||
|
||
} // namespace exclusive_lock | ||
} // namespace librbd | ||
|
||
template class librbd::exclusive_lock::GetLockerRequest<librbd::ImageCtx>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#ifndef CEPH_LIBRBD_EXCLUSIVE_LOCK_GET_LOCKER_REQUEST_H | ||
#define CEPH_LIBRBD_EXCLUSIVE_LOCK_GET_LOCKER_REQUEST_H | ||
|
||
#include "include/int_types.h" | ||
#include "include/buffer.h" | ||
|
||
class Context; | ||
|
||
namespace librbd { | ||
|
||
struct ImageCtx; | ||
|
||
namespace exclusive_lock { | ||
|
||
struct Locker; | ||
|
||
template <typename ImageCtxT = ImageCtx> | ||
class GetLockerRequest { | ||
public: | ||
static GetLockerRequest* create(ImageCtxT &image_ctx, Locker *locker, | ||
Context *on_finish) { | ||
return new GetLockerRequest(image_ctx, locker, on_finish); | ||
} | ||
|
||
void send(); | ||
|
||
private: | ||
ImageCtxT &m_image_ctx; | ||
Locker *m_locker; | ||
Context *m_on_finish; | ||
|
||
bufferlist m_out_bl; | ||
|
||
GetLockerRequest(ImageCtxT &image_ctx, Locker *locker, Context *on_finish) | ||
: m_image_ctx(image_ctx), m_locker(locker), m_on_finish(on_finish) { | ||
} | ||
|
||
void send_get_lockers(); | ||
void handle_get_lockers(int r); | ||
|
||
void finish(int r); | ||
|
||
}; | ||
|
||
} // namespace exclusive_lock | ||
} // namespace librbd | ||
|
||
extern template class librbd::exclusive_lock::GetLockerRequest<librbd::ImageCtx>; | ||
|
||
#endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_GET_LOCKER_REQUEST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#ifndef CEPH_LIBRBD_EXCLUSIVE_LOCK_TYPES_H | ||
#define CEPH_LIBRBD_EXCLUSIVE_LOCK_TYPES_H | ||
|
||
#include "msg/msg_types.h" | ||
#include <string> | ||
|
||
namespace librbd { | ||
namespace exclusive_lock { | ||
|
||
struct Locker { | ||
entity_name_t entity; | ||
std::string cookie; | ||
std::string address; | ||
uint64_t handle; | ||
}; | ||
|
||
} // namespace exclusive_lock | ||
} // namespace librbd | ||
|
||
#endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_TYPES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.