[Devel] [PATCH 4/6] don't support vz-specific cpu functions if vz kernel is not present

Glauber Costa glommer at parallels.com
Mon Nov 26 06:35:32 PST 2012


We can't call any of the vz ioctls if we are not running in a
vz-compatible kernel. So if it is compile-time disabled, don't
compile them in.

We could do it in headers, but those functions will have upstream
similars, so we need them to be callable function objects, that will
just return a meaningful error in this case.

Signed-off-by: Glauber Costa <glommer at parallels.com>
---
 src/lib/cpu.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/lib/cpu.c b/src/lib/cpu.c
index f5d85d1..9ff4d20 100644
--- a/src/lib/cpu.c
+++ b/src/lib/cpu.c
@@ -30,6 +30,7 @@
 #include "logger.h"
 #include "vzsyscalls.h"
 
+#ifdef VZ_KERNEL_SUPPORTED
 static inline int fairsched_chwt(unsigned int id, unsigned wght)
 {
 	int ret;
@@ -60,22 +61,38 @@ static inline int fairsched_vcpus(unsigned int id, unsigned vcpus)
 	return ret;
 }
 
-#if defined(__i386__) || defined(__x86_64__)
 static inline int fairsched_cpumask(unsigned int id,
 		unsigned int masksize, unsigned long *mask)
 {
-	int ret;
+	int ret = ENOTSUP;
+/*
+ * fairsched_cpumask is available only in vz kernels based on linux 2.6.32
+ * or later which do not support platforms different from x86.
+ */
+#if defined(__i386__) || defined(__x86_64__)
 
 	ret = syscall(__NR_fairsched_cpumask, id, masksize, mask);
 	if (ret && errno == ENOSYS)
 		ret = 0;
+#endif
 	return ret;
 }
 #else
-/*
- * fairsched_cpumask is available only in vz kernels based on linux 2.6.32
- * or later which do not support platforms different from x86.
- */
+static inline int fairsched_chwt(unsigned int id, unsigned wght)
+{
+	return ENOTSUP;
+}
+
+static inline int fairsched_rate(unsigned int id, int op, unsigned rate)
+{
+	return ENOTSUP;
+}
+
+static inline int fairsched_vcpus(unsigned int id, unsigned vcpus)
+{
+	return ENOTSUP;
+}
+
 static inline int fairsched_cpumask(unsigned int id,
 		unsigned int masksize, unsigned long *mask)
 {
-- 
1.7.11.7




More information about the Devel mailing list