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