Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx> --- src/libvirt_private.syms | 3 ++ src/qemu/qemu_driver.c | 81 ------------------------------------------------ src/util/virhostdev.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 8 +++++ 4 files changed, 92 insertions(+), 81 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0a4f341..5bb529c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1294,6 +1294,9 @@ virHookPresent; #util/virhostdev.h virHostdevManagerGetDefault; +virHostdevPciNodeDeviceDetach; +virHostdevPciNodeDeviceReAttach; +virHostdevPciNodeDeviceReset; virHostdevPreparePCIDevices; virHostdevPrepareSCSIDevices; virHostdevPrepareUSBDevices; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6b6a170..e0b92d2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11267,27 +11267,6 @@ out: } 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, unsigned int flags) @@ -11374,47 +11353,6 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev) } static int -virHostdevPciNodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr, - virPCIDevicePtr pci) -{ - virPCIDevicePtr other; - int ret = -1; - - virObjectLock(hostdev_mgr->activePciHostdevs); - virObjectLock(hostdev_mgr->inactivePciHostdevs); - other = virPCIDeviceListFind(hostdev_mgr->activePciHostdevs, pci); - if (other) { - const char *other_drvname = NULL; - const char *other_domname = NULL; - virPCIDeviceGetUsedBy(other, &other_drvname, &other_domname); - - if (other_drvname && other_domname) - virReportError(VIR_ERR_OPERATION_INVALID, - _("PCI device %s is still in use by " - "driver %s, domain %s"), - virPCIDeviceGetName(pci), - other_drvname, other_domname); - else - virReportError(VIR_ERR_OPERATION_INVALID, - _("PCI device %s is still in use"), - virPCIDeviceGetName(pci)); - goto out; - } - - virPCIDeviceReattachInit(pci); - - if (virPCIDeviceReattach(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 qemuNodeDeviceReAttach(virNodeDevicePtr dev) { virQEMUDriverPtr driver = dev->conn->privateData; @@ -11453,25 +11391,6 @@ cleanup: } static int -virHostdevPciNodeDeviceReset(virHostdevManagerPtr hostdev_mgr, - virPCIDevicePtr pci) -{ - int ret = -1; - - virObjectLock(hostdev_mgr->activePciHostdevs); - virObjectLock(hostdev_mgr->inactivePciHostdevs); - if (virPCIDeviceReset(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 qemuNodeDeviceReset(virNodeDevicePtr dev) { virQEMUDriverPtr driver = dev->conn->privateData; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index d9bfe43..4302385 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1382,3 +1382,84 @@ virHostdevReAttachScsiHostdevs(virHostdevManagerPtr hostdev_mgr, } virObjectUnlock(hostdev_mgr->activeScsiHostdevs); } + +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; +} + +int +virHostdevPciNodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr, + virPCIDevicePtr pci) +{ + virPCIDevicePtr other; + int ret = -1; + + virObjectLock(hostdev_mgr->activePciHostdevs); + virObjectLock(hostdev_mgr->inactivePciHostdevs); + other = virPCIDeviceListFind(hostdev_mgr->activePciHostdevs, pci); + if (other) { + const char *other_drvname = NULL; + const char *other_domname = NULL; + virPCIDeviceGetUsedBy(other, &other_drvname, &other_domname); + + if (other_drvname && other_domname) + virReportError(VIR_ERR_OPERATION_INVALID, + _("PCI device %s is still in use by " + "driver %s, domain %s"), + virPCIDeviceGetName(pci), + other_drvname, other_domname); + else + virReportError(VIR_ERR_OPERATION_INVALID, + _("PCI device %s is still in use"), + virPCIDeviceGetName(pci)); + goto out; + } + + virPCIDeviceReattachInit(pci); + + if (virPCIDeviceReattach(pci, hostdev_mgr->activePciHostdevs, + hostdev_mgr->inactivePciHostdevs) < 0) + goto out; + + ret = 0; +out: + virObjectUnlock(hostdev_mgr->inactivePciHostdevs); + virObjectUnlock(hostdev_mgr->activePciHostdevs); + return ret; +} + +int +virHostdevPciNodeDeviceReset(virHostdevManagerPtr hostdev_mgr, + virPCIDevicePtr pci) +{ + int ret = -1; + + virObjectLock(hostdev_mgr->activePciHostdevs); + virObjectLock(hostdev_mgr->inactivePciHostdevs); + if (virPCIDeviceReset(pci, hostdev_mgr->activePciHostdevs, + hostdev_mgr->inactivePciHostdevs) < 0) + goto out; + + ret = 0; +out: + virObjectUnlock(hostdev_mgr->inactivePciHostdevs); + virObjectUnlock(hostdev_mgr->activePciHostdevs); + return ret; +} diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 809996c..a502cfc 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -103,4 +103,12 @@ virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr, const char *drv_name, virDomainDefPtr def); +/* functions used by NodeDevDetach/Reattach/Reset */ +int virHostdevPciNodeDeviceDetach(virHostdevManagerPtr mgr, + virPCIDevicePtr pci); +int virHostdevPciNodeDeviceReAttach(virHostdevManagerPtr mgr, + virPCIDevicePtr pci); +int virHostdevPciNodeDeviceReset(virHostdevManagerPtr mgr, + virPCIDevicePtr pci); + #endif /* __VIR_HOSTDEV_H__ */ -- 1.9.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list