From 6cd8e593884719b04ee7b467346f285cf70ab59d Mon Sep 17 00:00:00 2001
From: john cooper <john.cooper@redhat.com>
Date: Thu, 1 Apr 2010 20:19:14 -0300
Subject: [PATCH 3/4] Add qemu cpu model configuration support v2 [BZ #569661]

RH-Author: john cooper <john.cooper@redhat.com>
Message-id: <4BB4FFC2.4060607@redhat.com>
Patchwork-id: 8331
O-Subject: [RHEL6 PATCH 3/4] Add qemu cpu model configuration support v2 [BZ
	#569661]
Bugzilla: 569661
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>

Apply upstream:

commit 292444cb87f3b883146ee30628a5922b1cde4073
Author: Anthony Liguori <aliguori@us.ibm.com>
Date:   Thu Jan 21 10:57:58 2010 -0600

    Load global config files by default

    A new option, -nodefconfig is introduced to prevent loading from the default
    config location.  Otherwise, two configuration files will be searched for,
    qemu.conf and target-<TARGET_NAME>.conf.

    To ensure that the default configuration is overridden by a user specified
    config, we introduce a two stage option parsing mechanism.

    Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu-options.hx |    9 +++++++++
 vl.c            |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 5efb57b..2d8ef64 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1929,6 +1929,15 @@ STEXI
 Immediately before starting guest execution, drop root privileges, switching
 to the specified user.
 ETEXI
+DEF("nodefconfig", 0, QEMU_OPTION_nodefconfig,
+    "-nodefconfig\n"
+    "                do not load default config files at startup\n")
+STEXI
+@item -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.
+ETEXI
 
 STEXI
 @end table
diff --git a/vl.c b/vl.c
index 29b6769..33fcdc3 100644
--- a/vl.c
+++ b/vl.c
@@ -5047,6 +5047,7 @@ int main(int argc, char **argv, char **envp)
 #endif
     CPUState *env;
     int show_vnc_port = 0;
+    int defconfig = 1;
 
     init_clocks();
 
@@ -5108,6 +5109,44 @@ int main(int argc, char **argv, char **envp)
     tb_size = 0;
     autostart= 1;
 
+    /* first pass of option parsing */
+    optind = 1;
+    while (optind < argc) {
+        if (argv[optind][0] != '-') {
+            /* disk image */
+            continue;
+        } else {
+            const QEMUOption *popt;
+
+            popt = lookup_opt(argc, argv, &optarg, &optind);
+            switch (popt->index) {
+            case QEMU_OPTION_nodefconfig:
+                defconfig=0;
+                break;
+            }
+        }
+    }
+
+    if (defconfig) {
+        FILE *fp;
+        fp = fopen(CONFIG_QEMU_CONFDIR "/qemu.conf", "r");
+        if (fp) {
+            if (qemu_config_parse(fp) != 0) {
+                exit(1);
+            }
+            fclose(fp);
+        }
+
+        fp = fopen(CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", "r");
+        if (fp) {
+            if (qemu_config_parse(fp) != 0) {
+                exit(1);
+            }
+            fclose(fp);
+        }
+    }
+
+    /* second pass of option parsing */
     optind = 1;
     for(;;) {
         if (optind >= argc)
-- 
1.7.0.3

