]> git.proxmox.com Git - mirror_zfs-debian.git/blame - config/kernel.m4
Suppress 'vdev_metaslab_init' memory warning
[mirror_zfs-debian.git] / config / kernel.m4
CommitLineData
c9c0d073
BB
1dnl #
2dnl # Default ZFS kernel configuration
3dnl #
4AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5 ZFS_AC_KERNEL
6 ZFS_AC_SPL
7 ZFS_AC_KERNEL_CONFIG
8 ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
9 ZFS_AC_KERNEL_TYPE_FMODE_T
10 ZFS_AC_KERNEL_KOBJ_NAME_LEN
45066d1f 11 ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
c9c0d073
BB
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
2959d94a 16 ZFS_AC_KERNEL_BIO_FAILFAST
f4af6bb7
BB
17 ZFS_AC_KERNEL_BIO_FAILFAST_DTD
18 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
c9c0d073 19 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
675de5aa 20 ZFS_AC_KERNEL_BIO_RW_SYNC
c9c0d073 21 ZFS_AC_KERNEL_BIO_RW_SYNCIO
675de5aa 22 ZFS_AC_KERNEL_REQ_SYNC
c9c0d073
BB
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
777d4af8 32 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
f9637c6c
BB
33 ZFS_AC_KERNEL_XATTR_HANDLER_GET
34 ZFS_AC_KERNEL_XATTR_HANDLER_SET
7268e1be 35 ZFS_AC_KERNEL_FSYNC_2ARGS
2c395def 36 ZFS_AC_KERNEL_EVICT_INODE
bdf4328b 37 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
c9c0d073 38
6283f55e
BB
39 if test "$LINUX_OBJ" != "$LINUX"; then
40 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
41 fi
42 AC_SUBST(KERNELMAKE_PARAMS)
43
44
c9c0d073
BB
45 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
46 dnl # compiler options are added by the kernel build system.
12c1acde 47 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wno-unused-but-set-variable"
c9c0d073
BB
48 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
49 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
c9c0d073 50
c9c0d073
BB
51 AC_SUBST(KERNELCPPFLAGS)
52])
53
54dnl #
55dnl # Detect name used for Module.symvers file in kernel
56dnl #
57AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
58 modpost=$LINUX/scripts/Makefile.modpost
59 AC_MSG_CHECKING([kernel file name for module symbols])
60 if test -f "$modpost"; then
61 if grep -q Modules.symvers $modpost; then
62 LINUX_SYMBOLS=Modules.symvers
63 else
64 LINUX_SYMBOLS=Module.symvers
65 fi
a60b1c0a
BB
66
67 if ! test -f "$LINUX_OBJ/$LINUX_SYMBOLS"; then
68 AC_MSG_ERROR([
69 *** Please make sure the kernel devel package for your distribution
70 *** is installed. If your building with a custom kernel make sure the
71 *** kernel is configured, built, and the '--with-linux=PATH' configure
72 *** option refers to the location of the kernel source.])
73 fi
c9c0d073
BB
74 else
75 LINUX_SYMBOLS=NONE
76 fi
77 AC_MSG_RESULT($LINUX_SYMBOLS)
78 AC_SUBST(LINUX_SYMBOLS)
79])
80
81dnl #
82dnl # Detect the kernel to be built against
83dnl #
84AC_DEFUN([ZFS_AC_KERNEL], [
85 AC_ARG_WITH([linux],
86 AS_HELP_STRING([--with-linux=PATH],
87 [Path to kernel source]),
88 [kernelsrc="$withval"])
89
90 AC_ARG_WITH(linux-obj,
91 AS_HELP_STRING([--with-linux-obj=PATH],
92 [Path to kernel build objects]),
93 [kernelbuild="$withval"])
94
95 AC_MSG_CHECKING([kernel source directory])
96 if test -z "$kernelsrc"; then
1b94c25c
BB
97 if test -e "/lib/modules/$(uname -r)/source"; then
98 headersdir="/lib/modules/$(uname -r)/source"
99 sourcelink=$(readlink -f "$headersdir")
100 elif test -e "/lib/modules/$(uname -r)/build"; then
101 headersdir="/lib/modules/$(uname -r)/build"
c9c0d073
BB
102 sourcelink=$(readlink -f "$headersdir")
103 else
104 sourcelink=$(ls -1d /usr/src/kernels/* \
105 /usr/src/linux-* \
106 2>/dev/null | grep -v obj | tail -1)
107 fi
108
109 if test -n "$sourcelink" && test -e ${sourcelink}; then
110 kernelsrc=`readlink -f ${sourcelink}`
111 else
112 AC_MSG_RESULT([Not found])
113 AC_MSG_ERROR([
114 *** Please make sure the kernel devel package for your distribution
115 *** is installed then try again. If that fails you can specify the
116 *** location of the kernel source with the '--with-linux=PATH' option.])
117 fi
118 else
119 if test "$kernelsrc" = "NONE"; then
120 kernsrcver=NONE
121 fi
122 fi
123
124 AC_MSG_RESULT([$kernelsrc])
125 AC_MSG_CHECKING([kernel build directory])
126 if test -z "$kernelbuild"; then
1b94c25c
BB
127 if test -e "/lib/modules/$(uname -r)/build"; then
128 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
129 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
c9c0d073
BB
130 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
131 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
132 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
133 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
134 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
135 else
136 kernelbuild=${kernelsrc}
137 fi
138 fi
139 AC_MSG_RESULT([$kernelbuild])
140
141 AC_MSG_CHECKING([kernel source version])
142 utsrelease1=$kernelbuild/include/linux/version.h
143 utsrelease2=$kernelbuild/include/linux/utsrelease.h
144 utsrelease3=$kernelbuild/include/generated/utsrelease.h
145 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
146 utsrelease=linux/version.h
147 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
148 utsrelease=linux/utsrelease.h
149 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
150 utsrelease=generated/utsrelease.h
151 fi
152
153 if test "$utsrelease"; then
154 kernsrcver=`(echo "#include <$utsrelease>";
155 echo "kernsrcver=UTS_RELEASE") |
156 cpp -I $kernelbuild/include |
157 grep "^kernsrcver=" | cut -d \" -f 2`
158
159 if test -z "$kernsrcver"; then
160 AC_MSG_RESULT([Not found])
161 AC_MSG_ERROR([*** Cannot determine kernel version.])
162 fi
163 else
164 AC_MSG_RESULT([Not found])
165 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
166 fi
167
168 AC_MSG_RESULT([$kernsrcver])
169
170 LINUX=${kernelsrc}
171 LINUX_OBJ=${kernelbuild}
172 LINUX_VERSION=${kernsrcver}
173
174 AC_SUBST(LINUX)
175 AC_SUBST(LINUX_OBJ)
176 AC_SUBST(LINUX_VERSION)
177
178 ZFS_AC_MODULE_SYMVERS
179])
180
181dnl #
182dnl # Detect name used for the additional SPL Module.symvers file. If one
183dnl # does not exist this is likely because the SPL has been configured
184dnl # but not built. To allow recursive builds a good guess is made as to
185dnl # what this file will be named based on what it is named in the kernel
186dnl # build products. This file will first be used at link time so if
187dnl # the guess is wrong the build will fail then. This unfortunately
188dnl # means the ZFS package does not contain a reliable mechanism to
189dnl # detect symbols exported by the SPL at configure time.
190dnl #
191AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
192 AC_MSG_CHECKING([spl file name for module symbols])
193 if test -r $SPL_OBJ/Module.symvers; then
194 SPL_SYMBOLS=Module.symvers
195 elif test -r $SPL_OBJ/Modules.symvers; then
196 SPL_SYMBOLS=Modules.symvers
6283f55e
BB
197 elif test -r $SPL_OBJ/module/Module.symvers; then
198 SPL_SYMBOLS=Module.symvers
199 elif test -r $SPL_OBJ/module/Modules.symvers; then
200 SPL_SYMBOLS=Modules.symvers
c9c0d073
BB
201 else
202 SPL_SYMBOLS=$LINUX_SYMBOLS
203 fi
204
205 AC_MSG_RESULT([$SPL_SYMBOLS])
206 AC_SUBST(SPL_SYMBOLS)
207])
208
209dnl #
210dnl # Detect the SPL module to be built against
211dnl #
212AC_DEFUN([ZFS_AC_SPL], [
213 AC_ARG_WITH([spl],
214 AS_HELP_STRING([--with-spl=PATH],
215 [Path to spl source]),
216 [splsrc="$withval"])
217
218 AC_ARG_WITH([spl-obj],
219 AS_HELP_STRING([--with-spl-obj=PATH],
220 [Path to spl build objects]),
221 [splbuild="$withval"])
222
223
224 AC_MSG_CHECKING([spl source directory])
225 if test -z "$splsrc"; then
226 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
227 2>/dev/null | tail -1`
228
229 if test -z "$sourcelink" || test ! -e $sourcelink; then
230 sourcelink=../spl
231 fi
232
233 if test -e $sourcelink; then
234 splsrc=`readlink -f ${sourcelink}`
235 else
236 AC_MSG_RESULT([Not found])
237 AC_MSG_ERROR([
238 *** Please make sure the spl devel package for your distribution
239 *** is installed then try again. If that fails you can specify the
240 *** location of the spl source with the '--with-spl=PATH' option.])
241 fi
242 else
243 if test "$splsrc" = "NONE"; then
244 splbuild=NONE
245 splsrcver=NONE
246 fi
247 fi
248
249 AC_MSG_RESULT([$splsrc])
250 AC_MSG_CHECKING([spl build directory])
251 if test -z "$splbuild"; then
6283f55e 252 splbuild=${splsrc}
c9c0d073
BB
253 fi
254 AC_MSG_RESULT([$splbuild])
255
256 AC_MSG_CHECKING([spl source version])
5e612145
BB
257 if test -r $splbuild/spl_config.h &&
258 fgrep -q SPL_META_VERSION $splbuild/spl_config.h; then
c9c0d073
BB
259
260 splsrcver=`(echo "#include <spl_config.h>";
261 echo "splsrcver=SPL_META_VERSION") |
5e612145 262 cpp -I $splbuild |
c9c0d073
BB
263 grep "^splsrcver=" | cut -d \" -f 2`
264 fi
265
266 if test -z "$splsrcver"; then
267 AC_MSG_RESULT([Not found])
268 AC_MSG_ERROR([
269 *** Cannot determine the version of the spl source.
270 *** Please prepare the spl source before running this script])
271 fi
272
273 AC_MSG_RESULT([$splsrcver])
274
275 SPL=${splsrc}
276 SPL_OBJ=${splbuild}
277 SPL_VERSION=${splsrcver}
278
279 AC_SUBST(SPL)
280 AC_SUBST(SPL_OBJ)
281 AC_SUBST(SPL_VERSION)
282
283 ZFS_AC_SPL_MODULE_SYMVERS
284])
285
15805c77
BB
286dnl #
287dnl # Certain kernel build options are not supported. These must be
288dnl # detected at configure time and cause a build failure. Otherwise
289dnl # modules may be successfully built that behave incorrectly.
290dnl #
291dnl # CONFIG_PREEMPT - Preempt kernels require special handling.
c9c0d073
BB
292dnl #
293dnl # There are certain kernel build options which when enabled are
294dnl # completely incompatible with non GPL kernel modules. It is best
295dnl # to detect these at configure time and fail with a clear error
296dnl # rather than build everything and fail during linking.
297dnl #
298dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
299dnl #
300AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
301
15805c77
BB
302 ZFS_LINUX_CONFIG([PREEMPT],
303 AC_MSG_ERROR([
304 *** Kernel built with CONFIG_PREEMPT which is not supported.
305 ** You must rebuild your kernel without this option.]), [])
306
c9c0d073
BB
307 if test "$ZFS_META_LICENSE" = CDDL; then
308 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
309 AC_MSG_ERROR([
310 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is
311 *** incompatible with the CDDL license. You must rebuild
312 *** your kernel without this option.]), [])
313 fi
314
315 if test "$ZFS_META_LICENSE" = GPL; then
316 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
317 [Define to 1 if licensed under the GPL])
318 fi
319])
320
321dnl #
322dnl # ZFS_LINUX_CONFTEST
323dnl #
324AC_DEFUN([ZFS_LINUX_CONFTEST], [
325cat confdefs.h - <<_ACEOF >conftest.c
326$1
327_ACEOF
328])
329
330dnl #
331dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
332dnl #
333m4_define([ZFS_LANG_PROGRAM], [
334$1
335int
336main (void)
337{
338dnl Do *not* indent the following line: there may be CPP directives.
339dnl Don't move the `;' right after for the same reason.
340$2
341 ;
342 return 0;
343}
344])
345
346dnl #
347dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
348dnl #
349AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
350 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
351 rm -Rf build && mkdir -p build
352 echo "obj-m := conftest.o" >build/Makefile
353 AS_IF(
354 [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])],
355 [$4],
356 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
357 )
358 rm -Rf build
359])
360
361dnl #
362dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
363dnl #
364AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
365 [ZFS_LINUX_COMPILE_IFELSE(
366 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
367 [modules],
368 [test -s build/conftest.o],
369 [$3], [$4])
370])
371
372dnl #
373dnl # ZFS_LINUX_CONFIG
374dnl #
375AC_DEFUN([ZFS_LINUX_CONFIG],
376 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
377 ZFS_LINUX_TRY_COMPILE([
378 #ifndef AUTOCONF_INCLUDED
379 #include <linux/config.h>
380 #endif
381 ],[
382 #ifndef CONFIG_$1
383 #error CONFIG_$1 not #defined
384 #endif
385 ],[
386 AC_MSG_RESULT([yes])
387 $2
388 ],[
389 AC_MSG_RESULT([no])
390 $3
391 ])
392])
393
394dnl #
395dnl # ZFS_CHECK_SYMBOL_EXPORT
396dnl # check symbol exported or not
397dnl #
398AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
399 [AC_MSG_CHECKING([whether symbol $1 is exported])
400 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
401 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
402 rc=$?
403 if test $rc -ne 0; then
404 export=0
405 for file in $2; do
406 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
407 rc=$?
408 if test $rc -eq 0; then
409 export=1
410 break;
411 fi
412 done
413 if test $export -eq 0; then
414 AC_MSG_RESULT([no])
415 $4
416 else
417 AC_MSG_RESULT([yes])
418 $3
419 fi
420 else
421 AC_MSG_RESULT([yes])
422 $3
423 fi
424])