From patchwork Wed Nov 24 22:45:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 72959 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 84200B7043 for ; Thu, 25 Nov 2010 10:03:53 +1100 (EST) Received: from localhost ([127.0.0.1]:60483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLONT-0001DY-2w for incoming@patchwork.ozlabs.org; Wed, 24 Nov 2010 18:03:51 -0500 Received: from [140.186.70.92] (port=37102 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLOHg-0006oj-Pw for qemu-devel@nongnu.org; Wed, 24 Nov 2010 17:57:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLOHe-0000Im-T7 for qemu-devel@nongnu.org; Wed, 24 Nov 2010 17:57:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PLOHe-0000Id-5c for qemu-devel@nongnu.org; Wed, 24 Nov 2010 17:57:50 -0500 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.13.8/8.13.8) with ESMTP id oAOMvn8P020721 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 24 Nov 2010 17:57:49 -0500 Received: from anvil.naka.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAOMvhPD011399; Wed, 24 Nov 2010 17:57:45 -0500 Message-ID: <4CED9582.2080801@redhat.com> Date: Wed, 24 Nov 2010 17:45:22 -0500 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: john cooper , Anthony Liguori Subject: [Qemu-devel] [PATCH 4/4] cpu model corrections/updates: add verbose config file handling 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 Failure by qemu to open a default config file isn't cause to error exit -- it just quietly continues on. After puzzling issues with otherwise opaque config file locations and startup handling numerous times, some help from qemu seemed justified. The prior version of this patch overloaded "-readconfig ?" to enable verbose handling. Here we add a global "-config" flag which takes [verbose][,nodefault] as options modifying config file handling. Note "-nodefconfig" has been removed and functionally replaced here by the "nodefault" flag option. Signed-off-by: john cooper diff --git a/qemu-config.c b/qemu-config.c index 52f18be..1b871d6 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -630,21 +630,31 @@ out: return res; } -int qemu_read_config_file(const char *filename) +/* attempt to open and parse config file, report problems if vflag + */ +int qemu_read_config_file(const char *filename, int vflag) { FILE *f = fopen(filename, "r"); - int ret; + int rv = 0; + const char *err; if (f == NULL) { - return -errno; + rv = -errno; + err = "open"; } - - ret = qemu_config_parse(f, vm_config_groups, filename); - fclose(f); - - if (ret == 0) { - return 0; - } else { - return -EINVAL; + else if (qemu_config_parse(f, vm_config_groups, filename) != 0) { + rv = -EINVAL; + err = "parse"; + } + else if (vflag) { + fprintf(stderr, "parsed config file %s\n", filename); + } + if (f) { + fclose(f); + } + if (rv && vflag) { + fprintf(stderr, "can't %s config file %s: %s\n", + err, filename, strerror(-rv)); } + return rv; } diff --git a/qemu-config.h b/qemu-config.h index 20d707f..b90a7cc 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -14,6 +14,6 @@ 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); +int qemu_read_config_file(const char *filename, int vflag); #endif /* QEMU_CONFIG_H */ diff --git a/qemu-options.hx b/qemu-options.hx index 4d99a58..00c0845 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2290,16 +2290,19 @@ STEXI @findex -writeconfig Write device configuration to @var{file}. ETEXI -DEF("nodefconfig", 0, QEMU_OPTION_nodefconfig, - "-nodefconfig\n" - " do not load default config files at startup\n", +DEF("config", HAS_ARG, QEMU_OPTION_config, + "-config [nodefault][,verbose]\n" + " set global config file options.\n", QEMU_ARCH_ALL) STEXI -@item -nodefconfig -@findex -nodefconfig -Normally QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and -@var{sysconfdir}/target-@var{ARCH}.conf on startup. The @code{-nodefconfig} -option will prevent QEMU from loading these configuration files at startup. +@item -config +@findex -config +By default QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and +@var{sysconfdir}/target-@var{ARCH}.conf on startup. +The @code{-config nodefault} option will prevent QEMU from loading these +configuration files at startup. +Additionally @code{-config verbose} will provide detail to the user of +all config file handling. ETEXI #ifdef CONFIG_SIMPLE_TRACE DEF("trace", HAS_ARG, QEMU_OPTION_trace, diff --git a/vl.c b/vl.c index 805e11f..160f14b 100644 --- a/vl.c +++ b/vl.c @@ -1806,6 +1806,7 @@ int main(int argc, char **argv, char **envp) const char *incoming = NULL; int show_vnc_port = 0; int defconfig = 1; + int defconfig_verbose = 0; #ifdef CONFIG_SIMPLE_TRACE const char *trace_file = NULL; @@ -1854,8 +1855,25 @@ int main(int argc, char **argv, char **envp) popt = lookup_opt(argc, argv, &optarg, &optind); switch (popt->index) { - case QEMU_OPTION_nodefconfig: - defconfig=0; + case QEMU_OPTION_config: + { + char *p, *q, *r; + + for (r = p = strdup(optarg); (q = strtok(r, ",")); r = NULL) + if (!strcmp(q, "nodefault")) { + defconfig = 0; + } else if (!strcmp(q, "verbose")) { + defconfig_verbose = 1; + } else { + fprintf(stderr, "unknown option \"%s\"\n", q); + exit(1); + } + free(p); + break; + } + case QEMU_OPTION_readconfig: + if (qemu_read_config_file(optarg, defconfig_verbose) < 0) + exit(1); break; } } @@ -1864,12 +1882,13 @@ 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_file(CONFIG_QEMU_CONFDIR "/qemu.conf", + defconfig_verbose); if (ret < 0 && ret != -ENOENT) { exit(1); } - ret = qemu_read_config_file(arch_config_name); + ret = qemu_read_config_file(arch_config_name, defconfig_verbose); if (ret < 0 && ret != -ENOENT) { exit(1); } @@ -2577,16 +2596,6 @@ int main(int argc, char **argv, char **envp) } break; #endif - case QEMU_OPTION_readconfig: - { - int ret = qemu_read_config_file(optarg); - if (ret < 0) { - fprintf(stderr, "read config %s: %s\n", optarg, - strerror(-ret)); - exit(1); - } - break; - } case QEMU_OPTION_spice: olist = qemu_find_opts("spice"); if (!olist) {