d89b3e
From cafefa3ed050be8e81f29e4b6fa4ea30597ab8a3 Mon Sep 17 00:00:00 2001
d89b3e
Message-Id: <cafefa3ed050be8e81f29e4b6fa4ea30597ab8a3@dist-git>
d89b3e
From: Michal Privoznik <mprivozn@redhat.com>
d89b3e
Date: Tue, 17 Mar 2015 13:13:48 +0100
d89b3e
Subject: [PATCH] qemuProcessHandleBlockJob: Set disk->mirrorState more often
d89b3e
d89b3e
https://bugzilla.redhat.com/show_bug.cgi?id=1202719
d89b3e
d89b3e
Currently, upon BLOCK_JOB_* event, disk->mirrorState is not updated
d89b3e
each time. The callback code handling the events checks if a blockjob
d89b3e
was started via our public APIs prior to setting the mirrorState.
d89b3e
However, some block jobs may be started internally (e.g. during
d89b3e
storage migration), in which case we don't bother with setting
d89b3e
disk->mirror (there's nothing we can set it to anyway), or other
d89b3e
fields. But it will come handy if we update the mirrorState in these
d89b3e
cases too. The event wasn't delivered just for fun - we've started the
d89b3e
job after all.
d89b3e
d89b3e
So, in this commit, the mirrorState is set to whatever job status
d89b3e
we've obtained. Of course, there are some actions on some statuses
d89b3e
that we want to perform. But instead of if {} else if {} else {} ...
d89b3e
enumeration, let's move to switch().
d89b3e
d89b3e
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
d89b3e
(cherry picked from commit c37943a0687a8fdb08e6eda8ae4b9f4f43f4f2ed)
d89b3e
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
d89b3e
---
d89b3e
 src/qemu/qemu_process.c | 35 ++++++++++++++++++++---------------
d89b3e
 1 file changed, 20 insertions(+), 15 deletions(-)
d89b3e
d89b3e
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
d89b3e
index 45bcf76..63cb198 100644
d89b3e
--- a/src/qemu/qemu_process.c
d89b3e
+++ b/src/qemu/qemu_process.c
d89b3e
@@ -1048,7 +1048,8 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
d89b3e
 
d89b3e
         /* If we completed a block pull or commit, then update the XML
d89b3e
          * to match.  */
d89b3e
-        if (status == VIR_DOMAIN_BLOCK_JOB_COMPLETED) {
d89b3e
+        switch ((virConnectDomainEventBlockJobStatus) status) {
d89b3e
+        case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
d89b3e
             if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
d89b3e
                 if (vm->newDef) {
d89b3e
                     int indx = virDomainDiskIndexByName(vm->newDef, disk->dst,
d89b3e
@@ -1098,20 +1099,24 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
d89b3e
             disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
d89b3e
             ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk,
d89b3e
                                                       true, true));
d89b3e
-        } else if (disk->mirror &&
d89b3e
-                   (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COPY ||
d89b3e
-                    type == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)) {
d89b3e
-            if (status == VIR_DOMAIN_BLOCK_JOB_READY) {
d89b3e
-                disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
d89b3e
-                save = true;
d89b3e
-            } else if (status == VIR_DOMAIN_BLOCK_JOB_FAILED ||
d89b3e
-                       status == VIR_DOMAIN_BLOCK_JOB_CANCELED) {
d89b3e
-                virStorageSourceFree(disk->mirror);
d89b3e
-                disk->mirror = NULL;
d89b3e
-                disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
d89b3e
-                disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
d89b3e
-                save = true;
d89b3e
-            }
d89b3e
+            break;
d89b3e
+
d89b3e
+        case VIR_DOMAIN_BLOCK_JOB_READY:
d89b3e
+            disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
d89b3e
+            save = true;
d89b3e
+            break;
d89b3e
+
d89b3e
+        case VIR_DOMAIN_BLOCK_JOB_FAILED:
d89b3e
+        case VIR_DOMAIN_BLOCK_JOB_CANCELED:
d89b3e
+            virStorageSourceFree(disk->mirror);
d89b3e
+            disk->mirror = NULL;
d89b3e
+            disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
d89b3e
+            disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
d89b3e
+            save = true;
d89b3e
+            break;
d89b3e
+
d89b3e
+        case VIR_DOMAIN_BLOCK_JOB_LAST:
d89b3e
+            break;
d89b3e
         }
d89b3e
     }
d89b3e
 
d89b3e
-- 
d89b3e
2.3.3
d89b3e