Re: [RFC PATCH v2 REBASE 12/18] hostdev: Introduce a reattach method for mediated devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 20, 2017 at 03:28:25PM +0100, Erik Skultety wrote:
> The name "reattach" does not really reflect the truth behind mediated
> devices, since these are purely software devices that do not need to be
> plugged back into the host in any way, however this patch pushes for
> naming consistency for methods where the logic behind the underlying
> operation stays the same except that in case of mdevs the operation
> itself is effectively a NO-OP.

This could be merged with the previous patch and you are also missing
the case when libvirtd is restarted, see qemuHostdevUpdateActiveDomainDevices.

Pavel

> 
> Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
> ---
>  src/libvirt_private.syms |  1 +
>  src/qemu/qemu_hostdev.c  | 15 ++++++++++++++
>  src/qemu/qemu_hostdev.h  |  4 ++++
>  src/util/virhostdev.c    | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virhostdev.h    |  7 +++++++
>  5 files changed, 80 insertions(+)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index e6d1282..f2e1a74 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1712,6 +1712,7 @@ virHostdevPrepareSCSIDevices;
>  virHostdevPrepareSCSIVHostDevices;
>  virHostdevPrepareUSBDevices;
>  virHostdevReAttachDomainDevices;
> +virHostdevReAttachMediatedDevices;
>  virHostdevReAttachPCIDevices;
>  virHostdevReAttachSCSIDevices;
>  virHostdevReAttachSCSIVHostDevices;
> diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
> index 45b731c..6a7232f 100644
> --- a/src/qemu/qemu_hostdev.c
> +++ b/src/qemu/qemu_hostdev.c
> @@ -419,6 +419,18 @@ qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr driver,
>  }
>  
>  void
> +qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
> +                                   const char *name,
> +                                   virDomainHostdevDefPtr *hostdevs,
> +                                   int nhostdevs)
> +{
> +    virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
> +
> +    virHostdevReAttachMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
> +                                      name, hostdevs, nhostdevs);
> +}
> +
> +void
>  qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
>                                   virDomainDefPtr def)
>  {
> @@ -436,4 +448,7 @@ qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
>  
>      qemuHostdevReAttachSCSIVHostDevices(driver, def->name, def->hostdevs,
>                                          def->nhostdevs);
> +
> +    qemuHostdevReAttachMediatedDevices(driver, def->name, def->hostdevs,
> +                                       def->nhostdevs);
>  }
> diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
> index 9399241..0096497 100644
> --- a/src/qemu/qemu_hostdev.h
> +++ b/src/qemu/qemu_hostdev.h
> @@ -84,6 +84,10 @@ void qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr driver,
>                                           const char *name,
>                                           virDomainHostdevDefPtr *hostdevs,
>                                           int nhostdevs);
> +void qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
> +                                        const char *name,
> +                                        virDomainHostdevDefPtr *hostdevs,
> +                                        int nhostdevs);
>  void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
>                                        virDomainDefPtr def);
>  
> diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
> index 681f720..2a43b4d 100644
> --- a/src/util/virhostdev.c
> +++ b/src/util/virhostdev.c
> @@ -1963,6 +1963,59 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerPtr mgr,
>      virObjectUnlock(mgr->activeSCSIVHostHostdevs);
>  }
>  
> +void
> +virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
> +                                  const char *drv_name,
> +                                  const char *dom_name,
> +                                  virDomainHostdevDefPtr *hostdevs,
> +                                  int nhostdevs)
> +{
> +    const char *used_by_drvname = NULL;
> +    const char *used_by_domname = NULL;
> +    virDomainHostdevDefPtr hostdev = NULL;
> +    virDomainHostdevSubsysMediatedDevPtr mdevsrc = NULL;
> +    size_t i;
> +
> +    if (nhostdevs == 0)
> +        return;
> +
> +    virObjectLock(mgr->activeMediatedHostdevs);
> +    for (i = 0; i < nhostdevs; i++) {
> +        virMediatedDevicePtr mdev, tmp;
> +
> +        hostdev = hostdevs[i];
> +        mdevsrc = &hostdev->source.subsys.u.mdev;
> +
> +        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
> +            hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
> +            continue;
> +
> +        if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr))) {
> +            VIR_WARN("Failed to reattach mediated device %s attached to "
> +                     "domain %s", mdevsrc->uuidstr, dom_name);
> +            continue;
> +        }
> +
> +        /* Remove from the list only mdevs assigned to @drv_name/@dom_name */
> +
> +        tmp = virMediatedDeviceListFind(mgr->activeMediatedHostdevs, mdev);
> +        virMediatedDeviceFree(mdev);
> +
> +        /* skip inactive devices */
> +        if (!tmp)
> +            continue;
> +
> +        virMediatedDeviceGetUsedBy(tmp, &used_by_drvname, &used_by_domname);
> +        if (STREQ_NULLABLE(drv_name, used_by_drvname) &&
> +            STREQ_NULLABLE(dom_name, used_by_domname)) {
> +            VIR_DEBUG("Removing %s dom=%s from activeMediatedHostdevs",
> +                      mdevsrc->uuidstr, dom_name);
> +            virMediatedDeviceListDel(mgr->activeMediatedHostdevs, tmp);
> +        }
> +    }
> +    virObjectUnlock(mgr->activeMediatedHostdevs);
> +}
> +
>  int
>  virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr,
>                                virPCIDevicePtr pci)
> diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
> index b077089..d0875d8 100644
> --- a/src/util/virhostdev.h
> +++ b/src/util/virhostdev.h
> @@ -134,6 +134,13 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerPtr hostdev_mgr,
>                                     virDomainHostdevDefPtr *hostdevs,
>                                     int nhostdevs)
>      ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
> +void
> +virHostdevReAttachMediatedDevices(virHostdevManagerPtr hostdev_mgr,
> +                                  const char *drv_name,
> +                                  const char *dom_name,
> +                                  virDomainHostdevDefPtr *hostdevs,
> +                                  int nhostdevs)
> +    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
>  int
>  virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
>                                   virDomainHostdevDefPtr *hostdevs,
> -- 
> 2.10.2
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux