From nobody Mon Nov 10 10:07:24 2025 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 ARC-Seal: i=1; a=rsa-sha256; t=1555004050; cv=none; d=zoho.com; s=zohoarc; b=Wwf3EeWv3ND/4Lqy9/BQQ8AYHXt+9GjzckdnZ3BRVAMtp7OwvY3tjfd49f10vN97k040f8uG+X+WvLBSPQjzu3to1QSX8/Nz1IgHHJhb2/OCDQ9oOjgGhjP4l5BzQsttKIZKY3FBOcJZqs9vuFMxM84/uRj4QGxXX1gpFYLApOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555004050; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SDXLQe+/HexX8MykGjYoutTYgYJVe70EfE9DjpZedfU=; b=G7C9TnN2rBaCLbSO1+ZK3vi2M0LtjXZhk6Rd81Vi87xgF7LoGcGiuk3ziaPgQ8Y8mbvA9uHn/LNxx6zf83+4Npd92pjg8dCVKi7129KCir91FFhI3EBlvhyWn1Nwasfvtl5hPI+dGHVxJgrRxAgM/2ilo/TT3LfhM/V2iYyDjTA= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555004050247559.1368032419463; Thu, 11 Apr 2019 10:34:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:52625 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEdaP-0001PO-8q for importer@patchew.org; Thu, 11 Apr 2019 13:34:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEdTn-0004ZK-Bq for qemu-devel@nongnu.org; Thu, 11 Apr 2019 13:27:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEdTl-0003bh-Rf for qemu-devel@nongnu.org; Thu, 11 Apr 2019 13:27:15 -0400 Received: from relay.sw.ru ([185.231.240.75]:59354) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEdTl-0003Zt-DG; Thu, 11 Apr 2019 13:27:13 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hEdTi-00044D-ER; Thu, 11 Apr 2019 20:27:10 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 11 Apr 2019 20:27:04 +0300 Message-Id: <20190411172709.205032-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190411172709.205032-1-vsementsov@virtuozzo.com> References: <20190411172709.205032-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 v6 2/7] 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, armbru@redhat.com, mreitz@redhat.com, stefanha@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" No reason to use blocking channel for negotiation and we'll benefit in further reconnect feature, as qio_channel reads and writes will do qemu_coroutine_yield while waiting for io completion. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- include/block/nbd.h | 3 ++- block/nbd-client.c | 16 +++++++--------- nbd/client.c | 16 +++++++++++----- qemu-nbd.c | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 6d05983a55..6961835654 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -290,7 +290,8 @@ struct NBDExportInfo { }; typedef struct NBDExportInfo NBDExportInfo; =20 -int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, + QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp); void nbd_free_export_list(NBDExportInfo *info, int count); diff --git a/block/nbd-client.c b/block/nbd-client.c index facf8f8099..f9cee25865 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -1123,6 +1123,7 @@ static int nbd_client_connect(BlockDriverState *bs, Error **errp) { NBDClientSession *client =3D nbd_get_client_session(bs); + AioContext *aio_context =3D bdrv_get_aio_context(bs); int ret; =20 /* @@ -1137,15 +1138,16 @@ 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); + qio_channel_attach_aio_context(QIO_CHANNEL(sioc), aio_context); =20 client->info.request_sizes =3D true; client->info.structured_reply =3D true; client->info.base_allocation =3D true; client->info.x_dirty_bitmap =3D g_strdup(x_dirty_bitmap); client->info.name =3D g_strdup(export ?: ""); - ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), tlscreds, hostname, - &client->ioc, &client->info, errp); + ret =3D nbd_receive_negotiate(aio_context, QIO_CHANNEL(sioc), tlscreds, + hostname, &client->ioc, &client->info, err= p); g_free(client->info.x_dirty_bitmap); g_free(client->info.name); if (ret < 0) { @@ -1180,17 +1182,13 @@ static int nbd_client_connect(BlockDriverState *bs, object_ref(OBJECT(client->ioc)); } =20 - qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); - qio_channel_attach_aio_context(client->ioc, bdrv_get_aio_context(bs)); - logout("Established connection with NBD server\n"); return 0; =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 }; diff --git a/nbd/client.c b/nbd/client.c index 4de30630c7..8f524c3e35 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -867,7 +867,8 @@ 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, +static int nbd_start_negotiate(AioContext *aio_context, QIOChannel *ioc, + QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, bool structured_reply, bool *zeroes, Error **errp) @@ -934,6 +935,10 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCrypt= oTLSCreds *tlscreds, return -EINVAL; } ioc =3D *outioc; + if (aio_context) { + qio_channel_set_blocking(ioc, false, NULL); + qio_channel_attach_aio_context(ioc, aio_context); + } } else { error_setg(errp, "Server does not support STARTTLS"); return -EINVAL; @@ -998,7 +1003,8 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *i= oc, NBDExportInfo *info, * Returns: negative errno: failure talking to server * 0: server is connected */ -int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, + QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp) { @@ -1009,7 +1015,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLS= Creds *tlscreds, assert(info->name); trace_nbd_receive_negotiate_name(info->name); =20 - result =3D nbd_start_negotiate(ioc, tlscreds, hostname, outioc, + result =3D nbd_start_negotiate(aio_context, ioc, tlscreds, hostname, o= utioc, info->structured_reply, &zeroes, errp); =20 info->structured_reply =3D false; @@ -1129,8 +1135,8 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, QIOChannel *sioc =3D NULL; =20 *info =3D NULL; - result =3D nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, true, N= ULL, - errp); + result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, &sioc, t= rue, + NULL, errp); if (tlscreds && sioc) { ioc =3D sioc; } diff --git a/qemu-nbd.c b/qemu-nbd.c index 941ba729c2..ed38b55428 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -370,7 +370,7 @@ static void *nbd_client_thread(void *arg) goto out; } =20 - ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), + ret =3D nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc), NULL, NULL, NULL, &info, &local_error); if (ret < 0) { if (local_error) { --=20 2.18.0