diff mbox series

[12/12,RFC] qom: Lock properties of all TYPE_USER_CREATABLE types

Message ID 20201009160122.1662082-13-ehabkost@redhat.com
State New
Headers show
Series qom: Make all -object types use only class properties | expand

Commit Message

Eduardo Habkost Oct. 9, 2020, 4:01 p.m. UTC
TYPE_USER_CREATABLE types expose all QOM properties through
`-object` and `object-add`.  Lock the properties on
TYPE_USER_CREATABLE so we will never add new writable instance
properties to those types.

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
---
 qom/object_interfaces.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index e8e1523960..40123d4b50 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -293,6 +293,16 @@  bool user_creatable_del(const char *id, Error **errp)
     return true;
 }
 
+static void user_creatable_class_init(ObjectClass *klass, void *data)
+{
+    /*
+     * User-creatable QOM types expose all writable QOM properties
+     * to the external world through `-object` and `object-add`,
+     * so all writable properties must be registered at class level.
+     */
+    object_class_lock_properties(klass);
+}
+
 void user_creatable_cleanup(void)
 {
     object_unparent(object_get_objects_root());
@@ -304,6 +314,7 @@  static void register_types(void)
         .name          = TYPE_USER_CREATABLE,
         .parent        = TYPE_INTERFACE,
         .class_size = sizeof(UserCreatableClass),
+        .class_init    = user_creatable_class_init,
     };
 
     type_register_static(&uc_interface_info);