]> git.proxmox.com Git - mirror_zfs.git/blob - config/kernel.m4
zvol processing should use struct bio
[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_TEST_MODULE
8 ZFS_AC_KERNEL_CONFIG
9 ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
10 ZFS_AC_KERNEL_CURRENT_BIO_TAIL
11 ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
12 ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
13 ZFS_AC_KERNEL_TYPE_FMODE_T
14 ZFS_AC_KERNEL_KOBJ_NAME_LEN
15 ZFS_AC_KERNEL_3ARG_BLKDEV_GET
16 ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
17 ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
18 ZFS_AC_KERNEL_LOOKUP_BDEV
19 ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
20 ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
21 ZFS_AC_KERNEL_BDEV_PHYSICAL_BLOCK_SIZE
22 ZFS_AC_KERNEL_BIO_BVEC_ITER
23 ZFS_AC_KERNEL_BIO_FAILFAST_DTD
24 ZFS_AC_KERNEL_REQ_FAILFAST_MASK
25 ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
26 ZFS_AC_KERNEL_BIO_RW_BARRIER
27 ZFS_AC_KERNEL_BIO_RW_DISCARD
28 ZFS_AC_KERNEL_BIO_RW_SYNC
29 ZFS_AC_KERNEL_BIO_RW_SYNCIO
30 ZFS_AC_KERNEL_REQ_SYNC
31 ZFS_AC_KERNEL_BLK_END_REQUEST
32 ZFS_AC_KERNEL_BLK_QUEUE_FLUSH
33 ZFS_AC_KERNEL_BLK_QUEUE_MAX_HW_SECTORS
34 ZFS_AC_KERNEL_BLK_QUEUE_MAX_SEGMENTS
35 ZFS_AC_KERNEL_BLK_QUEUE_NONROT
36 ZFS_AC_KERNEL_BLK_QUEUE_DISCARD
37 ZFS_AC_KERNEL_BLK_FETCH_REQUEST
38 ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST
39 ZFS_AC_KERNEL_BLK_RQ_BYTES
40 ZFS_AC_KERNEL_BLK_RQ_POS
41 ZFS_AC_KERNEL_BLK_RQ_SECTORS
42 ZFS_AC_KERNEL_GET_DISK_RO
43 ZFS_AC_KERNEL_GET_GENDISK
44 ZFS_AC_KERNEL_RQ_IS_SYNC
45 ZFS_AC_KERNEL_RQ_FOR_EACH_SEGMENT
46 ZFS_AC_KERNEL_DISCARD_GRANULARITY
47 ZFS_AC_KERNEL_CONST_XATTR_HANDLER
48 ZFS_AC_KERNEL_XATTR_HANDLER_GET
49 ZFS_AC_KERNEL_XATTR_HANDLER_SET
50 ZFS_AC_KERNEL_XATTR_HANDLER_LIST
51 ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
52 ZFS_AC_KERNEL_POSIX_ACL_FROM_XATTR_USERNS
53 ZFS_AC_KERNEL_POSIX_ACL_RELEASE
54 ZFS_AC_KERNEL_POSIX_ACL_CHMOD
55 ZFS_AC_KERNEL_POSIX_ACL_CACHING
56 ZFS_AC_KERNEL_POSIX_ACL_EQUIV_MODE_WANTS_UMODE_T
57 ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION
58 ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION_WITH_NAMEIDATA
59 ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL
60 ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL_WITH_FLAGS
61 ZFS_AC_KERNEL_INODE_OPERATIONS_GET_ACL
62 ZFS_AC_KERNEL_CURRENT_UMASK
63 ZFS_AC_KERNEL_SHOW_OPTIONS
64 ZFS_AC_KERNEL_FILE_INODE
65 ZFS_AC_KERNEL_FSYNC
66 ZFS_AC_KERNEL_EVICT_INODE
67 ZFS_AC_KERNEL_DIRTY_INODE_WITH_FLAGS
68 ZFS_AC_KERNEL_NR_CACHED_OBJECTS
69 ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
70 ZFS_AC_KERNEL_FALLOCATE
71 ZFS_AC_KERNEL_MKDIR_UMODE_T
72 ZFS_AC_KERNEL_LOOKUP_NAMEIDATA
73 ZFS_AC_KERNEL_CREATE_NAMEIDATA
74 ZFS_AC_KERNEL_FOLLOW_LINK
75 ZFS_AC_KERNEL_PUT_LINK
76 ZFS_AC_KERNEL_TRUNCATE_RANGE
77 ZFS_AC_KERNEL_AUTOMOUNT
78 ZFS_AC_KERNEL_ENCODE_FH_WITH_INODE
79 ZFS_AC_KERNEL_COMMIT_METADATA
80 ZFS_AC_KERNEL_CLEAR_INODE
81 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
82 ZFS_AC_KERNEL_D_MAKE_ROOT
83 ZFS_AC_KERNEL_D_OBTAIN_ALIAS
84 ZFS_AC_KERNEL_D_PRUNE_ALIASES
85 ZFS_AC_KERNEL_D_SET_D_OP
86 ZFS_AC_KERNEL_D_REVALIDATE_NAMEIDATA
87 ZFS_AC_KERNEL_CONST_DENTRY_OPERATIONS
88 ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE
89 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
90 ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
91 ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
92 ZFS_AC_KERNEL_MOUNT_NODEV
93 ZFS_AC_KERNEL_SHRINK
94 ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
95 ZFS_AC_KERNEL_S_INSTANCES_LIST_HEAD
96 ZFS_AC_KERNEL_S_D_OP
97 ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER
98 ZFS_AC_KERNEL_SET_NLINK
99 ZFS_AC_KERNEL_ELEVATOR_CHANGE
100 ZFS_AC_KERNEL_5ARG_SGET
101 ZFS_AC_KERNEL_LSEEK_EXECUTE
102 ZFS_AC_KERNEL_VFS_ITERATE
103 ZFS_AC_KERNEL_VFS_RW_ITERATE
104 ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
105 ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
106 ZFS_AC_KERNEL_MAKE_REQUEST_FN
107
108 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
109 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
110 ])
111 AC_SUBST(KERNELMAKE_PARAMS)
112
113
114 dnl # -Wall -fno-strict-aliasing -Wstrict-prototypes and other
115 dnl # compiler options are added by the kernel build system.
116 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_UNUSED_BUT_SET_VARIABLE"
117 KERNELCPPFLAGS="$KERNELCPPFLAGS $NO_BOOL_COMPARE"
118 KERNELCPPFLAGS="$KERNELCPPFLAGS -DHAVE_SPL -D_KERNEL"
119 KERNELCPPFLAGS="$KERNELCPPFLAGS -DTEXT_DOMAIN=\\\"zfs-linux-kernel\\\""
120
121 AC_SUBST(KERNELCPPFLAGS)
122 ])
123
124 dnl #
125 dnl # Detect name used for Module.symvers file in kernel
126 dnl #
127 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
128 modpost=$LINUX/scripts/Makefile.modpost
129 AC_MSG_CHECKING([kernel file name for module symbols])
130 AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
131 AS_IF([grep -q Modules.symvers $modpost], [
132 LINUX_SYMBOLS=Modules.symvers
133 ], [
134 LINUX_SYMBOLS=Module.symvers
135 ])
136
137 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
138 AC_MSG_ERROR([
139 *** Please make sure the kernel devel package for your distribution
140 *** is installed. If you are building with a custom kernel, make sure the
141 *** kernel is configured, built, and the '--with-linux=PATH' configure
142 *** option refers to the location of the kernel source.])
143 ])
144 ], [
145 LINUX_SYMBOLS=NONE
146 ])
147 AC_MSG_RESULT($LINUX_SYMBOLS)
148 AC_SUBST(LINUX_SYMBOLS)
149 ])
150
151 dnl #
152 dnl # Detect the kernel to be built against
153 dnl #
154 AC_DEFUN([ZFS_AC_KERNEL], [
155 AC_ARG_WITH([linux],
156 AS_HELP_STRING([--with-linux=PATH],
157 [Path to kernel source]),
158 [kernelsrc="$withval"])
159
160 AC_ARG_WITH(linux-obj,
161 AS_HELP_STRING([--with-linux-obj=PATH],
162 [Path to kernel build objects]),
163 [kernelbuild="$withval"])
164
165 AC_MSG_CHECKING([kernel source directory])
166 AS_IF([test -z "$kernelsrc"], [
167 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
168 headersdir="/lib/modules/$(uname -r)/source"
169 sourcelink=$(readlink -f "$headersdir")
170 ], [test -e "/lib/modules/$(uname -r)/build"], [
171 headersdir="/lib/modules/$(uname -r)/build"
172 sourcelink=$(readlink -f "$headersdir")
173 ], [
174 sourcelink=$(ls -1d /usr/src/kernels/* \
175 /usr/src/linux-* \
176 2>/dev/null | grep -v obj | tail -1)
177 ])
178
179 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
180 kernelsrc=`readlink -f ${sourcelink}`
181 ], [
182 kernelsrc="[Not found]"
183 ])
184 ], [
185 AS_IF([test "$kernelsrc" = "NONE"], [
186 kernsrcver=NONE
187 ])
188 ])
189
190 AC_MSG_RESULT([$kernelsrc])
191 AS_IF([test ! -d "$kernelsrc"], [
192 AC_MSG_ERROR([
193 *** Please make sure the kernel devel package for your distribution
194 *** is installed and then try again. If that fails, you can specify the
195 *** location of the kernel source with the '--with-linux=PATH' option.])
196 ])
197
198 AC_MSG_CHECKING([kernel build directory])
199 AS_IF([test -z "$kernelbuild"], [
200 AS_IF([test -e "/lib/modules/$(uname -r)/build"], [
201 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
202 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
203 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
204 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
205 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
206 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
207 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
208 ], [
209 kernelbuild=${kernelsrc}
210 ])
211 ])
212 AC_MSG_RESULT([$kernelbuild])
213
214 AC_MSG_CHECKING([kernel source version])
215 utsrelease1=$kernelbuild/include/linux/version.h
216 utsrelease2=$kernelbuild/include/linux/utsrelease.h
217 utsrelease3=$kernelbuild/include/generated/utsrelease.h
218 AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
219 utsrelease=linux/version.h
220 ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
221 utsrelease=linux/utsrelease.h
222 ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
223 utsrelease=generated/utsrelease.h
224 ])
225
226 AS_IF([test "$utsrelease"], [
227 kernsrcver=`(echo "#include <$utsrelease>";
228 echo "kernsrcver=UTS_RELEASE") |
229 cpp -I $kernelbuild/include |
230 grep "^kernsrcver=" | cut -d \" -f 2`
231
232 AS_IF([test -z "$kernsrcver"], [
233 AC_MSG_RESULT([Not found])
234 AC_MSG_ERROR([*** Cannot determine kernel version.])
235 ])
236 ], [
237 AC_MSG_RESULT([Not found])
238 if test "x$enable_linux_builtin" != xyes; then
239 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
240 else
241 AC_MSG_ERROR([
242 *** Cannot find UTS_RELEASE definition.
243 *** Please run 'make prepare' inside the kernel source tree.])
244 fi
245 ])
246
247 AC_MSG_RESULT([$kernsrcver])
248
249 LINUX=${kernelsrc}
250 LINUX_OBJ=${kernelbuild}
251 LINUX_VERSION=${kernsrcver}
252
253 AC_SUBST(LINUX)
254 AC_SUBST(LINUX_OBJ)
255 AC_SUBST(LINUX_VERSION)
256
257 ZFS_AC_MODULE_SYMVERS
258 ])
259
260
261 dnl #
262 dnl # Detect the SPL module to be built against
263 dnl #
264 AC_DEFUN([ZFS_AC_SPL], [
265 AC_ARG_WITH([spl],
266 AS_HELP_STRING([--with-spl=PATH],
267 [Path to spl source]),
268 [splsrc="$withval"])
269
270 AC_ARG_WITH([spl-obj],
271 AS_HELP_STRING([--with-spl-obj=PATH],
272 [Path to spl build objects]),
273 [splbuild="$withval"])
274
275 AC_ARG_WITH([spl-timeout],
276 AS_HELP_STRING([--with-spl-timeout=SECS],
277 [Wait SECS for SPL header and symver file @<:@default=0@:>@]),
278 [timeout="$withval"], [timeout=0])
279
280 dnl #
281 dnl # The existence of spl.release.in is used to identify a valid
282 dnl # source directory. In order of preference:
283 dnl #
284 splsrc0="/var/lib/dkms/spl/${VERSION}/build"
285 splsrc1="/usr/local/src/spl-${VERSION}/${LINUX_VERSION}"
286 splsrc2="/usr/local/src/spl-${VERSION}"
287 splsrc3="/usr/src/spl-${VERSION}/${LINUX_VERSION}"
288 splsrc4="/usr/src/spl-${VERSION}"
289 splsrc5="../spl/"
290 splsrc6="$LINUX"
291
292 AC_MSG_CHECKING([spl source directory])
293 AS_IF([test -z "${splsrc}"], [
294 AS_IF([ test -e "${splsrc0}/spl.release.in"], [
295 splsrc=${splsrc0}
296 ], [ test -e "${splsrc1}/spl.release.in"], [
297 splsrc=${splsrc1}
298 ], [ test -e "${splsrc2}/spl.release.in"], [
299 splsrc=${splsrc2}
300 ], [ test -e "${splsrc3}/spl.release.in"], [
301 splsrc=$(readlink -f "${splsrc3}")
302 ], [ test -e "${splsrc4}/spl.release.in" ], [
303 splsrc=${splsrc4}
304 ], [ test -e "${splsrc5}/spl.release.in"], [
305 splsrc=$(readlink -f "${splsrc5}")
306 ], [ test -e "${splsrc6}/spl.release.in" ], [
307 splsrc=${splsrc6}
308 ], [
309 splsrc="[Not found]"
310 ])
311 ], [
312 AS_IF([test "$splsrc" = "NONE"], [
313 splbuild=NONE
314 splsrcver=NONE
315 ])
316 ])
317
318 AC_MSG_RESULT([$splsrc])
319 AS_IF([ test ! -e "$splsrc/spl.release.in"], [
320 AC_MSG_ERROR([
321 *** Please make sure the kmod spl devel package for your distribution
322 *** is installed then try again. If that fails you can specify the
323 *** location of the spl source with the '--with-spl=PATH' option.])
324 ])
325
326 dnl #
327 dnl # The existence of the spl_config.h is used to identify a valid
328 dnl # spl object directory. In many cases the object and source
329 dnl # directory are the same, however the objects may also reside
330 dnl # is a subdirectory named after the kernel version.
331 dnl #
332 dnl # This file is supposed to be available after DKMS finishes
333 dnl # building the SPL kernel module for the target kernel. The
334 dnl # '--with-spl-timeout' option can be passed to pause here,
335 dnl # waiting for the file to appear from a concurrently building
336 dnl # SPL package.
337 dnl #
338 AC_MSG_CHECKING([spl build directory])
339 while true; do
340 AS_IF([test -z "$splbuild"], [
341 AS_IF([ test -e "${splsrc}/${LINUX_VERSION}/spl_config.h" ], [
342 splbuild="${splsrc}/${LINUX_VERSION}"
343 ], [ test -e "${splsrc}/spl_config.h" ], [
344 splbuild="${splsrc}"
345 ], [ find -L "${splsrc}" -name spl_config.h 2> /dev/null | grep -wq spl_config.h ], [
346 splbuild=$(find -L "${splsrc}" -name spl_config.h | sed 's,/spl_config.h,,')
347 ], [
348 splbuild="[Not found]"
349 ])
350 ])
351 AS_IF([test -e "$splbuild/spl_config.h" -o $timeout -le 0], [
352 break;
353 ], [
354 sleep 1
355 timeout=$((timeout-1))
356 ])
357 done
358
359 AC_MSG_RESULT([$splbuild])
360 AS_IF([ ! test -e "$splbuild/spl_config.h"], [
361 AC_MSG_ERROR([
362 *** Please make sure the kmod spl devel <kernel> package for your
363 *** distribution is installed then try again. If that fails you
364 *** can specify the location of the spl objects with the
365 *** '--with-spl-obj=PATH' option.])
366 ])
367
368 AC_MSG_CHECKING([spl source version])
369 AS_IF([test -r $splbuild/spl_config.h &&
370 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
371
372 splsrcver=`(echo "#include <spl_config.h>";
373 echo "splsrcver=SPL_META_VERSION-SPL_META_RELEASE") |
374 cpp -I $splbuild |
375 grep "^splsrcver=" | tr -d \" | cut -d= -f2`
376 ])
377
378 AS_IF([test -z "$splsrcver"], [
379 AC_MSG_RESULT([Not found])
380 AC_MSG_ERROR([
381 *** Cannot determine the version of the spl source.
382 *** Please prepare the spl source before running this script])
383 ])
384
385 AC_MSG_RESULT([$splsrcver])
386
387 SPL=${splsrc}
388 SPL_OBJ=${splbuild}
389 SPL_VERSION=${splsrcver}
390
391 AC_SUBST(SPL)
392 AC_SUBST(SPL_OBJ)
393 AC_SUBST(SPL_VERSION)
394
395 dnl #
396 dnl # Detect the name used for the SPL Module.symvers file. If one
397 dnl # does not exist this is likely because the SPL has been configured
398 dnl # but not built. The '--with-spl-timeout' option can be passed
399 dnl # to pause here, waiting for the file to appear from a concurrently
400 dnl # building SPL package. If the file does not appear in time, a good
401 dnl # guess is made as to what this file will be named based on what it
402 dnl # is named in the kernel build products. This file will first be
403 dnl # used at link time so if the guess is wrong the build will fail
404 dnl # then. This unfortunately means the ZFS package does not contain a
405 dnl # reliable mechanism to detect symbols exported by the SPL at
406 dnl # configure time.
407 dnl #
408 AC_MSG_CHECKING([spl file name for module symbols])
409 SPL_SYMBOLS=NONE
410
411 while true; do
412 AS_IF([test -r $SPL_OBJ/Module.symvers], [
413 SPL_SYMBOLS=Module.symvers
414 ], [test -r $SPL_OBJ/Modules.symvers], [
415 SPL_SYMBOLS=Modules.symvers
416 ], [test -r $SPL_OBJ/module/Module.symvers], [
417 SPL_SYMBOLS=Module.symvers
418 ], [test -r $SPL_OBJ/module/Modules.symvers], [
419 SPL_SYMBOLS=Modules.symvers
420 ])
421
422 AS_IF([test $SPL_SYMBOLS != NONE -o $timeout -le 0], [
423 break;
424 ], [
425 sleep 1
426 timeout=$((timeout-1))
427 ])
428 done
429
430 AS_IF([test "$SPL_SYMBOLS" = NONE], [
431 SPL_SYMBOLS=$LINUX_SYMBOLS
432 ])
433
434 AC_MSG_RESULT([$SPL_SYMBOLS])
435 AC_SUBST(SPL_SYMBOLS)
436 ])
437
438 dnl #
439 dnl # Basic toolchain sanity check.
440 dnl #
441 AC_DEFUN([ZFS_AC_TEST_MODULE], [
442 AC_MSG_CHECKING([whether modules can be built])
443 ZFS_LINUX_TRY_COMPILE([],[],[
444 AC_MSG_RESULT([yes])
445 ],[
446 AC_MSG_RESULT([no])
447 if test "x$enable_linux_builtin" != xyes; then
448 AC_MSG_ERROR([*** Unable to build an empty module.])
449 else
450 AC_MSG_ERROR([
451 *** Unable to build an empty module.
452 *** Please run 'make scripts' inside the kernel source tree.])
453 fi
454 ])
455 ])
456
457 dnl #
458 dnl # Certain kernel build options are not supported. These must be
459 dnl # detected at configure time and cause a build failure. Otherwise
460 dnl # modules may be successfully built that behave incorrectly.
461 dnl #
462 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
463 AC_RUN_IFELSE([
464 AC_LANG_PROGRAM([
465 #include "$LINUX/include/linux/license.h"
466 ], [
467 return !license_is_gpl_compatible("$ZFS_META_LICENSE");
468 ])
469 ], [
470 AC_DEFINE([ZFS_IS_GPL_COMPATIBLE], [1],
471 [Define to 1 if GPL-only symbols can be used])
472 ], [
473 ])
474
475 ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC
476 ])
477
478 dnl #
479 dnl # Check CONFIG_DEBUG_LOCK_ALLOC
480 dnl #
481 dnl # This is typically only set for debug kernels because it comes with
482 dnl # a performance penalty. However, when it is set it maps the non-GPL
483 dnl # symbol mutex_lock() to the GPL-only mutex_lock_nested() symbol.
484 dnl # This will cause a failure at link time which we'd rather know about
485 dnl # at compile time.
486 dnl #
487 dnl # Since we plan to pursue making mutex_lock_nested() a non-GPL symbol
488 dnl # with the upstream community we add a check to detect this case.
489 dnl #
490 AC_DEFUN([ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC], [
491
492 ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC], [
493 AC_MSG_CHECKING([whether mutex_lock() is GPL-only])
494 tmp_flags="$EXTRA_KCFLAGS"
495 ZFS_LINUX_TRY_COMPILE([
496 #include <linux/module.h>
497 #include <linux/mutex.h>
498
499 MODULE_LICENSE("$ZFS_META_LICENSE");
500 ],[
501 struct mutex lock;
502
503 mutex_init(&lock);
504 mutex_lock(&lock);
505 mutex_unlock(&lock);
506 ],[
507 AC_MSG_RESULT(no)
508 ],[
509 AC_MSG_RESULT(yes)
510 AC_MSG_ERROR([
511 *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is incompatible
512 *** with the CDDL license and will prevent the module linking stage
513 *** from succeeding. You must rebuild your kernel without this
514 *** option enabled.])
515 ])
516 EXTRA_KCFLAGS="$tmp_flags"
517 ], [])
518 ])
519
520 dnl #
521 dnl # ZFS_LINUX_CONFTEST_H
522 dnl #
523 AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
524 cat - <<_ACEOF >conftest.h
525 $1
526 _ACEOF
527 ])
528
529 dnl #
530 dnl # ZFS_LINUX_CONFTEST_C
531 dnl #
532 AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
533 cat confdefs.h - <<_ACEOF >conftest.c
534 $1
535 _ACEOF
536 ])
537
538 dnl #
539 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
540 dnl #
541 m4_define([ZFS_LANG_PROGRAM], [
542 $1
543 int
544 main (void)
545 {
546 dnl Do *not* indent the following line: there may be CPP directives.
547 dnl Don't move the `;' right after for the same reason.
548 $2
549 ;
550 return 0;
551 }
552 ])
553
554 dnl #
555 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
556 dnl #
557 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
558 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1])])
559 m4_ifvaln([$6], [ZFS_LINUX_CONFTEST_H([$6])], [ZFS_LINUX_CONFTEST_H([])])
560 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
561 echo "obj-m := conftest.o" >build/Makefile
562 modpost_flag=''
563 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
564 AS_IF(
565 [AC_TRY_COMMAND(cp conftest.c conftest.h build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
566 [$4],
567 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
568 )
569 rm -Rf build
570 ])
571
572 dnl #
573 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
574 dnl #
575 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
576 [ZFS_LINUX_COMPILE_IFELSE(
577 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
578 [modules],
579 [test -s build/conftest.o],
580 [$3], [$4])
581 ])
582
583 dnl #
584 dnl # ZFS_LINUX_CONFIG
585 dnl #
586 AC_DEFUN([ZFS_LINUX_CONFIG],
587 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
588 ZFS_LINUX_TRY_COMPILE([
589 #include <linux/module.h>
590 ],[
591 #ifndef CONFIG_$1
592 #error CONFIG_$1 not #defined
593 #endif
594 ],[
595 AC_MSG_RESULT([yes])
596 $2
597 ],[
598 AC_MSG_RESULT([no])
599 $3
600 ])
601 ])
602
603 dnl #
604 dnl # ZFS_CHECK_SYMBOL_EXPORT
605 dnl # check symbol exported or not
606 dnl #
607 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
608 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
609 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
610 rc=$?
611 if test $rc -ne 0; then
612 export=0
613 for file in $2; do
614 grep -q -E "EXPORT_SYMBOL.*($1)" \
615 "$LINUX/$file" 2>/dev/null
616 rc=$?
617 if test $rc -eq 0; then
618 export=1
619 break;
620 fi
621 done
622 if test $export -eq 0; then :
623 $4
624 else :
625 $3
626 fi
627 else :
628 $3
629 fi
630 ])
631
632 dnl #
633 dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
634 dnl # like ZFS_LINUX_TRY_COMPILE, except ZFS_CHECK_SYMBOL_EXPORT
635 dnl # is called if not compiling for builtin
636 dnl #
637 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
638 ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
639 if test $rc -ne 0; then :
640 $6
641 else
642 if test "x$enable_linux_builtin" != xyes; then
643 ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
644 fi
645 if test $rc -ne 0; then :
646 $6
647 else :
648 $5
649 fi
650 fi
651 ])
652
653 dnl #
654 dnl # ZFS_LINUX_TRY_COMPILE_HEADER
655 dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
656 dnl # provided via the fifth parameter
657 dnl #
658 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER],
659 [ZFS_LINUX_COMPILE_IFELSE(
660 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
661 [modules],
662 [test -s build/conftest.o],
663 [$3], [$4], [$5])
664 ])