]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: set pciConnectFlags to 0 instead of PCI|HOTPLUGGABLE if device isn't PCI
authorLaine Stump <laine@laine.org>
Fri, 7 Oct 2016 22:08:13 +0000 (18:08 -0400)
committerLaine Stump <laine@laine.org>
Mon, 14 Nov 2016 19:14:38 +0000 (14:14 -0500)
This patch cleans up the connect flags for certain types/models of
devices that aren't PCI to return 0. In the future that may be used as
an indicator to the caller about whether or not a device needs a PCI
address. For now it's just ignored, except for in
virDomainPCIAddressEnsureAddr() - called during device hotplug - (and
in some cases actually needs to be re-set to PCI|HOTPLUGGABLE just in
case someone (in some old config) has manually set a PCI address for a
device that isn't PCI.

src/conf/domain_addr.c
src/qemu/qemu_domain_address.c

index 0346471ea411c1a5439df860a17cbf4770a3a2f2..d3a2f6f23ec19a84cab1c1d3f2ba2218daf96f88 100644 (file)
@@ -493,6 +493,12 @@ virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr addrs,
     int ret = -1;
     char *addrStr = NULL;
 
+    /* if flags is 0, the particular model of this device on this
+     * machinetype doesn't need a PCI address, so we're done.
+     */
+    if (!flags)
+       return 0;
+
     if (!(addrStr = virDomainPCIAddressAsString(&dev->addr.pci)))
         goto cleanup;
 
index 4cdff7a57d164465dee6ec2333f07cce5d8592cd..4c688b18989dfded8094fe0a73e489b561cca8a7 100644 (file)
@@ -467,8 +467,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
             case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2: /* xen only */
             case VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE:
             case VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST:
-                /* should be 0 */
-                return pciFlags;
+                return 0;
             }
 
         case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
@@ -497,8 +496,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
          */
         if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||
             STREQ(net->model, "usb-net")) {
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
         return pciFlags;
     }
@@ -515,8 +513,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
         case VIR_DOMAIN_SOUND_MODEL_PCSPK:
         case VIR_DOMAIN_SOUND_MODEL_USB:
         case VIR_DOMAIN_SOUND_MODEL_LAST:
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
 
     case VIR_DOMAIN_DEVICE_DISK:
@@ -533,8 +530,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
         case VIR_DOMAIN_DISK_BUS_SATA:
         case VIR_DOMAIN_DISK_BUS_SD:
         case VIR_DOMAIN_DISK_BUS_LAST:
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
 
     case VIR_DOMAIN_DEVICE_HOSTDEV:
@@ -548,8 +544,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
         case VIR_DOMAIN_MEMBALLOON_MODEL_XEN:
         case VIR_DOMAIN_MEMBALLOON_MODEL_NONE:
         case VIR_DOMAIN_MEMBALLOON_MODEL_LAST:
-            /* should be 0 (not PCI) */
-            return pciFlags;
+            return 0;
         }
 
     case VIR_DOMAIN_DEVICE_RNG:
@@ -558,8 +553,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
             return pciFlags;
 
         case VIR_DOMAIN_RNG_MODEL_LAST:
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
 
     case VIR_DOMAIN_DEVICE_WATCHDOG:
@@ -571,8 +565,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
         case VIR_DOMAIN_WATCHDOG_MODEL_IB700:
         case VIR_DOMAIN_WATCHDOG_MODEL_DIAG288:
         case VIR_DOMAIN_WATCHDOG_MODEL_LAST:
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
 
     case VIR_DOMAIN_DEVICE_VIDEO:
@@ -588,8 +581,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
             return pciFlags;
 
         case VIR_DOMAIN_VIDEO_TYPE_LAST:
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
 
     case VIR_DOMAIN_DEVICE_SHMEM:
@@ -605,8 +597,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
         case VIR_DOMAIN_INPUT_BUS_XEN:
         case VIR_DOMAIN_INPUT_BUS_PARALLELS:
         case VIR_DOMAIN_INPUT_BUS_LAST:
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
 
     case VIR_DOMAIN_DEVICE_CHR:
@@ -617,8 +608,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
-            /* should be 0 */
-            return pciFlags;
+            return 0;
         }
 
     /* These devices don't ever connect with PCI */
@@ -635,8 +625,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
     case VIR_DOMAIN_DEVICE_IOMMU:
     case VIR_DOMAIN_DEVICE_LAST:
     case VIR_DOMAIN_DEVICE_NONE:
-        /* should be 0 */
-        return pciFlags;
+        return 0;
     }
 
     /* We can never get here, because all cases are covered in the
@@ -816,6 +805,28 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
         return 0;
     }
 
+    /* If we get to here, the device has a PCI address assigned in the
+     * config and we should mark it as in-use. But if the
+     * pciConnectFlags are 0, then this device shouldn't have a PCI
+     * address associated with it. *BUT* since there are cases in the
+     * past where we've apparently allowed that, we need to pretend
+     * for now that it's okay, otherwise an existing domain could
+     * "disappear" from the list of domains due to a parse failure. We
+     * can fix this by just forcing the pciConnectFlags to be
+     * PCI_DEVICE (and then relying on validation functions to report
+     * inappropriate address types.
+     */
+    if (!info->pciConnectFlags) {
+        char *addrStr = virDomainPCIAddressAsString(&info->addr.pci);
+
+        VIR_WARN("qemuDomainDeviceCalculatePCIConnectFlags() thinks that the "
+                 "device with PCI address %s should not have a PCI address",
+                 addrStr ? addrStr : "(unknown)");
+        VIR_FREE(addrStr);
+
+        info->pciConnectFlags = VIR_PCI_CONNECT_TYPE_PCI_DEVICE;
+    }
+
     /* Ignore implicit controllers on slot 0:0:1.0:
      * implicit IDE controller on 0:0:1.1 (no qemu command line)
      * implicit USB controller on 0:0:1.2 (-usb)