All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com
Subject: Re: [PATCH 3/3] vl: allow passing JSON to -object
Date: Thu, 11 Mar 2021 12:38:47 -0600	[thread overview]
Message-ID: <1727bd5b-e065-3e1b-d8b8-9cdf4f68d4a7@redhat.com> (raw)
In-Reply-To: <20210311172459.990281-4-pbonzini@redhat.com>

On 3/11/21 11:24 AM, Paolo Bonzini wrote:
> Extend the ObjectOption code that was added in the previous patch to
> enable passing JSON to -object.  Even though we cannot yet add
> non-scalar properties with the human-friendly comma-separated syntax,
> they can now be added as JSON.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  softmmu/vl.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index b245e912e5..7b07f19de7 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -31,6 +31,7 @@
>  #include "hw/qdev-properties.h"
>  #include "qapi/error.h"
>  #include "qapi/qmp/qdict.h"
> +#include "qapi/qmp/qjson.h"
>  #include "qemu-version.h"
>  #include "qemu/cutils.h"
>  #include "qemu/help_option.h"
> @@ -1714,19 +1715,27 @@ static void object_option_parse(const char *optarg)
>      const char *type;
>      Visitor *v;
>  
> -    opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
> -                                   optarg, true);
> -    if (!opts) {
> -        exit(1);
> -    }
> +    if (optarg[0] == '{') {
> +        QObject *obj = qobject_from_json(optarg, &error_fatal);
>  
> -    type = qemu_opt_get(opts, "qom-type");
> -    if (user_creatable_print_help(type, opts)) {
> -        exit(0);
> +        v = qobject_input_visitor_new(obj);
> +        qobject_unref(obj);

Interesting note: the JSON form has no way to access help text.  But
that's not a show-stopper.

> +    } else {
> +        opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
> +                                       optarg, true);
> +        if (!opts) {
> +            exit(1);
> +        }
> +
> +        type = qemu_opt_get(opts, "qom-type");
> +        if (user_creatable_print_help(type, opts)) {
> +            exit(0);
> +        }
> +
> +        v = opts_visitor_new(opts);
>      }
>  
>      opt = g_new0(ObjectOption, 1);
> -    v = opts_visitor_new(opts);
>      visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal);
>      visit_free(v);

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2021-03-11 18:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 17:24 [PATCH 0/3] vl: QAPIfy -object Paolo Bonzini
2021-03-11 17:24 ` [PATCH 1/3] tests: convert check-qom-proplist to keyval Paolo Bonzini
2021-03-11 18:29   ` Eric Blake
2021-03-12 10:21   ` Kevin Wolf
2021-03-11 17:24 ` [PATCH 2/3] qom: move user_creatable_add_opts logic to vl.c and QAPIfy it Paolo Bonzini
2021-03-11 18:37   ` Eric Blake
2021-03-12 10:18   ` Kevin Wolf
2021-03-13  9:35   ` Markus Armbruster
2021-03-13  9:40     ` Paolo Bonzini
2021-03-13 12:32       ` Markus Armbruster
2021-03-13  9:57   ` Markus Armbruster
2021-03-13 10:05     ` Paolo Bonzini
2021-03-11 17:24 ` [PATCH 3/3] vl: allow passing JSON to -object Paolo Bonzini
2021-03-11 18:38   ` Eric Blake [this message]
2021-03-12 10:21   ` Kevin Wolf
2021-03-13  9:41   ` Markus Armbruster
2021-03-11 17:39 ` [PATCH 0/3] vl: QAPIfy -object no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1727bd5b-e065-3e1b-d8b8-9cdf4f68d4a7@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.