diff mbox

[v2,13/17] block: use bdrv_has_zero_init to return BDRV_BLOCK_ZERO

Message ID 1373992168-26043-14-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini July 16, 2013, 4:29 p.m. UTC
Alternatively, this could use a "discard zeroes data" flag returned
by bdrv_get_info.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Peter Lieven July 17, 2013, 5:50 p.m. UTC | #1
We should change this when bdi->discard_zeroes is available.

Peter

Am 16.07.2013 um 18:29 schrieb Paolo Bonzini <pbonzini@redhat.com>:

> Alternatively, this could use a "discard zeroes data" flag returned
> by bdrv_get_info.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> block.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/block.c b/block.c
> index 7ff0716..0c867b8 100644
> --- a/block.c
> +++ b/block.c
> @@ -2977,6 +2977,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>                                                      int nb_sectors, int *pnum)
> {
>     int64_t n;
> +    int64_t ret;
> 
>     if (sector_num >= bs->total_sectors) {
>         *pnum = 0;
> @@ -2993,7 +2994,12 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>         return BDRV_BLOCK_DATA;
>     }
> 
> -    return bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum);
> +    ret = bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum);
> +    if (!(ret & BDRV_BLOCK_DATA) && bdrv_has_zero_init(bs)) {
> +        ret |= BDRV_BLOCK_ZERO;
> +    }
> +
> +    return ret;
> }
> 
> /* Coroutine wrapper for bdrv_get_block_status() */
> -- 
> 1.8.3.1
> 
>
Eric Blake July 19, 2013, 7:37 p.m. UTC | #2
On 07/16/2013 10:29 AM, Paolo Bonzini wrote:
> Alternatively, this could use a "discard zeroes data" flag returned
> by bdrv_get_info.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)

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

Patch

diff --git a/block.c b/block.c
index 7ff0716..0c867b8 100644
--- a/block.c
+++ b/block.c
@@ -2977,6 +2977,7 @@  static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
                                                      int nb_sectors, int *pnum)
 {
     int64_t n;
+    int64_t ret;
 
     if (sector_num >= bs->total_sectors) {
         *pnum = 0;
@@ -2993,7 +2994,12 @@  static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
         return BDRV_BLOCK_DATA;
     }
 
-    return bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum);
+    ret = bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum);
+    if (!(ret & BDRV_BLOCK_DATA) && bdrv_has_zero_init(bs)) {
+        ret |= BDRV_BLOCK_ZERO;
+    }
+
+    return ret;
 }
 
 /* Coroutine wrapper for bdrv_get_block_status() */