From nobody Tue May 13 10:57:41 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1681234540; cv=none; d=zohomail.com; s=zohoarc; b=PlWbrE8zrVgHuzpodrpJCvxr5m5HeikAyULAAxjkzbc9IiQKcxw8MEzkzrQp42aThB+giNc3YGC+dwHf0JLpw9rxRYB1r/qjbgbTvUCRcqNMU2TiRFSE/NDUPNBtjZYRCkNPhMoURzUTSe605Xt5GoPEQSBCcALtpkaQW0f6ks8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681234540; 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=xM9Fp2UyP8cRAV2CnXkDXMfR3w0iH91gS3/68r9J00Q=; b=OyDT6uBAMw5nVQIxfUahdjH+1u14jwsi9HntCHJSQHpYgmrex5gLH/6aksnpMf+fFgegFDULkDODX+UJO/oYESDDkiXOt+LfbjPVPVe9YpSy1SpLDzYr3c8Wyy7aAnwj1C3S7M2PSVeF5EtIBQRnNcqmB/k/EiQtZixQKHBNms4= 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+importer2=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 1681234540803623.7804530880006; Tue, 11 Apr 2023 10:35:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHt8-0004sa-3X; Tue, 11 Apr 2023 13:34:38 -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 1pmHsy-0004qa-V9 for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:34:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmHsx-00038Q-9H for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:34:28 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-34-3B6gpj1_PrO0-4L1x7-cQQ-1; Tue, 11 Apr 2023 13:34:25 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C57253C025B2; Tue, 11 Apr 2023 17:34:24 +0000 (UTC) Received: from localhost (unknown [10.39.194.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79D3514171D5; Tue, 11 Apr 2023 17:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681234466; 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=xM9Fp2UyP8cRAV2CnXkDXMfR3w0iH91gS3/68r9J00Q=; b=LUpfwgXz9nCmLrDQzFlba6PZD1oi4/u3Q+zx5/fwTIeEWHuqtBf5tn4hYjqJp1sMLB0LWB XDpxOTg8ZGNgKzfNbUCQFXixXU1es9wnr9uSyyB/CZW7sFrLtAB+3eBv+50dn09AB25Fen kBEkaSnNZAcPlWYwKYOvGF/MWcRfmlo= X-MC-Unique: 3B6gpj1_PrO0-4L1x7-cQQ-1 From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Vladimir Sementsov-Ogievskiy , Eric Blake , Kevin Wolf , Stefan Hajnoczi , Fam Zheng Subject: [PATCH v2 3/4] util/iov: Remove qemu_iovec_init_extended() Date: Tue, 11 Apr 2023 19:34:17 +0200 Message-Id: <20230411173418.19549-4-hreitz@redhat.com> In-Reply-To: <20230411173418.19549-1-hreitz@redhat.com> References: <20230411173418.19549-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.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, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681234541124100001 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 --- 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.39.1