From f6cc953900ecad5754d12d43bdc18266a06794a7 Mon Sep 17 00:00:00 2001 From: Gui Hecheng Date: Wed, 4 Jan 2017 15:49:47 +0800 Subject: [PATCH] test/librbd: handle writesame op in librados_test_stub, required Based on pr: https://github.com/ceph/ceph/pull/10019. Signed-off-by: Gui Hecheng Signed-off-by: Mingxin Liu --- .../librados_test_stub/LibradosTestStub.cc | 14 ++++++++ src/test/librados_test_stub/TestIoCtxImpl.h | 2 ++ .../librados_test_stub/TestMemIoCtxImpl.cc | 33 +++++++++++++++++++ .../librados_test_stub/TestMemIoCtxImpl.h | 2 ++ 4 files changed, 51 insertions(+) diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index 5b59ef17df2a7..16c0f4da3682f 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -668,6 +668,14 @@ int IoCtx::write_full(const std::string& oid, bufferlist& bl) { ctx->get_snap_context())); } +int IoCtx::writesame(const std::string& oid, bufferlist& bl, size_t len, + uint64_t off) { + TestIoCtxImpl *ctx = reinterpret_cast(io_ctx_impl); + return ctx->execute_operation( + oid, boost::bind(&TestIoCtxImpl::writesame, _1, _2, bl, len, off, + ctx->get_snap_context())); +} + static int save_operation_result(int result, int *pval) { if (pval != NULL) { *pval = result; @@ -840,6 +848,12 @@ void ObjectWriteOperation::write_full(const bufferlist& bl) { o->ops.push_back(boost::bind(&TestIoCtxImpl::write_full, _1, _2, bl, _4)); } +void ObjectWriteOperation::writesame(uint64_t off, uint64_t len, const bufferlist& bl) { + TestObjectOperationImpl *o = reinterpret_cast(impl); + o->ops.push_back(boost::bind(&TestIoCtxImpl::writesame, _1, _2, bl, len, + off, _4)); +} + void ObjectWriteOperation::zero(uint64_t off, uint64_t len) { TestObjectOperationImpl *o = reinterpret_cast(impl); o->ops.push_back(boost::bind(&TestIoCtxImpl::zero, _1, _2, off, len)); diff --git a/src/test/librados_test_stub/TestIoCtxImpl.h b/src/test/librados_test_stub/TestIoCtxImpl.h index a121ded3f67d7..30f1206169183 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.h +++ b/src/test/librados_test_stub/TestIoCtxImpl.h @@ -143,6 +143,8 @@ public: uint64_t off, const SnapContext &snapc) = 0; virtual int write_full(const std::string& oid, bufferlist& bl, const SnapContext &snapc) = 0; + virtual int writesame(const std::string& oid, bufferlist& bl, size_t len, + uint64_t off, const SnapContext &snapc) = 0; virtual int xattr_get(const std::string& oid, std::map* attrset) = 0; virtual int xattr_set(const std::string& oid, const std::string &name, diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.cc b/src/test/librados_test_stub/TestMemIoCtxImpl.cc index 239b0779dabc4..3df216adabbd7 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.cc @@ -499,6 +499,39 @@ int TestMemIoCtxImpl::write_full(const std::string& oid, bufferlist& bl, return 0; } +int TestMemIoCtxImpl::writesame(const std::string& oid, bufferlist& bl, size_t len, + uint64_t off, const SnapContext &snapc) { + if (get_snap_read() != CEPH_NOSNAP) { + return -EROFS; + } + + if (len == 0 || (len % bl.length())) { + return -EINVAL; + } + + TestMemRadosClient::SharedFile file; + { + RWLock::WLocker l(m_pool->file_lock); + file = get_file(oid, true, snapc); + } + + RWLock::WLocker l(file->lock); + if (len > 0) { + interval_set is; + is.insert(off, len); + is.intersection_of(file->snap_overlap); + file->snap_overlap.subtract(is); + } + + ensure_minimum_length(off + len, &file->data); + while (len > 0) { + file->data.copy_in(off, bl.length(), bl); + off += bl.length(); + len -= bl.length(); + } + return 0; +} + int TestMemIoCtxImpl::xattr_get(const std::string& oid, std::map* attrset) { TestMemRadosClient::SharedFile file; diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.h b/src/test/librados_test_stub/TestMemIoCtxImpl.h index ab04772013e63..97e9e89525ee5 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.h +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.h @@ -52,6 +52,8 @@ public: uint64_t off, const SnapContext &snapc); virtual int write_full(const std::string& oid, bufferlist& bl, const SnapContext &snapc); + virtual int writesame(const std::string& oid, bufferlist& bl, size_t len, + uint64_t off, const SnapContext &snapc); virtual int xattr_get(const std::string& oid, std::map* attrset); virtual int xattr_set(const std::string& oid, const std::string &name, -- 2.39.5