[libvirt] [PATCH v3 6/6] qemuDomainBlockJobImpl: utilize blockJob condition

Michal Privoznik mprivozn at redhat.com
Fri Feb 13 15:24:33 UTC 2015


Instead of unlocking and locking the domain object every 50ms
lets just wait on blockJob condition and run the loop body if and
BLOCK_JOB even occurred.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---

This one, well, I still left the only monitor call as I'm not
very familiar with this code so I don't know if it can be more
optimized. But hey, the 50ms sleep is gone!

 src/qemu/qemu_driver.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 709f468..9298619 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15872,10 +15872,6 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm,
             /* XXX If the event reports failure, we should reflect
              * that back into the return status of this API call.  */
             while (1) {
-                /* Poll every 50ms */
-                static struct timespec ts = {
-                    .tv_sec = 0,
-                    .tv_nsec = 50 * 1000 * 1000ull };
                 virDomainBlockJobInfo dummy;
 
                 qemuDomainObjEnterMonitor(driver, vm);
@@ -15886,11 +15882,12 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm,
                 if (ret <= 0)
                     break;
 
-                virObjectUnlock(vm);
-
-                nanosleep(&ts, NULL);
-
-                virObjectLock(vm);
+                if (virCondWait(&priv->blockJob, &vm->parent.lock) < 0) {
+                    virReportSystemError(errno, "%s",
+                                         _("Unable to wait on blockJob condition"));
+                    ret = -1;
+                    break;
+                }
 
                 if (!virDomainObjIsActive(vm)) {
                     virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-- 
2.0.5




More information about the libvir-list mailing list