mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
nodeinfo: Add sysfs_prefix to nodeCapsInitNUMA
Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_CPU_PATH which is a derivative of SYSFS_SYSTEM_PATH Use cpupath for nodeCapsInitNUMAFake and remove SYSFS_CPU_PATH
This commit is contained in:
parent
29e4f2243f
commit
b97b30480d
@ -77,7 +77,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
|
||||
* unexpected failures. We don't want to break the lxc
|
||||
* driver in this scenario, so log errors & carry on
|
||||
*/
|
||||
if (nodeCapsInitNUMA(caps) < 0) {
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0) {
|
||||
virCapabilitiesFreeNUMAInfo(caps);
|
||||
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
|
||||
}
|
||||
|
@ -283,7 +283,6 @@ freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
|
||||
#ifdef __linux__
|
||||
# define CPUINFO_PATH "/proc/cpuinfo"
|
||||
# define SYSFS_SYSTEM_PATH "/sys/devices/system"
|
||||
# define SYSFS_CPU_PATH SYSFS_SYSTEM_PATH"/cpu"
|
||||
# define PROCSTAT_PATH "/proc/stat"
|
||||
# define MEMINFO_PATH "/proc/meminfo"
|
||||
# define SYSFS_MEMORY_SHARED_PATH "/sys/kernel/mm/ksm"
|
||||
@ -1660,7 +1659,9 @@ nodeGetCPUMap(const char *sysfs_prefix,
|
||||
}
|
||||
|
||||
static int
|
||||
nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
|
||||
nodeCapsInitNUMAFake(const char *prefix,
|
||||
const char *cpupath ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virNodeInfo nodeinfo;
|
||||
virCapsHostNUMACellCPUPtr cpus;
|
||||
@ -1669,7 +1670,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
|
||||
int id, cid;
|
||||
int onlinecpus ATTRIBUTE_UNUSED;
|
||||
|
||||
if (nodeGetInfo(NULL, &nodeinfo) < 0)
|
||||
if (nodeGetInfo(prefix, &nodeinfo) < 0)
|
||||
return -1;
|
||||
|
||||
ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
|
||||
@ -1683,7 +1684,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
|
||||
for (c = 0; c < nodeinfo.cores; c++) {
|
||||
for (t = 0; t < nodeinfo.threads; t++) {
|
||||
#ifdef __linux__
|
||||
if (virNodeGetCpuValue(SYSFS_CPU_PATH, id, "online", 1)) {
|
||||
if (virNodeGetCpuValue(cpupath, id, "online", 1)) {
|
||||
#endif
|
||||
cpus[cid].id = id;
|
||||
cpus[cid].socket_id = s;
|
||||
@ -1810,26 +1811,27 @@ nodeGetMemoryFake(unsigned long long *mem,
|
||||
|
||||
/* returns 1 on success, 0 if the detection failed and -1 on hard error */
|
||||
static int
|
||||
virNodeCapsFillCPUInfo(int cpu_id ATTRIBUTE_UNUSED,
|
||||
virNodeCapsFillCPUInfo(const char *cpupath ATTRIBUTE_UNUSED,
|
||||
int cpu_id ATTRIBUTE_UNUSED,
|
||||
virCapsHostNUMACellCPUPtr cpu ATTRIBUTE_UNUSED)
|
||||
{
|
||||
#ifdef __linux__
|
||||
int tmp;
|
||||
cpu->id = cpu_id;
|
||||
|
||||
if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
|
||||
if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
|
||||
"topology/physical_package_id", -1)) < 0)
|
||||
return 0;
|
||||
|
||||
cpu->socket_id = tmp;
|
||||
|
||||
if ((tmp = virNodeGetCpuValue(SYSFS_CPU_PATH, cpu_id,
|
||||
if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
|
||||
"topology/core_id", -1)) < 0)
|
||||
return 0;
|
||||
|
||||
cpu->core_id = tmp;
|
||||
|
||||
if (!(cpu->siblings = virNodeGetSiblingsList(SYSFS_CPU_PATH, cpu_id)))
|
||||
if (!(cpu->siblings = virNodeGetSiblingsList(cpupath, cpu_id)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@ -1917,8 +1919,11 @@ virNodeCapsGetPagesInfo(int node,
|
||||
}
|
||||
|
||||
int
|
||||
nodeCapsInitNUMA(virCapsPtr caps)
|
||||
nodeCapsInitNUMA(const char *sysfs_prefix,
|
||||
virCapsPtr caps)
|
||||
{
|
||||
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
|
||||
char *cpupath;
|
||||
int n;
|
||||
unsigned long long memory;
|
||||
virCapsHostNUMACellCPUPtr cpus = NULL;
|
||||
@ -1933,8 +1938,13 @@ nodeCapsInitNUMA(virCapsPtr caps)
|
||||
bool topology_failed = false;
|
||||
int max_node;
|
||||
|
||||
if (!virNumaIsAvailable())
|
||||
return nodeCapsInitNUMAFake(caps);
|
||||
if (virAsprintf(&cpupath, "%s/cpu", prefix) < 0)
|
||||
return -1;
|
||||
|
||||
if (!virNumaIsAvailable()) {
|
||||
ret = nodeCapsInitNUMAFake(prefix, cpupath, caps);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((max_node = virNumaGetMaxNode()) < 0)
|
||||
goto cleanup;
|
||||
@ -1955,7 +1965,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
|
||||
|
||||
for (i = 0; i < virBitmapSize(cpumap); i++) {
|
||||
if (virBitmapIsBitSet(cpumap, i)) {
|
||||
if (virNodeCapsFillCPUInfo(i, cpus + cpu++) < 0) {
|
||||
if (virNodeCapsFillCPUInfo(cpupath, i, cpus + cpu++) < 0) {
|
||||
topology_failed = true;
|
||||
virResetLastError();
|
||||
}
|
||||
@ -1995,6 +2005,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
|
||||
VIR_FREE(cpus);
|
||||
VIR_FREE(siblings);
|
||||
VIR_FREE(pageinfo);
|
||||
VIR_FREE(cpupath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
# include "capabilities.h"
|
||||
|
||||
int nodeGetInfo(const char *sysfs_prefix, virNodeInfoPtr nodeinfo);
|
||||
int nodeCapsInitNUMA(virCapsPtr caps);
|
||||
int nodeCapsInitNUMA(const char *sysfs_prefix, virCapsPtr caps);
|
||||
|
||||
int nodeGetCPUStats(int cpuNum,
|
||||
virNodeCPUStatsPtr params,
|
||||
|
@ -175,7 +175,7 @@ virCapsPtr openvzCapsInit(void)
|
||||
false, false)) == NULL)
|
||||
goto no_memory;
|
||||
|
||||
if (nodeCapsInitNUMA(caps) < 0)
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0)
|
||||
goto no_memory;
|
||||
|
||||
if ((guest = virCapabilitiesAddGuest(caps,
|
||||
|
@ -335,7 +335,7 @@ phypCapsInit(void)
|
||||
* unexpected failures. We don't want to break the QEMU
|
||||
* driver in this scenario, so log errors & carry on
|
||||
*/
|
||||
if (nodeCapsInitNUMA(caps) < 0) {
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0) {
|
||||
virCapabilitiesFreeNUMAInfo(caps);
|
||||
VIR_WARN
|
||||
("Failed to query host NUMA topology, disabling NUMA capabilities");
|
||||
|
@ -1024,7 +1024,7 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
|
||||
* unexpected failures. We don't want to break the QEMU
|
||||
* driver in this scenario, so log errors & carry on
|
||||
*/
|
||||
if (nodeCapsInitNUMA(caps) < 0) {
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0) {
|
||||
virCapabilitiesFreeNUMAInfo(caps);
|
||||
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ virCapsPtr umlCapsInit(void)
|
||||
* unexpected failures. We don't want to break the QEMU
|
||||
* driver in this scenario, so log errors & carry on
|
||||
*/
|
||||
if (nodeCapsInitNUMA(caps) < 0) {
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0) {
|
||||
virCapabilitiesFreeNUMAInfo(caps);
|
||||
VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ static virCapsPtr vboxCapsInit(void)
|
||||
false, false)) == NULL)
|
||||
goto no_memory;
|
||||
|
||||
if (nodeCapsInitNUMA(caps) < 0)
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0)
|
||||
goto no_memory;
|
||||
|
||||
if ((guest = virCapabilitiesAddGuest(caps,
|
||||
|
@ -68,7 +68,7 @@ vmwareCapsInit(void)
|
||||
false, false)) == NULL)
|
||||
goto error;
|
||||
|
||||
if (nodeCapsInitNUMA(caps) < 0)
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0)
|
||||
goto error;
|
||||
|
||||
/* i686 guests are always supported */
|
||||
|
@ -122,7 +122,7 @@ vzBuildCapabilities(void)
|
||||
false, false)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (nodeCapsInitNUMA(caps) < 0)
|
||||
if (nodeCapsInitNUMA(NULL, caps) < 0)
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user