qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] nbd: wait all read/write requests finished when shu


From: Wen Congyang
Subject: [Qemu-devel] [PATCH] nbd: wait all read/write requests finished when shutdowning nbd socket
Date: Wed, 16 Sep 2015 15:16:37 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

If the socket fd is shutdown, there may be some data which is received before
shutdown. We will read the data and do read/write in nbd_trip(). But the exp's
blk is NULL, and it will cause qemu crashed.

Reported-by: Li Zhijian <address@hidden>
Signed-off-by: Wen Congyang <address@hidden>
---
 nbd.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/nbd.c b/nbd.c
index 06b501b..d8586a1 100644
--- a/nbd.c
+++ b/nbd.c
@@ -1132,6 +1132,7 @@ void nbd_export_close(NBDExport *exp)
     nbd_export_set_name(exp, NULL);
     nbd_export_put(exp);
     if (exp->blk) {
+        bdrv_drain(blk_bs(exp->blk));
         blk_remove_aio_context_notifier(exp->blk, blk_aio_attached,
                                         blk_aio_detach, exp);
         blk_unref(exp->blk);
@@ -1305,6 +1306,14 @@ static void nbd_trip(void *opaque)
         goto invalid_request;
     }
 
+    if (client->closing) {
+        /*
+         * The client may be closed when we are blocked in
+         * nbd_co_receive_request()
+         */
+        goto done;
+    }
+
     switch (command) {
     case NBD_CMD_READ:
         TRACE("Request type is READ");
-- 
2.4.3



reply via email to

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