From nobody Mon Nov 10 19:45:52 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1558428464; cv=none; d=zoho.com; s=zohoarc; b=DtVK8ECajKm8gGmJwMIT1eOjn4VyLSsRIF5A8U3a7KEF64M0LuD5kPQmuH02ygAeZvKmcdTTnTYPmb1D/3t0ElIttbCtQdiandkZLmUNUyFkwWcQcL0i1xMeqk0t9NYOZ7RESt67C9Qfl4Qgw5BBIyZ8eZywvKB/mc9mosOK4K4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558428464; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SPLvbiEZoCN45SXX3UOoWk1wFuo5tbK0Qpepg0I+4Ys=; b=HoOKv8Vr62q+7sMxMabd+QxhaMzipwLuaLlgrJAlhCRAJzPbCCvrE6cdVvlbIXtNslHd1EMHB2/BHpMOifBwEmmAZHmEw4UBpOjb/fdh/Nof6cPS3zLW9sTeb41JdUjXHmBv68soeN+2+TSDs9vckBRFcXNZ7ytAJ522Ioglmd4= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558428464407220.043881370623; Tue, 21 May 2019 01:47:44 -0700 (PDT) Received: from localhost ([127.0.0.1]:49023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hT0Qp-0004fI-D1 for importer@patchew.org; Tue, 21 May 2019 04:47:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hT0Op-0003bG-DZ for qemu-devel@nongnu.org; Tue, 21 May 2019 04:45:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hT0Oo-0004HE-6Q for qemu-devel@nongnu.org; Tue, 21 May 2019 04:45:31 -0400 Received: from relay.sw.ru ([185.231.240.75]:60612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hT0Ol-0004AI-Kb; Tue, 21 May 2019 04:45:27 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hT0Oh-0003ut-Nk; Tue, 21 May 2019 11:45:23 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 21 May 2019 11:45:22 +0300 Message-Id: <20190521084522.15050-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190521084522.15050-1-vsementsov@virtuozzo.com> References: <20190521084522.15050-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [RFC PATCH 3/3] block/qcow2: implement .bdrv_co_preadv_part X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implement and use new interface to get rid of hd_qiov. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 5b4e5e7537..dcfa688c13 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -75,7 +75,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) { @@ -1955,21 +1956,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 */ @@ -1988,34 +1986,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; } @@ -2063,12 +2058,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; } @@ -2083,12 +2078,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; @@ -4002,7 +3996,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; @@ -4032,7 +4027,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); @@ -5093,7 +5088,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_has_zero_init =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.18.0