Previous patch made it possible for the QEMU driver to check if
a given PCI hostdev is unassigned=true, meaning that this device
shouldn't be part of the actual guest launch and alias
generation.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_alias.c | 6 ++++
src/qemu/qemu_command.c | 4 +++
.../hostdev-pci-address-none.args | 31 +++++++++++++++++++
tests/qemuxml2argvtest.c | 4 +++
4 files changed, 45 insertions(+)
create mode 100644 tests/qemuxml2argvdata/hostdev-pci-address-none.args
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 93bdcb7548..8733db4cf5 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -603,6 +603,12 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr
qemuCaps)
return -1;
}
for (i = 0; i < def->nhostdevs; i++) {
+ /* do not assign alias for PCI multifunction hostdevs that
+ * will not be assigned to the guest.
+ */
+ if (def->hostdevs[i]->unassigned)
+ continue;
+
/* we can't start assigning at 0, since netdevs may have used
* up some hostdevN entries already. Also if the HostdevDef is
* linked to a NetDef, they will share an info and the alias
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ca1bd12594..d27ca39cbf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5418,6 +5418,10 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
}
}
+ /* Ignore unassigned devices */
+ if (hostdev->unassigned)
+ continue;
+
unsigned int bootIndex = hostdev->info->bootIndex;
/* bootNet will be non-0 if boot order was set and no other
diff --git a/tests/qemuxml2argvdata/hostdev-pci-address-none.args
b/tests/qemuxml2argvdata/hostdev-pci-address-none.args
new file mode 100644
index 0000000000..14fa3d6b37
--- /dev/null
+++ b/tests/qemuxml2argvdata/hostdev-pci-address-none.args
@@ -0,0 +1,31 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-delete \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-delete/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-delete/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-delete/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name delete \
+-S \
+-machine pc,accel=kvm,usb=off,dump-guest-core=off \
+-m 256 \
+-realtime mlock=off \
+-smp 4,sockets=4,cores=1,threads=1 \
+-uuid 583a8e8e-f0ce-4f53-89ab-092862148b25 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-delete/monitor.sock,\
+server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-usb \
+-device vfio-pci,host=0005:90:01.0,id=hostdev0,bus=pci.0,addr=0x3 \
+-device vfio-pci,host=0005:90:01.2,id=hostdev1,bus=pci.0,addr=0x4 \
+-device vfio-pci,host=0005:90:01.3,id=hostdev2,bus=pci.0,addr=0x5 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 07e711840d..ea9c440f5f 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1326,6 +1326,10 @@ mymain(void)
QEMU_CAPS_KVM,
QEMU_CAPS_DEVICE_VFIO_PCI);
+ DO_TEST("hostdev-pci-address-none",
+ QEMU_CAPS_KVM,
+ QEMU_CAPS_DEVICE_VFIO_PCI);
+
DO_TEST("serial-file-log",
QEMU_CAPS_CHARDEV_FILE_APPEND,
QEMU_CAPS_DEVICE_ISA_SERIAL,
--
2.21.0