qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Eric Blake <eblake@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>
Cc: "berrange@redhat.com" <berrange@redhat.com>,
	"mreitz@redhat.com" <mreitz@redhat.com>,
	"kwolf@redhat.com" <kwolf@redhat.com>,
	Denis Lunev <den@virtuozzo.com>
Subject: Re: [Qemu-devel] [PATCH 3/4] nbd: do qemu_coroutine_yield during tls handshake
Date: Tue, 19 Feb 2019 10:40:03 +0000	[thread overview]
Message-ID: <1b25b3e6-dcb7-31b0-d9db-1590ef9ed71e@virtuozzo.com> (raw)
In-Reply-To: <487bcf49-65fb-16eb-0d0e-978fa324817a@redhat.com>

12.02.2019 0:55, Eric Blake wrote:
> 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 ?

hmm, yes.

> 
>> +        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?

I think, not. It still may be called from non-coroutine context.

> 
>>       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:

Oops, agree.

> 
> 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.

OK

> 
> 
>> @@ -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.
> 


-- 
Best regards,
Vladimir

  reply	other threads:[~2019-02-19 10:40 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
2019-02-19 10:40     ` Vladimir Sementsov-Ogievskiy [this message]
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=1b25b3e6-dcb7-31b0-d9db-1590ef9ed71e@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=berrange@redhat.com \
    --cc=den@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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 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).