1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: fix default machine for argv -> xml convertor

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>
This commit is contained in:
Daniel P. Berrangé 2018-08-13 12:42:01 +01:00
parent 81950efa0b
commit 6700062fb0
12 changed files with 70 additions and 78 deletions

View File

@ -2069,6 +2069,18 @@ const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
return name; 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, int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
const char *name) const char *name)

View File

@ -559,6 +559,7 @@ bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
virCPUMode mode); virCPUMode mode);
const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps, const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
const char *name); const char *name);
const char *virQEMUCapsGetDefaultMachine(virQEMUCapsPtr qemuCaps);
int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps, int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
const char *name); const char *name);
bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps, bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,

View File

@ -7103,7 +7103,8 @@ static char *qemuConnectDomainXMLFromNative(virConnectPtr conn,
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup; goto cleanup;
def = qemuParseCommandLineString(caps, driver->xmlopt, config, def = qemuParseCommandLineString(driver->qemuCapsCache,
caps, driver->xmlopt, config,
NULL, NULL, NULL); NULL, NULL, NULL);
if (!def) if (!def)
goto cleanup; goto cleanup;
@ -16606,7 +16607,8 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup; goto cleanup;
if (!(def = qemuParseCommandLinePid(caps, driver->xmlopt, pid, if (!(def = qemuParseCommandLinePid(driver->qemuCapsCache,
caps, driver->xmlopt, pid,
&pidfile, &monConfig, &monJSON))) &pidfile, &monConfig, &monJSON)))
goto cleanup; goto cleanup;

View File

@ -1829,7 +1829,8 @@ qemuParseCommandLineBootDevs(virDomainDefPtr def, const char *str)
* as is practical. This is not an exact science.... * as is practical. This is not an exact science....
*/ */
static virDomainDefPtr static virDomainDefPtr
qemuParseCommandLine(virCapsPtr caps, qemuParseCommandLine(virFileCachePtr capsCache,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
char **progenv, char **progenv,
char **progargv, char **progargv,
@ -1851,6 +1852,7 @@ qemuParseCommandLine(virCapsPtr caps,
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
const char *ceph_args = qemuFindEnv(progenv, "CEPH_ARGS"); const char *ceph_args = qemuFindEnv(progenv, "CEPH_ARGS");
bool have_sdl = false; bool have_sdl = false;
virQEMUCapsPtr qemuCaps;
if (pidfile) if (pidfile)
*pidfile = NULL; *pidfile = NULL;
@ -1865,6 +1867,9 @@ qemuParseCommandLine(virCapsPtr caps,
return NULL; return NULL;
} }
if (!(qemuCaps = virQEMUCapsCacheLookup(capsCache, progargv[0])))
goto error;
if (!(def = virDomainDefNew())) if (!(def = virDomainDefNew()))
goto error; goto error;
@ -2017,17 +2022,18 @@ qemuParseCommandLine(virCapsPtr caps,
/* If no machine type has been found among the arguments, then figure /* If no machine type has been found among the arguments, then figure
* out a reasonable value by using capabilities */ * out a reasonable value by using capabilities */
if (!def->os.machine) { if (!def->os.machine) {
virCapsDomainDataPtr capsdata; const char *mach = virQEMUCapsGetDefaultMachine(qemuCaps);
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, if (!mach) {
def->os.arch, def->virtType, NULL, NULL))) virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
goto error; _("Binary '%s' does not have a default machine type "
"and no '-machine' arg is present"),
if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0) { progargv[0]);
VIR_FREE(capsdata);
goto error; goto error;
} }
VIR_FREE(capsdata);
if (VIR_STRDUP(def->os.machine, mach) < 0)
goto error;
} }
/* Now the real processing loop */ /* Now the real processing loop */
@ -2718,6 +2724,7 @@ qemuParseCommandLine(virCapsPtr caps,
else else
qemuDomainCmdlineDefFree(cmd); qemuDomainCmdlineDefFree(cmd);
virObjectUnref(qemuCaps);
return def; return def;
error: error:
@ -2732,11 +2739,13 @@ qemuParseCommandLine(virCapsPtr caps,
} }
if (pidfile) if (pidfile)
VIR_FREE(*pidfile); VIR_FREE(*pidfile);
virObjectUnref(qemuCaps);
return NULL; return NULL;
} }
virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps, virDomainDefPtr qemuParseCommandLineString(virFileCachePtr capsCache,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
const char *args, const char *args,
char **pidfile, char **pidfile,
@ -2750,7 +2759,7 @@ virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps,
if (qemuStringToArgvEnv(args, &progenv, &progargv) < 0) if (qemuStringToArgvEnv(args, &progenv, &progargv) < 0)
goto cleanup; goto cleanup;
def = qemuParseCommandLine(caps, xmlopt, progenv, progargv, def = qemuParseCommandLine(capsCache, caps, xmlopt, progenv, progargv,
pidfile, monConfig, monJSON); pidfile, monConfig, monJSON);
cleanup: cleanup:
@ -2808,7 +2817,8 @@ static int qemuParseProcFileStrings(int pid_value,
return ret; return ret;
} }
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps, virDomainDefPtr qemuParseCommandLinePid(virFileCachePtr capsCache,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
pid_t pid, pid_t pid,
char **pidfile, char **pidfile,
@ -2828,7 +2838,7 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
qemuParseProcFileStrings(pid, "environ", &progenv) < 0) qemuParseProcFileStrings(pid, "environ", &progenv) < 0)
goto cleanup; goto cleanup;
if (!(def = qemuParseCommandLine(caps, xmlopt, progenv, progargv, if (!(def = qemuParseCommandLine(capsCache, caps, xmlopt, progenv, progargv,
pidfile, monConfig, monJSON))) pidfile, monConfig, monJSON)))
goto cleanup; goto cleanup;

View File

@ -24,19 +24,23 @@
#ifndef __QEMU_PARSE_COMMAND_H__ #ifndef __QEMU_PARSE_COMMAND_H__
# define __QEMU_PARSE_COMMAND_H__ # define __QEMU_PARSE_COMMAND_H__
# include "virfilecache.h"
# define QEMU_QXL_VGAMEM_DEFAULT 16 * 1024 # define QEMU_QXL_VGAMEM_DEFAULT 16 * 1024
/* /*
* NB: def->name can be NULL upon return and the caller * NB: def->name can be NULL upon return and the caller
* *must* decide how to fill in a name in this case * *must* decide how to fill in a name in this case
*/ */
virDomainDefPtr qemuParseCommandLineString(virCapsPtr caps, virDomainDefPtr qemuParseCommandLineString(virFileCachePtr capsCache,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
const char *args, const char *args,
char **pidfile, char **pidfile,
virDomainChrSourceDefPtr *monConfig, virDomainChrSourceDefPtr *monConfig,
bool *monJSON); bool *monJSON);
virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps, virDomainDefPtr qemuParseCommandLinePid(virFileCachePtr capsCache,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
pid_t pid, pid_t pid,
char **pidfile, char **pidfile,

View File

@ -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

View File

@ -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>

View File

@ -5,7 +5,7 @@
<currentMemory unit='KiB'>524288</currentMemory> <currentMemory unit='KiB'>524288</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type arch='ppc64' machine='pseries'>hvm</type> <type arch='ppc64' machine='pseries-2.12'>hvm</type>
<boot dev='hd'/> <boot dev='hd'/>
</os> </os>
<clock offset='utc'/> <clock offset='utc'/>
@ -27,7 +27,7 @@
<readonly/> <readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='2'/> <address type='drive' controller='0' bus='0' target='0' unit='2'/>
</disk> </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'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</controller> </controller>
<controller type='pci' index='0' model='pci-root'> <controller type='pci' index='0' model='pci-root'>

View File

@ -5,7 +5,7 @@
<currentMemory unit='KiB'>524288</currentMemory> <currentMemory unit='KiB'>524288</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <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'/> <boot dev='hd'/>
</os> </os>
<features> <features>
@ -30,7 +30,7 @@
<readonly/> <readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/> <address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk> </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'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller> </controller>
<controller type='pci' index='0' model='pci-root'/> <controller type='pci' index='0' model='pci-root'/>

View File

@ -5,7 +5,7 @@
<currentMemory unit='KiB'>524288</currentMemory> <currentMemory unit='KiB'>524288</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type arch='ppc64' machine='pseries'>hvm</type> <type arch='ppc64' machine='pseries-2.12'>hvm</type>
<boot dev='hd'/> <boot dev='hd'/>
</os> </os>
<clock offset='utc'/> <clock offset='utc'/>
@ -27,7 +27,7 @@
<readonly/> <readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='2'/> <address type='drive' controller='0' bus='0' target='0' unit='2'/>
</disk> </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'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</controller> </controller>
<controller type='pci' index='0' model='pci-root'> <controller type='pci' index='0' model='pci-root'>

View File

@ -5,7 +5,7 @@
<currentMemory unit='KiB'>524288</currentMemory> <currentMemory unit='KiB'>524288</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type arch='ppc64' machine='pseries'>hvm</type> <type arch='ppc64' machine='pseries-2.12'>hvm</type>
<boot dev='hd'/> <boot dev='hd'/>
</os> </os>
<clock offset='utc'/> <clock offset='utc'/>
@ -14,7 +14,7 @@
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/bin/qemu-system-ppc64</emulator> <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'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</controller> </controller>
<controller type='pci' index='0' model='pci-root'> <controller type='pci' index='0' model='pci-root'>

View File

@ -65,7 +65,8 @@ static int testCompareXMLToArgvFiles(const char *xmlfile,
if (virTestLoadFile(cmdfile, &cmd) < 0) if (virTestLoadFile(cmdfile, &cmd) < 0)
goto fail; goto fail;
if (!(vmdef = qemuParseCommandLineString(driver.caps, driver.xmlopt, if (!(vmdef = qemuParseCommandLineString(driver.qemuCapsCache,
driver.caps, driver.xmlopt,
cmd, NULL, NULL, NULL))) cmd, NULL, NULL, NULL)))
goto fail; goto fail;
@ -154,6 +155,20 @@ mymain(void)
if (qemuTestDriverInit(&driver) < 0) if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE; 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) \ # define DO_TEST_FULL(name, flags) \
do { \ do { \
@ -290,7 +305,6 @@ mymain(void)
DO_TEST("machine-keywrap-none-argv"); DO_TEST("machine-keywrap-none-argv");
DO_TEST("nomachine-x86_64"); DO_TEST("nomachine-x86_64");
DO_TEST("nomachine-aarch64");
DO_TEST("nomachine-ppc64"); DO_TEST("nomachine-ppc64");
qemuTestDriverFree(&driver); qemuTestDriverFree(&driver);