xref: /src/sys/contrib/openzfs/config/kernel.m4 (revision 8a62a2a5659d1839d8799b4274c04469d7f17c78)
1dnl # SPDX-License-Identifier: CDDL-1.0
2dnl #
3dnl # Default ZFS kernel configuration
4dnl #
5AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
6	AM_COND_IF([BUILD_LINUX], [
7		dnl # Setup the kernel build environment.
8		ZFS_AC_KERNEL
9		ZFS_AC_QAT
10
11		dnl # Sanity checks for module building and CONFIG_* defines
12		ZFS_AC_KERNEL_CONFIG_DEFINED
13		ZFS_AC_MODULE_SYMVERS
14
15		dnl # Sequential ZFS_LINUX_TRY_COMPILE tests
16		ZFS_AC_KERNEL_FPU_HEADER
17		ZFS_AC_KERNEL_OBJTOOL_HEADER
18		ZFS_AC_KERNEL_MISC_MINOR
19		ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
20
21		dnl # Parallel ZFS_LINUX_TEST_SRC / ZFS_LINUX_TEST_RESULT tests
22		ZFS_AC_KERNEL_TEST_SRC
23		ZFS_AC_KERNEL_TEST_RESULT
24
25		AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
26			KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ"
27		])
28
29		AC_SUBST(KERNEL_MAKE)
30	])
31])
32
33dnl #
34dnl # Generate and compile all of the kernel API test cases to determine
35dnl # which interfaces are available.  By invoking the kernel build system
36dnl # only once the compilation can be done in parallel significantly
37dnl # speeding up the process.
38dnl #
39AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
40	ZFS_AC_KERNEL_SRC_TYPES
41	ZFS_AC_KERNEL_SRC_OBJTOOL
42	ZFS_AC_KERNEL_SRC_ACCESS_OK_TYPE
43	ZFS_AC_KERNEL_SRC_PDE_DATA
44	ZFS_AC_KERNEL_SRC_GENERIC_FADVISE
45	ZFS_AC_KERNEL_SRC_SCHED
46	ZFS_AC_KERNEL_SRC_USLEEP_RANGE
47	ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
48	ZFS_AC_KERNEL_SRC_INODE_TIMES
49	ZFS_AC_KERNEL_SRC_PROC_OPERATIONS
50	ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS
51	ZFS_AC_KERNEL_SRC_BIO
52	ZFS_AC_KERNEL_SRC_BLKDEV
53	ZFS_AC_KERNEL_SRC_BLK_QUEUE
54	ZFS_AC_KERNEL_SRC_GENHD_FLAGS
55	ZFS_AC_KERNEL_SRC_REVALIDATE_DISK
56	ZFS_AC_KERNEL_SRC_GET_DISK_RO
57	ZFS_AC_KERNEL_SRC_DISCARD_GRANULARITY
58	ZFS_AC_KERNEL_SRC_INODE_OWNER_OR_CAPABLE
59	ZFS_AC_KERNEL_SRC_XATTR
60	ZFS_AC_KERNEL_SRC_ACL
61	ZFS_AC_KERNEL_SRC_INODE_SETATTR
62	ZFS_AC_KERNEL_SRC_INODE_GETATTR
63	ZFS_AC_KERNEL_SRC_INODE_STATE_READ_ONCE
64	ZFS_AC_KERNEL_SRC_SHOW_OPTIONS
65	ZFS_AC_KERNEL_SRC_SHRINKER
66	ZFS_AC_KERNEL_SRC_MKDIR
67	ZFS_AC_KERNEL_SRC_LOOKUP_FLAGS
68	ZFS_AC_KERNEL_SRC_CREATE
69	ZFS_AC_KERNEL_SRC_PERMISSION
70	ZFS_AC_KERNEL_SRC_TMPFILE
71	ZFS_AC_KERNEL_SRC_AUTOMOUNT
72	ZFS_AC_KERNEL_SRC_COMMIT_METADATA
73	ZFS_AC_KERNEL_SRC_SETATTR_PREPARE
74	ZFS_AC_KERNEL_SRC_INSERT_INODE_LOCKED
75	ZFS_AC_KERNEL_SRC_DENTRY
76	ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE
77	ZFS_AC_KERNEL_SRC_SECURITY_INODE
78	ZFS_AC_KERNEL_SRC_FS_CONTEXT
79	ZFS_AC_KERNEL_SRC_SB_DYING
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_MIGRATE_FOLIO
85	ZFS_AC_KERNEL_SRC_VFS_MIGRATEPAGE
86	ZFS_AC_KERNEL_SRC_VFS_FSYNC_2ARGS
87	ZFS_AC_KERNEL_SRC_VFS_READPAGES
88	ZFS_AC_KERNEL_SRC_VFS_WRITEPAGE
89	ZFS_AC_KERNEL_SRC_VFS_SET_PAGE_DIRTY_NOBUFFERS
90	ZFS_AC_KERNEL_SRC_VFS_IOV_ITER
91	ZFS_AC_KERNEL_SRC_VFS_GENERIC_COPY_FILE_RANGE
92	ZFS_AC_KERNEL_SRC_VFS_SPLICE_COPY_FILE_RANGE
93	ZFS_AC_KERNEL_SRC_VFS_REMAP_FILE_RANGE
94	ZFS_AC_KERNEL_SRC_VFS_CLONE_FILE_RANGE
95	ZFS_AC_KERNEL_SRC_VFS_DEDUPE_FILE_RANGE
96	ZFS_AC_KERNEL_SRC_KMAP_ATOMIC_ARGS
97	ZFS_AC_KERNEL_SRC_KMAP_LOCAL_PAGE
98	ZFS_AC_KERNEL_SRC_FOLLOW_DOWN_ONE
99	ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN
100	ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT
101	ZFS_AC_KERNEL_SRC_FPU
102	ZFS_AC_KERNEL_SRC_FMODE_T
103	ZFS_AC_KERNEL_SRC_KUIDGID_T
104	ZFS_AC_KERNEL_SRC_KUID_HELPERS
105	ZFS_AC_KERNEL_SRC_RENAME
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_PAGEMAP_READAHEAD_PAGE
119	ZFS_AC_KERNEL_SRC_ADD_DISK
120	ZFS_AC_KERNEL_SRC_KTHREAD
121	ZFS_AC_KERNEL_SRC_ZERO_PAGE
122	ZFS_AC_KERNEL_SRC___COPY_FROM_USER_INATOMIC
123	ZFS_AC_KERNEL_SRC_IDMAP_MNT_API
124	ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS
125	ZFS_AC_KERNEL_SRC_IATTR_VFSID
126	ZFS_AC_KERNEL_SRC_WRITEBACK
127	ZFS_AC_KERNEL_SRC_RECLAIMED
128	ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_TABLE
129	ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_SZ
130	ZFS_AC_KERNEL_SRC_PROC_HANDLER_CTL_TABLE_CONST
131	ZFS_AC_KERNEL_SRC_COPY_SPLICE_READ
132	ZFS_AC_KERNEL_SRC_SYNC_BDEV
133	ZFS_AC_KERNEL_SRC_MM_PAGE_FLAGS
134	ZFS_AC_KERNEL_SRC_MM_PAGE_SIZE
135	ZFS_AC_KERNEL_SRC_MM_PAGE_MAPPING
136	ZFS_AC_KERNEL_SRC_FILE
137	ZFS_AC_KERNEL_SRC_PIN_USER_PAGES
138	ZFS_AC_KERNEL_SRC_TIMER
139	ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_WB_ERR
140	ZFS_AC_KERNEL_SRC_SOPS_FREE_INODE
141	ZFS_AC_KERNEL_SRC_NAMESPACE
142	ZFS_AC_KERNEL_SRC_INODE_GENERIC_DROP
143	ZFS_AC_KERNEL_SRC_KASAN_ENABLED
144	ZFS_AC_KERNEL_SRC_FILELOCK_HEADER
145	case "$host_cpu" in
146		powerpc*)
147			ZFS_AC_KERNEL_SRC_CPU_HAS_FEATURE
148			ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
149			;;
150		riscv*)
151			ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
152			;;
153	esac
154
155	AC_MSG_CHECKING([for available kernel interfaces])
156	ZFS_LINUX_TEST_COMPILE_ALL([kabi])
157	AC_MSG_RESULT([done])
158])
159
160dnl #
161dnl # Check results of kernel interface tests.
162dnl #
163AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
164	ZFS_AC_KERNEL_TYPES
165	ZFS_AC_KERNEL_ACCESS_OK_TYPE
166	ZFS_AC_KERNEL_OBJTOOL
167	ZFS_AC_KERNEL_PDE_DATA
168	ZFS_AC_KERNEL_GENERIC_FADVISE
169	ZFS_AC_KERNEL_SCHED
170	ZFS_AC_KERNEL_USLEEP_RANGE
171	ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
172	ZFS_AC_KERNEL_INODE_TIMES
173	ZFS_AC_KERNEL_PROC_OPERATIONS
174	ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS
175	ZFS_AC_KERNEL_BIO
176	ZFS_AC_KERNEL_BLKDEV
177	ZFS_AC_KERNEL_BLK_QUEUE
178	ZFS_AC_KERNEL_GENHD_FLAGS
179	ZFS_AC_KERNEL_REVALIDATE_DISK
180	ZFS_AC_KERNEL_GET_DISK_RO
181	ZFS_AC_KERNEL_DISCARD_GRANULARITY
182	ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
183	ZFS_AC_KERNEL_XATTR
184	ZFS_AC_KERNEL_ACL
185	ZFS_AC_KERNEL_INODE_SETATTR
186	ZFS_AC_KERNEL_INODE_GETATTR
187	ZFS_AC_KERNEL_INODE_STATE_READ_ONCE
188	ZFS_AC_KERNEL_SHOW_OPTIONS
189	ZFS_AC_KERNEL_SHRINKER
190	ZFS_AC_KERNEL_MKDIR
191	ZFS_AC_KERNEL_LOOKUP_FLAGS
192	ZFS_AC_KERNEL_CREATE
193	ZFS_AC_KERNEL_PERMISSION
194	ZFS_AC_KERNEL_TMPFILE
195	ZFS_AC_KERNEL_AUTOMOUNT
196	ZFS_AC_KERNEL_COMMIT_METADATA
197	ZFS_AC_KERNEL_SETATTR_PREPARE
198	ZFS_AC_KERNEL_INSERT_INODE_LOCKED
199	ZFS_AC_KERNEL_DENTRY
200	ZFS_AC_KERNEL_TRUNCATE_SETSIZE
201	ZFS_AC_KERNEL_SECURITY_INODE
202	ZFS_AC_KERNEL_FS_CONTEXT
203	ZFS_AC_KERNEL_SB_DYING
204	ZFS_AC_KERNEL_SET_NLINK
205	ZFS_AC_KERNEL_SGET
206	ZFS_AC_KERNEL_VFS_FILEMAP_DIRTY_FOLIO
207	ZFS_AC_KERNEL_VFS_READ_FOLIO
208	ZFS_AC_KERNEL_VFS_MIGRATE_FOLIO
209	ZFS_AC_KERNEL_VFS_MIGRATEPAGE
210	ZFS_AC_KERNEL_VFS_FSYNC_2ARGS
211	ZFS_AC_KERNEL_VFS_READPAGES
212	ZFS_AC_KERNEL_VFS_WRITEPAGE
213	ZFS_AC_KERNEL_VFS_SET_PAGE_DIRTY_NOBUFFERS
214	ZFS_AC_KERNEL_VFS_IOV_ITER
215	ZFS_AC_KERNEL_VFS_GENERIC_COPY_FILE_RANGE
216	ZFS_AC_KERNEL_VFS_SPLICE_COPY_FILE_RANGE
217	ZFS_AC_KERNEL_VFS_REMAP_FILE_RANGE
218	ZFS_AC_KERNEL_VFS_CLONE_FILE_RANGE
219	ZFS_AC_KERNEL_VFS_DEDUPE_FILE_RANGE
220	ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
221	ZFS_AC_KERNEL_KMAP_LOCAL_PAGE
222	ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
223	ZFS_AC_KERNEL_MAKE_REQUEST_FN
224	ZFS_AC_KERNEL_GENERIC_IO_ACCT
225	ZFS_AC_KERNEL_FPU
226	ZFS_AC_KERNEL_FMODE_T
227	ZFS_AC_KERNEL_KUIDGID_T
228	ZFS_AC_KERNEL_KUID_HELPERS
229	ZFS_AC_KERNEL_RENAME
230	ZFS_AC_KERNEL_TOTALRAM_PAGES_FUNC
231	ZFS_AC_KERNEL_TOTALHIGH_PAGES
232	ZFS_AC_KERNEL_PERCPU
233	ZFS_AC_KERNEL_GENERIC_FILLATTR
234	ZFS_AC_KERNEL_MKNOD
235	ZFS_AC_KERNEL_SYMLINK
236	ZFS_AC_KERNEL_BIO_MAX_SEGS
237	ZFS_AC_KERNEL_SIGINFO
238	ZFS_AC_KERNEL_SYSFS
239	ZFS_AC_KERNEL_STANDALONE_LINUX_STDARG
240	ZFS_AC_KERNEL_STRLCPY
241	ZFS_AC_KERNEL_PAGEMAP_FOLIO_WAIT_BIT
242	ZFS_AC_KERNEL_PAGEMAP_READAHEAD_PAGE
243	ZFS_AC_KERNEL_ADD_DISK
244	ZFS_AC_KERNEL_KTHREAD
245	ZFS_AC_KERNEL_ZERO_PAGE
246	ZFS_AC_KERNEL___COPY_FROM_USER_INATOMIC
247	ZFS_AC_KERNEL_IDMAP_MNT_API
248	ZFS_AC_KERNEL_IDMAP_NO_USERNS
249	ZFS_AC_KERNEL_IATTR_VFSID
250	ZFS_AC_KERNEL_WRITEBACK
251	ZFS_AC_KERNEL_RECLAIMED
252	ZFS_AC_KERNEL_REGISTER_SYSCTL_TABLE
253	ZFS_AC_KERNEL_REGISTER_SYSCTL_SZ
254	ZFS_AC_KERNEL_PROC_HANDLER_CTL_TABLE_CONST
255	ZFS_AC_KERNEL_COPY_SPLICE_READ
256	ZFS_AC_KERNEL_SYNC_BDEV
257	ZFS_AC_KERNEL_MM_PAGE_FLAGS
258	ZFS_AC_KERNEL_MM_PAGE_SIZE
259	ZFS_AC_KERNEL_MM_PAGE_MAPPING
260	ZFS_AC_KERNEL_1ARG_ASSIGN_STR
261	ZFS_AC_KERNEL_FILE
262	ZFS_AC_KERNEL_PIN_USER_PAGES
263	ZFS_AC_KERNEL_TIMER
264	ZFS_AC_KERNEL_SUPER_BLOCK_S_WB_ERR
265	ZFS_AC_KERNEL_SOPS_FREE_INODE
266	ZFS_AC_KERNEL_NAMESPACE
267	ZFS_AC_KERNEL_INODE_GENERIC_DROP
268	ZFS_AC_KERNEL_KASAN_ENABLED
269	ZFS_AC_KERNEL_FILELOCK_HEADER
270	case "$host_cpu" in
271		powerpc*)
272			ZFS_AC_KERNEL_CPU_HAS_FEATURE
273			ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
274			;;
275		riscv*)
276			ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
277			;;
278	esac
279])
280
281dnl #
282dnl # Detect name used for Module.symvers file in kernel
283dnl #
284AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
285	modpost=$LINUX/scripts/Makefile.modpost
286	AC_MSG_CHECKING([kernel file name for module symbols])
287	AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
288		AS_IF([grep -q Modules.symvers $modpost], [
289			LINUX_SYMBOLS=Modules.symvers
290		], [
291			LINUX_SYMBOLS=Module.symvers
292		])
293
294		AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
295			AC_MSG_ERROR([
296	*** Please make sure the kernel devel package for your distribution
297	*** is installed.  If you are building with a custom kernel, make sure
298	*** the kernel is configured, built, and the '--with-linux=PATH'
299	*** configure option refers to the location of the kernel source.
300			])
301		])
302	], [
303		LINUX_SYMBOLS=NONE
304	])
305	AC_MSG_RESULT($LINUX_SYMBOLS)
306	AC_SUBST(LINUX_SYMBOLS)
307])
308
309dnl #
310dnl # Detect the kernel to be built against
311dnl #
312dnl # Most modern Linux distributions have separate locations for bare
313dnl # source (source) and prebuilt (build) files. Additionally, there are
314dnl # `source` and `build` symlinks in `/lib/modules/$(KERNEL_VERSION)`
315dnl # pointing to them. The directory search order is now:
316dnl #
317dnl # - `configure` command line values if both `--with-linux` and
318dnl #   `--with-linux-obj` were defined
319dnl #
320dnl # - If only `--with-linux` was defined, `--with-linux-obj` is assumed
321dnl #   to have the same value as `--with-linux`
322dnl #
323dnl # - If neither `--with-linux` nor `--with-linux-obj` were defined
324dnl #   autodetection is used:
325dnl #
326dnl #   - `/lib/modules/$(uname -r)/{source,build}` respectively, if exist.
327dnl #
328dnl #   - If only `/lib/modules/$(uname -r)/build` exists, it is assumed
329dnl #     to be both source and build directory.
330dnl #
331dnl #   - The first directory in `/lib/modules` with the highest version
332dnl #     number according to `sort -V` which contains both `source` and
333dnl #     `build` symlinks/directories. If module directory contains only
334dnl #     `build` component, it is assumed to be both source and build
335dnl #     directory.
336dnl #
337dnl #   - Last resort: the first directory matching `/usr/src/kernels/*`
338dnl #     and `/usr/src/linux-*` with the highest version number according
339dnl #     to `sort -V` is assumed to be both source and build directory.
340dnl #
341AC_DEFUN([ZFS_AC_KERNEL], [
342	AC_ARG_WITH([linux],
343		AS_HELP_STRING([--with-linux=PATH],
344		[Path to kernel source]),
345		[kernelsrc="$withval"])
346
347	AC_ARG_WITH(linux-obj,
348		AS_HELP_STRING([--with-linux-obj=PATH],
349		[Path to kernel build objects]),
350		[kernelbuild="$withval"])
351
352	AC_MSG_CHECKING([kernel source and build directories])
353	AS_IF([test -n "$kernelsrc" && test -z "$kernelbuild"], [
354		kernelbuild="$kernelsrc"
355	], [test -z "$kernelsrc"], [
356		AS_IF([test -e "/lib/modules/$(uname -r)/source" && \
357		       test -e "/lib/modules/$(uname -r)/build"], [
358			src="/lib/modules/$(uname -r)/source"
359			build="/lib/modules/$(uname -r)/build"
360		], [test -e "/lib/modules/$(uname -r)/build"], [
361			build="/lib/modules/$(uname -r)/build"
362			src="$build"
363		], [
364			src=
365
366			for d in $(ls -1d /lib/modules/* 2>/dev/null | sort -Vr); do
367				if test -e "$d/source" && test -e "$d/build"; then
368					src="$d/source"
369					build="$d/build"
370					break
371				fi
372
373				if test -e "$d/build"; then
374					src="$d/build"
375					build="$d/build"
376					break
377				fi
378			done
379
380			# the least reliable method
381			if test -z "$src"; then
382				src=$(ls -1d /usr/src/kernels/* /usr/src/linux-* \
383				      2>/dev/null | grep -v obj | sort -Vr | head -1)
384				build="$src"
385			fi
386		])
387
388		AS_IF([test -n "$src" && test -e "$src"], [
389			kernelsrc=$(readlink -e "$src")
390		], [
391			kernelsrc="[Not found]"
392		])
393		AS_IF([test -n "$build" && test -e "$build"], [
394			kernelbuild=$(readlink -e "$build")
395		], [
396			kernelbuild="[Not found]"
397		])
398	], [
399		AS_IF([test "$kernelsrc" = "NONE"], [
400			kernsrcver=NONE
401		])
402		withlinux=yes
403	])
404
405	AC_MSG_RESULT([done])
406	AC_MSG_CHECKING([kernel source directory])
407	AC_MSG_RESULT([$kernelsrc])
408	AC_MSG_CHECKING([kernel build directory])
409	AC_MSG_RESULT([$kernelbuild])
410	AS_IF([test ! -d "$kernelsrc" || test ! -d "$kernelbuild"], [
411		AC_MSG_ERROR([
412	*** Please make sure the kernel devel package for your distribution
413	*** is installed and then try again.  If that fails, you can specify the
414	*** location of the kernel source and build with the '--with-linux=PATH' and
415	*** '--with-linux-obj=PATH' options respectively.])
416	])
417
418	AC_MSG_CHECKING([kernel source version])
419	utsrelease1=$kernelbuild/include/linux/version.h
420	utsrelease2=$kernelbuild/include/linux/utsrelease.h
421	utsrelease3=$kernelbuild/include/generated/utsrelease.h
422	AS_IF([test -r $utsrelease1 && grep -qF UTS_RELEASE $utsrelease1], [
423		utsrelease=$utsrelease1
424	], [test -r $utsrelease2 && grep -qF UTS_RELEASE $utsrelease2], [
425		utsrelease=$utsrelease2
426	], [test -r $utsrelease3 && grep -qF UTS_RELEASE $utsrelease3], [
427		utsrelease=$utsrelease3
428	])
429
430	AS_IF([test -n "$utsrelease"], [
431		kernsrcver=$($AWK '/UTS_RELEASE/ { gsub(/"/, "", $[3]); print $[3] }' $utsrelease)
432		AS_IF([test -z "$kernsrcver"], [
433			AC_MSG_RESULT([Not found])
434			AC_MSG_ERROR([
435	*** Cannot determine kernel version.
436			])
437		])
438	], [
439		AC_MSG_RESULT([Not found])
440		if test "x$enable_linux_builtin" != xyes; then
441			AC_MSG_ERROR([
442	*** Cannot find UTS_RELEASE definition.
443			])
444		else
445			AC_MSG_ERROR([
446	*** Cannot find UTS_RELEASE definition.
447	*** Please run 'make prepare' inside the kernel source tree.])
448		fi
449	])
450
451	AC_MSG_RESULT([$kernsrcver])
452
453	AX_COMPARE_VERSION([$kernsrcver], [ge], [$ZFS_META_KVER_MIN], [], [
454		AC_MSG_ERROR([
455	*** Cannot build against kernel version $kernsrcver.
456	*** The minimum supported kernel version is $ZFS_META_KVER_MIN.
457		])
458	])
459
460	AC_ARG_ENABLE([linux-experimental],
461		AS_HELP_STRING([--enable-linux-experimental],
462		[Allow building against some unsupported kernel versions]))
463
464	AX_COMPARE_VERSION([$kernsrcver], [ge], [$ZFS_META_KVER_MAX], [
465		AX_COMPARE_VERSION([$kernsrcver], [eq2], [$ZFS_META_KVER_MAX], [
466			kern_max_version_ok=yes
467		], [
468			kern_max_version_ok=no
469		])
470	], [
471		kern_max_version_ok=yes
472	])
473
474	AS_IF([test "x$kern_max_version_ok" != "xyes"], [
475		AS_IF([test "x$enable_linux_experimental" == "xyes"], [
476			AC_DEFINE(HAVE_LINUX_EXPERIMENTAL, 1,
477			    [building against unsupported kernel version])
478		], [
479			AC_MSG_ERROR([
480	*** Cannot build against kernel version $kernsrcver.
481	*** The maximum supported kernel version is $ZFS_META_KVER_MAX.
482			])
483		])
484	])
485
486	LINUX=${kernelsrc}
487	LINUX_OBJ=${kernelbuild}
488	LINUX_VERSION=${kernsrcver}
489
490	AC_SUBST(LINUX)
491	AC_SUBST(LINUX_OBJ)
492	AC_SUBST(LINUX_VERSION)
493
494	dnl # create a relatively unique numeric checksum based on the kernel
495	dnl # version and path. this is included in the cache key below,
496	dnl # allowing different cached values for different kernels
497	_zfs_linux_cache_checksum=$(echo ${kernelsrc} {$kernelbuild} ${kernsrcver} | cksum | cut -f1 -d' ')
498])
499
500AC_DEFUN([ZFS_AC_KERNEL_VERSION_WARNING], [
501	AS_IF([test "x$enable_linux_experimental" = "xyes" && \
502	    test "x$kern_max_version_ok" != "xyes"], [
503		AC_MSG_WARN([
504
505	You are building OpenZFS against Linux version $kernsrcver.
506
507	This combination is considered EXPERIMENTAL by the OpenZFS project.
508	Even if it appears to build and run correctly, there may be bugs that
509	can cause SERIOUS DATA LOSS.
510
511	YOU HAVE BEEN WARNED!
512
513	If you choose to continue, we'd appreciate if you could report your
514	results on the OpenZFS issue tracker at:
515
516	    https://github.com/openzfs/zfs/issues/new
517
518	Your feedback will help us prepare a new OpenZFS release that supports
519	this version of Linux.
520		])
521	])
522])
523
524dnl #
525dnl # Detect the QAT module to be built against, QAT provides hardware
526dnl # acceleration for data compression:
527dnl #
528dnl # https://01.org/intel-quickassist-technology
529dnl #
530dnl # 1) Download and install QAT driver from the above link
531dnl # 2) Start QAT driver in your system:
532dnl # 	 service qat_service start
533dnl # 3) Enable QAT in ZFS, e.g.:
534dnl # 	 ./configure --with-qat=<qat-driver-path>/QAT1.6
535dnl # 	 make
536dnl # 4) Set GZIP compression in ZFS dataset:
537dnl # 	 zfs set compression = gzip <dataset>
538dnl #
539dnl # Then the data written to this ZFS pool is compressed by QAT accelerator
540dnl # automatically, and de-compressed by QAT when read from the pool.
541dnl #
542dnl # 1) Get QAT hardware statistics with:
543dnl #	 cat /proc/icp_dh895xcc_dev/qat
544dnl # 2) To disable QAT:
545dnl # 	 insmod zfs.ko zfs_qat_disable=1
546dnl #
547AC_DEFUN([ZFS_AC_QAT], [
548	AC_ARG_WITH([qat],
549		AS_HELP_STRING([--with-qat=PATH],
550		[Path to qat source]),
551		AS_IF([test "$withval" = "yes"],
552			AC_MSG_ERROR([--with-qat=PATH requires a PATH]),
553			[qatsrc="$withval"]))
554
555	AC_ARG_WITH([qat-obj],
556		AS_HELP_STRING([--with-qat-obj=PATH],
557		[Path to qat build objects]),
558		[qatbuild="$withval"])
559
560	AS_IF([test ! -z "${qatsrc}"], [
561		AC_MSG_CHECKING([qat source directory])
562		AC_MSG_RESULT([$qatsrc])
563		QAT_SRC="${qatsrc}/quickassist"
564		AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [
565			AC_MSG_ERROR([
566	*** Please make sure the qat driver package is installed
567	*** and specify the location of the qat source with the
568	*** '--with-qat=PATH' option then try again. Failed to
569	*** find cpa.h in:
570	${QAT_SRC}/include])
571		])
572	])
573
574	AS_IF([test ! -z "${qatsrc}"], [
575		AC_MSG_CHECKING([qat build directory])
576		AS_IF([test -z "$qatbuild"], [
577			qatbuild="${qatsrc}/build"
578		])
579
580		AC_MSG_RESULT([$qatbuild])
581		QAT_OBJ=${qatbuild}
582		AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko" && ! test -e "$QAT_OBJ/qat_api.ko"], [
583			AC_MSG_ERROR([
584	*** Please make sure the qat driver is installed then try again.
585	*** Failed to find icp_qa_al.ko or qat_api.ko in:
586	$QAT_OBJ])
587		])
588
589		AC_SUBST(QAT_SRC)
590		AC_SUBST(QAT_OBJ)
591
592		AC_DEFINE(HAVE_QAT, 1,
593		[qat is enabled and existed])
594	])
595
596	dnl #
597	dnl # Detect the name used for the QAT Module.symvers file.
598	dnl #
599	AS_IF([test ! -z "${qatsrc}"], [
600		AC_MSG_CHECKING([qat file for module symbols])
601		QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers
602
603		AS_IF([test -r $QAT_SYMBOLS], [
604			AC_MSG_RESULT([$QAT_SYMBOLS])
605			AC_SUBST(QAT_SYMBOLS)
606		],[
607			AC_MSG_ERROR([
608	*** Please make sure the qat driver is installed then try again.
609	*** Failed to find Module.symvers in:
610	$QAT_SYMBOLS
611			])
612		])
613	])
614])
615
616dnl #
617dnl # ZFS_LINUX_CONFTEST_H
618dnl #
619AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
620test -d build/$2 || mkdir -p build/$2
621cat - <<_ACEOF >build/$2/$2.h
622$1
623_ACEOF
624])
625
626dnl #
627dnl # ZFS_LINUX_CONFTEST_C
628dnl #
629AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
630test -d build/$2 || mkdir -p build/$2
631cat confdefs.h - <<_ACEOF >build/$2/$2.c
632$1
633_ACEOF
634])
635
636dnl #
637dnl # ZFS_LINUX_CONFTEST_MAKEFILE
638dnl #
639dnl # $1 - test case name
640dnl # $2 - add to top-level Makefile
641dnl # $3 - additional build flags
642dnl #
643AC_DEFUN([ZFS_LINUX_CONFTEST_MAKEFILE], [
644	test -d build || mkdir -p build
645	test -d build/$1 || mkdir -p build/$1
646
647	file=build/$1/Makefile
648
649	dnl # Example command line to manually build source.
650	cat - <<_ACEOF >$file
651# Example command line to manually build source
652# make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1
653
654ccflags-y := -Werror $FRAME_LARGER_THAN
655_ACEOF
656
657	dnl # Additional custom CFLAGS as requested.
658	m4_ifval($3, [echo "ccflags-y += $3" >>$file], [])
659
660	dnl # Test case source
661	echo "obj-m := $1.o" >>$file
662
663	AS_IF([test "x$2" = "xyes"], [echo "obj-m += $1/" >>build/Makefile], [])
664])
665
666dnl #
667dnl # ZFS_LINUX_TEST_PROGRAM(C)([PROLOGUE], [BODY])
668dnl #
669m4_define([ZFS_LINUX_TEST_PROGRAM], [
670#include <linux/module.h>
671$1
672
673int
674main (void)
675{
676$2
677	;
678	return 0;
679}
680
681MODULE_DESCRIPTION("conftest");
682MODULE_AUTHOR(ZFS_META_AUTHOR);
683MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
684MODULE_LICENSE($3);
685])
686
687dnl #
688dnl # ZFS_LINUX_TEST_REMOVE
689dnl #
690dnl # Removes the specified test source and results.
691dnl #
692AC_DEFUN([ZFS_LINUX_TEST_REMOVE], [
693	test -d build/$1 && rm -Rf build/$1
694	test -f build/Makefile && sed '/$1/d' build/Makefile
695])
696
697dnl #
698dnl # ZFS_LINUX_COMPILE
699dnl #
700dnl # $1 - build dir
701dnl # $2 - test command
702dnl # $3 - pass command
703dnl # $4 - fail command
704dnl # $5 - set KBUILD_MODPOST_NOFINAL='yes'
705dnl # $6 - set KBUILD_MODPOST_WARN='yes'
706dnl #
707dnl # Used internally by ZFS_LINUX_TEST_{COMPILE,MODPOST}
708dnl #
709AC_DEFUN([ZFS_LINUX_COMPILE], [
710	AC_ARG_VAR([KERNEL_CC], [C compiler for
711		building kernel modules])
712	AC_ARG_VAR([KERNEL_LD], [Linker for
713		building kernel modules])
714	AC_ARG_VAR([KERNEL_LLVM], [Binary option to
715		build kernel modules with LLVM/CLANG toolchain])
716	AC_ARG_VAR([KERNEL_CROSS_COMPILE], [Cross compile prefix
717		for kernel module builds])
718	AC_ARG_VAR([KERNEL_ARCH], [Architecture to build kernel modules for])
719	AC_TRY_COMMAND([
720	    KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6"
721	    make modules -k -j$TEST_JOBS ${KERNEL_CC:+CC=$KERNEL_CC}
722	    ${KERNEL_LD:+LD=$KERNEL_LD} ${KERNEL_LLVM:+LLVM=$KERNEL_LLVM}
723	    CONFIG_MODULES=y CFLAGS_MODULE=-DCONFIG_MODULES
724	    ${KERNEL_CROSS_COMPILE:+CROSS_COMPILE=$KERNEL_CROSS_COMPILE}
725	    ${KERNEL_ARCH:+ARCH=$KERNEL_ARCH}
726	    -C $LINUX_OBJ $ARCH_UM M=$PWD/$1 >$1/build.log 2>&1])
727	AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4])
728])
729
730dnl #
731dnl # ZFS_LINUX_TEST_COMPILE
732dnl #
733dnl # Perform a full compile excluding the final modpost phase.
734dnl #
735AC_DEFUN([ZFS_LINUX_TEST_COMPILE], [
736	ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
737		mv $2/Makefile $2/Makefile.compile.$1
738		mv $2/build.log $2/build.log.$1
739	],[
740	        AC_MSG_ERROR([
741        *** Unable to compile test source to determine kernel interfaces.])
742	], [yes], [])
743])
744
745dnl #
746dnl # ZFS_LINUX_TEST_MODPOST
747dnl #
748dnl # Perform a full compile including the modpost phase.  This may
749dnl # be an incremental build if the objects have already been built.
750dnl #
751AC_DEFUN([ZFS_LINUX_TEST_MODPOST], [
752	ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
753		mv $2/Makefile $2/Makefile.modpost.$1
754		cat $2/build.log >>build/build.log.$1
755	],[
756	        AC_MSG_ERROR([
757        *** Unable to modpost test source to determine kernel interfaces.])
758	], [], [yes])
759])
760
761dnl #
762dnl # Perform the compilation of the test cases in two phases.
763dnl #
764dnl # Phase 1) attempt to build the object files for all of the tests
765dnl #          defined by the ZFS_LINUX_TEST_SRC macro.  But do not
766dnl #          perform the final modpost stage.
767dnl #
768dnl # Phase 2) disable all tests which failed the initial compilation,
769dnl #          then invoke the final modpost step for the remaining tests.
770dnl #
771dnl # This allows us efficiently build the test cases in parallel while
772dnl # remaining resilient to build failures which are expected when
773dnl # detecting the available kernel interfaces.
774dnl #
775dnl # The maximum allowed parallelism can be controlled by setting the
776dnl # TEST_JOBS environment variable.  Otherwise, it default to $(nproc).
777dnl #
778AC_DEFUN([ZFS_LINUX_TEST_COMPILE_ALL], [
779	dnl # Phase 1 - Compilation only, final linking is skipped.
780	ZFS_LINUX_TEST_COMPILE([$1], [build])
781
782	dnl #
783	dnl # Phase 2 - When building external modules disable test cases
784	dnl # which failed to compile and invoke modpost to verify the
785	dnl # final linking.
786	dnl #
787	dnl # Test names suffixed with '_license' call modpost independently
788	dnl # to ensure that a single incompatibility does not result in the
789	dnl # modpost phase exiting early.  This check is not performed on
790	dnl # every symbol since the majority are compatible and doing so
791	dnl # would significantly slow down this phase.
792	dnl #
793	dnl # When configuring for builtin (--enable-linux-builtin)
794	dnl # fake the linking step artificially create the expected .ko
795	dnl # files for tests which did compile.  This is required for
796	dnl # kernels which do not have loadable module support or have
797	dnl # not yet been built.
798	dnl #
799	AS_IF([test "x$enable_linux_builtin" = "xno"], [
800		for dir in $(awk '/^obj-m/ { print [$]3 }' \
801		    build/Makefile.compile.$1); do
802			name=${dir%/}
803			AS_IF([test -f build/$name/$name.o], [
804				AS_IF([test "${name##*_}" = "license"], [
805					ZFS_LINUX_TEST_MODPOST([$1],
806					    [build/$name])
807					echo "obj-n += $dir" >>build/Makefile
808				], [
809					echo "obj-m += $dir" >>build/Makefile
810				])
811			], [
812				echo "obj-n += $dir" >>build/Makefile
813			])
814		done
815
816		ZFS_LINUX_TEST_MODPOST([$1], [build])
817	], [
818		for dir in $(awk '/^obj-m/ { print [$]3 }' \
819		    build/Makefile.compile.$1); do
820			name=${dir%/}
821			AS_IF([test -f build/$name/$name.o], [
822				touch build/$name/$name.ko
823			])
824		done
825	])
826])
827
828dnl #
829dnl # ZFS_LINUX_TEST_SRC
830dnl #
831dnl # $1 - name
832dnl # $2 - global
833dnl # $3 - source
834dnl # $4 - extra cflags
835dnl # $5 - check license-compatibility
836dnl #
837dnl # Check if the test source is buildable at all and then if it is
838dnl # license compatible.
839dnl #
840dnl # N.B because all of the test cases are compiled in parallel they
841dnl # must never depend on the results of previous tests.  Each test
842dnl # needs to be entirely independent.
843dnl #
844AC_DEFUN([ZFS_LINUX_TEST_SRC], [
845	cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
846	eval "cacheval=\$$cachevar"
847	AS_IF([test "x$cacheval" = "x"], [
848		ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
849		    [["Dual BSD/GPL"]])], [$1])
850		ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
851
852		AS_IF([ test -n "$5" ], [
853			ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM(
854			    [[$2]], [[$3]], [[$5]])], [$1_license])
855			ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
856		])
857	])
858])
859
860dnl #
861dnl # ZFS_LINUX_TEST_RESULT
862dnl #
863dnl # $1 - name of a test source (ZFS_LINUX_TEST_SRC)
864dnl # $2 - run on success (valid .ko generated)
865dnl # $3 - run on failure (unable to compile)
866dnl #
867AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
868	cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
869	AC_CACHE_VAL([$cachevar], [
870		AS_IF([test -d build/$1], [
871			AS_IF([test -f build/$1/$1.ko], [
872				eval "$cachevar=yes"
873			], [
874				eval "$cachevar=no"
875			])
876		], [
877			AC_MSG_ERROR([
878	*** No matching source for the "$1" test, check that
879	*** both the test source and result macros refer to the same name.
880			])
881		])
882	])
883	eval "cacheval=\$$cachevar"
884	AS_IF([test "x$cacheval" = "xyes"], [$2], [$3])
885])
886
887dnl #
888dnl # ZFS_LINUX_TEST_ERROR
889dnl #
890dnl # Generic error message which can be used when none of the expected
891dnl # kernel interfaces were detected.
892dnl #
893AC_DEFUN([ZFS_LINUX_TEST_ERROR], [
894	AC_MSG_ERROR([
895	*** None of the expected "$1" interfaces were detected.
896	*** This may be because your kernel version is newer than what is
897	*** supported, or you are using a patched custom kernel with
898	*** incompatible modifications.
899	***
900	*** ZFS Version: $ZFS_META_ALIAS
901	*** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
902	])
903])
904
905dnl #
906dnl # ZFS_LINUX_TEST_RESULT_SYMBOL
907dnl #
908dnl # Like ZFS_LINUX_TEST_RESULT except ZFS_CHECK_SYMBOL_EXPORT is called to
909dnl # verify symbol exports, unless --enable-linux-builtin was provided to
910dnl # configure.
911dnl #
912AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
913	cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
914	AC_CACHE_VAL([$cachevar], [
915		AS_IF([ ! test -f build/$1/$1.ko], [
916			eval "$cachevar=no"
917		], [
918			AS_IF([test "x$enable_linux_builtin" != "xyes"], [
919				ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [
920					eval "$cachevar=yes"
921				], [
922					eval "$cachevar=no"
923				])
924			], [
925				eval "$cachevar=yes"
926			])
927		])
928	])
929	eval "cacheval=\$$cachevar"
930	AS_IF([test "x$cacheval" = "xyes"], [$4], [$5])
931])
932
933dnl #
934dnl # ZFS_LINUX_COMPILE_IFELSE
935dnl #
936AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
937	ZFS_LINUX_TEST_REMOVE([conftest])
938
939	m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1], [conftest])])
940	m4_ifvaln([$5], [ZFS_LINUX_CONFTEST_H([$5], [conftest])],
941	    [ZFS_LINUX_CONFTEST_H([], [conftest])])
942
943	ZFS_LINUX_CONFTEST_MAKEFILE([conftest], [no],
944	    [m4_ifvaln([$5], [-I$PWD/build/conftest], [])])
945	ZFS_LINUX_COMPILE([build/conftest], [$2], [$3], [$4], [], [])
946])
947
948dnl #
949dnl # ZFS_LINUX_TRY_COMPILE
950dnl #
951dnl # $1 - global
952dnl # $2 - source
953dnl # $3 - run on success (valid .ko generated)
954dnl # $4 - run on failure (unable to compile)
955dnl #
956dnl # When configuring as builtin (--enable-linux-builtin) for kernels
957dnl # without loadable module support (CONFIG_MODULES=n) only the object
958dnl # file is created.  See ZFS_LINUX_TEST_COMPILE_ALL for details.
959dnl #
960AC_DEFUN([ZFS_LINUX_TRY_COMPILE], [
961	AS_IF([test "x$enable_linux_builtin" = "xyes"], [
962		ZFS_LINUX_COMPILE_IFELSE(
963		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
964		    [[ZFS_META_LICENSE]])],
965		    [test -f build/conftest/conftest.o], [$3], [$4])
966	], [
967		ZFS_LINUX_COMPILE_IFELSE(
968		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
969		    [[ZFS_META_LICENSE]])],
970		    [test -f build/conftest/conftest.ko], [$3], [$4])
971	])
972])
973
974dnl #
975dnl # ZFS_CHECK_SYMBOL_EXPORT
976dnl #
977dnl # Check if a symbol is exported on not by consulting the symbols
978dnl # file, or optionally the source code.
979dnl #
980AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
981	grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
982		$LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
983	rc=$?
984	if test $rc -ne 0; then
985		export=0
986		for file in $2; do
987			grep -q -E "EXPORT_SYMBOL.*($1)" \
988				"$LINUX/$file" 2>/dev/null
989			rc=$?
990			if test $rc -eq 0; then
991				export=1
992				break;
993			fi
994		done
995		if test $export -eq 0; then :
996			$4
997		else :
998			$3
999		fi
1000	else :
1001		$3
1002	fi
1003])
1004
1005dnl #
1006dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
1007dnl #
1008dnl # Like ZFS_LINUX_TRY_COMPILER except ZFS_CHECK_SYMBOL_EXPORT is called
1009dnl # to verify symbol exports, unless --enable-linux-builtin was provided
1010dnl # to configure.
1011dnl #
1012AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
1013	ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
1014	if test $rc -ne 0; then :
1015		$6
1016	else
1017		if test "x$enable_linux_builtin" != xyes; then
1018			ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
1019		fi
1020		if test $rc -ne 0; then :
1021			$6
1022		else :
1023			$5
1024		fi
1025	fi
1026])
1027
1028dnl #
1029dnl # ZFS_LINUX_TRY_COMPILE_HEADER
1030dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
1031dnl # provided via the fifth parameter
1032dnl #
1033AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER], [
1034	AS_IF([test "x$enable_linux_builtin" = "xyes"], [
1035		ZFS_LINUX_COMPILE_IFELSE(
1036		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
1037		    [[ZFS_META_LICENSE]])],
1038		    [test -f build/conftest/conftest.o], [$3], [$4], [$5])
1039	], [
1040		ZFS_LINUX_COMPILE_IFELSE(
1041		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
1042		    [[ZFS_META_LICENSE]])],
1043		    [test -f build/conftest/conftest.ko], [$3], [$4], [$5])
1044	])
1045])
1046
1047dnl #
1048dnl # AS_VERSION_COMPARE_LE
1049dnl # like AS_VERSION_COMPARE_LE, but runs $3 if (and only if) $1 <= $2
1050dnl # AS_VERSION_COMPARE_LE (version-1, version-2, [action-if-less-or-equal], [action-if-greater])
1051dnl #
1052AC_DEFUN([AS_VERSION_COMPARE_LE], [
1053	AS_VERSION_COMPARE([$1], [$2], [$3], [$3], [$4])
1054])
1055
1056dnl #
1057dnl # ZFS_LINUX_REQUIRE_API
1058dnl # like ZFS_LINUX_TEST_ERROR, except only fails if the kernel is
1059dnl # at least some specified version.
1060dnl #
1061AC_DEFUN([ZFS_LINUX_REQUIRE_API], [
1062	AS_VERSION_COMPARE_LE([$2], [$kernsrcver], [
1063		AC_MSG_ERROR([
1064		*** None of the expected "$1" interfaces were detected. This
1065		*** interface is expected for kernels version "$2" and above.
1066		*** This may be because your kernel version is newer than what is
1067		*** supported, or you are using a patched custom kernel with
1068		*** incompatible modifications.  Newer kernels may have incompatible
1069		*** APIs.
1070		***
1071		*** ZFS Version: $ZFS_META_ALIAS
1072		*** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
1073		])
1074	], [
1075		AC_MSG_RESULT(no)
1076	])
1077])
1078