From nobody Sun Oct 5 19:25:07 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515194233708832.7466795783806; Fri, 5 Jan 2018 15:17:13 -0800 (PST) Received: from localhost ([::1]:35251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXbEV-0003re-2J for importer@patchew.org; Fri, 05 Jan 2018 18:17:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXawq-0003P9-RN for qemu-devel@nongnu.org; Fri, 05 Jan 2018 17:58:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXawp-0000Vl-JQ for qemu-devel@nongnu.org; Fri, 05 Jan 2018 17:58:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48130) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eXawk-0000Q6-DC; Fri, 05 Jan 2018 17:58:42 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7692C4ACBB; Fri, 5 Jan 2018 22:58:41 +0000 (UTC) Received: from red.redhat.com (ovpn-124-124.rdu2.redhat.com [10.10.124.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C32E60BE7; Fri, 5 Jan 2018 22:58:40 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 5 Jan 2018 16:57:49 -0600 Message-Id: <20180105225753.30509-17-eblake@redhat.com> In-Reply-To: <20180105225753.30509-1-eblake@redhat.com> References: <20180105225753.30509-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 05 Jan 2018 22:58:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 16/20] vdi: Switch to .bdrv_co_block_status() 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, vsementsov@virtuozzo.com, famz@redhat.com, qemu-block@nongnu.org, Stefan Weil , jcody@redhat.com, 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. Update the vdi driver accordingly. Note that the TODO is already covered (the block layer guarantees bounds of its requests), and that we can remove the now-unused s->block_sectors. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng --- v6-v7: no change v5: fix pnum when offset rounded down to block_size [Vladimir] v4: rebase to interface tweak v3: no change v2: rebase to mapping flag --- block/vdi.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 6f83221ddc..f309562d36 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -171,8 +171,6 @@ typedef struct { uint32_t *bmap; /* Size of block (bytes). */ uint32_t block_size; - /* Size of block (sectors). */ - uint32_t block_sectors; /* First sector of block map. */ uint32_t bmap_sector; /* VDI header (converted to host endianness). */ @@ -462,7 +460,6 @@ static int vdi_open(BlockDriverState *bs, QDict *option= s, int flags, bs->total_sectors =3D header.disk_size / SECTOR_SIZE; s->block_size =3D header.block_size; - s->block_sectors =3D header.block_size / SECTOR_SIZE; s->bmap_sector =3D header.offset_bmap / SECTOR_SIZE; s->header =3D header; @@ -508,33 +505,29 @@ static int vdi_reopen_prepare(BDRVReopenState *state, return 0; } -static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **= file) +static int coroutine_fn vdi_co_block_status(BlockDriverState *bs, + bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) { - /* TODO: Check for too large sector_num (in bdrv_is_allocated or here)= . */ BDRVVdiState *s =3D (BDRVVdiState *)bs->opaque; - size_t bmap_index =3D sector_num / s->block_sectors; - size_t sector_in_block =3D sector_num % s->block_sectors; - int n_sectors =3D s->block_sectors - sector_in_block; + size_t bmap_index =3D offset / s->block_size; + size_t index_in_block =3D offset % s->block_size; uint32_t bmap_entry =3D le32_to_cpu(s->bmap[bmap_index]); - uint64_t offset; int result; - logout("%p, %" PRId64 ", %d, %p\n", bs, sector_num, nb_sectors, pnum); - if (n_sectors > nb_sectors) { - n_sectors =3D nb_sectors; - } - *pnum =3D n_sectors; + logout("%p, %" PRId64 ", %" PRId64 ", %p\n", bs, offset, bytes, pnum); + *pnum =3D MIN(s->block_size - index_in_block, bytes); result =3D VDI_IS_ALLOCATED(bmap_entry); if (!result) { return 0; } - offset =3D s->header.offset_data + - (uint64_t)bmap_entry * s->block_size + - sector_in_block * SECTOR_SIZE; + *map =3D s->header.offset_data + (uint64_t)bmap_entry * s->block_size + + index_in_block; *file =3D bs->file->bs; - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset; + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } static int coroutine_fn @@ -902,7 +895,7 @@ static BlockDriver bdrv_vdi =3D { .bdrv_child_perm =3D bdrv_format_default_perms, .bdrv_create =3D vdi_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_co_get_block_status =3D vdi_co_get_block_status, + .bdrv_co_block_status =3D vdi_co_block_status, .bdrv_make_empty =3D vdi_make_empty, .bdrv_co_preadv =3D vdi_co_preadv, --=20 2.14.3