Received: from eggs.gnu.org ([2001:4830:134:3::10]:50930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViNvO-0005r6-JL for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:27:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ViNvD-0006pZ-E2 for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:27:30 -0500 Received: from mail-wg0-x22f.google.com ([2a00:1450:400c:c00::22f]:34149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViNvD-0006pT-7u for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:27:19 -0500 Received: by mail-wg0-f47.google.com with SMTP id y10so5984839wgg.2 for ; Mon, 18 Nov 2013 04:27:18 -0800 (PST) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 18 Nov 2013 13:25:20 +0100 Message-Id: <1384777531-14635-11-git-send-email-marcandre.lureau@gmail.com> In-Reply-To: <1384777531-14635-1-git-send-email-marcandre.lureau@gmail.com> References: <1384777531-14635-1-git-send-email-marcandre.lureau@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 10/21] nbd: finish any pending coroutine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , kraxel@redhat.com, spice-devel@freedesktop.org Make sure all pending coroutines are finished when closing the session. Signed-off-by: Marc-André Lureau --- block/nbd-client.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index c0ad2c2..ad6fb01 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -32,6 +32,18 @@ #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(NbdClientSession *s) +{ + int i; + + for (i = 0; i < MAX_NBD_REQUESTS; i++) { + if (s->recv_coroutine[i]) { + fprintf(stderr, "*nbd reply enter: %p %d\n", s, s->reply.error); + qemu_coroutine_enter(s->recv_coroutine[i], NULL); + } + } +} + static void nbd_reply_ready(void *opaque) { NbdClientSession *s = opaque; @@ -67,11 +79,7 @@ static void nbd_reply_ready(void *opaque) } fail: - for (i = 0; i < MAX_NBD_REQUESTS; i++) { - if (s->recv_coroutine[i]) { - qemu_coroutine_enter(s->recv_coroutine[i], NULL); - } - } + nbd_recv_coroutines_enter_all(s); } static void nbd_restart_write(void *opaque) @@ -332,6 +340,10 @@ static void nbd_teardown_connection(NbdClientSession *client) qemu_aio_set_fd_handler(client->sock, NULL, NULL, NULL); closesocket(client->sock); + /* finish any pending coroutines */ + client->reply.handle = 0; + client->reply.error = EIO; + nbd_recv_coroutines_enter_all(client); client->sock = -1; } -- 1.8.3.1