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