From nobody Sun Oct 5 19:25:49 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 1524681466281318.91797447494434; Wed, 25 Apr 2018 11:37:46 -0700 (PDT) Received: from localhost ([::1]:38485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPIX-0001VO-GP for importer@patchew.org; Wed, 25 Apr 2018 14:37:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDa-0005xF-Js for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBPDZ-0004Qf-GD for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50118 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 1fBPDW-0004KS-66; Wed, 25 Apr 2018 14:32:34 -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 BFBCC7CBBA; Wed, 25 Apr 2018 18:32:33 +0000 (UTC) Received: from red.redhat.com (ovpn-123-175.rdu2.redhat.com [10.10.123.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 567921101E88; Wed, 25 Apr 2018 18:32:33 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:18 -0500 Message-Id: <20180425183223.580566-4-eblake@redhat.com> In-Reply-To: <20180425183223.580566-1-eblake@redhat.com> References: <20180425183223.580566-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]); Wed, 25 Apr 2018 18:32:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 25 Apr 2018 18:32:33 +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 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: Kevin Wolf , "open list:qcow" , Max Reitz 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 repurposing index_in_cluster and n to be 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 --- block/qcow.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 32730a8dd91..bf9d80fd227 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -623,6 +623,8 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, QEMUIOVector hd_qiov; uint8_t *buf; void *orig_buf; + int64_t offset =3D sector_num << BDRV_SECTOR_BITS; + int64_t bytes =3D nb_sectors << BDRV_SECTOR_BITS; if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); @@ -636,36 +638,36 @@ 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, + 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; + index_in_cluster =3D offset & (s->cluster_size - 1); + n =3D s->cluster_size - index_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 ? */ @@ -673,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 + index_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 + index_in_clu= ster, + n, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { break; @@ -695,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; } @@ -704,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