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=GX6I44gS; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 82BA35A0265 for ; Thu, 12 Mar 2026 05:30:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773289822; bh=ZVYzF3pIGCbsvNDvYQt/M+70qQMzv4GmEW36pkES6To=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GX6I44gS+VvN6xzWFv7v8y95nHcqEeqAEuj8O5xidi71V5+Hy5pmsoHz//ZVnrP6J ilCrtf+sdraI8T1nX3Z1AFFPOxZFkvGXjr8dZvM8IRwZYVnMfIc14yLJgMb5agwe9E fqamypPE+pRxKHqVLIpAxTee7Ve+/4Knvz3r1HGCtPjiozfEFGvl7V89J622Y2A9nu OME2s3QnmdMduHDOiaA9RvjWP/L9NI82z/9fJpow7eP+B2V8TGZB61GanXoInerRS6 l261dE9JLns50qj+IdPPdGERmBimNEWiMgYw9jWipu/ZUz4DuJnnentOLUmNDpcQjf BI13G8YFI0sCw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fWZRL0g2Lz4wDJ; Thu, 12 Mar 2026 15:30:22 +1100 (AEDT) Date: Thu, 12 Mar 2026 15:12:00 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 06/13] iov: Add IOV_PUT_HEADER() to write header data back to iov_tail Message-ID: References: <20260309094744.1907754-1-lvivier@redhat.com> <20260309094744.1907754-7-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="KkwPpNiaUxXf6lai" Content-Disposition: inline In-Reply-To: <20260309094744.1907754-7-lvivier@redhat.com> Message-ID-Hash: EX5HQBV7U5CPDCGM3YIX57ZEAZF7GHBA X-Message-ID-Hash: EX5HQBV7U5CPDCGM3YIX57ZEAZF7GHBA 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: --KkwPpNiaUxXf6lai Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 09, 2026 at 10:47:37AM +0100, Laurent Vivier wrote: > Add a counterpart to IOV_PEEK_HEADER() that writes header data back > to an iov_tail after modification. If the header pointer matches the > original iov buffer location, it only advances the offset. Otherwise, > it copies the data using iov_from_buf(). >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson Although a couple of thoughts on possible improvements below. > --- > iov.c | 24 ++++++++++++++++++++++++ > iov.h | 14 +++++++++++++- > 2 files changed, 37 insertions(+), 1 deletion(-) >=20 > diff --git a/iov.c b/iov.c > index cd48667226f3..296f24b61067 100644 > --- a/iov.c > +++ b/iov.c > @@ -305,6 +305,30 @@ void *iov_peek_header_(struct iov_tail *tail, void *= v, size_t len, size_t align) > return v; > } > =20 > +/** > + * iov_put_header_() - Write header back to an IOV tail > + * @tail: IOV tail to write header to > + * @v: Pointer to header data to write > + * @len: Length of header to write, in bytes > + * > + * Return: number of bytes written > + */ > +/* cppcheck-suppress unusedFunction */ > +size_t iov_put_header_(struct iov_tail *tail, const void *v, size_t len) > +{ > + size_t l =3D len; > + > + /* iov_peek_header_() already called iov_check_header() */ > + if ((char *)tail->iov[0].iov_base + tail->off !=3D v) > + l =3D iov_from_buf(tail->iov, tail->cnt, tail->off, v, len); This assumes the tail is already pruned. That will be the case assuming this has a matching iov_peek_header_(), but it might be better to explicitly document that assumption. Better yet, is there a way we could enforce these come in pairs. Something like: struct some_header *hdr; with_header(hdr, tail) { hdr->a =3D 123; hdr->b =3D hdr->c - 7; } Where, #define with_header(hdr, tail) for ((typeof *(hdr)) store, hdr =3D IOV_PEEK_HEADER(tail, store); hdr; IOV_PUT_HEADER(tail, hdr), hdr =3D NULL) > + ASSERT(l =3D=3D len); > + > + tail->off +=3D l; > + > + return l; > +} > + > /** > * iov_remove_header_() - Remove a header from an IOV tail > * @tail: IOV tail to remove header from (modified) > diff --git a/iov.h b/iov.h > index d295d05b3bab..fe7c5163d2ab 100644 > --- a/iov.h > +++ b/iov.h > @@ -90,6 +90,7 @@ bool iov_tail_prune(struct iov_tail *tail); > size_t iov_tail_size(struct iov_tail *tail); > bool iov_drop_header(struct iov_tail *tail, size_t len); > void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_= t align); > +size_t iov_put_header_(struct iov_tail *tail, const void *v, size_t len); > void *iov_remove_header_(struct iov_tail *tail, void *v, size_t len, siz= e_t align); > ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > struct iov_tail *tail); > @@ -112,6 +113,16 @@ ssize_t iov_tail_clone(struct iovec *dst_iov, size_t= dst_iov_cnt, > sizeof(var_), \ > __alignof__(var_)))) > =20 > +/** > + * IOV_PUT_HEADER() - Write header back to an IOV tail > + * @tail_: IOV tail to write header to > + * @var_: Pointer to a variable containing the header data to write > + * > + * Return: number of bytes written > + */ > +#define IOV_PUT_HEADER(tail_, var_) \ > + (iov_put_header_((tail_), (var_), sizeof(*var_))) > + > /** > * IOV_REMOVE_HEADER() - Remove and return typed header from an IOV tail > * @tail_: IOV tail to remove header from (modified) > @@ -130,7 +141,8 @@ ssize_t iov_tail_clone(struct iovec *dst_iov, size_t = dst_iov_cnt, > ((__typeof__(var_) *)(iov_remove_header_((tail_), &(var_), \ > sizeof(var_), __alignof__(var_)))) > =20 > -/** IOV_DROP_HEADER() - Remove a typed header from an IOV tail > +/** > + * IOV_DROP_HEADER() - Remove a typed header from an IOV tail > * @tail_: IOV tail to remove header from (modified) > * @type_: Data type of the header to remove > * > --=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 --KkwPpNiaUxXf6lai Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmyPQ8ACgkQzQJF27ox 2GeymA/7BzHFT7dFCJvmcXWhLKhX5ZRip3Cd/3rMVQOLI6o5lcbDxDY4LTt0wBoe vqm3eo8nAXIH2PLQW6D3+qMrcjWaksZUUnaelyTJNRUw9SVkYcG4WHwiQfDrPaog PsYnf6Oj214epa6YlSGq0zxpq+M9M8zqSK4FN3iPMEtEmDIBVPXXHh6GRqKgsTTt +qK4YQNajTmbpTOJ99ps89UEI8SpRZYqYn9LNCUWrDTipQR1iBeZcyx6x8NKvura TAlFkT5zqrlZlz2ENwzL1/ffFBnK4GcZpZo3cW6TM1eqD2Y4pe8y+DizwOPoIBFM bhBwSlZyxr8BJQVYqjhCvHpIjewyiMChvyaYEjQQOdM1+Fd3e8/plhQvB8nAQ4fc 7VwyroswMhNx9UVoPxuH+koBrSpkmGkQeSE83hzFEYGliNq0dGYCacqxK7FhYVOH JZiDs3HYsapxsh9uPqTgcDKbSZx8ILzvhAB47MpM7yBpINZEN8kFOyn9kUvkxkCj Q7MMBLqVYeIZyhZj8KdOrgy40DOUVEiC/PvFH0fE+my0qypbF+bnbByysBFZNXdQ KC/4lg9+uAH34noPl5m9LlRG0KtwlX7BYvz6YMkmrJYO22bpr1vqJrzHliZ7rPOT WekUYS1xNEpN84j90pilpDLvgyEqDt0CXJ8MoztcQVc5bZpTbWM= =zV7/ -----END PGP SIGNATURE----- --KkwPpNiaUxXf6lai--