]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Move suspend capabilities APIs out of util.h into virnodesuspend.c
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 29 Nov 2011 14:42:58 +0000 (14:42 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 30 Nov 2011 10:12:29 +0000 (10:12 +0000)
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
src/util/util.c
src/util/util.h
src/util/virnodesuspend.c
src/util/virnodesuspend.h

index 4bbfd7869fd55243d3b2223dcc5746b627530307..64ab8a8652ee710c417501b216f3b2486bb161b4 100644 (file)
@@ -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>
index 72fbdac72bd8cf732c6ac2957820a574b63592af..9ecfa9dee8ae588e21cf0fc91a3ed957f1533d33 100644 (file)
@@ -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;
-}
index 6713547090df54bd60a3c6f05147d2076d2817f6..ee53b842c09fce06d94888d585a57c023d268a0f 100644 (file)
@@ -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__ */
index 8ce642accdb00f606f0b1fafc7898d068ea0ce63..e070cb1805f649e07a560aed269d29de25c96f3e 100644 (file)
@@ -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.
+ */
+static 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;
+}
index 66e3214a19697ad19116ad4376b24113e69993f2..5debde2aaa2f338bf42a4a57f3569e85dfe8b2b8 100644 (file)
@@ -31,6 +31,6 @@ int nodeSuspendForDuration(virConnectPtr conn,
                            unsigned int flags);
 
 int virNodeSuspendInit(void);
-
+int virNodeSuspendGetTargetMask(unsigned int *bitmask);
 
 #endif /* __VIR_NODE_SUSPEND_H__ */