[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 1/4] block: add BlockDriver.bdrv_zero_init.
From: |
Hu Tao |
Subject: |
[Qemu-devel] [RFC PATCH 1/4] block: add BlockDriver.bdrv_zero_init. |
Date: |
Tue, 12 Nov 2013 15:47:19 +0800 |
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 <address@hidden>
---
block.c | 13 +++++++++++++
include/block/block.h | 1 +
include/block/block_int.h | 2 ++
3 files changed, 16 insertions(+)
diff --git a/block.c b/block.c
index 58efb5b..6bd2e8b 100644
--- a/block.c
+++ b/block.c
@@ -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;
diff --git a/include/block/block.h b/include/block/block.h
index 3560deb..a0595d1 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -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);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1666066..069b6ce 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -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;
};
--
1.8.3.1