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=YnINZnlK; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 008F95A0275 for ; Fri, 27 Feb 2026 15:03:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772201033; 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=t53DE/GUSz75HH7OdIKFveTYXcbnzl6095jSWaj4kkk=; b=YnINZnlKLtuncnam43KVKWAVnaztwIyg7UBVkZKvyZ3pt6x7E3NczWZe3xqHKNWxhrZMwB snfaNZCmSD5QmZgZ4eGXeOLeRgcbWtk9RlIoHGAAYep1T8kbVdpdJQ0/67dQx4Qr8KuDhv ji4jSsGmBY9wjx04KbFl/RTSq2NEgMM= 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-694-67l4X2RuPEam5JUx0sf9mA-1; Fri, 27 Feb 2026 09:03:37 -0500 X-MC-Unique: 67l4X2RuPEam5JUx0sf9mA-1 X-Mimecast-MFC-AGG-ID: 67l4X2RuPEam5JUx0sf9mA_1772201015 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 EABEA195608E for ; Fri, 27 Feb 2026 14:03:34 +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 F380430001B9; Fri, 27 Feb 2026 14:03:33 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 01/12] iov: Add iov_tail_truncate() and iov_tail_zero_end() Date: Fri, 27 Feb 2026 15:03:19 +0100 Message-ID: <20260227140330.2216753-2-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: PiSja0iiVbRqYh1ZVR8usCMuX5PPUNfit0ZJ4pyWTug_1772201015 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 3HP7BXKSETDN65GGNDAK5E6GE2BJ6MPJ X-Message-ID-Hash: 3HP7BXKSETDN65GGNDAK5E6GE2BJ6MPJ 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: iov_tail_truncate() truncates a tail so it contains at most a given number of bytes from the current position, adjusting both the last iovec entry and the buffer count. iov_tail_zero_end() zero-fills all backing buffer bytes beyond a given number of leading bytes from the current tail position and can be used to clear trailing padding in fixed-size frames. Signed-off-by: Laurent Vivier --- iov.c | 39 +++++++++++++++++++++++++++++++++++++++ iov.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/iov.c b/iov.c index ad726daa4cd8..cb4d6fef5567 100644 --- a/iov.c +++ b/iov.c @@ -170,6 +170,45 @@ bool iov_tail_prune(struct iov_tail *tail) return !!tail->cnt; } +/** + * iov_tail_truncate() - Truncate tail to at most @size bytes + * @tail: IO vector tail (modified in place, including backing iovecs) + * @size: Maximum number of bytes to keep, relative to current tail offset + */ +/* cppcheck-suppress unusedFunction */ +void iov_tail_truncate(struct iov_tail *tail, size_t size) +{ + size_t i, off; + + i = iov_skip_bytes(tail->iov, tail->cnt, tail->off + size, &off); + + if (i < tail->cnt) { + struct iovec *last = (struct iovec *)&tail->iov[i]; + + last->iov_len = off; + tail->cnt = i + !!off; + } +} + +/** + * iov_tail_zero_end() - Zero-fill tail bytes beyond @size + * @tail: IO vector tail (backing buffers modified in place) + * @size: Number of leading bytes to preserve + */ +/* cppcheck-suppress unusedFunction */ +void iov_tail_zero_end(struct iov_tail *tail, size_t size) +{ + size_t i, off; + + i = iov_skip_bytes(tail->iov, tail->cnt, tail->off + size, &off); + + for (; i < tail->cnt; i++) { + memset((char *)tail->iov[i].iov_base + off, 0, + tail->iov[i].iov_len - off); + off = 0; + } +} + /** * iov_tail_size() - Calculate the total size of an IO vector tail * @tail: IO vector tail diff --git a/iov.h b/iov.h index d2184bfd12bd..a7b873d58134 100644 --- a/iov.h +++ b/iov.h @@ -89,6 +89,8 @@ void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align) 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); +void iov_tail_truncate(struct iov_tail *tail, size_t size); +void iov_tail_zero_end(struct iov_tail *tail, size_t size); /** * IOV_PEEK_HEADER() - Get typed pointer to a header from an IOV tail -- 2.53.0