From 4c159d30fda031b725a54570d5c10d1fb57c4ef8 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Sun, 6 Mar 2016 13:01:09 -0500 Subject: [PATCH] librados_test_stub: support for truncating/removing with old snap contexts Signed-off-by: Jason Dillaman --- src/test/librados_test_stub/LibradosTestStub.cc | 12 +++++++++--- src/test/librados_test_stub/MockTestMemIoCtxImpl.h | 14 ++++++++++---- src/test/librados_test_stub/TestIoCtxImpl.h | 2 +- src/test/librados_test_stub/TestMemIoCtxImpl.cc | 10 +++++----- src/test/librados_test_stub/TestMemIoCtxImpl.h | 2 +- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index 2c95c245ff68a..8df054775d0d0 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -538,8 +538,7 @@ int IoCtx::read(const std::string& oid, bufferlist& bl, size_t len, int IoCtx::remove(const std::string& oid) { TestIoCtxImpl *ctx = reinterpret_cast(io_ctx_impl); return ctx->execute_operation( - oid, boost::bind(&TestIoCtxImpl::remove, _1, _2)); - return ctx->remove(oid); + oid, boost::bind(&TestIoCtxImpl::remove, _1, _2, ctx->get_snap_context())); } int IoCtx::selfmanaged_snap_create(uint64_t *snapid) { @@ -581,6 +580,13 @@ int IoCtx::tmap_update(const std::string& oid, bufferlist& cmdbl) { oid, boost::bind(&TestIoCtxImpl::tmap_update, _1, _2, cmdbl)); } +int IoCtx::trunc(const std::string& oid, uint64_t off) { + TestIoCtxImpl *ctx = reinterpret_cast(io_ctx_impl); + return ctx->execute_operation( + oid, boost::bind(&TestIoCtxImpl::truncate, _1, _2, off, + ctx->get_snap_context())); +} + int IoCtx::unwatch2(uint64_t handle) { TestIoCtxImpl *ctx = reinterpret_cast(io_ctx_impl); return ctx->unwatch(handle); @@ -751,7 +757,7 @@ void ObjectWriteOperation::omap_set(const std::map &map void ObjectWriteOperation::remove() { TestObjectOperationImpl *o = reinterpret_cast(impl); - o->ops.push_back(boost::bind(&TestIoCtxImpl::remove, _1, _2)); + o->ops.push_back(boost::bind(&TestIoCtxImpl::remove, _1, _2, _4)); } void ObjectWriteOperation::selfmanaged_snap_rollback(uint64_t snapid) { diff --git a/src/test/librados_test_stub/MockTestMemIoCtxImpl.h b/src/test/librados_test_stub/MockTestMemIoCtxImpl.h index c9da11b1c04ba..40ccc8f23a21c 100644 --- a/src/test/librados_test_stub/MockTestMemIoCtxImpl.h +++ b/src/test/librados_test_stub/MockTestMemIoCtxImpl.h @@ -48,6 +48,11 @@ public: snapc); } + MOCK_METHOD2(list_snaps, int(const std::string& o, snap_set_t *out_snaps)); + int do_list_snaps(const std::string& o, snap_set_t *out_snaps) { + return TestMemIoCtxImpl::list_snaps(o, out_snaps); + } + MOCK_METHOD2(list_watchers, int(const std::string& o, std::list *out_watchers)); int do_list_watchers(const std::string& o, @@ -64,9 +69,9 @@ public: return TestMemIoCtxImpl::read(oid, len, off, bl); } - MOCK_METHOD1(remove, int(const std::string& oid)); - int do_remove(const std::string& oid) { - return TestMemIoCtxImpl::remove(oid); + MOCK_METHOD2(remove, int(const std::string& oid, const SnapContext &snapc)); + int do_remove(const std::string& oid, const SnapContext &snapc) { + return TestMemIoCtxImpl::remove(oid, snapc); } MOCK_METHOD1(selfmanaged_snap_create, int(uint64_t *snap_id)); @@ -112,9 +117,10 @@ public: using namespace ::testing; ON_CALL(*this, exec(_, _, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec)); + ON_CALL(*this, list_snaps(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_snaps)); ON_CALL(*this, list_watchers(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_watchers)); ON_CALL(*this, read(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read)); - ON_CALL(*this, remove(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove)); + ON_CALL(*this, remove(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove)); ON_CALL(*this, selfmanaged_snap_create(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_create)); ON_CALL(*this, selfmanaged_snap_remove(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_remove)); ON_CALL(*this, selfmanaged_snap_rollback(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_rollback)); diff --git a/src/test/librados_test_stub/TestIoCtxImpl.h b/src/test/librados_test_stub/TestIoCtxImpl.h index 0db715f34b382..b6d845da375c4 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.h +++ b/src/test/librados_test_stub/TestIoCtxImpl.h @@ -114,7 +114,7 @@ public: bufferlist *pbl); virtual int read(const std::string& oid, size_t len, uint64_t off, bufferlist *bl) = 0; - virtual int remove(const std::string& oid) = 0; + virtual int remove(const std::string& oid, const SnapContext &snapc) = 0; virtual int selfmanaged_snap_create(uint64_t *snapid) = 0; virtual int selfmanaged_snap_remove(uint64_t snapid) = 0; virtual int selfmanaged_snap_rollback(const std::string& oid, diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.cc b/src/test/librados_test_stub/TestMemIoCtxImpl.cc index 9b95c502f15c3..6c522e8e2aa5c 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.cc @@ -46,7 +46,8 @@ TestIoCtxImpl *TestMemIoCtxImpl::clone() { int TestMemIoCtxImpl::aio_remove(const std::string& oid, AioCompletionImpl *c) { m_client->add_aio_operation(oid, true, - boost::bind(&TestMemIoCtxImpl::remove, this, oid), + boost::bind(&TestMemIoCtxImpl::remove, this, oid, + get_snap_context()), c); return 0; } @@ -270,18 +271,17 @@ int TestMemIoCtxImpl::read(const std::string& oid, size_t len, uint64_t off, return len; } -int TestMemIoCtxImpl::remove(const std::string& oid) { +int TestMemIoCtxImpl::remove(const std::string& oid, const SnapContext &snapc) { if (get_snap_read() != CEPH_NOSNAP) { return -EROFS; } RWLock::WLocker l(m_pool->file_lock); - TestMemRadosClient::SharedFile file = get_file(oid, false, - get_snap_context()); + TestMemRadosClient::SharedFile file = get_file(oid, false, snapc); if (file == NULL) { return -ENOENT; } - file = get_file(oid, true, get_snap_context()); + file = get_file(oid, true, snapc); RWLock::WLocker l2(file->lock); file->exists = false; diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.h b/src/test/librados_test_stub/TestMemIoCtxImpl.h index 6556c9c723ef8..ab04772013e63 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.h +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.h @@ -38,7 +38,7 @@ public: bufferlist> &map); virtual int read(const std::string& oid, size_t len, uint64_t off, bufferlist *bl); - virtual int remove(const std::string& oid); + virtual int remove(const std::string& oid, const SnapContext &snapc); virtual int selfmanaged_snap_create(uint64_t *snapid); virtual int selfmanaged_snap_remove(uint64_t snapid); virtual int selfmanaged_snap_rollback(const std::string& oid, -- 2.39.5