Skip to contentSkip to conversation

qom: misc cleanups / fixes

PATCH Superseded Daniel P. Berrangé 3 participants 22 messages May 8 – May 11

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover qom: misc cleanups / fixes

The overall theme of this patch is to move some logic out of object_interfaces.c into object.c, since it is not tied to the user creatable interface.

Changed in v2

- Ensure object creation always triggers module loading
- Remove redundant NULL check in trace event
- Remove double #include line

Daniel P. Berrangé (10):
qom: add trace events for object/property lifecycle
qom: validate ID format when creating objects
qom: make errp last param in methods taking va_list
qom: shorten name of object_set_properties_from_keyval
qom: have object_set_props_keyval return bool
qom: move object_set_prop_keyval into object.c
qom: add object_new_with_props_from_qdict
qom: fix ability to create objects without a parent
qom: allow object_new_with_prop* to trigger module loading
qom: drop user_creatable_add_type method

 authz/listfile.c                |   4 +-
 include/qom/object.h            | 121 ++++++++++++++---
 include/qom/object_interfaces.h |  18 ---
 qom/object.c                    | 230 ++++++++++++++++++++++++++++----
 qom/object_interfaces.c         | 101 +-------------
 qom/trace-events                |  12 +-
 system/qdev-monitor.c           |   4 +-
 system/vl.c                     |   7 +-
 tests/unit/check-qom-proplist.c |  97 +++++++++++---
 9 files changed, 409 insertions(+), 185 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/10 qom: add trace events for object/property lifecycle

This adds tracing around object allocation & finalization, the addition & deletion of properties, and the addition & deletion of children.

---
 qom/object.c     | 34 +++++++++++++++++++++++++++-------
 qom/trace-events | 12 ++++++++++--
 2 files changed, 37 insertions(+), 9 deletions(-)
qom/object.c +27 -7
index f981e27044..9c391071fb 100644
@@ -603,6 +603,8 @@ static void object_property_del_all(Object *obj)
         object_property_iter_init(&iter, obj);
         while ((prop = object_property_iter_next(&iter)) != NULL) {
             if (g_hash_table_add(done, prop)) {
+                trace_object_property_del(obj, obj->class->type->name,
+                                          prop->name, prop->opaque);
                 if (prop->release) {
                     prop->release(obj, prop->name, prop->opaque);
                     released = true;
@@ -621,10 +623,14 @@ static void object_property_del_child(Object *obj, Object *child)
     GHashTableIter iter;
     gpointer key, value;
 
+    trace_object_property_del_child(obj, obj->class->type->name,
+                                    child, child->class->type->name);
     g_hash_table_iter_init(&iter, obj->properties);
     while (g_hash_table_iter_next(&iter, &key, &value)) {
         prop = value;
         if (object_property_is_child(prop) && prop->opaque == child) {
+            trace_object_property_del(obj, obj->class->type->name,
+                                      prop->name, prop->opaque);
             if (prop->release) {
                 prop->release(obj, prop->name, prop->opaque);
                 prop->release = NULL;
@@ -664,7 +670,7 @@ static void object_finalize(void *data)
 {
     Object *obj = data;
     TypeImpl *ti = obj->class->type;
-
+    trace_object_finalize(obj, obj->class->type->name);
     object_property_del_all(obj);
     object_deinit(obj, ti);
 
@@ -714,6 +720,7 @@ static Object *object_new_with_type(Type type)
     object_initialize_with_type(obj, size, type);
     obj->free = obj_free;
 
+    trace_object_new(obj, obj->class->type->name);
     return obj;
 }
 
@@ -844,8 +851,9 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
 Object *object_dynamic_cast_assert(Object *obj, const char *typename,
                                    const char *file, int line, const char *func)
 {
-    trace_object_dynamic_cast_assert(obj ? obj->class->type->name : "(null)",
-                                     typename, file, line, func);
+    trace_object_dynamic_cast_assert(
+        obj, obj ? obj->class->type->name : "(null)",
+        typename, file, line, func);
 
 #ifdef CONFIG_QOM_CAST_DEBUG
     int i;
@@ -935,8 +943,9 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
 {
     ObjectClass *ret;
 
-    trace_object_class_dynamic_cast_assert(class ? class->type->name : "(null)",
-                                           typename, file, line, func);
+    trace_object_class_dynamic_cast_assert(
+        class ? class->type->name : "(null)",
+        typename, file, line, func);
 
 #ifdef CONFIG_QOM_CAST_DEBUG
     int i;
@@ -1220,6 +1229,8 @@ object_property_try_add(Object *obj, const char *name, const char *type,
     prop->release = release;
     prop->opaque = opaque;
 
+    trace_object_property_add(obj, obj->class->type->name,
+                              prop->name, prop->opaque);
     g_hash_table_insert(obj->properties, prop->name, prop);
     return prop;
 }
@@ -1258,6 +1269,8 @@ object_class_property_add(ObjectClass *klass,
     prop->release = release;
     prop->opaque = opaque;
 
+    trace_object_class_property_add(klass->type->name, prop->name,
+                                    prop->opaque);
     g_hash_table_insert(klass->properties, prop->name, prop);
 
     return prop;
@@ -1346,6 +1359,8 @@ void object_property_del(Object *obj, const char *name)
 {
     ObjectProperty *prop = g_hash_table_lookup(obj->properties, name);
 
+    trace_object_property_del(obj, obj->class->type->name, prop->name,
+                              prop->opaque);
     if (prop->release) {
         prop->release(obj, name, prop->opaque);
     }
@@ -1634,8 +1649,11 @@ int object_property_get_enum(Object *obj, const char *name,
 bool object_property_parse(Object *obj, const char *name,
                            const char *string, Error **errp)
 {
-    Visitor *v = string_input_visitor_new(string);
-    bool ok = object_property_set(obj, name, v, errp);
+    Visitor *v;
+    bool ok;
+    trace_object_property_parse(obj, obj->class->type->name, name, string);
+    v = string_input_visitor_new(string);
+    ok = object_property_set(obj, name, v, errp);
 
     visit_free(v);
     return ok;
@@ -1766,6 +1784,8 @@ object_property_try_add_child(Object *obj, const char *name,
     g_autofree char *type = NULL;
     ObjectProperty *op;
 
+    trace_object_property_add_child(obj, obj->class->type->name, name,
+                                    child, child->class->type->name);
     assert(!child->parent);
 
     type = g_strdup_printf("child<%s>", object_get_typename(child));
qom/trace-events +10 -2
index b2e9f4a712..9aabbae4f7 100644
@@ -1,5 +1,13 @@
 # See docs/devel/tracing.rst for syntax documentation.
 
 # object.c
-object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
-object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
+object_dynamic_cast_assert(void *obj, const char *type, const char *target, const char *file, int line, const char *func) "obj=%p type=%s->%s (%s:%d:%s)"
+object_finalize(void *obj, const char *type) "obj=%p type=%s"
+object_new(void *obj, const char *type) "obj=%p type=%s"
+object_property_add(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
+object_property_add_child(void *obj, const char *type, const char *name, void *parent, const char *parenttype) "obj=%p type=%s name=%s parent=%p parent-type=%s"
+object_property_del(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
+object_property_del_child(void *obj, const char *type, void *parent, const char *parenttype) "obj=%p type=%s parent=%p parent-type=%s"
+object_property_parse(void *obj, const char *type, const char *name, const char *value) "obj=%p type=%s prop=%s value=%s"
+object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "type=%s->%s (%s:%d:%s)"
+object_class_property_add(const char *type, const char *name, void *value) "type=%s name=%s value=%p"
Signature · 1 line
2.54.0
#4 lore raw

PATCH v2 2/10 qom: validate ID format when creating objects

In reply to Daniel P. Berrangé

The object_new_with_props/propv methods failed to validate the ID string format, thus diverging from user_creatable_add_type.

---
 qom/object.c | 9 +++++++++
 1 file changed, 9 insertions(+)
qom/object.c +9 -0
index 9c391071fb..62d2f0486a 100644
@@ -24,6 +24,8 @@
 #include "qapi/forward-visitor.h"
 #include "qapi/qapi-builtin-visit.h"
 #include "qobject/qjson.h"
+#include "qemu/id.h"
+#include "qapi/qmp/qerror.h"
 #include "trace.h"
 
 /* TODO: replace QObject with a simpler visitor to avoid a dependency
@@ -764,6 +766,13 @@ Object *object_new_with_propv(const char *typename,
     ObjectClass *klass;
     UserCreatable *uc;
 
+    if (id != NULL && !id_wellformed(id)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+        error_append_hint(errp, "Identifiers consist of letters, digits, "
+                          "'-', '.', '_', starting with a letter.\n");
+        return NULL;
+    }
+
     klass = object_class_by_name(typename);
     if (!klass) {
         error_setg(errp, "invalid object type: %s", typename);
Signature · 1 line
2.54.0
#17 lore raw

PATCH v2 8/10 qom: fix ability to create objects without a parent

In reply to Daniel P. Berrangé

object_new_with_propv allowed id/parent to be optional, in which case the caller was expected to own the returned object. Unfortunately a trailing object_unref() meant that the returned object was already freed.

It is confusing to have a single method with two different ownership scenarios for the returned object.

Make id/parent mandatory in object_new_with_propv once more, and add a new object_new_with_propv_parentless that does not accept id/parent at all and lets the caller own the returned reference.

The helper method has abstracted the way properties are represented and setk in order to facilitate the subsequent commit.

Unit tests are added to address the root cause that allowed the bug to slip through in commit 6134d752.

Fixes 6134d7522e570a30d7f0d1e092ee37351c5183ed
---
 include/qom/object.h            | 47 ++++++++++++++++++
 qom/object.c                    | 74 +++++++++++++++++++++++----
 tests/unit/check-qom-proplist.c | 88 ++++++++++++++++++++++++++++-----
 3 files changed, 187 insertions(+), 22 deletions(-)
include/qom/object.h +47 -0
index cd59f1f171..71530dac76 100644
@@ -719,6 +719,53 @@ Object *object_new_with_props_from_qdict(const char *typename,
                                          Visitor *v,
                                          Error **errp);
 
+/**
+ * object_new_with_props_parentless:
+ * @typename:  The name of the type of the object to instantiate.
+ * @errp: pointer to error object
+ * @...: list of property names and values
+ *
+ * Behaviour as object_new_with_props(), except the object
+ * will not be added to any parent and thus the caller will
+ * own the returned instance. The caller must call
+ * object_unref when it is no longer required.
+ */
+Object *object_new_with_props_parentless(const char *typename,
+                                         Error **errp,
+                                         ...) G_GNUC_NULL_TERMINATED;
+
+/**
+ * object_new_with_propv_parentless:
+ * @typename:  The name of the type of the object to instantiate.
+ * @vargs: list of property names and values
+ * @errp: pointer to error object
+ *
+ * Behaviour as object_new_with_propv(), except the object
+ * will not be added to any parent and thus the caller will
+ * own the returned instance. The caller must call
+ * object_unref when it is no longer required.
+ */
+Object *object_new_with_propv_parentless(const char *typename,
+                                         va_list vargs,
+                                         Error **errp);
+
+/**
+ * object_new_with_props_from_qdict_parentless:
+ * @typename:  The name of the type of the object to instantiate.
+ * @props: dictionary of property names and values
+ * @v: visitor to iterate over @props
+ * @errp: pointer to error object
+ *
+ * Behaviour as object_new_with_props_from_qdict(), except the
+ * object will not be added to any parent and thus the caller
+ * will own the returned instance. The caller must call
+ * object_unref when it is no longer required.
+ */
+Object *object_new_with_props_from_qdict_parentless(const char *typename,
+                                                    QDict *props,
+                                                    Visitor *v,
+                                                    Error **errp);
+
 /**
  * object_set_props:
  * @obj: the object instance to set properties on
qom/object.c +65 -9

120 lines not on this page · raw message

tests/unit/check-qom-proplist.c +75 -13

130 lines not on this page · raw message

Signature · 1 line
2.54.0
#10 lore raw

PATCH v2 5/10 qom: have object_set_props_keyval return bool

In reply to Daniel P. Berrangé

This matches the convention established by the object_set_props and object_set_propv methods.

---
 include/qom/object.h    |  4 +++-
 qom/object_interfaces.c | 13 +++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)
include/qom/object.h +3 -1
index d841c338a2..20a04cc4a9 100644
@@ -924,8 +924,10 @@ bool type_print_class_properties(const char *type);
  *
  * For each key in the dictionary, parse the value string if needed,
  * then set the corresponding property in @obj.
+ *
+ * Returns: %true on success, %false on error.
  */
-void object_set_props_from_keyval(Object *obj, const QDict *qdict,
+bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
                                   bool from_json, Error **errp);
 
 /**
qom/object_interfaces.c +9 -4
index 4377d65b76..50736b80c8 100644
@@ -44,13 +44,14 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
     }
 }
 
-static void object_set_props_from_qdict(Object *obj, const QDict *qdict,
+static bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
                                         Visitor *v, Error **errp)
 {
+    ERRP_GUARD();
     const QDictEntry *e;
 
     if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
-        return;
+        return false;
     }
     for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
         if (!object_property_set(obj, e->key, v, errp)) {
@@ -60,19 +61,23 @@ static void object_set_props_from_qdict(Object *obj, const QDict *qdict,
     visit_check_struct(v, errp);
 out:
     visit_end_struct(v, NULL);
+
+    return *errp == NULL;
 }
 
-void object_set_props_from_keyval(Object *obj, const QDict *qdict,
+bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
                                   bool from_json, Error **errp)
 {
+    bool ret;
     Visitor *v;
     if (from_json) {
         v = qobject_input_visitor_new(QOBJECT(qdict));
     } else {
         v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
     }
-    object_set_props_from_qdict(obj, qdict, v, errp);
+    ret = object_set_props_from_qdict(obj, qdict, v, errp);
     visit_free(v);
+    return ret;
 }
 
 Object *user_creatable_add_type(const char *type, const char *id,
Signature · 1 line
2.54.0
#8 lore raw

PATCH v2 3/10 qom: make errp last param in methods taking va_list

In reply to Daniel P. Berrangé

object_new_with_props can't put 'errp' last due to the use of variadic arguments. That constraint does not apply to the use of va_list with object_new_with_propv, so follow normal practice with 'errp' placement.

The same rationale applies to object_set_propv.

---
 include/qom/object.h            | 10 +++++-----
 qom/object.c                    | 20 ++++++++++----------
 tests/unit/check-qom-proplist.c |  4 ++--
 3 files changed, 17 insertions(+), 17 deletions(-)
include/qom/object.h +5 -5
index 510885218b..c7d80914fb 100644
@@ -689,16 +689,16 @@ Object *object_new_with_props(const char *typename,
  * @typename:  The name of the type of the object to instantiate.
  * @parent: the parent object
  * @id: The unique ID of the object
- * @errp: pointer to error object
  * @vargs: list of property names and values
+ * @errp: pointer to error object
  *
  * See object_new_with_props() for documentation.
  */
 Object *object_new_with_propv(const char *typename,
                               Object *parent,
                               const char *id,
-                              Error **errp,
-                              va_list vargs);
+                              va_list vargs,
+                              Error **errp);
 
 /**
  * object_set_props:
@@ -739,14 +739,14 @@ bool object_set_props(Object *obj, Error **errp, ...) G_GNUC_NULL_TERMINATED;
 /**
  * object_set_propv:
  * @obj: the object instance to set properties on
- * @errp: pointer to error object
  * @vargs: list of property names and values
+ * @errp: pointer to error object
  *
  * See object_set_props() for documentation.
  *
  * Returns: %true on success, %false on error.
  */
-bool object_set_propv(Object *obj, Error **errp, va_list vargs);
+bool object_set_propv(Object *obj, va_list vargs, Error **errp);
 
 /**
  * object_initialize:
qom/object.c +10 -10
index 62d2f0486a..608c9c0ac7 100644
@@ -550,7 +550,7 @@ bool object_initialize_child_with_propsv(Object *parentobj,
     object_initialize(childobj, size, type);
     obj = OBJECT(childobj);
 
-    if (!object_set_propv(obj, errp, vargs)) {
+    if (!object_set_propv(obj, vargs, errp)) {
         goto out;
     }
 
@@ -749,7 +749,7 @@ Object *object_new_with_props(const char *typename,
     Object *obj;
 
     va_start(vargs, errp);
-    obj = object_new_with_propv(typename, parent, id, errp, vargs);
+    obj = object_new_with_propv(typename, parent, id, vargs, errp);
     va_end(vargs);
 
     return obj;
@@ -759,8 +759,8 @@ Object *object_new_with_props(const char *typename,
 Object *object_new_with_propv(const char *typename,
                               Object *parent,
                               const char *id,
-                              Error **errp,
-                              va_list vargs)
+                              va_list vargs,
+                              Error **errp)
 {
     Object *obj;
     ObjectClass *klass;
@@ -785,7 +785,7 @@ Object *object_new_with_propv(const char *typename,
     }
     obj = object_new_with_type(klass->type);
 
-    if (!object_set_propv(obj, errp, vargs)) {
+    if (!object_set_propv(obj, vargs, errp)) {
         goto error;
     }
 
@@ -813,14 +813,14 @@ Object *object_new_with_propv(const char *typename,
 
 
 bool object_set_props(Object *obj,
-                     Error **errp,
-                     ...)
+                      Error **errp,
+                      ...)
 {
     va_list vargs;
     bool ret;
 
     va_start(vargs, errp);
-    ret = object_set_propv(obj, errp, vargs);
+    ret = object_set_propv(obj, vargs, errp);
     va_end(vargs);
 
     return ret;
@@ -828,8 +828,8 @@ bool object_set_props(Object *obj,
 
 
 bool object_set_propv(Object *obj,
-                     Error **errp,
-                     va_list vargs)
+                      va_list vargs,
+                      Error **errp)
 {
     const char *propname;
 
tests/unit/check-qom-proplist.c +2 -2
index ee3c6fb32b..7f31735459 100644
@@ -373,8 +373,8 @@ static Object *new_helper(Error **errp,
     obj = object_new_with_propv(TYPE_DUMMY,
                                 parent,
                                 "dummy0",
-                                errp,
-                                vargs);
+                                vargs,
+                                errp);
     va_end(vargs);
     return obj;
 }
Signature · 1 line
2.54.0
#14 lore raw

PATCH v2 7/10 qom: add object_new_with_props_from_qdict

In reply to Daniel P. Berrangé

This will be used to replace user_creatable_add_type with an impl that shares most code with object_new_with_props, and is not tied to the user creatable interface.

---
 include/qom/object.h | 19 +++++++++++
 qom/object.c         | 75 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 88 insertions(+), 6 deletions(-)
include/qom/object.h +19 -0
index 1b2b2702fc..cd59f1f171 100644
@@ -700,6 +700,25 @@ Object *object_new_with_propv(const char *typename,
                               va_list vargs,
                               Error **errp);
 
+/**
+ * object_new_with_props_from_qdict:
+ * @typename:  The name of the type of the object to instantiate.
+ * @parent: the parent object
+ * @id: The unique ID of the object
+ * @props: dictionary of property names and values
+ * @v: visitor to iterate over @props
+ * @errp: pointer to error object
+ *
+ * A variant of object_new_with_props() which accepts the
+ * properties in a QDict.
+ */
+Object *object_new_with_props_from_qdict(const char *typename,
+                                         Object *parent,
+                                         const char *id,
+                                         QDict *props,
+                                         Visitor *v,
+                                         Error **errp);
+
 /**
  * object_set_props:
  * @obj: the object instance to set properties on
qom/object.c +69 -6

93 lines not on this page · raw message

Signature · 1 line
2.54.0
#9 lore raw

PATCH v2 4/10 qom: shorten name of object_set_properties_from_keyval

In reply to Daniel P. Berrangé

This matches the convention established by the object_set_props and object_set_propv methods.

---
 include/qom/object.h    |  6 +++---
 qom/object_interfaces.c | 12 ++++++------
 system/qdev-monitor.c   |  4 ++--
 system/vl.c             |  7 ++++---
 4 files changed, 15 insertions(+), 14 deletions(-)
include/qom/object.h +3 -3
index c7d80914fb..d841c338a2 100644
@@ -915,7 +915,7 @@ type_init(do_qemu_init_ ## type_array)
 bool type_print_class_properties(const char *type);
 
 /**
- * object_set_properties_from_keyval:
+ * object_set_props_from_keyval:
  * @obj: a QOM object
  * @qdict: a dictionary with the properties to be set
  * @from_json: true if leaf values of @qdict are typed, false if they
@@ -925,8 +925,8 @@ bool type_print_class_properties(const char *type);
  * For each key in the dictionary, parse the value string if needed,
  * then set the corresponding property in @obj.
  */
-void object_set_properties_from_keyval(Object *obj, const QDict *qdict,
-                                       bool from_json, Error **errp);
+void object_set_props_from_keyval(Object *obj, const QDict *qdict,
+                                  bool from_json, Error **errp);
 
 /**
  * object_class_dynamic_cast_assert:
qom/object_interfaces.c +6 -6
index 415cbee8c5..4377d65b76 100644
@@ -44,8 +44,8 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
     }
 }
 
-static void object_set_properties_from_qdict(Object *obj, const QDict *qdict,
-                                             Visitor *v, Error **errp)
+static void object_set_props_from_qdict(Object *obj, const QDict *qdict,
+                                        Visitor *v, Error **errp)
 {
     const QDictEntry *e;
 
@@ -62,8 +62,8 @@ out:
     visit_end_struct(v, NULL);
 }
 
-void object_set_properties_from_keyval(Object *obj, const QDict *qdict,
-                                       bool from_json, Error **errp)
+void object_set_props_from_keyval(Object *obj, const QDict *qdict,
+                                  bool from_json, Error **errp)
 {
     Visitor *v;
     if (from_json) {
@@ -71,7 +71,7 @@ void object_set_properties_from_keyval(Object *obj, const QDict *qdict,
     } else {
         v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
     }
-    object_set_properties_from_qdict(obj, qdict, v, errp);
+    object_set_props_from_qdict(obj, qdict, v, errp);
     visit_free(v);
 }
 
@@ -110,7 +110,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
 
     assert(qdict);
     obj = object_new_with_class(klass);
-    object_set_properties_from_qdict(obj, qdict, v, &local_err);
+    object_set_props_from_qdict(obj, qdict, v, &local_err);
     if (local_err) {
         goto out;
     }
system/qdev-monitor.c +2 -2
index e5b55e3004..dfc95a08c1 100644
@@ -730,8 +730,8 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
     qdict_del(properties, "bus");
     qdict_del(properties, "id");
 
-    object_set_properties_from_keyval(&dev->parent_obj, properties, from_json,
-                                      errp);
+    object_set_props_from_keyval(&dev->parent_obj, properties, from_json,
+                                 errp);
     qobject_unref(properties);
     if (*errp) {
         goto err_del_dev;
system/vl.c +4 -3
index d2f4044e5d..288819c409 100644
@@ -2009,7 +2009,8 @@ static bool object_create_early(const char *type)
 
 static void qemu_apply_machine_options(QDict *qdict)
 {
-    object_set_properties_from_keyval(OBJECT(current_machine), qdict, false, &error_fatal);
+    object_set_props_from_keyval(OBJECT(current_machine), qdict,
+                                 false, &error_fatal);
 
     if (semihosting_enabled(false) && !semihosting_get_argc()) {
         /* fall back to the -kernel/-append */
@@ -2224,8 +2225,8 @@ static void qemu_create_machine(QDict *qdict)
             keyval_parse(machine_class->default_machine_opts, NULL, NULL,
                          &error_abort);
         qemu_apply_legacy_machine_options(default_opts);
-        object_set_properties_from_keyval(OBJECT(current_machine), default_opts,
-                                          false, &error_abort);
+        object_set_props_from_keyval(OBJECT(current_machine), default_opts,
+                                     false, &error_abort);
         qobject_unref(default_opts);
     }
 }
Signature · 1 line
2.54.0
#19 lore raw

PATCH v2 10/10 qom: drop user_creatable_add_type method

In reply to Daniel P. Berrangé

This can be replaced by object_new_with_props_from_qdict, which does functionally the same job, but the caller does not own the returned reference, instead the parent object owns it.

In one case we can use object_new_with_props_from_qdict_owned instead since the object is not intended to have any parent.

---
 authz/listfile.c                |  4 +-
 include/qom/object_interfaces.h | 18 ---------
 qom/object_interfaces.c         | 70 ++-------------------------------
 tests/unit/check-qom-proplist.c |  5 +--
 4 files changed, 7 insertions(+), 90 deletions(-)
authz/listfile.c +2 -2
index 13741d5a72..23655f8663 100644
@@ -79,8 +79,8 @@ qauthz_list_file_load(QAuthZListFile *fauthz, Error **errp)
 
     v = qobject_input_visitor_new(obj);
 
-    ret = (QAuthZ *)user_creatable_add_type(TYPE_QAUTHZ_LIST,
-                                            NULL, pdict, v, errp);
+    ret = QAUTHZ(object_new_with_props_from_qdict_parentless(
+                     TYPE_QAUTHZ_LIST, pdict, v, errp));
 
  cleanup:
     visit_free(v);
include/qom/object_interfaces.h +0 -18
index 02b11a7ef0..e2b8615617 100644
@@ -69,24 +69,6 @@ bool user_creatable_complete(UserCreatable *uc, Error **errp);
  */
 bool user_creatable_can_be_deleted(UserCreatable *uc);
 
-/**
- * user_creatable_add_type:
- * @type: the object type name
- * @id: the unique ID for the object
- * @qdict: the object properties
- * @v: the visitor
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Create an instance of the user creatable object @type, placing
- * it in the object composition tree with name @id, initializing
- * it with properties from @qdict
- *
- * Returns: the newly created object or NULL on error
- */
-Object *user_creatable_add_type(const char *type, const char *id,
-                                const QDict *qdict,
-                                Visitor *v, Error **errp);
-
 /**
  * user_creatable_add_qapi:
  * @options: the object definition
qom/object_interfaces.c +3 -67

87 lines not on this page · raw message

tests/unit/check-qom-proplist.c +2 -3
index 954c898ce1..89de92b7d9 100644
@@ -461,10 +461,9 @@ static void test_dummy_createlist_parentless(void)
 static bool test_create_obj(QDict *qdict, Error **errp)
 {
     Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
-    Object *obj = user_creatable_add_type(TYPE_DUMMY, "dev0", qdict, v, errp);
-
+    Object *obj = object_new_with_props_from_qdict(
+        TYPE_DUMMY, object_get_objects_root(), "dev0", qdict, v, errp);
     visit_free(v);
-    object_unref(obj);
     return !!obj;
 }
 
Signature · 1 line
2.54.0
#18 lore raw

PATCH v2 9/10 qom: allow object_new_with_prop* to trigger module loading

In reply to Daniel P. Berrangé

The object_new_with_prop* methods will shortly be replacing the user_creatable_add_type method. In order to do that, the object_new_with_prop* methods must allow module loading to be triggered for any types.

---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qom/object.c +1 -1
index f530ce9a7d..19c5dce452 100644
@@ -783,7 +783,7 @@ object_new_with_props_helper(const char *typename,
         return NULL;
     }
 
-    klass = object_class_by_name(typename);
+    klass = module_object_class_by_name(typename);
     if (!klass) {
         error_setg(errp, "invalid object type: %s", typename);
         return NULL;
Signature · 1 line
2.54.0
#12 lore raw

PATCH v2 6/10 qom: move object_set_prop_keyval into object.c

In reply to Daniel P. Berrangé

This matches the location of the object_set_props and object_set_propv methods, since this method is not inherently tied to the user creatable interface. As part of this, object_set_props_from_qdict is also exposed as a public API since it is still called from object_interfaces.c.

---
 include/qom/object.h    | 47 +++++++++++++++++++++++++++--------------
 qom/object.c            | 36 +++++++++++++++++++++++++++++++
 qom/object_interfaces.c | 36 -------------------------------
 3 files changed, 67 insertions(+), 52 deletions(-)
include/qom/object.h +31 -16
index 20a04cc4a9..1b2b2702fc 100644
@@ -748,6 +748,37 @@ bool object_set_props(Object *obj, Error **errp, ...) G_GNUC_NULL_TERMINATED;
  */
 bool object_set_propv(Object *obj, va_list vargs, Error **errp);
 
+/**
+ * object_set_props_from_qdict:
+ * @obj: a QOM object
+ * @qdict: a dictionary with the properties to be set
+ * @v: a visitor to iterate over @dict
+ * @errp: pointer to error object
+ *
+ * For each key in the dictionary, set the corresponding
+ * property in @obj.
+ *
+ * Returns: %true on success, %false on error.
+ */
+bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
+                                 Visitor *v, Error **errp);
+
+/**
+ * object_set_props_from_keyval:
+ * @obj: a QOM object
+ * @qdict: a dictionary with the properties to be set
+ * @from_json: true if leaf values of @qdict are typed, false if they
+ * are strings
+ * @errp: pointer to error object
+ *
+ * For each key in the dictionary, parse the value string if needed,
+ * then set the corresponding property in @obj.
+ *
+ * Returns: %true on success, %false on error.
+ */
+bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
+                                  bool from_json, Error **errp);
+
 /**
  * object_initialize:
  * @obj: A pointer to the memory to be used for the object.
@@ -914,22 +945,6 @@ type_init(do_qemu_init_ ## type_array)
  */
 bool type_print_class_properties(const char *type);
 
-/**
- * object_set_props_from_keyval:
- * @obj: a QOM object
- * @qdict: a dictionary with the properties to be set
- * @from_json: true if leaf values of @qdict are typed, false if they
- * are strings
- * @errp: pointer to error object
- *
- * For each key in the dictionary, parse the value string if needed,
- * then set the corresponding property in @obj.
- *
- * Returns: %true on success, %false on error.
- */
-bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
-                                  bool from_json, Error **errp);
-
 /**
  * object_class_dynamic_cast_assert:
  * @klass: The #ObjectClass to attempt to cast.
qom/object.c +36 -0
index 608c9c0ac7..d8083dc318 100644
@@ -23,6 +23,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/forward-visitor.h"
 #include "qapi/qapi-builtin-visit.h"
+#include "qobject/qdict.h"
 #include "qobject/qjson.h"
 #include "qemu/id.h"
 #include "qapi/qmp/qerror.h"
@@ -847,6 +848,41 @@ bool object_set_propv(Object *obj,
     return true;
 }
 
+bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
+                                 Visitor *v, Error **errp)
+{
+    ERRP_GUARD();
+    const QDictEntry *e;
+
+    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
+        return false;
+    }
+    for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
+        if (!object_property_set(obj, e->key, v, errp)) {
+            goto out;
+        }
+    }
+    visit_check_struct(v, errp);
+out:
+    visit_end_struct(v, NULL);
+
+    return *errp == NULL;
+}
+
+bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
+                                  bool from_json, Error **errp)
+{
+    bool ret;
+    Visitor *v;
+    if (from_json) {
+        v = qobject_input_visitor_new(QOBJECT(qdict));
+    } else {
+        v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
+    }
+    ret = object_set_props_from_qdict(obj, qdict, v, errp);
+    visit_free(v);
+    return ret;
+}
 
 Object *object_dynamic_cast(Object *obj, const char *typename)
 {
qom/object_interfaces.c +0 -36
index 50736b80c8..e0a3cd8d0f 100644
@@ -44,42 +44,6 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
     }
 }
 
-static bool object_set_props_from_qdict(Object *obj, const QDict *qdict,
-                                        Visitor *v, Error **errp)
-{
-    ERRP_GUARD();
-    const QDictEntry *e;
-
-    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
-        return false;
-    }
-    for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
-        if (!object_property_set(obj, e->key, v, errp)) {
-            goto out;
-        }
-    }
-    visit_check_struct(v, errp);
-out:
-    visit_end_struct(v, NULL);
-
-    return *errp == NULL;
-}
-
-bool object_set_props_from_keyval(Object *obj, const QDict *qdict,
-                                  bool from_json, Error **errp)
-{
-    bool ret;
-    Visitor *v;
-    if (from_json) {
-        v = qobject_input_visitor_new(QOBJECT(qdict));
-    } else {
-        v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
-    }
-    ret = object_set_props_from_qdict(obj, qdict, v, errp);
-    visit_free(v);
-    return ret;
-}
-
 Object *user_creatable_add_type(const char *type, const char *id,
                                 const QDict *qdict,
                                 Visitor *v, Error **errp)
Signature · 1 line
2.54.0
#15 lore raw

Re: [PATCH v2 07/10] qom: add object_new_with_props_from_qdict

In reply to Daniel P. Berrangé

include/qom/object.h Object *object_new_with_propv(const char *typename, · line 718

Quoted 12 lines · Daniel P. Berrangé
include/qom/object.h +0 -0
index 1b2b2702fc9..cd59f1f1718 100644
@@ -700,6 +700,25 @@ Object *object_new_with_propv(const char *typename,

[ ... skip 13 lines ... ]
+ * properties in a QDict.
+ */

include/qom/object.h +4 -0
+Object *object_new_with_props_from_qdict(const char *typename,
+                                         Object *parent,
+                                         const char *id,
+                                         QDict *props,

This should take a const QDict, same for the _parentless added later.

Signature · 1 line
Marc-André Lureau <[email protected]>
#2 lore raw

Re: [PATCH v2 01/10] qom: add trace events for object/property lifecycle

In reply to Daniel P. Berrangé
Quoted 5 lines · Daniel P. Berrangé
qom/trace-events +0 -0
index b2e9f4a7127..9aabbae4f73 100644

qom/trace-events line 8

Quoted 10 lines
qom/trace-events +5 -2
@@ -1,5 +1,13 @@
 # See docs/devel/tracing.rst for syntax documentation.
 
 # object.c
-object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
-object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
+object_dynamic_cast_assert(void *obj, const char *type, const char *target, const char *file, int line, const char *func) "obj=%p type=%s->%s (%s:%d:%s)"
+object_finalize(void *obj, const char *type) "obj=%p type=%s"
+object_new(void *obj, const char *type) "obj=%p type=%s"
+object_property_add(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
+object_property_add_child(void *obj, const char *type, const char *name, void *parent, const char *parenttype) "obj=%p type=%s name=%s parent=%p parent-type=%s"

The 4th and 5th parameters are the child being added, not a parent. In object_property_try_add_child the call is:

trace_object_property_add_child(obj, ..., child, child->class->type->name)

So the parameter names should be "child"/"childtype" and the format string should use "child=" / "child-type=".

qom/trace-events line 10

Quoted 2 lines
qom/trace-events +2 -0
+object_property_del(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
+object_property_del_child(void *obj, const char *type, void *parent, const char *parenttype) "obj=%p type=%s parent=%p parent-type=%s"

Same here

Signature · 1 line
Marc-André Lureau <[email protected]>
#20 lore raw

Re: [PATCH v2 10/10] qom: drop user_creatable_add_type method

In reply to Daniel P. Berrangé

qom/object_interfaces.c bool user_creatable_can_be_deleted(UserCreatable *uc) · line 74

Quoted 12 lines · Daniel P. Berrangé
qom/object_interfaces.c +0 -0
index e0a3cd8d0f7..7080f85f95f 100644
@@ -44,75 +44,11 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)

[ ... skip 25 lines ... ]

qom/object_interfaces.c +0 -6
-    if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
-        error_setg(errp, "object type '%s' isn't supported by object-add",
-                   type);
-        return NULL;
-    }
-

It's worth to mention in the commit message that -object and object-add go through QAPI ObjectOptions list, and thus don't need the now gone TYPE_USER_CREATABLE check.

Signature · 1 line
Marc-André Lureau <[email protected]>
#21 lore raw

Re: [PATCH v2 10/10] qom: drop user_creatable_add_type method

Quoted 17 lines · On Fri, May 08, 2026 at 07:18:29PM +0400, [email protected] wrote:

qom/object_interfaces.c bool user_creatable_can_be_deleted(UserCreatable *uc) · line 74

Quoted 12 lines · Daniel P. Berrangé
qom/object_interfaces.c +0 -0
index e0a3cd8d0f7..7080f85f95f 100644
@@ -44,75 +44,11 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)

[ ... skip 25 lines ... ]

qom/object_interfaces.c +0 -6
-    if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
-        error_setg(errp, "object type '%s' isn't supported by object-add",
-                   type);
-        return NULL;
-    }
-

It's worth to mention in the commit message that -object and object-add go through QAPI ObjectOptions list, and thus don't need the now gone TYPE_USER_CREATABLE check.

Actually I hadn't taken that into account as it doesn't matter what the caller does in this case.

In this user_creatable_add_type method, we needed a TYPE_USER_CREATABLE check because the method later calls 'user_creatable_complete' unconditionally.

In the new object_new_with_prop* methods, user_creatable_complete is conditionally called only if a cast to TYPE_USER_CREATABLE succeeds.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#3 lore raw

Re: [PATCH v2 01/10] qom: add trace events for object/property lifecycle

In reply to [email protected]
Quoted 22 lines · On Fri, May 08, 2026 at 07:18:29PM +0400, [email protected] wrote:
Quoted 5 lines · Daniel P. Berrangé
qom/trace-events +0 -0
index b2e9f4a7127..9aabbae4f73 100644

qom/trace-events line 8

Quoted 10 lines
qom/trace-events +5 -2
@@ -1,5 +1,13 @@
 # See docs/devel/tracing.rst for syntax documentation.
 
 # object.c
-object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
-object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
+object_dynamic_cast_assert(void *obj, const char *type, const char *target, const char *file, int line, const char *func) "obj=%p type=%s->%s (%s:%d:%s)"
+object_finalize(void *obj, const char *type) "obj=%p type=%s"
+object_new(void *obj, const char *type) "obj=%p type=%s"
+object_property_add(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
+object_property_add_child(void *obj, const char *type, const char *name, void *parent, const char *parenttype) "obj=%p type=%s name=%s parent=%p parent-type=%s"

The 4th and 5th parameters are the child being added, not a parent. In object_property_try_add_child the call is:

trace_object_property_add_child(obj, ..., child, child->class->type->name)

Quoted 7 lines

So the parameter names should be "child"/"childtype" and the format string should use "child=" / "child-type=".

qom/trace-events line 10

Quoted 2 lines
qom/trace-events +2 -0
+object_property_del(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
+object_property_del_child(void *obj, const char *type, void *parent, const char *parenttype) "obj=%p type=%s parent=%p parent-type=%s"

Same here

Opps, yes, I don't know what I was thinking there !

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#16 lore raw

Re: [PATCH v2 07/10] qom: add object_new_with_props_from_qdict

In reply to [email protected]
Quoted 15 lines · On Fri, May 08, 2026 at 07:18:29PM +0400, [email protected] wrote:

include/qom/object.h Object *object_new_with_propv(const char *typename, · line 718

Quoted 12 lines · Daniel P. Berrangé
include/qom/object.h +0 -0
index 1b2b2702fc9..cd59f1f1718 100644
@@ -700,6 +700,25 @@ Object *object_new_with_propv(const char *typename,

[ ... skip 13 lines ... ]
+ * properties in a QDict.
+ */

include/qom/object.h +4 -0
+Object *object_new_with_props_from_qdict(const char *typename,
+                                         Object *parent,
+                                         const char *id,
+                                         QDict *props,

This should take a const QDict, same for the _parentless added later.

Ah yes, that would match the existing object_set_props_from_qdict signature.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
Reviewed-by on v2 5/10
#11 lore raw

Re: [PATCH v2 05/10] qom: have object_set_props_keyval return bool

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

This matches the convention established by the object_set_props and object_set_propv methods.

---
  include/qom/object.h    |  4 +++-
  qom/object_interfaces.c | 13 +++++++++----
  2 files changed, 12 insertions(+), 5 deletions(-)
#5 lore raw

Re: [PATCH v2 02/10] qom: validate ID format when creating objects

In reply to Daniel P. Berrangé
Quoted 22 lines · Daniel P. Berrangé

The object_new_with_props/propv methods failed to validate the ID string format, thus diverging from user_creatable_add_type.

---
  qom/object.c | 9 +++++++++
  1 file changed, 9 insertions(+)
qom/object.c +2 -0
index 9c391071fb..62d2f0486a 100644
@@ -24,6 +24,8 @@
  #include "qapi/forward-visitor.h"
  #include "qapi/qapi-builtin-visit.h"
  #include "qobject/qjson.h"
+#include "qemu/id.h"
+#include "qapi/qmp/qerror.h"
  #include "trace.h"
 
  /* TODO: replace QObject with a simpler visitor to avoid a dependency

qom/object.c Object *object_new_with_propv(const char *typename, · line 774

Quoted 9 lines
qom/object.c +6 -0
@@ -764,6 +766,13 @@ Object *object_new_with_propv(const char *typename,
      ObjectClass *klass;
      UserCreatable *uc;
 
+    if (id != NULL && !id_wellformed(id)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+        error_append_hint(errp, "Identifiers consist of letters, digits, "
+                          "'-', '.', '_', starting with a letter.\n");
+        return NULL;
+    }

Use a common object_identifier_is_well_formed() helper?

Quoted 4 lines
qom/object.c +1 -0
+
      klass = object_class_by_name(typename);
      if (!klass) {
          error_setg(errp, "invalid object type: %s", typename);
Reviewed-by on v2 6/10
#13 lore raw

Re: [PATCH v2 06/10] qom: move object_set_prop_keyval into object.c

In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé

This matches the location of the object_set_props and object_set_propv methods, since this method is not inherently tied to the user creatable interface. As part of this, object_set_props_from_qdict is also exposed as a public API since it is still called from object_interfaces.c.

---
  include/qom/object.h    | 47 +++++++++++++++++++++++++++--------------
  qom/object.c            | 36 +++++++++++++++++++++++++++++++
  qom/object_interfaces.c | 36 -------------------------------
  3 files changed, 67 insertions(+), 52 deletions(-)
#6 lore raw

Re: [PATCH v2 02/10] qom: validate ID format when creating objects

In reply to Philippe Mathieu-Daudé
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Daniel P. Berrangé

The object_new_with_props/propv methods failed to validate the ID string format, thus diverging from user_creatable_add_type.

---
  qom/object.c | 9 +++++++++

  1 file changed, 9 insertions(+)
qom/object.c +4 -0
index 9c391071fb..62d2f0486a 100644
@@ -24,6 +24,8 @@
   #include "qapi/forward-visitor.h"
   #include "qapi/qapi-builtin-visit.h"
   #include "qobject/qjson.h"
+#include "qemu/id.h"
+#include "qapi/qmp/qerror.h"
   #include "trace.h"
   /* TODO: replace QObject with a simpler visitor to avoid a dependency
@@ -764,6 +766,13 @@ Object *object_new_with_propv(const char *typename,
       ObjectClass *klass;
       UserCreatable *uc;
+    if (id != NULL && !id_wellformed(id)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an 
Quoted 8 lines
Quoted 6 lines
qom/object.c +1 -0
 identifier");
+        error_append_hint(errp, "Identifiers consist of letters, 

digits, "
+                          "'-', '.', '_', starting with a letter.\n"); +        return NULL;
+    }

Use a common object_identifier_is_well_formed() helper?

I see the last patch of this series remove the duplication, so:

#7 lore raw

Re: [PATCH v2 02/10] qom: validate ID format when creating objects

In reply to Philippe Mathieu-Daudé
Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Daniel P. Berrangé

The object_new_with_props/propv methods failed to validate the ID string format, thus diverging from user_creatable_add_type.

---
  qom/object.c | 9 +++++++++
  1 file changed, 9 insertions(+)
qom/object.c +2 -0
index 9c391071fb..62d2f0486a 100644
@@ -24,6 +24,8 @@
  #include "qapi/forward-visitor.h"
  #include "qapi/qapi-builtin-visit.h"
  #include "qobject/qjson.h"
+#include "qemu/id.h"
+#include "qapi/qmp/qerror.h"
  #include "trace.h"
  /* TODO: replace QObject with a simpler visitor to avoid a dependency
@@ -764,6 +766,13 @@ Object *object_new_with_propv(const char *typename,
      ObjectClass *klass;
      UserCreatable *uc;
Quoted 8 lines

qom/object.c Object *object_new_with_propv(const char *typename, · line 774

Quoted 6 lines
qom/object.c +6 -0
+    if (id != NULL && !id_wellformed(id)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+        error_append_hint(errp, "Identifiers consist of letters, digits, "
+                          "'-', '.', '_', starting with a letter.\n");
+        return NULL;
+    }

Use a common object_identifier_is_well_formed() helper?

At the end of this series, the only other use of id_wellformed in qom/object_interfaces.c is removed, so there is no need for an extracted helper method IMHO

Quoted 6 lines

qom/object.c Object *object_new_with_propv(const char *typename, · line 778

Quoted 5 lines
qom/object.c +1 -0
+
      klass = object_class_by_name(typename);
      if (!klass) {
          error_setg(errp, "invalid object type: %s", typename);

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|