From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnRkV-0001eZ-Eu for qemu-devel@nongnu.org; Fri, 14 Jun 2013 07:00:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UnRkT-0007bz-19 for qemu-devel@nongnu.org; Fri, 14 Jun 2013 07:00:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnRkS-0007bW-Ot for qemu-devel@nongnu.org; Fri, 14 Jun 2013 07:00:52 -0400 Message-ID: <51BAF79F.3070708@redhat.com> Date: Fri, 14 Jun 2013 11:59:43 +0100 From: Eric Blake MIME-Version: 1.0 References: <20130522134007.GA2051@t430s.nay.redhat.com> <20130607101230.GA32546@t430s.nay.redhat.com> <20130607101726.GB32546@t430s.nay.redhat.com> <20130614095244.GA24720@t430s.nay.redhat.com> In-Reply-To: <20130614095244.GA24720@t430s.nay.redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2ADKCIDSITCGEERFHSWTK" Subject: Re: [Qemu-devel] RFC: Full introspection support for QMP (with draft patch) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amos Kong Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, Markus Armbruster , qemu-devel , qiaonuohan@cn.fujitsu.com, Ronen Hod , lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2ADKCIDSITCGEERFHSWTK Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/14/2013 10:52 AM, Amos Kong wrote: > On Fri, Jun 07, 2013 at 06:17:26PM +0800, Amos Kong wrote: >> On Fri, Jun 07, 2013 at 06:12:30PM +0800, Amos Kong wrote: >>> Sent out a draft patch in the end of this week. It doesn't support: >>> * output all stuffs in one shot. >>> * introspect event >>> * provide metadata date >>> >>> How can we define a dynamic dict in qmp-schema.json ? >>> >>> Currently I just output the raw json dict by a string, Libvirt needs >>> parse two times, convert the string to json format. >>> >>> qmp-schema.h: auto generated head file by qapi script >>> >>> Attached some examples. >=20 >=20 > Hello all, >=20 > I defined a new type 'SchemaData', it contains 4 keys (type, name, data= , returns) >=20 > | { 'type': 'SchemaData', > | 'data': { 'type': 'str', 'name': 'str', '*data': 'str', '*returns':= 'str' } } It seems like 'type' should be an enum rather than an open-coded 'str'. Returning 'data' and 'returns' as an open-coded 'str' is not nice - it requires the client to do further parsing. I was serious when I suggested adding additional layers of formalized structure to the result. My suggestion was something like: { 'type': 'SchemaDataMember', 'data': { 'option': 'str', 'type': 'str', '*optional': 'bool' } } { 'enum': 'SchemaMetatype', 'data': [ 'command', 'type', 'event' ] } { 'type': 'SchemaData', 'data': { 'name': 'str', 'metatype': 'SchemaMetatype', '*returns': 'str', '*data': [ 'SchemaDataMember' ] } } > |=20 > | { 'command': 'query-qmp-schema', 'data': { '*type': 'str', '*name': '= str' }, > | 'returns': ['SchemaData'] } I'm still not sure whether optional filtering will be used by libvirt, or if it adds any complexity on your end (I'm not opposed to it, but I know that there hasn't been universal agreement on filtering queries yet)= =2E Again, it seems like 'type' should be an enum. Something like: { 'command': 'query-qmp-schema', 'data': { '*type': 'SchemaMetatype', '*name': 'str' }, 'returns': ['SchemaData'] } >=20 > Then we can provice meaningful result to Libvirt. Currently I set a str= ing > for SchemaData['data']. >=20 >=20 > I tried to define a dynamical dict for 'data', but it's failed.=20 >=20 > | { 'type': 'SchemaData', > | 'data': { 'type': 'str', 'name': 'str', '*data': '**', '*returns': = 'str' } } (Failed!!) >=20 >=20 > Does qapi support to define a dynamical dict, then I can convert dict s= tring > and set to SchemaData['data'] ? Rather, you want to take an arbitrary dict, and turn it into an array describing each key of the dict. That is, given the .json file containin= g: { 'command': 'add_client', 'data': { 'protocol': 'str', 'fdname': 'str', '*skipauth': 'bool', '*tls': 'bool' } } you would create an array of four members, describing each of the four dict members, resulting in this exchange: =3D> { "execute": "query-qmp-schema", "arguments": { "name": "add_client" } } <=3D { "return": [ { "name": "add_client", "type": "command", "data": [ { "name": "protocol", "type": "str" }, { "name": "fdname", "type": "str" }, { "name": "skipauth", "type": "bool", "optional": true }, { "name": "tls", "type": "bool", "optional": true } ] } ] } --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2ADKCIDSITCGEERFHSWTK Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRuvefAAoJEKeha0olJ0NqUFIIAICxODr4cCSGhZ1x3DpRf/iN aKfPktk8QRXL7aYzRUSurQj2xkVOY9i7+A3geklemc/FnjNSlA3YSOO95iGTzXBB /OlrD/KMSsV9euMzhJNzcuyZl1o1Fiovto/SElVS4CnJCYYtvdu6HpARL8Sm+v0o Tdq5CleaxIX+1Ro4/dUXjvhZRGHDA+jCz1OC080Um4SeyAvJJMsT7aAKwSZxOHgJ 8CLO+3ZVnEfqCg4DFi+C46Zbzso4ZkPVOEs2wxQCwoqM1q6m+SKCVhcBHJgkUhEF fWuSl4RwvuffVAtO6VgevuV9K8YM2pJvCcxsEBKQXaAmr92FfChwScjHvj3HyUg= =RLps -----END PGP SIGNATURE----- ------enig2ADKCIDSITCGEERFHSWTK--