diff mbox series

[21/36] qom: Add allow_set callback to ObjectProperty

Message ID 20201029220246.472693-22-ehabkost@redhat.com
State New
Headers show
Series Make qdev static property API usable by any QOM type | expand

Commit Message

Eduardo Habkost Oct. 29, 2020, 10:02 p.m. UTC
Note that this doesn't replace the check callback at
object*_property_add_link() (yet), because currently the link
property check callback needs to get the property value as
argument (despite this not being necessary in most cases).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 include/qom/object.h | 16 ++++++++++++++++
 qom/object.c         |  4 ++++
 2 files changed, 20 insertions(+)

Comments

Marc-André Lureau Oct. 30, 2020, 4:43 p.m. UTC | #1
On Fri, Oct 30, 2020 at 2:12 AM Eduardo Habkost <ehabkost@redhat.com> wrote:

> Note that this doesn't replace the check callback at
> object*_property_add_link() (yet), because currently the link
> property check callback needs to get the property value as
> argument (despite this not being necessary in most cases).
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
diff mbox series

Patch

diff --git a/include/qom/object.h b/include/qom/object.h
index d378f13a11..24e591d954 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -86,6 +86,21 @@  typedef void (ObjectPropertyRelease)(Object *obj,
  */
 typedef void (ObjectPropertyInit)(Object *obj, ObjectProperty *prop);
 
+/**
+ * typedef ObjectPropertyAllowSet:
+ * @obj: the object that owns the property
+ * @prop: the property being set
+ * @errp: pointer to error information
+ *
+ * Called when a property is being set.
+ *
+ * If return value is false, it will prevent the property from
+ * being changed.  Error information should be filled in @errp
+ * if return vlaue is false.
+ */
+typedef bool (ObjectPropertyAllowSet)(Object *obj, ObjectProperty *prop,
+                                      Error **errp);
+
 struct ObjectProperty
 {
     char *name;
@@ -96,6 +111,7 @@  struct ObjectProperty
     ObjectPropertyResolve *resolve;
     ObjectPropertyRelease *release;
     ObjectPropertyInit *init;
+    ObjectPropertyAllowSet *allow_set;
     void *opaque;
     QObject *defval;
 };
diff --git a/qom/object.c b/qom/object.c
index 1065355233..20726e4584 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1395,6 +1395,10 @@  bool object_property_set(Object *obj, const char *name, Visitor *v,
         error_setg(errp, QERR_PERMISSION_DENIED);
         return false;
     }
+    if (prop->allow_set && !prop->allow_set(obj, prop, errp)) {
+        return false;
+    }
+
     prop->set(obj, v, name, prop->opaque, &err);
     error_propagate(errp, err);
     return !err;