@@ -3095,6 +3095,19 @@ int bdrv_has_zero_init(BlockDriverState *bs)
return 0;
}
+int bdrv_zero_init(BlockDriverState *bs, int64_t offset, int64_t length)
+{
+ if (bs->backing_hd) {
+ return -1;
+ }
+
+ if (bs->drv->bdrv_zero_init) {
+ return bs->drv->bdrv_zero_init(bs, offset, length);
+ }
+
+ return -1;
+}
+
typedef struct BdrvCoGetBlockStatusData {
BlockDriverState *bs;
BlockDriverState *base;
@@ -315,6 +315,7 @@ void bdrv_drain_all(void);
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_zero_init(BlockDriverState *bs, int64_t offset, int64_t length);
int bdrv_has_zero_init(BlockDriverState *bs);
int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum);
@@ -227,6 +227,8 @@ struct BlockDriver {
*/
int (*bdrv_has_zero_init)(BlockDriverState *bs);
+ int (*bdrv_zero_init)(BlockDriverState *bs, int64_t offset, int64_t length);
+
QLIST_ENTRY(BlockDriver) list;
};
This field is used to zero-initialize block device. It can be used to preallocate space for the block device. Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- block.c | 13 +++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 2 ++ 3 files changed, 16 insertions(+)