* [Qemu-devel] [RFC PATCH 0/2] -readconfig: accept fd=<fd> option
@ 2012-03-13 20:53 Eduardo Habkost
2012-03-13 20:53 ` [Qemu-devel] [RFC PATCH 1/2] -readconfig: use QemuOpts option format Eduardo Habkost
2012-03-13 20:53 ` [Qemu-devel] [RFC PATCH 2/2] -readconfig: accept fd=<fd> option Eduardo Habkost
0 siblings, 2 replies; 3+ messages in thread
From: Eduardo Habkost @ 2012-03-13 20:53 UTC (permalink / raw)
To: qemu-devel; +Cc: Ronnie Sahlberg
This changes -readconfig to use the QemuOpts syntax and accept 'fd=<fd>' as
argument, too.
I'm not sure yet if it's OK to break compatibility of -readconfig for filenames
containing "=" or ",". On the one hand I wouldn't like to break it, on the
other hand, I wouldn't like to add Yet Another command-line option and make
-readconfig a legacy option.
Eduardo Habkost (2):
-readconfig: use QemuOpts option format
-readconfig: accept fd=<fd> option
qemu-config.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++---
qemu-config.h | 8 ++++-
qemu-options.hx | 6 ++--
vl.c | 6 ++--
4 files changed, 106 insertions(+), 13 deletions(-)
--
1.7.3.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [RFC PATCH 1/2] -readconfig: use QemuOpts option format
2012-03-13 20:53 [Qemu-devel] [RFC PATCH 0/2] -readconfig: accept fd=<fd> option Eduardo Habkost
@ 2012-03-13 20:53 ` Eduardo Habkost
2012-03-13 20:53 ` [Qemu-devel] [RFC PATCH 2/2] -readconfig: accept fd=<fd> option Eduardo Habkost
1 sibling, 0 replies; 3+ messages in thread
From: Eduardo Habkost @ 2012-03-13 20:53 UTC (permalink / raw)
To: qemu-devel; +Cc: Ronnie Sahlberg
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>
---
qemu-config.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++-----
qemu-config.h | 8 +++++-
qemu-options.hx | 4 +-
vl.c | 6 ++--
4 files changed, 75 insertions(+), 13 deletions(-)
diff --git a/qemu-config.c b/qemu-config.c
index be84a03..6b7b28b 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -816,21 +816,77 @@ out:
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,
+ },
+ { /*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'
+ *
+ * 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);
+}
- ret = qemu_config_parse(f, vm_config_groups, filename);
- fclose(f);
+/* Read Qemu config file based on parsed QemuOpts object
+ *
+ * Returns 0 on success, -errno on failure.
+ */
+static int qemu_read_config_opts(QemuOpts *opts)
+{
+ const char *path = qemu_opt_get(opts, "path");
+ if (!path) {
+ return -EINVAL;
+ }
+ return qemu_read_config_filename(path);
+}
- if (ret == 0) {
- return 0;
- } else {
+/* Read config file based on option arguments on 'arg'
+ *
+ * Returns 0 on success, -errno on failure.
+ */
+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;
}
diff --git a/qemu-config.h b/qemu-config.h
index 20d707f..0e6ac15 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -14,6 +14,12 @@ 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);
+
+/* Read config based on key=value options using QemuOpts syntax
+ */
+int qemu_read_config_arg(const char *arg);
#endif /* QEMU_CONFIG_H */
diff --git a/qemu-options.hx b/qemu-options.hx
index daefce3..caa4fe1 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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
diff --git a/vl.c b/vl.c
index bd95539..c3e60fa 100644
--- a/vl.c
+++ b/vl.c
@@ -2351,12 +2351,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 +3144,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));
--
1.7.3.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [RFC PATCH 2/2] -readconfig: accept fd=<fd> option
2012-03-13 20:53 [Qemu-devel] [RFC PATCH 0/2] -readconfig: accept fd=<fd> option Eduardo Habkost
2012-03-13 20:53 ` [Qemu-devel] [RFC PATCH 1/2] -readconfig: use QemuOpts option format Eduardo Habkost
@ 2012-03-13 20:53 ` Eduardo Habkost
1 sibling, 0 replies; 3+ messages in thread
From: Eduardo Habkost @ 2012-03-13 20:53 UTC (permalink / raw)
To: qemu-devel; +Cc: Ronnie Sahlberg
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
qemu-config.c | 35 +++++++++++++++++++++++++++++++++--
qemu-options.hx | 6 +++---
2 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/qemu-config.c b/qemu-config.c
index 6b7b28b..0a7f42c 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -828,6 +828,10 @@ static QemuOptsList qemu_readconfig_opts = {
.name = "path",
.type = QEMU_OPT_STRING,
},
+ {
+ .name = "fd",
+ .type = QEMU_OPT_NUMBER,
+ },
{ /*End of list */ }
},
};
@@ -863,17 +867,44 @@ 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.
+ */
+static 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);
+}
+
/* 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'
diff --git a/qemu-options.hx b/qemu-options.hx
index caa4fe1..86a5826 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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"
--
1.7.3.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-13 20:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-13 20:53 [Qemu-devel] [RFC PATCH 0/2] -readconfig: accept fd=<fd> option Eduardo Habkost
2012-03-13 20:53 ` [Qemu-devel] [RFC PATCH 1/2] -readconfig: use QemuOpts option format Eduardo Habkost
2012-03-13 20:53 ` [Qemu-devel] [RFC PATCH 2/2] -readconfig: accept fd=<fd> option Eduardo Habkost
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.