From nobody Thu Dec 18 13:24:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566937494; cv=none; d=zoho.com; s=zohoarc; b=RiXCAW9OV2rRnr4G3CpSFGda8JdCfMGm60s+4p/3DQeptaBsrsF5Jf4D9kc1FmP3+bdbI8OWG+cROzU1jiwOl5Y3JlQqMcJ3VlqHWcMSNyaY8m1nbbK0x/3GB4pjcnaCZPrPoZ5j+oZrmLCcMEB/ipNsq6+WDSOxz44m7KgPiGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566937494; h=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:ARC-Authentication-Results; bh=cVH/ythxD/5DJWqaN/TAKaB/WxY7SmecrpCzPBabuW8=; b=hNWLZNnLgZfZn03sAqiCSYFykKPYPMCU4tBNJpTjE7cUnDw7/NDq8WcL0w43uQ3zAWBxVS9x9wwfTlajYWxepdOB9JQraYE79fDExWvbJYvAgAEHPJSz+2sLQRokIa0PRw9AtMdJ9ICmH6318hAyDHAh1OJWpCZ5tpgqQGZIl5Y= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566937494526983.3096516216397; Tue, 27 Aug 2019 13:24:54 -0700 (PDT) Received: from localhost ([::1]:58136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2i1N-00061M-5I for importer@patchew.org; Tue, 27 Aug 2019 16:24:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51819) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2huw-0006qw-Uy for qemu-devel@nongnu.org; Tue, 27 Aug 2019 16:18:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2huv-000195-F6 for qemu-devel@nongnu.org; Tue, 27 Aug 2019 16:18:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33730) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2hus-000170-0v; Tue, 27 Aug 2019 16:18:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6C413B738; Tue, 27 Aug 2019 20:18:08 +0000 (UTC) Received: from localhost (ovpn-116-148.ams2.redhat.com [10.36.116.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCE3F5C207; Tue, 27 Aug 2019 20:18:03 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Tue, 27 Aug 2019 21:16:38 +0100 Message-Id: <20190827201639.30368-12-stefanha@redhat.com> In-Reply-To: <20190827201639.30368-1-stefanha@redhat.com> References: <20190827201639.30368-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 27 Aug 2019 20:18:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/12] block/qcow2: implement .bdrv_co_preadv_part X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Peter Maydell , Max Reitz , Stefan Hajnoczi , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Implement and use new interface to get rid of hd_qiov. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Stefan Hajnoczi Message-id: 20190604161514.262241-12-vsementsov@virtuozzo.com Message-Id: <20190604161514.262241-12-vsementsov@virtuozzo.com> Signed-off-by: Stefan Hajnoczi --- block/qcow2-cluster.c | 5 +++-- block/qcow2.c | 49 +++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index cc5609e27a..0e4524d450 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -452,8 +452,9 @@ static int coroutine_fn do_perform_cow_read(BlockDriver= State *bs, * interface. This avoids double I/O throttling and request tracking, * which can lead to deadlock when block layer copy-on-read is enabled. */ - ret =3D bs->drv->bdrv_co_preadv(bs, src_cluster_offset + offset_in_clu= ster, - qiov->size, qiov, 0); + ret =3D bs->drv->bdrv_co_preadv_part(bs, + src_cluster_offset + offset_in_clus= ter, + qiov->size, qiov, 0, 0); if (ret < 0) { return ret; } diff --git a/block/qcow2.c b/block/qcow2.c index b2b87d1a8d..ec1fff9dd1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -76,7 +76,8 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, uint64_t file_cluster_offset, uint64_t offset, uint64_t bytes, - QEMUIOVector *qiov); + QEMUIOVector *qiov, + size_t qiov_offset); =20 static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filen= ame) { @@ -1967,21 +1968,18 @@ out: return ret; } =20 -static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t off= set, - uint64_t bytes, QEMUIOVector *qiov, - int flags) +static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, + uint64_t offset, uint64_t byt= es, + QEMUIOVector *qiov, + size_t qiov_offset, int flags) { BDRVQcow2State *s =3D bs->opaque; int offset_in_cluster; int ret; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t cluster_offset =3D 0; - uint64_t bytes_done =3D 0; - QEMUIOVector hd_qiov; uint8_t *cluster_data =3D NULL; =20 - qemu_iovec_init(&hd_qiov, qiov->niov); - while (bytes !=3D 0) { =20 /* prepare next request */ @@ -2000,34 +1998,31 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, =20 offset_in_cluster =3D offset_into_cluster(s, offset); =20 - qemu_iovec_reset(&hd_qiov); - qemu_iovec_concat(&hd_qiov, qiov, bytes_done, cur_bytes); - switch (ret) { case QCOW2_CLUSTER_UNALLOCATED: =20 if (bs->backing) { BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); - ret =3D bdrv_co_preadv(bs->backing, offset, cur_bytes, - &hd_qiov, 0); + ret =3D bdrv_co_preadv_part(bs->backing, offset, cur_bytes, + qiov, qiov_offset, 0); if (ret < 0) { goto fail; } } else { /* Note: in this case, no need to wait */ - qemu_iovec_memset(&hd_qiov, 0, 0, cur_bytes); + qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } break; =20 case QCOW2_CLUSTER_ZERO_PLAIN: case QCOW2_CLUSTER_ZERO_ALLOC: - qemu_iovec_memset(&hd_qiov, 0, 0, cur_bytes); + qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); break; =20 case QCOW2_CLUSTER_COMPRESSED: ret =3D qcow2_co_preadv_compressed(bs, cluster_offset, offset, cur_bytes, - &hd_qiov); + qiov, qiov_offset); if (ret < 0) { goto fail; } @@ -2075,12 +2070,12 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, ret =3D -EIO; goto fail; } - qemu_iovec_from_buf(qiov, bytes_done, cluster_data, cur_by= tes); + qemu_iovec_from_buf(qiov, qiov_offset, cluster_data, cur_b= ytes); } else { BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_co_preadv(s->data_file, - cluster_offset + offset_in_cluster, - cur_bytes, &hd_qiov, 0); + ret =3D bdrv_co_preadv_part(s->data_file, + cluster_offset + offset_in_clust= er, + cur_bytes, qiov, qiov_offset, 0); if (ret < 0) { goto fail; } @@ -2095,12 +2090,11 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, =20 bytes -=3D cur_bytes; offset +=3D cur_bytes; - bytes_done +=3D cur_bytes; + qiov_offset +=3D cur_bytes; } ret =3D 0; =20 fail: - qemu_iovec_destroy(&hd_qiov); qemu_vfree(cluster_data); =20 return ret; @@ -4101,7 +4095,8 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, uint64_t file_cluster_offset, uint64_t offset, uint64_t bytes, - QEMUIOVector *qiov) + QEMUIOVector *qiov, + size_t qiov_offset) { BDRVQcow2State *s =3D bs->opaque; int ret =3D 0, csize, nb_csectors; @@ -4132,7 +4127,7 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, goto fail; } =20 - qemu_iovec_from_buf(qiov, 0, out_buf + offset_in_cluster, bytes); + qemu_iovec_from_buf(qiov, qiov_offset, out_buf + offset_in_cluster, by= tes); =20 fail: qemu_vfree(out_buf); @@ -4679,8 +4674,8 @@ static int qcow2_load_vmstate(BlockDriverState *bs, Q= EMUIOVector *qiov, BDRVQcow2State *s =3D bs->opaque; =20 BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_LOAD); - return bs->drv->bdrv_co_preadv(bs, qcow2_vm_state_offset(s) + pos, - qiov->size, qiov, 0); + return bs->drv->bdrv_co_preadv_part(bs, qcow2_vm_state_offset(s) + pos, + qiov->size, qiov, 0, 0); } =20 /* @@ -5222,7 +5217,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_has_zero_init_truncate =3D bdrv_has_zero_init_1, .bdrv_co_block_status =3D qcow2_co_block_status, =20 - .bdrv_co_preadv =3D qcow2_co_preadv, + .bdrv_co_preadv_part =3D qcow2_co_preadv_part, .bdrv_co_pwritev =3D qcow2_co_pwritev, .bdrv_co_flush_to_os =3D qcow2_co_flush_to_os, =20 --=20 2.21.0