From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7rMp-0002Wb-5Y for qemu-devel@nongnu.org; Mon, 27 Jan 2014 13:57:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7rMi-0006od-Tv for qemu-devel@nongnu.org; Mon, 27 Jan 2014 13:57:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52072) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7rMi-0006oZ-Ky for qemu-devel@nongnu.org; Mon, 27 Jan 2014 13:57:00 -0500 Message-ID: <52E6AC72.2050601@redhat.com> Date: Mon, 27 Jan 2014 19:58:58 +0100 From: Max Reitz MIME-Version: 1.0 References: <1390762963-25538-1-git-send-email-mreitz@redhat.com> <1390762963-25538-8-git-send-email-mreitz@redhat.com> <20140127031052.GF7415@irqsave.net> In-Reply-To: <20140127031052.GF7415@irqsave.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 07/10] block: Reuse fail path from bdrv_open() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-1?Q?Beno=EEt_Canet?= Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi On 27.01.2014 04:10, Beno=EEt Canet wrote: > Le Sunday 26 Jan 2014 =E0 20:02:40 (+0100), Max Reitz a =E9crit : >> The fail paths of bdrv_file_open() and bdrv_open() naturally exhibit >> similarities, thus it is possible to reuse the one from bdrv_open() an= d >> shorten the one in bdrv_file_open() accordingly. >> >> Signed-off-by: Max Reitz >> --- >> block.c | 17 +++++++---------- >> 1 file changed, 7 insertions(+), 10 deletions(-) >> >> diff --git a/block.c b/block.c >> index 72eddd5..0f2cd3f 100644 >> --- a/block.c >> +++ b/block.c >> @@ -1038,9 +1038,6 @@ static int bdrv_file_open(BlockDriverState *bs, = const char *filename, >> =20 >> fail: >> QDECREF(options); >> - if (!bs->drv) { >> - QDECREF(bs->options); >> - } >> return ret; >> } >> =20 >> @@ -1240,17 +1237,17 @@ int bdrv_open(BlockDriverState **pbs, const ch= ar *filename, >> if (flags & BDRV_O_PROTOCOL) { >> assert(!drv); >> ret =3D bdrv_file_open(bs, filename, options, flags & ~BDRV_= O_PROTOCOL, >> - errp); >> + &local_err); >> + options =3D NULL; >> if (ret) { >> - if (*pbs) { >> - bdrv_close(bs); >> + if (bs->drv) { >> + goto close_and_fail; >> } else { >> - bdrv_unref(bs); >> + goto fail; >> } >> - } else { >> - *pbs =3D bs; >> } > Forget what I said about the goto chain in the previous mail. > > But something like: > > if(!ret) { > *pbs =3D bs; > return 0; > } > if (bs->drv) { > goto close_and_fail; > } > goto fail; > > would keep the code in line. > > Best regards > > Beno=EEt Yes, this seems better to me as well. :-) Or, after patch 9: if (!ret) { goto done; } else if (bs->drv) { goto close_and_fail; } else { goto fail; } (which I like a bit more, with the three gotos on the same indentation=20 level) Max >> + *pbs =3D bs; >> + return 0; >> } >> =20 >> bs->options =3D options; >> --=20 >> 1.8.5.3 >> >>