Signed-off-by: Michael Roth <mdroth@xxxxxxxxxxxxxxxxxx> --- src/libvirt_private.syms | 1 + src/util/virhostdev.c | 83 ++++++++++++++++++++++++++++++++++++++++-------- src/util/virhostdev.h | 8 +++++ 3 files changed, 78 insertions(+), 14 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c1e9471..2bd3581 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1798,6 +1798,7 @@ virHostdevReAttachPCIDevices; virHostdevReAttachSCSIDevices; virHostdevReAttachSCSIVHostDevices; virHostdevReAttachUSBDevices; +virHostdevReleasePCIDevices; virHostdevUpdateActiveDomainDevices; virHostdevUpdateActiveMediatedDevices; virHostdevUpdateActivePCIDevices; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 579563c..2cd3f34 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -932,16 +932,20 @@ virHostdevReattachPCIDevice(virHostdevManagerPtr mgr, } } -/* @oldStateDir: - * For upgrade purpose: see virHostdevRestoreNetConfig +/* + * Move PCI devices to inactive list and prepare them for reattaching + * to host driver + * + * Pre-condition: inactivePCIHostdevs & activePCIHostdevs + * are locked */ -void -virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, - const char *drv_name, - const char *dom_name, - virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - const char *oldStateDir) +static void +virHostdevReleasePCIDevicesInternal(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) { virPCIDeviceListPtr pcidevs; size_t i; @@ -949,9 +953,6 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, if (!nhostdevs) return; - virObjectLock(mgr->activePCIHostdevs); - virObjectLock(mgr->inactivePCIHostdevs); - if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) { VIR_ERROR(_("Failed to allocate PCI device list: %s"), virGetLastErrorMessage()); @@ -1056,8 +1057,62 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, } } - /* Step 5: Reattach managed devices to their host drivers; unmanaged - * devices don't need to be processed further */ + cleanup: + virObjectUnref(pcidevs); +} + +void +virHostdevReleasePCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) +{ + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); + + + virHostdevReleasePCIDevicesInternal(mgr, drv_name, dom_name, + hostdevs, nhostdevs, oldStateDir); + + virObjectUnlock(mgr->activePCIHostdevs); + virObjectUnlock(mgr->inactivePCIHostdevs); +} + +/* @oldStateDir: + * For upgrade purpose: see virHostdevRestoreNetConfig + */ +void +virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) +{ + virPCIDeviceListPtr pcidevs; + size_t i; + + if (!nhostdevs) + return; + + virObjectLock(mgr->activePCIHostdevs); + virObjectLock(mgr->inactivePCIHostdevs); + + /* Release PCI devices to the inactive list */ + virHostdevReleasePCIDevicesInternal(mgr, drv_name, dom_name, + hostdevs, nhostdevs, oldStateDir); + + if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) { + VIR_ERROR(_("Failed to allocate PCI device list: %s"), + virGetLastErrorMessage()); + virResetLastError(); + goto cleanup; + } + + /* Reattach managed devices to their host drivers; unmanaged + * devices don't need to be processed further */ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) { virPCIDevicePtr pci = virPCIDeviceListGet(pcidevs, i); virPCIDevicePtr actual; diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 54e1c66..fbc7fbd 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -114,6 +114,14 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr, const char *oldStateDir) ATTRIBUTE_NONNULL(1); void +virHostdevReleasePCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) + ATTRIBUTE_NONNULL(1); +void virHostdevReAttachUSBDevices(virHostdevManagerPtr hostdev_mgr, const char *drv_name, const char *dom_name, -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list