Skip to contentSkip to conversation

Add a command to QMP to list the supported devices

PATCH In review Or Goshen 4 participants 7 messages Feb 24, 2014

lore
Share & tools
lore

Or Goshen

author
#0 lore raw

PATCH 1/1 Add a command to QMP to list the supported devices

From: Or Goshen <[email protected]>

Was done on behalf of Intel Corp.

---
 qapi-schema.json |   26 ++++++++++++++++++++++++++
 qdev-monitor.c   |   28 ++++++++++++++++++++++++++++
 qmp-commands.hx  |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 0 deletions(-)
qapi-schema.json +26 -0
index 05ced9d..cae1200 100644
@@ -526,6 +526,32 @@
 { 'command': 'query-commands', 'returns': ['CommandInfo'] }
 
 ##
+# @DeviceInfo:
+#
+# Information about a device
+#
+# @name: The command name
+# @bus: The bus it is connected to
+# @alias: Device alias
+# @desc: Description of the device
+#
+# Since: 1.6.0
+##
+{ 'type': 'DeviceInfo', 'data': {'name': 'str', 'bus': 'str', 'alias': 'str', 'desc': 'str'} }
+
+##
+# @query-devices:
+#
+# Return a list of supported devices
+#
+# Returns: A list of @DeviceInfo for all supported devices
+#
+# Since: 1.6.0
+##
+{ 'command': 'query-devices', 'returns': ['DeviceInfo'] }
+
+
+##
 # @EventInfo:
 #
 # Information about a QMP event
qdev-monitor.c +28 -0
index 1d3b68d..0a59fd9 100644
@@ -644,6 +644,34 @@ void do_info_qtree(Monitor *mon, const QDict *qdict)
         qbus_print(mon, sysbus_get_default(), 0);
 }
 
+static void qdev_list_devinfo(ObjectClass *klass, void *data)
+{
+    DeviceInfoList *e, **pret = data;
+    DeviceInfo *info;
+    DeviceClass *dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE);
+    if (!dc) return;
+
+    info = g_malloc0(sizeof(*info));
+    info->name = g_strdup(object_class_get_name(klass));
+    info->bus = g_strdup(dc->bus_type ? dc->bus_type : "");
+    info->alias = g_strdup(qdev_class_has_alias(dc) ? qdev_class_get_alias(dc) : "");
+    info->desc = g_strdup(dc->desc ? dc->desc : "");
+
+    e = g_malloc0(sizeof(*e));
+    e->value = info;
+    e->next = *pret;
+    *pret = e;
+}
+
+DeviceInfoList * qmp_query_devices(Error **errp)
+{
+    DeviceInfoList *list = NULL;
+
+    object_class_foreach(qdev_list_devinfo, TYPE_DEVICE, false, &list);
+
+    return list;
+}
+
 void do_info_qdm(Monitor *mon, const QDict *qdict)
 {
     qdev_print_devinfos(true);
qmp-commands.hx +40 -0
index cce6b81..be4451d 100644
@@ -1851,6 +1851,46 @@ EQMP
     },
 
 SQMP
+query-devices
+--------------
+
+List supported devices
+
+Each device is represented by a json-object, the returned value is a json-array
+of all devices.
+
+Each json-object contain:
+
+- "name": device's name (json-string)
+- "bus": bus the device connects to (json-string)
+- "alias": device's alias (json-string)
+- "desc": device's description (json-string)
+
+Example:
+
+-> { "execute": "query-devices" }
+<- {
+      "return":[
+         {
+            "name":"pci-bridge",
+            "bus":"PCI",
+            "alias":"",
+            "desc":"Standard PCI Bridge"
+         }
+      ]
+   }
+
+Note: This example has been shortened as the real response is too long.
+
+EQMP
+
+    {
+        .name       = "query-devices",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_devices,
+    },
+
+SQMP
 query-events
 --------------
 
Signature · 1 line
1.7.9
#1 lore raw

Il 24/02/2014 10:23, Or Goshen ha scritto:

Quoted 3 lines

From: Or Goshen <[email protected]>

Was done on behalf of Intel Corp.

Hi Or,

you can use qom-list-types for this purpose.

Paolo

Quoted 134 lines
---
 qapi-schema.json |   26 ++++++++++++++++++++++++++
 qdev-monitor.c   |   28 ++++++++++++++++++++++++++++
 qmp-commands.hx  |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 0 deletions(-)
qapi-schema.json +26 -0
index 05ced9d..cae1200 100644
@@ -526,6 +526,32 @@
 { 'command': 'query-commands', 'returns': ['CommandInfo'] }
 
 ##
+# @DeviceInfo:
+#
+# Information about a device
+#
+# @name: The command name
+# @bus: The bus it is connected to
+# @alias: Device alias
+# @desc: Description of the device
+#
+# Since: 1.6.0
+##
+{ 'type': 'DeviceInfo', 'data': {'name': 'str', 'bus': 'str', 'alias': 'str', 'desc': 'str'} }
+
+##
+# @query-devices:
+#
+# Return a list of supported devices
+#
+# Returns: A list of @DeviceInfo for all supported devices
+#
+# Since: 1.6.0
+##
+{ 'command': 'query-devices', 'returns': ['DeviceInfo'] }
+
+
+##
 # @EventInfo:
 #
 # Information about a QMP event
qdev-monitor.c +28 -0
index 1d3b68d..0a59fd9 100644
@@ -644,6 +644,34 @@ void do_info_qtree(Monitor *mon, const QDict *qdict)
         qbus_print(mon, sysbus_get_default(), 0);
 }
 
+static void qdev_list_devinfo(ObjectClass *klass, void *data)
+{
+    DeviceInfoList *e, **pret = data;
+    DeviceInfo *info;
+    DeviceClass *dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE);
+    if (!dc) return;
+
+    info = g_malloc0(sizeof(*info));
+    info->name = g_strdup(object_class_get_name(klass));
+    info->bus = g_strdup(dc->bus_type ? dc->bus_type : "");
+    info->alias = g_strdup(qdev_class_has_alias(dc) ? qdev_class_get_alias(dc) : "");
+    info->desc = g_strdup(dc->desc ? dc->desc : "");
+
+    e = g_malloc0(sizeof(*e));
+    e->value = info;
+    e->next = *pret;
+    *pret = e;
+}
+
+DeviceInfoList * qmp_query_devices(Error **errp)
+{
+    DeviceInfoList *list = NULL;
+
+    object_class_foreach(qdev_list_devinfo, TYPE_DEVICE, false, &list);
+
+    return list;
+}
+
 void do_info_qdm(Monitor *mon, const QDict *qdict)
 {
     qdev_print_devinfos(true);
qmp-commands.hx +40 -0
index cce6b81..be4451d 100644
@@ -1851,6 +1851,46 @@ EQMP
     },
 
 SQMP
+query-devices
+--------------
+
+List supported devices
+
+Each device is represented by a json-object, the returned value is a json-array
+of all devices.
+
+Each json-object contain:
+
+- "name": device's name (json-string)
+- "bus": bus the device connects to (json-string)
+- "alias": device's alias (json-string)
+- "desc": device's description (json-string)
+
+Example:
+
+-> { "execute": "query-devices" }
+<- {
+      "return":[
+         {
+            "name":"pci-bridge",
+            "bus":"PCI",
+            "alias":"",
+            "desc":"Standard PCI Bridge"
+         }
+      ]
+   }
+
+Note: This example has been shortened as the real response is too long.
+
+EQMP
+
+    {
+        .name       = "query-devices",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_devices,
+    },
+
+SQMP
 query-events
 --------------
 
#2 lore raw

Am 24.02.2014 10:31, schrieb Paolo Bonzini:

Quoted 8 lines

Il 24/02/2014 10:23, Or Goshen ha scritto:

Quoted 3 lines

From: Or Goshen <[email protected]>

Was done on behalf of Intel Corp.

Hi Or,

you can use qom-list-types for this purpose.

That can return a list of types, but there is no way to access the DeviceClass-specific bus, alias, desc values, is there?

It sounds to me as if they are trying to recreate the -device ? output in machine-readable form.

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Il 24/02/2014 14:40, Andreas Färber ha scritto:

Quoted 4 lines

Am 24.02.2014 10:31, schrieb Paolo Bonzini:

Quoted 3 lines

Il 24/02/2014 10:23, Or Goshen ha scritto:

Quoted 2 lines

From: Or Goshen <[email protected]>

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Was done on behalf of Intel Corp.

Hi Or,

you can use qom-list-types for this purpose.

That can return a list of types, but there is no way to access the DeviceClass-specific bus, alias, desc values, is there?

The bus value can be retrieved indirectly from the class hierarchy. Aliases are deprecated.

Desc could be moved to the object class and added to qom-list-types.

Quoted 2 lines

It sounds to me as if they are trying to recreate the -device ? output in machine-readable form.

Indeed. The question is why they need "-device ?". If it is just for "is the device supported" (as was the case for libvirt before it started using qom-list-types), then a new command is unnecessary.

Paolo

author
#4 lore raw
In reply to Andreas Färber

You are correct. I need "-device ?" functionality for porting libguestfs to mingw

Quoted 23 lines · Andreas Färber

Am 24.02.2014 10:31, schrieb Paolo Bonzini:

Quoted 8 lines

Il 24/02/2014 10:23, Or Goshen ha scritto:

Quoted 3 lines

From: Or Goshen <[email protected]>

Was done on behalf of Intel Corp.

Hi Or,

you can use qom-list-types for this purpose.

That can return a list of types, but there is no way to access the DeviceClass-specific bus, alias, desc values, is there?

It sounds to me as if they are trying to recreate the -device ? output in machine-readable form.

Regards,
Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

Signature · 4 lines
   Or Goshen
   CTO
   Cerbercomm
   Mob: 972-50-9182418
#5 lore raw
Quoted 3 lines

You are correct. I need "-device ?" functionality for porting libguestfs to mingw

Interesting!

Why is "-device ?" not enough? I think that libguestfs should not need anything that qom-list-types does not provide.

Paolo

#6 lore raw
In reply to Or Goshen
Quoted 11 lines · Or Goshen

From: Or Goshen <[email protected]>

Was done on behalf of Intel Corp.

---

+++ b/qapi-schema.json

qapi-schema.json +0 -0
@@ -526,6 +526,32 @@
 { 'command': 'query-commands', 'returns': ['CommandInfo'] }
 
 ##

qapi-schema.json line 538

Quoted 10 lines
qapi-schema.json +10 -0
+# @DeviceInfo:
+#
+# Information about a device
+#
+# @name: The command name
+# @bus: The bus it is connected to
+# @alias: Device alias
+# @desc: Description of the device
+#
+# Since: 1.6.0

This needs to be 2.0 (or whatever actual release it first makes it into), not 1.6.0.

qapi-schema.json line 549

Quoted 11 lines
qapi-schema.json +11 -0
+##
+{ 'type': 'DeviceInfo', 'data': {'name': 'str', 'bus': 'str', 'alias': 'str', 'desc': 'str'} }
+
+##
+# @query-devices:
+#
+# Return a list of supported devices
+#
+# Returns: A list of @DeviceInfo for all supported devices
+#
+# Since: 1.6.0

and again

qmp-commands.hx EQMP · line 1877

Quoted 7 lines
qmp-commands.hx +7 -0
+-> { "execute": "query-devices" }
+<- {
+      "return":[
+         {
+            "name":"pci-bridge",
+            "bus":"PCI",
+            "alias":"",

Should alias be optional, rather than an empty string, when there isn't one?

qmp-commands.hx EQMP · line 1878

Quoted 1 line
qmp-commands.hx +1 -0
+            "desc":"Standard PCI Bridge"

Is the description intended to be machine parseable, or is it only for human consumption?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org