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

login
register
mail settings
Submitter Andreas Färber
Date June 10, 2012, 1:09 a.m.
Message ID <1339290549-3789-8-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/163970/
State New
Headers show

Comments

Andreas Färber - June 10, 2012, 1:09 a.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>
[AF: Use object_get_typename() in place of object_get_id().]
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 ++++++++++++++++--------
 4 files changed, 33 insertions(+), 13 deletions(-)

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 940bf39..c099bec 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_typename(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_typename(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_typename(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_typename(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_typename(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..e93c3db 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_typename(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_typename(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_typename(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_typename(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_typename(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_typename(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_typename(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_typename(obj), name);
         return;
     }