On 11/13/2012 05:54 AM, Viktor Mihajlovski wrote:
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(a)linux.vnet.ibm.com>
---
src/nodeinfo.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
#ifdef __linux__
- /* 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 returning NN + 1 */
- return linuxParseCPUmax(SYSFS_SYSTEM_PATH "/cpu/present");
+ /* to support older kernels, like RHEL5, that lack
+ * cpu/present we fall back to count cpu/cpuNN
+ * entries.
+ */
+ 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));
The assumption here is that any kernel lacking cpu/present also lacks
hotplug, and therefore the cpuNN will be consecutive and we aren't going
to miss anything. You removed that assumption from the comment, but I
think it is important to leave in.
ACK. I'm firing up my RHEL 5 VM to test this before I push with this
comment change, but it looks sane.
diff --git i/src/nodeinfo.c w/src/nodeinfo.c
index cea3775..4589b77 100644
--- i/src/nodeinfo.c
+++ w/src/nodeinfo.c
@@ -978,9 +978,10 @@ int
nodeGetCPUCount(void)
{
#ifdef __linux__
- /* to support older kernels, like RHEL5, that lack
- * cpu/present we fall back to count cpu/cpuNN
- * entries.
+ /* To support older kernels that lack cpu/present, such as 2.6.18
+ * in RHEL5, we fall back to count cpu/cpuNN entries; this assumes
+ * that such kernels also lack hotplug, and therefore cpu/cpuNN
+ * will be consecutive.
*/
char *cpupath = NULL;
int i = 0;
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org