提交 302743f1 编写于 作者: S Srivatsa S. Bhat 提交者: Daniel Veillard

Add 'Hybrid-Suspend' power management discovery for the host

Some systems support a feature known as 'Hybrid-Suspend', apart from the
usual system-wide sleep states such as Suspend-to-RAM (S3) or Suspend-to-Disk
(S4). Add the functionality to discover this power management feature and
export it in the capabilities XML under the <power_management> tag.
上级 4e511fcc
...@@ -31,6 +31,7 @@ BIOS you will see</p> ...@@ -31,6 +31,7 @@ BIOS you will see</p>
&lt;power_management&gt; &lt;power_management&gt;
&lt;S3/&gt; &lt;S3/&gt;
&lt;S4/&gt; &lt;S4/&gt;
&lt;Hybrid-Suspend/&gt;
&lt;power_management/&gt; &lt;power_management/&gt;
&lt;/host&gt;</span> &lt;/host&gt;</span>
...@@ -71,8 +72,9 @@ BIOS you will see</p> ...@@ -71,8 +72,9 @@ BIOS you will see</p>
model, within a feature block (the block is similar to what model, within a feature block (the block is similar to what
you will find in a Xen fully virtualized domain you will find in a Xen fully virtualized domain
description). Further, the power management features description). Further, the power management features
supported by the host are shown, such as Suspend-to-RAM (S3) supported by the host are shown, such as Suspend-to-RAM (S3),
and Suspend-to-Disk (S4). In case the query for power Suspend-to-Disk (S4) and Hybrid-Suspend (a combination of S3
and S4). In case the query for power
management features succeeded but the host does not support management features succeeded but the host does not support
any such feature, then an empty &lt;power_management/&gt; any such feature, then an empty &lt;power_management/&gt;
tag will be shown. Otherwise, if the query itself failed, no tag will be shown. Otherwise, if the query itself failed, no
......
...@@ -121,6 +121,11 @@ ...@@ -121,6 +121,11 @@
<empty/> <empty/>
</element> </element>
</optional> </optional>
<optional>
<element name='Hybrid-Suspend'>
<empty/>
</element>
</optional>
</interleave> </interleave>
</element> </element>
</define> </define>
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES #define VIR_FROM_THIS VIR_FROM_CAPABILITIES
VIR_ENUM_IMPL(virHostPMCapability, VIR_HOST_PM_LAST, VIR_ENUM_IMPL(virHostPMCapability, VIR_HOST_PM_LAST,
"S3", "S4") "S3", "S4", "Hybrid-Suspend")
/** /**
* virCapabilitiesNew: * virCapabilitiesNew:
......
...@@ -2623,47 +2623,50 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams) ...@@ -2623,47 +2623,50 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
} }
/** /**
* Get the Power Management Capabilities of the host system. * virDiscoverHostPMFeature:
* The script 'pm-is-supported' (from the pm-utils package) is run * @bitmask: The bitmask which should be populated with the result of
* to find out all the power management features supported by the host, * the query
* such as Suspend-to-RAM (S3) and Suspend-to-Disk (S4). * @feature: The power management feature to check whether it is supported
* by the host. Values could be:
* VIR_HOST_PM_S3 for Suspend-to-RAM
* VIR_HOST_PM_S4 for Suspend-to-Disk
* VIR_HOST_PM_HYBRID_SUSPEND for Hybrid-Suspend
* *
* @bitmask: Pointer to the bitmask which will be set appropriately to * Run the script 'pm-is-supported' (from the pm-utils package)
* indicate all the supported host power management features. * to find out if @feature is supported by the host.
* *
* Returns 0 if the query was successful, -1 upon failure. * Returns 0 if the query was successful, -1 on failure.
*/ */
int int
virGetPMCapabilities(unsigned int *bitmask) virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature)
{ {
int ret = -1;
int status;
virCommandPtr cmd; virCommandPtr cmd;
int status;
int ret = -1;
*bitmask = 0; switch (feature) {
case VIR_HOST_PM_S3:
/* Check support for Suspend-to-RAM (S3) */
cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL); cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
if (virCommandRun(cmd, &status) < 0) break;
goto cleanup; case VIR_HOST_PM_S4:
/* Check return code of command == 0 for success
* (i.e., the PM capability is supported)
*/
if (status == 0)
*bitmask |= 1U << VIR_HOST_PM_S3;
virCommandFree(cmd);
/* Check support for Suspend-to-Disk (S4) */
cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL); cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
break;
case VIR_HOST_PM_HYBRID_SUSPEND:
cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
break;
default:
return ret;
}
if (virCommandRun(cmd, &status) < 0) if (virCommandRun(cmd, &status) < 0)
goto cleanup; goto cleanup;
/* Check return code of command == 0 for success /*
* Check return code of command == 0 for success
* (i.e., the PM capability is supported) * (i.e., the PM capability is supported)
*/ */
if (status == 0) if (status == 0)
*bitmask |= 1U << VIR_HOST_PM_S4; *bitmask |= 1U << feature;
ret = 0; ret = 0;
...@@ -2671,3 +2674,40 @@ cleanup: ...@@ -2671,3 +2674,40 @@ cleanup:
virCommandFree(cmd); virCommandFree(cmd);
return ret; return ret;
} }
/**
* virGetPMCapabilities:
*
* Get the Power Management Capabilities that the host system supports,
* such as Suspend-to-RAM (S3), Suspend-to-Disk (S4) and Hybrid-Suspend
* (a combination of S3 and S4).
*
* @bitmask: Pointer to the bitmask which will be set appropriately to
* indicate all the supported host power management features.
*
* Returns 0 if the query was successful, -1 on failure.
*/
int
virGetPMCapabilities(unsigned int *bitmask)
{
int ret;
*bitmask = 0;
/* Check support for Suspend-to-RAM (S3) */
ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_S3);
if (ret < 0)
return -1;
/* Check support for Suspend-to-Disk (S4) */
ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_S4);
if (ret < 0)
return -1;
/* Check support for Hybrid-Suspend */
ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_HYBRID_SUSPEND);
if (ret < 0)
return -1;
return 0;
}
...@@ -266,12 +266,14 @@ void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams); ...@@ -266,12 +266,14 @@ void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams);
enum virHostPMCapability { enum virHostPMCapability {
VIR_HOST_PM_S3, /* Suspend-to-RAM */ VIR_HOST_PM_S3, /* Suspend-to-RAM */
VIR_HOST_PM_S4, /* Suspend-to-Disk */ VIR_HOST_PM_S4, /* Suspend-to-Disk */
VIR_HOST_PM_HYBRID_SUSPEND, /* Hybrid-Suspend */
VIR_HOST_PM_LAST VIR_HOST_PM_LAST
}; };
VIR_ENUM_DECL(virHostPMCapability) VIR_ENUM_DECL(virHostPMCapability)
int virGetPMCapabilities(unsigned int *); int virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature);
int virGetPMCapabilities(unsigned int *bitmask);
#endif /* __VIR_UTIL_H__ */ #endif /* __VIR_UTIL_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册