- Add machine_class_set_name() so boards can keep a stable -M name when the QOM type is uniquified. machine_class_base_init still defaults the name to the QOM type without -machine. - Document that MachineClass::name is the -M name, not the QOM type. - Sort -M help by MachineClass::name so order matches the printed names when QOM types are prefixed (arm-virt-11.1-machine vs virt-11.1).
Signed-off-by: Yonggang Luo <[email protected]> --- hw/core/machine.c | 6 ++++++ include/hw/core/boards.h | 12 +++++++++++- system/vl.c | 8 +++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 73b4d82b4a1..082f95e4349 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1209,6 +1209,12 @@ static void machine_class_init(ObjectClass *oc, const void *data) "Memory size configuration"); } +void machine_class_set_name(MachineClass *mc, const char *name) +{ + g_free(mc->name); + mc->name = g_strdup(name); +} + static void machine_class_base_init(ObjectClass *oc, const void *data) { MachineClass *mc = MACHINE_CLASS(oc); diff --git a/include/hw/core/boards.h b/include/hw/core/boards.h index c963e956157..cb6a37235a2 100644 --- a/include/hw/core/boards.h +++ b/include/hw/core/boards.h @@ -37,6 +37,16 @@ const char *machine_default_cpu_type(const MachineState *ms); * @mc: Machine class */ const char *machine_class_default_cpu_type(MachineClass *mc); +/** + * machine_class_set_name: Set the -M name when it differs from the QOM type + * @mc: Machine class + * @name: Name used by -M lookup, help, and migration + * + * machine_class_base_init sets MachineClass::name from the QOM type with + * the -machine suffix removed. Call this from board class_init when the + * CLI name must stay stable after the QOM type is uniquified. + */ +void machine_class_set_name(MachineClass *mc, const char *name); void machine_add_audiodev_property(MachineClass *mc); void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp); @@ -270,7 +280,7 @@ struct MachineClass { /*< public >*/ const char *family; /* NULL iff @name identifies a standalone machtype */ - char *name; + char *name; /* -M name; default is QOM type without -machine */ const char *alias; const char *desc; const char *deprecation_reason; diff --git a/system/vl.c b/system/vl.c index 83b9425de9b..4b1fcd2031f 100644 --- a/system/vl.c +++ b/system/vl.c @@ -1538,10 +1538,9 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b, gpointer d) if (mc1->family == NULL) { if (mc2->family == NULL) { /* Compare standalone machine types against each other; they sort - * in increasing order. + * in increasing order by the name shown in -M help. */ - return strcmp(object_class_get_name(OBJECT_CLASS(mc1)), - object_class_get_name(OBJECT_CLASS(mc2))); + return strcmp(mc1->name, mc2->name); } /* Standalone machine types sort after families. */ @@ -1560,8 +1559,7 @@ static gint machine_class_cmp(gconstpointer a, gconstpointer b, gpointer d) } /* Within the same family, machine types sort in decreasing order. */ - return strcmp(object_class_get_name(OBJECT_CLASS(mc2)), - object_class_get_name(OBJECT_CLASS(mc1))); + return strcmp(mc2->name, mc1->name); } static void machine_help_func(const QDict *qdict) -- 2.52.0.windows.1
