From patchwork Tue Mar 13 20:53:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 146485 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 B064AB6EF1 for ; Wed, 14 Mar 2012 07:53:39 +1100 (EST) Received: from localhost ([::1]:54083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Yiv-00052a-Ka for incoming@patchwork.ozlabs.org; Tue, 13 Mar 2012 16:53:37 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Yik-00051b-Kv for qemu-devel@nongnu.org; Tue, 13 Mar 2012 16:53:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7Yih-0001BQ-Qt for qemu-devel@nongnu.org; Tue, 13 Mar 2012 16:53:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26381) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Yih-0001B6-IZ for qemu-devel@nongnu.org; Tue, 13 Mar 2012 16:53:23 -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 q2DKrLhj030722 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 13 Mar 2012 16:53:21 -0400 Received: from blackpad.lan.raisama.net (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2DKrJwd021756; Tue, 13 Mar 2012 16:53:20 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 32B632005B5; Tue, 13 Mar 2012 17:53:25 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2012 17:53:24 -0300 Message-Id: <1331672005-30798-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1331672005-30798-1-git-send-email-ehabkost@redhat.com> References: <1331672005-30798-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Ronnie Sahlberg Subject: [Qemu-devel] [RFC PATCH 1/2] -readconfig: use QemuOpts option format 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 changes -readconfig to use the name=value[,name=value] option format. It keeps "-readconfig filename" working by using the implied "path" option name, but it changes the existing syntax a little, meaning that files with "=" and "," in the filename have to be escaped. I chose to break compatibility in those cases, instead of adding a new option and keeping -readconfig as a legacy option. If you think adding a new option is better, please let me know. Cc: Ronnie Sahlberg Signed-off-by: Eduardo Habkost --- qemu-config.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++----- qemu-config.h | 8 +++++- qemu-options.hx | 4 +- vl.c | 6 ++-- 4 files changed, 75 insertions(+), 13 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index be84a03..6b7b28b 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -816,21 +816,77 @@ out: return res; } -int qemu_read_config_file(const char *filename) +/* Not on vm_config_groups because this is not a global option setable by -set + * (QEMU_OPTION_set), just settings used to parse -readconfig argument. + */ +static QemuOptsList qemu_readconfig_opts = { + .name = "readconfig-opts", + .implied_opt_name = "path", + .head = QTAILQ_HEAD_INITIALIZER(qemu_readconfig_opts.head), + .desc = { + { + .name = "path", + .type = QEMU_OPT_STRING, + }, + { /*End of list */ } + }, +}; + +/* Read Qemu config file from open file + * + * The file will be closed before returning. + * + * Returns 0 on success, -errno on failure. + */ +static int qemu_read_config_file(FILE *f, const char *filename) { - FILE *f = fopen(filename, "r"); int ret; + if (qemu_config_parse(f, vm_config_groups, filename) == 0) { + ret = 0; + } else { + ret = -EINVAL; + } + fclose(f); + return ret; +} +/* Read Qemu config file from 'filename' + * + * Returns 0 on success, -errno on failure. + */ +int qemu_read_config_filename(const char *filename) +{ + FILE *f = fopen(filename, "r"); if (f == NULL) { return -errno; } + return qemu_read_config_file(f, filename); +} - ret = qemu_config_parse(f, vm_config_groups, filename); - fclose(f); +/* Read Qemu config file based on parsed QemuOpts object + * + * Returns 0 on success, -errno on failure. + */ +static int qemu_read_config_opts(QemuOpts *opts) +{ + const char *path = qemu_opt_get(opts, "path"); + if (!path) { + return -EINVAL; + } + return qemu_read_config_filename(path); +} - if (ret == 0) { - return 0; - } else { +/* Read config file based on option arguments on 'arg' + * + * Returns 0 on success, -errno on failure. + */ +int qemu_read_config_arg(const char *arg) +{ + QemuOpts *opts = qemu_opts_parse(&qemu_readconfig_opts, arg, 1); + if (!opts) { return -EINVAL; } + int r = qemu_read_config_opts(opts); + qemu_opts_del(opts); + return r; } diff --git a/qemu-config.h b/qemu-config.h index 20d707f..0e6ac15 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -14,6 +14,12 @@ void qemu_add_globals(void); void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname); -int qemu_read_config_file(const char *filename); +/* Read config from filename + */ +int qemu_read_config_filename(const char *filename); + +/* Read config based on key=value options using QemuOpts syntax + */ +int qemu_read_config_arg(const char *arg); #endif /* QEMU_CONFIG_H */ diff --git a/qemu-options.hx b/qemu-options.hx index daefce3..caa4fe1 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2655,9 +2655,9 @@ Old param mode (ARM only). ETEXI DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, - "-readconfig \n", QEMU_ARCH_ALL) + "-readconfig [path=]\n", QEMU_ARCH_ALL) STEXI -@item -readconfig @var{file} +@item -readconfig [type=]@var{file} @findex -readconfig Read device configuration from @var{file}. ETEXI diff --git a/vl.c b/vl.c index bd95539..c3e60fa 100644 --- a/vl.c +++ b/vl.c @@ -2351,12 +2351,12 @@ int main(int argc, char **argv, char **envp) if (defconfig) { int ret; - ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); + ret = qemu_read_config_filename(CONFIG_QEMU_CONFDIR "/qemu.conf"); if (ret < 0 && ret != -ENOENT) { exit(1); } - ret = qemu_read_config_file(arch_config_name); + ret = qemu_read_config_filename(arch_config_name); if (ret < 0 && ret != -ENOENT) { exit(1); } @@ -3144,7 +3144,7 @@ int main(int argc, char **argv, char **envp) } case QEMU_OPTION_readconfig: { - int ret = qemu_read_config_file(optarg); + int ret = qemu_read_config_arg(optarg); if (ret < 0) { fprintf(stderr, "read config %s: %s\n", optarg, strerror(-ret));