Add a command that returns QOM type information that is specific to device types and is not returned by qom-list-types.
The returned DeviceTypeInfo struct inherits from ObjectTypeInfo, so fields returned by qom-list-types are also included. Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- qapi-schema.json | 35 +++++++++++++++++++++++++++++++++++ qmp.c | 25 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index a3ba1c9a1c..0955380a59 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1466,6 +1466,41 @@ 'returns': [ 'DevicePropertyInfo' ] } ## +# @DeviceTypeInfo: +# +# Information about a device type. +# +# @user-creatable: If true, the device can be instantiated using the -device +# command-line option. +# @hotpluggable: If true, the device can be instantiated using @device_add, +# if the machine supports the device. +# +# @description: Human-readable description of the device type. +# +# Since: 2.11 +## +{ 'struct': 'DeviceTypeInfo', + 'base': 'ObjectTypeInfo', + 'data': { 'hotpluggable': 'bool', + 'user-creatable': 'bool', + '*description': 'str' } } + +## +# @query-device-type: +# +# Query information about a device type. +# +# @typename: the name of the device type +# +# Returns: a DeviceTypeInfo struct +# +# Since: 2.11 +## +{ 'command': 'query-device-type', + 'data': { 'typename': 'str' }, + 'returns': 'DeviceTypeInfo' } + +## # @xen-set-global-dirty-log: # # Enable or disable the global dirty log mode. diff --git a/qmp.c b/qmp.c index 5ec829c09b..761fcf61c7 100644 --- a/qmp.c +++ b/qmp.c @@ -597,6 +597,31 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename, return prop_list; } +DeviceTypeInfo *qmp_query_device_type(const char *typename, Error **errp) +{ + DeviceTypeInfo *info = g_new0(DeviceTypeInfo, 1); + DeviceClass *dc = get_device_class(typename, errp); + + if (!dc) { + return NULL; + } + + qom_type_get_info(OBJECT_CLASS(dc), qapi_DeviceTypeInfo_base(info)); + info->user_creatable = dc->user_creatable; + /* + * We have non-user-creatable devices with hotpluggable=true (because they + * are instantiated internally by hotpluggable devices), but it doesn't make + * sense to tell the user that device_add is supported if the device is not + * user-creatable + */ + info->hotpluggable = dc->user_creatable && dc->hotpluggable; + if (dc->desc) { + info->has_description = true; + info->description = g_strdup(dc->desc); + } + return info; +} + CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { return arch_query_cpu_definitions(errp); -- 2.13.5