From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X3DZK-0001pj-Da for qemu-devel@nongnu.org; Fri, 04 Jul 2014 20:11:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X3DZE-0005AP-6V for qemu-devel@nongnu.org; Fri, 04 Jul 2014 20:11:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X3DZD-0005AL-UD for qemu-devel@nongnu.org; Fri, 04 Jul 2014 20:11:00 -0400 From: Eduardo Habkost Date: Fri, 4 Jul 2014 21:09:37 -0300 Message-Id: <1404519002-10224-11-git-send-email-ehabkost@redhat.com> In-Reply-To: <1404519002-10224-1-git-send-email-ehabkost@redhat.com> References: <1404519002-10224-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [RFC v3 10/35] machine: Make compat_props a linked list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Michael S. Tsirkin" , Alexander Graf , Don Slutz , Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= This will make it easier to write reusable class_init code which adds properties to MachineClass.compat_props. Signed-off-by: Eduardo Habkost --- hw/core/machine.c | 15 +++++++++++++++ hw/core/qdev-properties.c | 9 +++++---- hw/i386/pc.c | 4 +++- include/hw/boards.h | 10 +++++++++- include/hw/qdev-core.h | 2 ++ include/hw/qdev-properties.h | 2 +- vl.c | 8 ++++---- 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index cbba679..a4d928e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -290,12 +290,27 @@ static void machine_finalize(Object *obj) g_free(ms->firmware); } +void machine_class_add_compat_props(MachineClass *mc, GlobalProperty *props) +{ + int i; + for (i = 0; props[i].driver; i++) { + QTAILQ_INSERT_TAIL(&mc->compat_props, &props[i], next); + } +} + +static void machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + QTAILQ_INIT(&mc->compat_props); +} + static const TypeInfo machine_info = { .name = TYPE_MACHINE, .parent = TYPE_OBJECT, .abstract = true, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState), + .class_init = machine_class_init, .instance_init = machine_initfn, .instance_finalize = machine_finalize, }; diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 3d12560..7f6509c 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -946,12 +946,13 @@ void qdev_prop_register_global(GlobalProperty *prop) QTAILQ_INSERT_TAIL(&global_props, prop, next); } -void qdev_prop_register_global_list(GlobalProperty *props) +void qdev_prop_register_global_list(GlobalPropertyList *props) { - int i; + GlobalProperty *prop, *nprop; - for (i = 0; props[i].driver != NULL; i++) { - qdev_prop_register_global(props+i); + QTAILQ_FOREACH_SAFE(prop, props, next, nprop) { + QTAILQ_REMOVE(props, prop, next); + qdev_prop_register_global(prop); } } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2cf22b1..6755c80 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1531,8 +1531,10 @@ static void pc_generic_machine_class_init(ObjectClass *oc, void *data) mc->is_default = qm->is_default; mc->default_machine_opts = qm->default_machine_opts; mc->default_boot_order = qm->default_boot_order; - mc->compat_props = qm->compat_props; mc->hw_version = qm->hw_version; + if (qm->compat_props) { + machine_class_add_compat_props(mc, qm->compat_props); + } } void qemu_register_pc_machine(QEMUMachine *m) diff --git a/include/hw/boards.h b/include/hw/boards.h index 605a970..15d6ac7 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -4,6 +4,7 @@ #define HW_BOARDS_H #include "qemu/typedefs.h" +#include "qemu/queue.h" #include "sysemu/blockdev.h" #include "hw/qdev.h" #include "qom/object.h" @@ -97,7 +98,7 @@ struct MachineClass { int is_default; const char *default_machine_opts; const char *default_boot_order; - GlobalProperty *compat_props; + GlobalPropertyList compat_props; const char *hw_version; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, @@ -105,6 +106,13 @@ struct MachineClass { }; /** + * machine_class_add_compat_props: + * + * Adds compat props from an array to the MachineClass compat_props list. + */ +void machine_class_add_compat_props(MachineClass *mc, GlobalProperty *props); + +/** * MachineState: */ struct MachineState { diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 0799ff2..d93fbba 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -255,6 +255,8 @@ typedef struct GlobalProperty { QTAILQ_ENTRY(GlobalProperty) next; } GlobalProperty; +typedef QTAILQ_HEAD(GlobalPropertyList, GlobalProperty) GlobalPropertyList; + /*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create(BusState *bus, const char *name); diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 77fe3a1..b28ca37 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -176,7 +176,7 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_register_global(GlobalProperty *prop); -void qdev_prop_register_global_list(GlobalProperty *props); +void qdev_prop_register_global_list(GlobalPropertyList *props); int qdev_prop_check_global(void); void qdev_prop_set_globals(DeviceState *dev, Error **errp); void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename, diff --git a/vl.c b/vl.c index 732b0d4..578c1d6 100644 --- a/vl.c +++ b/vl.c @@ -1569,8 +1569,10 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->is_default = qm->is_default; mc->default_machine_opts = qm->default_machine_opts; mc->default_boot_order = qm->default_boot_order; - mc->compat_props = qm->compat_props; mc->hw_version = qm->hw_version; + if (qm->compat_props) { + machine_class_add_compat_props(mc, qm->compat_props); + } } int qemu_register_machine(QEMUMachine *m) @@ -4374,9 +4376,7 @@ int main(int argc, char **argv, char **envp) exit (i == 1 ? 1 : 0); } - if (machine_class->compat_props) { - qdev_prop_register_global_list(machine_class->compat_props); - } + qdev_prop_register_global_list(&machine_class->compat_props); qemu_add_globals(); qdev_machine_init(); -- 1.9.3