From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTUpV-00051Y-9d for qemu-devel@nongnu.org; Mon, 15 Sep 2014 07:52:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTUpQ-0003Ey-LW for qemu-devel@nongnu.org; Mon, 15 Sep 2014 07:52:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTUpQ-0003Eq-Da for qemu-devel@nongnu.org; Mon, 15 Sep 2014 07:52:20 -0400 From: Markus Armbruster References: <1410549984-16110-1-git-send-email-armbru@redhat.com> <1410549984-16110-2-git-send-email-armbru@redhat.com> <20140915111734.GA25752@irqsave.net> Date: Mon, 15 Sep 2014 13:52:14 +0200 In-Reply-To: <20140915111734.GA25752@irqsave.net> (=?utf-8?Q?=22Beno=C3=AE?= =?utf-8?Q?t?= Canet"'s message of "Mon, 15 Sep 2014 13:17:35 +0200") Message-ID: <871trdw175.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/4] blockdev: Disentangle BlockDriverState and DriveInfo creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Beno=C3=AEt?= Canet Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Beno=C3=AEt Canet writes: > The Friday 12 Sep 2014 =C3=A0 21:26:21 (+0200), Markus Armbruster wrote : >> blockdev_init() mixes up BlockDriverState and DriveInfo initialization >> Finish the BlockDriverState job before starting to mess with >> DriveInfo. Easier on the eyes. >>=20 >> Signed-off-by: Markus Armbruster >> --- >> blockdev.c | 43 +++++++++++++++++++++++-------------------- >> 1 file changed, 23 insertions(+), 20 deletions(-) >>=20 >> diff --git a/blockdev.c b/blockdev.c >> index b361fbb..5ec4635 100644 >> --- a/blockdev.c >> +++ b/blockdev.c >> @@ -301,6 +301,7 @@ static DriveInfo *blockdev_init(const char *file, QD= ict *bs_opts, >> int ro =3D 0; >> int bdrv_flags =3D 0; >> int on_read_error, on_write_error; >> + BlockDriverState *bs; >> DriveInfo *dinfo; >> ThrottleConfig cfg; >> int snapshot =3D 0; >> @@ -456,26 +457,27 @@ static DriveInfo *blockdev_init(const char *file, = QDict *bs_opts, >> } >>=20=20 >> /* init */ >> + bs =3D bdrv_new(qemu_opts_id(opts), errp); >> + if (!bs) { >> + goto early_err; >> + } >> + bs->open_flags =3D snapshot ? BDRV_O_SNAPSHOT : 0; >> + bs->read_only =3D ro; >> + bs->detect_zeroes =3D detect_zeroes; >> + >> + bdrv_set_on_error(bs, on_read_error, on_write_error); >> + >> + /* disk I/O throttling */ >> + if (throttle_enabled(&cfg)) { >> + bdrv_io_limits_enable(bs); >> + bdrv_set_io_limits(bs, &cfg); >> + } >> + >> dinfo =3D g_malloc0(sizeof(*dinfo)); >> dinfo->id =3D g_strdup(qemu_opts_id(opts)); >> - dinfo->bdrv =3D bdrv_new(dinfo->id, &error); >> - if (error) { >> - error_propagate(errp, error); >> - goto bdrv_new_err; >> - } >> - dinfo->bdrv->open_flags =3D snapshot ? BDRV_O_SNAPSHOT : 0; >> - dinfo->bdrv->read_only =3D ro; >> - dinfo->bdrv->detect_zeroes =3D detect_zeroes; >> + dinfo->bdrv =3D bs; >> QTAILQ_INSERT_TAIL(&drives, dinfo, next); >>=20=20 >> - bdrv_set_on_error(dinfo->bdrv, on_read_error, on_write_error); >> - >> - /* disk I/O throttling */ >> - if (throttle_enabled(&cfg)) { >> - bdrv_io_limits_enable(dinfo->bdrv); >> - bdrv_set_io_limits(dinfo->bdrv, &cfg); >> - } >> - >> if (!file || !*file) { >> if (has_driver_specific_opts) { >> file =3D NULL; >> @@ -502,7 +504,8 @@ static DriveInfo *blockdev_init(const char *file, QD= ict *bs_opts, >> bdrv_flags |=3D ro ? 0 : BDRV_O_RDWR; >>=20=20 >> QINCREF(bs_opts); >> - ret =3D bdrv_open(&dinfo->bdrv, file, NULL, bs_opts, bdrv_flags, dr= v, &error); >> + ret =3D bdrv_open(&bs, file, NULL, bs_opts, bdrv_flags, drv, &error= ); >> + assert(bs =3D=3D dinfo->bdrv); >>=20=20 >> if (ret < 0) { >> error_setg(errp, "could not open disk image %s: %s", >> @@ -511,8 +514,9 @@ static DriveInfo *blockdev_init(const char *file, QD= ict *bs_opts, >> goto err; >> } >>=20=20 >> - if (bdrv_key_required(dinfo->bdrv)) >> + if (bdrv_key_required(bs)) { >> autostart =3D 0; >> + } >>=20=20 >> QDECREF(bs_opts); >> qemu_opts_del(opts); >> @@ -520,9 +524,8 @@ static DriveInfo *blockdev_init(const char *file, QD= ict *bs_opts, >> return dinfo; >>=20=20 >> err: >> - bdrv_unref(dinfo->bdrv); > >> + bdrv_unref(bs); > I would have moved this. > >> QTAILQ_REMOVE(&drives, dinfo, next); >> -bdrv_new_err: >> g_free(dinfo->id); >> g_free(dinfo); > > To Here. > > No functional difference but it would reflect it's goto chain role: > being in the reverse order of the allocations. You're right. In the BlockBackend series, this becomes just err: blk_unref(blk); early_err: so the disorder is just temporary. I'll change it anyway if I have to respin for some other reason. >> early_err: >> --=20 >> 1.9.3 > > Reviewed-by: Beno=C3=AEt Canet Thanks!