
On Tue, Jan 19, 2016 at 04:36:06PM +0100, Andrea Bolognani wrote:
This function mirrors reattachPCIDevices().
The handling of active and inactive devices is updated and made more explicit, which means virHostdevPreparePCIDevices() has to be updated as well. --- src/util/virhostdev.c | 125 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 49 deletions(-)
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 74c43f2..2d219dd 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -593,6 +593,56 @@ reattachPCIDevices(virHostdevManagerPtr mgr, return ret; }
+/** + * detachPCIDevices:
Please keep a virHostdev prefix on this method, and also on the one added in the earlier patch. All methods should be prefixed to match the filename, even if they're static
+ * @mgr: hostdev manager + * @pcidevs: PCI devices to be detached + * @skipUnmanaged: whether to skip unmanaged devices + * + * Detach PCI devices from the host. + * + * The PCI related parts of @mgr (inactivePCIHostdevs, activePCIHostdevs) + * must have been locked beforehand using virObjectLock(). + * + * Returns: 0 on success, <0 on failure + */ +static int +detachPCIDevices(virHostdevManagerPtr mgr, + virPCIDeviceListPtr pcidevs, + bool skipUnmanaged) +{ + size_t i; + int ret = -1; + + for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) { + virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i); + + /* Skip unmanaged devices if asked to do so */ + if (!virPCIDeviceGetManaged(dev) && skipUnmanaged) { + VIR_DEBUG("Not detaching unmanaged PCI device %s", + virPCIDeviceGetName(dev)); + continue; + } + + VIR_DEBUG("Detaching managed PCI device %s", + virPCIDeviceGetName(dev)); + if (virPCIDeviceDetach(dev, + mgr->activePCIHostdevs, + mgr->inactivePCIHostdevs) < 0) { + virErrorPtr err = virGetLastError(); + VIR_ERROR(_("Failed to detach PCI device: %s"), + err ? err->message : _("unknown error")); + virResetError(err); + goto out; + } + } + + ret = 0; + + out: + return ret; +}
Again the body of the for() loop should really be a separate method that you can call passing in a single PCI device, to avoid later code where you have to stuff a single device into a list. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|