提交 f1a43a0f 编写于 作者: J John Ferlan

nodeinfo: Add sysfs_prefix to nodeGetCPUCount

Add the sysfs_prefix argument to the call to allow for setting the
path for tests to something other than SYSFS_SYSTEM_PATH.
上级 3119e05e
...@@ -705,7 +705,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl) ...@@ -705,7 +705,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()) < 0) if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
return -1; return -1;
if (maxcpu > hostcpus) if (maxcpu > hostcpus)
......
...@@ -1195,7 +1195,7 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED, ...@@ -1195,7 +1195,7 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED,
} }
int int
nodeGetCPUCount(void) nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
{ {
#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
...@@ -1204,21 +1204,27 @@ nodeGetCPUCount(void) ...@@ -1204,21 +1204,27 @@ nodeGetCPUCount(void)
* 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(NULL))) if (!(present_path = linuxGetCPUPresentPath(prefix)))
return -1; return -1;
if (virFileExists(present_path)) { if (virFileExists(present_path)) {
ncpu = linuxParseCPUmax(present_path); ncpu = linuxParseCPUmax(present_path);
} else if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/cpu0")) { goto cleanup;
}
if (virAsprintf(&cpupath, "%s/cpu/cpu0", prefix) < 0)
goto cleanup;
if (virFileExists(cpupath)) {
ncpu = 0; ncpu = 0;
do { do {
ncpu++; ncpu++;
VIR_FREE(cpupath); VIR_FREE(cpupath);
if (virAsprintf(&cpupath, "%s/cpu/cpu%d", if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
SYSFS_SYSTEM_PATH, ncpu) < 0) { prefix, ncpu) < 0) {
ncpu = -1; ncpu = -1;
goto cleanup; goto cleanup;
} }
...@@ -1251,7 +1257,7 @@ nodeGetPresentCPUBitmap(void) ...@@ -1251,7 +1257,7 @@ nodeGetPresentCPUBitmap(void)
virBitmapPtr bitmap = NULL; virBitmapPtr bitmap = NULL;
#endif #endif
if ((max_present = nodeGetCPUCount()) < 0) if ((max_present = nodeGetCPUCount(NULL)) < 0)
return NULL; return NULL;
#ifdef __linux__ #ifdef __linux__
...@@ -1274,7 +1280,7 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED) ...@@ -1274,7 +1280,7 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
virBitmapPtr cpumap; virBitmapPtr cpumap;
int present; int present;
present = nodeGetCPUCount(); present = nodeGetCPUCount(NULL);
if (present < 0) if (present < 0)
return NULL; return NULL;
...@@ -1621,7 +1627,7 @@ nodeGetCPUMap(unsigned char **cpumap, ...@@ -1621,7 +1627,7 @@ nodeGetCPUMap(unsigned char **cpumap,
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (!cpumap && !online) if (!cpumap && !online)
return nodeGetCPUCount(); return nodeGetCPUCount(NULL);
if (!(cpus = nodeGetCPUBitmap(&maxpresent))) if (!(cpus = nodeGetCPUBitmap(&maxpresent)))
goto cleanup; goto cleanup;
......
...@@ -45,7 +45,7 @@ int nodeGetMemory(unsigned long long *mem, ...@@ -45,7 +45,7 @@ int nodeGetMemory(unsigned long long *mem,
virBitmapPtr nodeGetPresentCPUBitmap(void); virBitmapPtr nodeGetPresentCPUBitmap(void);
virBitmapPtr nodeGetCPUBitmap(int *max_id); virBitmapPtr nodeGetCPUBitmap(int *max_id);
int nodeGetCPUCount(void); int nodeGetCPUCount(const char *sysfs_prefix);
int nodeGetMemoryParameters(virTypedParameterPtr params, int nodeGetMemoryParameters(virTypedParameterPtr params,
int *nparams, int *nparams,
......
...@@ -5237,7 +5237,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom, ...@@ -5237,7 +5237,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
if (!(def = virDomainObjGetOneDef(vm, flags))) if (!(def = virDomainObjGetOneDef(vm, flags)))
goto cleanup; goto cleanup;
if ((hostcpus = nodeGetCPUCount()) < 0) if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
goto cleanup; goto cleanup;
if (!(allcpumap = virBitmapNew(hostcpus))) if (!(allcpumap = virBitmapNew(hostcpus)))
...@@ -5425,7 +5425,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, ...@@ -5425,7 +5425,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
if (!(def = virDomainObjGetOneDef(vm, flags))) if (!(def = virDomainObjGetOneDef(vm, flags)))
goto cleanup; goto cleanup;
if ((hostcpus = nodeGetCPUCount()) < 0) if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
goto cleanup; goto cleanup;
if (def->cputune.emulatorpin) { if (def->cputune.emulatorpin) {
...@@ -5668,7 +5668,7 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef, ...@@ -5668,7 +5668,7 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef,
if (targetDef->iothreads == 0) if (targetDef->iothreads == 0)
return 0; return 0;
if ((hostcpus = nodeGetCPUCount()) < 0) if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC_N(info_ret, targetDef->iothreads) < 0) if (VIR_ALLOC_N(info_ret, targetDef->iothreads) < 0)
......
...@@ -2373,7 +2373,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) ...@@ -2373,7 +2373,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()) < 0) if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
goto cleanup; goto cleanup;
if (hostcpus > QEMUD_CPUMASK_LEN) if (hostcpus > QEMUD_CPUMASK_LEN)
......
...@@ -1141,7 +1141,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom, ...@@ -1141,7 +1141,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
PRL_RESULT pret; PRL_RESULT pret;
int ret = -1; int ret = -1;
if ((hostcpus = nodeGetCPUCount()) < 0) if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
goto cleanup; goto cleanup;
/* get number of CPUs */ /* get number of CPUs */
......
...@@ -649,8 +649,8 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED) ...@@ -649,8 +649,8 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
goto cleanup; goto cleanup;
} }
if (nodeGetCPUCount() != EXPECTED_NCPUS) { if (nodeGetCPUCount(NULL) != EXPECTED_NCPUS) {
fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount()); fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount(NULL));
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册