Introduce global config (v2)
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.
PATCH 1/3 Support --sysconfdir in configure to specify path to configuration files (v2)
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.
---
v1 -> v2
- rename to sysconf
--- configure | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
configure +10 -0
@@ -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
Signature · 1 line
1.6.5.2
[Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2)
Quoted 3 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.
Sorry for not being precise; --sysconfdir in Autoconf is just ${prefix}/etc.
Paolo
[Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2)
Quoted 6 lines · Paolo Bonzini
Quoted 3 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.
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
Quoted 1 line
Paolo
[Qemu-devel] Re: [PATCH 1/3] Support --sysconfdir in configure to specify path to configuration files (v2)
Quoted 5 lines
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
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
@@ -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
PATCH 3/3 Load global config files by default (v2)
In reply to Anthony LiguoriA 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.
---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
@@ -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
@@ -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)
Signature · 1 line
1.6.5.2