Message ID | 521cd9f1c99d5912c7438b1714fe4d0de758344e.1387419339.git.hutao@cn.fujitsu.com |
---|---|
State | New |
Headers | show |
On Thu, Dec 19, 2013 at 10:27:37AM +0800, Hu Tao wrote: > 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; > + } Depending on the image file format it may be possible to preallocate metadata while using a backing file. Why prevent this?
On Fri, Dec 20, 2013 at 11:10:30AM +0100, Stefan Hajnoczi wrote: > On Thu, Dec 19, 2013 at 10:27:37AM +0800, Hu Tao wrote: > > 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; > > + } > > Depending on the image file format it may be possible to preallocate > metadata while using a backing file. Why prevent this? I thought in the case we have no need to preallocate forbacking file. But yes, we can also preallocate for bs when there is backing file. Thanks!
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; };
This field is used to preallocate disk space for block device. Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- block.c | 13 +++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 3 +++ 3 files changed, 17 insertions(+)