Message ID | 1401473631-10724-6-git-send-email-armbru@redhat.com |
---|---|
State | New |
Headers | show |
The Friday 30 May 2014 à 20:13:46 (+0200), Markus Armbruster wrote : > Instead of bdrv_getlength(). > > Replace variables length, length2 by total_sectors, nb_sectors2. > Bonus: use total_sectors instead of the slightly unclean > bs->total_sectors. > > Signed-off-by: Markus Armbruster <armbru@redhat.com> > Reviewed-by: Eric Blake <eblake@redhat.com> > --- > block.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/block.c b/block.c > index 6639d09..cfeb497 100644 > --- a/block.c > +++ b/block.c > @@ -3926,21 +3926,21 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, > int64_t sector_num, > int nb_sectors, int *pnum) > { > - int64_t length; > + int64_t total_sectors; > int64_t n; > int64_t ret, ret2; > > - length = bdrv_getlength(bs); > - if (length < 0) { > - return length; > + total_sectors = bdrv_nb_sectors(bs); > + if (total_sectors < 0) { > + return total_sectors; > } > > - if (sector_num >= (length >> BDRV_SECTOR_BITS)) { > + if (sector_num >= total_sectors) { > *pnum = 0; > return 0; > } > > - n = bs->total_sectors - sector_num; > + n = total_sectors - sector_num; > if (n < nb_sectors) { > nb_sectors = n; > } > @@ -3975,8 +3975,8 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, > ret |= BDRV_BLOCK_ZERO; > } else if (bs->backing_hd) { > BlockDriverState *bs2 = bs->backing_hd; > - int64_t length2 = bdrv_getlength(bs2); > - if (length2 >= 0 && sector_num >= (length2 >> BDRV_SECTOR_BITS)) { > + int64_t nb_sectors2 = bdrv_nb_sectors(bs2); > + if (nb_sectors2 >= 0 && sector_num >= nb_sectors2) { > ret |= BDRV_BLOCK_ZERO; > } > } > -- > 1.9.3 > > Reviewed-by: Benoit Canet <benoit@irqsave.net>
diff --git a/block.c b/block.c index 6639d09..cfeb497 100644 --- a/block.c +++ b/block.c @@ -3926,21 +3926,21 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { - int64_t length; + int64_t total_sectors; int64_t n; int64_t ret, ret2; - length = bdrv_getlength(bs); - if (length < 0) { - return length; + total_sectors = bdrv_nb_sectors(bs); + if (total_sectors < 0) { + return total_sectors; } - if (sector_num >= (length >> BDRV_SECTOR_BITS)) { + if (sector_num >= total_sectors) { *pnum = 0; return 0; } - n = bs->total_sectors - sector_num; + n = total_sectors - sector_num; if (n < nb_sectors) { nb_sectors = n; } @@ -3975,8 +3975,8 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, ret |= BDRV_BLOCK_ZERO; } else if (bs->backing_hd) { BlockDriverState *bs2 = bs->backing_hd; - int64_t length2 = bdrv_getlength(bs2); - if (length2 >= 0 && sector_num >= (length2 >> BDRV_SECTOR_BITS)) { + int64_t nb_sectors2 = bdrv_nb_sectors(bs2); + if (nb_sectors2 >= 0 && sector_num >= nb_sectors2) { ret |= BDRV_BLOCK_ZERO; } }