Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 09, 2012
@ehabkost ehabkost -readconfig: use QemuOpts option format
This 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.

Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
bd52187
Showing with 85 additions and 14 deletions.
  1. +77 −7 qemu-config.c
  2. +2 −1 qemu-config.h
  3. +3 −3 qemu-options.hx
  4. +3 −3 vl.c
View
84 qemu-config.c
@@ -816,21 +816,91 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
return res;
}
-int qemu_read_config_file(const char *filename)
+/* 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.
+ */
+static QemuOptsList qemu_readconfig_opts = {
+ .name = "readconfig-opts",
+ .implied_opt_name = "path",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_readconfig_opts.head),
+ .desc = {
+ {
+ .name = "path",
+ .type = QEMU_OPT_STRING,
+ },
+ {
+ .name = "fd",
+ .type = QEMU_OPT_NUMBER,
+ },
+ { /*End of list */ }
+ },
+};
+
+/** 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 (qemu_config_parse(f, vm_config_groups, filename) == 0) {
+ ret = 0;
+ } else {
+ ret = -EINVAL;
+ }
+ fclose(f);
+ return ret;
+}
+/** Read Qemu config file from 'filename'
+ */
+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);
+}
- ret = qemu_config_parse(f, vm_config_groups, filename);
- fclose(f);
-
- if (ret == 0) {
- return 0;
+/** Read Qemu config file based on parsed QemuOpts object
+ */
+static int qemu_read_config_opts(QemuOpts *opts)
+{
+ FILE *f;
+ const char *fname;
+ const char *path = qemu_opt_get(opts, "path");
+ uint64_t fd = qemu_opt_get_number(opts, "fd", (uint64_t)-1);
+
+ if (path) {
+ f = fopen(path, "r");
+ fname = path;
+ } else if (fd != (uint64_t)-1) {
+ f = fdopen(fd, "r");
+ fname = "<fd>";
} else {
+ error_report("no fd or path set for config file");
+ return -EINVAL;
+ }
+
+ if (!f) {
+ return -errno;
+ }
+
+ return qemu_read_config_file(f, fname);
+}
+
+/** Read config file based on option arguments on 'arg'
+ */
+int qemu_read_config_arg(const char *arg)
+{
+ QemuOpts *opts = qemu_opts_parse(&qemu_readconfig_opts, arg, 1);
+ if (!opts) {
return -EINVAL;
}
+ int r = qemu_read_config_opts(opts);
+ qemu_opts_del(opts);
+ return r;
}
View
3 qemu-config.h
@@ -14,6 +14,7 @@ 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);
+int qemu_read_config_filename(const char *filename);
+int qemu_read_config_arg(const char *arg);
#endif /* QEMU_CONFIG_H */
View
6 qemu-options.hx
@@ -2655,11 +2655,11 @@ Old param mode (ARM only).
ETEXI
DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig,
- "-readconfig <file>\n", QEMU_ARCH_ALL)
+ "-readconfig [path=]<file>|fd=<fd>\n", QEMU_ARCH_ALL)
STEXI
-@item -readconfig @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"
View
6 vl.c
@@ -2349,12 +2349,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);
}
@@ -3148,7 +3148,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));

No commit comments for this range

Something went wrong with that request. Please try again.