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.blacklist_on_break_lock,
+ image_ctx.image_watcher, managed_lock::EXCLUSIVE,
+ 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) {
namespace librbd {
using std::string;
+using namespace managed_lock;
namespace {
template <typename I>
ManagedLock<I>::ManagedLock(librados::IoCtx &ioctx, ContextWQ *work_queue,
- const string& oid, Watcher *watcher,
+ const string& oid, Watcher *watcher, Mode mode,
bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds)
: m_lock(util::unique_lock_name("librbd::ManagedLock<I>::m_lock", this)),
m_work_queue(work_queue),
m_oid(oid),
m_watcher(watcher),
+ m_mode(mode),
m_blacklist_on_break_lock(blacklist_on_break_lock),
m_blacklist_expire_seconds(blacklist_expire_seconds) {
}
ldout(m_cct, 10) << dendl;
auto req = managed_lock::GetLockerRequest<I>::create(
- m_ioctx, m_oid, locker, on_finish);
+ m_ioctx, m_oid, m_mode == EXCLUSIVE, locker, on_finish);
req->send();
}
using managed_lock::AcquireRequest;
AcquireRequest<I>* req = AcquireRequest<I>::create(
- m_ioctx, m_watcher, m_work_queue, m_oid, m_cookie,
+ m_ioctx, m_watcher, m_work_queue, m_oid, m_cookie, m_mode == EXCLUSIVE,
m_blacklist_on_break_lock, m_blacklist_expire_seconds,
util::create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_acquire_lock>(this));
using managed_lock::ReacquireRequest;
ReacquireRequest<I>* req = ReacquireRequest<I>::create(m_ioctx, m_oid,
- m_cookie, m_new_cookie,
+ m_cookie, m_new_cookie, m_mode == EXCLUSIVE,
util::create_context_callback<
ManagedLock, &ManagedLock<I>::handle_reacquire_lock>(this));
m_work_queue->queue(new C_SendLockRequest<ReacquireRequest<I>>(req));
#include "include/rados/librados.hpp"
#include "cls/lock/cls_lock_types.h"
#include "librbd/watcher/Types.h"
+#include "librbd/managed_lock/Types.h"
#include "common/Mutex.h"
#include <list>
#include <string>
static ManagedLock *create(librados::IoCtx& ioctx, ContextWQ *work_queue,
const std::string& oid, Watcher *watcher,
+ managed_lock::Mode mode,
bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds) {
- return new ManagedLock(ioctx, work_queue, oid, watcher,
+ return new ManagedLock(ioctx, work_queue, oid, watcher, mode,
blacklist_on_break_lock, blacklist_expire_seconds);
}
ManagedLock(librados::IoCtx& ioctx, ContextWQ *work_queue,
const std::string& oid, Watcher *watcher,
- bool blacklist_on_break_lock,
+ managed_lock::Mode mode, bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds);
virtual ~ManagedLock();
ContextWQ *m_work_queue;
std::string m_oid;
Watcher *m_watcher;
+ managed_lock::Mode m_mode;
bool m_blacklist_on_break_lock;
uint32_t m_blacklist_expire_seconds;
ContextWQ *work_queue,
const string& oid,
const string& cookie,
+ bool exclusive,
bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds,
Context *on_finish) {
return new AcquireRequest(ioctx, watcher, work_queue, oid, cookie,
- blacklist_on_break_lock, blacklist_expire_seconds,
- on_finish);
+ exclusive, blacklist_on_break_lock,
+ blacklist_expire_seconds, on_finish);
}
template <typename I>
AcquireRequest<I>::AcquireRequest(librados::IoCtx& ioctx, Watcher *watcher,
ContextWQ *work_queue, const string& oid,
- const string& cookie,
+ const string& cookie, bool exclusive,
bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds,
Context *on_finish)
: m_ioctx(ioctx), m_watcher(watcher),
m_cct(reinterpret_cast<CephContext *>(m_ioctx.cct())),
m_work_queue(work_queue), m_oid(oid), m_cookie(cookie),
+ m_exclusive(exclusive),
m_blacklist_on_break_lock(blacklist_on_break_lock),
m_blacklist_expire_seconds(blacklist_expire_seconds),
m_on_finish(new C_AsyncCallback<ContextWQ>(work_queue, on_finish)) {
Context *ctx = create_context_callback<
AcquireRequest<I>, &AcquireRequest<I>::handle_get_locker>(this);
- auto req = GetLockerRequest<I>::create(m_ioctx, m_oid, &m_locker, ctx);
+ auto req = GetLockerRequest<I>::create(m_ioctx, m_oid, m_exclusive,
+ &m_locker, ctx);
req->send();
}
ldout(m_cct, 10) << dendl;
librados::ObjectWriteOperation op;
- rados::cls::lock::lock(&op, RBD_LOCK_NAME, LOCK_EXCLUSIVE, m_cookie,
+ rados::cls::lock::lock(&op, RBD_LOCK_NAME,
+ m_exclusive ? LOCK_EXCLUSIVE : LOCK_SHARED, m_cookie,
ManagedLock<I>::WATCHER_LOCK_TAG, "", utime_t(), 0);
using klass = AcquireRequest;
static AcquireRequest* create(librados::IoCtx& ioctx, Watcher *watcher,
ContextWQ *work_queue, const std::string& oid,
const std::string& cookie,
+ bool exclusive,
bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds,
Context *on_finish);
AcquireRequest(librados::IoCtx& ioctx, Watcher *watcher,
ContextWQ *work_queue, const std::string& oid,
- const std::string& cookie, bool blacklist_on_break_lock,
+ const std::string& cookie, bool exclusive,
+ bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds, Context *on_finish);
librados::IoCtx& m_ioctx;
ContextWQ *m_work_queue;
std::string m_oid;
std::string m_cookie;
+ bool m_exclusive;
bool m_blacklist_on_break_lock;
uint32_t m_blacklist_expire_seconds;
Context *m_on_finish;
template <typename I>
GetLockerRequest<I>::GetLockerRequest(librados::IoCtx& ioctx,
- const std::string& oid, Locker *locker,
- Context *on_finish)
+ const std::string& oid, bool exclusive,
+ Locker *locker, Context *on_finish)
: m_ioctx(ioctx), m_cct(reinterpret_cast<CephContext *>(m_ioctx.cct())),
- m_oid(oid), m_locker(locker), m_on_finish(on_finish) {
+ m_oid(oid), m_exclusive(exclusive), m_locker(locker),
+ m_on_finish(on_finish) {
}
template <typename I>
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);
+ r = rados::cls::lock::get_lock_info_finish(&it, &lockers, &lock_type,
+ &lock_tag);
}
if (r < 0) {
return;
}
- if (lock_type == LOCK_SHARED) {
- ldout(m_cct, 5) << "shared lock type detected" << dendl;
+ if (m_exclusive && lock_type == LOCK_SHARED) {
+ ldout(m_cct, 5) << "incompatible shared lock type detected" << dendl;
+ finish(-EBUSY);
+ return;
+ } else if (!m_exclusive && lock_type == LOCK_EXCLUSIVE) {
+ ldout(m_cct, 5) << "incompatible exclusive lock type detected" << dendl;
finish(-EBUSY);
return;
}
class GetLockerRequest {
public:
static GetLockerRequest* create(librados::IoCtx& ioctx,
- const std::string& oid,
+ const std::string& oid, bool exclusive,
Locker *locker, Context *on_finish) {
- return new GetLockerRequest(ioctx, oid, locker, on_finish);
+ return new GetLockerRequest(ioctx, oid, exclusive, locker, on_finish);
}
void send();
librados::IoCtx &m_ioctx;
CephContext *m_cct;
std::string m_oid;
+ bool m_exclusive;
Locker *m_locker;
Context *m_on_finish;
bufferlist m_out_bl;
GetLockerRequest(librados::IoCtx& ioctx, const std::string& oid,
- Locker *locker, Context *on_finish);
+ bool exclusive, Locker *locker, Context *on_finish);
void send_get_lockers();
void handle_get_lockers(int r);
const string& oid,
const string& old_cookie,
const string &new_cookie,
+ bool exclusive,
Context *on_finish)
: m_ioctx(ioctx), m_oid(oid), m_old_cookie(old_cookie),
- m_new_cookie(new_cookie), m_on_finish(on_finish) {
+ m_new_cookie(new_cookie), m_exclusive(exclusive), m_on_finish(on_finish) {
}
ldout(cct, 10) << dendl;
librados::ObjectWriteOperation op;
- rados::cls::lock::set_cookie(&op, RBD_LOCK_NAME, LOCK_EXCLUSIVE, m_old_cookie,
- ManagedLock<I>::WATCHER_LOCK_TAG, m_new_cookie);
+ rados::cls::lock::set_cookie(&op, RBD_LOCK_NAME,
+ m_exclusive ? LOCK_EXCLUSIVE : LOCK_SHARED,
+ m_old_cookie, ManagedLock<I>::WATCHER_LOCK_TAG,
+ m_new_cookie);
librados::AioCompletion *rados_completion = create_rados_safe_callback<
ReacquireRequest, &ReacquireRequest::handle_set_cookie>(this);
const std::string& oid,
const std::string& old_cookie,
const std::string &new_cookie,
+ bool exclusive,
Context *on_finish) {
- return new ReacquireRequest(ioctx, oid, old_cookie, new_cookie, on_finish);
+ return new ReacquireRequest(ioctx, oid, old_cookie, new_cookie, exclusive,
+ on_finish);
}
ReacquireRequest(librados::IoCtx& ioctx, const std::string& oid,
const std::string& old_cookie,
- const std::string &new_cookie, Context *on_finish);
+ const std::string &new_cookie, bool exclusive,
+ Context *on_finish);
void send();
std::string m_oid;
std::string m_old_cookie;
std::string m_new_cookie;
+ bool m_exclusive;
Context *m_on_finish;
void set_cookie();
uint64_t handle;
};
+enum Mode {
+ EXCLUSIVE,
+ SHARED
+};
+
+
} // namespace managed_lock
} // namespace librbd
static GetLockerRequest *s_instance;
static GetLockerRequest* create(librados::IoCtx& ioctx,
- const std::string& oid,
+ const std::string& oid, bool exclusive,
Locker *locker, Context *on_finish) {
assert(s_instance != nullptr);
s_instance->locker = locker;
#include "librbd/ManagedLock.cc"
template class librbd::ManagedLock<librbd::MockImageCtx>;
+namespace {
+
+MATCHER_P(IsLockType, exclusive, "") {
+ cls_lock_lock_op op;
+ bufferlist bl;
+ bl.share(arg);
+ bufferlist::iterator iter = bl.begin();
+ ::decode(op, iter);
+ return op.type == (exclusive ? LOCK_EXCLUSIVE : LOCK_SHARED);
+}
+
+} // anonymous namespace
+
namespace librbd {
namespace managed_lock {
typedef GetLockerRequest<MockImageCtx> MockGetLockerRequest;
typedef ManagedLock<MockImageCtx> MockManagedLock;
- void expect_lock(MockImageCtx &mock_image_ctx, int r) {
+ void expect_lock(MockImageCtx &mock_image_ctx, int r,
+ bool exclusive = true) {
EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
- exec(mock_image_ctx.header_oid, _, StrEq("lock"), StrEq("lock"), _, _, _))
+ exec(mock_image_ctx.header_oid, _, StrEq("lock"),
+ StrEq("lock"), IsLockType(exclusive), _, _))
.WillOnce(Return(r));
}
}
};
-TEST_F(TestMockManagedLockAcquireRequest, Success) {
+TEST_F(TestMockManagedLockAcquireRequest, SuccessExclusive) {
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
C_SaferCond ctx;
MockAcquireRequest *req = MockAcquireRequest::create(mock_image_ctx.md_ctx,
mock_image_ctx.image_watcher, ictx->op_work_queue, mock_image_ctx.header_oid,
- TEST_COOKIE, true, 0, &ctx);
+ TEST_COOKIE, true, true, 0, &ctx);
+ req->send();
+ ASSERT_EQ(0, ctx.wait());
+}
+
+TEST_F(TestMockManagedLockAcquireRequest, SuccessShared) {
+
+ librbd::ImageCtx *ictx;
+ ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+ MockImageCtx mock_image_ctx(*ictx);
+ MockGetLockerRequest mock_get_locker_request;
+
+ InSequence seq;
+ expect_get_locker(mock_image_ctx, mock_get_locker_request, {}, 0);
+ expect_lock(mock_image_ctx, 0, false);
+
+ C_SaferCond ctx;
+ MockAcquireRequest *req = MockAcquireRequest::create(mock_image_ctx.md_ctx,
+ mock_image_ctx.image_watcher, ictx->op_work_queue, mock_image_ctx.header_oid,
+ TEST_COOKIE, false, true, 0, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
}
C_SaferCond ctx;
MockAcquireRequest *req = MockAcquireRequest::create(mock_image_ctx.md_ctx,
mock_image_ctx.image_watcher, ictx->op_work_queue, mock_image_ctx.header_oid,
- TEST_COOKIE, true, 0, &ctx);
+ TEST_COOKIE, true, true, 0, &ctx);
req->send();
ASSERT_EQ(-ENOENT, ctx.wait());
}
C_SaferCond ctx;
MockAcquireRequest *req = MockAcquireRequest::create(mock_image_ctx.md_ctx,
mock_image_ctx.image_watcher, ictx->op_work_queue, mock_image_ctx.header_oid,
- TEST_COOKIE, true, 0, &ctx);
+ TEST_COOKIE, true, true, 0, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
C_SaferCond ctx;
MockAcquireRequest *req = MockAcquireRequest::create(mock_image_ctx.md_ctx,
mock_image_ctx.image_watcher, ictx->op_work_queue, mock_image_ctx.header_oid,
- TEST_COOKIE, true, 0, &ctx);
+ TEST_COOKIE, true, true, 0, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
C_SaferCond ctx;
MockAcquireRequest *req = MockAcquireRequest::create(mock_image_ctx.md_ctx,
mock_image_ctx.image_watcher, ictx->op_work_queue, mock_image_ctx.header_oid,
- TEST_COOKIE, true, 0, &ctx);
+ TEST_COOKIE, true, true, 0, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
}
};
-TEST_F(TestMockManagedLockGetLockerRequest, Success) {
+TEST_F(TestMockManagedLockGetLockerRequest, SuccessExclusive) {
REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
librbd::ImageCtx *ictx;
C_SaferCond ctx;
Locker locker;
MockGetLockerRequest *req = MockGetLockerRequest::create(
- mock_image_ctx.md_ctx, mock_image_ctx.header_oid, &locker, &ctx);
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, true, &locker, &ctx);
+ req->send();
+ ASSERT_EQ(0, ctx.wait());
+
+ ASSERT_EQ(entity_name_t::CLIENT(1), locker.entity);
+ ASSERT_EQ("1.2.3.4:0/0", locker.address);
+ ASSERT_EQ("auto 123", locker.cookie);
+ ASSERT_EQ(123U, locker.handle);
+}
+
+TEST_F(TestMockManagedLockGetLockerRequest, SuccessShared) {
+ REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+ librbd::ImageCtx *ictx;
+ ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+ MockTestImageCtx mock_image_ctx(*ictx);
+ expect_op_work_queue(mock_image_ctx);
+
+ InSequence seq;
+ expect_get_lock_info(mock_image_ctx, 0, entity_name_t::CLIENT(1), "1.2.3.4",
+ "auto 123", ManagedLock<>::WATCHER_LOCK_TAG,
+ LOCK_SHARED);
+
+ C_SaferCond ctx;
+ Locker locker;
+ MockGetLockerRequest *req = MockGetLockerRequest::create(
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, false, &locker, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
C_SaferCond ctx;
Locker locker;
MockGetLockerRequest *req = MockGetLockerRequest::create(
- mock_image_ctx.md_ctx, mock_image_ctx.header_oid, &locker, &ctx);
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, true, &locker, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
C_SaferCond ctx;
Locker locker;
MockGetLockerRequest *req = MockGetLockerRequest::create(
- mock_image_ctx.md_ctx, mock_image_ctx.header_oid, &locker, &ctx);
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, true, &locker, &ctx);
req->send();
ASSERT_EQ(-ENOENT, ctx.wait());
}
C_SaferCond ctx;
Locker locker;
MockGetLockerRequest *req = MockGetLockerRequest::create(
- mock_image_ctx.md_ctx, mock_image_ctx.header_oid, &locker, &ctx);
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, true, &locker, &ctx);
req->send();
ASSERT_EQ(-EBUSY, ctx.wait());
}
-TEST_F(TestMockManagedLockGetLockerRequest, GetLockInfoShared) {
+TEST_F(TestMockManagedLockGetLockerRequest, GetLockInfoIncompatibleShared) {
REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
librbd::ImageCtx *ictx;
C_SaferCond ctx;
Locker locker;
MockGetLockerRequest *req = MockGetLockerRequest::create(
- mock_image_ctx.md_ctx, mock_image_ctx.header_oid, &locker, &ctx);
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, true, &locker, &ctx);
+ req->send();
+ ASSERT_EQ(-EBUSY, ctx.wait());
+}
+
+TEST_F(TestMockManagedLockGetLockerRequest, GetLockInfoIncompatibleExclusive) {
+ REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+ librbd::ImageCtx *ictx;
+ ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+ MockTestImageCtx mock_image_ctx(*ictx);
+ expect_op_work_queue(mock_image_ctx);
+
+ InSequence seq;
+ expect_get_lock_info(mock_image_ctx, 0, entity_name_t::CLIENT(1), "1.2.3.4",
+ "auto 123", ManagedLock<>::WATCHER_LOCK_TAG,
+ LOCK_EXCLUSIVE);
+
+ C_SaferCond ctx;
+ Locker locker;
+ MockGetLockerRequest *req = MockGetLockerRequest::create(
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, false, &locker, &ctx);
req->send();
ASSERT_EQ(-EBUSY, ctx.wait());
}
C_SaferCond ctx;
Locker locker;
MockGetLockerRequest *req = MockGetLockerRequest::create(
- mock_image_ctx.md_ctx, mock_image_ctx.header_oid, &locker, &ctx);
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, true, &locker, &ctx);
req->send();
ASSERT_EQ(-EBUSY, ctx.wait());
}
#include "librbd/ManagedLock.cc"
template class librbd::ManagedLock<librbd::MockImageCtx>;
+namespace {
+
+MATCHER_P(IsLockType, exclusive, "") {
+ cls_lock_set_cookie_op op;
+ bufferlist bl;
+ bl.share(arg);
+ bufferlist::iterator iter = bl.begin();
+ ::decode(op, iter);
+ return op.type == (exclusive ? LOCK_EXCLUSIVE : LOCK_SHARED);
+}
+
+} // anonymous namespace
+
namespace librbd {
namespace managed_lock {
using ::testing::Return;
using ::testing::StrEq;
+
class TestMockManagedLockReacquireRequest : public TestMockFixture {
public:
typedef ReacquireRequest<MockImageCtx> MockReacquireRequest;
typedef ManagedLock<MockImageCtx> MockManagedLock;
- void expect_set_cookie(MockImageCtx &mock_image_ctx, int r) {
+ void expect_set_cookie(MockImageCtx &mock_image_ctx, int r,
+ bool exclusive = true) {
EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
exec(mock_image_ctx.header_oid, _, StrEq("lock"),
- StrEq("set_cookie"), _, _, _))
+ StrEq("set_cookie"), IsLockType(exclusive), _, _))
.WillOnce(Return(r));
}
};
-TEST_F(TestMockManagedLockReacquireRequest, Success) {
+TEST_F(TestMockManagedLockReacquireRequest, SuccessExclusive) {
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
C_SaferCond ctx;
MockReacquireRequest *req = MockReacquireRequest::create(
mock_image_ctx.md_ctx, mock_image_ctx.header_oid, "old_cookie",
- "new_cookie", &ctx);
+ "new_cookie", true, &ctx);
+ req->send();
+ ASSERT_EQ(0, ctx.wait());
+}
+
+TEST_F(TestMockManagedLockReacquireRequest, SuccessShared) {
+ librbd::ImageCtx *ictx;
+ ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+ MockImageCtx mock_image_ctx(*ictx);
+
+ InSequence seq;
+ expect_set_cookie(mock_image_ctx, 0, false);
+
+ C_SaferCond ctx;
+ MockReacquireRequest *req = MockReacquireRequest::create(
+ mock_image_ctx.md_ctx, mock_image_ctx.header_oid, "old_cookie",
+ "new_cookie", false, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
}
C_SaferCond ctx;
MockReacquireRequest *req = MockReacquireRequest::create(
mock_image_ctx.md_ctx, mock_image_ctx.header_oid, "old_cookie",
- "new_cookie", &ctx);
+ "new_cookie", true, &ctx);
req->send();
ASSERT_EQ(-EOPNOTSUPP, ctx.wait());
}
C_SaferCond ctx;
MockReacquireRequest *req = MockReacquireRequest::create(
mock_image_ctx.md_ctx, mock_image_ctx.header_oid, "old_cookie",
- "new_cookie", &ctx);
+ "new_cookie", true, &ctx);
req->send();
ASSERT_EQ(-EBUSY, ctx.wait());
}
static AcquireRequest* create(librados::IoCtx& ioctx,
MockImageWatcher *watcher,
ContextWQ *work_queue, const std::string& oid,
- const std::string& cookie,
+ const std::string& cookie, bool exclusive,
bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds,
Context *on_finish) {
- return BaseRequest::create(ioctx, watcher, work_queue, oid, cookie, on_finish);
+ return BaseRequest::create(ioctx, watcher, work_queue, oid, cookie,
+ on_finish);
}
MOCK_METHOD0(send, void());
};
struct ReacquireRequest<MockExclusiveLockImageCtx> : public BaseRequest<ReacquireRequest<MockExclusiveLockImageCtx> > {
static ReacquireRequest* create(librados::IoCtx &ioctx, const std::string& oid,
const string& old_cookie, const std::string& new_cookie,
- Context *on_finish) {
- return BaseRequest::create(ioctx, nullptr, nullptr, oid, new_cookie, on_finish);
+ bool exclusive, Context *on_finish) {
+ return BaseRequest::create(ioctx, nullptr, nullptr, oid, new_cookie,
+ on_finish);
}
MOCK_METHOD0(send, void());
template <>
struct ReleaseRequest<MockExclusiveLockImageCtx> : public BaseRequest<ReleaseRequest<MockExclusiveLockImageCtx> > {
+ static ReleaseRequest* create(librados::IoCtx& ioctx, MockImageWatcher *watcher,
+ ContextWQ *work_queue, const std::string& oid,
+ const std::string& cookie, Context *on_finish) {
+ return BaseRequest::create(ioctx, watcher, work_queue, oid, cookie,
+ on_finish);
+ }
+
MOCK_METHOD0(send, void());
};
MockImageWatcher *watcher,
ContextWQ *work_queue, const std::string& oid,
const std::string& cookie,
- bool blacklist_on_break_lock,
+ bool exclusive, bool blacklist_on_break_lock,
uint32_t blacklist_expire_seconds,
Context *on_finish) {
return BaseRequest::create(ioctx, watcher, work_queue, oid, cookie, on_finish);
struct ReacquireRequest<MockManagedLockImageCtx> : public BaseRequest<ReacquireRequest<MockManagedLockImageCtx> > {
static ReacquireRequest* create(librados::IoCtx &ioctx, const std::string& oid,
const string& old_cookie, const std::string& new_cookie,
- Context *on_finish) {
- return BaseRequest::create(ioctx, nullptr, nullptr, oid, new_cookie, on_finish);
+ bool exclusive, Context *on_finish) {
+ return BaseRequest::create(ioctx, nullptr, nullptr, oid, new_cookie,
+ on_finish);
}
MOCK_METHOD0(send, void());
template <>
struct ReleaseRequest<MockManagedLockImageCtx> : public BaseRequest<ReleaseRequest<MockManagedLockImageCtx> > {
+ static ReleaseRequest* create(librados::IoCtx& ioctx, MockImageWatcher *watcher,
+ ContextWQ *work_queue, const std::string& oid,
+ const std::string& cookie, Context *on_finish) {
+ return BaseRequest::create(ioctx, watcher, work_queue, oid, cookie,
+ on_finish);
+ }
MOCK_METHOD0(send, void());
};
template <>
struct GetLockerRequest<MockManagedLockImageCtx> {
static GetLockerRequest* create(librados::IoCtx& ioctx,
- const std::string& oid,
+ const std::string& oid, bool exclusive,
Locker *locker, Context *on_finish) {
assert(0 == "unexpected call");
}
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest request_lock_acquire1;
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest try_lock_acquire;
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest try_lock_acquire;
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest try_lock_acquire;
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest try_lock_acquire;
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
// will abort after seeing blacklist error (avoid infinite request loop)
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
ASSERT_EQ(0, when_release_lock(managed_lock));
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest try_lock_acquire;
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
expect_get_watch_handle(*mock_image_ctx.image_watcher);
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest request_lock_acquire;
MockManagedLockImageCtx mock_image_ctx(*ictx);
MockManagedLock managed_lock(ictx->md_ctx, ictx->op_work_queue,
ictx->header_oid, mock_image_ctx.image_watcher,
- true, 0);
+ librbd::managed_lock::EXCLUSIVE, true, 0);
InSequence seq;
MockAcquireRequest request_lock_acquire;