]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Buffers: Add function to buffer.h to copy bufferlist to an iovec
authorFrank S. Filz <ffilzlnx@mindspring.com>
Tue, 10 May 2022 21:15:05 +0000 (14:15 -0700)
committerFrank S. Filz <ffilzlnx@mindspring.com>
Mon, 24 Jul 2023 18:49:03 +0000 (11:49 -0700)
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
src/include/buffer.h

index 10dceaec2991752ba43b731f906cb6ddef74ad65..16ee0055ad21aefaf00d376bd75350d731cfac65 100644 (file)
@@ -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<unsigned>(resid, iov[j].iov_len);
+         iter.copy(round_size, reinterpret_cast<char*>(iov[j].iov_base));
+         resid -= round_size;
+         /* iter is self-updating */
+  }
+}
+
 } // namespace buffer
 
 } // namespace ceph