[PATCH] qemu: Fix PCI address allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When attaching a PCI device which doesn't explicitly set its PCI
address, libvirt allocates the address automatically. The problem is
that when checking which PCI address is unused, we only check for those
with slot number higher than the highest slot number ever used.

Thus attaching/detaching such device several times in a row (31 is the
theoretical limit, less then 30 tries are enough in practise) makes any
further device attachment fail. Furthermore, attaching a device with
predefined PCI address to 0:0:31 immediately forbids attachment of any
PCI device without explicit address.

This patch changes the logic so that we always check all PCI addresses
before we say there is no PCI address available.
---
 src/qemu/qemu_conf.c |   14 ++++----------
 1 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 57bc02f..eaebcc1 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -2055,8 +2055,6 @@ qemuAssignDeviceAliases(virDomainDefPtr def, unsigned long long qemuCmdFlags)
 #define QEMU_PCI_ADDRESS_LAST_SLOT 31
 struct _qemuDomainPCIAddressSet {
     virHashTablePtr used;
-    int nextslot;
-    /* XXX add domain, bus later when QEMU allows > 1 */
 };
 
 
@@ -2148,9 +2146,6 @@ int qemuDomainPCIAddressReserveAddr(qemuDomainPCIAddressSetPtr addrs,
         return -1;
     }
 
-    if (dev->addr.pci.slot > addrs->nextslot)
-        addrs->nextslot = dev->addr.pci.slot + 1;
-
     return 0;
 }
 
@@ -2217,7 +2212,7 @@ int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs,
 {
     int i;
 
-    for (i = addrs->nextslot ; i <= QEMU_PCI_ADDRESS_LAST_SLOT ; i++) {
+    for (i = 0 ; i <= QEMU_PCI_ADDRESS_LAST_SLOT ; i++) {
         virDomainDeviceInfo maybe;
         char *addr;
 
@@ -2228,13 +2223,14 @@ int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs,
 
         addr = qemuPCIAddressAsString(&maybe);
 
-        VIR_DEBUG("Allocating PCI addr %s", addr);
-
         if (virHashLookup(addrs->used, addr)) {
+            VIR_DEBUG("PCI addr %s already in use", addr);
             VIR_FREE(addr);
             continue;
         }
 
+        VIR_DEBUG("Allocating PCI addr %s", addr);
+
         if (virHashAddEntry(addrs->used, addr, addr) < 0) {
             VIR_FREE(addr);
             return -1;
@@ -2245,8 +2241,6 @@ int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs,
         dev->addr.pci.bus = 0;
         dev->addr.pci.slot = i;
 
-        addrs->nextslot = i + 1;
-
         return 0;
     }
 
-- 
1.7.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]