From nobody Sun May 5 21:20:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495056407485396.3725005201361; Wed, 17 May 2017 14:26:47 -0700 (PDT) Received: from localhost ([::1]:50806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB6Sz-0002Lw-OF for importer@patchew.org; Wed, 17 May 2017 17:26:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB6SC-000247-SP for qemu-devel@nongnu.org; Wed, 17 May 2017 17:25:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB6S9-0007UT-ME for qemu-devel@nongnu.org; Wed, 17 May 2017 17:25:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59290) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dB6S9-0007Tn-Cn for qemu-devel@nongnu.org; Wed, 17 May 2017 17:25:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CA19C0467C5 for ; Wed, 17 May 2017 21:25:51 +0000 (UTC) Received: from localhost (ovpn-116-71.gru2.redhat.com [10.97.116.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id E219C5C884; Wed, 17 May 2017 21:25:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4CA19C0467C5 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4CA19C0467C5 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 17 May 2017 18:25:47 -0300 Message-Id: <20170517212547.4767-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 17 May 2017 21:25:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC] qmp: Return 'user_creatable' & 'hotpluggable' fields on qom-list-types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcel Apfelbaum , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently there's no way for QMP clients to get a list of device types that are really usable with -device. This information would be useful for management software and test scripts (like the device-crash-test script I have submitted recently). Interestingly, the "info qdm" HMP command provides this information, but no QMP command does. Add two new fields to the return value of qom-list-types: "user-creatable-device" and "hotpluggable-device". Also, add extra arguments for filtering the list of types based on the new fields. I'm not sure about the naming of the new command arguments. Maybe the names are too long, but I believe that "user-creatable-devices-only=3Dfalse" would have more obvious semantics than "user-creatable-devices=3Dfalse" (the latter looks ambiguous: it could mean "return only non-user-creatable devices" or "return all devices"). Signed-off-by: Eduardo Habkost --- qapi-schema.json | 25 +++++++++++++++++++++++-- qmp.c | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 80603cfc51..c0a56fc3a2 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3034,12 +3034,24 @@ # # @name: the type name found in the search # +# @user-creatable-device: If true, the type is a user-creatable device that +# can be used with the "-device" command-line opti= on. +# Note that this does not guarantee that the device +# is going to be accepted by all machine-types. +# (since 2.10) +# +# @hotpluggable-device: If true, the type is a hotpluggable device that can +# be plugged using the "device_add" monitor command. +# Note that this does not guarantee that the device = can +# be hotplugged on any machine-type. (since 2.10) +# # Since: 1.1 # # Notes: This command is experimental and may change syntax in future rele= ases. ## { 'struct': 'ObjectTypeInfo', - 'data': { 'name': 'str' } } + 'data': { 'name': 'str', 'user-creatable-device': 'bool', + 'hotpluggable-device': 'bool' } } =20 ## # @qom-list-types: @@ -3050,12 +3062,21 @@ # # @abstract: if true, include abstract types in the results # +# @user-creatable-devices-only: If true, return only user-creatable device= types +# (See @ObjectTypeInfo.user-creatable-device) +# (since 2.10) +# +# @hotpluggable-devices-only: If true, return only hotpluggable device typ= es +# (See @ObjectTypeInfo.hotpluggable-device) +# (since 2.10) +# # Returns: a list of @ObjectTypeInfo or an empty list if no results are fo= und # # Since: 1.1 ## { 'command': 'qom-list-types', - 'data': { '*implements': 'str', '*abstract': 'bool' }, + 'data': { '*implements': 'str', '*abstract': 'bool', + '*user-creatable-devices-only': 'bool', '*hotpluggable-devices= -only': 'bool' }, 'returns': [ 'ObjectTypeInfo' ] } =20 ## diff --git a/qmp.c b/qmp.c index f656940769..4f350e4ea2 100644 --- a/qmp.c +++ b/qmp.c @@ -436,29 +436,58 @@ void qmp_change(const char *device, const char *targe= t, } } =20 +typedef struct QOMListTypesArgs { + bool user_creatable_devices_only; + bool hotpluggable_devices_only; + ObjectTypeInfoList **pret; +} QOMListTypesArgs; + static void qom_list_types_tramp(ObjectClass *klass, void *data) { - ObjectTypeInfoList *e, **pret =3D data; + QOMListTypesArgs *args =3D data; + ObjectTypeInfoList *e; ObjectTypeInfo *info; + DeviceClass *dc =3D DEVICE_CLASS(object_class_dynamic_cast(klass, + TYPE_DEVICE)); + bool uc =3D dc ? dc->user_creatable : false; + bool hp =3D dc ? uc && dc->hotpluggable : false; + + if ((args->user_creatable_devices_only && !uc) || + (args->hotpluggable_devices_only && !hp)) { + return; + } =20 info =3D g_malloc0(sizeof(*info)); info->name =3D g_strdup(object_class_get_name(klass)); + info->user_creatable_device =3D uc; + info->hotpluggable_device =3D hp; =20 e =3D g_malloc0(sizeof(*e)); e->value =3D info; - e->next =3D *pret; - *pret =3D e; + e->next =3D *args->pret; + *args->pret =3D e; } =20 ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, const char *implements, bool has_abstract, bool abstract, + bool has_user_creatable_devices_onl= y, + bool user_creatable_devices_only, + bool has_hotpluggable_devices_only, + bool hotpluggable_devices_only, Error **errp) { ObjectTypeInfoList *ret =3D NULL; - - object_class_foreach(qom_list_types_tramp, implements, abstract, &ret); + QOMListTypesArgs args =3D { + .pret =3D &ret, + .user_creatable_devices_only =3D has_user_creatable_devices_only && + user_creatable_devices_only, + .hotpluggable_devices_only =3D has_hotpluggable_devices_only && + hotpluggable_devices_only, + }; + + object_class_foreach(qom_list_types_tramp, implements, abstract, &args= ); =20 return ret; } --=20 2.11.0.259.g40922b1