From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JdVG6ws6; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 956525A004E for ; Fri, 27 Feb 2026 15:03:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772201023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2tVXheXZ6SfxRLFLg1wmoLEEhR5uNfyIhMuQ5wm/6Xw=; b=JdVG6ws6dl2P2bZG5i5L1sHRzn1U2y7p4ZK5pdI4Bj6bX2O807lqGDCdUcc+cTTbbbCfxm 0AxBy2qI9S9E5WWY0xNSL/20CR/R4um1b3GNwLLYSYsPurE/L9jiHC9Mrm48APkF46Eo8K cOhHcxL2nyErP0u2KyeQ/QJWIKSDaPg= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-RahlQVkRPSa41PeE62_KIA-1; Fri, 27 Feb 2026 09:03:41 -0500 X-MC-Unique: RahlQVkRPSa41PeE62_KIA-1 X-Mimecast-MFC-AGG-ID: RahlQVkRPSa41PeE62_KIA_1772201020 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A41F41956095 for ; Fri, 27 Feb 2026 14:03:40 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.225.86]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AF0B830001B9; Fri, 27 Feb 2026 14:03:39 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 05/12] iov: Add IOV_PUT_HEADER() to write header data back to iov_tail Date: Fri, 27 Feb 2026 15:03:23 +0100 Message-ID: <20260227140330.2216753-6-lvivier@redhat.com> In-Reply-To: <20260227140330.2216753-1-lvivier@redhat.com> References: <20260227140330.2216753-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: AoA6IGJkNk1b7SK00aUONH7l4-OscR-GbTAFFL-9Y3w_1772201020 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: Z52ZPLQMC4HO5D26REAMVYDBOOJFCA7I X-Message-ID-Hash: Z52ZPLQMC4HO5D26REAMVYDBOOJFCA7I X-MailFrom: lvivier@redhat.com 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: Laurent Vivier 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: 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(). Signed-off-by: Laurent Vivier --- iov.c | 22 ++++++++++++++++++++++ iov.h | 14 +++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/iov.c b/iov.c index 8836305fb701..2cf23d284e4a 100644 --- a/iov.c +++ b/iov.c @@ -296,6 +296,28 @@ void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align) return v; } +/** + * 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 = len; + + /* iov_peek_header_() already called iov_check_header() */ + if ((char *)tail->iov[0].iov_base + tail->off != v) + l = iov_from_buf(tail->iov, tail->cnt, tail->off, v, len); + + tail->off += 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 a7b873d58134..08cf60639358 100644 --- a/iov.h +++ b/iov.h @@ -86,6 +86,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, size_t align); ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, struct iov_tail *tail); @@ -110,6 +111,16 @@ void iov_tail_zero_end(struct iov_tail *tail, size_t size); sizeof(var_), \ __alignof__(var_)))) +/** + * 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) @@ -128,7 +139,8 @@ void iov_tail_zero_end(struct iov_tail *tail, size_t size); ((__typeof__(var_) *)(iov_remove_header_((tail_), &(var_), \ sizeof(var_), __alignof__(var_)))) -/** 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 * -- 2.53.0