Re: [v7 1/6] add hostdev passthrough common library

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

 



Chunyan Liu wrote:
> Extract code from qemu_hostdev.c and make it reusable for multiple drivers,
> meanwhile maintain a global hostdev state to solve conflict between different
> drivers.
>
> Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
> ---
>  po/POTFILES.in           |    1 +
>  src/Makefile.am          |    1 +
>  src/libvirt_private.syms |   21 +
>  src/util/virhostdev.c    | 1691 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virhostdev.h    |  134 ++++
>  src/util/virpci.c        |   30 +-
>  src/util/virpci.h        |    9 +-
>  src/util/virscsi.c       |   28 +-
>  src/util/virscsi.h       |    8 +-
>  src/util/virusb.c        |   29 +-
>  src/util/virusb.h        |    8 +-
>  11 files changed, 1932 insertions(+), 28 deletions(-)
>  create mode 100644 src/util/virhostdev.c
>  create mode 100644 src/util/virhostdev.h
>   

[...]
> diff --git a/src/util/virpci.c b/src/util/virpci.c
> index 8ec642f..7402898 100644
> --- a/src/util/virpci.c
> +++ b/src/util/virpci.c
> @@ -58,7 +58,10 @@ struct _virPCIDevice {
>      char          name[PCI_ADDR_LEN]; /* domain:bus:slot.function */
>      char          id[PCI_ID_LEN];     /* product vendor */
>      char          *path;
> -    const char    *used_by;           /* The domain which uses the device */
> +
> +    /* The driver:domain which uses the device */
> +    char          *used_by_drvname;
> +    char          *used_by_domname;
>  
>      unsigned int  pcie_cap_pos;
>      unsigned int  pci_pm_cap_pos;
> @@ -1562,6 +1565,8 @@ virPCIDeviceFree(virPCIDevicePtr dev)
>      VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
>      VIR_FREE(dev->path);
>      VIR_FREE(dev->stubDriver);
> +    VIR_FREE(dev->used_by_drvname);
> +    VIR_FREE(dev->used_by_domname);
>      VIR_FREE(dev);
>  }
>  
> @@ -1631,16 +1636,27 @@ virPCIDeviceSetReprobe(virPCIDevicePtr dev, bool reprobe)
>      dev->reprobe = reprobe;
>  }
>  
> -void
> -virPCIDeviceSetUsedBy(virPCIDevicePtr dev, const char *name)
> +int
> +virPCIDeviceSetUsedBy(virPCIDevicePtr dev,
> +                      const char *drv_name,
> +                      const char *dom_name)
>  {
> -    dev->used_by = name;
> +    if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0)
> +        return -1;
> +
> +    if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
> +        return -1;
> +
> +    return 0;
>  }
>  
> -const char *
> -virPCIDeviceGetUsedBy(virPCIDevicePtr dev)
> +void
> +virPCIDeviceGetUsedBy(virPCIDevicePtr dev,
> +                      const char **drv_name,
> +                      const char **dom_name)
>  {
> -    return dev->used_by;
> +    *drv_name = dev->used_by_drvname;
> +    *dom_name = dev->used_by_domname;
>  }
>  
>  void virPCIDeviceReattachInit(virPCIDevicePtr pci)
> diff --git a/src/util/virpci.h b/src/util/virpci.h
> index 0479f0b..2347b95 100644
> --- a/src/util/virpci.h
> +++ b/src/util/virpci.h
> @@ -65,9 +65,12 @@ unsigned int virPCIDeviceGetManaged(virPCIDevice *dev);
>  int virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
>                                const char *driver);
>  const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
> -void virPCIDeviceSetUsedBy(virPCIDevice *dev,
> -                           const char *used_by);
> -const char *virPCIDeviceGetUsedBy(virPCIDevice *dev);
> +int virPCIDeviceSetUsedBy(virPCIDevice *dev,
> +                          const char *drv_name,
> +                          const char *dom_name);
> +void virPCIDeviceGetUsedBy(virPCIDevice *dev,
> +                           const char **drv_name,
> +                           const char **dom_name);
>   

This change, and the similar ones below for USB and SCSI, cause build
failures in the qemu driver without patch 2 applied.  Recall that
'make', 'make syntax-check', and 'make check' should succeed after each
patch in the series.

Regards,
Jim

>  unsigned int virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
>  void  virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
>                                      bool unbind);
> diff --git a/src/util/virscsi.c b/src/util/virscsi.c
> index 7aca9e6..062e8bd 100644
> --- a/src/util/virscsi.c
> +++ b/src/util/virscsi.c
> @@ -55,7 +55,10 @@ struct _virSCSIDevice {
>      char *name; /* adapter:bus:target:unit */
>      char *id;   /* model:vendor */
>      char *sg_path; /* e.g. /dev/sg2 */
> -    const char *used_by; /* name of the domain using this dev */
> +
> +    /* driver:domain using this dev */
> +    char *used_by_drvname;
> +    char *used_by_domname;
>  
>      bool readonly;
>  };
> @@ -259,20 +262,31 @@ virSCSIDeviceFree(virSCSIDevicePtr dev)
>      VIR_FREE(dev->id);
>      VIR_FREE(dev->name);
>      VIR_FREE(dev->sg_path);
> +    VIR_FREE(dev->used_by_drvname);
> +    VIR_FREE(dev->used_by_domname);
>      VIR_FREE(dev);
>  }
>  
> -void
> +int
>  virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
> -                       const char *name)
> +                       const char *drvname,
> +                       const char *domname)
>  {
> -    dev->used_by = name;
> +    if (VIR_STRDUP(dev->used_by_drvname, drvname) < 0)
> +        return -1;
> +    if (VIR_STRDUP(dev->used_by_domname, domname) < 0)
> +        return -1;
> +
> +    return 0;
>  }
>  
> -const char *
> -virSCSIDeviceGetUsedBy(virSCSIDevicePtr dev)
> +void
> +virSCSIDeviceGetUsedBy(virSCSIDevicePtr dev,
> +                       const char **drvname,
> +                       const char **domname)
>  {
> -    return dev->used_by;
> +    *drvname = dev->used_by_drvname;
> +    *domname = dev->used_by_domname;
>  }
>  
>  const char *
> diff --git a/src/util/virscsi.h b/src/util/virscsi.h
> index cce5df4..263b175 100644
> --- a/src/util/virscsi.h
> +++ b/src/util/virscsi.h
> @@ -49,8 +49,12 @@ virSCSIDevicePtr virSCSIDeviceNew(const char *adapter,
>                                    bool readonly);
>  
>  void virSCSIDeviceFree(virSCSIDevicePtr dev);
> -void virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, const char *name);
> -const char *virSCSIDeviceGetUsedBy(virSCSIDevicePtr dev);
> +int virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
> +                           const char *drvname,
> +                           const char *domname);
> +void virSCSIDeviceGetUsedBy(virSCSIDevicePtr dev,
> +                            const char **drvname,
> +                            const char **domname);
>  const char *virSCSIDeviceGetName(virSCSIDevicePtr dev);
>  unsigned int virSCSIDeviceGetAdapter(virSCSIDevicePtr dev);
>  unsigned int virSCSIDeviceGetBus(virSCSIDevicePtr dev);
> diff --git a/src/util/virusb.c b/src/util/virusb.c
> index 3c82200..7b17b0a 100644
> --- a/src/util/virusb.c
> +++ b/src/util/virusb.c
> @@ -55,7 +55,10 @@ struct _virUSBDevice {
>      char          name[USB_ADDR_LEN]; /* domain:bus:slot.function */
>      char          id[USB_ID_LEN];     /* product vendor */
>      char          *path;
> -    const char    *used_by;           /* name of the domain using this dev */
> +
> +    /* driver:domain using this dev */
> +    char          *used_by_drvname;
> +    char          *used_by_domname;
>  };
>  
>  struct _virUSBDeviceList {
> @@ -375,19 +378,31 @@ virUSBDeviceFree(virUSBDevicePtr dev)
>          return;
>      VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
>      VIR_FREE(dev->path);
> +    VIR_FREE(dev->used_by_drvname);
> +    VIR_FREE(dev->used_by_domname);
>      VIR_FREE(dev);
>  }
>  
> -
> -void virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
> -                           const char *name)
> +int
> +virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
> +                      const char *drv_name,
> +                      const char *dom_name)
>  {
> -    dev->used_by = name;
> +    if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0)
> +        return -1;
> +    if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
> +        return -1;
> +
> +    return 0;
>  }
>  
> -const char * virUSBDeviceGetUsedBy(virUSBDevicePtr dev)
> +void
> +virUSBDeviceGetUsedBy(virUSBDevicePtr dev,
> +                      const char **drv_name,
> +                      const char **dom_name)
>  {
> -    return dev->used_by;
> +    *drv_name = dev->used_by_drvname;
> +    *dom_name = dev->used_by_domname;
>  }
>  
>  const char *virUSBDeviceGetName(virUSBDevicePtr dev)
> diff --git a/src/util/virusb.h b/src/util/virusb.h
> index aa59d12..41e680f 100644
> --- a/src/util/virusb.h
> +++ b/src/util/virusb.h
> @@ -60,8 +60,12 @@ int virUSBDeviceFind(unsigned int vendor,
>                       virUSBDevicePtr *usb);
>  
>  void virUSBDeviceFree(virUSBDevicePtr dev);
> -void virUSBDeviceSetUsedBy(virUSBDevicePtr dev, const char *name);
> -const char *virUSBDeviceGetUsedBy(virUSBDevicePtr dev);
> +int virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
> +                          const char *drv_name,
> +                          const char *dom_name);
> +void virUSBDeviceGetUsedBy(virUSBDevicePtr dev,
> +                           const char **drv_name,
> +                           const char **dom_name);
>  const char *virUSBDeviceGetName(virUSBDevicePtr dev);
>  
>  unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev);
>   

--
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]