]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: fix default machine for argv -> xml convertor
authorDaniel P. Berrangé <berrange@redhat.com>
Mon, 13 Aug 2018 11:42:01 +0000 (12:42 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 28 Aug 2018 10:49:01 +0000 (11:49 +0100)
Historically the argv -> xml convertor wanted the same default machine
as we'd set when parsing xml. The latter has now changed, however, to
use a default defined by libvirt. The former needs fixing to again
honour the default QEMU machine.

This exposed a bug in handling for the aarch64 target, as QEMU does not
define any default machine. Thus we should not having been accepting
argv without a -machine provided.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
12 files changed:
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_driver.c
src/qemu/qemu_parse_command.c
src/qemu/qemu_parse_command.h
tests/qemuargv2xmldata/nomachine-aarch64.args [deleted file]
tests/qemuargv2xmldata/nomachine-aarch64.xml [deleted file]
tests/qemuargv2xmldata/nomachine-ppc64.xml
tests/qemuargv2xmldata/nomachine-x86_64.xml
tests/qemuargv2xmldata/pseries-disk.xml
tests/qemuargv2xmldata/pseries-nvram.xml
tests/qemuargv2xmltest.c

index a97023ce82d8ec00442164b9adc3a2e32cdaaa23..a075677421de5ee0ce295adf8feb4ca9f696e55e 100644 (file)
@@ -2069,6 +2069,18 @@ const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
     return name;
 }
 
+const char *
+virQEMUCapsGetDefaultMachine(virQEMUCapsPtr qemuCaps)
+{
+    size_t i;
+
+    for (i = 0; i < qemuCaps->nmachineTypes; i++) {
+        if (qemuCaps->machineTypes[i].qemuDefault)
+            return qemuCaps->machineTypes[i].name;
+    }
+
+    return NULL;
+}
 
 int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
                                  const char *name)
index da017ff52bf2f98f9aaae30b11a382a413993e15..3d3a978759d6ea18bd08bc816ee4d697f6ae9d96 100644 (file)
@@ -559,6 +559,7 @@ bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
                                    virCPUMode mode);
 const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
                                            const char *name);
+const char *virQEMUCapsGetDefaultMachine(virQEMUCapsPtr qemuCaps);
 int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
                                  const char *name);
 bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
index da8c4e89917e9dce4a071386ccbb58b3d19078fd..a0f7c71675df69764ec4ca5df2cb871bf42ae2f3 100644 (file)
@@ -7103,7 +7103,8 @@ static char *qemuConnectDomainXMLFromNative(virConnectPtr conn,
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;
 
-    def = qemuParseCommandLineString(caps, driver->xmlopt, config,
+    def = qemuParseCommandLineString(driver->qemuCapsCache,
+                                     caps, driver->xmlopt, config,
                                      NULL, NULL, NULL);
     if (!def)
         goto cleanup;
@@ -16606,7 +16607,8 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;
 
-    if (!(def = qemuParseCommandLinePid(caps, driver->xmlopt, pid,
+    if (!(def = qemuParseCommandLinePid(driver->qemuCapsCache,
+                                        caps, driver->xmlopt, pid,
                                         &pidfile, &monConfig, &monJSON)))
         goto cleanup;
 
index fdc1d3406873cd21d360167dd6a0f49d54efafa3..c0bf27f8003b8a7479d3c7421c4cf3e04bfe21eb 100644 (file)
@@ -1829,7 +1829,8 @@ qemuParseCommandLineBootDevs(virDomainDefPtr def, const char *str)
  * as is practical. This is not an exact science....
  */
 static virDomainDefPtr
-qemuParseCommandLine(virCapsPtr caps,
+qemuParseCommandLine(virFileCachePtr capsCache,
+                     virCapsPtr caps,
                      virDomainXMLOptionPtr xmlopt,
                      char **progenv,
                      char **progargv,
@@ -1851,6 +1852,7 @@ qemuParseCommandLine(virCapsPtr caps,
     virDomainDiskDefPtr disk = NULL;
     const char *ceph_args = qemuFindEnv(progenv, "CEPH_ARGS");
     bool have_sdl = false;
+    virQEMUCapsPtr qemuCaps;
 
     if (pidfile)
         *pidfile = NULL;
@@ -1865,6 +1867,9 @@ qemuParseCommandLine(virCapsPtr caps,
         return NULL;
     }
 
+    if (!(qemuCaps = virQEMUCapsCacheLookup(capsCache, progargv[0])))
+        goto error;
+
     if (!(def = virDomainDefNew()))
         goto error;
 
@@ -2017,17 +2022,18 @@ qemuParseCommandLine(virCapsPtr caps,
     /* If no machine type has been found among the arguments, then figure
      * out a reasonable value by using capabilities */
     if (!def->os.machine) {
-        virCapsDomainDataPtr capsdata;
+        const char *mach = virQEMUCapsGetDefaultMachine(qemuCaps);
 
-        if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
-                def->os.arch, def->virtType, NULL, NULL)))
+        if (!mach) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Binary '%s' does not have a default machine type "
+                             "and no '-machine' arg is present"),
+                           progargv[0]);
             goto error;
+        }
 
-        if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0) {
-            VIR_FREE(capsdata);
+        if (VIR_STRDUP(def->os.machine, mach) < 0)
             goto error;
-        }
-        VIR_FREE(capsdata);
     }
 
     /* Now the real processing loop */
@@ -2718,6 +2724,7 @@ qemuParseCommandLine(virCapsPtr caps,
     else
         qemuDomainCmdlineDefFree(cmd);
 
+    virObjectUnref(qemuCaps);
     return def;
 
  error:
@@ -2732,11 +2739,13 @@ qemuParseCommandLine(virCapsPtr caps,
     }
     if (pidfile)
         VIR_FREE(*pidfile);
+    virObjectUnref(qemuCaps);
     return NULL;
 }
 
 
-virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps,
+virDomainDefPtr qemuParseCommandLineString(virFileCachePtr capsCache,
+                                           virCapsPtr caps,
                                            virDomainXMLOptionPtr xmlopt,
                                            const char *args,
                                            char **pidfile,
@@ -2750,7 +2759,7 @@ virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps,
     if (qemuStringToArgvEnv(args, &progenv, &progargv) < 0)
         goto cleanup;
 
-    def = qemuParseCommandLine(caps, xmlopt, progenv, progargv,
+    def = qemuParseCommandLine(capsCache, caps, xmlopt, progenv, progargv,
                                pidfile, monConfig, monJSON);
 
  cleanup:
@@ -2808,7 +2817,8 @@ static int qemuParseProcFileStrings(int pid_value,
     return ret;
 }
 
-virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
+virDomainDefPtr qemuParseCommandLinePid(virFileCachePtr capsCache,
+                                        virCapsPtr caps,
                                         virDomainXMLOptionPtr xmlopt,
                                         pid_t pid,
                                         char **pidfile,
@@ -2828,7 +2838,7 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
         qemuParseProcFileStrings(pid, "environ", &progenv) < 0)
         goto cleanup;
 
-    if (!(def = qemuParseCommandLine(caps, xmlopt, progenv, progargv,
+    if (!(def = qemuParseCommandLine(capsCache, caps, xmlopt, progenv, progargv,
                                      pidfile, monConfig, monJSON)))
         goto cleanup;
 
index b3a950a420cf7c5c67482d69d9e20d64537725e2..a4db1a50cae5b309fc0c4ed5ea96e54735b20c83 100644 (file)
 #ifndef __QEMU_PARSE_COMMAND_H__
 # define __QEMU_PARSE_COMMAND_H__
 
+# include "virfilecache.h"
+
 # define QEMU_QXL_VGAMEM_DEFAULT 16 * 1024
 
 /*
  * NB: def->name can be NULL upon return and the caller
  * *must* decide how to fill in a name in this case
  */
-virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps,
+virDomainDefPtr qemuParseCommandLineString(virFileCachePtr capsCache,
+                                           virCapsPtr caps,
                                            virDomainXMLOptionPtr xmlopt,
                                            const char *args,
                                            char **pidfile,
                                            virDomainChrSourceDefPtr *monConfig,
                                            bool *monJSON);
-virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
+virDomainDefPtr qemuParseCommandLinePid(virFileCachePtr capsCache,
+                                        virCapsPtr caps,
                                         virDomainXMLOptionPtr xmlopt,
                                         pid_t pid,
                                         char **pidfile,
diff --git a/tests/qemuargv2xmldata/nomachine-aarch64.args b/tests/qemuargv2xmldata/nomachine-aarch64.args
deleted file mode 100644 (file)
index b17c0d0..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-LC_ALL=C \
-PATH=/bin \
-HOME=/home/test \
-USER=test \
-LOGNAME=test \
-QEMU_AUDIO_DRV=none \
-/usr/bin/qemu-system-aarch64 \
--name QEMUGuest1 \
--m 512 \
--hda /dev/HostVG/QEMUGuest1 \
--cdrom /root/boot.iso
diff --git a/tests/qemuargv2xmldata/nomachine-aarch64.xml b/tests/qemuargv2xmldata/nomachine-aarch64.xml
deleted file mode 100644 (file)
index 9492423..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<domain type='qemu'>
-  <name>QEMUGuest1</name>
-  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
-  <memory unit='KiB'>524288</memory>
-  <currentMemory unit='KiB'>524288</currentMemory>
-  <vcpu placement='static'>1</vcpu>
-  <os>
-    <type arch='aarch64' machine='virt'>hvm</type>
-    <boot dev='hd'/>
-  </os>
-  <features>
-    <gic version='2'/>
-  </features>
-  <clock offset='utc'/>
-  <on_poweroff>destroy</on_poweroff>
-  <on_reboot>restart</on_reboot>
-  <on_crash>destroy</on_crash>
-  <devices>
-    <emulator>/usr/bin/qemu-system-aarch64</emulator>
-    <disk type='block' device='disk'>
-      <driver name='qemu' type='raw'/>
-      <source dev='/dev/HostVG/QEMUGuest1'/>
-      <target dev='hda' bus='ide'/>
-      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
-    </disk>
-    <disk type='file' device='cdrom'>
-      <driver name='qemu' type='raw'/>
-      <source file='/root/boot.iso'/>
-      <target dev='hdc' bus='ide'/>
-      <readonly/>
-      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
-    </disk>
-    <controller type='ide' index='0'/>
-    <graphics type='sdl'/>
-    <video>
-      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
-    </video>
-    <memballoon model='none'/>
-  </devices>
-</domain>
index 1f15a950e3a8599f18cf2c8a975d1ba03d9a76b5..18b0c5c20a91361abc290db57c848931e261aa9c 100644 (file)
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>524288</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
-    <type arch='ppc64' machine='pseries'>hvm</type>
+    <type arch='ppc64' machine='pseries-2.12'>hvm</type>
     <boot dev='hd'/>
   </os>
   <clock offset='utc'/>
@@ -27,7 +27,7 @@
       <readonly/>
       <address type='drive' controller='0' bus='0' target='0' unit='2'/>
     </disk>
-    <controller type='usb' index='0'>
+    <controller type='usb' index='0' model='pci-ohci'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
     </controller>
     <controller type='pci' index='0' model='pci-root'>
index 33cde4c55a0fc66e60285545f20b08b088910b9b..6863c8f5f4331bcb4624a0ba6e459d7178e434b5 100644 (file)
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>524288</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
-    <type arch='x86_64' machine='pc-0.11'>hvm</type>
+    <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>
     <boot dev='hd'/>
   </os>
   <features>
@@ -30,7 +30,7 @@
       <readonly/>
       <address type='drive' controller='0' bus='1' target='0' unit='0'/>
     </disk>
-    <controller type='usb' index='0'>
+    <controller type='usb' index='0' model='piix3-uhci'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
     </controller>
     <controller type='pci' index='0' model='pci-root'/>
index 1f15a950e3a8599f18cf2c8a975d1ba03d9a76b5..18b0c5c20a91361abc290db57c848931e261aa9c 100644 (file)
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>524288</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
-    <type arch='ppc64' machine='pseries'>hvm</type>
+    <type arch='ppc64' machine='pseries-2.12'>hvm</type>
     <boot dev='hd'/>
   </os>
   <clock offset='utc'/>
@@ -27,7 +27,7 @@
       <readonly/>
       <address type='drive' controller='0' bus='0' target='0' unit='2'/>
     </disk>
-    <controller type='usb' index='0'>
+    <controller type='usb' index='0' model='pci-ohci'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
     </controller>
     <controller type='pci' index='0' model='pci-root'>
index 7787847a903fcb7dea2c27999eea385dda48b5c0..500227afc0b933f17516ed9bfd4aa2b4c4d424b4 100644 (file)
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>524288</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
-    <type arch='ppc64' machine='pseries'>hvm</type>
+    <type arch='ppc64' machine='pseries-2.12'>hvm</type>
     <boot dev='hd'/>
   </os>
   <clock offset='utc'/>
@@ -14,7 +14,7 @@
   <on_crash>destroy</on_crash>
   <devices>
     <emulator>/usr/bin/qemu-system-ppc64</emulator>
-    <controller type='usb' index='0'>
+    <controller type='usb' index='0' model='pci-ohci'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
     </controller>
     <controller type='pci' index='0' model='pci-root'>
index cb010268c48c9032263c1ec197713eefa2fc857f..966e75ef5f3e2a233401641d16274e698daed951 100644 (file)
@@ -65,7 +65,8 @@ static int testCompareXMLToArgvFiles(const char *xmlfile,
     if (virTestLoadFile(cmdfile, &cmd) < 0)
         goto fail;
 
-    if (!(vmdef = qemuParseCommandLineString(driver.caps, driver.xmlopt,
+    if (!(vmdef = qemuParseCommandLineString(driver.qemuCapsCache,
+                                             driver.caps, driver.xmlopt,
                                              cmd, NULL, NULL, NULL)))
         goto fail;
 
@@ -154,6 +155,20 @@ mymain(void)
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
+# define LOAD_CAPS(arch) \
+    do { \
+        virQEMUCapsPtr qemuCaps; \
+        qemuCaps = qemuTestParseCapabilitiesArch(VIR_ARCH_X86_64, \
+                                                 "qemucapabilitiesdata/caps_2.12.0." arch ".xml"); \
+        if (virFileCacheInsertData(driver.qemuCapsCache, \
+                                   "/usr/bin/qemu-system-" arch, \
+                                   qemuCaps) < 0) \
+            return EXIT_FAILURE; \
+    } while (0)
+
+    LOAD_CAPS("x86_64");
+    LOAD_CAPS("aarch64");
+    LOAD_CAPS("ppc64");
 
 # define DO_TEST_FULL(name, flags) \
     do { \
@@ -290,7 +305,6 @@ mymain(void)
     DO_TEST("machine-keywrap-none-argv");
 
     DO_TEST("nomachine-x86_64");
-    DO_TEST("nomachine-aarch64");
     DO_TEST("nomachine-ppc64");
 
     qemuTestDriverFree(&driver);