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

Re: [PATCH v4 13/23] libxl: use COMPARE_PCI() macro is_pci_in_array()...


  • To: Paul Durrant <paul@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>
  • Date: Tue, 1 Dec 2020 15:20:26 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OpHT8MI2KZOG8h1yXjHL9YFDFZiOlGf6i/sOnfTamDQ=; b=NKPVK94hbnoFAYk+FbcsmsKXi4GxCM/Kh+WUcBcXndNXcUDmlIT/FRi4qvgpdqcDyAoQZBKdKC509VNN9OyVo909wbVqNoBNufdcJnQjBzdzXrjPc8Ks0v8g6IuEKGTpthg6JPp3gkv3Y8y+Iwl2VLjRrJwsco/5FVTTDs722dD+jst0pMgniUJn30PIp4Oqbdk9BH5jKNa8a38K382cDNTltt+X9mDLgTwwFf6z0PglRMVOR0Y/LlNMeVqzMLsTykXAb+h7VzWWB52VRO+ET0fvKJKxVD/qsOdLcayGOVLi56M6anX1nMRg8rTewC3CIiNMTmlKgncseCa75jLa3Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ne4e24vNTq7BGhOqI+cKdCEVddJykG/t/+Fb0I6Dmv5Ph/c+8GanJNKH6Sl0C0Hr837n+pEoT7AQk/dLHdUG+VQAULFJxUvfUY7Bh2ddcnvq77is3bE1g5Bjhkrg32h4zhJYEPJmcs+3XhJ6VXOYT42UA1+pkbJtsmksf5Z9C59E/6mjwwnMROeUbcNLhGJ3o7KORZuvZrcPXnWU6LOD4ojKpJMFqB+GBZPZa8lKD/u1XwV5PpHy3C2om13uXJrur8itDFcfY7K0fG0Z4K2j84Wt3Qs640rKKeHd3B1IlIDa18kLGm9t6y59E1MF1rXQG4SLvENqFF8XZ/EXAWLBhg==
  • Authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=epam.com;
  • Cc: Paul Durrant <pdurrant@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 01 Dec 2020 15:20:35 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHWx/V+Aj8+RUjOSEaa4IIEDCcUXQ==
  • Thread-topic: [PATCH v4 13/23] libxl: use COMPARE_PCI() macro is_pci_in_array()...

Hi, Paul!

On 11/24/20 10:01 AM, Paul Durrant wrote:
> From: Paul Durrant <pdurrant@xxxxxxxxxx>
>
> ... rather than an open-coded equivalent.
>
> This patch tidies up the is_pci_in_array() function, making it take a single
> 'libxl_device_pci' argument rather than separate domain, bus, device and
> function arguments. The already-available COMPARE_PCI() macro can then be
> used and it is also modified to return 'bool' rather than 'int'.
>
> The patch also modifies libxl_pci_assignable() to use is_pci_in_array() rather
> than a separate open-coded equivalent, and also modifies it to return a
> 'bool' rather than an 'int'.
>
> NOTE: The COMPARE_PCI() macro is also fixed to include the 'domain' in its
>        comparison, which should always have been the case.
>
> Signed-off-by: Paul Durrant <pdurrant@xxxxxxxxxx>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>

Thank you,

Oleksandr

> ---
> Cc: Ian Jackson <iwj@xxxxxxxxxxxxxx>
> Cc: Wei Liu <wl@xxxxxxx>
> ---
>   tools/libs/light/libxl_internal.h |  7 ++++---
>   tools/libs/light/libxl_pci.c      | 38 
> +++++++++++++-------------------------
>   2 files changed, 17 insertions(+), 28 deletions(-)
>
> diff --git a/tools/libs/light/libxl_internal.h 
> b/tools/libs/light/libxl_internal.h
> index ecee61b541..02f8a3179c 100644
> --- a/tools/libs/light/libxl_internal.h
> +++ b/tools/libs/light/libxl_internal.h
> @@ -4746,9 +4746,10 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx,
>    * devices have same identifier. */
>   #define COMPARE_DEVID(a, b) ((a)->devid == (b)->devid)
>   #define COMPARE_DISK(a, b) (!strcmp((a)->vdev, (b)->vdev))
> -#define COMPARE_PCI(a, b) ((a)->func == (b)->func &&    \
> -                           (a)->bus == (b)->bus &&      \
> -                           (a)->dev == (b)->dev)
> +#define COMPARE_PCI(a, b) ((a)->domain == (b)->domain && \
> +                           (a)->bus == (b)->bus &&       \
> +                           (a)->dev == (b)->dev &&       \
> +                           (a)->func == (b)->func)
>   #define COMPARE_USB(a, b) ((a)->ctrl == (b)->ctrl && \
>                              (a)->port == (b)->port)
>   #define COMPARE_USBCTRL(a, b) ((a)->devid == (b)->devid)
> diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
> index 5a3352c2ec..e0b616fe18 100644
> --- a/tools/libs/light/libxl_pci.c
> +++ b/tools/libs/light/libxl_pci.c
> @@ -336,24 +336,17 @@ retry_transaction2:
>       return 0;
>   }
>   
> -static int is_pci_in_array(libxl_device_pci *assigned, int num_assigned,
> -                           int dom, int bus, int dev, int func)
> +static bool is_pci_in_array(libxl_device_pci *pcis, int num,
> +                            libxl_device_pci *pci)
>   {
>       int i;
>   
> -    for(i = 0; i < num_assigned; i++) {
> -        if ( assigned[i].domain != dom )
> -            continue;
> -        if ( assigned[i].bus != bus )
> -            continue;
> -        if ( assigned[i].dev != dev )
> -            continue;
> -        if ( assigned[i].func != func )
> -            continue;
> -        return 1;
> +    for (i = 0; i < num; i++) {
> +        if (COMPARE_PCI(pci, &pcis[i]))
> +            break;
>       }
>   
> -    return 0;
> +    return i < num;
>   }
>   
>   /* Write the standard BDF into the sysfs path given by sysfs_path. */
> @@ -1487,21 +1480,17 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t 
> domid,
>       return AO_INPROGRESS;
>   }
>   
> -static int libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci)
> +static bool libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci)
>   {
>       libxl_device_pci *pcis;
> -    int num, i;
> +    int num;
> +    bool assignable;
>   
>       pcis = libxl_device_pci_assignable_list(ctx, &num);
> -    for (i = 0; i < num; i++) {
> -        if (pcis[i].domain == pci->domain &&
> -            pcis[i].bus == pci->bus &&
> -            pcis[i].dev == pci->dev &&
> -            pcis[i].func == pci->func)
> -            break;
> -    }
> +    assignable = is_pci_in_array(pcis, num, pci);
>       libxl_device_pci_assignable_list_free(pcis, num);
> -    return i != num;
> +
> +    return assignable;
>   }
>   
>   static void device_pci_add_stubdom_wait(libxl__egc *egc,
> @@ -1834,8 +1823,7 @@ static void do_pci_remove(libxl__egc *egc, 
> pci_remove_state *prs)
>           goto out_fail;
>       }
>   
> -    attached = is_pci_in_array(pcis, num, pci->domain,
> -                               pci->bus, pci->dev, pci->func);
> +    attached = is_pci_in_array(pcis, num, pci);
>       libxl_device_pci_list_free(pcis, num);
>   
>       rc = ERROR_INVAL;

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.