1 ###############################################################################
2 # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 # Copyright (C) 2007 The Regents of the University of California.
4 # Written by Brian Behlendorf <behlendorf1@llnl.gov>.
5 ###############################################################################
6 # SPL_AC_CONFIG_KERNEL: Default SPL kernel configuration.
7 ###############################################################################
9 AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
12 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
13 dnl # compiler options are added by the kernel build system.
14 abs_srcdir=`readlink -f ${srcdir}`
15 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes -Werror"
16 KERNELCPPFLAGS="$KERNELCPPFLAGS -I${abs_srcdir}/include"
17 KERNELCPPFLAGS="$KERNELCPPFLAGS -include ${abs_srcdir}/spl_config.h"
19 if test "${LINUX_OBJ}" != "${LINUX}"; then
20 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
23 AC_SUBST(KERNELMAKE_PARAMS)
24 AC_SUBST(KERNELCPPFLAGS)
28 SPL_AC_DEBUG_KMEM_TRACKING
29 SPL_AC_ATOMIC_SPINLOCK
30 SPL_AC_TYPE_ATOMIC64_CMPXCHG
31 SPL_AC_TYPE_ATOMIC64_XCHG
33 SPL_AC_3ARGS_INIT_WORK
34 SPL_AC_2ARGS_REGISTER_SYSCTL
36 SPL_AC_PATH_IN_NAMEIDATA
41 SPL_AC_5ARGS_DEVICE_CREATE
42 SPL_AC_CLASS_DEVICE_CREATE
43 SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT
44 SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE
51 SPL_AC_MONOTONIC_CLOCK
54 SPL_AC_MUTEX_LOCK_NESTED
57 SPL_AC_3ARGS_ON_EACH_CPU
58 SPL_AC_KALLSYMS_LOOKUP_NAME
59 SPL_AC_GET_VMALLOC_INFO
61 SPL_AC_FIRST_ONLINE_PGDAT
62 SPL_AC_NEXT_ONLINE_PGDAT
65 SPL_AC_GLOBAL_PAGE_STATE
66 SPL_AC_ZONE_STAT_ITEM_FREE
67 SPL_AC_ZONE_STAT_ITEM_INACTIVE
68 SPL_AC_ZONE_STAT_ITEM_ACTIVE
69 SPL_AC_GET_ZONE_COUNTS
71 SPL_AC_2ARGS_SET_FS_PWD
72 SPL_AC_2ARGS_VFS_UNLINK
73 SPL_AC_4ARGS_VFS_RENAME
76 SPL_AC_PUT_TASK_STRUCT
77 SPL_AC_5ARGS_PROC_HANDLER
81 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
82 modpost=$LINUX/scripts/Makefile.modpost
83 AC_MSG_CHECKING([kernel file name for module symbols])
84 if test -f "$modpost"; then
85 if grep -q Modules.symvers $modpost; then
86 LINUX_SYMBOLS=Modules.symvers
88 LINUX_SYMBOLS=Module.symvers
93 AC_MSG_RESULT($LINUX_SYMBOLS)
94 AC_SUBST(LINUX_SYMBOLS)
97 AC_DEFUN([SPL_AC_KERNEL], [
99 AS_HELP_STRING([--with-linux=PATH],
100 [Path to kernel source]),
101 [kernelsrc="$withval"])
103 AC_ARG_WITH([linux-obj],
104 AS_HELP_STRING([--with-linux-obj=PATH],
105 [Path to kernel build objects]),
106 [kernelbuild="$withval"])
108 AC_MSG_CHECKING([kernel source directory])
109 if test -z "$kernelsrc"; then
110 headersdir="/lib/modules/$(uname -r)/build"
111 if test -e "$headersdir"; then
112 sourcelink=$(readlink -f "$headersdir")
114 sourcelink=$(ls -1d /usr/src/kernels/* \
116 2>/dev/null | grep -v obj | tail -1)
119 if test -e ${sourcelink}; then
120 kernelsrc=`readlink -f ${sourcelink}`
122 AC_MSG_RESULT([Not found])
124 *** Please specify the location of the kernel source
125 *** with the '--with-linux=PATH' option])
128 if test "$kernelsrc" = "NONE"; then
133 AC_MSG_RESULT([$kernelsrc])
134 AC_MSG_CHECKING([kernel build directory])
135 if test -z "$kernelbuild"; then
136 if test -d ${kernelsrc}-obj/`arch`/`arch`; then
137 kernelbuild=${kernelsrc}-obj/`arch`/`arch`
138 elif test -d ${kernelsrc}-obj/`arch`/default; then
139 kernelbuild=${kernelsrc}-obj/`arch`/default
140 elif test -d `dirname ${kernelsrc}`/build-`arch`; then
141 kernelbuild=`dirname ${kernelsrc}`/build-`arch`
143 kernelbuild=${kernelsrc}
146 AC_MSG_RESULT([$kernelbuild])
148 AC_MSG_CHECKING([kernel source version])
149 utsrelease1=$kernelbuild/include/linux/version.h
150 utsrelease2=$kernelbuild/include/linux/utsrelease.h
151 utsrelease3=$kernelbuild/include/generated/utsrelease.h
152 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
153 utsrelease=linux/version.h
154 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
155 utsrelease=linux/utsrelease.h
156 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
157 utsrelease=generated/utsrelease.h
160 if test "$utsrelease"; then
161 kernsrcver=`(echo "#include <$utsrelease>";
162 echo "kernsrcver=UTS_RELEASE") |
163 cpp -I $kernelbuild/include |
164 grep "^kernsrcver=" | cut -d \" -f 2`
166 if test -z "$kernsrcver"; then
167 AC_MSG_RESULT([Not found])
168 AC_MSG_ERROR([*** Cannot determine kernel version.])
171 AC_MSG_RESULT([Not found])
172 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
175 AC_MSG_RESULT([$kernsrcver])
178 LINUX_OBJ=${kernelbuild}
179 LINUX_VERSION=${kernsrcver}
183 AC_SUBST(LINUX_VERSION)
185 SPL_AC_MODULE_SYMVERS
189 dnl # Default SPL user configuration
191 AC_DEFUN([SPL_AC_CONFIG_USER], [])
193 AC_DEFUN([SPL_AC_LICENSE], [
194 AC_MSG_CHECKING([spl license])
196 AC_MSG_RESULT([$LICENSE])
197 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DHAVE_GPL_ONLY_SYMBOLS"
201 AC_DEFUN([SPL_AC_CONFIG], [
203 AC_ARG_WITH([config],
204 AS_HELP_STRING([--with-config=CONFIG],
205 [Config file 'kernel|user|all|srpm']),
206 [SPL_CONFIG="$withval"])
208 AC_MSG_CHECKING([spl config])
209 AC_MSG_RESULT([$SPL_CONFIG]);
212 case "$SPL_CONFIG" in
213 kernel) SPL_AC_CONFIG_KERNEL ;;
214 user) SPL_AC_CONFIG_USER ;;
215 all) SPL_AC_CONFIG_KERNEL
216 SPL_AC_CONFIG_USER ;;
219 AC_MSG_RESULT([Error!])
220 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
221 user kernel|user|all|srpm]) ;;
224 AM_CONDITIONAL([CONFIG_USER],
225 [test "$SPL_CONFIG" = user] ||
226 [test "$SPL_CONFIG" = all])
227 AM_CONDITIONAL([CONFIG_KERNEL],
228 [test "$SPL_CONFIG" = kernel] ||
229 [test "$SPL_CONFIG" = all])
233 dnl # Enable if the SPL should be compiled with internal debugging enabled.
234 dnl # By default this support is disabled.
236 AC_DEFUN([SPL_AC_DEBUG], [
237 AC_ARG_ENABLE([debug],
238 [AS_HELP_STRING([--enable-debug],
239 [Enable generic debug support @<:@default=no@:>@])],
243 AS_IF([test "x$enable_debug" = xyes],
244 [KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG"],
245 [KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"])
247 AC_MSG_CHECKING([whether debugging is enabled])
248 AC_MSG_RESULT([$enable_debug])
252 dnl # Enabled by default it provides a minimal level of memory tracking.
253 dnl # A total count of bytes allocated is kept for each alloc and free.
254 dnl # Then at module unload time a report to the console will be printed
255 dnl # if memory was leaked. Additionally, /proc/spl/kmem/slab will exist
256 dnl # and provide an easy way to inspect the kmem based slab.
258 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
259 AC_ARG_ENABLE([debug-kmem],
260 [AS_HELP_STRING([--enable-debug-kmem],
261 [Enable basic kmem accounting @<:@default=yes@:>@])],
263 [enable_debug_kmem=yes])
265 AS_IF([test "x$enable_debug_kmem" = xyes],
266 [AC_DEFINE([DEBUG_KMEM], [1],
267 [Define to 1 to enable basic kmem accounting])
268 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"])
270 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
271 AC_MSG_RESULT([$enable_debug_kmem])
275 dnl # Disabled by default it provides detailed memory tracking. This
276 dnl # feature also requires --enable-debug-kmem to be set. When enabled
277 dnl # not only will total bytes be tracked but also the location of every
278 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
279 dnl # addresses and where they were allocated will be dumped to the console.
280 dnl # Enabling this feature has a significant impact on performance but it
281 dnl # makes finding memory leaks pretty straight forward.
283 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
284 AC_ARG_ENABLE([debug-kmem-tracking],
285 [AS_HELP_STRING([--enable-debug-kmem-tracking],
286 [Enable detailed kmem tracking @<:@default=no@:>@])],
288 [enable_debug_kmem_tracking=no])
290 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
291 [AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
292 [Define to 1 to enable detailed kmem tracking])
293 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"])
295 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
296 AC_MSG_RESULT([$enable_debug_kmem_tracking])
300 dnl # SPL_LINUX_CONFTEST
302 AC_DEFUN([SPL_LINUX_CONFTEST], [
303 cat >conftest.c <<_ACEOF
309 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
311 m4_define([SPL_LANG_PROGRAM], [
316 dnl Do *not* indent the following line: there may be CPP directives.
317 dnl Don't move the `;' right after for the same reason.
325 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
327 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
328 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
329 rm -Rf build && mkdir -p build
330 echo "obj-m := conftest.o" >build/Makefile
332 [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])],
334 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
340 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
342 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
343 [SPL_LINUX_COMPILE_IFELSE(
344 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
346 [test -s build/conftest.o],
351 dnl # SPL_LINUX_CONFIG
353 AC_DEFUN([SPL_LINUX_CONFIG],
354 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
355 SPL_LINUX_TRY_COMPILE([
356 #ifndef AUTOCONF_INCLUDED
357 #include <linux/config.h>
361 #error CONFIG_$1 not #defined
373 dnl # SPL_CHECK_SYMBOL_EXPORT
374 dnl # check symbol exported or not
376 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
377 [AC_MSG_CHECKING([whether symbol $1 is exported])
378 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
379 $LINUX_OBJ/Module*.symvers 2>/dev/null
381 if test $rc -ne 0; then
384 grep -q -E "EXPORT_SYMBOL.*($1)" \
385 "$LINUX_OBJ/$file" 2>/dev/null
387 if test $rc -eq 0; then
392 if test $export -eq 0; then
406 dnl # SPL_CHECK_HEADER
407 dnl # check whether header exists and define HAVE_$2_HEADER
409 AC_DEFUN([SPL_CHECK_HEADER],
410 [AC_MSG_CHECKING([whether header $1 exists])
411 SPL_LINUX_TRY_COMPILE([
416 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
426 dnl # Use the atomic implemenation based on global spinlocks. This
427 dnl # should only be needed by 32-bit kernels which do not provide
428 dnl # the atomic64_* API. It may be optionally enabled as a fallback
429 dnl # if problems are observed with the direct mapping to the native
430 dnl # Linux atomic operations. You may not disable atomic spinlocks
431 dnl # if you kernel does not an atomic64_* API.
433 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
434 AC_ARG_ENABLE([atomic-spinlocks],
435 [AS_HELP_STRING([--enable-atomic-spinlocks],
436 [Atomic types use spinlocks @<:@default=check@:>@])],
438 [enable_atomic_spinlocks=check])
440 SPL_LINUX_TRY_COMPILE([
441 #include <asm/atomic.h>
446 AC_DEFINE(HAVE_ATOMIC64_T, 1,
447 [kernel defines atomic64_t])
452 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
453 AS_IF([test "x$have_atomic64_t" = xyes], [
454 enable_atomic_spinlocks=no
456 enable_atomic_spinlocks=yes
460 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
461 AC_DEFINE([ATOMIC_SPINLOCK], [1],
462 [Atomic types use spinlocks])
464 AS_IF([test "x$have_atomic64_t" = xno], [
466 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
470 AC_MSG_CHECKING([whether atomic types use spinlocks])
471 AC_MSG_RESULT([$enable_atomic_spinlocks])
473 AC_MSG_CHECKING([whether kernel defines atomic64_t])
474 AC_MSG_RESULT([$have_atomic64_t])
478 dnl # 2.6.24 API change,
479 dnl # check if atomic64_cmpxchg is defined
481 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_CMPXCHG],
482 [AC_MSG_CHECKING([whether kernel defines atomic64_cmpxchg])
483 SPL_LINUX_TRY_COMPILE([
484 #include <asm/atomic.h>
486 atomic64_cmpxchg((atomic64_t *)NULL, 0, 0);
489 AC_DEFINE(HAVE_ATOMIC64_CMPXCHG, 1,
490 [kernel defines atomic64_cmpxchg])
497 dnl # 2.6.24 API change,
498 dnl # check if atomic64_xchg is defined
500 AC_DEFUN([SPL_AC_TYPE_ATOMIC64_XCHG],
501 [AC_MSG_CHECKING([whether kernel defines atomic64_xchg])
502 SPL_LINUX_TRY_COMPILE([
503 #include <asm/atomic.h>
505 atomic64_xchg((atomic64_t *)NULL, 0);
508 AC_DEFINE(HAVE_ATOMIC64_XCHG, 1,
509 [kernel defines atomic64_xchg])
516 dnl # 2.6.24 API change,
517 dnl # check if uintptr_t typedef is defined
519 AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
520 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
521 SPL_LINUX_TRY_COMPILE([
522 #include <linux/types.h>
527 AC_DEFINE(HAVE_UINTPTR_T, 1,
528 [kernel defines uintptr_t])
535 dnl # 2.6.20 API change,
536 dnl # INIT_WORK use 2 args and not store data inside
538 AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
539 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
540 SPL_LINUX_TRY_COMPILE([
541 #include <linux/workqueue.h>
543 struct work_struct work;
544 INIT_WORK(&work, NULL, NULL);
547 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
548 [INIT_WORK wants 3 args])
555 dnl # 2.6.21 API change,
556 dnl # 'register_sysctl_table' use only one argument instead of two
558 AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
559 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
560 SPL_LINUX_TRY_COMPILE([
561 #include <linux/sysctl.h>
563 return register_sysctl_table(NULL,0);
566 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
567 [register_sysctl_table() wants 2 args])
574 dnl # 2.6.23 API change
575 dnl # Old set_shrinker API replaced with register_shrinker
577 AC_DEFUN([SPL_AC_SET_SHRINKER], [
578 AC_MSG_CHECKING([whether set_shrinker() available])
579 SPL_LINUX_TRY_COMPILE([
580 #include <linux/mm.h>
582 return set_shrinker(DEFAULT_SEEKS, NULL);
585 AC_DEFINE(HAVE_SET_SHRINKER, 1,
586 [set_shrinker() available])
593 dnl # 2.6.25 API change,
594 dnl # struct path entry added to struct nameidata
596 AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
597 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
598 SPL_LINUX_TRY_COMPILE([
599 #include <linux/namei.h>
604 nd.path.dentry = NULL;
607 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
608 [struct path used in struct nameidata])
615 dnl # Custom SPL patch may export this system it is not required
617 AC_DEFUN([SPL_AC_TASK_CURR], [
618 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
619 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
624 dnl # 2.6.19 API change,
625 dnl # Use CTL_UNNUMBERED when binary sysctl is not required
627 AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
628 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
629 SPL_LINUX_TRY_COMPILE([
630 #include <linux/sysctl.h>
632 #ifndef CTL_UNNUMBERED
633 #error CTL_UNNUMBERED undefined
637 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
638 [unnumbered sysctl support exists])
645 dnl # 2.6.16 API change.
646 dnl # Check if 'fls64()' is available
648 AC_DEFUN([SPL_AC_FLS64],
649 [AC_MSG_CHECKING([whether fls64() is available])
650 SPL_LINUX_TRY_COMPILE([
651 #include <linux/bitops.h>
656 AC_DEFINE(HAVE_FLS64, 1, [fls64() is available])
663 dnl # 2.6.18 API change, check whether device_create() is available.
664 dnl # Device_create() was introduced in 2.6.18 and depricated
665 dnl # class_device_create() which was fully removed in 2.6.26.
667 AC_DEFUN([SPL_AC_DEVICE_CREATE], [
668 SPL_CHECK_SYMBOL_EXPORT(
670 [drivers/base/core.c],
671 [AC_DEFINE(HAVE_DEVICE_CREATE, 1,
672 [device_create() is available])],
677 dnl # 2.6.27 API change,
678 dnl # device_create() uses 5 args, new 'drvdata' argument.
680 AC_DEFUN([SPL_AC_5ARGS_DEVICE_CREATE], [
681 AC_MSG_CHECKING([whether device_create() wants 5 args])
682 tmp_flags="$EXTRA_KCFLAGS"
683 EXTRA_KCFLAGS="-Werror"
684 SPL_LINUX_TRY_COMPILE([
685 #include <linux/device.h>
687 device_create(NULL, NULL, 0, NULL, "%d", 1);
690 AC_DEFINE(HAVE_5ARGS_DEVICE_CREATE, 1,
691 [device_create wants 5 args])
695 EXTRA_KCFLAGS="$tmp_flags"
699 dnl # 2.6.13 API change, check whether class_device_create() is available.
700 dnl # Class_device_create() was introduced in 2.6.13 and depricated
701 dnl # class_simple_device_add() which was fully removed in 2.6.13.
703 AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [
704 SPL_CHECK_SYMBOL_EXPORT(
705 [class_device_create],
706 [drivers/base/class.c],
707 [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1,
708 [class_device_create() is available])],
713 dnl # 2.6.26 API change, set_normalized_timespec() is exported.
715 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT], [
716 SPL_CHECK_SYMBOL_EXPORT(
717 [set_normalized_timespec],
719 [AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
720 [set_normalized_timespec() is available as export])],
725 dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
726 dnl # previously it was available in time.h as an inline.
728 AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
729 AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
730 SPL_LINUX_TRY_COMPILE([
731 #include <linux/time.h>
732 void set_normalized_timespec(struct timespec *ts,
733 time_t sec, long nsec) { }
740 AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
741 [set_normalized_timespec() is available as inline])
746 dnl # 2.6.18 API change,
747 dnl # timespec_sub() inline function available in linux/time.h
749 AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
750 AC_MSG_CHECKING([whether timespec_sub() is available])
751 SPL_LINUX_TRY_COMPILE([
752 #include <linux/time.h>
754 struct timespec a, b, c = { 0 };
755 c = timespec_sub(a, b);
758 AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
765 dnl # 2.6.19 API change,
766 dnl # check if init_utsname() is available in linux/utsname.h
768 AC_DEFUN([SPL_AC_INIT_UTSNAME], [
769 AC_MSG_CHECKING([whether init_utsname() is available])
770 SPL_LINUX_TRY_COMPILE([
771 #include <linux/utsname.h>
773 struct new_utsname *a = init_utsname();
776 AC_DEFINE(HAVE_INIT_UTSNAME, 1, [init_utsname() is available])
783 dnl # 2.6.26 API change,
784 dnl # definition of struct fdtable relocated to linux/fdtable.h
786 AC_DEFUN([SPL_AC_FDTABLE_HEADER], [
787 SPL_CHECK_HEADER([linux/fdtable.h], [FDTABLE], [], [])
791 dnl # 2.6.14 API change,
792 dnl # check whether 'files_fdtable()' exists
794 AC_DEFUN([SPL_AC_FILES_FDTABLE], [
795 AC_MSG_CHECKING([whether files_fdtable() is available])
796 SPL_LINUX_TRY_COMPILE([
797 #include <linux/sched.h>
798 #include <linux/file.h>
799 #ifdef HAVE_FDTABLE_HEADER
800 #include <linux/fdtable.h>
803 struct files_struct *files = current->files;
804 struct fdtable *fdt = files_fdtable(files);
807 AC_DEFINE(HAVE_FILES_FDTABLE, 1, [files_fdtable() is available])
814 dnl # 2.6.18 API change,
815 dnl # added linux/uaccess.h
817 AC_DEFUN([SPL_AC_UACCESS_HEADER], [
818 SPL_CHECK_HEADER([linux/uaccess.h], [UACCESS], [], [])
822 dnl # 2.6.12 API change,
823 dnl # check whether 'kmalloc_node()' is available.
825 AC_DEFUN([SPL_AC_KMALLOC_NODE], [
826 AC_MSG_CHECKING([whether kmalloc_node() is available])
827 SPL_LINUX_TRY_COMPILE([
828 #include <linux/slab.h>
830 void *a = kmalloc_node(1, GFP_KERNEL, 0);
833 AC_DEFINE(HAVE_KMALLOC_NODE, 1, [kmalloc_node() is available])
840 dnl # 2.6.9 API change,
841 dnl # check whether 'monotonic_clock()' is available it may
842 dnl # be available for some archs but not others.
844 AC_DEFUN([SPL_AC_MONOTONIC_CLOCK], [
845 SPL_CHECK_SYMBOL_EXPORT(
848 [AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
849 [monotonic_clock() is available])],
854 dnl # 2.6.16 API change,
855 dnl # check whether 'struct inode' has i_mutex
857 AC_DEFUN([SPL_AC_INODE_I_MUTEX], [
858 AC_MSG_CHECKING([whether struct inode has i_mutex])
859 SPL_LINUX_TRY_COMPILE([
860 #include <linux/fs.h>
861 #include <linux/mutex.h>
864 mutex_init(&i.i_mutex);
867 AC_DEFINE(HAVE_INODE_I_MUTEX, 1, [struct inode has i_mutex])
874 dnl # 2.6.29 API change,
875 dnl # Adaptive mutexs introduced.
877 AC_DEFUN([SPL_AC_MUTEX_OWNER], [
878 AC_MSG_CHECKING([whether struct mutex has owner])
879 SPL_LINUX_TRY_COMPILE([
880 #include <linux/mutex.h>
886 AC_DEFINE(HAVE_MUTEX_OWNER, 1, [struct mutex has owner])
893 dnl # 2.6.18 API change,
894 dnl # First introduced 'mutex_lock_nested()' in include/linux/mutex.h,
895 dnl # as part of the mutex validator. Fallback to using 'mutex_lock()'
896 dnl # if the mutex validator is disabled or otherwise unavailable.
898 AC_DEFUN([SPL_AC_MUTEX_LOCK_NESTED], [
899 AC_MSG_CHECKING([whether mutex_lock_nested() is available])
900 SPL_LINUX_TRY_COMPILE([
901 #include <linux/mutex.h>
905 mutex_lock_nested(&mutex, 0);
908 AC_DEFINE(HAVE_MUTEX_LOCK_NESTED, 1,
909 [mutex_lock_nested() is available])
916 dnl # 2.6.22 API change,
917 dnl # First introduced 'div64_64()' in lib/div64.c
919 AC_DEFUN([SPL_AC_DIV64_64], [
920 SPL_CHECK_SYMBOL_EXPORT(
923 [AC_DEFINE(HAVE_DIV64_64, 1,
924 [div64_64() is available])],
929 dnl # 2.6.26 API change,
930 dnl # Renamed 'div64_64()' to 'div64_u64' in lib/div64.c
932 AC_DEFUN([SPL_AC_DIV64_U64], [
933 SPL_CHECK_SYMBOL_EXPORT(
936 [AC_DEFINE(HAVE_DIV64_U64, 1,
937 [div64_u64() is available])],
942 dnl # 2.6.27 API change,
943 dnl # on_each_cpu() uses 3 args, no 'retry' argument
945 AC_DEFUN([SPL_AC_3ARGS_ON_EACH_CPU], [
946 AC_MSG_CHECKING([whether on_each_cpu() wants 3 args])
947 SPL_LINUX_TRY_COMPILE([
948 #include <linux/smp.h>
950 on_each_cpu(NULL, NULL, 0);
953 AC_DEFINE(HAVE_3ARGS_ON_EACH_CPU, 1,
954 [on_each_cpu wants 3 args])
961 dnl # 2.6.18 API change,
962 dnl # kallsyms_lookup_name no longer exported
964 AC_DEFUN([SPL_AC_KALLSYMS_LOOKUP_NAME], [
965 SPL_CHECK_SYMBOL_EXPORT(
966 [kallsyms_lookup_name],
968 [AC_DEFINE(HAVE_KALLSYMS_LOOKUP_NAME, 1,
969 [kallsyms_lookup_name() is available])],
974 dnl # Proposed API change,
975 dnl # This symbol is not available in stock kernels. You may build a
976 dnl # custom kernel with the *-spl-export-symbols.patch which will export
977 dnl # these symbols for use. If your already rolling a custom kernel for
978 dnl # your environment this is recommended.
980 AC_DEFUN([SPL_AC_GET_VMALLOC_INFO], [
981 SPL_CHECK_SYMBOL_EXPORT(
984 [AC_DEFINE(HAVE_GET_VMALLOC_INFO, 1,
985 [get_vmalloc_info() is available])],
990 dnl # 2.6.17 API change
991 dnl # The helper functions first_online_pgdat(), next_online_pgdat(), and
992 dnl # next_zone() are introduced to simplify for_each_zone(). These symbols
993 dnl # were exported in 2.6.17 for use by modules which was consistent with
994 dnl # the previous implementation of for_each_zone(). From 2.6.18 - 2.6.19
995 dnl # the symbols were exported as 'unused', and by 2.6.20 they exports
996 dnl # were dropped entirely leaving modules no way to directly iterate over
997 dnl # the zone list. Because we need access to the zone helpers we check
998 dnl # if the kernel contains the old or new implementation. Then we check
999 dnl # to see if the symbols we need for each version are available. If they
1000 dnl # are not, dynamically aquire the addresses with kallsyms_lookup_name().
1002 AC_DEFUN([SPL_AC_PGDAT_HELPERS], [
1003 AC_MSG_CHECKING([whether symbol *_pgdat exist])
1004 grep -q -E 'first_online_pgdat' $LINUX/include/linux/mmzone.h 2>/dev/null
1006 if test $rc -eq 0; then
1007 AC_MSG_RESULT([yes])
1008 AC_DEFINE(HAVE_PGDAT_HELPERS, 1, [pgdat helpers are available])
1015 dnl # Proposed API change,
1016 dnl # This symbol is not available in stock kernels. You may build a
1017 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1018 dnl # these symbols for use. If your already rolling a custom kernel for
1019 dnl # your environment this is recommended.
1021 AC_DEFUN([SPL_AC_FIRST_ONLINE_PGDAT], [
1022 SPL_CHECK_SYMBOL_EXPORT(
1023 [first_online_pgdat],
1025 [AC_DEFINE(HAVE_FIRST_ONLINE_PGDAT, 1,
1026 [first_online_pgdat() is available])],
1031 dnl # Proposed API change,
1032 dnl # This symbol is not available in stock kernels. You may build a
1033 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1034 dnl # these symbols for use. If your already rolling a custom kernel for
1035 dnl # your environment this is recommended.
1037 AC_DEFUN([SPL_AC_NEXT_ONLINE_PGDAT], [
1038 SPL_CHECK_SYMBOL_EXPORT(
1039 [next_online_pgdat],
1041 [AC_DEFINE(HAVE_NEXT_ONLINE_PGDAT, 1,
1042 [next_online_pgdat() is available])],
1047 dnl # Proposed API change,
1048 dnl # This symbol is not available in stock kernels. You may build a
1049 dnl # custom kernel with the *-spl-export-symbols.patch which will export
1050 dnl # these symbols for use. If your already rolling a custom kernel for
1051 dnl # your environment this is recommended.
1053 AC_DEFUN([SPL_AC_NEXT_ZONE], [
1054 SPL_CHECK_SYMBOL_EXPORT(
1057 [AC_DEFINE(HAVE_NEXT_ZONE, 1,
1058 [next_zone() is available])],
1063 dnl # 2.6.17 API change,
1064 dnl # See SPL_AC_PGDAT_HELPERS for details.
1066 AC_DEFUN([SPL_AC_PGDAT_LIST], [
1067 SPL_CHECK_SYMBOL_EXPORT(
1070 [AC_DEFINE(HAVE_PGDAT_LIST, 1,
1071 [pgdat_list is available])],
1076 dnl # 2.6.18 API change,
1077 dnl # First introduced global_page_state() support as an inline.
1079 AC_DEFUN([SPL_AC_GLOBAL_PAGE_STATE], [
1080 AC_MSG_CHECKING([whether global_page_state() is available])
1081 SPL_LINUX_TRY_COMPILE([
1082 #include <linux/mm.h>
1084 unsigned long state;
1085 state = global_page_state(0);
1088 AC_DEFINE(HAVE_GLOBAL_PAGE_STATE, 1,
1089 [global_page_state() is available])
1096 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1097 dnl # Public global zone stats now include a free page count. However
1098 dnl # the enumerated names of the counters have changed since this API
1099 dnl # was introduced. We need to deduce the corrent name to use. This
1100 dnl # replaces the priviate get_zone_counts() interface.
1102 dnl # NR_FREE_PAGES was available from 2.6.21 to current kernels, which
1103 dnl # is 2.6.30 as of when this was written.
1105 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_FREE], [
1106 AC_MSG_CHECKING([whether page state NR_FREE_PAGES is available])
1107 SPL_LINUX_TRY_COMPILE([
1108 #include <linux/mm.h>
1110 enum zone_stat_item zsi;
1111 zsi = NR_FREE_PAGES;
1114 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES, 1,
1115 [Page state NR_FREE_PAGES is available])
1122 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1123 dnl # Public global zone stats now include an inactive page count. However
1124 dnl # the enumerated names of the counters have changed since this API
1125 dnl # was introduced. We need to deduce the corrent name to use. This
1126 dnl # replaces the priviate get_zone_counts() interface.
1128 dnl # NR_INACTIVE was available from 2.6.21 to 2.6.27 and included both
1129 dnl # anonymous and file inactive pages. As of 2.6.28 it was split in
1130 dnl # to NR_INACTIVE_ANON and NR_INACTIVE_FILE.
1132 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_INACTIVE], [
1133 AC_MSG_CHECKING([whether page state NR_INACTIVE is available])
1134 SPL_LINUX_TRY_COMPILE([
1135 #include <linux/mm.h>
1137 enum zone_stat_item zsi;
1141 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE, 1,
1142 [Page state NR_INACTIVE is available])
1147 AC_MSG_CHECKING([whether page state NR_INACTIVE_ANON is available])
1148 SPL_LINUX_TRY_COMPILE([
1149 #include <linux/mm.h>
1151 enum zone_stat_item zsi;
1152 zsi = NR_INACTIVE_ANON;
1155 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON, 1,
1156 [Page state NR_INACTIVE_ANON is available])
1161 AC_MSG_CHECKING([whether page state NR_INACTIVE_FILE is available])
1162 SPL_LINUX_TRY_COMPILE([
1163 #include <linux/mm.h>
1165 enum zone_stat_item zsi;
1166 zsi = NR_INACTIVE_FILE;
1169 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE, 1,
1170 [Page state NR_INACTIVE_FILE is available])
1177 dnl # 2.6.21 API change (plus subsequent naming convention changes),
1178 dnl # Public global zone stats now include an active page count. However
1179 dnl # the enumerated names of the counters have changed since this API
1180 dnl # was introduced. We need to deduce the corrent name to use. This
1181 dnl # replaces the priviate get_zone_counts() interface.
1183 dnl # NR_ACTIVE was available from 2.6.21 to 2.6.27 and included both
1184 dnl # anonymous and file active pages. As of 2.6.28 it was split in
1185 dnl # to NR_ACTIVE_ANON and NR_ACTIVE_FILE.
1187 AC_DEFUN([SPL_AC_ZONE_STAT_ITEM_ACTIVE], [
1188 AC_MSG_CHECKING([whether page state NR_ACTIVE is available])
1189 SPL_LINUX_TRY_COMPILE([
1190 #include <linux/mm.h>
1192 enum zone_stat_item zsi;
1196 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE, 1,
1197 [Page state NR_ACTIVE is available])
1202 AC_MSG_CHECKING([whether page state NR_ACTIVE_ANON is available])
1203 SPL_LINUX_TRY_COMPILE([
1204 #include <linux/mm.h>
1206 enum zone_stat_item zsi;
1207 zsi = NR_ACTIVE_ANON;
1210 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON, 1,
1211 [Page state NR_ACTIVE_ANON is available])
1216 AC_MSG_CHECKING([whether page state NR_ACTIVE_FILE is available])
1217 SPL_LINUX_TRY_COMPILE([
1218 #include <linux/mm.h>
1220 enum zone_stat_item zsi;
1221 zsi = NR_ACTIVE_FILE;
1224 AC_DEFINE(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE, 1,
1225 [Page state NR_ACTIVE_FILE is available])
1232 dnl # Proposed API change for legacy kernels.
1233 dnl # This symbol is not available in older kernels. For kernels post
1234 dnl # 2.6.21 the global_page_state() API is used to get free/inactive/active
1235 dnl # page state information. This symbol is only used in legacy kernels
1236 dnl # any only as a last resort.
1238 AC_DEFUN([SPL_AC_GET_ZONE_COUNTS], [
1239 AC_MSG_CHECKING([whether symbol get_zone_counts is needed])
1240 SPL_LINUX_TRY_COMPILE([
1242 #if !defined(HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES)
1243 #error "global_page_state needs NR_FREE_PAGES"
1246 #if !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE) && \
1247 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON) && \
1248 !defined(HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE)
1249 #error "global_page_state needs NR_ACTIVE*"
1252 #if !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE) && \
1253 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON) && \
1254 !defined(HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE)
1255 #error "global_page_state needs NR_INACTIVE*"
1261 AC_DEFINE(NEED_GET_ZONE_COUNTS, 1,
1262 [get_zone_counts() is needed])
1264 SPL_CHECK_SYMBOL_EXPORT(
1267 [AC_DEFINE(HAVE_GET_ZONE_COUNTS, 1,
1268 [get_zone_counts() is available])],
1274 dnl # Symbol available in RHEL kernels not in stock kernels.
1276 AC_DEFUN([SPL_AC_SET_FS_PWD], [
1277 SPL_CHECK_SYMBOL_EXPORT(
1280 [AC_DEFINE(HAVE_SET_FS_PWD, 1,
1281 [set_fs_pwd() is available])],
1286 dnl # 2.6.25 API change,
1287 dnl # Simplied API by replacing mnt+dentry args with a single path arg.
1289 AC_DEFUN([SPL_AC_2ARGS_SET_FS_PWD],
1290 [AC_MSG_CHECKING([whether set_fs_pwd() wants 2 args])
1291 SPL_LINUX_TRY_COMPILE([
1292 #include <linux/sched.h>
1293 #include <linux/fs_struct.h>
1295 set_fs_pwd(NULL, NULL);
1298 AC_DEFINE(HAVE_2ARGS_SET_FS_PWD, 1,
1299 [set_fs_pwd() wants 2 args])
1306 dnl # SLES API change, never adopted in mainline,
1307 dnl # Third 'struct vfsmount *' argument removed.
1309 AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
1310 [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
1311 SPL_LINUX_TRY_COMPILE([
1312 #include <linux/fs.h>
1314 vfs_unlink(NULL, NULL);
1317 AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
1318 [vfs_unlink() wants 2 args])
1325 dnl # SLES API change, never adopted in mainline,
1326 dnl # Third and sixth 'struct vfsmount *' argument removed.
1328 AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
1329 [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
1330 SPL_LINUX_TRY_COMPILE([
1331 #include <linux/fs.h>
1333 vfs_rename(NULL, NULL, NULL, NULL);
1336 AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
1337 [vfs_rename() wants 4 args])
1344 dnl # 2.6.29 API change,
1345 dnl # check whether 'struct cred' exists
1347 AC_DEFUN([SPL_AC_CRED_STRUCT], [
1348 AC_MSG_CHECKING([whether struct cred exists])
1349 SPL_LINUX_TRY_COMPILE([
1350 #include <linux/cred.h>
1356 AC_DEFINE(HAVE_CRED_STRUCT, 1, [struct cred exists])
1363 dnl # Custom SPL patch may export this symbol.
1365 AC_DEFUN([SPL_AC_GROUPS_SEARCH], [
1366 SPL_CHECK_SYMBOL_EXPORT(
1369 [AC_DEFINE(HAVE_GROUPS_SEARCH, 1,
1370 [groups_search() is available])],
1375 dnl # 2.6.x API change,
1376 dnl # __put_task_struct() was exported in RHEL5 but unavailable elsewhere.
1378 AC_DEFUN([SPL_AC_PUT_TASK_STRUCT], [
1379 SPL_CHECK_SYMBOL_EXPORT(
1380 [__put_task_struct],
1382 [AC_DEFINE(HAVE_PUT_TASK_STRUCT, 1,
1383 [__put_task_struct() is available])],
1388 dnl # 2.6.32 API change,
1389 dnl # Unused 'struct file *' removed from prototype.
1391 AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [
1392 AC_MSG_CHECKING([whether proc_handler() wants 5 args])
1393 SPL_LINUX_TRY_COMPILE([
1394 #include <linux/sysctl.h>
1396 proc_dostring(NULL, 0, NULL, NULL, NULL);
1399 AC_DEFINE(HAVE_5ARGS_PROC_HANDLER, 1,
1400 [proc_handler() wants 5 args])
1407 dnl # 2.6.x API change,
1408 dnl # kvasprintf() function added.
1410 AC_DEFUN([SPL_AC_KVASPRINTF], [
1411 SPL_CHECK_SYMBOL_EXPORT(
1414 [AC_DEFINE(HAVE_KVASPRINTF, 1,
1415 [kvasprintf() is available])],