yeahuh / rpms / qemu-kvm

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