managed_lock/GetLockerRequest.cc
managed_lock/ReleaseRequest.cc
managed_lock/ReacquireRequest.cc
+ managed_lock/Utils.cc
exclusive_lock/AutomaticPolicy.cc
exclusive_lock/PreAcquireRequest.cc
exclusive_lock/PostAcquireRequest.cc
#include "librbd/managed_lock/ReleaseRequest.h"
#include "librbd/managed_lock/ReacquireRequest.h"
#include "librbd/managed_lock/Types.h"
+#include "librbd/managed_lock/Utils.h"
#include "librbd/Watcher.h"
#include "librbd/ImageCtx.h"
#include "cls/lock/cls_lock_client.h"
#include "common/errno.h"
#include "common/WorkQueue.h"
#include "librbd/Utils.h"
-#include <sstream>
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
namespace {
-const std::string WATCHER_LOCK_COOKIE_PREFIX = "auto";
-
template <typename R>
struct C_SendLockRequest : public Context {
R* request;
} // anonymous namespace
-template <typename I>
-const std::string ManagedLock<I>::WATCHER_LOCK_TAG("internal");
+using librbd::util::create_context_callback;
+using librbd::util::unique_lock_name;
+using managed_lock::util::decode_lock_cookie;
+using managed_lock::util::encode_lock_cookie;
template <typename I>
ManagedLock<I>::ManagedLock(librados::IoCtx &ioctx, ContextWQ *work_queue,
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_lock(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),
on_finish->complete(r);
}
-template <typename I>
-bool ManagedLock<I>::decode_lock_cookie(const std::string &tag,
- uint64_t *handle) {
- std::string prefix;
- std::istringstream ss(tag);
- if (!(ss >> prefix >> *handle) || prefix != WATCHER_LOCK_COOKIE_PREFIX) {
- return false;
- }
- return true;
-}
-
-template <typename I>
-string ManagedLock<I>::encode_lock_cookie(uint64_t watch_handle) {
- assert(watch_handle != 0);
- std::ostringstream ss;
- ss << WATCHER_LOCK_COOKIE_PREFIX << " " << watch_handle;
- return ss.str();
-}
-
template <typename I>
bool ManagedLock<I>::is_transition_state() const {
switch (m_state) {
m_state = STATE_WAITING_FOR_REGISTER;
return;
}
- m_cookie = ManagedLock<I>::encode_lock_cookie(watch_handle);
+ m_cookie = encode_lock_cookie(watch_handle);
m_work_queue->queue(new FunctionContext([this](int r) {
- pre_acquire_lock_handler(util::create_context_callback<
+ pre_acquire_lock_handler(create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_pre_acquire_lock>(this));
}));
}
AcquireRequest<I>* req = AcquireRequest<I>::create(
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<
+ create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_acquire_lock>(this));
m_work_queue->queue(new C_SendLockRequest<AcquireRequest<I>>(req), 0);
}
m_post_next_state = (r < 0 ? STATE_UNLOCKED : STATE_LOCKED);
m_work_queue->queue(new FunctionContext([this, r](int ret) {
- post_acquire_lock_handler(r, util::create_context_callback<
+ post_acquire_lock_handler(r, create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_post_acquire_lock>(this));
}));
}
return;
}
- m_new_cookie = ManagedLock<I>::encode_lock_cookie(watch_handle);
+ m_new_cookie = encode_lock_cookie(watch_handle);
if (m_cookie == m_new_cookie) {
ldout(m_cct, 10) << ": skipping reacquire since cookie still valid"
<< dendl;
using managed_lock::ReacquireRequest;
ReacquireRequest<I>* req = ReacquireRequest<I>::create(m_ioctx, m_oid,
m_cookie, m_new_cookie, m_mode == EXCLUSIVE,
- util::create_context_callback<
+ create_context_callback<
ManagedLock, &ManagedLock<I>::handle_reacquire_lock>(this));
m_work_queue->queue(new C_SendLockRequest<ReacquireRequest<I>>(req));
}
m_state = STATE_PRE_RELEASING;
m_work_queue->queue(new FunctionContext([this](int r) {
- pre_release_lock_handler(false, util::create_context_callback<
+ pre_release_lock_handler(false, create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_pre_release_lock>(this));
}));
}
using managed_lock::ReleaseRequest;
ReleaseRequest<I>* req = ReleaseRequest<I>::create(m_ioctx, m_watcher,
m_work_queue, m_oid, m_cookie,
- util::create_context_callback<
+ create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_release_lock>(this));
m_work_queue->queue(new C_SendLockRequest<ReleaseRequest<I>>(req), 0);
}
m_post_next_state = r < 0 ? STATE_LOCKED : STATE_UNLOCKED;
m_work_queue->queue(new FunctionContext([this, r](int ret) {
- post_release_lock_handler(false, r, util::create_context_callback<
+ post_release_lock_handler(false, r, create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_post_release_lock>(this));
}));
}
if (m_state == STATE_UNLOCKED) {
m_state = STATE_SHUTTING_DOWN;
m_work_queue->queue(new FunctionContext([this](int r) {
- shutdown_handler(r, util::create_context_callback<
+ shutdown_handler(r, create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_shutdown>(this));
}));
return;
Mutex::Locker locker(m_lock);
m_work_queue->queue(new FunctionContext([this](int r) {
- pre_release_lock_handler(true, util::create_context_callback<
+ pre_release_lock_handler(true, create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_shutdown_pre_release>(this));
}));
}
ReleaseRequest<I>* req = ReleaseRequest<I>::create(m_ioctx, m_watcher,
m_work_queue, m_oid, cookie,
new FunctionContext([this](int r) {
- post_release_lock_handler(true, r, util::create_context_callback<
+ post_release_lock_handler(true, r, create_context_callback<
ManagedLock<I>, &ManagedLock<I>::handle_shutdown_post_release>(this));
}));
req->send();
typedef typename TypeTraits::Watcher Watcher;
public:
- static const std::string WATCHER_LOCK_TAG;
-
static ManagedLock *create(librados::IoCtx& ioctx, ContextWQ *work_queue,
const std::string& oid, Watcher *watcher,
managed_lock::Mode mode,
return m_state == STATE_LOCKED;
}
- static bool decode_lock_cookie(const std::string &tag, uint64_t *handle);
-
protected:
/**
ActionsContexts m_actions_contexts;
- static std::string encode_lock_cookie(uint64_t watch_handle);
-
bool is_lock_owner(Mutex &lock) const;
bool is_transition_state() const;
#include "common/WorkQueue.h"
#include "include/stringify.h"
#include "librbd/ExclusiveLock.h"
-#include "librbd/ManagedLock.h"
#include "librbd/ImageCtx.h"
#include "librbd/ImageState.h"
#include "librbd/ImageWatcher.h"
namespace librbd {
-template <typename> class Journal;
-template <typename> class ManagedLock;
-
namespace exclusive_lock {
template <typename ImageCtxT = ImageCtx>
#include "common/errno.h"
#include "librbd/AioImageRequestWQ.h"
#include "librbd/ExclusiveLock.h"
-#include "librbd/ManagedLock.h"
#include "librbd/ImageState.h"
#include "librbd/ImageWatcher.h"
#include "librbd/Journal.h"
namespace librbd {
struct ImageCtx;
-template <typename> class ManagedLock;
-template <typename> class Journal;
namespace exclusive_lock {
#include "librbd/managed_lock/AcquireRequest.h"
#include "librbd/Watcher.h"
-#include "librbd/ManagedLock.h"
#include "cls/lock/cls_lock_client.h"
#include "cls/lock/cls_lock_types.h"
#include "common/dout.h"
#include "common/errno.h"
#include "common/WorkQueue.h"
#include "include/stringify.h"
+#include "librbd/ImageCtx.h"
#include "librbd/Utils.h"
#include "librbd/managed_lock/BreakRequest.h"
#include "librbd/managed_lock/GetLockerRequest.h"
-
-#include "librbd/ImageCtx.h"
+#include "librbd/managed_lock/Utils.h"
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
namespace librbd {
-using util::detail::C_AsyncCallback;
-using util::create_context_callback;
-using util::create_rados_safe_callback;
-using util::create_rados_ack_callback;
+using librbd::util::detail::C_AsyncCallback;
+using librbd::util::create_context_callback;
+using librbd::util::create_rados_safe_callback;
+using librbd::util::create_rados_ack_callback;
namespace managed_lock {
librados::ObjectWriteOperation op;
rados::cls::lock::lock(&op, RBD_LOCK_NAME,
m_exclusive ? LOCK_EXCLUSIVE : LOCK_SHARED, m_cookie,
- ManagedLock<I>::WATCHER_LOCK_TAG, "", utime_t(), 0);
+ util::get_watcher_lock_tag(), "", utime_t(), 0);
using klass = AcquireRequest;
librados::AioCompletion *rados_completion =
#include "common/errno.h"
#include "include/stringify.h"
#include "librbd/ImageCtx.h"
-#include "librbd/ManagedLock.h"
#include "librbd/Utils.h"
#include "librbd/managed_lock/Types.h"
+#include "librbd/managed_lock/Utils.h"
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
namespace librbd {
namespace managed_lock {
-using util::create_rados_ack_callback;
+using librbd::util::create_rados_ack_callback;
template <typename I>
GetLockerRequest<I>::GetLockerRequest(librados::IoCtx& ioctx,
return;
}
- if (lock_tag != ManagedLock<>::WATCHER_LOCK_TAG) {
+ if (lock_tag != util::get_watcher_lock_tag()) {
ldout(m_cct, 5) <<"locked by external mechanism: tag=" << lock_tag << dendl;
finish(-EBUSY);
return;
std::map<rados::cls::lock::locker_id_t,
rados::cls::lock::locker_info_t>::iterator iter = lockers.begin();
- if (!ManagedLock<>::decode_lock_cookie(iter->first.cookie,
- &m_locker->handle)) {
+ if (!util::decode_lock_cookie(iter->first.cookie, &m_locker->handle)) {
ldout(m_cct, 5) << "locked by external mechanism: "
<< "cookie=" << iter->first.cookie << dendl;
finish(-EBUSY);
#include "librbd/managed_lock/ReacquireRequest.h"
#include "librbd/Watcher.h"
-#include "librbd/ManagedLock.h"
#include "cls/lock/cls_lock_client.h"
#include "cls/lock/cls_lock_types.h"
#include "common/dout.h"
#include "common/errno.h"
-#include "librbd/Utils.h"
-
#include "librbd/ImageCtx.h"
+#include "librbd/Utils.h"
+#include "librbd/managed_lock/Utils.h"
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
librados::ObjectWriteOperation op;
rados::cls::lock::set_cookie(&op, RBD_LOCK_NAME,
m_exclusive ? LOCK_EXCLUSIVE : LOCK_SHARED,
- m_old_cookie, ManagedLock<I>::WATCHER_LOCK_TAG,
+ m_old_cookie, util::get_watcher_lock_tag(),
m_new_cookie);
librados::AioCompletion *rados_completion = create_rados_safe_callback<
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "include/assert.h"
+#include "librbd/managed_lock/Utils.h"
+#include <sstream>
+
+namespace librbd {
+namespace managed_lock {
+namespace util {
+
+namespace {
+
+const std::string WATCHER_LOCK_COOKIE_PREFIX = "auto";
+const std::string WATCHER_LOCK_TAG("internal");
+
+} // anonymous namespace
+
+const std::string &get_watcher_lock_tag() {
+ return WATCHER_LOCK_TAG;
+}
+
+bool decode_lock_cookie(const std::string &tag, uint64_t *handle) {
+ std::string prefix;
+ std::istringstream ss(tag);
+ if (!(ss >> prefix >> *handle) || prefix != WATCHER_LOCK_COOKIE_PREFIX) {
+ return false;
+ }
+ return true;
+}
+
+std::string encode_lock_cookie(uint64_t watch_handle) {
+ assert(watch_handle != 0);
+ std::ostringstream ss;
+ ss << WATCHER_LOCK_COOKIE_PREFIX << " " << watch_handle;
+ return ss.str();
+}
+
+} // namespace util
+} // namespace managed_lock
+} // namespace librbd
+
+
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_MANAGED_LOCK_UTILS_H
+#define CEPH_LIBRBD_MANAGED_LOCK_UTILS_H
+
+#include "include/int_types.h"
+#include <string>
+
+namespace librbd {
+namespace managed_lock {
+namespace util {
+
+const std::string &get_watcher_lock_tag();
+
+bool decode_lock_cookie(const std::string &tag, uint64_t *handle);
+std::string encode_lock_cookie(uint64_t watch_handle);
+
+} // namespace util
+} // namespace managed_lock
+} // namespace librbd
+
+#endif // CEPH_LIBRBD_MANAGED_LOCK_UTILS_H
namespace librbd {
-using librbd::ManagedLock;
-
namespace exclusive_lock {
namespace {
#include "librbd/managed_lock/AcquireRequest.cc"
template class librbd::managed_lock::AcquireRequest<librbd::MockImageCtx>;
-#include "librbd/ManagedLock.cc"
-template class librbd::ManagedLock<librbd::MockImageCtx>;
-
namespace {
MATCHER_P(IsLockType, exclusive, "") {
typedef AcquireRequest<MockImageCtx> MockAcquireRequest;
typedef BreakRequest<MockImageCtx> MockBreakRequest;
typedef GetLockerRequest<MockImageCtx> MockGetLockerRequest;
- typedef ManagedLock<MockImageCtx> MockManagedLock;
void expect_lock(MockImageCtx &mock_image_ctx, int r,
bool exclusive = true) {
#include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
#include "test/librados_test_stub/MockTestMemRadosClient.h"
#include "cls/lock/cls_lock_ops.h"
-#include "librbd/ManagedLock.h"
#include "librbd/managed_lock/BreakRequest.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
#include "test/librados_test_stub/MockTestMemRadosClient.h"
#include "cls/lock/cls_lock_ops.h"
-#include "librbd/ManagedLock.h"
#include "librbd/managed_lock/GetLockerRequest.h"
#include "librbd/managed_lock/Types.h"
+#include "librbd/managed_lock/Utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <arpa/inet.h>
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,
+ "auto 123", util::get_watcher_lock_tag(),
LOCK_EXCLUSIVE);
C_SaferCond 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,
+ "auto 123", util::get_watcher_lock_tag(),
LOCK_SHARED);
C_SaferCond 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,
+ "auto 123", util::get_watcher_lock_tag(),
LOCK_SHARED);
C_SaferCond 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,
+ "auto 123", util::get_watcher_lock_tag(),
LOCK_EXCLUSIVE);
C_SaferCond ctx;
InSequence seq;
expect_get_lock_info(mock_image_ctx, 0, entity_name_t::CLIENT(1), "1.2.3.4",
- "external cookie", ManagedLock<>::WATCHER_LOCK_TAG,
+ "external cookie", util::get_watcher_lock_tag(),
LOCK_EXCLUSIVE);
C_SaferCond ctx;
#include "librbd/managed_lock/ReacquireRequest.cc"
template class librbd::managed_lock::ReacquireRequest<librbd::MockImageCtx>;
-#include "librbd/ManagedLock.cc"
-template class librbd::ManagedLock<librbd::MockImageCtx>;
-
namespace {
MATCHER_P(IsLockType, exclusive, "") {
class TestMockManagedLockReacquireRequest : public TestMockFixture {
public:
typedef ReacquireRequest<MockImageCtx> MockReacquireRequest;
- typedef ManagedLock<MockImageCtx> MockManagedLock;
void expect_set_cookie(MockImageCtx &mock_image_ctx, int r,
bool exclusive = true) {
#include "librbd/managed_lock/ReleaseRequest.cc"
template class librbd::managed_lock::ReleaseRequest<librbd::MockImageCtx>;
-#include "librbd/ManagedLock.cc"
-template class librbd::ManagedLock<librbd::MockImageCtx>;
-
namespace librbd {
namespace managed_lock {
class TestMockManagedLockReleaseRequest : public TestMockFixture {
public:
typedef ReleaseRequest<MockImageCtx> MockReleaseRequest;
- typedef ManagedLock<MockImageCtx> MockManagedLock;
void expect_unlock(MockImageCtx &mock_image_ctx, int r) {
EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),