From patchwork Mon Jun 7 14:42:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 54874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E91C2B7D81 for ; Tue, 8 Jun 2010 01:10:53 +1000 (EST) Received: from localhost ([127.0.0.1]:54669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLdyU-0005pc-Ch for incoming@patchwork.ozlabs.org; Mon, 07 Jun 2010 11:10:50 -0400 Received: from [140.186.70.92] (port=56409 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLdYc-0005yk-Gu for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:44:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLdY8-0005HQ-D7 for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:43:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31899) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLdY8-0005H6-2f for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:43:36 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o57EhZb6009361 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Jun 2010 10:43:35 -0400 Received: from localhost.localdomain (dhcp-1-192.lcy.redhat.com [10.32.224.192]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o57EgrCi031909; Mon, 7 Jun 2010 10:43:33 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 7 Jun 2010 15:42:30 +0100 Message-Id: <1275921752-29420-18-git-send-email-berrange@redhat.com> In-Reply-To: <1275921752-29420-1-git-send-email-berrange@redhat.com> References: <1275921752-29420-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 17/19] Add a query-config command to QMP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a new command to QMP called 'query-config' that provides information about the allowed configuration file entries for the binary. The data format looks like [ { "name": "drive", "properties": [ { "name": "bus", "validate": { }, "help": "bus number", "type": "number" }, { "name": "unit", "validate": { }, "help": "unit number (i.e. lun for scsi)", "type": "number" }, { "name": "if", "validate": { "values": [ "none", "ide", "scsi", "floppy", "pflash", "mtd", "sd", "virtio", "xen" ] }, "help": "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", "type": "enum" }, { .......... } ] Signed-off-by: Daniel P. Berrange --- monitor.c | 8 ++++ qemu-config.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- qemu-config.h | 2 + 3 files changed, 136 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index 19f42f3..39f8150 100644 --- a/monitor.c +++ b/monitor.c @@ -2560,6 +2560,14 @@ static const mon_cmd_t info_cmds[] = { .mhandler.info_new = do_info_netdev, }, { + .name = "config", + .args_type = "", + .params = "", + .help = "list valid config file parameters", + .user_print = monitor_user_noop, + .mhandler.info_new = do_info_config, + }, + { .name = "network", .args_type = "", .params = "", diff --git a/qemu-config.c b/qemu-config.c index 75cddc1..925bd04 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -5,6 +5,9 @@ #include "sysemu.h" #include "hw/qdev.h" #include "block.h" +#include "qjson.h" +#include "qlist.h" + QemuOptsList qemu_drive_opts = { .name = "drive", @@ -97,7 +100,7 @@ QemuOptsList qemu_drive_opts = { .to_string = bdrv_aio_to_string, .to_string_list = bdrv_aio_to_string_list, .from_string = bdrv_aio_from_string, - .last = BDRV_CACHE_LAST + .last = BDRV_AIO_LAST }, }, },{ @@ -612,3 +615,125 @@ int qemu_read_config_file(const char *filename) return -EINVAL; } } + + +/* + * do_info_config(): + * + * Return information about allowed configuration file + * parameters and their data types. + * + * At the top level is a QList containing one QDict entry + * for each top level config group. The QDict contains + * keys for + * + * 'name': name of the config group + * 'properties': QList of a config properties + * + * Each entry in the properties QList is another QDict + * containing keys + * + * 'name': name of the config parameter + * 'help': a short help string (optional) + * 'type': data type of the parameter (string, bool, number, size, enum) + * 'validate': a QDict of data validation rules + * + * The 'validate' key is only used for options for type='enum' and + * in this case describes the valid strings for the enumeration + * + * Example snippet of data: + * + * [ + * { + * "name": "drive", + * "properties": [ + * { + * "name": "bus", + * "validate": { + * }, + * "help": "bus number", + * "type": "number" + * }, + * { + * "name": "unit", + * "validate": { + * }, + * "help": "unit number (i.e. lun for scsi)", + * "type": "number" + * }, + * { + * "name": "if", + * "validate": { + * "values": [ + * "none", + * "ide", + * "scsi", + * "floppy", + * "pflash", + * "mtd", + * "sd", + * "virtio", + * "xen" + * ] + * }, + * "help": "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", + * "type": "enum" + * }, + * ] + * } + * ... + * ] + */ +void do_info_config(Monitor *mon, QObject **ret_data) +{ + QList *config = qlist_new(); + int i, j, k; + + for (i = 0 ; vm_config_groups[i] != NULL ; i++) { + QemuOptsList *grp = vm_config_groups[i]; + QList *props = qlist_new(); + QObject *entry; + + for (j = 0 ; grp->desc[j].name != NULL ; j++) { + QemuOptDesc *desc = &grp->desc[j]; + QObject *validate = QOBJECT(qlist_new()); + QObject *prop; + + if (desc->type == QEMU_OPT_ENUM) { + QList *valid = qlist_new(); + + for (k = 0 ; k < desc->validate.optEnum.last ; k++) { + fprintf(stderr, "name %s %d %d\n", grp->desc[j].name, k, desc->validate.optEnum.last); + const char *str = (desc->validate.optEnum.to_string)(k); + qlist_append_obj(valid, QOBJECT(qstring_from_str(str))); + } + + validate = qobject_from_jsonf("{ 'values': %p }", valid); + } else { + validate = qobject_from_jsonf("{}"); + } + + if (desc->help) { + prop = qobject_from_jsonf("{ 'name': %s, 'type': %s, 'help': %s, 'validate': %p }", + desc->name, + qemu_opt_type_to_string(desc->type), + desc->help, + validate); + } else { + prop = qobject_from_jsonf("{ 'name': %s, 'type': %s, 'validate': %p }", + desc->name, + qemu_opt_type_to_string(desc->type), + validate); + } + + qlist_append_obj(props, prop); + } + + entry = qobject_from_jsonf("{ 'name': %s, 'properties': %p }", + grp->name, props); + + qlist_append_obj(config, entry); + } + + *ret_data = QOBJECT(config); +} diff --git a/qemu-config.h b/qemu-config.h index dca69d4..b87e8fc 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -25,4 +25,6 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname); int qemu_read_config_file(const char *filename); +void do_info_config(Monitor *mon, QObject **ret_data); + #endif /* QEMU_CONFIG_H */