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