From patchwork Mon Jan 30 21:08:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 16F481007D2 for ; Tue, 31 Jan 2012 08:40:30 +1100 (EST) Received: from localhost ([::1]:39704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rryxf-000430-IY for incoming@patchwork.ozlabs.org; Mon, 30 Jan 2012 16:40:27 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RryTg-0002E9-Sl for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RryTf-00054V-Hq for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:28 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:34323 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RryTf-00054Q-1G for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:27 -0500 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id q0UL9MAG006046; Mon, 30 Jan 2012 15:09:22 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q0UL9Lqo006041; Mon, 30 Jan 2012 15:09:21 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 30 Jan 2012 15:08:50 -0600 Message-Id: <1327957741-5842-12-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1327957741-5842-1-git-send-email-aliguori@us.ibm.com> References: <1327957741-5842-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Paolo Bonzini , Andreas Faerber , Anthony Liguori , Peter Maydell Subject: [Qemu-devel] [PATCH 12/23] qom: add new command to search for types 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 This adds a command that allows searching for types that implement a property. This allows you to do things like search for all available PCIDevices. In the future, we'll also have a standard interface for things with a BlockDriverState property that a PCIDevice could implement. This will enable search queries like, "any type that implements the BlockDevice interface" which would allow management tools to present available block devices without having to hard code device names. Since an object can implement multiple interfaces, one device could act both as a BlockDevice and a NetworkDevice. Signed-off-by: Anthony Liguori --- qapi-schema.json | 33 +++++++++++++++++++++++++++++++++ qerror.c | 2 +- qmp-commands.hx | 5 +++++ qmp.c | 27 +++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 80debe6..56a4123 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1549,3 +1549,36 @@ # Since: 1.1 ## { 'command': 'block_job_cancel', 'data': { 'device': 'str' } } + +## +# @ObjectTypeInfo: +# +# This structure describes a search result from @qom-list-types +# +# @name: the type name found in the search +# +# Since: 1.1 +# +# Notes: This command is experimental and may change syntax in future releases. +## +{ 'type': 'ObjectTypeInfo', + 'data': { 'name': 'str' } } + +## +# @qom-list-types: +# +# This command will return a list of types given search parameters +# +# @implements: if specified, only return types that implement this type name +# +# @abstract: if true, include abstract types in the results +# +# Returns: a list of @ObjectTypeInfo or an empty list if no results are found +# +# Since: 1.1 +# +# Notes: This command is experimental and may change syntax in future releases. +## +{ 'command': 'qom-list-types', + 'data': { '*implements': 'str', '*abstract': 'bool' }, + 'returns': [ 'ObjectTypeInfo' ] } diff --git a/qerror.c b/qerror.c index 637eca7..3d179c8 100644 --- a/qerror.c +++ b/qerror.c @@ -161,7 +161,7 @@ static const QErrorStringTable qerror_table[] = { }, { .error_fmt = QERR_INVALID_PARAMETER_TYPE, - .desc = "Invalid parameter type, expected: %(expected)", + .desc = "Invalid parameter type for '%(name)', expected: %(expected)", }, { .error_fmt = QERR_INVALID_PARAMETER_VALUE, diff --git a/qmp-commands.hx b/qmp-commands.hx index bd6b641..b5e2ab8 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2042,3 +2042,8 @@ EQMP .args_type = "password:s", .mhandler.cmd_new = qmp_marshal_input_change_vnc_password, }, + { + .name = "qom-list-types", + .args_type = "implements:s?,abstract:b?", + .mhandler.cmd_new = qmp_marshal_input_qom_list_types, + }, diff --git a/qmp.c b/qmp.c index 1222b6c..75049ed 100644 --- a/qmp.c +++ b/qmp.c @@ -395,3 +395,30 @@ void qmp_change(const char *device, const char *target, qmp_change_blockdev(device, target, has_arg, arg, err); } } + +static void qom_list_types_tramp(ObjectClass *klass, void *data) +{ + ObjectTypeInfoList *e, **pret = data; + ObjectTypeInfo *info; + + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(object_class_get_name(klass)); + + e = g_malloc0(sizeof(*e)); + e->value = info; + e->next = *pret; + *pret = e; +} + +ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, + const char *implements, + bool has_abstract, + bool abstract, + Error **errp) +{ + ObjectTypeInfoList *ret = NULL; + + object_class_foreach(qom_list_types_tramp, implements, abstract, &ret); + + return ret; +}