2 dnl # Default ZFS kernel configuration
4 AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5 AM_COND_IF([BUILD_LINUX], [
6 dnl # Setup the kernel build environment.
10 dnl # Sanity checks for module building and CONFIG_* defines
11 ZFS_AC_KERNEL_CONFIG_DEFINED
14 dnl # Sequential ZFS_LINUX_TRY_COMPILE tests
15 ZFS_AC_KERNEL_FPU_HEADER
16 ZFS_AC_KERNEL_OBJTOOL_HEADER
17 ZFS_AC_KERNEL_WAIT_QUEUE_ENTRY_T
18 ZFS_AC_KERNEL_MISC_MINOR
19 ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
21 dnl # Parallel ZFS_LINUX_TEST_SRC / ZFS_LINUX_TEST_RESULT tests
22 ZFS_AC_KERNEL_TEST_SRC
23 ZFS_AC_KERNEL_TEST_RESULT
25 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
26 KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ"
34 dnl # Generate and compile all of the kernel API test cases to determine
35 dnl # which interfaces are available. By invoking the kernel build system
36 dnl # only once the compilation can be done in parallel significantly
37 dnl # speeding up the process.
39 AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
40 ZFS_AC_KERNEL_SRC_TYPES
41 ZFS_AC_KERNEL_SRC_OBJTOOL
42 ZFS_AC_KERNEL_SRC_GLOBAL_PAGE_STATE
43 ZFS_AC_KERNEL_SRC_ACCESS_OK_TYPE
44 ZFS_AC_KERNEL_SRC_PDE_DATA
45 ZFS_AC_KERNEL_SRC_GENERIC_FADVISE
46 ZFS_AC_KERNEL_SRC_SCHED
47 ZFS_AC_KERNEL_SRC_USLEEP_RANGE
48 ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
49 ZFS_AC_KERNEL_SRC_WAIT
50 ZFS_AC_KERNEL_SRC_INODE_TIMES
51 ZFS_AC_KERNEL_SRC_PROC_OPERATIONS
52 ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS
54 ZFS_AC_KERNEL_SRC_BLKDEV
55 ZFS_AC_KERNEL_SRC_BLK_QUEUE
56 ZFS_AC_KERNEL_SRC_GENHD_FLAGS
57 ZFS_AC_KERNEL_SRC_REVALIDATE_DISK
58 ZFS_AC_KERNEL_SRC_GET_DISK_RO
59 ZFS_AC_KERNEL_SRC_GENERIC_READLINK_GLOBAL
60 ZFS_AC_KERNEL_SRC_DISCARD_GRANULARITY
61 ZFS_AC_KERNEL_SRC_INODE_OWNER_OR_CAPABLE
62 ZFS_AC_KERNEL_SRC_XATTR
64 ZFS_AC_KERNEL_SRC_INODE_SETATTR
65 ZFS_AC_KERNEL_SRC_INODE_GETATTR
66 ZFS_AC_KERNEL_SRC_SHOW_OPTIONS
67 ZFS_AC_KERNEL_SRC_SHRINKER
68 ZFS_AC_KERNEL_SRC_MKDIR
69 ZFS_AC_KERNEL_SRC_LOOKUP_FLAGS
70 ZFS_AC_KERNEL_SRC_CREATE
71 ZFS_AC_KERNEL_SRC_PERMISSION
72 ZFS_AC_KERNEL_SRC_TMPFILE
73 ZFS_AC_KERNEL_SRC_AUTOMOUNT
74 ZFS_AC_KERNEL_SRC_COMMIT_METADATA
75 ZFS_AC_KERNEL_SRC_SETATTR_PREPARE
76 ZFS_AC_KERNEL_SRC_INSERT_INODE_LOCKED
77 ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE
78 ZFS_AC_KERNEL_SRC_SECURITY_INODE
79 ZFS_AC_KERNEL_SRC_FST_MOUNT
80 ZFS_AC_KERNEL_SRC_SET_NLINK
81 ZFS_AC_KERNEL_SRC_SGET
82 ZFS_AC_KERNEL_SRC_VFS_FILEMAP_DIRTY_FOLIO
83 ZFS_AC_KERNEL_SRC_VFS_READ_FOLIO
84 ZFS_AC_KERNEL_SRC_VFS_FSYNC_2ARGS
85 ZFS_AC_KERNEL_SRC_GET_USER_PAGES
86 ZFS_AC_KERNEL_SRC_VFS_DIRECT_IO
87 ZFS_AC_KERNEL_SRC_VFS_READPAGES
88 ZFS_AC_KERNEL_SRC_VFS_SET_PAGE_DIRTY_NOBUFFERS
89 ZFS_AC_KERNEL_SRC_VFS_IOV_ITER
90 ZFS_AC_KERNEL_SRC_VFS_GENERIC_COPY_FILE_RANGE
91 ZFS_AC_KERNEL_SRC_VFS_SPLICE_COPY_FILE_RANGE
92 ZFS_AC_KERNEL_SRC_VFS_REMAP_FILE_RANGE
93 ZFS_AC_KERNEL_SRC_VFS_CLONE_FILE_RANGE
94 ZFS_AC_KERNEL_SRC_VFS_DEDUPE_FILE_RANGE
95 ZFS_AC_KERNEL_SRC_KMAP_ATOMIC_ARGS
96 ZFS_AC_KERNEL_SRC_KMAP_LOCAL_PAGE
97 ZFS_AC_KERNEL_SRC_FOLLOW_DOWN_ONE
98 ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN
99 ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT
100 ZFS_AC_KERNEL_SRC_FPU
101 ZFS_AC_KERNEL_SRC_FMODE_T
102 ZFS_AC_KERNEL_SRC_KUIDGID_T
103 ZFS_AC_KERNEL_SRC_KUID_HELPERS
104 ZFS_AC_KERNEL_SRC_RENAME
105 ZFS_AC_KERNEL_SRC_USERNS_CAPABILITIES
106 ZFS_AC_KERNEL_SRC_TOTALRAM_PAGES_FUNC
107 ZFS_AC_KERNEL_SRC_TOTALHIGH_PAGES
108 ZFS_AC_KERNEL_SRC_PERCPU
109 ZFS_AC_KERNEL_SRC_GENERIC_FILLATTR
110 ZFS_AC_KERNEL_SRC_MKNOD
111 ZFS_AC_KERNEL_SRC_SYMLINK
112 ZFS_AC_KERNEL_SRC_BIO_MAX_SEGS
113 ZFS_AC_KERNEL_SRC_SIGINFO
114 ZFS_AC_KERNEL_SRC_SYSFS
115 ZFS_AC_KERNEL_SRC_STANDALONE_LINUX_STDARG
116 ZFS_AC_KERNEL_SRC_STRLCPY
117 ZFS_AC_KERNEL_SRC_PAGEMAP_FOLIO_WAIT_BIT
118 ZFS_AC_KERNEL_SRC_ADD_DISK
119 ZFS_AC_KERNEL_SRC_KTHREAD
120 ZFS_AC_KERNEL_SRC_ZERO_PAGE
121 ZFS_AC_KERNEL_SRC___COPY_FROM_USER_INATOMIC
122 ZFS_AC_KERNEL_SRC_IDMAP_MNT_API
123 ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS
124 ZFS_AC_KERNEL_SRC_IATTR_VFSID
125 ZFS_AC_KERNEL_SRC_WRITEPAGE_T
126 ZFS_AC_KERNEL_SRC_RECLAIMED
127 ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_TABLE
128 ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_SZ
129 ZFS_AC_KERNEL_SRC_PROC_HANDLER_CTL_TABLE_CONST
130 ZFS_AC_KERNEL_SRC_COPY_SPLICE_READ
131 ZFS_AC_KERNEL_SRC_SYNC_BDEV
132 ZFS_AC_KERNEL_SRC_MM_PAGE_SIZE
133 ZFS_AC_KERNEL_SRC_MM_PAGE_MAPPING
136 ZFS_AC_KERNEL_SRC_CPU_HAS_FEATURE
137 ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
140 ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
144 AC_MSG_CHECKING([for available kernel interfaces])
145 ZFS_LINUX_TEST_COMPILE_ALL([kabi])
146 AC_MSG_RESULT([done])
150 dnl # Check results of kernel interface tests.
152 AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
154 ZFS_AC_KERNEL_ACCESS_OK_TYPE
155 ZFS_AC_KERNEL_GLOBAL_PAGE_STATE
156 ZFS_AC_KERNEL_OBJTOOL
157 ZFS_AC_KERNEL_PDE_DATA
158 ZFS_AC_KERNEL_GENERIC_FADVISE
160 ZFS_AC_KERNEL_USLEEP_RANGE
161 ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
163 ZFS_AC_KERNEL_INODE_TIMES
164 ZFS_AC_KERNEL_PROC_OPERATIONS
165 ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS
168 ZFS_AC_KERNEL_BLK_QUEUE
169 ZFS_AC_KERNEL_GENHD_FLAGS
170 ZFS_AC_KERNEL_REVALIDATE_DISK
171 ZFS_AC_KERNEL_GET_DISK_RO
172 ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL
173 ZFS_AC_KERNEL_DISCARD_GRANULARITY
174 ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
177 ZFS_AC_KERNEL_INODE_SETATTR
178 ZFS_AC_KERNEL_INODE_GETATTR
179 ZFS_AC_KERNEL_SHOW_OPTIONS
180 ZFS_AC_KERNEL_SHRINKER
182 ZFS_AC_KERNEL_LOOKUP_FLAGS
184 ZFS_AC_KERNEL_PERMISSION
185 ZFS_AC_KERNEL_TMPFILE
186 ZFS_AC_KERNEL_AUTOMOUNT
187 ZFS_AC_KERNEL_COMMIT_METADATA
188 ZFS_AC_KERNEL_SETATTR_PREPARE
189 ZFS_AC_KERNEL_INSERT_INODE_LOCKED
190 ZFS_AC_KERNEL_TRUNCATE_SETSIZE
191 ZFS_AC_KERNEL_SECURITY_INODE
192 ZFS_AC_KERNEL_FST_MOUNT
193 ZFS_AC_KERNEL_SET_NLINK
195 ZFS_AC_KERNEL_VFS_FILEMAP_DIRTY_FOLIO
196 ZFS_AC_KERNEL_VFS_READ_FOLIO
197 ZFS_AC_KERNEL_VFS_FSYNC_2ARGS
198 ZFS_AC_KERNEL_GET_USER_PAGES
199 ZFS_AC_KERNEL_VFS_DIRECT_IO
200 ZFS_AC_KERNEL_VFS_READPAGES
201 ZFS_AC_KERNEL_VFS_SET_PAGE_DIRTY_NOBUFFERS
202 ZFS_AC_KERNEL_VFS_IOV_ITER
203 ZFS_AC_KERNEL_VFS_GENERIC_COPY_FILE_RANGE
204 ZFS_AC_KERNEL_VFS_SPLICE_COPY_FILE_RANGE
205 ZFS_AC_KERNEL_VFS_REMAP_FILE_RANGE
206 ZFS_AC_KERNEL_VFS_CLONE_FILE_RANGE
207 ZFS_AC_KERNEL_VFS_DEDUPE_FILE_RANGE
208 ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
209 ZFS_AC_KERNEL_KMAP_LOCAL_PAGE
210 ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
211 ZFS_AC_KERNEL_MAKE_REQUEST_FN
212 ZFS_AC_KERNEL_GENERIC_IO_ACCT
214 ZFS_AC_KERNEL_FMODE_T
215 ZFS_AC_KERNEL_KUIDGID_T
216 ZFS_AC_KERNEL_KUID_HELPERS
218 ZFS_AC_KERNEL_USERNS_CAPABILITIES
219 ZFS_AC_KERNEL_TOTALRAM_PAGES_FUNC
220 ZFS_AC_KERNEL_TOTALHIGH_PAGES
222 ZFS_AC_KERNEL_GENERIC_FILLATTR
224 ZFS_AC_KERNEL_SYMLINK
225 ZFS_AC_KERNEL_BIO_MAX_SEGS
226 ZFS_AC_KERNEL_SIGINFO
228 ZFS_AC_KERNEL_STANDALONE_LINUX_STDARG
229 ZFS_AC_KERNEL_STRLCPY
230 ZFS_AC_KERNEL_PAGEMAP_FOLIO_WAIT_BIT
231 ZFS_AC_KERNEL_ADD_DISK
232 ZFS_AC_KERNEL_KTHREAD
233 ZFS_AC_KERNEL_ZERO_PAGE
234 ZFS_AC_KERNEL___COPY_FROM_USER_INATOMIC
235 ZFS_AC_KERNEL_IDMAP_MNT_API
236 ZFS_AC_KERNEL_IDMAP_NO_USERNS
237 ZFS_AC_KERNEL_IATTR_VFSID
238 ZFS_AC_KERNEL_WRITEPAGE_T
239 ZFS_AC_KERNEL_RECLAIMED
240 ZFS_AC_KERNEL_REGISTER_SYSCTL_TABLE
241 ZFS_AC_KERNEL_REGISTER_SYSCTL_SZ
242 ZFS_AC_KERNEL_PROC_HANDLER_CTL_TABLE_CONST
243 ZFS_AC_KERNEL_COPY_SPLICE_READ
244 ZFS_AC_KERNEL_SYNC_BDEV
245 ZFS_AC_KERNEL_MM_PAGE_SIZE
246 ZFS_AC_KERNEL_MM_PAGE_MAPPING
247 ZFS_AC_KERNEL_1ARG_ASSIGN_STR
250 ZFS_AC_KERNEL_CPU_HAS_FEATURE
251 ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
254 ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
260 dnl # Detect name used for Module.symvers file in kernel
262 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
263 modpost=$LINUX/scripts/Makefile.modpost
264 AC_MSG_CHECKING([kernel file name for module symbols])
265 AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
266 AS_IF([grep -q Modules.symvers $modpost], [
267 LINUX_SYMBOLS=Modules.symvers
269 LINUX_SYMBOLS=Module.symvers
272 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
274 *** Please make sure the kernel devel package for your distribution
275 *** is installed. If you are building with a custom kernel, make sure
276 *** the kernel is configured, built, and the '--with-linux=PATH'
277 *** configure option refers to the location of the kernel source.
283 AC_MSG_RESULT($LINUX_SYMBOLS)
284 AC_SUBST(LINUX_SYMBOLS)
288 dnl # Detect the kernel to be built against
290 dnl # Most modern Linux distributions have separate locations for bare
291 dnl # source (source) and prebuilt (build) files. Additionally, there are
292 dnl # `source` and `build` symlinks in `/lib/modules/$(KERNEL_VERSION)`
293 dnl # pointing to them. The directory search order is now:
295 dnl # - `configure` command line values if both `--with-linux` and
296 dnl # `--with-linux-obj` were defined
298 dnl # - If only `--with-linux` was defined, `--with-linux-obj` is assumed
299 dnl # to have the same value as `--with-linux`
301 dnl # - If neither `--with-linux` nor `--with-linux-obj` were defined
302 dnl # autodetection is used:
304 dnl # - `/lib/modules/$(uname -r)/{source,build}` respectively, if exist.
306 dnl # - If only `/lib/modules/$(uname -r)/build` exists, it is assumed
307 dnl # to be both source and build directory.
309 dnl # - The first directory in `/lib/modules` with the highest version
310 dnl # number according to `sort -V` which contains both `source` and
311 dnl # `build` symlinks/directories. If module directory contains only
312 dnl # `build` component, it is assumed to be both source and build
315 dnl # - Last resort: the first directory matching `/usr/src/kernels/*`
316 dnl # and `/usr/src/linux-*` with the highest version number according
317 dnl # to `sort -V` is assumed to be both source and build directory.
319 AC_DEFUN([ZFS_AC_KERNEL], [
321 AS_HELP_STRING([--with-linux=PATH],
322 [Path to kernel source]),
323 [kernelsrc="$withval"])
325 AC_ARG_WITH(linux-obj,
326 AS_HELP_STRING([--with-linux-obj=PATH],
327 [Path to kernel build objects]),
328 [kernelbuild="$withval"])
330 AC_MSG_CHECKING([kernel source and build directories])
331 AS_IF([test -n "$kernelsrc" && test -z "$kernelbuild"], [
332 kernelbuild="$kernelsrc"
333 ], [test -z "$kernelsrc"], [
334 AS_IF([test -e "/lib/modules/$(uname -r)/source" && \
335 test -e "/lib/modules/$(uname -r)/build"], [
336 src="/lib/modules/$(uname -r)/source"
337 build="/lib/modules/$(uname -r)/build"
338 ], [test -e "/lib/modules/$(uname -r)/build"], [
339 build="/lib/modules/$(uname -r)/build"
344 for d in $(ls -1d /lib/modules/* 2>/dev/null | sort -Vr); do
345 if test -e "$d/source" && test -e "$d/build"; then
351 if test -e "$d/build"; then
358 # the least reliable method
359 if test -z "$src"; then
360 src=$(ls -1d /usr/src/kernels/* /usr/src/linux-* \
361 2>/dev/null | grep -v obj | sort -Vr | head -1)
366 AS_IF([test -n "$src" && test -e "$src"], [
367 kernelsrc=$(readlink -e "$src")
369 kernelsrc="[Not found]"
371 AS_IF([test -n "$build" && test -e "$build"], [
372 kernelbuild=$(readlink -e "$build")
374 kernelbuild="[Not found]"
377 AS_IF([test "$kernelsrc" = "NONE"], [
383 AC_MSG_RESULT([done])
384 AC_MSG_CHECKING([kernel source directory])
385 AC_MSG_RESULT([$kernelsrc])
386 AC_MSG_CHECKING([kernel build directory])
387 AC_MSG_RESULT([$kernelbuild])
388 AS_IF([test ! -d "$kernelsrc" || test ! -d "$kernelbuild"], [
390 *** Please make sure the kernel devel package for your distribution
391 *** is installed and then try again. If that fails, you can specify the
392 *** location of the kernel source and build with the '--with-linux=PATH' and
393 *** '--with-linux-obj=PATH' options respectively.])
396 AC_MSG_CHECKING([kernel source version])
397 utsrelease1=$kernelbuild/include/linux/version.h
398 utsrelease2=$kernelbuild/include/linux/utsrelease.h
399 utsrelease3=$kernelbuild/include/generated/utsrelease.h
400 AS_IF([test -r $utsrelease1 && grep -qF UTS_RELEASE $utsrelease1], [
401 utsrelease=$utsrelease1
402 ], [test -r $utsrelease2 && grep -qF UTS_RELEASE $utsrelease2], [
403 utsrelease=$utsrelease2
404 ], [test -r $utsrelease3 && grep -qF UTS_RELEASE $utsrelease3], [
405 utsrelease=$utsrelease3
408 AS_IF([test -n "$utsrelease"], [
409 kernsrcver=$($AWK '/UTS_RELEASE/ { gsub(/"/, "", $[3]); print $[3] }' $utsrelease)
410 AS_IF([test -z "$kernsrcver"], [
411 AC_MSG_RESULT([Not found])
413 *** Cannot determine kernel version.
417 AC_MSG_RESULT([Not found])
418 if test "x$enable_linux_builtin" != xyes; then
420 *** Cannot find UTS_RELEASE definition.
424 *** Cannot find UTS_RELEASE definition.
425 *** Please run 'make prepare' inside the kernel source tree.])
429 AC_MSG_RESULT([$kernsrcver])
431 AS_VERSION_COMPARE([$kernsrcver], [$ZFS_META_KVER_MIN], [
433 *** Cannot build against kernel version $kernsrcver.
434 *** The minimum supported kernel version is $ZFS_META_KVER_MIN.
439 LINUX_OBJ=${kernelbuild}
440 LINUX_VERSION=${kernsrcver}
444 AC_SUBST(LINUX_VERSION)
448 dnl # Detect the QAT module to be built against, QAT provides hardware
449 dnl # acceleration for data compression:
451 dnl # https://01.org/intel-quickassist-technology
453 dnl # 1) Download and install QAT driver from the above link
454 dnl # 2) Start QAT driver in your system:
455 dnl # service qat_service start
456 dnl # 3) Enable QAT in ZFS, e.g.:
457 dnl # ./configure --with-qat=<qat-driver-path>/QAT1.6
459 dnl # 4) Set GZIP compression in ZFS dataset:
460 dnl # zfs set compression = gzip <dataset>
462 dnl # Then the data written to this ZFS pool is compressed by QAT accelerator
463 dnl # automatically, and de-compressed by QAT when read from the pool.
465 dnl # 1) Get QAT hardware statistics with:
466 dnl # cat /proc/icp_dh895xcc_dev/qat
467 dnl # 2) To disable QAT:
468 dnl # insmod zfs.ko zfs_qat_disable=1
470 AC_DEFUN([ZFS_AC_QAT], [
472 AS_HELP_STRING([--with-qat=PATH],
473 [Path to qat source]),
474 AS_IF([test "$withval" = "yes"],
475 AC_MSG_ERROR([--with-qat=PATH requires a PATH]),
476 [qatsrc="$withval"]))
478 AC_ARG_WITH([qat-obj],
479 AS_HELP_STRING([--with-qat-obj=PATH],
480 [Path to qat build objects]),
481 [qatbuild="$withval"])
483 AS_IF([test ! -z "${qatsrc}"], [
484 AC_MSG_CHECKING([qat source directory])
485 AC_MSG_RESULT([$qatsrc])
486 QAT_SRC="${qatsrc}/quickassist"
487 AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [
489 *** Please make sure the qat driver package is installed
490 *** and specify the location of the qat source with the
491 *** '--with-qat=PATH' option then try again. Failed to
497 AS_IF([test ! -z "${qatsrc}"], [
498 AC_MSG_CHECKING([qat build directory])
499 AS_IF([test -z "$qatbuild"], [
500 qatbuild="${qatsrc}/build"
503 AC_MSG_RESULT([$qatbuild])
505 AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko" && ! test -e "$QAT_OBJ/qat_api.ko"], [
507 *** Please make sure the qat driver is installed then try again.
508 *** Failed to find icp_qa_al.ko or qat_api.ko in:
515 AC_DEFINE(HAVE_QAT, 1,
516 [qat is enabled and existed])
520 dnl # Detect the name used for the QAT Module.symvers file.
522 AS_IF([test ! -z "${qatsrc}"], [
523 AC_MSG_CHECKING([qat file for module symbols])
524 QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers
526 AS_IF([test -r $QAT_SYMBOLS], [
527 AC_MSG_RESULT([$QAT_SYMBOLS])
528 AC_SUBST(QAT_SYMBOLS)
531 *** Please make sure the qat driver is installed then try again.
532 *** Failed to find Module.symvers in:
540 dnl # ZFS_LINUX_CONFTEST_H
542 AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
543 test -d build/$2 || mkdir -p build/$2
544 cat - <<_ACEOF >build/$2/$2.h
550 dnl # ZFS_LINUX_CONFTEST_C
552 AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
553 test -d build/$2 || mkdir -p build/$2
554 cat confdefs.h - <<_ACEOF >build/$2/$2.c
560 dnl # ZFS_LINUX_CONFTEST_MAKEFILE
562 dnl # $1 - test case name
563 dnl # $2 - add to top-level Makefile
564 dnl # $3 - additional build flags
566 AC_DEFUN([ZFS_LINUX_CONFTEST_MAKEFILE], [
567 test -d build || mkdir -p build
568 test -d build/$1 || mkdir -p build/$1
570 file=build/$1/Makefile
572 dnl # Example command line to manually build source.
573 cat - <<_ACEOF >$file
574 # Example command line to manually build source
575 # make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1
577 ccflags-y := -Werror $FRAME_LARGER_THAN
580 dnl # Additional custom CFLAGS as requested.
581 m4_ifval($3, [echo "ccflags-y += $3" >>$file], [])
583 dnl # Test case source
584 echo "obj-m := $1.o" >>$file
586 AS_IF([test "x$2" = "xyes"], [echo "obj-m += $1/" >>build/Makefile], [])
590 dnl # ZFS_LINUX_TEST_PROGRAM(C)([PROLOGUE], [BODY])
592 m4_define([ZFS_LINUX_TEST_PROGRAM], [
593 #include <linux/module.h>
604 MODULE_DESCRIPTION("conftest");
605 MODULE_AUTHOR(ZFS_META_AUTHOR);
606 MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
611 dnl # ZFS_LINUX_TEST_REMOVE
613 dnl # Removes the specified test source and results.
615 AC_DEFUN([ZFS_LINUX_TEST_REMOVE], [
616 test -d build/$1 && rm -Rf build/$1
617 test -f build/Makefile && sed '/$1/d' build/Makefile
621 dnl # ZFS_LINUX_COMPILE
624 dnl # $2 - test command
625 dnl # $3 - pass command
626 dnl # $4 - fail command
627 dnl # $5 - set KBUILD_MODPOST_NOFINAL='yes'
628 dnl # $6 - set KBUILD_MODPOST_WARN='yes'
630 dnl # Used internally by ZFS_LINUX_TEST_{COMPILE,MODPOST}
632 AC_DEFUN([ZFS_LINUX_COMPILE], [
633 AC_ARG_VAR([KERNEL_CC], [C compiler for
634 building kernel modules])
635 AC_ARG_VAR([KERNEL_LD], [Linker for
636 building kernel modules])
637 AC_ARG_VAR([KERNEL_LLVM], [Binary option to
638 build kernel modules with LLVM/CLANG toolchain])
640 KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6"
641 make modules -k -j$TEST_JOBS ${KERNEL_CC:+CC=$KERNEL_CC}
642 ${KERNEL_LD:+LD=$KERNEL_LD} ${KERNEL_LLVM:+LLVM=$KERNEL_LLVM}
643 CONFIG_MODULES=y CFLAGS_MODULE=-DCONFIG_MODULES
644 -C $LINUX_OBJ $ARCH_UM M=$PWD/$1 >$1/build.log 2>&1])
645 AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4])
649 dnl # ZFS_LINUX_TEST_COMPILE
651 dnl # Perform a full compile excluding the final modpost phase.
653 AC_DEFUN([ZFS_LINUX_TEST_COMPILE], [
654 ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
655 mv $2/Makefile $2/Makefile.compile.$1
656 mv $2/build.log $2/build.log.$1
659 *** Unable to compile test source to determine kernel interfaces.])
664 dnl # ZFS_LINUX_TEST_MODPOST
666 dnl # Perform a full compile including the modpost phase. This may
667 dnl # be an incremental build if the objects have already been built.
669 AC_DEFUN([ZFS_LINUX_TEST_MODPOST], [
670 ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
671 mv $2/Makefile $2/Makefile.modpost.$1
672 cat $2/build.log >>build/build.log.$1
675 *** Unable to modpost test source to determine kernel interfaces.])
680 dnl # Perform the compilation of the test cases in two phases.
682 dnl # Phase 1) attempt to build the object files for all of the tests
683 dnl # defined by the ZFS_LINUX_TEST_SRC macro. But do not
684 dnl # perform the final modpost stage.
686 dnl # Phase 2) disable all tests which failed the initial compilation,
687 dnl # then invoke the final modpost step for the remaining tests.
689 dnl # This allows us efficiently build the test cases in parallel while
690 dnl # remaining resilient to build failures which are expected when
691 dnl # detecting the available kernel interfaces.
693 dnl # The maximum allowed parallelism can be controlled by setting the
694 dnl # TEST_JOBS environment variable. Otherwise, it default to $(nproc).
696 AC_DEFUN([ZFS_LINUX_TEST_COMPILE_ALL], [
697 dnl # Phase 1 - Compilation only, final linking is skipped.
698 ZFS_LINUX_TEST_COMPILE([$1], [build])
701 dnl # Phase 2 - When building external modules disable test cases
702 dnl # which failed to compile and invoke modpost to verify the
705 dnl # Test names suffixed with '_license' call modpost independently
706 dnl # to ensure that a single incompatibility does not result in the
707 dnl # modpost phase exiting early. This check is not performed on
708 dnl # every symbol since the majority are compatible and doing so
709 dnl # would significantly slow down this phase.
711 dnl # When configuring for builtin (--enable-linux-builtin)
712 dnl # fake the linking step artificially create the expected .ko
713 dnl # files for tests which did compile. This is required for
714 dnl # kernels which do not have loadable module support or have
715 dnl # not yet been built.
717 AS_IF([test "x$enable_linux_builtin" = "xno"], [
718 for dir in $(awk '/^obj-m/ { print [$]3 }' \
719 build/Makefile.compile.$1); do
721 AS_IF([test -f build/$name/$name.o], [
722 AS_IF([test "${name##*_}" = "license"], [
723 ZFS_LINUX_TEST_MODPOST([$1],
725 echo "obj-n += $dir" >>build/Makefile
727 echo "obj-m += $dir" >>build/Makefile
730 echo "obj-n += $dir" >>build/Makefile
734 ZFS_LINUX_TEST_MODPOST([$1], [build])
736 for dir in $(awk '/^obj-m/ { print [$]3 }' \
737 build/Makefile.compile.$1); do
739 AS_IF([test -f build/$name/$name.o], [
740 touch build/$name/$name.ko
747 dnl # ZFS_LINUX_TEST_SRC
752 dnl # $4 - extra cflags
753 dnl # $5 - check license-compatibility
755 dnl # Check if the test source is buildable at all and then if it is
756 dnl # license compatible.
758 dnl # N.B because all of the test cases are compiled in parallel they
759 dnl # must never depend on the results of previous tests. Each test
760 dnl # needs to be entirely independent.
762 AC_DEFUN([ZFS_LINUX_TEST_SRC], [
763 ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
764 [["Dual BSD/GPL"]])], [$1])
765 ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
767 AS_IF([ test -n "$5" ], [
768 ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM(
769 [[$2]], [[$3]], [[$5]])], [$1_license])
770 ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
775 dnl # ZFS_LINUX_TEST_RESULT
777 dnl # $1 - name of a test source (ZFS_LINUX_TEST_SRC)
778 dnl # $2 - run on success (valid .ko generated)
779 dnl # $3 - run on failure (unable to compile)
781 AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
782 AS_IF([test -d build/$1], [
783 AS_IF([test -f build/$1/$1.ko], [$2], [$3])
786 *** No matching source for the "$1" test, check that
787 *** both the test source and result macros refer to the same name.
793 dnl # ZFS_LINUX_TEST_ERROR
795 dnl # Generic error message which can be used when none of the expected
796 dnl # kernel interfaces were detected.
798 AC_DEFUN([ZFS_LINUX_TEST_ERROR], [
800 *** None of the expected "$1" interfaces were detected.
801 *** This may be because your kernel version is newer than what is
802 *** supported, or you are using a patched custom kernel with
803 *** incompatible modifications.
805 *** ZFS Version: $ZFS_META_ALIAS
806 *** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
811 dnl # ZFS_LINUX_TEST_RESULT_SYMBOL
813 dnl # Like ZFS_LINUX_TEST_RESULT except ZFS_CHECK_SYMBOL_EXPORT is called to
814 dnl # verify symbol exports, unless --enable-linux-builtin was provided to
817 AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
818 AS_IF([ ! test -f build/$1/$1.ko], [
821 AS_IF([test "x$enable_linux_builtin" != "xyes"], [
822 ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5])
830 dnl # ZFS_LINUX_COMPILE_IFELSE
832 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
833 ZFS_LINUX_TEST_REMOVE([conftest])
835 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1], [conftest])])
836 m4_ifvaln([$5], [ZFS_LINUX_CONFTEST_H([$5], [conftest])],
837 [ZFS_LINUX_CONFTEST_H([], [conftest])])
839 ZFS_LINUX_CONFTEST_MAKEFILE([conftest], [no],
840 [m4_ifvaln([$5], [-I$PWD/build/conftest], [])])
841 ZFS_LINUX_COMPILE([build/conftest], [$2], [$3], [$4], [], [])
845 dnl # ZFS_LINUX_TRY_COMPILE
849 dnl # $3 - run on success (valid .ko generated)
850 dnl # $4 - run on failure (unable to compile)
852 dnl # When configuring as builtin (--enable-linux-builtin) for kernels
853 dnl # without loadable module support (CONFIG_MODULES=n) only the object
854 dnl # file is created. See ZFS_LINUX_TEST_COMPILE_ALL for details.
856 AC_DEFUN([ZFS_LINUX_TRY_COMPILE], [
857 AS_IF([test "x$enable_linux_builtin" = "xyes"], [
858 ZFS_LINUX_COMPILE_IFELSE(
859 [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
860 [[ZFS_META_LICENSE]])],
861 [test -f build/conftest/conftest.o], [$3], [$4])
863 ZFS_LINUX_COMPILE_IFELSE(
864 [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
865 [[ZFS_META_LICENSE]])],
866 [test -f build/conftest/conftest.ko], [$3], [$4])
871 dnl # ZFS_CHECK_SYMBOL_EXPORT
873 dnl # Check if a symbol is exported on not by consulting the symbols
874 dnl # file, or optionally the source code.
876 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
877 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
878 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
880 if test $rc -ne 0; then
883 grep -q -E "EXPORT_SYMBOL.*($1)" \
884 "$LINUX/$file" 2>/dev/null
886 if test $rc -eq 0; then
891 if test $export -eq 0; then :
902 dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
904 dnl # Like ZFS_LINUX_TRY_COMPILER except ZFS_CHECK_SYMBOL_EXPORT is called
905 dnl # to verify symbol exports, unless --enable-linux-builtin was provided
908 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
909 ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
910 if test $rc -ne 0; then :
913 if test "x$enable_linux_builtin" != xyes; then
914 ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
916 if test $rc -ne 0; then :
925 dnl # ZFS_LINUX_TRY_COMPILE_HEADER
926 dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
927 dnl # provided via the fifth parameter
929 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER], [
930 AS_IF([test "x$enable_linux_builtin" = "xyes"], [
931 ZFS_LINUX_COMPILE_IFELSE(
932 [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
933 [[ZFS_META_LICENSE]])],
934 [test -f build/conftest/conftest.o], [$3], [$4], [$5])
936 ZFS_LINUX_COMPILE_IFELSE(
937 [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
938 [[ZFS_META_LICENSE]])],
939 [test -f build/conftest/conftest.ko], [$3], [$4], [$5])
944 dnl # AS_VERSION_COMPARE_LE
945 dnl # like AS_VERSION_COMPARE_LE, but runs $3 if (and only if) $1 <= $2
946 dnl # AS_VERSION_COMPARE_LE (version-1, version-2, [action-if-less-or-equal], [action-if-greater])
948 AC_DEFUN([AS_VERSION_COMPARE_LE], [
949 AS_VERSION_COMPARE([$1], [$2], [$3], [$3], [$4])
953 dnl # ZFS_LINUX_REQUIRE_API
954 dnl # like ZFS_LINUX_TEST_ERROR, except only fails if the kernel is
955 dnl # at least some specified version.
957 AC_DEFUN([ZFS_LINUX_REQUIRE_API], [
958 AS_VERSION_COMPARE_LE([$2], [$kernsrcver], [
960 *** None of the expected "$1" interfaces were detected. This
961 *** interface is expected for kernels version "$2" and above.
962 *** This may be because your kernel version is newer than what is
963 *** supported, or you are using a patched custom kernel with
964 *** incompatible modifications. Newer kernels may have incompatible
967 *** ZFS Version: $ZFS_META_ALIAS
968 *** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX