Patchwork [qom-next,7/7] qom: Add QERR_PROPERTY_SET_AFTER_REALIZE

login
register
mail settings
Submitter Andreas Färber
Date June 7, 2012, 7:31 p.m.
Message ID <1339097465-22977-8-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/163660/
State New
Headers show

Comments

Andreas Färber - June 7, 2012, 7:31 p.m.
From: Peter Maydell <peter.maydell@linaro.org>

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 "Insufficient permission" message.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/qdev-properties.c    |   15 ++++++++++-----
 qerror.c                |    4 ++++
 qerror.h                |    3 +++
 qom/object-properties.c |   24 ++++++++++++++++--------
 qom/object.c            |    6 ++++--
 5 files changed, 37 insertions(+), 15 deletions(-)
Andreas Färber - June 7, 2012, 7:56 p.m.
Am 07.06.2012 21:31, schrieb Andreas Färber:
> From: Peter Maydell <peter.maydell@linaro.org>
> 
> 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 "Insufficient permission" message.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  hw/qdev-properties.c    |   15 ++++++++++-----
>  qerror.c                |    4 ++++
>  qerror.h                |    3 +++
>  qom/object-properties.c |   24 ++++++++++++++++--------
>  qom/object.c            |    6 ++++--
>  5 files changed, 37 insertions(+), 15 deletions(-)
[...]
> diff --git a/qom/object.c b/qom/object.c
> index 40bc23a..c8a2cd7 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -817,7 +817,8 @@ void object_property_get(Object *obj, Visitor *v, const char *name,
>      }
>  
>      if (!prop->get) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  object_get_id(obj), name);
>      } else {
>          prop->get(obj, v, prop->opaque, name, errp);
>      }
> @@ -832,7 +833,8 @@ void object_property_set(Object *obj, Visitor *v, const char *name,
>      }
>  
>      if (!prop->set) {
> -        error_set(errp, QERR_PERMISSION_DENIED);
> +        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
> +                  object_get_id(obj), name);
>      } else {
>          prop->set(obj, v, prop->opaque, name, errp);
>      }

Hm, what does the lack of a setter have to do with realize? :)
Reverting these two hunks.

Andreas

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 7379c1c..830f3c7 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -76,7 +76,8 @@  static void set_pointer(Object *obj, Visitor *v, Property *prop,
     int ret;
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -242,7 +243,8 @@  static void set_vlan(Object *obj, Visitor *v, void *opaque,
     VLANState *vlan;
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -303,7 +305,8 @@  static void set_mac(Object *obj, Visitor *v, void *opaque,
     char *str, *p;
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -391,7 +394,8 @@  static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -469,7 +473,8 @@  static void set_blocksize(Object *obj, Visitor *v, void *opaque,
     const int64_t max = 32768;
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
diff --git a/qerror.c b/qerror.c
index 92c4eff..d3768cb 100644
--- a/qerror.c
+++ b/qerror.c
@@ -233,6 +233,10 @@  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 } }"
 
diff --git a/qom/object-properties.c b/qom/object-properties.c
index 6765e90..8c70e5f 100644
--- a/qom/object-properties.c
+++ b/qom/object-properties.c
@@ -50,7 +50,8 @@  static void set_bit(Object *obj, Visitor *v, void *opaque,
     bool value;
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -88,7 +89,8 @@  static void set_uint8(Object *obj, Visitor *v, void *opaque,
     uint8_t *ptr = object_get_prop_ptr(obj, prop);
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -153,7 +155,8 @@  static void set_uint16(Object *obj, Visitor *v, void *opaque,
     uint16_t *ptr = object_get_prop_ptr(obj, prop);
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -184,7 +187,8 @@  static void set_uint32(Object *obj, Visitor *v, void *opaque,
     uint32_t *ptr = object_get_prop_ptr(obj, prop);
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -207,7 +211,8 @@  static void set_int32(Object *obj, Visitor *v, void *opaque,
     int32_t *ptr = object_get_prop_ptr(obj, prop);
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -278,7 +283,8 @@  static void set_uint64(Object *obj, Visitor *v, void *opaque,
     uint64_t *ptr = object_get_prop_ptr(obj, prop);
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -364,7 +370,8 @@  static void set_string(Object *obj, Visitor *v, void *opaque,
     char *str;
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
@@ -407,7 +414,8 @@  void property_set_enum(Object *obj, Visitor *v, void *opaque,
     int *ptr = object_get_prop_ptr(obj, prop);
 
     if (object_is_realized(obj)) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
         return;
     }
 
diff --git a/qom/object.c b/qom/object.c
index 40bc23a..c8a2cd7 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -817,7 +817,8 @@  void object_property_get(Object *obj, Visitor *v, const char *name,
     }
 
     if (!prop->get) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
     } else {
         prop->get(obj, v, prop->opaque, name, errp);
     }
@@ -832,7 +833,8 @@  void object_property_set(Object *obj, Visitor *v, const char *name,
     }
 
     if (!prop->set) {
-        error_set(errp, QERR_PERMISSION_DENIED);
+        error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE,
+                  object_get_id(obj), name);
     } else {
         prop->set(obj, v, prop->opaque, name, errp);
     }