Patchwork [v2,22/27] qdev: access properties via QOM

login
register
mail settings
Submitter Paolo Bonzini
Date Feb. 4, 2012, 8:02 a.m.
Message ID <1328342577-25732-23-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/139561/
State New
Headers show

Comments

Paolo Bonzini - Feb. 4, 2012, 8:02 a.m.
Do not poke anymore in the struct when accessing qdev properties.
Instead, ask the object to set the right value.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev-addr.c       |    5 ++-
 hw/qdev-properties.c |   78 ++++++++++++++++++++++++++++++++++---------------
 hw/qdev.h            |    4 +--
 3 files changed, 59 insertions(+), 28 deletions(-)
Anthony Liguori - Feb. 6, 2012, 2:36 p.m.
On 02/04/2012 02:02 AM, Paolo Bonzini wrote:
> Do not poke anymore in the struct when accessing qdev properties.
> Instead, ask the object to set the right value.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   hw/qdev-addr.c       |    5 ++-
>   hw/qdev-properties.c |   78 ++++++++++++++++++++++++++++++++++---------------
>   hw/qdev.h            |    4 +--
>   3 files changed, 59 insertions(+), 28 deletions(-)
>
> diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
> index 5976dcd..8daa733 100644
> --- a/hw/qdev-addr.c
> +++ b/hw/qdev-addr.c
> @@ -71,5 +71,8 @@ PropertyInfo qdev_prop_taddr = {
>
>   void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_TADDR);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
> +
>   }
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index debb37f..5a11676 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -1115,7 +1115,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
>       return 0;
>   }
>
> -void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
> +static void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
>   {
>       Property *prop;
>
> @@ -1135,52 +1135,63 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
>
>   void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_BIT);
> +    Error *errp = NULL;
> +    object_property_set_bool(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_UINT8);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_UINT16);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_UINT32);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_INT32);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_UINT64);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_STRING);
> +    Error *errp = NULL;
> +    object_property_set_str(OBJECT(dev), value, name,&errp);
> +    assert(!errp);
>   }
>
>   int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
>   {
> -    int res;
> -
> -    res = bdrv_attach_dev(value, dev);
> -    if (res<  0) {
> -        error_report("Can't attach drive %s to %s.%s: %s",
> -                     bdrv_get_device_name(value),
> -                     dev->id ? dev->id : object_get_typename(OBJECT(dev)),
> -                     name, strerror(-res));
> +    Error *errp = NULL;
> +    object_property_set_str(OBJECT(dev), bdrv_get_device_name(value),
> +                            name,&errp);
> +    if (errp) {
> +        qerror_report_err(errp);
> +        error_free(errp);
>           return -1;
>       }
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_DRIVE);
>       return 0;
>   }
>
> @@ -1192,28 +1203,47 @@ void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverS
>   }
>   void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_CHR);
> +    Error *errp = NULL;
> +    assert(value->label);
> +    object_property_set_str(OBJECT(dev), value->label, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_NETDEV);
> +    Error *errp = NULL;
> +    assert(value->name);
> +    object_property_set_str(OBJECT(dev), value->name, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
>   {
> -    qdev_prop_set(dev, name,&value, PROP_TYPE_VLAN);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value ? value->id : -1, name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
>   {
> -    qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
> +    Error *errp = NULL;
> +    char str[2 * 6 + 5 + 1];
> +    snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
> +             value[0], value[1], value[2], value[3], value[4], value[5]);
> +
> +    object_property_set_str(OBJECT(dev), str, name,&errp);
> +    assert(!errp);
>   }
>
> -void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
> -                                  LostTickPolicy *value)
> +void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
>   {
> -    qdev_prop_set(dev, name, value, PROP_TYPE_LOSTTICKPOLICY);
> +    Property *prop;
> +    Error *errp = NULL;
> +
> +    prop = qdev_prop_find(dev, name);
> +    object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
> +                            name,&errp);
> +    assert(!errp);
>   }
>
>   void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
> diff --git a/hw/qdev.h b/hw/qdev.h
> index acccf26..9ccd5c3 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -310,7 +310,6 @@ extern PropertyInfo qdev_prop_pci_devfn;
>   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(DeviceState *dev, const char *name, void *src, enum PropertyType type);
>   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);
>   void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
> @@ -324,8 +323,7 @@ void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
>   int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
>   void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
>   void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
> -void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
> -                                  LostTickPolicy *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);
Blue Swirl - Feb. 11, 2012, 3:46 p.m.
On Sat, Feb 4, 2012 at 08:02, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Do not poke anymore in the struct when accessing qdev properties.
> Instead, ask the object to set the right value.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/qdev-addr.c       |    5 ++-
>  hw/qdev-properties.c |   78 ++++++++++++++++++++++++++++++++++---------------
>  hw/qdev.h            |    4 +--
>  3 files changed, 59 insertions(+), 28 deletions(-)
>
> diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
> index 5976dcd..8daa733 100644
> --- a/hw/qdev-addr.c
> +++ b/hw/qdev-addr.c
> @@ -71,5 +71,8 @@ PropertyInfo qdev_prop_taddr = {
>
>  void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_TADDR);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
> +
>  }
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index debb37f..5a11676 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -1115,7 +1115,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
>     return 0;
>  }
>
> -void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
> +static void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
>  {
>     Property *prop;
>
> @@ -1135,52 +1135,63 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
>
>  void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_BIT);
> +    Error *errp = NULL;
> +    object_property_set_bool(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT8);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_INT32);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_STRING);
> +    Error *errp = NULL;
> +    object_property_set_str(OBJECT(dev), value, name, &errp);
> +    assert(!errp);
>  }
>
>  int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
>  {
> -    int res;
> -
> -    res = bdrv_attach_dev(value, dev);
> -    if (res < 0) {
> -        error_report("Can't attach drive %s to %s.%s: %s",
> -                     bdrv_get_device_name(value),
> -                     dev->id ? dev->id : object_get_typename(OBJECT(dev)),
> -                     name, strerror(-res));
> +    Error *errp = NULL;
> +    object_property_set_str(OBJECT(dev), bdrv_get_device_name(value),
> +                            name, &errp);
> +    if (errp) {
> +        qerror_report_err(errp);
> +        error_free(errp);
>         return -1;
>     }
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE);
>     return 0;
>  }
>
> @@ -1192,28 +1203,47 @@ void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverS
>  }
>  void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
> +    Error *errp = NULL;
> +    assert(value->label);

This breaks Sparc32 and PPC:
Program received signal SIGSEGV, Segmentation fault.
qdev_prop_set_chr (dev=0x157e170, name=0x5bda5f "chrB", value=0x0)
    at /src/qemu/hw/qdev-properties.c:1142
1142        assert(value->label);
(gdb) bt
#0  qdev_prop_set_chr (dev=0x157e170, name=0x5bda5f "chrB", value=0x0)
    at /src/qemu/hw/qdev-properties.c:1142
#1  0x000000000046e1af in slavio_serial_ms_kbd_init (base=1895825408,
    irq=0x11cdab0, disabled=0, clock=4915200, it_shift=1)
    at /src/qemu/hw/escc.c:859
#2  0x000000000054117d in sun4m_hw_init (hwdef=0x5ef660, RAM_size=134217728,
    boot_device=<value optimized out>, kernel_filename=<value optimized out>,
    kernel_cmdline=0x57ade2 "", initrd_filename=<value optimized out>,
    cpu_model=0x0) at /src/qemu/hw/sun4m.c:961
#3  0x00000000005419d1 in ss5_init (RAM_size=<value optimized out>,
    boot_device=<value optimized out>, kernel_filename=<value optimized out>,
    kernel_cmdline=<value optimized out>,
    initrd_filename=<value optimized out>, cpu_model=<value optimized out>)
    at /src/qemu/hw/sun4m.c:1317
#4  0x0000000000481a3e in main (argc=<value optimized out>,
    argv=<value optimized out>, envp=<value optimized out>)
    at /src/qemu/vl.c:3391

Program received signal SIGSEGV, Segmentation fault.
qdev_prop_set_chr (dev=0x1365580, name=0x6ed811 "chrB", value=0x0)
    at /src/qemu/hw/qdev-properties.c:1142
1142        assert(value->label);
(gdb) bt
#0  qdev_prop_set_chr (dev=0x1365580, name=0x6ed811 "chrB", value=0x0)
    at /src/qemu/hw/qdev-properties.c:1142
#1  0x000000000048b484 in escc_init (base=0, irqA=0x12deb48, irqB=0x12deb60,
    chrA=0x128ff60, chrB=0x0, clock=<value optimized out>, it_shift=4)
    at /src/qemu/hw/escc.c:698
#2  0x00000000005ab173 in ppc_heathrow_init (ram_size=134217728,
    boot_device=<value optimized out>, kernel_filename=0x0,
    kernel_cmdline=<value optimized out>,
    initrd_filename=<value optimized out>, cpu_model=<value optimized out>)
    at /src/qemu/hw/ppc_oldworld.c:246
#3  0x00000000004d9a8e in main (argc=<value optimized out>,
    argv=<value optimized out>, envp=<value optimized out>)
    at /src/qemu/vl.c:3391

This is running qemu-system-sparc and qemu-system-ppc with no arguments.

> +    object_property_set_str(OBJECT(dev), value->label, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
> +    Error *errp = NULL;
> +    assert(value->name);
> +    object_property_set_str(OBJECT(dev), value->name, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
>  {
> -    qdev_prop_set(dev, name, &value, PROP_TYPE_VLAN);
> +    Error *errp = NULL;
> +    object_property_set_int(OBJECT(dev), value ? value->id : -1, name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
>  {
> -    qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
> +    Error *errp = NULL;
> +    char str[2 * 6 + 5 + 1];
> +    snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
> +             value[0], value[1], value[2], value[3], value[4], value[5]);
> +
> +    object_property_set_str(OBJECT(dev), str, name, &errp);
> +    assert(!errp);
>  }
>
> -void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
> -                                  LostTickPolicy *value)
> +void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
>  {
> -    qdev_prop_set(dev, name, value, PROP_TYPE_LOSTTICKPOLICY);
> +    Property *prop;
> +    Error *errp = NULL;
> +
> +    prop = qdev_prop_find(dev, name);
> +    object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
> +                            name, &errp);
> +    assert(!errp);
>  }
>
>  void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
> diff --git a/hw/qdev.h b/hw/qdev.h
> index acccf26..9ccd5c3 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -310,7 +310,6 @@ extern PropertyInfo qdev_prop_pci_devfn;
>  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(DeviceState *dev, const char *name, void *src, enum PropertyType type);
>  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);
>  void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
> @@ -324,8 +323,7 @@ void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
>  int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
>  void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
>  void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
> -void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
> -                                  LostTickPolicy *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);
> --
> 1.7.7.6
>
>
>
Paolo Bonzini - Feb. 13, 2012, 7:53 a.m.
On 02/11/2012 04:46 PM, Blue Swirl wrote:
> Program received signal SIGSEGV, Segmentation fault.
> qdev_prop_set_chr (dev=0x1365580, name=0x6ed811 "chrB", value=0x0)
>     at /src/qemu/hw/qdev-properties.c:1142
> 1142        assert(value->label);
> (gdb) bt
> #0  qdev_prop_set_chr (dev=0x1365580, name=0x6ed811 "chrB", value=0x0)
>     at /src/qemu/hw/qdev-properties.c:1142
> #1  0x000000000048b484 in escc_init (base=0, irqA=0x12deb48, irqB=0x12deb60,
>     chrA=0x128ff60, chrB=0x0, clock=<value optimized out>, it_shift=4)
>     at /src/qemu/hw/escc.c:698
> #2  0x00000000005ab173 in ppc_heathrow_init (ram_size=134217728,
>     boot_device=<value optimized out>, kernel_filename=0x0,
>     kernel_cmdline=<value optimized out>,
>     initrd_filename=<value optimized out>, cpu_model=<value optimized out>)
>     at /src/qemu/hw/ppc_oldworld.c:246
> #3  0x00000000004d9a8e in main (argc=<value optimized out>,
>     argv=<value optimized out>, envp=<value optimized out>)
>     at /src/qemu/vl.c:3391
>
> This is running qemu-system-sparc and qemu-system-ppc with no arguments.

Will fix, thanks for reporting.

Paolo

Patch

diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
index 5976dcd..8daa733 100644
--- a/hw/qdev-addr.c
+++ b/hw/qdev-addr.c
@@ -71,5 +71,8 @@  PropertyInfo qdev_prop_taddr = {
 
 void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_TADDR);
+    Error *errp = NULL;
+    object_property_set_int(OBJECT(dev), value, name, &errp);
+    assert(!errp);
+
 }
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index debb37f..5a11676 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -1115,7 +1115,7 @@  int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
     return 0;
 }
 
-void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
+static void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
 {
     Property *prop;
 
@@ -1135,52 +1135,63 @@  void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
 
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_BIT);
+    Error *errp = NULL;
+    object_property_set_bool(OBJECT(dev), value, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT8);
+    Error *errp = NULL;
+    object_property_set_int(OBJECT(dev), value, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16);
+    Error *errp = NULL;
+    object_property_set_int(OBJECT(dev), value, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32);
+    Error *errp = NULL;
+    object_property_set_int(OBJECT(dev), value, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_INT32);
+    Error *errp = NULL;
+    object_property_set_int(OBJECT(dev), value, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64);
+    Error *errp = NULL;
+    object_property_set_int(OBJECT(dev), value, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_string(DeviceState *dev, const char *name, char *value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_STRING);
+    Error *errp = NULL;
+    object_property_set_str(OBJECT(dev), value, name, &errp);
+    assert(!errp);
 }
 
 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
 {
-    int res;
-
-    res = bdrv_attach_dev(value, dev);
-    if (res < 0) {
-        error_report("Can't attach drive %s to %s.%s: %s",
-                     bdrv_get_device_name(value),
-                     dev->id ? dev->id : object_get_typename(OBJECT(dev)),
-                     name, strerror(-res));
+    Error *errp = NULL;
+    object_property_set_str(OBJECT(dev), bdrv_get_device_name(value),
+                            name, &errp);
+    if (errp) {
+        qerror_report_err(errp);
+        error_free(errp);
         return -1;
     }
-    qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE);
     return 0;
 }
 
@@ -1192,28 +1203,47 @@  void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverS
 }
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
+    Error *errp = NULL;
+    assert(value->label);
+    object_property_set_str(OBJECT(dev), value->label, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
+    Error *errp = NULL;
+    assert(value->name);
+    object_property_set_str(OBJECT(dev), value->name, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
 {
-    qdev_prop_set(dev, name, &value, PROP_TYPE_VLAN);
+    Error *errp = NULL;
+    object_property_set_int(OBJECT(dev), value ? value->id : -1, name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
 {
-    qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
+    Error *errp = NULL;
+    char str[2 * 6 + 5 + 1];
+    snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
+             value[0], value[1], value[2], value[3], value[4], value[5]);
+
+    object_property_set_str(OBJECT(dev), str, name, &errp);
+    assert(!errp);
 }
 
-void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
-                                  LostTickPolicy *value)
+void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
 {
-    qdev_prop_set(dev, name, value, PROP_TYPE_LOSTTICKPOLICY);
+    Property *prop;
+    Error *errp = NULL;
+
+    prop = qdev_prop_find(dev, name);
+    object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
+                            name, &errp);
+    assert(!errp);
 }
 
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
diff --git a/hw/qdev.h b/hw/qdev.h
index acccf26..9ccd5c3 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -310,7 +310,6 @@  extern PropertyInfo qdev_prop_pci_devfn;
 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(DeviceState *dev, const char *name, void *src, enum PropertyType type);
 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);
 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
@@ -324,8 +323,7 @@  void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
-void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
-                                  LostTickPolicy *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);