From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH 6/7] iov: introduce iov_memcopy()
Date: Mon, 23 Mar 2026 17:52:58 +0100 [thread overview]
Message-ID: <20260323165259.1253482-7-lvivier@redhat.com> (raw)
In-Reply-To: <20260323165259.1253482-1-lvivier@redhat.com>
Copy buffers data from one iovec array to another.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
iov.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
iov.h | 2 ++
2 files changed, 48 insertions(+)
diff --git a/iov.c b/iov.c
index c1eda9941f32..55263ec10b44 100644
--- a/iov.c
+++ b/iov.c
@@ -196,6 +196,52 @@ void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c,
}
}
+/**
+ * iov_memcopy() - Copy data between two iovec arrays
+ * @dst_iov: Destination iovec array
+ * @dst_iov_cnt: Number of elements in destination iovec array
+ * @dst_offs: Destination offset
+ * @iov: Source iovec array
+ * @iov_cnt: Number of elements in source iovec array
+ * @offs: Source offset
+ *
+ * Return: total number of bytes copied
+ */
+/* cppcheck-suppress unusedFunction */
+size_t iov_memcopy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offs,
+ const struct iovec *iov, size_t iov_cnt, size_t offs)
+{
+ unsigned int i, j;
+ size_t total = 0;
+
+ i = iov_skip_bytes(iov, iov_cnt, offs, &offs);
+ j = iov_skip_bytes(dst_iov, dst_iov_cnt, dst_offs, &dst_offs);
+
+ /* copying data */
+ while (i < iov_cnt && j < dst_iov_cnt) {
+ size_t len = MIN(dst_iov[j].iov_len - dst_offs,
+ iov[i].iov_len - offs);
+
+ memcpy((char *)dst_iov[j].iov_base + dst_offs,
+ (const char *)iov[i].iov_base + offs, len);
+
+ dst_offs += len;
+ offs += len;
+ total += len;
+
+ if (dst_offs == dst_iov[j].iov_len) {
+ dst_offs = 0;
+ j++;
+ }
+ if (offs == iov[i].iov_len) {
+ offs = 0;
+ i++;
+ }
+ }
+
+ return total;
+}
+
/**
* iov_tail_prune() - Remove any unneeded buffers from an IOV tail
* @tail: IO vector tail (modified)
diff --git a/iov.h b/iov.h
index 4ce425ccdbe5..d3c51dc8d6da 100644
--- a/iov.h
+++ b/iov.h
@@ -32,6 +32,8 @@ size_t iov_size(const struct iovec *iov, size_t iov_cnt);
size_t iov_truncate(struct iovec *iov, size_t iov_cnt, size_t size);
void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c,
size_t length);
+size_t iov_memcopy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offs,
+ const struct iovec *iov, size_t iov_cnt, size_t offs);
/*
* DOC: Theory of Operation, struct iov_tail
--
2.53.0
next prev parent reply other threads:[~2026-03-23 16:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 16:52 [PATCH 0/7] vhost-user,tcp: Handle multiple iovec entries per virtqueue element Laurent Vivier
2026-03-23 16:52 ` [PATCH 1/7] tcp: pass ipv4h checksum, not a pointer to the checksum Laurent Vivier
2026-03-24 3:53 ` David Gibson
2026-03-24 7:56 ` Laurent Vivier
2026-03-24 23:49 ` David Gibson
2026-03-23 16:52 ` [PATCH 2/7] tcp: use iov_tail to access headers in tcp_fill_headers() Laurent Vivier
2026-03-24 3:58 ` David Gibson
2026-03-23 16:52 ` [PATCH 3/7] tcp_vu: Use iov_tail helpers to build headers in tcp_vu_prepare() Laurent Vivier
2026-03-25 4:46 ` David Gibson
2026-03-23 16:52 ` [PATCH 4/7] tcp_vu: Support multibuffer frames in tcp_vu_sock_recv() Laurent Vivier
2026-03-25 5:06 ` David Gibson
2026-03-23 16:52 ` [PATCH 5/7] tcp: Use iov_tail to access headers in tcp_prepare_flags() Laurent Vivier
2026-03-23 16:52 ` Laurent Vivier [this message]
2026-03-23 16:52 ` [PATCH 7/7] tcp_vu: Use iov_tail helpers to build headers in tcp_vu_send_flag() Laurent Vivier
2026-03-25 5:07 ` [PATCH 0/7] vhost-user,tcp: Handle multiple iovec entries per virtqueue element David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323165259.1253482-7-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).