From nobody Mon Apr 29 06:03:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154988991500851.97579770194852; Mon, 11 Feb 2019 04:58:35 -0800 (PST) Received: from localhost ([127.0.0.1]:49333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtBAJ-00039R-0W for importer@patchew.org; Mon, 11 Feb 2019 07:58:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtB82-0001x2-Pg for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtB81-0007Rh-Sv for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:06 -0500 Received: from relay.sw.ru ([185.231.240.75]:54580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtB81-0007Ph-Ig; Mon, 11 Feb 2019 07:56:05 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gtB7x-0007uA-QR; Mon, 11 Feb 2019 15:56:01 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 11 Feb 2019 15:55:58 +0300 Message-Id: <20190211125601.86533-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190211125601.86533-1-vsementsov@virtuozzo.com> References: <20190211125601.86533-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/4] io/channel: add qio_channel_get_attached_aio_context() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Expose attached aio context. It will be used in nbd code, to understand, in which aio context negotiation should be done. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/io/channel.h | 9 +++++++++ io/channel.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index da2f138200..1a1e4a01b0 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -718,6 +718,15 @@ GSource *qio_channel_add_watch_source(QIOChannel *ioc, void qio_channel_attach_aio_context(QIOChannel *ioc, AioContext *ctx); =20 +/* + * qio_channel_get_aio_context + * @ioc: the channel object + * + * Returns channel AioContext if any attached by + * qio_channel_attach_aio_context(), otherwise NULL. + */ +AioContext *qio_channel_get_attached_aio_context(QIOChannel *ioc); + /** * qio_channel_detach_aio_context: * @ioc: the channel object diff --git a/io/channel.c b/io/channel.c index 8dd0684f5d..a1b937bb6b 100644 --- a/io/channel.c +++ b/io/channel.c @@ -454,6 +454,11 @@ void qio_channel_detach_aio_context(QIOChannel *ioc) ioc->ctx =3D NULL; } =20 +AioContext *qio_channel_get_attached_aio_context(QIOChannel *ioc) +{ + return ioc->ctx; +} + void coroutine_fn qio_channel_yield(QIOChannel *ioc, GIOCondition condition) { --=20 2.18.0 From nobody Mon Apr 29 06:03:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549890069260855.8824311972838; Mon, 11 Feb 2019 05:01:09 -0800 (PST) Received: from localhost ([127.0.0.1]:49418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtBCp-0005Be-61 for importer@patchew.org; Mon, 11 Feb 2019 08:01:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtB83-0001x3-0n for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtB81-0007RO-Qb for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:06 -0500 Received: from relay.sw.ru ([185.231.240.75]:54576) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtB81-0007Pj-Gy; Mon, 11 Feb 2019 07:56:05 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gtB7x-0007uA-Th; Mon, 11 Feb 2019 15:56:02 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 11 Feb 2019 15:55:59 +0300 Message-Id: <20190211125601.86533-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190211125601.86533-1-vsementsov@virtuozzo.com> References: <20190211125601.86533-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/4] nbd/client: do negotiation in coroutine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As a first step to non-blocking negotiation, move it to coroutine. Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/client.c | 123 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 109 insertions(+), 14 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 10a52ad7d0..2ba2220a4a 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -859,13 +859,14 @@ static int nbd_list_meta_contexts(QIOChannel *ioc, * 2: server is newstyle, but lacks structured replies * 3: server is newstyle and set up for structured replies */ -static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, - const char *hostname, QIOChannel **outioc, - bool structured_reply, bool *zeroes, - Error **errp) +static int coroutine_fn nbd_co_start_negotiate( + QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, + QIOChannel **outioc, bool structured_reply, bool *zeroes, Error **= errp) { uint64_t magic; =20 + assert(qemu_in_coroutine()); + trace_nbd_start_negotiate(tlscreds, hostname ? hostname : ""); =20 if (zeroes) { @@ -990,19 +991,20 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *= ioc, NBDExportInfo *info, * Returns: negative errno: failure talking to server * 0: server is connected */ -int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, - const char *hostname, QIOChannel **outioc, - NBDExportInfo *info, Error **errp) +static int coroutine_fn nbd_co_receive_negotiate( + QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, + QIOChannel **outioc, NBDExportInfo *info, Error **errp) { int result; bool zeroes; bool base_allocation =3D info->base_allocation; =20 + assert(qemu_in_coroutine()); assert(info->name); trace_nbd_receive_negotiate_name(info->name); =20 - result =3D nbd_start_negotiate(ioc, tlscreds, hostname, outioc, - info->structured_reply, &zeroes, errp); + result =3D nbd_co_start_negotiate(ioc, tlscreds, hostname, outioc, + info->structured_reply, &zeroes, errp); =20 info->structured_reply =3D false; info->base_allocation =3D false; @@ -1108,9 +1110,9 @@ void nbd_free_export_list(NBDExportInfo *info, int co= unt) * in @info by the server, or -1 on error. Caller must free @info using * nbd_free_export_list(). */ -int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, - const char *hostname, NBDExportInfo **info, - Error **errp) +static int coroutine_fn nbd_co_receive_export_list( + QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, + NBDExportInfo **info, Error **errp) { int result; int count =3D 0; @@ -1120,9 +1122,10 @@ int nbd_receive_export_list(QIOChannel *ioc, QCrypto= TLSCreds *tlscreds, NBDExportInfo *array =3D NULL; QIOChannel *sioc =3D NULL; =20 + assert(qemu_in_coroutine()); *info =3D NULL; - result =3D nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, true, N= ULL, - errp); + result =3D nbd_co_start_negotiate(ioc, tlscreds, hostname, &sioc, true= , NULL, + errp); if (tlscreds && sioc) { ioc =3D sioc; } @@ -1212,6 +1215,98 @@ int nbd_receive_export_list(QIOChannel *ioc, QCrypto= TLSCreds *tlscreds, return ret; } =20 +typedef struct NbdReceiveNegotiateCo { + QIOChannel *ioc; + QCryptoTLSCreds *tlscreds; + const char *hostname; + union { + struct { + QIOChannel **outioc; + NBDExportInfo *info; + } negotiate; + struct { + NBDExportInfo **info; + } export_list; + }; + Error **errp; + int ret; +} NbdReceiveNegotiateCo; + +static void coroutine_fn nbd_receive_negotiate_entry(void *opaque) +{ + NbdReceiveNegotiateCo *s =3D opaque; + + s->ret =3D nbd_co_receive_negotiate(s->ioc, s->tlscreds, s->hostname, + s->negotiate.outioc, s->negotiate.in= fo, + s->errp); +} + +static void coroutine_fn nbd_receive_export_list_entry(void *opaque) +{ + NbdReceiveNegotiateCo *s =3D opaque; + + s->ret =3D nbd_co_receive_export_list(s->ioc, s->tlscreds, s->hostname, + s->export_list.info, s->errp); +} + +static int nbd_receive_common(CoroutineEntry *entry, + NbdReceiveNegotiateCo *data) +{ + data->ret =3D -EINPROGRESS; + + if (qemu_in_coroutine()) { + entry(data); + } else { + AioContext *ctx =3D qio_channel_get_attached_aio_context(data->ioc= ); + bool attach =3D !ctx; + + if (attach) { + ctx =3D qemu_get_current_aio_context(); + qio_channel_attach_aio_context(data->ioc, ctx); + } + + qemu_aio_coroutine_enter(ctx, qemu_coroutine_create(entry, data)); + AIO_WAIT_WHILE(ctx, data->ret =3D=3D -EINPROGRESS); + + if (attach) { + qio_channel_detach_aio_context(data->ioc); + } + } + + return data->ret; +} + +int nbd_receive_negotiate( + QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, + QIOChannel **outioc, NBDExportInfo *info, Error **errp) +{ + NbdReceiveNegotiateCo data =3D { + .ioc =3D ioc, + .tlscreds =3D tlscreds, + .hostname =3D hostname, + .negotiate.outioc =3D outioc, + .negotiate.info =3D info, + .errp =3D errp, + }; + + return nbd_receive_common(nbd_receive_negotiate_entry, &data); +} + +int nbd_receive_export_list( + QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, + NBDExportInfo **info, Error **errp) +{ + NbdReceiveNegotiateCo data =3D { + .ioc =3D ioc, + .tlscreds =3D tlscreds, + .hostname =3D hostname, + .export_list.info =3D info, + .errp =3D errp, + }; + + return nbd_receive_common(nbd_receive_export_list_entry, &data); +} + #ifdef __linux__ int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp) --=20 2.18.0 From nobody Mon Apr 29 06:03:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549889916163911.1590361917148; Mon, 11 Feb 2019 04:58:36 -0800 (PST) Received: from localhost ([127.0.0.1]:49335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtBAL-0003DG-3A for importer@patchew.org; Mon, 11 Feb 2019 07:58:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtB83-0001x4-Dp for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtB81-0007RV-RD for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:07 -0500 Received: from relay.sw.ru ([185.231.240.75]:54590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtB81-0007Pk-HW; Mon, 11 Feb 2019 07:56:05 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gtB7y-0007uA-6L; Mon, 11 Feb 2019 15:56:02 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 11 Feb 2019 15:56:00 +0300 Message-Id: <20190211125601.86533-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190211125601.86533-1-vsementsov@virtuozzo.com> References: <20190211125601.86533-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 3/4] nbd: do qemu_coroutine_yield during tls handshake X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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; } =20 -static QIOChannel *nbd_receive_starttls(QIOChannel *ioc, - QCryptoTLSCreds *tlscreds, - const char *hostname, Error **errp) +static QIOChannel *nbd_co_receive_starttls( + QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, + Error **errp) { int ret; QIOChannelTLS *tioc; - struct NBDTLSHandshakeData data =3D { 0 }; + + assert(qemu_in_coroutine()); =20 ret =3D nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, errp); if (ret <=3D 0) { @@ -601,23 +602,13 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *i= oc, return NULL; } qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-client-tls"); - data.loop =3D 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(); =20 return QIO_CHANNEL(tioc); } @@ -922,7 +913,8 @@ static int coroutine_fn nbd_co_start_negotiate( } if (tlscreds) { if (fixedNewStyle) { - *outioc =3D nbd_receive_starttls(ioc, tlscreds, hostname, = errp); + *outioc =3D nbd_co_receive_starttls(ioc, tlscreds, hostnam= e, + errp); if (!*outioc) { return -EINVAL; } diff --git a/nbd/common.c b/nbd/common.c index cc8b278e54..8cff29ec33 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -50,11 +50,9 @@ int nbd_drop(QIOChannel *ioc, size_t size, Error **errp) void nbd_tls_handshake(QIOTask *task, void *opaque) { - struct NBDTLSHandshakeData *data =3D opaque; + Coroutine *co =3D opaque; =20 - qio_task_propagate_error(task, &data->error); - data->complete =3D true; - g_main_loop_quit(data->loop); + aio_co_wake(co); } =20 =20 diff --git a/nbd/server.c b/nbd/server.c index 838c150d8c..4463e8d792 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -668,16 +668,15 @@ static int nbd_negotiate_handle_info(NBDClient *clien= t, uint16_t myflags, =20 /* 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( + NBDClient *client, Error **errp) { QIOChannel *ioc; QIOChannelTLS *tioc; - struct NBDTLSHandshakeData data =3D { 0 }; =20 assert(client->opt =3D=3D NBD_OPT_STARTTLS); =20 - trace_nbd_negotiate_handle_starttls(); + trace_nbd_co_negotiate_handle_starttls(); ioc =3D client->ioc; =20 if (nbd_negotiate_send_rep(client, NBD_REP_ACK, errp) < 0) { @@ -693,23 +692,13 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDC= lient *client, } =20 qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-server-tls"); - trace_nbd_negotiate_handle_starttls_handshake(); - data.loop =3D g_main_loop_new(g_main_context_default(), FALSE); + trace_nbd_co_negotiate_handle_starttls_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) { - object_unref(OBJECT(tioc)); - error_propagate(errp, data.error); - return NULL; - } + qemu_coroutine_yield(); =20 return QIO_CHANNEL(tioc); } @@ -1023,8 +1012,8 @@ static int nbd_negotiate_meta_queries(NBDClient *clie= nt, * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect, * errp is not set */ -static int nbd_negotiate_options(NBDClient *client, uint16_t myflags, - Error **errp) +static int coroutine_fn nbd_co_negotiate_options( + NBDClient *client, uint16_t myflags, Error **errp) { uint32_t flags; bool fixedNewstyle =3D false; @@ -1048,7 +1037,7 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, if (nbd_read32(client->ioc, &flags, "flags", errp) < 0) { return -EIO; } - trace_nbd_negotiate_options_flags(flags); + trace_nbd_co_negotiate_options_flags(flags); if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) { fixedNewstyle =3D true; flags &=3D ~NBD_FLAG_C_FIXED_NEWSTYLE; @@ -1070,7 +1059,7 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, if (nbd_read64(client->ioc, &magic, "opts magic", errp) < 0) { return -EINVAL; } - trace_nbd_negotiate_options_check_magic(magic); + trace_nbd_co_negotiate_options_check_magic(magic); if (magic !=3D NBD_OPTS_MAGIC) { error_setg(errp, "Bad magic received"); return -EINVAL; @@ -1093,7 +1082,7 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, return -EINVAL; } =20 - trace_nbd_negotiate_options_check_option(option, + trace_nbd_co_negotiate_options_check_option(option, nbd_opt_lookup(option)); if (client->tlscreds && client->ioc =3D=3D (QIOChannel *)client->sioc) { @@ -1109,7 +1098,7 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, * can't start a TLS negotiation correctly */ return nbd_reject_length(client, true, errp); } - tioc =3D nbd_negotiate_handle_starttls(client, errp); + tioc =3D nbd_co_negotiate_handle_starttls(client, errp); if (!tioc) { return -EIO; } @@ -1241,7 +1230,7 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect, * errp is not set */ -static coroutine_fn int nbd_negotiate(NBDClient *client, Error **errp) +static coroutine_fn int nbd_co_negotiate(NBDClient *client, Error **errp) { char buf[NBD_OLDSTYLE_NEGOTIATE_SIZE] =3D ""; int ret; @@ -1265,7 +1254,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) =20 qio_channel_set_blocking(client->ioc, false, NULL); =20 - trace_nbd_negotiate_begin(); + trace_nbd_co_negotiate_begin(); memcpy(buf, "NBDMAGIC", 8); =20 stq_be_p(buf + 8, NBD_OPTS_MAGIC); @@ -1275,7 +1264,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) error_prepend(errp, "write failed: "); return -EINVAL; } - ret =3D nbd_negotiate_options(client, myflags, errp); + ret =3D nbd_co_negotiate_options(client, myflags, errp); if (ret !=3D 0) { if (ret < 0) { error_prepend(errp, "option negotiation failed: "); @@ -1284,7 +1273,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) } =20 assert(!client->optlen); - trace_nbd_negotiate_success(); + trace_nbd_co_negotiate_success(); =20 return 0; } @@ -2408,7 +2397,7 @@ static coroutine_fn void nbd_co_client_start(void *op= aque) =20 qemu_co_mutex_init(&client->send_lock); =20 - if (nbd_negotiate(client, &local_err)) { + if (nbd_co_negotiate(client, &local_err)) { if (local_err) { error_report_err(local_err); } diff --git a/nbd/trace-events b/nbd/trace-events index 7f10ebd4e0..0316ba0c71 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -46,19 +46,18 @@ nbd_negotiate_send_info(int info, const char *name, uin= t32_t length) "Sending NB nbd_negotiate_handle_info_requests(int requests) "Client requested %d item= s of info" nbd_negotiate_handle_info_request(int request, const char *name) "Client r= equested info %d (%s)" nbd_negotiate_handle_info_block_size(uint32_t minimum, uint32_t preferred,= uint32_t maximum) "advertising minimum 0x%" PRIx32 ", preferred 0x%" PRIx3= 2 ", maximum 0x%" PRIx32 -nbd_negotiate_handle_starttls(void) "Setting up TLS" -nbd_negotiate_handle_starttls_handshake(void) "Starting TLS handshake" +nbd_co_negotiate_handle_starttls(void) "Setting up TLS" +nbd_co_negotiate_handle_starttls_handshake(void) "Starting TLS handshake" nbd_negotiate_meta_context(const char *optname, const char *export, uint32= _t queries) "Client requested %s for export %s, with %" PRIu32 " queries" nbd_negotiate_meta_query_skip(const char *reason) "Skipping meta query: %s" nbd_negotiate_meta_query_parse(const char *query) "Parsed meta query '%s'" nbd_negotiate_meta_query_reply(const char *context, uint32_t id) "Replying= with meta context '%s' id %" PRIu32 -nbd_negotiate_options_flags(uint32_t flags) "Received client flags 0x%" PR= Ix32 -nbd_negotiate_options_check_magic(uint64_t magic) "Checking opts magic 0x%= " PRIx64 -nbd_negotiate_options_check_option(uint32_t option, const char *name) "Che= cking option %" PRIu32 " (%s)" -nbd_negotiate_begin(void) "Beginning negotiation" -nbd_negotiate_old_style(uint64_t size, unsigned flags) "advertising size %= " PRIu64 " and flags 0x%x" +nbd_co_negotiate_options_flags(uint32_t flags) "Received client flags 0x%"= PRIx32 +nbd_co_negotiate_options_check_magic(uint64_t magic) "Checking opts magic = 0x%" PRIx64 +nbd_co_negotiate_options_check_option(uint32_t option, const char *name) "= Checking option %" PRIu32 " (%s)" +nbd_co_negotiate_begin(void) "Beginning negotiation" nbd_negotiate_new_style_size_flags(uint64_t size, unsigned flags) "adverti= sing size %" PRIu64 " and flags 0x%x" -nbd_negotiate_success(void) "Negotiation succeeded" +nbd_co_negotiate_success(void) "Negotiation succeeded" nbd_receive_request(uint32_t magic, uint16_t flags, uint16_t type, uint64_= t from, uint32_t len) "Got request: { magic =3D 0x%" PRIx32 ", .flags =3D 0= x%" PRIx16 ", .type =3D 0x%" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRI= u32 " }" nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching cl= ients to AIO context %p\n" nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p\n" --=20 2.18.0 From nobody Mon Apr 29 06:03:07 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154988991599931.629182742789226; Mon, 11 Feb 2019 04:58:35 -0800 (PST) Received: from localhost ([127.0.0.1]:49331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtBAH-00036b-05 for importer@patchew.org; Mon, 11 Feb 2019 07:58:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtB82-0001x1-Oh for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtB81-0007Rc-Rh for qemu-devel@nongnu.org; Mon, 11 Feb 2019 07:56:06 -0500 Received: from relay.sw.ru ([185.231.240.75]:54582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtB81-0007Pi-Ht; Mon, 11 Feb 2019 07:56:05 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gtB7y-0007uA-Av; Mon, 11 Feb 2019 15:56:02 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 11 Feb 2019 15:56:01 +0300 Message-Id: <20190211125601.86533-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190211125601.86533-1-vsementsov@virtuozzo.com> References: <20190211125601.86533-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 4/4] block/nbd-client: use non-blocking io channel for nbd negotiation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now negotiation is done in coroutine, so to take benefit of it let's use non-blocking model. Note that QIOChannel handle synchronous io calls correctly anyway, so it's not a problem to send final NBD_CMD_DISC to non-blocking channel but using sync qio interface, even not in coroutine. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd-client.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index f0ad54ce21..79bc6b7e29 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -1029,7 +1029,7 @@ static int nbd_client_connect(BlockDriverState *bs, =20 /* NBD handshake */ logout("session init %s\n", export); - qio_channel_set_blocking(QIO_CHANNEL(sioc), true, NULL); + qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); =20 client->info.request_sizes =3D true; client->info.structured_reply =3D true; @@ -1072,9 +1072,6 @@ static int nbd_client_connect(BlockDriverState *bs, object_ref(OBJECT(client->ioc)); } =20 - /* Now that we're connected, set the socket to be non-blocking and - * kick the reply mechanism. */ - qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); client->connection_co =3D qemu_coroutine_create(nbd_connection_entry, = client); nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs)); =20 @@ -1083,9 +1080,8 @@ static int nbd_client_connect(BlockDriverState *bs, =20 fail: /* - * We have connected, but must fail for other reasons. The - * connection is still blocking; send NBD_CMD_DISC as a courtesy - * to the server. + * We have connected, but must fail for other reasons. + * Send NBD_CMD_DISC as a courtesy to the server. */ { NBDRequest request =3D { .type =3D NBD_CMD_DISC }; --=20 2.18.0