From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Su4W2-0004Zt-5w for qemu-devel@nongnu.org; Wed, 25 Jul 2012 12:32:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Su4W0-0003cy-SS for qemu-devel@nongnu.org; Wed, 25 Jul 2012 12:32:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33311) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Su4W0-0003cs-Jd for qemu-devel@nongnu.org; Wed, 25 Jul 2012 12:32:48 -0400 Message-ID: <50101E5D.30808@redhat.com> Date: Wed, 25 Jul 2012 10:27:09 -0600 From: Eric Blake MIME-Version: 1.0 References: <1343219765-12297-1-git-send-email-benoit@irqsave.net> <1343219765-12297-2-git-send-email-benoit@irqsave.net> In-Reply-To: <1343219765-12297-2-git-send-email-benoit@irqsave.net> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig67F6ED80AD22371FE15C4B41" 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: benoit.canet@gmail.com Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com, stefanha@gmail.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?UTF-8?B?QmVub8OudCBDYW5ldA==?= This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig67F6ED80AD22371FE15C4B41 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 07/25/2012 06:36 AM, benoit.canet@gmail.com wrote: > From: Beno=C3=AEt 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(BlockD= riverState *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); 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. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig67F6ED80AD22371FE15C4B41 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJQEB5dAAoJEKeha0olJ0NquUcIAIvGH7vpK8ZvFLey3gpKjkyR jxPn5NbZEvqKKIb0HH8kO+g1mHWzFmikkHs42QL+R9csj7iNNQAMGlv5LVuD5DZT L8tyBH6PxWc0OZLzBTvIPlHPt4ZoGxwl9yyt1WYvvOmloyoqPnyxHcBLf67jZwnG ii3HSgbpMx8MvKhf5kuHSV0alNfgovdznjLhHildsgvUdr2JQRA+D0io1WmTQAOp EqMFOgWBwYfEBv3f3t+vwW+GA2Mz5mYTJLJW4MKh+ykZTLI6n1R4bMrfEvhid5ps mpnxWhcYhDdv/mHwVt8Br1zXg+Se5kIo/EA5K7vSZw/c9KQur3Wbcpu74N2wNhA= =1EJ4 -----END PGP SIGNATURE----- --------------enig67F6ED80AD22371FE15C4B41--