mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
qemu: hide details of fake reboot
If we use fake reboot then domain goes thru running->shutdown->running state changes with shutdown state only for short period of time. At least this is implementation details leaking into API. And also there is one real case when this is not convinient. I'm doing a backup with the help of temporary block snapshot (with the help of qemu's API which is used in the newly created libvirt's backup API). If guest is shutdowned I want to continue to backup so I don't kill the process and domain is in shutdown state. Later when backup is finished I want to destroy qemu process. So I check if it is in shutdowned state and destroy it if it is. Now if instead of shutdown domain got fake reboot then I can destroy process in the middle of fake reboot process. After shutdown event we also get stop event and now as domain state is running it will be transitioned to paused state and back to running later. Though this is not critical for the described case I guess it is better not to leak these details to user too. So let's leave domain in running state on stop event if fake reboot is in process. Reconnection code handles this patch without modification. It detects that qemu is not running due to shutdown and then calls qemuProcessShutdownOrReboot which reboots as fake reboot flag is set. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com> Reviewed-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
546e1c112d
commit
6c6d93bc62
@ -319,6 +319,7 @@ struct _qemuDomainObjPrivate {
|
||||
char *lockState;
|
||||
|
||||
bool fakeReboot;
|
||||
bool pausedShutdown;
|
||||
virTristateBool allowReboot;
|
||||
|
||||
int jobs_queued;
|
||||
|
@ -501,6 +501,7 @@ qemuProcessFakeReboot(void *opaque)
|
||||
qemuDomainObjEndJob(driver, vm);
|
||||
|
||||
cleanup:
|
||||
priv->pausedShutdown = false;
|
||||
if (ret == -1)
|
||||
ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE));
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -523,6 +524,7 @@ qemuProcessShutdownOrReboot(virQEMUDriverPtr driver,
|
||||
vm) < 0) {
|
||||
VIR_ERROR(_("Failed to create reboot thread, killing domain"));
|
||||
ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_NOWAIT));
|
||||
priv->pausedShutdown = false;
|
||||
virObjectUnref(vm);
|
||||
}
|
||||
} else {
|
||||
@ -584,35 +586,41 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon G_GNUC_UNUSED,
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
VIR_DEBUG("Transitioned guest %s to shutdown state",
|
||||
vm->def->name);
|
||||
virDomainObjSetState(vm,
|
||||
VIR_DOMAIN_SHUTDOWN,
|
||||
VIR_DOMAIN_SHUTDOWN_UNKNOWN);
|
||||
/* In case of fake reboot qemu shutdown state is transient so don't
|
||||
* change domain state nor send events. */
|
||||
if (!priv->fakeReboot) {
|
||||
VIR_DEBUG("Transitioned guest %s to shutdown state",
|
||||
vm->def->name);
|
||||
virDomainObjSetState(vm,
|
||||
VIR_DOMAIN_SHUTDOWN,
|
||||
VIR_DOMAIN_SHUTDOWN_UNKNOWN);
|
||||
|
||||
switch (guest_initiated) {
|
||||
case VIR_TRISTATE_BOOL_YES:
|
||||
detail = VIR_DOMAIN_EVENT_SHUTDOWN_GUEST;
|
||||
break;
|
||||
switch (guest_initiated) {
|
||||
case VIR_TRISTATE_BOOL_YES:
|
||||
detail = VIR_DOMAIN_EVENT_SHUTDOWN_GUEST;
|
||||
break;
|
||||
|
||||
case VIR_TRISTATE_BOOL_NO:
|
||||
detail = VIR_DOMAIN_EVENT_SHUTDOWN_HOST;
|
||||
break;
|
||||
case VIR_TRISTATE_BOOL_NO:
|
||||
detail = VIR_DOMAIN_EVENT_SHUTDOWN_HOST;
|
||||
break;
|
||||
|
||||
case VIR_TRISTATE_BOOL_ABSENT:
|
||||
case VIR_TRISTATE_BOOL_LAST:
|
||||
default:
|
||||
detail = VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED;
|
||||
break;
|
||||
}
|
||||
case VIR_TRISTATE_BOOL_ABSENT:
|
||||
case VIR_TRISTATE_BOOL_LAST:
|
||||
default:
|
||||
detail = VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED;
|
||||
break;
|
||||
}
|
||||
|
||||
event = virDomainEventLifecycleNewFromObj(vm,
|
||||
VIR_DOMAIN_EVENT_SHUTDOWN,
|
||||
detail);
|
||||
event = virDomainEventLifecycleNewFromObj(vm,
|
||||
VIR_DOMAIN_EVENT_SHUTDOWN,
|
||||
detail);
|
||||
|
||||
if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) {
|
||||
VIR_WARN("Unable to save status on vm %s after state change",
|
||||
vm->def->name);
|
||||
if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) {
|
||||
VIR_WARN("Unable to save status on vm %s after state change",
|
||||
vm->def->name);
|
||||
}
|
||||
} else {
|
||||
priv->pausedShutdown = true;
|
||||
}
|
||||
|
||||
if (priv->agent)
|
||||
@ -645,7 +653,10 @@ qemuProcessHandleStop(qemuMonitorPtr mon G_GNUC_UNUSED,
|
||||
reason = priv->pausedReason;
|
||||
priv->pausedReason = VIR_DOMAIN_PAUSED_UNKNOWN;
|
||||
|
||||
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
|
||||
/* In case of fake reboot qemu paused state is transient so don't
|
||||
* reveal it in domain state nor sent events */
|
||||
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING &&
|
||||
!priv->pausedShutdown) {
|
||||
if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT) {
|
||||
if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY)
|
||||
reason = VIR_DOMAIN_PAUSED_POSTCOPY;
|
||||
|
Loading…
Reference in New Issue
Block a user