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