From: "Daniel P. Berrange" <berrange(a)redhat.com>
If we ensure that virNodeSuspendGetTargetMask always resets
*bitmask to zero upon failure, there is no need for the
powerMgmt_valid field.
* src/util/virnodesuspend.c: Ensure *bitmask is zero upon
failure
* src/conf/capabilities.c, src/conf/capabilities.h: Remove
powerMgmt_valid field
* src/qemu/qemu_capabilities.c: Remove powerMgmt_valid
---
src/conf/capabilities.c | 30 ++++++++++++++----------------
src/conf/capabilities.h | 1 -
src/qemu/qemu_capabilities.c | 5 +----
src/util/virnodesuspend.c | 10 +++++++---
4 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index df5ff23..ac050df 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -696,23 +696,21 @@ virCapabilitiesFormatXML(virCapsPtr caps)
virBufferAddLit(&xml, " </cpu>\n");
- if (caps->host.powerMgmt_valid) {
- /* The PM query was successful. */
- if (caps->host.powerMgmt) {
- /* The host supports some PM features. */
- unsigned int pm = caps->host.powerMgmt;
- virBufferAddLit(&xml, " <power_management>\n");
- while (pm) {
- int bit = ffs(pm) - 1;
- virBufferAsprintf(&xml, " <%s/>\n",
- virCapsHostPMTargetTypeToString(bit));
- pm &= ~(1U << bit);
- }
- virBufferAddLit(&xml, " </power_management>\n");
- } else {
- /* The host does not support any PM feature. */
- virBufferAddLit(&xml, " <power_management/>\n");
+ /* The PM query was successful. */
+ if (caps->host.powerMgmt) {
+ /* The host supports some PM features. */
+ unsigned int pm = caps->host.powerMgmt;
+ virBufferAddLit(&xml, " <power_management>\n");
+ while (pm) {
+ int bit = ffs(pm) - 1;
+ virBufferAsprintf(&xml, " <%s/>\n",
+ virCapsHostPMTargetTypeToString(bit));
+ pm &= ~(1U << bit);
}
+ virBufferAddLit(&xml, " </power_management>\n");
+ } else {
+ /* The host does not support any PM feature. */
+ virBufferAddLit(&xml, " <power_management/>\n");
}
if (caps->host.offlineMigrate) {
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 148c7cc..7f35c17 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -105,7 +105,6 @@ struct _virCapsHost {
size_t nfeatures;
size_t nfeatures_max;
char **features;
- bool powerMgmt_valid;
unsigned int powerMgmt; /* Bitmask of the PM capabilities.
* See enum virHostPMCapability.
*/
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 64ab8a8..deef0ea 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -851,11 +851,8 @@ virCapsPtr qemuCapsInit(virCapsPtr old_caps)
/* Add the power management features of the host */
- if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0) {
+ if (virNodeSuspendGetTargetMask(&caps->host.powerMgmt) < 0)
VIR_WARN("Failed to get host power management capabilities");
- caps->host.powerMgmt_valid = false;
- } else
- caps->host.powerMgmt_valid = true; /* The PM query succeeded. */
virCapabilitiesAddHostMigrateTransport(caps,
"tcp");
diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c
index 4eb5439..6420f5b 100644
--- a/src/util/virnodesuspend.c
+++ b/src/util/virnodesuspend.c
@@ -346,23 +346,27 @@ virNodeSuspendGetTargetMask(unsigned int *bitmask)
/* Check support for Suspend-to-RAM (S3) */
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_MEM, &supported);
if (ret < 0)
- return -1;
+ goto error;
if (supported)
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_MEM);
/* Check support for Suspend-to-Disk (S4) */
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_DISK, &supported);
if (ret < 0)
- return -1;
+ goto error;
if (supported)
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_DISK);
/* Check support for Hybrid-Suspend */
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_HYBRID, &supported);
if (ret < 0)
- return -1;
+ goto error;
if (supported)
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_HYBRID);
return 0;
+
+error:
+ *bitmask = 0;
+ return -1;
}
--
1.7.6.4