]> xenbits.xensource.com Git - libvirt.git/commitdiff
Export KVM Host Power Management capabilities
authorSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Tue, 22 Nov 2011 03:31:22 +0000 (11:31 +0800)
committerDaniel Veillard <veillard@redhat.com>
Tue, 22 Nov 2011 03:31:22 +0000 (11:31 +0800)
This patch exports KVM Host Power Management capabilities as XML so that
higher-level systems management software can make use of these features
available in the host.

The script "pm-is-supported" (from pm-utils package) is run to discover if
Suspend-to-RAM (S3) or Suspend-to-Disk (S4) is supported by the host.
If either of them are supported, then a new tag "<power_management>" is
introduced in the XML under the <host> tag.

However in case the query to check for power management features succeeded,
but the host does not support any such feature, then the XML will contain
an empty <power_management/> tag. In the event that the PM query itself
failed, the XML will not contain any "power_management" tag.

To use this, new APIs could be implemented in libvirt to exploit power
management features such as S3/S4.

12 files changed:
AUTHORS
docs/formatcaps.html.in
docs/schemas/capability.rng
include/libvirt/virterror.h
libvirt.spec.in
src/conf/capabilities.c
src/conf/capabilities.h
src/libvirt_private.syms
src/qemu/qemu_capabilities.c
src/util/util.c
src/util/util.h
src/util/virterror.c

diff --git a/AUTHORS b/AUTHORS
index 272a82869e8420aa11388a10322336fe6240cc68..9d5f8b52f6090f1ce5b4b82dc8205640ca488cee 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -206,6 +206,7 @@ Patches have also been contributed by:
   Eli Qiao             <taget@linux.vnet.ibm.com>
   Michael Wood         <esiotrot@gmail.com>
   Bharata B Rao        <bharata@linux.vnet.ibm.com>
+  Srivatsa S. Bhat     <srivatsa.bhat@linux.vnet.ibm.com>
 
   [....send patches to get your name here....]
 
index a4297cefa1ce1e32e53dc4c7f7e7a5efda14768e..ce6f9a644a64ce045520ddf11699abc1990ede49 100644 (file)
@@ -28,6 +28,10 @@ BIOS you will see</p>
       &lt;feature name='xtpr'/&gt;
       ...
     &lt;/cpu&gt;
+    &lt;power_management&gt;
+      &lt;S3/&gt;
+      &lt;S4/&gt;
+    &lt;power_management/&gt;
   &lt;/host&gt;</span>
 
   &lt;!-- xen-3.0-x86_64 --&gt;
@@ -61,11 +65,16 @@ BIOS you will see</p>
   ...
 &lt;/capabilities&gt;</pre>
         <p>The first block (in red) indicates the host hardware capabilities, currently
-it is limited to the CPU properties but other information may be available,
-it shows the CPU architecture, topology, model name, and additional features
-which are not included in the model but the CPU provides them. Features of the
-chip are shown within the feature block (the block is similar to what you will
-find in a Xen fully virtualized domain description).</p>
+it is limited to the CPU properties and the power management features of
+the host platform, but other information may be available, it shows the CPU architecture,
+topology, model name, and additional features which are not included in the model but the
+CPU provides them. Features of the chip are shown within the 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 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 such tag will
+be displayed (i.e., there will not be any power_management block or empty tag in the XML).</p>
         <p>The second block (in blue) indicates the paravirtualization support of the
 Xen support, you will see the os_type of xen to indicate a paravirtual
 kernel, then architecture information and potential features.</p>
index 0a63a1c6a15af8272299e42851bfb5b96e635dc8..645769e330df7ac54edf48392aae94c8fef445cf 100644 (file)
@@ -34,6 +34,9 @@
           <ref name='cpuspec'/>
         </optional>
       </element>
+      <optional>
+        <ref name='power_management'/>
+      </optional>
       <optional>
         <ref name='migration'/>
       </optional>
     </zeroOrMore>
   </define>
 
+  <define name='power_management'>
+    <element name='power_management'>
+      <interleave>
+        <optional>
+          <element name='S3'>
+            <empty/>
+          </element>
+        </optional>
+        <optional>
+          <element name='S4'>
+            <empty/>
+          </element>
+        </optional>
+      </interleave>
+    </element>
+  </define>
+
   <define name='migration'>
     <element name='migration_features'>
       <optional>
index a8549b784f81c097606b58f198ac0c5e55926dfb..7063ef6a8ed0c0faf43c6b2cf2456dc1b74a1f3e 100644 (file)
@@ -84,6 +84,7 @@ typedef enum {
     VIR_FROM_LIBXL = 41,       /* Error from libxenlight driver */
     VIR_FROM_LOCKING = 42,     /* Error from lock manager */
     VIR_FROM_HYPERV = 43,      /* Error from Hyper-V driver */
+    VIR_FROM_CAPABILITIES = 44, /* Error from capabilities */
 } virErrorDomain;
 
 
index ce541a7cc84c746da360f12e5aa2b22d5b846969..f61a243acb6c2bd8987e0c7c45e9c85a7feab4b3 100644 (file)
@@ -506,6 +506,8 @@ Requires: nc
 Requires: gettext
 # Needed by virt-pki-validate script.
 Requires: gnutls-utils
+# Needed for probing the power management features of the host.
+Requires: pm-utils
 %if %{with_sasl}
 Requires: cyrus-sasl
 # Not technically required, but makes 'out-of-box' config
index 40e297678a37308e13e0bfeb6a94a3af245dbb6e..87b60b0c3e0fe899e11f3f9def43b945be6b33fd 100644 (file)
 #include "util.h"
 #include "uuid.h"
 #include "cpu_conf.h"
+#include "virterror_internal.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
+
+VIR_ENUM_IMPL(virHostPMCapability, VIR_HOST_PM_LAST,
+              "S3", "S4")
 
 /**
  * virCapabilitiesNew:
@@ -201,7 +208,6 @@ virCapabilitiesAddHostFeature(virCapsPtr caps,
     return 0;
 }
 
-
 /**
  * virCapabilitiesAddHostMigrateTransport:
  * @caps: capabilities to extend
@@ -687,6 +693,25 @@ 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",
+                    virHostPMCapabilityTypeToString(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) {
         virBufferAddLit(&xml, "    <migration_features>\n");
         if (caps->host.liveMigrate)
index dd4a8279b38c2ac5661a26f408576a715a8eb55c..148c7cc939f6b3906493c510d1207fd9326fa99c 100644 (file)
@@ -105,6 +105,10 @@ 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.
+                                */
     int offlineMigrate;
     int liveMigrate;
     size_t nmigrateTrans;
index e5784f579c746b7f443cdedf9e358024c94ee00d..2cf50d30b037a9aecc148f7eaa688a7c86fcb252 100644 (file)
@@ -1094,6 +1094,7 @@ virFormatMacAddr;
 virGenerateMacAddr;
 virGetGroupID;
 virGetHostname;
+virGetPMCapabilities;
 virGetUserDirectory;
 virGetUserID;
 virGetUserName;
index 26a7f11a677fbde261d40287dde7f39185e7eb84..c5fe41d9a898d93c1a6784121542b30497a892e7 100644 (file)
@@ -848,6 +848,14 @@ virCapsPtr qemuCapsInit(virCapsPtr old_caps)
         old_caps->host.cpu = NULL;
     }
 
+    /* Add the power management features of the host */
+
+    if (virGetPMCapabilities(&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");
 
index 9ecfa9dee8ae588e21cf0fc91a3ed957f1533d33..ce697fb7b444781b6ff99ac9284ecd7951785d5d 100644 (file)
@@ -2621,3 +2621,53 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
             VIR_FREE(params[i].value.s);
     }
 }
+
+/**
+ * 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).
+ *
+ * @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 upon failure.
+ */
+int
+virGetPMCapabilities(unsigned int *bitmask)
+{
+    int ret = -1;
+    int status;
+    virCommandPtr cmd;
+
+    *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);
+
+    /* 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)
+     */
+    if (status == 0)
+        *bitmask |= 1U << VIR_HOST_PM_S4;
+
+    ret = 0;
+
+cleanup:
+    virCommandFree(cmd);
+    return ret;
+}
index 3295ce8b5555cf1cf0d633ee33893802a8cba5ea..5afcf58dccc1645b41675f6b3aeb671ed9b09886 100644 (file)
@@ -260,4 +260,18 @@ int virEmitXMLWarning(int fd,
                       const char *cmd) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 
 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_LAST
+};
+
+VIR_ENUM_DECL(virHostPMCapability)
+
+int virGetPMCapabilities(unsigned int *);
+
 #endif /* __VIR_UTIL_H__ */
index 5006fa27ede74d1ac140cda9141f327855ef4a5f..44a276a9db5c9829ae9b16e9a0ffc17f4f0fe246 100644 (file)
@@ -175,6 +175,9 @@ static const char *virErrorDomainName(virErrorDomain domain) {
         case VIR_FROM_HYPERV:
             dom = "Hyper-V ";
             break;
+        case VIR_FROM_CAPABILITIES:
+            dom = "Capabilities ";
+            break;
     }
     return(dom);
 }