query-targets lists each linked target, including none, with its arch, endianness, and the machines that target accepts.
Signed-off-by: Yonggang Luo <[email protected]> --- hw/core/machine-qmp-cmds.c | 30 ++++++++++++++++++++++++++++++ qapi/machine.json | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index 9c08b17510a..c7b73efa31d 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -21,6 +21,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/type-helpers.h" #include "qemu/uuid.h" +#include "qemu/target-info-def.h" #include "qemu/target-info.h" #include "qemu/target-info-qapi.h" #include "qom/qom-qobject.h" @@ -173,6 +174,35 @@ QemuTargetInfo *qmp_query_target(Error **errp) return info; } +TargetMachinesList *qmp_query_targets(Error **errp) +{ + TargetMachinesList *head = NULL; + TargetMachinesList **tail = &head; + GSList *machines, *el; + TargetInfoNode *node; + + machines = object_class_get_list(TYPE_MACHINE, false); + QLIST_FOREACH(node, target_info_list(), next) { + const TargetInfo *ti = node->info; + TargetMachines *row = g_new0(TargetMachines, 1); + strList **names = &row->machines; + + row->arch = ti->target_arch; + row->endianness = ti->endianness; + for (el = machines; el; el = el->next) { + MachineClass *mc = el->data; + + if (!object_class_get_is_available(OBJECT_CLASS(mc))(ti)) { + continue; + } + QAPI_LIST_APPEND(names, g_strdup(mc->name)); + } + QAPI_LIST_APPEND(tail, row); + } + g_slist_free(machines); + return head; +} + HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp) { MachineState *ms = MACHINE(qdev_get_machine()); diff --git a/qapi/machine.json b/qapi/machine.json index 6aaa2af709a..d8cdea6203e 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -307,6 +307,41 @@ ## { 'command': 'query-target', 'returns': 'QemuTargetInfo' } +## +# @TargetMachines: +# +# One registered system target and the machines that can run on it. +# +# @arch: the target architecture +# +# @endianness: the target endianness +# +# @machines: machine type names, not aliases +# +# Since: 11.2 +## +{ 'struct': 'TargetMachines', + 'data': { 'arch': 'SysEmuTarget', + 'endianness': 'EndianMode', + 'machines': ['str'] } } + +## +# @query-targets: +# +# Return each target linked into this QEMU binary and the machines +# whose availability check accepts that target. +# +# Since: 11.2 +# +# .. qmp-example:: +# +# -> { "execute": "query-targets" } +# <- { "return": [ { "arch": "aarch64", "endianness": "little", +# "machines": [ "virt" ] } ] } +## +{ 'command': 'query-targets', + 'returns': ['TargetMachines'] } + ## # @UuidInfo: # -- 2.52.0.windows.1
