Skip to contentSkip to conversation

fix query-memdev not repporting IDs of memory backends

PATCH Superseded Igor Mammedov 3 participants 14 messages Jan 2, 2017 – Jan 10, 2017 Arm STM32

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover fix query-memdev not repporting IDs of memory backends

Series is a couple of preparratory cleanups which simplify fix and a fix itself.

Before fix HMP 'info memdevs' for CLI:
qemu-system-x86_64 -object memory-backend-ram,id=mem0,size=1G outputs:

memory backend: 0

    size:  1073741824
    merge: true
    dump: true
    prealloc: false
    policy: default
    host nodes: 128

after fix:

memory backend: mem0

    size:  1073741824
    merge: true
    dump: true
    prealloc: false
    policy: default
    host nodes: 128

it should help to avoid remembering hotplugged IDs as they could be queried back via HMP/QMP interface.

Igor Mammedov (3):
cleanup: remove not used header
reuse user_creatable_add_opts() instead of user_creatable_add() in
monitor
fix qmp/hmp query-memdev not repporting IDs of memory backends

 include/qom/object_interfaces.h | 19 +---------
 include/sysemu/hostmem.h        |  1 +
 backends/hostmem.c              | 26 ++++++++++++++
 docs/qmp-commands.txt           |  1 +
 hmp.c                           | 10 ++----
 numa.c                          |  3 ++
 qapi-schema.json                |  3 ++
 qom/object_interfaces.c         | 78 ++++++++++++-----------------------------
 8 files changed, 59 insertions(+), 82 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 cleanup: remove not used header

---
 qom/object_interfaces.c | 1 -
 1 file changed, 1 deletion(-)
qom/object_interfaces.c +0 -1
index ded4d84..4b880d0 100644
@@ -3,7 +3,6 @@
 #include "qom/object_interfaces.h"
 #include "qemu/module.h"
 #include "qapi-visit.h"
-#include "qapi/qobject-output-visitor.h"
 #include "qapi/opts-visitor.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
Signature · 1 line
2.7.4
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] cleanup: remove not used header

On 01/02/2017 09:44 AM, Igor Mammedov wrote:

perhaps s/not used/unused/ in the subject

Quoted 18 lines
---
 qom/object_interfaces.c | 1 -
 1 file changed, 1 deletion(-)
qom/object_interfaces.c +0 -1
index ded4d84..4b880d0 100644
@@ -3,7 +3,6 @@
 #include "qom/object_interfaces.h"
 #include "qemu/module.h"
 #include "qapi-visit.h"
-#include "qapi/qobject-output-visitor.h"
 #include "qapi/opts-visitor.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] cleanup: remove not used header

Am 03.01.2017 um 16:25 schrieb Eric Blake:

Quoted 3 lines · Igor Mammedov

perhaps s/not used/unused/ in the subject

... and qom: instead of cleanup: if this gets re-spun.

Andreas

Quoted 22 lines
Quoted 18 lines
---
 qom/object_interfaces.c | 1 -
 1 file changed, 1 deletion(-)
qom/object_interfaces.c +0 -1
index ded4d84..4b880d0 100644
@@ -3,7 +3,6 @@
 #include "qom/object_interfaces.h"
 #include "qemu/module.h"
 #include "qapi-visit.h"
-#include "qapi/qobject-output-visitor.h"
 #include "qapi/opts-visitor.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] cleanup: remove not used header

Quoted 6 lines · On Tue, 3 Jan 2017 16:26:16 +0100 Andreas Färber <[email protected]> wrote:

Am 03.01.2017 um 16:25 schrieb Eric Blake:

Quoted 3 lines · Igor Mammedov

perhaps s/not used/unused/ in the subject

... and qom: instead of cleanup: if this gets re-spun.

sure

Quoted 27 lines

Andreas

Quoted 22 lines
Quoted 18 lines
---
 qom/object_interfaces.c | 1 -
 1 file changed, 1 deletion(-)
qom/object_interfaces.c +0 -1
index ded4d84..4b880d0 100644
@@ -3,7 +3,6 @@
 #include "qom/object_interfaces.h"
 #include "qemu/module.h"
 #include "qapi-visit.h"
-#include "qapi/qobject-output-visitor.h"
 #include "qapi/opts-visitor.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
#5 lore raw

PATCH 2/3 reuse user_creatable_add_opts() instead of user_creatable_add() in monitor

In reply to Igor Mammedov

Simplify code by dropping ~57LOC by merging user_creatable_add() into user_creatable_add_opts() and using the later from monutor. Along with it allocate opts_visitor_new() once in user_creatable_add_opts().

As result we have one less API func and a more readable/simple user_creatable_add_opts() vs user_creatable_add().

---
 include/qom/object_interfaces.h | 17 ----------
 hmp.c                           |  5 +--
 qom/object_interfaces.c         | 71 ++++++++++-------------------------------
 3 files changed, 18 insertions(+), 75 deletions(-)
include/qom/object_interfaces.h +0 -17
index 8b17f4d..fdd7603 100644
@@ -76,23 +76,6 @@ void user_creatable_complete(Object *obj, Error **errp);
 bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp);
 
 /**
- * user_creatable_add:
- * @qdict: the object definition
- * @v: the visitor
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Create an instance of the user creatable object whose type
- * is defined in @qdict by the 'qom-type' field, placing it
- * in the object composition tree with name provided by the
- * 'id' field. The remaining fields in @qdict are used to
- * initialize the object properties.
- *
- * Returns: the newly created object or NULL on error
- */
-Object *user_creatable_add(const QDict *qdict,
-                           Visitor *v, Error **errp);
-
-/**
  * user_creatable_add_type:
  * @type: the object type name
  * @id: the unique ID for the object
hmp.c +1 -4
index b869617..e7bead5 100644
@@ -1808,7 +1808,6 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
     QemuOpts *opts;
-    Visitor *v;
     Object *obj = NULL;
 
     opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
@@ -1817,9 +1816,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
         return;
     }
 
-    v = opts_visitor_new(opts);
-    obj = user_creatable_add(qdict, v, &err);
-    visit_free(v);
+    obj = user_creatable_add_opts(opts, &err);
     qemu_opts_del(opts);
 
     if (err) {
qom/object_interfaces.c +17 -54

87 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v1 2/3
#6 lore raw

Re: [Qemu-devel] [PATCH 2/3] reuse user_creatable_add_opts() instead of user_creatable_add() in monitor

Quoted 9 lines · Igor Mammedov

Simplify code by dropping ~57LOC by merging user_creatable_add() into user_creatable_add_opts() and using the later from monutor. Along with it allocate opts_visitor_new() once in user_creatable_add_opts().

As result we have one less API func and a more readable/simple user_creatable_add_opts() vs user_creatable_add().

---

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw

Re: [Qemu-devel] [PATCH 2/3] reuse user_creatable_add_opts() instead of user_creatable_add() in monitor

In reply to Igor Mammedov
Quoted 2 lines · Igor Mammedov

Simplify code by dropping ~57LOC by merging user_creatable_add() into user_creatable_add_opts() and using the later from monutor.

s/monutor/monitor/

Quoted 1 line

Along with it allocate opts_visitor_new() once in user_creatable_add_opts().

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#8 lore raw

PATCH 3/3 fix qmp/hmp query-memdev not repporting IDs of memory backends

In reply to Igor Mammedov

Do it by adding 'id' property to hostmem backends and fetch it in query-memdev from object directly.

---
 include/qom/object_interfaces.h |  2 +-
 include/sysemu/hostmem.h        |  1 +
 backends/hostmem.c              | 26 ++++++++++++++++++++++++++
 docs/qmp-commands.txt           |  1 +
 hmp.c                           |  5 +----
 numa.c                          |  3 +++
 qapi-schema.json                |  3 +++
 qom/object_interfaces.c         |  6 +++++-
 8 files changed, 41 insertions(+), 6 deletions(-)
include/qom/object_interfaces.h +1 -1
index fdd7603..06cccd9 100644
@@ -90,7 +90,7 @@ bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp);
  * Returns: the newly created object or NULL on error
  */
 Object *user_creatable_add_type(const char *type, const char *id,
-                                const QDict *qdict,
+                                QDict *qdict,
                                 Visitor *v, Error **errp);
 
 /**
include/sysemu/hostmem.h +1 -0
index 678232a..ecae0cf 100644
@@ -52,6 +52,7 @@ struct HostMemoryBackend {
     Object parent;
 
     /* protected */
+    char *id;
     uint64_t size;
     bool merge, dump;
     bool prealloc, force_prealloc, is_mapped;
backends/hostmem.c +26 -0
index 4256d24..7f5de70 100644
@@ -348,6 +348,24 @@ host_memory_backend_can_be_deleted(UserCreatable *uc, Error **errp)
     }
 }
 
+static char *get_id(Object *o, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(o);
+
+    return g_strdup(backend->id);
+}
+
+static void set_id(Object *o, const char *str, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(o);
+
+    if (backend->id) {
+        error_setg(errp, "cannot change property value");
+        return;
+    }
+    backend->id = g_strdup(str);
+}
+
 static void
 host_memory_backend_class_init(ObjectClass *oc, void *data)
 {
@@ -377,6 +395,13 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
         HostMemPolicy_lookup,
         host_memory_backend_get_policy,
         host_memory_backend_set_policy, &error_abort);
+    object_class_property_add_str(oc, "id", get_id, set_id, &error_abort);
+}
+
+static void host_memory_backend_finalize(Object *o)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(o);
+    g_free(backend->id);
 }
 
 static const TypeInfo host_memory_backend_info = {
@@ -387,6 +412,7 @@ static const TypeInfo host_memory_backend_info = {
     .class_init = host_memory_backend_class_init,
     .instance_size = sizeof(HostMemoryBackend),
     .instance_init = host_memory_backend_init,
+    .instance_finalize = host_memory_backend_finalize,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
         { }
docs/qmp-commands.txt +1 -0
index abf210a..18db4cd 100644
@@ -3529,6 +3529,7 @@ Example (1):
          "policy": "bind"
        },
        {
+         "id": "mem1",
          "size": 536870912,
          "merge": false,
          "dump": true,
hmp.c +1 -4
index e7bead5..8522efe 100644
@@ -2078,13 +2078,11 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
     MemdevList *m = memdev_list;
     Visitor *v;
     char *str;
-    int i = 0;
-
 
     while (m) {
         v = string_output_visitor_new(false, &str);
         visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
-        monitor_printf(mon, "memory backend: %d\n", i);
+        monitor_printf(mon, "memory backend: %s\n", m->value->id);
         monitor_printf(mon, "  size:  %" PRId64 "\n", m->value->size);
         monitor_printf(mon, "  merge: %s\n",
                        m->value->merge ? "true" : "false");
@@ -2100,7 +2098,6 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
         g_free(str);
         visit_free(v);
         m = m->next;
-        i++;
     }
 
     monitor_printf(mon, "\n");
numa.c +3 -0
index 9c09e45..f5fc7da 100644
@@ -518,6 +518,9 @@ static int query_memdev(Object *obj, void *opaque)
 
         m->value = g_malloc0(sizeof(*m->value));
 
+        m->value->id = object_property_get_str(obj, "id", NULL);
+        m->value->has_id = !!m->value->id;
+
         m->value->size = object_property_get_int(obj, "size",
                                                  &error_abort);
         m->value->merge = object_property_get_bool(obj, "merge",
qapi-schema.json +3 -0
index a0d3b5d..88eb2b9 100644
@@ -4453,6 +4453,8 @@
 #
 # Information about memory backend
 #
+# @id: #optional backend's ID if backend has 'id' property (since 2.9)
+#
 # @size: memory backend size
 #
 # @merge: enables or disables memory merge support
@@ -4469,6 +4471,7 @@
 ##
 { 'struct': 'Memdev',
   'data': {
+    '*id':        'str',
     'size':       'size',
     'merge':      'bool',
     'dump':       'bool',
qom/object_interfaces.c +5 -1
index 9b4155a..7a8f520 100644
@@ -4,6 +4,7 @@
 #include "qemu/module.h"
 #include "qapi-visit.h"
 #include "qapi/opts-visitor.h"
+#include "qapi/qmp/qstring.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
@@ -35,7 +36,7 @@ bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp)
 }
 
 Object *user_creatable_add_type(const char *type, const char *id,
-                                const QDict *qdict,
+                                QDict *qdict,
                                 Visitor *v, Error **errp)
 {
     Object *obj;
@@ -62,6 +63,9 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
     assert(qdict);
     obj = object_new(type);
+    if (object_property_find(obj, "id", NULL)) {
+        qdict_put(qdict, "id", qstring_from_str(id));
+    }
     visit_start_struct(v, NULL, NULL, 0, &local_err);
     if (local_err) {
         goto out;
Signature · 1 line
2.7.4
#9 lore raw

Re: [Qemu-devel] [PATCH 3/3] fix qmp/hmp query-memdev not repporting IDs of memory backends

On 01/02/2017 09:44 AM, Igor Mammedov wrote:

s/repporting/reporting/ in the subject

Quoted 25 lines

Do it by adding 'id' property to hostmem backends and fetch it in query-memdev from object directly.

---

+++ b/qom/object_interfaces.c

qom/object_interfaces.c +2 -1
@@ -4,6 +4,7 @@
 #include "qemu/module.h"
 #include "qapi-visit.h"
 #include "qapi/opts-visitor.h"
+#include "qapi/qmp/qstring.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
@@ -35,7 +36,7 @@ bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp)
 }
 
 Object *user_creatable_add_type(const char *type, const char *id,
-                                const QDict *qdict,
+                                QDict *qdict,
                                 Visitor *v, Error **errp)
 {
     Object *obj;

qom/object_interfaces.c Object *user_creatable_add_type(const char *type, const char *id, · line 68

Quoted 6 lines
qom/object_interfaces.c +3 -0
@@ -62,6 +63,9 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
     assert(qdict);
     obj = object_new(type);
+    if (object_property_find(obj, "id", NULL)) {
+        qdict_put(qdict, "id", qstring_from_str(id));
+    }

Wait. Isn't this going to inject an 'id' dict member to every use of user_creatable_add_type()? But not all QAPI structs contain an id member. Which means that you are now explicitly relying on the visitor to silently ignore garbage in the dictionary, rather than our desired goal of only validating if the dictionary exactly matches what the QAPI says it will match.

I'm not sure if I like this hack, or if there is a better way to do things when using a strict (rather than relaxed) input visitor.

Quoted 4 lines
qom/object_interfaces.c +0 -0
     visit_start_struct(v, NULL, NULL, 0, &local_err);
     if (local_err) {
         goto out;
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] fix qmp/hmp query-memdev not repporting IDs of memory backends

Quoted 30 lines · On Tue, 3 Jan 2017 09:34:40 -0600 Eric Blake <[email protected]> wrote:

On 01/02/2017 09:44 AM, Igor Mammedov wrote:

s/repporting/reporting/ in the subject

Quoted 26 lines

Do it by adding 'id' property to hostmem backends and fetch it in query-memdev from object directly.

---

+++ b/qom/object_interfaces.c

qom/object_interfaces.c +2 -1
@@ -4,6 +4,7 @@
 #include "qemu/module.h"
 #include "qapi-visit.h"
 #include "qapi/opts-visitor.h"
+#include "qapi/qmp/qstring.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
@@ -35,7 +36,7 @@ bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp)
 }
 
 Object *user_creatable_add_type(const char *type, const char *id,
-                                const QDict *qdict,
+                                QDict *qdict,
                                 Visitor *v, Error **errp)
 {
     Object *obj;
@@ -62,6 +63,9 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
Quoted 9 lines

qom/object_interfaces.c Object *user_creatable_add_type(const char *type, const char *id, · line 68

Quoted 5 lines
qom/object_interfaces.c +3 -0
     assert(qdict);
     obj = object_new(type);
+    if (object_property_find(obj, "id", NULL)) {
+        qdict_put(qdict, "id", qstring_from_str(id));
+    }

Wait. Isn't this going to inject an 'id' dict member to every use of user_creatable_add_type()? But not all QAPI structs contain an id member.

it would 'inject' 'id' only for objects that have 'id' property. or more exactly it would restore 'id' that is deleted earlier from the same qdict. Look for qdict_del() usage in this file. This way it'd be able to process both kinds of objects that implement 'id' property and ones that don't.

Quoted 4 lines

Which means that you are now explicitly relying on the visitor to silently ignore garbage in the dictionary, rather than our desired goal of only validating if the dictionary exactly matches what the QAPI says it will match.

currently 'id' is mandatory, but not enforced by QAPI structs, for all objects created with -object/object_add as it's used for naming object in qom tree:

      object_property_add_child(object_get_objects_root(), id, obj, &local_err); 
Quoted 3 lines

I'm not sure if I like this hack, or if there is a better way to do things when using a strict (rather than relaxed) input visitor.

I'm not sure about a better way to do this.
Currently we use 2 visitors: opts (for cli/hmp) and qobject_input for qmp path, which accept anything as target object could take different options.

The only things we currently enforce in code is presence of implicit 'qom-type' property and 'id' property. The rest of properties are validated by object's property setters.

Quoted 6 lines
Quoted 5 lines
qom/object_interfaces.c +0 -0
     visit_start_struct(v, NULL, NULL, 0, &local_err);
     if (local_err) {
         goto out;
#11 lore raw

Re: [Qemu-devel] [PATCH 3/3] fix qmp/hmp query-memdev not repporting IDs of memory backends

In reply to Eric Blake
Quoted 43 lines · On Tue, 3 Jan 2017 09:34:40 -0600 Eric Blake <[email protected]> wrote:

On 01/02/2017 09:44 AM, Igor Mammedov wrote:

s/repporting/reporting/ in the subject

Quoted 25 lines

Do it by adding 'id' property to hostmem backends and fetch it in query-memdev from object directly.

---

+++ b/qom/object_interfaces.c

(quoted diff) +2 -1
@@ -4,6 +4,7 @@
 #include "qemu/module.h"
 #include "qapi-visit.h"
 #include "qapi/opts-visitor.h"
+#include "qapi/qmp/qstring.h"
 
 void user_creatable_complete(Object *obj, Error **errp)
 {
@@ -35,7 +36,7 @@ bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp)
 }
 
 Object *user_creatable_add_type(const char *type, const char *id,
-                                const QDict *qdict,
+                                QDict *qdict,
                                 Visitor *v, Error **errp)
 {
     Object *obj;

Review Object *user_creatable_add_type(const char *type, const char *id, · line 68

Quoted 6 lines
(quoted diff) +3 -0
@@ -62,6 +63,9 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
     assert(qdict);
     obj = object_new(type);
+    if (object_property_find(obj, "id", NULL)) {
+        qdict_put(qdict, "id", qstring_from_str(id));
+    }  

Wait. Isn't this going to inject an 'id' dict member to every use of user_creatable_add_type()? But not all QAPI structs contain an id member. Which means that you are now explicitly relying on the visitor to silently ignore garbage in the dictionary, rather than our desired goal of only validating if the dictionary exactly matches what the QAPI says it will match.

Quoted 2 lines

I'm not sure if I like this hack, or if there is a better way to do things when using a strict (rather than relaxed) input visitor.

a bit less ugly variant but with the same basic idea would look like:
--------------
Subject: [PATCH] fix qmp/hmp query-memdev not reporting IDs of memory backends

Considering 'id' is mandatory for user_creatable objects/backends and user_creatable_add_type() always has it as an argument regardless of where from it is called CLI/monitor or QMP, Fix issue by adding 'id' property to hostmem backends and set it in user_creatable_add_type() for every object that implements 'id' property. Then later at query-memdev time get 'id' from object directly.

[...]

qom/object_interfaces.c +6 -0
index 9b4155a..03a95c3 100644
@@ -62,6 +62,12 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
     assert(qdict);
     obj = object_new(type);
+    if (object_property_find(obj, "id", NULL)) {
+        object_property_set_str(obj, id, "id", &local_err);
+        if (local_err) {
+            goto out;
+        }
+    }
     visit_start_struct(v, NULL, NULL, 0, &local_err);
     if (local_err) {
         goto out;
#12 lore raw

Re: [Qemu-devel] [PATCH 3/3] fix qmp/hmp query-memdev not repporting IDs of memory backends

Quoted 13 lines · Igor Mammedov
Quoted 9 lines

Wait. Isn't this going to inject an 'id' dict member to every use of user_creatable_add_type()? But not all QAPI structs contain an id member. Which means that you are now explicitly relying on the visitor to silently ignore garbage in the dictionary, rather than our desired goal of only validating if the dictionary exactly matches what the QAPI says it will match.

I'm not sure if I like this hack, or if there is a better way to do things when using a strict (rather than relaxed) input visitor.

a bit less ugly variant but with the same basic idea would look like:
--------------
Subject: [PATCH] fix qmp/hmp query-memdev not reporting IDs of memory backends

Quoted 7 lines

Considering 'id' is mandatory for user_creatable objects/backends and user_creatable_add_type() always has it as an argument regardless of where from it is called CLI/monitor or QMP, Fix issue by adding 'id' property to hostmem backends and set it in user_creatable_add_type() for every object that implements 'id' property. Then later at query-memdev time get 'id' from object directly.

Yes, that seems like an improved message.

Quoted 10 lines

[...]

qom/object_interfaces.c +0 -0
index 9b4155a..03a95c3 100644

qom/object_interfaces.c Object *user_creatable_add_type(const char *type, const char *id, · line 70

Quoted 9 lines
qom/object_interfaces.c +6 -0
@@ -62,6 +62,12 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
     assert(qdict);
     obj = object_new(type);
+    if (object_property_find(obj, "id", NULL)) {
+        object_property_set_str(obj, id, "id", &local_err);
+        if (local_err) {
+            goto out;
+        }
+    }

Works for me.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw

Re: [Qemu-devel] [PATCH 3/3] fix qmp/hmp query-memdev not repporting IDs of memory backends

Quoted 36 lines · On Mon, 9 Jan 2017 14:26:28 -0600 Eric Blake <[email protected]> wrote:
Quoted 13 lines · Igor Mammedov
Quoted 9 lines

Wait. Isn't this going to inject an 'id' dict member to every use of user_creatable_add_type()? But not all QAPI structs contain an id member. Which means that you are now explicitly relying on the visitor to silently ignore garbage in the dictionary, rather than our desired goal of only validating if the dictionary exactly matches what the QAPI says it will match.

I'm not sure if I like this hack, or if there is a better way to do things when using a strict (rather than relaxed) input visitor.

a bit less ugly variant but with the same basic idea would look like:
--------------
Subject: [PATCH] fix qmp/hmp query-memdev not reporting IDs of memory backends

Quoted 7 lines

Considering 'id' is mandatory for user_creatable objects/backends and user_creatable_add_type() always has it as an argument regardless of where from it is called CLI/monitor or QMP, Fix issue by adding 'id' property to hostmem backends and set it in user_creatable_add_type() for every object that implements 'id' property. Then later at query-memdev time get 'id' from object directly.

Yes, that seems like an improved message.

Quoted 11 lines

[...]

qom/object_interfaces.c +0 -0
index 9b4155a..03a95c3 100644
@@ -62,6 +62,12 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
Quoted 11 lines

qom/object_interfaces.c Object *user_creatable_add_type(const char *type, const char *id, · line 70

Quoted 8 lines
qom/object_interfaces.c +6 -0
     assert(qdict);
     obj = object_new(type);
+    if (object_property_find(obj, "id", NULL)) {
+        object_property_set_str(obj, id, "id", &local_err);
+        if (local_err) {
+            goto out;
+        }
+    }  

Works for me.

Thanks,
Then, I'll respin v2 with noted fixups in commit messages this amended patch.