From: Markus Armbruster <armbru@redhat.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: pbonzini@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/3] qapi: convert add_client
Date: Tue, 25 Sep 2012 13:29:32 +0200 [thread overview]
Message-ID: <87fw661gtf.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1348523754-6897-4-git-send-email-lcapitulino@redhat.com> (Luiz Capitulino's message of "Mon, 24 Sep 2012 18:55:54 -0300")
Luiz Capitulino <lcapitulino@redhat.com> writes:
> Also fixes a few issues while there:
>
> 1. The fd returned by monitor_get_fd() leaks in most error conditions
> 2. monitor_get_fd() return value is not checked. Best case we get
> an error that is not correctly reported, worse case one of the
> functions using the fd (with value of -1) will explode
> 3. A few error conditions aren't reported
4. We now "use up" @fdname always. Before, it was left alone for
invalid @protocol.
>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
> monitor.c | 39 ---------------------------------------
> qapi-schema.json | 23 +++++++++++++++++++++++
> qmp-commands.hx | 5 +----
> qmp.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 67 insertions(+), 43 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index 645f8f4..e18df38 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -944,45 +944,6 @@ static void do_trace_print_events(Monitor *mon)
> trace_print_events((FILE *)mon, &monitor_fprintf);
> }
>
> -static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_data)
> -{
> - const char *protocol = qdict_get_str(qdict, "protocol");
> - const char *fdname = qdict_get_str(qdict, "fdname");
> - CharDriverState *s;
> -
> - if (strcmp(protocol, "spice") == 0) {
> - int fd = monitor_get_fd(mon, fdname, NULL);
> - int skipauth = qdict_get_try_bool(qdict, "skipauth", 0);
> - int tls = qdict_get_try_bool(qdict, "tls", 0);
> - if (!using_spice) {
> - /* correct one? spice isn't a device ,,, */
> - qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
> - return -1;
> - }
> - if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
> - close(fd);
> - }
> - return 0;
> -#ifdef CONFIG_VNC
> - } else if (strcmp(protocol, "vnc") == 0) {
> - int fd = monitor_get_fd(mon, fdname, NULL);
> - int skipauth = qdict_get_try_bool(qdict, "skipauth", 0);
> - vnc_display_add_client(NULL, fd, skipauth);
> - return 0;
> -#endif
> - } else if ((s = qemu_chr_find(protocol)) != NULL) {
> - int fd = monitor_get_fd(mon, fdname, NULL);
> - if (qemu_chr_add_client(s, fd) < 0) {
> - qerror_report(QERR_ADD_CLIENT_FAILED);
> - return -1;
> - }
> - return 0;
> - }
> -
> - qerror_report(QERR_INVALID_PARAMETER, "protocol");
> - return -1;
> -}
> -
> static int client_migrate_info(Monitor *mon, const QDict *qdict,
> MonitorCompletion cb, void *opaque)
> {
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 14e4419..c977ec7 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -33,6 +33,29 @@
> 'MigrationExpected' ] }
>
> ##
> +# @add_client
> +#
> +# Allow client connections for VNC, Spice and socket based
> +# character devices to be passed in to QEMU via SCM_RIGHTS.
> +#
> +# @protocol: protocol name. Valid names are "vnc", "spice" or the
> +# name of a character device (eg. from -chardev id=XXXX)
Not this patch's fault, but here goes anyway: rotten design, breaks when
you name your character device "vnc" or "spice". I think we shouldn't
overload commands like that.
> +#
> +# @fdname: file descriptor name previously passed via 'getfd' command
> +#
> +# @skipauth: #optional whether to skip authentication
Should we document that this applies only to vnc and spice?
> +#
> +# @tls: #optional whether to perform TLS
Should we document that this applies only to spice?
> +#
> +# Returns: nothing on success.
> +#
> +# Since: 0.14.0
> +##
Should we document that this always "uses up" @fdname, i.e. even when it
fails?
> +{ 'command': 'add_client',
> + 'data': { 'protocol': 'str', 'fdname': 'str', '*skipauth': 'bool',
> + '*tls': 'bool' } }
> +
> +##
> # @NameInfo:
> #
> # Guest name information.
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 6e21ddb..36e08d9 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1231,10 +1231,7 @@ EQMP
> {
> .name = "add_client",
> .args_type = "protocol:s,fdname:s,skipauth:b?,tls:b?",
> - .params = "protocol fdname skipauth tls",
> - .help = "add a graphics client",
> - .user_print = monitor_user_noop,
> - .mhandler.cmd_new = add_graphics_client,
> + .mhandler.cmd_new = qmp_marshal_input_add_client,
> },
>
> SQMP
> diff --git a/qmp.c b/qmp.c
> index 8463922..36c54c5 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -479,3 +479,46 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
> return arch_query_cpu_definitions(errp);
> }
>
> +void qmp_add_client(const char *protocol, const char *fdname,
> + bool has_skipauth, bool skipauth, bool has_tls, bool tls,
> + Error **errp)
> +{
> + CharDriverState *s;
> + int fd;
> +
> + fd = monitor_get_fd(cur_mon, fdname, errp);
> + if (fd < 0) {
> + return;
> + }
> +
> + if (strcmp(protocol, "spice") == 0) {
> + if (!using_spice) {
> + error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
> + close(fd);
> + return;
> + }
> + skipauth = has_skipauth ? skipauth : false;
> + tls = has_tls ? tls : false;
Pattern "has_FOO ? FOO : DEFAULT". Would it be feasible and useful to
declare the default in the schema, and pass only FOO to the function
then, not has_FOO? Outside this patch's scope, of course.
> + if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
> + error_setg(errp, "spice failed to add client");
Error message could use some love, but anything is an improvement over
nothing.
> + close(fd);
> + }
> + return;
> +#ifdef CONFIG_VNC
> + } else if (strcmp(protocol, "vnc") == 0) {
I hate "return; else", but to each his own :)
> + skipauth = has_skipauth ? skipauth : false;
> + vnc_display_add_client(NULL, fd, skipauth);
Amazingly, this can't fail. Wonder what happens when you pass a bogus
file descriptor... Not this patch's fault.
> + return;
> +#endif
> + } else if ((s = qemu_chr_find(protocol)) != NULL) {
> + if (qemu_chr_add_client(s, fd) < 0) {
> + error_setg(errp, "failed to add client");
Error message could use some love, but it's no worse than before.
> + close(fd);
> + return;
> + }
> + return;
> + }
> +
> + error_setg(errp, "protocol '%s' is invalid", protocol);
> + close(fd);
> +}
Just comments, no objections.
next prev parent reply other threads:[~2012-09-25 11:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-24 21:55 [Qemu-devel] [PATCH v3 0/3] qapi: convert add_client Luiz Capitulino
2012-09-24 21:55 ` [Qemu-devel] [PATCH 1/3] pci-assign: use monitor_handle_fd_param Luiz Capitulino
2012-09-25 11:03 ` Markus Armbruster
2012-09-26 7:54 ` Markus Armbruster
2012-09-24 21:55 ` [Qemu-devel] [PATCH 2/3] monitor: add Error * argument to monitor_get_fd Luiz Capitulino
2012-09-25 11:06 ` Markus Armbruster
2012-09-24 21:55 ` [Qemu-devel] [PATCH 3/3] qapi: convert add_client Luiz Capitulino
2012-09-25 11:29 ` Markus Armbruster [this message]
2012-09-25 12:39 ` Luiz Capitulino
2012-09-25 14:04 ` Markus Armbruster
2012-09-25 6:34 ` [Qemu-devel] [PATCH v3 0/3] " Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2012-09-25 20:24 [Qemu-devel] [PATCH v4 " Luiz Capitulino
2012-09-25 20:24 ` [Qemu-devel] [PATCH 3/3] " Luiz Capitulino
2012-09-20 20:28 [Qemu-devel] [PATCH v2 0/3]: " Luiz Capitulino
2012-09-20 20:28 ` [Qemu-devel] [PATCH 3/3] " Luiz Capitulino
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=87fw661gtf.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 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.