fix query-memdev not repporting IDs of memory backends
v2 cover fix query-memdev not repporting IDs of memory backends
Changelog:
since v1:
* fix mistakes in commit messages/change them as suggested
* extend 3/3 commit message to explain why it's ok to use 'id'
* 3/3 set 'id' property directly instead of injecting it back into qdict.
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: 128after fix:
memory backend: mem0
size: 1073741824
merge: true
dump: true
prealloc: false
policy: default
host nodes: 128it should help to avoid remembering hotplugged IDs as they could be queried back via HMP/QMP interface.
Igor Mammedov (3):
qom: remove unused header
reuse user_creatable_add_opts() instead of user_creatable_add() in
monitor
fix qmp/hmp query-memdev not reporting IDs of memory backends
include/qom/object_interfaces.h | 17 --------- 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(+), 80 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/3 qom: remove unused header
--- qom/object_interfaces.c | 1 - 1 file changed, 1 deletion(-)
qom/object_interfaces.c +0 -1
@@ -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
PATCH v2 2/3 reuse user_creatable_add_opts() instead of user_creatable_add() in monitor
In reply to Igor MammedovSimplify code by dropping ~57LOC by merging user_creatable_add() into user_creatable_add_opts() and using the later from monitor. 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
@@ -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
@@ -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
PATCH v2 3/3 fix qmp/hmp query-memdev not reporting IDs of memory backends
In reply to Igor MammedovConsidering '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.
--- 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 ++++++ 7 files changed, 41 insertions(+), 4 deletions(-)
include/sysemu/hostmem.h +1 -0
@@ -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
@@ -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
@@ -3529,6 +3529,7 @@ Example (1): "policy": "bind" }, { + "id": "mem1", "size": 536870912, "merge": false, "dump": true,
hmp.c +1 -4
@@ -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
@@ -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
@@ -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 +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; + } + }visit_start_struct (v,NULL ,NULL ,0 , &local_err);if (local_err) { goto out;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 3/3] fix qmp/hmp query-memdev not reporting IDs of memory backends
Quoted 9 lines · Igor Mammedov
Considering 'id' is mandatory for
user_creatableobjects/backends anduser_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 inuser_creatable_add_type()for every object that implements 'id' property. Then later at query-memdev time get 'id' from object directly.Signed-off-by Igor Mammedov <[email protected]>
Quoted 9 lines
--- 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 ++++++ 7 files changed, 41 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Eduardo Habkost
AppliedQuoted 34 lines · Igor Mammedov
Changelog:
since v1:
* fix mistakes in commit messages/change them as suggested
* extend 3/3 commit message to explain why it's ok to use 'id'
* 3/3 set 'id' property directly instead of injecting it back into qdict.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: 128after fix:
memory backend: mem0
size: 1073741824 merge: true dump: true prealloc: false policy: default host nodes: 128
Quoted 3 lines
it should help to avoid remembering hotplugged IDs as they could be queried back via HMP/QMP interface.
Applied to machine-next. Thanks!
Signature · 1 line
Eduardo