]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuProcessHandleBlockJob: Set disk->mirrorState more often
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 10 Feb 2015 14:32:59 +0000 (15:32 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 19 Feb 2015 13:12:38 +0000 (14:12 +0100)
Currently, upon BLOCK_JOB_* event, disk->mirrorState is not updated
each time. The callback code handling the events checks if a blockjob
was started via our public APIs prior to setting the mirrorState.
However, some block jobs may be started internally (e.g. during
storage migration), in which case we don't bother with setting
disk->mirror (there's nothing we can set it to anyway), or other
fields. But it will come handy if we update the mirrorState in these
cases too. The event wasn't delivered just for fun - we've started the
job after all.

So, in this commit, the mirrorState is set to whatever job status
we've obtained. Of course, there are some actions on some statuses
that we want to perform. But instead of if {} else if {} else {} ...
enumeration, let's move to switch().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_process.c

index 1d4e957729880a67f2c09b1f547c1299223b85e8..a92258e63d0d29ce018012b19720f1ec92b6e1f6 100644 (file)
@@ -1041,7 +1041,8 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
 
         /* If we completed a block pull or commit, then update the XML
          * to match.  */
-        if (status == VIR_DOMAIN_BLOCK_JOB_COMPLETED) {
+        switch ((virConnectDomainEventBlockJobStatus) status) {
+        case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
             if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
                 if (vm->newDef) {
                     int indx = virDomainDiskIndexByName(vm->newDef, disk->dst,
@@ -1091,20 +1092,24 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
             disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
             ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk,
                                                       true, true));
-        } else if (disk->mirror &&
-                   (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COPY ||
-                    type == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)) {
-            if (status == VIR_DOMAIN_BLOCK_JOB_READY) {
-                disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
-                save = true;
-            } else if (status == VIR_DOMAIN_BLOCK_JOB_FAILED ||
-                       status == VIR_DOMAIN_BLOCK_JOB_CANCELED) {
-                virStorageSourceFree(disk->mirror);
-                disk->mirror = NULL;
-                disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
-                disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
-                save = true;
-            }
+            break;
+
+        case VIR_DOMAIN_BLOCK_JOB_READY:
+            disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
+            save = true;
+            break;
+
+        case VIR_DOMAIN_BLOCK_JOB_FAILED:
+        case VIR_DOMAIN_BLOCK_JOB_CANCELED:
+            virStorageSourceFree(disk->mirror);
+            disk->mirror = NULL;
+            disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
+            disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
+            save = true;
+            break;
+
+        case VIR_DOMAIN_BLOCK_JOB_LAST:
+            break;
         }
     }