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=YehJJaOr; 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 4F22E5A0262 for ; Fri, 27 Mar 2026 18:58:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774634321; 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=UM3YKYkb96N+986yglqS8MReWek/kosxVHmRCbPXFJg=; b=YehJJaOrc3JXCHStzUNOpemxdWeaI2jTB3JVCGBUZSvDJqITZHU+7rPj1Y2FCKuE+NY7YO gbjwQcLuhaU7lGypZUV+7HMKEGX0cWFszSmu2oxyI1mXV1KsylAn1jqCBH4C43rl/UuWCw dpp7O6NfomzvOYeRG9K3dr90VWgAJ6s= Received: from mx-prod-mc-03.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-220---pT-fIgO1m_pgxv0mSmDA-1; Fri, 27 Mar 2026 13:58:39 -0400 X-MC-Unique: --pT-fIgO1m_pgxv0mSmDA-1 X-Mimecast-MFC-AGG-ID: --pT-fIgO1m_pgxv0mSmDA_1774634319 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0D541195604F for ; Fri, 27 Mar 2026 17:58:39 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.96]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C3AF11800351; Fri, 27 Mar 2026 17:58:37 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v5 1/8] iov: Introduce iov_memset() Date: Fri, 27 Mar 2026 18:58:27 +0100 Message-ID: <20260327175834.831995-2-lvivier@redhat.com> In-Reply-To: <20260327175834.831995-1-lvivier@redhat.com> References: <20260327175834.831995-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zxHuiJtopKGyVaQqYpdhhXxJG4m_nffH0VI4JPNOy08_1774634319 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: EYDFHACQFEAUHZFCP25ASWTJU3RUOIKQ X-Message-ID-Hash: EYDFHACQFEAUHZFCP25ASWTJU3RUOIKQ 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 helper to set a range of bytes across an IO vector to a given value, similar to memset() but operating over scatter-gather buffers. It skips to the given offset and fills across iovec entries up to the requested length. Signed-off-by: Laurent Vivier --- iov.c | 27 +++++++++++++++++++++++++++ iov.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/iov.c b/iov.c index ae0743931d18..0188acdf5eba 100644 --- a/iov.c +++ b/iov.c @@ -170,6 +170,33 @@ size_t iov_truncate(struct iovec *iov, size_t iov_cnt, size_t size) return i; } +/** + * iov_memset() - Set bytes of an IO vector to a given value + * @iov: IO vector + * @iov_cnt: Number of elements in @iov + * @offset: Byte offset in the iovec at which to start + * @c: Byte value to fill with + * @length: Number of bytes to set + * Will write less than @length bytes if it runs out of space in + * the iov + */ +/* cppcheck-suppress unusedFunction */ +void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c, + size_t length) +{ + size_t i; + + i = iov_skip_bytes(iov, iov_cnt, offset, &offset); + + for ( ; i < iov_cnt && length; i++) { + size_t n = MIN(iov[i].iov_len - offset, length); + + memset((char *)iov[i].iov_base + offset, c, n); + offset = 0; + length -= n; + } +} + /** * 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 b4e50b0fca5a..d295d05b3bab 100644 --- a/iov.h +++ b/iov.h @@ -30,6 +30,8 @@ size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt, size_t offset, void *buf, size_t bytes); 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); /* * DOC: Theory of Operation, struct iov_tail -- 2.53.0