summaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-07-07 07:44:59 -0500
committerKevin Wolf <kwolf@redhat.com>2017-07-10 13:18:07 +0200
commit51b0a488882328f8f02519bb47ca7e0e7fbe12ff (patch)
tree36257cf2221ea7e4e54ab7deae446d02c46f326c /qemu-img.c
parentc00716beb30ba996bd6fdfd5f41bb07e4414144f (diff)
downloadqemu-51b0a488882328f8f02519bb47ca7e0e7fbe12ff.tar.gz
block: Make bdrv_is_allocated_above() byte-based
We are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the signature of the function to use int64_t *pnum ensures that the compiler enforces that all callers are updated. For now, the io.c layer still assert()s that all callers are sector-aligned, but that can be relaxed when a later patch implements byte-based block status. Therefore, for the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_is_allocated(). But some code, particularly stream_run(), gets a lot simpler because it no longer has to mess with sectors. Leave comments where we can further simplify by switching to byte-based iterations, once later patches eliminate the need for sector-aligned operations. For ease of review, bdrv_is_allocated() was tackled separately. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 86e24335fc..f7ffb79db6 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1508,12 +1508,16 @@ static int img_compare(int argc, char **argv)
}
for (;;) {
+ int64_t count;
+
nb_sectors = sectors_to_process(total_sectors_over, sector_num);
if (nb_sectors <= 0) {
break;
}
- ret = bdrv_is_allocated_above(blk_bs(blk_over), NULL, sector_num,
- nb_sectors, &pnum);
+ ret = bdrv_is_allocated_above(blk_bs(blk_over), NULL,
+ sector_num * BDRV_SECTOR_SIZE,
+ nb_sectors * BDRV_SECTOR_SIZE,
+ &count);
if (ret < 0) {
ret = 3;
error_report("Sector allocation test failed for %s",
@@ -1521,7 +1525,10 @@ static int img_compare(int argc, char **argv)
goto out;
}
- nb_sectors = pnum;
+ /* TODO relax this once bdrv_is_allocated_above does not enforce
+ * sector alignment */
+ assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE));
+ nb_sectors = count >> BDRV_SECTOR_BITS;
if (ret) {
ret = check_empty_sectors(blk_over, sector_num, nb_sectors,
filename_over, buf1, quiet);