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], [
13 if test "${LINUX_OBJ}" != "${LINUX}"; then
14 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
16 AC_SUBST(KERNELMAKE_PARAMS)
18 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes"
19 AC_SUBST(KERNELCPPFLAGS)
24 SPL_AC_DEBUG_KMEM_TRACKING
25 SPL_AC_ATOMIC_SPINLOCK
26 SPL_AC_TYPE_ATOMIC64_CMPXCHG
27 SPL_AC_TYPE_ATOMIC64_XCHG
29 SPL_AC_3ARGS_INIT_WORK
30 SPL_AC_2ARGS_REGISTER_SYSCTL
32 SPL_AC_3ARGS_SHRINKER_CALLBACK
33 SPL_AC_PATH_IN_NAMEIDATA
39 SPL_AC_5ARGS_DEVICE_CREATE
40 SPL_AC_CLASS_DEVICE_CREATE
41 SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT
42 SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE
47 SPL_AC_CLEAR_CLOSE_ON_EXEC
50 SPL_AC_MONOTONIC_CLOCK
53 SPL_AC_MUTEX_OWNER_TASK_STRUCT
54 SPL_AC_MUTEX_LOCK_NESTED
55 SPL_AC_3ARGS_ON_EACH_CPU
56 SPL_AC_KALLSYMS_LOOKUP_NAME
57 SPL_AC_GET_VMALLOC_INFO
59 SPL_AC_FIRST_ONLINE_PGDAT
60 SPL_AC_NEXT_ONLINE_PGDAT
63 SPL_AC_GLOBAL_PAGE_STATE
64 SPL_AC_ZONE_STAT_ITEM_FREE
65 SPL_AC_ZONE_STAT_ITEM_INACTIVE
66 SPL_AC_ZONE_STAT_ITEM_ACTIVE
67 SPL_AC_GET_ZONE_COUNTS
70 SPL_AC_2ARGS_SET_FS_PWD
71 SPL_AC_2ARGS_VFS_UNLINK
72 SPL_AC_4ARGS_VFS_RENAME
74 SPL_AC_2ARGS_VFS_FSYNC
75 SPL_AC_FS_STRUCT_SPINLOCK
78 SPL_AC_PUT_TASK_STRUCT
79 SPL_AC_5ARGS_PROC_HANDLER
81 SPL_AC_EXPORTED_RWSEM_IS_LOCKED
82 SPL_AC_KERNEL_INVALIDATE_INODES
83 SPL_AC_KERNEL_2ARGS_INVALIDATE_INODES
84 SPL_AC_SHRINK_DCACHE_MEMORY
85 SPL_AC_SHRINK_ICACHE_MEMORY
86 SPL_AC_KERN_PATH_PARENT_HEADER
87 SPL_AC_KERN_PATH_PARENT_SYMBOL
88 SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
89 SPL_AC_SHRINK_CONTROL_STRUCT
90 SPL_AC_RWSEM_SPINLOCK_IS_RAW
93 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
94 modpost=$LINUX/scripts/Makefile.modpost
95 AC_MSG_CHECKING([kernel file name for module symbols])
96 if test -f "$modpost"; then
97 if grep -q Modules.symvers $modpost; then
98 LINUX_SYMBOLS=Modules.symvers
100 LINUX_SYMBOLS=Module.symvers
103 if ! test -f "$LINUX_OBJ/$LINUX_SYMBOLS"; then
105 *** Please make sure the kernel devel package for your distribution
106 *** is installed. If your building with a custom kernel make sure the
107 *** kernel is configured, built, and the '--with-linux=PATH' configure
108 *** option refers to the location of the kernel source.])
113 AC_MSG_RESULT($LINUX_SYMBOLS)
114 AC_SUBST(LINUX_SYMBOLS)
117 AC_DEFUN([SPL_AC_KERNEL], [
119 AS_HELP_STRING([--with-linux=PATH],
120 [Path to kernel source]),
121 [kernelsrc="$withval"])
123 AC_ARG_WITH([linux-obj],
124 AS_HELP_STRING([--with-linux-obj=PATH],
125 [Path to kernel build objects]),
126 [kernelbuild="$withval"])
128 AC_MSG_CHECKING([kernel source directory])
129 if test -z "$kernelsrc"; then
130 if test -e "/lib/modules/$(uname -r)/source"; then
131 headersdir="/lib/modules/$(uname -r)/source"
132 sourcelink=$(readlink -f "$headersdir")
133 elif test -e "/lib/modules/$(uname -r)/build"; then
134 headersdir="/lib/modules/$(uname -r)/build"
135 sourcelink=$(readlink -f "$headersdir")
137 sourcelink=$(ls -1d /usr/src/kernels/* \
139 2>/dev/null | grep -v obj | tail -1)
142 if test -n "$sourcelink" && test -e ${sourcelink}; then
143 kernelsrc=`readlink -f ${sourcelink}`
145 AC_MSG_RESULT([Not found])
147 *** Please make sure the kernel devel package for your distribution
148 *** is installed then try again. If that fails you can specify the
149 *** location of the kernel source with the '--with-linux=PATH' option.])
152 if test "$kernelsrc" = "NONE"; then
157 AC_MSG_RESULT([$kernelsrc])
158 AC_MSG_CHECKING([kernel build directory])
159 if test -z "$kernelbuild"; then
160 if test -e "/lib/modules/$(uname -r)/build"; then
161 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
162 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
163 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
164 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
165 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
166 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
167 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
169 kernelbuild=${kernelsrc}
172 AC_MSG_RESULT([$kernelbuild])
174 AC_MSG_CHECKING([kernel source version])
175 utsrelease1=$kernelbuild/include/linux/version.h
176 utsrelease2=$kernelbuild/include/linux/utsrelease.h
177 utsrelease3=$kernelbuild/include/generated/utsrelease.h
178 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
179 utsrelease=linux/version.h
180 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
181 utsrelease=linux/utsrelease.h
182 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
183 utsrelease=generated/utsrelease.h
186 if test "$utsrelease"; then
187 kernsrcver=`(echo "#include <$utsrelease>";
188 echo "kernsrcver=UTS_RELEASE") |
189 cpp -I $kernelbuild/include |
190 grep "^kernsrcver=" | cut -d \" -f 2`
192 if test -z "$kernsrcver"; then
193 AC_MSG_RESULT([Not found])
194 AC_MSG_ERROR([*** Cannot determine kernel version.])
197 AC_MSG_RESULT([Not found])
198 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
201 AC_MSG_RESULT([$kernsrcver])
204 LINUX_OBJ=${kernelbuild}
205 LINUX_VERSION=${kernsrcver}
209 AC_SUBST(LINUX_VERSION)
211 SPL_AC_MODULE_SYMVERS
214 AC_DEFUN([SPL_AC_KERNEL_CONFIG], [
215 SPL_LINUX_CONFIG([PREEMPT],
217 *** Kernel built with CONFIG_PREEMPT which is not supported.
218 ** You must rebuild your kernel without this option.]), [])
222 dnl # Default SPL user configuration
224 AC_DEFUN([SPL_AC_CONFIG_USER], [])
227 dnl # Check for rpm+rpmbuild to build RPM packages. If these tools
228 dnl # are missing it is non-fatal but you will not be able to build
229 dnl # RPM packages and will be warned if you try too.
231 AC_DEFUN([SPL_AC_RPM], [
235 AC_MSG_CHECKING([whether $RPM is available])
236 AS_IF([tmp=$($RPM --version 2>/dev/null)], [
237 RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
239 AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
242 AC_MSG_RESULT([$HAVE_RPM])
245 AC_MSG_CHECKING([whether $RPMBUILD is available])
246 AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
247 RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
249 AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
252 AC_MSG_RESULT([$HAVE_RPMBUILD])
257 AC_SUBST(RPM_VERSION)
259 AC_SUBST(HAVE_RPMBUILD)
261 AC_SUBST(RPMBUILD_VERSION)
265 dnl # Check for dpkg+dpkg-buildpackage to build DEB packages. If these
266 dnl # tools are missing it is non-fatal but you will not be able to build
267 dnl # DEB packages and will be warned if you try too.
269 AC_DEFUN([SPL_AC_DPKG], [
271 DPKGBUILD=dpkg-buildpackage
273 AC_MSG_CHECKING([whether $DPKG is available])
274 AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
275 DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
277 AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
280 AC_MSG_RESULT([$HAVE_DPKG])
283 AC_MSG_CHECKING([whether $DPKGBUILD is available])
284 AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
285 DPKGBUILD_VERSION=$(echo $tmp | \
286 $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
288 AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
291 AC_MSG_RESULT([$HAVE_DPKGBUILD])
296 AC_SUBST(DPKG_VERSION)
298 AC_SUBST(HAVE_DPKGBUILD)
300 AC_SUBST(DPKGBUILD_VERSION)
304 dnl # Check for pacman+makepkg to build Arch Linux packages. If these
305 dnl # tools are missing it is non-fatal but you will not be able to
306 dnl # build Arch Linux packages and will be warned if you try too.
308 AC_DEFUN([SPL_AC_PACMAN], [
312 AC_MSG_CHECKING([whether $PACMAN is available])
313 tmp=$($PACMAN --version 2>/dev/null)
314 AS_IF([test -n "$tmp"], [
315 PACMAN_VERSION=$(echo $tmp |
316 $AWK '/Pacman/ { print $[3] }' |
319 AC_MSG_RESULT([$HAVE_PACMAN ($PACMAN_VERSION)])
322 AC_MSG_RESULT([$HAVE_PACMAN])
325 AC_MSG_CHECKING([whether $MAKEPKG is available])
326 tmp=$($MAKEPKG --version 2>/dev/null)
327 AS_IF([test -n "$tmp"], [
328 MAKEPKG_VERSION=$(echo $tmp | $AWK '/makepkg/ { print $[3] }')
330 AC_MSG_RESULT([$HAVE_MAKEPKG ($MAKEPKG_VERSION)])
333 AC_MSG_RESULT([$HAVE_MAKEPKG])
336 AC_SUBST(HAVE_PACMAN)
338 AC_SUBST(PACMAN_VERSION)
340 AC_SUBST(HAVE_MAKEPKG)
342 AC_SUBST(MAKEPKG_VERSION)
346 dnl # Until native packaging for various different packing systems
347 dnl # can be added the least we can do is attempt to use alien to
348 dnl # convert the RPM packages to the needed package type. This is
349 dnl # a hack but so far it has worked reasonable well.
351 AC_DEFUN([SPL_AC_ALIEN], [
354 AC_MSG_CHECKING([whether $ALIEN is available])
355 AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
356 ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
358 AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
361 AC_MSG_RESULT([$HAVE_ALIEN])
366 AC_SUBST(ALIEN_VERSION)
370 dnl # Using the VENDOR tag from config.guess set the default
371 dnl # package type for 'make pkg': (rpm | deb | tgz)
373 AC_DEFUN([SPL_AC_DEFAULT_PACKAGE], [
374 AC_MSG_CHECKING([linux distribution])
375 if test -f /etc/toss-release ; then
377 elif test -f /etc/fedora-release ; then
379 elif test -f /etc/redhat-release ; then
381 elif test -f /etc/gentoo-release ; then
383 elif test -f /etc/arch-release ; then
385 elif test -f /etc/SuSE-release ; then
387 elif test -f /etc/slackware-version ; then
389 elif test -f /etc/lunar.release ; then
391 elif test -f /etc/lsb-release ; then
393 elif test -f /etc/debian_version ; then
398 AC_MSG_RESULT([$VENDOR])
401 AC_MSG_CHECKING([default package type])
403 toss) DEFAULT_PACKAGE=rpm ;;
404 redhat) DEFAULT_PACKAGE=rpm ;;
405 fedora) DEFAULT_PACKAGE=rpm ;;
406 gentoo) DEFAULT_PACKAGE=tgz ;;
407 arch) DEFAULT_PACKAGE=arch ;;
408 sles) DEFAULT_PACKAGE=rpm ;;
409 slackware) DEFAULT_PACKAGE=tgz ;;
410 lunar) DEFAULT_PACKAGE=tgz ;;
411 ubuntu) DEFAULT_PACKAGE=deb ;;
412 debian) DEFAULT_PACKAGE=deb ;;
413 *) DEFAULT_PACKAGE=rpm ;;
416 AC_MSG_RESULT([$DEFAULT_PACKAGE])
417 AC_SUBST(DEFAULT_PACKAGE)
421 dnl # Default SPL user configuration
423 AC_DEFUN([SPL_AC_PACKAGE], [
424 SPL_AC_DEFAULT_PACKAGE
429 AS_IF([test "$VENDOR" = "arch"], [SPL_AC_PACMAN])
432 AC_DEFUN([SPL_AC_LICENSE], [
433 AC_MSG_CHECKING([spl license])
435 AC_MSG_RESULT([$LICENSE])
436 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DHAVE_GPL_ONLY_SYMBOLS"
440 AC_DEFUN([SPL_AC_CONFIG], [
442 AC_ARG_WITH([config],
443 AS_HELP_STRING([--with-config=CONFIG],
444 [Config file 'kernel|user|all|srpm']),
445 [SPL_CONFIG="$withval"])
447 AC_MSG_CHECKING([spl config])
448 AC_MSG_RESULT([$SPL_CONFIG]);
451 case "$SPL_CONFIG" in
452 kernel) SPL_AC_CONFIG_KERNEL ;;
453 user) SPL_AC_CONFIG_USER ;;
454 all) SPL_AC_CONFIG_KERNEL
455 SPL_AC_CONFIG_USER ;;
458 AC_MSG_RESULT([Error!])
459 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
460 user kernel|user|all|srpm]) ;;
463 AM_CONDITIONAL([CONFIG_USER],
464 [test "$SPL_CONFIG" = user] ||
465 [test "$SPL_CONFIG" = all])
466 AM_CONDITIONAL([CONFIG_KERNEL],
467 [test "$SPL_CONFIG" = kernel] ||
468 [test "$SPL_CONFIG" = all])
472 dnl # Enable if the SPL should be compiled with internal debugging enabled.
473 dnl # By default this support is disabled.
475 AC_DEFUN([SPL_AC_DEBUG], [
476 AC_MSG_CHECKING([whether debugging is enabled])
477 AC_ARG_ENABLE([debug],
478 [AS_HELP_STRING([--enable-debug],
479 [Enable generic debug support @<:@default=no@:>@])],
483 AS_IF([test "x$enable_debug" = xyes],
485 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
486 DEBUG_CFLAGS="-DDEBUG -Werror"
487 DEBUG_SPL="_with_debug"
489 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
490 DEBUG_CFLAGS="-DNDEBUG"
491 DEBUG_SPL="_without_debug"
494 AC_SUBST(DEBUG_CFLAGS)
496 AC_MSG_RESULT([$enable_debug])
500 dnl # Enabled by default it provides a basic debug log infrastructure.
501 dnl # Each subsystem registers itself with a name and logs messages
502 dnl # using predefined types. If the debug mask it set to allow the
503 dnl # message type it will be written to the internal log. The log
504 dnl # can be dumped to a file by echoing 1 to the 'dump' proc entry,
505 dnl # after dumping the log it must be decoded using the spl utility.
507 dnl # echo 1 >/proc/sys/kernel/spl/debug/dump
508 dnl # spl /tmp/spl-log.xxx.yyy /tmp/spl-log.xxx.yyy.txt
510 AC_DEFUN([SPL_AC_DEBUG_LOG], [
511 AC_ARG_ENABLE([debug-log],
512 [AS_HELP_STRING([--enable-debug-log],
513 [Enable basic debug logging @<:@default=yes@:>@])],
515 [enable_debug_log=yes])
517 AS_IF([test "x$enable_debug_log" = xyes],
519 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_LOG"
520 DEBUG_LOG="_with_debug_log"
521 AC_DEFINE([DEBUG_LOG], [1],
522 [Define to 1 to enable basic debug logging])
524 DEBUG_LOG="_without_debug_log"
528 AC_MSG_CHECKING([whether basic debug logging is enabled])
529 AC_MSG_RESULT([$enable_debug_log])
533 dnl # Enabled by default it provides a minimal level of memory tracking.
534 dnl # A total count of bytes allocated is kept for each alloc and free.
535 dnl # Then at module unload time a report to the console will be printed
536 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
537 dnl # and provide an easy way to inspect the kmem based slab.
539 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
540 AC_ARG_ENABLE([debug-kmem],
541 [AS_HELP_STRING([--enable-debug-kmem],
542 [Enable basic kmem accounting @<:@default=yes@:>@])],
544 [enable_debug_kmem=yes])
546 AS_IF([test "x$enable_debug_kmem" = xyes],
548 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
549 DEBUG_KMEM="_with_debug_kmem"
550 AC_DEFINE([DEBUG_KMEM], [1],
551 [Define to 1 to enable basic kmem accounting])
553 DEBUG_KMEM="_without_debug_kmem"
557 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
558 AC_MSG_RESULT([$enable_debug_kmem])
562 dnl # Disabled by default it provides detailed memory tracking. This
563 dnl # feature also requires --enable-debug-kmem to be set. When enabled
564 dnl # not only will total bytes be tracked but also the location of every
565 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
566 dnl # addresses and where they were allocated will be dumped to the console.
567 dnl # Enabling this feature has a significant impact on performance but it
568 dnl # makes finding memory leaks pretty straight forward.
570 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
571 AC_ARG_ENABLE([debug-kmem-tracking],
572 [AS_HELP_STRING([--enable-debug-kmem-tracking],
573 [Enable detailed kmem tracking @<:@default=no@:>@])],
575 [enable_debug_kmem_tracking=no])
577 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
579 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
580 DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
581 AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
582 [Define to 1 to enable detailed kmem tracking])
584 DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
587 AC_SUBST(DEBUG_KMEM_TRACKING)
588 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
589 AC_MSG_RESULT([$enable_debug_kmem_tracking])
593 dnl # SPL_LINUX_CONFTEST
595 AC_DEFUN([SPL_LINUX_CONFTEST], [
596 cat confdefs.h - <<_ACEOF >conftest.c
602 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
604 m4_define([SPL_LANG_PROGRAM], [
609 dnl Do *not* indent the following line: there may be CPP directives.
610 dnl Don't move the `;' right after for the same reason.
618 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
620 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
621 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
622 rm -Rf build && mkdir -p build
623 echo "obj-m := conftest.o" >build/Makefile
625 [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])],
627 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
633 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
635 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
636 [SPL_LINUX_COMPILE_IFELSE(
637 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
639 [test -s build/conftest.o],
644 dnl # SPL_LINUX_CONFIG
646 AC_DEFUN([SPL_LINUX_CONFIG],
647 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
648 SPL_LINUX_TRY_COMPILE([
649 #include <linux/module.h>
652 #error CONFIG_$1 not #defined
664 dnl # SPL_CHECK_SYMBOL_EXPORT
665 dnl # check symbol exported or not
667 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
668 [AC_MSG_CHECKING([whether symbol $1 is exported])
669 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
670 $LINUX_OBJ/Module*.symvers 2>/dev/null
672 if test $rc -ne 0; then
675 grep -q -E "EXPORT_SYMBOL.*($1)" \
676 "$LINUX_OBJ/$file" 2>/dev/null
678 if test $rc -eq 0; then
683 if test $export -eq 0; then
697 dnl # SPL_CHECK_SYMBOL_HEADER
698 dnl # check if a symbol prototype is defined in listed headers.
700 AC_DEFUN([SPL_CHECK_SYMBOL_HEADER], [
701 AC_MSG_CHECKING([whether symbol $1 exists in header])
704 grep -q "$2" "$LINUX/$file" 2>/dev/null
706 if test $rc -eq 0; then
711 if test $header -eq 0; then
721 dnl # SPL_CHECK_HEADER
722 dnl # check whether header exists and define HAVE_$2_HEADER
724 AC_DEFUN([SPL_CHECK_HEADER],
725 [AC_MSG_CHECKING([whether header $1 exists])
726 SPL_LINUX_TRY_COMPILE([
731 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
741 dnl # Use the atomic implemenation based on global spinlocks. This
742 dnl # should only be needed by 32-bit kernels which do not provide
743 dnl # the atomic64_* API. It may be optionally enabled as a fallback
744 dnl # if problems are observed with the direct mapping to the native
745 dnl # Linux atomic operations. You may not disable atomic spinlocks
746 dnl # if you kernel does not an atomic64_* API.
748 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
749 AC_ARG_ENABLE([atomic-spinlocks],
750 [AS_HELP_STRING([--enable-atomic-spinlocks],
751 [Atomic types use spinlocks @<:@default=check@:>@])],
753 [enable_atomic_spinlocks=check])
755 SPL_LINUX_TRY_COMPILE([
756 #include <asm/atomic.h>
758 atomic64_t *ptr __attribute__ ((unused));
761 AC_DEFINE(HAVE_ATOMIC64_T, 1,
762 [kernel defines atomic64_t])
767 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
768 AS_IF([test "x$have_atomic64_t" = xyes], [
769 enable_atomic_spinlocks=no
771 enable_atomic_spinlocks=yes
775 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
776 AC_DEFINE([ATOMIC_SPINLOCK], [1],
777 [Atomic types use spinlocks])
779 AS_IF([test "x$have_atomic64_t" = xno], [
781 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
785 AC_MSG_CHECKING([whether atomic types use spinlocks])
786 AC_MSG_RESULT([$enable_atomic_spinlocks])
788 AC_MSG_CHECKING([whether kernel defines atomic64_t])
789 AC_MSG_RESULT([$have_atomic64_t])
793 dnl # 2.6.24 API change,
794 dnl # check if atomic64_cmpxchg is defined
796 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG],
797 [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg])
798 SPL_LINUX_TRY_COMPILE([
799 #include <asm/atomic.h>
800 #include <asm/system.h>
802 atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
805 AC_DEFINE(HAVE_ATOMIC64_CMPXCHG, 1,
806 [kernel defines atomic64_cmpxchg])
813 dnl # 2.6.24 API change,
814 dnl # check if atomic64_xchg is defined
816 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG],
817 [AC_MSG_CHECKING([whether kernel defines atomic64_xchg])
818 SPL_LINUX_TRY_COMPILE([
819 #include <asm/atomic.h>
821 atomic64_xchg((atomic64_t *)NULL, 0);
824 AC_DEFINE(HAVE_ATOMIC64_XCHG, 1,
825 [kernel defines atomic64_xchg])
832 dnl # 2.6.24 API change,
833 dnl # check if uintptr_t typedef is defined
835 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
836 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
837 SPL_LINUX_TRY_COMPILE([
838 #include <linux/types.h>
840 uintptr_t *ptr __attribute__ ((unused));
843 AC_DEFINE(HAVE_UINTPTR_T, 1,
844 [kernel defines uintptr_t])
851 dnl # 2.6.20 API change,
852 dnl # INIT_WORK use 2 args and not store data inside
854 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
855 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
856 SPL_LINUX_TRY_COMPILE([
857 #include <linux/workqueue.h>
859 struct work_struct work __attribute__ ((unused));
860 INIT_WORK(&work, NULL, NULL);
863 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
864 [INIT_WORK wants 3 args])
871 dnl # 2.6.21 API change,
872 dnl # 'register_sysctl_table' use only one argument instead of two
874 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
875 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
876 SPL_LINUX_TRY_COMPILE([
877 #include <linux/sysctl.h>
879 (void) register_sysctl_table(NULL, 0);
882 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
883 [register_sysctl_table() wants 2 args])
890 dnl # 2.6.23 API change
891 dnl # Old set_shrinker API replaced with register_shrinker
893 AC_DEFUN([SPL_AC_SET_SHRINKER], [
894 AC_MSG_CHECKING([whether set_shrinker() available])
895 SPL_LINUX_TRY_COMPILE([
896 #include <linux/mm.h>
898 return set_shrinker(DEFAULT_SEEKS, NULL);
901 AC_DEFINE(HAVE_SET_SHRINKER, 1,
902 [set_shrinker() available])
909 dnl # 2.6.35 API change,
910 dnl # Add context to shrinker callback
912 AC_DEFUN([SPL_AC_3ARGS_SHRINKER_CALLBACK],
913 [AC_MSG_CHECKING([whether shrinker callback wants 3 args])
914 tmp_flags="$EXTRA_KCFLAGS"
915 EXTRA_KCFLAGS="-Werror"
916 SPL_LINUX_TRY_COMPILE([
917 #include <linux/mm.h>
919 int shrinker_cb(struct shrinker *, int, unsigned int);
921 struct shrinker cache_shrinker = {
922 .shrink = shrinker_cb,
923 .seeks = DEFAULT_SEEKS,
925 register_shrinker(&cache_shrinker);
928 AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1,
929 [shrinker callback wants 3 args])
933 EXTRA_KCFLAGS="$tmp_flags"
937 dnl # 2.6.25 API change,
938 dnl # struct path entry added to struct nameidata
940 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
941 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
942 SPL_LINUX_TRY_COMPILE([
943 #include <linux/namei.h>
945 struct nameidata nd __attribute__ ((unused));
948 nd.path.dentry = NULL;
951 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
952 [struct path used in struct nameidata])
959 dnl # Custom SPL patch may export this system it is not required
961 AC_DEFUN([SPL_AC_TASK_CURR], [
962 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
963 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
968 dnl # 2.6.19 API change,
969 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
971 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
972 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
973 SPL_LINUX_TRY_COMPILE([
974 #include <linux/sysctl.h>
976 #ifndef CTL_UNNUMBERED
977 #error CTL_UNNUMBERED undefined
981 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
982 [unnumbered sysctl support exists])
989 dnl # 2.6.33 API change,
990 dnl # Removed .ctl_name from struct ctl_table.
992 AC_DEFUN([SPL_AC_CTL_NAME], [
993 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
994 SPL_LINUX_TRY_COMPILE([
995 #include <linux/sysctl.h>
997 struct ctl_table ctl __attribute__ ((unused));
1001 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
1008 dnl # 2.6.16 API change.
1009 dnl # Check if 'fls64()' is available
1011 AC_DEFUN([SPL_AC_FLS64],
1012 [AC_MSG_CHECKING([whether fls64() is available])
1013 SPL_LINUX_TRY_COMPILE([
1014 #include <linux/bitops.h>
1019 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
1026 dnl # 2.6.18 API change, check whether device_create() is available.
1027 dnl # Device_create() was introduced in 2.6.18 and depricated
1028 dnl # class_device_create() which was fully removed in 2.6.26.
1030 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
1031 SPL_CHECK_SYMBOL_EXPORT(
1033 [drivers/base/core.c],
1034 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
1035 [device_create() is available])],
1040 dnl # 2.6.27 API change,
1041 dnl # device_create() uses 5 args, new 'drvdata' argument.
1043 AC_DEFUN([SPL_AC_5ARGS_DEVICE_CREATE], [
1044 AC_MSG_CHECKING([whether device_create() wants 5 args])
1045 tmp_flags="$EXTRA_KCFLAGS"
1046 EXTRA_KCFLAGS="-Werror"
1047 SPL_LINUX_TRY_COMPILE([
1048 #include <linux/device.h>
1050 device_create(NULL, NULL, 0, NULL, "%d", 1);
1053 AC_DEFINE(HAVE_5ARGS_DEVICE_CREATE, 1,
1054 [device_create wants 5 args])
1058 EXTRA_KCFLAGS="$tmp_flags"
1062 dnl # 2.6.13 API change, check whether class_device_create() is available.
1063 dnl # Class_device_create() was introduced in 2.6.13 and depricated
1064 dnl # class_simple_device_add() which was fully removed in 2.6.13.
1066 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
1067 SPL_CHECK_SYMBOL_EXPORT(
1068 [class_device_create],
1069 [drivers/base/class.c],
1070 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
1071 [class_device_create() is available])],
1076 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
1078 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
1079 SPL_CHECK_SYMBOL_EXPORT(
1080 [set_normalized_timespec],
1082 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
1083 [set_normalized_timespec() is available as export])],
1088 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
1089 dnl # previously it was available in time.h as an inline.
1091 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
1092 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
1093 SPL_LINUX_TRY_COMPILE([
1094 #include <linux/time.h>
1095 void set_normalized_timespec(struct timespec *ts,
1096 time_t sec, long nsec) { }
1103 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
1104 [set_normalized_timespec() is available as inline])
1109 dnl # 2.6.18 API change,
1110 dnl # timespec_sub() inline function available in linux/time.h
1112 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
1113 AC_MSG_CHECKING([whether timespec_sub() is available])
1114 SPL_LINUX_TRY_COMPILE([
1115 #include <linux/time.h>
1117 struct timespec a = { 0 };
1118 struct timespec b = { 0 };
1119 struct timespec c __attribute__ ((unused));
1120 c = timespec_sub(a, b);
1123 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
1130 dnl # 2.6.19 API change,
1131 dnl # check if init_utsname() is available in linux/utsname.h
1133 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
1134 AC_MSG_CHECKING([whether init_utsname() is available])
1135 SPL_LINUX_TRY_COMPILE([
1136 #include <linux/utsname.h>
1138 struct new_utsname *a __attribute__ ((unused));
1142 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
1149 dnl # 2.6.26 API change,
1150 dnl # definition of struct fdtable relocated to linux/fdtable.h
1152 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
1153 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
1157 dnl # 2.6.14 API change,
1158 dnl # check whether 'files_fdtable()' exists
1160 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
1161 AC_MSG_CHECKING([whether files_fdtable() is available])
1162 SPL_LINUX_TRY_COMPILE([
1163 #include <linux/sched.h>
1164 #include <linux/file.h>
1165 #ifdef HAVE_FDTABLE_HEADER
1166 #include <linux/fdtable.h>
1169 struct files_struct *files = current->files;
1170 struct fdtable *fdt __attribute__ ((unused));
1171 fdt = files_fdtable(files);
1174 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
1181 dnl # 3.4.0 API change,
1182 dnl # check whether '__clear_close_on_exec()' exists
1184 AC_DEFUN([SPL_AC_CLEAR_CLOSE_ON_EXEC], [
1185 AC_MSG_CHECKING([whether __clear_close_on_exec() is available])
1186 SPL_LINUX_TRY_COMPILE([
1187 #include <linux/fdtable.h>
1189 struct fdtable *fdt = NULL;
1192 __clear_close_on_exec(fd, fdt);
1195 AC_DEFINE(HAVE_CLEAR_CLOSE_ON_EXEC, 1,
1196 [__clear_close_on_exec() is available])
1203 dnl # 2.6.18 API change,
1204 dnl # added linux/uaccess.h
1206 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
1207 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
1211 dnl # 2.6.12 API change,
1212 dnl # check whether 'kmalloc_node()' is available.
1214 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
1215 AC_MSG_CHECKING([whether kmalloc_node() is available])
1216 SPL_LINUX_TRY_COMPILE([
1217 #include <linux/slab.h>
1219 void *a __attribute__ ((unused));
1220 a = kmalloc_node(1, GFP_KERNEL, 0);
1223 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
1230 dnl # 2.6.9 API change,
1231 dnl # check whether 'monotonic_clock()' is available it may
1232 dnl # be available for some archs but not others.
1234 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
1235 SPL_CHECK_SYMBOL_EXPORT(
1238 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
1239 [monotonic_clock() is available])],
1244 dnl # 2.6.16 API change,
1245 dnl # check whether 'struct inode' has i_mutex
1247 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
1248 AC_MSG_CHECKING([whether struct inode has i_mutex])
1249 SPL_LINUX_TRY_COMPILE([
1250 #include <linux/fs.h>
1251 #include <linux/mutex.h>
1254 mutex_init(&i.i_mutex);
1257 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
1264 dnl # 2.6.29 API change,
1265 dnl # Adaptive mutexs introduced.
1267 AC_DEFUN([SPL_AC_MUTEX_OWNER], [
1268 AC_MSG_CHECKING([whether struct mutex has owner])
1269 SPL_LINUX_TRY_COMPILE([
1270 #include <linux/mutex.h>
1272 struct mutex mtx __attribute__ ((unused));
1276 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
1283 dnl # 2.6.39 API change,
1284 dnl # Owner type change. A Linux mutex prior to 2.6.39 would store
1285 dnl # the owner as a thread_info pointer when CONFIG_DEBUG_MUTEXES
1286 dnl # was defined. As of 2.6.39 this was changed to a task_struct
1287 dnl # pointer which frankly makes a lot more sense.
1289 AC_DEFUN([SPL_AC_MUTEX_OWNER_TASK_STRUCT], [
1290 AC_MSG_CHECKING([whether struct mutex owner is a task_struct])
1291 tmp_flags="$EXTRA_KCFLAGS"
1292 EXTRA_KCFLAGS="-Werror"
1293 SPL_LINUX_TRY_COMPILE([
1294 #include <linux/mutex.h>
1296 struct mutex mtx __attribute__ ((unused));
1297 mtx.owner = current;
1300 AC_DEFINE(HAVE_MUTEX_OWNER_TASK_STRUCT, 1,
1301 [struct mutex owner is a task_struct])
1305 EXTRA_KCFLAGS="$tmp_flags"
1309 dnl # 2.6.18 API change,
1310 dnl # First introduced 'mutex_lock_nested()' in include/linux/mutex.h,
1311 dnl # as part of the mutex validator. Fallback to using 'mutex_lock()'
1312 dnl # if the mutex validator is disabled or otherwise unavailable.
1314 AC_DEFUN([SPL_AC_MUTEX_LOCK_NESTED], [
1315 AC_MSG_CHECKING([whether mutex_lock_nested() is available])
1316 SPL_LINUX_TRY_COMPILE([
1317 #include <linux/mutex.h>
1321 mutex_lock_nested(&mutex, 0);
1324 AC_DEFINE(HAVE_MUTEX_LOCK_NESTED, 1,
1325 [mutex_lock_nested() is available])
1332 dnl # 2.6.27 API change,
1333 dnl # on_each_cpu() uses 3 args, no 'retry' argument
1335 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
1336 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
1337 SPL_LINUX_TRY_COMPILE([
1338 #include <linux/smp.h>
1340 on_each_cpu(NULL, NULL, 0);
1343 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
1344 [on_each_cpu wants 3 args])
1351 dnl # 2.6.18 API change,
1352 dnl # kallsyms_lookup_name no longer exported
1354 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
1355 SPL_CHECK_SYMBOL_EXPORT(
1356 [kallsyms_lookup_name],
1358 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
1359 [kallsyms_lookup_name() is available])],
1364 dnl # Proposed API change,
1365 dnl # This symbol is not available in stock kernels. You may build a
1366 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1367 dnl # these symbols for use. If your already rolling a custom kernel for
1368 dnl # your environment this is recommended.
1370 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
1371 SPL_CHECK_SYMBOL_EXPORT(
1374 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
1375 [get_vmalloc_info() is available])],
1380 dnl # 2.6.17 API change
1381 dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
1382 dnl # next_zone() are introduced to simplify for_each_zone(). These symbols
1383 dnl # were exported in 2.6.17 for use by modules which was consistent with
1384 dnl # the previous implementation of for_each_zone(). From 2.6.18 - 2.6.19
1385 dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
1386 dnl # were dropped entirely leaving modules no way to directly iterate over
1387 dnl # the zone list. Because we need access to the zone helpers we check
1388 dnl # if the kernel contains the old or new implementation. Then we check
1389 dnl # to see if the symbols we need for each version are available. If they
1390 dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
1392 AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
1393 AC_MSG_CHECKING([whether symbol *_pgdat exist])
1394 grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
1396 if test $rc -eq 0; then
1397 AC_MSG_RESULT([yes])
1398 AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are available])
1405 dnl # Proposed API change,
1406 dnl # This symbol is not available in stock kernels. You may build a
1407 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1408 dnl # these symbols for use. If your already rolling a custom kernel for
1409 dnl # your environment this is recommended.
1411 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
1412 SPL_CHECK_SYMBOL_EXPORT(
1413 [first_online_pgdat],
1415 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
1416 [first_online_pgdat() is available])],
1421 dnl # Proposed API change,
1422 dnl # This symbol is not available in stock kernels. You may build a
1423 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1424 dnl # these symbols for use. If your already rolling a custom kernel for
1425 dnl # your environment this is recommended.
1427 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
1428 SPL_CHECK_SYMBOL_EXPORT(
1429 [next_online_pgdat],
1431 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
1432 [next_online_pgdat() is available])],
1437 dnl # Proposed API change,
1438 dnl # This symbol is not available in stock kernels. You may build a
1439 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1440 dnl # these symbols for use. If your already rolling a custom kernel for
1441 dnl # your environment this is recommended.
1443 AC_DEFUN([SPL_AC_NEXT_ZONE], [
1444 SPL_CHECK_SYMBOL_EXPORT(
1447 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
1448 [next_zone() is available])],
1453 dnl # 2.6.17 API change,
1454 dnl # See SPL_AC_PGDAT_HELPERS for details.
1456 AC_DEFUN([SPL_AC_PGDAT_LIST], [
1457 SPL_CHECK_SYMBOL_EXPORT(
1460 [AC_DEFINE(HAVE_PGDAT_LIST, 1,
1461 [pgdat_list is available])],
1466 dnl # 2.6.18 API change,
1467 dnl # First introduced global_page_state() support as an inline.
1469 AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
1470 AC_MSG_CHECKING([whether global_page_state() is available])
1471 SPL_LINUX_TRY_COMPILE([
1472 #include <linux/mm.h>
1474 unsigned long state __attribute__ ((unused));
1475 state = global_page_state(0);
1478 AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
1479 [global_page_state() is available])
1486 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1487 dnl # Public global zone stats now include a free page count. However
1488 dnl # the enumerated names of the counters have changed since this API
1489 dnl # was introduced. We need to deduce the corrent name to use. This
1490 dnl # replaces the priviate get_zone_counts() interface.
1492 dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
1493 dnl # is 2.6.30 as of when this was written.
1495 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
1496 AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
1497 SPL_LINUX_TRY_COMPILE([
1498 #include <linux/mm.h>
1500 enum zone_stat_item zsi __attribute__ ((unused));
1501 zsi = NR_FREE_PAGES;
1504 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
1505 [Page state NR_FREE_PAGES is available])
1512 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1513 dnl # Public global zone stats now include an inactive page count. However
1514 dnl # the enumerated names of the counters have changed since this API
1515 dnl # was introduced. We need to deduce the corrent name to use. This
1516 dnl # replaces the priviate get_zone_counts() interface.
1518 dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
1519 dnl # anonymous and file inactive pages. As of 2.6.28 it was split in
1520 dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
1522 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
1523 AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
1524 SPL_LINUX_TRY_COMPILE([
1525 #include <linux/mm.h>
1527 enum zone_stat_item zsi __attribute__ ((unused));
1531 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
1532 [Page state NR_INACTIVE is available])
1537 AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
1538 SPL_LINUX_TRY_COMPILE([
1539 #include <linux/mm.h>
1541 enum zone_stat_item zsi __attribute__ ((unused));
1542 zsi = NR_INACTIVE_ANON;
1545 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
1546 [Page state NR_INACTIVE_ANON is available])
1551 AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
1552 SPL_LINUX_TRY_COMPILE([
1553 #include <linux/mm.h>
1555 enum zone_stat_item zsi __attribute__ ((unused));
1556 zsi = NR_INACTIVE_FILE;
1559 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
1560 [Page state NR_INACTIVE_FILE is available])
1567 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1568 dnl # Public global zone stats now include an active page count. However
1569 dnl # the enumerated names of the counters have changed since this API
1570 dnl # was introduced. We need to deduce the corrent name to use. This
1571 dnl # replaces the priviate get_zone_counts() interface.
1573 dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
1574 dnl # anonymous and file active pages. As of 2.6.28 it was split in
1575 dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
1577 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
1578 AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
1579 SPL_LINUX_TRY_COMPILE([
1580 #include <linux/mm.h>
1582 enum zone_stat_item zsi __attribute__ ((unused));
1586 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
1587 [Page state NR_ACTIVE is available])
1592 AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
1593 SPL_LINUX_TRY_COMPILE([
1594 #include <linux/mm.h>
1596 enum zone_stat_item zsi __attribute__ ((unused));
1597 zsi = NR_ACTIVE_ANON;
1600 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
1601 [Page state NR_ACTIVE_ANON is available])
1606 AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
1607 SPL_LINUX_TRY_COMPILE([
1608 #include <linux/mm.h>
1610 enum zone_stat_item zsi __attribute__ ((unused));
1611 zsi = NR_ACTIVE_FILE;
1614 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
1615 [Page state NR_ACTIVE_FILE is available])
1622 dnl # Proposed API change for legacy kernels.
1623 dnl # This symbol is not available in older kernels. For kernels post
1624 dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
1625 dnl # page state information. This symbol is only used in legacy kernels
1626 dnl # any only as a last resort.
1628 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
1629 AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
1630 SPL_LINUX_TRY_COMPILE([
1632 #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
1633 #error "global_page_state needs NR_FREE_PAGES"
1636 #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
1637 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
1638 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
1639 #error "global_page_state needs NR_ACTIVE*"
1642 #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
1643 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
1644 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
1645 #error "global_page_state needs NR_INACTIVE*"
1651 AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
1652 [get_zone_counts() is needed])
1654 SPL_CHECK_SYMBOL_EXPORT(
1657 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
1658 [get_zone_counts() is available])],
1664 dnl # 2.6.27 API change,
1665 dnl # The user_path_dir() replaces __user_walk()
1667 AC_DEFUN([SPL_AC_USER_PATH_DIR], [
1668 SPL_CHECK_SYMBOL_EXPORT(
1671 [AC_DEFINE(HAVE_USER_PATH_DIR, 1,
1672 [user_path_dir() is available])],
1677 dnl # Symbol available in RHEL kernels not in stock kernels.
1679 AC_DEFUN([SPL_AC_SET_FS_PWD], [
1680 SPL_CHECK_SYMBOL_EXPORT(
1683 [AC_DEFINE(HAVE_SET_FS_PWD, 1,
1684 [set_fs_pwd() is available])],
1689 dnl # 2.6.25 API change,
1690 dnl # Simplied API by replacing mnt+dentry args with a single path arg.
1692 AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD],
1693 [AC_MSG_CHECKING([whether set_fs_pwd() wants 2 args])
1694 SPL_LINUX_TRY_COMPILE([
1695 #include <linux/sched.h>
1696 #include <linux/fs_struct.h>
1698 set_fs_pwd(NULL, NULL);
1701 AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1,
1702 [set_fs_pwd() wants 2 args])
1709 dnl # SLES API change, never adopted in mainline,
1710 dnl # Third 'struct vfsmount *' argument removed.
1712 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
1713 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
1714 SPL_LINUX_TRY_COMPILE([
1715 #include <linux/fs.h>
1717 vfs_unlink(NULL, NULL);
1720 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
1721 [vfs_unlink() wants 2 args])
1728 dnl # SLES API change, never adopted in mainline,
1729 dnl # Third and sixth 'struct vfsmount *' argument removed.
1731 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
1732 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
1733 SPL_LINUX_TRY_COMPILE([
1734 #include <linux/fs.h>
1736 vfs_rename(NULL, NULL, NULL, NULL);
1739 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
1740 [vfs_rename() wants 4 args])
1747 dnl # 2.6.36 API change,
1748 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
1749 dnl # a spinlock_t to improve the fastpath performance.
1751 AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
1752 AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
1753 tmp_flags="$EXTRA_KCFLAGS"
1754 EXTRA_KCFLAGS="-Werror"
1755 SPL_LINUX_TRY_COMPILE([
1756 #include <linux/sched.h>
1757 #include <linux/fs_struct.h>
1759 struct fs_struct fs;
1760 spin_lock_init(&fs.lock);
1763 AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
1764 [struct fs_struct uses spinlock_t])
1768 EXTRA_KCFLAGS="$tmp_flags"
1772 dnl # 2.6.29 API change,
1773 dnl # check whether 'struct cred' exists
1775 AC_DEFUN([SPL_AC_CRED_STRUCT], [
1776 AC_MSG_CHECKING([whether struct cred exists])
1777 SPL_LINUX_TRY_COMPILE([
1778 #include <linux/cred.h>
1780 struct cred *cr __attribute__ ((unused));
1784 AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
1791 dnl # Custom SPL patch may export this symbol.
1793 AC_DEFUN([SPL_AC_GROUPS_SEARCH], [
1794 SPL_CHECK_SYMBOL_EXPORT(
1797 [AC_DEFINE(HAVE_GROUPS_SEARCH, 1,
1798 [groups_search() is available])],
1803 dnl # 2.6.x API change,
1804 dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
1806 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT], [
1807 SPL_CHECK_SYMBOL_EXPORT(
1808 [__put_task_struct],
1810 [AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1811 [__put_task_struct() is available])],
1816 dnl # 2.6.32 API change,
1817 dnl # Unused 'struct file *' removed from prototype.
1819 AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
1820 AC_MSG_CHECKING([whether proc_handler() wants 5 args])
1821 SPL_LINUX_TRY_COMPILE([
1822 #include <linux/sysctl.h>
1824 proc_dostring(NULL, 0, NULL, NULL, NULL);
1827 AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
1828 [proc_handler() wants 5 args])
1835 dnl # 2.6.x API change,
1836 dnl # kvasprintf() function added.
1838 AC_DEFUN([SPL_AC_KVASPRINTF], [
1839 SPL_CHECK_SYMBOL_EXPORT(
1842 [AC_DEFINE(HAVE_KVASPRINTF, 1,
1843 [kvasprintf() is available])],
1848 dnl # 2.6.29 API change,
1849 dnl # vfs_fsync() funcation added, prior to this use file_fsync().
1851 AC_DEFUN([SPL_AC_VFS_FSYNC], [
1852 SPL_CHECK_SYMBOL_EXPORT(
1855 [AC_DEFINE(HAVE_VFS_FSYNC, 1, [vfs_fsync() is available])],
1860 dnl # 2.6.35 API change,
1861 dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
1863 AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
1864 AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
1865 SPL_LINUX_TRY_COMPILE([
1866 #include <linux/fs.h>
1871 AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
1878 dnl # 2.6.33 API change. Also backported in RHEL5 as of 2.6.18-190.el5.
1879 dnl # Earlier versions of rwsem_is_locked() were inline and had a race
1880 dnl # condition. The fixed version is exported as a symbol. The race
1881 dnl # condition is fixed by acquiring sem->wait_lock, so we must not
1882 dnl # call that version while holding sem->wait_lock.
1884 AC_DEFUN([SPL_AC_EXPORTED_RWSEM_IS_LOCKED], [
1885 SPL_CHECK_SYMBOL_EXPORT(
1887 [lib/rwsem-spinlock.c],
1888 [AC_DEFINE(RWSEM_IS_LOCKED_TAKES_WAIT_LOCK, 1,
1889 [rwsem_is_locked() acquires sem->wait_lock])],
1894 dnl # 2.6.37 API compat,
1895 dnl # The function invalidate_inodes() is no longer exported by the kernel.
1896 dnl # The prototype however is still available which means it is safe
1897 dnl # to acquire the symbol's address using spl_kallsyms_lookup_name().
1899 dnl # The Proxmox VE kernel contains a patch which renames the function
1900 dnl # invalidate_inodes() to invalidate_inodes_check(). In the process
1901 dnl # it adds a 'check' argument and a '#define invalidate_inodes(x)'
1902 dnl # compatibility wrapper for legacy callers. Therefore, if either
1903 dnl # of these functions are exported invalidate_inodes() can be
1906 AC_DEFUN([SPL_AC_KERNEL_INVALIDATE_INODES], [
1907 SPL_CHECK_SYMBOL_EXPORT(
1908 [invalidate_inodes],
1910 [AC_DEFINE(HAVE_INVALIDATE_INODES, 1,
1911 [invalidate_inodes() is available])],
1913 SPL_CHECK_SYMBOL_EXPORT(
1914 [invalidate_inodes_check],
1916 [AC_DEFINE(HAVE_INVALIDATE_INODES_CHECK, 1,
1917 [invalidate_inodes_check() is available])],
1922 dnl # 2.6.39 API compat,
1923 dnl # The function invalidate_inodes() now take 2 arguments. The second
1924 dnl # 'kill_dirty' argument describes how invalidate_inodes() should
1925 dnl # handle dirty inodes. Only when set will dirty inodes be discarded,
1926 dnl # otherwise they will be handled as busy.
1928 dnl # Unfortunately, we don't have access to the invalidate_inodes()
1929 dnl # prototype so it's not easy to check how many arguments it takes.
1930 dnl # However, this change was done for the benefit of invalidate_device()
1931 dnl # which also added an argument. The invalidate_device() symbol does
1932 dnl # exist in the development headers so if it takes two arguments we
1933 dnl # can fairly safely infer that invalidate_inodes() takes two arguments
1934 dnl # as well. See commit 93b270f76e7ef3b81001576860c2701931cdc78b.
1936 AC_DEFUN([SPL_AC_KERNEL_2ARGS_INVALIDATE_INODES],
1937 [AC_MSG_CHECKING([whether invalidate_inodes() wants 2 args])
1938 SPL_LINUX_TRY_COMPILE([
1939 #include <linux/fs.h>
1941 return __invalidate_device(NULL, 0);
1944 AC_DEFINE(HAVE_2ARGS_INVALIDATE_INODES, 1,
1945 [invalidate_inodes() wants 2 args])
1952 dnl # 2.6.xx API compat,
1953 dnl # There currently exists no exposed API to partially shrink the dcache.
1954 dnl # The expected mechanism to shrink the cache is a registered shrinker
1955 dnl # which is called during memory pressure.
1957 AC_DEFUN([SPL_AC_SHRINK_DCACHE_MEMORY], [
1958 SPL_CHECK_SYMBOL_EXPORT(
1959 [shrink_dcache_memory],
1961 [AC_DEFINE(HAVE_SHRINK_DCACHE_MEMORY, 1,
1962 [shrink_dcache_memory() is available])],
1967 dnl # 2.6.xx API compat,
1968 dnl # There currently exists no exposed API to partially shrink the icache.
1969 dnl # The expected mechanism to shrink the cache is a registered shrinker
1970 dnl # which is called during memory pressure.
1972 AC_DEFUN([SPL_AC_SHRINK_ICACHE_MEMORY], [
1973 SPL_CHECK_SYMBOL_EXPORT(
1974 [shrink_icache_memory],
1976 [AC_DEFINE(HAVE_SHRINK_ICACHE_MEMORY, 1,
1977 [shrink_icache_memory() is available])],
1982 dnl # 2.6.39 API compat,
1983 dnl # The path_lookup() function has been renamed to kern_path_parent()
1984 dnl # and the flags argument has been removed. The only behavior now
1985 dnl # offered is that of LOOKUP_PARENT. The spl already always passed
1986 dnl # this flag so dropping the flag does not impact us.
1988 AC_DEFUN([SPL_AC_KERN_PATH_PARENT_HEADER], [
1989 SPL_CHECK_SYMBOL_HEADER(
1991 [int kern_path_parent(const char \*, struct nameidata \*)],
1992 [include/linux/namei.h],
1993 [AC_DEFINE(HAVE_KERN_PATH_PARENT_HEADER, 1,
1994 [kern_path_parent() is available])],
1999 dnl # 3.1 API compat,
2000 dnl # The kern_path_parent() symbol is no longer exported by the kernel.
2001 dnl # However, it remains the prefered interface and since we still have
2002 dnl # access to the prototype we dynamically lookup the required address.
2004 AC_DEFUN([SPL_AC_KERN_PATH_PARENT_SYMBOL], [
2005 SPL_CHECK_SYMBOL_EXPORT(
2008 [AC_DEFINE(HAVE_KERN_PATH_PARENT_SYMBOL, 1,
2009 [kern_path_parent() is available])],
2014 dnl # 2.6.39 API compat,
2015 dnl # The function zlib_deflate_workspacesize() now take 2 arguments.
2016 dnl # This was done to avoid always having to allocate the maximum size
2017 dnl # workspace (268K). The caller can now specific the windowBits and
2018 dnl # memLevel compression parameters to get a smaller workspace.
2020 AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE],
2021 [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args])
2022 SPL_LINUX_TRY_COMPILE([
2023 #include <linux/zlib.h>
2025 return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL);
2028 AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1,
2029 [zlib_deflate_workspacesize() wants 2 args])
2036 dnl # 2.6.39 API change,
2037 dnl # Shrinker adjust to use common shrink_control structure.
2039 AC_DEFUN([SPL_AC_SHRINK_CONTROL_STRUCT], [
2040 AC_MSG_CHECKING([whether struct shrink_control exists])
2041 SPL_LINUX_TRY_COMPILE([
2042 #include <linux/mm.h>
2044 struct shrink_control sc __attribute__ ((unused));
2047 sc.gfp_mask = GFP_KERNEL;
2050 AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
2051 [struct shrink_control exists])
2058 dnl # 3.1 API Change
2060 dnl # The rw_semaphore.wait_lock member was changed from spinlock_t to
2061 dnl # raw_spinlock_t at commit ddb6c9b58a19edcfac93ac670b066c836ff729f1.
2063 AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
2064 AC_MSG_CHECKING([whether struct rw_semaphore member wait_lock is raw])
2065 tmp_flags="$EXTRA_KCFLAGS"
2066 EXTRA_KCFLAGS="-Werror"
2067 SPL_LINUX_TRY_COMPILE([
2068 #include <linux/rwsem.h>
2070 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
2071 raw_spinlock_t dummy_lock __attribute__ ((unused));
2072 dummy_semaphore.wait_lock = dummy_lock;
2075 AC_DEFINE(RWSEM_SPINLOCK_IS_RAW, 1,
2076 [struct rw_semaphore member wait_lock is raw_spinlock_t])
2080 EXTRA_KCFLAGS="$tmp_flags"