Skip to contentSkip to conversation

Introduce global config (v3)

PATCH In review Anthony Liguori 6 participants 18 messages Jan 24, 2010 – Jan 26, 2010

lore
Share & tools
lore
#0 lore raw

cover Introduce global config (v3)

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.

#1 lore raw

PATCH 1/3 Support --sysconfdir in configure to specify path to configuration files (v3)

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.

---
v2 -> v3
- default sysconfdir to ${prefix}/etc on unix, ${prefix} on win32
- set confdir to ${sysconfdir}/qemu on unix, ${sysconfdir} on win32
v1 -> v2
- rename to sysconf

---
 configure |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
configure +17 -0
index 5631bbb..379b536 100755
@@ -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,8 +1832,12 @@ if test "$mingw32" = "yes" ; then
   fi
   mansuffix=""
   datasuffix=""
+  confsuffix=""
   docsuffix=""
   binsuffix=""
+  if test -z "$sysconfdir" ; then
+      sysconfdir="${prefix}"
+  fi
 else
   if test -z "$prefix" ; then
       prefix="/usr/local"
@@ -1838,6 +1846,9 @@ else
   datasuffix="/share/qemu"
   docsuffix="/share/doc/qemu"
   binsuffix="/bin"
+  if test -z "$sysconfdir" ; then
+      sysconfdir="${prefix}/etc"
+  fi
 fi
 
 echo "Install prefix    $prefix"
@@ -1914,6 +1925,11 @@ printf " '%s'" "$0" "$@" >> $config_host_mak
 echo >> $config_host_mak
 
 echo "CONFIG_QEMU_SHAREDIR=\"$prefix$datasuffix\"" >> $config_host_mak
+if test "$mingw32" = "yes" ; then
+  echo "CONFIG_QEMU_CONFDIR=\"$sysconfdir\"" >> $config_host_mak
+else
+  echo "CONFIG_QEMU_CONFDIR=\"${sysconfdir}/qemu\"" >> $config_host_mak
+fi
 
 case "$cpu" in
   i386|x86_64|alpha|cris|hppa|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|s390|s390x|sparc|sparc64)
@@ -2159,6 +2175,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
Signature · 1 line
1.6.5.2
#2 lore raw

[Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3)

Quoted 9 lines · Anthony Liguori

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.

---
v2 -> v3
- default sysconfdir to ${prefix}/etc on unix, ${prefix} on win32
- set confdir to ${sysconfdir}/qemu on unix, ${sysconfdir} on win32

I'm not sure about the choice for Windows. Do we want possibly a dozen of .conf files all in the same directory as the binaries, or maybe it's better to set sysconfdir = ${prefix}/conf, confdir=${sysconfdir} on Windows?

configure printf " '%s'" "$0" "$@" >> $config_host_mak · line 1932

Quoted 5 lines
configure +5 -0
+if test "$mingw32" = "yes" ; then
+  echo "CONFIG_QEMU_CONFDIR=\"$sysconfdir\"" >> $config_host_mak
+else
+  echo "CONFIG_QEMU_CONFDIR=\"${sysconfdir}/qemu\"" >> $config_host_mak
+fi

Also, here you can use $confsuffix as used a bit above to avoid introducing an if here.

Anyway, this can be discussed/cleaned up later, this patch gets my ack.

Paolo

#3 lore raw

Re: [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3)

Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Anthony Liguori

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.

Quoted 7 lines
Quoted 5 lines

---
v2 -> v3
- default sysconfdir to ${prefix}/etc on unix, ${prefix} on win32
- set confdir to ${sysconfdir}/qemu on unix, ${sysconfdir} on win32

I'm not sure about the choice for Windows. Do we want possibly a dozen of .conf files all in the same directory as the binaries, or maybe it's better to set sysconfdir = ${prefix}/conf, confdir=${sysconfdir} on Windows?

I honestly don't know. What's the normal thing to do with Windows?

Quoted 10 lines

configure printf " '%s'" "$0" "$@" >> $config_host_mak · line 1932

Quoted 6 lines
configure +5 -0
+if test "$mingw32" = "yes" ; then
+  echo "CONFIG_QEMU_CONFDIR=\"$sysconfdir\"" >> $config_host_mak
+else
+  echo "CONFIG_QEMU_CONFDIR=\"${sysconfdir}/qemu\"" >> $config_host_mak
+fi

Also, here you can use $confsuffix as used a bit above to avoid introducing an if here.

Anyway, this can be discussed/cleaned up later, this patch gets my ack.

Regards,

Anthony Liguori

Quoted 4 lines

Paolo

#4 lore raw

Re: [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3)

Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Anthony Liguori

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.

---
v2 -> v3
- default sysconfdir to ${prefix}/etc on unix, ${prefix} on win32
- set confdir to ${sysconfdir}/qemu on unix, ${sysconfdir} on win32

Quoted 3 lines
Quoted 1 line

I'm not sure about the choice for Windows. Do we want possibly a dozen of .conf files all in the same directory as the binaries, or maybe it's better to set sysconfdir = ${prefix}/conf, confdir=${sysconfdir} on Windows?

I honestly don't know. What's the normal thing to do with Windows?

The registry, I think.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw

Re: [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3)

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

I'm not sure about the choice for Windows. Do we want possibly a dozen of .conf files all in the same directory as the binaries, or maybe it's better to set sysconfdir = ${prefix}/conf, confdir=${sysconfdir} on Windows?

I honestly don't know. What's the normal thing to do with Windows?

The registry, I think.

The registry would be used indeed to get the path or to override defaults. However, what would be the default value (written in the registry by the installer, or used by the program if the registry value is absent)?

Paolo

#6 lore raw

Re: [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3)

Quoted 11 lines · Paolo Bonzini
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

I'm not sure about the choice for Windows. Do we want possibly a dozen of .conf files all in the same directory as the binaries, or maybe it's better to set sysconfdir = ${prefix}/conf, confdir=${sysconfdir} on Windows?

I honestly don't know. What's the normal thing to do with Windows?

The registry, I think.

The registry would be used indeed to get the path or to override defaults. However, what would be the default value (written in the registry by the installer, or used by the program if the registry value is absent)?

ini-style configs are not at all uncommon on Windows. I also don't think it's that uncommon to store executables and config files side-by-side in a Program Files directory.

Regards,

Anthony Liguori

Quoted 1 line

Paolo

#7 lore raw

Re: [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3)

Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines

I'm not sure about the choice for Windows. Do we want possibly a dozen of .conf files all in the same directory as the binaries, or maybe it's better to set sysconfdir = ${prefix}/conf, confdir=${sysconfdir} on Windows?

I honestly don't know. What's the normal thing to do with Windows?

The registry, I think.

Quoted 8 lines
Quoted 4 lines

The registry would be used indeed to get the path or to override defaults. However, what would be the default value (written in the registry by the installer, or used by the program if the registry value is absent)?

ini-style configs are not at all uncommon on Windows. I also don't think it's that uncommon to store executables and config files side-by-side in a Program Files directory.

Indeed, that's what I'm saying. The registry may hold a path to the ini files, but you would still have to think of a sane default. You chose the binaries' directory, fine, that's not a huge deal---someone who cares about Windows can step up and say what they think.

Paolo

#8 lore raw

Re: [Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v3)

In reply to Paolo Bonzini
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

I'm not sure about the choice for Windows. Do we want possibly a dozen of .conf files all in the same directory as the binaries, or maybe it's better to set sysconfdir = ${prefix}/conf, confdir=${sysconfdir} on Windows?

I honestly don't know. What's the normal thing to do with Windows?

The registry, I think.

The registry would be used indeed to get the path or to override defaults. However, what would be the default value (written in the registry by the installer, or used by the program if the registry value is absent)?

You could use the registry to hold the defaults, not a path to the defaults.

Signature · 1 line
error compiling committee.c: too many arguments to function
#9 lore raw

PATCH 2/3 Move out option lookup into a separate function

In reply to Anthony Liguori
---
 vl.c |   72 +++++++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 43 insertions(+), 29 deletions(-)
vl.c +43 -29
index e070ec9..e00ae0d 100644
@@ -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);
Signature · 1 line
1.6.5.2
#10 lore raw

PATCH 3/3 Load global config files by default (v3)

In reply to Anthony Liguori

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.

---
v2->v3
- update to use confdir instead of sysconfdir
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(-)
qemu-options.hx +9 -0
index ee60d8a..9294e07 100644
@@ -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
vl.c +39 -0
index e00ae0d..7fe6a39 100644
@@ -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_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)
Signature · 1 line
1.6.5.2
#11 lore raw
In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

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).

Would be nice, in addition, to load per-user configuration from ~/.qemu/*.conf.

Signature · 1 line
error compiling committee.c: too many arguments to function
#12 lore raw
Quoted 5 lines · Avi Kivity
Quoted 2 lines · Anthony Liguori

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).

Would be nice, in addition, to load per-user configuration from ~/.qemu/*.conf.

Indeed. I'll make a follow on patch.

Regards,

Anthony Liguori

#13 lore raw
In reply to Anthony Liguori
Quoted 6 lines · Anthony Liguori

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.

btw, what does the corresponding patch to our imaginary management tool author guide read? Do we recommend -nodefconfig or not? I think we should, since otherwise qemu behaviour can be completely unexpected by the management tool.

Signature · 1 line
error compiling committee.c: too many arguments to function
#14 lore raw
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Anthony Liguori

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.

Quoted 4 lines

btw, what does the corresponding patch to our imaginary management tool author guide read? Do we recommend -nodefconfig or not? I think we should, since otherwise qemu behaviour can be completely unexpected by the management tool.

I think so, the next version of libvirt will use -nodefaults, and -nodefconfig is in the same group.

Paolo

#15 lore raw
Quoted 12 lines · Paolo Bonzini
Quoted 11 lines · Avi Kivity
Quoted 9 lines · Anthony Liguori

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.

Quoted 7 lines
Quoted 4 lines

btw, what does the corresponding patch to our imaginary management tool author guide read? Do we recommend -nodefconfig or not? I think we should, since otherwise qemu behaviour can be completely unexpected by the management tool.

I think so, the next version of libvirt will use -nodefaults, and -nodefconfig is in the same group.

It sounds like we need to add -nodefconfig too, unless -nodefaults will automatically imply -nodefconfig too ?

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#16 lore raw
Quoted 21 lines · Daniel P. Berrange
Quoted 19 lines · Paolo Bonzini
Quoted 17 lines · Avi Kivity
Quoted 10 lines · Anthony Liguori

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.

btw, what does the corresponding patch to our imaginary management tool author guide read? Do we recommend -nodefconfig or not? I think we should, since otherwise qemu behaviour can be completely unexpected by the management tool.

Quoted 6 lines
Quoted 3 lines

I think so, the next version of libvirt will use -nodefaults, and -nodefconfig is in the same group.

It sounds like we need to add -nodefconfig too, unless -nodefaults will automatically imply -nodefconfig too ?

Right now, -nodefaults does not imply -nodefconfig.

Regards,

Anthony Liguori

Quoted 2 lines

Daniel

#17 lore raw
In reply to Avi Kivity
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Anthony Liguori

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.

btw, what does the corresponding patch to our imaginary management tool author guide read? Do we recommend -nodefconfig or not? I think we should, since otherwise qemu behaviour can be completely unexpected by the management tool.

It depends. I think there are two classes of management tools. The first class, like libvirt, completely hides the details of QEMU from the user. For libvirt, it should definitely use -nodefconfig because a user should not be encouraged to tweak bits without libvirt knowing about it.

A second class of management tools would work with QEMU and basically extend what we currently expose. IOW, guest's would be represented through our native config file, full access would be provided to monitor/QMP commands. For this class of tools, a user should be encouraged to use the default configuration files to make global changes to a particular node.

Regards,

Anthony Liguori