diff options
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -702,7 +702,7 @@ static int find_image_format(BlockDriverState *bs, const char *filename, } /** - * Set the current 'total_sectors' value + * Set the current 'total_sectors' and 'total_bytes' value * Return 0 on success, -errno on error. */ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) @@ -722,7 +722,7 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) hint = DIV_ROUND_UP(length, BDRV_SECTOR_SIZE); } - bs->total_sectors = hint; + bdrv_setlength(bs, BDRV_SECTOR_SIZE * hint); return 0; } @@ -1840,7 +1840,7 @@ void bdrv_close(BlockDriverState *bs) bs->copy_on_read = 0; bs->backing_file[0] = '\0'; bs->backing_format[0] = '\0'; - bs->total_sectors = 0; + bdrv_setlength(bs, 0); bs->encrypted = 0; bs->valid_key = 0; bs->sg = 0; @@ -3360,7 +3360,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs, bs->wr_highest_sector = sector_num + nb_sectors - 1; } if (bs->growable && ret >= 0) { - bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors); + bdrv_setlength(bs, MAX(bs->total_bytes, + BDRV_SECTOR_SIZE * (sector_num + nb_sectors))); } return ret; @@ -3563,6 +3564,19 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) return -ENOTSUP; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +/** + * Sets the initial size of a block. + */ +void bdrv_setlength(BlockDriverState *bs, uint64_t bytes) +{ + bs->total_bytes = bytes; + /* Be careful with division here, see commit 7e38200 for VMDK */ + bs->total_sectors = DIV_ROUND_UP(bytes, BDRV_SECTOR_SIZE); +} +#pragma GCC diagnostic pop + /** * Return number of sectors on success, -errno on error. */ |