diff mbox

block: get_block_status: use "else" when testing the opposite condition

Message ID 1431599702-10431-1-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini May 14, 2015, 10:35 a.m. UTC
A bit of Boolean algebra (and common sense) tells us that the
second "if" here is looking for blocks that are not allocated.
This is the opposite of the "if" that sets BDRV_BLOCK_ALLOCATED,
and thus it can use an "else".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/io.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Eric Blake May 14, 2015, 2:07 p.m. UTC | #1
On 05/14/2015 04:35 AM, Paolo Bonzini wrote:
> A bit of Boolean algebra (and common sense) tells us that the
> second "if" here is looking for blocks that are not allocated.
> This is the opposite of the "if" that sets BDRV_BLOCK_ALLOCATED,
> and thus it can use an "else".
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/io.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>
Fam Zheng May 14, 2015, 2:09 p.m. UTC | #2
On Thu, 05/14 12:35, Paolo Bonzini wrote:
> A bit of Boolean algebra (and common sense) tells us that the
> second "if" here is looking for blocks that are not allocated.
> This is the opposite of the "if" that sets BDRV_BLOCK_ALLOCATED,
> and thus it can use an "else".
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/io.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/block/io.c b/block/io.c
> index 1ce62c4..494e3b3 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -1456,9 +1456,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>  
>      if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) {
>          ret |= BDRV_BLOCK_ALLOCATED;
> -    }
> -
> -    if (!(ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO)) {
> +    } else {
>          if (bdrv_unallocated_blocks_are_zero(bs)) {
>              ret |= BDRV_BLOCK_ZERO;
>          } else if (bs->backing_hd) {
> -- 
> 2.4.0
> 

Reviewed-by: Fam Zheng <famz@redhat.com>
Stefan Hajnoczi May 19, 2015, 10:49 a.m. UTC | #3
On Thu, May 14, 2015 at 12:35:02PM +0200, Paolo Bonzini wrote:
> A bit of Boolean algebra (and common sense) tells us that the
> second "if" here is looking for blocks that are not allocated.
> This is the opposite of the "if" that sets BDRV_BLOCK_ALLOCATED,
> and thus it can use an "else".
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/io.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan
diff mbox

Patch

diff --git a/block/io.c b/block/io.c
index 1ce62c4..494e3b3 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1456,9 +1456,7 @@  static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
 
     if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) {
         ret |= BDRV_BLOCK_ALLOCATED;
-    }
-
-    if (!(ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO)) {
+    } else {
         if (bdrv_unallocated_blocks_are_zero(bs)) {
             ret |= BDRV_BLOCK_ZERO;
         } else if (bs->backing_hd) {