[pve-devel] [PATCH qemu] pvebackup_complete_cb: avoid poll loop if already inside coroutine

Dietmar Maurer dietmar at proxmox.com
Sun Oct 27 08:19:16 CET 2019


---
 blockdev.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 1bfd85ebc1..5580d36da7 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3170,6 +3170,8 @@ static void coroutine_fn block_on_coroutine_wrapper(void *opaque)
 
 static void block_on_coroutine_fn(CoroutineEntry *entry, void *entry_arg)
 {
+    assert(!qemu_in_coroutine());
+
     AioContext *ctx = qemu_get_current_aio_context();
     BlockOnCoroutineWrapper wrapper = {
         .finished = false,
@@ -3499,13 +3501,17 @@ static void coroutine_fn pvebackup_co_complete_cb(void *opaque)
 
 static void pvebackup_complete_cb(void *opaque, int ret)
 {
-    // This always called from the main loop
+    // This can be called from the main loop, or from a coroutine
     PVEBackupCompeteCallbackData cb_data = {
         .di = opaque,
         .result = ret,
     };
 
-    block_on_coroutine_fn(pvebackup_co_complete_cb, &cb_data);
+    if (qemu_in_coroutine()) {
+        pvebackup_co_complete_cb(&cb_data);
+    } else {
+        block_on_coroutine_fn(pvebackup_co_complete_cb, &cb_data);
+    }
 }
 
 static void coroutine_fn pvebackup_co_cancel(void *opaque)
-- 
2.20.1




More information about the pve-devel mailing list