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: Benoît Canet
Subject: Re: [Qemu-devel] [PATCH V3 1/3] block: create bdrv_get_backing_file_ancestors_count()
Date: Wed, 25 Jul 2012 19:19:34 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Le Wednesday 25 Jul 2012 à 10:27:09 (-0600), Eric Blake a écrit :
> 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.
>
I don't know.

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

Hello,

I agree that 0(1) would be way better but wouldn't it increase further
the know how required to touch the block layer.
(I think about newcomers like me implementing another feature requiring
to change the depth and not being aware of this obligation)

Benoît

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





reply via email to

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