]> git.proxmox.com Git - mirror_spl.git/blobdiff - config/spl-build.m4
Linux 4.15 compat: timer updates
[mirror_spl.git] / config / spl-build.m4
index f9287e2de1084c00ebd720a4c86162cbe73c106f..926abd5c8b4916c0f30136b03ab7d989d417756b 100644 (file)
@@ -18,80 +18,43 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
        AC_SUBST(KERNELCPPFLAGS)
 
        SPL_AC_DEBUG
-       SPL_AC_DEBUG_LOG
        SPL_AC_DEBUG_KMEM
        SPL_AC_DEBUG_KMEM_TRACKING
        SPL_AC_TEST_MODULE
        SPL_AC_ATOMIC_SPINLOCK
-       SPL_AC_TYPE_ATOMIC64_CMPXCHG
-       SPL_AC_TYPE_ATOMIC64_XCHG
-       SPL_AC_TYPE_UINTPTR_T
-       SPL_AC_2ARGS_REGISTER_SYSCTL
        SPL_AC_SHRINKER_CALLBACK
-       SPL_AC_TASK_CURR
-       SPL_AC_CTL_UNNUMBERED
        SPL_AC_CTL_NAME
-       SPL_AC_VMALLOC_INFO
+       SPL_AC_CONFIG_TRIM_UNUSED_KSYMS
        SPL_AC_PDE_DATA
-       SPL_AC_FLS64
-       SPL_AC_DEVICE_CREATE
-       SPL_AC_5ARGS_DEVICE_CREATE
-       SPL_AC_CLASS_DEVICE_CREATE
-       SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT
-       SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE
-       SPL_AC_TIMESPEC_SUB
-       SPL_AC_INIT_UTSNAME
-       SPL_AC_UACCESS_HEADER
-       SPL_AC_KMALLOC_NODE
-       SPL_AC_MONOTONIC_CLOCK
-       SPL_AC_INODE_I_MUTEX
-       SPL_AC_MUTEX_OWNER
-       SPL_AC_MUTEX_OWNER_TASK_STRUCT
-       SPL_AC_MUTEX_LOCK_NESTED
-       SPL_AC_3ARGS_ON_EACH_CPU
-       SPL_AC_KALLSYMS_LOOKUP_NAME
-       SPL_AC_GET_VMALLOC_INFO
-       SPL_AC_PGDAT_HELPERS
-       SPL_AC_FIRST_ONLINE_PGDAT
-       SPL_AC_NEXT_ONLINE_PGDAT
-       SPL_AC_NEXT_ZONE
-       SPL_AC_PGDAT_LIST
-       SPL_AC_GLOBAL_PAGE_STATE
-       SPL_AC_ZONE_STAT_ITEM_FREE
-       SPL_AC_ZONE_STAT_ITEM_INACTIVE
-       SPL_AC_ZONE_STAT_ITEM_ACTIVE
-       SPL_AC_GET_ZONE_COUNTS
-       SPL_AC_USER_PATH_DIR
-       SPL_AC_SET_FS_PWD
        SPL_AC_SET_FS_PWD_WITH_CONST
-       SPL_AC_2ARGS_VFS_UNLINK
-       SPL_AC_4ARGS_VFS_RENAME
-       SPL_AC_VFS_FSYNC
        SPL_AC_2ARGS_VFS_FSYNC
        SPL_AC_INODE_TRUNCATE_RANGE
        SPL_AC_FS_STRUCT_SPINLOCK
-       SPL_AC_CRED_STRUCT
        SPL_AC_KUIDGID_T
-       SPL_AC_GROUPS_SEARCH
-       SPL_AC_PUT_TASK_STRUCT
-       SPL_AC_5ARGS_PROC_HANDLER
-       SPL_AC_KVASPRINTF
-       SPL_AC_EXPORTED_RWSEM_IS_LOCKED
        SPL_AC_KERNEL_FALLOCATE
-       SPL_AC_SHRINK_DCACHE_MEMORY
-       SPL_AC_SHRINK_ICACHE_MEMORY
-       SPL_AC_KERN_PATH
-       SPL_AC_CONFIG_KALLSYMS
        SPL_AC_CONFIG_ZLIB_INFLATE
        SPL_AC_CONFIG_ZLIB_DEFLATE
        SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
        SPL_AC_SHRINK_CONTROL_STRUCT
        SPL_AC_RWSEM_SPINLOCK_IS_RAW
+       SPL_AC_RWSEM_ACTIVITY
+       SPL_AC_RWSEM_ATOMIC_LONG_COUNT
        SPL_AC_SCHED_RT_HEADER
+       SPL_AC_SCHED_SIGNAL_HEADER
+       SPL_AC_4ARGS_VFS_GETATTR
+       SPL_AC_3ARGS_VFS_GETATTR
        SPL_AC_2ARGS_VFS_GETATTR
        SPL_AC_USLEEP_RANGE
        SPL_AC_KMEM_CACHE_ALLOCFLAGS
        SPL_AC_WAIT_ON_BIT
+       SPL_AC_INODE_LOCK
+       SPL_AC_GROUP_INFO_GID
+       SPL_AC_KMEM_CACHE_CREATE_USERCOPY
+       SPL_AC_WAIT_QUEUE_ENTRY_T
+       SPL_AC_WAIT_QUEUE_HEAD_ENTRY
+       SPL_AC_KERNEL_WRITE
+       SPL_AC_KERNEL_READ
+       SPL_AC_KERNEL_TIMER_FUNCTION_TIMER_LIST
 ])
 
 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
@@ -152,6 +115,7 @@ AC_DEFUN([SPL_AC_KERNEL], [
                if test "$kernelsrc" = "NONE"; then
                        kernsrcver=NONE
                fi
+               withlinux=yes
        fi
 
        AC_MSG_RESULT([$kernelsrc])
@@ -164,7 +128,7 @@ AC_DEFUN([SPL_AC_KERNEL], [
 
        AC_MSG_CHECKING([kernel build directory])
        if test -z "$kernelbuild"; then
-               if test -e "/lib/modules/$(uname -r)/build"; then
+               if test x$withlinux != xyes -a -e "/lib/modules/$(uname -r)/build"; then
                        kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
                elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
                        kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
@@ -263,7 +227,7 @@ AC_DEFUN([SPL_AC_RPM], [
                AC_MSG_RESULT([$HAVE_RPMBUILD])
        ])
 
-       RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1" --define "$(DEBUG_LOG) 1" --define "$(DEBUG_KMEM) 1" --define "$(DEBUG_KMEM_TRACKING) 1"'
+       RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1" --define "$(DEBUG_KMEM) 1" --define "$(DEBUG_KMEM_TRACKING) 1"'
        RPM_DEFINE_UTIL=
        RPM_DEFINE_KMOD='--define "kernels $(LINUX_VERSION)"'
        RPM_DEFINE_DKMS=
@@ -276,7 +240,7 @@ AC_DEFUN([SPL_AC_RPM], [
        RPM_SPEC_DIR="rpm/generic"
        AC_ARG_WITH([spec],
                AS_HELP_STRING([--with-spec=SPEC],
-               [Spec files 'generic|fedora']),
+               [Spec files 'generic|redhat']),
                [RPM_SPEC_DIR="rpm/$withval"])
 
        AC_MSG_CHECKING([whether spec files are available])
@@ -496,52 +460,18 @@ AC_DEFUN([SPL_AC_DEBUG], [
        AC_MSG_RESULT([$enable_debug])
 ])
 
-dnl #
-dnl # Enabled by default it provides a basic debug log infrastructure.
-dnl # Each subsystem registers itself with a name and logs messages
-dnl # using predefined types.  If the debug mask it set to allow the
-dnl # message type it will be written to the internal log.  The log
-dnl # can be dumped to a file by echoing 1 to the 'dump' proc entry,
-dnl # after dumping the log it must be decoded using the spl utility.
-dnl #
-dnl # echo 1 >/proc/sys/kernel/spl/debug/dump
-dnl # spl /tmp/spl-log.xxx.yyy /tmp/spl-log.xxx.yyy.txt
-dnl #
-AC_DEFUN([SPL_AC_DEBUG_LOG], [
-       AC_ARG_ENABLE([debug-log],
-               [AS_HELP_STRING([--enable-debug-log],
-               [Enable basic debug logging @<:@default=yes@:>@])],
-               [],
-               [enable_debug_log=yes])
-
-       AS_IF([test "x$enable_debug_log" = xyes],
-       [
-               KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_LOG"
-               DEBUG_LOG="_with_debug_log"
-               AC_DEFINE([DEBUG_LOG], [1],
-               [Define to 1 to enable basic debug logging])
-       ], [
-               DEBUG_LOG="_without_debug_log"
-       ])
-
-       AC_SUBST(DEBUG_LOG)
-       AC_MSG_CHECKING([whether basic debug logging is enabled])
-       AC_MSG_RESULT([$enable_debug_log])
-])
-
 dnl #
 dnl # Enabled by default it provides a minimal level of memory tracking.
 dnl # A total count of bytes allocated is kept for each alloc and free.
 dnl # Then at module unload time a report to the console will be printed
-dnl # if memory was leaked.  Additionally, /proc/spl/kmem/slab will exist
-dnl # and provide an easy way to inspect the kmem based slab.
+dnl # if memory was leaked.
 dnl #
 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
        AC_ARG_ENABLE([debug-kmem],
                [AS_HELP_STRING([--enable-debug-kmem],
-               [Enable basic kmem accounting @<:@default=yes@:>@])],
+               [Enable basic kmem accounting @<:@default=no@:>@])],
                [],
-               [enable_debug_kmem=yes])
+               [enable_debug_kmem=no])
 
        AS_IF([test "x$enable_debug_kmem" = xyes],
        [
@@ -755,16 +685,19 @@ AC_DEFUN([SPL_AC_TEST_MODULE],
                fi
        ])
 
-       AC_RUN_IFELSE([
-               AC_LANG_PROGRAM([
-                       #include "$LINUX/include/linux/license.h"
+       AS_IF([test "x$cross_compiling" != xyes], [
+               AC_RUN_IFELSE([
+                       AC_LANG_PROGRAM([
+                               #include "$LINUX/include/linux/license.h"
+                       ], [
+                               return !license_is_gpl_compatible(
+                                   "$SPL_META_LICENSE");
+                       ])
+               ], [
+                       AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
+                           [Define to 1 if GPL-only symbols can be used])
                ], [
-                       return !license_is_gpl_compatible("$SPL_META_LICENSE");
                ])
-       ], [
-               AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
-                   [Define to 1 if GPL-only symbols can be used])
-       ], [
        ])
 ])
 
@@ -820,82 +753,6 @@ AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
        AC_MSG_RESULT([$have_atomic64_t])
 ])
 
-dnl #
-dnl # 2.6.24 API change,
-dnl # check if atomic64_cmpxchg is defined
-dnl #
-AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG],
-       [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
-       ],[
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(HAVE_ATOMIC64_CMPXCHG, 1,
-                         [kernel defines atomic64_cmpxchg])
-       ],[
-               AC_MSG_RESULT([no])
-       ])
-])
-
-dnl #
-dnl # 2.6.24 API change,
-dnl # check if atomic64_xchg is defined
-dnl #
-AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG],
-       [AC_MSG_CHECKING([whether kernel defines atomic64_xchg])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               atomic64_xchg((atomic64_t *)NULL, 0);
-       ],[
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(HAVE_ATOMIC64_XCHG, 1,
-                         [kernel defines atomic64_xchg])
-       ],[
-               AC_MSG_RESULT([no])
-       ])
-])
-
-dnl #
-dnl # 2.6.24 API change,
-dnl # check if uintptr_t typedef is defined
-dnl #
-AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
-       [AC_MSG_CHECKING([whether kernel defines uintptr_t])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/types.h>
-       ],[
-               uintptr_t *ptr __attribute__ ((unused));
-       ],[
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(HAVE_UINTPTR_T, 1,
-                         [kernel defines uintptr_t])
-       ],[
-               AC_MSG_RESULT([no])
-       ])
-])
-
-dnl #
-dnl # 2.6.21 API change,
-dnl # 'register_sysctl_table' use only one argument instead of two
-dnl #
-AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
-       [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/sysctl.h>
-       ],[
-               (void) register_sysctl_table(NULL, 0);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
-                         [register_sysctl_table() wants 2 args])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
 AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
        tmp_flags="$EXTRA_KCFLAGS"
        EXTRA_KCFLAGS="-Werror"
@@ -1000,44 +857,6 @@ AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
        EXTRA_KCFLAGS="$tmp_flags"
 ])
 
-dnl #
-dnl # Custom SPL patch may export this system it is not required
-dnl #
-AC_DEFUN([SPL_AC_TASK_CURR],
-       [AC_MSG_CHECKING([whether task_curr() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/sched.h>
-       ], [
-               task_curr(NULL);
-       ], [task_curr], [kernel/sched.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.19 API change,
-dnl # Use CTL_UNNUMBERED when binary sysctl is not required
-dnl #
-AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
-       [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/sysctl.h>
-       ],[
-               #ifndef CTL_UNNUMBERED
-               #error CTL_UNNUMBERED undefined
-               #endif
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
-                         [unnumbered sysctl support exists])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
 dnl #
 dnl # 2.6.33 API change,
 dnl # Removed .ctl_name from struct ctl_table.
@@ -1058,1270 +877,223 @@ AC_DEFUN([SPL_AC_CTL_NAME], [
 ])
 
 dnl #
-dnl # 2.6.16 API change.
-dnl # Check if 'fls64()' is available
+dnl # 3.10 API change,
+dnl # PDE is replaced by PDE_DATA
 dnl #
-AC_DEFUN([SPL_AC_FLS64],
-       [AC_MSG_CHECKING([whether fls64() is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/bitops.h>
-       ],[
-               return fls64(0);
-       ],[
+AC_DEFUN([SPL_AC_PDE_DATA], [
+       AC_MSG_CHECKING([whether PDE_DATA() is available])
+       SPL_LINUX_TRY_COMPILE_SYMBOL([
+               #include <linux/proc_fs.h>
+       ], [
+               PDE_DATA(NULL);
+       ], [PDE_DATA], [], [
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
+               AC_DEFINE(HAVE_PDE_DATA, 1, [yes])
        ],[
                AC_MSG_RESULT(no)
        ])
 ])
 
 dnl #
-dnl # 2.6.18 API change, check whether device_create() is available.
-dnl # Device_create() was introduced in 2.6.18 and depricated 
-dnl # class_device_create() which was fully removed in 2.6.26.
-dnl #
-AC_DEFUN([SPL_AC_DEVICE_CREATE],
-       [AC_MSG_CHECKING([whether device_create() is available])
-       SPL_CHECK_SYMBOL_EXPORT([device_create], [drivers/base/core.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_DEVICE_CREATE, 1,
-                         [device_create() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.27 API change,
-dnl # device_create() uses 5 args, new 'drvdata' argument.
+dnl # 3.9 API change
+dnl # set_fs_pwd takes const struct path *
 dnl #
-AC_DEFUN([SPL_AC_5ARGS_DEVICE_CREATE], [
-       AC_MSG_CHECKING([whether device_create() wants 5 args])
+AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
        tmp_flags="$EXTRA_KCFLAGS"
        EXTRA_KCFLAGS="-Werror"
+       [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
        SPL_LINUX_TRY_COMPILE([
-               #include <linux/device.h>
+               #include <linux/spinlock.h>
+               #include <linux/fs_struct.h>
+               #include <linux/path.h>
+               void (*const set_fs_pwd_func)
+                       (struct fs_struct *, const struct path *)
+                       = set_fs_pwd;
        ],[
-               device_create(NULL, NULL, 0, NULL, "%d", 1);
+               return 0;
        ],[
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_5ARGS_DEVICE_CREATE, 1,
-                         [device_create wants 5 args])
+               AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
+                       [set_fs_pwd() needs const path *])
        ],[
-               AC_MSG_RESULT(no)
+               SPL_LINUX_TRY_COMPILE([
+                       #include <linux/spinlock.h>
+                       #include <linux/fs_struct.h>
+                       #include <linux/path.h>
+                       void (*const set_fs_pwd_func)
+                               (struct fs_struct *, struct path *)
+                               = set_fs_pwd;
+               ],[
+                       return 0;
+               ],[
+                       AC_MSG_RESULT(no)
+               ],[
+                       AC_MSG_ERROR(unknown)
+               ])
        ])
        EXTRA_KCFLAGS="$tmp_flags"
 ])
 
 dnl #
-dnl # 2.6.13 API change, check whether class_device_create() is available.
-dnl # Class_device_create() was introduced in 2.6.13 and depricated
-dnl # class_simple_device_add() which was fully removed in 2.6.13.
-dnl #
-AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE],
-       [AC_MSG_CHECKING([whether class_device_create() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/device.h>
-       ], [
-               class_device_create(NULL, NULL, 0, NULL, NULL);
-       ], [class_device_create], [drivers/base/class.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
-                         [class_device_create() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.26 API change, set_normalized_timespec() is exported.
+dnl # 2.6.36 API change,
+dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
+dnl # a spinlock_t to improve the fastpath performance.
 dnl #
-AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT],
-       [AC_MSG_CHECKING([whether set_normalized_timespec() is available as export])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/time.h>
-       ], [
-               set_normalized_timespec(NULL, 0, 0);
-       ], [set_normalized_timespec], [kernel/time.c], [
+AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
+       AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/sched.h>
+               #include <linux/fs_struct.h>
+       ],[
+               static struct fs_struct fs;
+               spin_lock_init(&fs.lock);
+       ],[
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
-                         [set_normalized_timespec() is available as export])
-       ], [
+               AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
+                         [struct fs_struct uses spinlock_t])
+       ],[
                AC_MSG_RESULT(no)
        ])
+       EXTRA_KCFLAGS="$tmp_flags"
 ])
 
 dnl #
-dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
-dnl # previously it was available in time.h as an inline.
+dnl # User namespaces, use kuid_t in place of uid_t
+dnl # where available. Not strictly a user namespaces thing
+dnl # but it should prevent surprises
 dnl #
-AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
-       AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
+AC_DEFUN([SPL_AC_KUIDGID_T], [
+       AC_MSG_CHECKING([whether kuid_t/kgid_t is available])
        SPL_LINUX_TRY_COMPILE([
-               #include <linux/time.h>
-               void set_normalized_timespec(struct timespec *ts,
-                                            time_t sec, long nsec) { }
-       ],
-       [],
-       [
-               AC_MSG_RESULT(no)
+               #include <linux/uidgid.h>
+       ], [
+               kuid_t userid = KUIDT_INIT(0);
+               kgid_t groupid = KGIDT_INIT(0);
        ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
-                         [set_normalized_timespec() is available as inline])
+               SPL_LINUX_TRY_COMPILE([
+                       #include <linux/uidgid.h>
+               ], [
+                       kuid_t userid = 0;
+                       kgid_t groupid = 0;
+               ],[
+                       AC_MSG_RESULT(yes; optional)
+               ],[
+                       AC_MSG_RESULT(yes; mandatory)
+                       AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use])
+               ])
+       ],[
+               AC_MSG_RESULT(no)
        ])
 ])
 
 dnl #
-dnl # 2.6.18 API change,
-dnl # timespec_sub() inline function available in linux/time.h
+dnl # 2.6.35 API change,
+dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
 dnl #
-AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
-       AC_MSG_CHECKING([whether timespec_sub() is available])
+AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
+       AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
        SPL_LINUX_TRY_COMPILE([
-               #include <linux/time.h>
+               #include <linux/fs.h>
        ],[
-               struct timespec a = { 0 };
-               struct timespec b = { 0 };
-               struct timespec c __attribute__ ((unused));
-               c = timespec_sub(a, b);
+               vfs_fsync(NULL, 0);
        ],[
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
+               AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
        ],[
                AC_MSG_RESULT(no)
        ])
 ])
 
 dnl #
-dnl # 2.6.19 API change,
-dnl # check if init_utsname() is available in linux/utsname.h
+dnl # 3.5 API change,
+dnl # inode_operations.truncate_range removed
 dnl #
-AC_DEFUN([SPL_AC_INIT_UTSNAME], [
-       AC_MSG_CHECKING([whether init_utsname() is available])
+AC_DEFUN([SPL_AC_INODE_TRUNCATE_RANGE], [
+       AC_MSG_CHECKING([whether truncate_range() inode operation is available])
        SPL_LINUX_TRY_COMPILE([
-               #include <linux/utsname.h>
+               #include <linux/fs.h>
        ],[
-               struct new_utsname *a __attribute__ ((unused));
-               a = init_utsname();
+               struct inode_operations ops;
+               ops.truncate_range = NULL;
        ],[
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
+               AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1,
+                       [truncate_range() inode operation is available])
        ],[
                AC_MSG_RESULT(no)
        ])
 ])
 
 dnl #
-dnl # 2.6.18 API change,
-dnl # added linux/uaccess.h
-dnl #
-AC_DEFUN([SPL_AC_UACCESS_HEADER], [
-       SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
-])
-
-dnl #
-dnl # 2.6.12 API change,
-dnl # check whether 'kmalloc_node()' is available.
+dnl # Linux 2.6.38 - 3.x API
 dnl #
-AC_DEFUN([SPL_AC_KMALLOC_NODE], [
-       AC_MSG_CHECKING([whether kmalloc_node() is available])
+AC_DEFUN([SPL_AC_KERNEL_FILE_FALLOCATE], [
+       AC_MSG_CHECKING([whether fops->fallocate() exists])
        SPL_LINUX_TRY_COMPILE([
-               #include <linux/slab.h>
+               #include <linux/fs.h>
        ],[
-               void *a __attribute__ ((unused));
-               a = kmalloc_node(1, GFP_KERNEL, 0);
+               long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
+               struct file_operations fops __attribute__ ((unused)) = {
+                       .fallocate = fallocate,
+               };
        ],[
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
+               AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
        ],[
                AC_MSG_RESULT(no)
        ])
 ])
 
 dnl #
-dnl # 2.6.9 API change,
-dnl # check whether 'monotonic_clock()' is available it may
-dnl # be available for some archs but not others.
-dnl #
-AC_DEFUN([SPL_AC_MONOTONIC_CLOCK],
-       [AC_MSG_CHECKING([whether monotonic_clock() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/timex.h>
-       ], [
-               monotonic_clock();
-       ], [monotonic_clock], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
-                         [monotonic_clock() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.16 API change,
-dnl # check whether 'struct inode' has i_mutex
+dnl # Linux 2.6.x - 2.6.37 API
 dnl #
-AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
-       AC_MSG_CHECKING([whether struct inode has i_mutex])
+AC_DEFUN([SPL_AC_KERNEL_INODE_FALLOCATE], [
+       AC_MSG_CHECKING([whether iops->fallocate() exists])
        SPL_LINUX_TRY_COMPILE([
                #include <linux/fs.h>
-               #include <linux/mutex.h>
        ],[
-               struct inode i;
-               mutex_init(&i.i_mutex);
+               long (*fallocate) (struct inode *, int, loff_t, loff_t) = NULL;
+               struct inode_operations fops __attribute__ ((unused)) = {
+                       .fallocate = fallocate,
+               };
        ],[
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
+               AC_DEFINE(HAVE_INODE_FALLOCATE, 1, [fops->fallocate() exists])
        ],[
                AC_MSG_RESULT(no)
        ])
 ])
 
 dnl #
-dnl # 2.6.29 API change,
-dnl # Adaptive mutexs introduced.
+dnl # PaX Linux 2.6.38 - 3.x API
 dnl #
-AC_DEFUN([SPL_AC_MUTEX_OWNER], [
-       AC_MSG_CHECKING([whether struct mutex has owner])
+AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [
+       AC_MSG_CHECKING([whether fops->fallocate() exists])
        SPL_LINUX_TRY_COMPILE([
-               #include <linux/mutex.h>
+               #include <linux/fs.h>
        ],[
-               struct mutex mtx __attribute__ ((unused));
-               mtx.owner = NULL;
+               long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
+               struct file_operations_no_const fops __attribute__ ((unused)) = {
+                       .fallocate = fallocate,
+               };
        ],[
                AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
+               AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
        ],[
                AC_MSG_RESULT(no)
        ])
 ])
 
 dnl #
-dnl # 2.6.39 API change,
-dnl # Owner type change.  A Linux mutex prior to 2.6.39 would store
-dnl # the owner as a thread_info pointer when CONFIG_DEBUG_MUTEXES
-dnl # was defined.  As of 2.6.39 this was changed to a task_struct
-dnl # pointer which frankly makes a lot more sense.
+dnl # The fallocate callback was moved from the inode_operations
+dnl # structure to the file_operations structure.
 dnl #
-AC_DEFUN([SPL_AC_MUTEX_OWNER_TASK_STRUCT], [
-       AC_MSG_CHECKING([whether struct mutex owner is a task_struct])
-       tmp_flags="$EXTRA_KCFLAGS"
-       EXTRA_KCFLAGS="-Werror"
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mutex.h>
-               #include <linux/sched.h>
-       ],[
-               struct mutex mtx __attribute__ ((unused));
-               mtx.owner = current;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_MUTEX_OWNER_TASK_STRUCT, 1,
-               [struct mutex owner is a task_struct])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-       EXTRA_KCFLAGS="$tmp_flags"
-])
-
-dnl #
-dnl # 2.6.18 API change,
-dnl # First introduced 'mutex_lock_nested()' in include/linux/mutex.h,
-dnl # as part of the mutex validator.  Fallback to using 'mutex_lock()' 
-dnl # if the mutex validator is disabled or otherwise unavailable.
-dnl #
-AC_DEFUN([SPL_AC_MUTEX_LOCK_NESTED], [
-       AC_MSG_CHECKING([whether mutex_lock_nested() is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mutex.h>
-       ],[
-               struct mutex mutex;
-               mutex_init(&mutex);
-               mutex_lock_nested(&mutex, 0);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_MUTEX_LOCK_NESTED, 1,
-               [mutex_lock_nested() is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.27 API change,
-dnl # on_each_cpu() uses 3 args, no 'retry' argument
-dnl #
-AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
-       AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/interrupt.h>
-               #include <linux/smp.h>
-
-               void on_each_cpu_func(void *data) { return; }
-       ],[
-               on_each_cpu(on_each_cpu_func, NULL, 0);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
-                         [on_each_cpu wants 3 args])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.18 API change,
-dnl # kallsyms_lookup_name no longer exported
-dnl #
-AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME],
-       [AC_MSG_CHECKING([whether kallsyms_lookup_name() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/kallsyms.h>
-       ], [
-               kallsyms_lookup_name(NULL);
-       ], [kallsyms_lookup_name], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
-                         [kallsyms_lookup_name() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Proposed API change,
-dnl # This symbol is not available in stock kernels.  You may build a
-dnl # custom kernel with the *-spl-export-symbols.patch which will export
-dnl # these symbols for use.  If your already rolling a custom kernel for
-dnl # your environment this is recommended.
-dnl #
-AC_DEFUN([SPL_AC_GET_VMALLOC_INFO],
-       [AC_MSG_CHECKING([whether get_vmalloc_info() is available])
-       SPL_CHECK_SYMBOL_EXPORT([get_vmalloc_info], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
-                         [get_vmalloc_info() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 3.10 API change,
-dnl # struct vmalloc_info is now declared in linux/vmalloc.h
-dnl #
-AC_DEFUN([SPL_AC_VMALLOC_INFO], [
-       AC_MSG_CHECKING([whether struct vmalloc_info is declared])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/vmalloc.h>
-               struct vmalloc_info { void *a; };
-       ],[
-               return 0;
-       ],[
-               AC_MSG_RESULT(no)
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_VMALLOC_INFO, 1, [yes])
-       ])
-])
-
-dnl #
-dnl # 3.10 API change,
-dnl # PDE is replaced by PDE_DATA
-dnl #
-AC_DEFUN([SPL_AC_PDE_DATA], [
-       AC_MSG_CHECKING([whether PDE_DATA() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/proc_fs.h>
-       ], [
-               PDE_DATA(NULL);
-       ], [PDE_DATA], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_PDE_DATA, 1, [yes])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.17 API change
-dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
-dnl # next_zone() are introduced to simplify for_each_zone().  These symbols
-dnl # were exported in 2.6.17 for use by modules which was consistent with
-dnl # the previous implementation of for_each_zone().  From 2.6.18 - 2.6.19
-dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
-dnl # were dropped entirely leaving modules no way to directly iterate over
-dnl # the zone list.  Because we need access to the zone helpers we check
-dnl # if the kernel contains the old or new implementation.  Then we check
-dnl # to see if the symbols we need for each version are available.  If they
-dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
-dnl #
-AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
-       AC_MSG_CHECKING([whether symbol *_pgdat exist])
-       grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
-       rc=$?
-       if test $rc -eq 0; then
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are available])
-       else
-               AC_MSG_RESULT([no])
-       fi
-])
-
-dnl #
-dnl # Proposed API change,
-dnl # This symbol is not available in stock kernels.  You may build a
-dnl # custom kernel with the *-spl-export-symbols.patch which will export
-dnl # these symbols for use.  If your already rolling a custom kernel for
-dnl # your environment this is recommended.
-dnl #
-AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT],
-       [AC_MSG_CHECKING([whether first_online_pgdat() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/mmzone.h>
-       ], [
-               first_online_pgdat();
-       ], [first_online_pgdat], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
-                         [first_online_pgdat() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Proposed API change,
-dnl # This symbol is not available in stock kernels.  You may build a
-dnl # custom kernel with the *-spl-export-symbols.patch which will export
-dnl # these symbols for use.  If your already rolling a custom kernel for
-dnl # your environment this is recommended.
-dnl #
-AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT],
-       [AC_MSG_CHECKING([whether next_online_pgdat() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/mmzone.h>
-       ], [
-               next_online_pgdat(NULL);
-       ], [next_online_pgdat], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
-                         [next_online_pgdat() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Proposed API change,
-dnl # This symbol is not available in stock kernels.  You may build a
-dnl # custom kernel with the *-spl-export-symbols.patch which will export
-dnl # these symbols for use.  If your already rolling a custom kernel for
-dnl # your environment this is recommended.
-dnl #
-AC_DEFUN([SPL_AC_NEXT_ZONE],
-       [AC_MSG_CHECKING([whether next_zone() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/mmzone.h>
-       ], [
-               next_zone(NULL);
-       ], [next_zone], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_NEXT_ZONE, 1, [next_zone() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.17 API change,
-dnl # See SPL_AC_PGDAT_HELPERS for details.
-dnl #
-AC_DEFUN([SPL_AC_PGDAT_LIST],
-       [AC_MSG_CHECKING([whether pgdat_list is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/topology.h>
-               pg_data_t *tmp = pgdat_list;
-       ], [], [pgdat_list], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_PGDAT_LIST, 1, [pgdat_list is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.18 API change,
-dnl # First introduced global_page_state() support as an inline.
-dnl #
-AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
-       AC_MSG_CHECKING([whether global_page_state() is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               unsigned long state __attribute__ ((unused));
-               state = global_page_state(0);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
-                         [global_page_state() is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.21 API change (plus subsequent naming convention changes),
-dnl # Public global zone stats now include a free page count.  However
-dnl # the enumerated names of the counters have changed since this API
-dnl # was introduced.  We need to deduce the corrent name to use.  This
-dnl # replaces the priviate get_zone_counts() interface.
-dnl #
-dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
-dnl # is 2.6.30 as of when this was written.
-dnl #
-AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
-       AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               enum zone_stat_item zsi __attribute__ ((unused));
-               zsi = NR_FREE_PAGES;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
-                         [Page state NR_FREE_PAGES is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.21 API change (plus subsequent naming convention changes),
-dnl # Public global zone stats now include an inactive page count.  However
-dnl # the enumerated names of the counters have changed since this API
-dnl # was introduced.  We need to deduce the corrent name to use.  This
-dnl # replaces the priviate get_zone_counts() interface.
-dnl #
-dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
-dnl # anonymous and file inactive pages.  As of 2.6.28 it was split in
-dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
-dnl #
-AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
-       AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               enum zone_stat_item zsi __attribute__ ((unused));
-               zsi = NR_INACTIVE;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
-                         [Page state NR_INACTIVE is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-
-       AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               enum zone_stat_item zsi __attribute__ ((unused));
-               zsi = NR_INACTIVE_ANON;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
-                         [Page state NR_INACTIVE_ANON is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-
-       AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               enum zone_stat_item zsi __attribute__ ((unused));
-               zsi = NR_INACTIVE_FILE;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
-                         [Page state NR_INACTIVE_FILE is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.21 API change (plus subsequent naming convention changes),
-dnl # Public global zone stats now include an active page count.  However
-dnl # the enumerated names of the counters have changed since this API
-dnl # was introduced.  We need to deduce the corrent name to use.  This
-dnl # replaces the priviate get_zone_counts() interface.
-dnl #
-dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
-dnl # anonymous and file active pages.  As of 2.6.28 it was split in
-dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
-dnl #
-AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
-       AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               enum zone_stat_item zsi __attribute__ ((unused));
-               zsi = NR_ACTIVE;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
-                         [Page state NR_ACTIVE is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-
-       AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               enum zone_stat_item zsi __attribute__ ((unused));
-               zsi = NR_ACTIVE_ANON;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
-                         [Page state NR_ACTIVE_ANON is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-
-       AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/mm.h>
-       ],[
-               enum zone_stat_item zsi __attribute__ ((unused));
-               zsi = NR_ACTIVE_FILE;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
-                         [Page state NR_ACTIVE_FILE is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Proposed API change for legacy kernels.
-dnl # This symbol is not available in older kernels.  For kernels post
-dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
-dnl # page state information.  This symbol is only used in legacy kernels
-dnl # any only as a last resort.
-dnl
-AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
-       AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
-       SPL_LINUX_TRY_COMPILE([
-       ],[
-               #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
-               #error "global_page_state needs NR_FREE_PAGES"
-               #endif
-
-               #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
-                   !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
-                   !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
-               #error "global_page_state needs NR_ACTIVE*"
-               #endif
-
-               #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
-                   !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
-                   !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
-               #error "global_page_state needs NR_INACTIVE*"
-               #endif
-       ],[
-               AC_MSG_RESULT(no)
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
-                         [get_zone_counts() is needed])
-
-               AC_MSG_CHECKING([whether get_zone_counts() is available])
-               SPL_LINUX_TRY_COMPILE_SYMBOL([
-                       #include <linux/mmzone.h>
-               ], [
-                       get_zone_counts(NULL, NULL, NULL);
-               ], [get_zone_counts], [], [
-                       AC_MSG_RESULT(yes)
-                       AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
-                                 [get_zone_counts() is available])
-               ], [
-                       AC_MSG_RESULT(no)
-               ])
-       ])
-])
-
-dnl #
-dnl # 2.6.27 API change,
-dnl # The user_path_dir() replaces __user_walk()
-dnl #
-AC_DEFUN([SPL_AC_USER_PATH_DIR],
-       [AC_MSG_CHECKING([whether user_path_dir() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/fcntl.h>
-               #include <linux/namei.h>
-       ], [
-               user_path_dir(NULL, NULL);
-       ], [user_path_at], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_USER_PATH_DIR, 1, [user_path_dir() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Symbol available in RHEL kernels not in stock kernels.
-dnl #
-AC_DEFUN([SPL_AC_SET_FS_PWD],
-       [AC_MSG_CHECKING([whether set_fs_pwd() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/spinlock.h>
-               #include <linux/fs_struct.h>
-       ], [
-               (void) set_fs_pwd;
-       ], [set_fs_pwd], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SET_FS_PWD, 1, [set_fs_pwd() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 3.9 API change
-dnl # set_fs_pwd takes const struct path *
-dnl #
-AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
-       tmp_flags="$EXTRA_KCFLAGS"
-       EXTRA_KCFLAGS="-Werror"
-       [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/spinlock.h>
-               #include <linux/fs_struct.h>
-               #include <linux/path.h>
-               void (*const set_fs_pwd_func)
-                       (struct fs_struct *, const struct path *)
-                       = set_fs_pwd;
-       ],[
-               return 0;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
-                       [set_fs_pwd() needs const path *])
-       ],[
-               SPL_LINUX_TRY_COMPILE([
-                       #include <linux/spinlock.h>
-                       #include <linux/fs_struct.h>
-                       #include <linux/path.h>
-                       void (*const set_fs_pwd_func)
-                               (struct fs_struct *, struct path *)
-                               = set_fs_pwd;
-               ],[
-                       return 0;
-               ],[
-                       AC_MSG_RESULT(no)
-               ],[
-                       AC_MSG_ERROR(unknown)
-               ])
-       ])
-       EXTRA_KCFLAGS="$tmp_flags"
-])
-
-AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
-       [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
-                         [vfs_unlink() wants 2 args])
-       ],[
-               AC_MSG_RESULT(no)
-               dnl #
-               dnl # Linux 3.13 API change
-               dnl # Added delegated inode
-               dnl #
-               AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
-               SPL_LINUX_TRY_COMPILE([
-                       #include <linux/fs.h>
-               ],[
-                       vfs_unlink((struct inode *) NULL,
-                               (struct dentry *) NULL,
-                               (struct inode **) NULL);
-               ],[
-                       AC_MSG_RESULT(yes)
-                       AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
-                                 [vfs_unlink() wants 3 args])
-               ],[
-                       AC_MSG_ERROR(no)
-               ])
-
-       ])
-])
-
-AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
-       [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
-                       (struct inode *) NULL, (struct dentry *) NULL);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
-                         [vfs_rename() wants 4 args])
-       ],[
-               AC_MSG_RESULT(no)
-               dnl #
-               dnl # Linux 3.13 API change
-               dnl # Added delegated inode
-               dnl #
-               AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
-               SPL_LINUX_TRY_COMPILE([
-                       #include <linux/fs.h>
-               ],[
-                       vfs_rename((struct inode *) NULL,
-                               (struct dentry *) NULL,
-                               (struct inode *) NULL,
-                               (struct dentry *) NULL,
-                               (struct inode **) NULL);
-               ],[
-                       AC_MSG_RESULT(yes)
-                       AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
-                                 [vfs_rename() wants 5 args])
-               ],[
-                       AC_MSG_RESULT(no)
-                       dnl #
-                       dnl # Linux 3.15 API change
-                       dnl # Added flags
-                       dnl #
-                       AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
-                       SPL_LINUX_TRY_COMPILE([
-                               #include <linux/fs.h>
-                       ],[
-                               vfs_rename((struct inode *) NULL,
-                                       (struct dentry *) NULL,
-                                       (struct inode *) NULL,
-                                       (struct dentry *) NULL,
-                                       (struct inode **) NULL,
-                                       (unsigned int) 0);
-                       ],[
-                               AC_MSG_RESULT(yes)
-                               AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
-                                         [vfs_rename() wants 6 args])
-                       ],[
-                               AC_MSG_ERROR(no)
-                       ])
-               ])
-       ])
-])
-
-dnl #
-dnl # 2.6.36 API change,
-dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
-dnl # a spinlock_t to improve the fastpath performance.
-dnl #
-AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
-       AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
-       tmp_flags="$EXTRA_KCFLAGS"
-       EXTRA_KCFLAGS="-Werror"
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/sched.h>
-               #include <linux/fs_struct.h>
-       ],[
-               struct fs_struct fs;
-               spin_lock_init(&fs.lock);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
-                         [struct fs_struct uses spinlock_t])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-       EXTRA_KCFLAGS="$tmp_flags"
-])
-
-dnl #
-dnl # 2.6.29 API change,
-dnl # check whether 'struct cred' exists
-dnl #
-AC_DEFUN([SPL_AC_CRED_STRUCT], [
-       AC_MSG_CHECKING([whether struct cred exists])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/cred.h>
-       ],[
-               struct cred *cr __attribute__ ((unused));
-               cr  = NULL;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-
-dnl #
-dnl # User namespaces, use kuid_t in place of uid_t
-dnl # where available. Not strictly a user namespaces thing
-dnl # but it should prevent surprises
-dnl #
-AC_DEFUN([SPL_AC_KUIDGID_T], [
-       AC_MSG_CHECKING([whether kuid_t/kgid_t is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/uidgid.h>
-       ], [
-               kuid_t userid = KUIDT_INIT(0);
-               kgid_t groupid = KGIDT_INIT(0);
-       ],[
-               SPL_LINUX_TRY_COMPILE([
-                       #include <linux/uidgid.h>
-               ], [
-                       kuid_t userid = 0;
-                       kgid_t groupid = 0;
-               ],[
-                       AC_MSG_RESULT(yes; optional)
-               ],[
-                       AC_MSG_RESULT(yes; mandatory)
-                       AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use])
-               ])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Custom SPL patch may export this symbol.
-dnl #
-AC_DEFUN([SPL_AC_GROUPS_SEARCH],
-       [AC_MSG_CHECKING([whether groups_search() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/cred.h>
-               #ifdef HAVE_KUIDGID_T
-               #include <linux/uidgid.h>
-               #endif
-       ], [
-               #ifdef HAVE_KUIDGID_T
-               groups_search(NULL, KGIDT_INIT(0));
-               #else
-               groups_search(NULL, 0);
-               #endif
-       ], [groups_search], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_GROUPS_SEARCH, 1, [groups_search() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.x API change,
-dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
-dnl #
-AC_DEFUN([SPL_AC_PUT_TASK_STRUCT],
-       [AC_MSG_CHECKING([whether __put_task_struct() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/sched.h>
-       ], [
-               __put_task_struct(NULL);
-       ], [__put_task_struct], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
-                         [__put_task_struct() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.32 API change,
-dnl # Unused 'struct file *' removed from prototype.
-dnl #
-AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
-       AC_MSG_CHECKING([whether proc_handler() wants 5 args])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/sysctl.h>
-       ],[
-               proc_dostring(NULL, 0, NULL, NULL, NULL);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
-                         [proc_handler() wants 5 args])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.x API change,
-dnl # kvasprintf() function added.
-dnl #
-AC_DEFUN([SPL_AC_KVASPRINTF],
-       [AC_MSG_CHECKING([whether kvasprintf() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/kernel.h>
-       ], [
-               kvasprintf(0, NULL, *((va_list*)NULL));
-       ], [kvasprintf], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_KVASPRINTF, 1, [kvasprintf() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.29 API change,
-dnl # vfs_fsync() funcation added, prior to this use file_fsync().
-dnl #
-AC_DEFUN([SPL_AC_VFS_FSYNC],
-       [AC_MSG_CHECKING([whether vfs_fsync() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/fs.h>
-       ], [
-               (void) vfs_fsync;
-       ], [vfs_fsync], [fs/sync.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_VFS_FSYNC, 1, [vfs_fsync() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.35 API change,
-dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
-dnl #
-AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
-       AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               vfs_fsync(NULL, 0);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 3.5 API change,
-dnl # inode_operations.truncate_range removed
-dnl #
-AC_DEFUN([SPL_AC_INODE_TRUNCATE_RANGE], [
-       AC_MSG_CHECKING([whether truncate_range() inode operation is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               struct inode_operations ops;
-               ops.truncate_range = NULL;
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1,
-                       [truncate_range() inode operation is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Linux 2.6.38 - 3.x API
-dnl #
-AC_DEFUN([SPL_AC_KERNEL_FILE_FALLOCATE], [
-       AC_MSG_CHECKING([whether fops->fallocate() exists])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
-               struct file_operations fops __attribute__ ((unused)) = {
-                       .fallocate = fallocate,
-               };
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # Linux 2.6.x - 2.6.37 API
-dnl #
-AC_DEFUN([SPL_AC_KERNEL_INODE_FALLOCATE], [
-       AC_MSG_CHECKING([whether iops->fallocate() exists])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               long (*fallocate) (struct inode *, int, loff_t, loff_t) = NULL;
-               struct inode_operations fops __attribute__ ((unused)) = {
-                       .fallocate = fallocate,
-               };
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_INODE_FALLOCATE, 1, [fops->fallocate() exists])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # PaX Linux 2.6.38 - 3.x API
-dnl #
-AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [
-       AC_MSG_CHECKING([whether fops->fallocate() exists])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/fs.h>
-       ],[
-               long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
-               struct file_operations_no_const fops __attribute__ ((unused)) = {
-                       .fallocate = fallocate,
-               };
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # The fallocate callback was moved from the inode_operations
-dnl # structure to the file_operations structure.
-dnl #
-AC_DEFUN([SPL_AC_KERNEL_FALLOCATE], [
-       SPL_AC_KERNEL_FILE_FALLOCATE
-       SPL_AC_KERNEL_INODE_FALLOCATE
-       SPL_AC_PAX_KERNEL_FILE_FALLOCATE
-])
-
-dnl #
-dnl # 2.6.33 API change. Also backported in RHEL5 as of 2.6.18-190.el5.
-dnl # Earlier versions of rwsem_is_locked() were inline and had a race
-dnl # condition.  The fixed version is exported as a symbol.  The race
-dnl # condition is fixed by acquiring sem->wait_lock, so we must not
-dnl # call that version while holding sem->wait_lock.
-dnl #
-AC_DEFUN([SPL_AC_EXPORTED_RWSEM_IS_LOCKED],
-       [AC_MSG_CHECKING([whether rwsem_is_locked() acquires sem->wait_lock])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/rwsem.h>
-               int rwsem_is_locked(struct rw_semaphore *sem) { return 0; }
-       ], [], [rwsem_is_locked], [lib/rwsem-spinlock.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(RWSEM_IS_LOCKED_TAKES_WAIT_LOCK, 1,
-                         [rwsem_is_locked() acquires sem->wait_lock])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.xx API compat,
-dnl # There currently exists no exposed API to partially shrink the dcache.
-dnl # The expected mechanism to shrink the cache is a registered shrinker
-dnl # which is called during memory pressure.
-dnl #
-AC_DEFUN([SPL_AC_SHRINK_DCACHE_MEMORY],
-       [AC_MSG_CHECKING([whether shrink_dcache_memory() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/dcache.h>
-       ], [
-               shrink_dcache_memory(0, 0);
-       ], [shrink_dcache_memory], [fs/dcache.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SHRINK_DCACHE_MEMORY, 1,
-                         [shrink_dcache_memory() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.xx API compat,
-dnl # There currently exists no exposed API to partially shrink the icache.
-dnl # The expected mechanism to shrink the cache is a registered shrinker
-dnl # which is called during memory pressure.
-dnl #
-AC_DEFUN([SPL_AC_SHRINK_ICACHE_MEMORY],
-       [AC_MSG_CHECKING([whether shrink_icache_memory() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/dcache.h>
-       ], [
-               shrink_icache_memory(0, 0);
-       ], [shrink_icache_memory], [fs/inode.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SHRINK_ICACHE_MEMORY, 1,
-                         [shrink_icache_memory() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.28 API change
-dnl # The kern_path() function has been introduced. We adopt it as the new way
-dnl # of looking up paths. When it is not available, we emulate it using the
-dnl # older interfaces.
-dnl #
-AC_DEFUN([SPL_AC_KERN_PATH],
-       [AC_MSG_CHECKING([whether kern_path() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/namei.h>
-       ], [
-               int r = kern_path(NULL, 0, NULL);
-       ], [kern_path], [fs/namei.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_KERN_PATH, 1,
-                         [kern_path() is available])
-       ], [
-               AC_MSG_RESULT(no)
-               AC_MSG_CHECKING([whether path_lookup() is available])
-               SPL_LINUX_TRY_COMPILE_SYMBOL([
-                       #include <linux/namei.h>
-               ], [
-                       int r = path_lookup(NULL, 0, NULL);
-               ], [path_lookup], [fs/namei.c], [
-                       AC_MSG_RESULT(yes)
-                       AC_DEFINE(HAVE_KERN_PATH, 1,
-                                 [kern_path() is available])
-               ], [
-                       AC_MSG_RESULT(no)
-                       AC_MSG_ERROR([
-       *** Neither kern_path() nor path_lookup() is available.
-       *** Please file an issue:
-       *** https://github.com/zfsonlinux/spl/issues/new])
-
-               ])
-       ])
-])
-
-dnl #
-dnl # /proc/kallsyms support,
-dnl # Verify the kernel has CONFIG_KALLSYMS support enabled.
-dnl #
-AC_DEFUN([SPL_AC_CONFIG_KALLSYMS], [
-       AC_MSG_CHECKING([whether CONFIG_KALLSYMS is defined])
-       SPL_LINUX_TRY_COMPILE([
-               #if !defined(CONFIG_KALLSYMS)
-               #error CONFIG_KALLSYMS not defined
-               #endif
-       ],[ ],[
-               AC_MSG_RESULT([yes])
-       ],[
-               AC_MSG_RESULT([no])
-               AC_MSG_ERROR([
-       *** This kernel does not include the required kallsyms support.
-       *** Rebuild the kernel with CONFIG_KALLSYMS=y set.])
-       ])
+AC_DEFUN([SPL_AC_KERNEL_FALLOCATE], [
+       SPL_AC_KERNEL_FILE_FALLOCATE
+       SPL_AC_KERNEL_INODE_FALLOCATE
+       SPL_AC_PAX_KERNEL_FILE_FALLOCATE
 ])
 
 dnl #
@@ -2366,6 +1138,26 @@ AC_DEFUN([SPL_AC_CONFIG_ZLIB_DEFLATE], [
        ])
 ])
 
+dnl #
+dnl # config trim unused symbols,
+dnl # Verify the kernel has CONFIG_TRIM_UNUSED_KSYMS DISABLED.
+dnl #
+AC_DEFUN([SPL_AC_CONFIG_TRIM_UNUSED_KSYMS], [
+       AC_MSG_CHECKING([whether CONFIG_TRIM_UNUSED_KSYM is disabled])
+       SPL_LINUX_TRY_COMPILE([
+               #if defined(CONFIG_TRIM_UNUSED_KSYMS)
+               #error CONFIG_TRIM_UNUSED_KSYMS not defined
+               #endif
+       ],[ ],[
+               AC_MSG_RESULT([yes])
+       ],[
+               AC_MSG_RESULT([no])
+               AC_MSG_ERROR([
+       *** This kernel has unused symbols trimming enabled, please disable.
+       *** Rebuild the kernel with CONFIG_TRIM_UNUSED_KSYMS=n set.])
+       ])
+])
+
 dnl #
 dnl # 2.6.39 API compat,
 dnl # The function zlib_deflate_workspacesize() now take 2 arguments.
@@ -2424,7 +1216,8 @@ AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
                #include <linux/rwsem.h>
        ],[
                struct rw_semaphore dummy_semaphore __attribute__ ((unused));
-               raw_spinlock_t dummy_lock __attribute__ ((unused));
+               raw_spinlock_t dummy_lock __attribute__ ((unused)) =
+                   __RAW_SPIN_LOCK_INITIALIZER(dummy_lock);
                dummy_semaphore.wait_lock = dummy_lock;
        ],[
                AC_MSG_RESULT(yes)
@@ -2436,6 +1229,55 @@ AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
        EXTRA_KCFLAGS="$tmp_flags"
 ])
 
+dnl #
+dnl # 3.16 API Change
+dnl #
+dnl # rwsem-spinlock "->activity" changed to "->count"
+dnl #
+AC_DEFUN([SPL_AC_RWSEM_ACTIVITY], [
+       AC_MSG_CHECKING([whether struct rw_semaphore has member activity])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/rwsem.h>
+       ],[
+               struct rw_semaphore dummy_semaphore __attribute__ ((unused));
+               dummy_semaphore.activity = 0;
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_RWSEM_ACTIVITY, 1,
+               [struct rw_semaphore has member activity])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])
+
+dnl #
+dnl # 4.8 API Change
+dnl #
+dnl # rwsem "->count" changed to atomic_long_t type
+dnl #
+AC_DEFUN([SPL_AC_RWSEM_ATOMIC_LONG_COUNT], [
+       AC_MSG_CHECKING(
+       [whether struct rw_semaphore has atomic_long_t member count])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/rwsem.h>
+       ],[
+               DECLARE_RWSEM(dummy_semaphore);
+               (void) atomic_long_read(&dummy_semaphore.count);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_RWSEM_ATOMIC_LONG_COUNT, 1,
+               [struct rw_semaphore has atomic_long_t member count])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])
+
 dnl #
 dnl # 3.9 API change,
 dnl # Moved things from linux/sched.h to linux/sched/rt.h
@@ -2456,33 +1298,84 @@ AC_DEFUN([SPL_AC_SCHED_RT_HEADER],
 ])
 
 dnl #
-dnl # 3.9 API change,
-dnl # vfs_getattr() uses 2 args
-dnl # It takes struct path * instead of struct vfsmount * and struct dentry *
+dnl # 4.11 API change,
+dnl # Moved things from linux/sched.h to linux/sched/signal.h
+dnl #
+AC_DEFUN([SPL_AC_SCHED_SIGNAL_HEADER],
+       [AC_MSG_CHECKING([whether header linux/sched/signal.h exists])
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/sched.h>
+               #include <linux/sched/signal.h>
+       ],[
+               return 0;
+       ],[
+               AC_DEFINE(HAVE_SCHED_SIGNAL_HEADER, 1, [linux/sched/signal.h exists])
+               AC_MSG_RESULT(yes)
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+])
+
+dnl #
+dnl # 4.11 API, a528d35e@torvalds/linux
+dnl # vfs_getattr(const struct path *p, struct kstat *s, u32 m, unsigned int f)
+dnl #
+AC_DEFUN([SPL_AC_4ARGS_VFS_GETATTR], [
+       AC_MSG_CHECKING([whether vfs_getattr() wants 4 args])
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/fs.h>
+       ],[
+               vfs_getattr((const struct path *)NULL,
+                       (struct kstat *)NULL,
+                       (u32)0,
+                       (unsigned int)0);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_4ARGS_VFS_GETATTR, 1,
+                 [vfs_getattr wants 4 args])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+])
+
+dnl #
+dnl # 3.9 API 
+dnl # vfs_getattr(struct path *p, struct kstat *s)
 dnl #
 AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [
-       AC_MSG_CHECKING([whether vfs_getattr() wants])
+       AC_MSG_CHECKING([whether vfs_getattr() wants 2 args])
        SPL_LINUX_TRY_COMPILE([
                #include <linux/fs.h>
        ],[
                vfs_getattr((struct path *) NULL,
                        (struct kstat *)NULL);
        ],[
-               AC_MSG_RESULT(2 args)
+               AC_MSG_RESULT(yes)
                AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1,
-                         [vfs_getattr wants 2 args])
+                         [vfs_getattr wants 2 args])
        ],[
-               SPL_LINUX_TRY_COMPILE([
-                       #include <linux/fs.h>
-               ],[
-                       vfs_getattr((struct vfsmount *)NULL,
-                               (struct dentry *)NULL,
-                               (struct kstat *)NULL);
-               ],[
-                       AC_MSG_RESULT(3 args)
-               ],[
-                       AC_MSG_ERROR(unknown)
-               ])
+               AC_MSG_RESULT(no)
+       ])
+])
+
+dnl #
+dnl # <3.9 API 
+dnl # vfs_getattr(struct vfsmount *v, struct dentry *d, struct kstat *k)
+dnl #
+AC_DEFUN([SPL_AC_3ARGS_VFS_GETATTR], [
+       AC_MSG_CHECKING([whether vfs_getattr() wants 3 args])
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/fs.h>
+       ],[
+               vfs_getattr((struct vfsmount *)NULL,
+                       (struct dentry *)NULL,
+                       (struct kstat *)NULL);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_3ARGS_VFS_GETATTR, 1,
+                 [vfs_getattr wants 3 args])
+       ],[
+               AC_MSG_RESULT(no)
        ])
 ])
 
@@ -2569,3 +1462,229 @@ AC_DEFUN([SPL_AC_WAIT_ON_BIT], [
                AC_MSG_RESULT(no)
        ])
 ])
+
+dnl #
+dnl # 4.7 API change
+dnl # i_mutex is changed to i_rwsem. Instead of directly using
+dnl # i_mutex/i_rwsem, we should use inode_lock() and inode_lock_shared()
+dnl # We test inode_lock_shared because inode_lock is introduced earlier.
+dnl #
+AC_DEFUN([SPL_AC_INODE_LOCK], [
+       AC_MSG_CHECKING([whether inode_lock_shared() exists])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/fs.h>
+       ],[
+               struct inode *inode = NULL;
+               inode_lock_shared(inode);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_INODE_LOCK_SHARED, 1, [yes])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])
+
+dnl #
+dnl # 4.9 API change
+dnl # group_info changed from 2d array via >blocks to 1d array via ->gid
+dnl #
+AC_DEFUN([SPL_AC_GROUP_INFO_GID], [
+       AC_MSG_CHECKING([whether group_info->gid exists])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/cred.h>
+       ],[
+               struct group_info *gi = groups_alloc(1);
+               gi->gid[0] = KGIDT_INIT(0);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_GROUP_INFO_GID, 1, [group_info->gid exists])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])
+
+dnl #
+dnl # grsecurity API change,
+dnl # kmem_cache_create() with SLAB_USERCOPY flag replaced by
+dnl # kmem_cache_create_usercopy().
+dnl #
+AC_DEFUN([SPL_AC_KMEM_CACHE_CREATE_USERCOPY], [
+       AC_MSG_CHECKING([whether kmem_cache_create_usercopy() exists])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/slab.h>
+               static void ctor(void *foo)
+               {
+                       // fake ctor
+               }
+       ],[
+               struct kmem_cache *skc_linux_cache;
+               const char *name = "test";
+               size_t size = 4096;
+               size_t align = 8;
+               unsigned long flags = 0;
+               size_t useroffset = 0;
+               size_t usersize = size - useroffset;
+
+               skc_linux_cache = kmem_cache_create_usercopy(
+                       name, size, align, flags, useroffset, usersize, ctor);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_KMEM_CACHE_CREATE_USERCOPY, 1,
+                               [kmem_cache_create_usercopy() exists])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])
+
+dnl #
+dnl # 4.13 API change
+dnl # Renamed struct wait_queue -> struct wait_queue_entry.
+dnl #
+AC_DEFUN([SPL_AC_WAIT_QUEUE_ENTRY_T], [
+       AC_MSG_CHECKING([whether wait_queue_entry_t exists])
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/wait.h>
+       ],[
+               wait_queue_entry_t *entry __attribute__ ((unused));
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_WAIT_QUEUE_ENTRY_T, 1,
+                   [wait_queue_entry_t exists])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+])
+
+dnl #
+dnl # 4.13 API change
+dnl # Renamed wait_queue_head::task_list -> wait_queue_head::head
+dnl # Renamed wait_queue_entry::task_list -> wait_queue_entry::entry
+dnl #
+AC_DEFUN([SPL_AC_WAIT_QUEUE_HEAD_ENTRY], [
+       AC_MSG_CHECKING([whether wq_head->head and wq_entry->entry exist])
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/wait.h>
+
+               #ifdef HAVE_WAIT_QUEUE_ENTRY_T
+               typedef wait_queue_head_t       spl_wait_queue_head_t;
+               typedef wait_queue_entry_t      spl_wait_queue_entry_t;
+               #else
+               typedef wait_queue_head_t       spl_wait_queue_head_t;
+               typedef wait_queue_t            spl_wait_queue_entry_t;
+               #endif
+       ],[
+               spl_wait_queue_head_t wq_head;
+               spl_wait_queue_entry_t wq_entry;
+               struct list_head *head __attribute__ ((unused));
+               struct list_head *entry __attribute__ ((unused));
+
+               head = &wq_head.head;
+               entry = &wq_entry.entry;
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_WAIT_QUEUE_HEAD_ENTRY, 1,
+                   [wq_head->head and wq_entry->entry exist])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+])
+
+dnl #
+dnl # 4.14 API change
+dnl # kernel_write() which was introduced in 3.9 was updated to take
+dnl # the offset as a pointer which is needed by vn_rdwr().
+dnl #
+AC_DEFUN([SPL_AC_KERNEL_WRITE], [
+       AC_MSG_CHECKING([whether kernel_write() takes loff_t pointer])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/fs.h>
+       ],[
+               struct file *file = NULL;
+               const void *buf = NULL;
+               size_t count = 0;
+               loff_t *pos = NULL;
+               ssize_t ret;
+
+               ret = kernel_write(file, buf, count, pos);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_KERNEL_WRITE_PPOS, 1,
+                   [kernel_write() take loff_t pointer])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])
+
+dnl #
+dnl # 4.14 API change
+dnl # kernel_read() which has existed for forever was updated to take
+dnl # the offset as a pointer which is needed by vn_rdwr().
+dnl #
+AC_DEFUN([SPL_AC_KERNEL_READ], [
+       AC_MSG_CHECKING([whether kernel_read() takes loff_t pointer])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/fs.h>
+       ],[
+               struct file *file = NULL;
+               void *buf = NULL;
+               size_t count = 0;
+               loff_t *pos = NULL;
+               ssize_t ret;
+
+               ret = kernel_read(file, buf, count, pos);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_KERNEL_READ_PPOS, 1,
+                   [kernel_read() take loff_t pointer])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])
+
+dnl #
+dnl # 4.15 API change
+dnl # https://lkml.org/lkml/2017/11/25/90
+dnl # Check if timer_list.func get passed a timer_list or an unsigned long
+dnl # (older kernels).  Also sanity check the from_timer() and timer_setup()
+dnl # macros are available as well, since they will be used in the same newer
+dnl # kernels that support the new timer_list.func signature.
+dnl #
+AC_DEFUN([SPL_AC_KERNEL_TIMER_FUNCTION_TIMER_LIST], [
+       AC_MSG_CHECKING([whether timer_list.function gets a timer_list])
+       tmp_flags="$EXTRA_KCFLAGS"
+       EXTRA_KCFLAGS="-Werror"
+       SPL_LINUX_TRY_COMPILE([
+               #include <linux/timer.h>
+               void task_expire(struct timer_list *tl) {}
+       ],[
+               #ifndef from_timer
+               #error "No from_timer() macro"
+               #endif
+
+               struct timer_list timer;
+               timer.function = task_expire;
+               timer_setup(&timer, NULL, 0);
+       ],[
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_KERNEL_TIMER_FUNCTION_TIMER_LIST, 1,
+                   [timer_list.function gets a timer_list])
+       ],[
+               AC_MSG_RESULT(no)
+       ])
+       EXTRA_KCFLAGS="$tmp_flags"
+])