From: Frank S. Filz Date: Tue, 10 May 2022 21:15:05 +0000 (-0700) Subject: Buffers: Add function to buffer.h to copy bufferlist to an iovec X-Git-Tag: v19.0.0~814^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d3c3bf5b772e38ecc39090e0bc32775a230764ad;p=ceph.git Buffers: Add function to buffer.h to copy bufferlist to an iovec Signed-off-by: Frank S. Filz --- diff --git a/src/include/buffer.h b/src/include/buffer.h index 10dceaec2991..16ee0055ad21 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