On Fri, Jul 17, 2015 at 18:13:23 +0200, Andrea Bolognani wrote:
> If the cpu/present file is not available, we assume that the kernel
> is too old to support non-consecutive CPU ids and return a bitmap
> with all the bits set to represent this fact. This assumption is
> already exploited in nodeGetCPUCount().
> 
> This means users of this API can expect the information to always
> be available unless an error has occurred, and no longer need to
> treat the NULL return value as a special case.
> 
> The error message has been updated as well.
> ---
>  src/nodeinfo.c | 46 ++++++++++++++++++++++++++++++++--------------
>  1 file changed, 32 insertions(+), 14 deletions(-)
> 
> diff --git a/src/nodeinfo.c b/src/nodeinfo.c
> index 52f5594..5aa0607 100644
> --- a/src/nodeinfo.c
> +++ b/src/nodeinfo.c
> @@ -441,6 +441,8 @@ virNodeParseNode(const char *sysfs_prefix,
>      }
>  
>      present_cpumap = nodeGetPresentCPUBitmap(sysfs_prefix);
> +    if (!present_cpumap)
> +        goto cleanup;
>  
>      /* enumerate sockets in the node */
>      CPU_ZERO(&sock_map);
> @@ -448,7 +450,7 @@ virNodeParseNode(const char *sysfs_prefix,
>          if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
>              continue;
>  
> -        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
> +        if (!virBitmapIsBitSet(present_cpumap, cpu))
>              continue;
>  
>          if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
> @@ -484,7 +486,7 @@ virNodeParseNode(const char *sysfs_prefix,
>          if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
>              continue;
>  
> -        if (present_cpumap && !(virBitmapIsBitSet(present_cpumap, cpu)))
> +        if (!virBitmapIsBitSet(present_cpumap, cpu))
>              continue;
>  
>          if ((online = virNodeGetCpuValue(node, cpu, "online", 1)) < 0)
> @@ -1278,27 +1280,43 @@ nodeGetCPUCount(const char *sysfs_prefix 
> ATTRIBUTE_UNUSED)
>  }
>  
>  virBitmapPtr
> -nodeGetPresentCPUBitmap(const char *sysfs_prefix)
> +nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
>  {
> -    int max_present;
>  #ifdef __linux__
> +    virBitmapPtr present_cpus = NULL;
>      char *present_path = NULL;
> -    virBitmapPtr bitmap = NULL;
> -#endif
> +    int npresent_cpus;
> +    int cpu;
>  
> -    if ((max_present = nodeGetCPUCount(sysfs_prefix)) < 0)
> -        return NULL;
> +    if ((npresent_cpus = nodeGetCPUCount(sysfs_prefix)) < 0)
> +        goto cleanup;
>  
> -#ifdef __linux__
>      if (!(present_path = linuxGetCPUPresentPath(sysfs_prefix)))
> -        return NULL;
> -    if (virFileExists(present_path))
> -        bitmap = linuxParseCPUmap(max_present, present_path);
> +        goto cleanup;
> +
> +    /* If the cpu/present file is available, parse it and exit */
> +    if (virFileExists(present_path)) {
> +        present_cpus = linuxParseCPUmap(npresent_cpus, present_path);
> +        goto cleanup;
> +    }
> +
> +    /* If the file is not available, we can assume that the kernel is
> +     * too old to support non-consecutive CPU ids and just mark all
> +     * possible CPUs as present */
> +    if (!(present_cpus = virBitmapNew(npresent_cpus)))
> +        goto cleanup;
> +
> +    for (cpu = 0; cpu < npresent_cpus; cpu++)
> +        if (virBitmapSetBit(present_cpus, cpu) < 0)

virBitmapSetAll();

> +            goto cleanup;
> +
> + cleanup:
>      VIR_FREE(present_path);
> -    return bitmap;
> +
> +    return present_cpus;
>  #endif
>      virReportError(VIR_ERR_NO_SUPPORT, "%s",
> -                   _("non-continuous host cpu numbers not implemented on 
> this platform"));
> +                   _("node present CPU map not implemented on this 
> platform"));
>      return NULL;
>  }

ACK with changing to virBitmapSetAll. It makes nodeGetPresentCPUBitmap a
little less horrible than it used to be.

Peter

Attachment: signature.asc
Description: Digital signature

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

Reply via email to