提交 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>
&lt;power_management&gt;
&lt;S3/&gt;
&lt;S4/&gt;
&lt;Hybrid-Suspend/&gt;
&lt;power_management/&gt;
&lt;/host&gt;</span>
......@@ -71,8 +72,9 @@ BIOS you will see</p>
model, within a feature block (the block is similar to what
you will find in a Xen fully virtualized domain
description). Further, the power management features
supported by the host are shown, such as Suspend-to-RAM (S3)
and Suspend-to-Disk (S4). In case the query for power
supported by the host are shown, such as Suspend-to-RAM (S3),
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
any such feature, then an empty &lt;power_management/&gt;
tag will be shown. Otherwise, if the query itself failed, no
......
......@@ -121,6 +121,11 @@
<empty/>
</element>
</optional>
<optional>
<element name='Hybrid-Suspend'>
<empty/>
</element>
</optional>
</interleave>
</element>
</define>
......
......@@ -37,7 +37,7 @@
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
VIR_ENUM_IMPL(virHostPMCapability, VIR_HOST_PM_LAST,
"S3", "S4")
"S3", "S4", "Hybrid-Suspend")
/**
* virCapabilitiesNew:
......
......@@ -2623,47 +2623,50 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
}
/**
* Get the Power Management Capabilities of the host system.
* The script 'pm-is-supported' (from the pm-utils package) is run
* to find out all the power management features supported by the host,
* such as Suspend-to-RAM (S3) and Suspend-to-Disk (S4).
* virDiscoverHostPMFeature:
* @bitmask: The bitmask which should be populated with the result of
* the query
* @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
* indicate all the supported host power management features.
* Run the script 'pm-is-supported' (from the pm-utils package)
* 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
virGetPMCapabilities(unsigned int *bitmask)
virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature)
{
int ret = -1;
int status;
virCommandPtr cmd;
int status;
int ret = -1;
*bitmask = 0;
/* Check support for Suspend-to-RAM (S3) */
cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
if (virCommandRun(cmd, &status) < 0)
goto cleanup;
/* 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);
switch (feature) {
case VIR_HOST_PM_S3:
cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
break;
case VIR_HOST_PM_S4:
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;
}
/* Check support for Suspend-to-Disk (S4) */
cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
if (virCommandRun(cmd, &status) < 0)
goto cleanup;
/* Check return code of command == 0 for success
* (i.e., the PM capability is supported)
*/
/*
* Check return code of command == 0 for success
* (i.e., the PM capability is supported)
*/
if (status == 0)
*bitmask |= 1U << VIR_HOST_PM_S4;
*bitmask |= 1U << feature;
ret = 0;
......@@ -2671,3 +2674,40 @@ cleanup:
virCommandFree(cmd);
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;
}
......@@ -264,14 +264,16 @@ void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams);
/* Power Management Capabilities of the host system */
enum virHostPMCapability {
VIR_HOST_PM_S3, /* Suspend-to-RAM */
VIR_HOST_PM_S4, /* Suspend-to-Disk */
VIR_HOST_PM_S3, /* Suspend-to-RAM */
VIR_HOST_PM_S4, /* Suspend-to-Disk */
VIR_HOST_PM_HYBRID_SUSPEND, /* Hybrid-Suspend */
VIR_HOST_PM_LAST
};
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__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册