[libvirt] [PATCH v2 5/9] hostdev: Use common detach code in virHostdevPCINodeDeviceDetach()

John Ferlan jferlan at redhat.com
Tue Jan 26 23:58:52 UTC 2016



On 01/25/2016 11:21 AM, Andrea Bolognani wrote:
> This ensures the behavior for detach is consistent, no matter how it
> was triggered (eg. 'virsh nodedev-detach', 'virsh attach-device' or
> startup of a domain that is configured to use hostdevs).
> ---
>  src/util/virhostdev.c | 28 ++++++++++++++++++++++++++--
>  1 file changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
> index 6f14574..5ded1e9 100644
> --- a/src/util/virhostdev.c
> +++ b/src/util/virhostdev.c
> @@ -1646,6 +1646,19 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr,
>      virObjectUnlock(hostdev_mgr->activeSCSIHostdevs);
>  }
>  
> +/**
> + * virHostdevPCINodeDeviceDetach:
> + * @hostdev_mgr: hostdev manager
> + * @pci: PCI device

A new PCI device to be detach from the host

IOW: Not currently on some active/inactive list, right?

Seems reasonable otherwise though.

John
> + *
> + * Detach a specific PCI device from the host.
> + *
> + * This function makes sure the device is not in use before detaching it
> + * from the host; if the device has already been detached from the host,
> + * the operation is considered successful.
> + *
> + * Returns: 0 on success, <0 on failure
> + */
>  int
>  virHostdevPCINodeDeviceDetach(virHostdevManagerPtr hostdev_mgr,
>                                virPCIDevicePtr pci)
> @@ -1660,11 +1673,22 @@ virHostdevPCINodeDeviceDetach(virHostdevManagerPtr hostdev_mgr,
>      if (virHostdevIsPCINodeDeviceUsed(virPCIDeviceGetAddress(pci), &data))
>          goto out;
>  
> -    if (virPCIDeviceDetach(pci, hostdev_mgr->activePCIHostdevs,
> -                           hostdev_mgr->inactivePCIHostdevs) < 0) {
> +    /* We want this function to be idempotent, so if the device has already
> +     * been added to the inactive list (and is not active, as per the check
> +     * above) just return right away */
> +    if (virPCIDeviceListFind(hostdev_mgr->inactivePCIHostdevs, pci)) {
> +        VIR_DEBUG("PCI device %s is already detached from the host",
> +                  virPCIDeviceGetName(pci));
> +        ret = 0;
>          goto out;
>      }
>  
> +    /* Detach the device. We don't want to skip unmanaged devices in
> +     * this case, because the user explicitly asked for the device to
> +     * be detached from the host driver */
> +    if (virHostdevOnlyDetachPCIDevice(hostdev_mgr, pci, false) < 0)
> +        goto out;
> +
>      ret = 0;
>   out:
>      virObjectUnlock(hostdev_mgr->inactivePCIHostdevs);
> 




More information about the libvir-list mailing list