query-machines returned only the -M name, so management apps inferred the QOM type as that name plus "-machine". A prefixed type such as arm-virt-11.1-machine no longer matches -M virt-11.1. Return the QOM type in MachineInfo typename from object_class_get_name() in qmp_query_machines(). test_query_machines_typename checks that qom-list-properties accepts it.
Signed-off-by: Yonggang Luo <[email protected]> --- hw/core/machine-qmp-cmds.c | 1 + qapi/machine.json | 6 +++- tests/qtest/qom-test.c | 65 ++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index 9c08b17510a..27ceed54a14 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -116,6 +116,7 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props, } info->name = g_strdup(mc->name); + info->q_typename = g_strdup(object_class_get_name(OBJECT_CLASS(mc))); info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus; info->hotpluggable_cpus = mc->has_hotpluggable_cpus; info->numa_mem_supported = mc->numa_mem_supported; diff --git a/qapi/machine.json b/qapi/machine.json index b1be5608b61..f5ead98e174 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -168,6 +168,9 @@ # # @name: the name of the machine # +# @typename: QOM type name of the machine, for qom-list-properties +# (since 11.2) +# # @alias: an alias for the machine name # # @is-default: whether the machine is default @@ -208,7 +211,7 @@ # Since: 1.2 ## { 'struct': 'MachineInfo', - 'data': { 'name': 'str', '*alias': 'str', + 'data': { 'name': 'str', 'typename': 'str', '*alias': 'str', '*is-default': 'bool', 'cpu-max': 'int', 'hotpluggable-cpus': 'bool', 'numa-mem-supported': 'bool', 'deprecated': 'bool', '*default-cpu-type': 'str', @@ -238,6 +241,7 @@ # { # "hotpluggable-cpus": true, # "name": "pc-q35-6.2", +# "typename": "pc-q35-6.2-machine", # "compat-props": [ # { # "qom-type": "virtio-mem", diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c index cf4c6b5add5..4ee95af6d94 100644 --- a/tests/qtest/qom-test.c +++ b/tests/qtest/qom-test.c @@ -200,13 +200,32 @@ static void test_machine(gconstpointer data) if (g_test_slow()) { /* Make sure we can get the machine class properties: */ - g_autofree char *qom_machine = g_strdup_printf("%s-machine", machine); - - response = qtest_qmp(qts, "{ 'execute': 'qom-list-properties'," - " 'arguments': { 'typename': %s } }", - qom_machine); - g_assert(response); + QList *list; + const QListEntry *p; + bool found = false; + + response = qtest_qmp(qts, "{ 'execute': 'query-machines' }"); + g_assert(!qdict_haskey(response, "error")); + list = qdict_get_qlist(response, "return"); + g_assert(list); + for (p = qlist_first(list); p; p = qlist_next(p)) { + QDict *minfo = qobject_to(QDict, qlist_entry_obj(p)); + QDict *props; + + if (strcmp(qdict_get_str(minfo, "name"), machine)) { + continue; + } + props = qtest_qmp(qts, "{ 'execute': 'qom-list-properties'," + " 'arguments': { 'typename': %s } }", + qdict_get_str(minfo, "typename")); + g_assert(!qdict_haskey(props, "error")); + g_assert(qdict_haskey(props, "return")); + qobject_unref(props); + found = true; + break; + } qobject_unref(response); + g_assert(found); } test_properties(qts, "/machine", true); @@ -218,6 +237,39 @@ static void test_machine(gconstpointer data) qtest_quit(qts); } +static void test_query_machines_typename(void) +{ + QTestState *qts; + QDict *response; + QList *list; + const QListEntry *p; + bool saw = false; + + qts = qtest_init("-machine none"); + response = qtest_qmp(qts, "{ 'execute': 'query-machines' }"); + g_assert(!qdict_haskey(response, "error")); + list = qdict_get_qlist(response, "return"); + g_assert(list); + + for (p = qlist_first(list); p; p = qlist_next(p)) { + QDict *minfo = qobject_to(QDict, qlist_entry_obj(p)); + const char *typename = qdict_get_str(minfo, "typename"); + g_autoptr(QDict) props = NULL; + + g_assert(g_str_has_suffix(typename, "-machine")); + props = qtest_qmp(qts, "{ 'execute': 'qom-list-properties'," + " 'arguments': { 'typename': %s } }", + typename); + g_assert(!qdict_haskey(props, "error")); + g_assert(qdict_haskey(props, "return")); + saw = true; + } + + g_assert(saw); + qobject_unref(response); + qtest_quit(qts); +} + static void add_machine_test_case(const char *mname) { char *path; @@ -250,6 +302,7 @@ int main(int argc, char **argv) qtest_cb_for_every_machine(add_machine_test_case, g_test_quick()); qtest_add_func("qom/qom-qtests", test_qom_qtests); + qtest_add_func("qom/machine-typename", test_query_machines_typename); return g_test_run(); } -- 2.52.0.windows.1
