From 98cec76a7076c4a38e16f1a9de170a7942b3be54 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 20 Aug 2015 14:54:36 -0700 Subject: [PATCH] machine: Set MachineClass::name automatically MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Now all TYPE_MACHINE subclasses use MACHINE_TYPE_NAME to generate the class name. So instead of requiring each subclass to set MachineClass::name manually, we can now set it automatically at the TYPE_MACHINE class_base_init() function. Signed-off-by: Eduardo Habkost Reviewed-by: Marcel Apfelbaum [AF/ehabkost: Updated for s390-ccw machines] [AF: Cleanup of intermediate virt and vexpress name handling] Signed-off-by: Andreas Färber --- hw/arm/vexpress.c | 8 ++------ hw/arm/virt.c | 4 +--- hw/core/machine.c | 3 +++ hw/ppc/mac_newworld.c | 1 - hw/ppc/spapr.c | 4 ---- hw/s390x/s390-virtio-ccw.c | 2 -- hw/s390x/s390-virtio.c | 1 - vl.c | 1 - 8 files changed, 6 insertions(+), 18 deletions(-) diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c index 2bcd312..058abbd 100644 --- a/hw/arm/vexpress.c +++ b/hw/arm/vexpress.c @@ -168,10 +168,8 @@ typedef struct { } VexpressMachineState; #define TYPE_VEXPRESS_MACHINE "vexpress" -#define VEXPRESS_A9_MACHINE_NAME "vexpress-a9" -#define VEXPRESS_A15_MACHINE_NAME "vexpress-a15" -#define TYPE_VEXPRESS_A9_MACHINE MACHINE_TYPE_NAME(VEXPRESS_A9_MACHINE_NAME) -#define TYPE_VEXPRESS_A15_MACHINE MACHINE_TYPE_NAME(VEXPRESS_A15_MACHINE_NAME) +#define TYPE_VEXPRESS_A9_MACHINE MACHINE_TYPE_NAME("vexpress-a9") +#define TYPE_VEXPRESS_A15_MACHINE MACHINE_TYPE_NAME("vexpress-a15") #define VEXPRESS_MACHINE(obj) \ OBJECT_CHECK(VexpressMachineState, (obj), TYPE_VEXPRESS_MACHINE) #define VEXPRESS_MACHINE_GET_CLASS(obj) \ @@ -760,7 +758,6 @@ static void vexpress_a9_class_init(ObjectClass *oc, void *data) MachineClass *mc = MACHINE_CLASS(oc); VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc); - mc->name = VEXPRESS_A9_MACHINE_NAME; mc->desc = "ARM Versatile Express for Cortex-A9"; vmc->daughterboard = &a9_daughterboard; @@ -771,7 +768,6 @@ static void vexpress_a15_class_init(ObjectClass *oc, void *data) MachineClass *mc = MACHINE_CLASS(oc); VexpressMachineClass *vmc = VEXPRESS_MACHINE_CLASS(oc); - mc->name = VEXPRESS_A15_MACHINE_NAME; mc->desc = "ARM Versatile Express for Cortex-A15"; vmc->daughterboard = &a15_daughterboard; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index fba2595..6bf0d6d 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -83,8 +83,7 @@ typedef struct { bool highmem; } VirtMachineState; -#define VIRT_MACHINE_NAME "virt" -#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME(VIRT_MACHINE_NAME) +#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt") #define VIRT_MACHINE(obj) \ OBJECT_CHECK(VirtMachineState, (obj), TYPE_VIRT_MACHINE) #define VIRT_MACHINE_GET_CLASS(obj) \ @@ -1074,7 +1073,6 @@ static void virt_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - mc->name = VIRT_MACHINE_NAME; mc->desc = "ARM Virtual Machine", mc->init = machvirt_init; mc->max_cpus = 8; diff --git a/hw/core/machine.c b/hw/core/machine.c index 3c1f248..f4db340 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -319,8 +319,11 @@ static void machine_class_init(ObjectClass *oc, void *data) static void machine_class_base_init(ObjectClass *oc, void *data) { if (!object_class_is_abstract(oc)) { + MachineClass *mc = MACHINE_CLASS(oc); const char *cname = object_class_get_name(oc); assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX)); + mc->name = g_strndup(cname, + strlen(cname) - strlen(TYPE_MACHINE_SUFFIX)); } } diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c index 31c40c9..e1c5ed7 100644 --- a/hw/ppc/mac_newworld.c +++ b/hw/ppc/mac_newworld.c @@ -508,7 +508,6 @@ static void core99_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - mc->name = "mac99"; mc->desc = "Mac99 based PowerMAC"; mc->init = ppc_core99_init; mc->max_cpus = MAX_CPUS; diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 012b6ed..05926a3 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1919,7 +1919,6 @@ static void spapr_machine_2_1_class_init(ObjectClass *oc, void *data) { /* end of list */ } }; - mc->name = "pseries-2.1"; mc->desc = "pSeries Logical Partition (PAPR compliant) v2.1"; mc->compat_props = compat_props; } @@ -1939,7 +1938,6 @@ static void spapr_machine_2_2_class_init(ObjectClass *oc, void *data) }; MachineClass *mc = MACHINE_CLASS(oc); - mc->name = "pseries-2.2"; mc->desc = "pSeries Logical Partition (PAPR compliant) v2.2"; mc->compat_props = compat_props; } @@ -1959,7 +1957,6 @@ static void spapr_machine_2_3_class_init(ObjectClass *oc, void *data) }; MachineClass *mc = MACHINE_CLASS(oc); - mc->name = "pseries-2.3"; mc->desc = "pSeries Logical Partition (PAPR compliant) v2.3"; mc->compat_props = compat_props; } @@ -1975,7 +1972,6 @@ static void spapr_machine_2_4_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - mc->name = "pseries-2.4"; mc->desc = "pSeries Logical Partition (PAPR compliant) v2.4"; mc->alias = "pseries"; mc->is_default = 1; diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index e738b5b..36f78b4 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -252,7 +252,6 @@ static void ccw_machine_2_4_class_init(ObjectClass *oc, void *data) { /* end of list */ } }; - mc->name = "s390-ccw-virtio-2.4"; mc->desc = "VirtIO-ccw based S390 machine v2.4"; mc->compat_props = compat_props; } @@ -267,7 +266,6 @@ static void ccw_machine_2_5_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - mc->name = "s390-ccw-virtio-2.5"; mc->alias = "s390-ccw-virtio"; mc->desc = "VirtIO-ccw based S390 machine v2.5"; mc->is_default = 1; diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index a1eca09..bc013eb 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -319,7 +319,6 @@ static void s390_machine_class_init(ObjectClass *oc, void *data) MachineClass *mc = MACHINE_CLASS(oc); NMIClass *nc = NMI_CLASS(oc); - mc->name = S390_MACHINE; mc->alias = "s390"; mc->desc = "VirtIO based S390 machine"; mc->init = s390_init; diff --git a/vl.c b/vl.c index 3c6c9b0..3b92635 100644 --- a/vl.c +++ b/vl.c @@ -1437,7 +1437,6 @@ static void qemu_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); QEMUMachine *qm = data; - mc->name = qm->name; mc->desc = qm->desc; mc->init = qm->init; mc->kvm_type = qm->kvm_type; -- 2.7.4