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