[libvirt] [PATCH] Drop dependency on pm-is-supported

Cédric Bosdonnat cbosdonnat at suse.com
Fri Mar 28 16:32:22 UTC 2014


From: Cédric Bosdonnat <cedric.bosdonnat at free.fr>

pm-is-supported is the only thing needed in pm-utils, better get rid of
it since systemd is heavily used for libvirt.
---
 src/util/virnodesuspend.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c
index 8088931..9839de2 100644
--- a/src/util/virnodesuspend.c
+++ b/src/util/virnodesuspend.c
@@ -29,6 +29,8 @@
 #include "viralloc.h"
 #include "virlog.h"
 #include "virerror.h"
+#include "virfile.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -263,41 +265,45 @@ int nodeSuspendForDuration(unsigned int target,
 static int
 virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
 {
-    virCommandPtr cmd;
-    int status;
     int ret = -1;
+    char *buf = NULL;
+    char **states = NULL;
+    bool canSuspend = false;
+    bool canHibernate = false;
 
     if (virNodeSuspendInitialize() < 0)
         return -1;
 
     *supported = false;
 
+    if (virFileReadAll("/sys/power/state", 1024, &buf) < 0)
+        goto cleanup;
+
+    states = virStringSplit(buf, " ", 0);
+
+    canSuspend = (virStringArrayHasString(states, "mem") ||
+                  virStringArrayHasString(states, "standby"));
+    canHibernate = virStringArrayHasString(states, "disk");
+
     switch (target) {
     case VIR_NODE_SUSPEND_TARGET_MEM:
-        cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
+        *supported = canSuspend;
         break;
     case VIR_NODE_SUSPEND_TARGET_DISK:
-        cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
+        *supported = canHibernate;
         break;
     case VIR_NODE_SUSPEND_TARGET_HYBRID:
-        cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
+        *supported = canSuspend && canHibernate;
         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);
+    VIR_FREE(buf);
+    virStringFreeList(states);
     return ret;
 }
 
-- 
1.8.4.5




More information about the libvir-list mailing list