From nobody Thu Dec 18 22:21:33 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685980052; cv=none; d=zohomail.com; s=zohoarc; b=QXjoZk1y7P96H43t0cmn9yOQkJmbg3gqFVmeMBIvwtRPzTw1jCgP3IFEO28ngB8ANiCV50UjvLbWgyZOZO2nurI1pUrvN6UFcoPv/H61Bdq2kjWliKvWD7NS0cvSwso1yupCCFEMBTyF0iezXnUENDffYGH3JB3x96D6a9HOdr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685980052; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BfJ02aGvCqfV0zX1lhxaJrquq3qvSsjbP7hNNd0fv+0=; b=QqWMMbPnPaGFjiRRDtmZ2aAG3UU5WVGH1taX2K6ZK8g6/YwYpqfgQgUhe7gKzG5y1MjHla/0ATIHB8+yve3fs908b5BN2a3G0UE7g6hSbKgvoKE+qJRupW8xHhH4/oKypoLB4dnNPM4IgeDb6O10W/R4BHJoKBRei4huAoIi9R4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16859800527391020.5857504486421; Mon, 5 Jun 2023 08:47:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6CPA-0007nF-EV; Mon, 05 Jun 2023 11:46:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q6CP3-0007jc-MT for qemu-devel@nongnu.org; Mon, 05 Jun 2023 11:45:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q6CP0-0001I3-Rj for qemu-devel@nongnu.org; Mon, 05 Jun 2023 11:45:53 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-509-m6-dilYeNxSLrzB3du-WFQ-1; Mon, 05 Jun 2023 11:45:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 86AA4801182; Mon, 5 Jun 2023 15:45:48 +0000 (UTC) Received: from localhost (unknown [10.39.194.13]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 465302166B25; Mon, 5 Jun 2023 15:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685979950; 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=BfJ02aGvCqfV0zX1lhxaJrquq3qvSsjbP7hNNd0fv+0=; b=BbtXVwVErc1KIsGJw90o5APUDIGEwMHfRqgWXd0MiBJixhFuKyVtRuHLNgnghSqeIY0i3k tlKTSp15WyyKve3QhAYcHHYLxncFACfUr42AOZt2F4gEtNkaApqAIUvM24hLZ6ZDQGnM0w PzGaf80K9KxHSNVxT0ZJUtzh67qjulo= X-MC-Unique: m6-dilYeNxSLrzB3du-WFQ-1 From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Richard Henderson Subject: [PULL 03/17] util/iov: Remove qemu_iovec_init_extended() Date: Mon, 5 Jun 2023 17:45:27 +0200 Message-Id: <20230605154541.1043261-4-hreitz@redhat.com> In-Reply-To: <20230605154541.1043261-1-hreitz@redhat.com> References: <20230605154541.1043261-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685980053664100010 Content-Type: text/plain; charset="utf-8" bdrv_pad_request() was the main user of qemu_iovec_init_extended(). HEAD^ has removed that use, so we can remove qemu_iovec_init_extended() now. The only remaining user is qemu_iovec_init_slice(), which can easily inline the small part it really needs. Note that qemu_iovec_init_extended() offered a memcpy() optimization to initialize the new I/O vector. qemu_iovec_concat_iov(), which is used to replace its functionality, does not, but calls qemu_iovec_add() for every single element. If we decide this optimization was important, we will need to re-implement it in qemu_iovec_concat_iov(), which might also benefit its pre-existing users. Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Hanna Czenczek Message-Id: <20230411173418.19549-4-hreitz@redhat.com> --- include/qemu/iov.h | 5 --- util/iov.c | 79 +++++++--------------------------------------- 2 files changed, 11 insertions(+), 73 deletions(-) diff --git a/include/qemu/iov.h b/include/qemu/iov.h index 46fadfb27a..63a1c01965 100644 --- a/include/qemu/iov.h +++ b/include/qemu/iov.h @@ -222,11 +222,6 @@ static inline void *qemu_iovec_buf(QEMUIOVector *qiov) =20 void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int n= iov); -int qemu_iovec_init_extended( - QEMUIOVector *qiov, - void *head_buf, size_t head_len, - QEMUIOVector *mid_qiov, size_t mid_offset, size_t mid_len, - void *tail_buf, size_t tail_len); void qemu_iovec_init_slice(QEMUIOVector *qiov, QEMUIOVector *source, size_t offset, size_t len); struct iovec *qemu_iovec_slice(QEMUIOVector *qiov, diff --git a/util/iov.c b/util/iov.c index 65a70449da..866fb577f3 100644 --- a/util/iov.c +++ b/util/iov.c @@ -416,70 +416,6 @@ int qemu_iovec_subvec_niov(QEMUIOVector *qiov, size_t = offset, size_t len) return niov; } =20 -/* - * Compile new iovec, combining @head_buf buffer, sub-qiov of @mid_qiov, - * and @tail_buf buffer into new qiov. - */ -int qemu_iovec_init_extended( - QEMUIOVector *qiov, - void *head_buf, size_t head_len, - QEMUIOVector *mid_qiov, size_t mid_offset, size_t mid_len, - void *tail_buf, size_t tail_len) -{ - size_t mid_head, mid_tail; - int total_niov, mid_niov =3D 0; - struct iovec *p, *mid_iov =3D NULL; - - assert(mid_qiov->niov <=3D IOV_MAX); - - if (SIZE_MAX - head_len < mid_len || - SIZE_MAX - head_len - mid_len < tail_len) - { - return -EINVAL; - } - - if (mid_len) { - mid_iov =3D qemu_iovec_slice(mid_qiov, mid_offset, mid_len, - &mid_head, &mid_tail, &mid_niov); - } - - total_niov =3D !!head_len + mid_niov + !!tail_len; - if (total_niov > IOV_MAX) { - return -EINVAL; - } - - if (total_niov =3D=3D 1) { - qemu_iovec_init_buf(qiov, NULL, 0); - p =3D &qiov->local_iov; - } else { - qiov->niov =3D qiov->nalloc =3D total_niov; - qiov->size =3D head_len + mid_len + tail_len; - p =3D qiov->iov =3D g_new(struct iovec, qiov->niov); - } - - if (head_len) { - p->iov_base =3D head_buf; - p->iov_len =3D head_len; - p++; - } - - assert(!mid_niov =3D=3D !mid_len); - if (mid_niov) { - memcpy(p, mid_iov, mid_niov * sizeof(*p)); - p[0].iov_base =3D (uint8_t *)p[0].iov_base + mid_head; - p[0].iov_len -=3D mid_head; - p[mid_niov - 1].iov_len -=3D mid_tail; - p +=3D mid_niov; - } - - if (tail_len) { - p->iov_base =3D tail_buf; - p->iov_len =3D tail_len; - } - - return 0; -} - /* * Check if the contents of subrange of qiov data is all zeroes. */ @@ -511,14 +447,21 @@ bool qemu_iovec_is_zero(QEMUIOVector *qiov, size_t of= fset, size_t bytes) void qemu_iovec_init_slice(QEMUIOVector *qiov, QEMUIOVector *source, size_t offset, size_t len) { - int ret; + struct iovec *slice_iov; + int slice_niov; + size_t slice_head, slice_tail; =20 assert(source->size >=3D len); assert(source->size - len >=3D offset); =20 - /* We shrink the request, so we can't overflow neither size_t nor MAX_= IOV */ - ret =3D qemu_iovec_init_extended(qiov, NULL, 0, source, offset, len, N= ULL, 0); - assert(ret =3D=3D 0); + slice_iov =3D qemu_iovec_slice(source, offset, len, + &slice_head, &slice_tail, &slice_niov); + if (slice_niov =3D=3D 1) { + qemu_iovec_init_buf(qiov, slice_iov[0].iov_base + slice_head, len); + } else { + qemu_iovec_init(qiov, slice_niov); + qemu_iovec_concat_iov(qiov, slice_iov, slice_niov, slice_head, len= ); + } } =20 void qemu_iovec_destroy(QEMUIOVector *qiov) --=20 2.40.1