]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Prohibit reattaching node device if it is in use
authorOsier Yang <jyang@redhat.com>
Tue, 17 Jan 2012 20:31:34 +0000 (04:31 +0800)
committerEric Blake <eblake@redhat.com>
Wed, 18 Jan 2012 00:15:22 +0000 (17:15 -0700)
It doesn't make sense to reattach a device to host while it's
still in use, e.g, by a domain.

src/qemu/qemu_driver.c

index 47e23802f767cac253c611b685a35d44b3e08fe9..c920bfd18d2fecdd5545ed76aa7b7c02d349418c 100644 (file)
@@ -9244,6 +9244,7 @@ qemudNodeDeviceReAttach (virNodeDevicePtr dev)
 {
     struct qemud_driver *driver = dev->conn->privateData;
     pciDevice *pci;
+    pciDevice *other;
     unsigned domain, bus, slot, function;
     int ret = -1;
 
@@ -9254,6 +9255,20 @@ qemudNodeDeviceReAttach (virNodeDevicePtr dev)
     if (!pci)
         return -1;
 
+    other = pciDeviceListFind(driver->activePciHostdevs, pci);
+    if (other) {
+        const char *other_name = pciDeviceGetUsedBy(other);
+
+        if (other_name)
+            qemuReportError(VIR_ERR_OPERATION_INVALID,
+                            _("PCI device %s is still in use by domain %s"),
+                            pciDeviceGetName(pci), other_name);
+        else
+            qemuReportError(VIR_ERR_OPERATION_INVALID,
+                            _("PCI device %s is still in use"),
+                            pciDeviceGetName(pci));
+    }
+
     pciDeviceReAttachInit(pci);
 
     qemuDriverLock(driver);