From cafefa3ed050be8e81f29e4b6fa4ea30597ab8a3 Mon Sep 17 00:00:00 2001
Message-Id: <cafefa3ed050be8e81f29e4b6fa4ea30597ab8a3@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Tue, 17 Mar 2015 13:13:48 +0100
Subject: [PATCH] qemuProcessHandleBlockJob: Set disk->mirrorState more often
https://bugzilla.redhat.com/show_bug.cgi?id=1202719
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>
(cherry picked from commit c37943a0687a8fdb08e6eda8ae4b9f4f43f4f2ed)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
src/qemu/qemu_process.c | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 45bcf76..63cb198 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1048,7 +1048,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,
@@ -1098,20 +1099,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;
}
}
--
2.3.3