[libvirt] [PATCH 07/14] Move suspend capabilities APIs out of util.h into virnodesuspend.c

Daniel P. Berrange berrange at redhat.com
Tue Nov 29 15:44:42 UTC 2011


From: "Daniel P. Berrange" <berrange at redhat.com>

The node suspend capabilities APIs should not have been put into
util.[ch]. Instead move them into virnodesuspend.[ch]

* src/util/util.c, src/util/util.h: Remove suspend capabilities APIs
* src/util/virnodesuspend.c, src/util/virnodesuspend.h: Add
  suspend capabilities APIs
* src/qemu/qemu_capabilities.c: Include virnodesuspend.h
---
 src/qemu/qemu_capabilities.c |    1 +
 src/util/util.c              |   96 -----------------------------------------
 src/util/util.h              |    5 --
 src/util/virnodesuspend.c    |   97 ++++++++++++++++++++++++++++++++++++++++++
 src/util/virnodesuspend.h    |    2 +
 5 files changed, 100 insertions(+), 101 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 4bbfd78..64ab8a8 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -34,6 +34,7 @@
 #include "domain_conf.h"
 #include "qemu_conf.h"
 #include "command.h"
+#include "virnodesuspend.h"
 
 #include <sys/stat.h>
 #include <unistd.h>
diff --git a/src/util/util.c b/src/util/util.c
index 72fbdac..9ecfa9d 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -2621,99 +2621,3 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
             VIR_FREE(params[i].value.s);
     }
 }
-
-/**
- * virNodeSuspendSupportsTarget:
- * @target: The power management target 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 @target is supported by the host.
- *
- * Returns 0 if the query was successful, -1 on failure.
- */
-int
-virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
-{
-    virCommandPtr cmd;
-    int status;
-    int ret = -1;
-
-    *supported = false;
-
-    switch (target) {
-    case VIR_NODE_SUSPEND_TARGET_MEM:
-        cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
-        break;
-    case VIR_NODE_SUSPEND_TARGET_DISK:
-        cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
-        break;
-    case VIR_NODE_SUSPEND_TARGET_HYBRID:
-        cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
-        break;
-    default:
-        return ret;
-    }
-
-    if (virCommandRun(cmd, &status) < 0)
-        goto cleanup;
-
-   /*
-    * Check return code of command == 0 for success
-    * (i.e., the PM capability is supported)
-    */
-    *supported = (status == 0);
-    ret = 0;
-
-cleanup:
-    virCommandFree(cmd);
-    return ret;
-}
-
-/**
- * virNodeSuspendGetTargetMask:
- *
- * 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 targets.
- *
- * Returns 0 if the query was successful, -1 on failure.
- */
-int
-virNodeSuspendGetTargetMask(unsigned int *bitmask)
-{
-    int ret;
-    bool supported;
-
-    *bitmask = 0;
-
-    /* Check support for Suspend-to-RAM (S3) */
-    ret = virNodeSuspendSupportsTarget(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 = virNodeSuspendSupportsTarget(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 = virNodeSuspendSupportsTarget(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 6713547..ee53b84 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -261,9 +261,4 @@ int virEmitXMLWarning(int fd,
 
 void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams);
 
-/* Power Management Capabilities of the host system */
-
-int virNodeSuspendSupportsTarget(unsigned int target, bool *supported);
-int virNodeSuspendGetTargetMask(unsigned int *bitmask);
-
 #endif /* __VIR_UTIL_H__ */
diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c
index 0814c36..4ac0d45 100644
--- a/src/util/virnodesuspend.c
+++ b/src/util/virnodesuspend.c
@@ -269,3 +269,100 @@ cleanup:
     VIR_FREE(cmdString);
     return -1;
 }
+
+
+/**
+ * virNodeSuspendSupportsTarget:
+ * @target: The power management target 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 @target is supported by the host.
+ *
+ * Returns 0 if the query was successful, -1 on failure.
+ */
+int
+virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
+{
+    virCommandPtr cmd;
+    int status;
+    int ret = -1;
+
+    *supported = false;
+
+    switch (target) {
+    case VIR_NODE_SUSPEND_TARGET_MEM:
+        cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
+        break;
+    case VIR_NODE_SUSPEND_TARGET_DISK:
+        cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
+        break;
+    case VIR_NODE_SUSPEND_TARGET_HYBRID:
+        cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
+        break;
+    default:
+        return ret;
+    }
+
+    if (virCommandRun(cmd, &status) < 0)
+        goto cleanup;
+
+   /*
+    * Check return code of command == 0 for success
+    * (i.e., the PM capability is supported)
+    */
+    *supported = (status == 0);
+    ret = 0;
+
+cleanup:
+    virCommandFree(cmd);
+    return ret;
+}
+
+/**
+ * virNodeSuspendGetTargetMask:
+ *
+ * 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 targets.
+ *
+ * Returns 0 if the query was successful, -1 on failure.
+ */
+int
+virNodeSuspendGetTargetMask(unsigned int *bitmask)
+{
+    int ret;
+    bool supported;
+
+    *bitmask = 0;
+
+    /* Check support for Suspend-to-RAM (S3) */
+    ret = virNodeSuspendSupportsTarget(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 = virNodeSuspendSupportsTarget(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 = virNodeSuspendSupportsTarget(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/virnodesuspend.h b/src/util/virnodesuspend.h
index 66e3214..1e23ce8 100644
--- a/src/util/virnodesuspend.h
+++ b/src/util/virnodesuspend.h
@@ -32,5 +32,7 @@ int nodeSuspendForDuration(virConnectPtr conn,
 
 int virNodeSuspendInit(void);
 
+int virNodeSuspendSupportsTarget(unsigned int target, bool *supported);
+int virNodeSuspendGetTargetMask(unsigned int *bitmask);
 
 #endif /* __VIR_NODE_SUSPEND_H__ */
-- 
1.7.6.4




More information about the libvir-list mailing list