From 6074f8316c88468a714518d15fa7d9ae2f78cd49 Mon Sep 17 00:00:00 2001 From: Kothapally Madhu Pavan Date: Tue, 26 May 2015 12:40:34 -0400 Subject: [PATCH] virsh: Fix to list online cpus using virsh capabilities 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 | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 22df95cf20..29f1aa7315 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1641,26 +1641,36 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED) virCapsHostNUMACellCPUPtr cpus; int ncpus; int s, c, t; - int id; + int id, cid; + int onlinecpus ATTRIBUTE_UNUSED; if (nodeGetInfo(&nodeinfo) < 0) return -1; ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo); + onlinecpus = nodeinfo.cpus; if (VIR_ALLOC_N(cpus, ncpus) < 0) return -1; - id = 0; + id = cid = 0; for (s = 0; s < nodeinfo.sockets; s++) { for (c = 0; c < nodeinfo.cores; c++) { for (t = 0; t < nodeinfo.threads; t++) { - cpus[id].id = id; - cpus[id].socket_id = s; - cpus[id].core_id = c; - if (!(cpus[id].siblings = virBitmapNew(ncpus))) - goto error; - ignore_value(virBitmapSetBit(cpus[id].siblings, id)); +#ifdef __linux__ + if (virNodeGetCpuValue(SYSFS_CPU_PATH, id, "online", 1)) { +#endif + 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++; +#ifdef __linux__ + } +#endif + id++; } } @@ -1668,7 +1678,11 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED) if (virCapabilitiesAddHostNUMACell(caps, 0, nodeinfo.memory, +#ifdef __linux__ + onlinecpus, cpus, +#else ncpus, cpus, +#endif 0, NULL, 0, NULL) < 0) goto error; -- GitLab