All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH 3/3] vl: allow passing JSON to -object
Date: Sat, 13 Mar 2021 10:41:17 +0100	[thread overview]
Message-ID: <878s6rwfuq.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20210311172459.990281-4-pbonzini@redhat.com> (Paolo Bonzini's message of "Thu, 11 Mar 2021 12:24:59 -0500")

Paolo Bonzini <pbonzini@redhat.com> writes:

> 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);
> +    } 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);

Best viewed with whitespace change ignored:

   commit d13ba69a7cf33f583a22c28644c28928b120aff0
   Author: Paolo Bonzini <pbonzini@redhat.com>
   Date:   Thu Mar 11 12:24:59 2021 -0500

       vl: allow passing JSON to -object

       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>
       Message-Id: <20210311172459.990281-4-pbonzini@redhat.com>

   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,6 +1715,12 @@ static void object_option_parse(const char *optarg)
        const char *type;
        Visitor *v;

   +    if (optarg[0] == '{') {
   +        QObject *obj = qobject_from_json(optarg, &error_fatal);
   +
   +        v = qobject_input_visitor_new(obj);
   +        qobject_unref(obj);
   +    } else {
            opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
                                           optarg, true);
            if (!opts) {
   @@ -1725,8 +1732,10 @@ static void object_option_parse(const char *optarg)
                exit(0);
            }

   -    opt = g_new0(ObjectOption, 1);
            v = opts_visitor_new(opts);
   +    }
   +
   +    opt = g_new0(ObjectOption, 1);
        visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal);
        visit_free(v);

Reviewed-by: Markus Armbruster <armbru@redhat.com>



  parent reply	other threads:[~2021-03-13  9:42 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
2021-03-12 10:21   ` Kevin Wolf
2021-03-13  9:41   ` Markus Armbruster [this message]
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=878s6rwfuq.fsf@dusky.pond.sub.org \
    --to=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.