[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 18/37] vmdk: Switch to .bdrv_co_block_status()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 18/37] vmdk: Switch to .bdrv_co_block_status() |
Date: |
Fri, 2 Mar 2018 19:54:29 +0100 |
From: Eric Blake <address@hidden>
We are gradually moving away from sector-based interfaces, towards
byte-based. Update the vmdk driver accordingly. Drop the
now-unused vmdk_find_index_in_cluster().
Also, fix a pre-existing bug: if find_extent() fails (unlikely,
since the block layer did a bounds check), then we must return a
failure, rather than 0.
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vmdk.c | 38 ++++++++++++++------------------------
1 file changed, 14 insertions(+), 24 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index ef15ddbfd3..75f84213e6 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1304,33 +1304,27 @@ static inline uint64_t
vmdk_find_offset_in_cluster(VmdkExtent *extent,
return extent_relative_offset % cluster_size;
}
-static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent,
- int64_t sector_num)
-{
- uint64_t offset;
- offset = vmdk_find_offset_in_cluster(extent, sector_num *
BDRV_SECTOR_SIZE);
- return offset / BDRV_SECTOR_SIZE;
-}
-
-static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file)
+static int coroutine_fn vmdk_co_block_status(BlockDriverState *bs,
+ bool want_zero,
+ int64_t offset, int64_t bytes,
+ int64_t *pnum, int64_t *map,
+ BlockDriverState **file)
{
BDRVVmdkState *s = bs->opaque;
int64_t index_in_cluster, n, ret;
- uint64_t offset;
+ uint64_t cluster_offset;
VmdkExtent *extent;
- extent = find_extent(s, sector_num, NULL);
+ extent = find_extent(s, offset >> BDRV_SECTOR_BITS, NULL);
if (!extent) {
- return 0;
+ return -EIO;
}
qemu_co_mutex_lock(&s->lock);
- ret = get_cluster_offset(bs, extent, NULL,
- sector_num * 512, false, &offset,
+ ret = get_cluster_offset(bs, extent, NULL, offset, false, &cluster_offset,
0, 0);
qemu_co_mutex_unlock(&s->lock);
- index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
+ index_in_cluster = vmdk_find_offset_in_cluster(extent, offset);
switch (ret) {
case VMDK_ERROR:
ret = -EIO;
@@ -1345,18 +1339,14 @@ static int64_t coroutine_fn
vmdk_co_get_block_status(BlockDriverState *bs,
ret = BDRV_BLOCK_DATA;
if (!extent->compressed) {
ret |= BDRV_BLOCK_OFFSET_VALID;
- ret |= (offset + (index_in_cluster << BDRV_SECTOR_BITS))
- & BDRV_BLOCK_OFFSET_MASK;
+ *map = cluster_offset + index_in_cluster;
}
*file = extent->file->bs;
break;
}
- n = extent->cluster_sectors - index_in_cluster;
- if (n > nb_sectors) {
- n = nb_sectors;
- }
- *pnum = n;
+ n = extent->cluster_sectors * BDRV_SECTOR_SIZE - index_in_cluster;
+ *pnum = MIN(n, bytes);
return ret;
}
@@ -2410,7 +2400,7 @@ static BlockDriver bdrv_vmdk = {
.bdrv_close = vmdk_close,
.bdrv_create = vmdk_create,
.bdrv_co_flush_to_disk = vmdk_co_flush,
- .bdrv_co_get_block_status = vmdk_co_get_block_status,
+ .bdrv_co_block_status = vmdk_co_block_status,
.bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
.bdrv_has_zero_init = vmdk_has_zero_init,
.bdrv_get_specific_info = vmdk_get_specific_info,
--
2.13.6
- [Qemu-block] [PULL 08/37] iscsi: Switch to .bdrv_co_block_status(), (continued)
- [Qemu-block] [PULL 08/37] iscsi: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 09/37] null: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 10/37] parallels: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 11/37] qcow: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 12/37] qcow2: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 13/37] qed: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 14/37] raw: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 15/37] sheepdog: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 16/37] vdi: Avoid bitrot of debugging code, Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 17/37] vdi: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 18/37] vmdk: Switch to .bdrv_co_block_status(),
Kevin Wolf <=
- [Qemu-block] [PULL 19/37] vpc: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 20/37] vvfat: Switch to .bdrv_co_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 21/37] block: Drop unused .bdrv_co_get_block_status(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 22/37] block: fix write with zero flag set and iovector provided, Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 23/37] iotest 033: add misaligned write-zeroes test via truncate, Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 26/37] aio: rename aio_context_in_iothread() to in_aio_context_home_thread(), Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 24/37] specs/qcow2: Fix documentation of the compressed cluster descriptor, Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 25/37] docs: document how to use the l2-cache-entry-size parameter, Kevin Wolf, 2018/03/02
- [Qemu-block] [PULL 27/37] block: extract AIO_WAIT_WHILE() from BlockDriverState, Kevin Wolf, 2018/03/02