From aa70feb765cdcf80bbad92f7e6a7bb8c5509f284 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 22 Aug 2014 13:02:37 +0200 Subject: block: convert internal refresh_total_sectors to use bytes Make bdrv_nv_sectors() handle sector calculation from bytes instead of relying on refresh_total_sectors. This prepares for the removal of bs->total_sectors. Signed-off-by: Peter Wu --- block.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index c91549bb5d..2d003f0584 100644 --- a/block.c +++ b/block.c @@ -702,10 +702,10 @@ static int find_image_format(BlockDriverState *bs, const char *filename, } /** - * Set the current 'total_sectors' and 'total_bytes' value + * Set the current 'total_bytes' value * Return 0 on success, -errno on error. */ -static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) +static int refresh_total_bytes(BlockDriverState *bs, uint64_t hint) { BlockDriver *drv = bs->drv; @@ -719,10 +719,10 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) if (length < 0) { return length; } - hint = DIV_ROUND_UP(length, BDRV_SECTOR_SIZE); + hint = length; } - bdrv_setlength(bs, BDRV_SECTOR_SIZE * hint); + bdrv_setlength(bs, hint); return 0; } @@ -998,7 +998,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, goto free_and_fail; } - ret = refresh_total_sectors(bs, bs->total_sectors); + ret = refresh_total_bytes(bs, bs->total_bytes); if (ret < 0) { error_setg_errno(errp, -ret, "Could not refresh total sector count"); goto free_and_fail; @@ -3539,7 +3539,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) ret = drv->bdrv_truncate(bs, offset); if (ret == 0) { - ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); + ret = refresh_total_bytes(bs, offset); bdrv_dev_resize_cb(bs); } return ret; @@ -3588,12 +3588,13 @@ int64_t bdrv_nb_sectors(BlockDriverState *bs) return -ENOMEDIUM; if (drv->has_variable_length) { - int ret = refresh_total_sectors(bs, bs->total_sectors); + int ret = refresh_total_bytes(bs, bs->total_bytes); if (ret < 0) { return ret; } } - return bs->total_sectors; + /* Be careful with division here, see commit 7e38200 for VMDK */ + return DIV_ROUND_UP(bs->total_bytes, BDRV_SECTOR_SIZE); } /** @@ -5028,7 +5029,7 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) return; } - ret = refresh_total_sectors(bs, bs->total_sectors); + ret = refresh_total_bytes(bs, bs->total_bytes); if (ret < 0) { error_setg_errno(errp, -ret, "Could not refresh total sector count"); return; -- cgit v1.2.1