Message ID | 20cb22a124616b01eb6d8e901fbe8f2bc37b6e08.1385518315.git.hutao@cn.fujitsu.com |
---|---|
State | New |
Headers | show |
On 2013年11月27日 10:15, Hu Tao wrote: > 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(+) > > diff --git a/block.c b/block.c > index 382ea71..3985133 100644 > --- a/block.c > +++ b/block.c > @@ -3102,6 +3102,19 @@ int bdrv_has_zero_init(BlockDriverState *bs) > return 0; > } > > +int bdrv_preallocate(BlockDriverState *bs, int64_t offset, int64_t length) > +{ > + if (bs->backing_hd) { > + return -1; Better to use -ENOTSUP. > + } > + > + if (bs->drv->bdrv_preallocate) { > + return bs->drv->bdrv_preallocate(bs, offset, length); > + } > + > + return -1; -ENOTSUP Fam > +} > + > typedef struct BdrvCoGetBlockStatusData { > BlockDriverState *bs; > BlockDriverState *base; > diff --git a/include/block/block.h b/include/block/block.h > index 461eaa4..8d48c8a 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_preallocate(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..6ac3735 100644 > --- a/include/block/block_int.h > +++ b/include/block/block_int.h > @@ -227,6 +227,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; > }; > >
diff --git a/block.c b/block.c index 382ea71..3985133 100644 --- a/block.c +++ b/block.c @@ -3102,6 +3102,19 @@ int bdrv_has_zero_init(BlockDriverState *bs) return 0; } +int bdrv_preallocate(BlockDriverState *bs, int64_t offset, int64_t length) +{ + if (bs->backing_hd) { + return -1; + } + + if (bs->drv->bdrv_preallocate) { + return bs->drv->bdrv_preallocate(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 461eaa4..8d48c8a 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_preallocate(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..6ac3735 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -227,6 +227,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(+)