From 61e101437bd5bdeedf843cd5bc7a4950684d905f Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Wed, 12 Oct 2016 17:02:37 +0200 Subject: [PATCH] conf: Explain some code in more detail The code is entirely correct, but it still managed to trip me up when I first ran into it because I did not realize right away that VIR_PCI_CONNECT_TYPES_ENDPOINT was not a single flag, but rather a mask including both VIR_PCI_CONNECT_TYPE_PCI_DEVICE and VIR_PCI_CONNECT_TYPE_PCIE_DEVICE. In order to save the next distracted traveler in PCI Address Land some time, document this fact with a comment. Add a test case for the behavior as well. --- src/conf/domain_addr.c | 4 +- .../qemuxml2argv-q35-pci-force-address.args | 25 ++++++++++ .../qemuxml2argv-q35-pci-force-address.xml | 32 +++++++++++++ tests/qemuxml2argvtest.c | 7 +++ .../qemuxml2xmlout-q35-pci-force-address.xml | 48 +++++++++++++++++++ tests/qemuxml2xmltest.c | 7 +++ 6 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-pci-force-address.xml diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 080d882119..1e96fe9730 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -96,7 +96,9 @@ virDomainPCIAddressFlagsCompatible(virPCIDeviceAddressPtr addr, if (fromConfig) { /* If the requested connection was manually specified in * config, allow a PCI device to connect to a PCIe slot, or - * vice versa. + * vice versa. In order to do so, we add *both* the PCI_DEVICE + * and the PCIE_DEVICE flags to the bus if it already has either + * of them, using the ENDPOINT mask. */ if (busFlags & VIR_PCI_CONNECT_TYPES_ENDPOINT) busFlags |= VIR_PCI_CONNECT_TYPES_ENDPOINT; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.args b/tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.args new file mode 100644 index 0000000000..9ca342ba71 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.args @@ -0,0 +1,25 @@ +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 i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \ +-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \ +-device ioh3420,port=0x10,chassis=3,id=pci.3,bus=pcie.0,addr=0x2 \ +-device e1000e,vlan=0,id=net0,mac=52:54:00:aa:bf:ef,bus=pci.2,addr=0x1 \ +-net user,vlan=0,name=hostnet0 \ +-device intel-hda,id=sound0,bus=pci.3,addr=0x0 \ +-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.xml b/tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.xml new file mode 100644 index 0000000000..34ec7c7750 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-q35-pci-force-address.xml @@ -0,0 +1,32 @@ + + q35-test + 11dbdcdd-4c3b-482b-8903-9bdb8c0a2774 + 2097152 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + /usr/libexec/qemu-kvm + + + + + +
+ + + + +
+ + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e8438b41e3..b1cc4d8cd5 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1756,6 +1756,13 @@ mymain(void) QEMU_CAPS_ICH9_AHCI, QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_NEC_USB_XHCI); + /* Make sure the user can always override libvirt's default device + * placement policy by providing an explicit PCI address */ + DO_TEST("q35-pci-force-address", + QEMU_CAPS_DEVICE_PCI_BRIDGE, + QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, + QEMU_CAPS_DEVICE_IOH3420, + QEMU_CAPS_HDA_DUPLEX); DO_TEST_PARSE_ERROR("q35-wrong-root", QEMU_CAPS_DEVICE_PCI_BRIDGE, diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-pci-force-address.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-pci-force-address.xml new file mode 100644 index 0000000000..c0332d4656 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-pci-force-address.xml @@ -0,0 +1,48 @@ + + q35-test + 11dbdcdd-4c3b-482b-8903-9bdb8c0a2774 + 2097152 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + /usr/libexec/qemu-kvm + + + +
+ + + + +
+ + + + +
+ + + +
+ + + + +
+ + + + +
+ + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 62bff8cd7a..95c0bf23a8 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -727,6 +727,13 @@ mymain(void) QEMU_CAPS_DEVICE_XIO3130_DOWNSTREAM, QEMU_CAPS_ICH9_AHCI, QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_NEC_USB_XHCI); + /* Make sure the user can always override libvirt's default device + * placement policy by providing an explicit PCI address */ + DO_TEST("q35-pci-force-address", + QEMU_CAPS_DEVICE_PCI_BRIDGE, + QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, + QEMU_CAPS_DEVICE_IOH3420, + QEMU_CAPS_HDA_DUPLEX); DO_TEST("hostdev-scsi-lsi", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_LSI, -- GitLab