From nobody Wed May 8 02:26:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489489969406150.31174308934476; Tue, 14 Mar 2017 04:12:49 -0700 (PDT) Received: from localhost ([::1]:57796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnkNk-0005sY-53 for importer@patchew.org; Tue, 14 Mar 2017 07:12:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnkN3-0005pH-0t for qemu-devel@nongnu.org; Tue, 14 Mar 2017 07:12:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnkN1-0005dy-UL for qemu-devel@nongnu.org; Tue, 14 Mar 2017 07:12:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnkMx-0005ZV-A5; Tue, 14 Mar 2017 07:11:59 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8470280462; Tue, 14 Mar 2017 11:11:59 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-149.ams2.redhat.com [10.36.117.149]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2EBBvif016903; Tue, 14 Mar 2017 07:11:58 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 14 Mar 2017 12:11:56 +0100 Message-Id: <20170314111157.14464-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 14 Mar 2017 11:11:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] nbd-client: fix handling of hungup connections 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: qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" After the switch to reading replies in a coroutine, nothing is reentering pending receive coroutines if the connection hangs. Move nbd_recv_coroutines_enter_all to the reply read coroutine, which is the place where hangups are detected. nbd_teardown_connection can simply wait for the reply read coroutine to detect the hangup and clean up after itself. This wouldn't be enough though because nbd_receive_reply returns 0 (rather than -EPIPE or similar) when reading from a hung connection. Fix the return value check in nbd_read_reply_entry. This fixes qemu-iotests 083. Reported-by: Max Reitz Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/nbd-client.c | 12 ++++++------ nbd/client.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 0dc12c2..1e2952f 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -33,17 +33,15 @@ #define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs)) #define INDEX_TO_HANDLE(bs, index) ((index) ^ ((uint64_t)(intptr_t)bs)) =20 -static void nbd_recv_coroutines_enter_all(BlockDriverState *bs) +static void nbd_recv_coroutines_enter_all(NBDClientSession *s) { - NBDClientSession *s =3D nbd_get_client_session(bs); int i; =20 for (i =3D 0; i < MAX_NBD_REQUESTS; i++) { if (s->recv_coroutine[i]) { - qemu_coroutine_enter(s->recv_coroutine[i]); + aio_co_wake(s->recv_coroutine[i]); } } - BDRV_POLL_WHILE(bs, s->read_reply_co); } =20 static void nbd_teardown_connection(BlockDriverState *bs) @@ -58,7 +56,7 @@ static void nbd_teardown_connection(BlockDriverState *bs) qio_channel_shutdown(client->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - nbd_recv_coroutines_enter_all(bs); + BDRV_POLL_WHILE(bs, client->read_reply_co); =20 nbd_client_detach_aio_context(bs); object_unref(OBJECT(client->sioc)); @@ -76,7 +74,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaqu= e) for (;;) { assert(s->reply.handle =3D=3D 0); ret =3D nbd_receive_reply(s->ioc, &s->reply); - if (ret < 0) { + if (ret <=3D 0) { break; } =20 @@ -103,6 +101,8 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) aio_co_wake(s->recv_coroutine[i]); qemu_coroutine_yield(); } + + nbd_recv_coroutines_enter_all(s); s->read_reply_co =3D NULL; } =20 diff --git a/nbd/client.c b/nbd/client.c index 5c9dee3..746e9a7 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -812,6 +812,6 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply) LOG("invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } - return 0; + return sizeof(buf); } =20 --=20 2.9.3