]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Ensure that PCI device is reattached to host if hotadd fails
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 28 May 2010 11:20:24 +0000 (12:20 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 8 Jun 2010 14:21:07 +0000 (15:21 +0100)
When an attempt to hotplug a PCI device to a guest fails,
the device was left attached to pci-stub. It is neccessary
to reset the device and then attach it to the host driver
again.

* src/qemu/qemu_driver.c: Reattach PCI device to host if
  hotadd fails

src/qemu/qemu_driver.c

index e367b367acfe46511724adc812168d2193c2892f..77a956258d221f42380e1102a331ecd1e11a5c86 100644 (file)
@@ -7720,6 +7720,7 @@ static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver,
         pciFreeDevice(pci);
         return -1;
     }
+    pci = NULL; /* activePciHostdevs owns the 'pci' reference now */
 
     if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
         if (qemuAssignDeviceHostdevAlias(vm->def, hostdev, -1) < 0)
@@ -7787,8 +7788,22 @@ error:
         qemuDomainPCIAddressReleaseAddr(priv->pciaddrs, &hostdev->info) < 0)
         VIR_WARN0("Unable to release PCI address on host device");
 
-    VIR_FREE(devstr);
+    pci = pciGetDevice(hostdev->source.subsys.u.pci.domain,
+                       hostdev->source.subsys.u.pci.bus,
+                       hostdev->source.subsys.u.pci.slot,
+                       hostdev->source.subsys.u.pci.function);
+
     pciDeviceListDel(driver->activePciHostdevs, pci);
+
+    if (pciResetDevice(pci, driver->activePciHostdevs) < 0)
+        VIR_WARN0("Unable to reset PCI device after assign failure");
+    else if (hostdev->managed &&
+             pciReAttachDevice(pci) < 0)
+        VIR_WARN0("Unable to re-attach PCI device after assign failure");
+    pciFreeDevice(pci);
+
+
+    VIR_FREE(devstr);
     VIR_FREE(configfd_name);
     if (configfd >= 0)
         close(configfd);