diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-08-22 13:02:37 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-08-22 13:37:35 +0200 |
commit | aa70feb765cdcf80bbad92f7e6a7bb8c5509f284 (patch) | |
tree | a40173a9c6909517117c34e0375c511514b7e63a | |
parent | e5164735e5b674a10134894589a060a0f5f32ccc (diff) | |
download | qemu-aa70feb765cdcf80bbad92f7e6a7bb8c5509f284.tar.gz |
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 <peter@lekensteyn.nl>
-rw-r--r-- | block.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -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; |