From 4e7b21b4138e011c05ae72ed8b92f0bd2b888744 Mon Sep 17 00:00:00 2001
Message-Id: <4e7b21b4138e011c05ae72ed8b92f0bd2b888744@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 17 Mar 2015 13:13:53 +0100
Subject: [PATCH] qemu: Disallow concurrent block jobs on a single disk
https://bugzilla.redhat.com/show_bug.cgi?id=1202719
While qemu may be prepared to do this libvirt is not. Forbid the block
ops until we fix our code.
(cherry picked from commit 51f9f03a4ca50b070c0fbfb29748d49f583e15e1)
Conflicts:
src/qemu/qemu_domain.h - context with upstream changes
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
src/conf/domain_conf.h | 4 ++++
src/qemu/qemu_domain.c | 23 +++++++++++++++++++++++
src/qemu/qemu_domain.h | 2 ++
src/qemu/qemu_driver.c | 28 +++++++++++++---------------
4 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 1436eb8..654c27d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -636,6 +636,10 @@ struct _virDomainDiskDef {
int tray_status; /* enum virDomainDiskTray */
int removable; /* enum virTristateSwitch */
+ /* ideally we want a smarter way to interlock block jobs on single qemu disk
+ * in the future, but for now we just disallow any concurrent job on a
+ * single disk */
+ bool blockjob;
virStorageSourcePtr mirror;
int mirrorState; /* enum virDomainDiskMirrorState */
int mirrorJob; /* virDomainBlockJobType */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0c3d21f..b9bf3eb 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2771,6 +2771,29 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
return ret;
}
+
+bool
+qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk)
+{
+ if (disk->mirror) {
+ virReportError(VIR_ERR_BLOCK_COPY_ACTIVE,
+ _("disk '%s' already in active block job"),
+ disk->dst);
+
+ return true;
+ }
+
+ if (disk->blockjob) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("disk '%s' already in active block job"),
+ disk->dst);
+ return true;
+ }
+
+ return false;
+}
+
+
int
qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
virDomainObjPtr vm,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 76054ec..63d1261 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -416,4 +416,6 @@ int qemuDomainJobInfoToParams(qemuDomainJobInfoPtr jobInfo,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk);
+
#endif /* __QEMU_DOMAIN_H__ */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a19281d..2bd4a1d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4490,6 +4490,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk,
true, true));
+ disk->blockjob = false;
break;
case VIR_DOMAIN_BLOCK_JOB_READY:
@@ -4505,6 +4506,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
VIR_DOMAIN_DISK_MIRROR_STATE_ABORT : VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
save = true;
+ disk->blockjob = false;
break;
case VIR_DOMAIN_BLOCK_JOB_LAST:
@@ -15583,6 +15585,7 @@ qemuDomainBlockPivot(virConnectPtr conn,
disk->mirror = NULL;
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
+ disk->blockjob = false;
}
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
ret = -1;
@@ -15679,12 +15682,9 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm,
goto endjob;
disk = vm->def->disks[idx];
- if (mode == BLOCK_JOB_PULL && disk->mirror) {
- virReportError(VIR_ERR_BLOCK_COPY_ACTIVE,
- _("disk '%s' already in active block job"),
- disk->dst);
+ if (mode == BLOCK_JOB_PULL && qemuDomainDiskBlockJobIsActive(disk))
goto endjob;
- }
+
if (mode == BLOCK_JOB_ABORT) {
if ((flags & VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT) &&
!(async && disk->mirror)) {
@@ -15756,6 +15756,8 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm,
if (mode == BLOCK_JOB_ABORT && disk->mirror)
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
goto endjob;
+ } else if (mode == BLOCK_JOB_PULL) {
+ disk->blockjob = true;
}
/* Snoop block copy operations, so future cancel operations can
@@ -15943,12 +15945,8 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
goto endjob;
}
disk = vm->def->disks[idx];
- if (disk->mirror) {
- virReportError(VIR_ERR_BLOCK_COPY_ACTIVE,
- _("disk '%s' already in active block job"),
- disk->dst);
+ if (qemuDomainDiskBlockJobIsActive(disk))
goto endjob;
- }
if (!(virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_MIRROR) &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKJOB_ASYNC))) {
@@ -16074,6 +16072,7 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
disk->mirror = mirror;
mirror = NULL;
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
+ disk->blockjob = true;
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
VIR_WARN("Unable to save status on vm %s after state change",
@@ -16232,12 +16231,9 @@ qemuDomainBlockCommit(virDomainPtr dom,
disk->dst);
goto endjob;
}
- if (disk->mirror) {
- virReportError(VIR_ERR_BLOCK_COPY_ACTIVE,
- _("disk '%s' already in active block job"),
- disk->dst);
+
+ if (qemuDomainDiskBlockJobIsActive(disk))
goto endjob;
- }
if (qemuDomainDetermineDiskChain(driver, vm, disk, false, true) < 0)
goto endjob;
@@ -16358,6 +16354,8 @@ qemuDomainBlockCommit(virDomainPtr dom,
bandwidth);
qemuDomainObjExitMonitor(driver, vm);
+ disk->blockjob = true;
+
if (mirror) {
if (ret == 0) {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
--
2.3.3