From nobody Sun Oct 5 20:58:03 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 1530218950242388.40724026800285; Thu, 28 Jun 2018 13:49:10 -0700 (PDT) Received: from localhost ([::1]:38519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdqn-000278-Hk for importer@patchew.org; Thu, 28 Jun 2018 16:49:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdKN-0007yz-7s for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:15:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdKK-0007eL-6w for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:15:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49690 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 1fYdKH-0007Y9-F2; Thu, 28 Jun 2018 16:15:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22D4681A8EB3; Thu, 28 Jun 2018 20:15:33 +0000 (UTC) Received: from red.redhat.com (ovpn-125-113.rdu2.redhat.com [10.10.125.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 598CF2142F20; Thu, 28 Jun 2018 20:15:32 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 15:15:22 -0500 Message-Id: <20180628201525.281787-6-eblake@redhat.com> In-Reply-To: <20180628201525.281787-1-eblake@redhat.com> References: <20180628201525.281787-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 28 Jun 2018 20:15:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 28 Jun 2018 20:15:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v3 5/8] qcow: Switch to a byte-based driver 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, famz@redhat.com, qemu-block@nongnu.org, jcody@redhat.com, mreitz@redhat.com, stefanha@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. The qcow driver is now ready to fully utilize the byte-based callback interface, as long as we override the default alignment to still be 512 (needed at least for asserts present because of encryption, but easier to do everywhere than to audit which sub-sector requests are handled correctly, especially since we no longer recommend qcow for new disk images). Signed-off-by: Eric Blake Reviewed-by: Jeff Cody --- v2: minor rebase to changes earlier in series --- block/qcow.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index d2af7b8e025..fd3fafb9903 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -70,7 +70,6 @@ typedef struct QCowHeader { typedef struct BDRVQcowState { int cluster_bits; int cluster_size; - int cluster_sectors; int l2_bits; int l2_size; unsigned int l1_size; @@ -236,7 +235,6 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, } s->cluster_bits =3D header.cluster_bits; s->cluster_size =3D 1 << s->cluster_bits; - s->cluster_sectors =3D 1 << (s->cluster_bits - 9); s->l2_bits =3D header.l2_bits; s->l2_size =3D 1 << s->l2_bits; bs->total_sectors =3D header.size / 512; @@ -614,8 +612,18 @@ static int decompress_cluster(BlockDriverState *bs, ui= nt64_t cluster_offset) return 0; } -static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector= _num, - int nb_sectors, QEMUIOVector *qiov) +static void qcow_refresh_limits(BlockDriverState *bs, Error **errp) +{ + /* At least encrypted images require 512-byte alignment. Apply the + * limit universally, rather than just on encrypted images, as + * it's easier to let the block layer handle rounding than to + * audit this code further. */ + bs->bl.request_alignment =3D BDRV_SECTOR_SIZE; +} + +static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, uint64_t offs= et, + uint64_t bytes, QEMUIOVector *qiov, + int flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -625,9 +633,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_SIZE; - int64_t bytes =3D nb_sectors * BDRV_SECTOR_SIZE; + assert(!flags); if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { @@ -719,9 +726,9 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, return ret; } -static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t secto= r_num, - int nb_sectors, QEMUIOVector *qiov, - int flags) +static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, uint64_t off= set, + uint64_t bytes, QEMUIOVector *qiov, + int flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -731,8 +738,6 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, 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; assert(!flags); s->cluster_cache_offset =3D -1; /* disable compressed cache */ @@ -1105,8 +1110,7 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uint= 64_t offset, if (ret !=3D Z_STREAM_END || out_len >=3D s->cluster_size) { /* could not compress: write normal cluster */ - ret =3D qcow_co_writev(bs, offset >> BDRV_SECTOR_BITS, - bytes >> BDRV_SECTOR_BITS, qiov, 0); + ret =3D qcow_co_pwritev(bs, offset, bytes, qiov, 0); if (ret < 0) { goto fail; } @@ -1191,9 +1195,10 @@ static BlockDriver bdrv_qcow =3D { .bdrv_co_create_opts =3D qcow_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .supports_backing =3D true, + .bdrv_refresh_limits =3D qcow_refresh_limits, - .bdrv_co_readv =3D qcow_co_readv, - .bdrv_co_writev =3D qcow_co_writev, + .bdrv_co_preadv =3D qcow_co_preadv, + .bdrv_co_pwritev =3D qcow_co_pwritev, .bdrv_co_block_status =3D qcow_co_block_status, .bdrv_make_empty =3D qcow_make_empty, --=20 2.14.4