From d3c3bf5b772e38ecc39090e0bc32775a230764ad Mon Sep 17 00:00:00 2001 From: "Frank S. Filz" Date: Tue, 10 May 2022 14:15:05 -0700 Subject: [PATCH] Buffers: Add function to buffer.h to copy bufferlist to an iovec Signed-off-by: Frank S. Filz --- src/include/buffer.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/include/buffer.h b/src/include/buffer.h index 10dceaec29917..16ee0055ad21a 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -1286,6 +1286,23 @@ inline bufferhash& operator<<(bufferhash& l, const bufferlist &r) { return l; } +static inline +void copy_bufferlist_to_iovec(const struct iovec *iov, unsigned iovcnt, + bufferlist *bl, int64_t r) +{ + auto iter = bl->cbegin(); + for (unsigned j = 0, resid = r; j < iovcnt && resid > 0; j++) { + /* + * This piece of code aims to handle the case that bufferlist + * does not have enough data to fill in the iov + */ + const auto round_size = std::min(resid, iov[j].iov_len); + iter.copy(round_size, reinterpret_cast(iov[j].iov_base)); + resid -= round_size; + /* iter is self-updating */ + } +} + } // namespace buffer } // namespace ceph -- 2.39.5