From bb8bf76fb1c4afa116a7f11fee559b3cca671a4a Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 16 Dec 2010 19:36:31 +0100 Subject: block: add discard support Add a new bdrv_discard method to free blocks in a mapping image, and a new drive property to set the granularity for these discard. If no discard granularity support is set discard support is disabled. Signed-off-by: Christoph Hellwig Signed-off-by: Kevin Wolf --- block.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'block.c') diff --git a/block.c b/block.c index fe07d0bbfb..9b5e9e11fe 100644 --- a/block.c +++ b/block.c @@ -1515,6 +1515,17 @@ int bdrv_has_zero_init(BlockDriverState *bs) return 1; } +int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) +{ + if (!bs->drv) { + return -ENOMEDIUM; + } + if (!bs->drv->bdrv_discard) { + return 0; + } + return bs->drv->bdrv_discard(bs, sector_num, nb_sectors); +} + /* * Returns true iff the specified sector is present in the disk image. Drivers * not implementing the functionality are assumed to not support backing files, -- cgit v1.2.3