Patchwork [RFC,07/13] qdev: move vmstate handling to qdev-system.c

login
register
mail settings
Submitter Eduardo Habkost
Date Oct. 4, 2012, 7:15 p.m.
Message ID <1349378133-25644-8-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/189288/
State New
Headers show

Comments

Eduardo Habkost - Oct. 4, 2012, 7:15 p.m.
Add GCC_WEAK symbols to qdev-core.c, so that qdev-core.o can be used
without qdev-system.o (i.e. by *-user).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/qdev-core.c   | 23 +++++++----------------
 hw/qdev-core.h   |  2 ++
 hw/qdev-system.c | 22 ++++++++++++++++++++++
 3 files changed, 31 insertions(+), 16 deletions(-)

Patch

diff --git a/hw/qdev-core.c b/hw/qdev-core.c
index 242347f..a5cac45 100644
--- a/hw/qdev-core.c
+++ b/hw/qdev-core.c
@@ -34,26 +34,17 @@  int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
 static bool qdev_hot_removed = false;
 
-const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
-{
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);
-    return dc->vmsd;
-}
-
-static void qdev_init_vmstate(DeviceState *dev)
+/* vmstate handling:
+ *
+ * The real implementations are on qdev-system.c. Those are weak symbols
+ * used by *-user.
+ */
+void GCC_WEAK qdev_init_vmstate(DeviceState *dev)
 {
-    if (qdev_get_vmsd(dev)) {
-        vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
-                                       dev->instance_id_alias,
-                                       dev->alias_required_for_version);
-    }
 }
 
-static void qdev_finalize_vmstate(DeviceState *dev)
+void GCC_WEAK qdev_finalize_vmstate(DeviceState *dev)
 {
-    if (qdev_get_vmsd(dev)) {
-        vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
-    }
 }
 
 const char *qdev_fw_name(DeviceState *dev)
diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index ca205fc..e9b6d6d 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -225,6 +225,8 @@  void qdev_machine_init(void);
 void device_reset(DeviceState *dev);
 
 const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
+void qdev_init_vmstate(DeviceState *dev);
+void qdev_finalize_vmstate(DeviceState *dev);
 
 const char *qdev_fw_name(DeviceState *dev);
 
diff --git a/hw/qdev-system.c b/hw/qdev-system.c
index 4891d2f..b4d40e8 100644
--- a/hw/qdev-system.c
+++ b/hw/qdev-system.c
@@ -91,3 +91,25 @@  DeviceState *qdev_try_create(BusState *bus, const char *type)
 
     return dev;
 }
+
+const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
+{
+    DeviceClass *dc = DEVICE_GET_CLASS(dev);
+    return dc->vmsd;
+}
+
+void qdev_init_vmstate(DeviceState *dev)
+{
+    if (qdev_get_vmsd(dev)) {
+        vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
+                                       dev->instance_id_alias,
+                                       dev->alias_required_for_version);
+    }
+}
+
+void qdev_finalize_vmstate(DeviceState *dev)
+{
+    if (qdev_get_vmsd(dev)) {
+        vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
+    }
+}