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=T9hqY0MI; 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 061425A0773 for ; Mon, 23 Mar 2026 17:53:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774284792; 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=pHWFe86pJtTl/lUpIAPnjCKjSX3mVf0P+d4bmVfiOAs=; b=T9hqY0MIRHjZlA/SmkEp97nuFjPduOLclLUGKCRnrGS0Zt9qr3brIZoqy3oJqbgZsN158E uqtbsLqCYm6mlzHcnnFTyOURZgOlBh40YKB3Dzz0e/k0mu9C59+yiGHButH3/0L9SKt0QD hJgOUZbcVLDJP3utw7/R2vgkHgl5oNs= 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-568-xVyV3z_VOAW2W5DgtI8q5g-1; Mon, 23 Mar 2026 12:53:11 -0400 X-MC-Unique: xVyV3z_VOAW2W5DgtI8q5g-1 X-Mimecast-MFC-AGG-ID: xVyV3z_VOAW2W5DgtI8q5g_1774284790 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 B6BDC1955EAC for ; Mon, 23 Mar 2026 16:53:10 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.96]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BFF44300019F; Mon, 23 Mar 2026 16:53:09 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 6/7] iov: introduce iov_memcopy() Date: Mon, 23 Mar 2026 17:52:58 +0100 Message-ID: <20260323165259.1253482-7-lvivier@redhat.com> In-Reply-To: <20260323165259.1253482-1-lvivier@redhat.com> References: <20260323165259.1253482-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: 4awHTb1BG2zeCSsk1gSu2bupbiswvy70s260BGlXilk_1774284790 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: XSVHDCKDC7JYHQHPSZZENGZZGQUW666H X-Message-ID-Hash: XSVHDCKDC7JYHQHPSZZENGZZGQUW666H 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: Copy buffers data from one iovec array to another. Signed-off-by: Laurent Vivier --- iov.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ iov.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/iov.c b/iov.c index c1eda9941f32..55263ec10b44 100644 --- a/iov.c +++ b/iov.c @@ -196,6 +196,52 @@ void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c, } } +/** + * iov_memcopy() - Copy data between two iovec arrays + * @dst_iov: Destination iovec array + * @dst_iov_cnt: Number of elements in destination iovec array + * @dst_offs: Destination offset + * @iov: Source iovec array + * @iov_cnt: Number of elements in source iovec array + * @offs: Source offset + * + * Return: total number of bytes copied + */ +/* cppcheck-suppress unusedFunction */ +size_t iov_memcopy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offs, + const struct iovec *iov, size_t iov_cnt, size_t offs) +{ + unsigned int i, j; + size_t total = 0; + + i = iov_skip_bytes(iov, iov_cnt, offs, &offs); + j = iov_skip_bytes(dst_iov, dst_iov_cnt, dst_offs, &dst_offs); + + /* copying data */ + while (i < iov_cnt && j < dst_iov_cnt) { + size_t len = MIN(dst_iov[j].iov_len - dst_offs, + iov[i].iov_len - offs); + + memcpy((char *)dst_iov[j].iov_base + dst_offs, + (const char *)iov[i].iov_base + offs, len); + + dst_offs += len; + offs += len; + total += len; + + if (dst_offs == dst_iov[j].iov_len) { + dst_offs = 0; + j++; + } + if (offs == iov[i].iov_len) { + offs = 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 4ce425ccdbe5..d3c51dc8d6da 100644 --- a/iov.h +++ b/iov.h @@ -32,6 +32,8 @@ 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_memcopy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offs, + const struct iovec *iov, size_t iov_cnt, size_t offs); /* * DOC: Theory of Operation, struct iov_tail -- 2.53.0