qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marcel Apfelbaum" <marcel.a@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Alexander Graf" <agraf@suse.de>,
	"Don Slutz" <dslutz@verizon.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH v4 10/33] machine: Make compat_props a linked list
Date: Thu, 14 Aug 2014 16:25:39 -0300	[thread overview]
Message-ID: <1408044362-11621-11-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1408044362-11621-1-git-send-email-ehabkost@redhat.com>

This will make it easier to write reusable class_init code which adds
properties to MachineClass.compat_props.

Use GList instead of reusing GlobalProperty.next, because the same
GlobalProperty can appear on multiple machine subclasses.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v3 -> v4:
* Use GList instead of reusing the "next" field on GlobalProperty,
  so the same GlobalProperty elements may be added to multiple classes.
---
 hw/core/machine.c            | 25 +++++++++++++++++++++++++
 hw/core/qdev-properties.c    |  9 ---------
 hw/i386/pc.c                 |  4 +++-
 include/hw/boards.h          | 19 ++++++++++++++++++-
 include/hw/qdev-properties.h |  1 -
 vl.c                         |  8 ++++----
 6 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 7a66c57..3eeb0a9 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -290,12 +290,37 @@ 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++) {
+        mc->compat_props = g_list_append(mc->compat_props, &props[i]);
+    }
+}
+
+void machine_class_register_compat_props(MachineClass *mc)
+{
+    GList *l;
+    for (l = mc->compat_props; l; l = l->next) {
+        GlobalProperty *prop = l->data;
+        qdev_prop_register_global(prop);
+    }
+}
+
+static void machine_class_base_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    /* compat_props can't be simply memcpy()ed */
+    mc->compat_props = g_list_copy(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_base_init = machine_class_base_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..4dd9faa 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -946,15 +946,6 @@ void qdev_prop_register_global(GlobalProperty *prop)
     QTAILQ_INSERT_TAIL(&global_props, prop, next);
 }
 
-void qdev_prop_register_global_list(GlobalProperty *props)
-{
-    int i;
-
-    for (i = 0; props[i].driver != NULL; i++) {
-        qdev_prop_register_global(props+i);
-    }
-}
-
 int qdev_prop_check_global(void)
 {
     GlobalProperty *prop;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9e58982..301b127 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1556,8 +1556,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..e9ddbc9 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -3,6 +3,8 @@
 #ifndef HW_BOARDS_H
 #define HW_BOARDS_H
 
+#include <glib.h>
+
 #include "qemu/typedefs.h"
 #include "sysemu/blockdev.h"
 #include "hw/qdev.h"
@@ -97,7 +99,7 @@ struct MachineClass {
     int is_default;
     const char *default_machine_opts;
     const char *default_boot_order;
-    GlobalProperty *compat_props;
+    GList *compat_props;
     const char *hw_version;
 
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
@@ -105,6 +107,21 @@ 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);
+
+/**
+ * machine_class_register_compat_props:
+ *
+ * Register the compat props that were added using
+ * machine_class_add_compat_props().
+ */
+void machine_class_register_compat_props(MachineClass *mc);
+
+/**
  * MachineState:
  */
 struct MachineState {
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 77fe3a1..4480b3e 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -176,7 +176,6 @@ 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);
 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 1dd12a8..140fea4 100644
--- a/vl.c
+++ b/vl.c
@@ -1587,8 +1587,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)
@@ -4410,9 +4412,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);
-    }
+    machine_class_register_compat_props(machine_class);
     qemu_add_globals();
 
     qdev_machine_init();
-- 
1.9.3

  parent reply	other threads:[~2014-08-14 19:27 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 01/33] pc: Replace tabs with spaces on pc.h Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 02/33] vl.c: Use qdev_prop_register_global() for single globals Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 03/33] pc: Eliminate has_pci_info global variable Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 04/33] piix: Add kvmclock_enabled, pci_enabled globals Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 05/33] piix: Eliminate pc_init_pci() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 06/33] piix: Move pc-0.14 qxl compat properties to PC_COMPAT_0_14 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 07/33] piix: Move pc-0.13 virtio-9p-pci compat to PC_COMPAT_0_13 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 08/33] piix: Move pc-0.1[23] rombar compat props " Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 09/33] piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11 Eduardo Habkost
2014-08-14 19:25 ` Eduardo Habkost [this message]
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 11/33] pc: Register machine classes directly instead of using QEMUMachine Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 12/33] pc: Eliminate pc_common_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 13/33] pc: Eliminate pc_default_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 14/33] piix: Eliminate pc_i440fx_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 15/33] q35: Eliminate pc_q35_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 16/33] q35: Eliminate pc_q35_1_4_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 17/33] pc: Eliminate all *_machine_options() functions Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 18/33] machine: Eliminate QEMUMachine.compat_props Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 19/33] pc: Rename pc_machine variable to pcms Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 20/33] pc: Pass PCMachineState argument to pc_cpus_init() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 21/33] machine: Add MachineClass.default_cpu_model field Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 22/33] pc: Move globals to PCMachineClass Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 23/33] pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 24/33] pc: Add PCMachineClass.compat_apic_id_mode field Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 25/33] target-i386: Move error handling to end of x86_cpu_parse_featurestr() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names Eduardo Habkost
2014-08-14 19:31   ` Michael S. Tsirkin
2014-08-14 19:32     ` Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature Eduardo Habkost
2014-08-14 21:08   ` Michael S. Tsirkin
2014-08-14 23:59     ` Eduardo Habkost
2014-08-16 21:03       ` Michael S. Tsirkin
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 28/33] target-i386: set [+-]feature using QOM properties Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 29/33] pc: Use compat_props for CPUID compat bits Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 30/33] target-i386: Move some declarations to hw/i386/cpu.h Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass Eduardo Habkost
2014-08-14 21:09   ` Michael S. Tsirkin
2014-08-15  0:04     ` Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 32/33] pc: Eliminate pc_compat_*() functions Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init() Eduardo Habkost
2014-08-14 20:03   ` Michael S. Tsirkin
2014-08-15  0:03     ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408044362-11621-11-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=dslutz@verizon.com \
    --cc=imammedo@redhat.com \
    --cc=marcel.a@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).