提交 1ceb0e93 编写于 作者: E Eric Blake

qemu: Use virDomainSnapshotState for switch statements

Clean up the previous patch which abused switch on virDomainState
while working with a variable containing virDomainSnapshotState, by
converting the two affected switch statements to now use the right
enum.
Signed-off-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 f43eb680
......@@ -15681,7 +15681,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
virQEMUDriverConfigPtr cfg = NULL;
virCapsPtr caps = NULL;
qemuDomainObjPrivatePtr priv;
virDomainState state;
virDomainSnapshotState state;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT |
......@@ -15767,36 +15767,36 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
}
/* allow snapshots only in certain states */
state = vm->state.state;
if (redefine)
state = def->state == VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT ? VIR_DOMAIN_SHUTOFF :
def->state;
/* FIXME: state should be virDomainSnapshotState, with the switch
* statement handling of VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT (the only
* enum value added beyond what virDomainState supports). But for
* now it doesn't matter, because we slammed the extra snapshot
* state into a safe domain state. */
state = redefine ? def->state : vm->state.state;
switch (state) {
/* valid states */
case VIR_DOMAIN_RUNNING:
case VIR_DOMAIN_PAUSED:
case VIR_DOMAIN_SHUTDOWN:
case VIR_DOMAIN_SHUTOFF:
case VIR_DOMAIN_CRASHED:
case VIR_DOMAIN_SNAPSHOT_RUNNING:
case VIR_DOMAIN_SNAPSHOT_PAUSED:
case VIR_DOMAIN_SNAPSHOT_SHUTDOWN:
case VIR_DOMAIN_SNAPSHOT_SHUTOFF:
case VIR_DOMAIN_SNAPSHOT_CRASHED:
break;
case VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT:
if (!redefine) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"),
virDomainSnapshotStateTypeToString(state));
goto cleanup;
}
break;
case VIR_DOMAIN_PMSUSPENDED:
case VIR_DOMAIN_SNAPSHOT_PMSUSPENDED:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("qemu doesn't support taking snapshots of "
"PMSUSPENDED guests"));
goto cleanup;
/* invalid states */
case VIR_DOMAIN_NOSTATE:
case VIR_DOMAIN_BLOCKED: /* invalid state, unused in qemu */
case VIR_DOMAIN_LAST:
case VIR_DOMAIN_SNAPSHOT_NOSTATE:
case VIR_DOMAIN_SNAPSHOT_BLOCKED: /* invalid state, unused in qemu */
case VIR_DOMAIN_SNAPSHOT_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid domain state %s"),
virDomainStateTypeToString(state));
virDomainSnapshotStateTypeToString(state));
goto cleanup;
}
......@@ -16474,14 +16474,9 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
cookie = (qemuDomainSaveCookiePtr) snap->def->cookie;
/* FIXME: This cast should be to virDomainSnapshotState, with
* better handling of VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT (the only enum
* value added beyond what virDomainState supports). But for now
* it doesn't matter, because of the above rejection of revert to
* external snapshots. */
switch ((virDomainState) snap->def->state) {
case VIR_DOMAIN_RUNNING:
case VIR_DOMAIN_PAUSED:
switch ((virDomainSnapshotState) snap->def->state) {
case VIR_DOMAIN_SNAPSHOT_RUNNING:
case VIR_DOMAIN_SNAPSHOT_PAUSED:
start_flags |= VIR_QEMU_PROCESS_START_PAUSED;
......@@ -16656,9 +16651,9 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
}
break;
case VIR_DOMAIN_SHUTDOWN:
case VIR_DOMAIN_SHUTOFF:
case VIR_DOMAIN_CRASHED:
case VIR_DOMAIN_SNAPSHOT_SHUTDOWN:
case VIR_DOMAIN_SNAPSHOT_SHUTOFF:
case VIR_DOMAIN_SNAPSHOT_CRASHED:
/* Transitions 1, 4, 7 */
/* Newer qemu -loadvm refuses to revert to the state of a snapshot
* created by qemu-img snapshot -c. If the domain is running, we
......@@ -16715,15 +16710,17 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
}
break;
case VIR_DOMAIN_PMSUSPENDED:
case VIR_DOMAIN_SNAPSHOT_PMSUSPENDED:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("qemu doesn't support reversion of snapshot taken in "
"PMSUSPENDED state"));
goto endjob;
case VIR_DOMAIN_NOSTATE:
case VIR_DOMAIN_BLOCKED:
case VIR_DOMAIN_LAST:
case VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT:
/* Rejected earlier as an external snapshot */
case VIR_DOMAIN_SNAPSHOT_NOSTATE:
case VIR_DOMAIN_SNAPSHOT_BLOCKED:
case VIR_DOMAIN_SNAPSHOT_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid target domain state '%s'. Refusing "
"snapshot reversion"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册