The internal snapshot revert code used a very unintuitive approach to
create lifecycle events while doing the revert. Refactor the code to use
the new automagic function to do the revertion.
---
src/qemu/qemu_driver.c | 76 +++++++++-----------------------------------------
1 file changed, 13 insertions(+), 63 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e794e02..1f98f4a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14047,16 +14047,12 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
virDomainObjPtr vm = NULL;
int ret = -1;
virDomainSnapshotObjPtr snap = NULL;
- virObjectEventPtr event = NULL;
- virObjectEventPtr event2 = NULL;
- int detail;
qemuDomainObjPrivatePtr priv;
int rc;
virDomainDefPtr config = NULL;
virQEMUDriverConfigPtr cfg = NULL;
virCapsPtr caps = NULL;
- bool was_running = false;
- bool was_stopped = false;
+ int oldState = vm->state.state;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED |
@@ -14187,24 +14183,18 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
qemuDomainSnapshotEmitLifecycleEvent(driver, vm,
vm->state.state,
VIR_DOMAIN_SHUTOFF);
+ oldState = VIR_DOMAIN_SHUTOFF;
goto load;
}
priv = vm->privateData;
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
/* Transitions 5, 6 */
- was_running = true;
if (qemuProcessStopCPUs(driver, vm,
VIR_DOMAIN_PAUSED_FROM_SNAPSHOT,
QEMU_ASYNC_JOB_NONE) < 0)
goto endjob;
- /* Create an event now in case the restore fails, so
- * that user will be alerted that they are now paused.
- * If restore later succeeds, we might replace this. */
- detail = VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT;
- event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_SUSPENDED,
- detail);
+
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("guest unexpectedly quit"));
@@ -14224,7 +14214,6 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
} else {
/* Transitions 2, 3 */
load:
- was_stopped = true;
if (config)
virDomainObjAssignDef(vm, config, false, NULL);
@@ -14233,10 +14222,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
VIR_QEMU_PROCESS_START_PAUSED);
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
- detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
- event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_STARTED,
- detail);
+
if (rc < 0)
goto endjob;
}
@@ -14248,13 +14234,6 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
/* Transitions 3, 6, 9 */
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
VIR_DOMAIN_PAUSED_FROM_SNAPSHOT);
- if (was_stopped) {
- /* Transition 3, use event as-is and add event2 */
- detail = VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT;
- event2 = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_SUSPENDED,
- detail);
- } /* else transition 6 and 9 use event as-is */
} else {
/* Transitions 2, 5, 8 */
if (!virDomainObjIsActive(vm)) {
@@ -14267,21 +14246,6 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
QEMU_ASYNC_JOB_NONE);
if (rc < 0)
goto endjob;
- virObjectUnref(event);
- event = NULL;
- if (was_stopped) {
- /* Transition 2 */
- detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
- event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_STARTED,
- detail);
- } else if (was_running) {
- /* Transition 8 */
- detail = VIR_DOMAIN_EVENT_RESUMED;
- event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_RESUMED,
- detail);
- }
}
break;
@@ -14300,10 +14264,9 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
/* Transitions 4, 7 */
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT, 0);
virDomainAuditStop(vm, "from-snapshot");
- detail = VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT;
- event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_STOPPED,
- detail);
+ qemuDomainSnapshotEmitLifecycleEvent(driver, vm, vm->state.state,
+ VIR_DOMAIN_SHUTOFF);
+ oldState = VIR_DOMAIN_SHUTOFF;
}
if (qemuDomainSnapshotRevertInactive(driver, vm, snap) < 0) {
@@ -14326,8 +14289,6 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
start_flags |= paused ? VIR_QEMU_PROCESS_START_PAUSED : 0;
- if (event)
- qemuDomainEventQueue(driver, event);
rc = qemuProcessStart(snapshot->domain->conn,
driver, vm, NULL, -1, NULL, NULL,
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
@@ -14342,16 +14303,6 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
}
goto endjob;
}
- detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
- event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_STARTED,
- detail);
- if (paused) {
- detail = VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT;
- event2 = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_SUSPENDED,
- detail);
- }
}
break;
@@ -14381,13 +14332,12 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
} else if (snap) {
snap->def->current = false;
}
- if (event) {
- qemuDomainEventQueue(driver, event);
- if (event2)
- qemuDomainEventQueue(driver, event2);
- }
- if (vm)
- virObjectUnlock(vm);
+
+ /* emit all appropriate events */
+ qemuDomainSnapshotEmitLifecycleEvent(driver, vm, oldState,
+ vm->state.state);
+
+ virObjectUnlock(vm);
virObjectUnref(caps);
virObjectUnref(cfg);
--
2.0.0