Re: [PATCH v2] virsh: Fix to list online cpus using virsh capabilities

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

 



On 26.05.2015 18:40, Kothapally Madhu Pavan wrote:
> Virsh capabilities will list offline cpus as online when
> libvirt is compiled with numactl option disabled. This
> fix will list correct set of online cpus.
> ---
>  src/nodeinfo.c |   43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/src/nodeinfo.c b/src/nodeinfo.c
> index 22df95c..410c9de 100644
> --- a/src/nodeinfo.c
> +++ b/src/nodeinfo.c
> @@ -1651,6 +1651,47 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
>      if (VIR_ALLOC_N(cpus, ncpus) < 0)
>          return -1;
>  
> +#ifdef __linux__

The following code it's 99% similar to the one just below it. This can
be written much shorter, much cleaner.

> +    {
> +    int cid = 0;
> +    int onlinecpus = nodeinfo.cpus;
> +
> +    id = 0;
> +    for (s = 0; s < nodeinfo.sockets; s++) {
> +        for (c = 0; c < nodeinfo.cores; c++) {
> +            for (t = 0; t < nodeinfo.threads; t++) {
> +                if (virNodeGetCpuValue(SYSFS_CPU_PATH, id, "online", 1)) {
> +                    cpus[cid].id = id;
> +                    cpus[cid].socket_id = s;
> +                    cpus[cid].core_id = c;
> +                    if (!(cpus[cid].siblings = virBitmapNew(ncpus)))
> +                        goto error;
> +                    ignore_value(virBitmapSetBit(cpus[cid].siblings, id));
> +                    cid++;
> +                }
> +
> +                id++;
> +            }
> +        }
> +    }
> +
> +    if (virCapabilitiesAddHostNUMACell(caps, 0,
> +                                       nodeinfo.memory,
> +                                       onlinecpus, cpus,
> +                                       0, NULL,
> +                                       0, NULL) < 0)
> +        goto error;
> +
> +    return 0;
> +
> + error:
> +    for (; cid >= 0; cid--)
> +        virBitmapFree(cpus[cid].siblings);
> +    VIR_FREE(cpus);
> +    return -1;
> +    }
> +#else
> +    {
>      id = 0;
>      for (s = 0; s < nodeinfo.sockets; s++) {
>          for (c = 0; c < nodeinfo.cores; c++) {
> @@ -1680,6 +1721,8 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
>          virBitmapFree(cpus[id].siblings);
>      VIR_FREE(cpus);
>      return -1;
> +    }
> +#endif
>  }
>  

I'm fixing the patch, ACKing and pushing.
Congratulations on your first libvirt contribution!

Michal

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