2 dnl # Default ZFS kernel configuration
4 AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
8 ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
9 ZFS_AC_KERNEL_TYPE_FMODE_T
10 ZFS_AC_KERNEL_KOBJ_NAME_LEN
11 ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
12 ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
13 ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
14 ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
15 ZFS_AC_KERNEL_BIO_EMPTY_BARRIER
16 ZFS_AC_KERNEL_BIO_FAILFAST
17 ZFS_AC_KERNEL_BIO_FAILFAST_DTD
18 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
19 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
20 ZFS_AC_KERNEL_BIO_RW_SYNC
21 ZFS_AC_KERNEL_BIO_RW_SYNCIO
22 ZFS_AC_KERNEL_REQ_SYNC
23 ZFS_AC_KERNEL_BLK_END_REQUEST
24 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
25 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
26 ZFS_AC_KERNEL_BLK_RQ_BYTES
27 ZFS_AC_KERNEL_BLK_RQ_POS
28 ZFS_AC_KERNEL_BLK_RQ_SECTORS
29 ZFS_AC_KERNEL_GET_DISK_RO
30 ZFS_AC_KERNEL_RQ_IS_SYNC
31 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
32 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
33 ZFS_AC_KERNEL_XATTR_HANDLER_GET
34 ZFS_AC_KERNEL_XATTR_HANDLER_SET
36 ZFS_AC_KERNEL_EVICT_INODE
37 ZFS_AC_KERNEL_NR_CACHED_OBJECTS
38 ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
39 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
40 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
41 ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
42 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
43 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
44 ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
45 ZFS_AC_KERNEL_MOUNT_NODEV
48 ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
49 ZFS_AC_KERNEL_SET_NLINK
51 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
52 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
54 AC_SUBST(KERNELMAKE_PARAMS)
57 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
58 dnl # compiler options are added by the kernel build system.
59 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
60 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
61 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
63 AC_SUBST(KERNELCPPFLAGS)
67 dnl # Detect name used for Module.symvers file in kernel
69 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
70 modpost=$LINUX/scripts/Makefile.modpost
71 AC_MSG_CHECKING([kernel file name for module symbols])
72 AS_IF([test -f "$modpost"], [
73 AS_IF([grep -q Modules.symvers $modpost], [
74 LINUX_SYMBOLS=Modules.symvers
76 LINUX_SYMBOLS=Module.symvers
79 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
81 *** Please make sure the kernel devel package for your distribution
82 *** is installed. If your building with a custom kernel make sure the
83 *** kernel is configured, built, and the '--with-linux=PATH' configure
84 *** option refers to the location of the kernel source.])
89 AC_MSG_RESULT($LINUX_SYMBOLS)
90 AC_SUBST(LINUX_SYMBOLS)
94 dnl # Detect the kernel to be built against
96 AC_DEFUN([ZFS_AC_KERNEL], [
98 AS_HELP_STRING([--with-linux=PATH],
99 [Path to kernel source]),
100 [kernelsrc="$withval"])
102 AC_ARG_WITH(linux-obj,
103 AS_HELP_STRING([--with-linux-obj=PATH],
104 [Path to kernel build objects]),
105 [kernelbuild="$withval"])
107 AC_MSG_CHECKING([kernel source directory])
108 AS_IF([test -z "$kernelsrc"], [
109 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
110 headersdir="/lib/modules/$(uname -r)/source"
111 sourcelink=$(readlink -f "$headersdir")
112 ], [test -e "/lib/modules/$(uname -r)/build"], [
113 headersdir="/lib/modules/$(uname -r)/build"
114 sourcelink=$(readlink -f "$headersdir")
116 sourcelink=$(ls -1d /usr/src/kernels/* \
118 2>/dev/null | grep -v obj | tail -1)
121 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
122 kernelsrc=`readlink -f ${sourcelink}`
124 AC_MSG_RESULT([Not found])
126 *** Please make sure the kernel devel package for your distribution
127 *** is installed then try again. If that fails you can specify the
128 *** location of the kernel source with the '--with-linux=PATH' option.])
131 AS_IF([test "$kernelsrc" = "NONE"], [
136 AC_MSG_RESULT([$kernelsrc])
137 AC_MSG_CHECKING([kernel build directory])
138 AS_IF([test -z "$kernelbuild"], [
139 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
140 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
141 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
142 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
143 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
144 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
145 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
146 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
148 kernelbuild=${kernelsrc}
151 AC_MSG_RESULT([$kernelbuild])
153 AC_MSG_CHECKING([kernel source version])
154 utsrelease1=$kernelbuild/include/linux/version.h
155 utsrelease2=$kernelbuild/include/linux/utsrelease.h
156 utsrelease3=$kernelbuild/include/generated/utsrelease.h
157 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
158 utsrelease=linux/version.h
159 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
160 utsrelease=linux/utsrelease.h
161 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
162 utsrelease=generated/utsrelease.h
165 AS_IF([test "$utsrelease"], [
166 kernsrcver=`(echo "#include <$utsrelease>";
167 echo "kernsrcver=UTS_RELEASE") |
168 cpp -I $kernelbuild/include |
169 grep "^kernsrcver=" | cut -d \" -f 2`
171 AS_IF([test -z "$kernsrcver"], [
172 AC_MSG_RESULT([Not found])
173 AC_MSG_ERROR([*** Cannot determine kernel version.])
176 AC_MSG_RESULT([Not found])
177 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
180 AC_MSG_RESULT([$kernsrcver])
183 LINUX_OBJ=${kernelbuild}
184 LINUX_VERSION=${kernsrcver}
188 AC_SUBST(LINUX_VERSION)
190 ZFS_AC_MODULE_SYMVERS
194 dnl # Detect name used for the additional SPL Module.symvers file. If one
195 dnl # does not exist this is likely because the SPL has been configured
196 dnl # but not built. To allow recursive builds a good guess is made as to
197 dnl # what this file will be named based on what it is named in the kernel
198 dnl # build products. This file will first be used at link time so if
199 dnl # the guess is wrong the build will fail then. This unfortunately
200 dnl # means the ZFS package does not contain a reliable mechanism to
201 dnl # detect symbols exported by the SPL at configure time.
203 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
204 AC_MSG_CHECKING([spl file name for module symbols])
205 AS_IF([test -r $SPL_OBJ/Module.symvers], [
206 SPL_SYMBOLS=Module.symvers
207 ], [test -r $SPL_OBJ/Modules.symvers], [
208 SPL_SYMBOLS=Modules.symvers
209 ], [test -r $SPL_OBJ/module/Module.symvers], [
210 SPL_SYMBOLS=Module.symvers
211 ], [test -r $SPL_OBJ/module/Modules.symvers], [
212 SPL_SYMBOLS=Modules.symvers
214 SPL_SYMBOLS=$LINUX_SYMBOLS
217 AC_MSG_RESULT([$SPL_SYMBOLS])
218 AC_SUBST(SPL_SYMBOLS)
222 dnl # Detect the SPL module to be built against
224 AC_DEFUN([ZFS_AC_SPL], [
226 AS_HELP_STRING([--with-spl=PATH],
227 [Path to spl source]),
230 AC_ARG_WITH([spl-obj],
231 AS_HELP_STRING([--with-spl-obj=PATH],
232 [Path to spl build objects]),
233 [splbuild="$withval"])
236 AC_MSG_CHECKING([spl source directory])
237 AS_IF([test -z "$splsrc"], [
238 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
239 2>/dev/null | tail -1`
241 AS_IF([test -z "$sourcelink" || test ! -e $sourcelink], [
245 AS_IF([test -e $sourcelink], [
246 splsrc=`readlink -f ${sourcelink}`
248 AC_MSG_RESULT([Not found])
250 *** Please make sure the spl devel package for your distribution
251 *** is installed then try again. If that fails you can specify the
252 *** location of the spl source with the '--with-spl=PATH' option.])
255 AS_IF([test "$splsrc" = "NONE"], [
261 AC_MSG_RESULT([$splsrc])
262 AC_MSG_CHECKING([spl build directory])
263 AS_IF([test -z "$splbuild"], [
266 AC_MSG_RESULT([$splbuild])
268 AC_MSG_CHECKING([spl source version])
269 AS_IF([test -r $splbuild/spl_config.h &&
270 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
272 splsrcver=`(echo "#include <spl_config.h>";
273 echo "splsrcver=SPL_META_VERSION") |
275 grep "^splsrcver=" | cut -d \" -f 2`
278 AS_IF([test -z "$splsrcver"], [
279 AC_MSG_RESULT([Not found])
281 *** Cannot determine the version of the spl source.
282 *** Please prepare the spl source before running this script])
285 AC_MSG_RESULT([$splsrcver])
289 SPL_VERSION=${splsrcver}
293 AC_SUBST(SPL_VERSION)
295 ZFS_AC_SPL_MODULE_SYMVERS
299 dnl # Certain kernel build options are not supported. These must be
300 dnl # detected at configure time and cause a build failure. Otherwise
301 dnl # modules may be successfully built that behave incorrectly.
303 dnl # CONFIG_PREEMPT - Preempt kernels require special handling.
305 dnl # There are certain kernel build options which when enabled are
306 dnl # completely incompatible with non GPL kernel modules. It is best
307 dnl # to detect these at configure time and fail with a clear error
308 dnl # rather than build everything and fail during linking.
310 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
312 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
314 ZFS_LINUX_CONFIG([PREEMPT],
316 *** Kernel built with CONFIG_PREEMPT which is not supported.
317 *** You must rebuild your kernel without this option.]), [])
319 AS_IF([test "$ZFS_META_LICENSE" = CDDL], [
320 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
322 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
323 *** incompatible with the CDDL license. You must rebuild
324 *** your kernel without this option.]), [])
327 AS_IF([test "$ZFS_META_LICENSE" = GPL], [
328 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
329 [Define to 1 if licensed under the GPL])
334 dnl # ZFS_LINUX_CONFTEST
336 AC_DEFUN([ZFS_LINUX_CONFTEST], [
337 cat confdefs.h - <<_ACEOF >conftest.c
343 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
345 m4_define([ZFS_LANG_PROGRAM], [
350 dnl Do *not* indent the following line: there may be CPP directives.
351 dnl Don't move the `;' right after for the same reason.
359 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
361 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
362 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
363 rm -Rf build && mkdir -p build
364 echo "obj-m := conftest.o" >build/Makefile
366 [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])],
368 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
374 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
376 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
377 [ZFS_LINUX_COMPILE_IFELSE(
378 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
380 [test -s build/conftest.o],
385 dnl # ZFS_LINUX_CONFIG
387 AC_DEFUN([ZFS_LINUX_CONFIG],
388 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
389 ZFS_LINUX_TRY_COMPILE([
390 #include <linux/module.h>
393 #error CONFIG_$1 not #defined
405 dnl # ZFS_CHECK_SYMBOL_EXPORT
406 dnl # check symbol exported or not
408 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
409 [AC_MSG_CHECKING([whether symbol $1 is exported])
410 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
411 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
413 AS_IF([test $rc -ne 0], [
416 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
418 AS_IF([test $rc -eq 0], [
423 AS_IF([test $export -eq 0], [