From: Luiz Capitulino <lcapitulino@redhat.com>
To: Corey Bryant <coreyb@linux.vnet.ibm.com>
Cc: kwolf@redhat.com, aliguori@us.ibm.com,
stefanha@linux.vnet.ibm.com, libvir-list@redhat.com,
qemu-devel@nongnu.org, pbonzini@redhat.com, eblake@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4 2/7] qapi: Convert getfd and closefd
Date: Wed, 11 Jul 2012 15:51:54 -0300 [thread overview]
Message-ID: <20120711155154.6bbacfb0@doriath.home> (raw)
In-Reply-To: <1340390174-7493-3-git-send-email-coreyb@linux.vnet.ibm.com>
On Fri, 22 Jun 2012 14:36:09 -0400
Corey Bryant <coreyb@linux.vnet.ibm.com> wrote:
> Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
I've cherry-picked this one into the qmp tree.
> ---
> v2:
> -Convert getfd and closefd to QAPI (lcapitulino@redhat.com)
> -Remove changes that returned fd from getfd (lcapitulino@redhat.com)
> -Wrap hmp_* functions around qmp_* functions (kwolf@redhat.com)
> -Move hmp_* functions to hmp.c (lcapitulino@redhat.com)
> -Drop .user_print lines (lcapitulino@redhat.com)
> -Use 'cmd' instead of 'cmd_new' for HMP (lcapitulino@redhat.com)
> -Change QMP command existance back to 0.14 (lcapitulino@redhat.com)
>
> v3:
> -Remove unnecessary return statements from qmp_* functions
> (lcapitulino@redhat.com)
> -Add notes to QMP command describing behavior in more detail
> (lcapitulino@redhat.com, eblake@redhat.com)
>
> v4:
> -No changes
>
> hmp-commands.hx | 6 ++----
> hmp.c | 18 ++++++++++++++++++
> hmp.h | 2 ++
> monitor.c | 32 ++++++++++++++------------------
> qapi-schema.json | 35 +++++++++++++++++++++++++++++++++++
> qmp-commands.hx | 14 ++++++++++----
> 6 files changed, 81 insertions(+), 26 deletions(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index f5d9d91..eea8b32 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1236,8 +1236,7 @@ ETEXI
> .args_type = "fdname:s",
> .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 = hmp_getfd,
> },
>
> STEXI
> @@ -1253,8 +1252,7 @@ ETEXI
> .args_type = "fdname:s",
> .params = "closefd name",
> .help = "close a file descriptor previously passed via SCM rights",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_closefd,
> + .mhandler.cmd = hmp_closefd,
> },
>
> STEXI
> diff --git a/hmp.c b/hmp.c
> index 2ce8cb9..6241856 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -999,3 +999,21 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
> qmp_netdev_del(id, &err);
> hmp_handle_error(mon, &err);
> }
> +
> +void hmp_getfd(Monitor *mon, const QDict *qdict)
> +{
> + const char *fdname = qdict_get_str(qdict, "fdname");
> + Error *errp = NULL;
> +
> + qmp_getfd(fdname, &errp);
> + hmp_handle_error(mon, &errp);
> +}
> +
> +void hmp_closefd(Monitor *mon, const QDict *qdict)
> +{
> + const char *fdname = qdict_get_str(qdict, "fdname");
> + Error *errp = NULL;
> +
> + qmp_closefd(fdname, &errp);
> + hmp_handle_error(mon, &errp);
> +}
> diff --git a/hmp.h b/hmp.h
> index 79d138d..8d2b0d7 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -64,5 +64,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict);
> void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
> void hmp_netdev_add(Monitor *mon, const QDict *qdict);
> void hmp_netdev_del(Monitor *mon, const QDict *qdict);
> +void hmp_getfd(Monitor *mon, const QDict *qdict);
> +void hmp_closefd(Monitor *mon, const QDict *qdict);
>
> #endif
> diff --git a/monitor.c b/monitor.c
> index a3bc2c7..1a7f7e7 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2182,48 +2182,45 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict)
> }
> #endif
>
> -static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_getfd(const char *fdname, Error **errp)
> {
> - const char *fdname = qdict_get_str(qdict, "fdname");
> mon_fd_t *monfd;
> int fd;
>
> - fd = qemu_chr_fe_get_msgfd(mon->chr);
> + fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
> if (fd == -1) {
> - qerror_report(QERR_FD_NOT_SUPPLIED);
> - return -1;
> + error_set(errp, QERR_FD_NOT_SUPPLIED);
> + return;
> }
>
> if (qemu_isdigit(fdname[0])) {
> - qerror_report(QERR_INVALID_PARAMETER_VALUE, "fdname",
> - "a name not starting with a digit");
> - return -1;
> + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
> + "a name not starting with a digit");
> + return;
> }
>
> - QLIST_FOREACH(monfd, &mon->fds, next) {
> + QLIST_FOREACH(monfd, &cur_mon->fds, next) {
> if (strcmp(monfd->name, fdname) != 0) {
> continue;
> }
>
> close(monfd->fd);
> monfd->fd = fd;
> - return 0;
> + return;
> }
>
> monfd = g_malloc0(sizeof(mon_fd_t));
> monfd->name = g_strdup(fdname);
> monfd->fd = fd;
>
> - QLIST_INSERT_HEAD(&mon->fds, monfd, next);
> - return 0;
> + QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
> }
>
> -static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_closefd(const char *fdname, Error **errp)
> {
> - const char *fdname = qdict_get_str(qdict, "fdname");
> mon_fd_t *monfd;
>
> - QLIST_FOREACH(monfd, &mon->fds, next) {
> + QLIST_FOREACH(monfd, &cur_mon->fds, next) {
> if (strcmp(monfd->name, fdname) != 0) {
> continue;
> }
> @@ -2232,11 +2229,10 @@ static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> close(monfd->fd);
> g_free(monfd->name);
> g_free(monfd);
> - return 0;
> + return;
> }
>
> - qerror_report(QERR_FD_NOT_FOUND, fdname);
> - return -1;
> + error_set(errp, QERR_FD_NOT_FOUND, fdname);
> }
>
> static void do_loadvm(Monitor *mon, const QDict *qdict)
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3b6e346..26a6b84 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -1862,3 +1862,38 @@
> # Since: 0.14.0
> ##
> { 'command': 'netdev_del', 'data': {'id': 'str'} }
> +
> +##
> +# @getfd:
> +#
> +# Receive a file descriptor via SCM rights and assign it a name
> +#
> +# @fdname: file descriptor name
> +#
> +# Returns: Nothing on success
> +# If file descriptor was not received, FdNotSupplied
> +# If @fdname is not valid, InvalidParameterType
> +#
> +# Since: 0.14.0
> +#
> +# Notes: If @fdname already exists, the file descriptor assigned to
> +# it will be closed and replaced by the received file
> +# descriptor.
> +# The 'closefd' command can be used to explicitly close the
> +# file descriptor when it is no longer needed.
> +##
> +{ 'command': 'getfd', 'data': {'fdname': 'str'} }
> +
> +##
> +# @closefd:
> +#
> +# Close a file descriptor previously passed via SCM rights
> +#
> +# @fdname: file descriptor name
> +#
> +# Returns: Nothing on success
> +# If @fdname is not found, FdNotFound
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'closefd', 'data': {'fdname': 'str'} }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 2e1a38e..e3cf3c5 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -873,8 +873,7 @@ EQMP
> .args_type = "fdname:s",
> .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
> @@ -892,6 +891,14 @@ Example:
> -> { "execute": "getfd", "arguments": { "fdname": "fd1" } }
> <- { "return": {} }
>
> +Notes:
> +
> +(1) If the name specified by the "fdname" argument already exists,
> + the file descriptor assigned to it will be closed and replaced
> + by the received file descriptor.
> +(2) The 'closefd' command can be used to explicitly close the file
> + descriptor when it is no longer needed.
> +
> EQMP
>
> {
> @@ -899,8 +906,7 @@ EQMP
> .args_type = "fdname:s",
> .params = "closefd name",
> .help = "close a file descriptor previously passed via SCM rights",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = do_closefd,
> + .mhandler.cmd_new = qmp_marshal_input_closefd,
> },
>
> SQMP
next prev parent reply other threads:[~2012-07-11 18:52 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-22 18:36 [Qemu-devel] [PATCH v4 0/7] file descriptor passing using pass-fd Corey Bryant
2012-06-22 18:36 ` [Qemu-devel] [PATCH v4 1/7] qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg Corey Bryant
2012-06-22 19:31 ` Eric Blake
2012-06-22 18:36 ` [Qemu-devel] [PATCH v4 2/7] qapi: Convert getfd and closefd Corey Bryant
2012-07-11 18:51 ` Luiz Capitulino [this message]
2012-06-22 18:36 ` [Qemu-devel] [PATCH v4 3/7] qapi: Add pass-fd QMP command Corey Bryant
2012-06-22 20:24 ` Eric Blake
2012-06-22 18:36 ` [Qemu-devel] [PATCH v4 4/7] qapi: Re-arrange monitor.c functions Corey Bryant
2012-06-22 18:36 ` [Qemu-devel] [PATCH v4 5/7] block: Prevent /dev/fd/X filename from being detected as floppy Corey Bryant
2012-06-22 18:36 ` [Qemu-devel] [PATCH v4 6/7] block: Convert open calls to qemu_open Corey Bryant
2012-06-22 18:36 ` [Qemu-devel] [PATCH v4 7/7] osdep: Enable qemu_open to dup pre-opened fd Corey Bryant
2012-06-22 19:58 ` Eric Blake
[not found] ` <20120626091004.GA14451@redhat.com>
[not found] ` <4FE9A0F0.2050809@redhat.com>
[not found] ` <20120626175045.2c7011b3@doriath.home>
[not found] ` <4FEA37A9.10707@linux.vnet.ibm.com>
[not found] ` <4FEA3D9C.8080205@redhat.com>
2012-07-02 22:02 ` [Qemu-devel] [PATCH v4 0/7] file descriptor passing using pass-fd Corey Bryant
2012-07-02 22:31 ` Eric Blake
2012-07-03 9:07 ` Daniel P. Berrange
2012-07-03 9:40 ` Kevin Wolf
2012-07-03 13:42 ` Corey Bryant
2012-07-03 15:40 ` Corey Bryant
2012-07-03 15:59 ` Kevin Wolf
2012-07-03 16:25 ` Corey Bryant
2012-07-03 17:03 ` Eric Blake
2012-07-03 17:46 ` Corey Bryant
2012-07-03 18:00 ` Eric Blake
2012-07-03 18:21 ` Corey Bryant
2012-07-04 8:09 ` Kevin Wolf
2012-07-05 15:06 ` Corey Bryant
2012-07-09 14:05 ` Luiz Capitulino
2012-07-09 15:05 ` Corey Bryant
2012-07-09 15:46 ` Kevin Wolf
2012-07-09 16:18 ` Luiz Capitulino
2012-07-09 17:59 ` Corey Bryant
2012-07-09 17:35 ` Corey Bryant
2012-07-09 17:48 ` Luiz Capitulino
2012-07-09 18:02 ` Corey Bryant
2012-07-10 7:53 ` Kevin Wolf
2012-07-09 18:20 ` Corey Bryant
2012-07-04 8:00 ` Kevin Wolf
2012-07-05 14:22 ` Corey Bryant
2012-07-05 14:51 ` Kevin Wolf
2012-07-05 16:35 ` Corey Bryant
2012-07-05 16:37 ` Corey Bryant
2012-07-06 9:06 ` Kevin Wolf
2012-07-05 17:00 ` Eric Blake
2012-07-05 17:36 ` Corey Bryant
2012-07-06 9:11 ` Kevin Wolf
2012-07-06 17:14 ` Corey Bryant
2012-07-06 17:15 ` Corey Bryant
2012-07-06 17:40 ` Corey Bryant
2012-07-06 18:19 ` [Qemu-devel] [libvirt] " Corey Bryant
2012-07-09 14:04 ` [Qemu-devel] " Kevin Wolf
2012-07-09 15:23 ` Corey Bryant
2012-07-09 15:30 ` Kevin Wolf
2012-07-09 18:40 ` Anthony Liguori
2012-07-09 19:00 ` Luiz Capitulino
2012-07-10 8:54 ` Daniel P. Berrange
2012-07-10 7:58 ` Kevin Wolf
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=20120711155154.6bbacfb0@doriath.home \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=coreyb@linux.vnet.ibm.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=libvir-list@redhat.com \
--cc=pbonzini@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).