|
|
9119d9 |
From 4c96d5344961e60ef8b0150192fa2a5c2c8ca960 Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <4c96d5344961e60ef8b0150192fa2a5c2c8ca960@dist-git>
|
|
|
9119d9 |
From: Jincheng Miao <jmiao@redhat.com>
|
|
|
9119d9 |
Date: Mon, 8 Sep 2014 13:24:18 +0200
|
|
|
9119d9 |
Subject: [PATCH] qemu: snapshot: Acquire job earlier on snapshot revert/delete
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1134154
|
|
|
9119d9 |
|
|
|
9119d9 |
The code would lookup the snapshot object before acquiring the job. This
|
|
|
9119d9 |
could lead to a crash as one thread could delete the snapshot object,
|
|
|
9119d9 |
while a second thread already had the reference.
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jincheng Miao <jmiao@redhat.com>
|
|
|
9119d9 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
(cherry picked from commit a4065dc3e7b17a5fa6916fca2fb28a0d723fe13d)
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/qemu/qemu_driver.c | 30 +++++++++++++++---------------
|
|
|
9119d9 |
1 file changed, 15 insertions(+), 15 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
index 6a79f28..fb4b508 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_driver.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
@@ -14018,9 +14018,12 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
|
|
|
9119d9 |
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
+ if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (!vm->persistent &&
|
|
|
9119d9 |
snap->def->state != VIR_DOMAIN_RUNNING &&
|
|
|
9119d9 |
snap->def->state != VIR_DOMAIN_PAUSED &&
|
|
|
9119d9 |
@@ -14029,13 +14032,13 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
9119d9 |
_("transient domain needs to request run or pause "
|
|
|
9119d9 |
"to revert to inactive snapshot"));
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSnapshotIsExternal(snap)) {
|
|
|
9119d9 |
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
9119d9 |
_("revert to external snapshot not supported yet"));
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
|
|
|
9119d9 |
@@ -14043,7 +14046,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY,
|
|
|
9119d9 |
_("snapshot '%s' lacks domain '%s' rollback info"),
|
|
|
9119d9 |
snap->def->name, vm->def->name);
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
if (virDomainObjIsActive(vm) &&
|
|
|
9119d9 |
!(snap->def->state == VIR_DOMAIN_RUNNING
|
|
|
9119d9 |
@@ -14052,7 +14055,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED))) {
|
|
|
9119d9 |
virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
|
|
|
9119d9 |
_("must respawn qemu to start inactive snapshot"));
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -14061,7 +14064,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
vm->current_snapshot->def->current = false;
|
|
|
9119d9 |
if (qemuDomainSnapshotWriteMetadata(vm, vm->current_snapshot,
|
|
|
9119d9 |
cfg->snapshotDir) < 0)
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
vm->current_snapshot = NULL;
|
|
|
9119d9 |
/* XXX Should we restore vm->current_snapshot after this point
|
|
|
9119d9 |
* in the failure cases where we know there was no change? */
|
|
|
9119d9 |
@@ -14076,12 +14079,9 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
if (snap->def->dom) {
|
|
|
9119d9 |
config = virDomainDefCopy(snap->def->dom, caps, driver->xmlopt, true);
|
|
|
9119d9 |
if (!config)
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
-
|
|
|
9119d9 |
switch ((virDomainState) snap->def->state) {
|
|
|
9119d9 |
case VIR_DOMAIN_RUNNING:
|
|
|
9119d9 |
case VIR_DOMAIN_PAUSED:
|
|
|
9119d9 |
@@ -14391,9 +14391,12 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
if (virDomainSnapshotDeleteEnsureACL(snapshot->domain->conn, vm->def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
|
|
|
9119d9 |
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
+ if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (!metadata_only) {
|
|
|
9119d9 |
if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) &&
|
|
|
9119d9 |
virDomainSnapshotIsExternal(snap))
|
|
|
9119d9 |
@@ -14406,13 +14409,10 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
|
|
|
9119d9 |
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
9119d9 |
_("deletion of %d external disk snapshots not "
|
|
|
9119d9 |
"supported yet"), external);
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
+ goto endjob;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
-
|
|
|
9119d9 |
if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
|
|
|
9119d9 |
VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
|
|
|
9119d9 |
rem.driver = driver;
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.0
|
|
|
9119d9 |
|