qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: berrange@redhat.com, mreitz@redhat.com, kwolf@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH 3/4] nbd: do qemu_coroutine_yield during tls handshake
Date: Mon, 11 Feb 2019 15:55:15 -0600	[thread overview]
Message-ID: <487bcf49-65fb-16eb-0d0e-978fa324817a@redhat.com> (raw)
In-Reply-To: <20190211125601.86533-4-vsementsov@virtuozzo.com>

[-- Attachment #1: Type: text/plain, Size: 4023 bytes --]

On 2/11/19 6:56 AM, Vladimir Sementsov-Ogievskiy wrote:
> We always call qio_channel_tls_handshake in nbd from couroutine. Take
> benefit of it and just yield instead of creating personal main loop.
> 
> Mark and rename the function and it's callers correspondingly and
> trace-points too.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  nbd/client.c     | 26 +++++++++-----------------
>  nbd/common.c     |  6 ++----
>  nbd/server.c     | 45 +++++++++++++++++----------------------------
>  nbd/trace-events | 15 +++++++--------
>  4 files changed, 35 insertions(+), 57 deletions(-)
> 
> diff --git a/nbd/client.c b/nbd/client.c
> index 2ba2220a4a..e3919be30e 100644
> --- a/nbd/client.c
> +++ b/nbd/client.c
> @@ -578,13 +578,14 @@ static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)
>      return 1;
>  }
>  
> -static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
> -                                        QCryptoTLSCreds *tlscreds,
> -                                        const char *hostname, Error **errp)
> +static QIOChannel *nbd_co_receive_starttls(

Missing coroutine_fn ?

> +        QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname,
> +        Error **errp)
>  {
>      int ret;
>      QIOChannelTLS *tioc;
> -    struct NBDTLSHandshakeData data = { 0 };
> +
> +    assert(qemu_in_coroutine());

Again, I'm not sure these assertions add much.

>  
>      ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, errp);

Should we also be marking these helper functions as coroutine_fn by the
end of the series, once all callers are marked that way?

>      if (ret <= 0) {
> @@ -601,23 +602,13 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
>          return NULL;
>      }
>      qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-client-tls");
> -    data.loop = g_main_loop_new(g_main_context_default(), FALSE);
>      trace_nbd_receive_starttls_tls_handshake();
>      qio_channel_tls_handshake(tioc,
>                                nbd_tls_handshake,
> -                              &data,
> +                              qemu_coroutine_self(),
>                                NULL,
>                                NULL);
> -
> -    if (!data.complete) {
> -        g_main_loop_run(data.loop);
> -    }
> -    g_main_loop_unref(data.loop);
> -    if (data.error) {
> -        error_propagate(errp, data.error);
> -        object_unref(OBJECT(tioc));
> -        return NULL;
> -    }
> +    qemu_coroutine_yield();

Nice.

> +++ b/nbd/server.c
> @@ -668,16 +668,15 @@ static int nbd_negotiate_handle_info(NBDClient *client, uint16_t myflags,
>  
>  /* Handle NBD_OPT_STARTTLS. Return NULL to drop connection, or else the
>   * new channel for all further (now-encrypted) communication. */
> -static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client,
> -                                                 Error **errp)
> +static QIOChannel coroutine_fn *nbd_co_negotiate_handle_starttls(

Awkward split of the return type; the coroutine_fn should instead be
placed after the *, as in:

block/mirror.c:static MirrorOp *coroutine_fn active_write_prepare(...

> +        NBDClient *client, Error **errp)
>  {
>      QIOChannel *ioc;
>      QIOChannelTLS *tioc;
> -    struct NBDTLSHandshakeData data = { 0 };

All uses of this type have been deleted; you should also remove it from
nbd-internal.h.


> @@ -1093,7 +1082,7 @@ static int nbd_negotiate_options(NBDClient *client, uint16_t myflags,
>              return -EINVAL;
>          }
>  
> -        trace_nbd_negotiate_options_check_option(option,
> +        trace_nbd_co_negotiate_options_check_option(option,
>                                                   nbd_opt_lookup(option));

Indentation looks off.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-02-11 21:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11 12:55 [Qemu-devel] [PATCH 0/4] nbd: non-blocking negotiation Vladimir Sementsov-Ogievskiy
2019-02-11 12:55 ` [Qemu-devel] [PATCH 1/4] io/channel: add qio_channel_get_attached_aio_context() Vladimir Sementsov-Ogievskiy
2019-02-11 21:22   ` Eric Blake
2019-02-12 10:33   ` Daniel P. Berrangé
2019-02-19 12:46     ` Vladimir Sementsov-Ogievskiy
2019-02-11 12:55 ` [Qemu-devel] [PATCH 2/4] nbd/client: do negotiation in coroutine Vladimir Sementsov-Ogievskiy
2019-02-11 21:38   ` Eric Blake
2019-02-19 10:37     ` Vladimir Sementsov-Ogievskiy
2019-02-11 12:56 ` [Qemu-devel] [PATCH 3/4] nbd: do qemu_coroutine_yield during tls handshake Vladimir Sementsov-Ogievskiy
2019-02-11 21:55   ` Eric Blake [this message]
2019-02-19 10:40     ` Vladimir Sementsov-Ogievskiy
2019-02-11 12:56 ` [Qemu-devel] [PATCH 4/4] block/nbd-client: use non-blocking io channel for nbd negotiation Vladimir Sementsov-Ogievskiy
2019-02-11 22:02   ` Eric Blake
2019-02-19 13:18     ` Vladimir Sementsov-Ogievskiy
2019-02-25  6:08       ` Vladimir Sementsov-Ogievskiy
2019-03-06 16:11 ` [Qemu-devel] [PATCH 0/4] nbd: non-blocking negotiation Eric Blake
2019-03-06 16:31   ` Vladimir Sementsov-Ogievskiy

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=487bcf49-65fb-16eb-0d0e-978fa324817a@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=den@openvz.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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).