Patchwork [v2] qerror: Add QERR_PROPERTY_SET_AFTER_REALIZE

login
register
mail settings
Submitter Peter Maydell
Date July 16, 2012, 3:25 p.m.
Message ID <1342452355-9341-1-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/171222/
State New
Headers show

Comments

Peter Maydell - July 16, 2012, 3:25 p.m.
Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts
to set a QOM or qdev property after the object/device has been
realized. This allows a slightly more informative diagnostic
than the previous "permission denied" message.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Changes since the v1 (which was sent way back in March...):
 * rebased on master now a pile of qdev/qom changesd have landed
 * fixed some overlong lines
 * avoid gcc '?:' extension
 * a couple of set_ functions in qdev-properties.c are new since v1
   and needed their QERR_PERMISSION_DENIED checks changing

 hw/qdev-properties.c |   42 ++++++++++++++++++++++++++++--------------
 qerror.c             |    5 +++++
 qerror.h             |    3 +++
 3 files changed, 36 insertions(+), 14 deletions(-)
Andreas Färber - July 18, 2012, 10:20 a.m.
Am 16.07.2012 17:25, schrieb Peter Maydell:
> Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts
> to set a QOM or qdev property after the object/device has been
> realized. This allows a slightly more informative diagnostic
> than the previous "permission denied" message.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Changes since the v1 (which was sent way back in March...):
>  * rebased on master now a pile of qdev/qom changesd have landed
>  * fixed some overlong lines
>  * avoid gcc '?:' extension
>  * a couple of set_ functions in qdev-properties.c are new since v1
>    and needed their QERR_PERMISSION_DENIED checks changing

This does not yet seem to take into account the discussion with libvirt
and Anthony on what parameters to pass. The ID generalization was
nack'ed by Anthony and a QOM path was suggested as alternative. Could
you please look into that?

Thanks,
Andreas

> 
>  hw/qdev-properties.c |   42 ++++++++++++++++++++++++++++--------------
>  qerror.c             |    5 +++++
>  qerror.h             |    3 +++
>  3 files changed, 36 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 0b89462..ae0c7a7 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -54,7 +54,8 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
>      bool value;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -94,7 +95,8 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
>      uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -161,7 +163,8 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
>      uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -194,7 +197,8 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
>      uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -219,7 +223,8 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
>      int32_t *ptr = qdev_get_prop_ptr(dev, prop);
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -292,7 +297,8 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque,
>      uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -380,7 +386,8 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
>      char *str;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -458,7 +465,8 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
>      int ret;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -627,7 +635,8 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
>      VLANState *vlan;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -697,7 +706,8 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
>      char *str, *p;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -767,7 +777,8 @@ static void set_enum(Object *obj, Visitor *v, void *opaque,
>      int *ptr = qdev_get_prop_ptr(dev, prop);
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -798,7 +809,8 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
>      char *str;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -868,7 +880,8 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
>      const int64_t max = 32768;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> @@ -936,7 +949,8 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
>      unsigned int slot = 0, func = 0;
>  
>      if (dev->state != DEV_STATE_CREATED) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  dev->id ? dev->id : "", name);
>          return;
>      }
>  
> diff --git a/qerror.c b/qerror.c
> index 92c4eff..2af081d 100644
> --- a/qerror.c
> +++ b/qerror.c
> @@ -233,6 +233,11 @@ static const QErrorStringTable qerror_table[] = {
>          .desc      = "Property '%(device).%(property)' not found",
>      },
>      {
> +        .error_fmt = QERR_PROPERTY_SET_AFTER_REALIZE,
> +        .desc      = "Property '%(device).%(property)' "
> +                     "cannot be set after realize",
> +    },
> +    {
>          .error_fmt = QERR_PROPERTY_VALUE_BAD,
>          .desc      = "Property '%(device).%(property)' doesn't take value '%(value)'",
>      },
> diff --git a/qerror.h b/qerror.h
> index b4c8758..b5cb730 100644
> --- a/qerror.h
> +++ b/qerror.h
> @@ -196,6 +196,9 @@ QError *qobject_to_qerror(const QObject *obj);
>  #define QERR_PROPERTY_NOT_FOUND \
>      "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
>  
> +#define QERR_PROPERTY_SET_AFTER_REALIZE \
> +    "{ 'class': 'PropertySetAfterRealize', 'data': { 'device': %s, 'property': %s } }"
> +
>  #define QERR_PROPERTY_VALUE_BAD \
>      "{ 'class': 'PropertyValueBad', 'data': { 'device': %s, 'property': %s, 'value': %s } }"
>  
>
Peter Maydell - July 18, 2012, 10:35 a.m.
n 18 July 2012 11:20, Andreas Färber <afaerber@suse.de> wrote:
> Am 16.07.2012 17:25, schrieb Peter Maydell:
>> Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts
>> to set a QOM or qdev property after the object/device has been
>> realized. This allows a slightly more informative diagnostic
>> than the previous "permission denied" message.
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>> Changes since the v1 (which was sent way back in March...):
>>  * rebased on master now a pile of qdev/qom changesd have landed
>>  * fixed some overlong lines
>>  * avoid gcc '?:' extension
>>  * a couple of set_ functions in qdev-properties.c are new since v1
>>    and needed their QERR_PERMISSION_DENIED checks changing
>
> This does not yet seem to take into account the discussion with libvirt
> and Anthony on what parameters to pass. The ID generalization was
> nack'ed by Anthony and a QOM path was suggested as alternative. Could
> you please look into that?

I'm afraid I'm not really sure what you're referring to here --
do you have a link to a discussion?

All I want is for errors printed to the user to be a bit more
helpful; the whole qerror infrastructure seems to make it
somewhere between difficult and impossible to do that :-(

-- PMM
Markus Armbruster - July 18, 2012, 11:19 a.m.
Peter Maydell <peter.maydell@linaro.org> writes:

> n 18 July 2012 11:20, Andreas Färber <afaerber@suse.de> wrote:
>> Am 16.07.2012 17:25, schrieb Peter Maydell:
>>> Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts
>>> to set a QOM or qdev property after the object/device has been
>>> realized. This allows a slightly more informative diagnostic
>>> than the previous "permission denied" message.
>>>
>>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>>> ---
>>> Changes since the v1 (which was sent way back in March...):
>>>  * rebased on master now a pile of qdev/qom changesd have landed
>>>  * fixed some overlong lines
>>>  * avoid gcc '?:' extension
>>>  * a couple of set_ functions in qdev-properties.c are new since v1
>>>    and needed their QERR_PERMISSION_DENIED checks changing
>>
>> This does not yet seem to take into account the discussion with libvirt
>> and Anthony on what parameters to pass. The ID generalization was
>> nack'ed by Anthony and a QOM path was suggested as alternative. Could
>> you please look into that?
>
> I'm afraid I'm not really sure what you're referring to here --
> do you have a link to a discussion?
>
> All I want is for errors printed to the user to be a bit more
> helpful; the whole qerror infrastructure seems to make it
> somewhere between difficult and impossible to do that :-(

Yup.  One of the reasons why I detest it.

A recent thread on how to recover from this disaster:
http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg03469.html
Peter Maydell - July 18, 2012, 11:36 a.m.
On 18 July 2012 12:19, Markus Armbruster <armbru@redhat.com> wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> n 18 July 2012 11:20, Andreas Färber <afaerber@suse.de> wrote:
>>> Am 16.07.2012 17:25, schrieb Peter Maydell:
>>>> Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts
>>>> to set a QOM or qdev property after the object/device has been
>>>> realized. This allows a slightly more informative diagnostic
>>>> than the previous "permission denied" message.
>>>>
>>>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>>>> ---
>>>> Changes since the v1 (which was sent way back in March...):
>>>>  * rebased on master now a pile of qdev/qom changesd have landed
>>>>  * fixed some overlong lines
>>>>  * avoid gcc '?:' extension
>>>>  * a couple of set_ functions in qdev-properties.c are new since v1
>>>>    and needed their QERR_PERMISSION_DENIED checks changing
>>>
>>> This does not yet seem to take into account the discussion with libvirt
>>> and Anthony on what parameters to pass. The ID generalization was
>>> nack'ed by Anthony and a QOM path was suggested as alternative. Could
>>> you please look into that?
>>
>> I'm afraid I'm not really sure what you're referring to here --
>> do you have a link to a discussion?
>>
>> All I want is for errors printed to the user to be a bit more
>> helpful; the whole qerror infrastructure seems to make it
>> somewhere between difficult and impossible to do that :-(
>
> Yup.  One of the reasons why I detest it.
>
> A recent thread on how to recover from this disaster:
> http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg03469.html

That's interesting but I'm not sure how it's relevant. We already
have QERR_PROPERTY values just this new one, so I don't see why
this is any worse than the ones we have. If we come up with some
new scheme we can convert this with all the rest. And I don't
really want to block "improve this error message" on getting
agreement for some big redesign effort...

-- PMM
Peter Maydell - July 18, 2012, 11:36 a.m.
On 18 July 2012 12:36, Peter Maydell <peter.maydell@linaro.org> wrote:
> That's interesting but I'm not sure how it's relevant. We already
> have QERR_PROPERTY values just this new one, so I don't see why
> this is any worse than the ones we have.

"just like".

-- PMM
Markus Armbruster - July 18, 2012, 11:59 a.m.
Peter Maydell <peter.maydell@linaro.org> writes:

> On 18 July 2012 12:19, Markus Armbruster <armbru@redhat.com> wrote:
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>
>>> n 18 July 2012 11:20, Andreas Färber <afaerber@suse.de> wrote:
>>>> Am 16.07.2012 17:25, schrieb Peter Maydell:
>>>>> Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts
>>>>> to set a QOM or qdev property after the object/device has been
>>>>> realized. This allows a slightly more informative diagnostic
>>>>> than the previous "permission denied" message.
>>>>>
>>>>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>>>>> ---
>>>>> Changes since the v1 (which was sent way back in March...):
>>>>>  * rebased on master now a pile of qdev/qom changesd have landed
>>>>>  * fixed some overlong lines
>>>>>  * avoid gcc '?:' extension
>>>>>  * a couple of set_ functions in qdev-properties.c are new since v1
>>>>>    and needed their QERR_PERMISSION_DENIED checks changing
>>>>
>>>> This does not yet seem to take into account the discussion with libvirt
>>>> and Anthony on what parameters to pass. The ID generalization was
>>>> nack'ed by Anthony and a QOM path was suggested as alternative. Could
>>>> you please look into that?
>>>
>>> I'm afraid I'm not really sure what you're referring to here --
>>> do you have a link to a discussion?
>>>
>>> All I want is for errors printed to the user to be a bit more
>>> helpful; the whole qerror infrastructure seems to make it
>>> somewhere between difficult and impossible to do that :-(
>>
>> Yup.  One of the reasons why I detest it.
>>
>> A recent thread on how to recover from this disaster:
>> http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg03469.html
>
> That's interesting but I'm not sure how it's relevant. We already
> have QERR_PROPERTY values just this new one, so I don't see why
> this is any worse than the ones we have. If we come up with some
> new scheme we can convert this with all the rest. And I don't
> really want to block "improve this error message" on getting
> agreement for some big redesign effort...

I'm not objecting to your patch (I didn't even review it), just pointing
out there's a glimmer of hope on the "emitting error messages fit for
humans is somewhere between difficult and impossible" front.
Luiz Capitulino - July 18, 2012, 1:03 p.m.
On Wed, 18 Jul 2012 13:59:06 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Peter Maydell <peter.maydell@linaro.org> writes:
> 
> > On 18 July 2012 12:19, Markus Armbruster <armbru@redhat.com> wrote:
> >> Peter Maydell <peter.maydell@linaro.org> writes:
> >>
> >>> n 18 July 2012 11:20, Andreas Färber <afaerber@suse.de> wrote:
> >>>> Am 16.07.2012 17:25, schrieb Peter Maydell:
> >>>>> Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts
> >>>>> to set a QOM or qdev property after the object/device has been
> >>>>> realized. This allows a slightly more informative diagnostic
> >>>>> than the previous "permission denied" message.
> >>>>>
> >>>>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> >>>>> ---
> >>>>> Changes since the v1 (which was sent way back in March...):
> >>>>>  * rebased on master now a pile of qdev/qom changesd have landed
> >>>>>  * fixed some overlong lines
> >>>>>  * avoid gcc '?:' extension
> >>>>>  * a couple of set_ functions in qdev-properties.c are new since v1
> >>>>>    and needed their QERR_PERMISSION_DENIED checks changing
> >>>>
> >>>> This does not yet seem to take into account the discussion with libvirt
> >>>> and Anthony on what parameters to pass. The ID generalization was
> >>>> nack'ed by Anthony and a QOM path was suggested as alternative. Could
> >>>> you please look into that?
> >>>
> >>> I'm afraid I'm not really sure what you're referring to here --
> >>> do you have a link to a discussion?
> >>>
> >>> All I want is for errors printed to the user to be a bit more
> >>> helpful; the whole qerror infrastructure seems to make it
> >>> somewhere between difficult and impossible to do that :-(
> >>
> >> Yup.  One of the reasons why I detest it.
> >>
> >> A recent thread on how to recover from this disaster:
> >> http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg03469.html
> >
> > That's interesting but I'm not sure how it's relevant. We already
> > have QERR_PROPERTY values just this new one, so I don't see why
> > this is any worse than the ones we have. If we come up with some
> > new scheme we can convert this with all the rest. And I don't
> > really want to block "improve this error message" on getting
> > agreement for some big redesign effort...
> 
> I'm not objecting to your patch (I didn't even review it), just pointing
> out there's a glimmer of hope on the "emitting error messages fit for
> humans is somewhere between difficult and impossible" front.

Yeah, I plan to fix that soon.

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 0b89462..ae0c7a7 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -54,7 +54,8 @@  static void set_bit(Object *obj, Visitor *v, void *opaque,
     bool value;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -94,7 +95,8 @@  static void set_uint8(Object *obj, Visitor *v, void *opaque,
     uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -161,7 +163,8 @@  static void set_uint16(Object *obj, Visitor *v, void *opaque,
     uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -194,7 +197,8 @@  static void set_uint32(Object *obj, Visitor *v, void *opaque,
     uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -219,7 +223,8 @@  static void set_int32(Object *obj, Visitor *v, void *opaque,
     int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -292,7 +297,8 @@  static void set_uint64(Object *obj, Visitor *v, void *opaque,
     uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -380,7 +386,8 @@  static void set_string(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -458,7 +465,8 @@  static void set_pointer(Object *obj, Visitor *v, Property *prop,
     int ret;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -627,7 +635,8 @@  static void set_vlan(Object *obj, Visitor *v, void *opaque,
     VLANState *vlan;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -697,7 +706,8 @@  static void set_mac(Object *obj, Visitor *v, void *opaque,
     char *str, *p;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -767,7 +777,8 @@  static void set_enum(Object *obj, Visitor *v, void *opaque,
     int *ptr = qdev_get_prop_ptr(dev, prop);
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -798,7 +809,8 @@  static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -868,7 +880,8 @@  static void set_blocksize(Object *obj, Visitor *v, void *opaque,
     const int64_t max = 32768;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
@@ -936,7 +949,8 @@  static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
     unsigned int slot = 0, func = 0;
 
     if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  dev->id ? dev->id : "", name);
         return;
     }
 
diff --git a/qerror.c b/qerror.c
index 92c4eff..2af081d 100644
--- a/qerror.c
+++ b/qerror.c
@@ -233,6 +233,11 @@  static const QErrorStringTable qerror_table[] = {
         .desc      = "Property '%(device).%(property)' not found",
     },
     {
+        .error_fmt = QERR_PROPERTY_SET_AFTER_REALIZE,
+        .desc      = "Property '%(device).%(property)' "
+                     "cannot be set after realize",
+    },
+    {
         .error_fmt = QERR_PROPERTY_VALUE_BAD,
         .desc      = "Property '%(device).%(property)' doesn't take value '%(value)'",
     },
diff --git a/qerror.h b/qerror.h
index b4c8758..b5cb730 100644
--- a/qerror.h
+++ b/qerror.h
@@ -196,6 +196,9 @@  QError *qobject_to_qerror(const QObject *obj);
 #define QERR_PROPERTY_NOT_FOUND \
     "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
 
+#define QERR_PROPERTY_SET_AFTER_REALIZE \
+    "{ 'class': 'PropertySetAfterRealize', 'data': { 'device': %s, 'property': %s } }"
+
 #define QERR_PROPERTY_VALUE_BAD \
     "{ 'class': 'PropertyValueBad', 'data': { 'device': %s, 'property': %s, 'value': %s } }"