]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add per-guest S3/S4 state configuration
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 2 Aug 2012 10:12:50 +0000 (12:12 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 3 Sep 2012 07:08:21 +0000 (09:08 +0200)
There is a new <pm/> element implemented that can control what ACPI
sleeping states will be advertised by BIOS and allowed to be switched
to by libvirt. The default keeps defaults on hypervisor, otherwise
forces chosen setting.
The documentation of the pm element is added as well.

docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms

index d8ad54ac850c00011317a46d650c058d803a77f2..5cb5a563815bcad353ff0e2d1d60fc4f6ac3c112 100644 (file)
         domain will be restarted with the same configuration</dd>
     </dl>
 
+    <h3><a name="elementsPowerManagement">Power Management</a></h3>
+
+    <p>
+      <span class="since">Since 0.10.2</span> it is possible to
+      forcibly enable or disable BIOS advertisements to the guest
+      OS. (NB: Only qemu driver support)
+    </p>
+
+<pre>
+  ...
+  &lt;pm&gt;
+    &lt;suspend-to-disk enabled='no'/&gt;
+    &lt;suspend-to-ram enabled='yes'/&gt;
+  &lt;/pm&gt;
+  ...</pre>
+
+    <dl>
+      <dt><code>pm</code></dt>
+      <dd>These elements enable ('yes') or disable ('no') BIOS support
+        for S3 (suspend-to-disk) and S4 (suspend-to-mem) ACPI sleep
+        states. If nothing is specified, then the hypervisor will be
+        left with its default value.</dd>
+    </dl>
+
     <h3><a name="elementsFeatures">Hypervisor features</a></h3>
 
     <p>
index 60cf33e0f936a1fe1a607706472f0e6685ce1481..abd0e8f8be4446038ecb2541bf5d6fbcf2a8dbc7 100644 (file)
@@ -52,6 +52,9 @@
         <ref name="resources"/>
         <ref name="features"/>
         <ref name="termination"/>
+        <optional>
+          <ref name="pm"/>
+        </optional>
         <optional>
           <ref name="devices"/>
         </optional>
       <value>coredump-restart</value>
     </choice>
   </define>
+  <!--
+      Control ACPI sleep states (dis)allowed for the domain
+      For each of the states the following rules apply:
+      on: the state will be forcefully enabled
+      off: the state will be forcefully disabled
+      not specified: hypervisor will be left to decide its defaults
+  -->
+  <define name="pm">
+    <element name="pm">
+      <interleave>
+        <optional>
+          <element name="suspend-to-mem">
+            <ref name="suspendChoices"/>
+          </element>
+        </optional>
+        <optional>
+          <element name="suspend-to-disk">
+            <ref name="suspendChoices"/>
+          </element>
+        </optional>
+      </interleave>
+      <empty/>
+    </element>
+  </define>
+  <define name="suspendChoices">
+    <optional>
+      <attribute name="enabled">
+        <choice>
+          <value>yes</value>
+          <value>no</value>
+        </choice>
+      </attribute>
+    </optional>
+  </define>
   <!--
       Specific setup for a qemu emulated character device.  Note: this
       definition doesn't fully specify the constraints on this node.
index faae315c4f62b88f1d8a0b61882a9ad88a7f002a..c34a0a8ff618095937dc1321635e149d6ecf1b51 100644 (file)
@@ -124,6 +124,11 @@ VIR_ENUM_IMPL(virDomainLifecycleCrash, VIR_DOMAIN_LIFECYCLE_CRASH_LAST,
               "coredump-destroy",
               "coredump-restart")
 
+VIR_ENUM_IMPL(virDomainPMState, VIR_DOMAIN_PM_STATE_LAST,
+              "default",
+              "yes",
+              "no")
+
 VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST,
               "none",
               "disk",
@@ -7239,6 +7244,28 @@ static int virDomainLifecycleParseXML(xmlXPathContextPtr ctxt,
     return 0;
 }
 
+static int
+virDomainPMStateParseXML(xmlXPathContextPtr ctxt,
+                         const char *xpath,
+                         int *val)
+{
+    int ret = -1;
+    char *tmp = virXPathString(xpath, ctxt);
+    if (tmp) {
+        *val = virDomainPMStateTypeFromString(tmp);
+        if (*val < 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unknown PM state value %s"), tmp);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(tmp);
+    return ret;
+}
+
 virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
                                               virDomainDefPtr def,
                                               const char *xmlStr,
@@ -8611,6 +8638,16 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
                                    virDomainLifecycleCrashTypeFromString) < 0)
         goto error;
 
+    if (virDomainPMStateParseXML(ctxt,
+                                 "string(./pm/suspend-to-mem/@enabled)",
+                                 &def->pm.s3) < 0)
+        goto error;
+
+    if (virDomainPMStateParseXML(ctxt,
+                                 "string(./pm/suspend-to-disk/@enabled)",
+                                 &def->pm.s4) < 0)
+        goto error;
+
     tmp = virXPathString("string(./clock/@offset)", ctxt);
     if (tmp) {
         if ((def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) {
@@ -13424,6 +13461,19 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                                     virDomainLifecycleCrashTypeToString) < 0)
         goto cleanup;
 
+    if (def->pm.s3 || def->pm.s4) {
+        virBufferAddLit(buf, "  <pm>\n");
+        if (def->pm.s3) {
+            virBufferAsprintf(buf, "    <suspend-to-mem enabled='%s'/>\n",
+                              virDomainPMStateTypeToString(def->pm.s3));
+        }
+        if (def->pm.s4) {
+            virBufferAsprintf(buf, "    <suspend-to-disk enabled='%s'/>\n",
+                              virDomainPMStateTypeToString(def->pm.s4));
+        }
+        virBufferAddLit(buf, "  </pm>\n");
+    }
+
     virBufferAddLit(buf, "  <devices>\n");
 
     virBufferEscapeString(buf, "    <emulator>%s</emulator>\n",
index 0073aa97700a9d437e1fdd9f846b0c6906f57b8a..f9f486557a98edd71b393809b1b1ea4e124329cf 100644 (file)
@@ -1371,6 +1371,14 @@ enum virDomainLifecycleCrashAction {
     VIR_DOMAIN_LIFECYCLE_CRASH_LAST
 };
 
+enum virDomainPMState {
+    VIR_DOMAIN_PM_STATE_DEFAULT = 0,
+    VIR_DOMAIN_PM_STATE_ENABLED,
+    VIR_DOMAIN_PM_STATE_DISABLED,
+
+    VIR_DOMAIN_PM_STATE_LAST,
+};
+
 enum virDomainBIOSUseserial {
     VIR_DOMAIN_BIOS_USESERIAL_DEFAULT = 0,
     VIR_DOMAIN_BIOS_USESERIAL_YES,
@@ -1625,6 +1633,12 @@ struct _virDomainDef {
     int onPoweroff;
     int onCrash;
 
+    struct {
+        /* These options are actually type of enum virDomainPMState */
+        int s3;
+        int s4;
+    } pm;
+
     virDomainOSDef os;
     char *emulator;
     int features;
@@ -2092,6 +2106,7 @@ VIR_ENUM_DECL(virDomainBoot)
 VIR_ENUM_DECL(virDomainFeature)
 VIR_ENUM_DECL(virDomainLifecycle)
 VIR_ENUM_DECL(virDomainLifecycleCrash)
+VIR_ENUM_DECL(virDomainPMState)
 VIR_ENUM_DECL(virDomainDevice)
 VIR_ENUM_DECL(virDomainDeviceAddress)
 VIR_ENUM_DECL(virDomainDisk)
index 6f14763e70996699c4f7fcab17aad73b4c4eac02..65067d6e348e835789992306cd3735fa0edc3893 100644 (file)
@@ -453,6 +453,8 @@ virDomainPausedReasonTypeFromString;
 virDomainPausedReasonTypeToString;
 virDomainPciRombarModeTypeFromString;
 virDomainPciRombarModeTypeToString;
+virDomainPMStateTypeFromString;
+virDomainPMStateTypeToString;
 virDomainRedirdevBusTypeFromString;
 virDomainRedirdevBusTypeToString;
 virDomainRemoveInactive;