From: Corey Bryant <coreyb@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, aliguori@us.ibm.com,
Corey Bryant <coreyb@linux.vnet.ibm.com>,
eblake@redhat.com, stefanha@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 1/3] qmp/hmp: Add QMP getfd command that returns fd
Date: Mon, 4 Jun 2012 09:10:08 -0400 [thread overview]
Message-ID: <1338815410-24890-2-git-send-email-coreyb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1338815410-24890-1-git-send-email-coreyb@linux.vnet.ibm.com>
This patch adds QMP support for the getfd command using the QAPI framework.
Like the HMP getfd command, it is used to pass a file descriptor via
SCM_RIGHTS. However, the QMP getfd command also returns the received file
descriptor, which is a difference in behavior from the HMP getfd command,
which returns nothing.
Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
---
hmp-commands.hx | 2 +-
monitor.c | 37 ++++++++++++++++++++++++++++++++++++-
qapi-schema.json | 13 +++++++++++++
qmp-commands.hx | 6 ++++--
4 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 18cb415..dfab369 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1211,7 +1211,7 @@ ETEXI
.params = "getfd name",
.help = "receive a file descriptor via SCM rights and assign it a name",
.user_print = monitor_user_noop,
- .mhandler.cmd_new = do_getfd,
+ .mhandler.cmd_new = hmp_getfd,
},
STEXI
diff --git a/monitor.c b/monitor.c
index 12a6fe2..6acf5a3 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2199,7 +2199,7 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict)
}
#endif
-static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
+static int hmp_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
const char *fdname = qdict_get_str(qdict, "fdname");
mon_fd_t *monfd;
@@ -2235,6 +2235,41 @@ static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
return 0;
}
+int64_t qmp_getfd(const char *fdname, Error **errp)
+{
+ mon_fd_t *monfd;
+ int fd;
+
+ fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
+ if (fd == -1) {
+ error_set(errp, QERR_FD_NOT_SUPPLIED);
+ return -1;
+ }
+
+ if (qemu_isdigit(fdname[0])) {
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
+ "a name not starting with a digit");
+ return -1;
+ }
+
+ QLIST_FOREACH(monfd, &cur_mon->fds, next) {
+ if (strcmp(monfd->name, fdname) != 0) {
+ continue;
+ }
+
+ close(monfd->fd);
+ monfd->fd = fd;
+ return fd;
+ }
+
+ monfd = g_malloc0(sizeof(mon_fd_t));
+ monfd->name = g_strdup(fdname);
+ monfd->fd = fd;
+
+ QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
+ return fd;
+}
+
static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
const char *fdname = qdict_get_str(qdict, "fdname");
diff --git a/qapi-schema.json b/qapi-schema.json
index 2ca7195..5f26ba2 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1755,3 +1755,16 @@
# Since: 0.14.0
##
{ 'command': 'device_del', 'data': {'id': 'str'} }
+
+##
+# @getfd:
+#
+# Receive a file descriptor via SCM rights and assign it a name
+#
+# @fdname: file descriptor name
+#
+# Returns: The QEMU @fd that was received
+#
+# Since: 1.2
+##
+{ 'command': 'getfd', 'data': {'fdname': 'str'}, 'returns': 'int' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index db980fa..e13d583 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -844,7 +844,7 @@ EQMP
.params = "getfd name",
.help = "receive a file descriptor via SCM rights and assign it a name",
.user_print = monitor_user_noop,
- .mhandler.cmd_new = do_getfd,
+ .mhandler.cmd_new = qmp_marshal_input_getfd,
},
SQMP
@@ -857,10 +857,12 @@ Arguments:
- "fdname": file descriptor name (json-string)
+Return a json-int with the QEMU file descriptor that was received.
+
Example:
-> { "execute": "getfd", "arguments": { "fdname": "fd1" } }
-<- { "return": {} }
+<- { "return": 42 }
EQMP
--
1.7.10.2
next prev parent reply other threads:[~2012-06-04 14:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-04 13:10 [Qemu-devel] [PATCH 0/3] file descriptor passing using getfd over QMP Corey Bryant
2012-06-04 13:10 ` Corey Bryant [this message]
2012-06-04 14:45 ` [Qemu-devel] [PATCH 1/3] qmp/hmp: Add QMP getfd command that returns fd Kevin Wolf
2012-06-04 15:57 ` Corey Bryant
2012-06-05 18:30 ` Luiz Capitulino
2012-06-06 14:04 ` Corey Bryant
2012-06-06 17:50 ` Luiz Capitulino
2012-06-06 19:42 ` Corey Bryant
2012-06-08 10:46 ` Daniel P. Berrange
2012-06-08 13:17 ` Corey Bryant
2012-06-04 13:10 ` [Qemu-devel] [PATCH 2/3] block: Add support to "open" /dev/fd/X filenames Corey Bryant
2012-06-04 14:32 ` Eric Blake
2012-06-04 15:51 ` Corey Bryant
2012-06-04 16:03 ` Eric Blake
2012-06-04 16:28 ` Corey Bryant
2012-06-04 16:36 ` Eric Blake
2012-06-04 16:40 ` Corey Bryant
2012-06-04 14:54 ` Kevin Wolf
2012-06-04 16:07 ` Corey Bryant
2012-06-04 13:10 ` [Qemu-devel] [PATCH 3/3] Sample server that opens image files for QEMU Corey Bryant
2012-06-04 15:01 ` Kevin Wolf
2012-06-04 16:15 ` Corey Bryant
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=1338815410-24890-2-git-send-email-coreyb@linux.vnet.ibm.com \
--to=coreyb@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.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).