From patchwork Mon Mar 19 15:08:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 147561 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 EC601B6FBE for ; Tue, 20 Mar 2012 02:46:39 +1100 (EST) Received: from localhost ([::1]:44232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9eDJ-0003Io-R7 for incoming@patchwork.ozlabs.org; Mon, 19 Mar 2012 11:09:37 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9eCb-0001Te-7p for qemu-devel@nongnu.org; Mon, 19 Mar 2012 11:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9eCS-0000Eq-OD for qemu-devel@nongnu.org; Mon, 19 Mar 2012 11:08:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52922) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9eCS-0000ET-FY for qemu-devel@nongnu.org; Mon, 19 Mar 2012 11:08:44 -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 q2JF8hEW017656 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 19 Mar 2012 11:08:43 -0400 Received: from blackpad.lan.raisama.net (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2JF8fCZ011260 for ; Mon, 19 Mar 2012 11:08:42 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id DDC042005B5; Mon, 19 Mar 2012 12:08:42 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2012 12:08:40 -0300 Message-Id: <1332169722-11126-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1332169722-11126-1-git-send-email-ehabkost@redhat.com> References: <1332169722-11126-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 Subject: [Qemu-devel] [RFC PATCH 1/3] move list of default config files to qemu-config-arch.c 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 Move the list to an array, with a "type" field to identify the config file purpose/type. Signed-off-by: Eduardo Habkost --- arch_init.c | 1 - arch_init.h | 2 -- qemu-config-arch.c | 36 ++++++++++++++++++++++++++++++++++++ qemu-config-arch.h | 4 ++++ vl.c | 12 +++--------- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/arch_init.c b/arch_init.c index a95ef49..56b2147 100644 --- a/arch_init.c +++ b/arch_init.c @@ -54,7 +54,6 @@ int graphic_height = 600; int graphic_depth = 15; #endif -const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf"; #if defined(TARGET_ALPHA) #define QEMU_ARCH QEMU_ARCH_ALPHA diff --git a/arch_init.h b/arch_init.h index 828256c..c7cb94a 100644 --- a/arch_init.h +++ b/arch_init.h @@ -1,8 +1,6 @@ #ifndef QEMU_ARCH_INIT_H #define QEMU_ARCH_INIT_H -extern const char arch_config_name[]; - enum { QEMU_ARCH_ALL = -1, QEMU_ARCH_ALPHA = 1, diff --git a/qemu-config-arch.c b/qemu-config-arch.c index ee5d515..83a0c89 100644 --- a/qemu-config-arch.c +++ b/qemu-config-arch.c @@ -45,6 +45,30 @@ static QemuOptsList qemu_readconfig_opts = { }, }; +#define MAIN_CONFIG_NAME (CONFIG_QEMU_CONFDIR "/qemu.conf") +#define ARCH_CONFIG_NAME (CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf") + +/* List of default config files + */ +struct DefaultConfigFile { + /* Identifier to the default config file. + */ + const char *type; + /* Config file path + */ + const char *path; +}; + +static struct DefaultConfigFile arch_default_configs[] = { + /* user-editable config files from /etc: */ + /* Main, generic config file: */ + {"main", MAIN_CONFIG_NAME}, + /* Arch-specific config file: */ + {"arch", ARCH_CONFIG_NAME}, + + /* end of list */ + {NULL, NULL}, +}; /* Read Qemu config file based on parsed QemuOpts object * @@ -84,3 +108,15 @@ int qemu_read_config_arg(const char *arg) qemu_opts_del(opts); return r; } + +int qemu_read_default_configs(void) +{ + const struct DefaultConfigFile *cfg; + for (cfg = arch_default_configs; cfg->path; cfg++) { + int ret = qemu_read_config_filename(cfg->path); + if (ret < 0 && ret != -ENOENT) { + return ret; + } + } + return 0; +} diff --git a/qemu-config-arch.h b/qemu-config-arch.h index 3a9943d..289ea59 100644 --- a/qemu-config-arch.h +++ b/qemu-config-arch.h @@ -12,4 +12,8 @@ */ int qemu_read_config_arg(const char *arg); +/* Read default config files for the architecture + */ +int qemu_read_default_configs(void); + #endif /* QEMU_CONFIG_ARCH_H */ diff --git a/vl.c b/vl.c index 26e6738..2ef172b 100644 --- a/vl.c +++ b/vl.c @@ -2350,15 +2350,9 @@ int main(int argc, char **argv, char **envp) } if (defconfig) { - int ret; - - ret = qemu_read_config_filename(CONFIG_QEMU_CONFDIR "/qemu.conf"); - if (ret < 0 && ret != -ENOENT) { - exit(1); - } - - ret = qemu_read_config_filename(arch_config_name); - if (ret < 0 && ret != -ENOENT) { + int ret = qemu_read_default_configs(); + if (ret < 0) { + fprintf(stderr, "error loading default config files: %s", strerror(ret)); exit(1); } }