From 6804cf756791d0e8342f209f2daf445100509b22 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Mon, 6 Apr 2015 18:38:06 -0400 Subject: [PATCH] LU-6266 libcfs: add kstrtoul() compat function The kstrtoul() function was only added to the upstream kernel in commit v2.6.38-6934-g33ee3b2. While it is backported to RHEL6 2.6.32 kernels, it does not exist for vanilla kernels before that point. The patch http://review.whamcloud.com/5700 added uses of kstrtoul() to Lustre that break the build for older kernels. While it would be possible to convert those calls to simple_strtoul(), that function is deprecated in newer kernels, and checkpatch.pl will generate a warning, so using kstrtoul() is the right thing for newer kernels. Add a wrapper function for kstrtoul() for older kernels. There are other kstrto*() functions in newer kernel not added by this patch. Only the one function call is currently used, though it would be good to convert Lustre over to using this family of functions instead of simple_strtoul() in the future. Signed-off-by: Andreas Dilger Change-Id: Id30313e51b8d240aacc09a6e86a22460fa2540e5 Reviewed-on: http://review.whamcloud.com/13820 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 20 ++++++++++++++++++++ libcfs/include/libcfs/linux/libcfs.h | 13 ++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 8b11794..d5eb5cf 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -138,6 +138,24 @@ sk_sleep, [ ]) # LC_SK_SLEEP # +# LIBCFS_KSTRTOUL +# +# 2.6.38 kstrtoul is added +# +AC_DEFUN([LIBCFS_KSTRTOUL], [ +LB_CHECK_COMPILE([if Linux kernel has 'kstrtoul'], +kstrtoul, [ + #include +],[ + unsigned long result; + return kstrtoul("12345", 0, &result); +],[ + AC_DEFINE(HAVE_KSTRTOUL, 1, + [kernel has kstrtoul]) +]) +]) # LIBCFS_KSTRTOUL + +# # LIBCFS_DUMP_TRACE_ADDRESS # # 2.6.39 adds a base pointer address argument to dump_trace @@ -298,6 +316,8 @@ LC_SHRINKER_WANT_SHRINK_PTR LIBCFS_SYSCTL_CTLNAME # 2.6.35 LC_SK_SLEEP +# 2.6.38 +LIBCFS_KSTRTOUL # 2.6.39 LIBCFS_DUMP_TRACE_ADDRESS # 2.6.40 fc15 diff --git a/libcfs/include/libcfs/linux/libcfs.h b/libcfs/include/libcfs/linux/libcfs.h index 162f86b..51991cb 100644 --- a/libcfs/include/libcfs/linux/libcfs.h +++ b/libcfs/include/libcfs/linux/libcfs.h @@ -61,6 +61,7 @@ #include /* THREAD_SIZE */ #include #include +#include #if !defined(__x86_64__) # ifdef __ia64__ @@ -106,7 +107,17 @@ int lprocfs_call_handler(void *data, int write, loff_t *ppos, int (*handler)(void *data, int write, loff_t pos, void __user *buffer, int len)); -#include +#ifndef HAVE_KSTRTOUL +static inline int kstrtoul(const char *s, unsigned int base, unsigned long *res) +{ + char *end = (char *)s; + + *res = simple_strtoul(s, &end, base); + if (end - s == 0) + return -EINVAL; + return 0; +} +#endif /* !HAVE_KSTRTOUL */ /* * No stack-back-tracing in Linux for now. -- 1.8.3.1