From 54d9026a2ca1338970c310e4faa7c671b511e1f9 Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Wed, 14 Mar 2012 23:26:53 +0800 Subject: [PATCH] New domain state pmsuspended This introduces a new domain state pmsuspended to represent the domain which has been suspended by guest power management, e.g. (entered itno s3 state). Because a "running" state could be confused in this case, one will see the guest is paused actually while playing. And state "paused" is for the domain which was paused by virDomainSuspend. --- include/libvirt/libvirt.h.in | 23 +++++++++++++++------- src/conf/domain_conf.c | 38 +++++++++++++++++++++++++++--------- tools/virsh.c | 10 ++++++++++ tools/virsh.pod | 7 ++++++- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index caf5085b9b..12ba63f2d3 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -86,13 +86,15 @@ typedef virDomain *virDomainPtr; * A domain may be in different states at a given point in time */ typedef enum { - VIR_DOMAIN_NOSTATE = 0, /* no state */ - VIR_DOMAIN_RUNNING = 1, /* the domain is running */ - VIR_DOMAIN_BLOCKED = 2, /* the domain is blocked on resource */ - VIR_DOMAIN_PAUSED = 3, /* the domain is paused by user */ - VIR_DOMAIN_SHUTDOWN= 4, /* the domain is being shut down */ - VIR_DOMAIN_SHUTOFF = 5, /* the domain is shut off */ - VIR_DOMAIN_CRASHED = 6, /* the domain is crashed */ + VIR_DOMAIN_NOSTATE = 0, /* no state */ + VIR_DOMAIN_RUNNING = 1, /* the domain is running */ + VIR_DOMAIN_BLOCKED = 2, /* the domain is blocked on resource */ + VIR_DOMAIN_PAUSED = 3, /* the domain is paused by user */ + VIR_DOMAIN_SHUTDOWN= 4, /* the domain is being shut down */ + VIR_DOMAIN_SHUTOFF = 5, /* the domain is shut off */ + VIR_DOMAIN_CRASHED = 6, /* the domain is crashed */ + VIR_DOMAIN_PMSUSPENDED = 7, /* the domain is suspended by guest + power management */ #ifdef VIR_ENUM_SENTINELS /* @@ -183,6 +185,13 @@ typedef enum { #endif } virDomainCrashedReason; +typedef enum { + VIR_DOMAIN_PMSUSPENDED_UNKNOWN = 0, + +#ifdef VIR_ENUM_SENTINELS + VIR_DOMAIN_PMSUSPENDED_LAST +#endif +} virDomainPMSuspendedReason; /** * virDomainControlState: diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d6fe4ca70d..3921c0f072 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -512,7 +512,8 @@ VIR_ENUM_IMPL(virDomainState, VIR_DOMAIN_LAST, "paused", "shutdown", "shutoff", - "crashed") + "crashed", + "pmsuspended") /* virDomainSnapshotState is really virDomainState plus one extra state */ VIR_ENUM_IMPL(virDomainSnapshotState, VIR_DOMAIN_SNAPSHOT_STATE_LAST, @@ -523,6 +524,7 @@ VIR_ENUM_IMPL(virDomainSnapshotState, VIR_DOMAIN_SNAPSHOT_STATE_LAST, "shutdown", "shutoff", "crashed", + "pmsuspended", "disk-snapshot") #define VIR_DOMAIN_NOSTATE_LAST (VIR_DOMAIN_NOSTATE_UNKNOWN + 1) @@ -14369,14 +14371,32 @@ virDomainObjSetState(virDomainObjPtr dom, virDomainState state, int reason) int last = -1; switch (state) { - case VIR_DOMAIN_NOSTATE: last = VIR_DOMAIN_NOSTATE_LAST; break; - case VIR_DOMAIN_RUNNING: last = VIR_DOMAIN_RUNNING_LAST; break; - case VIR_DOMAIN_BLOCKED: last = VIR_DOMAIN_BLOCKED_LAST; break; - case VIR_DOMAIN_PAUSED: last = VIR_DOMAIN_PAUSED_LAST; break; - case VIR_DOMAIN_SHUTDOWN: last = VIR_DOMAIN_SHUTDOWN_LAST; break; - case VIR_DOMAIN_SHUTOFF: last = VIR_DOMAIN_SHUTOFF_LAST; break; - case VIR_DOMAIN_CRASHED: last = VIR_DOMAIN_CRASHED_LAST; break; - default: last = -1; + case VIR_DOMAIN_NOSTATE: + last = VIR_DOMAIN_NOSTATE_LAST; + break; + case VIR_DOMAIN_RUNNING: + last = VIR_DOMAIN_RUNNING_LAST; + break; + case VIR_DOMAIN_BLOCKED: + last = VIR_DOMAIN_BLOCKED_LAST; + break; + case VIR_DOMAIN_PAUSED: + last = VIR_DOMAIN_PAUSED_LAST; + break; + case VIR_DOMAIN_SHUTDOWN: + last = VIR_DOMAIN_SHUTDOWN_LAST; + break; + case VIR_DOMAIN_SHUTOFF: + last = VIR_DOMAIN_SHUTOFF_LAST; + break; + case VIR_DOMAIN_CRASHED: + last = VIR_DOMAIN_CRASHED_LAST; + break; + case VIR_DOMAIN_PMSUSPENDED: + last = VIR_DOMAIN_PMSUSPENDED_LAST; + break; + default: + last = -1; } if (last < 0) { diff --git a/tools/virsh.c b/tools/virsh.c index 9e5c9b2e57..49bfa7adff 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -18822,6 +18822,8 @@ vshDomainStateToString(int state) return N_("shut off"); case VIR_DOMAIN_CRASHED: return N_("crashed"); + case VIR_DOMAIN_PMSUSPENDED: + return N_("pmsuspended"); case VIR_DOMAIN_NOSTATE: default: ;/*FALLTHROUGH*/ @@ -18935,6 +18937,14 @@ vshDomainStateReasonToString(int state, int reason) } break; + case VIR_DOMAIN_PMSUSPENDED: + switch ((virDomainPMSuspendedReason) reason) { + case VIR_DOMAIN_PMSUSPENDED_UNKNOWN: + case VIR_DOMAIN_PMSUSPENDED_LAST: + ; + } + break; + case VIR_DOMAIN_LAST: ; } diff --git a/tools/virsh.pod b/tools/virsh.pod index a8bd739778..f0c58706df 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -328,7 +328,7 @@ State is the run state (see below). B -The State field lists 7 states for a domain, and which ones the +The State field lists 8 states for a domain, and which ones the current domain is in. =over 4 @@ -372,6 +372,11 @@ restart on crash. The domain is in process of dying, but hasn't completely shutdown or crashed. +=item B + +The domain has been suspended by guest power management, e.g. entered +into s3 state. + =back If I<--managed-save> is specified, then domains that have managed save