diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c index 9ffabd63e3fe7e1569fc4cbc6ca93c29596f91de..5a6ef1d41c72b75ee6480b003512bfab4560f7ac 100644 --- a/examples/domain-events/events-c/event-test.c +++ b/examples/domain-events/events-c/event-test.c @@ -93,6 +93,9 @@ static const char *eventDetailToString(int event, int detail) { case VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT: ret = "Snapshot"; break; + case VIR_DOMAIN_EVENT_STARTED_WAKEUP: + ret = "Event wakeup"; + break; } break; case VIR_DOMAIN_EVENT_SUSPENDED: diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 12ba63f2d3a206646f3b4b7a1ba54acc3c4b244d..c702e663193b537b54881d3e0770b75ab429835d 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -123,6 +123,8 @@ typedef enum { VIR_DOMAIN_RUNNING_UNPAUSED = 5, /* returned from paused state */ VIR_DOMAIN_RUNNING_MIGRATION_CANCELED = 6, /* returned from migration */ VIR_DOMAIN_RUNNING_SAVE_CANCELED = 7, /* returned from failed save process */ + VIR_DOMAIN_RUNNING_WAKEUP = 8, /* returned from pmsuspended due to + wakeup event */ #ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_RUNNING_LAST @@ -2695,6 +2697,7 @@ typedef enum { VIR_DOMAIN_EVENT_STARTED_MIGRATED = 1, /* Incoming migration from another host */ VIR_DOMAIN_EVENT_STARTED_RESTORED = 2, /* Restored from a state file */ VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT = 3, /* Restored from snapshot */ + VIR_DOMAIN_EVENT_STARTED_WAKEUP = 4, /* Started due to wakeup event */ #ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_EVENT_STARTED_LAST diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2e873ecb8fe1c82ce58bad3f1fdd7944f777bdea..88b128b6e09548da9cc0d6dac58231636a0f2b92 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1067,15 +1067,38 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon ATTRIBUTE_UNUSED, { struct qemud_driver *driver = qemu_driver; virDomainEventPtr event = NULL; + virDomainEventPtr lifecycleEvent = NULL; virDomainObjLock(vm); event = virDomainEventPMWakeupNewFromObj(vm); + /* Don't set domain status back to running if it wasn't paused + * from guest side, otherwise it can just cause confusion. + */ + if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PMSUSPENDED) { + VIR_DEBUG("Transitioned guest %s from pmsuspended to running " + "state due to QMP wakeup event", vm->def->name); + + virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, + VIR_DOMAIN_RUNNING_WAKEUP); + lifecycleEvent = virDomainEventNewFromObj(vm, + VIR_DOMAIN_EVENT_STARTED, + VIR_DOMAIN_EVENT_STARTED_WAKEUP); + + if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) { + VIR_WARN("Unable to save status on vm %s after wakeup event", + vm->def->name); + } + } + virDomainObjUnlock(vm); - if (event) { + if (event || lifecycleEvent) { qemuDriverLock(driver); - qemuDomainEventQueue(driver, event); + if (event) + qemuDomainEventQueue(driver, event); + if (lifecycleEvent) + qemuDomainEventQueue(driver, lifecycleEvent); qemuDriverUnlock(driver); } diff --git a/tools/virsh.c b/tools/virsh.c index 49bfa7adff8b82ef613ac404373ec419ccf490f0..96bea39028c3a2e8ede2d40e3891104dc36dfd5e 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -18859,6 +18859,8 @@ vshDomainStateReasonToString(int state, int reason) return N_("migration canceled"); case VIR_DOMAIN_RUNNING_SAVE_CANCELED: return N_("save canceled"); + case VIR_DOMAIN_RUNNING_WAKEUP: + return N_("event wakeup"); case VIR_DOMAIN_RUNNING_UNKNOWN: case VIR_DOMAIN_RUNNING_LAST: ;