From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Su5FR-0003Rs-GQ for qemu-devel@nongnu.org; Wed, 25 Jul 2012 13:19:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Su5FQ-0001Af-0E for qemu-devel@nongnu.org; Wed, 25 Jul 2012 13:19:45 -0400 Received: from paradis.irqsave.net ([109.190.18.76]:50758) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Su5FP-00019t-Me for qemu-devel@nongnu.org; Wed, 25 Jul 2012 13:19:43 -0400 Date: Wed, 25 Jul 2012 19:19:34 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20120725171933.GE12455@irqsave.net> References: <1343219765-12297-1-git-send-email-benoit@irqsave.net> <1343219765-12297-2-git-send-email-benoit@irqsave.net> <50101E5D.30808@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <50101E5D.30808@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V3 1/3] block: create bdrv_get_backing_file_ancestors_count() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, benoit.canet@gmail.com, stefanha@linux.vnet.ibm.com, stefanha@gmail.com, qemu-devel@nongnu.org, pbonzini@redhat.com Le Wednesday 25 Jul 2012 =E0 10:27:09 (-0600), Eric Blake a =E9crit : > On 07/25/2012 06:36 AM, benoit.canet@gmail.com wrote: > > From: Beno=EEt Canet > >=20 > > 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. > >=20 > > Signed-off-by: Benoit Canet > > --- > > block.c | 13 +++++++++++++ > > block.h | 1 + > > 2 files changed, 14 insertions(+) > >=20 > > 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(Bloc= kDriverState *bs, > > return NULL; > > } > > =20 > > +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)= ; >=20 > 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 par= t > 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=EEt >=20 > --=20 > Eric Blake eblake@redhat.com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >=20