From patchwork Thu Jun 2 19:13:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 98468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 397D8B6FAF for ; Fri, 3 Jun 2011 05:27:14 +1000 (EST) Received: from localhost ([::1]:57809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSDXy-0006OO-If for incoming@patchwork.ozlabs.org; Thu, 02 Jun 2011 15:27:10 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSDKc-0003ha-Qw for qemu-devel@nongnu.org; Thu, 02 Jun 2011 15:13:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSDKZ-0003cr-Uc for qemu-devel@nongnu.org; Thu, 02 Jun 2011 15:13:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSDKZ-0003bO-CR for qemu-devel@nongnu.org; Thu, 02 Jun 2011 15:13:19 -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 p52JDGgb008350 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 2 Jun 2011 15:13:16 -0400 Received: from blackpad.lan.raisama.net (ovpn-113-117.phx2.redhat.com [10.3.113.117]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p52JDFeI029167; Thu, 2 Jun 2011 15:13:16 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id AE40620A67B; Thu, 2 Jun 2011 16:13:11 -0300 (BRT) From: Eduardo Habkost To: Anthony Liguori Date: Thu, 2 Jun 2011 16:13:03 -0300 Message-Id: <1307041990-26194-5-git-send-email-ehabkost@redhat.com> In-Reply-To: <1307041990-26194-1-git-send-email-ehabkost@redhat.com> References: <1307041990-26194-1-git-send-email-ehabkost@redhat.com> 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. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [RHEL6 qemu-kvm PATCH 04/11] Support -readconfig "?" to debug config file loading 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: john cooper 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. In the case of a "?" pseudo filename arg to -readconfig, verbose open of all config files will be enabled. Normal handling of config files is otherwise unaffected by this option. Note: other CLI flag schemes have been discussed at length to accommodate this option. However given the constraints of the existing user interface, a solution which minimally impacts the user is ultimately required. [ehabkost: edited commit message to have better Subject line] Signed-off-by: john cooper Signed-off-by: Eduardo Habkost --- qemu-config.c | 30 +++++++++++++++++++----------- qemu-config.h | 2 +- vl.c | 20 +++++++++++++------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 5d7ffa2..b39b8fe 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -666,21 +666,29 @@ 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"; + } 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); } - - ret = qemu_config_parse(f, vm_config_groups, filename); - fclose(f); - - if (ret == 0) { - return 0; - } else { - return -EINVAL; + 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/vl.c b/vl.c index b362871..65b0791 100644 --- a/vl.c +++ b/vl.c @@ -2059,6 +2059,7 @@ int main(int argc, char **argv, char **envp) int show_vnc_port = 0; #endif int defconfig = 1; + int defconfig_verbose = 0; const char *trace_file = NULL; atexit(qemu_run_exit_notifiers); @@ -2108,6 +2109,12 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_nodefconfig: defconfig=0; break; + case QEMU_OPTION_readconfig: + /* pseudo filename "?" enables verbose config file handling */ + if (!strcmp(optarg, "?")) { + defconfig_verbose = 1; + } + break; } } } @@ -2115,12 +2122,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); } @@ -2857,11 +2865,9 @@ int main(int argc, char **argv, char **envp) #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); + if (strcmp(optarg, "?") && + qemu_read_config_file(optarg, defconfig_verbose) < 0) { + exit(1); } break; }