Skip to contentSkip to conversation

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

PATCH Applied Paolo Bonzini 4 participants 4 messages May 14, 2015 – May 19, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: get_block_status: use "else" when testing the opposite condition

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".

---
 block/io.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
block/io.c +1 -3
index 1ce62c4..494e3b3 100644
@@ -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) {
Signature · 1 line
2.4.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Paolo Bonzini

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".

---
 block/io.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 28 lines · Paolo Bonzini

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".

---
 block/io.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
block/io.c +1 -3
index 1ce62c4..494e3b3 100644
@@ -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) {
Signature · 1 line
2.4.0
#3 lore raw
In reply to Paolo Bonzini
Quoted 9 lines · Paolo Bonzini

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".

---
 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