qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Introduce global config (v2)
@ 2010-01-22 16:08 Anthony Liguori
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2) Anthony Liguori
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Anthony Liguori @ 2010-01-22 16:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Cooper, Paolo Bonzini, Anthony Liguori, Gerd Hoffman

This series introduces global config files stored in /etc/qemu.  There is both
a common config (qemu.conf) and a per-target config (target-<TARGET_NAME>.conf).

I've removed the default device bits from the series as it requires some more
thought on how to best integrate it.  That makes this series rather simple.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2)
  2010-01-22 16:08 [Qemu-devel] Introduce global config (v2) Anthony Liguori
@ 2010-01-22 16:09 ` Anthony Liguori
  2010-01-22 16:32   ` [Qemu-devel] " Paolo Bonzini
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 2/3] Move out option lookup into a separate function Anthony Liguori
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 3/3] Load global config files by default (v2) Anthony Liguori
  2 siblings, 1 reply; 7+ messages in thread
From: Anthony Liguori @ 2010-01-22 16:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Cooper, Paolo Bonzini, Anthony Liguori, Gerd Hoffman

The default value is ${prefix}/etc/qemu.  --sysconfdir can be used to override
the default to an absolute path.  The expectation is that when installed to
/usr, --sysconfdir=/etc/qemu will be used.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
 - rename to sysconf
---
 configure |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 5631bbb..7f8c636 100755
--- a/configure
+++ b/configure
@@ -32,6 +32,7 @@ cpu=""
 prefix=""
 interp_prefix="/usr/gnemul/qemu-%M"
 static="no"
+sysconfdir=""
 sparc_cpu=""
 cross_prefix=""
 cc="gcc"
@@ -453,6 +454,8 @@ for opt do
   ;;
   --static) static="yes"
   ;;
+  --sysconfdir) sysconfdir="$optarg"
+  ;;
   --disable-sdl) sdl="no"
   ;;
   --enable-sdl) sdl="yes"
@@ -686,6 +689,7 @@ echo "  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS"
 echo "  --make=MAKE              use specified make [$make]"
 echo "  --install=INSTALL        use specified install [$install]"
 echo "  --static                 enable static build [$static]"
+echo "  --sysconfdir=PATH        install config in PATH"
 echo "  --enable-debug-tcg       enable TCG debugging"
 echo "  --disable-debug-tcg      disable TCG debugging (default)"
 echo "  --enable-debug           enable common debug build options"
@@ -1828,6 +1832,7 @@ if test "$mingw32" = "yes" ; then
   fi
   mansuffix=""
   datasuffix=""
+  confsuffix=""
   docsuffix=""
   binsuffix=""
 else
@@ -1838,6 +1843,9 @@ else
   datasuffix="/share/qemu"
   docsuffix="/share/doc/qemu"
   binsuffix="/bin"
+  if test -z "$sysconfdir" ; then
+      sysconfdir="${prefix}/etc/qemu"
+  fi
 fi
 
 echo "Install prefix    $prefix"
@@ -1914,6 +1922,7 @@ printf " '%s'" "$0" "$@" >> $config_host_mak
 echo >> $config_host_mak
 
 echo "CONFIG_QEMU_SHAREDIR=\"$prefix$datasuffix\"" >> $config_host_mak
+echo "CONFIG_QEMU_SYSCONFDIR=\"$sysconfdir\"" >> $config_host_mak
 
 case "$cpu" in
   i386|x86_64|alpha|cris|hppa|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64)
@@ -2159,6 +2168,7 @@ echo "prefix=$prefix" >> $config_host_mak
 echo "bindir=\${prefix}$binsuffix" >> $config_host_mak
 echo "mandir=\${prefix}$mansuffix" >> $config_host_mak
 echo "datadir=\${prefix}$datasuffix" >> $config_host_mak
+echo "sysconfdir=$sysconfdir" >> $config_host_mak
 echo "docdir=\${prefix}$docsuffix" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "INSTALL=$install" >> $config_host_mak
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 2/3] Move out option lookup into a separate function
  2010-01-22 16:08 [Qemu-devel] Introduce global config (v2) Anthony Liguori
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2) Anthony Liguori
@ 2010-01-22 16:09 ` Anthony Liguori
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 3/3] Load global config files by default (v2) Anthony Liguori
  2 siblings, 0 replies; 7+ messages in thread
From: Anthony Liguori @ 2010-01-22 16:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Cooper, Paolo Bonzini, Anthony Liguori, Gerd Hoffman

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 vl.c |   72 +++++++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/vl.c b/vl.c
index e070ec9..e00ae0d 100644
--- a/vl.c
+++ b/vl.c
@@ -4658,6 +4658,46 @@ static int debugcon_parse(const char *devname)
     return 0;
 }
 
+static const QEMUOption *lookup_opt(int argc, char **argv,
+                                    const char **poptarg, int *poptind)
+{
+    const QEMUOption *popt;
+    int optind = *poptind;
+    char *r = argv[optind];
+    const char *optarg;
+
+    optind++;
+    /* Treat --foo the same as -foo.  */
+    if (r[1] == '-')
+        r++;
+    popt = qemu_options;
+    for(;;) {
+        if (!popt->name) {
+            fprintf(stderr, "%s: invalid option -- '%s'\n",
+                    argv[0], r);
+            exit(1);
+        }
+        if (!strcmp(popt->name, r + 1))
+            break;
+        popt++;
+    }
+    if (popt->flags & HAS_ARG) {
+        if (optind >= argc) {
+            fprintf(stderr, "%s: option '%s' requires an argument\n",
+                    argv[0], r);
+            exit(1);
+        }
+        optarg = argv[optind++];
+    } else {
+        optarg = NULL;
+    }
+
+    *poptarg = optarg;
+    *poptind = optind;
+
+    return popt;
+}
+
 int main(int argc, char **argv, char **envp)
 {
     const char *gdbstub_dev = NULL;
@@ -4672,7 +4712,7 @@ int main(int argc, char **argv, char **envp)
     int cyls, heads, secs, translation;
     QemuOpts *hda_opts = NULL, *opts;
     int optind;
-    const char *r, *optarg;
+    const char *optarg;
     const char *loadvm = NULL;
     QEMUMachine *machine;
     const char *cpu_model;
@@ -4753,38 +4793,12 @@ int main(int argc, char **argv, char **envp)
     for(;;) {
         if (optind >= argc)
             break;
-        r = argv[optind];
-        if (r[0] != '-') {
+        if (argv[optind][0] != '-') {
 	    hda_opts = drive_add(argv[optind++], HD_ALIAS, 0);
         } else {
             const QEMUOption *popt;
 
-            optind++;
-            /* Treat --foo the same as -foo.  */
-            if (r[1] == '-')
-                r++;
-            popt = qemu_options;
-            for(;;) {
-                if (!popt->name) {
-                    fprintf(stderr, "%s: invalid option -- '%s'\n",
-                            argv[0], r);
-                    exit(1);
-                }
-                if (!strcmp(popt->name, r + 1))
-                    break;
-                popt++;
-            }
-            if (popt->flags & HAS_ARG) {
-                if (optind >= argc) {
-                    fprintf(stderr, "%s: option '%s' requires an argument\n",
-                            argv[0], r);
-                    exit(1);
-                }
-                optarg = argv[optind++];
-            } else {
-                optarg = NULL;
-            }
-
+            popt = lookup_opt(argc, argv, &optarg, &optind);
             switch(popt->index) {
             case QEMU_OPTION_M:
                 machine = find_machine(optarg);
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH 3/3] Load global config files by default (v2)
  2010-01-22 16:08 [Qemu-devel] Introduce global config (v2) Anthony Liguori
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2) Anthony Liguori
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 2/3] Move out option lookup into a separate function Anthony Liguori
@ 2010-01-22 16:09 ` Anthony Liguori
  2 siblings, 0 replies; 7+ messages in thread
From: Anthony Liguori @ 2010-01-22 16:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Cooper, Paolo Bonzini, Anthony Liguori, Gerd Hoffman

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>
---
v1->v2
 - Introduce two stage option parsing to make sure global config file is
   overridden by command line options
---
 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 ee60d8a..9294e07 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1965,6 +1965,15 @@ STEXI
 @item -writeconfig @var{file}
 Write device configuration to @var{file}.
 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
 
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
diff --git a/vl.c b/vl.c
index e00ae0d..a90c330 100644
--- a/vl.c
+++ b/vl.c
@@ -4730,6 +4730,7 @@ int main(int argc, char **argv, char **envp)
 #endif
     CPUState *env;
     int show_vnc_port = 0;
+    int defconfig = 1;
 
     init_clocks();
 
@@ -4789,6 +4790,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_SYSCONFDIR "/qemu.conf", "r");
+        if (fp) {
+            if (qemu_config_parse(fp) != 0) {
+                exit(1);
+            }
+            fclose(fp);
+        }
+
+        fp = fopen(CONFIG_QEMU_SYSCONFDIR "/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.6.5.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2)
  2010-01-22 16:09 ` [Qemu-devel] [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2) Anthony Liguori
@ 2010-01-22 16:32   ` Paolo Bonzini
  2010-01-22 16:59     ` Anthony Liguori
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2010-01-22 16:32 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: John Cooper, qemu-devel, Gerd Hoffman

On 01/22/2010 05:09 PM, Anthony Liguori wrote:
> The default value is ${prefix}/etc/qemu.  --sysconfdir can be used to override
> the default to an absolute path.  The expectation is that when installed to
> /usr, --sysconfdir=/etc/qemu will be used.

Sorry for not being precise; --sysconfdir in Autoconf is just ${prefix}/etc.

Paolo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2)
  2010-01-22 16:32   ` [Qemu-devel] " Paolo Bonzini
@ 2010-01-22 16:59     ` Anthony Liguori
  2010-01-22 17:00       ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: Anthony Liguori @ 2010-01-22 16:59 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: John Cooper, qemu-devel, Gerd Hoffman

On 01/22/2010 10:32 AM, Paolo Bonzini wrote:
> On 01/22/2010 05:09 PM, Anthony Liguori wrote:
>> The default value is ${prefix}/etc/qemu.  --sysconfdir can be used to 
>> override
>> the default to an absolute path.  The expectation is that when 
>> installed to
>> /usr, --sysconfdir=/etc/qemu will be used.
>
> Sorry for not being precise; --sysconfdir in Autoconf is just 
> ${prefix}/etc.

That's tough for us because on Windows, we store everything in a single 
directory.  That is, ${sysconfdir}/qemu wouldn't be a good base for us.  
We would need to have sysconfdir and then a confdir that we could make 
different for win32.

Regards,

Anthony Liguori

> Paolo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2)
  2010-01-22 16:59     ` Anthony Liguori
@ 2010-01-22 17:00       ` Paolo Bonzini
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2010-01-22 17:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: John Cooper, qemu-devel, Gerd Hoffman


> That's tough for us because on Windows, we store everything in a single
> directory. That is, ${sysconfdir}/qemu wouldn't be a good base for us.
> We would need to have sysconfdir and then a confdir that we could make
> different for win32.

That makes sense.  sysconf for system, conf for qemu.

Paolo

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-01-22 17:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-22 16:08 [Qemu-devel] Introduce global config (v2) Anthony Liguori
2010-01-22 16:09 ` [Qemu-devel] [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2) Anthony Liguori
2010-01-22 16:32   ` [Qemu-devel] " Paolo Bonzini
2010-01-22 16:59     ` Anthony Liguori
2010-01-22 17:00       ` Paolo Bonzini
2010-01-22 16:09 ` [Qemu-devel] [PATCH 2/3] Move out option lookup into a separate function Anthony Liguori
2010-01-22 16:09 ` [Qemu-devel] [PATCH 3/3] Load global config files by default (v2) Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).