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