From nobody Sun Oct 5 21:10:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527800185638778.331947205676; Thu, 31 May 2018 13:56:25 -0700 (PDT) Received: from localhost ([::1]:46121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOUcS-00079e-NF for importer@patchew.org; Thu, 31 May 2018 16:56:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOUXO-0003PG-51 for qemu-devel@nongnu.org; Thu, 31 May 2018 16:51:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOUXL-0001fF-1Y for qemu-devel@nongnu.org; Thu, 31 May 2018 16:51:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37702 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fOUXH-0001a4-Oi; Thu, 31 May 2018 16:51:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4EF017D83A; Thu, 31 May 2018 20:51:03 +0000 (UTC) Received: from red.redhat.com (ovpn-125-63.rdu2.redhat.com [10.10.125.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE8C51006EAB; Thu, 31 May 2018 20:51:02 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 31 May 2018 15:50:41 -0500 Message-Id: <20180531205046.153256-4-eblake@redhat.com> In-Reply-To: <20180531205046.153256-1-eblake@redhat.com> References: <20180531205046.153256-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 31 May 2018 20:51:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 31 May 2018 20:51:03 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/8] qcow: Switch qcow_co_readv to byte-based calls 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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the internals of the qcow driver read function, by iterating over offset/bytes instead of sector_num/nb_sectors, and with a rename of index_in_cluster and repurposing of n to track bytes instead of sectors. A later patch will then switch the qcow driver as a whole over to byte-based operation. Signed-off-by: Eric Blake Reviewed-by: Jeff Cody --- v2: prefer 64-bit * over 32-bit <<, rename variable for legibility [Kevin] --- block/qcow.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 42d1bbb7643..b90915218ff 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -617,13 +617,15 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVQcowState *s =3D bs->opaque; - int index_in_cluster; + int offset_in_cluster; int ret =3D 0, n; uint64_t cluster_offset; struct iovec hd_iov; QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; + int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; + int64_t bytes =3D nb_sectors * BDRV_SECTOR_SIZE; if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); @@ -637,36 +639,35 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, qemu_co_mutex_lock(&s->lock); - while (nb_sectors !=3D 0) { + while (bytes !=3D 0) { /* prepare next request */ - ret =3D get_cluster_offset(bs, sector_num << 9, - 0, 0, 0, 0, &cluster_offset); + ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset= ); if (ret < 0) { break; } - index_in_cluster =3D sector_num & (s->cluster_sectors - 1); - n =3D s->cluster_sectors - index_in_cluster; - if (n > nb_sectors) { - n =3D nb_sectors; + offset_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - offset_in_cluster; + if (n > bytes) { + n =3D bytes; } if (!cluster_offset) { if (bs->backing) { /* read from the base image */ hd_iov.iov_base =3D (void *)buf; - hd_iov.iov_len =3D n * 512; + hd_iov.iov_len =3D n; qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); /* qcow2 emits this on bs->file instead of bs->backing */ BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); - ret =3D bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov= ); + ret =3D bdrv_co_preadv(bs->backing, offset, n, &hd_qiov, 0= ); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; } } else { /* Note: in this case, no need to wait */ - memset(buf, 0, 512 * n); + memset(buf, 0, n); } } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { /* add AIO support for compressed blocks ? */ @@ -674,21 +675,19 @@ static coroutine_fn int qcow_co_readv(BlockDriverStat= e *bs, int64_t sector_num, ret =3D -EIO; break; } - memcpy(buf, - s->cluster_cache + index_in_cluster * 512, 512 * n); + memcpy(buf, s->cluster_cache + offset_in_cluster, n); } else { if ((cluster_offset & 511) !=3D 0) { ret =3D -EIO; break; } hd_iov.iov_base =3D (void *)buf; - hd_iov.iov_len =3D n * 512; + hd_iov.iov_len =3D n; qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); - ret =3D bdrv_co_readv(bs->file, - (cluster_offset >> 9) + index_in_cluster, - n, &hd_qiov); + ret =3D bdrv_co_preadv(bs->file, cluster_offset + offset_in_cl= uster, + n, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; @@ -696,8 +695,7 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, if (bs->encrypted) { assert(s->crypto); if (qcrypto_block_decrypt(s->crypto, - sector_num * BDRV_SECTOR_SIZE, b= uf, - n * BDRV_SECTOR_SIZE, NULL) < 0)= { + offset, buf, n, NULL) < 0) { ret =3D -EIO; break; } @@ -705,9 +703,9 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, } ret =3D 0; - nb_sectors -=3D n; - sector_num +=3D n; - buf +=3D n * 512; + bytes -=3D n; + offset +=3D n; + buf +=3D n; } qemu_co_mutex_unlock(&s->lock); --=20 2.14.3