Received: from eggs.gnu.org ([2001:4830:134:3::10]:37741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjVqL-0006cF-NK for qemu-devel@nongnu.org; Mon, 12 Sep 2016 14:20:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjVqG-0003uD-14 for qemu-devel@nongnu.org; Mon, 12 Sep 2016 14:20:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjVqF-0003u4-Oc for qemu-devel@nongnu.org; Mon, 12 Sep 2016 14:20:27 -0400 References: <1473088600-17930-1-git-send-email-berrange@redhat.com> <1473088600-17930-7-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <83dfd165-7ae5-ed42-bd8d-29af0095460a@redhat.com> Date: Mon, 12 Sep 2016 13:20:25 -0500 MIME-Version: 1.0 In-Reply-To: <1473088600-17930-7-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="uXwvQL7gC3GN3NdQxhrAMiwlfj5p6tgpD" Subject: Re: [Qemu-devel] [PATCH v11 6/6] qom: support arbitrary non-scalar properties with -object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Markus Armbruster , Max Reitz , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Paolo Bonzini , =?UTF-8?Q?Andreas_F=c3=a4rber?= This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --uXwvQL7gC3GN3NdQxhrAMiwlfj5p6tgpD From: Eric Blake To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Markus Armbruster , Max Reitz , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , Paolo Bonzini , =?UTF-8?Q?Andreas_F=c3=a4rber?= Message-ID: <83dfd165-7ae5-ed42-bd8d-29af0095460a@redhat.com> Subject: Re: [PATCH v11 6/6] qom: support arbitrary non-scalar properties with -object References: <1473088600-17930-1-git-send-email-berrange@redhat.com> <1473088600-17930-7-git-send-email-berrange@redhat.com> In-Reply-To: <1473088600-17930-7-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/05/2016 10:16 AM, Daniel P. Berrange wrote: > The current -object command line syntax only allows for > creation of objects with scalar properties, or a list > with a fixed scalar element type. Objects which have > properties that are represented as structs in the QAPI > schema cannot be created using -object. >=20 > The previously added qdict_crumple() method is able to > take a qdict containing a flat set of properties and > turn that into a arbitrarily nested set of dicts and > lists. By combining qemu_opts_to_qdict and qdict_crumple() > together, we can turn the opt string into a data structure > that is practically identical to that passed over QMP > when defining an object. The only difference is that all > the scalar values are represented as strings, rather than > strings, ints and bools. This is sufficient to let us > replace the OptsVisitor with the QMPInputVisitor for QObjectInputVisitor > use with -object. >=20 > Thus -object can now support non-scalar properties, > for example the QMP object >=20 > { > "execute": "object-add", > "arguments": { > "qom-type": "demo", > "id": "demo0", > "parameters": { > "foo": [ > { "bar": "one", "wizz": "1" }, > { "bar": "two", "wizz": "2" } > ] > } > } > } >=20 > Would be creatable via the CLI now using >=20 > $QEMU \ > -object demo,id=3Ddemo0,\ > foo.0.bar=3Done,foo.0.wizz=3D1,\ > foo.1.bar=3Dtwo,foo.1.wizz=3D2 >=20 > Notice that this syntax is intentionally compatible > with that currently used by block drivers. >=20 > This is also wired up to work for the 'object_add' command > in the HMP monitor with the same syntax. >=20 > (hmp) object_add demo,id=3Ddemo0,\ > foo.0.bar=3Done,foo.0.wizz=3D1,\ > foo.1.bar=3Dtwo,foo.1.wizz=3D2 >=20 > NB indentation should not be used with HMP commands, this > is just for convenient formatting in this commit message. >=20 > Signed-off-by: Daniel P. Berrange I still haven't looked closely at the intermediate patches in this series, but I do like the end result, so I'll start with a review of this one. > @@ -158,13 +167,21 @@ Object *user_creatable_add_opts(QemuOpts *opts, E= rror **errp) > { > Visitor *v; > QDict *pdict; > + QObject *pobj; > Object *obj =3D NULL; > =20 > - v =3D opts_visitor_new(opts); > pdict =3D qemu_opts_to_qdict(opts, NULL); > =20 > - obj =3D user_creatable_add(pdict, v, errp); > + pobj =3D qdict_crumple(pdict, true, errp); > + if (!pobj) { > + goto cleanup; > + } > + v =3D qobject_string_input_visitor_new(pobj); > + > + obj =3D user_creatable_add((QDict *)pobj, v, errp); This cast looks fishy; I think you want qobject_to_qdict(pobj) for absolute safety (if some future change causes QDict to not contain QObject at offset 0). Besides, qdict_crumple() can return a QList instead of a QDict in some cases, so asserting that qobject_to_qdict() did not return NULL may be worthwhile to prove that this particular crumple never gives us something unexpected. > +static void test_dummy_createopts(void) > +{ > + const char *optstr =3D "qemu-dummy,id=3Ddummy0,bv=3Dyes,av=3Dallig= ator,sv=3Dhiss," > + "person.name=3Dfred,person.age=3D52,sizes.0=3D12,sizes.1=3D65,= sizes.2=3D8139," > + "addrs.0.ip=3D127.0.0.1,addrs.0.prefix=3D24,addrs.0.ipv6only=3D= yes," > + "addrs.1.ip=3D0.0.0.0,addrs.1.prefix=3D16,addrs.1.ipv6only=3Dn= o"; > + QemuOpts *opts; Actually, what happens if I do an optstr of "qemu-dummy,1=3Dfoo,2=3Dbar"?= Is that rejected (because '1' and '2' are not valid key names) or does it try to create a 2-element list instead of the usual dict? That is, if a list is something the user can trigger at the CLI, then we need better error handling than just an assertion that we actually get a QDict above. But overall I like this patch. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --uXwvQL7gC3GN3NdQxhrAMiwlfj5p6tgpD 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/ iQEcBAEBCAAGBQJX1vHpAAoJEKeha0olJ0Nqw9QIAIobRW3Iisi4K5LAivWBTsTU 0RWV3Hkq7uiVIpSRR5P6kDz1c7HKJ4Csm/3EAppfheqN9m+3P2/SKwTmQ6seBrEl SRNuN78LFaHmCAo3wQMe4vx7E3JZd+GDlh9gBT2aOSdEXNYxy2ErKcnHzBYkeG0O vqhBV81CGDIN7IgkcxfMqSLHbdB7y4IKhA3WJtJkmB9FUSRd7KuOi00mQqGSyxhr XJ+ZBAk4C2ddZlaUdiK0cIs2NHLxoSWr+yZQMDSyKvhBZN03ICQPG9I+i4mj0AyK O0oPeL7bX1QC1MzvGhv4//GPV/LBANpP5FtC+vkI822R9t6qLsxHiAXnxgJiGK4= =/sHX -----END PGP SIGNATURE----- --uXwvQL7gC3GN3NdQxhrAMiwlfj5p6tgpD--