qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH V3 1/3] block: create bdrv_get_backing_file_ance


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH V3 1/3] block: create bdrv_get_backing_file_ancestors_count()
Date: Wed, 25 Jul 2012 10:27:09 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0

On 07/25/2012 06:36 AM, address@hidden wrote:
> From: Benoît Canet <address@hidden>
> 
> Create bdrv_get_backing_file_ancestors_count() in order to be
> able to show in QMP and HMP how many ancestors backing an image a
> block device have.
> 
> Signed-off-by: Benoit Canet <address@hidden>
> ---
>  block.c |   13 +++++++++++++
>  block.h |    1 +
>  2 files changed, 14 insertions(+)
> 
> diff --git a/block.c b/block.c
> index ce7eb8f..03e0860 100644
> --- a/block.c
> +++ b/block.c
> @@ -2754,6 +2754,19 @@ BlockDriverState 
> *bdrv_find_backing_image(BlockDriverState *bs,
>      return NULL;
>  }
>  
> +int bdrv_get_backing_file_ancestors_count(BlockDriverState *bs)
> +{
> +    if (!bs->drv) {
> +        return 0;
> +    }
> +
> +    if (!bs->backing_hd) {
> +        return 0;
> +    }
> +
> +    return 1 + bdrv_get_backing_file_ancestors_count(bs->backing_hd);

Is there any risk of stack overflow for a hugely nested setup?  Then
again, I suspect you are going to run into other issues if you are
nested that deeply, before this recursion could cause overflow worth
worrying about.

This is an O(n) operation; is it worth storing the nesting depth as part
of a BlockDriverState to turn it into an O(1) operation?  That is, you
already have to do the O(n) traversal once when originally opening the
chain, so why not have opening the chain populate a struct member with
how deep the opening went, so that all future queries can just return
that struct member.  Of course, you then run into the issue that
operations that change the depth (snapshot, block streaming, and the
proposed block commit) would then be O(n) to adjust the counts of every
member of the chain, instead of O(1) because the count is computed on
the fly.  Just food for thought, and not a technical reason requiring
you to rewrite the patch unless you really like the idea.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]