From: "Daniel P. Berrange" <berrange(a)redhat.com>
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
---
src/util/util.c | 24 +++++++++++++++---------
src/util/util.h | 2 +-
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index 5bd8c91..badfa3a 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -2624,13 +2624,12 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int
nparams)
/**
* 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_NODE_SUSPEND_TARGET_MEM
* VIR_NODE_SUSPEND_TARGET_DISK
* VIR_NODE_SUSPEND_TARGET_HYBRID
+ * @supported: set to true if supported, false otherwise
*
* Run the script 'pm-is-supported' (from the pm-utils package)
* 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.
*/
int
-virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature)
+virDiscoverHostPMFeature(unsigned int feature, bool *supported)
{
virCommandPtr cmd;
int status;
int ret = -1;
+ *supported = false;
+
switch (feature) {
case VIR_NODE_SUSPEND_TARGET_MEM:
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
* (i.e., the PM capability is supported)
*/
- if (status == 0)
- *bitmask |= 1U << feature;
-
+ *supported = (status == 0);
ret = 0;
cleanup:
@@ -2691,23 +2690,30 @@ int
virGetPMCapabilities(unsigned int *bitmask)
{
int ret;
+ bool supported;
*bitmask = 0;
/* 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)
return -1;
+ if (supported)
+ *bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_MEM);
/* 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)
return -1;
+ if (supported)
+ *bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_DISK);
/* Check support for Hybrid-Suspend */
- ret = virDiscoverHostPMFeature(bitmask, VIR_NODE_SUSPEND_TARGET_HYBRID);
+ ret = virDiscoverHostPMFeature(VIR_NODE_SUSPEND_TARGET_HYBRID, &supported);
if (ret < 0)
return -1;
+ if (supported)
+ *bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_HYBRID);
return 0;
}
diff --git a/src/util/util.h b/src/util/util.h
index 204e2b9..6a9de7e 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -263,7 +263,7 @@ void virTypedParameterArrayClear(virTypedParameterPtr params, int
nparams);
/* 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);
#endif /* __VIR_UTIL_H__ */
--
1.7.6.4