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