From patchwork Mon Mar 27 15:52:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 9647079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 22206602C8 for ; Mon, 27 Mar 2017 15:57:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 134AB2768C for ; Mon, 27 Mar 2017 15:57:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 066CD283BA; Mon, 27 Mar 2017 15:57:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9917B2768C for ; Mon, 27 Mar 2017 15:57:44 +0000 (UTC) Received: from localhost ([::1]:47739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csX1b-0004Rn-Mg for patchwork-qemu-devel@patchwork.kernel.org; Mon, 27 Mar 2017 11:57:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csWx0-0001ZQ-1L for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csWwz-0006JI-5e for qemu-devel@nongnu.org; Mon, 27 Mar 2017 11:52:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csWwv-0006G5-K6; Mon, 27 Mar 2017 11:52:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 862E96AADE; Mon, 27 Mar 2017 15:52:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 862E96AADE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 862E96AADE Received: from localhost (ovpn-204-144.brq.redhat.com [10.40.204.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1949981C00; Mon, 27 Mar 2017 15:52:51 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 27 Mar 2017 17:52:32 +0200 Message-Id: <20170327155234.10980-5-mreitz@redhat.com> In-Reply-To: <20170327155234.10980-1-mreitz@redhat.com> References: <20170327155234.10980-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 27 Mar 2017 15:52:52 +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] [PULL 4/6] 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: Peter Maydell , Paolo Bonzini , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini 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 Message-id: 20170314111157.14464-1-pbonzini@redhat.com Reviewed-by: Max Reitz Signed-off-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 0dc12c2d67..1e2952fdae 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)) -static void nbd_recv_coroutines_enter_all(BlockDriverState *bs) +static void nbd_recv_coroutines_enter_all(NBDClientSession *s) { - NBDClientSession *s = nbd_get_client_session(bs); int i; for (i = 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); } 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); nbd_client_detach_aio_context(bs); object_unref(OBJECT(client->sioc)); @@ -76,7 +74,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) for (;;) { assert(s->reply.handle == 0); ret = nbd_receive_reply(s->ioc, &s->reply); - if (ret < 0) { + if (ret <= 0) { break; } @@ -103,6 +101,8 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) aio_co_wake(s->recv_coroutine[i]); qemu_coroutine_yield(); } + + nbd_recv_coroutines_enter_all(s); s->read_reply_co = NULL; } diff --git a/nbd/client.c b/nbd/client.c index 3dc2564cd0..a58fb02cb4 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -812,6 +812,6 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply) LOG("invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } - return 0; + return sizeof(buf); }