mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-11 16:00:50 -07:00
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>
This commit is contained in:
parent
c00716beb3
commit
51b0a48888
7 changed files with 65 additions and 56 deletions
13
qemu-img.c
13
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue