Skip to contentSkip to conversation

qdev properties final installment: push, push!

PATCH In review Paolo Bonzini 5 participants 57 messages Apr 3, 2012 – May 16, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover qdev properties final installment: push, push!

This is the final installment of the qdev property cleanup. It includes the following parts:

* various bits of state are moved from DeviceState to Object:
state (aka realized), reset, static properties, and the simple "type" property

* bus properties are replaced with superclass properties

The series has many parts; they are logically separate, but because of dependencies it would take too much time to submit them one by one. In fact, to avoid conflicts, and because his patchset does not apply anymore, I took the liberty to include here Michael Roth's patches for uint*_t and int*_t visitors.

Patches 1 to 5 are small preparatory changes in QOM.

Patches 6 and 7 are bonus bugfixes.

Patches 8 to 13 refactor bus properties.

Patches 14 to 18 are Michael's patches + two cleanups.

Patches 19 to 22 push static properties from qdev to Object. As you can see from the diffstat below, this has to touch a lot of files.

Patches 23 to 25 implement the realized property and reimplement qdev's object lifecycle in terms of realize/unrealize.

Michael Roth (3):
qapi: add Visitor interfaces for uint*_t and int*_t
qdev: use int32_t container for devfn property
qdev: switch property accessors to fixed-width visitor interfaces

Paolo Bonzini (22):
qom: add object_class_get_parent
qom: add object_child_foreach
qom: add class_base_init
qom: make Object a type
qom: push type up to Object
qdev: fix -device foo,?
qdev: use object_property_print in info qtree
qdev: remove qdev_prop_set_defaults
qdev: move bus properties to a separate global
qdev: do not propagate properties to subclasses
qdev: pick global properties from superclasses
qdev: factor setting of global properties
qdev: replace bus properties with superclass properties
qdev: remove PropertyInfo range checking
qdev: remove qdev_prop_exists
qom: push state up to Object
qdev: generalize properties to Objects
qdev: move bulk of qdev-properties.c to qom/object.c
qom: push static properties to Object
qom: add realized property
qdev: implement qdev_init on top of realize
qdev: split part of device_finalize to device_unrealize

 hw/9pfs/virtio-9p-device.c    |    2 +-
 hw/a15mpcore.c                |    3 +-
 hw/a9mpcore.c                 |    2 +-
 hw/ac97.c                     |    2 +-
 hw/acpi_piix4.c               |    2 +-
 hw/apic_common.c              |    2 +-
 hw/applesmc.c                 |    2 +-
 hw/arm11mpcore.c              |    6 +-
 hw/arm_l2x0.c                 |    2 +-
 hw/arm_mptimer.c              |    2 +-
 hw/arm_sysctl.c               |    2 +-
 hw/arm_timer.c                |    3 +-
 hw/armv7m.c                   |    3 +-
 hw/armv7m_nvic.c              |    2 +-
 hw/cadence_gem.c              |    2 +-
 hw/ccid-card-emulated.c       |    2 +-
 hw/ccid-card-passthru.c       |    2 +-
 hw/cs4231.c                   |    2 +-
 hw/cs4231a.c                  |    2 +-
 hw/debugcon.c                 |    3 +-
 hw/ds1225y.c                  |    2 +-
 hw/e1000.c                    |    2 +-
 hw/eccmemctl.c                |    2 +-
 hw/eepro100.c                 |    2 +-
 hw/escc.c                     |    2 +-
 hw/esp.c                      |    2 +-
 hw/etraxfs_eth.c              |    3 +-
 hw/etraxfs_pic.c              |    3 +-
 hw/exynos4210_combiner.c      |    2 +-
 hw/exynos4210_gic.c           |    3 +-
 hw/exynos4210_uart.c          |    2 +-
 hw/fdc.c                      |    6 +-
 hw/fw_cfg.c                   |    2 +-
 hw/g364fb.c                   |    2 +-
 hw/grlib_apbuart.c            |    3 +-
 hw/grlib_gptimer.c            |    2 +-
 hw/grlib_irqmp.c              |    2 +-
 hw/gus.c                      |    2 +-
 hw/hda-audio.c                |    4 +-
 hw/hpet.c                     |    2 +-
 hw/i2c.c                      |   10 +-
 hw/i82374.c                   |    2 +-
 hw/i82378.c                   |    2 +-
 hw/i8254.c                    |    2 +-
 hw/i8259_common.c             |    2 +-
 hw/ide/ahci.c                 |    2 +-
 hw/ide/cmd646.c               |    3 +-
 hw/ide/isa.c                  |    2 +-
 hw/ide/qdev.c                 |   16 +-
 hw/integratorcp.c             |    3 +-
 hw/intel-hda.c                |   12 +-
 hw/ioh3420.c                  |    2 +-
 hw/ivshmem.c                  |    2 +-
 hw/kvm/i8254.c                |    2 +-
 hw/kvm/ioapic.c               |    2 +-
 hw/lan9118.c                  |    2 +-
 hw/lance.c                    |    2 +-
 hw/lm32_sys.c                 |    2 +-
 hw/lm32_timer.c               |    2 +-
 hw/m48t59.c                   |    4 +-
 hw/marvell_88w8618_audio.c    |    2 +-
 hw/mc146818rtc.c              |    9 +-
 hw/milkymist-minimac2.c       |    2 +-
 hw/milkymist-softusb.c        |    2 +-
 hw/milkymist-sysctl.c         |    2 +-
 hw/milkymist-vgafb.c          |    2 +-
 hw/mipsnet.c                  |    2 +-
 hw/musicpal.c                 |    2 +-
 hw/nand.c                     |    2 +-
 hw/ne2000-isa.c               |    3 +-
 hw/ne2000.c                   |    2 +-
 hw/omap_gpio.c                |    4 +-
 hw/omap_i2c.c                 |    2 +-
 hw/omap_intc.c                |    4 +-
 hw/onenand.c                  |    2 +-
 hw/opencores_eth.c            |    2 +-
 hw/parallel.c                 |    3 +-
 hw/pc_piix.c                  |   12 +-
 hw/pc_sysfw.c                 |    2 +-
 hw/pci.c                      |   24 +-
 hw/pci.h                      |    2 +-
 hw/pcnet-pci.c                |    2 +-
 hw/pcspk.c                    |    2 +-
 hw/pl041.c                    |    2 +-
 hw/pxa2xx.c                   |    2 +-
 hw/pxa2xx_dma.c               |    2 +-
 hw/pxa2xx_gpio.c              |    2 +-
 hw/pxa2xx_timer.c             |    4 +-
 hw/qdev-addr.c                |   26 +-
 hw/qdev-monitor.c             |   46 ++-
 hw/qdev-properties.c          |  683 ++++++-----------------------------------
 hw/qdev.c                     |  152 ++++-----
 hw/qdev.h                     |  109 +------
 hw/qxl.c                      |    4 +-
 hw/rtl8139.c                  |    2 +-
 hw/s390-virtio-bus.c          |   12 +-
 hw/sb16.c                     |    2 +-
 hw/scsi-bus.c                 |   16 +-
 hw/scsi-disk.c                |    8 +-
 hw/scsi-generic.c             |    2 +-
 hw/serial.c                   |    2 +-
 hw/slavio_timer.c             |    2 +-
 hw/smbus_eeprom.c             |    3 +-
 hw/smc91c111.c                |    2 +-
 hw/spapr_llan.c               |    3 +-
 hw/spapr_pci.c                |    3 +-
 hw/spapr_vio.c                |   10 +-
 hw/spapr_vscsi.c              |    3 +-
 hw/spapr_vty.c                |    3 +-
 hw/sparc32_dma.c              |    2 +-
 hw/spitz.c                    |    4 +-
 hw/stellaris_enet.c           |    3 +-
 hw/strongarm.c                |    2 +-
 hw/sun4m.c                    |    6 +-
 hw/sun4m_iommu.c              |    2 +-
 hw/sun4u.c                    |    6 +-
 hw/tcx.c                      |    2 +-
 hw/usb/bus.c                  |   11 +-
 hw/usb/dev-audio.c            |    2 +-
 hw/usb/dev-network.c          |    2 +-
 hw/usb/dev-serial.c           |    4 +-
 hw/usb/dev-smartcard-reader.c |   12 +-
 hw/usb/dev-storage.c          |    2 +-
 hw/usb/hcd-ehci.c             |    4 +-
 hw/usb/hcd-ohci.c             |    4 +-
 hw/usb/hcd-uhci.c             |   12 +-
 hw/usb/hcd-xhci.c             |    2 +-
 hw/usb/host-linux.c           |    2 +-
 hw/usb/redirect.c             |    2 +-
 hw/virtio-console.c           |    6 +-
 hw/virtio-pci.c               |   10 +-
 hw/virtio-serial-bus.c        |   12 +-
 hw/vmmouse.c                  |    2 +-
 hw/vt82c686.c                 |    2 +-
 hw/xgmac.c                    |    2 +-
 hw/xilinx_axidma.c            |    3 +-
 hw/xilinx_axienet.c           |    3 +-
 hw/xilinx_ethlite.c           |    3 +-
 hw/xilinx_intc.c              |    3 +-
 hw/xilinx_timer.c             |    3 +-
 hw/xio3130_downstream.c       |    2 +-
 hw/xio3130_upstream.c         |    2 +-
 hw/zaurus.c                   |    2 +-
 include/qemu/object.h         |  182 ++++++++++-
 qapi/qapi-visit-core.c        |  139 +++++++++
 qapi/qapi-visit-core.h        |   16 +
 qom/object.c                  |  681 ++++++++++++++++++++++++++++++++++++++--
 147 files changed, 1427 insertions(+), 1102 deletions(-)
Signature · 1 line
1.7.9.3
#1 lore raw

PATCH 1/25 qom: add object_class_get_parent

This simple bit of functionality was missing and we'll need it soon, so add it.

---
 include/qemu/object.h |   14 ++++++++++++++
 qom/object.c          |   13 +++++++++++++
 2 files changed, 27 insertions(+)
include/qemu/object.h +14 -0
index a675937..f814521 100644
@@ -548,6 +548,14 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
                                        const char *typename);
 
 /**
+ * object_class_get_parent:
+ * @klass: The class to obtain the parent for.
+ *
+ * Returns: The parent for @klass.
+ */
+ObjectClass *object_class_get_parent(ObjectClass *klass);
+
+/**
  * object_class_get_name:
  * @klass: The class to obtain the QOM typename for.
  *
@@ -555,6 +563,12 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
  */
 const char *object_class_get_name(ObjectClass *klass);
 
+/**
+ * object_class_by_name:
+ * @typename: The QOM typename to obtain the class for.
+ *
+ * Returns: The class for @typename.
+ */
 ObjectClass *object_class_by_name(const char *typename);
 
 void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
qom/object.c +13 -0
index e721fc2..3e9fed7 100644
@@ -545,6 +545,19 @@ ObjectClass *object_class_by_name(const char *typename)
     return type->class;
 }
 
+ObjectClass *object_class_get_parent(ObjectClass *class)
+{
+    TypeImpl *type = type_get_parent(class->type);
+
+    if (!type) {
+        return NULL;
+    }
+
+    type_initialize(type);
+
+    return type->class;
+}
+
 typedef struct OCFData
 {
     void (*fn)(ObjectClass *klass, void *opaque);
Signature · 1 line
1.7.9.3
Reviewed-by on v1 1/25
#2 lore raw

Re: [Qemu-devel] [PATCH 01/25] qom: add object_class_get_parent

Quoted 4 lines · Paolo Bonzini

This simple bit of functionality was missing and we'll need it soon, so add it.

Regards,

Anthony Liguori

Quoted 61 lines
---
  include/qemu/object.h |   14 ++++++++++++++
  qom/object.c          |   13 +++++++++++++
  2 files changed, 27 insertions(+)
include/qemu/object.h +14 -0
index a675937..f814521 100644
@@ -548,6 +548,14 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
                                         const char *typename);
 
  /**
+ * object_class_get_parent:
+ * @klass: The class to obtain the parent for.
+ *
+ * Returns: The parent for @klass.
+ */
+ObjectClass *object_class_get_parent(ObjectClass *klass);
+
+/**
   * object_class_get_name:
   * @klass: The class to obtain the QOM typename for.
   *
@@ -555,6 +563,12 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *klass,
   */
  const char *object_class_get_name(ObjectClass *klass);
 
+/**
+ * object_class_by_name:
+ * @typename: The QOM typename to obtain the class for.
+ *
+ * Returns: The class for @typename.
+ */
  ObjectClass *object_class_by_name(const char *typename);
 
  void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
qom/object.c +13 -0
index e721fc2..3e9fed7 100644
@@ -545,6 +545,19 @@ ObjectClass *object_class_by_name(const char *typename)
      return type->class;
  }
 
+ObjectClass *object_class_get_parent(ObjectClass *class)
+{
+    TypeImpl *type = type_get_parent(class->type);
+
+    if (!type) {
+        return NULL;
+    }
+
+    type_initialize(type);
+
+    return type->class;
+}
+
  typedef struct OCFData
  {
      void (*fn)(ObjectClass *klass, void *opaque);
#3 lore raw

PATCH 2/25 qom: add object_child_foreach

In reply to Paolo Bonzini

A utility function that will be used to implement hierarchical realization.

---
 include/qemu/object.h |   14 +++++++++++++-
 qom/object.c          |   17 +++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
include/qemu/object.h +13 -1
index f814521..470efe3 100644
@@ -918,6 +918,19 @@ void object_property_add_str(Object *obj, const char *name,
                              struct Error **errp);
 
 /**
+ * object_child_foreach:
+ * @obj: the object whose children will be navigated
+ * @fn: the iterator function to be called
+ * @opaque: an opaque value that will be passed to the iterator
+ *
+ * Call @fn passing each child of @obj and @opaque to it, until @fn returns
+ * non-zero.  Return the last value returned by @fn, or 0 if there is no
+ * child.
+ */
+int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
+                         void *opaque);
+
+/**
  * container_get:
  * @path: path to the container
  *
@@ -928,5 +941,4 @@ void object_property_add_str(Object *obj, const char *name,
  */
 Object *container_get(const char *path);
 
-
 #endif
qom/object.c +17 -0
index 3e9fed7..4975d93 100644
@@ -597,6 +597,23 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
     g_hash_table_foreach(type_table_get(), object_class_foreach_tramp, &data);
 }
 
+int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
+                         void *opaque)
+{
+    ObjectProperty *prop;
+    int ret = 0;
+
+    QTAILQ_FOREACH(prop, &obj->properties, node) {
+        if (strstart(prop->type, "child<", NULL)) {
+            ret = fn(prop->opaque, opaque);
+            if (ret != 0) {
+                break;
+            }
+        }
+    }
+    return ret;
+}
+
 static void object_class_get_list_tramp(ObjectClass *klass, void *opaque)
 {
     GSList **list = opaque;
Signature · 1 line
1.7.9.3
Reviewed-by on v1 2/25
#4 lore raw

Re: [Qemu-devel] [PATCH 02/25] qom: add object_child_foreach

Quoted 3 lines · Paolo Bonzini

A utility function that will be used to implement hierarchical realization.

Regards,

Anthony Liguori

Quoted 63 lines
---
  include/qemu/object.h |   14 +++++++++++++-
  qom/object.c          |   17 +++++++++++++++++
  2 files changed, 30 insertions(+), 1 deletion(-)
include/qemu/object.h +13 -1
index f814521..470efe3 100644
@@ -918,6 +918,19 @@ void object_property_add_str(Object *obj, const char *name,
                               struct Error **errp);
 
  /**
+ * object_child_foreach:
+ * @obj: the object whose children will be navigated
+ * @fn: the iterator function to be called
+ * @opaque: an opaque value that will be passed to the iterator
+ *
+ * Call @fn passing each child of @obj and @opaque to it, until @fn returns
+ * non-zero.  Return the last value returned by @fn, or 0 if there is no
+ * child.
+ */
+int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
+                         void *opaque);
+
+/**
   * container_get:
   * @path: path to the container
   *
@@ -928,5 +941,4 @@ void object_property_add_str(Object *obj, const char *name,
   */
  Object *container_get(const char *path);
 
-
  #endif
qom/object.c +17 -0
index 3e9fed7..4975d93 100644
@@ -597,6 +597,23 @@ void object_class_foreach(void (*fn)(ObjectClass *klass, void *opaque),
      g_hash_table_foreach(type_table_get(), object_class_foreach_tramp,&data);
  }
 
+int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
+                         void *opaque)
+{
+    ObjectProperty *prop;
+    int ret = 0;
+
+    QTAILQ_FOREACH(prop,&obj->properties, node) {
+        if (strstart(prop->type, "child<", NULL)) {
+            ret = fn(prop->opaque, opaque);
+            if (ret != 0) {
+                break;
+            }
+        }
+    }
+    return ret;
+}
+
  static void object_class_get_list_tramp(ObjectClass *klass, void *opaque)
  {
      GSList **list = opaque;
#5 lore raw

PATCH 3/25 qom: add class_base_init

In reply to Paolo Bonzini

The class_base_init TypeInfo callback was present in one of the early QOM versions but removed (on my request...) before committing. We will need it soon, add it.

---
 include/qemu/object.h |   10 ++++++++--
 qom/object.c          |    9 +++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
include/qemu/object.h +8 -2
index 470efe3..ccaea7d 100644
@@ -291,10 +291,15 @@ struct Object
  *   has occurred to allow a class to set its default virtual method pointers.
  *   This is also the function to use to override virtual methods from a parent
  *   class.
+ * @class_base_init: This function is called for all base classes after all
+ *   parent class initialization has occurred, but before the class itself
+ *   is initialized.  This is the function to use to undo the effects of
+ *   memcpy from the parent class to the descendents.
  * @class_finalize: This function is called during class destruction and is
  *   meant to release and dynamic parameters allocated by @class_init.
- * @class_data: Data to pass to the @class_init and @class_finalize functions.
- *   This can be useful when building dynamic classes.
+ * @class_data: Data to pass to the @class_init, @class_base_init and
+ *   @class_finalize functions.  This can be useful when building dynamic
+ *   classes.
  * @interfaces: The list of interfaces associated with this type.  This
  *   should point to a static array that's terminated with a zero filled
  *   element.
@@ -312,6 +317,7 @@ struct TypeInfo
     size_t class_size;
 
     void (*class_init)(ObjectClass *klass, void *data);
+    void (*class_base_init)(ObjectClass *klass, void *data);
     void (*class_finalize)(ObjectClass *klass, void *data);
     void *class_data;
 
qom/object.c +9 -0
index 4975d93..6ff1c19 100644
@@ -45,6 +45,7 @@ struct TypeImpl
     size_t instance_size;
 
     void (*class_init)(ObjectClass *klass, void *data);
+    void (*class_base_init)(ObjectClass *klass, void *data);
     void (*class_finalize)(ObjectClass *klass, void *data);
 
     void *class_data;
@@ -112,6 +113,7 @@ TypeImpl *type_register(const TypeInfo *info)
     ti->instance_size = info->instance_size;
 
     ti->class_init = info->class_init;
+    ti->class_base_init = info->class_base_init;
     ti->class_finalize = info->class_finalize;
     ti->class_data = info->class_data;
 
@@ -232,6 +234,13 @@ static void type_initialize(TypeImpl *ti)
         memcpy((void *)ti->class + sizeof(ObjectClass),
                (void *)parent->class + sizeof(ObjectClass),
                parent->class_size - sizeof(ObjectClass));
+
+        while (parent) {
+            if (parent->class_base_init) {
+                parent->class_base_init(ti->class, ti->class_data);
+            }
+            parent = type_get_parent(parent);
+        }
     }
 
     memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
Signature · 1 line
1.7.9.3
Reviewed-by on v1 3/25
#6 lore raw

Re: [Qemu-devel] [PATCH 03/25] qom: add class_base_init

Quoted 5 lines · Paolo Bonzini

The class_base_init TypeInfo callback was present in one of the early QOM versions but removed (on my request...) before committing. We will need it soon, add it.

Heh, funny how that worked out :-)

Regards,

Anthony Liguori

Quoted 69 lines
---
  include/qemu/object.h |   10 ++++++++--
  qom/object.c          |    9 +++++++++
  2 files changed, 17 insertions(+), 2 deletions(-)
include/qemu/object.h +8 -2
index 470efe3..ccaea7d 100644
@@ -291,10 +291,15 @@ struct Object
   *   has occurred to allow a class to set its default virtual method pointers.
   *   This is also the function to use to override virtual methods from a parent
   *   class.
+ * @class_base_init: This function is called for all base classes after all
+ *   parent class initialization has occurred, but before the class itself
+ *   is initialized.  This is the function to use to undo the effects of
+ *   memcpy from the parent class to the descendents.
   * @class_finalize: This function is called during class destruction and is
   *   meant to release and dynamic parameters allocated by @class_init.
- * @class_data: Data to pass to the @class_init and @class_finalize functions.
- *   This can be useful when building dynamic classes.
+ * @class_data: Data to pass to the @class_init, @class_base_init and
+ *   @class_finalize functions.  This can be useful when building dynamic
+ *   classes.
   * @interfaces: The list of interfaces associated with this type.  This
   *   should point to a static array that's terminated with a zero filled
   *   element.
@@ -312,6 +317,7 @@ struct TypeInfo
      size_t class_size;
 
      void (*class_init)(ObjectClass *klass, void *data);
+    void (*class_base_init)(ObjectClass *klass, void *data);
      void (*class_finalize)(ObjectClass *klass, void *data);
      void *class_data;
 
qom/object.c +9 -0
index 4975d93..6ff1c19 100644
@@ -45,6 +45,7 @@ struct TypeImpl
      size_t instance_size;
 
      void (*class_init)(ObjectClass *klass, void *data);
+    void (*class_base_init)(ObjectClass *klass, void *data);
      void (*class_finalize)(ObjectClass *klass, void *data);
 
      void *class_data;
@@ -112,6 +113,7 @@ TypeImpl *type_register(const TypeInfo *info)
      ti->instance_size = info->instance_size;
 
      ti->class_init = info->class_init;
+    ti->class_base_init = info->class_base_init;
      ti->class_finalize = info->class_finalize;
      ti->class_data = info->class_data;
 
@@ -232,6 +234,13 @@ static void type_initialize(TypeImpl *ti)
          memcpy((void *)ti->class + sizeof(ObjectClass),
                 (void *)parent->class + sizeof(ObjectClass),
                 parent->class_size - sizeof(ObjectClass));
+
+        while (parent) {
+            if (parent->class_base_init) {
+                parent->class_base_init(ti->class, ti->class_data);
+            }
+            parent = type_get_parent(parent);
+        }
      }
 
      memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
#7 lore raw

PATCH 4/25 qom: make Object a type

In reply to Paolo Bonzini

Right now the base Object class has a special NULL type. Change this so that we will be able to add class_init and class_base_init callbacks. To do this, remove some special casing of ObjectClass that is not really necessary.

---
 include/qemu/object.h |    2 +-
 qom/object.c          |   59 +++++++++++++++++++++++++------------------------
 2 files changed, 31 insertions(+), 30 deletions(-)
include/qemu/object.h +1 -1
index ccaea7d..22f646d 100644
@@ -33,7 +33,7 @@ typedef struct TypeInfo TypeInfo;
 typedef struct InterfaceClass InterfaceClass;
 typedef struct InterfaceInfo InterfaceInfo;
 
-#define TYPE_OBJECT NULL
+#define TYPE_OBJECT "object"
 
 /**
  * SECTION:object.h
qom/object.c +30 -29

89 lines not on this page · raw message

Signature · 1 line
1.7.9.3
#8 lore raw

Re: [Qemu-devel] [PATCH 04/25] qom: make Object a type

Am 03.04.2012 13:15, schrieb Paolo Bonzini:

Quoted 4 lines

Right now the base Object class has a special NULL type. Change this so that we will be able to add class_init and class_base_init callbacks. To do this, remove some special casing of ObjectClass that is not really necessary.

While the patch itself looks good, we should be aware that this changes
semantics: Before this patch, lack of .parent is identical to .parent = TYPE_OBJECT; with this patch that would become another base class. Should be mentioned in the commit message and all TypeInfos need to be reviewed. I don't think accidentally growing base classes is a good idea. Maybe whitelist valid base classes in type_register_static() and abort otherwise? Then at least we'd catch it by just running the executables.

Quoted 44 lines
---
 include/qemu/object.h |    2 +-
 qom/object.c          |   59 +++++++++++++++++++++++++------------------------
 2 files changed, 31 insertions(+), 30 deletions(-)
include/qemu/object.h +1 -1
index ccaea7d..22f646d 100644
@@ -33,7 +33,7 @@ typedef struct TypeInfo TypeInfo;
 typedef struct InterfaceClass InterfaceClass;
 typedef struct InterfaceInfo InterfaceInfo;
 
-#define TYPE_OBJECT NULL
+#define TYPE_OBJECT "object"
 
 /**
  * SECTION:object.h
qom/object.c +3 -5
index 6ff1c19..585619d 100644
@@ -210,7 +210,7 @@ static void type_class_interface_init(TypeImpl *ti, InterfaceImpl *iface)
 
 static void type_initialize(TypeImpl *ti)
 {
-    size_t class_size = sizeof(ObjectClass);
+    TypeImpl *parent;
     int i;
 
     if (ti->class) {
@@ -221,30 +221,24 @@ static void type_initialize(TypeImpl *ti)
     ti->instance_size = type_object_get_size(ti);
 
     ti->class = g_malloc0(ti->class_size);
-    ti->class->type = ti;
-
-    if (type_has_parent(ti)) {
-        TypeImpl *parent = type_get_parent(ti);
 
+    parent = type_get_parent(ti);
+    if (parent) {

qom/object.c static void type_initialize(TypeImpl *ti) · line 236

Quoted 10 lines
qom/object.c +2 -4
         type_initialize(parent);
 
-        class_size = parent->class_size;
         g_assert(parent->class_size <= ti->class_size);
+        memcpy(ti->class, parent->class, parent->class_size);
+    }
 
-        memcpy((void *)ti->class + sizeof(ObjectClass),
-               (void *)parent->class + sizeof(ObjectClass),
-               parent->class_size - sizeof(ObjectClass));

Is this really safe? Before we would only copy the contents of derived classes. Missing some explanations IMO.

Quoted 53 lines
qom/object.c +15 -20
+    ti->class->type = ti;
 
-        while (parent) {
-            if (parent->class_base_init) {
-                parent->class_base_init(ti->class, ti->class_data);
-            }
-            parent = type_get_parent(parent);
+    while (parent) {
+        if (parent->class_base_init) {
+            parent->class_base_init(ti->class, ti->class_data);
         }
+        parent = type_get_parent(parent);
     }
 
-    memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
-
     for (i = 0; i < ti->num_interfaces; i++) {
         type_class_interface_init(ti, &ti->interfaces[i]);
     }
@@ -467,19 +461,6 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
 }
 
 
-static void register_types(void)
-{
-    static TypeInfo interface_info = {
-        .name = TYPE_INTERFACE,
-        .instance_size = sizeof(Interface),
-        .abstract = true,
-    };
-
-    type_interface = type_register_static(&interface_info);
-}
-
-type_init(register_types)
-
 Object *object_dynamic_cast_assert(Object *obj, const char *typename)
 {
     Object *inst;
@@ -1233,3 +1214,23 @@ void object_property_add_str(Object *obj, const char *name,
                         property_release_str,
                         prop, errp);
 }
+
+static void register_types(void)
+{
+    static TypeInfo interface_info = {
+        .name = TYPE_INTERFACE,
+        .instance_size = sizeof(Interface),
+        .abstract = true,
+    };
+
+    static TypeInfo object_info = {

qom/object.c void object_property_add_str(Object *obj, const char *name, · line 1236

Quoted 10 lines
qom/object.c +10 -0
+        .name = TYPE_OBJECT,
+        .instance_size = sizeof(Object),
+        .abstract = true,
+    };
+
+    type_interface = type_register_static(&interface_info);
+    type_register_static(&object_info);
+}
+
+type_init(register_types)

Thanks for moving these down.

Is there a reason not to make them static const just before register_types()?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#9 lore raw

Re: [Qemu-devel] [PATCH 04/25] qom: make Object a type

Il 03/04/2012 14:30, Andreas Färber ha scritto:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Right now the base Object class has a special NULL type. Change this so that we will be able to add class_init and class_base_init callbacks. To do this, remove some special casing of ObjectClass that is not really necessary.

Quoted 9 lines

While the patch itself looks good, we should be aware that this changes
semantics: Before this patch, lack of .parent is identical to .parent = TYPE_OBJECT; with this patch that would become another base class. Should be mentioned in the commit message and all TypeInfos need to be reviewed. I don't think accidentally growing base classes is a good idea. Maybe whitelist valid base classes in type_register_static() and abort otherwise? Then at least we'd catch it by just running the executables.

Good idea.

Paolo

Reviewed-by on v1 4/25
#10 lore raw

Re: [Qemu-devel] [PATCH 04/25] qom: make Object a type

In reply to Paolo Bonzini
Quoted 6 lines · Paolo Bonzini

Right now the base Object class has a special NULL type. Change this so that we will be able to add class_init and class_base_init callbacks. To do this, remove some special casing of ObjectClass that is not really necessary.

Regards,

Anthony Liguori

Quoted 115 lines
---
  include/qemu/object.h |    2 +-
  qom/object.c          |   59 +++++++++++++++++++++++++------------------------
  2 files changed, 31 insertions(+), 30 deletions(-)
include/qemu/object.h +1 -1
index ccaea7d..22f646d 100644
@@ -33,7 +33,7 @@ typedef struct TypeInfo TypeInfo;
  typedef struct InterfaceClass InterfaceClass;
  typedef struct InterfaceInfo InterfaceInfo;
 
-#define TYPE_OBJECT NULL
+#define TYPE_OBJECT "object"
 
  /**
   * SECTION:object.h
qom/object.c +30 -29
index 6ff1c19..585619d 100644
@@ -210,7 +210,7 @@ static void type_class_interface_init(TypeImpl *ti, InterfaceImpl *iface)
 
  static void type_initialize(TypeImpl *ti)
  {
-    size_t class_size = sizeof(ObjectClass);
+    TypeImpl *parent;
      int i;
 
      if (ti->class) {
@@ -221,30 +221,24 @@ static void type_initialize(TypeImpl *ti)
      ti->instance_size = type_object_get_size(ti);
 
      ti->class = g_malloc0(ti->class_size);
-    ti->class->type = ti;
-
-    if (type_has_parent(ti)) {
-        TypeImpl *parent = type_get_parent(ti);
 
+    parent = type_get_parent(ti);
+    if (parent) {
          type_initialize(parent);
 
-        class_size = parent->class_size;
          g_assert(parent->class_size<= ti->class_size);
+        memcpy(ti->class, parent->class, parent->class_size);
+    }
 
-        memcpy((void *)ti->class + sizeof(ObjectClass),
-               (void *)parent->class + sizeof(ObjectClass),
-               parent->class_size - sizeof(ObjectClass));
+    ti->class->type = ti;
 
-        while (parent) {
-            if (parent->class_base_init) {
-                parent->class_base_init(ti->class, ti->class_data);
-            }
-            parent = type_get_parent(parent);
+    while (parent) {
+        if (parent->class_base_init) {
+            parent->class_base_init(ti->class, ti->class_data);
          }
+        parent = type_get_parent(parent);
      }
 
-    memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
-
      for (i = 0; i<  ti->num_interfaces; i++) {
          type_class_interface_init(ti,&ti->interfaces[i]);
      }
@@ -467,19 +461,6 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
  }
 
 
-static void register_types(void)
-{
-    static TypeInfo interface_info = {
-        .name = TYPE_INTERFACE,
-        .instance_size = sizeof(Interface),
-        .abstract = true,
-    };
-
-    type_interface = type_register_static(&interface_info);
-}
-
-type_init(register_types)
-
  Object *object_dynamic_cast_assert(Object *obj, const char *typename)
  {
      Object *inst;
@@ -1233,3 +1214,23 @@ void object_property_add_str(Object *obj, const char *name,
                          property_release_str,
                          prop, errp);
  }
+
+static void register_types(void)
+{
+    static TypeInfo interface_info = {
+        .name = TYPE_INTERFACE,
+        .instance_size = sizeof(Interface),
+        .abstract = true,
+    };
+
+    static TypeInfo object_info = {
+        .name = TYPE_OBJECT,
+        .instance_size = sizeof(Object),
+        .abstract = true,
+    };
+
+    type_interface = type_register_static(&interface_info);
+    type_register_static(&object_info);
+}
+
+type_init(register_types)
#11 lore raw

PATCH 5/25 qom: push type up to Object

In reply to Paolo Bonzini

Now that Object is a type, add an instance_init function and push the "type" property from qdev to there.

---
 hw/qdev.c    |    6 ------
 qom/object.c |   11 +++++++++++
 2 files changed, 11 insertions(+), 6 deletions(-)
hw/qdev.c +0 -6
index 0d3c0fc..bb6c1aa 100644
@@ -510,11 +510,6 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
     return strdup(path);
 }
 
-static char *qdev_get_type(Object *obj, Error **errp)
-{
-    return g_strdup(object_get_typename(obj));
-}
-
 /**
  * Legacy property handling
  */
@@ -630,7 +625,6 @@ static void device_initfn(Object *obj)
         qdev_property_add_static(dev, prop, NULL);
     }
 
-    object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
     qdev_prop_set_defaults(dev, qdev_get_props(dev));
 }
 
qom/object.c +11 -0
index 585619d..f3ffaa6 100644
@@ -1215,6 +1215,16 @@ void object_property_add_str(Object *obj, const char *name,
                         prop, errp);
 }
 
+static char *qdev_get_type(Object *obj, Error **errp)
+{
+    return g_strdup(object_get_typename(obj));
+}
+
+static void object_instance_init(Object *obj)
+{
+    object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
+}
+
 static void register_types(void)
 {
     static TypeInfo interface_info = {
@@ -1226,6 +1236,7 @@ static void register_types(void)
     static TypeInfo object_info = {
         .name = TYPE_OBJECT,
         .instance_size = sizeof(Object),
+        .instance_init = object_instance_init,
         .abstract = true,
     };
 
Signature · 1 line
1.7.9.3
Reviewed-by on v1 5/25
#12 lore raw

Re: [Qemu-devel] [PATCH 05/25] qom: push type up to Object

Am 03.04.2012 13:15, schrieb Paolo Bonzini:

Quoted 4 lines

Now that Object is a type, add an instance_init function and push the "type" property from qdev to there.

But please change the subject to 'qom: Push "type" property up to Object', otherwise it's confusing. ;)

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Reviewed-by on v1 5/25
#13 lore raw

Re: [Qemu-devel] [PATCH 05/25] qom: push type up to Object

In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

Now that Object is a type, add an instance_init function and push the "type" property from qdev to there.

Regards,

Anthony Liguori

Quoted 58 lines
---
  hw/qdev.c    |    6 ------
  qom/object.c |   11 +++++++++++
  2 files changed, 11 insertions(+), 6 deletions(-)
hw/qdev.c +0 -6
index 0d3c0fc..bb6c1aa 100644
@@ -510,11 +510,6 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
      return strdup(path);
  }
 
-static char *qdev_get_type(Object *obj, Error **errp)
-{
-    return g_strdup(object_get_typename(obj));
-}
-
  /**
   * Legacy property handling
   */
@@ -630,7 +625,6 @@ static void device_initfn(Object *obj)
          qdev_property_add_static(dev, prop, NULL);
      }
 
-    object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
      qdev_prop_set_defaults(dev, qdev_get_props(dev));
  }
 
qom/object.c +11 -0
index 585619d..f3ffaa6 100644
@@ -1215,6 +1215,16 @@ void object_property_add_str(Object *obj, const char *name,
                          prop, errp);
  }
 
+static char *qdev_get_type(Object *obj, Error **errp)
+{
+    return g_strdup(object_get_typename(obj));
+}
+
+static void object_instance_init(Object *obj)
+{
+    object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
+}
+
  static void register_types(void)
  {
      static TypeInfo interface_info = {
@@ -1226,6 +1236,7 @@ static void register_types(void)
      static TypeInfo object_info = {
          .name = TYPE_OBJECT,
          .instance_size = sizeof(Object),
+        .instance_init = object_instance_init,
          .abstract = true,
      };
 
#14 lore raw

PATCH 6/25 qdev: fix -device foo,?

In reply to Paolo Bonzini

Since most property types do not have a parse property now, this was broken. Fix it by looking at the setter instead.

---
 hw/qdev-monitor.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/qdev-monitor.c +2 -2
index 4783366..0acfc82 100644
@@ -157,7 +157,7 @@ int qdev_device_help(QemuOpts *opts)
          * for removal.  This conditional should be removed along with
          * it.
          */
-        if (!prop->info->parse) {
+        if (!prop->info->set) {
             continue;           /* no way to set it, don't show */
         }
         error_printf("%s.%s=%s\n", driver, prop->name,
@@ -165,7 +165,7 @@ int qdev_device_help(QemuOpts *opts)
     }
     if (info->bus_info) {
         for (prop = info->bus_info->props; prop && prop->name; prop++) {
-            if (!prop->info->parse) {
+            if (!prop->info->set) {
                 continue;           /* no way to set it, don't show */
             }
             error_printf("%s.%s=%s\n", driver, prop->name,
Signature · 1 line
1.7.9.3
Reviewed-by on v1 6/25
#15 lore raw

Re: [Qemu-devel] [PATCH 06/25] qdev: fix -device foo,?

Quoted 4 lines · Paolo Bonzini

Since most property types do not have a parse property now, this was broken. Fix it by looking at the setter instead.

Regards,

Anthony Liguori

Quoted 26 lines
---
  hw/qdev-monitor.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
hw/qdev-monitor.c +2 -2
index 4783366..0acfc82 100644
@@ -157,7 +157,7 @@ int qdev_device_help(QemuOpts *opts)
           * for removal.  This conditional should be removed along with
           * it.
           */
-        if (!prop->info->parse) {
+        if (!prop->info->set) {
              continue;           /* no way to set it, don't show */
          }
          error_printf("%s.%s=%s\n", driver, prop->name,
@@ -165,7 +165,7 @@ int qdev_device_help(QemuOpts *opts)
      }
      if (info->bus_info) {
          for (prop = info->bus_info->props; prop&&  prop->name; prop++) {
-            if (!prop->info->parse) {
+            if (!prop->info->set) {
                  continue;           /* no way to set it, don't show */
              }
              error_printf("%s.%s=%s\n", driver, prop->name,
#16 lore raw

PATCH 7/25 qdev: use object_property_print in info qtree

In reply to Paolo Bonzini

Otherwise, non-string properties without a legacy counterpart are missed. Also fix error propagation in object_property_print itself, otherwise pointer properties are printed as "<null>".

---
 hw/qdev-monitor.c |    2 +-
 qom/object.c      |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/qdev-monitor.c +1 -1
index 0acfc82..07ac525 100644
@@ -492,7 +492,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
         if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
             value = object_property_get_str(OBJECT(dev), legacy_name, &err);
         } else {
-            value = object_property_get_str(OBJECT(dev), props->name, &err);
+            value = object_property_print(OBJECT(dev), props->name, &err);
         }
         g_free(legacy_name);
 
qom/object.c +1 -1
index f3ffaa6..ff36946 100644
@@ -850,7 +850,7 @@ char *object_property_print(Object *obj, const char *name,
     char *string;
 
     mo = string_output_visitor_new();
-    object_property_get(obj, string_output_get_visitor(mo), name, NULL);
+    object_property_get(obj, string_output_get_visitor(mo), name, errp);
     string = string_output_get_string(mo);
     string_output_visitor_cleanup(mo);
     return string;
Signature · 1 line
1.7.9.3
#17 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Quoted 15 lines · Paolo Bonzini

Otherwise, non-string properties without a legacy counterpart are missed. Also fix error propagation in object_property_print itself, otherwise pointer properties are printed as "<null>".

---
 hw/qdev-monitor.c |    2 +-
 qom/object.c      |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/qdev-monitor.c +0 -0
index 0acfc82..07ac525 100644

hw/qdev-monitor.c static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, · line 493

Quoted 2 lines
hw/qdev-monitor.c +0 -0
@@ -492,7 +492,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
         if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
             value = object_property_get_str(OBJECT(dev), legacy_name, &err);

This is not a criticism on this patch, but I'd like to underline that the line above only works because legacy props also define print handlers.

[qdev_property_add_legacy]

    object_property_add(OBJECT(dev), name, type,
                        prop->info->print ? qdev_get_legacy_property : prop->info->get,
                        prop->info->parse ? qdev_set_legacy_property : prop->info->set,
                        NULL,
                        prop, errp);

But this statement above is still inconsistent. We should either assert(print && parse) or handle their non-existence properly.

Quoted 11 lines
hw/qdev-monitor.c +1 -1
         } else {
-            value = object_property_get_str(OBJECT(dev), props->name, &err);
+            value = object_property_print(OBJECT(dev), props->name, &err);
         }
         g_free(legacy_name);
 
qom/object.c +0 -0
index f3ffaa6..ff36946 100644

qom/object.c char *object_property_print(Object *obj, const char *name, · line 856

Quoted 8 lines
qom/object.c +1 -1
@@ -850,7 +850,7 @@ char *object_property_print(Object *obj, const char *name,
     char *string;
 
     mo = string_output_visitor_new();
-    object_property_get(obj, string_output_get_visitor(mo), name, NULL);
+    object_property_get(obj, string_output_get_visitor(mo), name, errp);
     string = string_output_get_string(mo);
     string_output_visitor_cleanup(mo);
     return string;

Patch works for me.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#18 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Il 03/04/2012 14:28, Jan Kiszka ha scritto:

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
         if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
             value = object_property_get_str(OBJECT(dev), legacy_name, &err);

This is not a criticism on this patch, but I'd like to underline that the line above only works because legacy props also define print

                                                 ^^^^

You mean always, I guess.

Quoted 2 lines

But this statement above is still inconsistent. We should either assert(print && parse) or handle their non-existence properly.

Yes, asserting that print/parse are always present in pairs (if at all) would be good.

Paolo

#19 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Am 03.04.2012 15:05, schrieb Paolo Bonzini:

Quoted 7 lines

Il 03/04/2012 14:28, Jan Kiszka ha scritto:

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
         if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
             value = object_property_get_str(OBJECT(dev), legacy_name, &err);

This is not a criticism on this patch, but I'd like to underline that the line above only works because legacy props also define print

                                                 ^^^^
Quoted 7 lines

You mean always, I guess.

Quoted 2 lines

But this statement above is still inconsistent. We should either assert(print && parse) or handle their non-existence properly.

Yes, asserting that print/parse are always present in pairs (if at all) would be good.

Paolo, has this issue been addressed somewhere?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#20 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Quoted 6 lines

Am 03.04.2012 15:05, schrieb Paolo Bonzini:

Quoted 5 lines

Il 03/04/2012 14:28, Jan Kiszka ha scritto:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
value = object_property_get_str(OBJECT(dev), legacy_name, &err);

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

[...] We should either
assert(print && parse) or handle their non-existence properly.

Yes, asserting that print/parse are always present in pairs (if at all) would be good.

Paolo, has this issue been addressed somewhere?

No, but it's a simple assertion. It doesn't look like 1.1 material. I should send and rebase the bus series today, I'll include it.

Paolo

#21 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

----- Messaggio originale -----

Quoted 16 lines

Da: "Paolo Bonzini" <[email protected]>
A: "Andreas Färber" <[email protected]>
Cc: "Jan Kiszka" <[email protected]>, [email protected], [email protected]
Inviato: Mercoledì, 16 maggio 2012 9:40:12
Oggetto: Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Quoted 10 lines

Am 03.04.2012 15:05, schrieb Paolo Bonzini:

Quoted 9 lines

Il 03/04/2012 14:28, Jan Kiszka ha scritto:

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
         if (object_property_get_type(OBJECT(dev),
         legacy_name,
         NULL)) {
             value = object_property_get_str(OBJECT(dev),
             legacy_name, &err);

[...] We should either
assert(print && parse) or handle their non-existence properly.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Yes, asserting that print/parse are always present in pairs (if at
all) would be good.

Paolo, has this issue been addressed somewhere?

No, but it's a simple assertion. It doesn't look like 1.1 material. I should send and rebase the bus series today, I'll include it.

Doh, it was handled by

commit 68ee356941801d0a17fdc43b11ac3e6b72fcd597

Author: Paolo Bonzini <[email protected]>
Date:   Thu Feb 2 10:17:19 2012 +0100

qdev: allow reusing get/set for legacy property

print/parse do not have to be present in pairs anymore.

Paolo

Reviewed-by on v1 7/25
#22 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

In reply to Paolo Bonzini
Quoted 5 lines · Paolo Bonzini

Otherwise, non-string properties without a legacy counterpart are missed. Also fix error propagation in object_property_print itself, otherwise pointer properties are printed as "<null>".

Regards,

Anthony Liguori

Quoted 31 lines
---
  hw/qdev-monitor.c |    2 +-
  qom/object.c      |    2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
hw/qdev-monitor.c +1 -1
index 0acfc82..07ac525 100644
@@ -492,7 +492,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
          if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
              value = object_property_get_str(OBJECT(dev), legacy_name,&err);
          } else {
-            value = object_property_get_str(OBJECT(dev), props->name,&err);
+            value = object_property_print(OBJECT(dev), props->name,&err);
          }
          g_free(legacy_name);
 
qom/object.c +1 -1
index f3ffaa6..ff36946 100644
@@ -850,7 +850,7 @@ char *object_property_print(Object *obj, const char *name,
      char *string;
 
      mo = string_output_visitor_new();
-    object_property_get(obj, string_output_get_visitor(mo), name, NULL);
+    object_property_get(obj, string_output_get_visitor(mo), name, errp);
      string = string_output_get_string(mo);
      string_output_visitor_cleanup(mo);
      return string;
#23 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Paolo Bonzini

Otherwise, non-string properties without a legacy counterpart are missed. Also fix error propagation in object_property_print itself, otherwise pointer properties are printed as "<null>".

The bug that this fixes is still present in current 1.1-rc. Any chance that the patch makes it into the release?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#24 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Il 10/05/2012 22:58, Jan Kiszka ha scritto:

Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Otherwise, non-string properties without a legacy counterpart are missed. Also fix error propagation in object_property_print itself, otherwise pointer properties are printed as "<null>".

The bug that this fixes is still present in current 1.1-rc. Any chance that the patch makes it into the release?

Andreas, are you queueing this patch and 6/25 for 1.1-rc2?

Paolo

#25 lore raw

Re: [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree

Am 11.05.2012 13:28, schrieb Paolo Bonzini:

Quoted 5 lines

Il 10/05/2012 22:58, Jan Kiszka ha scritto:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Otherwise, non-string properties without a legacy counterpart are missed. Also fix error propagation in object_property_print itself, otherwise pointer properties are printed as "<null>".

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

The bug that this fixes is still present in current 1.1-rc. Any chance that the patch makes it into the release?

Andreas, are you queueing this patch and 6/25 for 1.1-rc2?

I need to review it first and I try to pick the latest one (which would presumable be in the QBus series), but yes, this and one other of yours (the one with the prop->set or so check) is on my radar for 1.1-rc2.

I think I'll start a qom-1.1 branch to make this more transparent.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#26 lore raw

PATCH 8/25 qdev: remove qdev_prop_set_defaults

In reply to Paolo Bonzini
---
 hw/qdev-properties.c |   22 ----------------------
 hw/qdev.c            |   28 +++++++++++++++++++++++-----
 hw/qdev.h            |    1 -
 3 files changed, 23 insertions(+), 28 deletions(-)
hw/qdev-properties.c +0 -22
index bff9152..85897c7 100644
@@ -1083,28 +1083,6 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
-void qdev_prop_set_defaults(DeviceState *dev, Property *props)
-{
-    Object *obj = OBJECT(dev);
-    if (!props)
-        return;
-    for (; props->name; props++) {
-        Error *errp = NULL;
-        if (props->qtype == QTYPE_NONE) {
-            continue;
-        }
-        if (props->qtype == QTYPE_QBOOL) {
-            object_property_set_bool(obj, props->defval, props->name, &errp);
-        } else if (props->info->enum_table) {
-            object_property_set_str(obj, props->info->enum_table[props->defval],
-                                    props->name, &errp);
-        } else if (props->qtype == QTYPE_QINT) {
-            object_property_set_int(obj, props->defval, props->name, &errp);
-        }
-        assert_no_error(errp);
-    }
-}
-
 static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props);
 
 static void qdev_prop_register_global(GlobalProperty *prop)
hw/qdev.c +23 -5
index bb6c1aa..4ac5616 100644
@@ -90,7 +90,6 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
         qdev_property_add_legacy(dev, prop, NULL);
         qdev_property_add_static(dev, prop, NULL);
     }
-    qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
 }
 
 /* Create a new device.  This only initializes the device state structure
@@ -592,6 +591,9 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop,
 void qdev_property_add_static(DeviceState *dev, Property *prop,
                               Error **errp)
 {
+    Error *local_err = NULL;
+    Object *obj = OBJECT(dev);
+
     /*
      * TODO qdev_prop_ptr does not have getters or setters.  It must
      * go now that it can be replaced with links.  The test should be
@@ -601,10 +603,28 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
         return;
     }
 
-    object_property_add(OBJECT(dev), prop->name, prop->info->name,
+    object_property_add(obj, prop->name, prop->info->name,
                         prop->info->get, prop->info->set,
                         prop->info->release,
-                        prop, errp);
+                        prop, &local_err);
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    if (prop->qtype == QTYPE_NONE) {
+        return;
+    }
+
+    if (prop->qtype == QTYPE_QBOOL) {
+        object_property_set_bool(obj, prop->defval, prop->name, &local_err);
+    } else if (prop->info->enum_table) {
+        object_property_set_str(obj, prop->info->enum_table[prop->defval],
+                                prop->name, &local_err);
+    } else if (prop->qtype == QTYPE_QINT) {
+        object_property_set_int(obj, prop->defval, prop->name, &local_err);
+    }
+    assert_no_error(local_err);
 }
 
 static void device_initfn(Object *obj)
@@ -624,8 +644,6 @@ static void device_initfn(Object *obj)
         qdev_property_add_legacy(dev, prop, NULL);
         qdev_property_add_static(dev, prop, NULL);
     }
-
-    qdev_prop_set_defaults(dev, qdev_get_props(dev));
 }
 
 /* Unlink device from bus and free the structure.  */
hw/qdev.h +0 -1
index a8df42f..12de112 100644
@@ -308,7 +308,6 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 /* FIXME: Remove opaque pointer properties.  */
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
-void qdev_prop_set_defaults(DeviceState *dev, Property *props);
 
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev);
Signature · 1 line
1.7.9.3
#27 lore raw

Re: [Qemu-devel] [PATCH 08/25] qdev: remove qdev_prop_set_defaults

Quoted 47 lines · Paolo Bonzini
---
  hw/qdev-properties.c |   22 ----------------------
  hw/qdev.c            |   28 +++++++++++++++++++++++-----
  hw/qdev.h            |    1 -
  3 files changed, 23 insertions(+), 28 deletions(-)
hw/qdev-properties.c +0 -22
index bff9152..85897c7 100644
@@ -1083,28 +1083,6 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
      *ptr = value;
  }
 
-void qdev_prop_set_defaults(DeviceState *dev, Property *props)
-{
-    Object *obj = OBJECT(dev);
-    if (!props)
-        return;
-    for (; props->name; props++) {
-        Error *errp = NULL;
-        if (props->qtype == QTYPE_NONE) {
-            continue;
-        }
-        if (props->qtype == QTYPE_QBOOL) {
-            object_property_set_bool(obj, props->defval, props->name,&errp);
-        } else if (props->info->enum_table) {
-            object_property_set_str(obj, props->info->enum_table[props->defval],
-                                    props->name,&errp);
-        } else if (props->qtype == QTYPE_QINT) {
-            object_property_set_int(obj, props->defval, props->name,&errp);
-        }
-        assert_no_error(errp);
-    }
-}
-
  static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props);
 
  static void qdev_prop_register_global(GlobalProperty *prop)
hw/qdev.c +0 -0
index bb6c1aa..4ac5616 100644

hw/qdev.c void qdev_set_parent_bus(DeviceState *dev, BusState *bus) · line 93

Quoted 4 lines
hw/qdev.c +0 -1
@@ -90,7 +90,6 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
          qdev_property_add_legacy(dev, prop, NULL);
          qdev_property_add_static(dev, prop, NULL);
      }
-    qdev_prop_set_defaults(dev, dev->parent_bus->info->props);

Does this break bisectability?

Regards,

Anthony Liguori

#28 lore raw

Re: [Qemu-devel] [PATCH 08/25] qdev: remove qdev_prop_set_defaults

Il 03/04/2012 23:09, Anthony Liguori ha scritto:

Quoted 47 lines · Paolo Bonzini
Quoted 46 lines
---
  hw/qdev-properties.c |   22 ----------------------
  hw/qdev.c            |   28 +++++++++++++++++++++++-----
  hw/qdev.h            |    1 -
  3 files changed, 23 insertions(+), 28 deletions(-)
hw/qdev-properties.c +0 -17
index bff9152..85897c7 100644
@@ -1083,28 +1083,6 @@ void qdev_prop_set_ptr(DeviceState *dev, const
 char *name, void *value)
      *ptr = value;
  }
 
-void qdev_prop_set_defaults(DeviceState *dev, Property *props)
-{
-    Object *obj = OBJECT(dev);
-    if (!props)
-        return;
-    for (; props->name; props++) {
-        Error *errp = NULL;
-        if (props->qtype == QTYPE_NONE) {
-            continue;
-        }
-        if (props->qtype == QTYPE_QBOOL) {
-            object_property_set_bool(obj, props->defval,
 props->name,&errp);
-        } else if (props->info->enum_table) {
-            object_property_set_str(obj,
 props->info->enum_table[props->defval],
-                                    props->name,&errp);
-        } else if (props->qtype == QTYPE_QINT) {
-            object_property_set_int(obj, props->defval,

props->name,&errp);

hw/qdev-properties.c +0 -5
-        }
-        assert_no_error(errp);
-    }
-}
-
  static QTAILQ_HEAD(, GlobalProperty) global_props =

QTAILQ_HEAD_INITIALIZER(global_props);

Quoted 13 lines

hw/qdev.c void qdev_set_parent_bus(DeviceState *dev, BusState · line 94

Quoted 11 lines

static void qdev_prop_register_global(GlobalProperty *prop)

hw/qdev.c +0 -1
index bb6c1aa..4ac5616 100644
@@ -90,7 +90,6 @@ void qdev_set_parent_bus(DeviceState *dev, BusState
 *bus)
          qdev_property_add_legacy(dev, prop, NULL);
          qdev_property_add_static(dev, prop, NULL);
      }
-    qdev_prop_set_defaults(dev, dev->parent_bus->info->props);

Does this break bisectability?

Hmm, here it does. It must be moved later.

Paolo

#29 lore raw

PATCH 9/25 qdev: move bus properties to a separate global

In reply to Paolo Bonzini

Simple code movement in order to simplify future refactoring.

---
 hw/i2c.c                      |   10 ++++++----
 hw/ide/qdev.c                 |   10 ++++++----
 hw/intel-hda.c                |   10 ++++++----
 hw/pci.c                      |   22 ++++++++++++----------
 hw/scsi-bus.c                 |   14 ++++++++------
 hw/spapr_vio.c                |   10 ++++++----
 hw/usb/bus.c                  |   11 +++++++----
 hw/usb/dev-smartcard-reader.c |   10 ++++++----
 hw/virtio-serial-bus.c        |   12 +++++++-----
 9 files changed, 64 insertions(+), 45 deletions(-)
hw/i2c.c +6 -4
index 23dfccb..cb10b1d 100644
@@ -17,13 +17,15 @@ struct i2c_bus
     uint8_t saved_address;
 };
 
+static Property i2c_props[] = {
+    DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static struct BusInfo i2c_bus_info = {
     .name = "I2C",
     .size = sizeof(i2c_bus),
-    .props = (Property[]) {
-        DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+    .props = i2c_props,
 };
 
 static void i2c_bus_pre_save(void *opaque)
hw/ide/qdev.c +6 -4
index f6a4896..4d372f8 100644
@@ -27,14 +27,16 @@
 
 static char *idebus_get_fw_dev_path(DeviceState *dev);
 
+static Property ide_props[] = {
+    DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static struct BusInfo ide_bus_info = {
     .name  = "IDE",
     .size  = sizeof(IDEBus),
     .get_fw_dev_path = idebus_get_fw_dev_path,
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+    .props = ide_props,
 };
 
 void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id)
hw/intel-hda.c +6 -4
index bb11af2..0994f6b 100644
@@ -29,13 +29,15 @@
 /* --------------------------------------------------------------------- */
 /* hda bus                                                               */
 
+static Property hda_props[] = {
+    DEFINE_PROP_UINT32("cad", HDACodecDevice, cad, -1),
+    DEFINE_PROP_END_OF_LIST()
+};
+
 static struct BusInfo hda_codec_bus_info = {
     .name      = "HDA",
     .size      = sizeof(HDACodecBus),
-    .props     = (Property[]) {
-        DEFINE_PROP_UINT32("cad", HDACodecDevice, cad, -1),
-        DEFINE_PROP_END_OF_LIST()
-    }
+    .props     = hda_props,
 };
 
 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
hw/pci.c +12 -10
index ed8ec99..fff4c4a 100644
@@ -44,6 +44,17 @@ static char *pcibus_get_dev_path(DeviceState *dev);
 static char *pcibus_get_fw_dev_path(DeviceState *dev);
 static int pcibus_reset(BusState *qbus);
 
+static Property pci_props[] = {
+    DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
+    DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
+    DEFINE_PROP_UINT32("rombar",  PCIDevice, rom_bar, 1),
+    DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
+                    QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
+    DEFINE_PROP_BIT("command_serr_enable", PCIDevice, cap_present,
+                    QEMU_PCI_CAP_SERR_BITNR, true),
+    DEFINE_PROP_END_OF_LIST()
+};
+
 struct BusInfo pci_bus_info = {
     .name       = "PCI",
     .size       = sizeof(PCIBus),
@@ -51,16 +62,7 @@ struct BusInfo pci_bus_info = {
     .get_dev_path = pcibus_get_dev_path,
     .get_fw_dev_path = pcibus_get_fw_dev_path,
     .reset      = pcibus_reset,
-    .props      = (Property[]) {
-        DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
-        DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
-        DEFINE_PROP_UINT32("rombar",  PCIDevice, rom_bar, 1),
-        DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
-                        QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
-        DEFINE_PROP_BIT("command_serr_enable", PCIDevice, cap_present,
-                        QEMU_PCI_CAP_SERR_BITNR, true),
-        DEFINE_PROP_END_OF_LIST()
-    }
+    .props      = pci_props,
 };
 
 static void pci_update_mappings(PCIDevice *d);
hw/scsi-bus.c +8 -6
index 8e76c5d..0352c59 100644
@@ -12,17 +12,19 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev);
 static int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf);
 static void scsi_req_dequeue(SCSIRequest *req);
 
+static Property scsi_props[] = {
+    DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
+    DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
+    DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static struct BusInfo scsi_bus_info = {
     .name  = "SCSI",
     .size  = sizeof(SCSIBus),
     .get_dev_path = scsibus_get_dev_path,
     .get_fw_dev_path = scsibus_get_fw_dev_path,
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
-        DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
-        DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
-        DEFINE_PROP_END_OF_LIST(),
-    },
+    .props = scsi_props,
 };
 static int next_scsi_bus;
 
hw/spapr_vio.c +6 -4
index dbf5a90..941a013 100644
@@ -49,13 +49,15 @@
     do { } while (0)
 #endif
 
+static Property spapr_vio_props[] = {
+    DEFINE_PROP_UINT32("irq", VIOsPAPRDevice, vio_irq_num, 0), \
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static struct BusInfo spapr_vio_bus_info = {
     .name       = "spapr-vio",
     .size       = sizeof(VIOsPAPRBus),
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("irq", VIOsPAPRDevice, vio_irq_num, 0), \
-        DEFINE_PROP_END_OF_LIST(),
-    },
+    .props      = spapr_vio_props,
 };
 
 VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
hw/usb/bus.c +7 -4
index d3f8358..0271bc0 100644
@@ -11,17 +11,20 @@ static char *usb_get_dev_path(DeviceState *dev);
 static char *usb_get_fw_dev_path(DeviceState *qdev);
 static int usb_qdev_exit(DeviceState *qdev);
 
+static Property usb_props[] = {
+    DEFINE_PROP_STRING("port", USBDevice, port_path),
+    DEFINE_PROP_END_OF_LIST()
+};
+
 static struct BusInfo usb_bus_info = {
     .name      = "USB",
     .size      = sizeof(USBBus),
     .print_dev = usb_bus_dev_print,
     .get_dev_path = usb_get_dev_path,
     .get_fw_dev_path = usb_get_fw_dev_path,
-    .props      = (Property[]) {
-        DEFINE_PROP_STRING("port", USBDevice, port_path),
-        DEFINE_PROP_END_OF_LIST()
-    },
+    .props     = usb_props,
 };
+
 static int next_usb_bus = 0;
 static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
 
hw/usb/dev-smartcard-reader.c +6 -4
index 8e66675..4a9cc16 100644
@@ -1055,13 +1055,15 @@ static Answer *ccid_peek_next_answer(USBCCIDState *s)
         : &s->pending_answers[s->pending_answers_start % PENDING_ANSWERS_NUM];
 }
 
+static Property ccid_props[] = {
+    DEFINE_PROP_UINT32("slot", struct CCIDCardState, slot, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static struct BusInfo ccid_bus_info = {
     .name = "ccid-bus",
     .size = sizeof(CCIDBus),
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("slot", struct CCIDCardState, slot, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
+    .props = ccid_props,
 };
 
 void ccid_card_send_apdu_to_guest(CCIDCardState *card,
hw/virtio-serial-bus.c +7 -5
index e22940e..703c08d 100644
@@ -677,15 +677,17 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
 
 static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
 
+static Property virtser_props[] = {
+    DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID),
+    DEFINE_PROP_STRING("name", VirtIOSerialPort, name),
+    DEFINE_PROP_END_OF_LIST()
+};
+
 static struct BusInfo virtser_bus_info = {
     .name      = "virtio-serial-bus",
     .size      = sizeof(VirtIOSerialBus),
     .print_dev = virtser_bus_dev_print,
-    .props      = (Property[]) {
-        DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID),
-        DEFINE_PROP_STRING("name", VirtIOSerialPort, name),
-        DEFINE_PROP_END_OF_LIST()
-    }
+    .props     = virtser_props,
 };
 
 static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
Signature · 1 line
1.7.9.3
#30 lore raw

PATCH 10/25 qdev: do not propagate properties to subclasses

In reply to Paolo Bonzini

As soon as we'll look up properties along the inheritance chain, we will have duplicates if class A defines some properties and its subclass B does not define any, because class_b->props will be left equal to class_a->props.

The solution here is to reintroduce the class_base_init TypeInfo callback, that was present in one of the early QOM versions but removed (on my request...) before committing.

---
 hw/qdev.c |   11 +++++++++++
 1 file changed, 11 insertions(+)
hw/qdev.c +11 -0
index 4ac5616..d2b0134 100644
@@ -671,6 +671,16 @@ static void device_finalize(Object *obj)
     QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
 }
 
+static void device_class_base_init(ObjectClass *class, void *data)
+{
+    DeviceClass *klass = DEVICE_CLASS(class);
+
+    /* We explicitly look up properties in the superclasses,
+     * so do not propagate them to the subclasses.
+     */
+    klass->props = NULL;
+}
+
 void device_reset(DeviceState *dev)
 {
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -697,6 +707,7 @@ static TypeInfo device_type_info = {
     .instance_size = sizeof(DeviceState),
     .instance_init = device_initfn,
     .instance_finalize = device_finalize,
+    .class_base_init = device_class_base_init,
     .abstract = true,
     .class_size = sizeof(DeviceClass),
 };
Signature · 1 line
1.7.9.3
#31 lore raw

PATCH 11/25 qdev: pick global properties from superclasses

In reply to Paolo Bonzini

In qdev, each bus in practice identified an abstract superclass, but this was mostly hidden. In QOM, instead, these abstract classes are explicit so we can move bus properties there.

This patch moves global bus properties, an obscure feature when used with the command-line which is actually useful and used when used by backwards-compatible machine types.

---
 hw/pc_piix.c         |   12 ++++++------
 hw/qdev-properties.c |   23 +++++++++++++----------
 2 files changed, 19 insertions(+), 16 deletions(-)
hw/pc_piix.c +6 -6
index fadca4c..8bd6482 100644
@@ -460,7 +460,7 @@ static QEMUMachine pc_machine_v0_13 = {
             .property = "rombar",
             .value    = stringify(0),
         },{
-            .driver   = "PCI",
+            .driver   = TYPE_PCI_DEVICE,
             .property = "command_serr_enable",
             .value    = "off",
         },{
@@ -520,7 +520,7 @@ static QEMUMachine pc_machine_v0_12 = {
             .property = "rombar",
             .value    = stringify(0),
         },{
-            .driver   = "PCI",
+            .driver   = TYPE_PCI_DEVICE,
             .property = "command_serr_enable",
             .value    = "off",
         },{
@@ -584,11 +584,11 @@ static QEMUMachine pc_machine_v0_11 = {
             .property = "ver",
             .value    = "0.11",
         },{
-            .driver   = "PCI",
+            .driver   = TYPE_PCI_DEVICE,
             .property = "rombar",
             .value    = stringify(0),
         },{
-            .driver   = "PCI",
+            .driver   = TYPE_PCI_DEVICE,
             .property = "command_serr_enable",
             .value    = "off",
         },{
@@ -664,11 +664,11 @@ static QEMUMachine pc_machine_v0_10 = {
             .property = "ver",
             .value    = "0.10",
         },{
-            .driver   = "PCI",
+            .driver   = TYPE_PCI_DEVICE,
             .property = "rombar",
             .value    = stringify(0),
         },{
-            .driver   = "PCI",
+            .driver   = TYPE_PCI_DEVICE,
             .property = "command_serr_enable",
             .value    = "off",
         },{
hw/qdev-properties.c +13 -10
index 85897c7..a9276f9 100644
@@ -1101,17 +1101,20 @@ void qdev_prop_register_global_list(GlobalProperty *props)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    GlobalProperty *prop;
-
-    QTAILQ_FOREACH(prop, &global_props, next) {
-        if (strcmp(object_get_typename(OBJECT(dev)), prop->driver) != 0 &&
-            strcmp(qdev_get_bus_info(dev)->name, prop->driver) != 0) {
-            continue;
-        }
-        if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
-            exit(1);
+    ObjectClass *class = object_get_class(OBJECT(dev));
+
+    do {
+        GlobalProperty *prop;
+        QTAILQ_FOREACH(prop, &global_props, next) {
+            if (strcmp(object_class_get_name(class), prop->driver) != 0) {
+                continue;
+            }
+            if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
+                exit(1);
+            }
         }
-    }
+        class = object_class_get_parent(class);
+    } while (class);
 }
 
 static int qdev_add_one_global(QemuOpts *opts, void *opaque)
Signature · 1 line
1.7.9.3
#32 lore raw

PATCH 12/25 qdev: factor setting of global properties

In reply to Paolo Bonzini

Now that global properties do not depend on buses anymore, set them directly in the device instance_init function.

---
 hw/qdev-monitor.c |    1 -
 hw/qdev.c         |    2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
hw/qdev-monitor.c +0 -1
index 07ac525..3d95940 100644
@@ -448,7 +448,6 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     /* create device, set properties */
     qdev = DEVICE(object_new(driver));
     qdev_set_parent_bus(qdev, bus);
-    qdev_prop_set_globals(qdev);
 
     id = qemu_opts_id(opts);
     if (id) {
hw/qdev.c +1 -1
index d2b0134..adef566 100644
@@ -129,7 +129,6 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
     }
 
     qdev_set_parent_bus(dev, bus);
-    qdev_prop_set_globals(dev);
 
     return dev;
 }
@@ -644,6 +643,7 @@ static void device_initfn(Object *obj)
         qdev_property_add_legacy(dev, prop, NULL);
         qdev_property_add_static(dev, prop, NULL);
     }
+    qdev_prop_set_globals(dev);
 }
 
 /* Unlink device from bus and free the structure.  */
Signature · 1 line
1.7.9.3
#33 lore raw

PATCH 13/25 qdev: replace bus properties with superclass properties

In reply to Paolo Bonzini

After the previous patch, this one changes all bus property walks to look along the class hierarchy instead. Bus properties are moved to abstract classes.

---
 hw/i2c.c                      |    2 +-
 hw/ide/qdev.c                 |    2 +-
 hw/intel-hda.c                |    2 +-
 hw/pci.c                      |    2 +-
 hw/qdev-monitor.c             |   41 ++++++++++++++++++-----------------------
 hw/qdev-properties.c          |   17 +++++++++--------
 hw/qdev.c                     |   32 +++++++++-----------------------
 hw/qdev.h                     |    5 -----
 hw/scsi-bus.c                 |    2 +-
 hw/spapr_vio.c                |    2 +-
 hw/usb/bus.c                  |    2 +-
 hw/usb/dev-smartcard-reader.c |    2 +-
 hw/virtio-serial-bus.c        |    2 +-
 13 files changed, 45 insertions(+), 68 deletions(-)
hw/i2c.c +1 -1
index cb10b1d..af5979e 100644
@@ -25,7 +25,6 @@ static Property i2c_props[] = {
 static struct BusInfo i2c_bus_info = {
     .name = "I2C",
     .size = sizeof(i2c_bus),
-    .props = i2c_props,
 };
 
 static void i2c_bus_pre_save(void *opaque)
@@ -221,6 +220,7 @@ static void i2c_slave_class_init(ObjectClass *klass, void *data)
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = i2c_slave_qdev_init;
     k->bus_info = &i2c_bus_info;
+    k->props = i2c_props;
 }
 
 static TypeInfo i2c_slave_type_info = {
hw/ide/qdev.c +1 -1
index 4d372f8..27ff47c 100644
@@ -36,7 +36,6 @@ static struct BusInfo ide_bus_info = {
     .name  = "IDE",
     .size  = sizeof(IDEBus),
     .get_fw_dev_path = idebus_get_fw_dev_path,
-    .props = ide_props,
 };
 
 void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id)
@@ -248,6 +247,7 @@ static void ide_device_class_init(ObjectClass *klass, void *data)
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = ide_qdev_init;
     k->bus_info = &ide_bus_info;
+    k->props = ide_props;
 }
 
 static TypeInfo ide_device_type_info = {
hw/intel-hda.c +1 -1
index 0994f6b..e2bd41e 100644
@@ -37,7 +37,6 @@ static Property hda_props[] = {
 static struct BusInfo hda_codec_bus_info = {
     .name      = "HDA",
     .size      = sizeof(HDACodecBus),
-    .props     = hda_props,
 };
 
 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
@@ -1278,6 +1277,7 @@ static void hda_codec_device_class_init(ObjectClass *klass, void *data)
     k->init = hda_codec_dev_init;
     k->exit = hda_codec_dev_exit;
     k->bus_info = &hda_codec_bus_info;
+    k->props = hda_props;
 }
 
 static TypeInfo hda_codec_device_type_info = {
hw/pci.c +1 -1
index fff4c4a..4e8e726 100644
@@ -62,7 +62,6 @@ struct BusInfo pci_bus_info = {
     .get_dev_path = pcibus_get_dev_path,
     .get_fw_dev_path = pcibus_get_fw_dev_path,
     .reset      = pcibus_reset,
-    .props      = pci_props,
 };
 
 static void pci_update_mappings(PCIDevice *d);
@@ -2004,6 +2003,7 @@ static void pci_device_class_init(ObjectClass *klass, void *data)
     k->unplug = pci_unplug_device;
     k->exit = pci_unregister_device;
     k->bus_info = &pci_bus_info;
+    k->props = pci_props;
 }
 
 static TypeInfo pci_device_type_info = {
hw/qdev-monitor.c +18 -23

83 lines not on this page · raw message

hw/qdev-properties.c +9 -8
index a9276f9..60fef9a 100644
@@ -893,17 +893,18 @@ static Property *qdev_prop_walk(Property *props, const char *name)
 
 static Property *qdev_prop_find(DeviceState *dev, const char *name)
 {
+    ObjectClass *class;
     Property *prop;
 
     /* device properties */
-    prop = qdev_prop_walk(qdev_get_props(dev), name);
-    if (prop)
-        return prop;
-
-    /* bus properties */
-    prop = qdev_prop_walk(dev->parent_bus->info->props, name);
-    if (prop)
-        return prop;
+    class = object_get_class(OBJECT(dev));
+    do {
+        prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name);
+        if (prop) {
+            return prop;
+        }
+        class = object_class_get_parent(class);
+    } while (class != object_class_by_name(TYPE_DEVICE));
 
     return NULL;
 }
hw/qdev.c +9 -23
index adef566..aeebb86 100644
@@ -44,18 +44,6 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
     return dc->vmsd;
 }
 
-BusInfo *qdev_get_bus_info(DeviceState *dev)
-{
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);
-    return dc->bus_info;
-}
-
-Property *qdev_get_props(DeviceState *dev)
-{
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);
-    return dc->props;
-}
-
 const char *qdev_fw_name(DeviceState *dev)
 {
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
@@ -77,19 +65,12 @@ static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
 
 void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
 {
-    Property *prop;
-
     if (qdev_hotplug) {
         assert(bus->allow_hotplug);
     }
 
     dev->parent_bus = bus;
     QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
-
-    for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
-        qdev_property_add_legacy(dev, prop, NULL);
-        qdev_property_add_static(dev, prop, NULL);
-    }
 }
 
 /* Create a new device.  This only initializes the device state structure
@@ -629,6 +610,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
 static void device_initfn(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
+    ObjectClass *class;
     Property *prop;
 
     if (qdev_hotplug) {
@@ -639,10 +621,14 @@ static void device_initfn(Object *obj)
     dev->instance_id_alias = -1;
     dev->state = DEV_STATE_CREATED;
 
-    for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
-        qdev_property_add_legacy(dev, prop, NULL);
-        qdev_property_add_static(dev, prop, NULL);
-    }
+    class = object_get_class(OBJECT(dev));
+    do {
+        for (prop = DEVICE_CLASS(class)->props; prop && prop->name; prop++) {
+            qdev_property_add_legacy(dev, prop, NULL);
+            qdev_property_add_static(dev, prop, NULL);
+        }
+        class = object_class_get_parent(class);
+    } while (class != object_class_by_name(TYPE_DEVICE));
     qdev_prop_set_globals(dev);
 }
 
hw/qdev.h +0 -5
index 12de112..aea53c8 100644
@@ -95,7 +95,6 @@ struct BusInfo {
     bus_get_dev_path get_dev_path;
     bus_get_fw_dev_path get_fw_dev_path;
     qbus_resetfn *reset;
-    Property *props;
 };
 
 struct BusState {
@@ -344,10 +343,6 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
 
 const char *qdev_fw_name(DeviceState *dev);
 
-BusInfo *qdev_get_bus_info(DeviceState *dev);
-
-Property *qdev_get_props(DeviceState *dev);
-
 Object *qdev_get_machine(void);
 
 /* FIXME: make this a link<> */
hw/scsi-bus.c +1 -1
index 0352c59..10f9c63 100644
@@ -24,7 +24,6 @@ static struct BusInfo scsi_bus_info = {
     .size  = sizeof(SCSIBus),
     .get_dev_path = scsibus_get_dev_path,
     .get_fw_dev_path = scsibus_get_fw_dev_path,
-    .props = scsi_props,
 };
 static int next_scsi_bus;
 
@@ -1575,6 +1574,7 @@ static void scsi_device_class_init(ObjectClass *klass, void *data)
     k->init     = scsi_qdev_init;
     k->unplug   = qdev_simple_unplug_cb;
     k->exit     = scsi_qdev_exit;
+    k->props    = scsi_props;
 }
 
 static TypeInfo scsi_device_type_info = {
hw/spapr_vio.c +1 -1
index 941a013..897c057 100644
@@ -57,7 +57,6 @@ static Property spapr_vio_props[] = {
 static struct BusInfo spapr_vio_bus_info = {
     .name       = "spapr-vio",
     .size       = sizeof(VIOsPAPRBus),
-    .props      = spapr_vio_props,
 };
 
 VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
@@ -769,6 +768,7 @@ static void vio_spapr_device_class_init(ObjectClass *klass, void *data)
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = spapr_vio_busdev_init;
     k->bus_info = &spapr_vio_bus_info;
+    k->props = spapr_vio_props;
 }
 
 static TypeInfo spapr_vio_type_info = {
hw/usb/bus.c +1 -1
index 0271bc0..12d1be0 100644
@@ -22,7 +22,6 @@ static struct BusInfo usb_bus_info = {
     .print_dev = usb_bus_dev_print,
     .get_dev_path = usb_get_dev_path,
     .get_fw_dev_path = usb_get_fw_dev_path,
-    .props     = usb_props,
 };
 
 static int next_usb_bus = 0;
@@ -568,6 +567,7 @@ static void usb_device_class_init(ObjectClass *klass, void *data)
     k->init     = usb_qdev_init;
     k->unplug   = qdev_simple_unplug_cb;
     k->exit     = usb_qdev_exit;
+    k->props    = usb_props;
 }
 
 static TypeInfo usb_device_type_info = {
hw/usb/dev-smartcard-reader.c +1 -1
index 4a9cc16..a38a948 100644
@@ -1063,7 +1063,6 @@ static Property ccid_props[] = {
 static struct BusInfo ccid_bus_info = {
     .name = "ccid-bus",
     .size = sizeof(CCIDBus),
-    .props = ccid_props,
 };
 
 void ccid_card_send_apdu_to_guest(CCIDCardState *card,
@@ -1346,6 +1345,7 @@ static void ccid_card_class_init(ObjectClass *klass, void *data)
     k->bus_info = &ccid_bus_info;
     k->init = ccid_card_init;
     k->exit = ccid_card_exit;
+    k->props = ccid_props;
 }
 
 static TypeInfo ccid_card_type_info = {
hw/virtio-serial-bus.c +1 -1
index 703c08d..6d49ad6 100644
@@ -687,7 +687,6 @@ static struct BusInfo virtser_bus_info = {
     .name      = "virtio-serial-bus",
     .size      = sizeof(VirtIOSerialBus),
     .print_dev = virtser_bus_dev_print,
-    .props     = virtser_props,
 };
 
 static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
@@ -940,6 +939,7 @@ static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
     k->bus_info = &virtser_bus_info;
     k->exit = virtser_port_qdev_exit;
     k->unplug = qdev_simple_unplug_cb;
+    k->props = virtser_props;
 }
 
 static TypeInfo virtio_serial_port_type_info = {
Signature · 1 line
1.7.9.3
#34 lore raw

PATCH 14/25 qapi: add Visitor interfaces for uint*_t and int*_t

In reply to Paolo Bonzini

From: Michael Roth <[email protected]>

This adds visitor interfaces for fixed-width integers types. Implementing these in visitors is optional, otherwise we fall back to visit_type_int() (int64_t) with some additional bounds checking to avoid integer overflows for cases where the value fetched exceeds the bounds of our target C type.

---
 hw/mc146818rtc.c       |    7 ---
 qapi/qapi-visit-core.c |  139 ++++++++++++++++++++++++++++++++++++++++++++++++
 qapi/qapi-visit-core.h |   16 ++++++
 3 files changed, 155 insertions(+), 7 deletions(-)
hw/mc146818rtc.c +0 -7
index 9c64e0a..3777f85 100644
@@ -599,13 +599,6 @@ static const MemoryRegionOps cmos_ops = {
     .old_portio = cmos_portio
 };
 
-// FIXME add int32 visitor
-static void visit_type_int32(Visitor *v, int *value, const char *name, Error **errp)
-{
-    int64_t val = *value;
-    visit_type_int(v, &val, name, errp);
-}
-
 static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
                          const char *name, Error **errp)
 {
qapi/qapi-visit-core.c +139 -0

145 lines not on this page · raw message

qapi/qapi-visit-core.h +16 -0
index e850746..a19d70c 100644
@@ -52,6 +52,14 @@ struct Visitor
     void (*start_handle)(Visitor *v, void **obj, const char *kind,
                          const char *name, Error **errp);
     void (*end_handle)(Visitor *v, Error **errp);
+    void (*type_uint8)(Visitor *v, uint8_t *obj, const char *name, Error **errp);
+    void (*type_uint16)(Visitor *v, uint16_t *obj, const char *name, Error **errp);
+    void (*type_uint32)(Visitor *v, uint32_t *obj, const char *name, Error **errp);
+    void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name, Error **errp);
+    void (*type_int8)(Visitor *v, int8_t *obj, const char *name, Error **errp);
+    void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp);
+    void (*type_int32)(Visitor *v, int32_t *obj, const char *name, Error **errp);
+    void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Error **errp);
 };
 
 void visit_start_handle(Visitor *v, void **obj, const char *kind,
@@ -69,6 +77,14 @@ void visit_end_optional(Visitor *v, Error **errp);
 void visit_type_enum(Visitor *v, int *obj, const char *strings[],
                      const char *kind, const char *name, Error **errp);
 void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp);
+void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp);
+void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp);
+void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp);
+void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp);
+void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp);
+void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp);
+void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp);
+void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp);
Signature · 1 line
1.7.9.3
#35 lore raw

PATCH 15/25 qdev: use int32_t container for devfn property

In reply to Paolo Bonzini

From: Michael Roth <[email protected]>

Valid range for devfn is -1 to 255 (-1 for automatic assignment). We do not currently validate this due to devfn being stored as a uint32_t. This can lead to segfaults and other strange behavior.

We could technically just cast it to int32_t to implement the checking, but this will not work for visitor-based setting where we may do additional bounds-checking based on target container type, which is int32_t for this case.

---
 hw/pci.c             |    2 +-
 hw/pci.h             |    2 +-
 hw/qdev-properties.c |   11 ++++-------
 hw/qdev.h            |    2 +-
 4 files changed, 7 insertions(+), 10 deletions(-)
hw/pci.c +1 -1
index 4e8e726..6910fac 100644
@@ -1539,7 +1539,7 @@ PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction,
     DeviceState *dev;
 
     dev = qdev_create(&bus->qbus, name);
-    qdev_prop_set_uint32(dev, "addr", devfn);
+    qdev_prop_set_int32(dev, "addr", devfn);
     qdev_prop_set_bit(dev, "multifunction", multifunction);
     return PCI_DEVICE(dev);
 }
hw/pci.h +1 -1
index 4f19fdb..3edf38a 100644
@@ -188,7 +188,7 @@ struct PCIDevice {
 
     /* the following fields are read only */
     PCIBus *bus;
-    uint32_t devfn;
+    int32_t devfn;
     char name[64];
     PCIIORegion io_regions[PCI_NUM_REGIONS];
 
hw/qdev-properties.c +4 -7
index 60fef9a..af7c00a 100644
@@ -822,7 +822,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+    int32_t *ptr = qdev_get_prop_ptr(dev, prop);
     unsigned int slot, fn, n;
     Error *local_err = NULL;
     char *str = (char *)"";
@@ -855,7 +855,7 @@ invalid:
 
 static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len)
 {
-    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+    int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (*ptr == -1) {
         return snprintf(dest, len, "<unset>");
@@ -870,11 +870,8 @@ PropertyInfo qdev_prop_pci_devfn = {
     .print = print_pci_devfn,
     .get   = get_int32,
     .set   = set_pci_devfn,
-    /* FIXME: this should be -1...255, but the address is stored
-     * into an uint32_t rather than int32_t.
-     */
-    .min   = 0,
-    .max   = 0xFFFFFFFFULL,
+    .min   = -1,
+    .max   = 255,
 };
 
 /* --- public helpers --- */
hw/qdev.h +1 -1
index aea53c8..fc18387 100644
@@ -264,7 +264,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
 #define DEFINE_PROP_HEX64(_n, _s, _f, _d)                       \
     DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d)                   \
-    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
+    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
 
 #define DEFINE_PROP_PTR(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
Signature · 1 line
1.7.9.3
#36 lore raw

PATCH 16/25 qdev: switch property accessors to fixed-width visitor interfaces

In reply to Paolo Bonzini

From: Michael Roth <[email protected]>

---
 hw/qdev-addr.c       |    4 +-
 hw/qdev-properties.c |  140 ++++++++++++++++++++++++++++++--------------------
 2 files changed, 87 insertions(+), 57 deletions(-)
hw/qdev-addr.c +2 -2
index 0bb16c7..b711b6b 100644
@@ -27,7 +27,7 @@ static void get_taddr(Object *obj, Visitor *v, void *opaque,
     int64_t value;
 
     value = *ptr;
-    visit_type_int(v, &value, name, errp);
+    visit_type_int64(v, &value, name, errp);
 }
 
 static void set_taddr(Object *obj, Visitor *v, void *opaque,
@@ -44,7 +44,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
         return;
     }
 
-    visit_type_int(v, &value, name, &local_err);
+    visit_type_int64(v, &value, name, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return;
hw/qdev-properties.c +85 -55

301 lines not on this page · raw message

Signature · 1 line
1.7.9.3
#37 lore raw

PATCH 17/25 qdev: remove PropertyInfo range checking

In reply to Paolo Bonzini

Range checking in PropertyInfo is now used only for pci_devfn properties. Move it there, and remove all code that implements it in the various property types.

---
 hw/qdev-properties.c |  102 ++++++++++++--------------------------------------
 hw/qdev.h            |    2 -
 2 files changed, 24 insertions(+), 80 deletions(-)
hw/qdev-properties.c +24 -78
index 85d8a11..ace81cf 100644
@@ -91,34 +91,20 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    uint8_t value, *ptr = qdev_get_prop_ptr(dev, prop);
-    Error *local_err = NULL;
+    uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
 
-    visit_type_uint8(v, &value, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    if (value >= prop->info->min && value <= prop->info->max) {
-        *ptr = value;
-    } else {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                  dev->id?:"", name, (int64_t)value, prop->info->min,
-                  prop->info->max);
-    }
+    visit_type_uint8(v, ptr, name, errp);
 }
 
 PropertyInfo qdev_prop_uint8 = {
     .name  = "uint8",
     .get   = get_uint8,
     .set   = set_uint8,
-    .min   = 0,
-    .max   = 255,
 };
 
 /* --- 8bit hex value --- */
@@ -153,8 +139,6 @@ PropertyInfo qdev_prop_hex8 = {
     .print = print_hex8,
     .get   = get_uint8,
     .set   = set_uint8,
-    .min   = 0,
-    .max   = 255,
 };
 
 /* --- 16bit integer --- */
@@ -174,34 +158,20 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    uint16_t value, *ptr = qdev_get_prop_ptr(dev, prop);
-    Error *local_err = NULL;
+    uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
 
-    visit_type_uint16(v, &value, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    if (value >= prop->info->min && value <= prop->info->max) {
-        *ptr = value;
-    } else {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                  dev->id?:"", name, (int64_t)value, prop->info->min,
-                  prop->info->max);
-    }
+    visit_type_uint16(v, ptr, name, errp);
 }
 
 PropertyInfo qdev_prop_uint16 = {
     .name  = "uint16",
     .get   = get_uint16,
     .set   = set_uint16,
-    .min   = 0,
-    .max   = 65535,
 };
 
 /* --- 32bit integer --- */
@@ -211,10 +181,9 @@ static void get_uint32(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    uint32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
+    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    value = *ptr;
-    visit_type_uint32(v, &value, name, errp);
+    visit_type_uint32(v, ptr, name, errp);
 }
 
 static void set_uint32(Object *obj, Visitor *v, void *opaque,
@@ -222,26 +191,14 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    uint32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
-    Error *local_err = NULL;
+    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
 
-    visit_type_uint32(v, &value, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    if (value >= prop->info->min && value <= prop->info->max) {
-        *ptr = value;
-    } else {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                  dev->id?:"", name, (int64_t)value, prop->info->min,
-                  prop->info->max);
-    }
+    visit_type_uint32(v, ptr, name, errp);
 }
 
 static void get_int32(Object *obj, Visitor *v, void *opaque,
@@ -249,10 +206,9 @@ static void get_int32(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
+    int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    value = *ptr;
-    visit_type_int32(v, &value, name, errp);
+    visit_type_int32(v, ptr, name, errp);
 }
 
 static void set_int32(Object *obj, Visitor *v, void *opaque,
@@ -260,42 +216,26 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
-    Error *local_err = NULL;
+    int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
 
-    visit_type_int32(v, &value, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    if (value >= prop->info->min && value <= prop->info->max) {
-        *ptr = value;
-    } else {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                  dev->id?:"", name, (int64_t)value, prop->info->min,
-                  prop->info->max);
-    }
+    visit_type_int32(v, ptr, name, errp);
 }
 
 PropertyInfo qdev_prop_uint32 = {
     .name  = "uint32",
     .get   = get_uint32,
     .set   = set_uint32,
-    .min   = 0,
-    .max   = 0xFFFFFFFFULL,
 };
 
 PropertyInfo qdev_prop_int32 = {
     .name  = "int32",
     .get   = get_int32,
     .set   = set_int32,
-    .min   = -0x80000000LL,
-    .max   = 0x7FFFFFFFLL,
 };
 
 /* --- 32bit hex value --- */
@@ -330,8 +270,6 @@ PropertyInfo qdev_prop_hex32 = {
     .print = print_hex32,
     .get   = get_uint32,
     .set   = set_uint32,
-    .min   = 0,
-    .max   = 0xFFFFFFFFULL,
 };
 
 /* --- 64bit integer --- */
@@ -852,7 +790,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
 {
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    int32_t *ptr = qdev_get_prop_ptr(dev, prop);
+    int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
     unsigned int slot, fn, n;
     Error *local_err = NULL;
     char *str = (char *)"";
@@ -864,7 +802,17 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
 
     visit_type_str(v, &str, name, &local_err);
     if (local_err) {
-        return set_int32(obj, v, opaque, name, errp);
+        local_err = NULL;
+        visit_type_int32(v, &value, name, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+        } else if (value < -1 || value > 255) {
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
+                      "pci_devfn");
+        } else {
+            *ptr = value;
+        }
+        return;
     }
 
     if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
@@ -900,8 +848,6 @@ PropertyInfo qdev_prop_pci_devfn = {
     .print = print_pci_devfn,
     .get   = get_int32,
     .set   = set_pci_devfn,
-    .min   = -1,
-    .max   = 255,
 };
 
 /* --- public helpers --- */
hw/qdev.h +0 -2
index fc18387..dfff93a 100644
@@ -120,8 +120,6 @@ struct PropertyInfo {
     const char *name;
     const char *legacy_name;
     const char **enum_table;
-    int64_t min;
-    int64_t max;
     int (*parse)(DeviceState *dev, Property *prop, const char *str);
     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
     ObjectPropertyAccessor *get;
Signature · 1 line
1.7.9.3
#38 lore raw

PATCH 18/25 qdev: remove qdev_prop_exists

In reply to Paolo Bonzini

Can be replaced everywhere with object_property_find.

---
 hw/qdev-properties.c  |    5 -----
 hw/qdev.c             |    2 +-
 hw/qdev.h             |    1 -
 hw/scsi-bus.c         |    2 +-
 include/qemu/object.h |    9 +++++++++
 qom/object.c          |    2 +-
 6 files changed, 12 insertions(+), 9 deletions(-)
hw/qdev-properties.c +0 -5
index ace81cf..ffd601a 100644
@@ -882,11 +882,6 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
     return NULL;
 }
 
-int qdev_prop_exists(DeviceState *dev, const char *name)
-{
-    return qdev_prop_find(dev, name) ? true : false;
-}
-
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value)
 {
hw/qdev.c +1 -1
index aeebb86..9e7a4b7 100644
@@ -295,7 +295,7 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
     if (nd->netdev)
         qdev_prop_set_netdev(dev, "netdev", nd->netdev);
     if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED &&
-        qdev_prop_exists(dev, "vectors")) {
+        object_property_find(OBJECT(dev), "vectors")) {
         qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
     }
     nd->instantiated = 1;
hw/qdev.h +0 -1
index dfff93a..a159b94 100644
@@ -287,7 +287,6 @@ extern PropertyInfo qdev_prop_pci_devfn;
 
 /* Set properties between creation and init.  */
 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
-int qdev_prop_exists(DeviceState *dev, const char *name);
 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
hw/scsi-bus.c +1 -1
index 10f9c63..2777566 100644
@@ -206,7 +206,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
     if (bootindex >= 0) {
         qdev_prop_set_int32(dev, "bootindex", bootindex);
     }
-    if (qdev_prop_exists(dev, "removable")) {
+    if (object_property_find(OBJECT(dev), "removable")) {
         qdev_prop_set_bit(dev, "removable", removable);
     }
     if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
include/qemu/object.h +9 -0
index 22f646d..80f2bf3 100644
@@ -637,6 +637,15 @@ void object_property_add(Object *obj, const char *name, const char *type,
 
 void object_property_del(Object *obj, const char *name, struct Error **errp);
 
+/**
+ * object_property_find:
+ * @obj: the object
+ * @name: the name of the property
+ *
+ * Look up a property for an object and return its #ObjectProperty if found.
+ */
+ObjectProperty *object_property_find(Object *obj, const char *name);
+
 void object_unparent(Object *obj);
 
 /**
qom/object.c +1 -1
index ff36946..488047c 100644
@@ -656,7 +656,7 @@ void object_property_add(Object *obj, const char *name, const char *type,
     QTAILQ_INSERT_TAIL(&obj->properties, prop, node);
 }
 
-static ObjectProperty *object_property_find(Object *obj, const char *name)
+ObjectProperty *object_property_find(Object *obj, const char *name)
 {
     ObjectProperty *prop;
 
Signature · 1 line
1.7.9.3
#39 lore raw

PATCH 19/25 qom: push state up to Object

In reply to Paolo Bonzini

qdev properties use the state member (an embryo of the "realized" property) in order to disable setting them after a device has been initialized. So, in order to push qdev properties up to Object we need to push this bit there too.

---
 hw/qdev-addr.c        |    3 ++-
 hw/qdev-properties.c  |   24 ++++++++++++------------
 hw/qdev.c             |   11 +++++------
 hw/qdev.h             |    6 ------
 include/qemu/object.h |   14 ++++++++++++++
 qom/object.c          |    6 ++++++
 6 files changed, 39 insertions(+), 25 deletions(-)
hw/qdev-addr.c +2 -1
index b711b6b..a3796bd 100644
@@ -1,3 +1,4 @@
+#include "qemu/object.h"
 #include "qdev.h"
 #include "qdev-addr.h"
 #include "targphys.h"
@@ -39,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
hw/qdev-properties.c +12 -12
index ffd601a..282cf68 100644
@@ -53,7 +53,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     bool value;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -93,7 +93,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -160,7 +160,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -193,7 +193,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -218,7 +218,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -291,7 +291,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -379,7 +379,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -457,7 +457,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
     char *str;
     int ret;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -626,7 +626,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     int64_t id;
     VLANState *vlan;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -696,7 +696,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
     int i, pos;
     char *str, *p;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -764,7 +764,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -795,7 +795,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str = (char *)"";
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
hw/qdev.c +5 -6
index 9e7a4b7..12752e9 100644
@@ -124,7 +124,7 @@ int qdev_init(DeviceState *dev)
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
     int rc;
 
-    assert(dev->state == DEV_STATE_CREATED);
+    assert(!object_is_realized(OBJECT(dev)));
 
     rc = dc->init(dev);
     if (rc < 0) {
@@ -146,7 +146,7 @@ int qdev_init(DeviceState *dev)
                                        dev->instance_id_alias,
                                        dev->alias_required_for_version);
     }
-    dev->state = DEV_STATE_INITIALIZED;
+    OBJECT(dev)->state = OBJECT_STATE_REALIZED;
     if (dev->hotplugged) {
         device_reset(dev);
     }
@@ -156,7 +156,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(!object_is_realized(OBJECT(dev)));
     dev->instance_id_alias = alias_id;
     dev->alias_required_for_version = required_for_version;
 }
@@ -515,7 +515,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 (object_is_realized(obj)) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -619,7 +619,6 @@ static void device_initfn(Object *obj)
     }
 
     dev->instance_id_alias = -1;
-    dev->state = DEV_STATE_CREATED;
 
     class = object_get_class(OBJECT(dev));
     do {
@@ -639,7 +638,7 @@ static void device_finalize(Object *obj)
     BusState *bus;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (dev->state == DEV_STATE_INITIALIZED) {
+    if (object_is_realized(obj)) {
         while (dev->num_child_bus) {
             bus = QLIST_FIRST(&dev->child_bus);
             qbus_free(bus);
hw/qdev.h +0 -6
index a159b94..a21633b 100644
@@ -18,11 +18,6 @@ typedef struct BusState BusState;
 
 typedef struct BusInfo BusInfo;
 
-enum DevState {
-    DEV_STATE_CREATED = 1,
-    DEV_STATE_INITIALIZED,
-};
-
 enum {
     DEV_NVECTORS_UNSPECIFIED = -1,
 };
@@ -63,7 +58,6 @@ struct DeviceState {
     Object parent_obj;
 
     const char *id;
-    enum DevState state;
     QemuOpts *opts;
     int hotplugged;
     BusState *parent_bus;
include/qemu/object.h +14 -0
index 80f2bf3..a7e5fc2 100644
@@ -241,6 +241,11 @@ struct ObjectClass
     Type type;
 };
 
+typedef enum ObjectState {
+    OBJECT_STATE_CREATED = 1,
+    OBJECT_STATE_REALIZED,
+} ObjectState;
+
 /**
  * Object:
  *
@@ -264,6 +269,7 @@ struct Object
     QTAILQ_HEAD(, ObjectProperty) properties;
     uint32_t ref;
     Object *parent;
+    ObjectState state;
 };
 
 /**
@@ -812,6 +818,14 @@ const char *object_property_get_type(Object *obj, const char *name,
 Object *object_get_root(void);
 
 /**
+ * object_is_realized:
+ * @obj: the object
+ *
+ * Returns whether @obj has been realized (i.e. completely constructed).
+ */
+bool object_is_realized(Object *obj);
+
+/**
  * object_get_canonical_path:
  *
  * Returns: The canonical path for a object.  This is the path within the
qom/object.c +6 -0
index 488047c..65eaa84 100644
@@ -1220,9 +1220,15 @@ static char *qdev_get_type(Object *obj, Error **errp)
     return g_strdup(object_get_typename(obj));
 }
 
+bool object_is_realized(Object *obj)
+{
+    return obj->state == OBJECT_STATE_REALIZED;
+}
+
 static void object_instance_init(Object *obj)
 {
     object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
+    obj->state = OBJECT_STATE_CREATED;
 }
 
 static void register_types(void)
Signature · 1 line
1.7.9.3
#40 lore raw

PATCH 20/25 qdev: generalize properties to Objects

In reply to Paolo Bonzini

The property machinery uses DeviceState arguments in a few places. Replace this with Object so that we can push properties up.

---
 hw/qdev-addr.c       |   19 +++---
 hw/qdev-properties.c |  173 +++++++++++++++++++++-----------------------------
 hw/qdev.c            |    8 +--
 hw/qdev.h            |   10 +--
 4 files changed, 90 insertions(+), 120 deletions(-)
hw/qdev-addr.c +8 -11
index a3796bd..99ca116 100644
@@ -5,26 +5,25 @@
 
 /* --- target physical address --- */
 
-static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
+static int parse_taddr(Object *obj, Property *prop, const char *str)
 {
-    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
+    target_phys_addr_t *ptr = object_get_prop_ptr(obj, prop);
 
     *ptr = strtoull(str, NULL, 16);
     return 0;
 }
 
-static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
+static int print_taddr(Object *obj, Property *prop, char *dest, size_t len)
 {
-    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
+    target_phys_addr_t *ptr = object_get_prop_ptr(obj, prop);
     return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
 }
 
 static void get_taddr(Object *obj, Visitor *v, void *opaque,
                       const char *name, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
+    target_phys_addr_t *ptr = object_get_prop_ptr(obj, prop);
     int64_t value;
 
     value = *ptr;
@@ -34,9 +33,8 @@ static void get_taddr(Object *obj, Visitor *v, void *opaque,
 static void set_taddr(Object *obj, Visitor *v, void *opaque,
                       const char *name, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
-    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
+    target_phys_addr_t *ptr = object_get_prop_ptr(obj, prop);
     Error *local_err = NULL;
     int64_t value;
 
@@ -53,9 +51,8 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     if ((uint64_t)value <= (uint64_t) ~(target_phys_addr_t)0) {
         *ptr = value;
     } else {
-        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                  dev->id?:"", name, value, (uint64_t) 0,
-                  (uint64_t) ~(target_phys_addr_t)0);
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+		  name, "target_phys_addr_t");
     }
 }
 
hw/qdev-properties.c +74 -99

523 lines not on this page · raw message

hw/qdev.c +3 -5
index 12752e9..86162fc 100644
@@ -496,20 +496,18 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
 static void qdev_get_legacy_property(Object *obj, Visitor *v, void *opaque,
                                      const char *name, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
 
     char buffer[1024];
     char *ptr = buffer;
 
-    prop->info->print(dev, prop, buffer, sizeof(buffer));
+    prop->info->print(obj, prop, buffer, sizeof(buffer));
     visit_type_str(v, &ptr, name, errp);
 }
 
 static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
                                      const char *name, Error **errp)
 {
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     Error *local_err = NULL;
     char *ptr = NULL;
@@ -526,8 +524,8 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
         return;
     }
 
-    ret = prop->info->parse(dev, prop, ptr);
-    error_set_from_qdev_prop_error(errp, ret, dev, prop, ptr);
+    ret = prop->info->parse(obj, prop, ptr);
+    error_set_from_prop_error(errp, ret, obj, prop, ptr);
     g_free(ptr);
 }
 
hw/qdev.h +5 -5
index a21633b..eb421af 100644
@@ -114,8 +114,8 @@ struct PropertyInfo {
     const char *name;
     const char *legacy_name;
     const char **enum_table;
-    int (*parse)(DeviceState *dev, Property *prop, const char *str);
-    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
+    int (*parse)(Object *obj, Property *prop, const char *str);
+    int (*print)(Object *obj, Property *prop, char *dest, size_t len);
     ObjectPropertyAccessor *get;
     ObjectPropertyAccessor *set;
     ObjectPropertyRelease *release;
@@ -280,7 +280,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
     {}
 
 /* Set properties between creation and init.  */
-void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
+void *object_get_prop_ptr(Object *obj, Property *prop);
 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
@@ -301,8 +301,8 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev);
-void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
-                                    Property *prop, const char *value);
+void error_set_from_prop_error(Error **errp, int ret, Object *obj,
+                               Property *prop, const char *value);
 
 char *qdev_get_fw_dev_path(DeviceState *dev);
 
Signature · 1 line
1.7.9.3
#41 lore raw

PATCH 21/25 qdev: move bulk of qdev-properties.c to qom/object.c

In reply to Paolo Bonzini
---
 hw/qdev-properties.c  |  476 ++++---------------------------------------------
 hw/qdev.c             |   47 +----
 hw/qdev.h             |   87 ---------
 include/qemu/object.h |   98 ++++++++++
 qom/object.c          |  459 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 594 insertions(+), 573 deletions(-)
hw/qdev-properties.c +36 -440
index 59b9615..bea57e9 100644
@@ -3,392 +3,27 @@
 #include "qerror.h"
 #include "blockdev.h"
 
-void *object_get_prop_ptr(Object *obj, Property *prop)
-{
-    void *ptr = obj;
-    ptr += prop->offset;
-    return ptr;
-}
-
-static uint32_t get_prop_mask(Property *prop)
-{
-    assert(prop->info == &qdev_prop_bit);
-    return 0x1 << prop->bitnr;
-}
-
-static void bit_prop_set(Object *obj, Property *props, bool val)
-{
-    uint32_t *p = object_get_prop_ptr(obj, props);
-    uint32_t mask = get_prop_mask(props);
-    if (val)
-        *p |= mask;
-    else
-        *p &= ~mask;
-}
-
-/* Bit */
-
-static int print_bit(Object *obj, Property *prop, char *dest, size_t len)
-{
-    uint32_t *p = object_get_prop_ptr(obj, prop);
-    return snprintf(dest, len, (*p & get_prop_mask(prop)) ? "on" : "off");
-}
-
-static void get_bit(Object *obj, Visitor *v, void *opaque,
-                    const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint32_t *p = object_get_prop_ptr(obj, prop);
-    bool value = (*p & get_prop_mask(prop)) != 0;
-
-    visit_type_bool(v, &value, name, errp);
-}
-
-static void set_bit(Object *obj, Visitor *v, void *opaque,
-                    const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    Error *local_err = NULL;
-    bool value;
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_bool(v, &value, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    bit_prop_set(obj, prop, value);
-}
-
-PropertyInfo qdev_prop_bit = {
-    .name  = "boolean",
-    .legacy_name  = "on/off",
-    .print = print_bit,
-    .get   = get_bit,
-    .set   = set_bit,
-};
-
-/* --- 8bit integer --- */
-
-static void get_uint8(Object *obj, Visitor *v, void *opaque,
-                      const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint8_t *ptr = object_get_prop_ptr(obj, prop);
-
-    visit_type_uint8(v, ptr, name, errp);
-}
-
-static void set_uint8(Object *obj, Visitor *v, void *opaque,
-                      const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint8_t *ptr = object_get_prop_ptr(obj, prop);
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_uint8(v, ptr, name, errp);
-}
-
-PropertyInfo qdev_prop_uint8 = {
-    .name  = "uint8",
-    .get   = get_uint8,
-    .set   = set_uint8,
-};
-
-/* --- 8bit hex value --- */
-
-static int parse_hex8(Object *obj, Property *prop, const char *str)
-{
-    uint8_t *ptr = object_get_prop_ptr(obj, prop);
-    char *end;
-
-    if (str[0] != '0' || str[1] != 'x') {
-        return -EINVAL;
-    }
-
-    *ptr = strtoul(str, &end, 16);
-    if ((*end != '\0') || (end == str)) {
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static int print_hex8(Object *obj, Property *prop, char *dest, size_t len)
-{
-    uint8_t *ptr = object_get_prop_ptr(obj, prop);
-    return snprintf(dest, len, "0x%" PRIx8, *ptr);
-}
-
-PropertyInfo qdev_prop_hex8 = {
-    .name  = "uint8",
-    .legacy_name  = "hex8",
-    .parse = parse_hex8,
-    .print = print_hex8,
-    .get   = get_uint8,
-    .set   = set_uint8,
-};
-
-/* --- 16bit integer --- */
-
-static void get_uint16(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint16_t *ptr = object_get_prop_ptr(obj, prop);
-
-    visit_type_uint16(v, ptr, name, errp);
-}
-
-static void set_uint16(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint16_t *ptr = object_get_prop_ptr(obj, prop);
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_uint16(v, ptr, name, errp);
-}
-
-PropertyInfo qdev_prop_uint16 = {
-    .name  = "uint16",
-    .get   = get_uint16,
-    .set   = set_uint16,
-};
-
-/* --- 32bit integer --- */
-
-static void get_uint32(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint32_t *ptr = object_get_prop_ptr(obj, prop);
-
-    visit_type_uint32(v, ptr, name, errp);
-}
-
-static void set_uint32(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint32_t *ptr = object_get_prop_ptr(obj, prop);
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_uint32(v, ptr, name, errp);
-}
-
-static void get_int32(Object *obj, Visitor *v, void *opaque,
-                      const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    int32_t *ptr = object_get_prop_ptr(obj, prop);
-
-    visit_type_int32(v, ptr, name, errp);
-}
-
-static void set_int32(Object *obj, Visitor *v, void *opaque,
-                      const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    int32_t *ptr = object_get_prop_ptr(obj, prop);
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_int32(v, ptr, name, errp);
-}
-
-PropertyInfo qdev_prop_uint32 = {
-    .name  = "uint32",
-    .get   = get_uint32,
-    .set   = set_uint32,
-};
-
-PropertyInfo qdev_prop_int32 = {
-    .name  = "int32",
-    .get   = get_int32,
-    .set   = set_int32,
-};
-
-/* --- 32bit hex value --- */
-
-static int parse_hex32(Object *obj, Property *prop, const char *str)
-{
-    uint32_t *ptr = object_get_prop_ptr(obj, prop);
-    char *end;
-
-    if (str[0] != '0' || str[1] != 'x') {
-        return -EINVAL;
-    }
-
-    *ptr = strtoul(str, &end, 16);
-    if ((*end != '\0') || (end == str)) {
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static int print_hex32(Object *obj, Property *prop, char *dest, size_t len)
-{
-    uint32_t *ptr = object_get_prop_ptr(obj, prop);
-    return snprintf(dest, len, "0x%" PRIx32, *ptr);
-}
-
-PropertyInfo qdev_prop_hex32 = {
-    .name  = "uint32",
-    .legacy_name  = "hex32",
-    .parse = parse_hex32,
-    .print = print_hex32,
-    .get   = get_uint32,
-    .set   = set_uint32,
-};
-
-/* --- 64bit integer --- */
-
-static void get_uint64(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint64_t *ptr = object_get_prop_ptr(obj, prop);
-
-    visit_type_uint64(v, ptr, name, errp);
-}
-
-static void set_uint64(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    uint64_t *ptr = object_get_prop_ptr(obj, prop);
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_uint64(v, ptr, name, errp);
-}
-
-PropertyInfo qdev_prop_uint64 = {
-    .name  = "uint64",
-    .get   = get_uint64,
-    .set   = set_uint64,
-};
-
-/* --- 64bit hex value --- */
-
-static int parse_hex64(Object *obj, Property *prop, const char *str)
-{
-    uint64_t *ptr = object_get_prop_ptr(obj, prop);
-    char *end;
-
-    if (str[0] != '0' || str[1] != 'x') {
-        return -EINVAL;
-    }
-
-    *ptr = strtoull(str, &end, 16);
-    if ((*end != '\0') || (end == str)) {
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
-static int print_hex64(Object *obj, Property *prop, char *dest, size_t len)
-{
-    uint64_t *ptr = object_get_prop_ptr(obj, prop);
-    return snprintf(dest, len, "0x%" PRIx64, *ptr);
-}
-
-PropertyInfo qdev_prop_hex64 = {
-    .name  = "uint64",
-    .legacy_name  = "hex64",
-    .parse = parse_hex64,
-    .print = print_hex64,
-    .get   = get_uint64,
-    .set   = set_uint64,
-};
-
-/* --- string --- */
-
-static void release_string(Object *obj, const char *name, void *opaque)
-{
-    Property *prop = opaque;
-    g_free(*(char **)object_get_prop_ptr(obj, prop));
-}
-
-static int print_string(Object *obj, Property *prop, char *dest, size_t len)
-{
-    char **ptr = object_get_prop_ptr(obj, prop);
-    if (!*ptr)
-        return snprintf(dest, len, "<null>");
-    return snprintf(dest, len, "\"%s\"", *ptr);
-}
-
-static void get_string(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    char **ptr = object_get_prop_ptr(obj, prop);
-
-    if (!*ptr) {
-        char *str = (char *)"";
-        visit_type_str(v, &str, name, errp);
-    } else {
-        visit_type_str(v, ptr, name, errp);
-    }
-}
-
-static void set_string(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
+void error_set_from_prop_error(Error **errp, int ret, Object *obj,
+                               Property *prop, const char *value)
 {
-    Property *prop = opaque;
-    char **ptr = object_get_prop_ptr(obj, prop);
-    Error *local_err = NULL;
-    char *str;
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_str(v, &str, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    if (*ptr) {
-        g_free(*ptr);
+    switch (ret) {
+    case -EEXIST:
+        error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
+                  object_get_typename(obj), prop->name, value);
+        break;
+    default:
+    case -EINVAL:
+        error_set(errp, QERR_PROPERTY_VALUE_BAD,
+                  object_get_typename(obj), prop->name, value);
+        break;
+    case -ENOENT:
+        error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
+                  object_get_typename(obj), prop->name, value);
+        break;
+    case 0:
+        break;
     }
-    *ptr = str;
 }
-
-PropertyInfo qdev_prop_string = {
-    .name  = "string",
-    .print = print_string,
-    .release = release_string,
-    .get   = get_string,
-    .set   = set_string,
-};
-
 /* --- drive --- */
 
 static int parse_drive(Object *obj, const char *str, void **ptr)
@@ -636,13 +271,6 @@ PropertyInfo qdev_prop_vlan = {
     .set   = set_vlan,
 };
 
-/* --- pointer --- */
-
-/* Not a proper property, just for dirty hacks.  TODO Remove it!  */
-PropertyInfo qdev_prop_ptr = {
-    .name  = "ptr",
-};
-
 /* --- mac address --- */
 
 /*
@@ -711,6 +339,12 @@ PropertyInfo qdev_prop_macaddr = {
     .set   = set_mac,
 };
 
+/* --- pointer --- */
+
+/* Not a proper property, just for dirty hacks.  TODO Remove it!  */
+PropertyInfo qdev_prop_ptr = {
+    .name  = "ptr",
+};
 
 /* --- lost tick policy --- */
 
@@ -724,40 +358,24 @@ static const char *lost_tick_policy_table[LOST_TICK_MAX+1] = {
 
 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
 
-static void get_enum(Object *obj, Visitor *v, void *opaque,
-                     const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    int *ptr = object_get_prop_ptr(obj, prop);
-
-    visit_type_enum(v, ptr, prop->info->enum_table,
-                    prop->info->name, prop->name, errp);
-}
-
-static void set_enum(Object *obj, Visitor *v, void *opaque,
-                     const char *name, Error **errp)
-{
-    Property *prop = opaque;
-    int *ptr = object_get_prop_ptr(obj, prop);
-
-    if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_enum(v, ptr, prop->info->enum_table,
-                    prop->info->name, prop->name, errp);
-}
-
 PropertyInfo qdev_prop_losttickpolicy = {
     .name  = "LostTickPolicy",
     .enum_table  = lost_tick_policy_table,
-    .get   = get_enum,
-    .set   = set_enum,
+    .get   = property_get_enum,
+    .set   = property_set_enum,
 };
 
 /* --- pci address --- */
 
+static void get_pci_devfn(Object *obj, Visitor *v, void *opaque,
+                          const char *name, Error **errp)
+{
+    Property *prop = opaque;
+    int32_t *ptr = object_get_prop_ptr(obj, prop);
+
+    visit_type_int32(v, ptr, name, errp);
+}
+
 /*
  * bus-local address, i.e. "$slot" or "$slot.$fn"
  */
@@ -821,7 +439,7 @@ PropertyInfo qdev_prop_pci_devfn = {
     .name  = "int32",
     .legacy_name  = "pci-devfn",
     .print = print_pci_devfn,
-    .get   = get_int32,
+    .get   = get_pci_devfn,
     .set   = set_pci_devfn,
 };
 
@@ -857,28 +475,6 @@ static Property *qdev_prop_find(Object *obj, const char *name)
     return NULL;
 }
 
-void error_set_from_prop_error(Error **errp, int ret, Object *obj,
-                               Property *prop, const char *value)
-{
-    switch (ret) {
-    case -EEXIST:
-        error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
-                  object_get_typename(obj), prop->name, value);
-        break;
-    default:
-    case -EINVAL:
-        error_set(errp, QERR_PROPERTY_VALUE_BAD,
-                  object_get_typename(obj), prop->name, value);
-        break;
-    case -ENOENT:
-        error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
-                  object_get_typename(obj), prop->name, value);
-        break;
-    case 0:
-        break;
-    }
-}
-
 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
 {
     char *legacy_name;
hw/qdev.c +1 -46

59 lines not on this page · raw message

hw/qdev.h +0 -87

130 lines not on this page · raw message

include/qemu/object.h +98 -0

102 lines not on this page · raw message

qom/object.c +1 -0
index 65eaa84..28186d7 100644
@@ -1251,3 +1251,462 @@ static void register_types(void)
 }
 
 type_init(register_types)
+

+void *object_get_prop_ptr(Object *obj, Property *prop) +{

+    void *ptr = obj;
+    ptr += prop->offset;
+    return ptr;

+}
+
+static uint32_t get_prop_mask(Property *prop)
+{
+ assert(prop->info == &qdev_prop_bit);
+ return 0x1 << prop->bitnr;
+}
+
+static void bit_prop_set(Object *obj, Property *props, bool val) +{

+    uint32_t *p = object_get_prop_ptr(obj, props);
+    uint32_t mask = get_prop_mask(props);
+    if (val)

+ *p |= mask;
+ else
+ *p &= ~mask;
+}
+
+/* Bit */
+
+static int print_bit(Object *obj, Property *prop, char *dest, size_t len) +{
+ uint32_t *p = object_get_prop_ptr(obj, prop);
+ return snprintf(dest, len, (*p & get_prop_mask(prop)) ? "on" : "off");
+}
+
+static void get_bit(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{

+    Property *prop = opaque;
+    uint32_t *p = object_get_prop_ptr(obj, prop);
+    bool value = (*p & get_prop_mask(prop)) != 0;

+
+ visit_type_bool(v, &value, name, errp);
+}
+
+static void set_bit(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{

+    Property *prop = opaque;
+    Error *local_err = NULL;
+    bool value;

+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_bool(v, &value, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ bit_prop_set(obj, prop, value);
+}
+
+PropertyInfo qdev_prop_bit = {

+    .name  = "boolean",
+    .legacy_name  = "on/off",
+    .print = print_bit,
+    .get   = get_bit,
+    .set   = set_bit,

+};
+
+/* --- 8bit integer --- */
+
+static void get_uint8(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint8_t *ptr = object_get_prop_ptr(obj, prop);
+
+ visit_type_uint8(v, ptr, name, errp);
+}
+
+static void set_uint8(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint8_t *ptr = object_get_prop_ptr(obj, prop);
+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_uint8(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_uint8 = {

+    .name  = "uint8",
+    .get   = get_uint8,
+    .set   = set_uint8,

+};
+
+/* --- 8bit hex value --- */
+
+static int parse_hex8(Object *obj, Property *prop, const char *str) +{
+ uint8_t *ptr = object_get_prop_ptr(obj, prop);
+ char *end;
+
+ if (str[0] != '0' || str[1] != 'x') {
+ return -EINVAL;
+ }
+
+ *ptr = strtoul(str, &end, 16);
+ if ((*end != '\0') || (end == str)) {
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int print_hex8(Object *obj, Property *prop, char *dest, size_t len) +{
+ uint8_t *ptr = object_get_prop_ptr(obj, prop);
+ return snprintf(dest, len, "0x%" PRIx8, *ptr);
+}
+
+PropertyInfo qdev_prop_hex8 = {

+    .name  = "uint8",
+    .legacy_name  = "hex8",
+    .parse = parse_hex8,
+    .print = print_hex8,
+    .get   = get_uint8,
+    .set   = set_uint8,

+};
+
+/* --- 16bit integer --- */
+
+static void get_uint16(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint16_t *ptr = object_get_prop_ptr(obj, prop);
+
+ visit_type_uint16(v, ptr, name, errp);
+}
+
+static void set_uint16(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint16_t *ptr = object_get_prop_ptr(obj, prop);
+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_uint16(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_uint16 = {

+    .name  = "uint16",
+    .get   = get_uint16,
+    .set   = set_uint16,

+};
+
+/* --- 32bit integer --- */
+
+static void get_uint32(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint32_t *ptr = object_get_prop_ptr(obj, prop);
+
+ visit_type_uint32(v, ptr, name, errp);
+}
+
+static void set_uint32(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint32_t *ptr = object_get_prop_ptr(obj, prop);
+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_uint32(v, ptr, name, errp);
+}
+
+static void get_int32(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ int32_t *ptr = object_get_prop_ptr(obj, prop);
+
+ visit_type_int32(v, ptr, name, errp);
+}
+
+static void set_int32(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ int32_t *ptr = object_get_prop_ptr(obj, prop);
+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_int32(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_uint32 = {

+    .name  = "uint32",
+    .get   = get_uint32,
+    .set   = set_uint32,
+};
+
+PropertyInfo qdev_prop_int32 = {
+    .name  = "int32",
+    .get   = get_int32,
+    .set   = set_int32,

+};
+
+/* --- 32bit hex value --- */
+
+static int parse_hex32(Object *obj, Property *prop, const char *str) +{
+ uint32_t *ptr = object_get_prop_ptr(obj, prop);
+ char *end;
+
+ if (str[0] != '0' || str[1] != 'x') {
+ return -EINVAL;
+ }
+
+ *ptr = strtoul(str, &end, 16);
+ if ((*end != '\0') || (end == str)) {
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int print_hex32(Object *obj, Property *prop, char *dest, size_t len) +{
+ uint32_t *ptr = object_get_prop_ptr(obj, prop);
+ return snprintf(dest, len, "0x%" PRIx32, *ptr);
+}
+
+PropertyInfo qdev_prop_hex32 = {

+    .name  = "uint32",
+    .legacy_name  = "hex32",
+    .parse = parse_hex32,
+    .print = print_hex32,
+    .get   = get_uint32,
+    .set   = set_uint32,

+};
+
+/* --- 64bit integer --- */
+
+static void get_uint64(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint64_t *ptr = object_get_prop_ptr(obj, prop);
+
+ visit_type_uint64(v, ptr, name, errp);
+}
+
+static void set_uint64(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ uint64_t *ptr = object_get_prop_ptr(obj, prop);
+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_uint64(v, ptr, name, errp);
+}
+
+PropertyInfo qdev_prop_uint64 = {

+    .name  = "uint64",
+    .get   = get_uint64,
+    .set   = set_uint64,

+};
+
+/* --- 64bit hex value --- */
+
+static int parse_hex64(Object *obj, Property *prop, const char *str) +{
+ uint64_t *ptr = object_get_prop_ptr(obj, prop);
+ char *end;
+
+ if (str[0] != '0' || str[1] != 'x') {
+ return -EINVAL;
+ }
+
+ *ptr = strtoull(str, &end, 16);
+ if ((*end != '\0') || (end == str)) {
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int print_hex64(Object *obj, Property *prop, char *dest, size_t len) +{
+ uint64_t *ptr = object_get_prop_ptr(obj, prop);
+ return snprintf(dest, len, "0x%" PRIx64, *ptr);
+}
+
+PropertyInfo qdev_prop_hex64 = {

+    .name  = "uint64",
+    .legacy_name  = "hex64",
+    .parse = parse_hex64,
+    .print = print_hex64,
+    .get   = get_uint64,
+    .set   = set_uint64,

+};
+
+/* --- string --- */
+
+static void release_string(Object *obj, const char *name, void *opaque) +{
+ Property *prop = opaque;
+ g_free(*(char **)object_get_prop_ptr(obj, prop));
+}
+
+static int print_string(Object *obj, Property *prop, char *dest, size_t len) +{
+ char **ptr = object_get_prop_ptr(obj, prop);
+ if (!*ptr)
+ return snprintf(dest, len, "<null>");
+ return snprintf(dest, len, "\"%s\"", *ptr);
+}
+
+static void get_string(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ char **ptr = object_get_prop_ptr(obj, prop);
+
+ if (!*ptr) {
+ char *str = (char *)"";
+ visit_type_str(v, &str, name, errp);
+ } else {
+ visit_type_str(v, ptr, name, errp);
+ }
+}
+
+static void set_string(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{

+    Property *prop = opaque;
+    char **ptr = object_get_prop_ptr(obj, prop);
+    Error *local_err = NULL;
+    char *str;

+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_str(v, &str, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ if (*ptr) {
+ g_free(*ptr);
+ }
+ *ptr = str;
+}
+
+PropertyInfo qdev_prop_string = {

+    .name  = "string",
+    .print = print_string,
+    .release = release_string,
+    .get   = get_string,
+    .set   = set_string,

+};
+
+
+/* --- enums --- */
+
+void property_get_enum(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ int *ptr = object_get_prop_ptr(obj, prop);
+
+ visit_type_enum(v, ptr, prop->info->enum_table,
+ prop->info->name, prop->name, errp);
+}
+
+void property_set_enum(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ int *ptr = object_get_prop_ptr(obj, prop);
+
+ if (object_is_realized(obj)) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_enum(v, ptr, prop->info->enum_table,
+ prop->info->name, prop->name, errp);
+}
+
+
+/**
+ * @object_property_add_static - add a @Property to a device.
+ *
+ * Static properties access data in a struct. The actual type of the
+ * property and the field depends on the property type.
+ */
+void object_property_add_static(Object *obj, Property *prop,
+ Error **errp)
+{
+ Error *local_err = NULL;
+
+ /*

+     * TODO qdev_prop_ptr does not have getters or setters.  It must
+     * go now that it can be replaced with links.  The test should be
+     * removed along with it: all static properties are read/write.
+     */

+ if (!prop->info->get && !prop->info->set) {
+ return;
+ }
+
+ object_property_add(obj, prop->name, prop->info->name,

+                        prop->info->get, prop->info->set,
+                        prop->info->release,
+                        prop, &local_err);

+
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ if (prop->qtype == QTYPE_NONE) {
+ return;
+ }
+
+ if (prop->qtype == QTYPE_QBOOL) {
+ object_property_set_bool(obj, prop->defval, prop->name, &local_err);
+ } else if (prop->info->enum_table) {
+ object_property_set_str(obj, prop->info->enum_table[prop->defval],
+ prop->name, &local_err);
+ } else if (prop->qtype == QTYPE_QINT) {
+ object_property_set_int(obj, prop->defval, prop->name, &local_err);
+ }
+ assert_no_error(local_err);
+}

Signature · 1 line
1.7.9.3
#42 lore raw

PATCH 22/25 qom: push static properties to Object

In reply to Paolo Bonzini

This patch is made much larger by the need to touch all assignments of props. The interesting changes are in hw/qdev-monitor.c, hw/qdev-properties.c, hw/qdev.c, hw/qdev.h, include/qemu/object.h, qom/object.c.

---
 hw/9pfs/virtio-9p-device.c    |    2 +-
 hw/a15mpcore.c                |    3 +--
 hw/a9mpcore.c                 |    2 +-
 hw/ac97.c                     |    2 +-
 hw/acpi_piix4.c               |    2 +-
 hw/apic_common.c              |    2 +-
 hw/applesmc.c                 |    2 +-
 hw/arm11mpcore.c              |    6 ++----
 hw/arm_l2x0.c                 |    2 +-
 hw/arm_mptimer.c              |    2 +-
 hw/arm_sysctl.c               |    2 +-
 hw/arm_timer.c                |    3 +--
 hw/armv7m.c                   |    3 +--
 hw/armv7m_nvic.c              |    2 +-
 hw/cadence_gem.c              |    2 +-
 hw/ccid-card-emulated.c       |    2 +-
 hw/ccid-card-passthru.c       |    2 +-
 hw/cs4231.c                   |    2 +-
 hw/cs4231a.c                  |    2 +-
 hw/debugcon.c                 |    3 +--
 hw/ds1225y.c                  |    2 +-
 hw/e1000.c                    |    2 +-
 hw/eccmemctl.c                |    2 +-
 hw/eepro100.c                 |    2 +-
 hw/escc.c                     |    2 +-
 hw/esp.c                      |    2 +-
 hw/etraxfs_eth.c              |    3 +--
 hw/etraxfs_pic.c              |    3 +--
 hw/exynos4210_combiner.c      |    2 +-
 hw/exynos4210_gic.c           |    3 +--
 hw/exynos4210_uart.c          |    2 +-
 hw/fdc.c                      |    6 +++---
 hw/fw_cfg.c                   |    2 +-
 hw/g364fb.c                   |    2 +-
 hw/grlib_apbuart.c            |    3 +--
 hw/grlib_gptimer.c            |    2 +-
 hw/grlib_irqmp.c              |    2 +-
 hw/gus.c                      |    2 +-
 hw/hda-audio.c                |    4 ++--
 hw/hpet.c                     |    2 +-
 hw/i2c.c                      |    2 +-
 hw/i82374.c                   |    2 +-
 hw/i82378.c                   |    2 +-
 hw/i8254.c                    |    2 +-
 hw/i8259_common.c             |    2 +-
 hw/ide/ahci.c                 |    2 +-
 hw/ide/cmd646.c               |    3 +--
 hw/ide/isa.c                  |    2 +-
 hw/ide/qdev.c                 |    8 ++++----
 hw/integratorcp.c             |    3 +--
 hw/intel-hda.c                |    4 ++--
 hw/ioh3420.c                  |    2 +-
 hw/ivshmem.c                  |    2 +-
 hw/kvm/i8254.c                |    2 +-
 hw/kvm/ioapic.c               |    2 +-
 hw/lan9118.c                  |    2 +-
 hw/lance.c                    |    2 +-
 hw/lm32_sys.c                 |    2 +-
 hw/lm32_timer.c               |    2 +-
 hw/m48t59.c                   |    4 ++--
 hw/marvell_88w8618_audio.c    |    2 +-
 hw/mc146818rtc.c              |    2 +-
 hw/milkymist-minimac2.c       |    2 +-
 hw/milkymist-softusb.c        |    2 +-
 hw/milkymist-sysctl.c         |    2 +-
 hw/milkymist-vgafb.c          |    2 +-
 hw/mipsnet.c                  |    2 +-
 hw/musicpal.c                 |    2 +-
 hw/nand.c                     |    2 +-
 hw/ne2000-isa.c               |    3 +--
 hw/ne2000.c                   |    2 +-
 hw/omap_gpio.c                |    4 ++--
 hw/omap_i2c.c                 |    2 +-
 hw/omap_intc.c                |    4 ++--
 hw/onenand.c                  |    2 +-
 hw/opencores_eth.c            |    2 +-
 hw/parallel.c                 |    3 +--
 hw/pc_sysfw.c                 |    2 +-
 hw/pci.c                      |    2 +-
 hw/pcnet-pci.c                |    2 +-
 hw/pcspk.c                    |    2 +-
 hw/pl041.c                    |    2 +-
 hw/pxa2xx.c                   |    2 +-
 hw/pxa2xx_dma.c               |    2 +-
 hw/pxa2xx_gpio.c              |    2 +-
 hw/pxa2xx_timer.c             |    4 ++--
 hw/qdev-monitor.c             |    4 ++--
 hw/qdev-properties.c          |    2 +-
 hw/qdev.c                     |   14 +-------------
 hw/qdev.h                     |    1 -
 hw/qxl.c                      |    4 ++--
 hw/rtl8139.c                  |    2 +-
 hw/s390-virtio-bus.c          |   12 ++++--------
 hw/sb16.c                     |    2 +-
 hw/scsi-bus.c                 |    2 +-
 hw/scsi-disk.c                |    8 ++++----
 hw/scsi-generic.c             |    2 +-
 hw/serial.c                   |    2 +-
 hw/slavio_timer.c             |    2 +-
 hw/smbus_eeprom.c             |    3 +--
 hw/smc91c111.c                |    2 +-
 hw/spapr_llan.c               |    3 +--
 hw/spapr_pci.c                |    3 +--
 hw/spapr_vio.c                |    2 +-
 hw/spapr_vscsi.c              |    3 +--
 hw/spapr_vty.c                |    3 +--
 hw/sparc32_dma.c              |    2 +-
 hw/spitz.c                    |    4 ++--
 hw/stellaris_enet.c           |    3 +--
 hw/strongarm.c                |    2 +-
 hw/sun4m.c                    |    6 ++----
 hw/sun4m_iommu.c              |    2 +-
 hw/sun4u.c                    |    6 ++----
 hw/tcx.c                      |    2 +-
 hw/usb/bus.c                  |    2 +-
 hw/usb/dev-audio.c            |    2 +-
 hw/usb/dev-network.c          |    2 +-
 hw/usb/dev-serial.c           |    4 ++--
 hw/usb/dev-smartcard-reader.c |    4 ++--
 hw/usb/dev-storage.c          |    2 +-
 hw/usb/hcd-ehci.c             |    4 ++--
 hw/usb/hcd-ohci.c             |    4 ++--
 hw/usb/hcd-uhci.c             |   12 ++++++------
 hw/usb/hcd-xhci.c             |    2 +-
 hw/usb/host-linux.c           |    2 +-
 hw/usb/redirect.c             |    2 +-
 hw/virtio-console.c           |    6 ++----
 hw/virtio-pci.c               |   10 +++++-----
 hw/virtio-serial-bus.c        |    2 +-
 hw/vmmouse.c                  |    2 +-
 hw/vt82c686.c                 |    2 +-
 hw/xgmac.c                    |    2 +-
 hw/xilinx_axidma.c            |    3 +--
 hw/xilinx_axienet.c           |    3 +--
 hw/xilinx_ethlite.c           |    3 +--
 hw/xilinx_intc.c              |    3 +--
 hw/xilinx_timer.c             |    3 +--
 hw/xio3130_downstream.c       |    2 +-
 hw/xio3130_upstream.c         |    2 +-
 hw/zaurus.c                   |    2 +-
 include/qemu/object.h         |    9 ++++++---
 qom/object.c                  |   20 ++++++++++++++++++++
 142 files changed, 202 insertions(+), 227 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -1
index b8220ab..83e1495 100644
@@ -173,7 +173,7 @@ static void virtio_9p_class_init(ObjectClass *klass, void *data)
     k->device_id = 0x1009;
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = 0x2;
-    dc->props = virtio_9p_properties;
+    klass->props = virtio_9p_properties;
     dc->reset = virtio_pci_reset;
 }
 
hw/a15mpcore.c +1 -2
index 71142e5..ed5b663 100644
@@ -81,10 +81,9 @@ static Property a15mp_priv_properties[] = {
 
 static void a15mp_priv_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
     k->init = a15mp_priv_init;
-    dc->props = a15mp_priv_properties;
+    klass->props = a15mp_priv_properties;
     /* We currently have no savable state outside the common GIC state */
 }
 
hw/a9mpcore.c +1 -1
index 03b128c..45eaa74 100644
@@ -226,7 +226,7 @@ static void a9mp_priv_class_init(ObjectClass *klass, void *data)
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = a9mp_priv_init;
-    dc->props = a9mp_priv_properties;
+    klass->props = a9mp_priv_properties;
     dc->vmsd = &vmstate_a9mp_priv;
     dc->reset = a9mp_priv_reset;
 }
hw/ac97.c +1 -1
index c0fd019..d994924 100644
@@ -1362,7 +1362,7 @@ static void ac97_class_init (ObjectClass *klass, void *data)
     k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
     dc->desc = "Intel 82801AA AC97 Audio";
     dc->vmsd = &vmstate_ac97;
-    dc->props = ac97_properties;
+    klass->props = ac97_properties;
 }
 
 static TypeInfo ac97_info = {
hw/acpi_piix4.c +1 -1
index 797ed24..74fa6b0 100644
@@ -412,7 +412,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
     dc->desc = "PM";
     dc->no_user = 1;
     dc->vmsd = &vmstate_acpi;
-    dc->props = piix4_pm_properties;
+    klass->props = piix4_pm_properties;
 }
 
 static TypeInfo piix4_pm_info = {
hw/apic_common.c +1 -1
index 60b8259..9774cf6 100644
@@ -370,7 +370,7 @@ static void apic_common_class_init(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_apic_common;
     dc->reset = apic_reset_common;
     dc->no_user = 1;
-    dc->props = apic_properties_common;
+    klass->props = apic_properties_common;
     sc->init = apic_init_common;
 }
 
hw/applesmc.c +1 -1
index 8bedaad..b8f1855 100644
@@ -233,7 +233,7 @@ static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
     ic->init = applesmc_isa_init;
     dc->reset = qdev_applesmc_isa_reset;
-    dc->props = applesmc_isa_properties;
+    klass->props = applesmc_isa_properties;
 }
 
 static TypeInfo applesmc_isa_info = {
hw/arm11mpcore.c +2 -4
index ba6a89d..ad68817 100644
@@ -206,11 +206,10 @@ static Property mpcore_rirq_properties[] = {
 
 static void mpcore_rirq_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = realview_mpcore_init;
-    dc->props = mpcore_rirq_properties;
+    klass->props = mpcore_rirq_properties;
 }
 
 static TypeInfo mpcore_rirq_info = {
@@ -236,11 +235,10 @@ static Property mpcore_priv_properties[] = {
 
 static void mpcore_priv_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = mpcore_priv_init;
-    dc->props = mpcore_priv_properties;
+    klass->props = mpcore_priv_properties;
 }
 
 static TypeInfo mpcore_priv_info = {
hw/arm_l2x0.c +1 -1
index 09f290c..1e5fed9 100644
@@ -173,7 +173,7 @@ static void l2x0_class_init(ObjectClass *klass, void *data)
     k->init = l2x0_priv_init;
     dc->vmsd = &vmstate_l2x0;
     dc->no_user = 1;
-    dc->props = l2x0_properties;
+    klass->props = l2x0_properties;
     dc->reset = l2x0_priv_reset;
 }
 
hw/arm_mptimer.c +1 -1
index df7fb4c..c55d06f 100644
@@ -323,7 +323,7 @@ static void arm_mptimer_class_init(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_arm_mptimer;
     dc->reset = arm_mptimer_reset;
     dc->no_user = 1;
-    dc->props = arm_mptimer_properties;
+    klass->props = arm_mptimer_properties;
 }
 
 static TypeInfo arm_mptimer_info = {
hw/arm_sysctl.c +1 -1
index 5f1237b..7aa449c 100644
@@ -403,7 +403,7 @@ static void arm_sysctl_class_init(ObjectClass *klass, void *data)
     k->init = arm_sysctl_init;
     dc->reset = arm_sysctl_reset;
     dc->vmsd = &vmstate_arm_sysctl;
-    dc->props = arm_sysctl_properties;
+    klass->props = arm_sysctl_properties;
 }
 
 static TypeInfo arm_sysctl_info = {
hw/arm_timer.c +1 -2
index e3ecce2..d14166a 100644
@@ -370,10 +370,9 @@ static Property sp804_properties[] = {
 static void sp804_class_init(ObjectClass *klass, void *data)
 {
     SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
-    DeviceClass *k = DEVICE_CLASS(klass);
 
     sdc->init = sp804_init;
-    k->props = sp804_properties;
+    klass->props = sp804_properties;
 }
 
 static TypeInfo sp804_info = {
hw/armv7m.c +1 -2
index 4aac076..784e2ff 100644
@@ -252,11 +252,10 @@ static Property bitband_properties[] = {
 
 static void bitband_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = bitband_init;
-    dc->props = bitband_properties;
+    klass->props = bitband_properties;
 }
 
 static TypeInfo bitband_info = {
hw/armv7m_nvic.c +1 -1
index 3210129..b054d3f 100644
@@ -407,7 +407,7 @@ static void armv7m_nvic_class_init(ObjectClass *klass, void *data)
 
     sdc->init = armv7m_nvic_init;
     dc->vmsd  = &vmstate_nvic;
-    dc->props = armv7m_nvic_properties;
+    klass->props = armv7m_nvic_properties;
 }
 
 static TypeInfo armv7m_nvic_info = {
hw/cadence_gem.c +1 -1
index e2140ae..a065168 100644
@@ -1213,7 +1213,7 @@ static void gem_class_init(ObjectClass *klass, void *data)
     SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
 
     sdc->init = gem_init;
-    dc->props = gem_properties;
+    klass->props = gem_properties;
     dc->vmsd = &vmstate_cadence_gem;
     dc->reset = gem_reset;
 }
hw/ccid-card-emulated.c +1 -1
index f4a6da4..db27ec5 100644
@@ -584,7 +584,7 @@ static void emulated_class_initfn(ObjectClass *klass, void *data)
     cc->get_atr = emulated_get_atr;
     cc->apdu_from_guest = emulated_apdu_from_guest;
     dc->desc = "emulated smartcard";
-    dc->props = emulated_card_properties;
+    klass->props = emulated_card_properties;
 }
 
 static TypeInfo emulated_card_info = {
hw/ccid-card-passthru.c +1 -1
index bd6c777..856ee19 100644
@@ -333,7 +333,7 @@ static void passthru_class_initfn(ObjectClass *klass, void *data)
     cc->apdu_from_guest = passthru_apdu_from_guest;
     dc->desc = "passthrough smartcard";
     dc->vmsd = &passthru_vmstate;
-    dc->props = passthru_card_properties;
+    klass->props = passthru_card_properties;
 }
 
 static TypeInfo passthru_card_info = {
hw/cs4231.c +1 -1
index cfec1d9..06467cd 100644
@@ -163,7 +163,7 @@ static void cs4231_class_init(ObjectClass *klass, void *data)
     k->init = cs4231_init1;
     dc->reset = cs_reset;
     dc->vmsd = &vmstate_cs4231;
-    dc->props = cs4231_properties;
+    klass->props = cs4231_properties;
 }
 
 static TypeInfo cs4231_info = {
hw/cs4231a.c +1 -1
index e07b9d6..7e4d03c 100644
@@ -679,7 +679,7 @@ static void cs4231a_class_initfn (ObjectClass *klass, void *data)
     ic->init = cs4231a_initfn;
     dc->desc = "Crystal Semiconductor CS4231A";
     dc->vmsd = &vmstate_cs4231a;
-    dc->props = cs4231a_properties;
+    klass->props = cs4231a_properties;
 }
 
 static TypeInfo cs4231a_info = {
hw/debugcon.c +1 -2
index 14ab326..4dffebd 100644
@@ -96,10 +96,9 @@ static Property debugcon_isa_properties[] = {
 
 static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
     ic->init = debugcon_isa_initfn;
-    dc->props = debugcon_isa_properties;
+    klass->props = debugcon_isa_properties;
 }
 
 static TypeInfo debugcon_isa_info = {
hw/ds1225y.c +1 -1
index 2cd355b..d3d349c 100644
@@ -147,7 +147,7 @@ static void nvram_sysbus_class_init(ObjectClass *klass, void *data)
 
     k->init = nvram_sysbus_initfn;
     dc->vmsd = &vmstate_nvram;
-    dc->props = nvram_sysbus_properties;
+    klass->props = nvram_sysbus_properties;
 }
 
 static TypeInfo nvram_sysbus_info = {
hw/e1000.c +1 -1
index 7babc0b..7315698 100644
@@ -1217,7 +1217,7 @@ static void e1000_class_init(ObjectClass *klass, void *data)
     dc->desc = "Intel Gigabit Ethernet";
     dc->reset = qdev_e1000_reset;
     dc->vmsd = &vmstate_e1000;
-    dc->props = e1000_properties;
+    klass->props = e1000_properties;
 }
 
 static TypeInfo e1000_info = {
hw/eccmemctl.c +1 -1
index fe1cd90..82e4a4d 100644
@@ -321,7 +321,7 @@ static void ecc_class_init(ObjectClass *klass, void *data)
     k->init = ecc_init1;
     dc->reset = ecc_reset;
     dc->vmsd = &vmstate_ecc;
-    dc->props = ecc_properties;
+    klass->props = ecc_properties;
 }
 
 static TypeInfo ecc_info = {
hw/eepro100.c +1 -1
index e3ba719..0690654 100644
@@ -2076,7 +2076,7 @@ static void eepro100_class_init(ObjectClass *klass, void *data)
 
     info = eepro100_get_class_by_name(object_class_get_name(klass));
 
-    dc->props = e100_properties;
+    klass->props = e100_properties;
     dc->desc = info->desc;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
hw/escc.c +1 -1
index 4d8a8e8..16ef823 100644
@@ -921,7 +921,7 @@ static void escc_class_init(ObjectClass *klass, void *data)
     k->init = escc_init1;
     dc->reset = escc_reset;
     dc->vmsd = &vmstate_escc;
-    dc->props = escc_properties;
+    klass->props = escc_properties;
 }
 
 static TypeInfo escc_info = {
hw/esp.c +1 -1
index 8d73e56..b20d6a3 100644
@@ -766,7 +766,7 @@ static void esp_class_init(ObjectClass *klass, void *data)
     k->init = esp_init1;
     dc->reset = esp_hard_reset;
     dc->vmsd = &vmstate_esp;
-    dc->props = esp_properties;
+    klass->props = esp_properties;
 }
 
 static TypeInfo esp_info = {
hw/etraxfs_eth.c +1 -2
index 16a0637..30ad08e 100644
@@ -623,11 +623,10 @@ static Property etraxfs_eth_properties[] = {
 
 static void etraxfs_eth_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = fs_eth_init;
-    dc->props = etraxfs_eth_properties;
+    klass->props = etraxfs_eth_properties;
 }
 
 static TypeInfo etraxfs_eth_info = {
hw/etraxfs_pic.c +1 -2
index dc27f88..ad8c537 100644
@@ -158,11 +158,10 @@ static Property etraxfs_pic_properties[] = {
 
 static void etraxfs_pic_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = etraxfs_pic_init;
-    dc->props = etraxfs_pic_properties;
+    klass->props = etraxfs_pic_properties;
 }
 
 static TypeInfo etraxfs_pic_info = {
hw/exynos4210_combiner.c +1 -1
index 6110c19..a16c35d 100644
@@ -450,7 +450,7 @@ static void exynos4210_combiner_class_init(ObjectClass *klass, void *data)
 
     k->init = exynos4210_combiner_init;
     dc->reset = exynos4210_combiner_reset;
-    dc->props = exynos4210_combiner_properties;
+    klass->props = exynos4210_combiner_properties;
     dc->vmsd = &vmstate_exynos4210_combiner;
 }
 
hw/exynos4210_gic.c +1 -2
index ec13140..7297dbc 100644
@@ -333,11 +333,10 @@ static Property exynos4210_gic_properties[] = {
 
 static void exynos4210_gic_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = exynos4210_gic_init;
-    dc->props = exynos4210_gic_properties;
+    klass->props = exynos4210_gic_properties;
 }
 
 static TypeInfo exynos4210_gic_info = {
hw/exynos4210_uart.c +1 -1
index 73a9c18..791f1c5 100644
@@ -657,7 +657,7 @@ static void exynos4210_uart_class_init(ObjectClass *klass, void *data)
 
     k->init = exynos4210_uart_init;
     dc->reset = exynos4210_uart_reset;
-    dc->props = exynos4210_uart_properties;
+    klass->props = exynos4210_uart_properties;
     dc->vmsd = &vmstate_exynos4210_uart;
 }
 
hw/fdc.c +3 -3
index a0236b7..146dcab 100644
@@ -2064,7 +2064,7 @@ static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
     dc->no_user = 1;
     dc->reset = fdctrl_external_reset_isa;
     dc->vmsd = &vmstate_isa_fdc;
-    dc->props = isa_fdc_properties;
+    klass->props = isa_fdc_properties;
 }
 
 static TypeInfo isa_fdc_info = {
@@ -2098,7 +2098,7 @@ static void sysbus_fdc_class_init(ObjectClass *klass, void *data)
     k->init = sysbus_fdc_init1;
     dc->reset = fdctrl_external_reset_sysbus;
     dc->vmsd = &vmstate_sysbus_fdc;
-    dc->props = sysbus_fdc_properties;
+    klass->props = sysbus_fdc_properties;
 }
 
 static TypeInfo sysbus_fdc_info = {
@@ -2121,7 +2121,7 @@ static void sun4m_fdc_class_init(ObjectClass *klass, void *data)
     k->init = sun4m_fdc_init1;
     dc->reset = fdctrl_external_reset_sysbus;
     dc->vmsd = &vmstate_sysbus_fdc;
-    dc->props = sun4m_fdc_properties;
+    klass->props = sun4m_fdc_properties;
 }
 
 static TypeInfo sun4m_fdc_info = {
hw/fw_cfg.c +1 -1
index 7b3b576..5c3a388 100644
@@ -546,7 +546,7 @@ static void fw_cfg_class_init(ObjectClass *klass, void *data)
     dc->no_user = 1;
     dc->reset = fw_cfg_reset;
     dc->vmsd = &vmstate_fw_cfg;
-    dc->props = fw_cfg_properties;
+    klass->props = fw_cfg_properties;
 }
 
 static TypeInfo fw_cfg_info = {
hw/g364fb.c +1 -1
index 3a0b68f..597f004 100644
@@ -564,7 +564,7 @@ static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
     dc->desc = "G364 framebuffer";
     dc->reset = g364fb_sysbus_reset;
     dc->vmsd = &vmstate_g364fb;
-    dc->props = g364fb_sysbus_properties;
+    klass->props = g364fb_sysbus_properties;
 }
 
 static TypeInfo g364fb_sysbus_info = {
hw/grlib_apbuart.c +1 -2
index 73fc989..f64747d 100644
@@ -249,11 +249,10 @@ static Property grlib_gptimer_properties[] = {
 
 static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = grlib_apbuart_init;
-    dc->props = grlib_gptimer_properties;
+    klass->props = grlib_gptimer_properties;
 }
 
 static TypeInfo grlib_gptimer_info = {
hw/grlib_gptimer.c +1 -1
index 41770a9..c44b1fd 100644
@@ -386,7 +386,7 @@ static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
 
     k->init = grlib_gptimer_init;
     dc->reset = grlib_gptimer_reset;
-    dc->props = grlib_gptimer_properties;
+    klass->props = grlib_gptimer_properties;
 }
 
 static TypeInfo grlib_gptimer_info = {
hw/grlib_irqmp.c +1 -1
index 0f6e65c..3bbfcec 100644
@@ -367,7 +367,7 @@ static void grlib_irqmp_class_init(ObjectClass *klass, void *data)
 
     k->init = grlib_irqmp_init;
     dc->reset = grlib_irqmp_reset;
-    dc->props = grlib_irqmp_properties;
+    klass->props = grlib_irqmp_properties;
 }
 
 static TypeInfo grlib_irqmp_info = {
hw/gus.c +1 -1
index 840d098..1bc81a9 100644
@@ -314,7 +314,7 @@ static void gus_class_initfn (ObjectClass *klass, void *data)
     ic->init = gus_initfn;
     dc->desc = "Gravis Ultrasound GF1";
     dc->vmsd = &vmstate_gus;
-    dc->props = gus_properties;
+    klass->props = gus_properties;
 }
 
 static TypeInfo gus_info = {
hw/hda-audio.c +2 -2
index 8995519..de33422 100644
@@ -917,7 +917,7 @@ static void hda_audio_output_class_init(ObjectClass *klass, void *data)
     k->stream = hda_audio_stream;
     dc->desc = "HDA Audio Codec, output-only";
     dc->vmsd = &vmstate_hda_audio;
-    dc->props = hda_audio_properties;
+    klass->props = hda_audio_properties;
 }
 
 static TypeInfo hda_audio_output_info = {
@@ -938,7 +938,7 @@ static void hda_audio_duplex_class_init(ObjectClass *klass, void *data)
     k->stream = hda_audio_stream;
     dc->desc = "HDA Audio Codec, duplex";
     dc->vmsd = &vmstate_hda_audio;
-    dc->props = hda_audio_properties;
+    klass->props = hda_audio_properties;
 }
 
 static TypeInfo hda_audio_duplex_info = {
hw/hpet.c +1 -1
index fd3ddca..126e78b 100644
@@ -742,7 +742,7 @@ static void hpet_device_class_init(ObjectClass *klass, void *data)
     dc->no_user = 1;
     dc->reset = hpet_reset;
     dc->vmsd = &vmstate_hpet;
-    dc->props = hpet_device_properties;
+    klass->props = hpet_device_properties;
 }
 
 static TypeInfo hpet_device_info = {
hw/i2c.c +1 -1
index af5979e..5b3d9a0 100644
@@ -220,7 +220,7 @@ static void i2c_slave_class_init(ObjectClass *klass, void *data)
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = i2c_slave_qdev_init;
     k->bus_info = &i2c_bus_info;
-    k->props = i2c_props;
+    klass->props = i2c_props;
 }
 
 static TypeInfo i2c_slave_type_info = {
hw/i82374.c +1 -1
index 67298a3..99daf34 100644
@@ -147,7 +147,7 @@ static void i82374_class_init(ObjectClass *klass, void *data)
     
     k->init  = i82374_isa_init;
     dc->vmsd = &vmstate_isa_i82374;
-    dc->props = i82374_properties;
+    klass->props = i82374_properties;
 }
 
 static TypeInfo i82374_isa_info = {
hw/i82378.c +1 -1
index faad1a3..aa6f275 100644
@@ -259,7 +259,7 @@ static void pci_i82378_class_init(ObjectClass *klass, void *data)
     k->subsystem_vendor_id = 0x0;
     k->subsystem_id = 0x0;
     dc->vmsd = &vmstate_pci_i82378;
-    dc->props = i82378_properties;
+    klass->props = i82378_properties;
 }
 
 static TypeInfo pci_i82378_info = {
hw/i8254.c +1 -1
index 77bd5e8..9be9dbc 100644
@@ -342,7 +342,7 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
     k->get_channel_info = pit_get_channel_info_common;
     k->post_load = pit_post_load;
     dc->reset = pit_reset;
-    dc->props = pit_properties;
+    klass->props = pit_properties;
 }
 
 static TypeInfo pit_info = {
hw/i8259_common.c +1 -1
index ab3d98b..a91d1e5 100644
@@ -140,7 +140,7 @@ static void pic_common_class_init(ObjectClass *klass, void *data)
 
     dc->vmsd = &vmstate_pic_common;
     dc->no_user = 1;
-    dc->props = pic_properties_common;
+    klass->props = pic_properties_common;
     ic->init = pic_init_common;
 }
 
hw/ide/ahci.c +1 -1
index a883a92..dc87c34 100644
@@ -1202,7 +1202,7 @@ static void sysbus_ahci_class_init(ObjectClass *klass, void *data)
 
     sbc->init = sysbus_ahci_init;
     dc->vmsd = &vmstate_sysbus_ahci;
-    dc->props = sysbus_ahci_properties;
+    klass->props = sysbus_ahci_properties;
 }
 
 static TypeInfo sysbus_ahci_info = {
hw/ide/cmd646.c +1 -2
index bf8ece4..ab4cfdd 100644
@@ -332,7 +332,6 @@ static Property cmd646_ide_properties[] = {
 
 static void cmd646_ide_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->init = pci_cmd646_ide_initfn;
@@ -341,7 +340,7 @@ static void cmd646_ide_class_init(ObjectClass *klass, void *data)
     k->device_id = PCI_DEVICE_ID_CMD_646;
     k->revision = 0x07;
     k->class_id = PCI_CLASS_STORAGE_IDE;
-    dc->props = cmd646_ide_properties;
+    klass->props = cmd646_ide_properties;
 }
 
 static TypeInfo cmd646_ide_info = {
hw/ide/isa.c +1 -1
index 8ab2718..c2faba9 100644
@@ -108,7 +108,7 @@ static void isa_ide_class_initfn(ObjectClass *klass, void *data)
     ic->init = isa_ide_initfn;
     dc->fw_name = "ide";
     dc->reset = isa_ide_reset;
-    dc->props = isa_ide_properties;
+    klass->props = isa_ide_properties;
 }
 
 static TypeInfo isa_ide_info = {
hw/ide/qdev.c +4 -4
index 27ff47c..87ff2fe 100644
@@ -188,7 +188,7 @@ static void ide_hd_class_init(ObjectClass *klass, void *data)
     k->init = ide_hd_initfn;
     dc->fw_name = "drive";
     dc->desc = "virtual IDE disk";
-    dc->props = ide_hd_properties;
+    klass->props = ide_hd_properties;
 }
 
 static TypeInfo ide_hd_info = {
@@ -210,7 +210,7 @@ static void ide_cd_class_init(ObjectClass *klass, void *data)
     k->init = ide_cd_initfn;
     dc->fw_name = "drive";
     dc->desc = "virtual IDE CD-ROM";
-    dc->props = ide_cd_properties;
+    klass->props = ide_cd_properties;
 }
 
 static TypeInfo ide_cd_info = {
@@ -232,7 +232,7 @@ static void ide_drive_class_init(ObjectClass *klass, void *data)
     k->init = ide_drive_initfn;
     dc->fw_name = "drive";
     dc->desc = "virtual IDE disk or CD-ROM (legacy)";
-    dc->props = ide_drive_properties;
+    klass->props = ide_drive_properties;
 }
 
 static TypeInfo ide_drive_info = {
@@ -247,7 +247,7 @@ static void ide_device_class_init(ObjectClass *klass, void *data)
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = ide_qdev_init;
     k->bus_info = &ide_bus_info;
-    k->props = ide_props;
+    klass->props = ide_props;
 }
 
 static TypeInfo ide_device_type_info = {
hw/integratorcp.c +1 -2
index 9bdb9e6..3dd8661 100644
@@ -524,11 +524,10 @@ static Property core_properties[] = {
 
 static void core_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = integratorcm_init;
-    dc->props = core_properties;
+    klass->props = core_properties;
 }
 
 static TypeInfo core_info = {
hw/intel-hda.c +2 -2
index e2bd41e..f343603 100644
@@ -1261,7 +1261,7 @@ static void intel_hda_class_init(ObjectClass *klass, void *data)
     dc->desc = "Intel HD Audio Controller";
     dc->reset = intel_hda_reset;
     dc->vmsd = &vmstate_intel_hda;
-    dc->props = intel_hda_properties;
+    klass->props = intel_hda_properties;
 }
 
 static TypeInfo intel_hda_info = {
@@ -1277,7 +1277,7 @@ static void hda_codec_device_class_init(ObjectClass *klass, void *data)
     k->init = hda_codec_dev_init;
     k->exit = hda_codec_dev_exit;
     k->bus_info = &hda_codec_bus_info;
-    k->props = hda_props;
+    klass->props = hda_props;
 }
 
 static TypeInfo hda_codec_device_type_info = {
hw/ioh3420.c +1 -1
index 1632d31..cfb8507 100644
@@ -227,7 +227,7 @@ static void ioh3420_class_init(ObjectClass *klass, void *data)
     dc->desc = "Intel IOH device id 3420 PCIE Root Port";
     dc->reset = ioh3420_reset;
     dc->vmsd = &vmstate_ioh3420;
-    dc->props = ioh3420_properties;
+    klass->props = ioh3420_properties;
 }
 
 static TypeInfo ioh3420_info = {
hw/ivshmem.c +1 -1
index 64e1cd9..3aecbe2 100644
@@ -788,7 +788,7 @@ static void ivshmem_class_init(ObjectClass *klass, void *data)
     k->device_id = 0x1110;
     k->class_id = PCI_CLASS_MEMORY_RAM;
     dc->reset = ivshmem_reset;
-    dc->props = ivshmem_properties;
+    klass->props = ivshmem_properties;
 }
 
 static TypeInfo ivshmem_info = {
hw/kvm/i8254.c +1 -1
index bb5fe07..9e7dba9 100644
@@ -236,7 +236,7 @@ static void kvm_pit_class_init(ObjectClass *klass, void *data)
     k->pre_save = kvm_pit_get;
     k->post_load = kvm_pit_put;
     dc->reset = kvm_pit_reset;
-    dc->props = kvm_pit_properties;
+    klass->props = kvm_pit_properties;
 }
 
 static TypeInfo kvm_pit_info = {
hw/kvm/ioapic.c +1 -1
index 3ae3175..d57b11b 100644
@@ -107,7 +107,7 @@ static void kvm_ioapic_class_init(ObjectClass *klass, void *data)
     k->pre_save  = kvm_ioapic_get;
     k->post_load = kvm_ioapic_put;
     dc->reset    = kvm_ioapic_reset;
-    dc->props    = kvm_ioapic_properties;
+    klass->props = kvm_ioapic_properties;
 }
 
 static TypeInfo kvm_ioapic_info = {
hw/lan9118.c +1 -1
index 7b4fe87..dbefefb 100644
@@ -1362,7 +1362,7 @@ static void lan9118_class_init(ObjectClass *klass, void *data)
 
     k->init = lan9118_init1;
     dc->reset = lan9118_reset;
-    dc->props = lan9118_properties;
+    klass->props = lan9118_properties;
     dc->vmsd = &vmstate_lan9118;
 }
 
hw/lance.c +1 -1
index ce3d46c..a7e3dca 100644
@@ -152,7 +152,7 @@ static void lance_class_init(ObjectClass *klass, void *data)
     dc->fw_name = "ethernet";
     dc->reset = lance_reset;
     dc->vmsd = &vmstate_lance;
-    dc->props = lance_properties;
+    klass->props = lance_properties;
 }
 
 static TypeInfo lance_info = {
hw/lm32_sys.c +1 -1
index bbe03c4..99fef79 100644
@@ -154,7 +154,7 @@ static void lm32_sys_class_init(ObjectClass *klass, void *data)
     k->init = lm32_sys_init;
     dc->reset = sys_reset;
     dc->vmsd = &vmstate_lm32_sys;
-    dc->props = lm32_sys_properties;
+    klass->props = lm32_sys_properties;
 }
 
 static TypeInfo lm32_sys_info = {
hw/lm32_timer.c +1 -1
index e9450a0..f3a20ff 100644
@@ -212,7 +212,7 @@ static void lm32_timer_class_init(ObjectClass *klass, void *data)
     k->init = lm32_timer_init;
     dc->reset = timer_reset;
     dc->vmsd = &vmstate_lm32_timer;
-    dc->props = lm32_timer_properties;
+    klass->props = lm32_timer_properties;
 }
 
 static TypeInfo lm32_timer_info = {
hw/m48t59.c +2 -2
index 60bbb00..3f368f2 100644
@@ -734,7 +734,7 @@ static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
     ic->init = m48t59_init_isa1;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
-    dc->props = m48t59_isa_properties;
+    klass->props = m48t59_isa_properties;
 }
 
 static TypeInfo m48t59_isa_info = {
@@ -758,7 +758,7 @@ static void m48t59_class_init(ObjectClass *klass, void *data)
 
     k->init = m48t59_init1;
     dc->reset = m48t59_reset_sysbus;
-    dc->props = m48t59_properties;
+    klass->props = m48t59_properties;
 }
 
 static TypeInfo m48t59_info = {
hw/marvell_88w8618_audio.c +1 -1
index f6f1937..9cb70f2 100644
@@ -285,7 +285,7 @@ static void mv88w8618_audio_class_init(ObjectClass *klass, void *data)
     k->init = mv88w8618_audio_init;
     dc->reset = mv88w8618_audio_reset;
     dc->vmsd = &mv88w8618_audio_vmsd;
-    dc->props = mv88w8618_audio_properties;
+    klass->props = mv88w8618_audio_properties;
 }
 
 static TypeInfo mv88w8618_audio_info = {
hw/mc146818rtc.c +1 -1
index 3777f85..9c9b23c 100644
@@ -697,7 +697,7 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
     ic->init = rtc_initfn;
     dc->no_user = 1;
     dc->vmsd = &vmstate_rtc;
-    dc->props = mc146818rtc_properties;
+    klass->props = mc146818rtc_properties;
 }
 
 static TypeInfo mc146818rtc_info = {
hw/milkymist-minimac2.c +1 -1
index 70bf336..5bdb5e5 100644
@@ -532,7 +532,7 @@ static void milkymist_minimac2_class_init(ObjectClass *klass, void *data)
     k->init = milkymist_minimac2_init;
     dc->reset = milkymist_minimac2_reset;
     dc->vmsd = &vmstate_milkymist_minimac2;
-    dc->props = milkymist_minimac2_properties;
+    klass->props = milkymist_minimac2_properties;
 }
 
 static TypeInfo milkymist_minimac2_info = {
hw/milkymist-softusb.c +1 -1
index ecc2be9..e44d007 100644
@@ -313,7 +313,7 @@ static void milkymist_softusb_class_init(ObjectClass *klass, void *data)
     k->init = milkymist_softusb_init;
     dc->reset = milkymist_softusb_reset;
     dc->vmsd = &vmstate_milkymist_softusb;
-    dc->props = milkymist_softusb_properties;
+    klass->props = milkymist_softusb_properties;
 }
 
 static TypeInfo milkymist_softusb_info = {
hw/milkymist-sysctl.c +1 -1
index 8878d2b..6caabd9 100644
@@ -320,7 +320,7 @@ static void milkymist_sysctl_class_init(ObjectClass *klass, void *data)
     k->init = milkymist_sysctl_init;
     dc->reset = milkymist_sysctl_reset;
     dc->vmsd = &vmstate_milkymist_sysctl;
-    dc->props = milkymist_sysctl_properties;
+    klass->props = milkymist_sysctl_properties;
 }
 
 static TypeInfo milkymist_sysctl_info = {
hw/milkymist-vgafb.c +1 -1
index cd4365d..7cf00ef 100644
@@ -316,7 +316,7 @@ static void milkymist_vgafb_class_init(ObjectClass *klass, void *data)
     k->init = milkymist_vgafb_init;
     dc->reset = milkymist_vgafb_reset;
     dc->vmsd = &vmstate_milkymist_vgafb;
-    dc->props = milkymist_vgafb_properties;
+    klass->props = milkymist_vgafb_properties;
 }
 
 static TypeInfo milkymist_vgafb_info = {
hw/mipsnet.c +1 -1
index 3107246..50876bc 100644
@@ -266,7 +266,7 @@ static void mipsnet_class_init(ObjectClass *klass, void *data)
     dc->desc = "MIPS Simulator network device";
     dc->reset = mipsnet_sysbus_reset;
     dc->vmsd = &vmstate_mipsnet;
-    dc->props = mipsnet_properties;
+    klass->props = mipsnet_properties;
 }
 
 static TypeInfo mipsnet_info = {
hw/musicpal.c +1 -1
index c9f845a..7f186a9 100644
@@ -424,7 +424,7 @@ static void mv88w8618_eth_class_init(ObjectClass *klass, void *data)
 
     k->init = mv88w8618_eth_init;
     dc->vmsd = &mv88w8618_eth_vmsd;
-    dc->props = mv88w8618_eth_properties;
+    klass->props = mv88w8618_eth_properties;
 }
 
 static TypeInfo mv88w8618_eth_info = {
hw/nand.c +1 -1
index e9501ae..460f2fe 100644
@@ -432,7 +432,7 @@ static void nand_class_init(ObjectClass *klass, void *data)
     k->init = nand_device_init;
     dc->reset = nand_reset;
     dc->vmsd = &vmstate_nand;
-    dc->props = nand_properties;
+    klass->props = nand_properties;
 }
 
 static TypeInfo nand_info = {
hw/ne2000-isa.c +1 -2
index a4a783a..a38da68 100644
@@ -91,10 +91,9 @@ static Property ne2000_isa_properties[] = {
 
 static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
     ic->init = isa_ne2000_initfn;
-    dc->props = ne2000_isa_properties;
+    klass->props = ne2000_isa_properties;
 }
 
 static TypeInfo ne2000_isa_info = {
hw/ne2000.c +1 -1
index 71452e1..7bb83da 100644
@@ -795,7 +795,7 @@ static void ne2000_class_init(ObjectClass *klass, void *data)
     k->device_id = PCI_DEVICE_ID_REALTEK_8029;
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
     dc->vmsd = &vmstate_pci_ne2000;
-    dc->props = ne2000_properties;
+    klass->props = ne2000_properties;
 }
 
 static TypeInfo ne2000_info = {
hw/omap_gpio.c +2 -2
index 201ff77..b4fba0b 100644
@@ -744,7 +744,7 @@ static void omap_gpio_class_init(ObjectClass *klass, void *data)
 
     k->init = omap_gpio_init;
     dc->reset = omap_gpif_reset;
-    dc->props = omap_gpio_properties;
+    klass->props = omap_gpio_properties;
 }
 
 static TypeInfo omap_gpio_info = {
@@ -773,7 +773,7 @@ static void omap2_gpio_class_init(ObjectClass *klass, void *data)
 
     k->init = omap2_gpio_init;
     dc->reset = omap2_gpif_reset;
-    dc->props = omap2_gpio_properties;
+    klass->props = omap2_gpio_properties;
 }
 
 static TypeInfo omap2_gpio_info = {
hw/omap_i2c.c +1 -1
index 20bc82e..280c622 100644
@@ -467,7 +467,7 @@ static void omap_i2c_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
     k->init = omap_i2c_init;
-    dc->props = omap_i2c_properties;
+    klass->props = omap_i2c_properties;
     dc->reset = omap_i2c_reset;
 }
 
hw/omap_intc.c +2 -2
index 5076e07..7f98a3e 100644
@@ -386,7 +386,7 @@ static void omap_intc_class_init(ObjectClass *klass, void *data)
 
     k->init = omap_intc_init;
     dc->reset = omap_inth_reset;
-    dc->props = omap_intc_properties;
+    klass->props = omap_intc_properties;
 }
 
 static TypeInfo omap_intc_info = {
@@ -630,7 +630,7 @@ static void omap2_intc_class_init(ObjectClass *klass, void *data)
 
     k->init = omap2_intc_init;
     dc->reset = omap_inth_reset;
-    dc->props = omap2_intc_properties;
+    klass->props = omap2_intc_properties;
 }
 
 static TypeInfo omap2_intc_info = {
hw/onenand.c +1 -1
index db6af68..05126dc 100644
@@ -818,7 +818,7 @@ static void onenand_class_init(ObjectClass *klass, void *data)
 
     k->init = onenand_initfn;
     dc->reset = onenand_system_reset;
-    dc->props = onenand_properties;
+    klass->props = onenand_properties;
 }
 
 static TypeInfo onenand_info = {
hw/opencores_eth.c +1 -1
index 4c76969..bf26bf8 100644
@@ -740,7 +740,7 @@ static void open_eth_class_init(ObjectClass *klass, void *data)
     k->init = sysbus_open_eth_init;
     dc->desc = "Opencores 10/100 Mbit Ethernet";
     dc->reset = qdev_open_eth_reset;
-    dc->props = open_eth_properties;
+    klass->props = open_eth_properties;
 }
 
 static TypeInfo open_eth_info = {
hw/parallel.c +1 -2
index 219f384..f3fdbdb 100644
@@ -593,10 +593,9 @@ static Property parallel_isa_properties[] = {
 
 static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
     ic->init = parallel_isa_initfn;
-    dc->props = parallel_isa_properties;
+    klass->props = parallel_isa_properties;
 }
 
 static TypeInfo parallel_isa_info = {
hw/pc_sysfw.c +1 -1
index abf9004..7bad61e 100644
@@ -235,7 +235,7 @@ static void pcsysfw_class_init (ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS (klass);
 
     dc->desc = "PC System Firmware";
-    dc->props = pcsysfw_properties;
+    klass->props = pcsysfw_properties;
 }
 
 static TypeInfo pcsysfw_info = {
hw/pci.c +1 -1
index 6910fac..1679d40 100644
@@ -2003,7 +2003,7 @@ static void pci_device_class_init(ObjectClass *klass, void *data)
     k->unplug = pci_unplug_device;
     k->exit = pci_unregister_device;
     k->bus_info = &pci_bus_info;
-    k->props = pci_props;
+    klass->props = pci_props;
 }
 
 static TypeInfo pci_device_type_info = {
hw/pcnet-pci.c +1 -1
index 34d73aa..a322046 100644
@@ -359,7 +359,7 @@ static void pcnet_class_init(ObjectClass *klass, void *data)
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
     dc->reset = pci_reset;
     dc->vmsd = &vmstate_pci_pcnet;
-    dc->props = pcnet_properties;
+    klass->props = pcnet_properties;
 }
 
 static TypeInfo pcnet_info = {
hw/pcspk.c +1 -1
index e430324..f33eac2 100644
@@ -184,7 +184,7 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)
 
     ic->init = pcspk_initfn;
     dc->no_user = 1;
-    dc->props = pcspk_properties;
+    klass->props = pcspk_properties;
 }
 
 static TypeInfo pcspk_info = {
hw/pl041.c +1 -1
index b6723be..5a035e1 100644
@@ -628,7 +628,7 @@ static void pl041_device_class_init(ObjectClass *klass, void *data)
     dc->no_user = 1;
     dc->reset = pl041_device_reset;
     dc->vmsd = &vmstate_pl041;
-    dc->props = pl041_device_properties;
+    klass->props = pl041_device_properties;
 }
 
 static TypeInfo pl041_device_info = {
hw/pxa2xx.c +1 -1
index ddaa846..6fd0b26 100644
@@ -1556,7 +1556,7 @@ static void pxa2xx_i2c_class_init(ObjectClass *klass, void *data)
     k->init = pxa2xx_i2c_initfn;
     dc->desc = "PXA2xx I2C Bus Controller";
     dc->vmsd = &vmstate_pxa2xx_i2c;
-    dc->props = pxa2xx_i2c_properties;
+    klass->props = pxa2xx_i2c_properties;
 }
 
 static TypeInfo pxa2xx_i2c_info = {
hw/pxa2xx_dma.c +1 -1
index 0310154..aef039f 100644
@@ -556,7 +556,7 @@ static void pxa2xx_dma_class_init(ObjectClass *klass, void *data)
     k->init = pxa2xx_dma_init;
     dc->desc = "PXA2xx DMA controller";
     dc->vmsd = &vmstate_pxa2xx_dma;
-    dc->props = pxa2xx_dma_properties;
+    klass->props = pxa2xx_dma_properties;
 }
 
 static TypeInfo pxa2xx_dma_info = {
hw/pxa2xx_gpio.c +1 -1
index 09a408b..c98454e 100644
@@ -330,7 +330,7 @@ static void pxa2xx_gpio_class_init(ObjectClass *klass, void *data)
 
     k->init = pxa2xx_gpio_initfn;
     dc->desc = "PXA2xx GPIO controller";
-    dc->props = pxa2xx_gpio_properties;
+    klass->props = pxa2xx_gpio_properties;
 }
 
 static TypeInfo pxa2xx_gpio_info = {
hw/pxa2xx_timer.c +2 -2
index 77b033b..db2ebe2 100644
@@ -492,7 +492,7 @@ static void pxa25x_timer_dev_class_init(ObjectClass *klass, void *data)
     k->init = pxa2xx_timer_init;
     dc->desc = "PXA25x timer";
     dc->vmsd = &vmstate_pxa2xx_timer_regs;
-    dc->props = pxa25x_timer_dev_properties;
+    klass->props = pxa25x_timer_dev_properties;
 }
 
 static TypeInfo pxa25x_timer_dev_info = {
@@ -517,7 +517,7 @@ static void pxa27x_timer_dev_class_init(ObjectClass *klass, void *data)
     k->init = pxa2xx_timer_init;
     dc->desc = "PXA27x timer";
     dc->vmsd = &vmstate_pxa2xx_timer_regs;
-    dc->props = pxa27x_timer_dev_properties;
+    klass->props = pxa27x_timer_dev_properties;
 }
 
 static TypeInfo pxa27x_timer_dev_info = {
hw/qdev-monitor.c +2 -2
index d4fc843..2161a36 100644
@@ -148,7 +148,7 @@ int qdev_device_help(QemuOpts *opts)
         return 0;
     }
     do {
-        for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
+        for (prop = OBJECT_CLASS(klass)->props; prop && prop->name; prop++) {
             /*
              * TODO Properties without a parser are just for dirty hacks.
              * qdev_prop_ptr is the only such PropertyInfo.  It's marked
@@ -511,7 +511,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
     }
     class = object_get_class(OBJECT(dev));
     do {
-        qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent);
+        qdev_print_props(mon, dev, OBJECT_CLASS(class)->props, indent);
         class = object_class_get_parent(class);
     } while (class != object_class_by_name(TYPE_DEVICE));
     if (dev->parent_bus->info->print_dev)
hw/qdev-properties.c +1 -1
index bea57e9..6e518d8 100644
@@ -465,7 +465,7 @@ static Property *qdev_prop_find(Object *obj, const char *name)
     /* device properties */
     class = object_get_class(obj);
     do {
-        prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name);
+        prop = qdev_prop_walk(OBJECT_CLASS(class)->props, name);
         if (prop) {
             return prop;
         }
hw/qdev.c +1 -13
index 813f27e..d9f811f 100644
@@ -575,9 +575,8 @@ static void device_initfn(Object *obj)
 
     class = object_get_class(OBJECT(dev));
     do {
-        for (prop = DEVICE_CLASS(class)->props; prop && prop->name; prop++) {
+        for (prop = OBJECT_CLASS(class)->props; prop && prop->name; prop++) {
             qdev_property_add_legacy(dev, prop, NULL);
-            object_property_add_static(OBJECT(dev), prop, NULL);
         }
         class = object_class_get_parent(class);
     } while (class != object_class_by_name(TYPE_DEVICE));
@@ -609,16 +608,6 @@ static void device_finalize(Object *obj)
     QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
 }
 
-static void device_class_base_init(ObjectClass *class, void *data)
-{
-    DeviceClass *klass = DEVICE_CLASS(class);
-
-    /* We explicitly look up properties in the superclasses,
-     * so do not propagate them to the subclasses.
-     */
-    klass->props = NULL;
-}
-
 void device_reset(DeviceState *dev)
 {
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -645,7 +634,6 @@ static TypeInfo device_type_info = {
     .instance_size = sizeof(DeviceState),
     .instance_init = device_initfn,
     .instance_finalize = device_finalize,
-    .class_base_init = device_class_base_init,
     .abstract = true,
     .class_size = sizeof(DeviceClass),
 };
hw/qdev.h +0 -1
index d2596fe..3c35acf 100644
@@ -32,7 +32,6 @@ typedef struct DeviceClass {
 
     const char *fw_name;
     const char *desc;
-    Property *props;
     int no_user;
 
     /* callbacks */
hw/qxl.c +2 -2
index 47a162e..08cab5b 100644
@@ -1978,7 +1978,7 @@ static void qxl_primary_class_init(ObjectClass *klass, void *data)
     dc->desc = "Spice QXL GPU (primary, vga compatible)";
     dc->reset = qxl_reset_handler;
     dc->vmsd = &qxl_vmstate;
-    dc->props = qxl_properties;
+    klass->props = qxl_properties;
 }
 
 static TypeInfo qxl_primary_info = {
@@ -2000,7 +2000,7 @@ static void qxl_secondary_class_init(ObjectClass *klass, void *data)
     dc->desc = "Spice QXL GPU (secondary)";
     dc->reset = qxl_reset_handler;
     dc->vmsd = &qxl_vmstate;
-    dc->props = qxl_properties;
+    klass->props = qxl_properties;
 }
 
 static TypeInfo qxl_secondary_info = {
hw/rtl8139.c +1 -1
index 05b8e1e..b9b2354 100644
@@ -3513,7 +3513,7 @@ static void rtl8139_class_init(ObjectClass *klass, void *data)
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
     dc->reset = rtl8139_reset;
     dc->vmsd = &vmstate_rtl8139;
-    dc->props = rtl8139_properties;
+    klass->props = rtl8139_properties;
 }
 
 static TypeInfo rtl8139_info = {
hw/s390-virtio-bus.c +4 -8
index be1f5f1..1980e38 100644
@@ -361,11 +361,10 @@ static Property s390_virtio_net_properties[] = {
 
 static void s390_virtio_net_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
 
     k->init = s390_virtio_net_init;
-    dc->props = s390_virtio_net_properties;
+    klass->props = s390_virtio_net_properties;
 }
 
 static TypeInfo s390_virtio_net = {
@@ -383,11 +382,10 @@ static Property s390_virtio_blk_properties[] = {
 
 static void s390_virtio_blk_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
 
     k->init = s390_virtio_blk_init;
-    dc->props = s390_virtio_blk_properties;
+    klass->props = s390_virtio_blk_properties;
 }
 
 static TypeInfo s390_virtio_blk = {
@@ -405,11 +403,10 @@ static Property s390_virtio_serial_properties[] = {
 
 static void s390_virtio_serial_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
 
     k->init = s390_virtio_serial_init;
-    dc->props = s390_virtio_serial_properties;
+    klass->props = s390_virtio_serial_properties;
 }
 
 static TypeInfo s390_virtio_serial = {
@@ -452,11 +449,10 @@ static Property s390_virtio_scsi_properties[] = {
 
 static void s390_virtio_scsi_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
 
     k->init = s390_virtio_scsi_init;
-    dc->props = s390_virtio_scsi_properties;
+    klass->props = s390_virtio_scsi_properties;
 }
 
 static TypeInfo s390_virtio_scsi = {
hw/sb16.c +1 -1
index c81455d..5e8ef6e 100644
@@ -1407,7 +1407,7 @@ static void sb16_class_initfn (ObjectClass *klass, void *data)
     ic->init = sb16_initfn;
     dc->desc = "Creative Sound Blaster 16";
     dc->vmsd = &vmstate_sb16;
-    dc->props = sb16_properties;
+    klass->props = sb16_properties;
 }
 
 static TypeInfo sb16_info = {
hw/scsi-bus.c +1 -1
index 2777566..e64d2c5 100644
@@ -1574,7 +1574,7 @@ static void scsi_device_class_init(ObjectClass *klass, void *data)
     k->init     = scsi_qdev_init;
     k->unplug   = qdev_simple_unplug_cb;
     k->exit     = scsi_qdev_exit;
-    k->props    = scsi_props;
+    klass->props    = scsi_props;
 }
 
 static TypeInfo scsi_device_type_info = {
hw/scsi-disk.c +4 -4
index 9949786..5fe0627 100644
@@ -1844,7 +1844,7 @@ static void scsi_hd_class_initfn(ObjectClass *klass, void *data)
     dc->fw_name = "disk";
     dc->desc = "virtual SCSI disk";
     dc->reset = scsi_disk_reset;
-    dc->props = scsi_hd_properties;
+    klass->props = scsi_hd_properties;
     dc->vmsd  = &vmstate_scsi_disk_state;
 }
 
@@ -1872,7 +1872,7 @@ static void scsi_cd_class_initfn(ObjectClass *klass, void *data)
     dc->fw_name = "disk";
     dc->desc = "virtual SCSI CD-ROM";
     dc->reset = scsi_disk_reset;
-    dc->props = scsi_cd_properties;
+    klass->props = scsi_cd_properties;
     dc->vmsd  = &vmstate_scsi_disk_state;
 }
 
@@ -1900,7 +1900,7 @@ static void scsi_block_class_initfn(ObjectClass *klass, void *data)
     dc->fw_name = "disk";
     dc->desc = "SCSI block device passthrough";
     dc->reset = scsi_disk_reset;
-    dc->props = scsi_block_properties;
+    klass->props = scsi_block_properties;
     dc->vmsd  = &vmstate_scsi_disk_state;
 }
 
@@ -1930,7 +1930,7 @@ static void scsi_disk_class_initfn(ObjectClass *klass, void *data)
     dc->fw_name = "disk";
     dc->desc = "virtual SCSI disk or CD-ROM (legacy)";
     dc->reset = scsi_disk_reset;
-    dc->props = scsi_disk_properties;
+    klass->props = scsi_disk_properties;
     dc->vmsd  = &vmstate_scsi_disk_state;
 }
 
hw/scsi-generic.c +1 -1
index d856d23..c3a50a3 100644
@@ -497,7 +497,7 @@ static void scsi_generic_class_initfn(ObjectClass *klass, void *data)
     dc->fw_name = "disk";
     dc->desc = "pass through generic scsi device (/dev/sg*)";
     dc->reset = scsi_generic_reset;
-    dc->props = scsi_generic_properties;
+    klass->props = scsi_generic_properties;
     dc->vmsd  = &vmstate_scsi_device;
 }
 
hw/serial.c +1 -1
index a421d1e..1a76e91 100644
@@ -902,7 +902,7 @@ static void serial_isa_class_initfn(ObjectClass *klass, void *data)
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
     ic->init = serial_isa_initfn;
     dc->vmsd = &vmstate_isa_serial;
-    dc->props = serial_isa_properties;
+    klass->props = serial_isa_properties;
 }
 
 static TypeInfo serial_isa_info = {
hw/slavio_timer.c +1 -1
index 97edebb..62ceece 100644
@@ -417,7 +417,7 @@ static void slavio_timer_class_init(ObjectClass *klass, void *data)
     k->init = slavio_timer_init1;
     dc->reset = slavio_timer_reset;
     dc->vmsd = &vmstate_slavio_timer;
-    dc->props = slavio_timer_properties;
+    klass->props = slavio_timer_properties;
 }
 
 static TypeInfo slavio_timer_info = {
hw/smbus_eeprom.c +1 -2
index 11adab0..47e8a8a 100644
@@ -111,7 +111,6 @@ static Property smbus_eeprom_properties[] = {
 
 static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass);
 
     sc->init = smbus_eeprom_initfn;
@@ -120,7 +119,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data)
     sc->receive_byte = eeprom_receive_byte;
     sc->write_data = eeprom_write_data;
     sc->read_data = eeprom_read_data;
-    dc->props = smbus_eeprom_properties;
+    klass->props = smbus_eeprom_properties;
 }
 
 static TypeInfo smbus_eeprom_info = {
hw/smc91c111.c +1 -1
index 1a5213f..20a15ce 100644
@@ -771,7 +771,7 @@ static void smc91c111_class_init(ObjectClass *klass, void *data)
     k->init = smc91c111_init1;
     dc->reset = smc91c111_reset;
     dc->vmsd = &vmstate_smc91c111;
-    dc->props = smc91c111_properties;
+    klass->props = smc91c111_properties;
 }
 
 static TypeInfo smc91c111_info = {
hw/spapr_llan.c +1 -2
index cfc7778..38058e3 100644
@@ -482,7 +482,6 @@ static Property spapr_vlan_properties[] = {
 
 static void spapr_vlan_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
 
     k->init = spapr_vlan_init;
@@ -491,7 +490,7 @@ static void spapr_vlan_class_init(ObjectClass *klass, void *data)
     k->dt_type = "network";
     k->dt_compatible = "IBM,l-lan";
     k->signal_mask = 0x1;
-    dc->props = spapr_vlan_properties;
+    klass->props = spapr_vlan_properties;
 }
 
 static TypeInfo spapr_vlan_info = {
hw/spapr_pci.c +1 -2
index e7ef551..3080eb4 100644
@@ -298,10 +298,9 @@ static Property spapr_phb_properties[] = {
 static void spapr_phb_class_init(ObjectClass *klass, void *data)
 {
     SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
-    DeviceClass *dc = DEVICE_CLASS(klass);
 
     sdc->init = spapr_phb_init;
-    dc->props = spapr_phb_properties;
+    klass->props = spapr_phb_properties;
 
     spapr_rtas_register("read-pci-config", rtas_read_pci_config);
     spapr_rtas_register("write-pci-config", rtas_write_pci_config);
hw/spapr_vio.c +1 -1
index 897c057..d742b4d 100644
@@ -768,7 +768,7 @@ static void vio_spapr_device_class_init(ObjectClass *klass, void *data)
     DeviceClass *k = DEVICE_CLASS(klass);
     k->init = spapr_vio_busdev_init;
     k->bus_info = &spapr_vio_bus_info;
-    k->props = spapr_vio_props;
+    klass->props = spapr_vio_props;
 }
 
 static TypeInfo spapr_vio_type_info = {
hw/spapr_vscsi.c +1 -2
index 2167017..7e9ea95 100644
@@ -954,7 +954,6 @@ static Property spapr_vscsi_properties[] = {
 
 static void spapr_vscsi_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
 
     k->init = spapr_vscsi_init;
@@ -963,7 +962,7 @@ static void spapr_vscsi_class_init(ObjectClass *klass, void *data)
     k->dt_type = "vscsi";
     k->dt_compatible = "IBM,v-scsi";
     k->signal_mask = 0x00000001;
-    dc->props = spapr_vscsi_properties;
+    klass->props = spapr_vscsi_properties;
 }
 
 static TypeInfo spapr_vscsi_info = {
hw/spapr_vty.c +1 -2
index 60e22b1..2fc58d8 100644
@@ -143,14 +143,13 @@ static Property spapr_vty_properties[] = {
 
 static void spapr_vty_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
 
     k->init = spapr_vty_init;
     k->dt_name = "vty";
     k->dt_type = "serial";
     k->dt_compatible = "hvterm1";
-    dc->props = spapr_vty_properties;
+    klass->props = spapr_vty_properties;
 }
 
 static TypeInfo spapr_vty_info = {
hw/sparc32_dma.c +1 -1
index 1dbf69e..95b8a61 100644
@@ -297,7 +297,7 @@ static void sparc32_dma_class_init(ObjectClass *klass, void *data)
     k->init = sparc32_dma_init1;
     dc->reset = dma_reset;
     dc->vmsd = &vmstate_dma;
-    dc->props = sparc32_dma_properties;
+    klass->props = sparc32_dma_properties;
 }
 
 static TypeInfo sparc32_dma_info = {
hw/spitz.c +2 -2
index 1d6d2b0..8ff9b5b 100644
@@ -1036,7 +1036,7 @@ static void sl_nand_class_init(ObjectClass *klass, void *data)
 
     k->init = sl_nand_init;
     dc->vmsd = &vmstate_sl_nand_info;
-    dc->props = sl_nand_properties;
+    klass->props = sl_nand_properties;
 }
 
 static TypeInfo sl_nand_info = {
@@ -1071,7 +1071,7 @@ static void spitz_keyboard_class_init(ObjectClass *klass, void *data)
 
     k->init = spitz_keyboard_init;
     dc->vmsd = &vmstate_spitz_kbd;
-    dc->props = spitz_keyboard_properties;
+    klass->props = spitz_keyboard_properties;
 }
 
 static TypeInfo spitz_keyboard_info = {
hw/stellaris_enet.c +1 -2
index fbe99cb..6ef99c0 100644
@@ -427,11 +427,10 @@ static Property stellaris_enet_properties[] = {
 
 static void stellaris_enet_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = stellaris_enet_init;
-    dc->props = stellaris_enet_properties;
+    klass->props = stellaris_enet_properties;
 }
 
 static TypeInfo stellaris_enet_info = {
hw/strongarm.c +1 -1
index 1b15f39..8ce2f25 100644
@@ -1295,7 +1295,7 @@ static void strongarm_uart_class_init(ObjectClass *klass, void *data)
     dc->desc = "StrongARM UART controller";
     dc->reset = strongarm_uart_reset;
     dc->vmsd = &vmstate_strongarm_uart_regs;
-    dc->props = strongarm_uart_properties;
+    klass->props = strongarm_uart_properties;
 }
 
 static TypeInfo strongarm_uart_info = {
hw/sun4m.c +2 -4
index 7bcbf37..a68e19e 100644
@@ -728,11 +728,10 @@ static Property prom_properties[] = {
 
 static void prom_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = prom_init1;
-    dc->props = prom_properties;
+    klass->props = prom_properties;
 }
 
 static TypeInfo prom_info = {
@@ -792,11 +791,10 @@ static Property ram_properties[] = {
 
 static void ram_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = ram_init1;
-    dc->props = ram_properties;
+    klass->props = ram_properties;
 }
 
 static TypeInfo ram_info = {
hw/sun4m_iommu.c +1 -1
index ebefa91..485eee3 100644
@@ -370,7 +370,7 @@ static void iommu_class_init(ObjectClass *klass, void *data)
     k->init = iommu_init1;
     dc->reset = iommu_reset;
     dc->vmsd = &vmstate_iommu;
-    dc->props = iommu_properties;
+    klass->props = iommu_properties;
 }
 
 static TypeInfo iommu_info = {
hw/sun4u.c +2 -4
index 237e20c..c49308d 100644
@@ -665,11 +665,10 @@ static Property prom_properties[] = {
 
 static void prom_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = prom_init1;
-    dc->props = prom_properties;
+    klass->props = prom_properties;
 }
 
 static TypeInfo prom_info = {
@@ -722,11 +721,10 @@ static Property ram_properties[] = {
 
 static void ram_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = ram_init1;
-    dc->props = ram_properties;
+    klass->props = ram_properties;
 }
 
 static TypeInfo ram_info = {
hw/tcx.c +1 -1
index ac7dcb4..5b64296 100644
@@ -654,7 +654,7 @@ static void tcx_class_init(ObjectClass *klass, void *data)
     k->init = tcx_init1;
     dc->reset = tcx_reset;
     dc->vmsd = &vmstate_tcx;
-    dc->props = tcx_properties;
+    klass->props = tcx_properties;
 }
 
 static TypeInfo tcx_info = {
hw/usb/bus.c +1 -1
index 12d1be0..b42469e 100644
@@ -567,7 +567,7 @@ static void usb_device_class_init(ObjectClass *klass, void *data)
     k->init     = usb_qdev_init;
     k->unplug   = qdev_simple_unplug_cb;
     k->exit     = usb_qdev_exit;
-    k->props    = usb_props;
+    klass->props    = usb_props;
 }
 
 static TypeInfo usb_device_type_info = {
hw/usb/dev-audio.c +1 -1
index 426b95c..04b52df 100644
@@ -687,7 +687,7 @@ static void usb_audio_class_init(ObjectClass *klass, void *data)
     USBDeviceClass *k = USB_DEVICE_CLASS(klass);
 
     dc->vmsd          = &vmstate_usb_audio;
-    dc->props         = usb_audio_properties;
+    klass->props         = usb_audio_properties;
     k->product_desc   = "QEMU USB Audio Interface";
     k->usb_desc       = &desc_audio;
     k->init           = usb_audio_initfn;
hw/usb/dev-network.c +1 -1
index cff55f2..fbc24df 100644
@@ -1404,7 +1404,7 @@ static void usb_net_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = usb_net_handle_destroy;
     dc->fw_name = "network";
     dc->vmsd = &vmstate_usb_net;
-    dc->props = net_properties;
+    klass->props = net_properties;
 }
 
 static TypeInfo net_info = {
hw/usb/dev-serial.c +2 -2
index 8dcac8b..595b40e 100644
@@ -588,7 +588,7 @@ static void usb_serial_class_initfn(ObjectClass *klass, void *data)
     uc->handle_data    = usb_serial_handle_data;
     uc->handle_destroy = usb_serial_handle_destroy;
     dc->vmsd = &vmstate_usb_serial;
-    dc->props = serial_properties;
+    klass->props = serial_properties;
 }
 
 static TypeInfo serial_info = {
@@ -616,7 +616,7 @@ static void usb_braille_class_initfn(ObjectClass *klass, void *data)
     uc->handle_data    = usb_serial_handle_data;
     uc->handle_destroy = usb_serial_handle_destroy;
     dc->vmsd = &vmstate_usb_serial;
-    dc->props = braille_properties;
+    klass->props = braille_properties;
 }
 
 static TypeInfo braille_info = {
hw/usb/dev-smartcard-reader.c +2 -2
index a38a948..b60a963 100644
@@ -1329,7 +1329,7 @@ static void ccid_class_initfn(ObjectClass *klass, void *data)
     uc->handle_destroy = ccid_handle_destroy;
     dc->desc = "CCID Rev 1.1 smartcard reader";
     dc->vmsd = &ccid_vmstate;
-    dc->props = ccid_properties;
+    klass->props = ccid_properties;
 }
 
 static TypeInfo ccid_info = {
@@ -1345,7 +1345,7 @@ static void ccid_card_class_init(ObjectClass *klass, void *data)
     k->bus_info = &ccid_bus_info;
     k->init = ccid_card_init;
     k->exit = ccid_card_exit;
-    k->props = ccid_props;
+    klass->props = ccid_props;
 }
 
 static TypeInfo ccid_card_type_info = {
hw/usb/dev-storage.c +1 -1
index bdbe7bd..be58c4f 100644
@@ -658,7 +658,7 @@ static void usb_msd_class_initfn(ObjectClass *klass, void *data)
     uc->handle_data    = usb_msd_handle_data;
     dc->fw_name = "storage";
     dc->vmsd = &vmstate_usb_msd;
-    dc->props = msd_properties;
+    klass->props = msd_properties;
 }
 
 static TypeInfo msd_info = {
hw/usb/hcd-ehci.c +2 -2
index 60f9f5b..202398c 100644
@@ -2227,7 +2227,7 @@ static void ehci_class_init(ObjectClass *klass, void *data)
     k->revision = 0x10;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_ehci;
-    dc->props = ehci_properties;
+    klass->props = ehci_properties;
 }
 
 static TypeInfo ehci_info = {
@@ -2248,7 +2248,7 @@ static void ich9_ehci_class_init(ObjectClass *klass, void *data)
     k->revision = 0x03;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_ehci;
-    dc->props = ehci_properties;
+    klass->props = ehci_properties;
 }
 
 static TypeInfo ich9_ehci_info = {
hw/usb/hcd-ohci.c +2 -2
index 1a1cc88..b547381 100644
@@ -1863,7 +1863,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void *data)
     k->device_id = PCI_DEVICE_ID_APPLE_IPID_USB;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->desc = "Apple USB Controller";
-    dc->props = ohci_pci_properties;
+    klass->props = ohci_pci_properties;
 }
 
 static TypeInfo ohci_pci_info = {
@@ -1886,7 +1886,7 @@ static void ohci_sysbus_class_init(ObjectClass *klass, void *data)
 
     sbc->init = ohci_init_pxa;
     dc->desc = "OHCI USB Controller";
-    dc->props = ohci_sysbus_properties;
+    klass->props = ohci_sysbus_properties;
 }
 
 static TypeInfo ohci_sysbus_info = {
hw/usb/hcd-uhci.c +6 -6
index e55dad9..e50b38b 100644
@@ -1248,7 +1248,7 @@ static void piix3_uhci_class_init(ObjectClass *klass, void *data)
     k->revision = 0x01;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_uhci;
-    dc->props = uhci_properties;
+    klass->props = uhci_properties;
 }
 
 static TypeInfo piix3_uhci_info = {
@@ -1270,7 +1270,7 @@ static void piix4_uhci_class_init(ObjectClass *klass, void *data)
     k->revision = 0x01;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_uhci;
-    dc->props = uhci_properties;
+    klass->props = uhci_properties;
 }
 
 static TypeInfo piix4_uhci_info = {
@@ -1292,7 +1292,7 @@ static void vt82c686b_uhci_class_init(ObjectClass *klass, void *data)
     k->revision = 0x01;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_uhci;
-    dc->props = uhci_properties;
+    klass->props = uhci_properties;
 }
 
 static TypeInfo vt82c686b_uhci_info = {
@@ -1313,7 +1313,7 @@ static void ich9_uhci1_class_init(ObjectClass *klass, void *data)
     k->revision = 0x03;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_uhci;
-    dc->props = uhci_properties;
+    klass->props = uhci_properties;
 }
 
 static TypeInfo ich9_uhci1_info = {
@@ -1334,7 +1334,7 @@ static void ich9_uhci2_class_init(ObjectClass *klass, void *data)
     k->revision = 0x03;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_uhci;
-    dc->props = uhci_properties;
+    klass->props = uhci_properties;
 }
 
 static TypeInfo ich9_uhci2_info = {
@@ -1355,7 +1355,7 @@ static void ich9_uhci3_class_init(ObjectClass *klass, void *data)
     k->revision = 0x03;
     k->class_id = PCI_CLASS_SERIAL_USB;
     dc->vmsd = &vmstate_uhci;
-    dc->props = uhci_properties;
+    klass->props = uhci_properties;
 }
 
 static TypeInfo ich9_uhci3_info = {
hw/usb/hcd-xhci.c +1 -1
index 73b0c7f..9ec5cc4 100644
@@ -2900,7 +2900,7 @@ static void xhci_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd    = &vmstate_xhci;
-    dc->props   = xhci_properties;
+    klass->props    = xhci_properties;
     k->init         = usb_xhci_initfn;
     k->vendor_id    = PCI_VENDOR_ID_NEC;
     k->device_id    = PCI_DEVICE_ID_NEC_UPD720200;
hw/usb/host-linux.c +1 -1
index 90919c2..dc32566 100644
@@ -1434,7 +1434,7 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
     uc->handle_reset   = usb_host_handle_reset;
     uc->handle_destroy = usb_host_handle_destroy;
     dc->vmsd = &vmstate_usb_host;
-    dc->props = usb_host_dev_properties;
+    klass->props = usb_host_dev_properties;
 }
 
 static TypeInfo usb_host_dev_info = {
hw/usb/redirect.c +1 -1
index 8e9f175..ad40809 100644
@@ -1467,7 +1467,7 @@ static void usbredir_class_initfn(ObjectClass *klass, void *data)
     uc->handle_reset   = usbredir_handle_reset;
     uc->handle_data    = usbredir_handle_data;
     uc->handle_control = usbredir_handle_control;
-    dc->props          = usbredir_properties;
+    klass->props          = usbredir_properties;
 }
 
 static TypeInfo usbredir_dev_info = {
hw/virtio-console.c +2 -4
index cffee3d..212544a 100644
@@ -131,7 +131,6 @@ static Property virtconsole_properties[] = {
 
 static void virtconsole_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
 
     k->is_console = true;
@@ -139,7 +138,7 @@ static void virtconsole_class_init(ObjectClass *klass, void *data)
     k->have_data = flush_buf;
     k->guest_open = guest_open;
     k->guest_close = guest_close;
-    dc->props = virtconsole_properties;
+    klass->props = virtconsole_properties;
 }
 
 static TypeInfo virtconsole_info = {
@@ -156,14 +155,13 @@ static Property virtserialport_properties[] = {
 
 static void virtserialport_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_CLASS(klass);
 
     k->init = virtconsole_initfn;
     k->have_data = flush_buf;
     k->guest_open = guest_open;
     k->guest_close = guest_close;
-    dc->props = virtserialport_properties;
+    klass->props = virtserialport_properties;
 }
 
 static TypeInfo virtserialport_info = {
hw/virtio-pci.c +5 -5
index a0fb7c1..cf43fd8 100644
@@ -829,7 +829,7 @@ static void virtio_blk_class_init(ObjectClass *klass, void *data)
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_STORAGE_SCSI;
     dc->reset = virtio_pci_reset;
-    dc->props = virtio_blk_properties;
+    klass->props = virtio_blk_properties;
 }
 
 static TypeInfo virtio_blk_info = {
@@ -863,7 +863,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
     dc->reset = virtio_pci_reset;
-    dc->props = virtio_net_properties;
+    klass->props = virtio_net_properties;
 }
 
 static TypeInfo virtio_net_info = {
@@ -894,7 +894,7 @@ static void virtio_serial_class_init(ObjectClass *klass, void *data)
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
     dc->reset = virtio_pci_reset;
-    dc->props = virtio_serial_properties;
+    klass->props = virtio_serial_properties;
 }
 
 static TypeInfo virtio_serial_info = {
@@ -921,7 +921,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, void *data)
     k->revision = VIRTIO_PCI_ABI_VERSION;
     k->class_id = PCI_CLASS_MEMORY_RAM;
     dc->reset = virtio_pci_reset;
-    dc->props = virtio_balloon_properties;
+    klass->props = virtio_balloon_properties;
 }
 
 static TypeInfo virtio_balloon_info = {
@@ -975,7 +975,7 @@ static void virtio_scsi_class_init(ObjectClass *klass, void *data)
     k->revision = 0x00;
     k->class_id = PCI_CLASS_STORAGE_SCSI;
     dc->reset = virtio_pci_reset;
-    dc->props = virtio_scsi_properties;
+    klass->props = virtio_scsi_properties;
 }
 
 static TypeInfo virtio_scsi_info = {
hw/virtio-serial-bus.c +1 -1
index 6d49ad6..f0fa45c 100644
@@ -939,7 +939,7 @@ static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
     k->bus_info = &virtser_bus_info;
     k->exit = virtser_port_qdev_exit;
     k->unplug = qdev_simple_unplug_cb;
-    k->props = virtser_props;
+    klass->props = virtser_props;
 }
 
 static TypeInfo virtio_serial_port_type_info = {
hw/vmmouse.c +1 -1
index 6338efa..0fb7064 100644
@@ -284,7 +284,7 @@ static void vmmouse_class_initfn(ObjectClass *klass, void *data)
     dc->no_user = 1;
     dc->reset = vmmouse_reset;
     dc->vmsd = &vmstate_vmmouse;
-    dc->props = vmmouse_properties;
+    klass->props = vmmouse_properties;
 }
 
 static TypeInfo vmmouse_info = {
hw/vt82c686.c +1 -1
index 6fb7950..59d1f0f 100644
@@ -471,7 +471,7 @@ static void via_pm_class_init(ObjectClass *klass, void *data)
     k->revision = 0x40;
     dc->desc = "PM";
     dc->vmsd = &vmstate_acpi;
-    dc->props = via_pm_properties;
+    klass->props = via_pm_properties;
 }
 
 static TypeInfo via_pm_info = {
hw/xgmac.c +1 -1
index dd4bdc4..70ce403 100644
@@ -415,7 +415,7 @@ static void xgmac_enet_class_init(ObjectClass *klass, void *data)
 
     sbc->init = xgmac_enet_init;
     dc->vmsd = &vmstate_xgmac;
-    dc->props = xgmac_properties;
+    klass->props = xgmac_properties;
 }
 
 static TypeInfo xgmac_enet_info = {
hw/xilinx_axidma.c +1 -2
index 85dfcbf..710c2ca 100644
@@ -494,11 +494,10 @@ static Property axidma_properties[] = {
 
 static void axidma_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = xilinx_axidma_init;
-    dc->props = axidma_properties;
+    klass->props = axidma_properties;
 }
 
 static TypeInfo axidma_info = {
hw/xilinx_axienet.c +1 -2
index 7526273..326ce0c 100644
@@ -881,11 +881,10 @@ static Property xilinx_enet_properties[] = {
 
 static void xilinx_enet_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = xilinx_enet_init;
-    dc->props = xilinx_enet_properties;
+    klass->props = xilinx_enet_properties;
 }
 
 static TypeInfo xilinx_enet_info = {
hw/xilinx_ethlite.c +1 -2
index 857b33d..7164891 100644
@@ -235,11 +235,10 @@ static Property xilinx_ethlite_properties[] = {
 
 static void xilinx_ethlite_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = xilinx_ethlite_init;
-    dc->props = xilinx_ethlite_properties;
+    klass->props = xilinx_ethlite_properties;
 }
 
 static TypeInfo xilinx_ethlite_info = {
hw/xilinx_intc.c +1 -2
index 553f848..8acda8f 100644
@@ -168,11 +168,10 @@ static Property xilinx_intc_properties[] = {
 
 static void xilinx_intc_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = xilinx_intc_init;
-    dc->props = xilinx_intc_properties;
+    klass->props = xilinx_intc_properties;
 }
 
 static TypeInfo xilinx_intc_info = {
hw/xilinx_timer.c +1 -2
index 3ab2f2b..2e441b4 100644
@@ -227,11 +227,10 @@ static Property xilinx_timer_properties[] = {
 
 static void xilinx_timer_class_init(ObjectClass *klass, void *data)
 {
-    DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
     k->init = xilinx_timer_init;
-    dc->props = xilinx_timer_properties;
+    klass->props = xilinx_timer_properties;
 }
 
 static TypeInfo xilinx_timer_info = {
hw/xio3130_downstream.c +1 -1
index 319624f..6528af0 100644
@@ -193,7 +193,7 @@ static void xio3130_downstream_class_init(ObjectClass *klass, void *data)
     dc->desc = "TI X3130 Downstream Port of PCI Express Switch";
     dc->reset = xio3130_downstream_reset;
     dc->vmsd = &vmstate_xio3130_downstream;
-    dc->props = xio3130_downstream_properties;
+    klass->props = xio3130_downstream_properties;
 }
 
 static TypeInfo xio3130_downstream_info = {
hw/xio3130_upstream.c +1 -1
index 34a99bb..4ff5e4c 100644
@@ -167,7 +167,7 @@ static void xio3130_upstream_class_init(ObjectClass *klass, void *data)
     dc->desc = "TI X3130 Upstream Port of PCI Express Switch";
     dc->reset = xio3130_upstream_reset;
     dc->vmsd = &vmstate_xio3130_upstream;
-    dc->props = xio3130_upstream_properties;
+    klass->props = xio3130_upstream_properties;
 }
 
 static TypeInfo xio3130_upstream_info = {
hw/zaurus.c +1 -1
index 72838ec..4aca57c 100644
@@ -233,7 +233,7 @@ static void scoop_sysbus_class_init(ObjectClass *klass, void *data)
     k->init = scoop_init;
     dc->desc = "Scoop2 Sharp custom ASIC";
     dc->vmsd = &vmstate_scoop_regs;
-    dc->props = scoop_sysbus_properties;
+    klass->props = scoop_sysbus_properties;
 }
 
 static TypeInfo scoop_sysbus_info = {
include/qemu/object.h +6 -3
index f60b6b6..6db376d 100644
@@ -33,6 +33,9 @@ typedef struct TypeInfo TypeInfo;
 typedef struct InterfaceClass InterfaceClass;
 typedef struct InterfaceInfo InterfaceInfo;
 
+typedef struct Property Property;
+typedef struct PropertyInfo PropertyInfo;
+
 #define TYPE_OBJECT "object"
 
 /**
@@ -239,6 +242,9 @@ struct ObjectClass
 {
     /*< private >*/
     Type type;
+
+    /*< public >*/
+    Property *props;
 };
 
 typedef enum ObjectState {
@@ -970,9 +976,6 @@ int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),
  */
 Object *container_get(const char *path);
 
-typedef struct Property Property;
-typedef struct PropertyInfo PropertyInfo;
-
 struct Property {
     const char   *name;
     PropertyInfo *info;
qom/object.c +20 -0
index 28186d7..3a6b37b 100644
@@ -1225,10 +1225,29 @@ bool object_is_realized(Object *obj)
     return obj->state == OBJECT_STATE_REALIZED;
 }
 
+static void object_class_base_init(ObjectClass *klass, void *data)
+{
+    /* We explicitly look up properties in the superclasses,
+     * so do not propagate them to the subclasses.
+     */
+    klass->props = NULL;
+}
+
 static void object_instance_init(Object *obj)
 {
+    ObjectClass *class;
+    Property *prop;
+
     object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
     obj->state = OBJECT_STATE_CREATED;
+
+    class = object_get_class(obj);
+    do {
+        for (prop = OBJECT_CLASS(class)->props; prop && prop->name; prop++) {
+            object_property_add_static(obj, prop, NULL);
+        }
+        class = object_class_get_parent(class);
+    } while (class != object_class_by_name(TYPE_OBJECT));
 }
 
 static void register_types(void)
@@ -1242,6 +1261,7 @@ static void register_types(void)
     static TypeInfo object_info = {
         .name = TYPE_OBJECT,
         .instance_size = sizeof(Object),
+        .class_base_init = object_class_base_init,
         .instance_init = object_instance_init,
         .abstract = true,
     };
Signature · 1 line
1.7.9.3
#43 lore raw

PATCH 23/25 qom: add realized property

In reply to Paolo Bonzini

Since we had to move the state field from DeviceState to Object, we cannot delay the implementation of the "realized" property. The property is a trigger for two actions that propagate through the composition tree. "Realize" is called when the property becomes true, and propagates in pre-order; realize can fail if the values of the properties are not valid. "Unrealize" is called when the property becomes false, and propagates in post-order; unrealize cannot fail.

Unrealize is also called by object_deinit, as a separate step before finalization.

Realize/unrealize is separate from reset. Reset propagation is a thorny issue of its own. We expect classes that care to implement a reset method and call it from realize or realize_children, depending on whether pre-order or post-order is more appropriate.

This patch adds four methods (realize, realize_children, unrealize, unrealize_children) to ObjectClass, together with a default implementation of realize_children and unrealize_children.

---
 include/qemu/object.h |   20 +++++++++++
 qom/object.c          |   93 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
include/qemu/object.h +20 -0
index 6db376d..6bded2a 100644
@@ -245,6 +245,10 @@ struct ObjectClass
 
     /*< public >*/
     Property *props;
+    void (*realize)(Object *obj, struct Error **errp);
+    void (*realize_children)(Object *obj, struct Error **errp);
+    void (*unrealize)(Object *obj);
+    void (*unrealize_children)(Object *obj);
 };
 
 typedef enum ObjectState {
@@ -463,6 +467,22 @@ Object *object_new_with_type(Type type);
 void object_delete(Object *obj);
 
 /**
+ * object_realize_children:
+ * @obj: The object whose children should be realized.
+ *
+ * The default implementation of realize_children.
+ */
+void object_realize_children(Object *obj, struct Error **errp);
+
+/**
+ * object_unrealize_children:
+ * @obj: The object whose children should be unrealize.
+ *
+ * The default implementation of unrealize_children.
+ */
+void object_unrealize_children(Object *obj);
+
+/**
  * object_initialize_with_type:
  * @obj: A pointer to the memory to be used for the object.
  * @type: The type of the object to instantiate.
qom/object.c +93 -0

124 lines not on this page · raw message

Signature · 1 line
1.7.9.3
#44 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Paolo,

Am 03.04.2012 13:15, schrieb Paolo Bonzini:

Quoted 16 lines

Since we had to move the state field from DeviceState to Object, we cannot delay the implementation of the "realized" property. The property is a trigger for two actions that propagate through the composition tree. "Realize" is called when the property becomes true, and propagates in pre-order; realize can fail if the values of the properties are not valid. "Unrealize" is called when the property becomes false, and propagates in post-order; unrealize cannot fail.

Unrealize is also called by object_deinit, as a separate step before finalization.

Realize/unrealize is separate from reset. Reset propagation is a thorny issue of its own. We expect classes that care to implement a reset method and call it from realize or realize_children, depending on whether pre-order or post-order is more appropriate.

Quoted 5 lines

This patch adds four methods (realize, realize_children, unrealize, unrealize_children) to ObjectClass, together with a default implementation of realize_children and unrealize_children.

Since this patch is clearly an extended version of my realize patch
http://patchwork.ozlabs.org/patch/148752/, it should carry my SoB, as reminded last night. If you don't want my SoB on the parts I didn't do - namely unrealize and *_childen - then feel free to split the patch in two. Simply dropping attribution in both cover letter and commit just because I didn't get around yet to sending a v2 with those requests addressed is not nice!

Patch 24/25 was done differently (calling realized = true from init rather than the other way around) so this comment only applies to 23/25.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#45 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Il 03/04/2012 14:11, Andreas Färber ha scritto:

Quoted 7 lines

Since this patch is clearly an extended version of my realize patch
http://patchwork.ozlabs.org/patch/148752/, it should carry my SoB, as reminded last night. If you don't want my SoB on the parts I didn't do - namely unrealize and *_childen - then feel free to split the patch in two. Simply dropping attribution in both cover letter and commit just because I didn't get around yet to sending a v2 with those requests addressed is not nice!

Technically it's not, because I redid it from scratch (I never even had time to really look at your patches beyond reading the commit message, and I did this part while I didn't even have network access).

Paolo

#46 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Am 03.04.2012 15:03, schrieb Paolo Bonzini:

Quoted 9 lines

Il 03/04/2012 14:11, Andreas Färber ha scritto:

Quoted 7 lines

Since this patch is clearly an extended version of my realize patch
http://patchwork.ozlabs.org/patch/148752/, it should carry my SoB, as reminded last night. If you don't want my SoB on the parts I didn't do - namely unrealize and *_childen - then feel free to split the patch in two. Simply dropping attribution in both cover letter and commit just because I didn't get around yet to sending a v2 with those requests addressed is not nice!

Quoted 3 lines

Technically it's not, because I redid it from scratch (I never even had time to really look at your patches beyond reading the commit message, and I did this part while I didn't even have network access).

That's just as lame an accuse as Fabrice's when he "redid" a patch of rth back in CVS days. You were around on IRC on March 23rd when I offered to aliguori to put together a patch for realize (which I am using in my qom-cpu-sh4 series). Had you volunteered back then, I wouldn't have invested time and we wouldn't be having this discussion. But if there's something I hate more than political extremism, it's having my time wasted.

I was fair to cc you and Anthony on it, to avoid clashes between those of us working on QOM, you commented on my series, so you have read part of it; yet you announce the day before your series that you are going to send realize and ignore my request to not forget my SoB if you do. That makes me think that you're deliberately trying to keep my code contribution out of the picture there, whereas Anthony has stated in the context of unicore32 that rewriting someone's contribution to get that person's authorship out of the way were not acceptable.

Apart from the personal disrespect this implies here, it's also about me wanting to prove my bosses that I don't just sit in an arm chair or write useless crap. My patch is available under GPLv2+ allowing anyone to freely modify and reuse that code but doing so without copyright and authorship attribution is in violation of the license. I respect people's contributions and am all in favor of documenting people's effort with Reported-by, Tested-by, Reviewed-by, and I expect that others respect mine too.

You had me write a trivial follow-up to your series, which I did now, so you should consider living to the same standard and following up on mine.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#47 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Il 05/04/2012 14:04, Andreas Färber ha scritto:

Quoted 10 lines

Am 03.04.2012 15:03, schrieb Paolo Bonzini:

Quoted 9 lines

Il 03/04/2012 14:11, Andreas Färber ha scritto:

Quoted 7 lines

Since this patch is clearly an extended version of my realize patch
http://patchwork.ozlabs.org/patch/148752/, it should carry my SoB, as reminded last night. If you don't want my SoB on the parts I didn't do - namely unrealize and *_childen - then feel free to split the patch in two. Simply dropping attribution in both cover letter and commit just because I didn't get around yet to sending a v2 with those requests addressed is not nice!

Quoted 5 lines
Quoted 3 lines

Technically it's not, because I redid it from scratch (I never even had time to really look at your patches beyond reading the commit message, and I did this part while I didn't even have network access).

That's just as lame an accuse

(Did you mean excuse?) It's a fact, not an excuse. Do I need to show the two patches side-by-side? That would be even more ridiculous.

But I can very well add a SoB on v2.

Quoted 1 line

as Fabrice's when he "redid" a patch of rth back in CVS days.

Wasn't there, sorry.

Quoted 3 lines

You were around on IRC on March 23rd when I
offered to aliguori to put together a patch for realize (which I am using in my qom-cpu-sh4 series).

Well, I'm always around, that doesn't mean I always have time to read it.

Quoted 8 lines

I was fair to cc you and Anthony on it, to avoid clashes between those of us working on QOM, you commented on my series, so you have read part of it; yet you announce the day before your series that you are going to send realize and ignore my request to not forget my SoB if you do. That makes me think that you're deliberately trying to keep my code contribution out of the picture there, whereas Anthony has stated in the context of unicore32 that rewriting someone's contribution to get that person's authorship out of the way were not acceptable.

You're assuming I read your patches, which is not the case beyond seeing that the realize didn't propagate. There's really nothing deliberate, and it's quite surprising to me to hear tones escalating so quickly.

Paolo

#48 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Am 05.04.2012 14:36, schrieb Paolo Bonzini:

Quoted 11 lines

Il 05/04/2012 14:04, Andreas Färber ha scritto:

Quoted 10 lines

Am 03.04.2012 15:03, schrieb Paolo Bonzini:

Quoted 9 lines

Il 03/04/2012 14:11, Andreas Färber ha scritto:

Quoted 7 lines

Since this patch is clearly an extended version of my realize patch
http://patchwork.ozlabs.org/patch/148752/, it should carry my SoB, as reminded last night. If you don't want my SoB on the parts I didn't do - namely unrealize and *_childen - then feel free to split the patch in two. Simply dropping attribution in both cover letter and commit just because I didn't get around yet to sending a v2 with those requests addressed is not nice!

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Technically it's not, because I redid it from scratch (I never even had time to really look at your patches beyond reading the commit message, and I did this part while I didn't even have network access).

That's just as lame an accuse

(Did you mean excuse?)

Yes.

Quoted 2 lines

It's a fact, not an excuse. Do I need to show
the two patches side-by-side? That would be even more ridiculous.

Here's how I see it:

* You add a realize callback to ObjectClass like I did, you add the Error** parameter that was requested as feedback to mine.
* You add a static object_realize() method that clashes with my introducing it as a public wrapper function.
* You introduce a function object_get_realized() like I did, only you defer your implementation to object_is_realized() which I didn't have and used a new bool realized instead of a state enum (since I left qdev unmodified).
* You introduce a function object_set_realized() like I did, only you change the logic to also do unrealize.
* You introduce additional stuff that I don't particularly care about.

So my point is, whether you've read some patch or not, I just can't understand why you couldn't wait a week for me to resend the updated version and rush it so much that you ignore existing patches that were actually coordinated with Anthony
(https://github.com/afaerber/qemu-cpu/commit/bc78ab1c0e4ba375bc5942447644323281184a31
on qom-cpu-sh4 branch already incorporates pm215's wish of a dedicated QERR, f.ex.).

While having unrealize and propagation is certainly nice, the most serious issue with yours I see is that it doesn't offer me a way to actually make use of it outside qdev, so that *I* am left with no benefit from your patch!

Some practical thoughts on how to align both approaches would be helpful here. For starters, should I name my function object_realize_nofail() instead? And could you prefer _one over _1 in your patch please?

If your problem is Signed-off-by specifically, feel free to invent some inofficial tag such as Inspired-by or Derived-from-commit-message-by or resort to a textual reference.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#49 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Il 05/04/2012 15:31, Andreas Färber ha scritto:

Quoted 13 lines

Here's how I see it:

* You add a realize callback to ObjectClass like I did, you add the Error** parameter that was requested as feedback to mine.
* You add a static object_realize() method that clashes with my introducing it as a public wrapper function.
* You introduce a function object_get_realized() like I did, only you defer your implementation to object_is_realized() which I didn't have and used a new bool realized instead of a state enum (since I left qdev unmodified).
* You introduce a function object_set_realized() like I did, only you change the logic to also do unrealize.
* You introduce additional stuff that I don't particularly care about.

Since we're nitpicking, I also do correct error propagation.

Quoted 3 lines

So my point is, whether you've read some patch or not, I just can't understand why you couldn't wait a week for me to resend the updated version

Because a week is a long time 10 days before the feature freeze, and (via object_is_realized and a few other small bits) the whole series depends on the implementation of realized.

Quoted 4 lines

While having unrealize and propagation is certainly nice, the most serious issue with yours I see is that it doesn't offer me a way to actually make use of it outside qdev, so that *I* am left with no benefit from your patch!

Can you explain? I definitely would need to fix this.

Quoted 3 lines

Some practical thoughts on how to align both approaches would be helpful here. For starters, should I name my function object_realize_nofail() instead?

Yes, that would be an idea. I would hope that long-term there would be only one object_realize call during in initial machine creation (i.e. except for hot-plug), but it would be fine as a start.

Quoted 1 line

And could you prefer _one over _1 in your patch please?

Yes.

Quoted 3 lines

If your problem is Signed-off-by specifically, feel free to invent some inofficial tag such as Inspired-by or Derived-from-commit-message-by or resort to a textual reference.

I can add the SoB, no problem.

Paolo

#50 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Hi,

I'm about to board a plane but I at least want to comment that we should all give each other the benefit of the doubt in a situation like this. Everyone on this thread is a long term contributer to QEMU that has more than earned the right not to be accussed of impropriety. Let's all take a deep breathe and tone down this discussion in this thread by assuming that noone is intentionally doing anything wrong

Quoted 52 lines · Paolo Bonzini

Il 05/04/2012 15:31, Andreas Färber ha scritto:

Quoted 13 lines

Here's how I see it:

* You add a realize callback to ObjectClass like I did, you add the Error** parameter that was requested as feedback to mine.
* You add a static object_realize() method that clashes with my introducing it as a public wrapper function.
* You introduce a function object_get_realized() like I did, only you defer your implementation to object_is_realized() which I didn't have and used a new bool realized instead of a state enum (since I left qdev unmodified).
* You introduce a function object_set_realized() like I did, only you change the logic to also do unrealize.
* You introduce additional stuff that I don't particularly care about.

Since we're nitpicking, I also do correct error propagation.

Quoted 3 lines

So my point is, whether you've read some patch or not, I just can't understand why you couldn't wait a week for me to resend the updated version

Because a week is a long time 10 days before the feature freeze, and (via object_is_realized and a few other small bits) the whole series depends on the implementation of realized.

Quoted 4 lines

While having unrealize and propagation is certainly nice, the most serious issue with yours I see is that it doesn't offer me a way to actually make use of it outside qdev, so that *I* am left with no benefit from your patch!

Can you explain? I definitely would need to fix this.

Quoted 3 lines

Some practical thoughts on how to align both approaches would be helpful here. For starters, should I name my function object_realize_nofail() instead?

Yes, that would be an idea. I would hope that long-term there would be only one object_realize call during in initial machine creation (i.e. except for hot-plug), but it would be fine as a start.

Quoted 1 line

And could you prefer _one over _1 in your patch please?

Yes.

Quoted 3 lines

If your problem is Signed-off-by specifically, feel free to invent some inofficial tag such as Inspired-by or Derived-from-commit-message-by or resort to a textual reference.

I can add the SoB, no problem.

Paolo

#51 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

In reply to Paolo Bonzini

Hi Paolo,

Are you plannig to respin this and related patches? If yes, when?

Quoted 200 lines · Paolo Bonzini

Since we had to move the state field from DeviceState to Object, we cannot delay the implementation of the "realized" property. The property is a trigger for two actions that propagate through the composition tree. "Realize" is called when the property becomes true, and propagates in pre-order; realize can fail if the values of the properties are not valid. "Unrealize" is called when the property becomes false, and propagates in post-order; unrealize cannot fail.

Unrealize is also called by object_deinit, as a separate step before finalization.

Realize/unrealize is separate from reset. Reset propagation is a thorny issue of its own. We expect classes that care to implement a reset method and call it from realize or realize_children, depending on whether pre-order or post-order is more appropriate.

This patch adds four methods (realize, realize_children, unrealize, unrealize_children) to ObjectClass, together with a default implementation of realize_children and unrealize_children.

---
 include/qemu/object.h |   20 +++++++++++
 qom/object.c          |   93 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
include/qemu/object.h +20 -0
index 6db376d..6bded2a 100644
@@ -245,6 +245,10 @@ struct ObjectClass
 
     /*< public >*/
     Property *props;
+    void (*realize)(Object *obj, struct Error **errp);
+    void (*realize_children)(Object *obj, struct Error **errp);
+    void (*unrealize)(Object *obj);
+    void (*unrealize_children)(Object *obj);
 };
 
 typedef enum ObjectState {
@@ -463,6 +467,22 @@ Object *object_new_with_type(Type type);
 void object_delete(Object *obj);
 
 /**
+ * object_realize_children:
+ * @obj: The object whose children should be realized.
+ *
+ * The default implementation of realize_children.
+ */
+void object_realize_children(Object *obj, struct Error **errp);
+
+/**
+ * object_unrealize_children:
+ * @obj: The object whose children should be unrealize.
+ *
+ * The default implementation of unrealize_children.
+ */
+void object_unrealize_children(Object *obj);
+
+/**
  * object_initialize_with_type:
  * @obj: A pointer to the memory to be used for the object.
  * @type: The type of the object to instantiate.
qom/object.c +93 -0
index 3a6b37b..2a3753a 100644
@@ -259,6 +259,87 @@ static void object_interface_init(Object *obj, InterfaceImpl *iface)
     obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
 }
 
+static void object_get_realized(Object *obj, Visitor *v, void *opaque,
+                                const char *name, Error **errp)
+{
+    bool value = object_is_realized(obj);
+
+    visit_type_bool(v, &value, name, errp);
+}
+
+static void object_unrealize(Object *obj)
+{
+    ObjectClass *klass = object_get_class(obj);
+
+    if (klass->unrealize_children) {
+        klass->unrealize_children(obj);
+    }
+    if (obj->state != OBJECT_STATE_CREATED && klass->unrealize) {
+        klass->unrealize(obj);
+    }
+    obj->state = OBJECT_STATE_CREATED;
+}
+
+static int object_unrealize_1(Object *obj, void *unused)
+{
+    object_unrealize(obj);
+    return 0;
+}
+
+void object_unrealize_children(Object *obj)
+{
+    object_child_foreach(obj, object_unrealize_1, NULL);
+}
+
+static void object_realize(Object *obj, Error **errp)
+{
+    ObjectClass *klass = object_get_class(obj);
+
+    if (obj->state != OBJECT_STATE_REALIZED && klass->realize) {
+        klass->realize(obj, errp);
+    }
+    obj->state = OBJECT_STATE_REALIZED;
+    if (klass->realize_children) {
+        klass->realize_children(obj, errp);
+    }
+}
+
+static int object_realize_1(Object *obj, void *errp)
+{
+    Error *err = NULL;
+    object_realize(obj, &err);
+    if (err) {
+        error_propagate((Error **)errp, err);
+        return 1;
+    }
+
+    return 0;
+}
+
+void object_realize_children(Object *obj, Error **errp)
+{
+    object_child_foreach(obj, object_realize_1, errp);
+}
+
+static void object_set_realized(Object *obj, Visitor *v, void *opaque,
+                                const char *name, Error **errp)
+{
+    bool value;
+    Error *err = NULL;
+
+    visit_type_bool(v, &value, name, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    if (value) {
+        object_realize(obj, errp);
+    } else {
+        object_unrealize(obj);
+    }
+}
+
 static void object_init_with_type(Object *obj, TypeImpl *ti)
 {
     int i;
@@ -337,6 +418,8 @@ void object_unparent(Object *obj)
 
 static void object_deinit(Object *obj, TypeImpl *type)
 {
+    object_property_set_bool(obj, false, "realized", NULL);
+
     if (type->instance_finalize) {
         type->instance_finalize(obj);
     }
@@ -1239,7 +1322,10 @@ static void object_instance_init(Object *obj)
     Property *prop;
 
     object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
+
     obj->state = OBJECT_STATE_CREATED;
+    object_property_add(obj, "realized", "bool", object_get_realized,
+                        object_set_realized, NULL, NULL, NULL);
 
     class = object_get_class(obj);
     do {
@@ -1250,6 +1336,12 @@ static void object_instance_init(Object *obj)
     } while (class != object_class_by_name(TYPE_OBJECT));
 }
 
+static void object_class_init(ObjectClass *klass, void *class_data)
+{
+    klass->realize_children = object_realize_children;
+    klass->unrealize_children = object_unrealize_children;
+}
+
 static void register_types(void)
 {
     static TypeInfo interface_info = {
@@ -1262,6 +1354,7 @@ static void register_types(void)
         .name = TYPE_OBJECT,
         .instance_size = sizeof(Object),
         .class_base_init = object_class_base_init,
+        .class_init = object_class_init,
         .instance_init = object_instance_init,
         .abstract = true,
     };
Signature · 1 line
1.7.9.3
#52 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Il 09/05/2012 22:01, Igor Mammedov ha scritto:

Quoted 4 lines

Hi Paolo,

Are you plannig to respin this and related patches? If yes, when?

After the first part goes in (21 patches including Anthony's bus series). A reviewed-by from Andreas or Anthony would help, so that I can make Andreas's suggested documentation changes and send a pull request to someone.

Andreas, would you object to being honorary maintainer of qom-next for this month?

Paolo

#53 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Am 10.05.2012 09:05, schrieb Paolo Bonzini:

Quoted 6 lines

Il 09/05/2012 22:01, Igor Mammedov ha scritto:

Quoted 4 lines

Hi Paolo,

Are you plannig to respin this and related patches? If yes, when?

Quoted 7 lines

After the first part goes in (21 patches including Anthony's bus series). A reviewed-by from Andreas or Anthony would help, so that I can make Andreas's suggested documentation changes and send a pull request to someone.

Andreas, would you object to being honorary maintainer of qom-next for this month?

Sometimes there's so many trees that one doesn't see the forrest... I brought that topic up in
http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00926.html:

Quoted 4 lines

there's more and more colliding patch series on the list - fixed-width visitors, realize, QBus, VMState, AREG0, CPU - for which we need a strategy to coordinate our ongoing development and post-1.1 merging. Someone needs to rebase on someone else, question is whom.

If Anthony is okay with me maintaining a qom-next branch then I'd happily do that! It doesn't relieve us of reviewing and acking each other's patches though. And in particular we need to figure out how to proceed with your and Anthony's series - I have stated opinions on some parts, but it's Anthony's baby.

Also, I still think there's at least one patch in your series that should go into 1.1 (the -device fix thingy).

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#54 lore raw

Re: [Qemu-devel] [PATCH 23/25] qom: add realized property

Quoted 24 lines · Andreas Färber

Am 10.05.2012 09:05, schrieb Paolo Bonzini:

Quoted 6 lines

Il 09/05/2012 22:01, Igor Mammedov ha scritto:

Quoted 4 lines

Hi Paolo,

Are you plannig to respin this and related patches? If yes, when?

Quoted 7 lines

After the first part goes in (21 patches including Anthony's bus series). A reviewed-by from Andreas or Anthony would help, so that I can make Andreas's suggested documentation changes and send a pull request to someone.

Andreas, would you object to being honorary maintainer of qom-next for this month?

Sometimes there's so many trees that one doesn't see the forrest... I brought that topic up in
http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00926.html:

Quoted 4 lines

there's more and more colliding patch series on the list - fixed-width visitors, realize, QBus, VMState, AREG0, CPU - for which we need a strategy to coordinate our ongoing development and post-1.1 merging. Someone needs to rebase on someone else, question is whom.

Quoted 5 lines

If Anthony is okay with me maintaining a qom-next branch then I'd happily do that! It doesn't relieve us of reviewing and acking each other's patches though. And in particular we need to figure out how to proceed with your and Anthony's series - I have stated opinions on some parts, but it's Anthony's baby.

Yeah, I'd be more than happy with you maintaining a qom-next tree.

Regards,

Anthony Liguori

Quoted 6 lines

Also, I still think there's at least one patch in your series that should go into 1.1 (the -device fix thingy).

Andreas

#55 lore raw

PATCH 24/25 qdev: implement qdev_init on top of realize

In reply to Paolo Bonzini

Switch the qdev_init function to simply set the "realized" property to true. The old contents of qdev_init become the realize and realize_children methods.

---
 hw/qdev.c |   36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)
hw/qdev.c +30 -6
index d9f811f..e674248 100644
@@ -119,17 +119,17 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
    calling this function.
    On failure, destroy the device and return negative value.
    Return 0 on success.  */
-int qdev_init(DeviceState *dev)
+static void device_realize(Object *obj, Error **errp)
 {
+    DeviceState *dev = DEVICE(obj);
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
     int rc;
 
-    assert(!object_is_realized(OBJECT(dev)));
-
     rc = dc->init(dev);
     if (rc < 0) {
         qdev_free(dev);
-        return rc;
+        error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
+        return;
     }
 
     if (!OBJECT(dev)->parent) {
@@ -146,11 +146,28 @@ int qdev_init(DeviceState *dev)
                                        dev->instance_id_alias,
                                        dev->alias_required_for_version);
     }
-    OBJECT(dev)->state = OBJECT_STATE_REALIZED;
+}
+
+static void device_realize_children(Object *obj, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Error *err = NULL;
+
+    object_realize_children(OBJECT(dev), &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
     if (dev->hotplugged) {
         device_reset(dev);
     }
-    return 0;
+}
+
+int qdev_init(DeviceState *dev)
+{
+    Error *err = NULL;
+    object_property_set_bool(OBJECT(dev), true, "realized", &err);
+    return err ? -EINVAL : 0;
 }
 
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
@@ -628,6 +645,12 @@ Object *qdev_get_machine(void)
     return dev;
 }
 
+static void device_class_init(ObjectClass *klass, void *data)
+{
+    klass->realize = device_realize;
+    klass->realize_children = device_realize_children;
+}
+
 static TypeInfo device_type_info = {
     .name = TYPE_DEVICE,
     .parent = TYPE_OBJECT,
@@ -636,6 +659,7 @@ static TypeInfo device_type_info = {
     .instance_finalize = device_finalize,
     .abstract = true,
     .class_size = sizeof(DeviceClass),
+    .class_init = device_class_init,
 };
 
 static void qdev_register_types(void)
Signature · 1 line
1.7.9.3
#56 lore raw

PATCH 25/25 qdev: split part of device_finalize to device_unrealize

In reply to Paolo Bonzini
---
 hw/qdev.c |   35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)
hw/qdev.c +20 -15
index e674248..45f1133 100644
@@ -601,27 +601,31 @@ static void device_initfn(Object *obj)
 }
 
 /* Unlink device from bus and free the structure.  */
-static void device_finalize(Object *obj)
+static void device_unrealize(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
     BusState *bus;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (object_is_realized(obj)) {
-        while (dev->num_child_bus) {
-            bus = QLIST_FIRST(&dev->child_bus);
-            qbus_free(bus);
-        }
-        if (qdev_get_vmsd(dev)) {
-            vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
-        }
-        if (dc->exit) {
-            dc->exit(dev);
-        }
-        if (dev->opts) {
-            qemu_opts_del(dev->opts);
-        }
+    while (dev->num_child_bus) {
+        bus = QLIST_FIRST(&dev->child_bus);
+        qbus_free(bus);
+    }
+    if (qdev_get_vmsd(dev)) {
+        vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
     }
+    if (dc->exit) {
+        dc->exit(dev);
+    }
+    if (dev->opts) {
+        qemu_opts_del(dev->opts);
+    }
+}
+
+static void device_finalize(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
     QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
 }
 
@@ -649,6 +653,7 @@ static void device_class_init(ObjectClass *klass, void *data)
 {
     klass->realize = device_realize;
     klass->realize_children = device_realize_children;
+    klass->unrealize = device_unrealize;
 }
 
 static TypeInfo device_type_info = {
Signature · 1 line
1.7.9.3