qmp: query-device-type command
cover qmp: query-device-type command
This series implements a new 'query-device-type' command, that can be used to query TYPE_DEVICE-specific information that is not returned by qom-list-types.
The new field can be used instead of "info qdm" parsing by the device-crash-test script. It can be also used by hotplug test cases, to skip non-hotpluggable device types.
Eduardo Habkost (4):
qmp: qom_type_get_info() helper
qmp: get_device_class() helper
qmp: query-device-type command
device-crash-test: Use query-device-info for user-creatable check
qapi-schema.json | 35 ++++++++++++++++++++++++++ qmp.c | 63 +++++++++++++++++++++++++++++++++++++++-------- scripts/device-crash-test | 19 ++------------ 3 files changed, 90 insertions(+), 27 deletions(-)
Signature · 1 line
2.13.5
PATCH 1/4 qmp: qom_type_get_info() helper
Extract the code that fills ObjectTypeInfo fields to a qom_type_get_info() helper. It will be reused in other QMP commands.
--- qmp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
qmp.c +10 -4
@@ -426,19 +426,25 @@ void qmp_change(const char *device, const char *target, } } -static void qom_list_types_tramp (ObjectClass *klass,void *data) +static void qom_type_get_info (ObjectClass *klass,ObjectTypeInfo *info) { -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)); } +} + +static void qom_list_types_tramp (ObjectClass *klass,void *data) +{ +ObjectTypeInfoList *e, **pret = data; +ObjectTypeInfo *info; + + info =g_malloc0 (sizeof (*info)); +qom_type_get_info (klass, info); e =g_malloc0 (sizeof (*e)); e->value = info;
Signature · 1 line
2.13.5
PATCH 2/4 qmp: get_device_class() helper
In reply to Eduardo HabkostExtract device type lookup code from qmp_device_list_properties() to a get_device_class() helper. It will be reused by other QMP commands.
--- qmp.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
qmp.c +18 -6
@@ -517,14 +517,9 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,return info; } -DevicePropertyInfoList *qmp_device_list_properties (const char *typename, -Error **errp) +static DeviceClass *get_device_class (const char *typename,Error **errp) {ObjectClass *klass; -Object *obj; -ObjectProperty *prop; -ObjectPropertyIterator iter; -DevicePropertyInfoList *prop_list =NULL ; klass =object_class_by_name (typename);if (klass ==NULL ) {
@@ -539,6 +534,23 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,return NULL ; } +return DEVICE_CLASS (klass); +} + +DevicePropertyInfoList *qmp_device_list_properties (const char *typename, +Error **errp) +{ +ObjectClass *klass; +Object *obj; +ObjectProperty *prop; +ObjectPropertyIterator iter; +DevicePropertyInfoList *prop_list =NULL ; + + klass =OBJECT_CLASS (get_device_class (typename, errp)); +if (!klass) { +return NULL ; + } +if (object_class_is_abstract (klass)) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"typename" ,"non-abstract device type" );
Signature · 1 line
2.13.5
PATCH 3/4 qmp: query-device-type command
In reply to Eduardo HabkostAdd 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.
--- qapi-schema.json | 35 +++++++++++++++++++++++++++++++++++ qmp.c | 25 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
qapi-schema.json +35 -0
@@ -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.
qmp.c +25 -0
@@ -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);
Signature · 1 line
2.13.5
PATCH 4/4 device-crash-test: Use query-device-info for user-creatable check
In reply to Eduardo HabkostNow that we have query-device-info, we don't need to parse "info qdm" output to find out if a device is user-creatable.
--- scripts/device-crash-test | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-)
scripts/device-crash-test +2 -17
@@ -318,19 +318,6 @@ def qomListTypeNames(vm, **kwargs): return [t['name'] for t in types] -def infoQDM(vm): - """Parse 'info qdm' output""" - args = {'command-line': 'info qdm'} - devhelp = vm.command('human-monitor-command', **args) - for l in devhelp.split('\n'): - l = l.strip() - if l == '' or l.endswith(':'): - continue - d = {'name': re.search(r'name "([^"]+)"', l).group(1), - 'no-user': (re.search(', no-user', l) is not None)} - yield d - - class QemuBinaryInfo(object): def __init__(self, binary, devtype): if devtype is None:
@@ -346,11 +333,9 @@ class QemuBinaryInfo(object): vm.launch() try: self.alldevs = set(qomListTypeNames(vm, implements=devtype, abstract=False)) - # there's no way to query DeviceClass::user_creatable using QMP, - # so use 'info qdm': - self.no_user_devs = set([d['name'] for d in infoQDM(vm, ) if d['no-user']]) + self.dev_info = dict((t, vm.command('query-device-type', typename=t)) for t in self.alldevs) + self.user_devs = set(d for d in self.alldevs if self.dev_info[d]['user-creatable']) self.machines = list(m['name'] for m in vm.command('query-machines')) - self.user_devs = self.alldevs.difference(self.no_user_devs) self.kvm_available = vm.command('query-kvm')['enabled'] finally: vm.shutdown()
Signature · 1 line
2.13.5