From patchwork Thu Apr 25 20:44:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 239595 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 1B0AC2C00C4 for ; Fri, 26 Apr 2013 06:44:58 +1000 (EST) Received: from localhost ([::1]:56429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVT2G-0001L1-BO for incoming@patchwork.ozlabs.org; Thu, 25 Apr 2013 16:44:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVT1j-00019L-OG for qemu-devel@nongnu.org; Thu, 25 Apr 2013 16:44:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVT1g-0008UD-Ej for qemu-devel@nongnu.org; Thu, 25 Apr 2013 16:44:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7317) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVT1g-0008T9-7h for qemu-devel@nongnu.org; Thu, 25 Apr 2013 16:44:20 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3PKiJuk027142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Apr 2013 16:44:19 -0400 Received: from localhost (ovpn-113-63.phx2.redhat.com [10.3.113.63]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3PKiIOR008762; Thu, 25 Apr 2013 16:44:19 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 25 Apr 2013 16:44:16 -0400 Message-Id: <1366922656-32545-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1366922656-32545-1-git-send-email-lcapitulino@redhat.com> References: <1366922656-32545-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PULL] monitor: introduce query-command-line-options 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: Amos Kong Libvirt has no way to probe if an option or property is supported, This patch introduces a new qmp command to query command line option information. hmp command isn't added because it's not needed. Signed-off-by: Amos Kong CC: Luiz Capitulino CC: Osier Yang CC: Anthony Liguori Signed-off-by: Luiz Capitulino Reviewed-by: Eric Blake --- qapi-schema.json | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 751d3c2..5b0fb3b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3505,3 +3505,69 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +## +# @CommandLineParameterType: +# +# Possible types for an option parameter. +# +# @string: accepts a character string +# +# @boolean: accepts "on" or "off" +# +# @number: accepts a number +# +# @size: accepts a number followed by an optional suffix (K)ilo, +# (M)ega, (G)iga, (T)era +# +# Since 1.5 +## +{ 'enum': 'CommandLineParameterType', + 'data': ['string', 'boolean', 'number', 'size'] } + +## +# @CommandLineParameterInfo: +# +# Details about a single parameter of a command line option. +# +# @name: parameter name +# +# @type: parameter @CommandLineParameterType +# +# @help: #optional human readable text string, not suitable for parsing. +# +# Since 1.5 +## +{ 'type': 'CommandLineParameterInfo', + 'data': { 'name': 'str', + 'type': 'CommandLineParameterType', + '*help': 'str' } } + +## +# @CommandLineOptionInfo: +# +# Details about a command line option, including its list of parameter details +# +# @option: option name +# +# @parameters: an array of @CommandLineParameterInfo +# +# Since 1.5 +## +{ 'type': 'CommandLineOptionInfo', + 'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'] } } + +## +# @query-command-line-options: +# +# Query command line option schema. +# +# @option: #optional option name +# +# Returns: list of @CommandLineOptionInfo for all options (or for the given +# @option). Returns an error if the given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-command-line-options', 'data': { '*option': 'str' }, + 'returns': ['CommandLineOptionInfo'] } diff --git a/qmp-commands.hx b/qmp-commands.hx index 4d65422..0e89132 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2416,6 +2416,53 @@ EQMP }, SQMP +query-command-line-options +-------------------------- + +Show command line option schema. + +Return a json-array of command line option schema for all options (or for +the given option), returning an error if the given option doesn't exist. + +Each array entry contains the following: + +- "option": option name (json-string) +- "parameters": a json-array describes all parameters of the option: + - "name": parameter name (json-string) + - "type": parameter type (one of 'string', 'boolean', 'number', + or 'size') + - "help": human readable description of the parameter + (json-string, optional) + +Example: + +-> { "execute": "query-command-line-options", "arguments": { "option": "option-rom" } } +<- { "return": [ + { + "parameters": [ + { + "name": "romfile", + "type": "string" + }, + { + "name": "bootindex", + "type": "number" + } + ], + "option": "option-rom" + } + ] + } + +EQMP + + { + .name = "query-command-line-options", + .args_type = "option:s?", + .mhandler.cmd_new = qmp_marshal_input_query_command_line_options, + }, + +SQMP query-migrate ------------- diff --git a/util/qemu-config.c b/util/qemu-config.c index 01ca890..a59568d 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -5,6 +5,7 @@ #include "qapi/qmp/qerror.h" #include "hw/qdev.h" #include "qapi/error.h" +#include "qmp-commands.h" static QemuOptsList *vm_config_groups[32]; @@ -37,6 +38,72 @@ QemuOptsList *qemu_find_opts(const char *group) return ret; } +static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc) +{ + CommandLineParameterInfoList *param_list = NULL, *entry; + CommandLineParameterInfo *info; + int i; + + for (i = 0; desc[i].name != NULL; i++) { + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(desc[i].name); + + switch (desc[i].type) { + case QEMU_OPT_STRING: + info->type = COMMAND_LINE_PARAMETER_TYPE_STRING; + break; + case QEMU_OPT_BOOL: + info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN; + break; + case QEMU_OPT_NUMBER: + info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER; + break; + case QEMU_OPT_SIZE: + info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE; + break; + } + + if (desc[i].help) { + info->has_help = true; + info->help = g_strdup(desc[i].help); + } + + entry = g_malloc0(sizeof(*entry)); + entry->value = info; + entry->next = param_list; + param_list = entry; + } + + return param_list; +} + +CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option, + const char *option, + Error **errp) +{ + CommandLineOptionInfoList *conf_list = NULL, *entry; + CommandLineOptionInfo *info; + int i; + + for (i = 0; vm_config_groups[i] != NULL; i++) { + if (!has_option || !strcmp(option, vm_config_groups[i]->name)) { + info = g_malloc0(sizeof(*info)); + info->option = g_strdup(vm_config_groups[i]->name); + info->parameters = query_option_descs(vm_config_groups[i]->desc); + entry = g_malloc0(sizeof(*entry)); + entry->value = info; + entry->next = conf_list; + conf_list = entry; + } + } + + if (conf_list == NULL) { + error_setg(errp, "invalid option name: %s", option); + } + + return conf_list; +} + QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) { return find_list(vm_config_groups, group, errp);