> - 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]>
> Reviewed-by: Daniel P. Berrangé <[email protected]>
> Message-ID: <[email protected]>
>
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 92f7be52a13f..6b933f2302d5 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -1215,6 +1215,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 3b86724cf007..851140ad0520 100644
> --- a/include/hw/core/boards.h
> +++ b/include/hw/core/boards.h
> @@ -36,6 +36,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);

add machine_class_set_name() to the comment example around line 484:

Add after the existing mc->desc line in the example:
 *          machine_class_set_name(mc, "virt-" MACHINE_VER_STR(__VA_ARGS__)); \

And update the example's type name from "virt" to show a prefixed name like
"arm-virt" so it matches the real usage pattern.

-- 
Marc-André Lureau <[email protected]>


Reply via email to