Skip to contentSkip to conversation

QOM realize, device-only

PATCH Superseded Andreas Färber 2 participants 4 messages Jan 6, 2013 – Jan 7, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover QOM realize, device-only

Hello Anthony,

Here's a rebased version of device-only QOM realization, otherwise unchanged. This is based on master now and drops all general-purpose qdev cleanups that potentially conflict with Paolo's reference counting change proposal. It will trivially conflict with my qdev unparenting fix, pending to be added to the qom-cpu queue (touches k->unparent in class_init).

Same as v1, this is not the big throw of a recursive, central realization model.

The immediate purpose of this series is to allow CPUs, which partially already have realizefns prepared, to adjust to the new DeviceState signature (being a device on qom-cpu branch) and hook them up to DeviceClass::realize rather than exposing as a function through cpu.h. Please review and apply to qemu.git.

As discussed in the last cover letter, doing realization at DeviceState level does not allow for trivial [un]realize_children as proposed by Paolo for Object. An idea how to implement this as a follow-up would be to do a deep search for child<> properties dynamic_cast'able to DeviceState. Or to simply try setting a "realized" property and it that fails check for children (but how to differ between "realized" that failed and "realized" that doesn't exist then?).

Available from:
https://github.com/afaerber/qemu-cpu/commits/realize-qdev.v2
git://github.com/afaerber/qemu-cpu.git realize-qdev.v2

Regards,
Andreas

Cc Anthony Liguori <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Peter Maydell <[email protected]>

Andreas Färber (2):
qdev: Fold state enum into bool realized
qdev: Prepare "realized" property

 hw/qdev-addr.c              |    2 +-
 hw/qdev-core.h              |   11 ++---
 hw/qdev-properties-system.c |    4 +-
 hw/qdev-properties.c        |   24 +++++-----
 hw/qdev.c                   |  106 +++++++++++++++++++++++++++++++------------

5 Dateien geändert, 97 Zeilen hinzugefügt(+), 50 Zeilen entfernt(-)

Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/2 qdev: Fold state enum into bool realized

Whether the device was initialized or not is QOM-level information and currently unused. Drop it from qdev. This leaves the boolean state of whether or not DeviceClass::init was called or not, a.k.a. "realized".

---
 hw/qdev-addr.c              |    2 +-
 hw/qdev-core.h              |    7 +------
 hw/qdev-properties-system.c |    4 ++--
 hw/qdev-properties.c        |   24 ++++++++++++------------
 hw/qdev.c                   |   12 ++++++------

5 Dateien geändert, 22 Zeilen hinzugefügt(+), 27 Zeilen entfernt(-)

hw/qdev-addr.c +1 -1
index 3bfe101..b4388f6 100644
@@ -40,7 +40,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     int64_t value;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
hw/qdev-core.h +1 -6
index fdf14ec..5836e35 100644
@@ -8,11 +8,6 @@
 #include "hw/irq.h"
 #include "qapi/error.h"
 
-enum DevState {
-    DEV_STATE_CREATED = 1,
-    DEV_STATE_INITIALIZED,
-};
-
 enum {
     DEV_NVECTORS_UNSPECIFIED = -1,
 };
@@ -55,7 +50,7 @@ struct DeviceState {
     Object parent_obj;
 
     const char *id;
-    enum DevState state;
+    bool realized;
     QemuOpts *opts;
     int hotplugged;
     BusState *parent_bus;
hw/qdev-properties-system.c +2 -2
index c73c713..ce0f793 100644
@@ -42,7 +42,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
     char *str;
     int ret;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -254,7 +254,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     int32_t id;
     NetClientState *hubport;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
hw/qdev-properties.c +12 -12
index f724357..a8a31f5 100644
@@ -32,7 +32,7 @@ static void set_enum(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     int *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -85,7 +85,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     bool value;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -125,7 +125,7 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -192,7 +192,7 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -225,7 +225,7 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -250,7 +250,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -323,7 +323,7 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -413,7 +413,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -477,7 +477,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
     int i, pos;
     char *str, *p;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -569,7 +569,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -640,7 +640,7 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
     const int64_t min = 512;
     const int64_t max = 32768;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -708,7 +708,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
     unsigned long dom = 0, bus = 0;
     unsigned int slot = 0, func = 0;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
hw/qdev.c +6 -6
index f2c2484..b214c8a 100644
@@ -151,7 +151,7 @@ int qdev_init(DeviceState *dev)
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
     int rc;
 
-    assert(dev->state == DEV_STATE_CREATED);
+    assert(!dev->realized);
 
     rc = dc->init(dev);
     if (rc < 0) {
@@ -174,7 +174,7 @@ int qdev_init(DeviceState *dev)
                                        dev->instance_id_alias,
                                        dev->alias_required_for_version);
     }
-    dev->state = DEV_STATE_INITIALIZED;
+    dev->realized = true;
     if (dev->hotplugged) {
         device_reset(dev);
     }
@@ -184,7 +184,7 @@ int qdev_init(DeviceState *dev)
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
                                  int required_for_version)
 {
-    assert(dev->state == DEV_STATE_CREATED);
+    assert(!dev->realized);
     dev->instance_id_alias = alias_id;
     dev->alias_required_for_version = required_for_version;
 }
@@ -541,7 +541,7 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
     char *ptr = NULL;
     int ret;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -648,7 +648,7 @@ static void device_initfn(Object *obj)
     }
 
     dev->instance_id_alias = -1;
-    dev->state = DEV_STATE_CREATED;
+    dev->realized = false;
 
     class = object_get_class(OBJECT(dev));
     do {
@@ -671,7 +671,7 @@ static void device_finalize(Object *obj)
     BusState *bus;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (dev->state == DEV_STATE_INITIALIZED) {
+    if (dev->realized) {
         while (dev->num_child_bus) {
             bus = QLIST_FIRST(&dev->child_bus);
             qbus_free(bus);
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v2 2/2 qdev: Prepare "realized" property

In reply to Andreas Färber

Based on earlier patches by Paolo and me, introduce the QOM realizefn at device level only, as requested by Anthony.

For now this just wraps the qdev initfn, which it deprecates.

---
 hw/qdev-core.h |    4 +++
 hw/qdev.c      |   96 ++++++++++++++++++++++++++++++++++++++++++--------------

2 Dateien geändert, 76 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

hw/qdev-core.h +4 -0
index 5836e35..e50c866 100644
@@ -20,6 +20,8 @@ enum {
 typedef int (*qdev_initfn)(DeviceState *dev);
 typedef int (*qdev_event)(DeviceState *dev);
 typedef void (*qdev_resetfn)(DeviceState *dev);
+typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
+typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
 
 struct VMStateDescription;
 
@@ -38,6 +40,8 @@ typedef struct DeviceClass {
     const struct VMStateDescription *vmsd;
 
     /* Private to qdev / bus.  */
+    DeviceRealize realize;
+    DeviceUnrealize unrealize;
     qdev_initfn init;
     qdev_event unplug;
     qdev_event exit;
hw/qdev.c +72 -24

135 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] qdev: Prepare "realized" property

Quoted 27 lines · Andreas Färber

Based on earlier patches by Paolo and me, introduce the QOM realizefn at device level only, as requested by Anthony.

For now this just wraps the qdev initfn, which it deprecates.

---
 hw/qdev-core.h |    4 +++
 hw/qdev.c      |   96 ++++++++++++++++++++++++++++++++++++++++++--------------

2 Dateien geändert, 76 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

hw/qdev-core.h +2 -0
index 5836e35..e50c866 100644
@@ -20,6 +20,8 @@ enum {
 typedef int (*qdev_initfn)(DeviceState *dev);
 typedef int (*qdev_event)(DeviceState *dev);
 typedef void (*qdev_resetfn)(DeviceState *dev);
+typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
+typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
 
 struct VMStateDescription;
 

hw/qdev-core.h typedef struct DeviceClass { · line 45

Quoted 6 lines
hw/qdev-core.h +2 -0
@@ -38,6 +40,8 @@ typedef struct DeviceClass {
     const struct VMStateDescription *vmsd;
 
     /* Private to qdev / bus.  */
+    DeviceRealize realize;
+    DeviceUnrealize unrealize;
     qdev_initfn init;

Can we get the semantics of the realize/unrealize/init functions documented here? For example, explicitly document that subclasses are supposed to call the parent's realize function (this is the case, right?), and the differences between DeviceState.init and DeviceState.realize.

I took some time to understand the reason for DeviceState.realize to exist when we already have DeviceState.init, and I am sure I already forgot half of the explanation, and I will forget it completely in 1 or 2 months. :-)

Quoted 1 line

[...]

Signature · 1 line
Eduardo