qemu: Introduce shutdown reason for paused state

Qemu sends STOP event as part of the shutdown process. Detect such STOP
event and consider shutdown to be reason of emitting such event. That's
the best we can do until qemu provides us the reason directly in STOP
event. This allows us to report shutdown reason for paused state so that
apps can detect domains that failed to finish the shutdown process
(e.g., because qemu is buggy and doesn't exit on SIGTERM or it is
blocked in flushing disk buffers).
This commit is contained in:
Jiri Denemark 2011-09-15 15:07:51 +02:00
parent 96fc478417
commit d2d6776342
5 changed files with 29 additions and 5 deletions

View File

@ -124,6 +124,7 @@ typedef enum {
VIR_DOMAIN_PAUSED_IOERROR = 5, /* paused due to a disk I/O error */
VIR_DOMAIN_PAUSED_WATCHDOG = 6, /* paused due to a watchdog event */
VIR_DOMAIN_PAUSED_FROM_SNAPSHOT = 7, /* paused after restoring from snapshot */
VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */
} virDomainPausedReason;
typedef enum {

View File

@ -487,7 +487,7 @@ VIR_ENUM_IMPL(virDomainRunningReason, VIR_DOMAIN_RUNNING_LAST,
VIR_ENUM_IMPL(virDomainBlockedReason, VIR_DOMAIN_BLOCKED_LAST,
"unknown")
#define VIR_DOMAIN_PAUSED_LAST (VIR_DOMAIN_PAUSED_FROM_SNAPSHOT + 1)
#define VIR_DOMAIN_PAUSED_LAST (VIR_DOMAIN_PAUSED_SHUTTING_DOWN + 1)
VIR_ENUM_IMPL(virDomainPausedReason, VIR_DOMAIN_PAUSED_LAST,
"unknown",
"user",
@ -496,7 +496,8 @@ VIR_ENUM_IMPL(virDomainPausedReason, VIR_DOMAIN_PAUSED_LAST,
"dump",
"ioerror",
"watchdog",
"from snapshot")
"from snapshot",
"shutdown")
#define VIR_DOMAIN_SHUTDOWN_LAST (VIR_DOMAIN_SHUTDOWN_USER + 1)
VIR_ENUM_IMPL(virDomainShutdownReason, VIR_DOMAIN_SHUTDOWN_LAST,

View File

@ -231,6 +231,8 @@ virDiskNameToBusDeviceIndex;
virDiskNameToIndex;
virDomainActualNetDefFree;
virDomainAssignDef;
virDomainBlockedReasonTypeFromString;
virDomainBlockedReasonTypeToString;
virDomainChrConsoleTargetTypeFromString;
virDomainChrConsoleTargetTypeToString;
virDomainChrDefForeach;
@ -360,6 +362,8 @@ virDomainNetIndexByMac;
virDomainNetInsert;
virDomainNetRemoveByMac;
virDomainNetTypeToString;
virDomainNostateReasonTypeFromString;
virDomainNostateReasonTypeToString;
virDomainNumatuneMemModeTypeFromString;
virDomainNumatuneMemModeTypeToString;
virDomainObjAssignDef;
@ -379,12 +383,20 @@ virDomainObjSetState;
virDomainObjTaint;
virDomainObjUnlock;
virDomainObjUnref;
virDomainPausedReasonTypeFromString;
virDomainPausedReasonTypeToString;
virDomainRedirdevBusTypeFromString;
virDomainRedirdevBusTypeToString;
virDomainRemoveInactive;
virDomainRunningReasonTypeFromString;
virDomainRunningReasonTypeToString;
virDomainSaveConfig;
virDomainSaveStatus;
virDomainSaveXML;
virDomainShutdownReasonTypeFromString;
virDomainShutdownReasonTypeToString;
virDomainShutoffReasonTypeFromString;
virDomainShutoffReasonTypeToString;
virDomainSmartcardDefForeach;
virDomainSmartcardDefFree;
virDomainSmartcardTypeFromString;

View File

@ -473,14 +473,22 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
{
struct qemud_driver *driver = qemu_driver;
virDomainEventPtr event = NULL;
virDomainPausedReason reason = VIR_DOMAIN_PAUSED_UNKNOWN;
virDomainObjLock(vm);
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
qemuDomainObjPrivatePtr priv = vm->privateData;
VIR_DEBUG("Transitioned guest %s to paused state due to unknown event",
vm->def->name);
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_UNKNOWN);
if (priv->gotShutdown) {
VIR_DEBUG("Got STOP event after SHUTDOWN, assuming we are stopping"
" for shutdown");
reason = VIR_DOMAIN_PAUSED_SHUTTING_DOWN;
}
VIR_DEBUG("Transitioned guest %s to paused state, reason=%s",
vm->def->name, virDomainPausedReasonTypeToString(reason));
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, reason);
event = virDomainEventNewFromObj(vm,
VIR_DOMAIN_EVENT_SUSPENDED,
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);

View File

@ -15151,6 +15151,8 @@ vshDomainStateReasonToString(int state, int reason)
return N_("watchdog");
case VIR_DOMAIN_PAUSED_FROM_SNAPSHOT:
return N_("from snapshot");
case VIR_DOMAIN_PAUSED_SHUTTING_DOWN:
return N_("shutting down");
case VIR_DOMAIN_PAUSED_UNKNOWN:
;
}