Patchwork [v3,15/19] block: use bdrv_has_zero_init to return BDRV_BLOCK_ZERO

login
register
mail settings
Submitter Paolo Bonzini
Date July 25, 2013, 2:23 p.m.
Message ID <1374762197-7261-16-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/261714/
State New
Headers show

Comments

Paolo Bonzini - July 25, 2013, 2:23 p.m.
Alternatively, this could use a "discard zeroes data" flag returned
by bdrv_get_info.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Kevin Wolf - July 31, 2013, 9:16 a.m.
Am 25.07.2013 um 16:23 hat Paolo Bonzini geschrieben:
> Alternatively, this could use a "discard zeroes data" flag returned
> by bdrv_get_info.
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 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 7cfbf71..fc1da56 100644
> --- a/block.c
> +++ b/block.c
> @@ -2991,6 +2991,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;
> @@ -3007,7 +3008,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);

I think here you should check for ret < 0 before modifying bits.

> +    if (!(ret & BDRV_BLOCK_DATA) && bdrv_has_zero_init(bs)) {
> +        ret |= BDRV_BLOCK_ZERO;
> +    }
> +
> +    return ret;
>  }

Kevin

Patch

diff --git a/block.c b/block.c
index 7cfbf71..fc1da56 100644
--- a/block.c
+++ b/block.c
@@ -2991,6 +2991,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;
@@ -3007,7 +3008,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() */