If the multifunction attribute isn't set in the config for the device
at function 0 of a slot used for multifunction, it would previously
have been an error. This patch will instead automatically correct the
omission (but only if it hasn't been set at all - if someone
explicitly has "multifunction='off'" on function 0, or
"multifunction='on'" when function != 0, we have to assume they have a
reason for that).
This effectively obsoletes the requirement of specifying
multifunction='on' in the config, although you're still free to do
so. Note that if you migrate a domain that needs an implied
"multifunction='on'" back to any older libvirt that doesn't have
it,
the migration will fail. (Note that this would only be an issue with a
domain config that was *created* on a newer libvirt; any config
created on an older libvirt and then later migrated to a newer libvirt
would necessarily have multifunction explicitly set in the config, and
that will not be lost during migration).
---
src/qemu/qemu_command.c | 16 +++++-
.../qemuxml2argv-q35-multifunction.args | 31 +++++++++++
.../qemuxml2argv-q35-multifunction.xml | 40 +++++++++++++
tests/qemuxml2argvtest.c | 23 ++++++++
.../qemuxml2xmlout-q35-multifunction.xml | 65 ++++++++++++++++++++++
tests/qemuxml2xmltest.c | 23 ++++++++
6 files changed, 196 insertions(+), 2 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-multifunction.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 96c4f31..01590da 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -295,6 +295,7 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
int ret = -1;
char *devStr = NULL;
const char *contAlias = NULL;
+ virTristateSwitch multi = VIR_TRISTATE_SWITCH_ABSENT;
if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
size_t i;
@@ -327,6 +328,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
goto cleanup;
}
+ multi = info->addr.pci.multi;
+
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_MULTIFUNCTION)) {
if (info->addr.pci.function != 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -340,6 +343,15 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
"this QEMU binary"));
goto cleanup;
}
+ } else if (info->addr.pci.function == 0 &&
+ multi == VIR_TRISTATE_SWITCH_ABSENT &&
+ virDomainPCIAddressIsMulti(domainDef, &info->addr.pci)) {
+ /* Even if the config doesn't tell us, by definition we
+ * must have multifunction=on in the commandline for the
+ * device at function 0 if there are any other devices on
+ * the same slot.
+ */
+ multi = VIR_TRISTATE_SWITCH_ON;
}
if (info->addr.pci.bus != 0 &&
@@ -351,9 +363,9 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
}
virBufferAsprintf(buf, ",bus=%s", contAlias);
- if (info->addr.pci.multi == VIR_TRISTATE_SWITCH_ON)
+ if (multi == VIR_TRISTATE_SWITCH_ON)
virBufferAddLit(buf, ",multifunction=on");
- else if (info->addr.pci.multi == VIR_TRISTATE_SWITCH_OFF)
+ else if (multi == VIR_TRISTATE_SWITCH_OFF)
virBufferAddLit(buf, ",multifunction=off");
virBufferAsprintf(buf, ",addr=0x%x", info->addr.pci.slot);
if (info->addr.pci.function != 0)
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.args
b/tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.args
new file mode 100644
index 0000000..de1a4a4
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.args
@@ -0,0 +1,31 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/libexec/qemu-kvm \
+-name q35-test \
+-S \
+-M q35 \
+-m 2048 \
+-smp 2,sockets=2,cores=1,threads=1 \
+-uuid 11dbdcdd-4c3b-482b-8903-9bdb8c0a2774 \
+-nographic \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-q35-test/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-device ioh3420,port=0x10,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,\
+addr=0x2 \
+-device ioh3420,port=0x11,chassis=2,id=pci.2,bus=pcie.0,addr=0x2.0x1 \
+-device ioh3420,port=0x12,chassis=3,id=pci.3,bus=pcie.0,addr=0x2.0x2 \
+-device ioh3420,port=0x18,chassis=4,id=pci.4,bus=pcie.0,multifunction=on,\
+addr=0x3 \
+-device ioh3420,port=0x19,chassis=5,id=pci.5,bus=pcie.0,multifunction=on,\
+addr=0x3.0x1 \
+-device ioh3420,port=0x20,chassis=6,id=pci.6,bus=pcie.0,multifunction=off,\
+addr=0x4 \
+-device ioh3420,port=0x21,chassis=7,id=pci.7,bus=pcie.0,addr=0x4.0x1 \
+-device nec-usb-xhci,id=usb,bus=pci.1,addr=0x0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.xml
b/tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.xml
new file mode 100644
index 0000000..b1f3c5e
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.xml
@@ -0,0 +1,40 @@
+<domain type='qemu'>
+ <name>q35-test</name>
+ <uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
+ <memory unit='KiB'>2097152</memory>
+ <currentMemory unit='KiB'>2097152</currentMemory>
+ <vcpu placement='static' cpuset='0-1'>2</vcpu>
+ <os>
+ <type arch='x86_64' machine='q35'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/libexec/qemu-kvm</emulator>
+ <controller type='pci' model='pcie-root'/>
+ <controller type='pci' model='pcie-root-port'>
+ <address type='pci' slot='2' function='0'/>
+ </controller>
+ <controller type='pci' model='pcie-root-port'>
+ <address type='pci' slot='2' function='1'/>
+ </controller>
+ <controller type='pci' model='pcie-root-port'>
+ <address type='pci' slot='2' function='2'/>
+ </controller>
+ <controller type='pci' model='pcie-root-port'>
+ <address type='pci' slot='3' function='0'/>
+ </controller>
+ <controller type='pci' model='pcie-root-port'>
+ <address type='pci' slot='3' function='1'
multifunction='on'/>
+ </controller>
+ <controller type='pci' model='pcie-root-port'>
+ <address type='pci' slot='4' function='0'
multifunction='off'/>
+ </controller>
+ <controller type='pci' model='pcie-root-port'>
+ <address type='pci' slot='4' function='1'/>
+ </controller>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 2b6ce10..20ea95b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1881,6 +1881,29 @@ mymain(void)
QEMU_CAPS_ICH9_USB_EHCI1,
QEMU_CAPS_NEC_USB_XHCI,
QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
+ DO_TEST("q35-multifunction",
+ QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY,
+ QEMU_CAPS_DEVICE_VIRTIO_RNG,
+ QEMU_CAPS_OBJECT_RNG_RANDOM,
+ QEMU_CAPS_NETDEV,
+ QEMU_CAPS_DEVICE_VIRTIO_NET,
+ QEMU_CAPS_DEVICE_VIRTIO_GPU,
+ QEMU_CAPS_VIRTIO_GPU_VIRGL,
+ QEMU_CAPS_VIRTIO_KEYBOARD,
+ QEMU_CAPS_VIRTIO_MOUSE,
+ QEMU_CAPS_VIRTIO_TABLET,
+ QEMU_CAPS_VIRTIO_INPUT_HOST,
+ QEMU_CAPS_VIRTIO_SCSI,
+ QEMU_CAPS_FSDEV,
+ QEMU_CAPS_FSDEV_WRITEOUT,
+ QEMU_CAPS_DEVICE_PCI_BRIDGE,
+ QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
+ QEMU_CAPS_DEVICE_IOH3420,
+ QEMU_CAPS_ICH9_AHCI,
+ QEMU_CAPS_PCI_MULTIFUNCTION,
+ QEMU_CAPS_ICH9_USB_EHCI1,
+ QEMU_CAPS_NEC_USB_XHCI,
+ QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
DO_TEST("q35-virt-manager-basic",
QEMU_CAPS_KVM,
QEMU_CAPS_RTC,
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-multifunction.xml
b/tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-multifunction.xml
new file mode 100644
index 0000000..3d5cd76
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-multifunction.xml
@@ -0,0 +1,65 @@
+<domain type='qemu'>
+ <name>q35-test</name>
+ <uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
+ <memory unit='KiB'>2097152</memory>
+ <currentMemory unit='KiB'>2097152</currentMemory>
+ <vcpu placement='static' cpuset='0-1'>2</vcpu>
+ <os>
+ <type arch='x86_64' machine='q35'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/libexec/qemu-kvm</emulator>
+ <controller type='pci' index='0' model='pcie-root'/>
+ <controller type='pci' index='1'
model='pcie-root-port'>
+ <model name='ioh3420'/>
+ <target chassis='1' port='0x10'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x0'/>
+ </controller>
+ <controller type='pci' index='2'
model='pcie-root-port'>
+ <model name='ioh3420'/>
+ <target chassis='2' port='0x11'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x1'/>
+ </controller>
+ <controller type='pci' index='3'
model='pcie-root-port'>
+ <model name='ioh3420'/>
+ <target chassis='3' port='0x12'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x2'/>
+ </controller>
+ <controller type='pci' index='4'
model='pcie-root-port'>
+ <model name='ioh3420'/>
+ <target chassis='4' port='0x18'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x03' function='0x0'/>
+ </controller>
+ <controller type='pci' index='5'
model='pcie-root-port'>
+ <model name='ioh3420'/>
+ <target chassis='5' port='0x19'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x03' function='0x1' multifunction='on'/>
+ </controller>
+ <controller type='pci' index='6'
model='pcie-root-port'>
+ <model name='ioh3420'/>
+ <target chassis='6' port='0x20'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x04' function='0x0' multifunction='off'/>
+ </controller>
+ <controller type='pci' index='7'
model='pcie-root-port'>
+ <model name='ioh3420'/>
+ <target chassis='7' port='0x21'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x04' function='0x1'/>
+ </controller>
+ <controller type='usb' index='0' model='nec-xhci'>
+ <address type='pci' domain='0x0000' bus='0x01'
slot='0x00' function='0x0'/>
+ </controller>
+ <controller type='sata' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x1f' function='0x2'/>
+ </controller>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='virtio'>
+ <address type='pci' domain='0x0000' bus='0x02'
slot='0x00' function='0x0'/>
+ </memballoon>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index e22b63f..20b9b17 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -794,6 +794,29 @@ mymain(void)
QEMU_CAPS_ICH9_USB_EHCI1,
QEMU_CAPS_NEC_USB_XHCI,
QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
+ DO_TEST("q35-multifunction",
+ QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY,
+ QEMU_CAPS_DEVICE_VIRTIO_RNG,
+ QEMU_CAPS_OBJECT_RNG_RANDOM,
+ QEMU_CAPS_NETDEV,
+ QEMU_CAPS_DEVICE_VIRTIO_NET,
+ QEMU_CAPS_DEVICE_VIRTIO_GPU,
+ QEMU_CAPS_VIRTIO_GPU_VIRGL,
+ QEMU_CAPS_VIRTIO_KEYBOARD,
+ QEMU_CAPS_VIRTIO_MOUSE,
+ QEMU_CAPS_VIRTIO_TABLET,
+ QEMU_CAPS_VIRTIO_INPUT_HOST,
+ QEMU_CAPS_VIRTIO_SCSI,
+ QEMU_CAPS_FSDEV,
+ QEMU_CAPS_FSDEV_WRITEOUT,
+ QEMU_CAPS_DEVICE_PCI_BRIDGE,
+ QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
+ QEMU_CAPS_DEVICE_IOH3420,
+ QEMU_CAPS_ICH9_AHCI,
+ QEMU_CAPS_PCI_MULTIFUNCTION,
+ QEMU_CAPS_ICH9_USB_EHCI1,
+ QEMU_CAPS_NEC_USB_XHCI,
+ QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
DO_TEST("q35-virt-manager-basic",
QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY,
QEMU_CAPS_DEVICE_VIRTIO_RNG,
--
2.7.4