[PATCH 00/16] qom qapi: QOM introspection interface cleanup
QOM introspection provides a "type" value that qom/object.h calls "pretty loosely defined". This lack of discipline has turned out to be problematic. There's a zoo of "well-known" values consumers need to know, and these are documented by handwaving or not at all. The values for child and link properties need to be parsed, which is an anti-pattern for QMP. Marc-André's "qom/qdev: associate properties with QAPI schema types" provided a much better alternative: a "qapi-type" that can be looked up in output of query-qmp-schema. Except we still need to parse "type" to recognize and make sense of QOM link and child properties. My series closes this gap. Three parts: * PATCH 01-08 replace most uses of ObjectProperty member @type. After PATCH 08, only printing help in type_print_class_properties() and copying to result "type" of QMP commands qom-list, qom-list-properties, qom-list-get remain. * PATCH 09-15 eliminates in-tree uses of this result. * PATCH 16 deprecates this result. This is for 12.0, obviously. Based-on: <20261117103629.2612744-1-armbru@redhat.com> Based-on: <20261117105945.2802923-1-armbru@redhat.com> Based-on: <20261118182005.1066151-1-armbru@redhat.com> Markus Armbruster (16): util: Move QMP command query-command-line-options back to util/ util: Wean query-command-line-options off ObjectProperty member @type monitor: Fix query-command-line-options for -machine integer parameters qom: New ObjectProperty member @qom_type qom: Inline object_property_get_type() into its only caller qom: Simplify object_resolve_link() qom: Wean "is child?" checks off ObjectProperty member @type qom: Wean "is link?" checks off ObjectProperty member @type qom: Extend ObjectPropertyInfo so clients don't have to parse @type qom: Wean HMP commands off ObjectPropertyInfo member @type tests: Wean off ObjectPropertyInfo member @type python/qemu: Wean off ObjectPropertyInfo member @type qom: Extend ObjectPropertyValue so clients don't have to parse @type tests: Wean off ObjectPropertyValue member @type python/qemu: Wean off ObjectPropertyValue member @type qom: Deprecate ObjectPropertyInfo, ObjectPropertyValue member @type docs/about/deprecated.rst | 5 ++ qapi/qom.json | 74 +++++++++++++++---- include/qom/object.h | 15 +--- hw/ppc/spapr_drc.c | 4 +- qom/object.c | 56 +++++++------- qom/qom-hmp-cmds.c | 2 +- qom/qom-qmp-cmds.c | 18 +++++ tests/qtest/device-introspect-test.c | 4 +- tests/qtest/qom-test.c | 8 +- tests/qtest/readconfig-test.c | 5 +- .../qemu-config-qmp-cmds.c | 9 ++- monitor/meson.build | 1 - python/qemu/utils/qom.py | 2 +- python/qemu/utils/qom_common.py | 28 ++++--- util/meson.build | 3 +- 15 files changed, 151 insertions(+), 83 deletions(-) rename monitor/qemu-config-qmp.c => util/qemu-config-qmp-cmds.c (96%) -- 2.55.0
Commit 3df4c28860e1 (util/qemu-config: Extract QMP commands to qemu-config-qmp.c) extracted it from util/qemu-config.c so we don't link it into user emulation binaries. Good. It also moved it from util/ to monitor/. Not good; it's not about the monitor. Move it back. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- monitor/qemu-config-qmp.c => util/qemu-config-qmp-cmds.c | 0 monitor/meson.build | 1 - util/meson.build | 3 ++- 3 files changed, 2 insertions(+), 2 deletions(-) rename monitor/qemu-config-qmp.c => util/qemu-config-qmp-cmds.c (100%) diff --git a/monitor/qemu-config-qmp.c b/util/qemu-config-qmp-cmds.c similarity index 100% rename from monitor/qemu-config-qmp.c rename to util/qemu-config-qmp-cmds.c diff --git a/monitor/meson.build b/monitor/meson.build index f67e0291a42..ea3600d78cf 100644 --- a/monitor/meson.build +++ b/monitor/meson.build @@ -2,7 +2,6 @@ qmp_ss.add(files('monitor.c', 'qmp.c', 'qmp-cmds-control.c')) system_ss.add(files( 'fds.c', - 'qemu-config-qmp.c', 'qmp-cmds.c', )) diff --git a/util/meson.build b/util/meson.build index fa174c07a57..e02b3a16221 100644 --- a/util/meson.build +++ b/util/meson.build @@ -42,7 +42,8 @@ util_ss.add(files('cacheflush.c')) util_ss.add(files('error.c', 'error-report.c')) util_ss.add(files('qemu-print.c')) util_ss.add(files('id.c')) -util_ss.add(files('qemu-config.c', 'notify.c')) +util_ss.add(files('qemu-config.c', 'qemu-config-qmp-cmds.c')) +util_ss.add(files('notify.c')) util_ss.add(files('qemu-option.c', 'qemu-progress.c')) util_ss.add(files('keyval.c')) util_ss.add(files('crc32.c')) -- 2.55.0
ObjectProperty member @type comes from object_property_try_add() / object_class_property_add() parameter @type. The former's function comment calls it "pretty loosely defined". This lack of discipline has turned out to be problematic. I'm replacing it step by step. query-command-line-options derives CommandLineParameterInfo member @type from it for class properties of machine types. Derive from @qapi_type instead, which is rigorously defined. The type of qemu-system-ppc64 machine parameter "cap-hpt-max-page-size" changes from "number" to "size", because @type is "int", whereas @qapi_type is &size_type_info. Small improvement. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- util/qemu-config-qmp-cmds.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/util/qemu-config-qmp-cmds.c b/util/qemu-config-qmp-cmds.c index a680c9feca5..e0038628f97 100644 --- a/util/qemu-config-qmp-cmds.c +++ b/util/qemu-config-qmp-cmds.c @@ -98,16 +98,17 @@ static CommandLineParameterInfoList *get_drive_infolist(void) static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop) { + const QAPITypeInfo *qt = prop->qapi_type; CommandLineParameterInfo *info; info = g_malloc0(sizeof(*info)); info->name = g_strdup(prop->name); - if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) { + if (g_str_equal(qt->name, "bool") || g_str_equal(qt->name, "OnOffAuto")) { info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; - } else if (g_str_equal(prop->type, "int")) { + } else if (g_str_equal(qt->name, "int")) { info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; - } else if (g_str_equal(prop->type, "size")) { + } else if (g_str_equal(qt->name, "size")) { info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; } else { info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; -- 2.55.0
query-command-line-options derives the parameters of -machine from machine type class properties. The code maps property types "bool", "OnOffAuto", "int", and "size" to CommandLineParameterTypes "bool", "number", and "size". Any other property type becomes "string". This includes all the other integer types. The obvious fix would be code to map all the integer types to "number". But there's an easier one: all the integer types have the same masked name "int". So use that. This fixes the type of several parameters of -machine: * qemu-system-aarch64 and -arm: virtio-mmio-transports * qemu-system-hexagon: subsystem-base * qemu-system-x86_64 and -i386: pci-mmio-high-base pci-mmio-size pci-intx-irq-base pci-ecam-size pci-ecam-base pci-mmio-high-size ram-low-size ram-low-base pci-mmio-base ram-high-size ram-high-base bus-lock-ratelimit * qemu-system-riscv64 and -riscv32: signature-granularity * qemu-system-risc64: clint-timebase-frequency Signed-off-by: Markus Armbruster <armbru@redhat.com> --- util/qemu-config-qmp-cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/qemu-config-qmp-cmds.c b/util/qemu-config-qmp-cmds.c index e0038628f97..f1a6cde56bd 100644 --- a/util/qemu-config-qmp-cmds.c +++ b/util/qemu-config-qmp-cmds.c @@ -106,10 +106,10 @@ static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop) if (g_str_equal(qt->name, "bool") || g_str_equal(qt->name, "OnOffAuto")) { info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; - } else if (g_str_equal(qt->name, "int")) { - info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; } else if (g_str_equal(qt->name, "size")) { info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; + } else if (g_str_equal(qt->masked_name, "int")) { + info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; } else { info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; } -- 2.55.0
ObjectProperty member @type is "child<T>" for a child property of QOM type T, and "link<T>" for a link property of QOM type T. We parse @type in various places to extract "is child?", "is link?", and "T". Undesirable. Add member @qom_type. It is is "T" when @type is "child<T>" or "link<T>", else null. The next commits will use it to get rid of the parsing. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- include/qom/object.h | 1 + qom/object.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/qom/object.h b/include/qom/object.h index 70d8ea3e299..c8cedfe0f89 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -93,6 +93,7 @@ struct ObjectProperty char *type; char *description; const QAPITypeInfo *qapi_type; + char *qom_type; ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; ObjectPropertyResolve *resolve; diff --git a/qom/object.c b/qom/object.c index 9276b7a4351..3c5a8f49154 100644 --- a/qom/object.c +++ b/qom/object.c @@ -331,6 +331,7 @@ static void object_property_free(gpointer data) } g_free(prop->name); g_free(prop->type); + g_free(prop->qom_type); g_free(prop->description); g_free(prop); } @@ -1905,6 +1906,7 @@ ObjectProperty * object_property_try_add_child(Object *obj, const char *name, Object *child, Error **errp) { + const char *qom_type = object_get_typename(child); g_autofree char *type = NULL; ObjectProperty *op; @@ -1912,7 +1914,7 @@ object_property_try_add_child(Object *obj, const char *name, child, child->class->type->name); assert(!child->parent); - type = g_strdup_printf("child<%s>", object_get_typename(child)); + type = g_strdup_printf("child<%s>", qom_type); op = object_property_try_add(obj, name, type, &str_type_info, object_get_child_property, @@ -1921,6 +1923,7 @@ object_property_try_add_child(Object *obj, const char *name, if (!op) { return NULL; } + op->qom_type = g_strdup(qom_type); op->resolve = object_resolve_child_property; object_ref(child); child->parent = obj; @@ -2114,6 +2117,7 @@ object_add_link_prop(Object *obj, const char *name, check ? object_set_link_property : NULL, object_release_link_property, prop); + op->qom_type = g_strdup(type); op->resolve = object_resolve_link_property; return op; } @@ -2152,6 +2156,7 @@ object_class_property_add_link(ObjectClass *oc, object_release_link_property, prop); + op->qom_type = g_strdup(type); op->resolve = object_resolve_link_property; g_free(full_type); @@ -3105,6 +3110,7 @@ object_property_add_alias(Object *obj, const char *name, property_set_alias, property_release_alias, prop); + op->qom_type = g_strdup(target_prop->qom_type); op->resolve = property_resolve_alias; if (target_prop->defval) { op->defval = qobject_ref(target_prop->defval); @@ -3150,6 +3156,7 @@ object_class_property_add_alias(ObjectClass *klass, const char *name, property_set_alias, property_release_alias, prop); + op->qom_type = g_strdup(target_prop->qom_type); op->resolve = property_resolve_alias; if (target_prop->defval) { op->defval = qobject_ref(target_prop->defval); -- 2.55.0
Signed-off-by: Markus Armbruster <armbru@redhat.com> --- include/qom/object.h | 11 ----------- qom/object.c | 13 ++----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index c8cedfe0f89..dbfc29a2d6a 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1616,17 +1616,6 @@ bool object_property_parse(Object *obj, const char *name, char *object_property_print(Object *obj, const char *name, bool human, Error **errp); -/** - * object_property_get_type: - * @obj: the object - * @name: the name of the property - * @errp: returns an error if this function fails - * - * Returns: The type name of the property. - */ -const char *object_property_get_type(Object *obj, const char *name, - Error **errp); - /** * object_get_root: * diff --git a/qom/object.c b/qom/object.c index 3c5a8f49154..47e5979aa06 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1802,16 +1802,6 @@ out: return string; } -const char *object_property_get_type(Object *obj, const char *name, Error **errp) -{ - ObjectProperty *prop = object_property_find_err(obj, name, errp); - if (prop == NULL) { - return NULL; - } - - return prop->type; -} - static const char *const root_containers[] = { "audiodevs", "chardevs", @@ -2024,7 +2014,8 @@ static Object *object_resolve_link(Object *obj, const char *name, g_autofree char *target_type = NULL; /* Go from link<FOO> to FOO. */ - type = object_property_get_type(obj, name, NULL); + ObjectProperty *prop = object_property_find_err(obj, name, NULL); + type = prop ? prop->type : NULL; target_type = g_strndup(&type[5], strlen(type) - 6); return object_resolve_and_typecheck(path, name, target_type, errp); } -- 2.55.0
object_resolve_link() finds the property, then extracts the QOM type from its member @type. @type must be like "link<T>", or else the extraction produces crap, and may read beyond the buffer. This is actually ensured by the users of object_set_link_property(). Simpler: use new member @qom_type instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- qom/object.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/qom/object.c b/qom/object.c index 47e5979aa06..14fd2f3d17e 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2010,14 +2010,10 @@ Object *object_resolve_and_typecheck(const char *path, const char *name, static Object *object_resolve_link(Object *obj, const char *name, const char *path, Error **errp) { - const char *type; - g_autofree char *target_type = NULL; + ObjectProperty *prop = object_property_find(obj, name); - /* Go from link<FOO> to FOO. */ - ObjectProperty *prop = object_property_find_err(obj, name, NULL); - type = prop ? prop->type : NULL; - target_type = g_strndup(&type[5], strlen(type) - 6); - return object_resolve_and_typecheck(path, name, target_type, errp); + assert(prop->qom_type); + return object_resolve_and_typecheck(path, name, prop->qom_type, errp); } static void object_set_link_property(Object *obj, Visitor *v, -- 2.55.0
object_property_is_child() parses member @type to decide. Check the getter instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- include/qom/object.h | 1 + qom/object.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index dbfc29a2d6a..f43b13dfca7 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1886,6 +1886,7 @@ ObjectProperty *object_class_property_add_link(ObjectClass *oc, Object *val, Error **errp), ObjectPropertyLinkFlags flags); +bool object_property_is_child(ObjectProperty *prop); /** * object_resolve_and_typecheck: * @path: path to look up diff --git a/qom/object.c b/qom/object.c index 14fd2f3d17e..4a3c2a8f4a6 100644 --- a/qom/object.c +++ b/qom/object.c @@ -589,11 +589,6 @@ void object_initialize_child_internal(Object *parent, &error_abort, NULL); } -static inline bool object_property_is_child(ObjectProperty *prop) -{ - return strstart(prop->type, "child<", NULL); -} - static void object_property_del_all(Object *obj) { g_autoptr(GHashTable) done = g_hash_table_new(NULL, NULL); @@ -2159,6 +2154,15 @@ object_property_add_const_link(Object *obj, const char *name, NULL, OBJ_PROP_LINK_DIRECT); } +bool object_property_is_child(ObjectProperty *prop) +{ + if (prop->get == object_get_child_property) { + assert(prop->qom_type); + return true; + } + return false; +} + const char *object_get_canonical_path_component(const Object *obj) { ObjectProperty *prop = NULL; -- 2.55.0
Several functions parse member @type to decide whether it is a link. Use new object_property_is_link() instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- include/qom/object.h | 2 ++ hw/ppc/spapr_drc.c | 4 ++-- qom/object.c | 14 ++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index f43b13dfca7..b394ec642d3 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1887,6 +1887,8 @@ ObjectProperty *object_class_property_add_link(ObjectClass *oc, ObjectPropertyLinkFlags flags); bool object_property_is_child(ObjectProperty *prop); +bool object_property_is_link(ObjectProperty *prop); + /** * object_resolve_and_typecheck: * @path: path to look up diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 7663f232e05..a10410c8ec3 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -882,7 +882,7 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask) g_autofree char *drc_name = NULL; uint32_t drc_index, drc_power_domain; - if (!strstart(prop->type, "link<", NULL)) { + if (!object_property_is_link(prop)) { continue; } @@ -971,7 +971,7 @@ restart: while ((prop = object_property_iter_next(&iter))) { SpaprDrc *drc; - if (!strstart(prop->type, "link<", NULL)) { + if (!object_property_is_link(prop)) { continue; } drc = SPAPR_DR_CONNECTOR(object_property_get_link(drc_container, diff --git a/qom/object.c b/qom/object.c index 4a3c2a8f4a6..badc12fe4a8 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2163,6 +2163,14 @@ bool object_property_is_child(ObjectProperty *prop) return false; } +bool object_property_is_link(ObjectProperty *prop) +{ + if (object_property_is_child(prop)) { + return false; + } + return prop->qom_type != NULL; +} + const char *object_get_canonical_path_component(const Object *obj) { ObjectProperty *prop = NULL; @@ -3084,8 +3092,7 @@ object_property_add_alias(Object *obj, const char *name, &error_abort); if (object_property_is_child(target_prop)) { - prop_type = g_strdup_printf("link%s", - target_prop->type + strlen("child")); + prop_type = g_strdup_printf("link<%s>", target_prop->qom_type); } else { prop_type = g_strdup(target_prop->type); } @@ -3130,8 +3137,7 @@ object_class_property_add_alias(ObjectClass *klass, const char *name, assert(target_prop); if (object_property_is_child(target_prop)) { - prop_type = g_strdup_printf("link%s", - target_prop->type + strlen("child")); + prop_type = g_strdup_printf("link<%s>", target_prop->qom_type); } else { prop_type = g_strdup(target_prop->type); } -- 2.55.0
ObjectPropertyInfo member @type is "child<T>" for a child property of QOM type T, and "link<T>" for a link property of QOM type T. Such encoding of information in strings should be avoided in QMP, because it requires clients to parse the strings in addition to parse JSON. Turn ObjectPropertyInfo into a union with discriminator @kind and a variant member @qom-type in branches "child" and "link". This provides the same information unencoded. A later commit will deprecate @type. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- qapi/qom.json | 48 +++++++++++++++++++++++++++++++++++++++------- qom/qom-qmp-cmds.c | 9 +++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index cc642c7ba97..ca74b652a0d 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -15,11 +15,33 @@ # *********************** ## +## +# @ObjectPropertyKind: +# +# @child: TODO +# +# @link: TODO +# +# @other: TODO +## +{ 'enum': 'ObjectPropertyKind', + 'data': [ 'child', 'link', 'other' ] } + +## +# @ObjectPropertyQomType: +# +# @qom-type: TODO +## +{ 'struct': 'ObjectPropertyQomType', + 'data': { 'qom-type': 'str' } } + ## # @ObjectPropertyInfo: # # @name: the name of the property # +# @kind: TODO +# # @type: the type of the property. This will typically come in one of # four forms: # @@ -48,12 +70,16 @@ # # Since: 1.2 ## -{ 'struct': 'ObjectPropertyInfo', - 'data': { 'name': 'str', +{ 'union': 'ObjectPropertyInfo', + 'base': { 'name': 'str', + 'kind': 'ObjectPropertyKind', 'type': 'str', 'qapi-type': { 'type': 'str', 'features': [ 'unstable' ] }, '*description': 'str', - '*default-value': 'any' } } + '*default-value': 'any' }, + 'discriminator': 'kind', + 'data': { 'child': 'ObjectPropertyQomType', + 'link': 'ObjectPropertyQomType' } } ## # @ObjectPropertyValue: @@ -106,10 +132,18 @@ # # -> { "execute": "qom-list", # "arguments": { "path": "/chardevs" } } -# <- { "return": [ { "name": "type", "type": "string" }, -# { "name": "parallel0", "type": "child<chardev-vc>" }, -# { "name": "serial0", "type": "child<chardev-vc>" }, -# { "name": "mon0", "type": "child<chardev-stdio>" } ] } +# <- {"return": [ +# {"name": "type", "kind": "other", "qapi-type": "str", +# "type": "string"}, +# {"name": "parallel0", "kind": "child", "qapi-type": "str", +# "type": "child<chardev-vc>", +# "qom-type": "chardev-vc"}, +# {"name": "compat_monitor0", "kind": "child", "qapi-type": "str", +# "type": "child<chardev-stdio>", +# "qom-type": "chardev-stdio"}, +# {"name": "serial0", "kind": "child", "qapi-type": "str", +# "type": "child<chardev-vc>", +# "qom-type": "chardev-vc"}]} ## { 'command': 'qom-list', 'data': { 'path': 'str' }, diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 84a29590514..2b491caaf7a 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -34,6 +34,15 @@ static ObjectPropertyInfo *qom_property_info(ObjectProperty *prop) ObjectPropertyInfo *info = g_new0(ObjectPropertyInfo, 1); info->name = g_strdup(prop->name); + if (object_property_is_child(prop)) { + info->kind = OBJECT_PROPERTY_KIND_CHILD; + info->u.child.qom_type = g_strdup(prop->qom_type); + } else if (object_property_is_link(prop)) { + info->kind = OBJECT_PROPERTY_KIND_LINK; + info->u.link.qom_type = g_strdup(prop->qom_type); + } else { + info->kind = OBJECT_PROPERTY_KIND_OTHER; + } info->type = g_strdup(prop->type); info->description = g_strdup(prop->description); info->default_value = qobject_ref(prop->defval); -- 2.55.0
Use member @kind instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- qom/qom-hmp-cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index bbf5980332a..52c08c7060b 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -211,7 +211,7 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str) while (list) { ObjectPropertyInfo *info = list->value; - if (!strncmp(info->type, "child<", 5)) { + if (info->kind == OBJECT_PROPERTY_KIND_CHILD) { readline_add_completion_of(rs, str, info->name); } list = list->next; -- 2.55.0
Use members @kind and @qom-type instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- tests/qtest/device-introspect-test.c | 4 ++-- tests/qtest/qom-test.c | 4 ++-- tests/qtest/readconfig-test.c | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/qtest/device-introspect-test.c b/tests/qtest/device-introspect-test.c index f6eca2c8eb7..60afdbbc9d0 100644 --- a/tests/qtest/device-introspect-test.c +++ b/tests/qtest/device-introspect-test.c @@ -120,8 +120,8 @@ static void qom_tree_walk(QTestState *qts, const char *path, GString *result) QLIST_FOREACH_ENTRY(list, e) { QDict *prop = qobject_to(QDict, qlist_entry_obj(e)); - const char *type = qdict_get_str(prop, "type"); - if (g_str_has_prefix(type, "child<")) { + const char *kind = qdict_get_str(prop, "kind"); + if (!strcmp(kind, "child")) { const char *name = qdict_get_str(prop, "name"); children = g_list_prepend(children, g_strdup(name)); } diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c index cf4c6b5add5..6f1e9606c5e 100644 --- a/tests/qtest/qom-test.c +++ b/tests/qtest/qom-test.c @@ -148,8 +148,8 @@ static void test_properties(QTestState *qts, const char *path, bool recurse) list = qobject_to(QList, qdict_get(response, "return")); QLIST_FOREACH_ENTRY(list, entry) { tuple = qobject_to(QDict, qlist_entry_obj(entry)); - bool is_child = strstart(qdict_get_str(tuple, "type"), "child<", NULL); - bool is_link = strstart(qdict_get_str(tuple, "type"), "link<", NULL); + bool is_child = !strcmp(qdict_get_str(tuple, "kind"), "child"); + bool is_link = !strcmp(qdict_get_str(tuple, "kind"), "link"); if (is_child || is_link) { child_path = g_strdup_printf("%s/%s", diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c index c6f32a4e144..7e473f98ee0 100644 --- a/tests/qtest/readconfig-test.c +++ b/tests/qtest/readconfig-test.c @@ -132,7 +132,6 @@ static void test_object_available(QObject *res, const char *name, ObjectPropertyInfoList *tmp; ObjectPropertyInfo *obj; bool object_available = false; - g_autofree char *childtype = g_strdup_printf("child<%s>", type); g_assert(res); v = qobject_input_visitor_new(res); @@ -144,7 +143,9 @@ static void test_object_available(QObject *res, const char *name, g_assert(tmp->value); obj = tmp->value; - if (g_str_equal(obj->name, name) && g_str_equal(obj->type, childtype)) { + if (g_str_equal(obj->name, name) + && obj->kind == OBJECT_PROPERTY_KIND_CHILD + && g_str_equal(obj->u.child.qom_type, type)) { object_available = true; break; } -- 2.55.0
Use members @kind and @qom-type instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- python/qemu/utils/qom_common.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/python/qemu/utils/qom_common.py b/python/qemu/utils/qom_common.py index e5bae1c7421..8d324f29cc3 100644 --- a/python/qemu/utils/qom_common.py +++ b/python/qemu/utils/qom_common.py @@ -35,11 +35,12 @@ class ObjectPropertyInfo: """ Represents the return type from e.g. qom-list. """ - def __init__(self, name: str, type_: str, + def __init__(self, name: str, kind: str, qom_type: Optional[str], description: Optional[str] = None, default_value: Optional[object] = None): self.name = name - self.type = type_ + self.kind = kind + self.qom_type = qom_type self.description = description self.default_value = default_value @@ -48,20 +49,20 @@ def make(cls, value: Dict[str, Any]) -> 'ObjectPropertyInfo': """ Build an ObjectPropertyInfo from a Dict with an unknown shape. """ - assert value.keys() >= {'name', 'type'} - return cls(value['name'], value['type'], + assert value.keys() >= {'name', 'kind'} + return cls(value['name'], value['kind'], value.get('qom-type'), value.get('description'), value.get('default-value')) @property def child(self) -> bool: """Is this property a child property?""" - return self.type.startswith('child<') + return self.kind == "child" @property def link(self) -> bool: """Is this property a link property?""" - return self.type.startswith('link<') + return self.kind == "link" class ObjectPropertyValue: -- 2.55.0
ObjectPropertyValue member @type is "child<T>" for a child property of QOM type T, and "link<T>" for a link property of QOM type T. Such encoding of information in strings should be avoided in QMP, because it requires clients to parse the strings in addition to parse JSON. Turn ObjectPropertyValue into a union with discriminator @kind and a variant member @qom-type in branches "child" and "link". This provides the same information unencoded. A later commit will deprecate @type. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- qapi/qom.json | 12 +++++++++--- qom/qom-qmp-cmds.c | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index ca74b652a0d..0b274787b3f 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -86,6 +86,8 @@ # # @name: the name of the property. # +# @kind: TODO +# # @type: the type of the property, as described in # `ObjectPropertyInfo`. # @@ -101,11 +103,15 @@ # # Since: 10.1 ## -{ 'struct': 'ObjectPropertyValue', - 'data': { 'name': 'str', +{ 'union': 'ObjectPropertyValue', + 'base': { 'name': 'str', + 'kind': 'ObjectPropertyKind', 'type': 'str', 'qapi-type': { 'type': 'str', 'features': [ 'unstable' ] }, - '*value': 'any' } } + '*value': 'any' }, + 'discriminator': 'kind', + 'data': { 'child': 'ObjectPropertyQomType', + 'link': 'ObjectPropertyQomType' } } ## # @ObjectPropertiesValues: diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 2b491caaf7a..d2945d1efe0 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -97,6 +97,15 @@ static void qom_list_add_property_value(Object *obj, ObjectProperty *prop, QAPI_LIST_PREPEND(*props, item); item->name = g_strdup(prop->name); + if (object_property_is_child(prop)) { + item->kind = OBJECT_PROPERTY_KIND_CHILD; + item->u.child.qom_type = g_strdup(prop->qom_type); + } else if (object_property_is_link(prop)) { + item->kind = OBJECT_PROPERTY_KIND_LINK; + item->u.link.qom_type = g_strdup(prop->qom_type); + } else { + item->kind = OBJECT_PROPERTY_KIND_OTHER; + } item->type = g_strdup(prop->type); if (prop->qapi_type) { assert(prop->qapi_type->masked_name); -- 2.55.0
Use member @kind instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- tests/qtest/qom-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c index 6f1e9606c5e..51e31d79997 100644 --- a/tests/qtest/qom-test.c +++ b/tests/qtest/qom-test.c @@ -98,7 +98,7 @@ static void test_list_get(QTestState *qts, QList *paths) prop = qobject_to(QDict, qlist_entry_obj(prop_entry)); g_assert(qdict_haskey(prop, "name")); g_assert(qdict_haskey(prop, "type")); - has_child |= strstart(qdict_get_str(prop, "type"), "child<", NULL); + has_child |= !strcmp(qdict_get_str(prop, "kind"), "child"); } if (has_child) { @@ -109,7 +109,7 @@ static void test_list_get(QTestState *qts, QList *paths) QLIST_FOREACH_ENTRY(properties, prop_entry) { prop = qobject_to(QDict, qlist_entry_obj(prop_entry)); - if (strstart(qdict_get_str(prop, "type"), "child<", NULL)) { + if (!strcmp(qdict_get_str(prop, "kind"), "child")) { g_autofree char *child_path = g_strdup_printf( "%s/%s", path, qdict_get_str(prop, "name")); qlist_append_str(child_paths, child_path); -- 2.55.0
QOMTree._list_nodes() uses @type to print non-child properties like "NAME: VALUE (TYPE)". Drop (TYPE). This affects qom-tree. Replace all other uses of @type by @kind and @qom-type. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- python/qemu/utils/qom.py | 2 +- python/qemu/utils/qom_common.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/python/qemu/utils/qom.py b/python/qemu/utils/qom.py index 05e5f141791..9f113240f9b 100644 --- a/python/qemu/utils/qom.py +++ b/python/qemu/utils/qom.py @@ -242,7 +242,7 @@ def _list_nodes(self, paths: List[str]) -> None: value = item.value if value is None: value = "<EXCEPTION: property could not be read>" - print(f" {item.name}: {value} ({item.type})") + print(f" {item.name}: {value}") print('') diff --git a/python/qemu/utils/qom_common.py b/python/qemu/utils/qom_common.py index 8d324f29cc3..c0f684bc455 100644 --- a/python/qemu/utils/qom_common.py +++ b/python/qemu/utils/qom_common.py @@ -69,9 +69,11 @@ class ObjectPropertyValue: """ Represents a property return from e.g. qom-tree-get """ - def __init__(self, name: str, type_: str, value: object): + def __init__(self, name: str, kind: str, qom_type: Optional[str], + value: object): self.name = name - self.type = type_ + self.kind = kind + self.qom_type = qom_type self.value = value @classmethod @@ -79,13 +81,14 @@ def make(cls, value: Dict[str, Any]) -> 'ObjectPropertyValue': """ Build an ObjectPropertyValue from a Dict with an unknown shape. """ - assert value.keys() >= {'name', 'type'} - return cls(value['name'], value['type'], value.get('value')) + assert value.keys() >= {'name', 'kind'} + return cls(value['name'], value['kind'], value.get('qom-type'), + value.get('value')) @property def child(self) -> bool: """Is this property a child property?""" - return self.type.startswith('child<') + return self.kind == "child" class ObjectPropertiesValues: @@ -104,7 +107,7 @@ def make(cls, value: Dict[str, Any]) -> 'ObjectPropertiesValues': """ assert value.keys() <= {'properties'} props = [ObjectPropertyValue(item['name'], - item['type'], + item['kind'], item.get('qom-type'), item.get('value')) for item in value['properties']] return cls(props) -- 2.55.0
Use members @kind, @qapi-type, and @qom-type instead. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- docs/about/deprecated.rst | 5 +++++ qapi/qom.json | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 5ab329705b6..bcae9c0afbc 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -190,6 +190,11 @@ so the concept of an 'unavailable' trace event no longer exists. The ``ignore-unavailable`` parameter in ``trace-event-set-state`` thus has no effect and should no longer be used. +``qom-list``, ``qom-list-property``, ``qom-list-get`` return value member @type (since 12.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Use members @kind, @qapi-type, and @qom-type instead. + Human Machine Protocol (HMP) commands ------------------------------------- diff --git a/qapi/qom.json b/qapi/qom.json index 0b274787b3f..e41add67059 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -66,15 +66,16 @@ # # Features: # -# @unstable: Member @qapi-type is experimental. +# @deprecated: Member @type is deprecated. Use @kind, @qapi-type, and +# @qom-type instead. # # Since: 1.2 ## { 'union': 'ObjectPropertyInfo', 'base': { 'name': 'str', 'kind': 'ObjectPropertyKind', - 'type': 'str', - 'qapi-type': { 'type': 'str', 'features': [ 'unstable' ] }, + 'type': { 'type': 'str', 'features': [ 'deprecated' ] }, + 'qapi-type': 'str', '*description': 'str', '*default-value': 'any' }, 'discriminator': 'kind', @@ -99,15 +100,16 @@ # # Features: # -# @unstable: Member @qapi-type is experimental. +# @deprecated: Member @type is deprecated. Use @kind, @qapi-type, and +# @qom-type instead. # # Since: 10.1 ## { 'union': 'ObjectPropertyValue', 'base': { 'name': 'str', 'kind': 'ObjectPropertyKind', - 'type': 'str', - 'qapi-type': { 'type': 'str', 'features': [ 'unstable' ] }, + 'type': { 'type': 'str', 'features': [ 'deprecated' ] }, + 'qapi-type': 'str', '*value': 'any' }, 'discriminator': 'kind', 'data': { 'child': 'ObjectPropertyQomType', -- 2.55.0
On Thu, Nov 26, 2026 at 11:01:39 +0100, Markus Armbruster via Devel wrote:
Use members @kind, @qapi-type, and @qom-type instead.
Signed-off-by: Markus Armbruster <armbru@redhat.com> --- docs/about/deprecated.rst | 5 +++++ qapi/qom.json | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 5ab329705b6..bcae9c0afbc 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -190,6 +190,11 @@ so the concept of an 'unavailable' trace event no longer exists. The ``ignore-unavailable`` parameter in ``trace-event-set-state`` thus has no effect and should no longer be used.
+``qom-list``, ``qom-list-property``, ``qom-list-get`` return value member @type (since 12.0) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Use members @kind, @qapi-type, and @qom-type instead.
libvirt proper doesn't currently look at the 'type' property at all. We're only interested in the name of the property and internally assume the type. (Said that I'll be looking into using 'qapi-type' as source of data for validating properties of -device we generate when I'll have time to look at it. I had already some code where I tried to synthetize the data but this oguth to be much simpler and already present in our queries) The only code in the libvirt repo which looks at @type is the scripts/qemu-replies-tool script when the --dump-all mode is used, which I use to generate diffs of capabilities of qemu, but that is used only manually so I'll address that after this will be comitted. On behalf of libvirt: ACKed-by: Peter Krempa <pipo@pipo.sk>
participants (2)
-
Markus Armbruster -
Peter Krempa