nodeinfo: Increase the num of CPU thread siblings to a larger value

Current libvirt can only handle up to 1023 bytes when it
reads Linux sysfs topology/thread_siblings. This isn't enough for
Linux distributions that support a large value. This patch fixes
the problem by using VIR_ALLOC()/VIR_FREE(), instead of using a
fixed-size (1024) local char array. In the meanwhile
SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX is increased to 8192 which
should be large enough for a foreseeable future.

Signed-off-by: Wei Huang <wei@redhat.com>
(cherry picked from commit c13de016916c826ad4d35157ee6a52baee87ac22)
This commit is contained in:
Wei Huang 2015-03-26 00:48:13 -04:00 committed by Cole Robinson
parent 0b635e15c8
commit cb4fd344b4

View File

@ -287,7 +287,7 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
# define PROCSTAT_PATH "/proc/stat" # define PROCSTAT_PATH "/proc/stat"
# define MEMINFO_PATH "/proc/meminfo" # define MEMINFO_PATH "/proc/meminfo"
# define SYSFS_MEMORY_SHARED_PATH "/sys/kernel/mm/ksm" # define SYSFS_MEMORY_SHARED_PATH "/sys/kernel/mm/ksm"
# define SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX 1024 # define SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX 8192
# define LINUX_NB_CPU_STATS 4 # define LINUX_NB_CPU_STATS 4
# define LINUX_NB_MEMORY_STATS_ALL 4 # define LINUX_NB_MEMORY_STATS_ALL 4
@ -345,7 +345,7 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
unsigned long ret = 0; unsigned long ret = 0;
char *path; char *path;
FILE *pathfp; FILE *pathfp;
char str[1024]; char *str = NULL;
size_t i; size_t i;
if (virAsprintf(&path, "%s/cpu%u/topology/thread_siblings", if (virAsprintf(&path, "%s/cpu%u/topology/thread_siblings",
@ -365,7 +365,10 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
return 0; return 0;
} }
if (fgets(str, sizeof(str), pathfp) == NULL) { if (VIR_ALLOC_N(str, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX) < 0)
goto cleanup;
if (fgets(str, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, pathfp) == NULL) {
virReportSystemError(errno, _("cannot read from %s"), path); virReportSystemError(errno, _("cannot read from %s"), path);
goto cleanup; goto cleanup;
} }
@ -382,6 +385,7 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
} }
cleanup: cleanup:
VIR_FREE(str);
VIR_FORCE_FCLOSE(pathfp); VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path); VIR_FREE(path);