diff options
Diffstat (limited to 'qemu-img.c')
-rw-r--r-- | qemu-img.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/qemu-img.c b/qemu-img.c index c81d6ce733..78c820e487 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1226,7 +1226,7 @@ static int img_compare(int argc, char **argv) BlockDriverState *bs1, *bs2; int64_t total_sectors1, total_sectors2; uint8_t *buf1 = NULL, *buf2 = NULL; - int pnum1, pnum2; + int64_t pnum1, pnum2; int allocated1, allocated2; int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; @@ -1374,15 +1374,17 @@ static int img_compare(int argc, char **argv) } for (;;) { - int64_t status1, status2; + int status1, status2; nb_sectors = sectors_to_process(total_sectors, sector_num); if (nb_sectors <= 0) { break; } - status1 = bdrv_get_block_status_above(bs1, NULL, sector_num, - total_sectors1 - sector_num, - &pnum1, NULL); + status1 = bdrv_block_status_above(bs1, NULL, + sector_num * BDRV_SECTOR_SIZE, + (total_sectors1 - sector_num) * + BDRV_SECTOR_SIZE, + &pnum1, NULL, NULL); if (status1 < 0) { ret = 3; error_report("Sector allocation test failed for %s", filename1); @@ -1390,25 +1392,29 @@ static int img_compare(int argc, char **argv) } allocated1 = status1 & BDRV_BLOCK_ALLOCATED; - status2 = bdrv_get_block_status_above(bs2, NULL, sector_num, - total_sectors2 - sector_num, - &pnum2, NULL); + status2 = bdrv_block_status_above(bs2, NULL, + sector_num * BDRV_SECTOR_SIZE, + (total_sectors2 - sector_num) * + BDRV_SECTOR_SIZE, + &pnum2, NULL, NULL); if (status2 < 0) { ret = 3; error_report("Sector allocation test failed for %s", filename2); goto out; } allocated2 = status2 & BDRV_BLOCK_ALLOCATED; + /* TODO: Relax this once comparison is byte-based, and we no longer + * have to worry about sector alignment */ + assert(QEMU_IS_ALIGNED(pnum1 | pnum2, BDRV_SECTOR_SIZE)); if (pnum1) { - nb_sectors = MIN(nb_sectors, pnum1); + nb_sectors = MIN(nb_sectors, pnum1 >> BDRV_SECTOR_BITS); } if (pnum2) { - nb_sectors = MIN(nb_sectors, pnum2); + nb_sectors = MIN(nb_sectors, pnum2 >> BDRV_SECTOR_BITS); } if (strict) { - if ((status1 & ~BDRV_BLOCK_OFFSET_MASK) != - (status2 & ~BDRV_BLOCK_OFFSET_MASK)) { + if (status1 != status2) { ret = 1; qprintf(quiet, "Strict mode: Offset %" PRId64 " block status mismatch!\n", @@ -1417,7 +1423,7 @@ static int img_compare(int argc, char **argv) } } if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) { - nb_sectors = MIN(pnum1, pnum2); + nb_sectors = DIV_ROUND_UP(MIN(pnum1, pnum2), BDRV_SECTOR_SIZE); } else if (allocated1 == allocated2) { if (allocated1) { ret = blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, buf1, @@ -1589,8 +1595,8 @@ static void convert_select_part(ImgConvertState *s, int64_t sector_num, static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num) { - int64_t ret, src_cur_offset; - int n, src_cur; + int64_t src_cur_offset; + int ret, n, src_cur; convert_select_part(s, sector_num, &src_cur, &src_cur_offset); @@ -1598,23 +1604,24 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num) n = MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); if (s->sector_next_status <= sector_num) { + int64_t count = n * BDRV_SECTOR_SIZE; + if (s->target_has_backing) { - int64_t count = n * BDRV_SECTOR_SIZE; ret = bdrv_block_status(blk_bs(s->src[src_cur]), (sector_num - src_cur_offset) * BDRV_SECTOR_SIZE, count, &count, NULL, NULL); - assert(ret < 0 || QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); - n = count >> BDRV_SECTOR_BITS; } else { - ret = bdrv_get_block_status_above(blk_bs(s->src[src_cur]), NULL, - sector_num - src_cur_offset, - n, &n, NULL); + ret = bdrv_block_status_above(blk_bs(s->src[src_cur]), NULL, + (sector_num - src_cur_offset) * + BDRV_SECTOR_SIZE, + count, &count, NULL, NULL); } if (ret < 0) { return ret; } + n = DIV_ROUND_UP(count, BDRV_SECTOR_SIZE); if (ret & BDRV_BLOCK_ZERO) { s->status = BLK_ZERO; |