From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIETl-0003Qc-Ru for qemu-devel@nongnu.org; Wed, 29 Jun 2016 08:20:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIETh-0002ie-4L for qemu-devel@nongnu.org; Wed, 29 Jun 2016 08:20:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIETg-0002iX-Sp for qemu-devel@nongnu.org; Wed, 29 Jun 2016 08:20:25 -0400 Date: Wed, 29 Jun 2016 13:20:20 +0100 From: "Daniel P. Berrange" Message-ID: <20160629122020.GK4221@redhat.com> Reply-To: "Daniel P. Berrange" References: <1465920443-22804-1-git-send-email-berrange@redhat.com> <1465920443-22804-5-git-send-email-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v6 4/7] qom: support arbitrary non-scalar properties with -object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: QEMU , Markus Armbruster , Max Reitz , Paolo Bonzini , Andreas =?utf-8?Q?F=C3=A4rber?= On Tue, Jun 28, 2016 at 06:09:08PM +0200, Marc-Andr=C3=A9 Lureau wrote: > Hi >=20 > On Tue, Jun 14, 2016 at 6:07 PM, 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. > > > > 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. > > > > 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. > > > > 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. > > > > 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. > > > > Thus -object can now support non-scalar properties, > > for example the QMP object > > > > { > > "execute": "object-add", > > "arguments": { > > "qom-type": "demo", > > "id": "demo0", > > "parameters": { > > "foo": [ > > { "bar": "one", "wizz": "1" }, > > { "bar": "two", "wizz": "2" } > > ] > > } > > } > > } > > > > Would be creatable via the CLI now using > > > > $QEMU \ > > -object demo,id=3Ddemo0,\ > > foo.0.bar=3Done,foo.0.wizz=3D1,\ > > foo.1.bar=3Dtwo,foo.1.wizz=3D2 > > > > Notice that this syntax is intentionally compatible > > with that currently used by block drivers. > > > > This is also wired up to work for the 'object_add' command > > in the HMP monitor with the same syntax. > > > > (hmp) object_add demo,id=3Ddemo0,\ > > foo.0.bar=3Done,foo.0.wizz=3D1,\ > > foo.1.bar=3Dtwo,foo.1.wizz=3D2 > > > > NB indentation should not be used with HMP commands, this > > is just for convenient formatting in this commit message. > > > > Signed-off-by: Daniel P. Berrange >=20 > The patch breaks parsing of size arguments: >=20 > -object memory-backend-file,id=3Dmem,size=3D512M,mem-path=3D/tmp: Param= eter > 'size' expects a number >=20 >=20 > Looks like the previous patch needs type_size support Yep, I've modified the previous patch to implement the type_size callback on the QMP visitor and added a unit test case for this too. Regards, Daniel --=20 |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / :| |: http://libvirt.org -o- http://virt-manager.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vn= c :|