From 02f5543c8df9e2a175ce5d9a96773b641e212c1c Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Thu, 27 Jun 2019 19:05:26 +0530 Subject: [PATCH] libradosstriper: add function to read into char* Signed-off-by: Milind Changire Signed-off-by: Patrick Donnelly --- src/include/radosstriper/libradosstriper.hpp | 1 + src/libradosstriper/libradosstriper.cc | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/include/radosstriper/libradosstriper.hpp b/src/include/radosstriper/libradosstriper.hpp index fb790b0d7ef..064c7d2c3d8 100644 --- a/src/include/radosstriper/libradosstriper.hpp +++ b/src/include/radosstriper/libradosstriper.hpp @@ -168,6 +168,7 @@ namespace libradosstriper * synchronously read from the striped object at the specified offset. */ int read(const std::string& soid, ceph::bufferlist* pbl, size_t len, uint64_t off); + int read(const std::string& soid, char *buf, size_t len, uint64_t off); /** * asynchronously read from the striped object at the specified offset. diff --git a/src/libradosstriper/libradosstriper.cc b/src/libradosstriper/libradosstriper.cc index e98dfc17935..7f23a380550 100644 --- a/src/libradosstriper/libradosstriper.cc +++ b/src/libradosstriper/libradosstriper.cc @@ -254,6 +254,28 @@ int libradosstriper::RadosStriper::read(const std::string& soid, return rados_striper_impl->read(soid, bl, len, off); } +int libradosstriper::RadosStriper::read(const std::string& soid, + char *buf, + size_t len, + uint64_t off) +{ + bufferlist bl; + bufferptr bp = buffer::create_static(len, buf); + + bl.push_back(bp); + + int ret = rados_striper_impl->read(soid, &bl, len, off); + + if (ret >= 0) { + if (bl.length() > len) + return -ERANGE; + if (!bl.is_provided_buffer(buf)) + bl.begin().copy(bl.length(), buf); + ret = bl.length(); // hrm :/ + } + return ret; +} + int libradosstriper::RadosStriper::aio_read(const std::string& soid, librados::AioCompletion *c, bufferlist* bl, -- 2.39.5