diff mbox

[v2,08/37] block: Make bdrv_is_inserted() recursive

Message ID 1423501897-30410-9-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Feb. 9, 2015, 5:11 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 | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Eric Blake Feb. 9, 2015, 7:16 p.m. UTC | #1
On 02/09/2015 10:11 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 | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

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

> 
> diff --git a/block.c b/block.c
> index ee7dfba..dafa4b7 100644
> --- a/block.c
> +++ b/block.c
> @@ -5237,10 +5237,9 @@ bool bdrv_is_inserted(BlockDriverState *bs)
>      if (!drv) {
>          return false;
>      }
> -    if (!drv->bdrv_is_inserted) {
> -        return true;
> -    }
> -    return drv->bdrv_is_inserted(bs);
> +    return (!drv->bdrv_is_inserted || drv->bdrv_is_inserted(bs)) &&
> +           (!bs->file              || bdrv_is_inserted(bs->file)) &&
> +           (!bs->backing_hd        || bdrv_is_inserted(bs->backing_hd));
>  }
>  
>  /**
>
diff mbox

Patch

diff --git a/block.c b/block.c
index ee7dfba..dafa4b7 100644
--- a/block.c
+++ b/block.c
@@ -5237,10 +5237,9 @@  bool bdrv_is_inserted(BlockDriverState *bs)
     if (!drv) {
         return false;
     }
-    if (!drv->bdrv_is_inserted) {
-        return true;
-    }
-    return drv->bdrv_is_inserted(bs);
+    return (!drv->bdrv_is_inserted || drv->bdrv_is_inserted(bs)) &&
+           (!bs->file              || bdrv_is_inserted(bs->file)) &&
+           (!bs->backing_hd        || bdrv_is_inserted(bs->backing_hd));
 }
 
 /**