From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=IGKWjLfD; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 2EAD15A026D for ; Fri, 10 Apr 2026 08:45:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1775803525; bh=NxDUpknWfxXQHyg3qHtLpiEOwFjvnFnZiDbZQoCO44Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IGKWjLfD7CjNBGTFAASHHa1BxOH/u/D/XN12wBxYsnK9PW9PsOeSCrM/u1pGeYeZC Vt3L/XVcaO2LDmBztbL7jeujxCRCvktZx4sXByK36dum5wMAWxa5+5ZNP1gvxRUHnn W8YHpYh9Jc0N39CURaSbB3C4+b5DeM2cyKBbpgJaJd6890TVi+qj5iuDzTS29TamZF Ies1P/XNC4pKukPvZNICPjL7cFuskm5q69PhirkyM7qWwhzsOVxcpJeMVTopFJIFKG 6N9gbL0m9UD+SbdMreU2r56p2+On035EpPz91bsXerMztTKAKEeRrKK5xZmFpkj9Q5 LdnLU1iKbMt8Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fsS3n0qxVz4wLn; Fri, 10 Apr 2026 16:45:25 +1000 (AEST) Date: Fri, 10 Apr 2026 16:44:58 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 02/10] iov: Add iov_memcpy() to copy data between iovec arrays Message-ID: References: <20260403163811.3209635-1-lvivier@redhat.com> <20260403163811.3209635-3-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="N5qOOovBKARRfqkm" Content-Disposition: inline In-Reply-To: <20260403163811.3209635-3-lvivier@redhat.com> Message-ID-Hash: GHXZTFXGCW6EDG3I7FOJN4PKY7NGEHAT X-Message-ID-Hash: GHXZTFXGCW6EDG3I7FOJN4PKY7NGEHAT X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --N5qOOovBKARRfqkm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 03, 2026 at 06:38:03PM +0200, 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. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > iov.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > iov.h | 3 +++ > 2 files changed, 55 insertions(+) >=20 > 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, > } > } > =20 > +/** > + * 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; > + size_t total =3D 0; > + > + i =3D iov_skip_bytes(src_iov, src_iov_cnt, src_offset, &src_offset); > + j =3D 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 =3D MIN(dst_iov[j].iov_len - dst_offset, > + src_iov[i].iov_len - src_offset); > + > + if (n > length) > + n =3D length; > + > + memcpy((char *)dst_iov[j].iov_base + dst_offset, > + (const char *)src_iov[i].iov_base + src_offset, n); > + > + dst_offset +=3D n; > + src_offset +=3D n; > + total +=3D n; > + length -=3D n; > + > + if (dst_offset =3D=3D dst_iov[j].iov_len) { > + dst_offset =3D 0; > + j++; > + } > + if (src_offset =3D=3D src_iov[i].iov_len) { > + src_offset =3D 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); > =20 > /* > * DOC: Theory of Operation, struct iov_tail > --=20 > 2.53.0 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --N5qOOovBKARRfqkm Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnYnF4ACgkQzQJF27ox 2Gc3sQ//bVyL5sc9Ob7lgl+L1N6UVahFBJDejyp5ZUEI/MPoyTAZcY9GahQ0UJ0e uvM7QDZJC8Z0t3SZ2xmgSqpxeLjEG4qYRozCC3H6hKlzHvGkzkqMxFRnbpSUDv+E hUYsWggcXRjL65Y2OJ1U5XfexDsx6u+mnrdckw554lL7Dl5n95ttFQbhYaB43lWc KZUjtwQiGu8c21Py71i/AXiAH0dJSYjWE041rtIB11adHDDLh35GEpLKf7w16J6t SwJDPf8RrCF+m/123uh6nvNiYXiNP9bAPpLzI5KhmjYAZ0BsV7Oq6fZApiGLo//M 655BHqu1n4f2TKUWXrQMUDrWO9ytjkVJX6cuDXdojl/Rug6iqdI7EuqtoQoqtC8i qaWumUG3noooIwhTny0Dh4OLt7YUglAw7mPM65BR18jtJtO48XxjDVqgfSk4+cG1 WwTrIfUlu1Rl72oh0Jwlwd/OFYwB6phiVxV2cwwWWsiTk1dP9AR/2k0Z2SEvgxCa nxyUTnbfRi2F0NJe8d/FUnchKhWV7KZ7qAZmFfd6cGfhSFzfVExIcNw1kPHC8DLW Bd+M8VnDnXyngy0utSJ7rXXhVD8cnKZA2GYZrLFFjGZ7ZmgvuL+JTvnhhOraVZrZ 92+mu9pvAYo+bc4Z/VeAbLIZ04NISaPgJB0TDwgu6mXWdvjtLbw= =dYSa -----END PGP SIGNATURE----- --N5qOOovBKARRfqkm--