1 ###############################################################################
2 # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 # Copyright (C) 2007 The Regents of the University of California.
4 # Written by Brian Behlendorf <behlendorf1@llnl.gov>.
5 ###############################################################################
6 # SPL_AC_CONFIG_KERNEL: Default SPL kernel configuration.
7 ###############################################################################
9 AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
12 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
13 dnl # compiler options are added by the kernel build system.
14 abs_srcdir=`readlink -f ${srcdir}`
15 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes"
16 KERNELCPPFLAGS="$KERNELCPPFLAGS -I${abs_srcdir}/include"
17 KERNELCPPFLAGS="$KERNELCPPFLAGS -include ${abs_srcdir}/spl_config.h"
19 if test "${LINUX_OBJ}" != "${LINUX}"; then
20 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
23 AC_SUBST(KERNELMAKE_PARAMS)
24 AC_SUBST(KERNELCPPFLAGS)
28 SPL_AC_DEBUG_KMEM_TRACKING
29 SPL_AC_ATOMIC_SPINLOCK
30 SPL_AC_TYPE_ATOMIC64_CMPXCHG
31 SPL_AC_TYPE_ATOMIC64_XCHG
33 SPL_AC_3ARGS_INIT_WORK
34 SPL_AC_2ARGS_REGISTER_SYSCTL
36 SPL_AC_PATH_IN_NAMEIDATA
42 SPL_AC_5ARGS_DEVICE_CREATE
43 SPL_AC_CLASS_DEVICE_CREATE
44 SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT
45 SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE
52 SPL_AC_MONOTONIC_CLOCK
55 SPL_AC_MUTEX_LOCK_NESTED
58 SPL_AC_3ARGS_ON_EACH_CPU
59 SPL_AC_KALLSYMS_LOOKUP_NAME
60 SPL_AC_GET_VMALLOC_INFO
62 SPL_AC_FIRST_ONLINE_PGDAT
63 SPL_AC_NEXT_ONLINE_PGDAT
66 SPL_AC_GLOBAL_PAGE_STATE
67 SPL_AC_ZONE_STAT_ITEM_FREE
68 SPL_AC_ZONE_STAT_ITEM_INACTIVE
69 SPL_AC_ZONE_STAT_ITEM_ACTIVE
70 SPL_AC_GET_ZONE_COUNTS
72 SPL_AC_2ARGS_SET_FS_PWD
73 SPL_AC_2ARGS_VFS_UNLINK
74 SPL_AC_4ARGS_VFS_RENAME
77 SPL_AC_PUT_TASK_STRUCT
78 SPL_AC_5ARGS_PROC_HANDLER
82 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
83 modpost=$LINUX/scripts/Makefile.modpost
84 AC_MSG_CHECKING([kernel file name for module symbols])
85 if test -f "$modpost"; then
86 if grep -q Modules.symvers $modpost; then
87 LINUX_SYMBOLS=Modules.symvers
89 LINUX_SYMBOLS=Module.symvers
94 AC_MSG_RESULT($LINUX_SYMBOLS)
95 AC_SUBST(LINUX_SYMBOLS)
98 AC_DEFUN([SPL_AC_KERNEL], [
100 AS_HELP_STRING([--with-linux=PATH],
101 [Path to kernel source]),
102 [kernelsrc="$withval"])
104 AC_ARG_WITH([linux-obj],
105 AS_HELP_STRING([--with-linux-obj=PATH],
106 [Path to kernel build objects]),
107 [kernelbuild="$withval"])
109 AC_MSG_CHECKING([kernel source directory])
110 if test -z "$kernelsrc"; then
111 headersdir="/lib/modules/$(uname -r)/build"
112 if test -e "$headersdir"; then
113 sourcelink=$(readlink -f "$headersdir")
115 sourcelink=$(ls -1d /usr/src/kernels/* \
117 2>/dev/null | grep -v obj | tail -1)
120 if test -e ${sourcelink}; then
121 kernelsrc=`readlink -f ${sourcelink}`
123 AC_MSG_RESULT([Not found])
125 *** Please specify the location of the kernel source
126 *** with the '--with-linux=PATH' option])
129 if test "$kernelsrc" = "NONE"; then
134 AC_MSG_RESULT([$kernelsrc])
135 AC_MSG_CHECKING([kernel build directory])
136 if test -z "$kernelbuild"; then
137 if test -d ${kernelsrc}-obj/`arch`/`arch`; then
138 kernelbuild=${kernelsrc}-obj/`arch`/`arch`
139 elif test -d ${kernelsrc}-obj/`arch`/default; then
140 kernelbuild=${kernelsrc}-obj/`arch`/default
141 elif test -d `dirname ${kernelsrc}`/build-`arch`; then
142 kernelbuild=`dirname ${kernelsrc}`/build-`arch`
144 kernelbuild=${kernelsrc}
147 AC_MSG_RESULT([$kernelbuild])
149 AC_MSG_CHECKING([kernel source version])
150 utsrelease1=$kernelbuild/include/linux/version.h
151 utsrelease2=$kernelbuild/include/linux/utsrelease.h
152 utsrelease3=$kernelbuild/include/generated/utsrelease.h
153 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
154 utsrelease=linux/version.h
155 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
156 utsrelease=linux/utsrelease.h
157 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
158 utsrelease=generated/utsrelease.h
161 if test "$utsrelease"; then
162 kernsrcver=`(echo "#include <$utsrelease>";
163 echo "kernsrcver=UTS_RELEASE") |
164 cpp -I $kernelbuild/include |
165 grep "^kernsrcver=" | cut -d \" -f 2`
167 if test -z "$kernsrcver"; then
168 AC_MSG_RESULT([Not found])
169 AC_MSG_ERROR([*** Cannot determine kernel version.])
172 AC_MSG_RESULT([Not found])
173 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
176 AC_MSG_RESULT([$kernsrcver])
179 LINUX_OBJ=${kernelbuild}
180 LINUX_VERSION=${kernsrcver}
184 AC_SUBST(LINUX_VERSION)
186 SPL_AC_MODULE_SYMVERS
190 dnl # Default SPL user configuration
192 AC_DEFUN([SPL_AC_CONFIG_USER], [])
194 AC_DEFUN([SPL_AC_LICENSE], [
195 AC_MSG_CHECKING([spl license])
197 AC_MSG_RESULT([$LICENSE])
198 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DHAVE_GPL_ONLY_SYMBOLS"
202 AC_DEFUN([SPL_AC_CONFIG], [
204 AC_ARG_WITH([config],
205 AS_HELP_STRING([--with-config=CONFIG],
206 [Config file 'kernel|user|all|srpm']),
207 [SPL_CONFIG="$withval"])
209 AC_MSG_CHECKING([spl config])
210 AC_MSG_RESULT([$SPL_CONFIG]);
213 case "$SPL_CONFIG" in
214 kernel) SPL_AC_CONFIG_KERNEL ;;
215 user) SPL_AC_CONFIG_USER ;;
216 all) SPL_AC_CONFIG_KERNEL
217 SPL_AC_CONFIG_USER ;;
220 AC_MSG_RESULT([Error!])
221 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
222 user kernel|user|all|srpm]) ;;
225 AM_CONDITIONAL([CONFIG_USER],
226 [test "$SPL_CONFIG" = user] ||
227 [test "$SPL_CONFIG" = all])
228 AM_CONDITIONAL([CONFIG_KERNEL],
229 [test "$SPL_CONFIG" = kernel] ||
230 [test "$SPL_CONFIG" = all])
234 dnl # Enable if the SPL should be compiled with internal debugging enabled.
235 dnl # By default this support is disabled.
237 AC_DEFUN([SPL_AC_DEBUG], [
238 AC_MSG_CHECKING([whether debugging is enabled])
239 AC_ARG_ENABLE([debug],
240 [AS_HELP_STRING([--enable-debug],
241 [Enable generic debug support @<:@default=no@:>@])],
245 AS_IF([test "x$enable_debug" = xyes],
247 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
248 DEBUG_CFLAGS="-DDEBUG -Werror"
251 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
252 DEBUG_CFLAGS="-DNDEBUG"
255 AC_SUBST(DEBUG_CFLAGS)
256 AC_MSG_RESULT([$enable_debug])
260 dnl # Enabled by default it provides a minimal level of memory tracking.
261 dnl # A total count of bytes allocated is kept for each alloc and free.
262 dnl # Then at module unload time a report to the console will be printed
263 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
264 dnl # and provide an easy way to inspect the kmem based slab.
266 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
267 AC_ARG_ENABLE([debug-kmem],
268 [AS_HELP_STRING([--enable-debug-kmem],
269 [Enable basic kmem accounting @<:@default=yes@:>@])],
271 [enable_debug_kmem=yes])
273 AS_IF([test "x$enable_debug_kmem" = xyes],
274 [AC_DEFINE([DEBUG_KMEM], [1],
275 [Define to 1 to enable basic kmem accounting])
276 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"])
278 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
279 AC_MSG_RESULT([$enable_debug_kmem])
283 dnl # Disabled by default it provides detailed memory tracking. This
284 dnl # feature also requires --enable-debug-kmem to be set. When enabled
285 dnl # not only will total bytes be tracked but also the location of every
286 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
287 dnl # addresses and where they were allocated will be dumped to the console.
288 dnl # Enabling this feature has a significant impact on performance but it
289 dnl # makes finding memory leaks pretty straight forward.
291 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
292 AC_ARG_ENABLE([debug-kmem-tracking],
293 [AS_HELP_STRING([--enable-debug-kmem-tracking],
294 [Enable detailed kmem tracking @<:@default=no@:>@])],
296 [enable_debug_kmem_tracking=no])
298 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
299 [AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
300 [Define to 1 to enable detailed kmem tracking])
301 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"])
303 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
304 AC_MSG_RESULT([$enable_debug_kmem_tracking])
308 dnl # SPL_LINUX_CONFTEST
310 AC_DEFUN([SPL_LINUX_CONFTEST], [
311 cat >conftest.c <<_ACEOF
317 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
319 m4_define([SPL_LANG_PROGRAM], [
324 dnl Do *not* indent the following line: there may be CPP directives.
325 dnl Don't move the `;' right after for the same reason.
333 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
335 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
336 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
337 rm -Rf build && mkdir -p build
338 echo "obj-m := conftest.o" >build/Makefile
340 [AC_TRY_COMMAND(cp conftest.c build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
342 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
348 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
350 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
351 [SPL_LINUX_COMPILE_IFELSE(
352 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
354 [test -s build/conftest.o],
359 dnl # SPL_LINUX_CONFIG
361 AC_DEFUN([SPL_LINUX_CONFIG],
362 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
363 SPL_LINUX_TRY_COMPILE([
364 #ifndef AUTOCONF_INCLUDED
365 #include <linux/config.h>
369 #error CONFIG_$1 not #defined
381 dnl # SPL_CHECK_SYMBOL_EXPORT
382 dnl # check symbol exported or not
384 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
385 [AC_MSG_CHECKING([whether symbol $1 is exported])
386 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
387 $LINUX_OBJ/Module*.symvers 2>/dev/null
389 if test $rc -ne 0; then
392 grep -q -E "EXPORT_SYMBOL.*($1)" \
393 "$LINUX_OBJ/$file" 2>/dev/null
395 if test $rc -eq 0; then
400 if test $export -eq 0; then
414 dnl # SPL_CHECK_HEADER
415 dnl # check whether header exists and define HAVE_$2_HEADER
417 AC_DEFUN([SPL_CHECK_HEADER],
418 [AC_MSG_CHECKING([whether header $1 exists])
419 SPL_LINUX_TRY_COMPILE([
424 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
434 dnl # Use the atomic implemenation based on global spinlocks. This
435 dnl # should only be needed by 32-bit kernels which do not provide
436 dnl # the atomic64_* API. It may be optionally enabled as a fallback
437 dnl # if problems are observed with the direct mapping to the native
438 dnl # Linux atomic operations. You may not disable atomic spinlocks
439 dnl # if you kernel does not an atomic64_* API.
441 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
442 AC_ARG_ENABLE([atomic-spinlocks],
443 [AS_HELP_STRING([--enable-atomic-spinlocks],
444 [Atomic types use spinlocks @<:@default=check@:>@])],
446 [enable_atomic_spinlocks=check])
448 SPL_LINUX_TRY_COMPILE([
449 #include <asm/atomic.h>
454 AC_DEFINE(HAVE_ATOMIC64_T, 1,
455 [kernel defines atomic64_t])
460 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
461 AS_IF([test "x$have_atomic64_t" = xyes], [
462 enable_atomic_spinlocks=no
464 enable_atomic_spinlocks=yes
468 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
469 AC_DEFINE([ATOMIC_SPINLOCK], [1],
470 [Atomic types use spinlocks])
472 AS_IF([test "x$have_atomic64_t" = xno], [
474 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
478 AC_MSG_CHECKING([whether atomic types use spinlocks])
479 AC_MSG_RESULT([$enable_atomic_spinlocks])
481 AC_MSG_CHECKING([whether kernel defines atomic64_t])
482 AC_MSG_RESULT([$have_atomic64_t])
486 dnl # 2.6.24 API change,
487 dnl # check if atomic64_cmpxchg is defined
489 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG],
490 [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg])
491 SPL_LINUX_TRY_COMPILE([
492 #include <asm/atomic.h>
494 atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
497 AC_DEFINE(HAVE_ATOMIC64_CMPXCHG, 1,
498 [kernel defines atomic64_cmpxchg])
505 dnl # 2.6.24 API change,
506 dnl # check if atomic64_xchg is defined
508 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG],
509 [AC_MSG_CHECKING([whether kernel defines atomic64_xchg])
510 SPL_LINUX_TRY_COMPILE([
511 #include <asm/atomic.h>
513 atomic64_xchg((atomic64_t *)NULL, 0);
516 AC_DEFINE(HAVE_ATOMIC64_XCHG, 1,
517 [kernel defines atomic64_xchg])
524 dnl # 2.6.24 API change,
525 dnl # check if uintptr_t typedef is defined
527 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
528 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
529 SPL_LINUX_TRY_COMPILE([
530 #include <linux/types.h>
535 AC_DEFINE(HAVE_UINTPTR_T, 1,
536 [kernel defines uintptr_t])
543 dnl # 2.6.20 API change,
544 dnl # INIT_WORK use 2 args and not store data inside
546 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
547 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
548 SPL_LINUX_TRY_COMPILE([
549 #include <linux/workqueue.h>
551 struct work_struct work;
552 INIT_WORK(&work, NULL, NULL);
555 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
556 [INIT_WORK wants 3 args])
563 dnl # 2.6.21 API change,
564 dnl # 'register_sysctl_table' use only one argument instead of two
566 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
567 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
568 SPL_LINUX_TRY_COMPILE([
569 #include <linux/sysctl.h>
571 return register_sysctl_table(NULL,0);
574 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
575 [register_sysctl_table() wants 2 args])
582 dnl # 2.6.23 API change
583 dnl # Old set_shrinker API replaced with register_shrinker
585 AC_DEFUN([SPL_AC_SET_SHRINKER], [
586 AC_MSG_CHECKING([whether set_shrinker() available])
587 SPL_LINUX_TRY_COMPILE([
588 #include <linux/mm.h>
590 return set_shrinker(DEFAULT_SEEKS, NULL);
593 AC_DEFINE(HAVE_SET_SHRINKER, 1,
594 [set_shrinker() available])
601 dnl # 2.6.25 API change,
602 dnl # struct path entry added to struct nameidata
604 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
605 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
606 SPL_LINUX_TRY_COMPILE([
607 #include <linux/namei.h>
612 nd.path.dentry = NULL;
615 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
616 [struct path used in struct nameidata])
623 dnl # Custom SPL patch may export this system it is not required
625 AC_DEFUN([SPL_AC_TASK_CURR], [
626 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
627 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
632 dnl # 2.6.19 API change,
633 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
635 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
636 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
637 SPL_LINUX_TRY_COMPILE([
638 #include <linux/sysctl.h>
640 #ifndef CTL_UNNUMBERED
641 #error CTL_UNNUMBERED undefined
645 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
646 [unnumbered sysctl support exists])
653 dnl # 2.6.33 API change,
654 dnl # Removed .ctl_name from struct ctl_table.
656 AC_DEFUN([SPL_AC_CTL_NAME], [
657 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
658 SPL_LINUX_TRY_COMPILE([
659 #include <linux/sysctl.h>
661 struct ctl_table ctl;
665 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
672 dnl # 2.6.16 API change.
673 dnl # Check if 'fls64()' is available
675 AC_DEFUN([SPL_AC_FLS64],
676 [AC_MSG_CHECKING([whether fls64() is available])
677 SPL_LINUX_TRY_COMPILE([
678 #include <linux/bitops.h>
683 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
690 dnl # 2.6.18 API change, check whether device_create() is available.
691 dnl # Device_create() was introduced in 2.6.18 and depricated
692 dnl # class_device_create() which was fully removed in 2.6.26.
694 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
695 SPL_CHECK_SYMBOL_EXPORT(
697 [drivers/base/core.c],
698 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
699 [device_create() is available])],
704 dnl # 2.6.27 API change,
705 dnl # device_create() uses 5 args, new 'drvdata' argument.
707 AC_DEFUN([SPL_AC_5ARGS_DEVICE_CREATE], [
708 AC_MSG_CHECKING([whether device_create() wants 5 args])
709 tmp_flags="$EXTRA_KCFLAGS"
710 EXTRA_KCFLAGS="-Werror"
711 SPL_LINUX_TRY_COMPILE([
712 #include <linux/device.h>
714 device_create(NULL, NULL, 0, NULL, "%d", 1);
717 AC_DEFINE(HAVE_5ARGS_DEVICE_CREATE, 1,
718 [device_create wants 5 args])
722 EXTRA_KCFLAGS="$tmp_flags"
726 dnl # 2.6.13 API change, check whether class_device_create() is available.
727 dnl # Class_device_create() was introduced in 2.6.13 and depricated
728 dnl # class_simple_device_add() which was fully removed in 2.6.13.
730 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
731 SPL_CHECK_SYMBOL_EXPORT(
732 [class_device_create],
733 [drivers/base/class.c],
734 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
735 [class_device_create() is available])],
740 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
742 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
743 SPL_CHECK_SYMBOL_EXPORT(
744 [set_normalized_timespec],
746 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
747 [set_normalized_timespec() is available as export])],
752 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
753 dnl # previously it was available in time.h as an inline.
755 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
756 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
757 SPL_LINUX_TRY_COMPILE([
758 #include <linux/time.h>
759 void set_normalized_timespec(struct timespec *ts,
760 time_t sec, long nsec) { }
767 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
768 [set_normalized_timespec() is available as inline])
773 dnl # 2.6.18 API change,
774 dnl # timespec_sub() inline function available in linux/time.h
776 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
777 AC_MSG_CHECKING([whether timespec_sub() is available])
778 SPL_LINUX_TRY_COMPILE([
779 #include <linux/time.h>
781 struct timespec a, b, c = { 0 };
782 c = timespec_sub(a, b);
785 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
792 dnl # 2.6.19 API change,
793 dnl # check if init_utsname() is available in linux/utsname.h
795 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
796 AC_MSG_CHECKING([whether init_utsname() is available])
797 SPL_LINUX_TRY_COMPILE([
798 #include <linux/utsname.h>
800 struct new_utsname *a = init_utsname();
803 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
810 dnl # 2.6.26 API change,
811 dnl # definition of struct fdtable relocated to linux/fdtable.h
813 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
814 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
818 dnl # 2.6.14 API change,
819 dnl # check whether 'files_fdtable()' exists
821 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
822 AC_MSG_CHECKING([whether files_fdtable() is available])
823 SPL_LINUX_TRY_COMPILE([
824 #include <linux/sched.h>
825 #include <linux/file.h>
826 #ifdef HAVE_FDTABLE_HEADER
827 #include <linux/fdtable.h>
830 struct files_struct *files = current->files;
831 struct fdtable *fdt = files_fdtable(files);
834 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
841 dnl # 2.6.18 API change,
842 dnl # added linux/uaccess.h
844 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
845 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
849 dnl # 2.6.12 API change,
850 dnl # check whether 'kmalloc_node()' is available.
852 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
853 AC_MSG_CHECKING([whether kmalloc_node() is available])
854 SPL_LINUX_TRY_COMPILE([
855 #include <linux/slab.h>
857 void *a = kmalloc_node(1, GFP_KERNEL, 0);
860 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
867 dnl # 2.6.9 API change,
868 dnl # check whether 'monotonic_clock()' is available it may
869 dnl # be available for some archs but not others.
871 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
872 SPL_CHECK_SYMBOL_EXPORT(
875 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
876 [monotonic_clock() is available])],
881 dnl # 2.6.16 API change,
882 dnl # check whether 'struct inode' has i_mutex
884 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
885 AC_MSG_CHECKING([whether struct inode has i_mutex])
886 SPL_LINUX_TRY_COMPILE([
887 #include <linux/fs.h>
888 #include <linux/mutex.h>
891 mutex_init(&i.i_mutex);
894 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
901 dnl # 2.6.29 API change,
902 dnl # Adaptive mutexs introduced.
904 AC_DEFUN([SPL_AC_MUTEX_OWNER], [
905 AC_MSG_CHECKING([whether struct mutex has owner])
906 SPL_LINUX_TRY_COMPILE([
907 #include <linux/mutex.h>
913 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
920 dnl # 2.6.18 API change,
921 dnl # First introduced 'mutex_lock_nested()' in include/linux/mutex.h,
922 dnl # as part of the mutex validator. Fallback to using 'mutex_lock()'
923 dnl # if the mutex validator is disabled or otherwise unavailable.
925 AC_DEFUN([SPL_AC_MUTEX_LOCK_NESTED], [
926 AC_MSG_CHECKING([whether mutex_lock_nested() is available])
927 SPL_LINUX_TRY_COMPILE([
928 #include <linux/mutex.h>
932 mutex_lock_nested(&mutex, 0);
935 AC_DEFINE(HAVE_MUTEX_LOCK_NESTED, 1,
936 [mutex_lock_nested() is available])
943 dnl # 2.6.22 API change,
944 dnl # First introduced 'div64_64()' in lib/div64.c
946 AC_DEFUN([SPL_AC_DIV64_64], [
947 SPL_CHECK_SYMBOL_EXPORT(
950 [AC_DEFINE(HAVE_DIV64_64, 1,
951 [div64_64() is available])],
956 dnl # 2.6.26 API change,
957 dnl # Renamed 'div64_64()' to 'div64_u64' in lib/div64.c
959 AC_DEFUN([SPL_AC_DIV64_U64], [
960 SPL_CHECK_SYMBOL_EXPORT(
963 [AC_DEFINE(HAVE_DIV64_U64, 1,
964 [div64_u64() is available])],
969 dnl # 2.6.27 API change,
970 dnl # on_each_cpu() uses 3 args, no 'retry' argument
972 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
973 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
974 SPL_LINUX_TRY_COMPILE([
975 #include <linux/smp.h>
977 on_each_cpu(NULL, NULL, 0);
980 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
981 [on_each_cpu wants 3 args])
988 dnl # 2.6.18 API change,
989 dnl # kallsyms_lookup_name no longer exported
991 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
992 SPL_CHECK_SYMBOL_EXPORT(
993 [kallsyms_lookup_name],
995 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
996 [kallsyms_lookup_name() is available])],
1001 dnl # Proposed API change,
1002 dnl # This symbol is not available in stock kernels. You may build a
1003 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1004 dnl # these symbols for use. If your already rolling a custom kernel for
1005 dnl # your environment this is recommended.
1007 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
1008 SPL_CHECK_SYMBOL_EXPORT(
1011 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
1012 [get_vmalloc_info() is available])],
1017 dnl # 2.6.17 API change
1018 dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
1019 dnl # next_zone() are introduced to simplify for_each_zone(). These symbols
1020 dnl # were exported in 2.6.17 for use by modules which was consistent with
1021 dnl # the previous implementation of for_each_zone(). From 2.6.18 - 2.6.19
1022 dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
1023 dnl # were dropped entirely leaving modules no way to directly iterate over
1024 dnl # the zone list. Because we need access to the zone helpers we check
1025 dnl # if the kernel contains the old or new implementation. Then we check
1026 dnl # to see if the symbols we need for each version are available. If they
1027 dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
1029 AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
1030 AC_MSG_CHECKING([whether symbol *_pgdat exist])
1031 grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
1033 if test $rc -eq 0; then
1034 AC_MSG_RESULT([yes])
1035 AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are available])
1042 dnl # Proposed API change,
1043 dnl # This symbol is not available in stock kernels. You may build a
1044 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1045 dnl # these symbols for use. If your already rolling a custom kernel for
1046 dnl # your environment this is recommended.
1048 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
1049 SPL_CHECK_SYMBOL_EXPORT(
1050 [first_online_pgdat],
1052 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
1053 [first_online_pgdat() is available])],
1058 dnl # Proposed API change,
1059 dnl # This symbol is not available in stock kernels. You may build a
1060 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1061 dnl # these symbols for use. If your already rolling a custom kernel for
1062 dnl # your environment this is recommended.
1064 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
1065 SPL_CHECK_SYMBOL_EXPORT(
1066 [next_online_pgdat],
1068 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
1069 [next_online_pgdat() is available])],
1074 dnl # Proposed API change,
1075 dnl # This symbol is not available in stock kernels. You may build a
1076 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1077 dnl # these symbols for use. If your already rolling a custom kernel for
1078 dnl # your environment this is recommended.
1080 AC_DEFUN([SPL_AC_NEXT_ZONE], [
1081 SPL_CHECK_SYMBOL_EXPORT(
1084 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
1085 [next_zone() is available])],
1090 dnl # 2.6.17 API change,
1091 dnl # See SPL_AC_PGDAT_HELPERS for details.
1093 AC_DEFUN([SPL_AC_PGDAT_LIST], [
1094 SPL_CHECK_SYMBOL_EXPORT(
1097 [AC_DEFINE(HAVE_PGDAT_LIST, 1,
1098 [pgdat_list is available])],
1103 dnl # 2.6.18 API change,
1104 dnl # First introduced global_page_state() support as an inline.
1106 AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
1107 AC_MSG_CHECKING([whether global_page_state() is available])
1108 SPL_LINUX_TRY_COMPILE([
1109 #include <linux/mm.h>
1111 unsigned long state;
1112 state = global_page_state(0);
1115 AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
1116 [global_page_state() is available])
1123 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1124 dnl # Public global zone stats now include a free page count. However
1125 dnl # the enumerated names of the counters have changed since this API
1126 dnl # was introduced. We need to deduce the corrent name to use. This
1127 dnl # replaces the priviate get_zone_counts() interface.
1129 dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
1130 dnl # is 2.6.30 as of when this was written.
1132 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
1133 AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
1134 SPL_LINUX_TRY_COMPILE([
1135 #include <linux/mm.h>
1137 enum zone_stat_item zsi;
1138 zsi = NR_FREE_PAGES;
1141 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
1142 [Page state NR_FREE_PAGES is available])
1149 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1150 dnl # Public global zone stats now include an inactive page count. However
1151 dnl # the enumerated names of the counters have changed since this API
1152 dnl # was introduced. We need to deduce the corrent name to use. This
1153 dnl # replaces the priviate get_zone_counts() interface.
1155 dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
1156 dnl # anonymous and file inactive pages. As of 2.6.28 it was split in
1157 dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
1159 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
1160 AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
1161 SPL_LINUX_TRY_COMPILE([
1162 #include <linux/mm.h>
1164 enum zone_stat_item zsi;
1168 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
1169 [Page state NR_INACTIVE is available])
1174 AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
1175 SPL_LINUX_TRY_COMPILE([
1176 #include <linux/mm.h>
1178 enum zone_stat_item zsi;
1179 zsi = NR_INACTIVE_ANON;
1182 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
1183 [Page state NR_INACTIVE_ANON is available])
1188 AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
1189 SPL_LINUX_TRY_COMPILE([
1190 #include <linux/mm.h>
1192 enum zone_stat_item zsi;
1193 zsi = NR_INACTIVE_FILE;
1196 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
1197 [Page state NR_INACTIVE_FILE is available])
1204 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1205 dnl # Public global zone stats now include an active page count. However
1206 dnl # the enumerated names of the counters have changed since this API
1207 dnl # was introduced. We need to deduce the corrent name to use. This
1208 dnl # replaces the priviate get_zone_counts() interface.
1210 dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
1211 dnl # anonymous and file active pages. As of 2.6.28 it was split in
1212 dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
1214 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
1215 AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
1216 SPL_LINUX_TRY_COMPILE([
1217 #include <linux/mm.h>
1219 enum zone_stat_item zsi;
1223 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
1224 [Page state NR_ACTIVE is available])
1229 AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
1230 SPL_LINUX_TRY_COMPILE([
1231 #include <linux/mm.h>
1233 enum zone_stat_item zsi;
1234 zsi = NR_ACTIVE_ANON;
1237 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
1238 [Page state NR_ACTIVE_ANON is available])
1243 AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
1244 SPL_LINUX_TRY_COMPILE([
1245 #include <linux/mm.h>
1247 enum zone_stat_item zsi;
1248 zsi = NR_ACTIVE_FILE;
1251 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
1252 [Page state NR_ACTIVE_FILE is available])
1259 dnl # Proposed API change for legacy kernels.
1260 dnl # This symbol is not available in older kernels. For kernels post
1261 dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
1262 dnl # page state information. This symbol is only used in legacy kernels
1263 dnl # any only as a last resort.
1265 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
1266 AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
1267 SPL_LINUX_TRY_COMPILE([
1269 #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
1270 #error "global_page_state needs NR_FREE_PAGES"
1273 #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
1274 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
1275 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
1276 #error "global_page_state needs NR_ACTIVE*"
1279 #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
1280 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
1281 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
1282 #error "global_page_state needs NR_INACTIVE*"
1288 AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
1289 [get_zone_counts() is needed])
1291 SPL_CHECK_SYMBOL_EXPORT(
1294 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
1295 [get_zone_counts() is available])],
1301 dnl # Symbol available in RHEL kernels not in stock kernels.
1303 AC_DEFUN([SPL_AC_SET_FS_PWD], [
1304 SPL_CHECK_SYMBOL_EXPORT(
1307 [AC_DEFINE(HAVE_SET_FS_PWD, 1,
1308 [set_fs_pwd() is available])],
1313 dnl # 2.6.25 API change,
1314 dnl # Simplied API by replacing mnt+dentry args with a single path arg.
1316 AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD],
1317 [AC_MSG_CHECKING([whether set_fs_pwd() wants 2 args])
1318 SPL_LINUX_TRY_COMPILE([
1319 #include <linux/sched.h>
1320 #include <linux/fs_struct.h>
1322 set_fs_pwd(NULL, NULL);
1325 AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1,
1326 [set_fs_pwd() wants 2 args])
1333 dnl # SLES API change, never adopted in mainline,
1334 dnl # Third 'struct vfsmount *' argument removed.
1336 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
1337 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
1338 SPL_LINUX_TRY_COMPILE([
1339 #include <linux/fs.h>
1341 vfs_unlink(NULL, NULL);
1344 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
1345 [vfs_unlink() wants 2 args])
1352 dnl # SLES API change, never adopted in mainline,
1353 dnl # Third and sixth 'struct vfsmount *' argument removed.
1355 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
1356 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
1357 SPL_LINUX_TRY_COMPILE([
1358 #include <linux/fs.h>
1360 vfs_rename(NULL, NULL, NULL, NULL);
1363 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
1364 [vfs_rename() wants 4 args])
1371 dnl # 2.6.29 API change,
1372 dnl # check whether 'struct cred' exists
1374 AC_DEFUN([SPL_AC_CRED_STRUCT], [
1375 AC_MSG_CHECKING([whether struct cred exists])
1376 SPL_LINUX_TRY_COMPILE([
1377 #include <linux/cred.h>
1383 AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
1390 dnl # Custom SPL patch may export this symbol.
1392 AC_DEFUN([SPL_AC_GROUPS_SEARCH], [
1393 SPL_CHECK_SYMBOL_EXPORT(
1396 [AC_DEFINE(HAVE_GROUPS_SEARCH, 1,
1397 [groups_search() is available])],
1402 dnl # 2.6.x API change,
1403 dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
1405 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT], [
1406 SPL_CHECK_SYMBOL_EXPORT(
1407 [__put_task_struct],
1409 [AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1410 [__put_task_struct() is available])],
1415 dnl # 2.6.32 API change,
1416 dnl # Unused 'struct file *' removed from prototype.
1418 AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
1419 AC_MSG_CHECKING([whether proc_handler() wants 5 args])
1420 SPL_LINUX_TRY_COMPILE([
1421 #include <linux/sysctl.h>
1423 proc_dostring(NULL, 0, NULL, NULL, NULL);
1426 AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
1427 [proc_handler() wants 5 args])
1434 dnl # 2.6.x API change,
1435 dnl # kvasprintf() function added.
1437 AC_DEFUN([SPL_AC_KVASPRINTF], [
1438 SPL_CHECK_SYMBOL_EXPORT(
1441 [AC_DEFINE(HAVE_KVASPRINTF, 1,
1442 [kvasprintf() is available])],