@@ -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;
};
@@ -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;
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(+)