From nobody Sun Oct 5 19:22:58 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 152468146845128.490977675834642; Wed, 25 Apr 2018 11:37:48 -0700 (PDT) Received: from localhost ([::1]:38486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPIZ-0001Xi-NT for importer@patchew.org; Wed, 25 Apr 2018 14:37:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBPDb-0005xu-3d for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBPDZ-0004RN-Sy for qemu-devel@nongnu.org; Wed, 25 Apr 2018 14:32:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58116 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 1fBPDX-0004ME-BP; Wed, 25 Apr 2018 14:32:35 -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 E6AA3EB6E5; Wed, 25 Apr 2018 18:32:34 +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 7E65110F1C05; Wed, 25 Apr 2018 18:32:34 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 Apr 2018 13:32:20 -0500 Message-Id: <20180425183223.580566-6-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.1]); Wed, 25 Apr 2018 18:32:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 25 Apr 2018 18:32:34 +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 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: 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. 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 encryption, but easier to do everywhere than to audit which sub-sector requests are handled correctly). Signed-off-by: Eric Blake --- block/qcow.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index ea81a3bf87d..75fd75cf976 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; @@ -612,8 +610,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 index_in_cluster; @@ -623,9 +631,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; + 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 index_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_BITS; - int64_t bytes =3D nb_sectors << BDRV_SECTOR_BITS; 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