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_INSERT_INODE_LOCKED
38 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
39 ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
40 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
41 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
42 ZFS_AC_KERNEL_MOUNT_NODEV
44 ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
45 ZFS_AC_KERNEL_SET_NLINK
47 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
48 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
50 AC_SUBST(KERNELMAKE_PARAMS)
53 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
54 dnl # compiler options are added by the kernel build system.
55 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
56 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
57 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
59 AC_SUBST(KERNELCPPFLAGS)
63 dnl # Detect name used for Module.symvers file in kernel
65 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
66 modpost=$LINUX/scripts/Makefile.modpost
67 AC_MSG_CHECKING([kernel file name for module symbols])
68 AS_IF([test -f "$modpost"], [
69 AS_IF([grep -q Modules.symvers $modpost], [
70 LINUX_SYMBOLS=Modules.symvers
72 LINUX_SYMBOLS=Module.symvers
75 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
77 *** Please make sure the kernel devel package for your distribution
78 *** is installed. If your building with a custom kernel make sure the
79 *** kernel is configured, built, and the '--with-linux=PATH' configure
80 *** option refers to the location of the kernel source.])
85 AC_MSG_RESULT($LINUX_SYMBOLS)
86 AC_SUBST(LINUX_SYMBOLS)
90 dnl # Detect the kernel to be built against
92 AC_DEFUN([ZFS_AC_KERNEL], [
94 AS_HELP_STRING([--with-linux=PATH],
95 [Path to kernel source]),
96 [kernelsrc="$withval"])
98 AC_ARG_WITH(linux-obj,
99 AS_HELP_STRING([--with-linux-obj=PATH],
100 [Path to kernel build objects]),
101 [kernelbuild="$withval"])
103 AC_MSG_CHECKING([kernel source directory])
104 AS_IF([test -z "$kernelsrc"], [
105 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
106 headersdir="/lib/modules/$(uname -r)/source"
107 sourcelink=$(readlink -f "$headersdir")
108 ], [test -e "/lib/modules/$(uname -r)/build"], [
109 headersdir="/lib/modules/$(uname -r)/build"
110 sourcelink=$(readlink -f "$headersdir")
112 sourcelink=$(ls -1d /usr/src/kernels/* \
114 2>/dev/null | grep -v obj | tail -1)
117 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
118 kernelsrc=`readlink -f ${sourcelink}`
120 AC_MSG_RESULT([Not found])
122 *** Please make sure the kernel devel package for your distribution
123 *** is installed then try again. If that fails you can specify the
124 *** location of the kernel source with the '--with-linux=PATH' option.])
127 AS_IF([test "$kernelsrc" = "NONE"], [
132 AC_MSG_RESULT([$kernelsrc])
133 AC_MSG_CHECKING([kernel build directory])
134 AS_IF([test -z "$kernelbuild"], [
135 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
136 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
137 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
138 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
139 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
140 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
141 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
142 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
144 kernelbuild=${kernelsrc}
147 AC_MSG_RESULT([$kernelbuild])
149 AC_MSG_CHECKING([kernel source version])
150 utsrelease1=$kernelbuild/include/linux/version.h
151 utsrelease2=$kernelbuild/include/linux/utsrelease.h
152 utsrelease3=$kernelbuild/include/generated/utsrelease.h
153 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
154 utsrelease=linux/version.h
155 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
156 utsrelease=linux/utsrelease.h
157 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
158 utsrelease=generated/utsrelease.h
161 AS_IF([test "$utsrelease"], [
162 kernsrcver=`(echo "#include <$utsrelease>";
163 echo "kernsrcver=UTS_RELEASE") |
164 cpp -I $kernelbuild/include |
165 grep "^kernsrcver=" | cut -d \" -f 2`
167 AS_IF([test -z "$kernsrcver"], [
168 AC_MSG_RESULT([Not found])
169 AC_MSG_ERROR([*** Cannot determine kernel version.])
172 AC_MSG_RESULT([Not found])
173 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
176 AC_MSG_RESULT([$kernsrcver])
179 LINUX_OBJ=${kernelbuild}
180 LINUX_VERSION=${kernsrcver}
184 AC_SUBST(LINUX_VERSION)
186 ZFS_AC_MODULE_SYMVERS
190 dnl # Detect name used for the additional SPL Module.symvers file. If one
191 dnl # does not exist this is likely because the SPL has been configured
192 dnl # but not built. To allow recursive builds a good guess is made as to
193 dnl # what this file will be named based on what it is named in the kernel
194 dnl # build products. This file will first be used at link time so if
195 dnl # the guess is wrong the build will fail then. This unfortunately
196 dnl # means the ZFS package does not contain a reliable mechanism to
197 dnl # detect symbols exported by the SPL at configure time.
199 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
200 AC_MSG_CHECKING([spl file name for module symbols])
201 AS_IF([test -r $SPL_OBJ/Module.symvers], [
202 SPL_SYMBOLS=Module.symvers
203 ], [test -r $SPL_OBJ/Modules.symvers], [
204 SPL_SYMBOLS=Modules.symvers
205 ], [test -r $SPL_OBJ/module/Module.symvers], [
206 SPL_SYMBOLS=Module.symvers
207 ], [test -r $SPL_OBJ/module/Modules.symvers], [
208 SPL_SYMBOLS=Modules.symvers
210 SPL_SYMBOLS=$LINUX_SYMBOLS
213 AC_MSG_RESULT([$SPL_SYMBOLS])
214 AC_SUBST(SPL_SYMBOLS)
218 dnl # Detect the SPL module to be built against
220 AC_DEFUN([ZFS_AC_SPL], [
222 AS_HELP_STRING([--with-spl=PATH],
223 [Path to spl source]),
226 AC_ARG_WITH([spl-obj],
227 AS_HELP_STRING([--with-spl-obj=PATH],
228 [Path to spl build objects]),
229 [splbuild="$withval"])
232 AC_MSG_CHECKING([spl source directory])
233 AS_IF([test -z "$splsrc"], [
234 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
235 2>/dev/null | tail -1`
237 AS_IF([test -z "$sourcelink" || test ! -e $sourcelink], [
241 AS_IF([test -e $sourcelink], [
242 splsrc=`readlink -f ${sourcelink}`
244 AC_MSG_RESULT([Not found])
246 *** Please make sure the spl devel package for your distribution
247 *** is installed then try again. If that fails you can specify the
248 *** location of the spl source with the '--with-spl=PATH' option.])
251 AS_IF([test "$splsrc" = "NONE"], [
257 AC_MSG_RESULT([$splsrc])
258 AC_MSG_CHECKING([spl build directory])
259 AS_IF([test -z "$splbuild"], [
262 AC_MSG_RESULT([$splbuild])
264 AC_MSG_CHECKING([spl source version])
265 AS_IF([test -r $splbuild/spl_config.h &&
266 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
268 splsrcver=`(echo "#include <spl_config.h>";
269 echo "splsrcver=SPL_META_VERSION") |
271 grep "^splsrcver=" | cut -d \" -f 2`
274 AS_IF([test -z "$splsrcver"], [
275 AC_MSG_RESULT([Not found])
277 *** Cannot determine the version of the spl source.
278 *** Please prepare the spl source before running this script])
281 AC_MSG_RESULT([$splsrcver])
285 SPL_VERSION=${splsrcver}
289 AC_SUBST(SPL_VERSION)
291 ZFS_AC_SPL_MODULE_SYMVERS
295 dnl # Certain kernel build options are not supported. These must be
296 dnl # detected at configure time and cause a build failure. Otherwise
297 dnl # modules may be successfully built that behave incorrectly.
299 dnl # CONFIG_PREEMPT - Preempt kernels require special handling.
301 dnl # There are certain kernel build options which when enabled are
302 dnl # completely incompatible with non GPL kernel modules. It is best
303 dnl # to detect these at configure time and fail with a clear error
304 dnl # rather than build everything and fail during linking.
306 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
308 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
310 ZFS_LINUX_CONFIG([PREEMPT],
312 *** Kernel built with CONFIG_PREEMPT which is not supported.
313 *** You must rebuild your kernel without this option.]), [])
315 AS_IF([test "$ZFS_META_LICENSE" = CDDL], [
316 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
318 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
319 *** incompatible with the CDDL license. You must rebuild
320 *** your kernel without this option.]), [])
323 AS_IF([test "$ZFS_META_LICENSE" = GPL], [
324 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
325 [Define to 1 if licensed under the GPL])
330 dnl # ZFS_LINUX_CONFTEST
332 AC_DEFUN([ZFS_LINUX_CONFTEST], [
333 cat confdefs.h - <<_ACEOF >conftest.c
339 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
341 m4_define([ZFS_LANG_PROGRAM], [
346 dnl Do *not* indent the following line: there may be CPP directives.
347 dnl Don't move the `;' right after for the same reason.
355 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
357 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
358 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
359 rm -Rf build && mkdir -p build
360 echo "obj-m := conftest.o" >build/Makefile
362 [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])],
364 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
370 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
372 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
373 [ZFS_LINUX_COMPILE_IFELSE(
374 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
376 [test -s build/conftest.o],
381 dnl # ZFS_LINUX_CONFIG
383 AC_DEFUN([ZFS_LINUX_CONFIG],
384 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
385 ZFS_LINUX_TRY_COMPILE([
386 #include <linux/module.h>
389 #error CONFIG_$1 not #defined
401 dnl # ZFS_CHECK_SYMBOL_EXPORT
402 dnl # check symbol exported or not
404 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
405 [AC_MSG_CHECKING([whether symbol $1 is exported])
406 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
407 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
409 AS_IF([test $rc -ne 0], [
412 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
414 AS_IF([test $rc -eq 0], [
419 AS_IF([test $export -eq 0], [