]> git.proxmox.com Git - mirror_zfs.git/blob - config/kernel.m4
Simplify BDI integration
[mirror_zfs.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 ZFS_AC_KERNEL_BDI
44 ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
45
46 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
47 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
48 ])
49 AC_SUBST(KERNELMAKE_PARAMS)
50
51
52 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
53 dnl # compiler options are added by the kernel build system.
54 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
55 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
56 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
57
58 AC_SUBST(KERNELCPPFLAGS)
59 ])
60
61 dnl #
62 dnl # Detect name used for Module.symvers file in kernel
63 dnl #
64 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
65 modpost=$LINUX/scripts/Makefile.modpost
66 AC_MSG_CHECKING([kernel file name for module symbols])
67 AS_IF([test -f "$modpost"], [
68 AS_IF([grep -q Modules.symvers $modpost], [
69 LINUX_SYMBOLS=Modules.symvers
70 ], [
71 LINUX_SYMBOLS=Module.symvers
72 ])
73
74 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
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.])
80 ])
81 ], [
82 LINUX_SYMBOLS=NONE
83 ])
84 AC_MSG_RESULT($LINUX_SYMBOLS)
85 AC_SUBST(LINUX_SYMBOLS)
86 ])
87
88 dnl #
89 dnl # Detect the kernel to be built against
90 dnl #
91 AC_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])
103 AS_IF([test -z "$kernelsrc"], [
104 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
105 headersdir="/lib/modules/$(uname -r)/source"
106 sourcelink=$(readlink -f "$headersdir")
107 ], [test -e "/lib/modules/$(uname -r)/build"], [
108 headersdir="/lib/modules/$(uname -r)/build"
109 sourcelink=$(readlink -f "$headersdir")
110 ], [
111 sourcelink=$(ls -1d /usr/src/kernels/* \
112 /usr/src/linux-* \
113 2>/dev/null | grep -v obj | tail -1)
114 ])
115
116 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
117 kernelsrc=`readlink -f ${sourcelink}`
118 ], [
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.])
124 ])
125 ], [
126 AS_IF([test "$kernelsrc" = "NONE"], [
127 kernsrcver=NONE
128 ])
129 ])
130
131 AC_MSG_RESULT([$kernelsrc])
132 AC_MSG_CHECKING([kernel build directory])
133 AS_IF([test -z "$kernelbuild"], [
134 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
135 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
136 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
137 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
138 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
139 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
140 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
141 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
142 ], [
143 kernelbuild=${kernelsrc}
144 ])
145 ])
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
152 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
153 utsrelease=linux/version.h
154 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
155 utsrelease=linux/utsrelease.h
156 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
157 utsrelease=generated/utsrelease.h
158 ])
159
160 AS_IF([test "$utsrelease"], [
161 kernsrcver=`(echo "#include <$utsrelease>";
162 echo "kernsrcver=UTS_RELEASE") |
163 cpp -I $kernelbuild/include |
164 grep "^kernsrcver=" | cut -d \" -f 2`
165
166 AS_IF([test -z "$kernsrcver"], [
167 AC_MSG_RESULT([Not found])
168 AC_MSG_ERROR([*** Cannot determine kernel version.])
169 ])
170 ], [
171 AC_MSG_RESULT([Not found])
172 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
173 ])
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
188 dnl #
189 dnl # Detect name used for the additional SPL Module.symvers file. If one
190 dnl # does not exist this is likely because the SPL has been configured
191 dnl # but not built. To allow recursive builds a good guess is made as to
192 dnl # what this file will be named based on what it is named in the kernel
193 dnl # build products. This file will first be used at link time so if
194 dnl # the guess is wrong the build will fail then. This unfortunately
195 dnl # means the ZFS package does not contain a reliable mechanism to
196 dnl # detect symbols exported by the SPL at configure time.
197 dnl #
198 AC_DEFUN([ZFS_AC_SPL_MODULE_SYMVERS], [
199 AC_MSG_CHECKING([spl file name for module symbols])
200 AS_IF([test -r $SPL_OBJ/Module.symvers], [
201 SPL_SYMBOLS=Module.symvers
202 ], [test -r $SPL_OBJ/Modules.symvers], [
203 SPL_SYMBOLS=Modules.symvers
204 ], [test -r $SPL_OBJ/module/Module.symvers], [
205 SPL_SYMBOLS=Module.symvers
206 ], [test -r $SPL_OBJ/module/Modules.symvers], [
207 SPL_SYMBOLS=Modules.symvers
208 ], [
209 SPL_SYMBOLS=$LINUX_SYMBOLS
210 ])
211
212 AC_MSG_RESULT([$SPL_SYMBOLS])
213 AC_SUBST(SPL_SYMBOLS)
214 ])
215
216 dnl #
217 dnl # Detect the SPL module to be built against
218 dnl #
219 AC_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])
232 AS_IF([test -z "$splsrc"], [
233 sourcelink=`ls -1d /usr/src/spl-*/${LINUX_VERSION} \
234 2>/dev/null | tail -1`
235
236 AS_IF([test -z "$sourcelink" || test ! -e $sourcelink], [
237 sourcelink=../spl
238 ])
239
240 AS_IF([test -e $sourcelink], [
241 splsrc=`readlink -f ${sourcelink}`
242 ], [
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.])
248 ])
249 ], [
250 AS_IF([test "$splsrc" = "NONE"], [
251 splbuild=NONE
252 splsrcver=NONE
253 ])
254 ])
255
256 AC_MSG_RESULT([$splsrc])
257 AC_MSG_CHECKING([spl build directory])
258 AS_IF([test -z "$splbuild"], [
259 splbuild=${splsrc}
260 ])
261 AC_MSG_RESULT([$splbuild])
262
263 AC_MSG_CHECKING([spl source version])
264 AS_IF([test -r $splbuild/spl_config.h &&
265 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
266
267 splsrcver=`(echo "#include <spl_config.h>";
268 echo "splsrcver=SPL_META_VERSION") |
269 cpp -I $splbuild |
270 grep "^splsrcver=" | cut -d \" -f 2`
271 ])
272
273 AS_IF([test -z "$splsrcver"], [
274 AC_MSG_RESULT([Not found])
275 AC_MSG_ERROR([
276 *** Cannot determine the version of the spl source.
277 *** Please prepare the spl source before running this script])
278 ])
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
293 dnl #
294 dnl # Certain kernel build options are not supported. These must be
295 dnl # detected at configure time and cause a build failure. Otherwise
296 dnl # modules may be successfully built that behave incorrectly.
297 dnl #
298 dnl # CONFIG_PREEMPT - Preempt kernels require special handling.
299 dnl #
300 dnl # There are certain kernel build options which when enabled are
301 dnl # completely incompatible with non GPL kernel modules. It is best
302 dnl # to detect these at configure time and fail with a clear error
303 dnl # rather than build everything and fail during linking.
304 dnl #
305 dnl # CONFIG_DEBUG_LOCK_ALLOC - Maps mutex_lock() to mutex_lock_nested()
306 dnl #
307 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
308
309 ZFS_LINUX_CONFIG([PREEMPT],
310 AC_MSG_ERROR([
311 *** Kernel built with CONFIG_PREEMPT which is not supported.
312 *** You must rebuild your kernel without this option.]), [])
313
314 AS_IF([test "$ZFS_META_LICENSE" = CDDL], [
315 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC],
316 AC_MSG_ERROR([
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.]), [])
320 ])
321
322 AS_IF([test "$ZFS_META_LICENSE" = GPL], [
323 AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
324 [Define to 1 if licensed under the GPL])
325 ])
326 ])
327
328 dnl #
329 dnl # ZFS_LINUX_CONFTEST
330 dnl #
331 AC_DEFUN([ZFS_LINUX_CONFTEST], [
332 cat confdefs.h - <<_ACEOF >conftest.c
333 $1
334 _ACEOF
335 ])
336
337 dnl #
338 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
339 dnl #
340 m4_define([ZFS_LANG_PROGRAM], [
341 $1
342 int
343 main (void)
344 {
345 dnl Do *not* indent the following line: there may be CPP directives.
346 dnl Don't move the `;' right after for the same reason.
347 $2
348 ;
349 return 0;
350 }
351 ])
352
353 dnl #
354 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
355 dnl #
356 AC_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
368 dnl #
369 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
370 dnl #
371 AC_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
379 dnl #
380 dnl # ZFS_LINUX_CONFIG
381 dnl #
382 AC_DEFUN([ZFS_LINUX_CONFIG],
383 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
384 ZFS_LINUX_TRY_COMPILE([
385 #include <linux/module.h>
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 AS_IF([test $rc -ne 0], [
409 export=0
410 for file in $2; do
411 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
412 rc=$?
413 AS_IF([test $rc -eq 0], [
414 export=1
415 break;
416 ])
417 done
418 AS_IF([test $export -eq 0], [
419 AC_MSG_RESULT([no])
420 $4
421 ], [
422 AC_MSG_RESULT([yes])
423 $3
424 ])
425 ], [
426 AC_MSG_RESULT([yes])
427 $3
428 ])
429 ])