Skip to content

Commit

Permalink
librbd: managed_lock: make AcquireRequest use GetLockRequest and Brea…
Browse files Browse the repository at this point in the history
…kRequest

Initially this was implemented for exclusive_lock (03533b9,
23f60fe) but was lost when merging managed_lock refactoring.

Signed-off-by: Mykola Golub <mgolub@mirantis.com>
  • Loading branch information
Mykola Golub committed Jan 14, 2017
1 parent cabb58e commit cb56d02
Show file tree
Hide file tree
Showing 15 changed files with 358 additions and 633 deletions.
3 changes: 2 additions & 1 deletion src/librbd/ExclusiveLock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ using ML = ManagedLock<I>;
template <typename I>
ExclusiveLock<I>::ExclusiveLock(I &image_ctx)
: ML<I>(image_ctx.md_ctx, image_ctx.op_work_queue, image_ctx.header_oid,
image_ctx.image_watcher),
image_ctx.image_watcher, image_ctx.blacklist_on_break_lock,
image_ctx.blacklist_expire_seconds),
m_image_ctx(image_ctx), m_pre_post_callback(nullptr),
m_shutting_down(false) {
ML<I>::m_state = ML<I>::STATE_UNINITIALIZED;
Expand Down
15 changes: 10 additions & 5 deletions src/librbd/ManagedLock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ const std::string ManagedLock<I>::WATCHER_LOCK_TAG("internal");

template <typename I>
ManagedLock<I>::ManagedLock(librados::IoCtx &ioctx, ContextWQ *work_queue,
const string& oid, Watcher *watcher)
const string& oid, Watcher *watcher,
bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds)
: m_lock(util::unique_lock_name("librbd::ManagedLock<I>::m_lock", this)),
m_state(STATE_UNLOCKED),
m_ioctx(ioctx), m_cct(reinterpret_cast<CephContext *>(ioctx.cct())),
m_work_queue(work_queue),
m_oid(oid),
m_watcher(watcher) {
m_watcher(watcher),
m_blacklist_on_break_lock(blacklist_on_break_lock),
m_blacklist_expire_seconds(blacklist_expire_seconds) {
}

template <typename I>
Expand Down Expand Up @@ -376,9 +380,10 @@ void ManagedLock<I>::handle_pre_acquire_lock(int r) {
}

using managed_lock::AcquireRequest;
AcquireRequest<I>* req = AcquireRequest<I>::create(m_ioctx, m_watcher,
m_work_queue, m_oid, m_cookie,
util::create_context_callback<
AcquireRequest<I>* req = AcquireRequest<I>::create(
m_ioctx, m_watcher, m_work_queue, m_oid, m_cookie,
m_blacklist_on_break_lock, m_blacklist_expire_seconds,
util::create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_acquire_lock>(this));
m_work_queue->queue(new C_SendLockRequest<AcquireRequest<I>>(req), 0);
}
Expand Down
13 changes: 10 additions & 3 deletions src/librbd/ManagedLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ class ManagedLock {
static const std::string WATCHER_LOCK_TAG;

static ManagedLock *create(librados::IoCtx& ioctx, ContextWQ *work_queue,
const std::string& oid, Watcher *watcher) {
return new ManagedLock(ioctx, work_queue, oid, watcher);
const std::string& oid, Watcher *watcher,
bool blacklist_on_break_lock = true,
uint32_t blacklist_expire_seconds = 0) {
return new ManagedLock(ioctx, work_queue, oid, watcher,
blacklist_on_break_lock, blacklist_expire_seconds);
}

ManagedLock(librados::IoCtx& ioctx, ContextWQ *work_queue,
const std::string& oid, Watcher *watcher);
const std::string& oid, Watcher *watcher,
bool blacklist_on_break_lock = true,
uint32_t blacklist_expire_seconds = 0);
virtual ~ManagedLock();

bool is_lock_owner() const;
Expand Down Expand Up @@ -151,6 +156,8 @@ class ManagedLock {
ContextWQ *m_work_queue;
std::string m_oid;
Watcher *m_watcher;
bool m_blacklist_on_break_lock;
uint32_t m_blacklist_expire_seconds;

std::string m_cookie;
std::string m_new_cookie;
Expand Down
8 changes: 5 additions & 3 deletions src/librbd/internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ void filter_out_mirror_watchers(ImageCtx *ictx,
managed_lock::Locker locker;
C_SaferCond get_owner_ctx;
auto get_owner_req = managed_lock::GetLockerRequest<>::create(
*ictx, &locker, &get_owner_ctx);
ictx->md_ctx, ictx->header_oid, &locker, &get_owner_ctx);
get_owner_req->send();

int r = get_owner_ctx.wait();
Expand Down Expand Up @@ -1604,7 +1604,7 @@ void filter_out_mirror_watchers(ImageCtx *ictx,
managed_lock::Locker locker;
C_SaferCond get_owner_ctx;
auto get_owner_req = managed_lock::GetLockerRequest<>::create(
*ictx, &locker, &get_owner_ctx);
ictx->md_ctx, ictx->header_oid, &locker, &get_owner_ctx);
get_owner_req->send();

int r = get_owner_ctx.wait();
Expand All @@ -1622,7 +1622,9 @@ void filter_out_mirror_watchers(ImageCtx *ictx,

C_SaferCond break_ctx;
auto break_req = managed_lock::BreakRequest<>::create(
*ictx, locker, ictx->blacklist_on_break_lock, true, &break_ctx);
ictx->md_ctx, ictx->op_work_queue, ictx->header_oid, locker,
ictx->blacklist_on_break_lock, ictx->blacklist_expire_seconds, true,
&break_ctx);
break_req->send();

r = break_ctx.wait();
Expand Down
Loading

0 comments on commit cb56d02

Please sign in to comment.