From patchwork Mon Aug 13 19:49:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 177039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 134312C008D for ; Tue, 14 Aug 2012 05:51:21 +1000 (EST) Received: from localhost ([::1]:37468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10fX-0004M3-7v for incoming@patchwork.ozlabs.org; Mon, 13 Aug 2012 15:51:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10dy-000220-Ht for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:49:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T10dw-0003xt-2y for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:49:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10dv-0003xg-Rg for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:49:40 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7DJndBa027614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 13 Aug 2012 15:49:39 -0400 Received: from localhost (ovpn-113-98.phx2.redhat.com [10.3.113.98]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7DJncZ6016417; Mon, 13 Aug 2012 15:49:38 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Mon, 13 Aug 2012 16:49:03 -0300 Message-Id: <1344887349-13041-43-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1344887349-13041-1-git-send-email-lcapitulino@redhat.com> References: <1344887349-13041-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 42/48] qmp: introduce device-list-properties command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Anthony Liguori This can be used in conjunction with qom-list-types to determine the supported set of devices and their parameters. Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- qapi-schema.json | 28 ++++++++++++++++++++++++++++ qmp-commands.hx | 7 +++++++ qmp.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index ec8d919..927fdea 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1725,6 +1725,34 @@ 'returns': [ 'ObjectTypeInfo' ] } ## +# @DevicePropertyInfo: +# +# Information about device properties. +# +# @name: the name of the property +# @type: the typename of the property +# +# Since: 1.2 +## +{ 'type': 'DevicePropertyInfo', + 'data': { 'name': 'str', 'type': 'str' } } + +## +# @device-list-properties: +# +# List properties associated with a device. +# +# @typename: the type name of a device +# +# Returns: a list of DevicePropertyInfo describing a devices properties +# +# Since: 1.2 +## +{ 'command': 'device-list-properties', + 'data': { 'typename': 'str'}, + 'returns': [ 'DevicePropertyInfo' ] } + +## # @migrate # # Migrates the current running guest to another Virtual Machine. diff --git a/qmp-commands.hx b/qmp-commands.hx index e07c7b0..e9e0410 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2217,3 +2217,10 @@ EQMP .args_type = "implements:s?,abstract:b?", .mhandler.cmd_new = qmp_marshal_input_qom_list_types, }, + + { + .name = "device-list-properties", + .args_type = "typename:s", + .mhandler.cmd_new = qmp_marshal_input_device_list_properties, + }, + diff --git a/qmp.c b/qmp.c index fee9fb2..254a32f 100644 --- a/qmp.c +++ b/qmp.c @@ -417,3 +417,53 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, return ret; } + +DevicePropertyInfoList *qmp_device_list_properties(const char *typename, + Error **errp) +{ + ObjectClass *klass; + Property *prop; + DevicePropertyInfoList *prop_list = NULL; + + klass = object_class_by_name(typename); + if (klass == NULL) { + error_set(errp, QERR_DEVICE_NOT_FOUND, typename); + return NULL; + } + + klass = object_class_dynamic_cast(klass, TYPE_DEVICE); + if (klass == NULL) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, + "name", TYPE_DEVICE); + return NULL; + } + + do { + for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { + DevicePropertyInfoList *entry; + DevicePropertyInfo *info; + + /* + * TODO Properties without a parser are just for dirty hacks. + * qdev_prop_ptr is the only such PropertyInfo. It's marked + * for removal. This conditional should be removed along with + * it. + */ + if (!prop->info->set) { + continue; /* no way to set it, don't show */ + } + + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(prop->name); + info->type = g_strdup(prop->info->legacy_name ?: prop->info->name); + + entry = g_malloc0(sizeof(*entry)); + entry->value = info; + entry->next = prop_list; + prop_list = entry; + } + klass = object_class_get_parent(klass); + } while (klass != object_class_by_name(TYPE_DEVICE)); + + return prop_list; +}