From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ai9EU-0000Cn-A5 for qemu-devel@nongnu.org; Mon, 21 Mar 2016 19:27:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ai9ET-0007lM-6g for qemu-devel@nongnu.org; Mon, 21 Mar 2016 19:27:34 -0400 References: <1457635927-23045-1-git-send-email-berrange@redhat.com> <1457636396-24983-1-git-send-email-berrange@redhat.com> <1457636396-24983-3-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <56F0835C.2020703@redhat.com> Date: Mon, 21 Mar 2016 17:27:24 -0600 MIME-Version: 1.0 In-Reply-To: <1457636396-24983-3-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="hQjnuLXBewhax31313MeeK5NLGRwHhOUm" Subject: Re: [Qemu-devel] [PATCH v3 03/10] 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: Paolo Bonzini , qemu-block@nongnu.org, Markus Armbruster , =?UTF-8?Q?Andreas_F=c3=a4rber?= , Max Reitz This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --hQjnuLXBewhax31313MeeK5NLGRwHhOUm Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 03/10/2016 11:59 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 > This is a design limitation of the way the OptsVisitor > is written. It simply iterates over the QemuOpts values > as a flat list. The support for lists is enabled by > allowing the same key to be repeated in the opts string. >=20 > It is not practical to extend the OptsVisitor to support > more complex data structures while also maintaining > the existing list handling behaviour that is relied upon > by other areas of QEMU. Zolt=C3=A1n K=C5=91v=C3=A1g=C3=B3 tried earlier with his GSoC patches for= the audio subsystem last year, but those got stalled waiting for qapi enhancements to go in. But I think your approach is indeed a bit nicer (rather than making the warty OptsVisitor even wartier, just avoid it). >=20 > Fortunately there is no existing object that implements > the UserCreatable interface that relies on the list > handling behaviour, so it is possible to swap out the > OptsVisitor for a different visitor implementation, so > -object supports non-scalar properties, thus leaving > other users of OptsVisitor unaffected. >=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 > use with -object. Indeed, nice replacement. >=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 > 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 Maybe mention that the indentation is not actually present in the real command lines typed. >=20 > Signed-off-by: Daniel P. Berrange > --- > hmp.c | 18 +-- > qom/object_interfaces.c | 20 ++- > tests/check-qom-proplist.c | 295 +++++++++++++++++++++++++++++++++++++= +++++++- > 3 files changed, 313 insertions(+), 20 deletions(-) >=20 > @@ -120,6 +120,7 @@ Object *user_creatable_add_type(const char *type, c= onst char *id, > obj =3D object_new(type); > if (qdict) { > for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) = { > + > object_property_set(obj, v, e->key, &local_err); > if (local_err) { > goto out; Spurious hunk? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --hQjnuLXBewhax31313MeeK5NLGRwHhOUm 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/ iQEcBAEBCAAGBQJW8INcAAoJEKeha0olJ0NqMHEH/2OZN9UcczO6Gels9VS7z3pp pZ5dv2ocSL583kjP6yum9VxLULPfZI7gkFT8cSrq5RSTSDUzwwodVgfKaj0K1QOH s7wcTrGEnhBQJAT794JnwjyCR3ip3wjhDk6WgP7RVbfRNMteFN+yb1s797hIbmll ekQfu1lG06j7xuiHUCRfVZyjaDOvbZ4frFsk63NW5UFn2HJHwZjlR5CUSYCIWfuX 3mtYmgeO8cekJQlaeNjHn9+dewIOmY2G8SKw8+U9BrqeSpV8BrnA9JaQ/kYFsuBN hOALwHreQFRDNMVKOufUEdJAPORqSZzn0U15CchCvOlyo6TNNTUFHmzVRPoSMBc= =E1pk -----END PGP SIGNATURE----- --hQjnuLXBewhax31313MeeK5NLGRwHhOUm--