Due to race qemuDomainGetBlockJobInfo can return there is
no block job for disk but later call to spawn new blockjob
can fail because libvirt internally still not process blockjob
finishing. Thus let's wait for blockjob finishing if we
report there is no more blockjob.

Signed-off-by: Nikolay Shirokovskiy <nshirokovs...@virtuozzo.com>
---
 src/qemu/qemu_driver.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 669c12d6ca..b148df3a57 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17785,12 +17785,26 @@ qemuDomainGetBlockJobInfo(virDomainPtr dom,
         goto endjob;
     }
 
+    qemuBlockJobSyncBegin(job);
+
     qemuDomainObjEnterMonitor(driver, vm);
     ret = qemuMonitorGetBlockJobInfo(qemuDomainGetMonitor(vm), job->name, 
&rawInfo);
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         ret = -1;
-    if (ret <= 0)
+    if (ret < 0)
+        goto endjob;
+
+    if (ret == 0) {
+        qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
+        while (qemuBlockJobIsRunning(job)) {
+            if (virDomainObjWait(vm) < 0) {
+                ret = -1;
+                goto endjob;
+            }
+            qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
+        }
         goto endjob;
+    }
 
     if (qemuBlockJobInfoTranslate(&rawInfo, info, disk,
                                   flags & 
VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES) < 0) {
@@ -17799,6 +17813,8 @@ qemuDomainGetBlockJobInfo(virDomainPtr dom,
     }
 
  endjob:
+    if (job)
+        qemuBlockJobSyncEnd(vm, job, QEMU_ASYNC_JOB_NONE);
     qemuDomainObjEndJob(driver, vm);
 
  cleanup:
-- 
2.23.0


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to