#include <boost/scope_exit.hpp>
namespace librbd {
+
+namespace {
+
+struct MockRefreshImageCtx : public MockImageCtx {
+ MockRefreshImageCtx(ImageCtx &image_ctx) : MockImageCtx(image_ctx) {
+ }
+};
+
+} // anonymous namespace
+
namespace image {
template <>
-struct RefreshParentRequest<MockImageCtx> {
+struct RefreshParentRequest<MockRefreshImageCtx> {
static RefreshParentRequest* s_instance;
- static RefreshParentRequest* create(MockImageCtx &mock_image_ctx,
+ static RefreshParentRequest* create(MockRefreshImageCtx &mock_image_ctx,
const parent_info& parent_md,
Context *on_finish) {
assert(s_instance != nullptr);
s_instance->on_finish = on_finish;
return s_instance;
}
- static bool is_refresh_required(MockImageCtx &mock_image_ctx,
+ static bool is_refresh_required(MockRefreshImageCtx &mock_image_ctx,
const parent_info& parent_md) {
assert(s_instance != nullptr);
return s_instance->is_refresh_required();
MOCK_METHOD1(finalize, void(Context *));
};
-RefreshParentRequest<MockImageCtx>* RefreshParentRequest<MockImageCtx>::s_instance = nullptr;
+RefreshParentRequest<MockRefreshImageCtx>* RefreshParentRequest<MockRefreshImageCtx>::s_instance = nullptr;
} // namespace image
} // namespace librbd
// template definitions
#include "librbd/image/RefreshRequest.cc"
-template class librbd::image::RefreshRequest<librbd::MockImageCtx>;
+template class librbd::image::RefreshRequest<librbd::MockRefreshImageCtx>;
ACTION_P(TestFeatures, image_ctx) {
return ((image_ctx->features & arg0) != 0);
class TestMockImageRefreshRequest : public TestMockFixture {
public:
- typedef RefreshRequest<MockImageCtx> MockRefreshRequest;
- typedef RefreshParentRequest<MockImageCtx> MockRefreshParentRequest;
+ typedef RefreshRequest<MockRefreshImageCtx> MockRefreshRequest;
+ typedef RefreshParentRequest<MockRefreshImageCtx> MockRefreshParentRequest;
- void expect_set_require_lock_on_read(MockImageCtx &mock_image_ctx) {
+ void expect_set_require_lock_on_read(MockRefreshImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, set_require_lock_on_read());
}
- void expect_clear_require_lock_on_read(MockImageCtx &mock_image_ctx) {
+ void expect_clear_require_lock_on_read(MockRefreshImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, clear_require_lock_on_read());
}
- void expect_v1_read_header(MockImageCtx &mock_image_ctx, int r) {
+ void expect_v1_read_header(MockRefreshImageCtx &mock_image_ctx, int r) {
auto &expect = EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
read(mock_image_ctx.header_oid, _, _, _));
if (r < 0) {
}
}
- void expect_v1_get_snapshots(MockImageCtx &mock_image_ctx, int r) {
+ void expect_v1_get_snapshots(MockRefreshImageCtx &mock_image_ctx, int r) {
auto &expect = EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
exec(mock_image_ctx.header_oid, _, "rbd", "snap_list", _, _, _));
if (r < 0) {
}
}
- void expect_v1_get_locks(MockImageCtx &mock_image_ctx, int r) {
+ void expect_v1_get_locks(MockRefreshImageCtx &mock_image_ctx, int r) {
auto &expect = EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
exec(mock_image_ctx.header_oid, _, "lock", "get_info", _, _, _));
if (r < 0) {
}
}
- void expect_get_mutable_metadata(MockImageCtx &mock_image_ctx, int r) {
+ void expect_get_mutable_metadata(MockRefreshImageCtx &mock_image_ctx, int r) {
auto &expect = EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
exec(mock_image_ctx.header_oid, _, "rbd", "get_size", _, _, _));
if (r < 0) {
}
}
- void expect_get_flags(MockImageCtx &mock_image_ctx, int r) {
+ void expect_get_flags(MockRefreshImageCtx &mock_image_ctx, int r) {
auto &expect = EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
exec(mock_image_ctx.header_oid, _, "rbd", "get_flags", _, _, _));
if (r < 0) {
}
}
- void expect_get_snapshots(MockImageCtx &mock_image_ctx, int r) {
+ void expect_get_snapshots(MockRefreshImageCtx &mock_image_ctx, int r) {
auto &expect = EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
exec(mock_image_ctx.header_oid, _, "rbd", "get_snapshot_name", _, _, _));
if (r < 0) {
}
}
- void expect_add_snap(MockImageCtx &mock_image_ctx,
+ void expect_add_snap(MockRefreshImageCtx &mock_image_ctx,
const std::string &snap_name, uint64_t snap_id) {
EXPECT_CALL(mock_image_ctx, add_snap(snap_name, snap_id, _, _, _, _));
}
- void expect_init_exclusive_lock(MockImageCtx &mock_image_ctx,
+ void expect_init_exclusive_lock(MockRefreshImageCtx &mock_image_ctx,
MockExclusiveLock &mock_exclusive_lock,
int r) {
EXPECT_CALL(mock_image_ctx, create_exclusive_lock())
.WillOnce(WithArg<1>(CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue)));
}
- void expect_shut_down_exclusive_lock(MockImageCtx &mock_image_ctx,
+ void expect_shut_down_exclusive_lock(MockRefreshImageCtx &mock_image_ctx,
MockExclusiveLock &mock_exclusive_lock,
int r) {
EXPECT_CALL(mock_exclusive_lock, shut_down(_))
CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue)));
}
- void expect_init_layout(MockImageCtx &mock_image_ctx) {
+ void expect_init_layout(MockRefreshImageCtx &mock_image_ctx) {
EXPECT_CALL(mock_image_ctx, init_layout());
}
- void expect_test_features(MockImageCtx &mock_image_ctx) {
+ void expect_test_features(MockRefreshImageCtx &mock_image_ctx) {
EXPECT_CALL(mock_image_ctx, test_features(_, _))
.WillRepeatedly(TestFeatures(&mock_image_ctx));
}
.WillRepeatedly(Return(required));
}
- void expect_refresh_parent_send(MockImageCtx &mock_image_ctx,
+ void expect_refresh_parent_send(MockRefreshImageCtx &mock_image_ctx,
MockRefreshParentRequest &mock_refresh_parent_request,
int r) {
EXPECT_CALL(mock_refresh_parent_request, send())
EXPECT_CALL(mock_refresh_parent_request, apply());
}
- void expect_refresh_parent_finalize(MockImageCtx &mock_image_ctx,
+ void expect_refresh_parent_finalize(MockRefreshImageCtx &mock_image_ctx,
MockRefreshParentRequest &mock_refresh_parent_request,
int r) {
EXPECT_CALL(mock_refresh_parent_request, finalize(_))
EXPECT_CALL(mock_exclusive_lock, is_lock_owner()).WillOnce(Return(is_owner));
}
- void expect_open_journal(MockImageCtx &mock_image_ctx,
+ void expect_open_journal(MockRefreshImageCtx &mock_image_ctx,
MockJournal &mock_journal, int r) {
EXPECT_CALL(mock_image_ctx, create_journal())
.WillOnce(Return(&mock_journal));
.WillOnce(CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue));
}
- void expect_close_journal(MockImageCtx &mock_image_ctx,
+ void expect_close_journal(MockRefreshImageCtx &mock_image_ctx,
MockJournal &mock_journal, int r) {
EXPECT_CALL(mock_journal, close(_))
.WillOnce(CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue));
}
- void expect_open_object_map(MockImageCtx &mock_image_ctx,
+ void expect_open_object_map(MockRefreshImageCtx &mock_image_ctx,
MockObjectMap &mock_object_map, int r) {
EXPECT_CALL(mock_image_ctx, create_object_map(_))
.WillOnce(Return(&mock_object_map));
.WillOnce(CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue));
}
- void expect_close_object_map(MockImageCtx &mock_image_ctx,
+ void expect_close_object_map(MockRefreshImageCtx &mock_image_ctx,
MockObjectMap &mock_object_map, int r) {
EXPECT_CALL(mock_object_map, close(_))
.WillOnce(CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue));
}
- void expect_get_snap_id(MockImageCtx &mock_image_ctx,
+ void expect_get_snap_id(MockRefreshImageCtx &mock_image_ctx,
const std::string &snap_name, uint64_t snap_id) {
EXPECT_CALL(mock_image_ctx, get_snap_id(snap_name)).WillOnce(Return(snap_id));
}
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
expect_op_work_queue(mock_image_ctx);
expect_test_features(mock_image_ctx);
ASSERT_EQ(0, snap_create(*ictx, "snap"));
ASSERT_EQ(0, ictx->state->refresh());
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
expect_op_work_queue(mock_image_ctx);
expect_test_features(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
expect_op_work_queue(mock_image_ctx);
ASSERT_EQ(0, open_image(m_image_name, &ictx));
ASSERT_EQ(0, snap_create(*ictx, "snap"));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
expect_op_work_queue(mock_image_ctx);
ASSERT_EQ(0, snap_create(*ictx, "snap"));
ASSERT_EQ(0, librbd::snap_set(ictx, "snap"));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockObjectMap mock_object_map;
expect_op_work_queue(mock_image_ctx);
ASSERT_EQ(0, open_image(clone_name, &ictx2));
- MockImageCtx mock_image_ctx(*ictx2);
+ MockRefreshImageCtx mock_image_ctx(*ictx2);
MockRefreshParentRequest *mock_refresh_parent_request = new MockRefreshParentRequest();
MockExclusiveLock mock_exclusive_lock;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock *mock_exclusive_lock = new MockExclusiveLock();
RBD_FEATURE_OBJECT_MAP |
RBD_FEATURE_FAST_DIFF, false));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
RBD_FEATURE_OBJECT_MAP |
RBD_FEATURE_FAST_DIFF, false));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
ASSERT_EQ(0, update_features(ictx, RBD_FEATURE_JOURNALING, false));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
ASSERT_EQ(0, update_features(ictx, RBD_FEATURE_JOURNALING, false));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockRefreshImageCtx mock_image_ctx(*ictx);
MockRefreshParentRequest mock_refresh_parent_request;
MockExclusiveLock mock_exclusive_lock;
namespace librbd {
+namespace {
+
+struct MockReplayImageCtx : public MockImageCtx {
+ MockReplayImageCtx(ImageCtx &image_ctx) : MockImageCtx(image_ctx) {
+ }
+};
+
+} // anonymous namespace
+
template <>
-struct AioImageRequest<MockImageCtx> {
+struct AioImageRequest<MockReplayImageCtx> {
static AioImageRequest *s_instance;
MOCK_METHOD5(aio_write, void(AioCompletion *c, uint64_t off, size_t len,
const char *buf, int op_flags));
- static void aio_write(MockImageCtx *ictx, AioCompletion *c, uint64_t off,
+ static void aio_write(MockReplayImageCtx *ictx, AioCompletion *c, uint64_t off,
size_t len, const char *buf, int op_flags) {
assert(s_instance != nullptr);
s_instance->aio_write(c, off, len, buf, op_flags);
}
MOCK_METHOD3(aio_discard, void(AioCompletion *c, uint64_t off, uint64_t len));
- static void aio_discard(MockImageCtx *ictx, AioCompletion *c, uint64_t off,
+ static void aio_discard(MockReplayImageCtx *ictx, AioCompletion *c, uint64_t off,
uint64_t len) {
assert(s_instance != nullptr);
s_instance->aio_discard(c, off, len);
}
MOCK_METHOD1(aio_flush, void(AioCompletion *c));
- static void aio_flush(MockImageCtx *ictx, AioCompletion *c) {
+ static void aio_flush(MockReplayImageCtx *ictx, AioCompletion *c) {
assert(s_instance != nullptr);
s_instance->aio_flush(c);
}
}
};
-AioImageRequest<MockImageCtx> *AioImageRequest<MockImageCtx>::s_instance = nullptr;
+AioImageRequest<MockReplayImageCtx> *AioImageRequest<MockReplayImageCtx>::s_instance = nullptr;
}
// template definitions
#include "librbd/journal/Replay.cc"
-template class librbd::journal::Replay<librbd::MockImageCtx>;
+template class librbd::journal::Replay<librbd::MockReplayImageCtx>;
using ::testing::_;
using ::testing::DoAll;
class TestMockJournalReplay : public TestMockFixture {
public:
- typedef AioImageRequest<MockImageCtx> MockAioImageRequest;
- typedef Replay<MockImageCtx> MockJournalReplay;
+ typedef AioImageRequest<MockReplayImageCtx> MockAioImageRequest;
+ typedef Replay<MockReplayImageCtx> MockJournalReplay;
TestMockJournalReplay() : m_invoke_lock("m_invoke_lock") {
}
.WillOnce(SaveArg<0>(aio_comp));
}
- void expect_aio_flush(MockImageCtx &mock_image_ctx,
+ void expect_aio_flush(MockReplayImageCtx &mock_image_ctx,
MockAioImageRequest &mock_aio_image_request, int r) {
EXPECT_CALL(mock_aio_image_request, aio_flush(_))
.WillOnce(CompleteAioCompletion(r, mock_image_ctx.image_ctx));
.WillOnce(SaveArg<0>(aio_comp));
}
- void expect_flatten(MockImageCtx &mock_image_ctx, Context **on_finish) {
+ void expect_flatten(MockReplayImageCtx &mock_image_ctx, Context **on_finish) {
EXPECT_CALL(*mock_image_ctx.operations, flatten(_, _))
.WillOnce(DoAll(SaveArg<1>(on_finish),
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_rename(MockImageCtx &mock_image_ctx, Context **on_finish,
+ void expect_rename(MockReplayImageCtx &mock_image_ctx, Context **on_finish,
const char *image_name) {
EXPECT_CALL(*mock_image_ctx.operations, rename(CStrEq(image_name), _))
.WillOnce(DoAll(SaveArg<1>(on_finish),
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_resize(MockImageCtx &mock_image_ctx, Context **on_finish,
+ void expect_resize(MockReplayImageCtx &mock_image_ctx, Context **on_finish,
uint64_t size, uint64_t op_tid) {
EXPECT_CALL(*mock_image_ctx.operations, resize(size, _, _, op_tid))
.WillOnce(DoAll(SaveArg<2>(on_finish),
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_snap_create(MockImageCtx &mock_image_ctx,
+ void expect_snap_create(MockReplayImageCtx &mock_image_ctx,
Context **on_finish, const char *snap_name,
uint64_t op_tid) {
EXPECT_CALL(*mock_image_ctx.operations, snap_create(CStrEq(snap_name), _,
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_snap_remove(MockImageCtx &mock_image_ctx,
+ void expect_snap_remove(MockReplayImageCtx &mock_image_ctx,
Context **on_finish, const char *snap_name) {
EXPECT_CALL(*mock_image_ctx.operations, snap_remove(CStrEq(snap_name), _))
.WillOnce(DoAll(SaveArg<1>(on_finish),
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_snap_rename(MockImageCtx &mock_image_ctx,
+ void expect_snap_rename(MockReplayImageCtx &mock_image_ctx,
Context **on_finish, uint64_t snap_id,
const char *snap_name) {
EXPECT_CALL(*mock_image_ctx.operations, snap_rename(snap_id, CStrEq(snap_name), _))
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_snap_protect(MockImageCtx &mock_image_ctx,
+ void expect_snap_protect(MockReplayImageCtx &mock_image_ctx,
Context **on_finish, const char *snap_name) {
EXPECT_CALL(*mock_image_ctx.operations, snap_protect(CStrEq(snap_name), _))
.WillOnce(DoAll(SaveArg<1>(on_finish),
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_snap_unprotect(MockImageCtx &mock_image_ctx,
+ void expect_snap_unprotect(MockReplayImageCtx &mock_image_ctx,
Context **on_finish, const char *snap_name) {
EXPECT_CALL(*mock_image_ctx.operations, snap_unprotect(CStrEq(snap_name), _))
.WillOnce(DoAll(SaveArg<1>(on_finish),
NotifyInvoke(&m_invoke_lock, &m_invoke_cond)));
}
- void expect_snap_rollback(MockImageCtx &mock_image_ctx,
+ void expect_snap_rollback(MockReplayImageCtx &mock_image_ctx,
Context **on_finish, const char *snap_name) {
EXPECT_CALL(*mock_image_ctx.operations, snap_rollback(CStrEq(snap_name), _, _))
.WillOnce(DoAll(SaveArg<2>(on_finish),
mock_journal_replay.process(it, on_ready, on_safe);
}
- void when_complete(MockImageCtx &mock_image_ctx, AioCompletion *aio_comp,
+ void when_complete(MockReplayImageCtx &mock_image_ctx, AioCompletion *aio_comp,
int r) {
aio_comp->get();
aio_comp->set_request_count(mock_image_ctx.cct, 1);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
MockAioImageRequest mock_aio_image_request;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
MockAioImageRequest mock_aio_image_request;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
MockAioImageRequest mock_aio_image_request;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
MockAioImageRequest mock_aio_image_request;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
MockAioImageRequest mock_aio_image_request;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
MockAioImageRequest mock_aio_image_request;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
MockAioImageRequest mock_aio_image_request;
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockReplayImageCtx mock_image_ctx(*ictx);
MockJournalReplay mock_journal_replay(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
namespace librbd {
namespace object_map {
-template <>
-struct InvalidateRequest<MockImageCtx> {
- static std::list<InvalidateRequest *> s_requests;
+template <typename I>
+struct MockInvalidateRequestBase {
+ static std::list<InvalidateRequest<I>*> s_requests;
uint64_t snap_id;
bool force;
Context *on_finish;
- static InvalidateRequest* create(MockImageCtx &image_ctx, uint64_t snap_id,
- bool force, Context *on_finish) {
+ static InvalidateRequest<I>* create(I &image_ctx, uint64_t snap_id,
+ bool force, Context *on_finish) {
assert(!s_requests.empty());
- InvalidateRequest* req = s_requests.front();
+ InvalidateRequest<I>* req = s_requests.front();
req->snap_id = snap_id;
req->force = force;
req->on_finish = on_finish;
return req;
}
- InvalidateRequest() {
- s_requests.push_back(this);
+ MockInvalidateRequestBase() {
+ s_requests.push_back(static_cast<InvalidateRequest<I>*>(this));
}
MOCK_METHOD0(send, void());
};
-typedef InvalidateRequest<MockImageCtx> MockInvalidateRequest;
-
-std::list<InvalidateRequest<MockImageCtx>*> InvalidateRequest<MockImageCtx>::s_requests;
+template <typename I>
+std::list<InvalidateRequest<I>*> MockInvalidateRequestBase<I>::s_requests;
} // namespace object_map
} // namespace librbd
#include "librbd/object_map/LockRequest.h"
namespace librbd {
+
+namespace {
+
+struct MockObjectMapImageCtx : public MockImageCtx {
+ MockObjectMapImageCtx(ImageCtx &image_ctx) : MockImageCtx(image_ctx) {
+ }
+};
+
+} // anonymous namespace
+
namespace object_map {
template <>
-class LockRequest<MockImageCtx> {
+class LockRequest<MockObjectMapImageCtx> {
public:
static LockRequest *s_instance;
- static LockRequest *create(MockImageCtx &image_ctx, Context *on_finish) {
+ static LockRequest *create(MockObjectMapImageCtx &image_ctx, Context *on_finish) {
assert(s_instance != nullptr);
s_instance->on_finish = on_finish;
return s_instance;
MOCK_METHOD0(send, void());
};
-LockRequest<MockImageCtx> *LockRequest<MockImageCtx>::s_instance = nullptr;
+template<>
+struct InvalidateRequest<MockObjectMapImageCtx> :
+ public MockInvalidateRequestBase<MockObjectMapImageCtx> {
+};
+
+LockRequest<MockObjectMapImageCtx> *LockRequest<MockObjectMapImageCtx>::s_instance = nullptr;
} // namespace object_map
} // namespace librbd
public:
static const uint64_t TEST_SNAP_ID = 123;
- typedef RefreshRequest<MockImageCtx> MockRefreshRequest;
- typedef LockRequest<MockImageCtx> MockLockRequest;
+ typedef RefreshRequest<MockObjectMapImageCtx> MockRefreshRequest;
+ typedef LockRequest<MockObjectMapImageCtx> MockLockRequest;
+ typedef InvalidateRequest<MockObjectMapImageCtx> MockInvalidateRequest;
- void expect_object_map_lock(MockImageCtx &mock_image_ctx,
+ void expect_object_map_lock(MockObjectMapImageCtx &mock_image_ctx,
MockLockRequest &mock_lock_request) {
EXPECT_CALL(mock_lock_request, send())
.WillOnce(FinishRequest(&mock_lock_request, 0,
&mock_image_ctx));
}
- void expect_object_map_load(MockImageCtx &mock_image_ctx,
+ void expect_object_map_load(MockObjectMapImageCtx &mock_image_ctx,
ceph::BitVector<2> *object_map, uint64_t snap_id,
int r) {
std::string oid(ObjectMap::object_map_name(mock_image_ctx.id, snap_id));
}
}
- void expect_get_image_size(MockImageCtx &mock_image_ctx, uint64_t snap_id,
+ void expect_get_image_size(MockObjectMapImageCtx &mock_image_ctx, uint64_t snap_id,
uint64_t size) {
EXPECT_CALL(mock_image_ctx, get_image_size(snap_id))
.WillOnce(Return(size));
}
- void expect_invalidate_request(MockImageCtx &mock_image_ctx,
+ void expect_invalidate_request(MockObjectMapImageCtx &mock_image_ctx,
MockInvalidateRequest &invalidate_request) {
EXPECT_CALL(invalidate_request, send())
.WillOnce(FinishRequest(&invalidate_request, 0,
&mock_image_ctx));
}
- void expect_truncate_request(MockImageCtx &mock_image_ctx) {
+ void expect_truncate_request(MockObjectMapImageCtx &mock_image_ctx) {
std::string oid(ObjectMap::object_map_name(mock_image_ctx.id, TEST_SNAP_ID));
EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), truncate(oid, 0, _))
.WillOnce(Return(0));
}
- void expect_object_map_resize(MockImageCtx &mock_image_ctx,
+ void expect_object_map_resize(MockObjectMapImageCtx &mock_image_ctx,
uint64_t num_objects, int r) {
std::string oid(ObjectMap::object_map_name(mock_image_ctx.id, TEST_SNAP_ID));
auto &expect = EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
expect.WillOnce(Return(r));
}
- void init_object_map(MockImageCtx &mock_image_ctx,
+ void init_object_map(MockObjectMapImageCtx &mock_image_ctx,
ceph::BitVector<2> *object_map) {
uint64_t num_objs = Striper::get_num_objects(
mock_image_ctx.layout, mock_image_ctx.image_ctx->size);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockObjectMapImageCtx mock_image_ctx(*ictx);
ceph::BitVector<2> on_disk_object_map;
init_object_map(mock_image_ctx, &on_disk_object_map);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockObjectMapImageCtx mock_image_ctx(*ictx);
ceph::BitVector<2> on_disk_object_map;
init_object_map(mock_image_ctx, &on_disk_object_map);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockObjectMapImageCtx mock_image_ctx(*ictx);
ceph::BitVector<2> on_disk_object_map;
init_object_map(mock_image_ctx, &on_disk_object_map);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockObjectMapImageCtx mock_image_ctx(*ictx);
ceph::BitVector<2> on_disk_object_map;
init_object_map(mock_image_ctx, &on_disk_object_map);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockObjectMapImageCtx mock_image_ctx(*ictx);
ceph::BitVector<2> on_disk_object_map;
init_object_map(mock_image_ctx, &on_disk_object_map);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockObjectMapImageCtx mock_image_ctx(*ictx);
ceph::BitVector<2> on_disk_object_map;
init_object_map(mock_image_ctx, &on_disk_object_map);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockObjectMapImageCtx mock_image_ctx(*ictx);
ceph::BitVector<2> on_disk_object_map;
init_object_map(mock_image_ctx, &on_disk_object_map);
#include "gtest/gtest.h"
namespace librbd {
+
+namespace {
+
+struct MockOperationImageCtx : public MockImageCtx {
+ MockOperationImageCtx(ImageCtx &image_ctx) : MockImageCtx(image_ctx) {
+ }
+};
+
+} // anonymous namespace
+
namespace operation {
template <>
-struct ResizeRequest<MockImageCtx> {
+struct ResizeRequest<MockOperationImageCtx> {
static ResizeRequest *s_instance;
Context *on_finish = nullptr;
- static ResizeRequest* create(MockImageCtx &image_ctx, Context *on_finish,
+ static ResizeRequest* create(MockOperationImageCtx &image_ctx, Context *on_finish,
uint64_t new_size, ProgressContext &prog_ctx,
uint64_t journal_op_tid, bool disable_journal) {
assert(s_instance != nullptr);
MOCK_METHOD0(send, void());
};
-ResizeRequest<MockImageCtx> *ResizeRequest<MockImageCtx>::s_instance = nullptr;
+ResizeRequest<MockOperationImageCtx> *ResizeRequest<MockOperationImageCtx>::s_instance = nullptr;
} // namespace operation
+
+template <>
+struct AsyncRequest<MockOperationImageCtx> : public AsyncRequest<MockImageCtx> {
+ MockOperationImageCtx &m_image_ctx;
+
+ AsyncRequest(MockOperationImageCtx &image_ctx, Context *on_finish)
+ : AsyncRequest<MockImageCtx>(image_ctx, on_finish), m_image_ctx(image_ctx) {
+ }
+};
+
} // namespace librbd
// template definitions
+#include "librbd/AsyncRequest.cc"
+#include "librbd/AsyncObjectThrottle.cc"
+#include "librbd/operation/Request.cc"
#include "librbd/operation/SnapshotRollbackRequest.cc"
+template class librbd::AsyncRequest<librbd::MockImageCtx>;
+template class librbd::AsyncObjectThrottle<librbd::MockImageCtx>;
+template class librbd::operation::Request<librbd::MockImageCtx>;
+
namespace librbd {
namespace operation {
class TestMockOperationSnapshotRollbackRequest : public TestMockFixture {
public:
- typedef SnapshotRollbackRequest<MockImageCtx> MockSnapshotRollbackRequest;
- typedef ResizeRequest<MockImageCtx> MockResizeRequest;
+ typedef SnapshotRollbackRequest<MockOperationImageCtx> MockSnapshotRollbackRequest;
+ typedef ResizeRequest<MockOperationImageCtx> MockResizeRequest;
- void expect_block_writes(MockImageCtx &mock_image_ctx, int r) {
+ void expect_block_writes(MockOperationImageCtx &mock_image_ctx, int r) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, block_writes(_))
.WillOnce(CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue));
}
- void expect_unblock_writes(MockImageCtx &mock_image_ctx) {
+ void expect_unblock_writes(MockOperationImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, unblock_writes())
.Times(1);
}
- void expect_get_image_size(MockImageCtx &mock_image_ctx,
+ void expect_get_image_size(MockOperationImageCtx &mock_image_ctx,
uint64_t size) {
EXPECT_CALL(mock_image_ctx, get_image_size(CEPH_NOSNAP))
.WillOnce(Return(size));
}
- void expect_resize(MockImageCtx &mock_image_ctx,
+ void expect_resize(MockOperationImageCtx &mock_image_ctx,
MockResizeRequest &mock_resize_request, int r) {
expect_get_image_size(mock_image_ctx, 123);
EXPECT_CALL(mock_resize_request, send())
&mock_image_ctx));
}
- void expect_rollback_object_map(MockImageCtx &mock_image_ctx,
+ void expect_rollback_object_map(MockOperationImageCtx &mock_image_ctx,
MockObjectMap &mock_object_map) {
if (mock_image_ctx.object_map != nullptr) {
EXPECT_CALL(mock_object_map, rollback(_, _))
}
}
- void expect_get_object_name(MockImageCtx &mock_image_ctx,
+ void expect_get_object_name(MockOperationImageCtx &mock_image_ctx,
uint64_t object_num) {
EXPECT_CALL(mock_image_ctx, get_object_name(object_num))
.WillOnce(Return("object-name-" + stringify(object_num)));
}
- void expect_get_current_size(MockImageCtx &mock_image_ctx, uint64_t size) {
+ void expect_get_current_size(MockOperationImageCtx &mock_image_ctx, uint64_t size) {
EXPECT_CALL(mock_image_ctx, get_current_size())
.WillOnce(Return(size));
}
- void expect_rollback_snap_id(MockImageCtx &mock_image_ctx,
+ void expect_rollback_snap_id(MockOperationImageCtx &mock_image_ctx,
const std::string &oid, int r) {
EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.data_ctx),
selfmanaged_snap_rollback(oid, _))
.WillOnce(Return(r));
}
- void expect_rollback(MockImageCtx &mock_image_ctx, int r) {
+ void expect_rollback(MockOperationImageCtx &mock_image_ctx, int r) {
expect_get_current_size(mock_image_ctx, 1);
expect_get_object_name(mock_image_ctx, 0);
expect_rollback_snap_id(mock_image_ctx, "object-name-0", r);
}
- void expect_create_object_map(MockImageCtx &mock_image_ctx,
+ void expect_create_object_map(MockOperationImageCtx &mock_image_ctx,
MockObjectMap *mock_object_map) {
EXPECT_CALL(mock_image_ctx, create_object_map(_))
.WillOnce(Return(mock_object_map));
}
- void expect_open_object_map(MockImageCtx &mock_image_ctx,
+ void expect_open_object_map(MockOperationImageCtx &mock_image_ctx,
MockObjectMap &mock_object_map) {
EXPECT_CALL(mock_object_map, open(_))
.WillOnce(CompleteContext(0, mock_image_ctx.image_ctx->op_work_queue));
}
- void expect_refresh_object_map(MockImageCtx &mock_image_ctx,
+ void expect_refresh_object_map(MockOperationImageCtx &mock_image_ctx,
MockObjectMap &mock_object_map) {
if (mock_image_ctx.object_map != nullptr) {
expect_create_object_map(mock_image_ctx, &mock_object_map);
}
}
- void expect_invalidate_cache(MockImageCtx &mock_image_ctx, int r) {
+ void expect_invalidate_cache(MockOperationImageCtx &mock_image_ctx, int r) {
if (mock_image_ctx.object_cacher != nullptr) {
EXPECT_CALL(mock_image_ctx, invalidate_cache(_))
.WillOnce(CompleteContext(r, NULL));
}
}
- int when_snap_rollback(MockImageCtx &mock_image_ctx,
+ int when_snap_rollback(MockOperationImageCtx &mock_image_ctx,
const std::string &snap_name,
uint64_t snap_id, uint64_t snap_size) {
C_SaferCond cond_ctx;
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockOperationImageCtx mock_image_ctx(*ictx);
MockExclusiveLock mock_exclusive_lock;
MockJournal mock_journal;
MockObjectMap *mock_object_map = new MockObjectMap();
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockOperationImageCtx mock_image_ctx(*ictx);
MockExclusiveLock mock_exclusive_lock;
MockJournal mock_journal;
MockObjectMap mock_object_map;
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockOperationImageCtx mock_image_ctx(*ictx);
MockExclusiveLock mock_exclusive_lock;
MockJournal mock_journal;
MockObjectMap *mock_object_map = new MockObjectMap();
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockOperationImageCtx mock_image_ctx(*ictx);
MockExclusiveLock mock_exclusive_lock;
MockJournal mock_journal;
MockObjectMap mock_object_map;
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockOperationImageCtx mock_image_ctx(*ictx);
MockExclusiveLock mock_exclusive_lock;
MockJournal mock_journal;
MockObjectMap mock_object_map;
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockOperationImageCtx mock_image_ctx(*ictx);
MockExclusiveLock mock_exclusive_lock;
MockJournal mock_journal;
MockObjectMap *mock_object_map = new MockObjectMap();
#include <list>
namespace librbd {
+
+namespace {
+
+struct MockExclusiveLockImageCtx : public MockImageCtx {
+ MockExclusiveLockImageCtx(ImageCtx &image_ctx) : MockImageCtx(image_ctx) {
+ }
+};
+
+} // anonymous namespace
+
namespace exclusive_lock {
template<typename T>
Context *on_lock_unlock = nullptr;
Context *on_finish = nullptr;
- static T* create(MockImageCtx &image_ctx, const std::string &cookie,
+ static T* create(MockExclusiveLockImageCtx &image_ctx, const std::string &cookie,
Context *on_lock_unlock, Context *on_finish) {
assert(!s_requests.empty());
T* req = s_requests.front();
std::list<T *> BaseRequest<T>::s_requests;
template <>
-struct AcquireRequest<MockImageCtx> : public BaseRequest<AcquireRequest<MockImageCtx> > {
+struct AcquireRequest<MockExclusiveLockImageCtx> : public BaseRequest<AcquireRequest<MockExclusiveLockImageCtx> > {
MOCK_METHOD0(send, void());
};
template <>
-struct ReleaseRequest<MockImageCtx> : public BaseRequest<ReleaseRequest<MockImageCtx> > {
+struct ReleaseRequest<MockExclusiveLockImageCtx> : public BaseRequest<ReleaseRequest<MockExclusiveLockImageCtx> > {
MOCK_METHOD0(send, void());
};
// template definitions
#include "librbd/ExclusiveLock.cc"
-template class librbd::ExclusiveLock<librbd::MockImageCtx>;
+template class librbd::ExclusiveLock<librbd::MockExclusiveLockImageCtx>;
ACTION_P(FinishLockUnlock, request) {
if (request->on_lock_unlock != nullptr) {
class TestMockExclusiveLock : public TestMockFixture {
public:
- typedef ExclusiveLock<MockImageCtx> MockExclusiveLock;
- typedef exclusive_lock::AcquireRequest<MockImageCtx> MockAcquireRequest;
- typedef exclusive_lock::ReleaseRequest<MockImageCtx> MockReleaseRequest;
+ typedef ExclusiveLock<MockExclusiveLockImageCtx> MockExclusiveLock;
+ typedef exclusive_lock::AcquireRequest<MockExclusiveLockImageCtx> MockAcquireRequest;
+ typedef exclusive_lock::ReleaseRequest<MockExclusiveLockImageCtx> MockReleaseRequest;
- void expect_get_watch_handle(MockImageCtx &mock_image_ctx) {
+ void expect_get_watch_handle(MockExclusiveLockImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.image_watcher, get_watch_handle())
.WillRepeatedly(Return(1234567890));
}
- void expect_set_require_lock_on_read(MockImageCtx &mock_image_ctx) {
+ void expect_set_require_lock_on_read(MockExclusiveLockImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, set_require_lock_on_read());
}
- void expect_clear_require_lock_on_read(MockImageCtx &mock_image_ctx) {
+ void expect_clear_require_lock_on_read(MockExclusiveLockImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, clear_require_lock_on_read());
}
- void expect_block_writes(MockImageCtx &mock_image_ctx) {
+ void expect_block_writes(MockExclusiveLockImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, block_writes(_))
.WillOnce(CompleteContext(0, mock_image_ctx.image_ctx->op_work_queue));
if ((mock_image_ctx.features & RBD_FEATURE_JOURNALING) != 0) {
}
}
- void expect_unblock_writes(MockImageCtx &mock_image_ctx) {
+ void expect_unblock_writes(MockExclusiveLockImageCtx &mock_image_ctx) {
expect_clear_require_lock_on_read(mock_image_ctx);
EXPECT_CALL(*mock_image_ctx.aio_work_queue, unblock_writes());
}
- void expect_acquire_lock(MockImageCtx &mock_image_ctx,
+ void expect_acquire_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockAcquireRequest &acquire_request, int r) {
expect_get_watch_handle(mock_image_ctx);
EXPECT_CALL(acquire_request, send())
}
}
- void expect_release_lock(MockImageCtx &mock_image_ctx,
+ void expect_release_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockReleaseRequest &release_request, int r,
bool shutting_down = false) {
EXPECT_CALL(release_request, send())
}
}
- void expect_notify_request_lock(MockImageCtx &mock_image_ctx,
+ void expect_notify_request_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &mock_exclusive_lock) {
EXPECT_CALL(*mock_image_ctx.image_watcher, notify_request_lock())
.WillRepeatedly(Invoke(&mock_exclusive_lock,
&MockExclusiveLock::handle_lock_released));
}
- void expect_notify_acquired_lock(MockImageCtx &mock_image_ctx) {
+ void expect_notify_acquired_lock(MockExclusiveLockImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.image_watcher, notify_acquired_lock())
.Times(1);
}
- void expect_notify_released_lock(MockImageCtx &mock_image_ctx) {
+ void expect_notify_released_lock(MockExclusiveLockImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.image_watcher, notify_released_lock())
.Times(1);
}
- void expect_is_lock_request_needed(MockImageCtx &mock_image_ctx, bool ret) {
+ void expect_is_lock_request_needed(MockExclusiveLockImageCtx &mock_image_ctx, bool ret) {
EXPECT_CALL(*mock_image_ctx.aio_work_queue, is_lock_request_needed())
.WillRepeatedly(Return(ret));
}
- void expect_flush_notifies(MockImageCtx &mock_image_ctx) {
+ void expect_flush_notifies(MockExclusiveLockImageCtx &mock_image_ctx) {
EXPECT_CALL(*mock_image_ctx.image_watcher, flush(_))
.WillOnce(CompleteContext(0, mock_image_ctx.image_ctx->op_work_queue));
}
- int when_init(MockImageCtx &mock_image_ctx,
+ int when_init(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &exclusive_lock) {
C_SaferCond ctx;
{
return ctx.wait();
}
- int when_try_lock(MockImageCtx &mock_image_ctx,
+ int when_try_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &exclusive_lock) {
C_SaferCond ctx;
{
}
return ctx.wait();
}
- int when_request_lock(MockImageCtx &mock_image_ctx,
+ int when_request_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &exclusive_lock) {
C_SaferCond ctx;
{
}
return ctx.wait();
}
- int when_release_lock(MockImageCtx &mock_image_ctx,
+ int when_release_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &exclusive_lock) {
C_SaferCond ctx;
{
}
return ctx.wait();
}
- int when_shut_down(MockImageCtx &mock_image_ctx,
+ int when_shut_down(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &exclusive_lock) {
C_SaferCond ctx;
{
return ctx.wait();
}
- bool is_lock_owner(MockImageCtx &mock_image_ctx,
+ bool is_lock_owner(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &exclusive_lock) {
RWLock::RLocker owner_locker(mock_image_ctx.owner_lock);
return exclusive_lock.is_lock_owner();
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockExclusiveLockImageCtx mock_image_ctx(*ictx);
MockExclusiveLock exclusive_lock(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
} // namespace journal
namespace librbd {
+
+namespace {
+
+struct MockJournalImageCtx : public MockImageCtx {
+ MockJournalImageCtx(librbd::ImageCtx& image_ctx) : MockImageCtx(image_ctx) {
+ }
+};
+
+} // anonymous namespace
+
namespace journal {
template <>
-struct TypeTraits<MockImageCtx> {
+struct TypeTraits<MockJournalImageCtx> {
typedef ::journal::MockJournalerProxy Journaler;
typedef ::journal::MockFutureProxy Future;
typedef ::journal::MockReplayEntryProxy ReplayEntry;
};
template <>
-class Replay<MockImageCtx> {
+class Replay<MockJournalImageCtx> {
public:
- static Replay *create(MockImageCtx &image_ctx) {
+ static Replay *create(MockJournalImageCtx &image_ctx) {
return new Replay();
}
// template definitions
#include "librbd/Journal.cc"
-template class librbd::Journal<librbd::MockImageCtx>;
+template class librbd::Journal<librbd::MockJournalImageCtx>;
using ::testing::_;
using ::testing::DoAll;
class TestMockJournal : public TestMockFixture {
public:
typedef journal::MockReplay MockJournalReplay;
- typedef Journal<MockImageCtx> MockJournal;
+ typedef Journal<MockJournalImageCtx> MockJournal;
typedef std::function<void(::journal::ReplayHandler*)> ReplayAction;
typedef std::list<ReplayAction> ReplayActions;
}
- void expect_start_replay(MockImageCtx &mock_image_ctx,
+ void expect_start_replay(MockJournalImageCtx &mock_image_ctx,
::journal::MockJournaler &mock_journaler,
const ReplayActions &actions) {
EXPECT_CALL(mock_journaler, start_replay(_))
EXPECT_CALL(mock_journaler, stop_replay());
}
- void expect_shut_down_replay(MockImageCtx &mock_image_ctx,
+ void expect_shut_down_replay(MockJournalImageCtx &mock_image_ctx,
MockJournalReplay &mock_journal_replay, int r,
bool cancel_ops = false) {
EXPECT_CALL(mock_journal_replay, shut_down(cancel_ops, _))
return ctx.wait();
}
- uint64_t when_append_io_event(MockImageCtx &mock_image_ctx,
+ uint64_t when_append_io_event(MockJournalImageCtx &mock_image_ctx,
MockJournal &mock_journal,
AioCompletion *aio_comp = nullptr) {
RWLock::RLocker owner_locker(mock_image_ctx.owner_lock);
m_cond.Signal();
}
- void commit_replay(MockImageCtx &mock_image_ctx, Context *on_flush, int r) {
+ void commit_replay(MockJournalImageCtx &mock_image_ctx, Context *on_flush,
+ int r) {
Contexts commit_contexts;
std::swap(commit_contexts, m_commit_contexts);
mock_image_ctx.image_ctx->op_work_queue->queue(on_flush, 0);
}
- void open_journal(MockImageCtx &mock_image_ctx, MockJournal &mock_journal,
+ void open_journal(MockJournalImageCtx &mock_image_ctx,
+ MockJournal &mock_journal,
::journal::MockJournaler &mock_journaler) {
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
expect_op_work_queue(mock_image_ctx);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
::journal::MockJournaler mock_journaler;
open_journal(mock_image_ctx, mock_journal, mock_journaler);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
::journal::MockJournaler mock_journaler;
open_journal(mock_image_ctx, mock_journal, mock_journaler);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
::journal::MockJournaler mock_journaler;
open_journal(mock_image_ctx, mock_journal, mock_journaler);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
::journal::MockJournaler mock_journaler;
open_journal(mock_image_ctx, mock_journal, mock_journaler);
librbd::ImageCtx *ictx;
ASSERT_EQ(0, open_image(m_image_name, &ictx));
- MockImageCtx mock_image_ctx(*ictx);
+ MockJournalImageCtx mock_image_ctx(*ictx);
MockJournal mock_journal(mock_image_ctx);
::journal::MockJournaler mock_journaler;
open_journal(mock_image_ctx, mock_journal, mock_journaler);
// template definitions
#include "librbd/AsyncRequest.cc"
#include "librbd/AsyncObjectThrottle.cc"
+#include "librbd/ExclusiveLock.cc"
#include "librbd/operation/Request.cc"
template class librbd::AsyncRequest<librbd::MockImageCtx>;
template class librbd::AsyncObjectThrottle<librbd::MockImageCtx>;
+template class librbd::ExclusiveLock<librbd::MockImageCtx>;
template class librbd::operation::Request<librbd::MockImageCtx>;
using ::testing::_;