mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 23:55:23 +00:00
nodeinfo: Add sysfs_prefix to nodeGetCPUBitmap
Add the sysfs_prefix argument to the call to allow for setting the path for tests to something other than SYSFS_SYSTEM_PATH.
This commit is contained in:
parent
51281dcb90
commit
f220a3e5a8
@ -1275,29 +1275,35 @@ nodeGetPresentCPUBitmap(const char *sysfs_prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
virBitmapPtr
|
virBitmapPtr
|
||||||
nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
|
nodeGetCPUBitmap(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
||||||
|
int *max_id ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
|
||||||
|
char *online_path = NULL;
|
||||||
virBitmapPtr cpumap;
|
virBitmapPtr cpumap;
|
||||||
int present;
|
int present;
|
||||||
|
|
||||||
present = nodeGetCPUCount(NULL);
|
present = nodeGetCPUCount(prefix);
|
||||||
if (present < 0)
|
if (present < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/online")) {
|
if (virAsprintf(&online_path, "%s/cpu/online", prefix) < 0)
|
||||||
cpumap = linuxParseCPUmap(present, SYSFS_SYSTEM_PATH "/cpu/online");
|
return NULL;
|
||||||
|
if (virFileExists(online_path)) {
|
||||||
|
cpumap = linuxParseCPUmap(present, online_path);
|
||||||
} else {
|
} else {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
cpumap = virBitmapNew(present);
|
cpumap = virBitmapNew(present);
|
||||||
if (!cpumap)
|
if (!cpumap)
|
||||||
return NULL;
|
goto cleanup;
|
||||||
for (i = 0; i < present; i++) {
|
for (i = 0; i < present; i++) {
|
||||||
int online = virNodeGetCpuValue(SYSFS_SYSTEM_PATH, i, "online", 1);
|
int online = virNodeGetCpuValue(prefix, i, "online", 1);
|
||||||
if (online < 0) {
|
if (online < 0) {
|
||||||
virBitmapFree(cpumap);
|
virBitmapFree(cpumap);
|
||||||
return NULL;
|
cpumap = NULL;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (online)
|
if (online)
|
||||||
ignore_value(virBitmapSetBit(cpumap, i));
|
ignore_value(virBitmapSetBit(cpumap, i));
|
||||||
@ -1305,6 +1311,8 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
|
|||||||
}
|
}
|
||||||
if (max_id && cpumap)
|
if (max_id && cpumap)
|
||||||
*max_id = present;
|
*max_id = present;
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(online_path);
|
||||||
return cpumap;
|
return cpumap;
|
||||||
#else
|
#else
|
||||||
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
||||||
@ -1630,7 +1638,7 @@ nodeGetCPUMap(unsigned char **cpumap,
|
|||||||
if (!cpumap && !online)
|
if (!cpumap && !online)
|
||||||
return nodeGetCPUCount(NULL);
|
return nodeGetCPUCount(NULL);
|
||||||
|
|
||||||
if (!(cpus = nodeGetCPUBitmap(&maxpresent)))
|
if (!(cpus = nodeGetCPUBitmap(NULL, &maxpresent)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0)
|
if (cpumap && virBitmapToData(cpus, cpumap, &dummy) < 0)
|
||||||
|
@ -44,7 +44,7 @@ int nodeGetMemory(unsigned long long *mem,
|
|||||||
unsigned long long *freeMem);
|
unsigned long long *freeMem);
|
||||||
|
|
||||||
virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix);
|
virBitmapPtr nodeGetPresentCPUBitmap(const char *sysfs_prefix);
|
||||||
virBitmapPtr nodeGetCPUBitmap(int *max_id);
|
virBitmapPtr nodeGetCPUBitmap(const char *sysfs_prefix, int *max_id);
|
||||||
int nodeGetCPUCount(const char *sysfs_prefix);
|
int nodeGetCPUCount(const char *sysfs_prefix);
|
||||||
|
|
||||||
int nodeGetMemoryParameters(virTypedParameterPtr params,
|
int nodeGetMemoryParameters(virTypedParameterPtr params,
|
||||||
|
Loading…
Reference in New Issue
Block a user