From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtTNE-0004KK-ML for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:30:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtTN6-0007m4-G1 for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:30:04 -0500 Received: from [222.73.24.84] (port=44631 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtTN6-0007l3-4P for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:29:56 -0500 From: Hu Tao Date: Thu, 19 Dec 2013 10:27:37 +0800 Message-Id: <521cd9f1c99d5912c7438b1714fe4d0de758344e.1387419339.git.hutao@cn.fujitsu.com> In-Reply-To: References: Subject: [Qemu-devel] [RFC PATCH v3 2/6] block: add BlockDriver.bdrv_preallocate. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Peter Lieven , hutao@cn.fujitsu.com This field is used to preallocate disk space for block device. Signed-off-by: Hu Tao --- 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