Skip to contentSkip to conversation

qmp: Return extra information on qom-list-types

PATCH Superseded Eduardo Habkost 2 participants 8 messages May 26, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover qmp: Return extra information on qom-list-types

This series adds 'abstract' and 'parent' fields to the output of qom-list-types.

For reference, below are the sizes of the output of "qom-list-types abstract=true" on qemu-system-x86_64, before and after applying the patches:

* before: 11724 bytes
* with 'abstract' field: 13146 bytes
* with 'abstract' and 'parent': 24046 bytes

Changes v1 (RFC) -> v2:
* Make 'parent' field optional, to make output shorter
* Return only immediate parent type on 'parent' field, instead of all parent-types on a 'parent-types' field

Eduardo Habkost (3):
tests: Simplify abstract-interfaces check with a helper
qmp: Include 'abstract' field on 'qom-list-types' output
qmp: Include parent type on 'qom-list-types' output

 qapi-schema.json               |   7 +-
 qmp.c                          |   6 ++
 tests/device-introspect-test.c | 156 +++++++++++++++++++++++++++++++++--------
 3 files changed, 139 insertions(+), 30 deletions(-)
Signature · 1 line
2.11.0.259.g40922b1
#1 lore raw

PATCH v2 1/3 tests: Simplify abstract-interfaces check with a helper

Add a new type_list_find() helper to device-introspect-test.c, to simplify the code at test_abstract_interfaces().

---
 tests/device-introspect-test.c | 43 ++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)
tests/device-introspect-test.c +25 -18
index b1abb2ad89..f1e6dddfa3 100644
@@ -45,6 +45,22 @@ static QList *qom_list_types(const char *implements, bool abstract)
     return ret;
 }
 
+/* Find an entry on a list returned by qom-list-types */
+static QDict *type_list_find(QList *types, const char *name)
+{
+    QListEntry *e;
+
+    QLIST_FOREACH_ENTRY(types, e) {
+        QDict *d = qobject_to_qdict(qlist_entry_obj(e));
+        const char *ename = qdict_get_str(d, "name");
+        if (!strcmp(ename, name)) {
+            return d;
+        }
+    }
+
+    return NULL;
+}
+
 static QList *device_type_list(bool abstract)
 {
     return qom_list_types("device", abstract);
@@ -125,7 +141,7 @@ static void test_abstract_interfaces(void)
 {
     QList *all_types;
     QList *obj_types;
-    QListEntry *ae;
+    QListEntry *e;
 
     qtest_start(common_args);
     /* qom-list-types implements=interface would return any type
@@ -138,24 +154,15 @@ static void test_abstract_interfaces(void)
     all_types = qom_list_types(NULL, false);
     obj_types = qom_list_types("object", false);
 
-    QLIST_FOREACH_ENTRY(all_types, ae) {
-        QDict *at = qobject_to_qdict(qlist_entry_obj(ae));
-        const char *aname = qdict_get_str(at, "name");
-        QListEntry *oe;
-        const char *found = NULL;
-
-        QLIST_FOREACH_ENTRY(obj_types, oe) {
-            QDict *ot = qobject_to_qdict(qlist_entry_obj(oe));
-            const char *oname = qdict_get_str(ot, "name");
-            if (!strcmp(aname, oname)) {
-                found = oname;
-                break;
-            }
-        }
+    QLIST_FOREACH_ENTRY(all_types, e) {
+        QDict *d = qobject_to_qdict(qlist_entry_obj(e));
+
+        /*
+         * An interface (incorrectly) marked as non-abstract would
+         * appear on all_types, but not on obj_types:
+         */
+        g_assert(type_list_find(obj_types, qdict_get_str(d, "name")));
 
-        /* Using g_assert_cmpstr() will give more useful failure
-         * messages than g_assert(found) */
-        g_assert_cmpstr(aname, ==, found);
     }
 
     QDECREF(all_types);
Signature · 1 line
2.11.0.259.g40922b1
Reviewed-by on v2 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] tests: Simplify abstract-interfaces check with a helper

Quoted 8 lines · Eduardo Habkost

Add a new type_list_find() helper to device-introspect-test.c, to simplify the code at test_abstract_interfaces().

---
 tests/device-introspect-test.c | 43 ++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw

PATCH v2 2/3 qmp: Include 'abstract' field on 'qom-list-types' output

In reply to Eduardo Habkost

A client may be interested in getting the list of both abstract and non-abstract types. Instead of requiring them to make multiple queries with different filter arguments, just return an 'abstract' field in 'qom-list-types'.

In addition to the new test code for validating this field, update the abstract-interfaces test case to query for all 'interface' subtypes (including abstract ones), and to look at the 'abstract' field directly.

---
Changes v1 -> v2:
* Omit field if false, to keep command output smaller.

---
 qapi-schema.json               |  5 +++-
 qmp.c                          |  1 +
 tests/device-introspect-test.c | 53 +++++++++++++++++++++++++++++++-----------
 3 files changed, 45 insertions(+), 14 deletions(-)
qapi-schema.json +4 -1
index e38c5f0423..6af4b38851 100644
@@ -3056,12 +3056,15 @@
 #
 # @name: the type name found in the search
 #
+# @abstract: the type is abstract and can't be directly instantiated.
+#            Omitted if false. (since 2.10)
+#
 # Since: 1.1
 #
 # Notes: This command is experimental and may change syntax in future releases.
 ##
 { 'struct': 'ObjectTypeInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*abstract': 'bool' } }
 
 ##
 # @qom-list-types:
qmp.c +1 -0
index f656940769..413a917802 100644
@@ -443,6 +443,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(object_class_get_name(klass));
+    info->has_abstract = info->abstract = object_class_is_abstract(klass);
 
     e = g_malloc0(sizeof(*e));
     e->value = info;
tests/device-introspect-test.c +40 -13

77 lines not on this page · raw message

Signature · 1 line
2.11.0.259.g40922b1
Reviewed-by on v2 2/3
#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/3] qmp: Include 'abstract' field on 'qom-list-types' output

Quoted 14 lines · Eduardo Habkost

A client may be interested in getting the list of both abstract and non-abstract types. Instead of requiring them to make multiple queries with different filter arguments, just return an 'abstract' field in 'qom-list-types'.

In addition to the new test code for validating this field, update the abstract-interfaces test case to query for all 'interface' subtypes (including abstract ones), and to look at the 'abstract' field directly.

---

+++ b/qapi-schema.json

qapi-schema.json line 3061

Quoted 6 lines
qapi-schema.json +3 -0
@@ -3056,12 +3056,15 @@
 #
 # @name: the type name found in the search
 #
+# @abstract: the type is abstract and can't be directly instantiated.
+#            Omitted if false. (since 2.10)
+#

A little bit awkward in that libvirt will have to see if ANY entry in the large returned result has "abstract":true before it can assume "abstract":false on the remaining entries (that is, older qemu don't output abstract ever, but still mentions abstract types, so blindly writing code to assume absence of "abstract" means false breaks on those older versions). Or a query of introspection to see if the field name is even supported would do. Not insurmountable, though.

qapi-schema.json line 3064

Quoted 3 lines
qapi-schema.json +0 -0
 # Since: 1.1
 #
 # Notes: This command is experimental and may change syntax in future releases.

Is this note still helpful, or should we delete it now?

qapi-schema.json line 3067

Quoted 4 lines
qapi-schema.json +1 -1
 ##
 { 'struct': 'ObjectTypeInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*abstract': 'bool' } }
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/3] qmp: Include 'abstract' field on 'qom-list-types' output

Quoted 13 lines · Eric Blake
Quoted 11 lines · Eduardo Habkost

A client may be interested in getting the list of both abstract and non-abstract types. Instead of requiring them to make multiple queries with different filter arguments, just return an 'abstract' field in 'qom-list-types'.

In addition to the new test code for validating this field, update the abstract-interfaces test case to query for all 'interface' subtypes (including abstract ones), and to look at the 'abstract' field directly.

---

Quoted 16 lines

qapi-schema.json line 3061

Quoted 8 lines

+++ b/qapi-schema.json

qapi-schema.json +3 -0
@@ -3056,12 +3056,15 @@
 #
 # @name: the type name found in the search
 #
+# @abstract: the type is abstract and can't be directly instantiated.
+#            Omitted if false. (since 2.10)
+#

A little bit awkward in that libvirt will have to see if ANY entry in the large returned result has "abstract":true before it can assume "abstract":false on the remaining entries (that is, older qemu don't output abstract ever, but still mentions abstract types, so blindly writing code to assume absence of "abstract" means false breaks on those older versions). Or a query of introspection to see if the field name is even supported would do. Not insurmountable, though.

True.

I have the impression that management is not likely to look at this field in the near future. Probably the new field will be more useful for automated test code like device-instrospect-test.c and the device-crash-test script I submitted recently.

Quoted 6 lines

qapi-schema.json line 3064

Quoted 4 lines
qapi-schema.json +0 -0
 # Since: 1.1
 #
 # Notes: This command is experimental and may change syntax in future releases.

Is this note still helpful, or should we delete it now?

The patch removing this line is already in a pending pull request submitted by Markus last Tuesday.

Quoted 7 lines

qapi-schema.json line 3067

Quoted 5 lines
qapi-schema.json +1 -1
 ##
 { 'struct': 'ObjectTypeInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*abstract': 'bool' } }

Thanks!

Signature · 1 line
Eduardo
#6 lore raw

PATCH v2 3/3 qmp: Include parent type on 'qom-list-types' output

In reply to Eduardo Habkost

Include name of parent type of each type on 'qom-list-types' output.

Without this, there's no way to figure out the parents of a given type without making additional 'qom-list-types' queries.

In addition to the test case for the new feature, update the abstract-interface test case to use the new field and avoid the "qom-list-types implements=object" trick.

---
Changes v1 -> v2:
* Include only immediate parent type, rename new field to 'parent'

---
 qapi-schema.json               |  4 +-
 qmp.c                          |  5 +++
 tests/device-introspect-test.c | 84 +++++++++++++++++++++++++++++++++++++-----
 3 files changed, 82 insertions(+), 11 deletions(-)
qapi-schema.json +3 -1
index 6af4b38851..14b09fd069 100644
@@ -3059,12 +3059,14 @@
 # @abstract: the type is abstract and can't be directly instantiated.
 #            Omitted if false. (since 2.10)
 #
+# @parent: Name of parent type, if any (since 2.10)
+#
 # Since: 1.1
 #
 # Notes: This command is experimental and may change syntax in future releases.
 ##
 { 'struct': 'ObjectTypeInfo',
-  'data': { 'name': 'str', '*abstract': 'bool' } }
+  'data': { 'name': 'str', '*abstract': 'bool', '*parent': 'str' } }
 
 ##
 # @qom-list-types:
qmp.c +5 -0
index 413a917802..db87a74315 100644
@@ -440,10 +440,15 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
 {
     ObjectTypeInfoList *e, **pret = data;
     ObjectTypeInfo *info;
+    ObjectClass *parent = object_class_get_parent(klass);
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(object_class_get_name(klass));
     info->has_abstract = info->abstract = object_class_is_abstract(klass);
+    if (parent) {
+        info->has_parent = true;
+        info->parent = g_strdup(object_class_get_name(parent));
+    }
 
     e = g_malloc0(sizeof(*e));
     e->value = info;
tests/device-introspect-test.c +74 -10

122 lines not on this page · raw message

Signature · 1 line
2.11.0.259.g40922b1
Reviewed-by on v2 3/3
#7 lore raw

Re: [Qemu-devel] [PATCH v2 3/3] qmp: Include parent type on 'qom-list-types' output

Quoted 11 lines · Eduardo Habkost

Include name of parent type of each type on 'qom-list-types' output.

Without this, there's no way to figure out the parents of a given type without making additional 'qom-list-types' queries.

In addition to the test case for the new feature, update the abstract-interface test case to use the new field and avoid the "qom-list-types implements=object" trick.

---

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org