From patchwork Wed Apr 24 17:33:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 239285 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 BB0FA2C019D for ; Thu, 25 Apr 2013 03:34:00 +1000 (EST) Received: from localhost ([::1]:40632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV3Zv-0006DL-08 for incoming@patchwork.ozlabs.org; Wed, 24 Apr 2013 13:33:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV3ZY-0006BZ-B6 for qemu-devel@nongnu.org; Wed, 24 Apr 2013 13:33:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UV3ZT-0007aJ-Fx for qemu-devel@nongnu.org; Wed, 24 Apr 2013 13:33:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV3ZT-0007a4-7m for qemu-devel@nongnu.org; Wed, 24 Apr 2013 13:33:31 -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 r3OHXUGE012075 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 24 Apr 2013 13:33:30 -0400 Received: from t430s.nay.redhat.com (vpn1-4-31.sin2.redhat.com [10.67.4.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3OHXQ2l014112; Wed, 24 Apr 2013 13:33:27 -0400 From: Amos Kong To: qemu-devel@nongnu.org, lcapitulino@redhat.com Date: Thu, 25 Apr 2013 01:33:24 +0800 Message-Id: <1366824804-24532-1-git-send-email-akong@redhat.com> In-Reply-To: <1366807646-8473-2-git-send-email-akong@redhat.com> References: <1366807646-8473-2-git-send-email-akong@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, jyang@redhat.com Subject: [Qemu-devel] [PATCH] monitor: introduce query-config-schema 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 Libvirt has no way to probe if an option or property is supported, This patch introdues a new qmp command to query configuration schema information. hmp command isn't added because it's not needed. V2: fix jaso schema and comments (Eric) Signed-off-by: Amos Kong CC: Osier Yang CC: Anthony Liguori Signed-off-by: Amos Kong --- qapi-schema.json | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 43 ++++++++++++++++++++++++++++++++++++ util/qemu-config.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 751d3c2..55aee4a 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3505,3 +3505,67 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +## +# @ConfigParamType: +# +# JSON representation of values of QEMUOptionParType, may grow in future +# +# @flag: If no value is given, the flag is set to 1. Otherwise the value must +# be "on" (set to 1) or "off" (set to 0) +# +# @number: Simple number +# +# @size: The value is converted to an integer. Suffixes for kilobytes etc +# +# @string: Character string +# +# Since 1.5 +## +{ 'enum': 'ConfigParamType', + 'data': [ 'flag', 'number', 'size', 'string' ] } + +## +# @ConfigParamInfo: +# +# JSON representation of QEMUOptionParameter, may grow in future +# +# @name: parameter name +# +# @type: parameter type +# +# @help is optional if no text was present +# +# Since 1.5 +## +{ 'type': 'ConfigParamInfo', + 'data': { 'name': 'str', 'type': 'ConfigParamType', '*help':'str' } } + +## +# @ConfigSchemaInfo: +# +# Each command line option, and its list of parameters +# +# @option: option name +# +# @params: a list of parameters of one option +# +# Since 1.5 +## +{ 'type': 'ConfigSchemaInfo', + 'data': { 'option':'str', 'params': ['ConfigParamInfo'] } } + +## +# @query-config-schema: +# +# Query configuration schema information +# +# @option: #optional option name +# +# Returns: list of @ConfigSchemaInfo for all options (or for the given +# @option). Returns an error if a given @option doesn't exist. +# +# Since 1.5 +## +{'command': 'query-config-schema', 'data': {'*option': 'str'}, + 'returns': ['ConfigSchemaInfo']} diff --git a/qmp-commands.hx b/qmp-commands.hx index 4d65422..19415e4 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2414,6 +2414,49 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_uuid, }, +SQMP +query-config-schema +------------ + +Show configuration schema. + +Return list of configuration schema of all options (or for the given option), +return an error if given option doesn't exist. + +- "option": option name +- "params": parameters infomation list of one option +- "name": parameter name +- "type": parameter type +- "help": parameter help message + +Example: + +-> {"execute": "query-config-schema", "arguments" : {"option": "option-rom"}} +<- { + "return": [ + { + "params": [ + { + "name": "romfile", + "type": "flag" + }, + { + "name": "bootindex", + "type": "size" + } + ], + "option": "option-rom" + } + ] + } + +EQMP + + { + .name = "query-config-schema", + .args_type = "option:s?", + .mhandler.cmd_new = qmp_marshal_input_query_config_schema, + }, SQMP query-migrate diff --git a/util/qemu-config.c b/util/qemu-config.c index 01ca890..6d93642 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,56 @@ QemuOptsList *qemu_find_opts(const char *group) return ret; } +ConfigSchemaInfoList *qmp_query_config_schema(bool has_option, + const char *option, Error **errp) +{ + ConfigSchemaInfoList *conf_list = NULL, *conf_entry; + ConfigSchemaInfo *schema_info; + ConfigParamInfoList *param_list = NULL, *param_entry; + ConfigParamInfo *param_info; + int entries, i, j; + + entries = ARRAY_SIZE(vm_config_groups); + + for (i = 0; i < entries; i++) { + if (vm_config_groups[i] != NULL && + (!has_option || !strcmp(option, vm_config_groups[i]->name))) { + schema_info = g_malloc0(sizeof(*schema_info)); + schema_info->option = g_strdup(vm_config_groups[i]->name); + param_list = NULL; + + for (j = 0; vm_config_groups[i]->desc[j].name != NULL; j++) { + param_info = g_malloc0(sizeof(*param_info)); + param_info->name = g_strdup(vm_config_groups[i]->desc[j].name); + param_info->type = vm_config_groups[i]->desc[j].type; + + if (vm_config_groups[i]->desc[j].help) { + param_info->has_help = true; + param_info->help = g_strdup( + vm_config_groups[i]->desc[j].help); + } + + param_entry = g_malloc0(sizeof(*param_entry)); + param_entry->value = param_info; + param_entry->next = param_list; + param_list = param_entry; + } + + schema_info->params = param_list; + conf_entry = g_malloc0(sizeof(*conf_entry)); + conf_entry->value = schema_info; + conf_entry->next = conf_list; + conf_list = conf_entry; + } + } + + if (conf_list == NULL) { + error_set(errp, QERR_INVALID_OPTION_GROUP, option); + } + + return conf_list; +} + QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) { return find_list(vm_config_groups, group, errp);