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=A8lQsV6S; 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 C43DF5A026E for ; Fri, 03 Apr 2026 08:20:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775197227; 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=FRScYXPDw1PsQYGrEw+yy3eneqytX+ly2UVdIEUkEsI=; b=A8lQsV6S8A0Rw1NhT1o0JMfMMsHQyb0wDS+W2WqoFjTcotOe0IPMyPXoqMmoxiokb93SpJ bdiMOl3Fs6JcmLeyFsFJJvbBb0kkxABmaU4v5EXM0JWwSWxppRcJ2pNybvrSvM8bgepuCp ws5VbJkSMjBp0r9Ev1zgiI5CGEb1xd4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-PHRqdCVDOxWc0N4qI3G4nw-1; Fri, 03 Apr 2026 02:20:26 -0400 X-MC-Unique: PHRqdCVDOxWc0N4qI3G4nw-1 X-Mimecast-MFC-AGG-ID: PHRqdCVDOxWc0N4qI3G4nw_1775197225 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48889eae7bfso8763945e9.0 for ; Thu, 02 Apr 2026 23:20:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775197225; x=1775802025; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FRScYXPDw1PsQYGrEw+yy3eneqytX+ly2UVdIEUkEsI=; b=BUCqlPNpD6fdOzowAITie8359Lunn5hnosuatZXrgwnujWSF2NGU4NgYr4tm5jW2VT zfHAiXbABVnTRbUNeSeT9lIwjgyurd0He/q5TR4INufH6w/Q1vl6L+r/q4GnvEs6re0z N/4+tq0IEiBMbCVOn51gMXC2tOvJBrKKF7i+bPblEGbMpZL94iuU3+tIOMBtt/Rr+3SF t2SYc3KXSd+fXeOuph0OuGy1lx9QRt+ZhY55OM3VK4EQWqjvGpnmLp3t1xE31BlAqqk0 052XAnJs6Nxfc7uBIX4I/HrWRjTyWUn0S7INrpz07i7otAxTyzIXWRsK3BsHMEpeKGdP 5vzw== X-Gm-Message-State: AOJu0YxdVAqc4GKzwIkWDDppSmsVj1ztgMBxjhcqgvMGYGcSQcSi5F2V K7Y5ahCFhKF3O1uaVKfveny3k/RkFOzD4J7IPt0Vrw05HfbhtZqUnRr7LRkR8Ix0LAibNn7jFE/ 2VQa487i1Ykx8/Ao6RPRf78Y5Y7p4VzsZMJxHGwiCXKYbmAUEgAv/uI1LqoQ9wYrkejwTXmEjvL 22c0EanwL2zAeF8/nHxrkDqncUrNCeFEzOMHJ2 X-Gm-Gg: ATEYQzxc4/tPwduMyZK8oQG9u0nxdl5HawLsivUNYm5ikjuVRrozyja9Qi6LMFS94Le tSGbu4zbNq4ZrqxaLx7RxF/t8fMUrDOLHuUTYFk0RlTvySrHJ4B41tSOWYSGBsqTZk5+0zBsDk7 Qd2TxDvA/AfeR+6b/6lvvsRVfkG8refv5Y14ZjOJarGvagRV6LTIfg45KadAgR4IC+TGx6s9rGy ZhLHuaiMbETnjEtNJo6abvR1HKhmQNvKTV+DFkR4g2QT8UGP/O+40t1otc3vcmfP5cRrckE5RIV EeDHnAAjGr+jBeBwtI8EZgGGpMfqaKwR4OOdwv9JxfBMSS+IbKGHgR4Hkzb+HKT30CO0Q0PM6oP 7L1R+lVsXR/GQo+/kkIUz00xjbFi0WbbA X-Received: by 2002:a05:600c:3550:b0:487:1108:48b8 with SMTP id 5b1f17b1804b1-488996cd8edmr24812745e9.2.1775197219974; Thu, 02 Apr 2026 23:20:19 -0700 (PDT) X-Received: by 2002:a05:600c:3550:b0:487:1108:48b8 with SMTP id 5b1f17b1804b1-488996cd8edmr24812045e9.2.1775197219073; Thu, 02 Apr 2026 23:20:19 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4887e967badsm320114585e9.14.2026.04.02.23.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 23:20:18 -0700 (PDT) From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH 02/10] iov: Add iov_memcopy() to copy data between iovec arrays Message-ID: <20260403082017.0b91aa2c@elisabeth> In-Reply-To: <20260401191826.1782394-3-lvivier@redhat.com> References: <20260401191826.1782394-1-lvivier@redhat.com> <20260401191826.1782394-3-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Fri, 03 Apr 2026 08:20:18 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: kaP3yxSFGNwGF4CS6dKTRs45m8FF1vbC9vteQlZ2h0A_1775197225 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: RXEZAKKEURF7QN5QQ2LXO7JXFIUI5JR4 X-Message-ID-Hash: RXEZAKKEURF7QN5QQ2LXO7JXFIUI5JR4 X-MailFrom: sbrivio@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: 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: Nits, all about names: On Wed, 1 Apr 2026 21:18:18 +0200 Laurent Vivier wrote: > Add a helper to copy data from a source iovec array to a destination > iovec array, each starting at an arbitrary byte offset, iterating > through both arrays simultaneously and copying in chunks matching the > smaller of the two current segments. > > Signed-off-by: Laurent Vivier > --- > iov.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > iov.h | 3 +++ > 2 files changed, 55 insertions(+) > > diff --git a/iov.c b/iov.c > index 0188acdf5eba..83b683f3976a 100644 > --- a/iov.c > +++ b/iov.c > @@ -197,6 +197,58 @@ void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c, > } > } > > +/** > + * iov_memcopy() - Copy data between two iovec arrays Wouldn't it be less surprising to call this iov_memcpy(), like memcpy()? > + * @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 I think @src_iov and @src_iov_cnt would make the whole function easier to follow and look more symmetric. > + * @offs: Source offset What about @dst_offset and @src_offset? "offs" as a short-form for "offset" isn't really obvious (to me at least). > + * @length: Number of bytes to copy > + * > + * 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, > + size_t length) > +{ > + 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 (length && i < iov_cnt && j < dst_iov_cnt) { > + size_t n = MIN(dst_iov[j].iov_len - dst_offs, > + iov[i].iov_len - offs); > + > + if (n > length) > + n = length; > + > + memcpy((char *)dst_iov[j].iov_base + dst_offs, > + (const char *)iov[i].iov_base + offs, n); > + > + dst_offs += n; > + offs += n; > + total += n; > + length -= n; > + > + 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 d295d05b3bab..074266e127ef 100644 > --- a/iov.h > +++ b/iov.h > @@ -32,6 +32,9 @@ 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, > + size_t length); > > /* > * DOC: Theory of Operation, struct iov_tail -- Stefano