From e1ff3c67e8544f41f1bea76ba76385faee0d2bb7 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Tue, 10 Jan 2017 13:53:15 +0100 Subject: monitor: 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. Signed-off-by: Igor Mammedov Message-Id: <1484052795-158195-4-git-send-email-imammedo@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Eduardo Habkost --- backends/hostmem.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'backends/hostmem.c') diff --git a/backends/hostmem.c b/backends/hostmem.c index 4256d24..7f5de70 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -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 }, { } -- cgit v1.1