|
|
dc89ad |
From 9eace35bd8fd465a36132f3b66b662fff0cb92e5 Mon Sep 17 00:00:00 2001
|
|
|
dc89ad |
Message-Id: <9eace35bd8fd465a36132f3b66b662fff0cb92e5@dist-git>
|
|
|
dc89ad |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
dc89ad |
Date: Thu, 2 Apr 2015 11:27:58 +0200
|
|
|
dc89ad |
Subject: [PATCH] qemu: Extract internals of processBlockJobEvent into a helper
|
|
|
dc89ad |
|
|
|
dc89ad |
https://bugzilla.redhat.com/show_bug.cgi?id=1208021
|
|
|
dc89ad |
|
|
|
dc89ad |
Later on I'll be adding a condition that will allow to synchronise a
|
|
|
dc89ad |
SYNC block job abort. The approach will require this code to be called
|
|
|
dc89ad |
from two different places so it has to be extracted into a helper.
|
|
|
dc89ad |
|
|
|
dc89ad |
(cherry picked from commit 0c4474df4e10d27e27dbcda80b1f9cc14f4bdd8a)
|
|
|
dc89ad |
|
|
|
dc89ad |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
dc89ad |
---
|
|
|
dc89ad |
src/qemu/qemu_driver.c | 198 +++++++++++++++++++++++++------------------------
|
|
|
dc89ad |
1 file changed, 103 insertions(+), 95 deletions(-)
|
|
|
dc89ad |
|
|
|
dc89ad |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
dc89ad |
index 0939223..490650e 100644
|
|
|
dc89ad |
--- a/src/qemu/qemu_driver.c
|
|
|
dc89ad |
+++ b/src/qemu/qemu_driver.c
|
|
|
dc89ad |
@@ -4402,116 +4402,101 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
|
|
|
dc89ad |
|
|
|
dc89ad |
|
|
|
dc89ad |
static void
|
|
|
dc89ad |
-processBlockJobEvent(virQEMUDriverPtr driver,
|
|
|
dc89ad |
- virDomainObjPtr vm,
|
|
|
dc89ad |
- char *diskAlias,
|
|
|
dc89ad |
- int type,
|
|
|
dc89ad |
- int status)
|
|
|
dc89ad |
+qemuBlockJobEventProcess(virQEMUDriverPtr driver,
|
|
|
dc89ad |
+ virDomainObjPtr vm,
|
|
|
dc89ad |
+ virDomainDiskDefPtr disk,
|
|
|
dc89ad |
+ int type,
|
|
|
dc89ad |
+ int status)
|
|
|
dc89ad |
{
|
|
|
dc89ad |
virObjectEventPtr event = NULL;
|
|
|
dc89ad |
virObjectEventPtr event2 = NULL;
|
|
|
dc89ad |
const char *path;
|
|
|
dc89ad |
- virDomainDiskDefPtr disk;
|
|
|
dc89ad |
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
|
|
dc89ad |
virDomainDiskDefPtr persistDisk = NULL;
|
|
|
dc89ad |
bool save = false;
|
|
|
dc89ad |
|
|
|
dc89ad |
- if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
|
|
dc89ad |
- goto cleanup;
|
|
|
dc89ad |
+ /* Have to generate two variants of the event for old vs. new
|
|
|
dc89ad |
+ * client callbacks */
|
|
|
dc89ad |
+ if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
|
|
|
dc89ad |
+ disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
|
|
|
dc89ad |
+ type = disk->mirrorJob;
|
|
|
dc89ad |
+ path = virDomainDiskGetSource(disk);
|
|
|
dc89ad |
+ event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
|
|
|
dc89ad |
+ event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type, status);
|
|
|
dc89ad |
|
|
|
dc89ad |
- if (!virDomainObjIsActive(vm)) {
|
|
|
dc89ad |
- VIR_DEBUG("Domain is not running");
|
|
|
dc89ad |
- goto endjob;
|
|
|
dc89ad |
- }
|
|
|
dc89ad |
+ /* If we completed a block pull or commit, then update the XML
|
|
|
dc89ad |
+ * to match. */
|
|
|
dc89ad |
+ switch ((virConnectDomainEventBlockJobStatus) status) {
|
|
|
dc89ad |
+ case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
|
|
|
dc89ad |
+ if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
|
|
|
dc89ad |
+ if (vm->newDef) {
|
|
|
dc89ad |
+ int indx = virDomainDiskIndexByName(vm->newDef, disk->dst, false);
|
|
|
dc89ad |
+ virStorageSourcePtr copy = NULL;
|
|
|
dc89ad |
|
|
|
dc89ad |
- disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias);
|
|
|
dc89ad |
-
|
|
|
dc89ad |
- if (disk) {
|
|
|
dc89ad |
- /* Have to generate two variants of the event for old vs. new
|
|
|
dc89ad |
- * client callbacks */
|
|
|
dc89ad |
- if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
|
|
|
dc89ad |
- disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
|
|
|
dc89ad |
- type = disk->mirrorJob;
|
|
|
dc89ad |
- path = virDomainDiskGetSource(disk);
|
|
|
dc89ad |
- event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
|
|
|
dc89ad |
- event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type,
|
|
|
dc89ad |
- status);
|
|
|
dc89ad |
-
|
|
|
dc89ad |
- /* If we completed a block pull or commit, then update the XML
|
|
|
dc89ad |
- * to match. */
|
|
|
dc89ad |
- switch ((virConnectDomainEventBlockJobStatus) status) {
|
|
|
dc89ad |
- case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
|
|
|
dc89ad |
- if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
|
|
|
dc89ad |
- if (vm->newDef) {
|
|
|
dc89ad |
- int indx = virDomainDiskIndexByName(vm->newDef, disk->dst,
|
|
|
dc89ad |
- false);
|
|
|
dc89ad |
- virStorageSourcePtr copy = NULL;
|
|
|
dc89ad |
-
|
|
|
dc89ad |
- if (indx >= 0) {
|
|
|
dc89ad |
- persistDisk = vm->newDef->disks[indx];
|
|
|
dc89ad |
- copy = virStorageSourceCopy(disk->mirror, false);
|
|
|
dc89ad |
- if (virStorageSourceInitChainElement(copy,
|
|
|
dc89ad |
- persistDisk->src,
|
|
|
dc89ad |
- true) < 0) {
|
|
|
dc89ad |
- VIR_WARN("Unable to update persistent definition "
|
|
|
dc89ad |
- "on vm %s after block job",
|
|
|
dc89ad |
- vm->def->name);
|
|
|
dc89ad |
- virStorageSourceFree(copy);
|
|
|
dc89ad |
- copy = NULL;
|
|
|
dc89ad |
- persistDisk = NULL;
|
|
|
dc89ad |
- }
|
|
|
dc89ad |
- }
|
|
|
dc89ad |
- if (copy) {
|
|
|
dc89ad |
- virStorageSourceFree(persistDisk->src);
|
|
|
dc89ad |
- persistDisk->src = copy;
|
|
|
dc89ad |
+ if (indx >= 0) {
|
|
|
dc89ad |
+ persistDisk = vm->newDef->disks[indx];
|
|
|
dc89ad |
+ copy = virStorageSourceCopy(disk->mirror, false);
|
|
|
dc89ad |
+ if (virStorageSourceInitChainElement(copy,
|
|
|
dc89ad |
+ persistDisk->src,
|
|
|
dc89ad |
+ true) < 0) {
|
|
|
dc89ad |
+ VIR_WARN("Unable to update persistent definition "
|
|
|
dc89ad |
+ "on vm %s after block job",
|
|
|
dc89ad |
+ vm->def->name);
|
|
|
dc89ad |
+ virStorageSourceFree(copy);
|
|
|
dc89ad |
+ copy = NULL;
|
|
|
dc89ad |
+ persistDisk = NULL;
|
|
|
dc89ad |
}
|
|
|
dc89ad |
}
|
|
|
dc89ad |
-
|
|
|
dc89ad |
- /* XXX We want to revoke security labels and disk
|
|
|
dc89ad |
- * lease, as well as audit that revocation, before
|
|
|
dc89ad |
- * dropping the original source. But it gets tricky
|
|
|
dc89ad |
- * if both source and mirror share common backing
|
|
|
dc89ad |
- * files (we want to only revoke the non-shared
|
|
|
dc89ad |
- * portion of the chain); so for now, we leak the
|
|
|
dc89ad |
- * access to the original. */
|
|
|
dc89ad |
- virStorageSourceFree(disk->src);
|
|
|
dc89ad |
- disk->src = disk->mirror;
|
|
|
dc89ad |
- } else {
|
|
|
dc89ad |
- virStorageSourceFree(disk->mirror);
|
|
|
dc89ad |
+ if (copy) {
|
|
|
dc89ad |
+ virStorageSourceFree(persistDisk->src);
|
|
|
dc89ad |
+ persistDisk->src = copy;
|
|
|
dc89ad |
+ }
|
|
|
dc89ad |
}
|
|
|
dc89ad |
|
|
|
dc89ad |
- /* Recompute the cached backing chain to match our
|
|
|
dc89ad |
- * updates. Better would be storing the chain ourselves
|
|
|
dc89ad |
- * rather than reprobing, but we haven't quite completed
|
|
|
dc89ad |
- * that conversion to use our XML tracking. */
|
|
|
dc89ad |
- disk->mirror = NULL;
|
|
|
dc89ad |
- save = disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
|
dc89ad |
- disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
|
dc89ad |
- disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
|
dc89ad |
- ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk,
|
|
|
dc89ad |
- true, true));
|
|
|
dc89ad |
- disk->blockjob = false;
|
|
|
dc89ad |
- break;
|
|
|
dc89ad |
-
|
|
|
dc89ad |
- case VIR_DOMAIN_BLOCK_JOB_READY:
|
|
|
dc89ad |
- disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
|
|
|
dc89ad |
- save = true;
|
|
|
dc89ad |
- break;
|
|
|
dc89ad |
-
|
|
|
dc89ad |
- case VIR_DOMAIN_BLOCK_JOB_FAILED:
|
|
|
dc89ad |
- case VIR_DOMAIN_BLOCK_JOB_CANCELED:
|
|
|
dc89ad |
+ /* XXX We want to revoke security labels and disk
|
|
|
dc89ad |
+ * lease, as well as audit that revocation, before
|
|
|
dc89ad |
+ * dropping the original source. But it gets tricky
|
|
|
dc89ad |
+ * if both source and mirror share common backing
|
|
|
dc89ad |
+ * files (we want to only revoke the non-shared
|
|
|
dc89ad |
+ * portion of the chain); so for now, we leak the
|
|
|
dc89ad |
+ * access to the original. */
|
|
|
dc89ad |
+ virStorageSourceFree(disk->src);
|
|
|
dc89ad |
+ disk->src = disk->mirror;
|
|
|
dc89ad |
+ } else {
|
|
|
dc89ad |
virStorageSourceFree(disk->mirror);
|
|
|
dc89ad |
- disk->mirror = NULL;
|
|
|
dc89ad |
- disk->mirrorState = status == VIR_DOMAIN_BLOCK_JOB_FAILED ?
|
|
|
dc89ad |
- VIR_DOMAIN_DISK_MIRROR_STATE_ABORT : VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
|
dc89ad |
- disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
|
dc89ad |
- save = true;
|
|
|
dc89ad |
- disk->blockjob = false;
|
|
|
dc89ad |
- break;
|
|
|
dc89ad |
-
|
|
|
dc89ad |
- case VIR_DOMAIN_BLOCK_JOB_LAST:
|
|
|
dc89ad |
- break;
|
|
|
dc89ad |
}
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+ /* Recompute the cached backing chain to match our
|
|
|
dc89ad |
+ * updates. Better would be storing the chain ourselves
|
|
|
dc89ad |
+ * rather than reprobing, but we haven't quite completed
|
|
|
dc89ad |
+ * that conversion to use our XML tracking. */
|
|
|
dc89ad |
+ disk->mirror = NULL;
|
|
|
dc89ad |
+ save = disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
|
dc89ad |
+ disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
|
dc89ad |
+ disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
|
dc89ad |
+ ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk,
|
|
|
dc89ad |
+ true, true));
|
|
|
dc89ad |
+ disk->blockjob = false;
|
|
|
dc89ad |
+ break;
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+ case VIR_DOMAIN_BLOCK_JOB_READY:
|
|
|
dc89ad |
+ disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
|
|
|
dc89ad |
+ save = true;
|
|
|
dc89ad |
+ break;
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+ case VIR_DOMAIN_BLOCK_JOB_FAILED:
|
|
|
dc89ad |
+ case VIR_DOMAIN_BLOCK_JOB_CANCELED:
|
|
|
dc89ad |
+ virStorageSourceFree(disk->mirror);
|
|
|
dc89ad |
+ disk->mirror = NULL;
|
|
|
dc89ad |
+ disk->mirrorState = status == VIR_DOMAIN_BLOCK_JOB_FAILED ?
|
|
|
dc89ad |
+ VIR_DOMAIN_DISK_MIRROR_STATE_ABORT : VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
|
dc89ad |
+ disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
|
dc89ad |
+ save = true;
|
|
|
dc89ad |
+ disk->blockjob = false;
|
|
|
dc89ad |
+ break;
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+ case VIR_DOMAIN_BLOCK_JOB_LAST:
|
|
|
dc89ad |
+ break;
|
|
|
dc89ad |
}
|
|
|
dc89ad |
|
|
|
dc89ad |
if (save) {
|
|
|
dc89ad |
@@ -4523,13 +4508,36 @@ processBlockJobEvent(virQEMUDriverPtr driver,
|
|
|
dc89ad |
VIR_WARN("Unable to update persistent definition on vm %s "
|
|
|
dc89ad |
"after block job", vm->def->name);
|
|
|
dc89ad |
}
|
|
|
dc89ad |
- virObjectUnref(cfg);
|
|
|
dc89ad |
|
|
|
dc89ad |
if (event)
|
|
|
dc89ad |
qemuDomainEventQueue(driver, event);
|
|
|
dc89ad |
if (event2)
|
|
|
dc89ad |
qemuDomainEventQueue(driver, event2);
|
|
|
dc89ad |
|
|
|
dc89ad |
+ virObjectUnref(cfg);
|
|
|
dc89ad |
+}
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+static void
|
|
|
dc89ad |
+processBlockJobEvent(virQEMUDriverPtr driver,
|
|
|
dc89ad |
+ virDomainObjPtr vm,
|
|
|
dc89ad |
+ char *diskAlias,
|
|
|
dc89ad |
+ int type,
|
|
|
dc89ad |
+ int status)
|
|
|
dc89ad |
+{
|
|
|
dc89ad |
+ virDomainDiskDefPtr disk;
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
|
|
dc89ad |
+ goto cleanup;
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+ if (!virDomainObjIsActive(vm)) {
|
|
|
dc89ad |
+ VIR_DEBUG("Domain is not running");
|
|
|
dc89ad |
+ goto endjob;
|
|
|
dc89ad |
+ }
|
|
|
dc89ad |
+
|
|
|
dc89ad |
+ if ((disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias)))
|
|
|
dc89ad |
+ qemuBlockJobEventProcess(driver, vm, disk, type, status);
|
|
|
dc89ad |
+
|
|
|
dc89ad |
endjob:
|
|
|
dc89ad |
ignore_value(qemuDomainObjEndJob(driver, vm));
|
|
|
dc89ad |
cleanup:
|
|
|
dc89ad |
--
|
|
|
dc89ad |
2.3.5
|
|
|
dc89ad |
|