mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-24 12:22:20 +00:00
Sanitize virDiscoverHostPMFeature to return a boolean
Since virDiscoverHostPMFeature is just checking one feature, there is no reason for it to return a bitmask. Change it to return a boolean * src/util/util.c, src/util/util.h: Make virDiscoverHostPMFeature return a boolean
This commit is contained in:
parent
6ea25cd975
commit
33386276a9
@ -2624,13 +2624,12 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* virDiscoverHostPMFeature:
|
* 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
|
* @feature: The power management feature to check whether it is supported
|
||||||
* by the host. Values could be:
|
* by the host. Values could be:
|
||||||
* VIR_NODE_SUSPEND_TARGET_MEM
|
* VIR_NODE_SUSPEND_TARGET_MEM
|
||||||
* VIR_NODE_SUSPEND_TARGET_DISK
|
* VIR_NODE_SUSPEND_TARGET_DISK
|
||||||
* VIR_NODE_SUSPEND_TARGET_HYBRID
|
* VIR_NODE_SUSPEND_TARGET_HYBRID
|
||||||
|
* @supported: set to true if supported, false otherwise
|
||||||
*
|
*
|
||||||
* Run the script 'pm-is-supported' (from the pm-utils package)
|
* Run the script 'pm-is-supported' (from the pm-utils package)
|
||||||
* to find out if @feature is supported by the host.
|
* to find out if @feature is supported by the host.
|
||||||
@ -2638,12 +2637,14 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
|
|||||||
* Returns 0 if the query was successful, -1 on failure.
|
* Returns 0 if the query was successful, -1 on failure.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature)
|
virDiscoverHostPMFeature(unsigned int feature, bool *supported)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd;
|
virCommandPtr cmd;
|
||||||
int status;
|
int status;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
*supported = false;
|
||||||
|
|
||||||
switch (feature) {
|
switch (feature) {
|
||||||
case VIR_NODE_SUSPEND_TARGET_MEM:
|
case VIR_NODE_SUSPEND_TARGET_MEM:
|
||||||
cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
|
cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
|
||||||
@ -2665,9 +2666,7 @@ virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature)
|
|||||||
* 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)
|
*supported = (status == 0);
|
||||||
*bitmask |= 1U << feature;
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -2691,23 +2690,30 @@ int
|
|||||||
virGetPMCapabilities(unsigned int *bitmask)
|
virGetPMCapabilities(unsigned int *bitmask)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
bool supported;
|
||||||
|
|
||||||
*bitmask = 0;
|
*bitmask = 0;
|
||||||
|
|
||||||
/* Check support for Suspend-to-RAM (S3) */
|
/* Check support for Suspend-to-RAM (S3) */
|
||||||
ret = virDiscoverHostPMFeature(bitmask, VIR_NODE_SUSPEND_TARGET_MEM);
|
ret = virDiscoverHostPMFeature(VIR_NODE_SUSPEND_TARGET_MEM, &supported);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (supported)
|
||||||
|
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_MEM);
|
||||||
|
|
||||||
/* Check support for Suspend-to-Disk (S4) */
|
/* Check support for Suspend-to-Disk (S4) */
|
||||||
ret = virDiscoverHostPMFeature(bitmask, VIR_NODE_SUSPEND_TARGET_DISK);
|
ret = virDiscoverHostPMFeature(VIR_NODE_SUSPEND_TARGET_DISK, &supported);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (supported)
|
||||||
|
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_DISK);
|
||||||
|
|
||||||
/* Check support for Hybrid-Suspend */
|
/* Check support for Hybrid-Suspend */
|
||||||
ret = virDiscoverHostPMFeature(bitmask, VIR_NODE_SUSPEND_TARGET_HYBRID);
|
ret = virDiscoverHostPMFeature(VIR_NODE_SUSPEND_TARGET_HYBRID, &supported);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (supported)
|
||||||
|
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_HYBRID);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams);
|
|||||||
|
|
||||||
/* Power Management Capabilities of the host system */
|
/* Power Management Capabilities of the host system */
|
||||||
|
|
||||||
int virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature);
|
int virDiscoverHostPMFeature(unsigned int feature, bool *supported);
|
||||||
int virGetPMCapabilities(unsigned int *bitmask);
|
int virGetPMCapabilities(unsigned int *bitmask);
|
||||||
|
|
||||||
#endif /* __VIR_UTIL_H__ */
|
#endif /* __VIR_UTIL_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user