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.
This commit is contained in:
Osier Yang 2012-01-18 04:31:34 +08:00 committed by Eric Blake
parent 6be610bfaa
commit 7aeb9794d2

View 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);