[libvirt] [PATCH 3/5] conf: Remove obsolete <hpt> feature

Andrea Bolognani abologna at redhat.com
Tue Jan 23 15:45:02 UTC 2018


Now that the <pseries><hpt> feature has been implemented, we
can get rid of the original <hpt> feature and thus ensure all
pSeries features are grouped together in the same sub-element.

Compatibility code is provided so that existing guests can be
parsed and migrated successfully despite the change.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 docs/formatdomain.html.in                         |  12 ---
 src/conf/domain_conf.c                            | 105 ++++++++++++++--------
 src/conf/domain_conf.h                            |   2 -
 src/qemu/qemu_command.c                           |  20 -----
 src/qemu/qemu_domain.c                            |   8 --
 tests/qemuxml2xmloutdata/pseries-hpt-resizing.xml |   4 +-
 6 files changed, 71 insertions(+), 80 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index b2584fbb0..1e2fccaeb 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1774,7 +1774,6 @@
   <pvspinlock state='on'/>
   <gic version='2'/>
   <ioapic driver='qemu'/>
-  <hpt resizing='required'/>
 </features>
 ...</pre>
 
@@ -1960,17 +1959,6 @@
           which is also known as a split I/O APIC mode.
           <span class="since">Since 3.4.0</span> (QEMU/KVM only)
       </dd>
-      <dt><code>hpt</code></dt>
-      <dd>Configure the HPT (Hash Page Table) of a pSeries guest. Possible
-          values for the <code>resizing</code> attribute are
-          <code>enabled</code>, which causes HPT resizing to be enabled if
-          both the guest and the host support it; <code>disabled</code>, which
-          causes HPT resizing to be disabled regardless of guest and host
-          support; and <code>required</code>, which prevents the guest from
-          starting unless both the guest and the host support HPT resizing. If
-          the attribute is not defined, the hypervisor default will be used.
-          <span class="since">Since 3.10.0</span> (QEMU/KVM only)
-      </dd>
       <dt><code>vmcoreinfo</code></dt>
       <dd>Enable QEMU vmcoreinfo device to let the guest kernel save debug
           details. <span class="since">Since 3.10.0</span> (QEMU only)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 577a804df..763228ca7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -150,7 +150,6 @@ VIR_ENUM_IMPL(virDomainFeature, VIR_DOMAIN_FEATURE_LAST,
               "gic",
               "smm",
               "ioapic",
-              "hpt",
               "vmcoreinfo",
               "pseries",
 );
@@ -18857,6 +18856,36 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
 
     for (i = 0; i < n; i++) {
+
+        /* Compatibility code.
+         *
+         * Between 3.10.0 and 4.1.0, we had <features><hpt> instead of
+         * <features><pseries><hpt>, and we need to be able to parse existing
+         * guest configurations; this takes care of it. Note that the compat
+         * code, like the original implementation and unlike the new one,
+         * must handle gracefully the 'resizing' attribute being absent */
+        if (STREQ((const char *) nodes[i]->name, "hpt")) {
+            tmp = virXMLPropString(nodes[i], "resizing");
+            if (tmp) {
+                int value = virDomainHPTResizingTypeFromString(tmp);
+                if (value < 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("Invalid value '%s' for '%s' "
+                                     "attribute of '%s' pSeries feature"),
+                                   tmp, "resizing", nodes[i]->name);
+                    goto error;
+                }
+
+                def->features[VIR_DOMAIN_FEATURE_PSERIES] = VIR_TRISTATE_SWITCH_ON;
+                def->pseries_features[VIR_DOMAIN_PSERIES_HPT] = VIR_TRISTATE_SWITCH_ON;
+                def->pseries_hpt_resizing = value;
+
+                VIR_FREE(tmp);
+            }
+            i++;
+            continue;
+        }
+
         int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
         if (val < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -18951,22 +18980,6 @@ virDomainDefParseXML(xmlDocPtr xml,
             }
             break;
 
-        case VIR_DOMAIN_FEATURE_HPT:
-            tmp = virXMLPropString(nodes[i], "resizing");
-            if (tmp) {
-                int value = virDomainHPTResizingTypeFromString(tmp);
-                if (value < 0) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("Unknown HPT resizing setting: %s"),
-                                   tmp);
-                    goto error;
-                }
-                def->hpt_resizing = value;
-                def->features[val] = VIR_TRISTATE_SWITCH_ON;
-                VIR_FREE(tmp);
-            }
-            break;
-
         /* coverity[dead_error_begin] */
         case VIR_DOMAIN_FEATURE_LAST:
             break;
@@ -21228,18 +21241,6 @@ virDomainDefFeaturesCheckABIStability(virDomainDefPtr src,
         return false;
     }
 
-    /* HPT resizing */
-    if (src->features[VIR_DOMAIN_FEATURE_HPT] == VIR_TRISTATE_SWITCH_ON) {
-        if (src->hpt_resizing != dst->hpt_resizing) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("HPT resizing configuration differs: "
-                             "source: '%s', destination: '%s'"),
-                           virDomainHPTResizingTypeToString(src->hpt_resizing),
-                           virDomainHPTResizingTypeToString(dst->hpt_resizing));
-            return false;
-        }
-    }
-
     return true;
 }
 
@@ -26565,10 +26566,44 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                 virBufferAddLit(buf, "</kvm>\n");
                 break;
 
-            case VIR_DOMAIN_FEATURE_PSERIES:
+            case VIR_DOMAIN_FEATURE_PSERIES: {
+                bool needsPSeriesElement = false;
+
                 if (def->features[i] != VIR_TRISTATE_SWITCH_ON)
                     break;
 
+                /* Figure out whether we need the <pseries> element.
+                 * For compatibility reasons (see below) we might need to
+                 * skip it even though some pSeries features are enabled:
+                 * namely, if the HPT feature is enabled and we're formatting
+                 * a migratable XML */
+                for (j = 0; j < VIR_DOMAIN_PSERIES_LAST; j++) {
+                    if (def->pseries_features[j] == VIR_TRISTATE_SWITCH_ABSENT)
+                        continue;
+                    if ((virDomainPSeries) j == VIR_DOMAIN_PSERIES_HPT &&
+                        flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) {
+                        continue;
+                    }
+                    needsPSeriesElement = true;
+                    break;
+                }
+
+                /* Compatibility code.
+                 * Between 3.10.0 and 4.1.0, we had <features><hpt> instead
+                 * of <features><pseries><hpt>, and we need to be able to
+                 * migrate existing guests back and forth between old libvirt
+                 * and new libvirt; this takes care of it, by using the old
+                 * element when formatting a migratable XML */
+                if (def->pseries_features[VIR_DOMAIN_PSERIES_HPT] == VIR_TRISTATE_SWITCH_ON &&
+                    flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) {
+                    virBufferAsprintf(buf, "<hpt resizing='%s'/>\n",
+                                      virDomainHPTResizingTypeToString(def->pseries_hpt_resizing));
+                }
+
+                /* Stop here unless we need the <pseries> element */
+                if (!needsPSeriesElement)
+                    break;
+
                 virBufferAddLit(buf, "<pseries>\n");
                 virBufferAdjustIndent(buf, 2);
                 for (j = 0; j < VIR_DOMAIN_PSERIES_LAST; j++) {
@@ -26576,6 +26611,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                     case VIR_DOMAIN_PSERIES_HPT:
                         if (def->pseries_features[j] != VIR_TRISTATE_SWITCH_ON)
                             break;
+                        if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)
+                            break;
 
                         virBufferAsprintf(buf, "<hpt resizing='%s'/>\n",
                                           virDomainHPTResizingTypeToString(def->pseries_hpt_resizing));
@@ -26588,6 +26625,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                 virBufferAdjustIndent(buf, -2);
                 virBufferAddLit(buf, "</pseries>\n");
                 break;
+            }
 
             case VIR_DOMAIN_FEATURE_CAPABILITIES:
                 if (def->features[i] == VIR_DOMAIN_CAPABILITIES_POLICY_DEFAULT &&
@@ -26625,13 +26663,6 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                 }
                 break;
 
-            case VIR_DOMAIN_FEATURE_HPT:
-                if (def->features[i] == VIR_TRISTATE_SWITCH_ON) {
-                    virBufferAsprintf(buf, "<hpt resizing='%s'/>\n",
-                                      virDomainHPTResizingTypeToString(def->hpt_resizing));
-                }
-                break;
-
             /* coverity[dead_error_begin] */
             case VIR_DOMAIN_FEATURE_LAST:
                 break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e4ae2a26c..91db2220a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1738,7 +1738,6 @@ typedef enum {
     VIR_DOMAIN_FEATURE_GIC,
     VIR_DOMAIN_FEATURE_SMM,
     VIR_DOMAIN_FEATURE_IOAPIC,
-    VIR_DOMAIN_FEATURE_HPT,
     VIR_DOMAIN_FEATURE_VMCOREINFO,
     VIR_DOMAIN_FEATURE_PSERIES,
 
@@ -2360,7 +2359,6 @@ struct _virDomainDef {
     virGICVersion gic_version;
     char *hyperv_vendor_id;
     virDomainIOAPIC ioapic;
-    virDomainHPTResizing hpt_resizing;
     virDomainHPTResizing pseries_hpt_resizing;
 
     /* These options are of type virTristateSwitch: ON = keep, OFF = drop */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a053b597c..26122b048 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7645,26 +7645,6 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
             }
         }
 
-        if (def->features[VIR_DOMAIN_FEATURE_HPT] == VIR_TRISTATE_SWITCH_ON) {
-            const char *str;
-
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_PSERIES_RESIZE_HPT)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("HTP resizing is not supported by this "
-                                 "QEMU binary"));
-                goto cleanup;
-            }
-
-            str = virDomainHPTResizingTypeToString(def->hpt_resizing);
-            if (!str) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("Invalid setting for HPT resizing"));
-                goto cleanup;
-            }
-
-            virBufferAsprintf(&buf, ",resize-hpt=%s", str);
-        }
-
         if (def->features[VIR_DOMAIN_FEATURE_PSERIES] == VIR_TRISTATE_SWITCH_ON) {
             const char *value;
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index edef3838e..c604f0657 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3132,14 +3132,6 @@ qemuDomainDefVerifyFeatures(const virDomainDef *def)
         return -1;
     }
 
-    if (def->features[VIR_DOMAIN_FEATURE_HPT] == VIR_TRISTATE_SWITCH_ON &&
-        !qemuDomainIsPSeries(def)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       "%s",
-                       _("HPT tuning is only supported for pSeries guests"));
-        return -1;
-    }
-
     return 0;
 }
 
diff --git a/tests/qemuxml2xmloutdata/pseries-hpt-resizing.xml b/tests/qemuxml2xmloutdata/pseries-hpt-resizing.xml
index 5dd0dbd0b..b6a89ffe2 100644
--- a/tests/qemuxml2xmloutdata/pseries-hpt-resizing.xml
+++ b/tests/qemuxml2xmloutdata/pseries-hpt-resizing.xml
@@ -9,7 +9,9 @@
     <boot dev='hd'/>
   </os>
   <features>
-    <hpt resizing='required'/>
+    <pseries>
+      <hpt resizing='required'/>
+    </pseries>
   </features>
   <clock offset='utc'/>
   <on_poweroff>destroy</on_poweroff>
-- 
2.14.3




More information about the libvir-list mailing list