From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGV1V-0000il-JO for qemu-devel@nongnu.org; Fri, 24 Jun 2016 13:36:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGV1T-0008Ko-E2 for qemu-devel@nongnu.org; Fri, 24 Jun 2016 13:36:08 -0400 References: <1466692592-9551-1-git-send-email-kwolf@redhat.com> <1466692592-9551-2-git-send-email-kwolf@redhat.com> From: Eric Blake Message-ID: <576D6F7F.6020904@redhat.com> Date: Fri, 24 Jun 2016 11:35:59 -0600 MIME-Version: 1.0 In-Reply-To: <1466692592-9551-2-git-send-email-kwolf@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PnrBoc6S52JgtK3XqAQw1E6vxKLSXUvDf" Subject: Re: [Qemu-devel] [RFC PATCH 1/7] block/qdev: Allow node name for drive properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-block@nongnu.org Cc: armbru@redhat.com, stefanha@redhat.com, mreitz@redhat.com, famz@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --PnrBoc6S52JgtK3XqAQw1E6vxKLSXUvDf From: Eric Blake To: Kevin Wolf , qemu-block@nongnu.org Cc: armbru@redhat.com, stefanha@redhat.com, mreitz@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Message-ID: <576D6F7F.6020904@redhat.com> Subject: Re: [RFC PATCH 1/7] block/qdev: Allow node name for drive properties References: <1466692592-9551-1-git-send-email-kwolf@redhat.com> <1466692592-9551-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1466692592-9551-2-git-send-email-kwolf@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/23/2016 08:36 AM, Kevin Wolf wrote: > If a node name instead of a BlockBackend name is specified as the drive= r > for a guest device, an anonymous BlockBackend is created now. >=20 > Signed-off-by: Kevin Wolf > --- > hw/core/qdev-properties-system.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) >=20 > diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties= -system.c > index df38b8a..c5cc9cf 100644 > --- a/hw/core/qdev-properties-system.c > +++ b/hw/core/qdev-properties-system.c > @@ -72,9 +72,18 @@ static void parse_drive(DeviceState *dev, const char= *str, void **ptr, > const char *propname, Error **errp) > { > BlockBackend *blk; > + bool blk_created =3D false; > =20 > blk =3D blk_by_name(str); > if (!blk) { > + BlockDriverState *bs =3D bdrv_lookup_bs(NULL, str, NULL); So BB name takes priority, but if one is not found, you try a BDS lookup (node name) and create an anonymous BB to match. Seems okay. > + if (bs) { > + blk =3D blk_new(); > + blk_insert_bs(blk, bs); > + blk_created =3D true; > + } > + } > + if (!blk) { > error_setg(errp, "Property '%s.%s' can't find value '%s'", > object_get_typename(OBJECT(dev)), propname, str); > return; This return is safe, but looks a bit odd... > @@ -91,9 +100,16 @@ static void parse_drive(DeviceState *dev, const cha= r *str, void **ptr, > error_setg(errp, "Drive '%s' is already in use by another = device", > str); > } > - return; > + goto fail; =2E..given that you had to convert this return to a goto. > } > + > *ptr =3D blk; > + > +fail: > + if (blk_created) { > + /* If we need to keep a reference, blk_attach_dev() took it */= > + blk_unref(blk); > + } > } > =20 > static void release_drive(Object *obj, const char *name, void *opaque)= >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --PnrBoc6S52JgtK3XqAQw1E6vxKLSXUvDf Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXbW9/AAoJEKeha0olJ0NqjTMH/R0M7WAaCrmBuuele/EW2IDU cEv/2c33TG63m6ipl3JkLAXPaRVjxmAip4Csoddby/vU9xSXxp0B0Na55e45mQ0x KONDgCmwmrd6YmdWGY0YiIw5GWuXOLbOAE5XQjnq9RrFyl/ySWMBV9E/LPcDYYGj oWZGg4l/TYN7+yuzmqEpnFpZRhy/lLo1x8ocPFmxQpFSe22PPjbmmxUkZeksZmv7 ZfY9DWXlKC+OJmmfLTGfd0fvg1achAtbmBqyd4jF0VlrnjBWEyH2AYnGAsdR13eD YNWaY5Reom1DCYAbM7sA6+knfL8K8Q9CPTyDXzeCSHr3AmN3S5VT3rr3eTRtmd0= =KY+f -----END PGP SIGNATURE----- --PnrBoc6S52JgtK3XqAQw1E6vxKLSXUvDf--