From: Osier Yang Date: Tue, 17 Jan 2012 20:31:34 +0000 (+0800) Subject: qemu: Prohibit reattaching node device if it is in use X-Git-Tag: v0.9.10-rc1~165 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7aeb9794d235f8383c6901957f6e464e1f206b58;p=thirdparty%2Flibvirt.git qemu: Prohibit reattaching node device if it is in use It doesn't make sense to reattach a device to host while it's still in use, e.g, by a domain. --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 47e23802f7..c920bfd18d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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);