qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v7 4/7] qom: support arbitrary non-scalar proper


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v7 4/7] qom: support arbitrary non-scalar properties with -object
Date: Wed, 13 Jul 2016 22:00:21 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 07/05/2016 07:11 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.
> 

> 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=demo0,\
>               foo.0.bar=one,foo.0.wizz=1,\
>               foo.1.bar=two,foo.1.wizz=2

Overall, I like it.

> 
> Notice that this syntax is intentionally compatible
> with that currently used by block drivers.

And this gives me hope that someday we may replace blockdev-add from
QemuOpts munging to direct QAPI type handling. Maybe :)  But certainly
not for 2.7.


> @@ -1721,20 +1721,12 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
>  void hmp_object_add(Monitor *mon, const QDict *qdict)
>  {
>      Error *err = NULL;
> -    QemuOpts *opts;
> -    OptsVisitor *ov;
> +    QmpInputVisitor *qiv;

Will need rebasing now that some of my qapi cleanups have landed in
master, and also depending on whether my adoption of your patch 3/7 in
my 'qapi subset F' series also lands first, since I tweaked your string
input visitor interface slightly.  But the idea is right on track.

>      Object *obj = NULL;
>  
> -    opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
> -    if (err) {
> -        hmp_handle_error(mon, &err);
> -        return;
> -    }
> -
> -    ov = opts_visitor_new(opts);
> -    obj = user_creatable_add(qdict, opts_get_visitor(ov), &err);
> -    opts_visitor_cleanup(ov);
> -    qemu_opts_del(opts);
> +    qiv = qmp_string_input_visitor_new((QObject *)qdict, true);

While this cast happens to work (because QDict currently has QObject as
its first member), it is not necessarily safe to future layout changes,
and you should probably be using QOBJECT(qdict) instead.

> +    obj = user_creatable_add(qdict, qmp_input_get_visitor(qiv), &err);
> +    qmp_input_visitor_cleanup(qiv);

That looks so much simpler, even if it does need rebasing!

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]