diff mbox

[PATCHv5,05/17] block: add wrappers for logical block provisioning information

Message ID 1382283791-11181-6-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven Oct. 20, 2013, 3:42 p.m. UTC
This adds 2 wrappers to read the unallocated_blocks_are_zero and
can_write_zeroes_with_unmap info from the BDI. The wrappers are
required to check for the existence of a backing_hd and
if the devices are opened with the correct flags.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block.c               |   30 ++++++++++++++++++++++++++++++
 include/block/block.h |    2 ++
 2 files changed, 32 insertions(+)

Comments

Eric Blake Oct. 22, 2013, 1:28 p.m. UTC | #1
On 10/20/2013 04:42 PM, Peter Lieven wrote:
> This adds 2 wrappers to read the unallocated_blocks_are_zero and
> can_write_zeroes_with_unmap info from the BDI. The wrappers are
> required to check for the existence of a backing_hd and
> if the devices are opened with the correct flags.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block.c               |   30 ++++++++++++++++++++++++++++++
>  include/block/block.h |    2 ++
>  2 files changed, 32 insertions(+)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index 0d97ce6..0601b02 100644
--- a/block.c
+++ b/block.c
@@ -3094,6 +3094,36 @@  int bdrv_has_zero_init(BlockDriverState *bs)
     return 0;
 }
 
+bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs)
+{
+    BlockDriverInfo bdi;
+
+    if (bs->backing_hd) {
+        return false;
+    }
+
+    if (bdrv_get_info(bs, &bdi) == 0) {
+        return bdi.unallocated_blocks_are_zero;
+    }
+
+    return false;
+}
+
+bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs)
+{
+    BlockDriverInfo bdi;
+
+    if (bs->backing_hd || !(bs->open_flags & BDRV_O_UNMAP)) {
+        return false;
+    }
+
+    if (bdrv_get_info(bs, &bdi) == 0) {
+        return bdi.can_write_zeroes_with_unmap;
+    }
+
+    return false;
+}
+
 typedef struct BdrvCoGetBlockStatusData {
     BlockDriverState *bs;
     BlockDriverState *base;
diff --git a/include/block/block.h b/include/block/block.h
index 5fbab01..de0d6ab 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -344,6 +344,8 @@  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);
+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,
                               int nb_sectors, int *pnum);
 int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,