From: Or Ozeri Date: Thu, 24 Dec 2020 09:22:08 +0000 (+0200) Subject: librados_test_stub: add support for reading object version X-Git-Tag: v16.1.0~87^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=221b4afa891a28db4fee535f7d8faac0abd74e0f;p=ceph.git librados_test_stub: add support for reading object version This commit implements a missing handling of librados_test_stub of objver reading Signed-off-by: Or Ozeri --- diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index e91659f3c3f..c16cc436aa4 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -431,7 +431,7 @@ int IoCtx::aio_operate(const std::string& oid, AioCompletion *c, TestIoCtxImpl *ctx = reinterpret_cast(io_ctx_impl); TestObjectOperationImpl *ops = reinterpret_cast(op->impl); return ctx->aio_operate_read(oid, *ops, c->pc, flags, pbl, - ctx->get_snap_read()); + ctx->get_snap_read(), nullptr); } int IoCtx::aio_operate(const std::string& oid, AioCompletion *c, @@ -619,7 +619,7 @@ int IoCtx::read(const std::string& oid, bufferlist& bl, size_t len, TestIoCtxImpl *ctx = reinterpret_cast(io_ctx_impl); return ctx->execute_operation( oid, std::bind(&TestIoCtxImpl::read, _1, _2, len, off, &bl, - ctx->get_snap_read())); + ctx->get_snap_read(), nullptr)); } int IoCtx::remove(const std::string& oid) { @@ -843,7 +843,7 @@ void ObjectOperation::cmpext(uint64_t off, const bufferlist& cmp_bl, cmp_bl, _4); if (prval != NULL) { op = std::bind(save_operation_result, - std::bind(op, _1, _2, _3, _4, _5), prval); + std::bind(op, _1, _2, _3, _4, _5, _6), prval); } o->ops.push_back(op); } @@ -855,7 +855,7 @@ void ObjectReadOperation::list_snaps(snap_set_t *out_snaps, int *prval) { out_snaps); if (prval != NULL) { op = std::bind(save_operation_result, - std::bind(op, _1, _2, _3, _4, _5), prval); + std::bind(op, _1, _2, _3, _4, _5, _6), prval); } o->ops.push_back(op); } @@ -868,7 +868,7 @@ void ObjectReadOperation::list_watchers(std::list *out_watchers, _2, out_watchers); if (prval != NULL) { op = std::bind(save_operation_result, - std::bind(op, _1, _2, _3, _4, _5), prval); + std::bind(op, _1, _2, _3, _4, _5, _6), prval); } o->ops.push_back(op); } @@ -879,14 +879,14 @@ void ObjectReadOperation::read(size_t off, uint64_t len, bufferlist *pbl, ObjectOperationTestImpl op; if (pbl != NULL) { - op = std::bind(&TestIoCtxImpl::read, _1, _2, len, off, pbl, _4); + op = std::bind(&TestIoCtxImpl::read, _1, _2, len, off, pbl, _4, nullptr); } else { - op = std::bind(&TestIoCtxImpl::read, _1, _2, len, off, _3, _4); + op = std::bind(&TestIoCtxImpl::read, _1, _2, len, off, _3, _4, nullptr); } if (prval != NULL) { op = std::bind(save_operation_result, - std::bind(op, _1, _2, _3, _4, _5), prval); + std::bind(op, _1, _2, _3, _4, _5, _6), prval); } o->ops.push_back(op); } @@ -905,7 +905,7 @@ void ObjectReadOperation::sparse_read(uint64_t off, uint64_t len, if (prval != NULL) { op = std::bind(save_operation_result, - std::bind(op, _1, _2, _3, _4, _5), prval); + std::bind(op, _1, _2, _3, _4, _5, _6), prval); } o->ops.push_back(op); } @@ -918,7 +918,7 @@ void ObjectReadOperation::stat(uint64_t *psize, time_t *pmtime, int *prval) { if (prval != NULL) { op = std::bind(save_operation_result, - std::bind(op, _1, _2, _3, _4, _5), prval); + std::bind(op, _1, _2, _3, _4, _5, _6), prval); } o->ops.push_back(op); } @@ -1381,7 +1381,8 @@ int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len, bufferlist *outbl, uint32_t op_flags) { librados::TestClassHandler::MethodContext *ctx = reinterpret_cast(hctx); - return ctx->io_ctx_impl->read(ctx->oid, len, ofs, outbl, ctx->snap_id); + return ctx->io_ctx_impl->read( + ctx->oid, len, ofs, outbl, ctx->snap_id, nullptr); } int cls_cxx_setxattr(cls_method_context_t hctx, const char *name, diff --git a/src/test/librados_test_stub/MockTestMemIoCtxImpl.h b/src/test/librados_test_stub/MockTestMemIoCtxImpl.h index 4ea625eac08..7937e221ad7 100644 --- a/src/test/librados_test_stub/MockTestMemIoCtxImpl.h +++ b/src/test/librados_test_stub/MockTestMemIoCtxImpl.h @@ -140,13 +140,13 @@ public: return TestMemIoCtxImpl::sparse_read(oid, off, len, m, bl, snap_id); } - MOCK_METHOD5(read, int(const std::string& oid, + MOCK_METHOD6(read, int(const std::string& oid, size_t len, uint64_t off, - bufferlist *bl, uint64_t snap_id)); + bufferlist *bl, uint64_t snap_id, uint64_t* objver)); int do_read(const std::string& oid, size_t len, uint64_t off, - bufferlist *bl, uint64_t snap_id) { - return TestMemIoCtxImpl::read(oid, len, off, bl, snap_id); + bufferlist *bl, uint64_t snap_id, uint64_t* objver) { + return TestMemIoCtxImpl::read(oid, len, off, bl, snap_id, objver); } MOCK_METHOD2(remove, int(const std::string& oid, const SnapContext &snapc)); @@ -226,7 +226,7 @@ public: 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, notify(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_notify)); - ON_CALL(*this, read(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read)); + ON_CALL(*this, read(_, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read)); ON_CALL(*this, set_snap_read(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_set_snap_read)); ON_CALL(*this, sparse_read(_, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_sparse_read)); ON_CALL(*this, remove(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove)); diff --git a/src/test/librados_test_stub/NeoradosTestStub.cc b/src/test/librados_test_stub/NeoradosTestStub.cc index c91a0aad4ed..03d729466b6 100644 --- a/src/test/librados_test_stub/NeoradosTestStub.cc +++ b/src/test/librados_test_stub/NeoradosTestStub.cc @@ -268,7 +268,7 @@ void Op::cmpext(uint64_t off, ceph::buffer::list&& cmp_bl, std::size_t* s) { &librados::TestIoCtxImpl::cmpext, _1, _2, off, cmp_bl, _4); if (s != nullptr) { op = std::bind( - save_operation_size, std::bind(op, _1, _2, _3, _4, _5), s); + save_operation_size, std::bind(op, _1, _2, _3, _4, _5, _6), s); } o->ops.push_back(op); } @@ -316,7 +316,7 @@ void Op::exec(std::string_view cls, std::string_view method, librados::ObjectOperationTestImpl op = [cls_handler, cls, method, inbl = const_cast(inbl), out] (librados::TestIoCtxImpl* io_ctx, const std::string& oid, bufferlist* outbl, - uint64_t snap_id, const SnapContext& snapc) mutable -> int { + uint64_t snap_id, const SnapContext& snapc, uint64_t*) mutable -> int { return io_ctx->exec( oid, cls_handler, std::string(cls).c_str(), std::string(method).c_str(), inbl, @@ -324,7 +324,7 @@ void Op::exec(std::string_view cls, std::string_view method, }; if (ec != nullptr) { op = std::bind( - save_operation_ec, std::bind(op, _1, _2, _3, _4, _5), ec); + save_operation_ec, std::bind(op, _1, _2, _3, _4, _5, _6), ec); } o->ops.push_back(op); } @@ -338,14 +338,14 @@ void Op::exec(std::string_view cls, std::string_view method, librados::ObjectOperationTestImpl op = [cls_handler, cls, method, inbl = const_cast(inbl)] (librados::TestIoCtxImpl* io_ctx, const std::string& oid, bufferlist* outbl, - uint64_t snap_id, const SnapContext& snapc) mutable -> int { + uint64_t snap_id, const SnapContext& snapc, uint64_t*) mutable -> int { return io_ctx->exec( oid, cls_handler, std::string(cls).c_str(), std::string(method).c_str(), inbl, outbl, snap_id, snapc); }; if (ec != NULL) { op = std::bind( - save_operation_ec, std::bind(op, _1, _2, _3, _4, _5), ec); + save_operation_ec, std::bind(op, _1, _2, _3, _4, _5, _6), ec); } o->ops.push_back(op); } @@ -355,14 +355,16 @@ void ReadOp::read(size_t off, uint64_t len, ceph::buffer::list* out, auto o = *reinterpret_cast(&impl); librados::ObjectOperationTestImpl op; if (out != nullptr) { - op = std::bind(&librados::TestIoCtxImpl::read, _1, _2, len, off, out, _4); + op = std::bind( + &librados::TestIoCtxImpl::read, _1, _2, len, off, out, _4, _6); } else { - op = std::bind(&librados::TestIoCtxImpl::read, _1, _2, len, off, _3, _4); + op = std::bind( + &librados::TestIoCtxImpl::read, _1, _2, len, off, _3, _4, _6); } if (ec != NULL) { op = std::bind( - save_operation_ec, std::bind(op, _1, _2, _3, _4, _5), ec); + save_operation_ec, std::bind(op, _1, _2, _3, _4, _5, _6), ec); } o->ops.push_back(op); } @@ -376,7 +378,7 @@ void ReadOp::sparse_read(uint64_t off, uint64_t len, librados::ObjectOperationTestImpl op = [off, len, out, extents] (librados::TestIoCtxImpl* io_ctx, const std::string& oid, bufferlist* outbl, - uint64_t snap_id, const SnapContext& snapc) mutable -> int { + uint64_t snap_id, const SnapContext& snapc, uint64_t*) mutable -> int { std::map m; int r = io_ctx->sparse_read( oid, off, len, &m, (out != nullptr ? out : outbl), snap_id); @@ -388,7 +390,7 @@ void ReadOp::sparse_read(uint64_t off, uint64_t len, }; if (ec != NULL) { op = std::bind(save_operation_ec, - std::bind(op, _1, _2, _3, _4, _5), ec); + std::bind(op, _1, _2, _3, _4, _5, _6), ec); } o->ops.push_back(op); } @@ -398,7 +400,7 @@ void ReadOp::list_snaps(SnapSet* snaps, bs::error_code* ec) { librados::ObjectOperationTestImpl op = [snaps] (librados::TestIoCtxImpl* io_ctx, const std::string& oid, bufferlist*, - uint64_t, const SnapContext&) mutable -> int { + uint64_t, const SnapContext&, uint64_t*) mutable -> int { librados::snap_set_t snap_set; int r = io_ctx->list_snaps(oid, &snap_set); if (r >= 0 && snaps != nullptr) { @@ -418,7 +420,7 @@ void ReadOp::list_snaps(SnapSet* snaps, bs::error_code* ec) { }; if (ec != NULL) { op = std::bind(save_operation_ec, - std::bind(op, _1, _2, _3, _4, _5), ec); + std::bind(op, _1, _2, _3, _4, _5, _6), ec); } o->ops.push_back(op); } @@ -519,7 +521,7 @@ void RADOS::execute(const Object& o, const IOContext& ioc, ReadOp&& op, auto completion = create_aio_completion(std::move(c)); auto r = io_ctx->aio_operate_read(std::string{o}, *ops, completion, 0U, bl, - snap_id); + snap_id, objver); ceph_assert(r == 0); } diff --git a/src/test/librados_test_stub/TestIoCtxImpl.cc b/src/test/librados_test_stub/TestIoCtxImpl.cc index acaf8ea78c4..73bc8d4a885 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestIoCtxImpl.cc @@ -112,20 +112,21 @@ int TestIoCtxImpl::aio_operate(const std::string& oid, TestObjectOperationImpl & m_client->add_aio_operation(oid, true, std::bind( &TestIoCtxImpl::execute_aio_operations, this, oid, &ops, reinterpret_cast(0), m_snap_seq, - snap_context != NULL ? *snap_context : m_snapc), c); + snap_context != NULL ? *snap_context : m_snapc, nullptr), c); return 0; } int TestIoCtxImpl::aio_operate_read(const std::string& oid, TestObjectOperationImpl &ops, AioCompletionImpl *c, int flags, - bufferlist *pbl, uint64_t snap_id) { + bufferlist *pbl, uint64_t snap_id, + uint64_t* objver) { // TODO ignoring flags for now ops.get(); m_pending_ops++; m_client->add_aio_operation(oid, true, std::bind( &TestIoCtxImpl::execute_aio_operations, this, oid, &ops, pbl, snap_id, - m_snapc), c); + m_snapc, objver), c); return 0; } @@ -211,7 +212,7 @@ int TestIoCtxImpl::operate(const std::string& oid, m_pending_ops++; m_client->add_aio_operation(oid, false, std::bind( &TestIoCtxImpl::execute_aio_operations, this, oid, &ops, - reinterpret_cast(0), m_snap_seq, m_snapc), comp); + reinterpret_cast(0), m_snap_seq, m_snapc, nullptr), comp); comp->wait_for_complete(); int ret = comp->get_return_value(); @@ -228,7 +229,7 @@ int TestIoCtxImpl::operate_read(const std::string& oid, m_pending_ops++; m_client->add_aio_operation(oid, false, std::bind( &TestIoCtxImpl::execute_aio_operations, this, oid, &ops, pbl, - m_snap_seq, m_snapc), comp); + m_snap_seq, m_snapc, nullptr), comp); comp->wait_for_complete(); int ret = comp->get_return_value(); @@ -291,7 +292,7 @@ int TestIoCtxImpl::tmap_update(const std::string& oid, bufferlist& cmdbl) { if (size > 0) { bufferlist inbl; - r = read(oid, size, 0, &inbl, CEPH_NOSNAP); + r = read(oid, size, 0, &inbl, CEPH_NOSNAP, nullptr); if (r < 0) { return r; } @@ -362,7 +363,8 @@ int TestIoCtxImpl::execute_operation(const std::string& oid, int TestIoCtxImpl::execute_aio_operations(const std::string& oid, TestObjectOperationImpl *ops, bufferlist *pbl, uint64_t snap_id, - const SnapContext &snapc) { + const SnapContext &snapc, + uint64_t* objver) { int ret = 0; if (m_client->is_blocklisted()) { ret = -EBLOCKLISTED; @@ -370,7 +372,7 @@ int TestIoCtxImpl::execute_aio_operations(const std::string& oid, TestRadosClient::Transaction transaction(m_client, get_namespace(), oid); for (ObjectOperations::iterator it = ops->ops.begin(); it != ops->ops.end(); ++it) { - ret = (*it)(this, oid, pbl, snap_id, snapc); + ret = (*it)(this, oid, pbl, snap_id, snapc, objver); if (ret < 0) { break; } diff --git a/src/test/librados_test_stub/TestIoCtxImpl.h b/src/test/librados_test_stub/TestIoCtxImpl.h index 2ebc42edd79..3c6ff590da6 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.h +++ b/src/test/librados_test_stub/TestIoCtxImpl.h @@ -22,8 +22,9 @@ class TestRadosClient; typedef boost::function ObjectOperationTestImpl; + uint64_t, + const SnapContext &, + uint64_t*)> ObjectOperationTestImpl; typedef std::list ObjectOperations; struct TestObjectOperationImpl { @@ -90,7 +91,8 @@ public: int flags); virtual int aio_operate_read(const std::string& oid, TestObjectOperationImpl &ops, AioCompletionImpl *c, int flags, - bufferlist *pbl, uint64_t snap_id); + bufferlist *pbl, uint64_t snap_id, + uint64_t* objver); virtual int aio_remove(const std::string& oid, AioCompletionImpl *c, int flags = 0) = 0; virtual int aio_watch(const std::string& o, AioCompletionImpl *c, @@ -133,7 +135,7 @@ public: virtual int operate_read(const std::string& oid, TestObjectOperationImpl &ops, bufferlist *pbl); virtual int read(const std::string& oid, size_t len, uint64_t off, - bufferlist *bl, uint64_t snap_id) = 0; + bufferlist *bl, uint64_t snap_id, uint64_t* objver) = 0; virtual int remove(const std::string& oid, const SnapContext &snapc) = 0; virtual int selfmanaged_snap_create(uint64_t *snapid) = 0; virtual void aio_selfmanaged_snap_create(uint64_t *snapid, @@ -186,7 +188,8 @@ protected: int execute_aio_operations(const std::string& oid, TestObjectOperationImpl *ops, bufferlist *pbl, uint64_t, - const SnapContext &snapc); + const SnapContext &snapc, + uint64_t* objver); private: struct C_AioNotify : public Context { diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.cc b/src/test/librados_test_stub/TestMemIoCtxImpl.cc index 6ad3ce3861a..687abb16d40 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.cc @@ -356,7 +356,8 @@ int TestMemIoCtxImpl::omap_set(const std::string& oid, } int TestMemIoCtxImpl::read(const std::string& oid, size_t len, uint64_t off, - bufferlist *bl, uint64_t snap_id) { + bufferlist *bl, uint64_t snap_id, + uint64_t* objver) { if (m_client->is_blocklisted()) { return -EBLOCKLISTED; } @@ -380,6 +381,9 @@ int TestMemIoCtxImpl::read(const std::string& oid, size_t len, uint64_t off, bit.substr_of(file->data, off, len); append_clone(bit, bl); } + if (objver != nullptr) { + *objver = file->objver; + } return len; } diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.h b/src/test/librados_test_stub/TestMemIoCtxImpl.h index 9b904226236..4706f46d218 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.h +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.h @@ -48,7 +48,7 @@ public: int omap_set(const std::string& oid, const std::map &map) override; int read(const std::string& oid, size_t len, uint64_t off, - bufferlist *bl, uint64_t snap_id) override; + bufferlist *bl, uint64_t snap_id, uint64_t* objver) override; int remove(const std::string& oid, const SnapContext &snapc) override; int selfmanaged_snap_create(uint64_t *snapid) override; int selfmanaged_snap_remove(uint64_t snapid) override; diff --git a/src/test/librbd/image/test_mock_RefreshRequest.cc b/src/test/librbd/image/test_mock_RefreshRequest.cc index 2912237c166..96b8fe30673 100644 --- a/src/test/librbd/image/test_mock_RefreshRequest.cc +++ b/src/test/librbd/image/test_mock_RefreshRequest.cc @@ -168,7 +168,7 @@ public: 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, _, _, _, _)); + read(mock_image_ctx.header_oid, _, _, _, _, _)); if (r < 0) { expect.WillOnce(Return(r)); } else { diff --git a/src/test/librbd/image/test_mock_ValidatePoolRequest.cc b/src/test/librbd/image/test_mock_ValidatePoolRequest.cc index 95e4028ec96..65460eab785 100644 --- a/src/test/librbd/image/test_mock_ValidatePoolRequest.cc +++ b/src/test/librbd/image/test_mock_ValidatePoolRequest.cc @@ -53,7 +53,8 @@ public: void expect_read_rbd_info(librados::MockTestMemIoCtxImpl &mock_io_ctx, const std::string& data, int r) { - auto& expect = EXPECT_CALL(mock_io_ctx, read(StrEq(RBD_INFO), 0, 0, _, _)); + auto& expect = EXPECT_CALL( + mock_io_ctx, read(StrEq(RBD_INFO), 0, 0, _, _, _)); if (r < 0) { expect.WillOnce(Return(r)); } else { diff --git a/src/test/librbd/io/test_mock_ObjectRequest.cc b/src/test/librbd/io/test_mock_ObjectRequest.cc index 5a451bcfbc5..18069b9c99d 100644 --- a/src/test/librbd/io/test_mock_ObjectRequest.cc +++ b/src/test/librbd/io/test_mock_ObjectRequest.cc @@ -215,7 +215,7 @@ struct TestMockIoObjectRequest : public TestMockFixture { auto& mock_io_ctx = librados::get_mock_io_ctx( mock_image_ctx.rados_api, *mock_image_ctx.get_data_io_context()); - auto& expect = EXPECT_CALL(mock_io_ctx, read(oid, len, off, _, _)); + auto& expect = EXPECT_CALL(mock_io_ctx, read(oid, len, off, _, _, _)); if (r < 0) { expect.WillOnce(Return(r)); } else { diff --git a/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc b/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc index b49f7419d5d..7f77aaf839f 100644 --- a/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc +++ b/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc @@ -33,11 +33,11 @@ public: if (r < 0) { EXPECT_CALL(get_mock_io_ctx(ictx->md_ctx), read(ObjectMap<>::object_map_name(ictx->id, CEPH_NOSNAP), - 0, 0, _, _)).WillOnce(Return(r)); + 0, 0, _, _, _)).WillOnce(Return(r)); } else { EXPECT_CALL(get_mock_io_ctx(ictx->md_ctx), read(ObjectMap<>::object_map_name(ictx->id, CEPH_NOSNAP), - 0, 0, _, _)).WillOnce(DoDefault()); + 0, 0, _, _, _)).WillOnce(DoDefault()); } } diff --git a/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc b/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc index 96636ab14d0..7b89a0996c1 100644 --- a/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc +++ b/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc @@ -25,11 +25,11 @@ public: if (r < 0) { EXPECT_CALL(get_mock_io_ctx(ictx->md_ctx), read(ObjectMap<>::object_map_name(ictx->id, snap_id), - 0, 0, _, _)).WillOnce(Return(r)); + 0, 0, _, _, _)).WillOnce(Return(r)); } else { EXPECT_CALL(get_mock_io_ctx(ictx->md_ctx), read(ObjectMap<>::object_map_name(ictx->id, snap_id), - 0, 0, _, _)).WillOnce(DoDefault()); + 0, 0, _, _, _)).WillOnce(DoDefault()); } }