The MachineInfo struct is extended to report the list of aliases
from the TYPE_ALIASED interface, in preference to the traditional
alias from the TYPE_MACHINE struct.

Initially we use 'alias' to fill the 'aliases' field in QOM. As
machines get converted to set 'aliases', the first 'aliases'
element will get used to fill 'alias. This provides backcompat
during the transition phase.

Signed-off-by: Daniel P. Berrangé <[email protected]>
---
 hw/core/machine-qmp-cmds.c | 25 +++++++++++++++++++++++++
 qapi/machine.json          |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 0558d6d703c..787c69e176f 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -33,6 +33,7 @@
 #include "system/runstate.h"
 #include "system/system.h"
 #include "hw/s390x/storage-keys.h"
+#include "qom/object_interfaces.h"
 
 /*
  * QMP query for enabled and present accelerators
@@ -163,6 +164,7 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, 
bool compat_props,
         MachineClass *mc = el->data;
         const char *default_cpu_type = machine_class_default_cpu_type(mc);
         MachineInfo *info;
+        AliasedClass *alc = ALIASED_CLASS(mc);
 
         info = g_malloc0(sizeof(*info));
         if (mc->is_default) {
@@ -170,8 +172,31 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, 
bool compat_props,
             info->is_default = true;
         }
 
+        if (alc->aliases) {
+            strList **aliases = &info->aliases;
+            size_t i;
+            info->has_aliases = true;
+            for (i = 0; alc->aliases[i] != NULL; i++) {
+                /*
+                 * We record type names internally, but publically
+                 * we report machine types to the user, hence must
+                 * strip the typename suffix
+                 */
+                int len = strlen(alc->aliases[i]) - 
strlen(TYPE_MACHINE_SUFFIX);
+                QAPI_LIST_APPEND(aliases,
+                                 g_strndup(alc->aliases[i], len));
+            }
+            if (!mc->alias) {
+                int len = strlen(alc->aliases[0]) - 
strlen(TYPE_MACHINE_SUFFIX);
+                info->alias = g_strndup(alc->aliases[0], len);
+            }
+        }
         if (mc->alias) {
             info->alias = g_strdup(mc->alias);
+            if (!info->aliases) {
+                strList **aliases = &info->aliases;
+                QAPI_LIST_APPEND(aliases, g_strdup(mc->alias));
+            }
         }
 
         info->name = g_strdup(mc->name);
diff --git a/qapi/machine.json b/qapi/machine.json
index 18d9dce849b..c25a492a4e8 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -163,6 +163,8 @@
 #
 # @alias: an alias for the machine name
 #
+# @aliases: a list of aliases for the machine type name (since 12.0)
+#
 # @is-default: whether the machine is default
 #
 # @cpu-max: maximum number of CPUs supported by the machine type
@@ -202,6 +204,7 @@
 ##
 { 'struct': 'MachineInfo',
   'data': { 'name': 'str', '*alias': 'str',
+            '*aliases': ['str'],
             '*is-default': 'bool', 'cpu-max': 'int',
             'hotpluggable-cpus': 'bool',  'numa-mem-supported': 'bool',
             'deprecated': 'bool', '*default-cpu-type': 'str',
-- 
2.56.1


Reply via email to