xref: /freebsd/sys/contrib/openzfs/config/kernel.m4 (revision 357378bbdedf24ce2b90e9bd831af4a9db3ec70a)
1dnl #
2dnl # Default ZFS kernel configuration
3dnl #
4AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5	AM_COND_IF([BUILD_LINUX], [
6		dnl # Setup the kernel build environment.
7		ZFS_AC_KERNEL
8		ZFS_AC_QAT
9
10		dnl # Sanity checks for module building and CONFIG_* defines
11		ZFS_AC_KERNEL_CONFIG_DEFINED
12		ZFS_AC_MODULE_SYMVERS
13
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
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_GLOBAL_PAGE_STATE
43	ZFS_AC_KERNEL_SRC_ACCESS_OK_TYPE
44	ZFS_AC_KERNEL_SRC_PDE_DATA
45	ZFS_AC_KERNEL_SRC_FALLOCATE
46	ZFS_AC_KERNEL_SRC_FADVISE
47	ZFS_AC_KERNEL_SRC_GENERIC_FADVISE
48	ZFS_AC_KERNEL_SRC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
49	ZFS_AC_KERNEL_SRC_RWSEM
50	ZFS_AC_KERNEL_SRC_SCHED
51	ZFS_AC_KERNEL_SRC_USLEEP_RANGE
52	ZFS_AC_KERNEL_SRC_KMEM_CACHE
53	ZFS_AC_KERNEL_SRC_KVMALLOC
54	ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
55	ZFS_AC_KERNEL_SRC_WAIT
56	ZFS_AC_KERNEL_SRC_INODE_TIMES
57	ZFS_AC_KERNEL_SRC_INODE_LOCK
58	ZFS_AC_KERNEL_SRC_GROUP_INFO_GID
59	ZFS_AC_KERNEL_SRC_RW
60	ZFS_AC_KERNEL_SRC_TIMER_SETUP
61	ZFS_AC_KERNEL_SRC_SUPER_USER_NS
62	ZFS_AC_KERNEL_SRC_PROC_OPERATIONS
63	ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS
64	ZFS_AC_KERNEL_SRC_BIO
65	ZFS_AC_KERNEL_SRC_BLKDEV
66	ZFS_AC_KERNEL_SRC_BLK_QUEUE
67	ZFS_AC_KERNEL_SRC_GENHD_FLAGS
68	ZFS_AC_KERNEL_SRC_REVALIDATE_DISK
69	ZFS_AC_KERNEL_SRC_GET_DISK_RO
70	ZFS_AC_KERNEL_SRC_GENERIC_READLINK_GLOBAL
71	ZFS_AC_KERNEL_SRC_DISCARD_GRANULARITY
72	ZFS_AC_KERNEL_SRC_INODE_OWNER_OR_CAPABLE
73	ZFS_AC_KERNEL_SRC_XATTR
74	ZFS_AC_KERNEL_SRC_ACL
75	ZFS_AC_KERNEL_SRC_INODE_SETATTR
76	ZFS_AC_KERNEL_SRC_INODE_GETATTR
77	ZFS_AC_KERNEL_SRC_INODE_SET_FLAGS
78	ZFS_AC_KERNEL_SRC_INODE_SET_IVERSION
79	ZFS_AC_KERNEL_SRC_SHOW_OPTIONS
80	ZFS_AC_KERNEL_SRC_FILE_INODE
81	ZFS_AC_KERNEL_SRC_FILE_DENTRY
82	ZFS_AC_KERNEL_SRC_FSYNC
83	ZFS_AC_KERNEL_SRC_AIO_FSYNC
84	ZFS_AC_KERNEL_SRC_EVICT_INODE
85	ZFS_AC_KERNEL_SRC_DIRTY_INODE
86	ZFS_AC_KERNEL_SRC_SHRINKER
87	ZFS_AC_KERNEL_SRC_MKDIR
88	ZFS_AC_KERNEL_SRC_LOOKUP_FLAGS
89	ZFS_AC_KERNEL_SRC_CREATE
90	ZFS_AC_KERNEL_SRC_PERMISSION
91	ZFS_AC_KERNEL_SRC_GET_LINK
92	ZFS_AC_KERNEL_SRC_PUT_LINK
93	ZFS_AC_KERNEL_SRC_TMPFILE
94	ZFS_AC_KERNEL_SRC_AUTOMOUNT
95	ZFS_AC_KERNEL_SRC_ENCODE_FH_WITH_INODE
96	ZFS_AC_KERNEL_SRC_COMMIT_METADATA
97	ZFS_AC_KERNEL_SRC_CLEAR_INODE
98	ZFS_AC_KERNEL_SRC_SETATTR_PREPARE
99	ZFS_AC_KERNEL_SRC_INSERT_INODE_LOCKED
100	ZFS_AC_KERNEL_SRC_DENTRY
101	ZFS_AC_KERNEL_SRC_DENTRY_ALIAS_D_U
102	ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE
103	ZFS_AC_KERNEL_SRC_SECURITY_INODE
104	ZFS_AC_KERNEL_SRC_FST_MOUNT
105	ZFS_AC_KERNEL_SRC_BDI
106	ZFS_AC_KERNEL_SRC_SET_NLINK
107	ZFS_AC_KERNEL_SRC_SGET
108	ZFS_AC_KERNEL_SRC_LSEEK_EXECUTE
109	ZFS_AC_KERNEL_SRC_VFS_FILEMAP_DIRTY_FOLIO
110	ZFS_AC_KERNEL_SRC_VFS_READ_FOLIO
111	ZFS_AC_KERNEL_SRC_VFS_GETATTR
112	ZFS_AC_KERNEL_SRC_VFS_FSYNC_2ARGS
113	ZFS_AC_KERNEL_SRC_VFS_ITERATE
114	ZFS_AC_KERNEL_SRC_VFS_DIRECT_IO
115	ZFS_AC_KERNEL_SRC_VFS_READPAGES
116	ZFS_AC_KERNEL_SRC_VFS_SET_PAGE_DIRTY_NOBUFFERS
117	ZFS_AC_KERNEL_SRC_VFS_RW_ITERATE
118	ZFS_AC_KERNEL_SRC_VFS_GENERIC_WRITE_CHECKS
119	ZFS_AC_KERNEL_SRC_VFS_IOV_ITER
120	ZFS_AC_KERNEL_SRC_VFS_COPY_FILE_RANGE
121	ZFS_AC_KERNEL_SRC_VFS_GENERIC_COPY_FILE_RANGE
122	ZFS_AC_KERNEL_SRC_VFS_SPLICE_COPY_FILE_RANGE
123	ZFS_AC_KERNEL_SRC_VFS_REMAP_FILE_RANGE
124	ZFS_AC_KERNEL_SRC_VFS_CLONE_FILE_RANGE
125	ZFS_AC_KERNEL_SRC_VFS_DEDUPE_FILE_RANGE
126	ZFS_AC_KERNEL_SRC_VFS_FILE_OPERATIONS_EXTEND
127	ZFS_AC_KERNEL_SRC_KMAP_ATOMIC_ARGS
128	ZFS_AC_KERNEL_SRC_KMAP_LOCAL_PAGE
129	ZFS_AC_KERNEL_SRC_FOLLOW_DOWN_ONE
130	ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN
131	ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT
132	ZFS_AC_KERNEL_SRC_FPU
133	ZFS_AC_KERNEL_SRC_FMODE_T
134	ZFS_AC_KERNEL_SRC_KUIDGID_T
135	ZFS_AC_KERNEL_SRC_KUID_HELPERS
136	ZFS_AC_KERNEL_SRC_RENAME
137	ZFS_AC_KERNEL_SRC_CURRENT_TIME
138	ZFS_AC_KERNEL_SRC_USERNS_CAPABILITIES
139	ZFS_AC_KERNEL_SRC_IN_COMPAT_SYSCALL
140	ZFS_AC_KERNEL_SRC_KTIME
141	ZFS_AC_KERNEL_SRC_TOTALRAM_PAGES_FUNC
142	ZFS_AC_KERNEL_SRC_TOTALHIGH_PAGES
143	ZFS_AC_KERNEL_SRC_KSTRTOUL
144	ZFS_AC_KERNEL_SRC_PERCPU
145	ZFS_AC_KERNEL_SRC_CPU_HOTPLUG
146	ZFS_AC_KERNEL_SRC_GENERIC_FILLATTR
147	ZFS_AC_KERNEL_SRC_MKNOD
148	ZFS_AC_KERNEL_SRC_SYMLINK
149	ZFS_AC_KERNEL_SRC_BIO_MAX_SEGS
150	ZFS_AC_KERNEL_SRC_SIGNAL_STOP
151	ZFS_AC_KERNEL_SRC_SIGINFO
152	ZFS_AC_KERNEL_SRC_SYSFS
153	ZFS_AC_KERNEL_SRC_SET_SPECIAL_STATE
154	ZFS_AC_KERNEL_SRC_STANDALONE_LINUX_STDARG
155	ZFS_AC_KERNEL_SRC_STRLCPY
156	ZFS_AC_KERNEL_SRC_STRSCPY
157	ZFS_AC_KERNEL_SRC_PAGEMAP_FOLIO_WAIT_BIT
158	ZFS_AC_KERNEL_SRC_ADD_DISK
159	ZFS_AC_KERNEL_SRC_KTHREAD
160	ZFS_AC_KERNEL_SRC_ZERO_PAGE
161	ZFS_AC_KERNEL_SRC___COPY_FROM_USER_INATOMIC
162	ZFS_AC_KERNEL_SRC_USER_NS_COMMON_INUM
163	ZFS_AC_KERNEL_SRC_IDMAP_MNT_API
164	ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS
165	ZFS_AC_KERNEL_SRC_IATTR_VFSID
166	ZFS_AC_KERNEL_SRC_FILEMAP
167	ZFS_AC_KERNEL_SRC_WRITEPAGE_T
168	ZFS_AC_KERNEL_SRC_RECLAIMED
169	ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_TABLE
170	ZFS_AC_KERNEL_SRC_COPY_SPLICE_READ
171	ZFS_AC_KERNEL_SRC_SYNC_BDEV
172	ZFS_AC_KERNEL_SRC_MM_PAGE_SIZE
173	case "$host_cpu" in
174		powerpc*)
175			ZFS_AC_KERNEL_SRC_CPU_HAS_FEATURE
176			ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
177			;;
178		riscv*)
179			ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
180			;;
181	esac
182
183	AC_MSG_CHECKING([for available kernel interfaces])
184	ZFS_LINUX_TEST_COMPILE_ALL([kabi])
185	AC_MSG_RESULT([done])
186])
187
188dnl #
189dnl # Check results of kernel interface tests.
190dnl #
191AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
192	ZFS_AC_KERNEL_TYPES
193	ZFS_AC_KERNEL_ACCESS_OK_TYPE
194	ZFS_AC_KERNEL_GLOBAL_PAGE_STATE
195	ZFS_AC_KERNEL_OBJTOOL
196	ZFS_AC_KERNEL_PDE_DATA
197	ZFS_AC_KERNEL_FALLOCATE
198	ZFS_AC_KERNEL_FADVISE
199	ZFS_AC_KERNEL_GENERIC_FADVISE
200	ZFS_AC_KERNEL_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
201	ZFS_AC_KERNEL_RWSEM
202	ZFS_AC_KERNEL_SCHED
203	ZFS_AC_KERNEL_USLEEP_RANGE
204	ZFS_AC_KERNEL_KMEM_CACHE
205	ZFS_AC_KERNEL_KVMALLOC
206	ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
207	ZFS_AC_KERNEL_WAIT
208	ZFS_AC_KERNEL_INODE_TIMES
209	ZFS_AC_KERNEL_INODE_LOCK
210	ZFS_AC_KERNEL_GROUP_INFO_GID
211	ZFS_AC_KERNEL_RW
212	ZFS_AC_KERNEL_TIMER_SETUP
213	ZFS_AC_KERNEL_SUPER_USER_NS
214	ZFS_AC_KERNEL_PROC_OPERATIONS
215	ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS
216	ZFS_AC_KERNEL_BIO
217	ZFS_AC_KERNEL_BLKDEV
218	ZFS_AC_KERNEL_BLK_QUEUE
219	ZFS_AC_KERNEL_GENHD_FLAGS
220	ZFS_AC_KERNEL_REVALIDATE_DISK
221	ZFS_AC_KERNEL_GET_DISK_RO
222	ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL
223	ZFS_AC_KERNEL_DISCARD_GRANULARITY
224	ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
225	ZFS_AC_KERNEL_XATTR
226	ZFS_AC_KERNEL_ACL
227	ZFS_AC_KERNEL_INODE_SETATTR
228	ZFS_AC_KERNEL_INODE_GETATTR
229	ZFS_AC_KERNEL_INODE_SET_FLAGS
230	ZFS_AC_KERNEL_INODE_SET_IVERSION
231	ZFS_AC_KERNEL_SHOW_OPTIONS
232	ZFS_AC_KERNEL_FILE_INODE
233	ZFS_AC_KERNEL_FILE_DENTRY
234	ZFS_AC_KERNEL_FSYNC
235	ZFS_AC_KERNEL_AIO_FSYNC
236	ZFS_AC_KERNEL_EVICT_INODE
237	ZFS_AC_KERNEL_DIRTY_INODE
238	ZFS_AC_KERNEL_SHRINKER
239	ZFS_AC_KERNEL_MKDIR
240	ZFS_AC_KERNEL_LOOKUP_FLAGS
241	ZFS_AC_KERNEL_CREATE
242	ZFS_AC_KERNEL_PERMISSION
243	ZFS_AC_KERNEL_GET_LINK
244	ZFS_AC_KERNEL_PUT_LINK
245	ZFS_AC_KERNEL_TMPFILE
246	ZFS_AC_KERNEL_AUTOMOUNT
247	ZFS_AC_KERNEL_ENCODE_FH_WITH_INODE
248	ZFS_AC_KERNEL_COMMIT_METADATA
249	ZFS_AC_KERNEL_CLEAR_INODE
250	ZFS_AC_KERNEL_SETATTR_PREPARE
251	ZFS_AC_KERNEL_INSERT_INODE_LOCKED
252	ZFS_AC_KERNEL_DENTRY
253	ZFS_AC_KERNEL_DENTRY_ALIAS_D_U
254	ZFS_AC_KERNEL_TRUNCATE_SETSIZE
255	ZFS_AC_KERNEL_SECURITY_INODE
256	ZFS_AC_KERNEL_FST_MOUNT
257	ZFS_AC_KERNEL_BDI
258	ZFS_AC_KERNEL_SET_NLINK
259	ZFS_AC_KERNEL_SGET
260	ZFS_AC_KERNEL_LSEEK_EXECUTE
261	ZFS_AC_KERNEL_VFS_FILEMAP_DIRTY_FOLIO
262	ZFS_AC_KERNEL_VFS_READ_FOLIO
263	ZFS_AC_KERNEL_VFS_GETATTR
264	ZFS_AC_KERNEL_VFS_FSYNC_2ARGS
265	ZFS_AC_KERNEL_VFS_ITERATE
266	ZFS_AC_KERNEL_VFS_DIRECT_IO
267	ZFS_AC_KERNEL_VFS_READPAGES
268	ZFS_AC_KERNEL_VFS_SET_PAGE_DIRTY_NOBUFFERS
269	ZFS_AC_KERNEL_VFS_RW_ITERATE
270	ZFS_AC_KERNEL_VFS_GENERIC_WRITE_CHECKS
271	ZFS_AC_KERNEL_VFS_IOV_ITER
272	ZFS_AC_KERNEL_VFS_COPY_FILE_RANGE
273	ZFS_AC_KERNEL_VFS_GENERIC_COPY_FILE_RANGE
274	ZFS_AC_KERNEL_VFS_SPLICE_COPY_FILE_RANGE
275	ZFS_AC_KERNEL_VFS_REMAP_FILE_RANGE
276	ZFS_AC_KERNEL_VFS_CLONE_FILE_RANGE
277	ZFS_AC_KERNEL_VFS_DEDUPE_FILE_RANGE
278	ZFS_AC_KERNEL_VFS_FILE_OPERATIONS_EXTEND
279	ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
280	ZFS_AC_KERNEL_KMAP_LOCAL_PAGE
281	ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
282	ZFS_AC_KERNEL_MAKE_REQUEST_FN
283	ZFS_AC_KERNEL_GENERIC_IO_ACCT
284	ZFS_AC_KERNEL_FPU
285	ZFS_AC_KERNEL_FMODE_T
286	ZFS_AC_KERNEL_KUIDGID_T
287	ZFS_AC_KERNEL_KUID_HELPERS
288	ZFS_AC_KERNEL_RENAME
289	ZFS_AC_KERNEL_CURRENT_TIME
290	ZFS_AC_KERNEL_USERNS_CAPABILITIES
291	ZFS_AC_KERNEL_IN_COMPAT_SYSCALL
292	ZFS_AC_KERNEL_KTIME
293	ZFS_AC_KERNEL_TOTALRAM_PAGES_FUNC
294	ZFS_AC_KERNEL_TOTALHIGH_PAGES
295	ZFS_AC_KERNEL_KSTRTOUL
296	ZFS_AC_KERNEL_PERCPU
297	ZFS_AC_KERNEL_CPU_HOTPLUG
298	ZFS_AC_KERNEL_GENERIC_FILLATTR
299	ZFS_AC_KERNEL_MKNOD
300	ZFS_AC_KERNEL_SYMLINK
301	ZFS_AC_KERNEL_BIO_MAX_SEGS
302	ZFS_AC_KERNEL_SIGNAL_STOP
303	ZFS_AC_KERNEL_SIGINFO
304	ZFS_AC_KERNEL_SYSFS
305	ZFS_AC_KERNEL_SET_SPECIAL_STATE
306	ZFS_AC_KERNEL_STANDALONE_LINUX_STDARG
307	ZFS_AC_KERNEL_STRLCPY
308	ZFS_AC_KERNEL_STRSCPY
309	ZFS_AC_KERNEL_PAGEMAP_FOLIO_WAIT_BIT
310	ZFS_AC_KERNEL_ADD_DISK
311	ZFS_AC_KERNEL_KTHREAD
312	ZFS_AC_KERNEL_ZERO_PAGE
313	ZFS_AC_KERNEL___COPY_FROM_USER_INATOMIC
314	ZFS_AC_KERNEL_USER_NS_COMMON_INUM
315	ZFS_AC_KERNEL_IDMAP_MNT_API
316	ZFS_AC_KERNEL_IDMAP_NO_USERNS
317	ZFS_AC_KERNEL_IATTR_VFSID
318	ZFS_AC_KERNEL_FILEMAP
319	ZFS_AC_KERNEL_WRITEPAGE_T
320	ZFS_AC_KERNEL_RECLAIMED
321	ZFS_AC_KERNEL_REGISTER_SYSCTL_TABLE
322	ZFS_AC_KERNEL_COPY_SPLICE_READ
323	ZFS_AC_KERNEL_SYNC_BDEV
324	ZFS_AC_KERNEL_MM_PAGE_SIZE
325	case "$host_cpu" in
326		powerpc*)
327			ZFS_AC_KERNEL_CPU_HAS_FEATURE
328			ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
329			;;
330		riscv*)
331			ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
332			;;
333	esac
334])
335
336dnl #
337dnl # Detect name used for Module.symvers file in kernel
338dnl #
339AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
340	modpost=$LINUX/scripts/Makefile.modpost
341	AC_MSG_CHECKING([kernel file name for module symbols])
342	AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
343		AS_IF([grep -q Modules.symvers $modpost], [
344			LINUX_SYMBOLS=Modules.symvers
345		], [
346			LINUX_SYMBOLS=Module.symvers
347		])
348
349		AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
350			AC_MSG_ERROR([
351	*** Please make sure the kernel devel package for your distribution
352	*** is installed.  If you are building with a custom kernel, make sure
353	*** the kernel is configured, built, and the '--with-linux=PATH'
354	*** configure option refers to the location of the kernel source.
355			])
356		])
357	], [
358		LINUX_SYMBOLS=NONE
359	])
360	AC_MSG_RESULT($LINUX_SYMBOLS)
361	AC_SUBST(LINUX_SYMBOLS)
362])
363
364dnl #
365dnl # Detect the kernel to be built against
366dnl #
367dnl # Most modern Linux distributions have separate locations for bare
368dnl # source (source) and prebuilt (build) files. Additionally, there are
369dnl # `source` and `build` symlinks in `/lib/modules/$(KERNEL_VERSION)`
370dnl # pointing to them. The directory search order is now:
371dnl #
372dnl # - `configure` command line values if both `--with-linux` and
373dnl #   `--with-linux-obj` were defined
374dnl #
375dnl # - If only `--with-linux` was defined, `--with-linux-obj` is assumed
376dnl #   to have the same value as `--with-linux`
377dnl #
378dnl # - If neither `--with-linux` nor `--with-linux-obj` were defined
379dnl #   autodetection is used:
380dnl #
381dnl #   - `/lib/modules/$(uname -r)/{source,build}` respectively, if exist.
382dnl #
383dnl #   - If only `/lib/modules/$(uname -r)/build` exists, it is assumed
384dnl #     to be both source and build directory.
385dnl #
386dnl #   - The first directory in `/lib/modules` with the highest version
387dnl #     number according to `sort -V` which contains both `source` and
388dnl #     `build` symlinks/directories. If module directory contains only
389dnl #     `build` component, it is assumed to be both source and build
390dnl #     directory.
391dnl #
392dnl #   - Last resort: the first directory matching `/usr/src/kernels/*`
393dnl #     and `/usr/src/linux-*` with the highest version number according
394dnl #     to `sort -V` is assumed to be both source and build directory.
395dnl #
396AC_DEFUN([ZFS_AC_KERNEL], [
397	AC_ARG_WITH([linux],
398		AS_HELP_STRING([--with-linux=PATH],
399		[Path to kernel source]),
400		[kernelsrc="$withval"])
401
402	AC_ARG_WITH(linux-obj,
403		AS_HELP_STRING([--with-linux-obj=PATH],
404		[Path to kernel build objects]),
405		[kernelbuild="$withval"])
406
407	AC_MSG_CHECKING([kernel source and build directories])
408	AS_IF([test -n "$kernelsrc" && test -z "$kernelbuild"], [
409		kernelbuild="$kernelsrc"
410	], [test -z "$kernelsrc"], [
411		AS_IF([test -e "/lib/modules/$(uname -r)/source" && \
412		       test -e "/lib/modules/$(uname -r)/build"], [
413			src="/lib/modules/$(uname -r)/source"
414			build="/lib/modules/$(uname -r)/build"
415		], [test -e "/lib/modules/$(uname -r)/build"], [
416			build="/lib/modules/$(uname -r)/build"
417			src="$build"
418		], [
419			src=
420
421			for d in $(ls -1d /lib/modules/* 2>/dev/null | sort -Vr); do
422				if test -e "$d/source" && test -e "$d/build"; then
423					src="$d/source"
424					build="$d/build"
425					break
426				fi
427
428				if test -e "$d/build"; then
429					src="$d/build"
430					build="$d/build"
431					break
432				fi
433			done
434
435			# the least reliable method
436			if test -z "$src"; then
437				src=$(ls -1d /usr/src/kernels/* /usr/src/linux-* \
438				      2>/dev/null | grep -v obj | sort -Vr | head -1)
439				build="$src"
440			fi
441		])
442
443		AS_IF([test -n "$src" && test -e "$src"], [
444			kernelsrc=$(readlink -e "$src")
445		], [
446			kernelsrc="[Not found]"
447		])
448		AS_IF([test -n "$build" && test -e "$build"], [
449			kernelbuild=$(readlink -e "$build")
450		], [
451			kernelbuild="[Not found]"
452		])
453	], [
454		AS_IF([test "$kernelsrc" = "NONE"], [
455			kernsrcver=NONE
456		])
457		withlinux=yes
458	])
459
460	AC_MSG_RESULT([done])
461	AC_MSG_CHECKING([kernel source directory])
462	AC_MSG_RESULT([$kernelsrc])
463	AC_MSG_CHECKING([kernel build directory])
464	AC_MSG_RESULT([$kernelbuild])
465	AS_IF([test ! -d "$kernelsrc" || test ! -d "$kernelbuild"], [
466		AC_MSG_ERROR([
467	*** Please make sure the kernel devel package for your distribution
468	*** is installed and then try again.  If that fails, you can specify the
469	*** location of the kernel source and build with the '--with-linux=PATH' and
470	*** '--with-linux-obj=PATH' options respectively.])
471	])
472
473	AC_MSG_CHECKING([kernel source version])
474	utsrelease1=$kernelbuild/include/linux/version.h
475	utsrelease2=$kernelbuild/include/linux/utsrelease.h
476	utsrelease3=$kernelbuild/include/generated/utsrelease.h
477	AS_IF([test -r $utsrelease1 && grep -qF UTS_RELEASE $utsrelease1], [
478		utsrelease=$utsrelease1
479	], [test -r $utsrelease2 && grep -qF UTS_RELEASE $utsrelease2], [
480		utsrelease=$utsrelease2
481	], [test -r $utsrelease3 && grep -qF UTS_RELEASE $utsrelease3], [
482		utsrelease=$utsrelease3
483	])
484
485	AS_IF([test -n "$utsrelease"], [
486		kernsrcver=$($AWK '/UTS_RELEASE/ { gsub(/"/, "", $[3]); print $[3] }' $utsrelease)
487		AS_IF([test -z "$kernsrcver"], [
488			AC_MSG_RESULT([Not found])
489			AC_MSG_ERROR([
490	*** Cannot determine kernel version.
491			])
492		])
493	], [
494		AC_MSG_RESULT([Not found])
495		if test "x$enable_linux_builtin" != xyes; then
496			AC_MSG_ERROR([
497	*** Cannot find UTS_RELEASE definition.
498			])
499		else
500			AC_MSG_ERROR([
501	*** Cannot find UTS_RELEASE definition.
502	*** Please run 'make prepare' inside the kernel source tree.])
503		fi
504	])
505
506	AC_MSG_RESULT([$kernsrcver])
507
508	AS_VERSION_COMPARE([$kernsrcver], [$ZFS_META_KVER_MIN], [
509		 AC_MSG_ERROR([
510	*** Cannot build against kernel version $kernsrcver.
511	*** The minimum supported kernel version is $ZFS_META_KVER_MIN.
512		])
513	])
514
515	LINUX=${kernelsrc}
516	LINUX_OBJ=${kernelbuild}
517	LINUX_VERSION=${kernsrcver}
518
519	AC_SUBST(LINUX)
520	AC_SUBST(LINUX_OBJ)
521	AC_SUBST(LINUX_VERSION)
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_TRY_COMMAND([
717	    KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6"
718	    make modules -k -j$TEST_JOBS ${KERNEL_CC:+CC=$KERNEL_CC}
719	    ${KERNEL_LD:+LD=$KERNEL_LD} ${KERNEL_LLVM:+LLVM=$KERNEL_LLVM}
720	    CONFIG_MODULES=y CFLAGS_MODULE=-DCONFIG_MODULES
721	    -C $LINUX_OBJ $ARCH_UM M=$PWD/$1 >$1/build.log 2>&1])
722	AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4])
723])
724
725dnl #
726dnl # ZFS_LINUX_TEST_COMPILE
727dnl #
728dnl # Perform a full compile excluding the final modpost phase.
729dnl #
730AC_DEFUN([ZFS_LINUX_TEST_COMPILE], [
731	ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
732		mv $2/Makefile $2/Makefile.compile.$1
733		mv $2/build.log $2/build.log.$1
734	],[
735	        AC_MSG_ERROR([
736        *** Unable to compile test source to determine kernel interfaces.])
737	], [yes], [])
738])
739
740dnl #
741dnl # ZFS_LINUX_TEST_MODPOST
742dnl #
743dnl # Perform a full compile including the modpost phase.  This may
744dnl # be an incremental build if the objects have already been built.
745dnl #
746AC_DEFUN([ZFS_LINUX_TEST_MODPOST], [
747	ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
748		mv $2/Makefile $2/Makefile.modpost.$1
749		cat $2/build.log >>build/build.log.$1
750	],[
751	        AC_MSG_ERROR([
752        *** Unable to modpost test source to determine kernel interfaces.])
753	], [], [yes])
754])
755
756dnl #
757dnl # Perform the compilation of the test cases in two phases.
758dnl #
759dnl # Phase 1) attempt to build the object files for all of the tests
760dnl #          defined by the ZFS_LINUX_TEST_SRC macro.  But do not
761dnl #          perform the final modpost stage.
762dnl #
763dnl # Phase 2) disable all tests which failed the initial compilation,
764dnl #          then invoke the final modpost step for the remaining tests.
765dnl #
766dnl # This allows us efficiently build the test cases in parallel while
767dnl # remaining resilient to build failures which are expected when
768dnl # detecting the available kernel interfaces.
769dnl #
770dnl # The maximum allowed parallelism can be controlled by setting the
771dnl # TEST_JOBS environment variable.  Otherwise, it default to $(nproc).
772dnl #
773AC_DEFUN([ZFS_LINUX_TEST_COMPILE_ALL], [
774	dnl # Phase 1 - Compilation only, final linking is skipped.
775	ZFS_LINUX_TEST_COMPILE([$1], [build])
776
777	dnl #
778	dnl # Phase 2 - When building external modules disable test cases
779	dnl # which failed to compile and invoke modpost to verify the
780	dnl # final linking.
781	dnl #
782	dnl # Test names suffixed with '_license' call modpost independently
783	dnl # to ensure that a single incompatibility does not result in the
784	dnl # modpost phase exiting early.  This check is not performed on
785	dnl # every symbol since the majority are compatible and doing so
786	dnl # would significantly slow down this phase.
787	dnl #
788	dnl # When configuring for builtin (--enable-linux-builtin)
789	dnl # fake the linking step artificially create the expected .ko
790	dnl # files for tests which did compile.  This is required for
791	dnl # kernels which do not have loadable module support or have
792	dnl # not yet been built.
793	dnl #
794	AS_IF([test "x$enable_linux_builtin" = "xno"], [
795		for dir in $(awk '/^obj-m/ { print [$]3 }' \
796		    build/Makefile.compile.$1); do
797			name=${dir%/}
798			AS_IF([test -f build/$name/$name.o], [
799				AS_IF([test "${name##*_}" = "license"], [
800					ZFS_LINUX_TEST_MODPOST([$1],
801					    [build/$name])
802					echo "obj-n += $dir" >>build/Makefile
803				], [
804					echo "obj-m += $dir" >>build/Makefile
805				])
806			], [
807				echo "obj-n += $dir" >>build/Makefile
808			])
809		done
810
811		ZFS_LINUX_TEST_MODPOST([$1], [build])
812	], [
813		for dir in $(awk '/^obj-m/ { print [$]3 }' \
814		    build/Makefile.compile.$1); do
815			name=${dir%/}
816			AS_IF([test -f build/$name/$name.o], [
817				touch build/$name/$name.ko
818			])
819		done
820	])
821])
822
823dnl #
824dnl # ZFS_LINUX_TEST_SRC
825dnl #
826dnl # $1 - name
827dnl # $2 - global
828dnl # $3 - source
829dnl # $4 - extra cflags
830dnl # $5 - check license-compatibility
831dnl #
832dnl # Check if the test source is buildable at all and then if it is
833dnl # license compatible.
834dnl #
835dnl # N.B because all of the test cases are compiled in parallel they
836dnl # must never depend on the results of previous tests.  Each test
837dnl # needs to be entirely independent.
838dnl #
839AC_DEFUN([ZFS_LINUX_TEST_SRC], [
840	ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
841	    [["Dual BSD/GPL"]])], [$1])
842	ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
843
844	AS_IF([ test -n "$5" ], [
845		ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM(
846		    [[$2]], [[$3]], [[$5]])], [$1_license])
847		ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
848	])
849])
850
851dnl #
852dnl # ZFS_LINUX_TEST_RESULT
853dnl #
854dnl # $1 - name of a test source (ZFS_LINUX_TEST_SRC)
855dnl # $2 - run on success (valid .ko generated)
856dnl # $3 - run on failure (unable to compile)
857dnl #
858AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
859	AS_IF([test -d build/$1], [
860		AS_IF([test -f build/$1/$1.ko], [$2], [$3])
861	], [
862		AC_MSG_ERROR([
863	*** No matching source for the "$1" test, check that
864	*** both the test source and result macros refer to the same name.
865		])
866	])
867])
868
869dnl #
870dnl # ZFS_LINUX_TEST_ERROR
871dnl #
872dnl # Generic error message which can be used when none of the expected
873dnl # kernel interfaces were detected.
874dnl #
875AC_DEFUN([ZFS_LINUX_TEST_ERROR], [
876	AC_MSG_ERROR([
877	*** None of the expected "$1" interfaces were detected.
878	*** This may be because your kernel version is newer than what is
879	*** supported, or you are using a patched custom kernel with
880	*** incompatible modifications.
881	***
882	*** ZFS Version: $ZFS_META_ALIAS
883	*** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
884	])
885])
886
887dnl #
888dnl # ZFS_LINUX_TEST_RESULT_SYMBOL
889dnl #
890dnl # Like ZFS_LINUX_TEST_RESULT except ZFS_CHECK_SYMBOL_EXPORT is called to
891dnl # verify symbol exports, unless --enable-linux-builtin was provided to
892dnl # configure.
893dnl #
894AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
895	AS_IF([ ! test -f build/$1/$1.ko], [
896		$5
897	], [
898		AS_IF([test "x$enable_linux_builtin" != "xyes"], [
899			ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5])
900		], [
901			$4
902		])
903	])
904])
905
906dnl #
907dnl # ZFS_LINUX_COMPILE_IFELSE
908dnl #
909AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
910	ZFS_LINUX_TEST_REMOVE([conftest])
911
912	m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1], [conftest])])
913	m4_ifvaln([$5], [ZFS_LINUX_CONFTEST_H([$5], [conftest])],
914	    [ZFS_LINUX_CONFTEST_H([], [conftest])])
915
916	ZFS_LINUX_CONFTEST_MAKEFILE([conftest], [no],
917	    [m4_ifvaln([$5], [-I$PWD/build/conftest], [])])
918	ZFS_LINUX_COMPILE([build/conftest], [$2], [$3], [$4], [], [])
919])
920
921dnl #
922dnl # ZFS_LINUX_TRY_COMPILE
923dnl #
924dnl # $1 - global
925dnl # $2 - source
926dnl # $3 - run on success (valid .ko generated)
927dnl # $4 - run on failure (unable to compile)
928dnl #
929dnl # When configuring as builtin (--enable-linux-builtin) for kernels
930dnl # without loadable module support (CONFIG_MODULES=n) only the object
931dnl # file is created.  See ZFS_LINUX_TEST_COMPILE_ALL for details.
932dnl #
933AC_DEFUN([ZFS_LINUX_TRY_COMPILE], [
934	AS_IF([test "x$enable_linux_builtin" = "xyes"], [
935		ZFS_LINUX_COMPILE_IFELSE(
936		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
937		    [[ZFS_META_LICENSE]])],
938		    [test -f build/conftest/conftest.o], [$3], [$4])
939	], [
940		ZFS_LINUX_COMPILE_IFELSE(
941		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
942		    [[ZFS_META_LICENSE]])],
943		    [test -f build/conftest/conftest.ko], [$3], [$4])
944	])
945])
946
947dnl #
948dnl # ZFS_CHECK_SYMBOL_EXPORT
949dnl #
950dnl # Check if a symbol is exported on not by consulting the symbols
951dnl # file, or optionally the source code.
952dnl #
953AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
954	grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
955		$LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
956	rc=$?
957	if test $rc -ne 0; then
958		export=0
959		for file in $2; do
960			grep -q -E "EXPORT_SYMBOL.*($1)" \
961				"$LINUX/$file" 2>/dev/null
962			rc=$?
963			if test $rc -eq 0; then
964				export=1
965				break;
966			fi
967		done
968		if test $export -eq 0; then :
969			$4
970		else :
971			$3
972		fi
973	else :
974		$3
975	fi
976])
977
978dnl #
979dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
980dnl #
981dnl # Like ZFS_LINUX_TRY_COMPILER except ZFS_CHECK_SYMBOL_EXPORT is called
982dnl # to verify symbol exports, unless --enable-linux-builtin was provided
983dnl # to configure.
984dnl #
985AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
986	ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
987	if test $rc -ne 0; then :
988		$6
989	else
990		if test "x$enable_linux_builtin" != xyes; then
991			ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
992		fi
993		if test $rc -ne 0; then :
994			$6
995		else :
996			$5
997		fi
998	fi
999])
1000
1001dnl #
1002dnl # ZFS_LINUX_TRY_COMPILE_HEADER
1003dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
1004dnl # provided via the fifth parameter
1005dnl #
1006AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER], [
1007	AS_IF([test "x$enable_linux_builtin" = "xyes"], [
1008		ZFS_LINUX_COMPILE_IFELSE(
1009		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
1010		    [[ZFS_META_LICENSE]])],
1011		    [test -f build/conftest/conftest.o], [$3], [$4], [$5])
1012	], [
1013		ZFS_LINUX_COMPILE_IFELSE(
1014		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
1015		    [[ZFS_META_LICENSE]])],
1016		    [test -f build/conftest/conftest.ko], [$3], [$4], [$5])
1017	])
1018])
1019
1020dnl #
1021dnl # AS_VERSION_COMPARE_LE
1022dnl # like AS_VERSION_COMPARE_LE, but runs $3 if (and only if) $1 <= $2
1023dnl # AS_VERSION_COMPARE_LE (version-1, version-2, [action-if-less-or-equal], [action-if-greater])
1024dnl #
1025AC_DEFUN([AS_VERSION_COMPARE_LE], [
1026	AS_VERSION_COMPARE([$1], [$2], [$3], [$3], [$4])
1027])
1028
1029dnl #
1030dnl # ZFS_LINUX_REQUIRE_API
1031dnl # like ZFS_LINUX_TEST_ERROR, except only fails if the kernel is
1032dnl # at least some specified version.
1033dnl #
1034AC_DEFUN([ZFS_LINUX_REQUIRE_API], [
1035	AS_VERSION_COMPARE_LE([$2], [$kernsrcver], [
1036		AC_MSG_ERROR([
1037		*** None of the expected "$1" interfaces were detected. This
1038		*** interface is expected for kernels version "$2" and above.
1039		*** This may be because your kernel version is newer than what is
1040		*** supported, or you are using a patched custom kernel with
1041		*** incompatible modifications.  Newer kernels may have incompatible
1042		*** APIs.
1043		***
1044		*** ZFS Version: $ZFS_META_ALIAS
1045		*** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
1046		])
1047	], [
1048		AC_MSG_RESULT(no)
1049	])
1050])
1051