Whamcloud - gitweb
LU-6266 libcfs: add kstrtoul() compat function 20/13820/7
authorAndreas Dilger <andreas.dilger@intel.com>
Mon, 6 Apr 2015 22:38:06 +0000 (18:38 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 1 May 2015 03:25:09 +0000 (03:25 +0000)
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 <andreas.dilger@intel.com>
Change-Id: Id30313e51b8d240aacc09a6e86a22460fa2540e5
Reviewed-on: http://review.whamcloud.com/13820
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/linux/libcfs.h

index 8b11794..d5eb5cf 100644 (file)
@@ -138,6 +138,24 @@ sk_sleep, [
 ]) # LC_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 <linux/kernel.h>
+],[
+       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
 # 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
 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
 # 2.6.39
 LIBCFS_DUMP_TRACE_ADDRESS
 # 2.6.40 fc15
index 162f86b..51991cb 100644 (file)
@@ -61,6 +61,7 @@
 #include <linux/sched.h> /* THREAD_SIZE */
 #include <linux/rbtree.h>
 #include <linux/bitops.h>
 #include <linux/sched.h> /* THREAD_SIZE */
 #include <linux/rbtree.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 
 #if !defined(__x86_64__)
 # ifdef  __ia64__
 
 #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));
 
                         int (*handler)(void *data, int write,
                         loff_t pos, void __user *buffer, int len));
 
-#include <linux/capability.h>
+#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.
 
 /*
  * No stack-back-tracing in Linux for now.