[libvirt] [PATCH 05/30] conf: pass in default architecture via domain XML options

Daniel P. Berrangé berrange at redhat.com
Wed Dec 4 14:20:48 UTC 2019


When parsing the guest XML we must fill in the default guest arch if it
is not already present because later parts of the parsing process need
this information.

If no arch is specified we lookup the first guest in the capabilities
data matching the os type and virt type. In most cases this will result
in picking the host architecture but there are some exceptions...

 - The test driver is hardcoded to always use i686 arch
 - The VMWare/ESX drivers will always place i686 guests ahead
   of x86_64 guests in capabilities, so effectively they always
   use i686
 - The QEMU driver can potentially return any arch at all
   depending on what combination of QEMU binaries are installed.

The domain XML hardware configurations are inherently architecture
specific in many places. As a result whomever/whatever created the
domain XML will have had a particular architecture in mind when
specifying the config. In pretty much any sensible case this arch
will have been the native host architecture. i686 on x86_64 is
the only sensible divergance because both these archs are
compatible from a domaain XML config POV.

IOW, although the QEMU driver can pick an almost arbitrary arch as its
default, in the real world no application or user is likely to be
relying on this default arch being anything other than native.

With all this in mind, it is reasonable to change the XML parser to
allow the default architecture to be passed via the domain XML options
struct. If no info is explicitly given then it is safe & sane to pick
the host native architecture as the default for the guest.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 docs/formatdomain.html.in  |  6 +++++-
 src/conf/domain_conf.c     | 12 +++++++++---
 src/conf/domain_conf.h     |  1 +
 src/test/test_driver.c     |  1 +
 src/vmware/vmware_driver.c |  1 +
 src/vmx/vmx.c              |  1 +
 6 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 6df4a8b26e..d7092761c5 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -175,7 +175,11 @@
         and <a id="attributeOSTypeMachine"><code>machine</code></a> referring
         to the machine type. The <a href="formatcaps.html">Capabilities XML</a>
         provides details on allowed values for
-        these. <span class="since">Since 0.0.1</span></dd>
+        these. If <code>arch</code> is omitted then for most hypervisor
+        drivers, the host native arch will be chosen. For the <code>test</code>,
+        <code>ESX</code> and <code>VMWare</code> hypervisor drivers, however,
+        the <code>i686</code> arch will always be chosen even on an
+        <code>x86_64</code> host. <span class="since">Since 0.0.1</span></dd>
       <dt><a id="elementLoader"><code>loader</code></a></dt>
       <dd>The optional <code>loader</code> tag refers to a firmware blob,
         which is specified by absolute path,
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 781bf9d2d4..1c2b8f26ed 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19565,6 +19565,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
 static int
 virDomainDefParseCaps(virDomainDefPtr def,
                       xmlXPathContextPtr ctxt,
+                      virDomainXMLOptionPtr xmlopt,
                       virCapsPtr caps,
                       unsigned int flags)
 {
@@ -19625,6 +19626,13 @@ virDomainDefParseCaps(virDomainDefPtr def,
         return -1;
     }
 
+    if (def->os.arch == VIR_ARCH_NONE) {
+        if (xmlopt && xmlopt->config.defArch != VIR_ARCH_NONE)
+            def->os.arch = xmlopt->config.defArch;
+        else
+            def->os.arch = virArchFromHost();
+    }
+
     if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
                                                      def->os.arch,
                                                      def->virtType,
@@ -19633,8 +19641,6 @@ virDomainDefParseCaps(virDomainDefPtr def,
             return -1;
         virResetLastError();
     } else {
-        if (!def->os.arch)
-            def->os.arch = capsdata->arch;
         if (!def->os.machine)
             def->os.machine = g_strdup(capsdata->machinetype);
     }
@@ -19792,7 +19798,7 @@ virDomainDefParseXML(xmlDocPtr xml,
             id = -1;
     def->id = (int)id;
 
-    if (virDomainDefParseCaps(def, ctxt, caps, flags) < 0)
+    if (virDomainDefParseCaps(def, ctxt, xmlopt, caps, flags) < 0)
         goto error;
 
     /* Extract domain name */
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f7a611d5ef..e1622f2112 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2705,6 +2705,7 @@ struct _virDomainDefParserConfig {
     /* data */
     unsigned int features; /* virDomainDefFeatures */
     unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
+    virArch defArch;
 };
 
 typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e7ec537bb0..f2700d90bc 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -424,6 +424,7 @@ testDriverNew(void)
                     VIR_DOMAIN_DEF_FEATURE_USER_ALIAS |
                     VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT |
                     VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING,
+        .defArch = VIR_ARCH_I686,
     };
     virDomainXMLPrivateDataCallbacks privatecb = {
         .alloc = testDomainObjPrivateAlloc,
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index c0071fc18c..bab4fdb82b 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -139,6 +139,7 @@ vmwareDomainDeviceDefPostParse(virDomainDeviceDefPtr dev G_GNUC_UNUSED,
 virDomainDefParserConfig vmwareDomainDefParserConfig = {
     .devicesPostParseCallback = vmwareDomainDeviceDefPostParse,
     .domainPostParseCallback = vmwareDomainDefPostParse,
+    .defArch = VIR_ARCH_I686,
 };
 
 static virDomainXMLOptionPtr
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 0ccc4eefe6..c4af7b1ce9 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -556,6 +556,7 @@ static virDomainDefParserConfig virVMXDomainDefParserConfig = {
     .features = (VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI |
                  VIR_DOMAIN_DEF_FEATURE_NAME_SLASH |
                  VIR_DOMAIN_DEF_FEATURE_NO_BOOT_ORDER),
+    .defArch = VIR_ARCH_I686,
 };
 
 struct virVMXDomainDefNamespaceData {
-- 
2.23.0




More information about the libvir-list mailing list