diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1c0700389dd2e7e6cd7029e48ebbd2a52fe8860b..6562a1ded3247e351bac43ac4cc5256bb70c2287 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11264,6 +11264,27 @@ out: return ret; } +static int +virHostdevPciNodeDeviceDetach(virHostdevManagerPtr hostdev_mgr, + virPCIDevicePtr pci) +{ + int ret = -1; + + virObjectLock(hostdev_mgr->activePciHostdevs); + virObjectLock(hostdev_mgr->inactivePciHostdevs); + + if (virPCIDeviceDetach(pci, hostdev_mgr->activePciHostdevs, + hostdev_mgr->inactivePciHostdevs) < 0) { + goto out; + } + + ret = 0; +out: + virObjectUnlock(hostdev_mgr->inactivePciHostdevs); + virObjectUnlock(hostdev_mgr->activePciHostdevs); + return ret; +} + static int qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, const char *driverName, @@ -11336,18 +11357,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, goto cleanup; } - virObjectLock(hostdev_mgr->activePciHostdevs); - virObjectLock(hostdev_mgr->inactivePciHostdevs); - - if (virPCIDeviceDetach(pci, hostdev_mgr->activePciHostdevs, - hostdev_mgr->inactivePciHostdevs) < 0) { - goto out; - } - - ret = 0; -out: - virObjectUnlock(hostdev_mgr->inactivePciHostdevs); - virObjectUnlock(hostdev_mgr->activePciHostdevs); + ret = virHostdevPciNodeDeviceDetach(hostdev_mgr, pci); cleanup: virPCIDeviceFree(pci); virNodeDeviceDefFree(def);