aboutsummaryrefslogtreecommitdiff
path: root/kernel-features.c
diff options
context:
space:
mode:
authorAdam Litke <agl@us.ibm.com>2008-09-03 15:16:18 +0000
committerAdam Litke <agl@us.ibm.com>2008-09-03 15:16:18 +0000
commitf3fccb665dd611f46308998489576d9bd1a8f2a8 (patch)
tree994e2f3fcd138bb28a7d893caa707d7c42764aa5 /kernel-features.c
parentf9456b5f72ce0310884084c9e25c4cbfb4f57ca2 (diff)
downloadlibhugetlbfs-f3fccb665dd611f46308998489576d9bd1a8f2a8.tar.gz
Allow users to override feature detection (V2)
Changes since V1: - Changed the environment variable name and format for specifying overrides. In some cases (such as a distro kernel with backported features) libhugetlbfs will be wrong about the presence of a feature. In these rare cases it will be useful to tell the library whether or not the feature is present in the running kernel. All feature overrides will be specified in the HUGETLB_FEATURES environment variable. The required format is: "[no_]feature1[,[no_]feature2] ... ". The "no_" prefix will mark a feature as absent. Otherwise the named feature is marked present. Signed-off-by: Adam Litke <agl@us.ibm.com>
Diffstat (limited to 'kernel-features.c')
-rw-r--r--kernel-features.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/kernel-features.c b/kernel-features.c
index 1b4508c..8b58f9b 100644
--- a/kernel-features.c
+++ b/kernel-features.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <string.h>
#include <sys/utsname.h>
#include "kernel-features.h"
#include "hugetlbfs.h"
@@ -157,6 +158,7 @@ int hugetlbfs_test_feature(int feature_code)
void __lh_setup_features()
{
struct utsname u;
+ char *env;
int i;
if (uname(&u)) {
@@ -167,10 +169,29 @@ void __lh_setup_features()
str_to_ver(u.release, &running_kernel_version);
debug_kernel_version();
+ /* Check if the user has overrided any features */
+ env = getenv("HUGETLB_FEATURES");
+
for (i = 0; i < HUGETLB_FEATURE_NR; i++) {
struct kernel_version ver;
+ char *name = kernel_features[i].name;
+ char *pos;
+
str_to_ver(kernel_features[i].required_version, &ver);
+ /* Has the user overridden feature detection? */
+ if (env && (pos = strstr(env, name))) {
+ DEBUG("Overriding feature %s: ", name);
+ /* If feature is preceeded by 'no_' then turn it off */
+ if (((pos - 3) >= env) && !strncmp(pos - 3, "no_", 3))
+ DEBUG_CONT("no\n");
+ else {
+ DEBUG_CONT("yes\n");
+ feature_mask |= (1UL << i);
+ }
+ continue;
+ }
+
/* Is the running kernel version newer? */
if (ver_cmp(&running_kernel_version, &ver) >= 0) {
DEBUG("Feature %s is present in this kernel\n",