[libvirt] [PATCH 1/3 V7] add nodeGetCPUmap() for getting available CPU IDs in a cpumap.

Richard W.M. Jones rjones at redhat.com
Tue Mar 6 10:53:02 UTC 2012


On Fri, Mar 02, 2012 at 10:54:22AM +0800, Lai Jiangshan wrote:
> +/*
> + * Linux maintains cpu bit map. For example, if cpuid=5's flag is not set
> + * and max cpu is 7. The map file shows 0-4,6-7. This function parses
> + * it and returns cpumap.
> + */
> +static const char *
> +linuxParseCPUmap(int *max_cpuid, const char *path)
> +{
> +    char *map = NULL;
> +    char *str = NULL;
> +    int max_id, i;
> +
> +    if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0) {
> +        virReportOOMError();
> +        goto error;
> +    }
> +
> +    if (VIR_ALLOC_N(map, VIR_DOMAIN_CPUMASK_LEN) < 0) {
> +        virReportOOMError();
> +        goto error;
> +    }
> +    if (virDomainCpuSetParse(str, 0, map,
> +                             VIR_DOMAIN_CPUMASK_LEN) < 0) {
> +        goto error;
> +    }
> +
> +    for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
> +        if (map[i]) {
> +            max_id = i;
> +        }
> +    }
> +    *max_cpuid = max_id;

Please compile with './configure --enable-compile-warnings=error'.
The compiler spots that max_id could be used uninitialized here.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top




More information about the libvir-list mailing list