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)
22 SPL_AC_DEBUG_KMEM_TRACKING
24 SPL_AC_ATOMIC_SPINLOCK
25 SPL_AC_SHRINKER_CALLBACK
28 SPL_AC_SET_FS_PWD_WITH_CONST
29 SPL_AC_2ARGS_VFS_UNLINK
30 SPL_AC_4ARGS_VFS_RENAME
31 SPL_AC_2ARGS_VFS_FSYNC
32 SPL_AC_INODE_TRUNCATE_RANGE
33 SPL_AC_FS_STRUCT_SPINLOCK
35 SPL_AC_PUT_TASK_STRUCT
36 SPL_AC_KERNEL_FALLOCATE
37 SPL_AC_CONFIG_ZLIB_INFLATE
38 SPL_AC_CONFIG_ZLIB_DEFLATE
39 SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
40 SPL_AC_SHRINK_CONTROL_STRUCT
41 SPL_AC_RWSEM_SPINLOCK_IS_RAW
42 SPL_AC_SCHED_RT_HEADER
43 SPL_AC_2ARGS_VFS_GETATTR
45 SPL_AC_KMEM_CACHE_ALLOCFLAGS
49 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
50 modpost=$LINUX/scripts/Makefile.modpost
51 AC_MSG_CHECKING([kernel file name for module symbols])
52 if test "x$enable_linux_builtin" != xyes -a -f "$modpost"; then
53 if grep -q Modules.symvers $modpost; then
54 LINUX_SYMBOLS=Modules.symvers
56 LINUX_SYMBOLS=Module.symvers
59 if ! test -f "$LINUX_OBJ/$LINUX_SYMBOLS"; then
61 *** Please make sure the kernel devel package for your distribution
62 *** is installed. If you are building with a custom kernel, make sure the
63 *** kernel is configured, built, and the '--with-linux=PATH' configure
64 *** option refers to the location of the kernel source.])
69 AC_MSG_RESULT($LINUX_SYMBOLS)
70 AC_SUBST(LINUX_SYMBOLS)
73 AC_DEFUN([SPL_AC_KERNEL], [
75 AS_HELP_STRING([--with-linux=PATH],
76 [Path to kernel source]),
77 [kernelsrc="$withval"])
79 AC_ARG_WITH([linux-obj],
80 AS_HELP_STRING([--with-linux-obj=PATH],
81 [Path to kernel build objects]),
82 [kernelbuild="$withval"])
84 AC_MSG_CHECKING([kernel source directory])
85 if test -z "$kernelsrc"; then
86 if test -e "/lib/modules/$(uname -r)/source"; then
87 headersdir="/lib/modules/$(uname -r)/source"
88 sourcelink=$(readlink -f "$headersdir")
89 elif test -e "/lib/modules/$(uname -r)/build"; then
90 headersdir="/lib/modules/$(uname -r)/build"
91 sourcelink=$(readlink -f "$headersdir")
93 sourcelink=$(ls -1d /usr/src/kernels/* \
95 2>/dev/null | grep -v obj | tail -1)
98 if test -n "$sourcelink" && test -e ${sourcelink}; then
99 kernelsrc=`readlink -f ${sourcelink}`
101 kernelsrc="[Not found]"
104 if test "$kernelsrc" = "NONE"; then
109 AC_MSG_RESULT([$kernelsrc])
110 if test ! -d "$kernelsrc"; then
112 *** Please make sure the kernel devel package for your distribution
113 *** is installed and then try again. If that fails, you can specify the
114 *** location of the kernel source with the '--with-linux=PATH' option.])
117 AC_MSG_CHECKING([kernel build directory])
118 if test -z "$kernelbuild"; then
119 if test -e "/lib/modules/$(uname -r)/build"; then
120 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
121 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
122 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
123 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
124 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
125 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
126 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
128 kernelbuild=${kernelsrc}
131 AC_MSG_RESULT([$kernelbuild])
133 AC_MSG_CHECKING([kernel source version])
134 utsrelease1=$kernelbuild/include/linux/version.h
135 utsrelease2=$kernelbuild/include/linux/utsrelease.h
136 utsrelease3=$kernelbuild/include/generated/utsrelease.h
137 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
138 utsrelease=linux/version.h
139 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
140 utsrelease=linux/utsrelease.h
141 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
142 utsrelease=generated/utsrelease.h
145 if test "$utsrelease"; then
146 kernsrcver=`(echo "#include <$utsrelease>";
147 echo "kernsrcver=UTS_RELEASE") |
148 cpp -I $kernelbuild/include |
149 grep "^kernsrcver=" | cut -d \" -f 2`
151 if test -z "$kernsrcver"; then
152 AC_MSG_RESULT([Not found])
153 AC_MSG_ERROR([*** Cannot determine kernel version.])
156 AC_MSG_RESULT([Not found])
157 if test "x$enable_linux_builtin" != xyes; then
158 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
161 *** Cannot find UTS_RELEASE definition.
162 *** Please run 'make prepare' inside the kernel source tree.])
166 AC_MSG_RESULT([$kernsrcver])
169 LINUX_OBJ=${kernelbuild}
170 LINUX_VERSION=${kernsrcver}
174 AC_SUBST(LINUX_VERSION)
176 SPL_AC_MODULE_SYMVERS
180 dnl # Default SPL user configuration
182 AC_DEFUN([SPL_AC_CONFIG_USER], [])
185 dnl # Check for rpm+rpmbuild to build RPM packages. If these tools
186 dnl # are missing, it is non-fatal, but you will not be able to build
187 dnl # RPM packages and will be warned if you try too.
189 dnl # By default, the generic spec file will be used because it requires
190 dnl # minimal dependencies. Distribution specific spec files can be
191 dnl # placed under the 'rpm/<distribution>' directory and enabled using
192 dnl # the --with-spec=<distribution> configure option.
194 AC_DEFUN([SPL_AC_RPM], [
198 AC_MSG_CHECKING([whether $RPM is available])
199 AS_IF([tmp=$($RPM --version 2>/dev/null)], [
200 RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
202 AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
205 AC_MSG_RESULT([$HAVE_RPM])
208 AC_MSG_CHECKING([whether $RPMBUILD is available])
209 AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
210 RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
212 AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
215 AC_MSG_RESULT([$HAVE_RPMBUILD])
218 RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1" --define "$(DEBUG_KMEM) 1" --define "$(DEBUG_KMEM_TRACKING) 1"'
220 RPM_DEFINE_KMOD='--define "kernels $(LINUX_VERSION)"'
223 SRPM_DEFINE_COMMON='--define "build_src_rpm 1"'
228 RPM_SPEC_DIR="rpm/generic"
230 AS_HELP_STRING([--with-spec=SPEC],
231 [Spec files 'generic|redhat']),
232 [RPM_SPEC_DIR="rpm/$withval"])
234 AC_MSG_CHECKING([whether spec files are available])
235 AC_MSG_RESULT([yes ($RPM_SPEC_DIR/*.spec.in)])
239 AC_SUBST(RPM_VERSION)
241 AC_SUBST(HAVE_RPMBUILD)
243 AC_SUBST(RPMBUILD_VERSION)
245 AC_SUBST(RPM_SPEC_DIR)
246 AC_SUBST(RPM_DEFINE_UTIL)
247 AC_SUBST(RPM_DEFINE_KMOD)
248 AC_SUBST(RPM_DEFINE_DKMS)
249 AC_SUBST(RPM_DEFINE_COMMON)
250 AC_SUBST(SRPM_DEFINE_UTIL)
251 AC_SUBST(SRPM_DEFINE_KMOD)
252 AC_SUBST(SRPM_DEFINE_DKMS)
253 AC_SUBST(SRPM_DEFINE_COMMON)
257 dnl # Check for dpkg+dpkg-buildpackage to build DEB packages. If these
258 dnl # tools are missing it is non-fatal but you will not be able to build
259 dnl # DEB packages and will be warned if you try too.
261 AC_DEFUN([SPL_AC_DPKG], [
263 DPKGBUILD=dpkg-buildpackage
265 AC_MSG_CHECKING([whether $DPKG is available])
266 AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
267 DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
269 AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
272 AC_MSG_RESULT([$HAVE_DPKG])
275 AC_MSG_CHECKING([whether $DPKGBUILD is available])
276 AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
277 DPKGBUILD_VERSION=$(echo $tmp | \
278 $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
280 AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
283 AC_MSG_RESULT([$HAVE_DPKGBUILD])
288 AC_SUBST(DPKG_VERSION)
290 AC_SUBST(HAVE_DPKGBUILD)
292 AC_SUBST(DPKGBUILD_VERSION)
296 dnl # Until native packaging for various different packing systems
297 dnl # can be added the least we can do is attempt to use alien to
298 dnl # convert the RPM packages to the needed package type. This is
299 dnl # a hack but so far it has worked reasonable well.
301 AC_DEFUN([SPL_AC_ALIEN], [
304 AC_MSG_CHECKING([whether $ALIEN is available])
305 AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
306 ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
308 AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
311 AC_MSG_RESULT([$HAVE_ALIEN])
316 AC_SUBST(ALIEN_VERSION)
320 dnl # Using the VENDOR tag from config.guess set the default
321 dnl # package type for 'make pkg': (rpm | deb | tgz)
323 AC_DEFUN([SPL_AC_DEFAULT_PACKAGE], [
324 AC_MSG_CHECKING([linux distribution])
325 if test -f /etc/toss-release ; then
327 elif test -f /etc/fedora-release ; then
329 elif test -f /etc/redhat-release ; then
331 elif test -f /etc/gentoo-release ; then
333 elif test -f /etc/arch-release ; then
335 elif test -f /etc/SuSE-release ; then
337 elif test -f /etc/slackware-version ; then
339 elif test -f /etc/lunar.release ; then
341 elif test -f /etc/lsb-release ; then
343 elif test -f /etc/debian_version ; then
348 AC_MSG_RESULT([$VENDOR])
351 AC_MSG_CHECKING([default package type])
353 toss) DEFAULT_PACKAGE=rpm ;;
354 redhat) DEFAULT_PACKAGE=rpm ;;
355 fedora) DEFAULT_PACKAGE=rpm ;;
356 gentoo) DEFAULT_PACKAGE=tgz ;;
357 arch) DEFAULT_PACKAGE=tgz ;;
358 sles) DEFAULT_PACKAGE=rpm ;;
359 slackware) DEFAULT_PACKAGE=tgz ;;
360 lunar) DEFAULT_PACKAGE=tgz ;;
361 ubuntu) DEFAULT_PACKAGE=deb ;;
362 debian) DEFAULT_PACKAGE=deb ;;
363 *) DEFAULT_PACKAGE=rpm ;;
366 AC_MSG_RESULT([$DEFAULT_PACKAGE])
367 AC_SUBST(DEFAULT_PACKAGE)
371 dnl # Default SPL user configuration
373 AC_DEFUN([SPL_AC_PACKAGE], [
374 SPL_AC_DEFAULT_PACKAGE
380 AC_DEFUN([SPL_AC_LICENSE], [
381 AC_MSG_CHECKING([spl author])
382 AC_MSG_RESULT([$SPL_META_AUTHOR])
384 AC_MSG_CHECKING([spl license])
385 AC_MSG_RESULT([$SPL_META_LICENSE])
388 AC_DEFUN([SPL_AC_CONFIG], [
390 AC_ARG_WITH([config],
391 AS_HELP_STRING([--with-config=CONFIG],
392 [Config file 'kernel|user|all|srpm']),
393 [SPL_CONFIG="$withval"])
394 AC_ARG_ENABLE([linux-builtin],
395 [AC_HELP_STRING([--enable-linux-builtin],
396 [Configure for builtin in-tree kernel modules @<:@default=no@:>@])],
398 [enable_linux_builtin=no])
400 AC_MSG_CHECKING([spl config])
401 AC_MSG_RESULT([$SPL_CONFIG]);
404 case "$SPL_CONFIG" in
405 kernel) SPL_AC_CONFIG_KERNEL ;;
406 user) SPL_AC_CONFIG_USER ;;
407 all) SPL_AC_CONFIG_KERNEL
408 SPL_AC_CONFIG_USER ;;
411 AC_MSG_RESULT([Error!])
412 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
413 user kernel|user|all|srpm]) ;;
416 AM_CONDITIONAL([CONFIG_USER],
417 [test "$SPL_CONFIG" = user -o "$SPL_CONFIG" = all])
418 AM_CONDITIONAL([CONFIG_KERNEL],
419 [test "$SPL_CONFIG" = kernel -o "$SPL_CONFIG" = all] &&
420 [test "x$enable_linux_builtin" != xyes ])
424 dnl # Enable if the SPL should be compiled with internal debugging enabled.
425 dnl # By default this support is disabled.
427 AC_DEFUN([SPL_AC_DEBUG], [
428 AC_MSG_CHECKING([whether debugging is enabled])
429 AC_ARG_ENABLE([debug],
430 [AS_HELP_STRING([--enable-debug],
431 [Enable generic debug support @<:@default=no@:>@])],
435 AS_IF([test "x$enable_debug" = xyes],
437 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
438 DEBUG_CFLAGS="-DDEBUG -Werror"
439 DEBUG_SPL="_with_debug"
441 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
442 DEBUG_CFLAGS="-DNDEBUG"
443 DEBUG_SPL="_without_debug"
446 AC_SUBST(DEBUG_CFLAGS)
448 AC_MSG_RESULT([$enable_debug])
452 dnl # Enabled by default it provides a minimal level of memory tracking.
453 dnl # A total count of bytes allocated is kept for each alloc and free.
454 dnl # Then at module unload time a report to the console will be printed
455 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
456 dnl # and provide an easy way to inspect the kmem based slab.
458 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
459 AC_ARG_ENABLE([debug-kmem],
460 [AS_HELP_STRING([--enable-debug-kmem],
461 [Enable basic kmem accounting @<:@default=yes@:>@])],
463 [enable_debug_kmem=yes])
465 AS_IF([test "x$enable_debug_kmem" = xyes],
467 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
468 DEBUG_KMEM="_with_debug_kmem"
469 AC_DEFINE([DEBUG_KMEM], [1],
470 [Define to 1 to enable basic kmem accounting])
472 DEBUG_KMEM="_without_debug_kmem"
476 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
477 AC_MSG_RESULT([$enable_debug_kmem])
481 dnl # Disabled by default it provides detailed memory tracking. This
482 dnl # feature also requires --enable-debug-kmem to be set. When enabled
483 dnl # not only will total bytes be tracked but also the location of every
484 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
485 dnl # addresses and where they were allocated will be dumped to the console.
486 dnl # Enabling this feature has a significant impact on performance but it
487 dnl # makes finding memory leaks pretty straight forward.
489 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
490 AC_ARG_ENABLE([debug-kmem-tracking],
491 [AS_HELP_STRING([--enable-debug-kmem-tracking],
492 [Enable detailed kmem tracking @<:@default=no@:>@])],
494 [enable_debug_kmem_tracking=no])
496 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
498 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
499 DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
500 AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
501 [Define to 1 to enable detailed kmem tracking])
503 DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
506 AC_SUBST(DEBUG_KMEM_TRACKING)
507 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
508 AC_MSG_RESULT([$enable_debug_kmem_tracking])
512 dnl # SPL_LINUX_CONFTEST
514 AC_DEFUN([SPL_LINUX_CONFTEST], [
515 cat confdefs.h - <<_ACEOF >conftest.c
521 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
523 m4_define([SPL_LANG_PROGRAM], [
528 dnl Do *not* indent the following line: there may be CPP directives.
529 dnl Don't move the `;' right after for the same reason.
537 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
539 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
540 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
541 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
542 echo "obj-m := conftest.o" >build/Makefile
544 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
546 [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])],
548 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
554 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
556 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
557 [SPL_LINUX_COMPILE_IFELSE(
558 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
560 [test -s build/conftest.o],
565 dnl # SPL_CHECK_SYMBOL_EXPORT
566 dnl # check symbol exported or not
568 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT], [
569 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
570 $LINUX_OBJ/Module*.symvers 2>/dev/null
572 if test $rc -ne 0; then
575 grep -q -E "EXPORT_SYMBOL.*($1)" \
576 "$LINUX_OBJ/$file" 2>/dev/null
578 if test $rc -eq 0; then
583 if test $export -eq 0; then :
594 dnl # SPL_LINUX_TRY_COMPILE_SYMBOL
595 dnl # like SPL_LINUX_TRY_COMPILE, except SPL_CHECK_SYMBOL_EXPORT
596 dnl # is called if not compiling for builtin
598 AC_DEFUN([SPL_LINUX_TRY_COMPILE_SYMBOL], [
599 SPL_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
600 if test $rc -ne 0; then :
603 if test "x$enable_linux_builtin" != xyes; then
604 SPL_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
606 if test $rc -ne 0; then :
615 dnl # SPL_CHECK_SYMBOL_HEADER
616 dnl # check if a symbol prototype is defined in listed headers.
618 AC_DEFUN([SPL_CHECK_SYMBOL_HEADER], [
619 AC_MSG_CHECKING([whether symbol $1 exists in header])
622 grep -q "$2" "$LINUX/$file" 2>/dev/null
624 if test $rc -eq 0; then
629 if test $header -eq 0; then
639 dnl # SPL_CHECK_HEADER
640 dnl # check whether header exists and define HAVE_$2_HEADER
642 AC_DEFUN([SPL_CHECK_HEADER],
643 [AC_MSG_CHECKING([whether header $1 exists])
644 SPL_LINUX_TRY_COMPILE([
649 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
659 dnl # Basic toolchain sanity check. Verify that kernel modules can
660 dnl # be built and which symbols can be used.
662 AC_DEFUN([SPL_AC_TEST_MODULE],
663 [AC_MSG_CHECKING([whether modules can be built])
664 SPL_LINUX_TRY_COMPILE([],[],[
668 if test "x$enable_linux_builtin" != xyes; then
669 AC_MSG_ERROR([*** Unable to build an empty module.])
672 *** Unable to build an empty module.
673 *** Please run 'make scripts' inside the kernel source tree.])
679 #include "$LINUX/include/linux/license.h"
681 return !license_is_gpl_compatible("$SPL_META_LICENSE");
684 AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
685 [Define to 1 if GPL-only symbols can be used])
691 dnl # Use the atomic implemenation based on global spinlocks. This
692 dnl # should only be needed by 32-bit kernels which do not provide
693 dnl # the atomic64_* API. It may be optionally enabled as a fallback
694 dnl # if problems are observed with the direct mapping to the native
695 dnl # Linux atomic operations. You may not disable atomic spinlocks
696 dnl # if you kernel does not an atomic64_* API.
698 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
699 AC_ARG_ENABLE([atomic-spinlocks],
700 [AS_HELP_STRING([--enable-atomic-spinlocks],
701 [Atomic types use spinlocks @<:@default=check@:>@])],
703 [enable_atomic_spinlocks=check])
705 SPL_LINUX_TRY_COMPILE([
706 #include <linux/fs.h>
708 atomic64_t *ptr __attribute__ ((unused));
711 AC_DEFINE(HAVE_ATOMIC64_T, 1,
712 [kernel defines atomic64_t])
717 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
718 AS_IF([test "x$have_atomic64_t" = xyes], [
719 enable_atomic_spinlocks=no
721 enable_atomic_spinlocks=yes
725 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
726 AC_DEFINE([ATOMIC_SPINLOCK], [1],
727 [Atomic types use spinlocks])
729 AS_IF([test "x$have_atomic64_t" = xno], [
731 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
735 AC_MSG_CHECKING([whether atomic types use spinlocks])
736 AC_MSG_RESULT([$enable_atomic_spinlocks])
738 AC_MSG_CHECKING([whether kernel defines atomic64_t])
739 AC_MSG_RESULT([$have_atomic64_t])
742 AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
743 tmp_flags="$EXTRA_KCFLAGS"
744 EXTRA_KCFLAGS="-Werror"
746 dnl # 2.6.23 to 2.6.34 API change
747 dnl # ->shrink(int nr_to_scan, gfp_t gfp_mask)
749 AC_MSG_CHECKING([whether old 2-argument shrinker exists])
750 SPL_LINUX_TRY_COMPILE([
751 #include <linux/mm.h>
753 int shrinker_cb(int nr_to_scan, gfp_t gfp_mask);
755 struct shrinker cache_shrinker = {
756 .shrink = shrinker_cb,
757 .seeks = DEFAULT_SEEKS,
759 register_shrinker(&cache_shrinker);
762 AC_DEFINE(HAVE_2ARGS_OLD_SHRINKER_CALLBACK, 1,
763 [old shrinker callback wants 2 args])
767 dnl # 2.6.35 - 2.6.39 API change
768 dnl # ->shrink(struct shrinker *,
769 dnl # int nr_to_scan, gfp_t gfp_mask)
771 AC_MSG_CHECKING([whether old 3-argument shrinker exists])
772 SPL_LINUX_TRY_COMPILE([
773 #include <linux/mm.h>
775 int shrinker_cb(struct shrinker *, int nr_to_scan,
778 struct shrinker cache_shrinker = {
779 .shrink = shrinker_cb,
780 .seeks = DEFAULT_SEEKS,
782 register_shrinker(&cache_shrinker);
785 AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1,
786 [old shrinker callback wants 3 args])
790 dnl # 3.0 - 3.11 API change
791 dnl # ->shrink(struct shrinker *,
792 dnl # struct shrink_control *sc)
795 [whether new 2-argument shrinker exists])
796 SPL_LINUX_TRY_COMPILE([
797 #include <linux/mm.h>
799 int shrinker_cb(struct shrinker *,
800 struct shrink_control *sc);
802 struct shrinker cache_shrinker = {
803 .shrink = shrinker_cb,
804 .seeks = DEFAULT_SEEKS,
806 register_shrinker(&cache_shrinker);
809 AC_DEFINE(HAVE_2ARGS_NEW_SHRINKER_CALLBACK, 1,
810 [new shrinker callback wants 2 args])
814 dnl # 3.12 API change,
815 dnl # ->shrink() is logically split in to
816 dnl # ->count_objects() and ->scan_objects()
819 [whether ->count_objects callback exists])
820 SPL_LINUX_TRY_COMPILE([
821 #include <linux/mm.h>
823 unsigned long shrinker_cb(
825 struct shrink_control *sc);
827 struct shrinker cache_shrinker = {
828 .count_objects = shrinker_cb,
829 .scan_objects = shrinker_cb,
830 .seeks = DEFAULT_SEEKS,
832 register_shrinker(&cache_shrinker);
835 AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
836 1, [->count_objects exists])
843 EXTRA_KCFLAGS="$tmp_flags"
847 dnl # 2.6.33 API change,
848 dnl # Removed .ctl_name from struct ctl_table.
850 AC_DEFUN([SPL_AC_CTL_NAME], [
851 AC_MSG_CHECKING([whether struct ctl_table has ctl_name])
852 SPL_LINUX_TRY_COMPILE([
853 #include <linux/sysctl.h>
855 struct ctl_table ctl __attribute__ ((unused));
859 AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name])
866 dnl # 3.10 API change,
867 dnl # PDE is replaced by PDE_DATA
869 AC_DEFUN([SPL_AC_PDE_DATA], [
870 AC_MSG_CHECKING([whether PDE_DATA() is available])
871 SPL_LINUX_TRY_COMPILE_SYMBOL([
872 #include <linux/proc_fs.h>
877 AC_DEFINE(HAVE_PDE_DATA, 1, [yes])
885 dnl # set_fs_pwd takes const struct path *
887 AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
888 tmp_flags="$EXTRA_KCFLAGS"
889 EXTRA_KCFLAGS="-Werror"
890 [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *])
891 SPL_LINUX_TRY_COMPILE([
892 #include <linux/spinlock.h>
893 #include <linux/fs_struct.h>
894 #include <linux/path.h>
895 void (*const set_fs_pwd_func)
896 (struct fs_struct *, const struct path *)
902 AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1,
903 [set_fs_pwd() needs const path *])
905 SPL_LINUX_TRY_COMPILE([
906 #include <linux/spinlock.h>
907 #include <linux/fs_struct.h>
908 #include <linux/path.h>
909 void (*const set_fs_pwd_func)
910 (struct fs_struct *, struct path *)
917 AC_MSG_ERROR(unknown)
920 EXTRA_KCFLAGS="$tmp_flags"
924 dnl # 3.13 API change
925 dnl # vfs_unlink() updated to take a third delegated_inode argument.
927 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
928 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
929 SPL_LINUX_TRY_COMPILE([
930 #include <linux/fs.h>
932 vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
935 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
936 [vfs_unlink() wants 2 args])
940 dnl # Linux 3.13 API change
941 dnl # Added delegated inode
943 AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
944 SPL_LINUX_TRY_COMPILE([
945 #include <linux/fs.h>
947 vfs_unlink((struct inode *) NULL,
948 (struct dentry *) NULL,
949 (struct inode **) NULL);
952 AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
953 [vfs_unlink() wants 3 args])
962 dnl # 3.13 and 3.15 API changes
963 dnl # Added delegated inode and flags argument.
965 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
966 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
967 SPL_LINUX_TRY_COMPILE([
968 #include <linux/fs.h>
970 vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
971 (struct inode *) NULL, (struct dentry *) NULL);
974 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
975 [vfs_rename() wants 4 args])
979 dnl # Linux 3.13 API change
980 dnl # Added delegated inode
982 AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
983 SPL_LINUX_TRY_COMPILE([
984 #include <linux/fs.h>
986 vfs_rename((struct inode *) NULL,
987 (struct dentry *) NULL,
988 (struct inode *) NULL,
989 (struct dentry *) NULL,
990 (struct inode **) NULL);
993 AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
994 [vfs_rename() wants 5 args])
998 dnl # Linux 3.15 API change
1001 AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
1002 SPL_LINUX_TRY_COMPILE([
1003 #include <linux/fs.h>
1005 vfs_rename((struct inode *) NULL,
1006 (struct dentry *) NULL,
1007 (struct inode *) NULL,
1008 (struct dentry *) NULL,
1009 (struct inode **) NULL,
1013 AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
1014 [vfs_rename() wants 6 args])
1023 dnl # 2.6.36 API change,
1024 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
1025 dnl # a spinlock_t to improve the fastpath performance.
1027 AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [
1028 AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t])
1029 tmp_flags="$EXTRA_KCFLAGS"
1030 EXTRA_KCFLAGS="-Werror"
1031 SPL_LINUX_TRY_COMPILE([
1032 #include <linux/sched.h>
1033 #include <linux/fs_struct.h>
1035 static struct fs_struct fs;
1036 spin_lock_init(&fs.lock);
1039 AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1,
1040 [struct fs_struct uses spinlock_t])
1044 EXTRA_KCFLAGS="$tmp_flags"
1048 dnl # User namespaces, use kuid_t in place of uid_t
1049 dnl # where available. Not strictly a user namespaces thing
1050 dnl # but it should prevent surprises
1052 AC_DEFUN([SPL_AC_KUIDGID_T], [
1053 AC_MSG_CHECKING([whether kuid_t/kgid_t is available])
1054 SPL_LINUX_TRY_COMPILE([
1055 #include <linux/uidgid.h>
1057 kuid_t userid = KUIDT_INIT(0);
1058 kgid_t groupid = KGIDT_INIT(0);
1060 SPL_LINUX_TRY_COMPILE([
1061 #include <linux/uidgid.h>
1066 AC_MSG_RESULT(yes; optional)
1068 AC_MSG_RESULT(yes; mandatory)
1069 AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use])
1077 dnl # 2.6.39 API change,
1078 dnl # __put_task_struct() was exported by the mainline kernel.
1080 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT],
1081 [AC_MSG_CHECKING([whether __put_task_struct() is available])
1082 SPL_LINUX_TRY_COMPILE_SYMBOL([
1083 #include <linux/sched.h>
1085 __put_task_struct(NULL);
1086 ], [__put_task_struct], [], [
1088 AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1089 [__put_task_struct() is available])
1096 dnl # 2.6.35 API change,
1097 dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype.
1099 AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [
1100 AC_MSG_CHECKING([whether vfs_fsync() wants 2 args])
1101 SPL_LINUX_TRY_COMPILE([
1102 #include <linux/fs.h>
1107 AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args])
1114 dnl # 3.5 API change,
1115 dnl # inode_operations.truncate_range removed
1117 AC_DEFUN([SPL_AC_INODE_TRUNCATE_RANGE], [
1118 AC_MSG_CHECKING([whether truncate_range() inode operation is available])
1119 SPL_LINUX_TRY_COMPILE([
1120 #include <linux/fs.h>
1122 struct inode_operations ops;
1123 ops.truncate_range = NULL;
1126 AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1,
1127 [truncate_range() inode operation is available])
1134 dnl # Linux 2.6.38 - 3.x API
1136 AC_DEFUN([SPL_AC_KERNEL_FILE_FALLOCATE], [
1137 AC_MSG_CHECKING([whether fops->fallocate() exists])
1138 SPL_LINUX_TRY_COMPILE([
1139 #include <linux/fs.h>
1141 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1142 struct file_operations fops __attribute__ ((unused)) = {
1143 .fallocate = fallocate,
1147 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1154 dnl # Linux 2.6.x - 2.6.37 API
1156 AC_DEFUN([SPL_AC_KERNEL_INODE_FALLOCATE], [
1157 AC_MSG_CHECKING([whether iops->fallocate() exists])
1158 SPL_LINUX_TRY_COMPILE([
1159 #include <linux/fs.h>
1161 long (*fallocate) (struct inode *, int, loff_t, loff_t) = NULL;
1162 struct inode_operations fops __attribute__ ((unused)) = {
1163 .fallocate = fallocate,
1167 AC_DEFINE(HAVE_INODE_FALLOCATE, 1, [fops->fallocate() exists])
1174 dnl # PaX Linux 2.6.38 - 3.x API
1176 AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [
1177 AC_MSG_CHECKING([whether fops->fallocate() exists])
1178 SPL_LINUX_TRY_COMPILE([
1179 #include <linux/fs.h>
1181 long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL;
1182 struct file_operations_no_const fops __attribute__ ((unused)) = {
1183 .fallocate = fallocate,
1187 AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists])
1194 dnl # The fallocate callback was moved from the inode_operations
1195 dnl # structure to the file_operations structure.
1197 AC_DEFUN([SPL_AC_KERNEL_FALLOCATE], [
1198 SPL_AC_KERNEL_FILE_FALLOCATE
1199 SPL_AC_KERNEL_INODE_FALLOCATE
1200 SPL_AC_PAX_KERNEL_FILE_FALLOCATE
1204 dnl # zlib inflate compat,
1205 dnl # Verify the kernel has CONFIG_ZLIB_INFLATE support enabled.
1207 AC_DEFUN([SPL_AC_CONFIG_ZLIB_INFLATE], [
1208 AC_MSG_CHECKING([whether CONFIG_ZLIB_INFLATE is defined])
1209 SPL_LINUX_TRY_COMPILE([
1210 #if !defined(CONFIG_ZLIB_INFLATE) && \
1211 !defined(CONFIG_ZLIB_INFLATE_MODULE)
1212 #error CONFIG_ZLIB_INFLATE not defined
1215 AC_MSG_RESULT([yes])
1219 *** This kernel does not include the required zlib inflate support.
1220 *** Rebuild the kernel with CONFIG_ZLIB_INFLATE=y|m set.])
1225 dnl # zlib deflate compat,
1226 dnl # Verify the kernel has CONFIG_ZLIB_DEFLATE support enabled.
1228 AC_DEFUN([SPL_AC_CONFIG_ZLIB_DEFLATE], [
1229 AC_MSG_CHECKING([whether CONFIG_ZLIB_DEFLATE is defined])
1230 SPL_LINUX_TRY_COMPILE([
1231 #if !defined(CONFIG_ZLIB_DEFLATE) && \
1232 !defined(CONFIG_ZLIB_DEFLATE_MODULE)
1233 #error CONFIG_ZLIB_DEFLATE not defined
1236 AC_MSG_RESULT([yes])
1240 *** This kernel does not include the required zlib deflate support.
1241 *** Rebuild the kernel with CONFIG_ZLIB_DEFLATE=y|m set.])
1246 dnl # 2.6.39 API compat,
1247 dnl # The function zlib_deflate_workspacesize() now take 2 arguments.
1248 dnl # This was done to avoid always having to allocate the maximum size
1249 dnl # workspace (268K). The caller can now specific the windowBits and
1250 dnl # memLevel compression parameters to get a smaller workspace.
1252 AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE],
1253 [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args])
1254 SPL_LINUX_TRY_COMPILE([
1255 #include <linux/zlib.h>
1257 return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL);
1260 AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1,
1261 [zlib_deflate_workspacesize() wants 2 args])
1268 dnl # 2.6.39 API change,
1269 dnl # Shrinker adjust to use common shrink_control structure.
1271 AC_DEFUN([SPL_AC_SHRINK_CONTROL_STRUCT], [
1272 AC_MSG_CHECKING([whether struct shrink_control exists])
1273 SPL_LINUX_TRY_COMPILE([
1274 #include <linux/mm.h>
1276 struct shrink_control sc __attribute__ ((unused));
1279 sc.gfp_mask = GFP_KERNEL;
1282 AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
1283 [struct shrink_control exists])
1290 dnl # 3.1 API Change
1292 dnl # The rw_semaphore.wait_lock member was changed from spinlock_t to
1293 dnl # raw_spinlock_t at commit ddb6c9b58a19edcfac93ac670b066c836ff729f1.
1295 AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [
1296 AC_MSG_CHECKING([whether struct rw_semaphore member wait_lock is raw])
1297 tmp_flags="$EXTRA_KCFLAGS"
1298 EXTRA_KCFLAGS="-Werror"
1299 SPL_LINUX_TRY_COMPILE([
1300 #include <linux/rwsem.h>
1302 struct rw_semaphore dummy_semaphore __attribute__ ((unused));
1303 raw_spinlock_t dummy_lock __attribute__ ((unused));
1304 dummy_semaphore.wait_lock = dummy_lock;
1307 AC_DEFINE(RWSEM_SPINLOCK_IS_RAW, 1,
1308 [struct rw_semaphore member wait_lock is raw_spinlock_t])
1312 EXTRA_KCFLAGS="$tmp_flags"
1316 dnl # 3.9 API change,
1317 dnl # Moved things from linux/sched.h to linux/sched/rt.h
1319 AC_DEFUN([SPL_AC_SCHED_RT_HEADER],
1320 [AC_MSG_CHECKING([whether header linux/sched/rt.h exists])
1321 SPL_LINUX_TRY_COMPILE([
1322 #include <linux/sched.h>
1323 #include <linux/sched/rt.h>
1327 AC_DEFINE(HAVE_SCHED_RT_HEADER, 1, [linux/sched/rt.h exists])
1335 dnl # 3.9 API change,
1336 dnl # vfs_getattr() uses 2 args
1337 dnl # It takes struct path * instead of struct vfsmount * and struct dentry *
1339 AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [
1340 AC_MSG_CHECKING([whether vfs_getattr() wants])
1341 SPL_LINUX_TRY_COMPILE([
1342 #include <linux/fs.h>
1344 vfs_getattr((struct path *) NULL,
1345 (struct kstat *)NULL);
1347 AC_MSG_RESULT(2 args)
1348 AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1,
1349 [vfs_getattr wants 2 args])
1351 SPL_LINUX_TRY_COMPILE([
1352 #include <linux/fs.h>
1354 vfs_getattr((struct vfsmount *)NULL,
1355 (struct dentry *)NULL,
1356 (struct kstat *)NULL);
1358 AC_MSG_RESULT(3 args)
1360 AC_MSG_ERROR(unknown)
1366 dnl # 2.6.36 API compatibility.
1367 dnl # Added usleep_range timer.
1368 dnl # usleep_range is a finer precision implementation of msleep
1369 dnl # designed to be a drop-in replacement for udelay where a precise
1370 dnl # sleep / busy-wait is unnecessary.
1372 AC_DEFUN([SPL_AC_USLEEP_RANGE], [
1373 AC_MSG_CHECKING([whether usleep_range() is available])
1374 SPL_LINUX_TRY_COMPILE([
1375 #include <linux/delay.h>
1380 AC_DEFINE(HAVE_USLEEP_RANGE, 1,
1381 [usleep_range is available])
1388 dnl # 2.6.35 API change,
1389 dnl # The cachep->gfpflags member was renamed cachep->allocflags. These are
1390 dnl # private allocation flags which are applied when allocating a new slab
1391 dnl # in kmem_getpages(). Unfortunately there is no public API for setting
1392 dnl # non-default flags.
1394 AC_DEFUN([SPL_AC_KMEM_CACHE_ALLOCFLAGS], [
1395 AC_MSG_CHECKING([whether struct kmem_cache has allocflags])
1396 SPL_LINUX_TRY_COMPILE([
1397 #include <linux/slab.h>
1399 struct kmem_cache cachep __attribute__ ((unused));
1400 cachep.allocflags = GFP_KERNEL;
1403 AC_DEFINE(HAVE_KMEM_CACHE_ALLOCFLAGS, 1,
1404 [struct kmem_cache has allocflags])
1408 AC_MSG_CHECKING([whether struct kmem_cache has gfpflags])
1409 SPL_LINUX_TRY_COMPILE([
1410 #include <linux/slab.h>
1412 struct kmem_cache cachep __attribute__ ((unused));
1413 cachep.gfpflags = GFP_KERNEL;
1416 AC_DEFINE(HAVE_KMEM_CACHE_GFPFLAGS, 1,
1417 [struct kmem_cache has gfpflags])
1425 dnl # 3.17 API change,
1426 dnl # wait_on_bit() no longer requires an action argument. The former
1427 dnl # "wait_on_bit" interface required an 'action' function to be provided
1428 dnl # which does the actual waiting. There were over 20 such functions in the
1429 dnl # kernel, many of them identical, though most cases can be satisfied by one
1430 dnl # of just two functions: one which uses io_schedule() and one which just
1431 dnl # uses schedule(). This API change was made to consolidate all of those
1432 dnl # redundant wait functions.
1434 AC_DEFUN([SPL_AC_WAIT_ON_BIT], [
1435 AC_MSG_CHECKING([whether wait_on_bit() takes an action])
1436 SPL_LINUX_TRY_COMPILE([
1437 #include <linux/wait.h>
1439 int (*action)(void *) = NULL;
1440 wait_on_bit(NULL, 0, action, 0);
1443 AC_DEFINE(HAVE_WAIT_ON_BIT_ACTION, 1, [yes])