diff mbox

[v5,07/38] block: Make bdrv_is_inserted() recursive

Message ID 1442589793-7105-8-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Sept. 18, 2015, 3:22 p.m. UTC
If bdrv_is_inserted() is called on the top level BDS, it should make
sure all nodes in the BDS tree are actually inserted.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Eric Blake Sept. 18, 2015, 4:20 p.m. UTC | #1
On 09/18/2015 09:22 AM, Max Reitz wrote:
> If bdrv_is_inserted() is called on the top level BDS, it should make
> sure all nodes in the BDS tree are actually inserted.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Alberto Garcia Sept. 29, 2015, 9:15 a.m. UTC | #2
On Fri 18 Sep 2015 05:22:42 PM CEST, Max Reitz wrote:
> If bdrv_is_inserted() is called on the top level BDS, it should make
> sure all nodes in the BDS tree are actually inserted.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/block.c b/block.c
> index 4a089e6..c4fa299 100644
> --- a/block.c
> +++ b/block.c
> @@ -3247,14 +3247,20 @@ void bdrv_invalidate_cache_all(Error **errp)
>  bool bdrv_is_inserted(BlockDriverState *bs)
>  {
>      BlockDriver *drv = bs->drv;
> +    BdrvChild *child;
>  
>      if (!drv) {
>          return false;
>      }
> -    if (!drv->bdrv_is_inserted) {
> -        return true;
> +    if (drv->bdrv_is_inserted) {
> +        return drv->bdrv_is_inserted(bs);
>      }

If there's drv->bdrv_is_inserted then this code stops here and does not
iterate the children, is this correct?

> -    return drv->bdrv_is_inserted(bs);
> +    QLIST_FOREACH(child, &bs->children, next) {
> +        if (!bdrv_is_inserted(child->bs)) {
> +            return false;
> +        }
> +    }
> +    return true;
>  }

Berto
Max Reitz Sept. 30, 2015, 2:32 p.m. UTC | #3
On 29.09.2015 11:15, Alberto Garcia wrote:
> On Fri 18 Sep 2015 05:22:42 PM CEST, Max Reitz wrote:
>> If bdrv_is_inserted() is called on the top level BDS, it should make
>> sure all nodes in the BDS tree are actually inserted.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  block.c | 12 +++++++++---
>>  1 file changed, 9 insertions(+), 3 deletions(-)
>>
>> diff --git a/block.c b/block.c
>> index 4a089e6..c4fa299 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -3247,14 +3247,20 @@ void bdrv_invalidate_cache_all(Error **errp)
>>  bool bdrv_is_inserted(BlockDriverState *bs)
>>  {
>>      BlockDriver *drv = bs->drv;
>> +    BdrvChild *child;
>>  
>>      if (!drv) {
>>          return false;
>>      }
>> -    if (!drv->bdrv_is_inserted) {
>> -        return true;
>> +    if (drv->bdrv_is_inserted) {
>> +        return drv->bdrv_is_inserted(bs);
>>      }
> 
> If there's drv->bdrv_is_inserted then this code stops here and does not
> iterate the children, is this correct?

Yes, that is how it's supposed to be.

Max

>> -    return drv->bdrv_is_inserted(bs);
>> +    QLIST_FOREACH(child, &bs->children, next) {
>> +        if (!bdrv_is_inserted(child->bs)) {
>> +            return false;
>> +        }
>> +    }
>> +    return true;
>>  }
> 
> Berto
>
diff mbox

Patch

diff --git a/block.c b/block.c
index 4a089e6..c4fa299 100644
--- a/block.c
+++ b/block.c
@@ -3247,14 +3247,20 @@  void bdrv_invalidate_cache_all(Error **errp)
 bool bdrv_is_inserted(BlockDriverState *bs)
 {
     BlockDriver *drv = bs->drv;
+    BdrvChild *child;
 
     if (!drv) {
         return false;
     }
-    if (!drv->bdrv_is_inserted) {
-        return true;
+    if (drv->bdrv_is_inserted) {
+        return drv->bdrv_is_inserted(bs);
     }
-    return drv->bdrv_is_inserted(bs);
+    QLIST_FOREACH(child, &bs->children, next) {
+        if (!bdrv_is_inserted(child->bs)) {
+            return false;
+        }
+    }
+    return true;
 }
 
 /**