mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 03:21:19 +00:00
qemu: Fix networking for ARM guests
Similar to the chardev bit, ARM boards depend on the old style '-net nic' for actually instantiating net devices. But we can't block out -netdev altogether since it's needed for upcoming virtio support. And add tests for working ARM XML with console, disk, and networking.
This commit is contained in:
parent
3730353f63
commit
54a77c6df3
@ -417,6 +417,26 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
qemuDomainSupportsNicdev(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
|
||||||
|
{
|
||||||
|
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* arm boards require legacy -net nic */
|
||||||
|
if (def->os.arch == VIR_ARCH_ARMV7L)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
qemuDomainSupportsNetdev(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
|
||||||
|
{
|
||||||
|
if (!qemuDomainSupportsNicdev(def, qemuCaps))
|
||||||
|
return false;
|
||||||
|
return virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuOpenVhostNet:
|
* qemuOpenVhostNet:
|
||||||
@ -454,8 +474,7 @@ qemuOpenVhostNet(virDomainDefPtr def,
|
|||||||
* option), don't try to open the device.
|
* option), don't try to open the device.
|
||||||
*/
|
*/
|
||||||
if (!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOST_NET) &&
|
if (!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOST_NET) &&
|
||||||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
|
qemuDomainSupportsNetdev(def, qemuCaps))) {
|
||||||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))) {
|
|
||||||
if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST) {
|
if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
"%s", _("vhost-net is not supported with "
|
"%s", _("vhost-net is not supported with "
|
||||||
@ -7335,8 +7354,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
|
|||||||
*
|
*
|
||||||
* NB, no support for -netdev without use of -device
|
* NB, no support for -netdev without use of -device
|
||||||
*/
|
*/
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
|
if (qemuDomainSupportsNetdev(def, qemuCaps)) {
|
||||||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
|
|
||||||
if (!(host = qemuBuildHostNetStr(net, driver,
|
if (!(host = qemuBuildHostNetStr(net, driver,
|
||||||
',', vlan,
|
',', vlan,
|
||||||
tapfdName, tapfdSize,
|
tapfdName, tapfdSize,
|
||||||
@ -7344,7 +7362,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
virCommandAddArgList(cmd, "-netdev", host, NULL);
|
virCommandAddArgList(cmd, "-netdev", host, NULL);
|
||||||
}
|
}
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
|
if (qemuDomainSupportsNicdev(def, qemuCaps)) {
|
||||||
bool multiqueue = tapfdSize > 1 || vhostfdSize > 1;
|
bool multiqueue = tapfdSize > 1 || vhostfdSize > 1;
|
||||||
|
|
||||||
if (!(nic = qemuBuildNicDevStr(def, net, vlan, bootindex,
|
if (!(nic = qemuBuildNicDevStr(def, net, vlan, bootindex,
|
||||||
@ -7356,8 +7374,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
virCommandAddArgList(cmd, "-net", nic, NULL);
|
virCommandAddArgList(cmd, "-net", nic, NULL);
|
||||||
}
|
}
|
||||||
if (!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
|
if (!qemuDomainSupportsNetdev(def, qemuCaps)) {
|
||||||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))) {
|
|
||||||
if (!(host = qemuBuildHostNetStr(net, driver,
|
if (!(host = qemuBuildHostNetStr(net, driver,
|
||||||
',', vlan,
|
',', vlan,
|
||||||
tapfdName, tapfdSize,
|
tapfdName, tapfdSize,
|
||||||
@ -8408,8 +8425,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
int vlan;
|
int vlan;
|
||||||
|
|
||||||
/* VLANs are not used with -netdev, so don't record them */
|
/* VLANs are not used with -netdev, so don't record them */
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
|
if (qemuDomainSupportsNetdev(def, qemuCaps))
|
||||||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
|
|
||||||
vlan = -1;
|
vlan = -1;
|
||||||
else
|
else
|
||||||
vlan = i;
|
vlan = i;
|
||||||
|
@ -799,6 +799,23 @@ qemuDomainDefPostParse(virDomainDefPtr def,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
qemuDomainDefaultNetModel(virDomainDefPtr def) {
|
||||||
|
if (def->os.arch == VIR_ARCH_S390 ||
|
||||||
|
def->os.arch == VIR_ARCH_S390X)
|
||||||
|
return "virtio";
|
||||||
|
|
||||||
|
if (def->os.arch == VIR_ARCH_ARMV7L) {
|
||||||
|
if (STREQ(def->os.machine, "versatilepb"))
|
||||||
|
return "smc91c111";
|
||||||
|
|
||||||
|
/* Incomplete. vexpress (and a few others) use this, but not all
|
||||||
|
* arm boards */
|
||||||
|
return "lan9118";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "rtl8139";
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||||
@ -814,8 +831,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
|||||||
dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
|
dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
|
||||||
!dev->data.net->model) {
|
!dev->data.net->model) {
|
||||||
if (VIR_STRDUP(dev->data.net->model,
|
if (VIR_STRDUP(dev->data.net->model,
|
||||||
def->os.arch == VIR_ARCH_S390 ||
|
qemuDomainDefaultNetModel(def)) < 0)
|
||||||
def->os.arch == VIR_ARCH_S390X ? "virtio" : "rtl8139") < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
|
||||||
|
/usr/bin/qemu-system-arm -S -M vexpress-a9 -m 1024 -smp 1 -nographic \
|
||||||
|
-nodefconfig -nodefaults -monitor unix:/tmp/test-monitor,server,nowait \
|
||||||
|
-boot c -kernel /arm.kernel -initrd /arm.initrd -append \
|
||||||
|
'console=ttyAMA0,115200n8 rw root=/dev/mmcblk0p3 rootwait physmap.enabled=0' \
|
||||||
|
-dtb /arm.dtb -usb -drive file=/arm.raw,if=sd,index=0 \
|
||||||
|
-net nic,macaddr=52:54:00:09:a4:37,vlan=0,model=lan9118,name=net0 \
|
||||||
|
-net user,vlan=0,name=hostnet0 -serial pty
|
34
tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-basic.xml
Normal file
34
tests/qemuxml2argvdata/qemuxml2argv-arm-vexpressa9-basic.xml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<domain type="qemu">
|
||||||
|
<name>armtest</name>
|
||||||
|
<uuid>496d7ea8-9739-544b-4ebd-ef08be936e6a</uuid>
|
||||||
|
<memory>1048576</memory>
|
||||||
|
<currentMemory>1048576</currentMemory>
|
||||||
|
<vcpu>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch="armv7l" machine="vexpress-a9">hvm</type>
|
||||||
|
<kernel>/arm.kernel</kernel>
|
||||||
|
<initrd>/arm.initrd</initrd>
|
||||||
|
<dtb>/arm.dtb</dtb>
|
||||||
|
<cmdline>console=ttyAMA0,115200n8 rw root=/dev/mmcblk0p3 rootwait physmap.enabled=0</cmdline>
|
||||||
|
</os>
|
||||||
|
<features>
|
||||||
|
<acpi/>
|
||||||
|
<apic/>
|
||||||
|
<pae/>
|
||||||
|
</features>
|
||||||
|
<clock offset="utc"/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>restart</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu-system-arm</emulator>
|
||||||
|
<disk type='file' device='disk'>
|
||||||
|
<source file='/arm.raw'/>
|
||||||
|
<target dev='sda' bus='sd'/>
|
||||||
|
</disk>
|
||||||
|
<interface type='user'>
|
||||||
|
<mac address='52:54:00:09:a4:37'/>
|
||||||
|
</interface>
|
||||||
|
<console type='pty'/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -1063,6 +1063,9 @@ mymain(void)
|
|||||||
|
|
||||||
DO_TEST("arm-vexpressa9-nodevs",
|
DO_TEST("arm-vexpressa9-nodevs",
|
||||||
QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DTB);
|
QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DTB);
|
||||||
|
DO_TEST("arm-vexpressa9-basic",
|
||||||
|
QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DTB,
|
||||||
|
QEMU_CAPS_DRIVE);
|
||||||
|
|
||||||
virObjectUnref(driver.config);
|
virObjectUnref(driver.config);
|
||||||
virObjectUnref(driver.caps);
|
virObjectUnref(driver.caps);
|
||||||
|
Loading…
Reference in New Issue
Block a user