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