From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Subject: [Qemu-devel] [RFC PATCH 2/2] -readconfig: accept fd=<fd> option
Date: Tue, 13 Mar 2012 17:53:25 -0300 [thread overview]
Message-ID: <1331672005-30798-3-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1331672005-30798-1-git-send-email-ehabkost@redhat.com>
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
prev parent reply other threads:[~2012-03-13 20:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1331672005-30798-3-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=ronniesahlberg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).