From nobody Sun Oct 5 21:10:50 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 1527800020466459.9512758968805; Thu, 31 May 2018 13:53:40 -0700 (PDT) Received: from localhost ([::1]:46096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOUZk-0004f5-Oi for importer@patchew.org; Thu, 31 May 2018 16:53:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOUXO-0003PE-47 for qemu-devel@nongnu.org; Thu, 31 May 2018 16:51:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOUXL-0001gJ-Qx for qemu-devel@nongnu.org; Thu, 31 May 2018 16:51:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40048 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 1fOUXJ-0001bt-28; Thu, 31 May 2018 16:51:05 -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 9125D40BC04F; Thu, 31 May 2018 20:51:04 +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 1FC5810FFE7E; Thu, 31 May 2018 20:51:04 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 31 May 2018 15:50:43 -0500 Message-Id: <20180531205046.153256-6-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.7]); Thu, 31 May 2018 20:51:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 31 May 2018 20:51:04 +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 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, 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. 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 44adeba276c..55720b006ef 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -69,7 +69,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; @@ -235,7 +234,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; @@ -613,8 +611,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; @@ -624,9 +632,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) { @@ -718,9 +725,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; @@ -730,8 +737,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 */ @@ -1108,8 +1113,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; } @@ -1194,9 +1198,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.3