mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-23 06:23:10 +00:00
nodeinfo: enable nodeGetCPUCount for older kernels
Since /sys/devices/system/cpu/present is not available on older kernels like on RHEL 5.x nodeGetCPUCount will fail there. The fallback implemented is to scan for /sys/devices/system/cpu/cpuNN entries. Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
This commit is contained in:
parent
39c814ff46
commit
0c996c10e4
@ -978,11 +978,35 @@ int
|
|||||||
nodeGetCPUCount(void)
|
nodeGetCPUCount(void)
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
/* XXX should we also work on older kernels, like RHEL5, that lack
|
/* To support older kernels that lack cpu/present, such as 2.6.18
|
||||||
* cpu/present and cpu/online files? Those kernels also lack cpu
|
* in RHEL5, we fall back to count cpu/cpuNN entries; this assumes
|
||||||
* hotplugging, so it would be a matter of finding the largest
|
* that such kernels also lack hotplug, and therefore cpu/cpuNN
|
||||||
* cpu/cpuNN directory, and returning NN + 1 */
|
* will be consecutive.
|
||||||
return linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
|
*/
|
||||||
|
char *cpupath = NULL;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/present")) {
|
||||||
|
i = linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
|
||||||
|
} else if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/cpu0")) {
|
||||||
|
do {
|
||||||
|
i++;
|
||||||
|
VIR_FREE(cpupath);
|
||||||
|
if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
|
||||||
|
SYSFS_SYSTEM_PATH, i) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} while (virFileExists(cpupath));
|
||||||
|
} else {
|
||||||
|
/* no cpu/cpu0: we give up */
|
||||||
|
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
||||||
|
_("host cpu counting not supported on this node"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIR_FREE(cpupath);
|
||||||
|
return i;
|
||||||
#else
|
#else
|
||||||
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
||||||
_("host cpu counting not implemented on this platform"));
|
_("host cpu counting not implemented on this platform"));
|
||||||
|
Loading…
Reference in New Issue
Block a user