This field is used to preallocate disk space for block device. Signed-off-by: Hu Tao <hu...@cn.fujitsu.com> --- block.c | 13 +++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 3 +++ 3 files changed, 17 insertions(+)
diff --git a/block.c b/block.c index 64e7d22..b901587 100644 --- a/block.c +++ b/block.c @@ -3216,6 +3216,19 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs) return false; } +int bdrv_preallocate(BlockDriverState *bs, int64_t offset, int64_t length) +{ + if (bs->backing_hd) { + return -ENOTSUP; + } + + if (bs->drv->bdrv_preallocate) { + return bs->drv->bdrv_preallocate(bs, offset, length); + } + + return -ENOTSUP; +} + typedef struct BdrvCoGetBlockStatusData { BlockDriverState *bs; BlockDriverState *base; diff --git a/include/block/block.h b/include/block/block.h index 3732f25..bc1f277 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -349,6 +349,7 @@ int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); +int bdrv_preallocate(BlockDriverState *bs, int64_t offset, int64_t length); bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num, diff --git a/include/block/block_int.h b/include/block/block_int.h index 8b132d7..5bb1005 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -232,6 +232,9 @@ struct BlockDriver { */ int (*bdrv_has_zero_init)(BlockDriverState *bs); + int (*bdrv_preallocate)(BlockDriverState *bs, int64_t offset, + int64_t length); + QLIST_ENTRY(BlockDriver) list; }; -- 1.7.11.7