]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add 'Hybrid-Suspend' power management discovery for the host
authorSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Tue, 29 Nov 2011 06:56:10 +0000 (14:56 +0800)
committerDaniel Veillard <veillard@redhat.com>
Tue, 29 Nov 2011 09:29:16 +0000 (17:29 +0800)
Some systems support a feature known as 'Hybrid-Suspend', apart from the
usual system-wide sleep states such as Suspend-to-RAM (S3) or Suspend-to-Disk
(S4). Add the functionality to discover this power management feature and
export it in the capabilities XML under the <power_management> tag.

docs/formatcaps.html.in
docs/schemas/capability.rng
src/conf/capabilities.c
src/util/util.c
src/util/util.h

index 423bc480ec6108713cdfe2e6445d300c390c2306..c1bc2f58e166d2d6b464dce4fab72d8dad915807 100644 (file)
@@ -31,6 +31,7 @@ BIOS you will see</p>
     &lt;power_management&gt;
       &lt;S3/&gt;
       &lt;S4/&gt;
+      &lt;Hybrid-Suspend/&gt;
     &lt;power_management/&gt;
   &lt;/host&gt;</span>
 
@@ -71,8 +72,9 @@ BIOS you will see</p>
           model, within a feature block (the block is similar to what
           you will find in a Xen fully virtualized domain
           description). Further, the power management features
-          supported by the host are shown, such as Suspend-to-RAM (S3)
-          and Suspend-to-Disk (S4). In case the query for power
+          supported by the host are shown, such as Suspend-to-RAM (S3),
+          Suspend-to-Disk (S4) and Hybrid-Suspend (a combination of S3
+          and S4). In case the query for power
           management features succeeded but the host does not support
           any such feature, then an empty &lt;power_management/&gt;
           tag will be shown. Otherwise, if the query itself failed, no
index 645769e330df7ac54edf48392aae94c8fef445cf..6cf21885aecbb7c4b5ea46f35e9b927b5f90033b 100644 (file)
             <empty/>
           </element>
         </optional>
+        <optional>
+          <element name='Hybrid-Suspend'>
+            <empty/>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
index ac132f9ec4c448f84f735e9a4ab1dc4e8ff0fe91..70f9ab0b4985979a25a1f89092610033f7d5a371 100644 (file)
@@ -37,7 +37,7 @@
 #define VIR_FROM_THIS VIR_FROM_CAPABILITIES
 
 VIR_ENUM_IMPL(virHostPMCapability, VIR_HOST_PM_LAST,
-              "S3", "S4")
+              "S3", "S4", "Hybrid-Suspend")
 
 /**
  * virCapabilitiesNew:
index ce697fb7b444781b6ff99ac9284ecd7951785d5d..34541ec93a9011fc87f02961690af511418aa2b0 100644 (file)
@@ -2623,47 +2623,50 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
 }
 
 /**
- * Get the Power Management Capabilities of the host system.
- * The script 'pm-is-supported' (from the pm-utils package) is run
- * to find out all the power management features supported by the host,
- * such as Suspend-to-RAM (S3) and Suspend-to-Disk (S4).
+ * 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_HOST_PM_S3 for Suspend-to-RAM
+ *           VIR_HOST_PM_S4 for Suspend-to-Disk
+ *           VIR_HOST_PM_HYBRID_SUSPEND for Hybrid-Suspend
  *
- * @bitmask: Pointer to the bitmask which will be set appropriately to
- *           indicate all the supported host power management features.
+ * Run the script 'pm-is-supported' (from the pm-utils package)
+ * to find out if @feature is supported by the host.
  *
- * Returns 0 if the query was successful, -1 upon failure.
+ * Returns 0 if the query was successful, -1 on failure.
  */
 int
-virGetPMCapabilities(unsigned int *bitmask)
+virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature)
 {
-    int ret = -1;
-    int status;
     virCommandPtr cmd;
+    int status;
+    int ret = -1;
 
-    *bitmask = 0;
-
-    /* Check support for Suspend-to-RAM (S3) */
-    cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
-    if (virCommandRun(cmd, &status) < 0)
-        goto cleanup;
-
-    /* Check return code of command == 0 for success
-     * (i.e., the PM capability is supported)
-     */
-    if (status == 0)
-        *bitmask |= 1U << VIR_HOST_PM_S3;
-    virCommandFree(cmd);
+    switch (feature) {
+    case VIR_HOST_PM_S3:
+        cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
+        break;
+    case VIR_HOST_PM_S4:
+        cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
+        break;
+    case VIR_HOST_PM_HYBRID_SUSPEND:
+        cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
+        break;
+    default:
+        return ret;
+    }
 
-    /* Check support for Suspend-to-Disk (S4) */
-    cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
     if (virCommandRun(cmd, &status) < 0)
         goto cleanup;
 
-    /* Check return code of command == 0 for success
-     * (i.e., the PM capability is supported)
-     */
+   /*
+    * Check return code of command == 0 for success
+    * (i.e., the PM capability is supported)
+    */
     if (status == 0)
-        *bitmask |= 1U << VIR_HOST_PM_S4;
+        *bitmask |= 1U << feature;
 
     ret = 0;
 
@@ -2671,3 +2674,40 @@ cleanup:
     virCommandFree(cmd);
     return ret;
 }
+
+/**
+ * virGetPMCapabilities:
+ *
+ * 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 features.
+ *
+ * Returns 0 if the query was successful, -1 on failure.
+ */
+int
+virGetPMCapabilities(unsigned int *bitmask)
+{
+    int ret;
+
+    *bitmask = 0;
+
+    /* Check support for Suspend-to-RAM (S3) */
+    ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_S3);
+    if (ret < 0)
+        return -1;
+
+    /* Check support for Suspend-to-Disk (S4) */
+    ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_S4);
+    if (ret < 0)
+        return -1;
+
+    /* Check support for Hybrid-Suspend */
+    ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_HYBRID_SUSPEND);
+    if (ret < 0)
+        return -1;
+
+    return 0;
+}
index 5afcf58dccc1645b41675f6b3aeb671ed9b09886..eda60d2db592c06e0f566c6a6cc8379b6bbdddf5 100644 (file)
@@ -264,14 +264,16 @@ void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams);
 /* Power Management Capabilities of the host system */
 
 enum virHostPMCapability {
-    VIR_HOST_PM_S3,  /* Suspend-to-RAM */
-    VIR_HOST_PM_S4,  /* Suspend-to-Disk */
+    VIR_HOST_PM_S3,              /* Suspend-to-RAM */
+    VIR_HOST_PM_S4,              /* Suspend-to-Disk */
+    VIR_HOST_PM_HYBRID_SUSPEND,  /* Hybrid-Suspend */
 
     VIR_HOST_PM_LAST
 };
 
 VIR_ENUM_DECL(virHostPMCapability)
 
-int virGetPMCapabilities(unsigned int *);
+int virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature);
+int virGetPMCapabilities(unsigned int *bitmask);
 
 #endif /* __VIR_UTIL_H__ */