nodeinfo: remove sysfs_prefix from all methods

Nearly all the methods in the nodeinfo file are given a
'const char *sysfs_prefix' parameter to override the
default sysfs path (/sys/devices/system). Every single
caller passes in NULL for this, except one use in the
unit tests. Furthermore this parameter is totally
Linux-specific, when the APIs are intended to be cross
platform portable.

This removes the sysfs_prefix parameter and instead gives
a new method linuxNodeInfoSetSysFSSystemPath for use by
the test suite.

For two of the methods this hardcodes use of the constant
SYSFS_SYSTEM_PATH, since the test suite does not need to
override the path for thos methods.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2016-04-13 15:28:55 +01:00
parent 5f4c50d528
commit 08ea852c25
24 changed files with 108 additions and 115 deletions

View File

@ -51,7 +51,7 @@ virBhyveCapsInitCPU(virCapsPtr caps,
cpu->arch = arch; cpu->arch = arch;
if (nodeGetInfo(NULL, &nodeinfo)) if (nodeGetInfo(&nodeinfo))
goto error; goto error;
cpu->type = VIR_CPU_TYPE_HOST; cpu->type = VIR_CPU_TYPE_HOST;

View File

@ -1175,7 +1175,7 @@ bhyveNodeGetMemoryStats(virConnectPtr conn,
if (virNodeGetMemoryStatsEnsureACL(conn) < 0) if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); return nodeGetMemoryStats(cellNum, params, nparams, flags);
} }
static int static int
@ -1185,7 +1185,7 @@ bhyveNodeGetInfo(virConnectPtr conn,
if (virNodeGetInfoEnsureACL(conn) < 0) if (virNodeGetInfoEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetInfo(NULL, nodeinfo); return nodeGetInfo(nodeinfo);
} }
static int static int
@ -1361,7 +1361,7 @@ bhyveNodeGetCPUMap(virConnectPtr conn,
if (virNodeGetCPUMapEnsureACL(conn) < 0) if (virNodeGetCPUMapEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetCPUMap(NULL, cpumap, online, flags); return nodeGetCPUMap(cpumap, online, flags);
} }
static int static int

View File

@ -5,6 +5,7 @@
# nodeinfo.h # nodeinfo.h
linuxNodeGetCPUStats; linuxNodeGetCPUStats;
linuxNodeInfoCPUPopulate; linuxNodeInfoCPUPopulate;
linuxNodeInfoSetSysFSSystemPath;
# Let emacs know we want case-insensitive sorting # Let emacs know we want case-insensitive sorting
# Local Variables: # Local Variables:

View File

@ -77,7 +77,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
* unexpected failures. We don't want to break the lxc * unexpected failures. We don't want to break the lxc
* driver in this scenario, so log errors & carry on * driver in this scenario, so log errors & carry on
*/ */
if (nodeCapsInitNUMA(NULL, caps) < 0) { if (nodeCapsInitNUMA(caps) < 0) {
virCapabilitiesFreeNUMAInfo(caps); virCapabilitiesFreeNUMAInfo(caps);
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities"); VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
} }

View File

@ -730,7 +730,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
/* setaffinity fails if you set bits for CPUs which /* setaffinity fails if you set bits for CPUs which
* aren't present, so we have to limit ourselves */ * aren't present, so we have to limit ourselves */
if ((hostcpus = nodeGetCPUCount(NULL)) < 0) if ((hostcpus = nodeGetCPUCount()) < 0)
return -1; return -1;
if (maxcpu > hostcpus) if (maxcpu > hostcpus)

View File

@ -5154,7 +5154,7 @@ lxcNodeGetInfo(virConnectPtr conn,
if (virNodeGetInfoEnsureACL(conn) < 0) if (virNodeGetInfoEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetInfo(NULL, nodeinfo); return nodeGetInfo(nodeinfo);
} }
@ -5246,7 +5246,7 @@ lxcNodeGetMemoryStats(virConnectPtr conn,
if (virNodeGetMemoryStatsEnsureACL(conn) < 0) if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); return nodeGetMemoryStats(cellNum, params, nparams, flags);
} }
@ -5313,7 +5313,7 @@ lxcNodeGetCPUMap(virConnectPtr conn,
if (virNodeGetCPUMapEnsureACL(conn) < 0) if (virNodeGetCPUMapEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetCPUMap(NULL, cpumap, online, flags); return nodeGetCPUMap(cpumap, online, flags);
} }

View File

@ -65,7 +65,6 @@
VIR_LOG_INIT("nodeinfo"); VIR_LOG_INIT("nodeinfo");
#define SYSFS_SYSTEM_PATH "/sys/devices/system"
#if defined(__FreeBSD__) || defined(__APPLE__) #if defined(__FreeBSD__) || defined(__APPLE__)
static int static int
@ -290,6 +289,7 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
#endif /* __FreeBSD__ */ #endif /* __FreeBSD__ */
#ifdef __linux__ #ifdef __linux__
# define SYSFS_SYSTEM_PATH "/sys/devices/system"
# define CPUINFO_PATH "/proc/cpuinfo" # define CPUINFO_PATH "/proc/cpuinfo"
# define PROCSTAT_PATH "/proc/stat" # define PROCSTAT_PATH "/proc/stat"
# define MEMINFO_PATH "/proc/meminfo" # define MEMINFO_PATH "/proc/meminfo"
@ -300,6 +300,16 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
# define LINUX_NB_MEMORY_STATS_ALL 4 # define LINUX_NB_MEMORY_STATS_ALL 4
# define LINUX_NB_MEMORY_STATS_CELL 2 # define LINUX_NB_MEMORY_STATS_CELL 2
static const char *sysfs_system_path = SYSFS_SYSTEM_PATH;
void linuxNodeInfoSetSysFSSystemPath(const char *path)
{
if (path)
sysfs_system_path = path;
else
sysfs_system_path = SYSFS_SYSTEM_PATH;
}
/* Return the positive decimal contents of the given /* Return the positive decimal contents of the given
* DIR/cpu%u/FILE, or -1 on error. If DEFAULT_VALUE is non-negative * DIR/cpu%u/FILE, or -1 on error. If DEFAULT_VALUE is non-negative
* and the file could not be found, return that instead of an error; * and the file could not be found, return that instead of an error;
@ -593,8 +603,7 @@ virNodeParseNode(const char *node,
* A valid configuration is one where no secondary thread is online; * A valid configuration is one where no secondary thread is online;
* the primary thread in a subcore is always the first one */ * the primary thread in a subcore is always the first one */
static bool static bool
nodeHasValidSubcoreConfiguration(const char *sysfs_prefix, nodeHasValidSubcoreConfiguration(int threads_per_subcore)
int threads_per_subcore)
{ {
virBitmapPtr online_cpus = NULL; virBitmapPtr online_cpus = NULL;
int cpu = -1; int cpu = -1;
@ -604,7 +613,7 @@ nodeHasValidSubcoreConfiguration(const char *sysfs_prefix,
if (threads_per_subcore <= 0) if (threads_per_subcore <= 0)
goto cleanup; goto cleanup;
if (!(online_cpus = nodeGetOnlineCPUBitmap(sysfs_prefix))) if (!(online_cpus = nodeGetOnlineCPUBitmap()))
goto cleanup; goto cleanup;
while ((cpu = virBitmapNextSetBit(online_cpus, cpu)) >= 0) { while ((cpu = virBitmapNextSetBit(online_cpus, cpu)) >= 0) {
@ -624,12 +633,10 @@ nodeHasValidSubcoreConfiguration(const char *sysfs_prefix,
} }
int int
linuxNodeInfoCPUPopulate(const char *sysfs_prefix, linuxNodeInfoCPUPopulate(FILE *cpuinfo,
FILE *cpuinfo,
virArch arch, virArch arch,
virNodeInfoPtr nodeinfo) virNodeInfoPtr nodeinfo)
{ {
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
virBitmapPtr present_cpus_map = NULL; virBitmapPtr present_cpus_map = NULL;
virBitmapPtr online_cpus_map = NULL; virBitmapPtr online_cpus_map = NULL;
char line[1024]; char line[1024];
@ -726,17 +733,17 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
/* Get information about what CPUs are present in the host and what /* Get information about what CPUs are present in the host and what
* CPUs are online, so that we don't have to so for each node */ * CPUs are online, so that we don't have to so for each node */
present_cpus_map = nodeGetPresentCPUBitmap(sysfs_prefix); present_cpus_map = nodeGetPresentCPUBitmap();
if (!present_cpus_map) if (!present_cpus_map)
goto cleanup; goto cleanup;
online_cpus_map = nodeGetOnlineCPUBitmap(sysfs_prefix); online_cpus_map = nodeGetOnlineCPUBitmap();
if (!online_cpus_map) if (!online_cpus_map)
goto cleanup; goto cleanup;
/* OK, we've parsed clock speed out of /proc/cpuinfo. Get the /* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
* core, node, socket, thread and topology information from /sys * core, node, socket, thread and topology information from /sys
*/ */
if (virAsprintf(&sysfs_nodedir, "%s/node", prefix) < 0) if (virAsprintf(&sysfs_nodedir, "%s/node", sysfs_system_path) < 0)
goto cleanup; goto cleanup;
if (!(nodedir = opendir(sysfs_nodedir))) { if (!(nodedir = opendir(sysfs_nodedir))) {
@ -771,7 +778,7 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
/* If the subcore configuration is not valid, just pretend subcores /* If the subcore configuration is not valid, just pretend subcores
* are not in use and count threads one by one */ * are not in use and count threads one by one */
if (!nodeHasValidSubcoreConfiguration(sysfs_prefix, threads_per_subcore)) if (!nodeHasValidSubcoreConfiguration(threads_per_subcore))
threads_per_subcore = 0; threads_per_subcore = 0;
while ((direrr = virDirRead(nodedir, &nodedirent, sysfs_nodedir)) > 0) { while ((direrr = virDirRead(nodedir, &nodedirent, sysfs_nodedir)) > 0) {
@ -781,7 +788,7 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
nodeinfo->nodes++; nodeinfo->nodes++;
if (virAsprintf(&sysfs_cpudir, "%s/node/%s", if (virAsprintf(&sysfs_cpudir, "%s/node/%s",
prefix, nodedirent->d_name) < 0) sysfs_system_path, nodedirent->d_name) < 0)
goto cleanup; goto cleanup;
if ((cpus = virNodeParseNode(sysfs_cpudir, arch, if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
@ -815,7 +822,7 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
fallback: fallback:
VIR_FREE(sysfs_cpudir); VIR_FREE(sysfs_cpudir);
if (virAsprintf(&sysfs_cpudir, "%s/cpu", prefix) < 0) if (virAsprintf(&sysfs_cpudir, "%s/cpu", sysfs_system_path) < 0)
goto cleanup; goto cleanup;
if ((cpus = virNodeParseNode(sysfs_cpudir, arch, if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
@ -1079,28 +1086,26 @@ linuxNodeGetMemoryStats(FILE *meminfo,
} }
static char * static char *
linuxGetCPUGlobalPath(const char *sysfs_prefix, linuxGetCPUGlobalPath(const char *file)
const char *file)
{ {
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
char *path = NULL; char *path = NULL;
if (virAsprintf(&path, "%s/cpu/%s", prefix, file) < 0) if (virAsprintf(&path, "%s/cpu/%s", sysfs_system_path, file) < 0)
return NULL; return NULL;
return path; return path;
} }
static char * static char *
linuxGetCPUPresentPath(const char *sysfs_prefix) linuxGetCPUPresentPath(void)
{ {
return linuxGetCPUGlobalPath(sysfs_prefix, "present"); return linuxGetCPUGlobalPath("present");
} }
static char * static char *
linuxGetCPUOnlinePath(const char *sysfs_prefix) linuxGetCPUOnlinePath(void)
{ {
return linuxGetCPUGlobalPath(sysfs_prefix, "online"); return linuxGetCPUGlobalPath("online");
} }
/* Determine the number of CPUs (maximum CPU id + 1) from a file containing /* Determine the number of CPUs (maximum CPU id + 1) from a file containing
@ -1184,8 +1189,7 @@ virNodeGetSiblingsList(const char *dir, int cpu_id)
#endif #endif
int int
nodeGetInfo(const char *sysfs_prefix ATTRIBUTE_UNUSED, nodeGetInfo(virNodeInfoPtr nodeinfo)
virNodeInfoPtr nodeinfo)
{ {
virArch hostarch = virArchFromHost(); virArch hostarch = virArchFromHost();
@ -1205,8 +1209,7 @@ nodeGetInfo(const char *sysfs_prefix ATTRIBUTE_UNUSED,
return -1; return -1;
} }
ret = linuxNodeInfoCPUPopulate(sysfs_prefix, cpuinfo, ret = linuxNodeInfoCPUPopulate(cpuinfo, hostarch, nodeinfo);
hostarch, nodeinfo);
if (ret < 0) if (ret < 0)
goto cleanup; goto cleanup;
@ -1293,8 +1296,7 @@ nodeGetCPUStats(int cpuNum ATTRIBUTE_UNUSED,
} }
int int
nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED, nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED,
int cellNum ATTRIBUTE_UNUSED,
virNodeMemoryStatsPtr params ATTRIBUTE_UNUSED, virNodeMemoryStatsPtr params ATTRIBUTE_UNUSED,
int *nparams ATTRIBUTE_UNUSED, int *nparams ATTRIBUTE_UNUSED,
unsigned int flags) unsigned int flags)
@ -1304,7 +1306,6 @@ nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED,
#ifdef __linux__ #ifdef __linux__
{ {
int ret; int ret;
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
char *meminfo_path = NULL; char *meminfo_path = NULL;
FILE *meminfo; FILE *meminfo;
int max_node; int max_node;
@ -1323,8 +1324,9 @@ nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED,
return -1; return -1;
} }
if (virAsprintf(&meminfo_path, "%s/node/node%d/meminfo", if (virAsprintf(&meminfo_path,
prefix, cellNum) < 0) SYSFS_SYSTEM_PATH "/node/node%d/meminfo",
cellNum) < 0)
return -1; return -1;
} }
meminfo = fopen(meminfo_path, "r"); meminfo = fopen(meminfo_path, "r");
@ -1351,7 +1353,7 @@ nodeGetMemoryStats(const char *sysfs_prefix ATTRIBUTE_UNUSED,
} }
int int
nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED) nodeGetCPUCount(void)
{ {
#if defined(__linux__) #if defined(__linux__)
/* To support older kernels that lack cpu/present, such as 2.6.18 /* To support older kernels that lack cpu/present, such as 2.6.18
@ -1360,11 +1362,10 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
* will be consecutive. * will be consecutive.
*/ */
char *present_path = NULL; char *present_path = NULL;
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
char *cpupath = NULL; char *cpupath = NULL;
int ncpu = -1; int ncpu = -1;
if (!(present_path = linuxGetCPUPresentPath(sysfs_prefix))) if (!(present_path = linuxGetCPUPresentPath()))
return -1; return -1;
if (virFileExists(present_path)) { if (virFileExists(present_path)) {
@ -1372,7 +1373,7 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
goto cleanup; goto cleanup;
} }
if (virAsprintf(&cpupath, "%s/cpu/cpu0", prefix) < 0) if (virAsprintf(&cpupath, "%s/cpu/cpu0", sysfs_system_path) < 0)
goto cleanup; goto cleanup;
if (virFileExists(cpupath)) { if (virFileExists(cpupath)) {
ncpu = 0; ncpu = 0;
@ -1380,7 +1381,7 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
ncpu++; ncpu++;
VIR_FREE(cpupath); VIR_FREE(cpupath);
if (virAsprintf(&cpupath, "%s/cpu/cpu%d", if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
prefix, ncpu) < 0) { sysfs_system_path, ncpu) < 0) {
ncpu = -1; ncpu = -1;
goto cleanup; goto cleanup;
} }
@ -1405,17 +1406,17 @@ nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
} }
virBitmapPtr virBitmapPtr
nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED) nodeGetPresentCPUBitmap(void)
{ {
#ifdef __linux__ #ifdef __linux__
virBitmapPtr present_cpus = NULL; virBitmapPtr present_cpus = NULL;
char *present_path = NULL; char *present_path = NULL;
int npresent_cpus; int npresent_cpus;
if ((npresent_cpus = nodeGetCPUCount(sysfs_prefix)) < 0) if ((npresent_cpus = nodeGetCPUCount()) < 0)
goto cleanup; goto cleanup;
if (!(present_path = linuxGetCPUPresentPath(sysfs_prefix))) if (!(present_path = linuxGetCPUPresentPath()))
goto cleanup; goto cleanup;
/* If the cpu/present file is available, parse it and exit */ /* If the cpu/present file is available, parse it and exit */
@ -1443,20 +1444,19 @@ nodeGetPresentCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
} }
virBitmapPtr virBitmapPtr
nodeGetOnlineCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED) nodeGetOnlineCPUBitmap(void)
{ {
#ifdef __linux__ #ifdef __linux__
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
char *online_path = NULL; char *online_path = NULL;
char *cpudir = NULL; char *cpudir = NULL;
virBitmapPtr cpumap; virBitmapPtr cpumap;
int present; int present;
present = nodeGetCPUCount(sysfs_prefix); present = nodeGetCPUCount();
if (present < 0) if (present < 0)
return NULL; return NULL;
if (!(online_path = linuxGetCPUOnlinePath(sysfs_prefix))) if (!(online_path = linuxGetCPUOnlinePath()))
return NULL; return NULL;
if (virFileExists(online_path)) { if (virFileExists(online_path)) {
cpumap = linuxParseCPUmap(present, online_path); cpumap = linuxParseCPUmap(present, online_path);
@ -1467,7 +1467,7 @@ nodeGetOnlineCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED)
if (!cpumap) if (!cpumap)
goto cleanup; goto cleanup;
if (virAsprintf(&cpudir, "%s/cpu", prefix) < 0) if (virAsprintf(&cpudir, "%s/cpu", sysfs_system_path) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < present; i++) { for (i = 0; i < present; i++) {
@ -1796,8 +1796,7 @@ nodeGetMemoryParameters(virTypedParameterPtr params ATTRIBUTE_UNUSED,
} }
int int
nodeGetCPUMap(const char *sysfs_prefix, nodeGetCPUMap(unsigned char **cpumap,
unsigned char **cpumap,
unsigned int *online, unsigned int *online,
unsigned int flags) unsigned int flags)
{ {
@ -1808,9 +1807,9 @@ nodeGetCPUMap(const char *sysfs_prefix,
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (!cpumap && !online) if (!cpumap && !online)
return nodeGetCPUCount(sysfs_prefix); return nodeGetCPUCount();
if (!(cpus = nodeGetOnlineCPUBitmap(sysfs_prefix))) if (!(cpus = nodeGetOnlineCPUBitmap()))
goto cleanup; goto cleanup;
if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0) if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0)
@ -1828,8 +1827,7 @@ nodeGetCPUMap(const char *sysfs_prefix,
} }
static int static int
nodeCapsInitNUMAFake(const char *sysfs_prefix, nodeCapsInitNUMAFake(const char *cpupath ATTRIBUTE_UNUSED,
const char *cpupath ATTRIBUTE_UNUSED,
virCapsPtr caps ATTRIBUTE_UNUSED) virCapsPtr caps ATTRIBUTE_UNUSED)
{ {
virNodeInfo nodeinfo; virNodeInfo nodeinfo;
@ -1839,7 +1837,7 @@ nodeCapsInitNUMAFake(const char *sysfs_prefix,
int id, cid; int id, cid;
int onlinecpus ATTRIBUTE_UNUSED; int onlinecpus ATTRIBUTE_UNUSED;
if (nodeGetInfo(sysfs_prefix, &nodeinfo) < 0) if (nodeGetInfo(&nodeinfo) < 0)
return -1; return -1;
ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo); ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
@ -2088,11 +2086,8 @@ virNodeCapsGetPagesInfo(int node,
} }
int int
nodeCapsInitNUMA(const char *sysfs_prefix, nodeCapsInitNUMA(virCapsPtr caps)
virCapsPtr caps)
{ {
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
char *cpupath;
int n; int n;
unsigned long long memory; unsigned long long memory;
virCapsHostNUMACellCPUPtr cpus = NULL; virCapsHostNUMACellCPUPtr cpus = NULL;
@ -2107,11 +2102,8 @@ nodeCapsInitNUMA(const char *sysfs_prefix,
bool topology_failed = false; bool topology_failed = false;
int max_node; int max_node;
if (virAsprintf(&cpupath, "%s/cpu", prefix) < 0)
return -1;
if (!virNumaIsAvailable()) { if (!virNumaIsAvailable()) {
ret = nodeCapsInitNUMAFake(sysfs_prefix, cpupath, caps); ret = nodeCapsInitNUMAFake(SYSFS_SYSTEM_PATH "/cpu", caps);
goto cleanup; goto cleanup;
} }
@ -2134,7 +2126,8 @@ nodeCapsInitNUMA(const char *sysfs_prefix,
for (i = 0; i < virBitmapSize(cpumap); i++) { for (i = 0; i < virBitmapSize(cpumap); i++) {
if (virBitmapIsBitSet(cpumap, i)) { if (virBitmapIsBitSet(cpumap, i)) {
if (virNodeCapsFillCPUInfo(cpupath, i, cpus + cpu++) < 0) { if (virNodeCapsFillCPUInfo(SYSFS_SYSTEM_PATH "/cpu",
i, cpus + cpu++) < 0) {
topology_failed = true; topology_failed = true;
virResetLastError(); virResetLastError();
} }
@ -2174,7 +2167,6 @@ nodeCapsInitNUMA(const char *sysfs_prefix,
VIR_FREE(cpus); VIR_FREE(cpus);
VIR_FREE(siblings); VIR_FREE(siblings);
VIR_FREE(pageinfo); VIR_FREE(pageinfo);
VIR_FREE(cpupath);
return ret; return ret;
} }

View File

@ -26,15 +26,14 @@
# include "capabilities.h" # include "capabilities.h"
int nodeGetInfo(const char *sysfs_prefix, virNodeInfoPtr nodeinfo); int nodeGetInfo(virNodeInfoPtr nodeinfo);
int nodeCapsInitNUMA(const char *sysfs_prefix, virCapsPtr caps); int nodeCapsInitNUMA(virCapsPtr caps);
int nodeGetCPUStats(int cpuNum, int nodeGetCPUStats(int cpuNum,
virNodeCPUStatsPtr params, virNodeCPUStatsPtr params,
int *nparams, int *nparams,
unsigned int flags); unsigned int flags);
int nodeGetMemoryStats(const char *sysfs_prefix, int nodeGetMemoryStats(int cellNum,
int cellNum,
virNodeMemoryStatsPtr params, virNodeMemoryStatsPtr params,
int *nparams, int *nparams,
unsigned int flags); unsigned int flags);
@ -44,9 +43,9 @@ int nodeGetCellsFreeMemory(unsigned long long *freeMems,
int nodeGetMemory(unsigned long long *mem, int nodeGetMemory(unsigned long long *mem,
unsigned long long *freeMem); unsigned long long *freeMem);
virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix); virBitmapPtr nodeGetPresentCPUBitmap(void);
virBitmapPtr nodeGetOnlineCPUBitmap(const char *sysfs_prefix); virBitmapPtr nodeGetOnlineCPUBitmap(void);
int nodeGetCPUCount(const char *sysfs_prefix); int nodeGetCPUCount(void);
int nodeGetThreadsPerSubcore(virArch arch); int nodeGetThreadsPerSubcore(virArch arch);
int nodeGetMemoryParameters(virTypedParameterPtr params, int nodeGetMemoryParameters(virTypedParameterPtr params,
@ -57,8 +56,7 @@ int nodeSetMemoryParameters(virTypedParameterPtr params,
int nparams, int nparams,
unsigned int flags); unsigned int flags);
int nodeGetCPUMap(const char *sysfs_prefix, int nodeGetCPUMap(unsigned char **cpumap,
unsigned char **cpumap,
unsigned int *online, unsigned int *online,
unsigned int flags); unsigned int flags);

View File

@ -25,8 +25,9 @@
# include "nodeinfo.h" # include "nodeinfo.h"
# ifdef __linux__ # ifdef __linux__
int linuxNodeInfoCPUPopulate(const char *sysfs_prefix, void linuxNodeInfoSetSysFSSystemPath(const char *path);
FILE *cpuinfo,
int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
virArch arch, virArch arch,
virNodeInfoPtr nodeinfo); virNodeInfoPtr nodeinfo);

View File

@ -165,7 +165,7 @@ virCapsPtr openvzCapsInit(void)
false, false)) == NULL) false, false)) == NULL)
goto no_memory; goto no_memory;
if (nodeCapsInitNUMA(NULL, caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto no_memory; goto no_memory;
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
@ -633,7 +633,7 @@ openvzGetNodeCPUs(void)
{ {
virNodeInfo nodeinfo; virNodeInfo nodeinfo;
if (nodeGetInfo(NULL, &nodeinfo) < 0) if (nodeGetInfo(&nodeinfo) < 0)
return 0; return 0;
return nodeinfo.cpus; return nodeinfo.cpus;

View File

@ -2157,7 +2157,7 @@ static int
openvzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, openvzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
virNodeInfoPtr nodeinfo) virNodeInfoPtr nodeinfo)
{ {
return nodeGetInfo(NULL, nodeinfo); return nodeGetInfo(nodeinfo);
} }
@ -2179,7 +2179,7 @@ openvzNodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
int *nparams, int *nparams,
unsigned int flags) unsigned int flags)
{ {
return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); return nodeGetMemoryStats(cellNum, params, nparams, flags);
} }
@ -2209,7 +2209,7 @@ openvzNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
unsigned int *online, unsigned int *online,
unsigned int flags) unsigned int flags)
{ {
return nodeGetCPUMap(NULL, cpumap, online, flags); return nodeGetCPUMap(cpumap, online, flags);
} }

View File

@ -335,7 +335,7 @@ phypCapsInit(void)
* unexpected failures. We don't want to break the QEMU * unexpected failures. We don't want to break the QEMU
* driver in this scenario, so log errors & carry on * driver in this scenario, so log errors & carry on
*/ */
if (nodeCapsInitNUMA(NULL, caps) < 0) { if (nodeCapsInitNUMA(caps) < 0) {
virCapabilitiesFreeNUMAInfo(caps); virCapabilitiesFreeNUMAInfo(caps);
VIR_WARN VIR_WARN
("Failed to query host NUMA topology, disabling NUMA capabilities"); ("Failed to query host NUMA topology, disabling NUMA capabilities");

View File

@ -1013,7 +1013,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
cpu->arch = arch; cpu->arch = arch;
if (nodeGetInfo(NULL, &nodeinfo)) if (nodeGetInfo(&nodeinfo))
goto error; goto error;
cpu->type = VIR_CPU_TYPE_HOST; cpu->type = VIR_CPU_TYPE_HOST;
@ -1076,7 +1076,7 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
* unexpected failures. We don't want to break the QEMU * unexpected failures. We don't want to break the QEMU
* driver in this scenario, so log errors & carry on * driver in this scenario, so log errors & carry on
*/ */
if (nodeCapsInitNUMA(NULL, caps) < 0) { if (nodeCapsInitNUMA(caps) < 0) {
virCapabilitiesFreeNUMAInfo(caps); virCapabilitiesFreeNUMAInfo(caps);
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities"); VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
} }

View File

@ -5152,7 +5152,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
priv = vm->privateData; priv = vm->privateData;
ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps, ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
nodeGetCPUCount(NULL), nodeGetCPUCount(),
priv->autoCpuset); priv->autoCpuset);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
@ -5297,7 +5297,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
if (!(def = virDomainObjGetOneDef(vm, flags))) if (!(def = virDomainObjGetOneDef(vm, flags)))
goto cleanup; goto cleanup;
if ((hostcpus = nodeGetCPUCount(NULL)) < 0) if ((hostcpus = nodeGetCPUCount()) < 0)
goto cleanup; goto cleanup;
priv = vm->privateData; priv = vm->privateData;
@ -5545,7 +5545,7 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef,
if (targetDef->niothreadids == 0) if (targetDef->niothreadids == 0)
return 0; return 0;
if ((hostcpus = nodeGetCPUCount(NULL)) < 0) if ((hostcpus = nodeGetCPUCount()) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC_N(info_ret, targetDef->niothreadids) < 0) if (VIR_ALLOC_N(info_ret, targetDef->niothreadids) < 0)
@ -18081,7 +18081,7 @@ qemuNodeGetInfo(virConnectPtr conn,
if (virNodeGetInfoEnsureACL(conn) < 0) if (virNodeGetInfoEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetInfo(NULL, nodeinfo); return nodeGetInfo(nodeinfo);
} }
@ -18109,7 +18109,7 @@ qemuNodeGetMemoryStats(virConnectPtr conn,
if (virNodeGetMemoryStatsEnsureACL(conn) < 0) if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); return nodeGetMemoryStats(cellNum, params, nparams, flags);
} }
@ -18176,7 +18176,7 @@ qemuNodeGetCPUMap(virConnectPtr conn,
if (virNodeGetCPUMapEnsureACL(conn) < 0) if (virNodeGetCPUMapEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetCPUMap(NULL, cpumap, online, flags); return nodeGetCPUMap(cpumap, online, flags);
} }

View File

@ -2229,7 +2229,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
/* setaffinity fails if you set bits for CPUs which /* setaffinity fails if you set bits for CPUs which
* aren't present, so we have to limit ourselves */ * aren't present, so we have to limit ourselves */
if ((hostcpus = nodeGetCPUCount(NULL)) < 0) if ((hostcpus = nodeGetCPUCount()) < 0)
goto cleanup; goto cleanup;
if (hostcpus > QEMUD_CPUMASK_LEN) if (hostcpus > QEMUD_CPUMASK_LEN)

View File

@ -65,7 +65,7 @@ virCapsPtr umlCapsInit(void)
* unexpected failures. We don't want to break the QEMU * unexpected failures. We don't want to break the QEMU
* driver in this scenario, so log errors & carry on * driver in this scenario, so log errors & carry on
*/ */
if (nodeCapsInitNUMA(NULL, caps) < 0) { if (nodeCapsInitNUMA(caps) < 0) {
virCapabilitiesFreeNUMAInfo(caps); virCapabilitiesFreeNUMAInfo(caps);
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities"); VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
} }

View File

@ -2774,7 +2774,7 @@ umlNodeGetInfo(virConnectPtr conn,
if (virNodeGetInfoEnsureACL(conn) < 0) if (virNodeGetInfoEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetInfo(NULL, nodeinfo); return nodeGetInfo(nodeinfo);
} }
@ -2802,7 +2802,7 @@ umlNodeGetMemoryStats(virConnectPtr conn,
if (virNodeGetMemoryStatsEnsureACL(conn) < 0) if (virNodeGetMemoryStatsEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); return nodeGetMemoryStats(cellNum, params, nparams, flags);
} }
@ -2869,7 +2869,7 @@ umlNodeGetCPUMap(virConnectPtr conn,
if (virNodeGetCPUMapEnsureACL(conn) < 0) if (virNodeGetCPUMapEnsureACL(conn) < 0)
return -1; return -1;
return nodeGetCPUMap(NULL, cpumap, online, flags); return nodeGetCPUMap(cpumap, online, flags);
} }

View File

@ -3147,7 +3147,7 @@ virCgroupGetPercpuStats(virCgroupPtr group,
} }
/* To parse account file, we need to know how many cpus are present. */ /* To parse account file, we need to know how many cpus are present. */
if (!(cpumap = nodeGetPresentCPUBitmap(NULL))) if (!(cpumap = nodeGetPresentCPUBitmap()))
return -1; return -1;
total_cpus = virBitmapSize(cpumap); total_cpus = virBitmapSize(cpumap);

View File

@ -318,7 +318,7 @@ static virCapsPtr vboxCapsInit(void)
false, false)) == NULL) false, false)) == NULL)
goto no_memory; goto no_memory;
if (nodeCapsInitNUMA(NULL, caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto no_memory; goto no_memory;
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
@ -7527,7 +7527,7 @@ static int
vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
virNodeInfoPtr nodeinfo) virNodeInfoPtr nodeinfo)
{ {
return nodeGetInfo(NULL, nodeinfo); return nodeGetInfo(nodeinfo);
} }
static int static int

View File

@ -68,7 +68,7 @@ vmwareCapsInit(void)
false, false)) == NULL) false, false)) == NULL)
goto error; goto error;
if (nodeCapsInitNUMA(NULL, caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto error; goto error;
/* i686 guests are always supported */ /* i686 guests are always supported */

View File

@ -115,7 +115,7 @@ vzBuildCapabilities(void)
false, false)) == NULL) false, false)) == NULL)
return NULL; return NULL;
if (nodeCapsInitNUMA(NULL, caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto error; goto error;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
@ -125,7 +125,7 @@ vzBuildCapabilities(void)
emulators[k], virt_types[k]) < 0) emulators[k], virt_types[k]) < 0)
goto error; goto error;
if (nodeGetInfo(NULL, &nodeinfo)) if (nodeGetInfo(&nodeinfo))
goto error; goto error;
if (VIR_ALLOC(cpu) < 0) if (VIR_ALLOC(cpu) < 0)
@ -832,7 +832,7 @@ static int
vzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, vzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
virNodeInfoPtr nodeinfo) virNodeInfoPtr nodeinfo)
{ {
return nodeGetInfo(NULL, nodeinfo); return nodeGetInfo(nodeinfo);
} }
static int vzConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) static int vzConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
@ -919,7 +919,7 @@ vzNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
unsigned int *online, unsigned int *online,
unsigned int flags) unsigned int flags)
{ {
return nodeGetCPUMap(NULL, cpumap, online, flags); return nodeGetCPUMap(cpumap, online, flags);
} }
static int static int
@ -1487,7 +1487,7 @@ vzNodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
int *nparams, int *nparams,
unsigned int flags) unsigned int flags)
{ {
return nodeGetMemoryStats(NULL, cellNum, params, nparams, flags); return nodeGetMemoryStats(cellNum, params, nparams, flags);
} }
static int static int

View File

@ -1151,7 +1151,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
PRL_RESULT pret; PRL_RESULT pret;
int ret = -1; int ret = -1;
if ((hostcpus = nodeGetCPUCount(NULL)) < 0) if ((hostcpus = nodeGetCPUCount()) < 0)
goto cleanup; goto cleanup;
/* get number of CPUs */ /* get number of CPUs */

View File

@ -24,8 +24,7 @@ main(void)
#else #else
static int static int
linuxTestCompareFiles(char *sysfs_prefix, linuxTestCompareFiles(const char *cpuinfofile,
const char *cpuinfofile,
virArch arch, virArch arch,
const char *outputfile) const char *outputfile)
{ {
@ -42,7 +41,7 @@ linuxTestCompareFiles(char *sysfs_prefix,
} }
memset(&nodeinfo, 0, sizeof(nodeinfo)); memset(&nodeinfo, 0, sizeof(nodeinfo));
if (linuxNodeInfoCPUPopulate(sysfs_prefix, cpuinfo, arch, &nodeinfo) < 0) { if (linuxNodeInfoCPUPopulate(cpuinfo, arch, &nodeinfo) < 0) {
if (virTestGetDebug()) { if (virTestGetDebug()) {
if (virGetLastError()) if (virGetLastError())
VIR_TEST_DEBUG("\n%s\n", virGetLastErrorMessage()); VIR_TEST_DEBUG("\n%s\n", virGetLastErrorMessage());
@ -175,7 +174,9 @@ linuxTestNodeInfo(const void *opaque)
goto cleanup; goto cleanup;
} }
result = linuxTestCompareFiles(sysfs_prefix, cpuinfo, data->arch, output); linuxNodeInfoSetSysFSSystemPath(sysfs_prefix);
result = linuxTestCompareFiles(cpuinfo, data->arch, output);
linuxNodeInfoSetSysFSSystemPath(NULL);
cleanup: cleanup:
VIR_FREE(cpuinfo); VIR_FREE(cpuinfo);

View File

@ -649,8 +649,8 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
goto cleanup; goto cleanup;
} }
if (nodeGetCPUCount(NULL) != EXPECTED_NCPUS) { if (nodeGetCPUCount() != EXPECTED_NCPUS) {
fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount(NULL)); fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount());
goto cleanup; goto cleanup;
} }