All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qom: Support JSON in user_creatable_parse_str()
@ 2021-03-12 13:19 Kevin Wolf
  2021-03-12 13:59 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kevin Wolf @ 2021-03-12 13:19 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, pkrempa, armbru

Support JSON for --object in all tools and in HMP object_add in the same
way as it is supported in qobject_input_visitor_new_str().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
Based-on: <20210311144811.313451-1-kwolf@redhat.com>

 qom/object_interfaces.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 62d7db7629..f5ea84b6c4 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -295,25 +295,35 @@ static void user_creatable_print_help_from_qdict(QDict *args)
 ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
 {
     ERRP_GUARD();
-    QDict *args;
+    QObject *obj;
     bool help;
     Visitor *v;
     ObjectOptions *options;
 
-    args = keyval_parse(optarg, "qom-type", &help, errp);
-    if (*errp) {
-        return NULL;
-    }
-    if (help) {
-        user_creatable_print_help_from_qdict(args);
-        qobject_unref(args);
-        return NULL;
+    if (optarg[0] == '{') {
+        obj = qobject_from_json(optarg, errp);
+        if (!obj) {
+            return NULL;
+        }
+        v = qobject_input_visitor_new(obj);
+    } else {
+        QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
+        if (*errp) {
+            return NULL;
+        }
+        if (help) {
+            user_creatable_print_help_from_qdict(args);
+            qobject_unref(args);
+            return NULL;
+        }
+
+        obj = QOBJECT(args);
+        v = qobject_input_visitor_new_keyval(obj);
     }
 
-    v = qobject_input_visitor_new_keyval(QOBJECT(args));
     visit_type_ObjectOptions(v, NULL, &options, errp);
     visit_free(v);
-    qobject_unref(args);
+    qobject_unref(obj);
 
     return options;
 }
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
  2021-03-12 13:19 [PATCH] qom: Support JSON in user_creatable_parse_str() Kevin Wolf
@ 2021-03-12 13:59 ` Eric Blake
  2021-03-12 14:47   ` Paolo Bonzini
  2021-03-12 16:01 ` Markus Armbruster
  2021-03-13  8:00 ` Markus Armbruster
  2 siblings, 1 reply; 8+ messages in thread
From: Eric Blake @ 2021-03-12 13:59 UTC (permalink / raw)
  To: Kevin Wolf, qemu-devel; +Cc: pbonzini, pkrempa, armbru

On 3/12/21 7:19 AM, Kevin Wolf wrote:
> Support JSON for --object in all tools and in HMP object_add in the same
> way as it is supported in qobject_input_visitor_new_str().
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> Based-on: <20210311144811.313451-1-kwolf@redhat.com>
> 
>  qom/object_interfaces.c | 32 +++++++++++++++++++++-----------
>  1 file changed, 21 insertions(+), 11 deletions(-)
> 

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

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
  2021-03-12 13:59 ` Eric Blake
@ 2021-03-12 14:47   ` Paolo Bonzini
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2021-03-12 14:47 UTC (permalink / raw)
  To: Eric Blake, Kevin Wolf, qemu-devel; +Cc: pkrempa, armbru

On 12/03/21 14:59, Eric Blake wrote:
> On 3/12/21 7:19 AM, Kevin Wolf wrote:
>> Support JSON for --object in all tools and in HMP object_add in the same
>> way as it is supported in qobject_input_visitor_new_str().
>>
>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>> ---
>> Based-on: <20210311144811.313451-1-kwolf@redhat.com>
>>
>>   qom/object_interfaces.c | 32 +++++++++++++++++++++-----------
>>   1 file changed, 21 insertions(+), 11 deletions(-)
>>
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 

Queued, thanks.

Paolo



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
  2021-03-12 13:19 [PATCH] qom: Support JSON in user_creatable_parse_str() Kevin Wolf
  2021-03-12 13:59 ` Eric Blake
@ 2021-03-12 16:01 ` Markus Armbruster
  2021-03-12 16:32   ` Kevin Wolf
  2021-03-13  8:00 ` Markus Armbruster
  2 siblings, 1 reply; 8+ messages in thread
From: Markus Armbruster @ 2021-03-12 16:01 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: pbonzini, pkrempa, qemu-devel

Is this an alternative to Paolo's "[PATCH 0/3] vl: QAPIfy -object", and
if not, how do the two play together?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
  2021-03-12 16:01 ` Markus Armbruster
@ 2021-03-12 16:32   ` Kevin Wolf
  0 siblings, 0 replies; 8+ messages in thread
From: Kevin Wolf @ 2021-03-12 16:32 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: pbonzini, pkrempa, qemu-devel

Am 12.03.2021 um 17:01 hat Markus Armbruster geschrieben:
> Is this an alternative to Paolo's "[PATCH 0/3] vl: QAPIfy -object", and
> if not, how do the two play together?

Paolo's patch adds JSON support to the system emulator CLI (using
QemuOpts to stay compatible with the list magic), this patch adds it to
everything else (tools don't have memory-backend, and HMP isn't a stable
interface, so they all use the same keyval-based function modified by
this patch).

Kevin



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
  2021-03-12 13:19 [PATCH] qom: Support JSON in user_creatable_parse_str() Kevin Wolf
  2021-03-12 13:59 ` Eric Blake
  2021-03-12 16:01 ` Markus Armbruster
@ 2021-03-13  8:00 ` Markus Armbruster
  2021-03-15 11:56   ` Kevin Wolf
  2 siblings, 1 reply; 8+ messages in thread
From: Markus Armbruster @ 2021-03-13  8:00 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: pbonzini, pkrempa, qemu-devel

Recommend

    qom: Support JSON in HMP object_add and tools --object

to put the most interesting bit right in "git-log --oneline".

Kevin Wolf <kwolf@redhat.com> writes:

> Support JSON for --object in all tools and in HMP object_add in the same
> way as it is supported in qobject_input_visitor_new_str().
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> Based-on: <20210311144811.313451-1-kwolf@redhat.com>
>
>  qom/object_interfaces.c | 32 +++++++++++++++++++++-----------
>  1 file changed, 21 insertions(+), 11 deletions(-)
>
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index 62d7db7629..f5ea84b6c4 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -295,25 +295,35 @@ static void user_creatable_print_help_from_qdict(QDict *args)
>  ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
>  {
>      ERRP_GUARD();
> -    QDict *args;
> +    QObject *obj;
>      bool help;
>      Visitor *v;
>      ObjectOptions *options;
>  
> -    args = keyval_parse(optarg, "qom-type", &help, errp);
> -    if (*errp) {
> -        return NULL;
> -    }
> -    if (help) {
> -        user_creatable_print_help_from_qdict(args);
> -        qobject_unref(args);
> -        return NULL;
> +    if (optarg[0] == '{') {
> +        obj = qobject_from_json(optarg, errp);
> +        if (!obj) {
> +            return NULL;
> +        }
> +        v = qobject_input_visitor_new(obj);
> +    } else {
> +        QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
> +        if (*errp) {
> +            return NULL;
> +        }
> +        if (help) {
> +            user_creatable_print_help_from_qdict(args);
> +            qobject_unref(args);
> +            return NULL;
> +        }
> +
> +        obj = QOBJECT(args);
> +        v = qobject_input_visitor_new_keyval(obj);
>      }
>  
> -    v = qobject_input_visitor_new_keyval(QOBJECT(args));
>      visit_type_ObjectOptions(v, NULL, &options, errp);
>      visit_free(v);
> -    qobject_unref(args);
> +    qobject_unref(obj);
>  
>      return options;
>  }

Best viewed with whitespace change ignored:

   diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
   index 2e50698075..93b8878127 100644
   --- a/qom/object_interfaces.c
   +++ b/qom/object_interfaces.c
   @@ -242,12 +242,19 @@ static void user_creatable_print_help_from_qdict(QDict *args)
    ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
    {
        ERRP_GUARD();
   -    QDict *args;
   +    QObject *obj;
        bool help;
        Visitor *v;
        ObjectOptions *options;

   -    args = keyval_parse(optarg, "qom-type", &help, errp);
   +    if (optarg[0] == '{') {
   +        obj = qobject_from_json(optarg, errp);
   +        if (!obj) {
   +            return NULL;
   +        }
   +        v = qobject_input_visitor_new(obj);
   +    } else {
   +        QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
            if (*errp) {
                return NULL;
            }
   @@ -257,10 +264,13 @@ ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
                return NULL;
            }

   -    v = qobject_input_visitor_new_keyval(QOBJECT(args));
   +        obj = QOBJECT(args);
   +        v = qobject_input_visitor_new_keyval(obj);
   +    }
   +
        visit_type_ObjectOptions(v, NULL, &options, errp);
        visit_free(v);
   -    qobject_unref(args);
   +    qobject_unref(obj);

        return options;
    }

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
  2021-03-13  8:00 ` Markus Armbruster
@ 2021-03-15 11:56   ` Kevin Wolf
  2021-03-15 12:00     ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Kevin Wolf @ 2021-03-15 11:56 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: pbonzini, pkrempa, qemu-devel

Am 13.03.2021 um 09:00 hat Markus Armbruster geschrieben:
> Recommend
> 
>     qom: Support JSON in HMP object_add and tools --object
> 
> to put the most interesting bit right in "git-log --oneline".

Makes sense. I've updated my patch locally, but Paolo has already queued
it. Paolo, can you update the subject line accordingly?

Kevin



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] qom: Support JSON in user_creatable_parse_str()
  2021-03-15 11:56   ` Kevin Wolf
@ 2021-03-15 12:00     ` Paolo Bonzini
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2021-03-15 12:00 UTC (permalink / raw)
  To: Kevin Wolf, Markus Armbruster; +Cc: pkrempa, qemu-devel

On 15/03/21 12:56, Kevin Wolf wrote:
> Am 13.03.2021 um 09:00 hat Markus Armbruster geschrieben:
>> Recommend
>>
>>      qom: Support JSON in HMP object_add and tools --object
>>
>> to put the most interesting bit right in "git-log --oneline".
> 
> Makes sense. I've updated my patch locally, but Paolo has already queued
> it. Paolo, can you update the subject line accordingly?

Ok, done.

Paolo



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-15 12:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 13:19 [PATCH] qom: Support JSON in user_creatable_parse_str() Kevin Wolf
2021-03-12 13:59 ` Eric Blake
2021-03-12 14:47   ` Paolo Bonzini
2021-03-12 16:01 ` Markus Armbruster
2021-03-12 16:32   ` Kevin Wolf
2021-03-13  8:00 ` Markus Armbruster
2021-03-15 11:56   ` Kevin Wolf
2021-03-15 12:00     ` Paolo Bonzini

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.