mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
nodeinfo: port nodecpumap to RHEL5
Prior to this patch, 'virsh nodecpumap' on older kernels reported: error: Unable to get cpu map error: out of memory * src/nodeinfo.c (linuxParseCPUmax): Don't overwrite error. (nodeGetCPUBitmap): Provide backup implementation.
This commit is contained in:
parent
47976b484c
commit
9504ae5b67
@ -792,10 +792,8 @@ linuxParseCPUmax(const char *path)
|
|||||||
char *tmp;
|
char *tmp;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0) {
|
if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
tmp = str;
|
tmp = str;
|
||||||
do {
|
do {
|
||||||
@ -1024,15 +1022,30 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
|
|||||||
virBitmapPtr cpumap;
|
virBitmapPtr cpumap;
|
||||||
int present;
|
int present;
|
||||||
|
|
||||||
present = linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
|
present = nodeGetCPUCount();
|
||||||
/* XXX should we also work on older kernels, like RHEL5, that lack
|
|
||||||
* cpu/present and cpu/online files? Those kernels also lack cpu
|
|
||||||
* hotplugging, so it would be a matter of finding the largest
|
|
||||||
* cpu/cpuNN directory, and creating a map that size with all bits
|
|
||||||
* set. */
|
|
||||||
if (present < 0)
|
if (present < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/online")) {
|
||||||
cpumap = linuxParseCPUmap(present, SYSFS_SYSTEM_PATH "/cpu/online");
|
cpumap = linuxParseCPUmap(present, SYSFS_SYSTEM_PATH "/cpu/online");
|
||||||
|
} else {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
cpumap = virBitmapNew(present);
|
||||||
|
if (!cpumap) {
|
||||||
|
virReportOOMError();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
for (i = 0; i < present; i++) {
|
||||||
|
int online = virNodeGetCpuValue(SYSFS_SYSTEM_PATH, i, "online", 1);
|
||||||
|
if (online < 0) {
|
||||||
|
virBitmapFree(cpumap);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (online)
|
||||||
|
ignore_value(virBitmapSetBit(cpumap, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (max_id && cpumap)
|
if (max_id && cpumap)
|
||||||
*max_id = present;
|
*max_id = present;
|
||||||
return cpumap;
|
return cpumap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user