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 if test "${LINUX_OBJ}" != "${LINUX}"; then
13 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
15 AC_SUBST(KERNELMAKE_PARAMS)
17 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes"
18 AC_SUBST(KERNELCPPFLAGS)
23 SPL_AC_DEBUG_KMEM_TRACKING
25 SPL_AC_ATOMIC_SPINLOCK
26 SPL_AC_SHRINKER_CALLBACK
31 SPL_AC_MUTEX_OWNER_TASK_STRUCT
32 SPL_AC_KALLSYMS_LOOKUP_NAME
33 SPL_AC_GET_VMALLOC_INFO
35 SPL_AC_FIRST_ONLINE_PGDAT
36 SPL_AC_NEXT_ONLINE_PGDAT
39 SPL_AC_GLOBAL_PAGE_STATE
40 SPL_AC_ZONE_STAT_ITEM_FREE
41 SPL_AC_ZONE_STAT_ITEM_INACTIVE
42 SPL_AC_ZONE_STAT_ITEM_ACTIVE
43 SPL_AC_GET_ZONE_COUNTS
46 SPL_AC_SET_FS_PWD_WITH_CONST
47 SPL_AC_2ARGS_VFS_UNLINK
48 SPL_AC_4ARGS_VFS_RENAME
50 SPL_AC_2ARGS_VFS_FSYNC
51 SPL_AC_INODE_TRUNCATE_RANGE
52 SPL_AC_FS_STRUCT_SPINLOCK
56 SPL_AC_PUT_TASK_STRUCT
57 SPL_AC_5ARGS_PROC_HANDLER
59 SPL_AC_EXPORTED_RWSEM_IS_LOCKED
60 SPL_AC_KERNEL_FALLOCATE
61 SPL_AC_SHRINK_DCACHE_MEMORY
62 SPL_AC_SHRINK_ICACHE_MEMORY
64 SPL_AC_CONFIG_KALLSYMS
65 SPL_AC_CONFIG_ZLIB_INFLATE
66 SPL_AC_CONFIG_ZLIB_DEFLATE
67 SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
68 SPL_AC_SHRINK_CONTROL_STRUCT
69 SPL_AC_RWSEM_SPINLOCK_IS_RAW
70 SPL_AC_SCHED_RT_HEADER
71 SPL_AC_2ARGS_VFS_GETATTR
73 SPL_AC_KMEM_CACHE_ALLOCFLAGS
77 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
78 modpost=$LINUX/scripts/Makefile.modpost
79 AC_MSG_CHECKING([kernel file name for module symbols])
80 if test "x$enable_linux_builtin" != xyes -a -f "$modpost"; then
81 if grep -q Modules.symvers $modpost; then
82 LINUX_SYMBOLS=Modules.symvers
84 LINUX_SYMBOLS=Module.symvers
87 if ! test -f "$LINUX_OBJ/$LINUX_SYMBOLS"; then
89 *** Please make sure the kernel devel package for your distribution
90 *** is installed. If you are building with a custom kernel, make sure the
91 *** kernel is configured, built, and the '--with-linux=PATH' configure
92 *** option refers to the location of the kernel source.])
97 AC_MSG_RESULT($LINUX_SYMBOLS)
98 AC_SUBST(LINUX_SYMBOLS)
101 AC_DEFUN([SPL_AC_KERNEL], [
103 AS_HELP_STRING([--with-linux=PATH],
104 [Path to kernel source]),
105 [kernelsrc="$withval"])
107 AC_ARG_WITH([linux-obj],
108 AS_HELP_STRING([--with-linux-obj=PATH],
109 [Path to kernel build objects]),
110 [kernelbuild="$withval"])
112 AC_MSG_CHECKING([kernel source directory])
113 if test -z "$kernelsrc"; then
114 if test -e "/lib/modules/$(uname -r)/source"; then
115 headersdir="/lib/modules/$(uname -r)/source"
116 sourcelink=$(readlink -f "$headersdir")
117 elif test -e "/lib/modules/$(uname -r)/build"; then
118 headersdir="/lib/modules/$(uname -r)/build"
119 sourcelink=$(readlink -f "$headersdir")
121 sourcelink=$(ls -1d /usr/src/kernels/* \
123 2>/dev/null | grep -v obj | tail -1)
126 if test -n "$sourcelink" && test -e ${sourcelink}; then
127 kernelsrc=`readlink -f ${sourcelink}`
129 kernelsrc="[Not found]"
132 if test "$kernelsrc" = "NONE"; then
137 AC_MSG_RESULT([$kernelsrc])
138 if test ! -d "$kernelsrc"; then
140 *** Please make sure the kernel devel package for your distribution
141 *** is installed and then try again. If that fails, you can specify the
142 *** location of the kernel source with the '--with-linux=PATH' option.])
145 AC_MSG_CHECKING([kernel build directory])
146 if test -z "$kernelbuild"; then
147 if test -e "/lib/modules/$(uname -r)/build"; then
148 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
149 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
150 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
151 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
152 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
153 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
154 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
156 kernelbuild=${kernelsrc}
159 AC_MSG_RESULT([$kernelbuild])
161 AC_MSG_CHECKING([kernel source version])
162 utsrelease1=$kernelbuild/include/linux/version.h
163 utsrelease2=$kernelbuild/include/linux/utsrelease.h
164 utsrelease3=$kernelbuild/include/generated/utsrelease.h
165 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
166 utsrelease=linux/version.h
167 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
168 utsrelease=linux/utsrelease.h
169 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
170 utsrelease=generated/utsrelease.h
173 if test "$utsrelease"; then
174 kernsrcver=`(echo "#include <$utsrelease>";
175 echo "kernsrcver=UTS_RELEASE") |
176 cpp -I $kernelbuild/include |
177 grep "^kernsrcver=" | cut -d \" -f 2`
179 if test -z "$kernsrcver"; then
180 AC_MSG_RESULT([Not found])
181 AC_MSG_ERROR([*** Cannot determine kernel version.])
184 AC_MSG_RESULT([Not found])
185 if test "x$enable_linux_builtin" != xyes; then
186 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
189 *** Cannot find UTS_RELEASE definition.
190 *** Please run 'make prepare' inside the kernel source tree.])
194 AC_MSG_RESULT([$kernsrcver])
197 LINUX_OBJ=${kernelbuild}
198 LINUX_VERSION=${kernsrcver}
202 AC_SUBST(LINUX_VERSION)
204 SPL_AC_MODULE_SYMVERS
208 dnl # Default SPL user configuration
210 AC_DEFUN([SPL_AC_CONFIG_USER], [])
213 dnl # Check for rpm+rpmbuild to build RPM packages. If these tools
214 dnl # are missing, it is non-fatal, but you will not be able to build
215 dnl # RPM packages and will be warned if you try too.
217 dnl # By default, the generic spec file will be used because it requires
218 dnl # minimal dependencies. Distribution specific spec files can be
219 dnl # placed under the 'rpm/<distribution>' directory and enabled using
220 dnl # the --with-spec=<distribution> configure option.
222 AC_DEFUN([SPL_AC_RPM], [
226 AC_MSG_CHECKING([whether $RPM is available])
227 AS_IF([tmp=$($RPM --version 2>/dev/null)], [
228 RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
230 AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
233 AC_MSG_RESULT([$HAVE_RPM])
236 AC_MSG_CHECKING([whether $RPMBUILD is available])
237 AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
238 RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
240 AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
243 AC_MSG_RESULT([$HAVE_RPMBUILD])
246 RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1" --define "$(DEBUG_LOG) 1" --define "$(DEBUG_KMEM) 1" --define "$(DEBUG_KMEM_TRACKING) 1"'
248 RPM_DEFINE_KMOD='--define "kernels $(LINUX_VERSION)"'
251 SRPM_DEFINE_COMMON='--define "build_src_rpm 1"'
256 RPM_SPEC_DIR="rpm/generic"
258 AS_HELP_STRING([--with-spec=SPEC],
259 [Spec files 'generic|fedora']),
260 [RPM_SPEC_DIR="rpm/$withval"])
262 AC_MSG_CHECKING([whether spec files are available])
263 AC_MSG_RESULT([yes ($RPM_SPEC_DIR/*.spec.in)])
267 AC_SUBST(RPM_VERSION)
269 AC_SUBST(HAVE_RPMBUILD)
271 AC_SUBST(RPMBUILD_VERSION)
273 AC_SUBST(RPM_SPEC_DIR)
274 AC_SUBST(RPM_DEFINE_UTIL)
275 AC_SUBST(RPM_DEFINE_KMOD)
276 AC_SUBST(RPM_DEFINE_DKMS)
277 AC_SUBST(RPM_DEFINE_COMMON)
278 AC_SUBST(SRPM_DEFINE_UTIL)
279 AC_SUBST(SRPM_DEFINE_KMOD)
280 AC_SUBST(SRPM_DEFINE_DKMS)
281 AC_SUBST(SRPM_DEFINE_COMMON)
285 dnl # Check for dpkg+dpkg-buildpackage to build DEB packages. If these
286 dnl # tools are missing it is non-fatal but you will not be able to build
287 dnl # DEB packages and will be warned if you try too.
289 AC_DEFUN([SPL_AC_DPKG], [
291 DPKGBUILD=dpkg-buildpackage
293 AC_MSG_CHECKING([whether $DPKG is available])
294 AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
295 DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
297 AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
300 AC_MSG_RESULT([$HAVE_DPKG])
303 AC_MSG_CHECKING([whether $DPKGBUILD is available])
304 AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
305 DPKGBUILD_VERSION=$(echo $tmp | \
306 $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
308 AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
311 AC_MSG_RESULT([$HAVE_DPKGBUILD])
316 AC_SUBST(DPKG_VERSION)
318 AC_SUBST(HAVE_DPKGBUILD)
320 AC_SUBST(DPKGBUILD_VERSION)
324 dnl # Until native packaging for various different packing systems
325 dnl # can be added the least we can do is attempt to use alien to
326 dnl # convert the RPM packages to the needed package type. This is
327 dnl # a hack but so far it has worked reasonable well.
329 AC_DEFUN([SPL_AC_ALIEN], [
332 AC_MSG_CHECKING([whether $ALIEN is available])
333 AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
334 ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
336 AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
339 AC_MSG_RESULT([$HAVE_ALIEN])
344 AC_SUBST(ALIEN_VERSION)
348 dnl # Using the VENDOR tag from config.guess set the default
349 dnl # package type for 'make pkg': (rpm | deb | tgz)
351 AC_DEFUN([SPL_AC_DEFAULT_PACKAGE], [
352 AC_MSG_CHECKING([linux distribution])
353 if test -f /etc/toss-release ; then
355 elif test -f /etc/fedora-release ; then
357 elif test -f /etc/redhat-release ; then
359 elif test -f /etc/gentoo-release ; then
361 elif test -f /etc/arch-release ; then
363 elif test -f /etc/SuSE-release ; then
365 elif test -f /etc/slackware-version ; then
367 elif test -f /etc/lunar.release ; then
369 elif test -f /etc/lsb-release ; then
371 elif test -f /etc/debian_version ; then
376 AC_MSG_RESULT([$VENDOR])
379 AC_MSG_CHECKING([default package type])
381 toss) DEFAULT_PACKAGE=rpm ;;
382 redhat) DEFAULT_PACKAGE=rpm ;;
383 fedora) DEFAULT_PACKAGE=rpm ;;
384 gentoo) DEFAULT_PACKAGE=tgz ;;
385 arch) DEFAULT_PACKAGE=tgz ;;
386 sles) DEFAULT_PACKAGE=rpm ;;
387 slackware) DEFAULT_PACKAGE=tgz ;;
388 lunar) DEFAULT_PACKAGE=tgz ;;
389 ubuntu) DEFAULT_PACKAGE=deb ;;
390 debian) DEFAULT_PACKAGE=deb ;;
391 *) DEFAULT_PACKAGE=rpm ;;
394 AC_MSG_RESULT([$DEFAULT_PACKAGE])
395 AC_SUBST(DEFAULT_PACKAGE)
399 dnl # Default SPL user configuration
401 AC_DEFUN([SPL_AC_PACKAGE], [
402 SPL_AC_DEFAULT_PACKAGE
408 AC_DEFUN([SPL_AC_LICENSE], [
409 AC_MSG_CHECKING([spl author])
410 AC_MSG_RESULT([$SPL_META_AUTHOR])
412 AC_MSG_CHECKING([spl license])
413 AC_MSG_RESULT([$SPL_META_LICENSE])
416 AC_DEFUN([SPL_AC_CONFIG], [
418 AC_ARG_WITH([config],
419 AS_HELP_STRING([--with-config=CONFIG],
420 [Config file 'kernel|user|all|srpm']),
421 [SPL_CONFIG="$withval"])
422 AC_ARG_ENABLE([linux-builtin],
423 [AC_HELP_STRING([--enable-linux-builtin],
424 [Configure for builtin in-tree kernel modules @<:@default=no@:>@])],
426 [enable_linux_builtin=no])
428 AC_MSG_CHECKING([spl config])
429 AC_MSG_RESULT([$SPL_CONFIG]);
432 case "$SPL_CONFIG" in
433 kernel) SPL_AC_CONFIG_KERNEL ;;
434 user) SPL_AC_CONFIG_USER ;;
435 all) SPL_AC_CONFIG_KERNEL
436 SPL_AC_CONFIG_USER ;;
439 AC_MSG_RESULT([Error!])
440 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
441 user kernel|user|all|srpm]) ;;
444 AM_CONDITIONAL([CONFIG_USER],
445 [test "$SPL_CONFIG" = user -o "$SPL_CONFIG" = all])
446 AM_CONDITIONAL([CONFIG_KERNEL],
447 [test "$SPL_CONFIG" = kernel -o "$SPL_CONFIG" = all] &&
448 [test "x$enable_linux_builtin" != xyes ])
452 dnl # Enable if the SPL should be compiled with internal debugging enabled.
453 dnl # By default this support is disabled.
455 AC_DEFUN([SPL_AC_DEBUG], [
456 AC_MSG_CHECKING([whether debugging is enabled])
457 AC_ARG_ENABLE([debug],
458 [AS_HELP_STRING([--enable-debug],
459 [Enable generic debug support @<:@default=no@:>@])],
463 AS_IF([test "x$enable_debug" = xyes],
465 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
466 DEBUG_CFLAGS="-DDEBUG -Werror"
467 DEBUG_SPL="_with_debug"
469 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
470 DEBUG_CFLAGS="-DNDEBUG"
471 DEBUG_SPL="_without_debug"
474 AC_SUBST(DEBUG_CFLAGS)
476 AC_MSG_RESULT([$enable_debug])
480 dnl # Enabled by default it provides a basic debug log infrastructure.
481 dnl # Each subsystem registers itself with a name and logs messages
482 dnl # using predefined types. If the debug mask it set to allow the
483 dnl # message type it will be written to the internal log. The log
484 dnl # can be dumped to a file by echoing 1 to the 'dump' proc entry,
485 dnl # after dumping the log it must be decoded using the spl utility.
487 dnl # echo 1 >/proc/sys/kernel/spl/debug/dump
488 dnl # spl /tmp/spl-log.xxx.yyy /tmp/spl-log.xxx.yyy.txt
490 AC_DEFUN([SPL_AC_DEBUG_LOG], [
491 AC_ARG_ENABLE([debug-log],
492 [AS_HELP_STRING([--enable-debug-log],
493 [Enable basic debug logging @<:@default=yes@:>@])],
495 [enable_debug_log=yes])
497 AS_IF([test "x$enable_debug_log" = xyes],
499 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_LOG"
500 DEBUG_LOG="_with_debug_log"
501 AC_DEFINE([DEBUG_LOG], [1],
502 [Define to 1 to enable basic debug logging])
504 DEBUG_LOG="_without_debug_log"
508 AC_MSG_CHECKING([whether basic debug logging is enabled])
509 AC_MSG_RESULT([$enable_debug_log])
513 dnl # Enabled by default it provides a minimal level of memory tracking.
514 dnl # A total count of bytes allocated is kept for each alloc and free.
515 dnl # Then at module unload time a report to the console will be printed
516 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
517 dnl # and provide an easy way to inspect the kmem based slab.
519 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
520 AC_ARG_ENABLE([debug-kmem],
521 [AS_HELP_STRING([--enable-debug-kmem],
522 [Enable basic kmem accounting @<:@default=yes@:>@])],
524 [enable_debug_kmem=yes])
526 AS_IF([test "x$enable_debug_kmem" = xyes],
528 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
529 DEBUG_KMEM="_with_debug_kmem"
530 AC_DEFINE([DEBUG_KMEM], [1],
531 [Define to 1 to enable basic kmem accounting])
533 DEBUG_KMEM="_without_debug_kmem"
537 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
538 AC_MSG_RESULT([$enable_debug_kmem])
542 dnl # Disabled by default it provides detailed memory tracking. This
543 dnl # feature also requires --enable-debug-kmem to be set. When enabled
544 dnl # not only will total bytes be tracked but also the location of every
545 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
546 dnl # addresses and where they were allocated will be dumped to the console.
547 dnl # Enabling this feature has a significant impact on performance but it
548 dnl # makes finding memory leaks pretty straight forward.
550 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
551 AC_ARG_ENABLE([debug-kmem-tracking],
552 [AS_HELP_STRING([--enable-debug-kmem-tracking],
553 [Enable detailed kmem tracking @<:@default=no@:>@])],
555 [enable_debug_kmem_tracking=no])
557 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
559 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
560 DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
561 AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
562 [Define to 1 to enable detailed kmem tracking])
564 DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
567 AC_SUBST(DEBUG_KMEM_TRACKING)
568 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
569 AC_MSG_RESULT([$enable_debug_kmem_tracking])
573 dnl # SPL_LINUX_CONFTEST
575 AC_DEFUN([SPL_LINUX_CONFTEST], [
576 cat confdefs.h - <<_ACEOF >conftest.c
582 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
584 m4_define([SPL_LANG_PROGRAM], [
589 dnl Do *not* indent the following line: there may be CPP directives.
590 dnl Don't move the `;' right after for the same reason.
598 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
600 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
601 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
602 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
603 echo "obj-m := conftest.o" >build/Makefile
605 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
607 [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 $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
609 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
615 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
617 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
618 [SPL_LINUX_COMPILE_IFELSE(
619 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
621 [test -s build/conftest.o],
626 dnl # SPL_CHECK_SYMBOL_EXPORT
627 dnl # check symbol exported or not
629 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT], [
630 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
631 $LINUX_OBJ/Module*.symvers 2>/dev/null
633 if test $rc -ne 0; then
636 grep -q -E "EXPORT_SYMBOL.*($1)" \
637 "$LINUX_OBJ/$file" 2>/dev/null
639 if test $rc -eq 0; then
644 if test $export -eq 0; then :
655 dnl # SPL_LINUX_TRY_COMPILE_SYMBOL
656 dnl # like SPL_LINUX_TRY_COMPILE, except SPL_CHECK_SYMBOL_EXPORT
657 dnl # is called if not compiling for builtin
659 AC_DEFUN([SPL_LINUX_TRY_COMPILE_SYMBOL], [
660 SPL_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
661 if test $rc -ne 0; then :
664 if test "x$enable_linux_builtin" != xyes; then
665 SPL_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
667 if test $rc -ne 0; then :
676 dnl # SPL_CHECK_SYMBOL_HEADER
677 dnl # check if a symbol prototype is defined in listed headers.
679 AC_DEFUN([SPL_CHECK_SYMBOL_HEADER], [
680 AC_MSG_CHECKING([whether symbol $1 exists in header])
683 grep -q "$2" "$LINUX/$file" 2>/dev/null
685 if test $rc -eq 0; then
690 if test $header -eq 0; then
700 dnl # SPL_CHECK_HEADER
701 dnl # check whether header exists and define HAVE_$2_HEADER
703 AC_DEFUN([SPL_CHECK_HEADER],
704 [AC_MSG_CHECKING([whether header $1 exists])
705 SPL_LINUX_TRY_COMPILE([
710 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
720 dnl # Basic toolchain sanity check. Verify that kernel modules can
721 dnl # be built and which symbols can be used.
723 AC_DEFUN([SPL_AC_TEST_MODULE],
724 [AC_MSG_CHECKING([whether modules can be built])
725 SPL_LINUX_TRY_COMPILE([],[],[
729 if test "x$enable_linux_builtin" != xyes; then
730 AC_MSG_ERROR([*** Unable to build an empty module.])
733 *** Unable to build an empty module.
734 *** Please run 'make scripts' inside the kernel source tree.])
740 #include "$LINUX/include/linux/license.h"
742 return !license_is_gpl_compatible("$SPL_META_LICENSE");
745 AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
746 [Define to 1 if GPL-only symbols can be used])
752 dnl # Use the atomic implemenation based on global spinlocks. This
753 dnl # should only be needed by 32-bit kernels which do not provide
754 dnl # the atomic64_* API. It may be optionally enabled as a fallback
755 dnl # if problems are observed with the direct mapping to the native
756 dnl # Linux atomic operations. You may not disable atomic spinlocks
757 dnl # if you kernel does not an atomic64_* API.
759 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
760 AC_ARG_ENABLE([atomic-spinlocks],
761 [AS_HELP_STRING([--enable-atomic-spinlocks],
762 [Atomic types use spinlocks @<:@default=check@:>@])],
764 [enable_atomic_spinlocks=check])
766 SPL_LINUX_TRY_COMPILE([
767 #include <linux/fs.h>
769 atomic64_t *ptr __attribute__ ((unused));
772 AC_DEFINE(HAVE_ATOMIC64_T, 1,
773 [kernel defines atomic64_t])
778 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
779 AS_IF([test "x$have_atomic64_t" = xyes], [
780 enable_atomic_spinlocks=no
782 enable_atomic_spinlocks=yes
786 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
787 AC_DEFINE([ATOMIC_SPINLOCK], [1],
788 [Atomic types use spinlocks])
790 AS_IF([test "x$have_atomic64_t" = xno], [
792 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
796 AC_MSG_CHECKING([whether atomic types use spinlocks])
797 AC_MSG_RESULT([$enable_atomic_spinlocks])
799 AC_MSG_CHECKING([whether kernel defines atomic64_t])
800 AC_MSG_RESULT([$have_atomic64_t])
803 AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
804 tmp_flags="$EXTRA_KCFLAGS"
805 EXTRA_KCFLAGS="-Werror"
807 dnl # 2.6.23 to 2.6.34 API change
808 dnl # ->shrink(int nr_to_scan, gfp_t gfp_mask)
810 AC_MSG_CHECKING([whether old 2-argument shrinker exists])
811 SPL_LINUX_TRY_COMPILE([
812 #include <linux/mm.h>
814 int shrinker_cb(int nr_to_scan, gfp_t gfp_mask);
816 struct shrinker cache_shrinker = {
817 .shrink = shrinker_cb,
818 .seeks = DEFAULT_SEEKS,
820 register_shrinker(&cache_shrinker);
823 AC_DEFINE(HAVE_2ARGS_OLD_SHRINKER_CALLBACK, 1,
824 [old shrinker callback wants 2 args])
828 dnl # 2.6.35 - 2.6.39 API change
829 dnl # ->shrink(struct shrinker *,
830 dnl # int nr_to_scan, gfp_t gfp_mask)
832 AC_MSG_CHECKING([whether old 3-argument shrinker exists])
833 SPL_LINUX_TRY_COMPILE([
834 #include <linux/mm.h>
836 int shrinker_cb(struct shrinker *, int nr_to_scan,
839 struct shrinker cache_shrinker = {
840 .shrink = shrinker_cb,
841 .seeks = DEFAULT_SEEKS,
843 register_shrinker(&cache_shrinker);
846 AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1,
847 [old shrinker callback wants 3 args])
851 dnl # 3.0 - 3.11 API change
852 dnl # ->shrink(struct shrinker *,
853 dnl # struct shrink_control *sc)
856 [whether new 2-argument shrinker exists])
857 SPL_LINUX_TRY_COMPILE([
858 #include <linux/mm.h>
860 int shrinker_cb(struct shrinker *,
861 struct shrink_control *sc);
863 struct shrinker cache_shrinker = {
864 .shrink = shrinker_cb,
865 .seeks = DEFAULT_SEEKS,
867 register_shrinker(&cache_shrinker);
870 AC_DEFINE(HAVE_2ARGS_NEW_SHRINKER_CALLBACK, 1,
871 [new shrinker callback wants 2 args])
875 dnl # 3.12 API change,
876 dnl # ->shrink() is logically split in to
877 dnl # ->count_objects() and ->scan_objects()
880 [whether ->count_objects callback exists])
881 SPL_LINUX_TRY_COMPILE([
882 #include <linux/mm.h>
884 unsigned long shrinker_cb(
886 struct shrink_control *sc);
888 struct shrinker cache_shrinker = {
889 .count_objects = shrinker_cb,
890 .scan_objects = shrinker_cb,
891 .seeks = DEFAULT_SEEKS,
893 register_shrinker(&cache_shrinker);
896 AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
897 1, [->count_objects exists])
904 EXTRA_KCFLAGS="$tmp_flags"
908 dnl # 2.6.33 API change,
909 dnl # Removed .ctl_name from struct ctl_table.
911 AC_DEFUN([SPL_AC_CTL_NAME], [
912 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
913 SPL_LINUX_TRY_COMPILE([
914 #include <linux/sysctl.h>
916 struct ctl_table ctl __attribute__ ((unused));
920 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
927 dnl # 2.6.29 API change,
928 dnl # Adaptive mutexs were introduced which track the mutex owner. The
929 dnl # mutex wrappers leverage this functionality to avoid tracking the
930 dnl # owner multipe times.
932 AC_DEFUN([SPL_AC_MUTEX_OWNER], [
933 AC_MSG_CHECKING([whether struct mutex has owner])
934 SPL_LINUX_TRY_COMPILE([
935 #include <linux/mutex.h>
937 struct mutex mtx __attribute__ ((unused));
941 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
948 dnl # 2.6.39 API change,
949 dnl # Owner type change. A Linux mutex prior to 2.6.39 would store
950 dnl # the owner as a thread_info pointer when CONFIG_DEBUG_MUTEXES
951 dnl # was defined. As of 2.6.39 this was changed to a task_struct
952 dnl # pointer which frankly makes a lot more sense.
954 AC_DEFUN([SPL_AC_MUTEX_OWNER_TASK_STRUCT], [
955 AC_MSG_CHECKING([whether struct mutex owner is a task_struct])
956 tmp_flags="$EXTRA_KCFLAGS"
957 EXTRA_KCFLAGS="-Werror"
958 SPL_LINUX_TRY_COMPILE([
959 #include <linux/mutex.h>
960 #include <linux/sched.h>
962 struct mutex mtx __attribute__ ((unused));
966 AC_DEFINE(HAVE_MUTEX_OWNER_TASK_STRUCT, 1,
967 [struct mutex owner is a task_struct])
971 EXTRA_KCFLAGS="$tmp_flags"
975 dnl # 2.6.18 API change,
976 dnl # kallsyms_lookup_name no longer exported
978 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME],
979 [AC_MSG_CHECKING([whether kallsyms_lookup_name() is available])
980 SPL_LINUX_TRY_COMPILE_SYMBOL([
981 #include <linux/kallsyms.h>
983 kallsyms_lookup_name(NULL);
984 ], [kallsyms_lookup_name], [], [
986 AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
987 [kallsyms_lookup_name() is available])
994 dnl # Proposed API change,
995 dnl # This symbol is not available in stock kernels. You may build a
996 dnl # custom kernel with the *-spl-export-symbols.patch which will export
997 dnl # these symbols for use. If your already rolling a custom kernel for
998 dnl # your environment this is recommended.
1000 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO],
1001 [AC_MSG_CHECKING([whether get_vmalloc_info() is available])
1002 SPL_CHECK_SYMBOL_EXPORT([get_vmalloc_info], [], [
1004 AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
1005 [get_vmalloc_info() is available])
1012 dnl # 3.10 API change,
1013 dnl # struct vmalloc_info is now declared in linux/vmalloc.h
1015 AC_DEFUN([SPL_AC_VMALLOC_INFO], [
1016 AC_MSG_CHECKING([whether struct vmalloc_info is declared])
1017 SPL_LINUX_TRY_COMPILE([
1018 #include <linux/vmalloc.h>
1019 struct vmalloc_info { void *a; };
1026 AC_DEFINE(HAVE_VMALLOC_INFO, 1, [yes])
1031 dnl # 3.10 API change,
1032 dnl # PDE is replaced by PDE_DATA
1034 AC_DEFUN([SPL_AC_PDE_DATA], [
1035 AC_MSG_CHECKING([whether PDE_DATA() is available])
1036 SPL_LINUX_TRY_COMPILE_SYMBOL([
1037 #include <linux/proc_fs.h>
1040 ], [PDE_DATA], [], [
1042 AC_DEFINE(HAVE_PDE_DATA, 1, [yes])
1049 dnl # 2.6.17 API change
1050 dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
1051 dnl # next_zone() are introduced to simplify for_each_zone(). These symbols
1052 dnl # were exported in 2.6.17 for use by modules which was consistent with
1053 dnl # the previous implementation of for_each_zone(). From 2.6.18 - 2.6.19
1054 dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
1055 dnl # were dropped entirely leaving modules no way to directly iterate over
1056 dnl # the zone list. Because we need access to the zone helpers we check
1057 dnl # if the kernel contains the old or new implementation. Then we check
1058 dnl # to see if the symbols we need for each version are available. If they
1059 dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
1061 AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
1062 AC_MSG_CHECKING([whether symbol *_pgdat exist])
1063 grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
1065 if test $rc -eq 0; then
1066 AC_MSG_RESULT([yes])
1067 AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are 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_FIRST_ONLINE_PGDAT],
1081 [AC_MSG_CHECKING([whether first_online_pgdat() is available])
1082 SPL_LINUX_TRY_COMPILE_SYMBOL([
1083 #include <linux/mmzone.h>
1085 first_online_pgdat();
1086 ], [first_online_pgdat], [], [
1088 AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
1089 [first_online_pgdat() is available])
1096 dnl # Proposed API change,
1097 dnl # This symbol is not available in stock kernels. You may build a
1098 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1099 dnl # these symbols for use. If your already rolling a custom kernel for
1100 dnl # your environment this is recommended.
1102 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT],
1103 [AC_MSG_CHECKING([whether next_online_pgdat() is available])
1104 SPL_LINUX_TRY_COMPILE_SYMBOL([
1105 #include <linux/mmzone.h>
1107 next_online_pgdat(NULL);
1108 ], [next_online_pgdat], [], [
1110 AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
1111 [next_online_pgdat() is available])
1118 dnl # Proposed API change,
1119 dnl # This symbol is not available in stock kernels. You may build a
1120 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1121 dnl # these symbols for use. If your already rolling a custom kernel for
1122 dnl # your environment this is recommended.
1124 AC_DEFUN([SPL_AC_NEXT_ZONE],
1125 [AC_MSG_CHECKING([whether next_zone() is available])
1126 SPL_LINUX_TRY_COMPILE_SYMBOL([
1127 #include <linux/mmzone.h>
1130 ], [next_zone], [], [
1132 AC_DEFINE(HAVE_NEXT_ZONE, 1, [next_zone() is available])
1139 dnl # 2.6.17 API change,
1140 dnl # See SPL_AC_PGDAT_HELPERS for details.
1142 AC_DEFUN([SPL_AC_PGDAT_LIST],
1143 [AC_MSG_CHECKING([whether pgdat_list is available])
1144 SPL_LINUX_TRY_COMPILE_SYMBOL([
1145 #include <linux/topology.h>
1146 pg_data_t *tmp = pgdat_list;
1147 ], [], [pgdat_list], [], [
1149 AC_DEFINE(HAVE_PGDAT_LIST, 1, [pgdat_list is available])
1156 dnl # 2.6.18 API change,
1157 dnl # First introduced global_page_state() support as an inline.
1159 AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
1160 AC_MSG_CHECKING([whether global_page_state() is available])
1161 SPL_LINUX_TRY_COMPILE([
1162 #include <linux/mm.h>
1164 unsigned long state __attribute__ ((unused));
1165 state = global_page_state(0);
1168 AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
1169 [global_page_state() is available])
1176 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1177 dnl # Public global zone stats now include a free page count. However
1178 dnl # the enumerated names of the counters have changed since this API
1179 dnl # was introduced. We need to deduce the corrent name to use. This
1180 dnl # replaces the priviate get_zone_counts() interface.
1182 dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
1183 dnl # is 2.6.30 as of when this was written.
1185 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
1186 AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
1187 SPL_LINUX_TRY_COMPILE([
1188 #include <linux/mm.h>
1190 enum zone_stat_item zsi __attribute__ ((unused));
1191 zsi = NR_FREE_PAGES;
1194 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
1195 [Page state NR_FREE_PAGES is available])
1202 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1203 dnl # Public global zone stats now include an inactive page count. However
1204 dnl # the enumerated names of the counters have changed since this API
1205 dnl # was introduced. We need to deduce the corrent name to use. This
1206 dnl # replaces the priviate get_zone_counts() interface.
1208 dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
1209 dnl # anonymous and file inactive pages. As of 2.6.28 it was split in
1210 dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
1212 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
1213 AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
1214 SPL_LINUX_TRY_COMPILE([
1215 #include <linux/mm.h>
1217 enum zone_stat_item zsi __attribute__ ((unused));
1221 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
1222 [Page state NR_INACTIVE is available])
1227 AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
1228 SPL_LINUX_TRY_COMPILE([
1229 #include <linux/mm.h>
1231 enum zone_stat_item zsi __attribute__ ((unused));
1232 zsi = NR_INACTIVE_ANON;
1235 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
1236 [Page state NR_INACTIVE_ANON is available])
1241 AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
1242 SPL_LINUX_TRY_COMPILE([
1243 #include <linux/mm.h>
1245 enum zone_stat_item zsi __attribute__ ((unused));
1246 zsi = NR_INACTIVE_FILE;
1249 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
1250 [Page state NR_INACTIVE_FILE is available])
1257 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1258 dnl # Public global zone stats now include an active page count. However
1259 dnl # the enumerated names of the counters have changed since this API
1260 dnl # was introduced. We need to deduce the corrent name to use. This
1261 dnl # replaces the priviate get_zone_counts() interface.
1263 dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
1264 dnl # anonymous and file active pages. As of 2.6.28 it was split in
1265 dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
1267 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
1268 AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
1269 SPL_LINUX_TRY_COMPILE([
1270 #include <linux/mm.h>
1272 enum zone_stat_item zsi __attribute__ ((unused));
1276 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
1277 [Page state NR_ACTIVE is available])
1282 AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
1283 SPL_LINUX_TRY_COMPILE([
1284 #include <linux/mm.h>
1286 enum zone_stat_item zsi __attribute__ ((unused));
1287 zsi = NR_ACTIVE_ANON;
1290 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
1291 [Page state NR_ACTIVE_ANON is available])
1296 AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
1297 SPL_LINUX_TRY_COMPILE([
1298 #include <linux/mm.h>
1300 enum zone_stat_item zsi __attribute__ ((unused));
1301 zsi = NR_ACTIVE_FILE;
1304 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
1305 [Page state NR_ACTIVE_FILE is available])
1312 dnl # Proposed API change for legacy kernels.
1313 dnl # This symbol is not available in older kernels. For kernels post
1314 dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
1315 dnl # page state information. This symbol is only used in legacy kernels
1316 dnl # any only as a last resort.
1318 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
1319 AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
1320 SPL_LINUX_TRY_COMPILE([
1322 #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
1323 #error "global_page_state needs NR_FREE_PAGES"
1326 #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
1327 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
1328 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
1329 #error "global_page_state needs NR_ACTIVE*"
1332 #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
1333 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
1334 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
1335 #error "global_page_state needs NR_INACTIVE*"
1341 AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
1342 [get_zone_counts() is needed])
1344 AC_MSG_CHECKING([whether get_zone_counts() is available])
1345 SPL_LINUX_TRY_COMPILE_SYMBOL([
1346 #include <linux/mmzone.h>
1348 get_zone_counts(NULL, NULL, NULL);
1349 ], [get_zone_counts], [], [
1351 AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
1352 [get_zone_counts() is available])
1360 dnl # 2.6.27 API change,
1361 dnl # The user_path_dir() replaces __user_walk()
1363 AC_DEFUN([SPL_AC_USER_PATH_DIR],
1364 [AC_MSG_CHECKING([whether user_path_dir() is available])
1365 SPL_LINUX_TRY_COMPILE_SYMBOL([
1366 #include <linux/fcntl.h>
1367 #include <linux/namei.h>
1369 user_path_dir(NULL, NULL);
1370 ], [user_path_at], [], [
1372 AC_DEFINE(HAVE_USER_PATH_DIR, 1, [user_path_dir() is available])
1379 dnl # Symbol available in RHEL kernels not in stock kernels.
1381 AC_DEFUN([SPL_AC_SET_FS_PWD],
1382 [AC_MSG_CHECKING([whether set_fs_pwd() is available])
1383 SPL_LINUX_TRY_COMPILE_SYMBOL([
1384 #include <linux/spinlock.h>
1385 #include <linux/fs_struct.h>
1388 ], [set_fs_pwd], [], [
1390 AC_DEFINE(HAVE_SET_FS_PWD, 1, [set_fs_pwd() is available])
1397 dnl # 3.9 API change
1398 dnl # set_fs_pwd takes const struct path *
1400 AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
1401 tmp_flags="$EXTRA_KCFLAGS"
1402 EXTRA_KCFLAGS="-Werror"
1403 [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
1404 SPL_LINUX_TRY_COMPILE([
1405 #include <linux/spinlock.h>
1406 #include <linux/fs_struct.h>
1407 #include <linux/path.h>
1408 void (*const set_fs_pwd_func)
1409 (struct fs_struct *, const struct path *)
1415 AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
1416 [set_fs_pwd() needs const path *])
1418 SPL_LINUX_TRY_COMPILE([
1419 #include <linux/spinlock.h>
1420 #include <linux/fs_struct.h>
1421 #include <linux/path.h>
1422 void (*const set_fs_pwd_func)
1423 (struct fs_struct *, struct path *)
1430 AC_MSG_ERROR(unknown)
1433 EXTRA_KCFLAGS="$tmp_flags"
1436 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
1437 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
1438 SPL_LINUX_TRY_COMPILE([
1439 #include <linux/fs.h>
1441 vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
1444 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
1445 [vfs_unlink() wants 2 args])
1449 dnl # Linux 3.13 API change
1450 dnl # Added delegated inode
1452 AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
1453 SPL_LINUX_TRY_COMPILE([
1454 #include <linux/fs.h>
1456 vfs_unlink((struct inode *) NULL,
1457 (struct dentry *) NULL,
1458 (struct inode **) NULL);
1461 AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
1462 [vfs_unlink() wants 3 args])
1470 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
1471 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
1472 SPL_LINUX_TRY_COMPILE([
1473 #include <linux/fs.h>
1475 vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
1476 (struct inode *) NULL, (struct dentry *) NULL);
1479 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
1480 [vfs_rename() wants 4 args])
1484 dnl # Linux 3.13 API change
1485 dnl # Added delegated inode
1487 AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
1488 SPL_LINUX_TRY_COMPILE([
1489 #include <linux/fs.h>
1491 vfs_rename((struct inode *) NULL,
1492 (struct dentry *) NULL,
1493 (struct inode *) NULL,
1494 (struct dentry *) NULL,
1495 (struct inode **) NULL);
1498 AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
1499 [vfs_rename() wants 5 args])
1503 dnl # Linux 3.15 API change
1506 AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
1507 SPL_LINUX_TRY_COMPILE([
1508 #include <linux/fs.h>
1510 vfs_rename((struct inode *) NULL,
1511 (struct dentry *) NULL,
1512 (struct inode *) NULL,
1513 (struct dentry *) NULL,
1514 (struct inode **) NULL,
1518 AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
1519 [vfs_rename() wants 6 args])
1528 dnl # 2.6.36 API change,
1529 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
1530 dnl # a spinlock_t to improve the fastpath performance.
1532 AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
1533 AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
1534 tmp_flags="$EXTRA_KCFLAGS"
1535 EXTRA_KCFLAGS="-Werror"
1536 SPL_LINUX_TRY_COMPILE([
1537 #include <linux/sched.h>
1538 #include <linux/fs_struct.h>
1540 struct fs_struct fs;
1541 spin_lock_init(&fs.lock);
1544 AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
1545 [struct fs_struct uses spinlock_t])
1549 EXTRA_KCFLAGS="$tmp_flags"
1553 dnl # 2.6.29 API change,
1554 dnl # check whether 'struct cred' exists
1556 AC_DEFUN([SPL_AC_CRED_STRUCT], [
1557 AC_MSG_CHECKING([whether struct cred exists])
1558 SPL_LINUX_TRY_COMPILE([
1559 #include <linux/cred.h>
1561 struct cred *cr __attribute__ ((unused));
1565 AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
1573 dnl # User namespaces, use kuid_t in place of uid_t
1574 dnl # where available. Not strictly a user namespaces thing
1575 dnl # but it should prevent surprises
1577 AC_DEFUN([SPL_AC_KUIDGID_T], [
1578 AC_MSG_CHECKING([whether kuid_t/kgid_t is available])
1579 SPL_LINUX_TRY_COMPILE([
1580 #include <linux/uidgid.h>
1582 kuid_t userid = KUIDT_INIT(0);
1583 kgid_t groupid = KGIDT_INIT(0);
1585 SPL_LINUX_TRY_COMPILE([
1586 #include <linux/uidgid.h>
1591 AC_MSG_RESULT(yes; optional)
1593 AC_MSG_RESULT(yes; mandatory)
1594 AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use])
1602 dnl # Custom SPL patch may export this symbol.
1604 AC_DEFUN([SPL_AC_GROUPS_SEARCH],
1605 [AC_MSG_CHECKING([whether groups_search() is available])
1606 SPL_LINUX_TRY_COMPILE_SYMBOL([
1607 #include <linux/cred.h>
1608 #ifdef HAVE_KUIDGID_T
1609 #include <linux/uidgid.h>
1612 #ifdef HAVE_KUIDGID_T
1613 groups_search(NULL, KGIDT_INIT(0));
1615 groups_search(NULL, 0);
1617 ], [groups_search], [], [
1619 AC_DEFINE(HAVE_GROUPS_SEARCH, 1, [groups_search() is available])
1626 dnl # 2.6.x API change,
1627 dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
1629 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT],
1630 [AC_MSG_CHECKING([whether __put_task_struct() is available])
1631 SPL_LINUX_TRY_COMPILE_SYMBOL([
1632 #include <linux/sched.h>
1634 __put_task_struct(NULL);
1635 ], [__put_task_struct], [], [
1637 AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1638 [__put_task_struct() is available])
1645 dnl # 2.6.32 API change,
1646 dnl # Unused 'struct file *' removed from prototype.
1648 AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
1649 AC_MSG_CHECKING([whether proc_handler() wants 5 args])
1650 SPL_LINUX_TRY_COMPILE([
1651 #include <linux/sysctl.h>
1653 proc_dostring(NULL, 0, NULL, NULL, NULL);
1656 AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
1657 [proc_handler() wants 5 args])
1664 dnl # 2.6.x API change,
1665 dnl # kvasprintf() function added.
1667 AC_DEFUN([SPL_AC_KVASPRINTF],
1668 [AC_MSG_CHECKING([whether kvasprintf() is available])
1669 SPL_LINUX_TRY_COMPILE_SYMBOL([
1670 #include <linux/kernel.h>
1672 kvasprintf(0, NULL, *((va_list*)NULL));
1673 ], [kvasprintf], [], [
1675 AC_DEFINE(HAVE_KVASPRINTF, 1, [kvasprintf() is available])
1682 dnl # 2.6.29 API change,
1683 dnl # vfs_fsync() funcation added, prior to this use file_fsync().
1685 AC_DEFUN([SPL_AC_VFS_FSYNC],
1686 [AC_MSG_CHECKING([whether vfs_fsync() is available])
1687 SPL_LINUX_TRY_COMPILE_SYMBOL([
1688 #include <linux/fs.h>
1691 ], [vfs_fsync], [fs/sync.c], [
1693 AC_DEFINE(HAVE_VFS_FSYNC, 1, [vfs_fsync() is available])
1700 dnl # 2.6.35 API change,
1701 dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
1703 AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
1704 AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
1705 SPL_LINUX_TRY_COMPILE([
1706 #include <linux/fs.h>
1711 AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
1718 dnl # 3.5 API change,
1719 dnl # inode_operations.truncate_range removed
1721 AC_DEFUN([SPL_AC_INODE_TRUNCATE_RANGE], [
1722 AC_MSG_CHECKING([whether truncate_range() inode operation is available])
1723 SPL_LINUX_TRY_COMPILE([
1724 #include <linux/fs.h>
1726 struct inode_operations ops;
1727 ops.truncate_range = NULL;
1730 AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1,
1731 [truncate_range() inode operation is available])
1738 dnl # Linux 2.6.38 - 3.x API
1740 AC_DEFUN([SPL_AC_KERNEL_FILE_FALLOCATE], [
1741 AC_MSG_CHECKING([whether fops->fallocate() exists])
1742 SPL_LINUX_TRY_COMPILE([
1743 #include <linux/fs.h>
1745 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1746 struct file_operations fops __attribute__ ((unused)) = {
1747 .fallocate = fallocate,
1751 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1758 dnl # Linux 2.6.x - 2.6.37 API
1760 AC_DEFUN([SPL_AC_KERNEL_INODE_FALLOCATE], [
1761 AC_MSG_CHECKING([whether iops->fallocate() exists])
1762 SPL_LINUX_TRY_COMPILE([
1763 #include <linux/fs.h>
1765 long (*fallocate) (struct inode *, int, loff_t, loff_t) = NULL;
1766 struct inode_operations fops __attribute__ ((unused)) = {
1767 .fallocate = fallocate,
1771 AC_DEFINE(HAVE_INODE_FALLOCATE, 1, [fops->fallocate() exists])
1778 dnl # PaX Linux 2.6.38 - 3.x API
1780 AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [
1781 AC_MSG_CHECKING([whether fops->fallocate() exists])
1782 SPL_LINUX_TRY_COMPILE([
1783 #include <linux/fs.h>
1785 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1786 struct file_operations_no_const fops __attribute__ ((unused)) = {
1787 .fallocate = fallocate,
1791 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1798 dnl # The fallocate callback was moved from the inode_operations
1799 dnl # structure to the file_operations structure.
1801 AC_DEFUN([SPL_AC_KERNEL_FALLOCATE], [
1802 SPL_AC_KERNEL_FILE_FALLOCATE
1803 SPL_AC_KERNEL_INODE_FALLOCATE
1804 SPL_AC_PAX_KERNEL_FILE_FALLOCATE
1808 dnl # 2.6.33 API change. Also backported in RHEL5 as of 2.6.18-190.el5.
1809 dnl # Earlier versions of rwsem_is_locked() were inline and had a race
1810 dnl # condition. The fixed version is exported as a symbol. The race
1811 dnl # condition is fixed by acquiring sem->wait_lock, so we must not
1812 dnl # call that version while holding sem->wait_lock.
1814 AC_DEFUN([SPL_AC_EXPORTED_RWSEM_IS_LOCKED],
1815 [AC_MSG_CHECKING([whether rwsem_is_locked() acquires sem->wait_lock])
1816 SPL_LINUX_TRY_COMPILE_SYMBOL([
1817 #include <linux/rwsem.h>
1818 int rwsem_is_locked(struct rw_semaphore *sem) { return 0; }
1819 ], [], [rwsem_is_locked], [lib/rwsem-spinlock.c], [
1821 AC_DEFINE(RWSEM_IS_LOCKED_TAKES_WAIT_LOCK, 1,
1822 [rwsem_is_locked() acquires sem->wait_lock])
1829 dnl # 2.6.xx API compat,
1830 dnl # There currently exists no exposed API to partially shrink the dcache.
1831 dnl # The expected mechanism to shrink the cache is a registered shrinker
1832 dnl # which is called during memory pressure.
1834 AC_DEFUN([SPL_AC_SHRINK_DCACHE_MEMORY],
1835 [AC_MSG_CHECKING([whether shrink_dcache_memory() is available])
1836 SPL_LINUX_TRY_COMPILE_SYMBOL([
1837 #include <linux/dcache.h>
1839 shrink_dcache_memory(0, 0);
1840 ], [shrink_dcache_memory], [fs/dcache.c], [
1842 AC_DEFINE(HAVE_SHRINK_DCACHE_MEMORY, 1,
1843 [shrink_dcache_memory() is available])
1850 dnl # 2.6.xx API compat,
1851 dnl # There currently exists no exposed API to partially shrink the icache.
1852 dnl # The expected mechanism to shrink the cache is a registered shrinker
1853 dnl # which is called during memory pressure.
1855 AC_DEFUN([SPL_AC_SHRINK_ICACHE_MEMORY],
1856 [AC_MSG_CHECKING([whether shrink_icache_memory() is available])
1857 SPL_LINUX_TRY_COMPILE_SYMBOL([
1858 #include <linux/dcache.h>
1860 shrink_icache_memory(0, 0);
1861 ], [shrink_icache_memory], [fs/inode.c], [
1863 AC_DEFINE(HAVE_SHRINK_ICACHE_MEMORY, 1,
1864 [shrink_icache_memory() is available])
1871 dnl # 2.6.28 API change
1872 dnl # The kern_path() function has been introduced. We adopt it as the new way
1873 dnl # of looking up paths. When it is not available, we emulate it using the
1874 dnl # older interfaces.
1876 AC_DEFUN([SPL_AC_KERN_PATH],
1877 [AC_MSG_CHECKING([whether kern_path() is available])
1878 SPL_LINUX_TRY_COMPILE_SYMBOL([
1879 #include <linux/namei.h>
1881 int r = kern_path(NULL, 0, NULL);
1882 ], [kern_path], [fs/namei.c], [
1884 AC_DEFINE(HAVE_KERN_PATH, 1,
1885 [kern_path() is available])
1888 AC_MSG_CHECKING([whether path_lookup() is available])
1889 SPL_LINUX_TRY_COMPILE_SYMBOL([
1890 #include <linux/namei.h>
1892 int r = path_lookup(NULL, 0, NULL);
1893 ], [path_lookup], [fs/namei.c], [
1895 AC_DEFINE(HAVE_KERN_PATH, 1,
1896 [kern_path() is available])
1900 *** Neither kern_path() nor path_lookup() is available.
1901 *** Please file an issue:
1902 *** https://github.com/zfsonlinux/spl/issues/new])
1909 dnl # /proc/kallsyms support,
1910 dnl # Verify the kernel has CONFIG_KALLSYMS support enabled.
1912 AC_DEFUN([SPL_AC_CONFIG_KALLSYMS], [
1913 AC_MSG_CHECKING([whether CONFIG_KALLSYMS is defined])
1914 SPL_LINUX_TRY_COMPILE([
1915 #if !defined(CONFIG_KALLSYMS)
1916 #error CONFIG_KALLSYMS not defined
1919 AC_MSG_RESULT([yes])
1923 *** This kernel does not include the required kallsyms support.
1924 *** Rebuild the kernel with CONFIG_KALLSYMS=y set.])
1929 dnl # zlib inflate compat,
1930 dnl # Verify the kernel has CONFIG_ZLIB_INFLATE support enabled.
1932 AC_DEFUN([SPL_AC_CONFIG_ZLIB_INFLATE], [
1933 AC_MSG_CHECKING([whether CONFIG_ZLIB_INFLATE is defined])
1934 SPL_LINUX_TRY_COMPILE([
1935 #if !defined(CONFIG_ZLIB_INFLATE) && \
1936 !defined(CONFIG_ZLIB_INFLATE_MODULE)
1937 #error CONFIG_ZLIB_INFLATE not defined
1940 AC_MSG_RESULT([yes])
1944 *** This kernel does not include the required zlib inflate support.
1945 *** Rebuild the kernel with CONFIG_ZLIB_INFLATE=y|m set.])
1950 dnl # zlib deflate compat,
1951 dnl # Verify the kernel has CONFIG_ZLIB_DEFLATE support enabled.
1953 AC_DEFUN([SPL_AC_CONFIG_ZLIB_DEFLATE], [
1954 AC_MSG_CHECKING([whether CONFIG_ZLIB_DEFLATE is defined])
1955 SPL_LINUX_TRY_COMPILE([
1956 #if !defined(CONFIG_ZLIB_DEFLATE) && \
1957 !defined(CONFIG_ZLIB_DEFLATE_MODULE)
1958 #error CONFIG_ZLIB_DEFLATE not defined
1961 AC_MSG_RESULT([yes])
1965 *** This kernel does not include the required zlib deflate support.
1966 *** Rebuild the kernel with CONFIG_ZLIB_DEFLATE=y|m set.])
1971 dnl # 2.6.39 API compat,
1972 dnl # The function zlib_deflate_workspacesize() now take 2 arguments.
1973 dnl # This was done to avoid always having to allocate the maximum size
1974 dnl # workspace (268K). The caller can now specific the windowBits and
1975 dnl # memLevel compression parameters to get a smaller workspace.
1977 AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE],
1978 [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args])
1979 SPL_LINUX_TRY_COMPILE([
1980 #include <linux/zlib.h>
1982 return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL);
1985 AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1,
1986 [zlib_deflate_workspacesize() wants 2 args])
1993 dnl # 2.6.39 API change,
1994 dnl # Shrinker adjust to use common shrink_control structure.
1996 AC_DEFUN([SPL_AC_SHRINK_CONTROL_STRUCT], [
1997 AC_MSG_CHECKING([whether struct shrink_control exists])
1998 SPL_LINUX_TRY_COMPILE([
1999 #include <linux/mm.h>
2001 struct shrink_control sc __attribute__ ((unused));
2004 sc.gfp_mask = GFP_KERNEL;
2007 AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
2008 [struct shrink_control exists])
2015 dnl # 3.1 API Change
2017 dnl # The rw_semaphore.wait_lock member was changed from spinlock_t to
2018 dnl # raw_spinlock_t at commit ddb6c9b58a19edcfac93ac670b066c836ff729f1.
2020 AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
2021 AC_MSG_CHECKING([whether struct rw_semaphore member wait_lock is raw])
2022 tmp_flags="$EXTRA_KCFLAGS"
2023 EXTRA_KCFLAGS="-Werror"
2024 SPL_LINUX_TRY_COMPILE([
2025 #include <linux/rwsem.h>
2027 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
2028 raw_spinlock_t dummy_lock __attribute__ ((unused));
2029 dummy_semaphore.wait_lock = dummy_lock;
2032 AC_DEFINE(RWSEM_SPINLOCK_IS_RAW, 1,
2033 [struct rw_semaphore member wait_lock is raw_spinlock_t])
2037 EXTRA_KCFLAGS="$tmp_flags"
2041 dnl # 3.9 API change,
2042 dnl # Moved things from linux/sched.h to linux/sched/rt.h
2044 AC_DEFUN([SPL_AC_SCHED_RT_HEADER],
2045 [AC_MSG_CHECKING([whether header linux/sched/rt.h exists])
2046 SPL_LINUX_TRY_COMPILE([
2047 #include <linux/sched.h>
2048 #include <linux/sched/rt.h>
2052 AC_DEFINE(HAVE_SCHED_RT_HEADER, 1, [linux/sched/rt.h exists])
2060 dnl # 3.9 API change,
2061 dnl # vfs_getattr() uses 2 args
2062 dnl # It takes struct path * instead of struct vfsmount * and struct dentry *
2064 AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [
2065 AC_MSG_CHECKING([whether vfs_getattr() wants])
2066 SPL_LINUX_TRY_COMPILE([
2067 #include <linux/fs.h>
2069 vfs_getattr((struct path *) NULL,
2070 (struct kstat *)NULL);
2072 AC_MSG_RESULT(2 args)
2073 AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1,
2074 [vfs_getattr wants 2 args])
2076 SPL_LINUX_TRY_COMPILE([
2077 #include <linux/fs.h>
2079 vfs_getattr((struct vfsmount *)NULL,
2080 (struct dentry *)NULL,
2081 (struct kstat *)NULL);
2083 AC_MSG_RESULT(3 args)
2085 AC_MSG_ERROR(unknown)
2091 dnl # 2.6.36 API compatibility.
2092 dnl # Added usleep_range timer.
2093 dnl # usleep_range is a finer precision implementation of msleep
2094 dnl # designed to be a drop-in replacement for udelay where a precise
2095 dnl # sleep / busy-wait is unnecessary.
2097 AC_DEFUN([SPL_AC_USLEEP_RANGE], [
2098 AC_MSG_CHECKING([whether usleep_range() is available])
2099 SPL_LINUX_TRY_COMPILE([
2100 #include <linux/delay.h>
2105 AC_DEFINE(HAVE_USLEEP_RANGE, 1,
2106 [usleep_range is available])
2113 dnl # 2.6.35 API change,
2114 dnl # The cachep->gfpflags member was renamed cachep->allocflags. These are
2115 dnl # private allocation flags which are applied when allocating a new slab
2116 dnl # in kmem_getpages(). Unfortunately there is no public API for setting
2117 dnl # non-default flags.
2119 AC_DEFUN([SPL_AC_KMEM_CACHE_ALLOCFLAGS], [
2120 AC_MSG_CHECKING([whether struct kmem_cache has allocflags])
2121 SPL_LINUX_TRY_COMPILE([
2122 #include <linux/slab.h>
2124 struct kmem_cache cachep __attribute__ ((unused));
2125 cachep.allocflags = GFP_KERNEL;
2128 AC_DEFINE(HAVE_KMEM_CACHE_ALLOCFLAGS, 1,
2129 [struct kmem_cache has allocflags])
2133 AC_MSG_CHECKING([whether struct kmem_cache has gfpflags])
2134 SPL_LINUX_TRY_COMPILE([
2135 #include <linux/slab.h>
2137 struct kmem_cache cachep __attribute__ ((unused));
2138 cachep.gfpflags = GFP_KERNEL;
2141 AC_DEFINE(HAVE_KMEM_CACHE_GFPFLAGS, 1,
2142 [struct kmem_cache has gfpflags])
2150 dnl # 3.17 API change,
2151 dnl # wait_on_bit() no longer requires an action argument. The former
2152 dnl # "wait_on_bit" interface required an 'action' function to be provided
2153 dnl # which does the actual waiting. There were over 20 such functions in the
2154 dnl # kernel, many of them identical, though most cases can be satisfied by one
2155 dnl # of just two functions: one which uses io_schedule() and one which just
2156 dnl # uses schedule(). This API change was made to consolidate all of those
2157 dnl # redundant wait functions.
2159 AC_DEFUN([SPL_AC_WAIT_ON_BIT], [
2160 AC_MSG_CHECKING([whether wait_on_bit() takes an action])
2161 SPL_LINUX_TRY_COMPILE([
2162 #include <linux/wait.h>
2164 int (*action)(void *) = NULL;
2165 wait_on_bit(NULL, 0, action, 0);
2168 AC_DEFINE(HAVE_WAIT_ON_BIT_ACTION, 1, [yes])