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>




-- 
Marc-André Lureau
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 30, 2020 at 2:12 AM Eduardo Habkost &lt;<a href="mailto:ehabkost@redhat.com" target="_blank">ehabkost@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Note that this doesn&#39;t replace the check callback at<br>
object*_property_add_link() (yet), because currently the link<br>
property check callback needs to get the property value as<br>
argument (despite this not being necessary in most cases).<br>
<br>
Signed-off-by: Eduardo Habkost &lt;<a href="mailto:ehabkost@redhat.com" target="_blank">ehabkost@redhat.com</a>&gt;<br></blockquote><div><br></div><div>Reviewed-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com" target="_blank">marcandre.lureau@redhat.com</a>&gt;</div><div> <br></div><br clear="all"></div><br>-- <br><div dir="ltr">Marc-André Lureau<br></div></div>
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;