thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ddf19c
From 4ef2c464a54b0b618d933641ac0a7012e629fed9 Mon Sep 17 00:00:00 2001
ddf19c
From: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Date: Wed, 11 Mar 2020 10:51:42 +0000
ddf19c
Subject: [PATCH 01/20] block/nbd: Fix hang in .bdrv_close()
ddf19c
ddf19c
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Message-id: <20200311105147.13208-2-mlevitsk@redhat.com>
ddf19c
Patchwork-id: 94224
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 1/6] block/nbd: Fix hang in .bdrv_close()
ddf19c
Bugzilla: 1640894
ddf19c
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
ddf19c
RH-Acked-by: John Snow <jsnow@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
ddf19c
From: Max Reitz <mreitz@redhat.com>
ddf19c
ddf19c
When nbd_close() is called from a coroutine, the connection_co never
ddf19c
gets to run, and thus nbd_teardown_connection() hangs.
ddf19c
ddf19c
This is because aio_co_enter() only puts the connection_co into the main
ddf19c
coroutine's wake-up queue, so this main coroutine needs to yield and
ddf19c
wait for connection_co to terminate.
ddf19c
ddf19c
Suggested-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Signed-off-by: Max Reitz <mreitz@redhat.com>
ddf19c
Message-Id: <20200122164532.178040-2-mreitz@redhat.com>
ddf19c
Reviewed-by: Eric Blake <eblake@redhat.com>
ddf19c
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Signed-off-by: Max Reitz <mreitz@redhat.com>
ddf19c
(cherry picked from commit 78c81a3f108870d325b0a39d88711366afe6f703)
ddf19c
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 block/nbd.c | 14 +++++++++++++-
ddf19c
 1 file changed, 13 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/block/nbd.c b/block/nbd.c
ddf19c
index 5f18f78..a73f0d9 100644
ddf19c
--- a/block/nbd.c
ddf19c
+++ b/block/nbd.c
ddf19c
@@ -70,6 +70,7 @@ typedef struct BDRVNBDState {
ddf19c
     CoMutex send_mutex;
ddf19c
     CoQueue free_sema;
ddf19c
     Coroutine *connection_co;
ddf19c
+    Coroutine *teardown_co;
ddf19c
     QemuCoSleepState *connection_co_sleep_ns_state;
ddf19c
     bool drained;
ddf19c
     bool wait_drained_end;
ddf19c
@@ -203,7 +204,15 @@ static void nbd_teardown_connection(BlockDriverState *bs)
ddf19c
             qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
ddf19c
         }
ddf19c
     }
ddf19c
-    BDRV_POLL_WHILE(bs, s->connection_co);
ddf19c
+    if (qemu_in_coroutine()) {
ddf19c
+        s->teardown_co = qemu_coroutine_self();
ddf19c
+        /* connection_co resumes us when it terminates */
ddf19c
+        qemu_coroutine_yield();
ddf19c
+        s->teardown_co = NULL;
ddf19c
+    } else {
ddf19c
+        BDRV_POLL_WHILE(bs, s->connection_co);
ddf19c
+    }
ddf19c
+    assert(!s->connection_co);
ddf19c
 }
ddf19c
 
ddf19c
 static bool nbd_client_connecting(BDRVNBDState *s)
ddf19c
@@ -395,6 +404,9 @@ static coroutine_fn void nbd_connection_entry(void *opaque)
ddf19c
         s->ioc = NULL;
ddf19c
     }
ddf19c
 
ddf19c
+    if (s->teardown_co) {
ddf19c
+        aio_co_wake(s->teardown_co);
ddf19c
+    }
ddf19c
     aio_wait_kick();
ddf19c
 }
ddf19c
 
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c