-readconfig: accept fd=<fd> option (v2)
cover -readconfig: accept fd=<fd> option (v2)
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Changes v1 -> v2:
- Moved some code to qemu-config-arch.c, as it will eventually have arch-specific features
Eduardo Habkost (3):
qemu-config.h: include qemu-option.h
-readconfig: use QemuOpts option format (v2)
-readconfig: accept fd=<fd> option (v2)
Makefile.target | 2 +- qemu-config-arch.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-config-arch.h | 15 +++++++++ qemu-config.c | 46 ++++++++++++++++++++++----- qemu-config.h | 10 +++++- qemu-options.hx | 6 ++-- vl.c | 7 ++-- 7 files changed, 155 insertions(+), 17 deletions(-) create mode 100644 qemu-config-arch.c create mode 100644 qemu-config-arch.h
Signature · 1 line
1.7.3.2
PATCH 1/3 qemu-config.h: include qemu-option.h
It uses QemuOptList, so it needs qemu-option.h to be included.
--- qemu-config.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
qemu-config.h +2 -0
@@ -1,6 +1,8 @@#ifndef QEMU_CONFIG_H #define QEMU_CONFIG_H +#include "qemu-option.h" +extern QemuOptsList qemu_fsdev_opts;extern QemuOptsList qemu_virtfs_opts;extern QemuOptsList qemu_spice_opts;
Signature · 1 line
1.7.3.2
PATCH 2/3 -readconfig: use QemuOpts option format (v2)
In reply to Eduardo HabkostThis changes -readconfig to use the name=value[,name=value] option format.
It keeps "-readconfig filename" working by using the implied "path" option name, but it changes the existing syntax a little, meaning that files with "=" and "," in the filename have to be escaped.
I chose to break compatibility in those cases, instead of adding a new option and keeping -readconfig as a legacy option. If you think adding a new option is better, please let me know.
Most of the code is being added to qemu-config-arch.c because the command-line handling of -readconfig will eventually depend on arch-specific stuff, such as the list of default config files, and qemu-config.o is not arch-specific.
Changes v1 -> v2:
- Create qemu-config-arch.c for the readconfig-specific code that will depend on arch-specific stuff
--- Makefile.target | 2 +- qemu-config-arch.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-config-arch.h | 15 +++++++++++ qemu-config.c | 34 +++++++++++++++++-------- qemu-config.h | 4 ++- qemu-options.hx | 4 +- vl.c | 7 +++-- 7 files changed, 117 insertions(+), 18 deletions(-) create mode 100644 qemu-config-arch.c create mode 100644 qemu-config-arch.h
Makefile.target +1 -1
@@ -204,7 +204,7 @@ endif #CONFIG_BSD_USER # System emulator target ifdef CONFIG_SOFTMMU -obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o +obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o qemu-config-arch.o # virtio has to be here due to weird dependency between PCI and virtio-net. # need to fix this properly obj-$(CONFIG_NO_PCI) += pci-stub.o
qemu-config-arch.c new file +69 -0
69 lines not on this page · raw message
qemu-config-arch.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef QEMU_CONFIG_ARCH_H +#define QEMU_CONFIG_ARCH_H +/* Arch-specific qemu config code +* +* Contains functions that depend on arch-specific variables and settings, +* such as the handling of -readconfig help options. +*/ + +#include "qemu-config.h" + +/* Read config based on key=value options using QemuOpts syntax +*/ +int qemu_read_config_arg (const char *arg); + +#endif /* QEMU_CONFIG_ARCH_H */
qemu-config.c +23 -11
@@ -816,21 +816,33 @@ out:return res; } -int qemu_read_config_file (const char *filename) +/* Read Qemu config file from open file +* +* The file will be closed before returning. +* +* Returns 0 on success, -errno on failure. +*/ +static int qemu_read_config_file (FILE *f,const char *filename) { -FILE *f =fopen (filename,"r" );int ret; - -if (f ==NULL ) { -return -errno; +if (qemu_config_parse (f, vm_config_groups, filename) ==0 ) { + ret =0 ; + }else { + ret = -EINVAL ; } - - ret =qemu_config_parse (f, vm_config_groups, filename);fclose (f); +return ret; +} -if (ret ==0 ) { -return 0 ; - }else { -return -EINVAL ; +/* Read Qemu config file from 'filename' +* +* Returns 0 on success, -errno on failure. +*/ +int qemu_read_config_filename (const char *filename) +{ +FILE *f =fopen (filename,"r" ); +if (f ==NULL ) { +return -errno; } +return qemu_read_config_file (f, filename); }
qemu-config.h +3 -1
@@ -16,6 +16,8 @@ void qemu_add_globals(void);void qemu_config_write (FILE *fp);int qemu_config_parse (FILE *fp,QemuOptsList **lists,const char *fname); -int qemu_read_config_file (const char *filename); +/* Read config from filename +*/ +int qemu_read_config_filename (const char *filename);#endif /* QEMU_CONFIG_H */
qemu-options.hx +2 -2
@@ -2655,9 +2655,9 @@ Old param mode (ARM only). ETEXI DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, - "-readconfig <file>\n", QEMU_ARCH_ALL) + "-readconfig [path=]<file>\n", QEMU_ARCH_ALL) STEXI -@item -readconfig @var{file} +@item -readconfig [type=]@var{file} @findex -readconfig Read device configuration from @var{file}. ETEXI
vl.c +4 -3
@@ -146,6 +146,7 @@ int main(int argc, char **argv)#include "qjson.h" #include "qemu-option.h" #include "qemu-config.h" +#include "qemu-config-arch.h" #include "qemu-options.h" #include "qmp-commands.h" #include "main-loop.h"
@@ -2351,12 +2352,12 @@ int main(int argc, char **argv, char **envp)if (defconfig) {int ret; - ret =qemu_read_config_file (CONFIG_QEMU_CONFDIR "/qemu.conf" ); + ret =qemu_read_config_filename (CONFIG_QEMU_CONFDIR "/qemu.conf" );if (ret <0 && ret != -ENOENT ) {exit (1 ); } - ret =qemu_read_config_file (arch_config_name); + ret =qemu_read_config_filename (arch_config_name);if (ret <0 && ret != -ENOENT ) {exit (1 ); }
@@ -3144,7 +3145,7 @@ int main(int argc, char **argv, char **envp) }case QEMU_OPTION_readconfig: { -int ret =qemu_read_config_file (optarg); +int ret =qemu_read_config_arg (optarg);if (ret <0 ) {fprintf (stderr,"read config %s: %s\n" , optarg,strerror (-ret));
Signature · 1 line
1.7.3.2
PATCH 3/3 -readconfig: accept fd=<fd> option (v2)
In reply to Eduardo HabkostChhanges v1 -> v2:
- Moved code to qemu-config-arch.c
--- qemu-config-arch.c | 21 +++++++++++++++++++-- qemu-config.c | 16 ++++++++++++++++ qemu-config.h | 4 ++++ qemu-options.hx | 6 +++--- 4 files changed, 42 insertions(+), 5 deletions(-)
qemu-config-arch.c +19 -2
@@ -23,6 +23,7 @@*/ #include "qemu-config-arch.h" #include "qemu-option.h" +#include "qemu-error.h" /* Not on vm_config_groups because this is not a global option setable by -set * (QEMU_OPTION_set), just settings used to parse -readconfig argument.
@@ -36,21 +37,37 @@ static QemuOptsList qemu_readconfig_opts = { .name = "path", .type = QEMU_OPT_STRING, }, + { + .name = "fd", + .type = QEMU_OPT_NUMBER, + }, {/*End of list */ } }, }; +/* Read Qemu config file based on parsed QemuOpts object * * Returns 0 on success, -errno on failure. */ static int qemu_read_config_opts (QemuOpts *opts) { +int fd =-1 ; +uint64_t fd_arg =qemu_opt_get_number (opts,"fd" , (uint64_t )-1 );const char *path =qemu_opt_get (opts,"path" ); -if (!path) { + +if (fd_arg != (uint64_t )-1 ) { + fd = fd_arg; + } + +if (path) { +return qemu_read_config_filename (path); + }else if (fd >=0 ) { +return qemu_read_config_fd (fd); + }else { +error_report ("no fd or path set for config file" );return -EINVAL ; } -return qemu_read_config_filename (path); }/* Read config file based on option arguments on 'arg'
qemu-config.c +16 -0
@@ -846,3 +846,19 @@ int qemu_read_config_filename(const char *filename) }return qemu_read_config_file (f, filename); } + +/* Read Qemu config file from file descriptor +* +* Returns 0 on success, -errno on failure. +*/ +int qemu_read_config_fd (int fd) +{ +/* For the "<fd:%d>" pseudo-filename, used only for error messages */ +char fname[16 ]; +FILE *f =fdopen (fd,"r" ); +if (f ==NULL ) { +return -errno; + } +snprintf (fname,sizeof (fname),"<fd:%d>" , fd); +return qemu_read_config_file (f, fname); +}
qemu-config.h +4 -0
@@ -20,4 +20,8 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname);*/ int qemu_read_config_filename (const char *filename); +/* Read config from file descriptor +*/ +int qemu_read_config_fd (int fd); +#endif /* QEMU_CONFIG_H */
qemu-options.hx +3 -3
@@ -2655,11 +2655,11 @@ Old param mode (ARM only). ETEXI DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, - "-readconfig [path=]<file>\n", QEMU_ARCH_ALL) + "-readconfig [path=]<file>|fd=<fd>\n", QEMU_ARCH_ALL) STEXI -@item -readconfig [type=]@var{file} +@item -readconfig [path=]@var{file}|fd=@var{fd} @findex -readconfig -Read device configuration from @var{file}. +Read device configuration from @var{file}, or from file descriptor @var{fd}. ETEXI DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, "-writeconfig <file>\n"
Signature · 1 line
1.7.3.2
Quoted 6 lines · Eduardo Habkost
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Why not just use /dev/fd/N ?
Regards,
Anthony Liguori
Quoted 21 lines
Changes v1 -> v2:
- Moved some code toqemu-config-arch.c, as it will eventually have arch-specific featuresEduardo Habkost (3):
qemu-config.h: includeqemu-option.h
-readconfig: use QemuOpts option format (v2)
-readconfig: accept fd=<fd> option (v2)Makefile.target | 2 +- qemu-config-arch.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-config-arch.h | 15 +++++++++ qemu-config.c | 46 ++++++++++++++++++++++----- qemu-config.h | 10 +++++- qemu-options.hx | 6 ++-- vl.c | 7 ++-- 7 files changed, 155 insertions(+), 17 deletions(-)create mode 100644
qemu-config-arch.c
create mode 100644qemu-config-arch.h
Quoted 9 lines · Anthony Liguori
Quoted 6 lines · Eduardo Habkost
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Why not just use
/dev/fd/N?
Personally, I don't like filenames with special meanings (as not every OS has /dev/fd we would have to treat them specially), or filenames that become non-extensible mini-languages by themselves. Many other command-line options use the key=value syntax, and some already have an "fd" option, so this just follows the convention.
Also, this is more extensible to allow more options to be added to -readconfig if needed (for example: debugging options, or the help=defconfig option I added on the RFC series I sent after this one).
Signature · 1 line
Eduardo
Quoted 9 lines · Eduardo Habkost
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Eduardo Habkost
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Quoted 7 lines
Quoted 1 line
Why not just use
/dev/fd/N?Personally, I don't like filenames with special meanings (as not every OS has
/dev/fdwe would have to treat them specially), or filenames that become non-extensible mini-languages by themselves. Many other command-line options use the key=value syntax, and some already have an "fd" option, so this just follows the convention.
But you're also breaking compat, which is not something to be done lightly.
Quoted 4 lines
Also, this is more extensible to allow more options to be added to -readconfig if needed (for example: debugging options, or the help=defconfig option I added on the RFC series I sent after this one).
I'd personally prefer to keep readconfig simple. See the series I sent out as an RFC.
Regards,
Anthony Liguori
Quoted 1 line
Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Eduardo Habkost
Quoted 9 lines · Anthony Liguori
Quoted 6 lines · Eduardo Habkost
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Why not just use
/dev/fd/N?
Quoted 7 lines
Quoted 5 lines
Personally, I don't like filenames with special meanings (as not every OS has
/dev/fdwe would have to treat them specially), or filenames that become non-extensible mini-languages by themselves. Many other command-line options use the key=value syntax, and some already have an "fd" option, so this just follows the convention.But you're also breaking compat, which is not something to be done lightly.
True. In that case, I propose adding a "-config" option that is more extensible than the current one, instead of defining a new mini-language for -readconfig that looks like a file path but has hidden complexities behind it.
Quoted 6 lines
Quoted 3 lines
Also, this is more extensible to allow more options to be added to -readconfig if needed (for example: debugging options, or the help=defconfig option I added on the RFC series I sent after this one).
I'd personally prefer to keep readconfig simple. See the series I sent out as an RFC.
If you are supporting FDs, the complexity is already there. Using the key=value format just makes the complexity explicit (and familiar, for humans and code that already uses key=value for other options) instead of hiding it behind magic filenames.
I still have to take a look at your series.
Signature · 1 line
Eduardo
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Anthony Liguori
Quoted 16 lines · Eduardo Habkost
Quoted 9 lines · Anthony Liguori
Quoted 6 lines · Eduardo Habkost
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Why not just use
/dev/fd/N?Personally, I don't like filenames with special meanings (as not every OS has
/dev/fdwe would have to treat them specially), or filenames that become non-extensible mini-languages by themselves. Many other command-line options use the key=value syntax, and some already have an "fd" option, so this just follows the convention.
Quoted 6 lines
Quoted 1 line
But you're also breaking compat, which is not something to be done lightly.
True. In that case, I propose adding a "-config" option that is more extensible than the current one, instead of defining a new mini-language for -readconfig that looks like a file path but has hidden complexities behind it.
What? /dev/fd is a pretty standard unix feature. It'll work today with existing versions of QEMU.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Also, this is more extensible to allow more options to be added to -readconfig if needed (for example: debugging options, or the help=defconfig option I added on the RFC series I sent after this one).
I'd personally prefer to keep readconfig simple. See the series I sent out as an RFC.
Quoted 6 lines
If you are supporting FDs, the complexity is already there. Using the key=value format just makes the complexity explicit (and familiar, for humans and code that already uses key=value for other options) instead of hiding it behind magic filenames.
I still have to take a look at your series.
I think there are cases where /dev/fd doesn't make any sense as an interface (like tun/tap) because tun/tap doesn't have normal file semantics.
Likewise, block devices don't act like normal files so you need to treat fd differently than you treat a file path.
But for something like the BIOS file, config files, kernels, etc, they are all just simple files and instead of making everything take a fd:, we can (and should) just use the existing unix mechanism for this.
Regards,
Anthony Liguori
Quoted 22 lines · Anthony Liguori
Quoted 21 lines · Eduardo Habkost
Quoted 19 lines · Anthony Liguori
Quoted 9 lines · Eduardo Habkost
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Eduardo Habkost
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Quoted 7 lines
Quoted 1 line
Why not just use
/dev/fd/N?Personally, I don't like filenames with special meanings (as not every OS has
/dev/fdwe would have to treat them specially), or filenames that become non-extensible mini-languages by themselves. Many other command-line options use the key=value syntax, and some already have an "fd" option, so this just follows the convention.But you're also breaking compat, which is not something to be done lightly.
Quoted 7 lines
Quoted 4 lines
True. In that case, I propose adding a "-config" option that is more extensible than the current one, instead of defining a new mini-language for -readconfig that looks like a file path but has hidden complexities behind it.
What?
/dev/fdis a pretty standard unix feature. It'll work today with existing versions of QEMU.
When I replied, I was thinking of this proposal:
http://marc.info/?l=qemu-devel&m=133076148831720
If you are proposing having zero special-case code to Qemu because of /dev/fd, it's OK to me.
Quoted 18 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Also, this is more extensible to allow more options to be added to -readconfig if needed (for example: debugging options, or the help=defconfig option I added on the RFC series I sent after this one).
I'd personally prefer to keep readconfig simple. See the series I sent out as an RFC.
Quoted 6 lines
If you are supporting FDs, the complexity is already there. Using the key=value format just makes the complexity explicit (and familiar, for humans and code that already uses key=value for other options) instead of hiding it behind magic filenames.
I still have to take a look at your series.
I think there are cases where
/dev/fddoesn't make any sense as an interface (like tun/tap) because tun/tap doesn't have normal file semantics.
Quoted 7 lines
Likewise, block devices don't act like normal files so you need to treat fd differently than you treat a file path.
But for something like the BIOS file, config files, kernels, etc, they are all just simple files and instead of making everything take a fd:, we can (and should) just use the existing unix mechanism for this.
OK to me, if that doesn't require code to handle "/dev/fd/" as special inside Qemu, but just use what the OS provides. I am just against making magic filenames special.
I was still considering adding a key=value interface for -readconfig (or an equivalent -config parameter) because of the debugging and probing options I would like to add, but those options could be enabled/disabled somewhere else, so there wouldn't be a strong reason for it anymore.
On the other hand, I:
- Would like to let the user (a human) list where are the default config files being used by Qemu;
- Don't want to add Yet Another "-option ?" parameter to Qemu (e.g. "-readconfig ?").
Do you have any suggestions for that?
Signature · 1 line
Eduardo
Quoted 71 lines · Eduardo Habkost
Quoted 22 lines · Anthony Liguori
Quoted 21 lines · Eduardo Habkost
Quoted 19 lines · Anthony Liguori
Quoted 9 lines · Eduardo Habkost
Quoted 8 lines · Anthony Liguori
Quoted 6 lines · Eduardo Habkost
This is a resubmit of a previous series I sent as a RFC, with some changes to prepare for an upcoming patch that will make additional changes to the default config-file loading code.
This series needs be applied on top of the "./configure --confdir" series I sent today.
Quoted 7 lines
Quoted 1 line
Why not just use
/dev/fd/N?Personally, I don't like filenames with special meanings (as not every OS has
/dev/fdwe would have to treat them specially), or filenames that become non-extensible mini-languages by themselves. Many other command-line options use the key=value syntax, and some already have an "fd" option, so this just follows the convention.But you're also breaking compat, which is not something to be done lightly.
Quoted 7 lines
Quoted 4 lines
True. In that case, I propose adding a "-config" option that is more extensible than the current one, instead of defining a new mini-language for -readconfig that looks like a file path but has hidden complexities behind it.
What?
/dev/fdis a pretty standard unix feature. It'll work today with existing versions of QEMU.When I replied, I was thinking of this proposal:
http://marc.info/?l=qemu-devel&m=133076148831720
If you are proposing having zero special-case code to Qemu because of/dev/fd, it's OK to me.Quoted 18 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Also, this is more extensible to allow more options to be added to -readconfig if needed (for example: debugging options, or the help=defconfig option I added on the RFC series I sent after this one).
I'd personally prefer to keep readconfig simple. See the series I sent out as an RFC.
Quoted 6 lines
If you are supporting FDs, the complexity is already there. Using the key=value format just makes the complexity explicit (and familiar, for humans and code that already uses key=value for other options) instead of hiding it behind magic filenames.
I still have to take a look at your series.
I think there are cases where
/dev/fddoesn't make any sense as an interface (like tun/tap) because tun/tap doesn't have normal file semantics.Quoted 7 lines
Likewise, block devices don't act like normal files so you need to treat fd differently than you treat a file path.
But for something like the BIOS file, config files, kernels, etc, they are all just simple files and instead of making everything take a fd:, we can (and should) just use the existing unix mechanism for this.
OK to me, if that doesn't require code to handle "
/dev/fd/" as special inside Qemu, but just use what the OS provides. I am just against making magic filenames special.I was still considering adding a key=value interface for -readconfig (or an equivalent -config parameter) because of the debugging and probing options I would like to add, but those options could be enabled/disabled somewhere else, so there wouldn't be a strong reason for it anymore.
Quoted 4 lines
On the other hand, I:
- Would like to let the user (a human) list where are the default config files being used by Qemu;
This should be provided via a QMP command and as part of -query-capabilities (see previous series).
Regards,
Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 4 lines
On the other hand, I:
- Would like to let the user (a human) list where are the default config files being used by Qemu;
This should be provided via a QMP command and as part of -query-capabilities (see previous series).
Is this usable by a human?
Signature · 1 line
Eduardo
Quoted 10 lines · Eduardo Habkost
Quoted 7 lines · Anthony Liguori
Quoted 4 lines
On the other hand, I:
- Would like to let the user (a human) list where are the default config files being used by Qemu;
This should be provided via a QMP command and as part of -query-capabilities (see previous series).
Is this usable by a human?
It surely is for the users that would care about this.
Normally, this stuff is printed in either --help or --version FWIW. But we can't touch either because of libvirt (hence my other series). So if we fix that problem, we can provide a nicer --help/--version output that has this information.
Regards,
Anthony Liguori