public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Jon Maloy <jmaloy@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH v3 02/10] iov: Add iov_memcpy() to copy data between iovec arrays
Date: Mon, 11 May 2026 05:07:55 -0400	[thread overview]
Message-ID: <8aad121d-d89e-406b-9cab-f07f4a18d186@redhat.com> (raw)
In-Reply-To: <20260416155721.3807225-3-lvivier@redhat.com>



On 2026-04-16 11:57, Laurent Vivier wrote:
> Add a helper to copy data from a source iovec array to a destination
> iovec array, each starting at an arbitrary byte offset, iterating
> through both arrays simultaneously and copying in chunks matching the
> smaller of the two current segments.
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

Reviewed-by: Jon Maloy <jmaloy@redhat.com>

But see below,

> ---
>   iov.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   iov.h |  3 +++
>   2 files changed, 55 insertions(+)
> 
> diff --git a/iov.c b/iov.c
> index 0188acdf5eba..dabc4f1ceea3 100644
> --- a/iov.c
> +++ b/iov.c
> @@ -197,6 +197,58 @@ void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c,
>   	}
>   }
>   
> +/**
> + * iov_memcpy() - Copy data between two iovec arrays
> + * @dst_iov:		Destination iovec array
> + * @dst_iov_cnt:	Number of elements in destination iovec array
> + * @dst_offset:		Destination offset
> + * @src_iov:		Source iovec array
> + * @src_iov_cnt:	Number of elements in source iovec array
> + * @offs:		Source offset
> + * @length:		Number of bytes to copy
> + *
> + * Return: total number of bytes copied
> + */
> +/* cppcheck-suppress unusedFunction */
> +size_t iov_memcpy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offset,
> +		  const struct iovec *src_iov, size_t src_iov_cnt,
> +		  size_t src_offset, size_t length)
> +{
> +	unsigned int i, j;

These could be size_t for consistency with the in parameters.

/jon


> +	size_t total = 0;
> +
> +	i = iov_skip_bytes(src_iov, src_iov_cnt, src_offset, &src_offset);
> +	j = iov_skip_bytes(dst_iov, dst_iov_cnt, dst_offset, &dst_offset);
> +
> +	/* copying data */
> +	while (length && i < src_iov_cnt && j < dst_iov_cnt) {
> +		size_t n = MIN(dst_iov[j].iov_len - dst_offset,
> +			       src_iov[i].iov_len - src_offset);
> +
> +		if (n > length)
> +			n = length;
> +
> +		memcpy((char *)dst_iov[j].iov_base + dst_offset,
> +		       (const char *)src_iov[i].iov_base + src_offset, n);
> +
> +		dst_offset += n;
> +		src_offset += n;
> +		total += n;
> +		length -= n;
> +
> +		if (dst_offset == dst_iov[j].iov_len) {
> +			dst_offset = 0;
> +			j++;
> +		}
> +		if (src_offset == src_iov[i].iov_len) {
> +			src_offset = 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 d295d05b3bab..3c63308e554f 100644
> --- a/iov.h
> +++ b/iov.h
> @@ -32,6 +32,9 @@ 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_memcpy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offset,
> +		  const struct iovec *src_iov, size_t src_iov_cnt,
> +		  size_t src_offset, size_t length);
>   
>   /*
>    * DOC: Theory of Operation, struct iov_tail


  reply	other threads:[~2026-05-11  9:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16 15:57 [PATCH v3 00/10] vhost-user: Preparatory series for multiple iovec entries per virtqueue element Laurent Vivier
2026-04-16 15:57 ` [PATCH v3 01/10] iov: Introduce iov_memset() Laurent Vivier
2026-04-16 15:57 ` [PATCH v3 02/10] iov: Add iov_memcpy() to copy data between iovec arrays Laurent Vivier
2026-05-11  9:07   ` Jon Maloy [this message]
2026-04-16 15:57 ` [PATCH v3 03/10] vu_common: Move vnethdr setup into vu_flush() Laurent Vivier
2026-04-16 15:57 ` [PATCH v3 04/10] udp_vu: Move virtqueue management from udp_vu_sock_recv() to its caller Laurent Vivier
2026-05-11  9:30   ` Jon Maloy
2026-05-11 10:44     ` David Gibson
2026-04-16 15:57 ` [PATCH v3 05/10] udp_vu: Pass iov explicitly to helpers instead of using file-scoped array Laurent Vivier
2026-05-11  9:37   ` Jon Maloy
2026-04-16 15:57 ` [PATCH v3 06/10] checksum: Pass explicit L4 length to checksum functions Laurent Vivier
2026-05-11  1:33   ` David Gibson
2026-04-16 15:57 ` [PATCH v3 07/10] pcap: Pass explicit L2 length to pcap_iov() Laurent Vivier
2026-05-11  1:42   ` David Gibson
2026-05-11  9:50   ` Jon Maloy
2026-04-16 15:57 ` [PATCH v3 08/10] vu_common: Pass explicit frame length to vu_flush() Laurent Vivier
2026-04-16 15:57 ` [PATCH v3 09/10] tcp: Pass explicit data length to tcp_fill_headers() Laurent Vivier
2026-04-16 15:57 ` [PATCH v3 10/10] vhost-user: Centralise Ethernet frame padding in vu_collect() and vu_pad() Laurent Vivier
2026-05-11  2:01   ` David Gibson
2026-05-11  9:53 ` [PATCH v3 00/10] vhost-user: Preparatory series for multiple iovec entries per virtqueue element Jon Maloy

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=8aad121d-d89e-406b-9cab-f07f4a18d186@redhat.com \
    --to=jmaloy@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=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).