[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/35] qemu-img: Switch get_block_status() to byte-ba
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 08/35] qemu-img: Switch get_block_status() to byte-based |
Date: |
Thu, 26 Oct 2017 15:17:14 +0200 |
From: Eric Blake <address@hidden>
We are gradually converting to byte-based interfaces, as they are
easier to reason about than sector-based. Continue by converting
an internal function (no semantic change), and simplifying its
caller accordingly.
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: John Snow <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-img.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index e9c7b30c91..af3effdec5 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2671,14 +2671,16 @@ static void dump_map_entry(OutputFormat output_format,
MapEntry *e,
}
}
-static int get_block_status(BlockDriverState *bs, int64_t sector_num,
- int nb_sectors, MapEntry *e)
+static int get_block_status(BlockDriverState *bs, int64_t offset,
+ int64_t bytes, MapEntry *e)
{
int64_t ret;
int depth;
BlockDriverState *file;
bool has_offset;
+ int nb_sectors = bytes >> BDRV_SECTOR_BITS;
+ assert(bytes < INT_MAX);
/* As an optimization, we could cache the current range of unallocated
* clusters in each file of the chain, and avoid querying the same
* range repeatedly.
@@ -2686,8 +2688,8 @@ static int get_block_status(BlockDriverState *bs, int64_t
sector_num,
depth = 0;
for (;;) {
- ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &nb_sectors,
- &file);
+ ret = bdrv_get_block_status(bs, offset >> BDRV_SECTOR_BITS, nb_sectors,
+ &nb_sectors, &file);
if (ret < 0) {
return ret;
}
@@ -2707,7 +2709,7 @@ static int get_block_status(BlockDriverState *bs, int64_t
sector_num,
has_offset = !!(ret & BDRV_BLOCK_OFFSET_VALID);
*e = (MapEntry) {
- .start = sector_num * BDRV_SECTOR_SIZE,
+ .start = offset,
.length = nb_sectors * BDRV_SECTOR_SIZE,
.data = !!(ret & BDRV_BLOCK_DATA),
.zero = !!(ret & BDRV_BLOCK_ZERO),
@@ -2837,16 +2839,12 @@ static int img_map(int argc, char **argv)
length = blk_getlength(blk);
while (curr.start + curr.length < length) {
- int64_t nsectors_left;
- int64_t sector_num;
- int n;
-
- sector_num = (curr.start + curr.length) >> BDRV_SECTOR_BITS;
+ int64_t offset = curr.start + curr.length;
+ int64_t n;
/* Probe up to 1 GiB at a time. */
- nsectors_left = DIV_ROUND_UP(length, BDRV_SECTOR_SIZE) - sector_num;
- n = MIN(1 << (30 - BDRV_SECTOR_BITS), nsectors_left);
- ret = get_block_status(bs, sector_num, n, &next);
+ n = QEMU_ALIGN_DOWN(MIN(1 << 30, length - offset), BDRV_SECTOR_SIZE);
+ ret = get_block_status(bs, offset, n, &next);
if (ret < 0) {
error_report("Could not read file metadata: %s", strerror(-ret));
--
2.13.6
- [Qemu-devel] [PULL 00/35] Block layer patches, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 02/35] qemu-iotests: Test backing_fmt with backing node reference, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 01/35] block: don't add 'driver' to options when referring to backing via node name, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 03/35] block: Allow NULL file for bdrv_get_block_status(), Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 04/35] block: Add flag to avoid wasted work in bdrv_is_allocated(), Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 07/35] block: Switch bdrv_make_zero() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 09/35] block: Convert bdrv_get_block_status() to bytes, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 06/35] qcow2: Switch is_zero_sectors() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 08/35] qemu-img: Switch get_block_status() to byte-based,
Kevin Wolf <=
- [Qemu-devel] [PULL 05/35] block: Make bdrv_round_to_clusters() signature more useful, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 12/35] block: Switch bdrv_common_block_status_above() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 10/35] block: Switch bdrv_co_get_block_status() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 15/35] qemu-img: Simplify logic in img_compare(), Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 11/35] block: Switch BdrvCoGetBlockStatusData to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 13/35] block: Switch bdrv_co_get_block_status_above() to byte-based, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 16/35] qemu-img: Speed up compare on pre-allocated larger file, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 14/35] block: Convert bdrv_get_block_status_above() to bytes, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 18/35] qemu-img: Drop redundant error message in compare, Kevin Wolf, 2017/10/26
- [Qemu-devel] [PULL 17/35] qemu-img: Add find_nonzero(), Kevin Wolf, 2017/10/26