From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwXrG-0000Kv-FN for qemu-devel@nongnu.org; Mon, 16 Jun 2014 10:26:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwXr6-0008DE-CS for qemu-devel@nongnu.org; Mon, 16 Jun 2014 10:26:02 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:51403 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwXr6-0008D4-6D for qemu-devel@nongnu.org; Mon, 16 Jun 2014 10:25:52 -0400 Date: Mon, 16 Jun 2014 16:25:51 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140616142550.GB12177@irqsave.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v5 03/10] block: simplify bdrv_find_base() and bdrv_find_overlay() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jeff Cody Cc: kwolf@redhat.com, benoit.canet@irqsave.net, pkrempa@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com The Friday 13 Jun 2014 =E0 14:52:31 (-0400), Jeff Cody wrote : > This simplifies the function bdrv_find_overlay(). With this change, > bdrv_find_base() is just a subset of usage of bdrv_find_overlay(), > so this also takes advantage of that. >=20 > Reviewed-by: Eric Blake > Signed-off-by: Jeff Cody > --- > block.c | 45 ++++++++++----------------------------------- > 1 file changed, 10 insertions(+), 35 deletions(-) >=20 > diff --git a/block.c b/block.c > index f9ea1b4..83996e3 100644 > --- a/block.c > +++ b/block.c > @@ -2569,32 +2569,23 @@ int bdrv_change_backing_file(BlockDriverState *= bs, > * > * Returns NULL if bs is not found in active's image chain, > * or if active =3D=3D bs. > + * > + * Returns the bottommost base image if bs =3D=3D NULL. > */ > BlockDriverState *bdrv_find_overlay(BlockDriverState *active, > BlockDriverState *bs) > { > - BlockDriverState *overlay =3D NULL; > - BlockDriverState *intermediate; > - > - assert(active !=3D NULL); > - assert(bs !=3D NULL); > - > - /* if bs is the same as active, then by definition it has no overl= ay > - */ > - if (active =3D=3D bs) { > - return NULL; > + while (active && bs !=3D active->backing_hd) { > + active =3D active->backing_hd; > } > =20 > - intermediate =3D active; > - while (intermediate->backing_hd) { > - if (intermediate->backing_hd =3D=3D bs) { > - overlay =3D intermediate; > - break; > - } > - intermediate =3D intermediate->backing_hd; > - } > + return active; > +} > =20 > - return overlay; > +/* Given a BDS, searches for the base layer. */ > +BlockDriverState *bdrv_find_base(BlockDriverState *bs) > +{ > + return bdrv_find_overlay(bs, NULL); > } > =20 > typedef struct BlkIntermediateStates { > @@ -4376,22 +4367,6 @@ int bdrv_get_backing_file_depth(BlockDriverState= *bs) > return 1 + bdrv_get_backing_file_depth(bs->backing_hd); > } > =20 > -BlockDriverState *bdrv_find_base(BlockDriverState *bs) > -{ > - BlockDriverState *curr_bs =3D NULL; > - > - if (!bs) { > - return NULL; > - } > - > - curr_bs =3D bs; > - > - while (curr_bs->backing_hd) { > - curr_bs =3D curr_bs->backing_hd; > - } > - return curr_bs; > -} > - > /**************************************************************/ > /* async I/Os */ > =20 > --=20 > 1.8.3.1 >=20 >=20 That is a neat simplification. Reviewed-by: Benoit Canet