qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 12/13] nbd: finish any pending coroutine


From: Marc-André Lureau
Subject: [Qemu-devel] [PATCH 12/13] nbd: finish any pending coroutine
Date: Fri, 29 Nov 2013 15:58:43 +0100

Make sure all pending coroutines are finished when closing the session.

Signed-off-by: Marc-André Lureau <address@hidden>
---
 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.4.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]