|
|
7a3408 |
From 8fd08f800670d5e6ca2e1013d6ffbbf210b5aff4 Mon Sep 17 00:00:00 2001
|
|
|
7a3408 |
Message-Id: <8fd08f800670d5e6ca2e1013d6ffbbf210b5aff4@dist-git>
|
|
|
7a3408 |
From: John Ferlan <jferlan@redhat.com>
|
|
|
7a3408 |
Date: Wed, 5 Aug 2015 18:18:08 +0200
|
|
|
7a3408 |
Subject: [PATCH] nodeinfo: Add sysfs_prefix to nodeGetCPUCount
|
|
|
7a3408 |
|
|
|
7a3408 |
Add the sysfs_prefix argument to the call to allow for setting the
|
|
|
7a3408 |
path for tests to something other than SYSFS_SYSTEM_PATH.
|
|
|
7a3408 |
|
|
|
7a3408 |
(cherry picked from commit f1a43a0f91d80ccbbd9e084de17673e48c2e60f4)
|
|
|
7a3408 |
|
|
|
7a3408 |
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1213713
|
|
|
7a3408 |
|
|
|
7a3408 |
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
|
|
|
7a3408 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
7a3408 |
---
|
|
|
7a3408 |
src/lxc/lxc_controller.c | 2 +-
|
|
|
7a3408 |
src/nodeinfo.c | 20 +++++++++++++-------
|
|
|
7a3408 |
src/nodeinfo.h | 2 +-
|
|
|
7a3408 |
src/qemu/qemu_driver.c | 6 +++---
|
|
|
7a3408 |
src/qemu/qemu_process.c | 2 +-
|
|
|
7a3408 |
src/vz/vz_sdk.c | 2 +-
|
|
|
7a3408 |
tests/vircgrouptest.c | 4 ++--
|
|
|
7a3408 |
7 files changed, 22 insertions(+), 16 deletions(-)
|
|
|
7a3408 |
|
|
|
7a3408 |
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
|
|
|
7a3408 |
index 828b8a8..27e2e3a 100644
|
|
|
7a3408 |
--- a/src/lxc/lxc_controller.c
|
|
|
7a3408 |
+++ b/src/lxc/lxc_controller.c
|
|
|
7a3408 |
@@ -705,7 +705,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
|
|
|
7a3408 |
|
|
|
7a3408 |
/* setaffinity fails if you set bits for CPUs which
|
|
|
7a3408 |
* aren't present, so we have to limit ourselves */
|
|
|
7a3408 |
- if ((hostcpus = nodeGetCPUCount()) < 0)
|
|
|
7a3408 |
+ if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
|
|
|
7a3408 |
return -1;
|
|
|
7a3408 |
|
|
|
7a3408 |
if (maxcpu > hostcpus)
|
|
|
7a3408 |
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
|
|
|
7a3408 |
index f3e3108..409f922 100644
|
|
|
7a3408 |
--- a/src/nodeinfo.c
|
|
|
7a3408 |
+++ b/src/nodeinfo.c
|
|
|
7a3408 |
@@ -1195,7 +1195,7 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED,
|
|
|
7a3408 |
}
|
|
|
7a3408 |
|
|
|
7a3408 |
int
|
|
|
7a3408 |
-nodeGetCPUCount(void)
|
|
|
7a3408 |
+nodeGetCPUCount(const char *sysfs_prefix ATTRIBUTE_UNUSED)
|
|
|
7a3408 |
{
|
|
|
7a3408 |
#if defined(__linux__)
|
|
|
7a3408 |
/* To support older kernels that lack cpu/present, such as 2.6.18
|
|
|
7a3408 |
@@ -1204,21 +1204,27 @@ nodeGetCPUCount(void)
|
|
|
7a3408 |
* will be consecutive.
|
|
|
7a3408 |
*/
|
|
|
7a3408 |
char *present_path = NULL;
|
|
|
7a3408 |
+ const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
|
|
|
7a3408 |
char *cpupath = NULL;
|
|
|
7a3408 |
int ncpu = -1;
|
|
|
7a3408 |
|
|
|
7a3408 |
- if (!(present_path = linuxGetCPUPresentPath(NULL)))
|
|
|
7a3408 |
+ if (!(present_path = linuxGetCPUPresentPath(prefix)))
|
|
|
7a3408 |
return -1;
|
|
|
7a3408 |
|
|
|
7a3408 |
if (virFileExists(present_path)) {
|
|
|
7a3408 |
ncpu = linuxParseCPUmax(present_path);
|
|
|
7a3408 |
- } else if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/cpu0")) {
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+ }
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (virAsprintf(&cpupath, "%s/cpu/cpu0", prefix) < 0)
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+ if (virFileExists(cpupath)) {
|
|
|
7a3408 |
ncpu = 0;
|
|
|
7a3408 |
do {
|
|
|
7a3408 |
ncpu++;
|
|
|
7a3408 |
VIR_FREE(cpupath);
|
|
|
7a3408 |
if (virAsprintf(&cpupath, "%s/cpu/cpu%d",
|
|
|
7a3408 |
- SYSFS_SYSTEM_PATH, ncpu) < 0) {
|
|
|
7a3408 |
+ prefix, ncpu) < 0) {
|
|
|
7a3408 |
ncpu = -1;
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
}
|
|
|
7a3408 |
@@ -1251,7 +1257,7 @@ nodeGetPresentCPUBitmap(void)
|
|
|
7a3408 |
virBitmapPtr bitmap = NULL;
|
|
|
7a3408 |
#endif
|
|
|
7a3408 |
|
|
|
7a3408 |
- if ((max_present = nodeGetCPUCount()) < 0)
|
|
|
7a3408 |
+ if ((max_present = nodeGetCPUCount(NULL)) < 0)
|
|
|
7a3408 |
return NULL;
|
|
|
7a3408 |
|
|
|
7a3408 |
#ifdef __linux__
|
|
|
7a3408 |
@@ -1274,7 +1280,7 @@ nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
|
|
|
7a3408 |
virBitmapPtr cpumap;
|
|
|
7a3408 |
int present;
|
|
|
7a3408 |
|
|
|
7a3408 |
- present = nodeGetCPUCount();
|
|
|
7a3408 |
+ present = nodeGetCPUCount(NULL);
|
|
|
7a3408 |
if (present < 0)
|
|
|
7a3408 |
return NULL;
|
|
|
7a3408 |
|
|
|
7a3408 |
@@ -1621,7 +1627,7 @@ nodeGetCPUMap(unsigned char **cpumap,
|
|
|
7a3408 |
virCheckFlags(0, -1);
|
|
|
7a3408 |
|
|
|
7a3408 |
if (!cpumap && !online)
|
|
|
7a3408 |
- return nodeGetCPUCount();
|
|
|
7a3408 |
+ return nodeGetCPUCount(NULL);
|
|
|
7a3408 |
|
|
|
7a3408 |
if (!(cpus = nodeGetCPUBitmap(&maxpresent)))
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
|
|
|
7a3408 |
index 047bd5c..4f9699e 100644
|
|
|
7a3408 |
--- a/src/nodeinfo.h
|
|
|
7a3408 |
+++ b/src/nodeinfo.h
|
|
|
7a3408 |
@@ -45,7 +45,7 @@ int nodeGetMemory(unsigned long long *mem,
|
|
|
7a3408 |
|
|
|
7a3408 |
virBitmapPtr nodeGetPresentCPUBitmap(void);
|
|
|
7a3408 |
virBitmapPtr nodeGetCPUBitmap(int *max_id);
|
|
|
7a3408 |
-int nodeGetCPUCount(void);
|
|
|
7a3408 |
+int nodeGetCPUCount(const char *sysfs_prefix);
|
|
|
7a3408 |
|
|
|
7a3408 |
int nodeGetMemoryParameters(virTypedParameterPtr params,
|
|
|
7a3408 |
int *nparams,
|
|
|
7a3408 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
7a3408 |
index 8f5e4fb..e30a02d 100644
|
|
|
7a3408 |
--- a/src/qemu/qemu_driver.c
|
|
|
7a3408 |
+++ b/src/qemu/qemu_driver.c
|
|
|
7a3408 |
@@ -5253,7 +5253,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
|
|
|
7a3408 |
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
|
|
|
7a3408 |
- if ((hostcpus = nodeGetCPUCount()) < 0)
|
|
|
7a3408 |
+ if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
|
|
|
7a3408 |
if (!(allcpumap = virBitmapNew(hostcpus)))
|
|
|
7a3408 |
@@ -5441,7 +5441,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
|
|
|
7a3408 |
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
|
|
|
7a3408 |
- if ((hostcpus = nodeGetCPUCount()) < 0)
|
|
|
7a3408 |
+ if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
|
|
|
7a3408 |
if (def->cputune.emulatorpin) {
|
|
|
7a3408 |
@@ -5684,7 +5684,7 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr targetDef,
|
|
|
7a3408 |
if (targetDef->iothreads == 0)
|
|
|
7a3408 |
return 0;
|
|
|
7a3408 |
|
|
|
7a3408 |
- if ((hostcpus = nodeGetCPUCount()) < 0)
|
|
|
7a3408 |
+ if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
|
|
|
7a3408 |
if (VIR_ALLOC_N(info_ret, targetDef->iothreads) < 0)
|
|
|
7a3408 |
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
|
7a3408 |
index f41fd9d..e1c7f0b 100644
|
|
|
7a3408 |
--- a/src/qemu/qemu_process.c
|
|
|
7a3408 |
+++ b/src/qemu/qemu_process.c
|
|
|
7a3408 |
@@ -2408,7 +2408,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
|
|
|
7a3408 |
|
|
|
7a3408 |
/* setaffinity fails if you set bits for CPUs which
|
|
|
7a3408 |
* aren't present, so we have to limit ourselves */
|
|
|
7a3408 |
- if ((hostcpus = nodeGetCPUCount()) < 0)
|
|
|
7a3408 |
+ if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
|
|
|
7a3408 |
if (hostcpus > QEMUD_CPUMASK_LEN)
|
|
|
7a3408 |
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
|
|
|
7a3408 |
index f27098c..a584940 100644
|
|
|
7a3408 |
--- a/src/vz/vz_sdk.c
|
|
|
7a3408 |
+++ b/src/vz/vz_sdk.c
|
|
|
7a3408 |
@@ -1141,7 +1141,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
|
|
|
7a3408 |
PRL_RESULT pret;
|
|
|
7a3408 |
int ret = -1;
|
|
|
7a3408 |
|
|
|
7a3408 |
- if ((hostcpus = nodeGetCPUCount()) < 0)
|
|
|
7a3408 |
+ if ((hostcpus = nodeGetCPUCount(NULL)) < 0)
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
|
|
|
7a3408 |
/* get number of CPUs */
|
|
|
7a3408 |
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
|
|
|
7a3408 |
index dddf33a..7a87640 100644
|
|
|
7a3408 |
--- a/tests/vircgrouptest.c
|
|
|
7a3408 |
+++ b/tests/vircgrouptest.c
|
|
|
7a3408 |
@@ -649,8 +649,8 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
}
|
|
|
7a3408 |
|
|
|
7a3408 |
- if (nodeGetCPUCount() != EXPECTED_NCPUS) {
|
|
|
7a3408 |
- fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount());
|
|
|
7a3408 |
+ if (nodeGetCPUCount(NULL) != EXPECTED_NCPUS) {
|
|
|
7a3408 |
+ fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount(NULL));
|
|
|
7a3408 |
goto cleanup;
|
|
|
7a3408 |
}
|
|
|
7a3408 |
|
|
|
7a3408 |
--
|
|
|
7a3408 |
2.5.0
|
|
|
7a3408 |
|