From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVzVX-0003up-QS for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVzVW-00040X-TR for qemu-devel@nongnu.org; Fri, 14 Jul 2017 08:15:43 -0400 From: Eric Blake Date: Fri, 14 Jul 2017 07:14:47 -0500 Message-Id: <20170714121457.10322-11-eblake@redhat.com> In-Reply-To: <20170714121457.10322-1-eblake@redhat.com> References: <20170714121457.10322-1-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v2 10/20] qcow: Switch to .bdrv_co_block_status() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, famz@redhat.com, jsnow@redhat.com, kwolf@redhat.com, Max Reitz We are gradually moving away from sector-based interfaces, towards byte-based. Update the qcow driver accordingly. There is no intent to optimize based on the mapping flag for this format. Signed-off-by: Eric Blake --- v2: rebase to mapping flag --- block/qcow.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 66827d6..38dd191 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -486,20 +486,25 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, return cluster_offset; } -static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file) +static int64_t coroutine_fn qcow_co_block_status(BlockDriverState *bs, + bool mapping, + int64_t offset, int64_t bytes, + int64_t *pnum, + BlockDriverState **file) { BDRVQcowState *s = bs->opaque; - int index_in_cluster, n; + int index_in_cluster; + int64_t n; uint64_t cluster_offset; qemu_co_mutex_lock(&s->lock); - cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0); + cluster_offset = get_cluster_offset(bs, offset, 0, 0, 0, 0); qemu_co_mutex_unlock(&s->lock); - index_in_cluster = sector_num & (s->cluster_sectors - 1); - n = s->cluster_sectors - index_in_cluster; - if (n > nb_sectors) - n = nb_sectors; + index_in_cluster = offset & (s->cluster_size - 1); + n = s->cluster_size - index_in_cluster; + if (n > bytes) { + n = bytes; + } *pnum = n; if (!cluster_offset) { return 0; @@ -507,7 +512,7 @@ static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs, if ((cluster_offset & QCOW_OFLAG_COMPRESSED) || s->crypto) { return BDRV_BLOCK_DATA; } - cluster_offset |= (index_in_cluster << BDRV_SECTOR_BITS); + cluster_offset |= (index_in_cluster & BDRV_BLOCK_OFFSET_MASK); *file = bs->file->bs; return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | cluster_offset; } @@ -1076,7 +1081,7 @@ static BlockDriver bdrv_qcow = { .bdrv_co_readv = qcow_co_readv, .bdrv_co_writev = qcow_co_writev, - .bdrv_co_get_block_status = qcow_co_get_block_status, + .bdrv_co_block_status = qcow_co_block_status, .bdrv_make_empty = qcow_make_empty, .bdrv_co_pwritev_compressed = qcow_co_pwritev_compressed, -- 2.9.4