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 AC_DEFINE([DEBUG], [1], [Define to 1 to enable debug])
248 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
249 DEBUG_CFLAGS="-DDEBUG -Werror"
252 AC_DEFINE([NDEBUG], [1], [Define to 1 to enable debug])
253 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
254 DEBUG_CFLAGS="-DNDEBUG"
257 AC_SUBST(DEBUG_CFLAGS)
258 AC_MSG_RESULT([$enable_debug])
262 dnl # Enabled by default it provides a minimal level of memory tracking.
263 dnl # A total count of bytes allocated is kept for each alloc and free.
264 dnl # Then at module unload time a report to the console will be printed
265 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
266 dnl # and provide an easy way to inspect the kmem based slab.
268 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
269 AC_ARG_ENABLE([debug-kmem],
270 [AS_HELP_STRING([--enable-debug-kmem],
271 [Enable basic kmem accounting @<:@default=yes@:>@])],
273 [enable_debug_kmem=yes])
275 AS_IF([test "x$enable_debug_kmem" = xyes],
276 [AC_DEFINE([DEBUG_KMEM], [1],
277 [Define to 1 to enable basic kmem accounting])
278 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"])
280 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
281 AC_MSG_RESULT([$enable_debug_kmem])
285 dnl # Disabled by default it provides detailed memory tracking. This
286 dnl # feature also requires --enable-debug-kmem to be set. When enabled
287 dnl # not only will total bytes be tracked but also the location of every
288 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
289 dnl # addresses and where they were allocated will be dumped to the console.
290 dnl # Enabling this feature has a significant impact on performance but it
291 dnl # makes finding memory leaks pretty straight forward.
293 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
294 AC_ARG_ENABLE([debug-kmem-tracking],
295 [AS_HELP_STRING([--enable-debug-kmem-tracking],
296 [Enable detailed kmem tracking @<:@default=no@:>@])],
298 [enable_debug_kmem_tracking=no])
300 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
301 [AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
302 [Define to 1 to enable detailed kmem tracking])
303 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"])
305 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
306 AC_MSG_RESULT([$enable_debug_kmem_tracking])
310 dnl # SPL_LINUX_CONFTEST
312 AC_DEFUN([SPL_LINUX_CONFTEST], [
313 cat >conftest.c <<_ACEOF
319 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
321 m4_define([SPL_LANG_PROGRAM], [
326 dnl Do *not* indent the following line: there may be CPP directives.
327 dnl Don't move the `;' right after for the same reason.
335 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
337 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
338 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
339 rm -Rf build && mkdir -p build
340 echo "obj-m := conftest.o" >build/Makefile
342 [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])],
344 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
350 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
352 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
353 [SPL_LINUX_COMPILE_IFELSE(
354 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
356 [test -s build/conftest.o],
361 dnl # SPL_LINUX_CONFIG
363 AC_DEFUN([SPL_LINUX_CONFIG],
364 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
365 SPL_LINUX_TRY_COMPILE([
366 #ifndef AUTOCONF_INCLUDED
367 #include <linux/config.h>
371 #error CONFIG_$1 not #defined
383 dnl # SPL_CHECK_SYMBOL_EXPORT
384 dnl # check symbol exported or not
386 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
387 [AC_MSG_CHECKING([whether symbol $1 is exported])
388 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
389 $LINUX_OBJ/Module*.symvers 2>/dev/null
391 if test $rc -ne 0; then
394 grep -q -E "EXPORT_SYMBOL.*($1)" \
395 "$LINUX_OBJ/$file" 2>/dev/null
397 if test $rc -eq 0; then
402 if test $export -eq 0; then
416 dnl # SPL_CHECK_HEADER
417 dnl # check whether header exists and define HAVE_$2_HEADER
419 AC_DEFUN([SPL_CHECK_HEADER],
420 [AC_MSG_CHECKING([whether header $1 exists])
421 SPL_LINUX_TRY_COMPILE([
426 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
436 dnl # Use the atomic implemenation based on global spinlocks. This
437 dnl # should only be needed by 32-bit kernels which do not provide
438 dnl # the atomic64_* API. It may be optionally enabled as a fallback
439 dnl # if problems are observed with the direct mapping to the native
440 dnl # Linux atomic operations. You may not disable atomic spinlocks
441 dnl # if you kernel does not an atomic64_* API.
443 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
444 AC_ARG_ENABLE([atomic-spinlocks],
445 [AS_HELP_STRING([--enable-atomic-spinlocks],
446 [Atomic types use spinlocks @<:@default=check@:>@])],
448 [enable_atomic_spinlocks=check])
450 SPL_LINUX_TRY_COMPILE([
451 #include <asm/atomic.h>
456 AC_DEFINE(HAVE_ATOMIC64_T, 1,
457 [kernel defines atomic64_t])
462 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
463 AS_IF([test "x$have_atomic64_t" = xyes], [
464 enable_atomic_spinlocks=no
466 enable_atomic_spinlocks=yes
470 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
471 AC_DEFINE([ATOMIC_SPINLOCK], [1],
472 [Atomic types use spinlocks])
474 AS_IF([test "x$have_atomic64_t" = xno], [
476 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
480 AC_MSG_CHECKING([whether atomic types use spinlocks])
481 AC_MSG_RESULT([$enable_atomic_spinlocks])
483 AC_MSG_CHECKING([whether kernel defines atomic64_t])
484 AC_MSG_RESULT([$have_atomic64_t])
488 dnl # 2.6.24 API change,
489 dnl # check if atomic64_cmpxchg is defined
491 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG],
492 [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg])
493 SPL_LINUX_TRY_COMPILE([
494 #include <asm/atomic.h>
496 atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
499 AC_DEFINE(HAVE_ATOMIC64_CMPXCHG, 1,
500 [kernel defines atomic64_cmpxchg])
507 dnl # 2.6.24 API change,
508 dnl # check if atomic64_xchg is defined
510 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG],
511 [AC_MSG_CHECKING([whether kernel defines atomic64_xchg])
512 SPL_LINUX_TRY_COMPILE([
513 #include <asm/atomic.h>
515 atomic64_xchg((atomic64_t *)NULL, 0);
518 AC_DEFINE(HAVE_ATOMIC64_XCHG, 1,
519 [kernel defines atomic64_xchg])
526 dnl # 2.6.24 API change,
527 dnl # check if uintptr_t typedef is defined
529 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
530 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
531 SPL_LINUX_TRY_COMPILE([
532 #include <linux/types.h>
537 AC_DEFINE(HAVE_UINTPTR_T, 1,
538 [kernel defines uintptr_t])
545 dnl # 2.6.20 API change,
546 dnl # INIT_WORK use 2 args and not store data inside
548 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
549 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
550 SPL_LINUX_TRY_COMPILE([
551 #include <linux/workqueue.h>
553 struct work_struct work;
554 INIT_WORK(&work, NULL, NULL);
557 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
558 [INIT_WORK wants 3 args])
565 dnl # 2.6.21 API change,
566 dnl # 'register_sysctl_table' use only one argument instead of two
568 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
569 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
570 SPL_LINUX_TRY_COMPILE([
571 #include <linux/sysctl.h>
573 return register_sysctl_table(NULL,0);
576 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
577 [register_sysctl_table() wants 2 args])
584 dnl # 2.6.23 API change
585 dnl # Old set_shrinker API replaced with register_shrinker
587 AC_DEFUN([SPL_AC_SET_SHRINKER], [
588 AC_MSG_CHECKING([whether set_shrinker() available])
589 SPL_LINUX_TRY_COMPILE([
590 #include <linux/mm.h>
592 return set_shrinker(DEFAULT_SEEKS, NULL);
595 AC_DEFINE(HAVE_SET_SHRINKER, 1,
596 [set_shrinker() available])
603 dnl # 2.6.25 API change,
604 dnl # struct path entry added to struct nameidata
606 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
607 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
608 SPL_LINUX_TRY_COMPILE([
609 #include <linux/namei.h>
614 nd.path.dentry = NULL;
617 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
618 [struct path used in struct nameidata])
625 dnl # Custom SPL patch may export this system it is not required
627 AC_DEFUN([SPL_AC_TASK_CURR], [
628 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
629 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
634 dnl # 2.6.19 API change,
635 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
637 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
638 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
639 SPL_LINUX_TRY_COMPILE([
640 #include <linux/sysctl.h>
642 #ifndef CTL_UNNUMBERED
643 #error CTL_UNNUMBERED undefined
647 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
648 [unnumbered sysctl support exists])
655 dnl # 2.6.33 API change,
656 dnl # Removed .ctl_name from struct ctl_table.
658 AC_DEFUN([SPL_AC_CTL_NAME], [
659 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
660 SPL_LINUX_TRY_COMPILE([
661 #include <linux/sysctl.h>
663 struct ctl_table ctl;
667 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
674 dnl # 2.6.16 API change.
675 dnl # Check if 'fls64()' is available
677 AC_DEFUN([SPL_AC_FLS64],
678 [AC_MSG_CHECKING([whether fls64() is available])
679 SPL_LINUX_TRY_COMPILE([
680 #include <linux/bitops.h>
685 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
692 dnl # 2.6.18 API change, check whether device_create() is available.
693 dnl # Device_create() was introduced in 2.6.18 and depricated
694 dnl # class_device_create() which was fully removed in 2.6.26.
696 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
697 SPL_CHECK_SYMBOL_EXPORT(
699 [drivers/base/core.c],
700 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
701 [device_create() is available])],
706 dnl # 2.6.27 API change,
707 dnl # device_create() uses 5 args, new 'drvdata' argument.
709 AC_DEFUN([SPL_AC_5ARGS_DEVICE_CREATE], [
710 AC_MSG_CHECKING([whether device_create() wants 5 args])
711 tmp_flags="$EXTRA_KCFLAGS"
712 EXTRA_KCFLAGS="-Werror"
713 SPL_LINUX_TRY_COMPILE([
714 #include <linux/device.h>
716 device_create(NULL, NULL, 0, NULL, "%d", 1);
719 AC_DEFINE(HAVE_5ARGS_DEVICE_CREATE, 1,
720 [device_create wants 5 args])
724 EXTRA_KCFLAGS="$tmp_flags"
728 dnl # 2.6.13 API change, check whether class_device_create() is available.
729 dnl # Class_device_create() was introduced in 2.6.13 and depricated
730 dnl # class_simple_device_add() which was fully removed in 2.6.13.
732 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
733 SPL_CHECK_SYMBOL_EXPORT(
734 [class_device_create],
735 [drivers/base/class.c],
736 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
737 [class_device_create() is available])],
742 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
744 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
745 SPL_CHECK_SYMBOL_EXPORT(
746 [set_normalized_timespec],
748 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
749 [set_normalized_timespec() is available as export])],
754 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
755 dnl # previously it was available in time.h as an inline.
757 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
758 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
759 SPL_LINUX_TRY_COMPILE([
760 #include <linux/time.h>
761 void set_normalized_timespec(struct timespec *ts,
762 time_t sec, long nsec) { }
769 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
770 [set_normalized_timespec() is available as inline])
775 dnl # 2.6.18 API change,
776 dnl # timespec_sub() inline function available in linux/time.h
778 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
779 AC_MSG_CHECKING([whether timespec_sub() is available])
780 SPL_LINUX_TRY_COMPILE([
781 #include <linux/time.h>
783 struct timespec a, b, c = { 0 };
784 c = timespec_sub(a, b);
787 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
794 dnl # 2.6.19 API change,
795 dnl # check if init_utsname() is available in linux/utsname.h
797 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
798 AC_MSG_CHECKING([whether init_utsname() is available])
799 SPL_LINUX_TRY_COMPILE([
800 #include <linux/utsname.h>
802 struct new_utsname *a = init_utsname();
805 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
812 dnl # 2.6.26 API change,
813 dnl # definition of struct fdtable relocated to linux/fdtable.h
815 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
816 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
820 dnl # 2.6.14 API change,
821 dnl # check whether 'files_fdtable()' exists
823 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
824 AC_MSG_CHECKING([whether files_fdtable() is available])
825 SPL_LINUX_TRY_COMPILE([
826 #include <linux/sched.h>
827 #include <linux/file.h>
828 #ifdef HAVE_FDTABLE_HEADER
829 #include <linux/fdtable.h>
832 struct files_struct *files = current->files;
833 struct fdtable *fdt = files_fdtable(files);
836 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
843 dnl # 2.6.18 API change,
844 dnl # added linux/uaccess.h
846 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
847 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
851 dnl # 2.6.12 API change,
852 dnl # check whether 'kmalloc_node()' is available.
854 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
855 AC_MSG_CHECKING([whether kmalloc_node() is available])
856 SPL_LINUX_TRY_COMPILE([
857 #include <linux/slab.h>
859 void *a = kmalloc_node(1, GFP_KERNEL, 0);
862 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
869 dnl # 2.6.9 API change,
870 dnl # check whether 'monotonic_clock()' is available it may
871 dnl # be available for some archs but not others.
873 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
874 SPL_CHECK_SYMBOL_EXPORT(
877 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
878 [monotonic_clock() is available])],
883 dnl # 2.6.16 API change,
884 dnl # check whether 'struct inode' has i_mutex
886 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
887 AC_MSG_CHECKING([whether struct inode has i_mutex])
888 SPL_LINUX_TRY_COMPILE([
889 #include <linux/fs.h>
890 #include <linux/mutex.h>
893 mutex_init(&i.i_mutex);
896 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
903 dnl # 2.6.29 API change,
904 dnl # Adaptive mutexs introduced.
906 AC_DEFUN([SPL_AC_MUTEX_OWNER], [
907 AC_MSG_CHECKING([whether struct mutex has owner])
908 SPL_LINUX_TRY_COMPILE([
909 #include <linux/mutex.h>
915 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
922 dnl # 2.6.18 API change,
923 dnl # First introduced 'mutex_lock_nested()' in include/linux/mutex.h,
924 dnl # as part of the mutex validator. Fallback to using 'mutex_lock()'
925 dnl # if the mutex validator is disabled or otherwise unavailable.
927 AC_DEFUN([SPL_AC_MUTEX_LOCK_NESTED], [
928 AC_MSG_CHECKING([whether mutex_lock_nested() is available])
929 SPL_LINUX_TRY_COMPILE([
930 #include <linux/mutex.h>
934 mutex_lock_nested(&mutex, 0);
937 AC_DEFINE(HAVE_MUTEX_LOCK_NESTED, 1,
938 [mutex_lock_nested() is available])
945 dnl # 2.6.22 API change,
946 dnl # First introduced 'div64_64()' in lib/div64.c
948 AC_DEFUN([SPL_AC_DIV64_64], [
949 SPL_CHECK_SYMBOL_EXPORT(
952 [AC_DEFINE(HAVE_DIV64_64, 1,
953 [div64_64() is available])],
958 dnl # 2.6.26 API change,
959 dnl # Renamed 'div64_64()' to 'div64_u64' in lib/div64.c
961 AC_DEFUN([SPL_AC_DIV64_U64], [
962 SPL_CHECK_SYMBOL_EXPORT(
965 [AC_DEFINE(HAVE_DIV64_U64, 1,
966 [div64_u64() is available])],
971 dnl # 2.6.27 API change,
972 dnl # on_each_cpu() uses 3 args, no 'retry' argument
974 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
975 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
976 SPL_LINUX_TRY_COMPILE([
977 #include <linux/smp.h>
979 on_each_cpu(NULL, NULL, 0);
982 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
983 [on_each_cpu wants 3 args])
990 dnl # 2.6.18 API change,
991 dnl # kallsyms_lookup_name no longer exported
993 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
994 SPL_CHECK_SYMBOL_EXPORT(
995 [kallsyms_lookup_name],
997 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
998 [kallsyms_lookup_name() is available])],
1003 dnl # Proposed API change,
1004 dnl # This symbol is not available in stock kernels. You may build a
1005 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1006 dnl # these symbols for use. If your already rolling a custom kernel for
1007 dnl # your environment this is recommended.
1009 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
1010 SPL_CHECK_SYMBOL_EXPORT(
1013 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
1014 [get_vmalloc_info() is available])],
1019 dnl # 2.6.17 API change
1020 dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
1021 dnl # next_zone() are introduced to simplify for_each_zone(). These symbols
1022 dnl # were exported in 2.6.17 for use by modules which was consistent with
1023 dnl # the previous implementation of for_each_zone(). From 2.6.18 - 2.6.19
1024 dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
1025 dnl # were dropped entirely leaving modules no way to directly iterate over
1026 dnl # the zone list. Because we need access to the zone helpers we check
1027 dnl # if the kernel contains the old or new implementation. Then we check
1028 dnl # to see if the symbols we need for each version are available. If they
1029 dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
1031 AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
1032 AC_MSG_CHECKING([whether symbol *_pgdat exist])
1033 grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
1035 if test $rc -eq 0; then
1036 AC_MSG_RESULT([yes])
1037 AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are available])
1044 dnl # Proposed API change,
1045 dnl # This symbol is not available in stock kernels. You may build a
1046 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1047 dnl # these symbols for use. If your already rolling a custom kernel for
1048 dnl # your environment this is recommended.
1050 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
1051 SPL_CHECK_SYMBOL_EXPORT(
1052 [first_online_pgdat],
1054 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
1055 [first_online_pgdat() is available])],
1060 dnl # Proposed API change,
1061 dnl # This symbol is not available in stock kernels. You may build a
1062 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1063 dnl # these symbols for use. If your already rolling a custom kernel for
1064 dnl # your environment this is recommended.
1066 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
1067 SPL_CHECK_SYMBOL_EXPORT(
1068 [next_online_pgdat],
1070 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
1071 [next_online_pgdat() is available])],
1076 dnl # Proposed API change,
1077 dnl # This symbol is not available in stock kernels. You may build a
1078 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1079 dnl # these symbols for use. If your already rolling a custom kernel for
1080 dnl # your environment this is recommended.
1082 AC_DEFUN([SPL_AC_NEXT_ZONE], [
1083 SPL_CHECK_SYMBOL_EXPORT(
1086 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
1087 [next_zone() is available])],
1092 dnl # 2.6.17 API change,
1093 dnl # See SPL_AC_PGDAT_HELPERS for details.
1095 AC_DEFUN([SPL_AC_PGDAT_LIST], [
1096 SPL_CHECK_SYMBOL_EXPORT(
1099 [AC_DEFINE(HAVE_PGDAT_LIST, 1,
1100 [pgdat_list is available])],
1105 dnl # 2.6.18 API change,
1106 dnl # First introduced global_page_state() support as an inline.
1108 AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
1109 AC_MSG_CHECKING([whether global_page_state() is available])
1110 SPL_LINUX_TRY_COMPILE([
1111 #include <linux/mm.h>
1113 unsigned long state;
1114 state = global_page_state(0);
1117 AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
1118 [global_page_state() is available])
1125 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1126 dnl # Public global zone stats now include a free page count. However
1127 dnl # the enumerated names of the counters have changed since this API
1128 dnl # was introduced. We need to deduce the corrent name to use. This
1129 dnl # replaces the priviate get_zone_counts() interface.
1131 dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
1132 dnl # is 2.6.30 as of when this was written.
1134 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
1135 AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
1136 SPL_LINUX_TRY_COMPILE([
1137 #include <linux/mm.h>
1139 enum zone_stat_item zsi;
1140 zsi = NR_FREE_PAGES;
1143 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
1144 [Page state NR_FREE_PAGES is available])
1151 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1152 dnl # Public global zone stats now include an inactive page count. However
1153 dnl # the enumerated names of the counters have changed since this API
1154 dnl # was introduced. We need to deduce the corrent name to use. This
1155 dnl # replaces the priviate get_zone_counts() interface.
1157 dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
1158 dnl # anonymous and file inactive pages. As of 2.6.28 it was split in
1159 dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
1161 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
1162 AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
1163 SPL_LINUX_TRY_COMPILE([
1164 #include <linux/mm.h>
1166 enum zone_stat_item zsi;
1170 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
1171 [Page state NR_INACTIVE is available])
1176 AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
1177 SPL_LINUX_TRY_COMPILE([
1178 #include <linux/mm.h>
1180 enum zone_stat_item zsi;
1181 zsi = NR_INACTIVE_ANON;
1184 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
1185 [Page state NR_INACTIVE_ANON is available])
1190 AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
1191 SPL_LINUX_TRY_COMPILE([
1192 #include <linux/mm.h>
1194 enum zone_stat_item zsi;
1195 zsi = NR_INACTIVE_FILE;
1198 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
1199 [Page state NR_INACTIVE_FILE is available])
1206 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1207 dnl # Public global zone stats now include an active page count. However
1208 dnl # the enumerated names of the counters have changed since this API
1209 dnl # was introduced. We need to deduce the corrent name to use. This
1210 dnl # replaces the priviate get_zone_counts() interface.
1212 dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
1213 dnl # anonymous and file active pages. As of 2.6.28 it was split in
1214 dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
1216 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
1217 AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
1218 SPL_LINUX_TRY_COMPILE([
1219 #include <linux/mm.h>
1221 enum zone_stat_item zsi;
1225 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
1226 [Page state NR_ACTIVE is available])
1231 AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
1232 SPL_LINUX_TRY_COMPILE([
1233 #include <linux/mm.h>
1235 enum zone_stat_item zsi;
1236 zsi = NR_ACTIVE_ANON;
1239 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
1240 [Page state NR_ACTIVE_ANON is available])
1245 AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
1246 SPL_LINUX_TRY_COMPILE([
1247 #include <linux/mm.h>
1249 enum zone_stat_item zsi;
1250 zsi = NR_ACTIVE_FILE;
1253 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
1254 [Page state NR_ACTIVE_FILE is available])
1261 dnl # Proposed API change for legacy kernels.
1262 dnl # This symbol is not available in older kernels. For kernels post
1263 dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
1264 dnl # page state information. This symbol is only used in legacy kernels
1265 dnl # any only as a last resort.
1267 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
1268 AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
1269 SPL_LINUX_TRY_COMPILE([
1271 #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
1272 #error "global_page_state needs NR_FREE_PAGES"
1275 #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
1276 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
1277 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
1278 #error "global_page_state needs NR_ACTIVE*"
1281 #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
1282 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
1283 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
1284 #error "global_page_state needs NR_INACTIVE*"
1290 AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
1291 [get_zone_counts() is needed])
1293 SPL_CHECK_SYMBOL_EXPORT(
1296 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
1297 [get_zone_counts() is available])],
1303 dnl # Symbol available in RHEL kernels not in stock kernels.
1305 AC_DEFUN([SPL_AC_SET_FS_PWD], [
1306 SPL_CHECK_SYMBOL_EXPORT(
1309 [AC_DEFINE(HAVE_SET_FS_PWD, 1,
1310 [set_fs_pwd() is available])],
1315 dnl # 2.6.25 API change,
1316 dnl # Simplied API by replacing mnt+dentry args with a single path arg.
1318 AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD],
1319 [AC_MSG_CHECKING([whether set_fs_pwd() wants 2 args])
1320 SPL_LINUX_TRY_COMPILE([
1321 #include <linux/sched.h>
1322 #include <linux/fs_struct.h>
1324 set_fs_pwd(NULL, NULL);
1327 AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1,
1328 [set_fs_pwd() wants 2 args])
1335 dnl # SLES API change, never adopted in mainline,
1336 dnl # Third 'struct vfsmount *' argument removed.
1338 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
1339 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
1340 SPL_LINUX_TRY_COMPILE([
1341 #include <linux/fs.h>
1343 vfs_unlink(NULL, NULL);
1346 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
1347 [vfs_unlink() wants 2 args])
1354 dnl # SLES API change, never adopted in mainline,
1355 dnl # Third and sixth 'struct vfsmount *' argument removed.
1357 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
1358 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
1359 SPL_LINUX_TRY_COMPILE([
1360 #include <linux/fs.h>
1362 vfs_rename(NULL, NULL, NULL, NULL);
1365 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
1366 [vfs_rename() wants 4 args])
1373 dnl # 2.6.29 API change,
1374 dnl # check whether 'struct cred' exists
1376 AC_DEFUN([SPL_AC_CRED_STRUCT], [
1377 AC_MSG_CHECKING([whether struct cred exists])
1378 SPL_LINUX_TRY_COMPILE([
1379 #include <linux/cred.h>
1385 AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
1392 dnl # Custom SPL patch may export this symbol.
1394 AC_DEFUN([SPL_AC_GROUPS_SEARCH], [
1395 SPL_CHECK_SYMBOL_EXPORT(
1398 [AC_DEFINE(HAVE_GROUPS_SEARCH, 1,
1399 [groups_search() is available])],
1404 dnl # 2.6.x API change,
1405 dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
1407 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT], [
1408 SPL_CHECK_SYMBOL_EXPORT(
1409 [__put_task_struct],
1411 [AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1412 [__put_task_struct() is available])],
1417 dnl # 2.6.32 API change,
1418 dnl # Unused 'struct file *' removed from prototype.
1420 AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
1421 AC_MSG_CHECKING([whether proc_handler() wants 5 args])
1422 SPL_LINUX_TRY_COMPILE([
1423 #include <linux/sysctl.h>
1425 proc_dostring(NULL, 0, NULL, NULL, NULL);
1428 AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
1429 [proc_handler() wants 5 args])
1436 dnl # 2.6.x API change,
1437 dnl # kvasprintf() function added.
1439 AC_DEFUN([SPL_AC_KVASPRINTF], [
1440 SPL_CHECK_SYMBOL_EXPORT(
1443 [AC_DEFINE(HAVE_KVASPRINTF, 1,
1444 [kvasprintf() is available])],