xref: /freebsd/sys/contrib/openzfs/config/kernel.m4 (revision dd41de95a84d979615a2ef11df6850622bf6184e)
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_TEST_MODULE
12		ZFS_AC_KERNEL_CONFIG_DEFINED
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_OBJTOOL
41	ZFS_AC_KERNEL_SRC_GLOBAL_PAGE_STATE
42	ZFS_AC_KERNEL_SRC_ACCESS_OK_TYPE
43	ZFS_AC_KERNEL_SRC_PDE_DATA
44	ZFS_AC_KERNEL_SRC_FALLOCATE
45	ZFS_AC_KERNEL_SRC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
46	ZFS_AC_KERNEL_SRC_RWSEM
47	ZFS_AC_KERNEL_SRC_SCHED
48	ZFS_AC_KERNEL_SRC_USLEEP_RANGE
49	ZFS_AC_KERNEL_SRC_KMEM_CACHE
50	ZFS_AC_KERNEL_SRC_KVMALLOC
51	ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
52	ZFS_AC_KERNEL_SRC_WAIT
53	ZFS_AC_KERNEL_SRC_INODE_TIMES
54	ZFS_AC_KERNEL_SRC_INODE_LOCK
55	ZFS_AC_KERNEL_SRC_GROUP_INFO_GID
56	ZFS_AC_KERNEL_SRC_RW
57	ZFS_AC_KERNEL_SRC_TIMER_SETUP
58	ZFS_AC_KERNEL_SRC_SUPER_USER_NS
59	ZFS_AC_KERNEL_SRC_PROC_OPERATIONS
60	ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS
61	ZFS_AC_KERNEL_SRC_BIO
62	ZFS_AC_KERNEL_SRC_BLKDEV
63	ZFS_AC_KERNEL_SRC_BLK_QUEUE
64	ZFS_AC_KERNEL_SRC_REVALIDATE_DISK
65	ZFS_AC_KERNEL_SRC_GET_DISK_RO
66	ZFS_AC_KERNEL_SRC_GENERIC_READLINK_GLOBAL
67	ZFS_AC_KERNEL_SRC_DISCARD_GRANULARITY
68	ZFS_AC_KERNEL_SRC_INODE_OWNER_OR_CAPABLE
69	ZFS_AC_KERNEL_SRC_XATTR
70	ZFS_AC_KERNEL_SRC_ACL
71	ZFS_AC_KERNEL_SRC_INODE_GETATTR
72	ZFS_AC_KERNEL_SRC_INODE_SET_FLAGS
73	ZFS_AC_KERNEL_SRC_INODE_SET_IVERSION
74	ZFS_AC_KERNEL_SRC_SHOW_OPTIONS
75	ZFS_AC_KERNEL_SRC_FILE_INODE
76	ZFS_AC_KERNEL_SRC_FILE_DENTRY
77	ZFS_AC_KERNEL_SRC_FSYNC
78	ZFS_AC_KERNEL_SRC_AIO_FSYNC
79	ZFS_AC_KERNEL_SRC_EVICT_INODE
80	ZFS_AC_KERNEL_SRC_DIRTY_INODE
81	ZFS_AC_KERNEL_SRC_SHRINKER
82	ZFS_AC_KERNEL_SRC_MKDIR
83	ZFS_AC_KERNEL_SRC_LOOKUP_FLAGS
84	ZFS_AC_KERNEL_SRC_CREATE
85	ZFS_AC_KERNEL_SRC_GET_LINK
86	ZFS_AC_KERNEL_SRC_PUT_LINK
87	ZFS_AC_KERNEL_SRC_TMPFILE
88	ZFS_AC_KERNEL_SRC_AUTOMOUNT
89	ZFS_AC_KERNEL_SRC_ENCODE_FH_WITH_INODE
90	ZFS_AC_KERNEL_SRC_COMMIT_METADATA
91	ZFS_AC_KERNEL_SRC_CLEAR_INODE
92	ZFS_AC_KERNEL_SRC_SETATTR_PREPARE
93	ZFS_AC_KERNEL_SRC_INSERT_INODE_LOCKED
94	ZFS_AC_KERNEL_SRC_DENTRY
95	ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE
96	ZFS_AC_KERNEL_SRC_SECURITY_INODE
97	ZFS_AC_KERNEL_SRC_FST_MOUNT
98	ZFS_AC_KERNEL_SRC_BDI
99	ZFS_AC_KERNEL_SRC_SET_NLINK
100	ZFS_AC_KERNEL_SRC_SGET
101	ZFS_AC_KERNEL_SRC_LSEEK_EXECUTE
102	ZFS_AC_KERNEL_SRC_VFS_GETATTR
103	ZFS_AC_KERNEL_SRC_VFS_FSYNC_2ARGS
104	ZFS_AC_KERNEL_SRC_VFS_ITERATE
105	ZFS_AC_KERNEL_SRC_VFS_DIRECT_IO
106	ZFS_AC_KERNEL_SRC_VFS_RW_ITERATE
107	ZFS_AC_KERNEL_SRC_VFS_GENERIC_WRITE_CHECKS
108	ZFS_AC_KERNEL_SRC_VFS_IOV_ITER
109	ZFS_AC_KERNEL_SRC_KMAP_ATOMIC_ARGS
110	ZFS_AC_KERNEL_SRC_FOLLOW_DOWN_ONE
111	ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN
112	ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT
113	ZFS_AC_KERNEL_SRC_FPU
114	ZFS_AC_KERNEL_SRC_FMODE_T
115	ZFS_AC_KERNEL_SRC_KUIDGID_T
116	ZFS_AC_KERNEL_SRC_KUID_HELPERS
117	ZFS_AC_KERNEL_SRC_MODULE_PARAM_CALL_CONST
118	ZFS_AC_KERNEL_SRC_RENAME
119	ZFS_AC_KERNEL_SRC_CURRENT_TIME
120	ZFS_AC_KERNEL_SRC_USERNS_CAPABILITIES
121	ZFS_AC_KERNEL_SRC_IN_COMPAT_SYSCALL
122	ZFS_AC_KERNEL_SRC_KTIME
123	ZFS_AC_KERNEL_SRC_TOTALRAM_PAGES_FUNC
124	ZFS_AC_KERNEL_SRC_TOTALHIGH_PAGES
125	ZFS_AC_KERNEL_SRC_KSTRTOUL
126	ZFS_AC_KERNEL_SRC_PERCPU
127	ZFS_AC_KERNEL_SRC_CPU_HOTPLUG
128	ZFS_AC_KERNEL_SRC_GENERIC_FILLATTR_USERNS
129	ZFS_AC_KERNEL_SRC_MKNOD
130	ZFS_AC_KERNEL_SRC_SYMLINK
131	ZFS_AC_KERNEL_SRC_BIO_MAX_SEGS
132
133	AC_MSG_CHECKING([for available kernel interfaces])
134	ZFS_LINUX_TEST_COMPILE_ALL([kabi])
135	AC_MSG_RESULT([done])
136])
137
138dnl #
139dnl # Check results of kernel interface tests.
140dnl #
141AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
142	ZFS_AC_KERNEL_ACCESS_OK_TYPE
143	ZFS_AC_KERNEL_GLOBAL_PAGE_STATE
144	ZFS_AC_KERNEL_OBJTOOL
145	ZFS_AC_KERNEL_PDE_DATA
146	ZFS_AC_KERNEL_FALLOCATE
147	ZFS_AC_KERNEL_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
148	ZFS_AC_KERNEL_RWSEM
149	ZFS_AC_KERNEL_SCHED
150	ZFS_AC_KERNEL_USLEEP_RANGE
151	ZFS_AC_KERNEL_KMEM_CACHE
152	ZFS_AC_KERNEL_KVMALLOC
153	ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
154	ZFS_AC_KERNEL_WAIT
155	ZFS_AC_KERNEL_INODE_TIMES
156	ZFS_AC_KERNEL_INODE_LOCK
157	ZFS_AC_KERNEL_GROUP_INFO_GID
158	ZFS_AC_KERNEL_RW
159	ZFS_AC_KERNEL_TIMER_SETUP
160	ZFS_AC_KERNEL_SUPER_USER_NS
161	ZFS_AC_KERNEL_PROC_OPERATIONS
162	ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS
163	ZFS_AC_KERNEL_BIO
164	ZFS_AC_KERNEL_BLKDEV
165	ZFS_AC_KERNEL_BLK_QUEUE
166	ZFS_AC_KERNEL_REVALIDATE_DISK
167	ZFS_AC_KERNEL_GET_DISK_RO
168	ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL
169	ZFS_AC_KERNEL_DISCARD_GRANULARITY
170	ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
171	ZFS_AC_KERNEL_XATTR
172	ZFS_AC_KERNEL_ACL
173	ZFS_AC_KERNEL_INODE_GETATTR
174	ZFS_AC_KERNEL_INODE_SET_FLAGS
175	ZFS_AC_KERNEL_INODE_SET_IVERSION
176	ZFS_AC_KERNEL_SHOW_OPTIONS
177	ZFS_AC_KERNEL_FILE_INODE
178	ZFS_AC_KERNEL_FILE_DENTRY
179	ZFS_AC_KERNEL_FSYNC
180	ZFS_AC_KERNEL_AIO_FSYNC
181	ZFS_AC_KERNEL_EVICT_INODE
182	ZFS_AC_KERNEL_DIRTY_INODE
183	ZFS_AC_KERNEL_SHRINKER
184	ZFS_AC_KERNEL_MKDIR
185	ZFS_AC_KERNEL_LOOKUP_FLAGS
186	ZFS_AC_KERNEL_CREATE
187	ZFS_AC_KERNEL_GET_LINK
188	ZFS_AC_KERNEL_PUT_LINK
189	ZFS_AC_KERNEL_TMPFILE
190	ZFS_AC_KERNEL_AUTOMOUNT
191	ZFS_AC_KERNEL_ENCODE_FH_WITH_INODE
192	ZFS_AC_KERNEL_COMMIT_METADATA
193	ZFS_AC_KERNEL_CLEAR_INODE
194	ZFS_AC_KERNEL_SETATTR_PREPARE
195	ZFS_AC_KERNEL_INSERT_INODE_LOCKED
196	ZFS_AC_KERNEL_DENTRY
197	ZFS_AC_KERNEL_TRUNCATE_SETSIZE
198	ZFS_AC_KERNEL_SECURITY_INODE
199	ZFS_AC_KERNEL_FST_MOUNT
200	ZFS_AC_KERNEL_BDI
201	ZFS_AC_KERNEL_SET_NLINK
202	ZFS_AC_KERNEL_SGET
203	ZFS_AC_KERNEL_LSEEK_EXECUTE
204	ZFS_AC_KERNEL_VFS_GETATTR
205	ZFS_AC_KERNEL_VFS_FSYNC_2ARGS
206	ZFS_AC_KERNEL_VFS_ITERATE
207	ZFS_AC_KERNEL_VFS_DIRECT_IO
208	ZFS_AC_KERNEL_VFS_RW_ITERATE
209	ZFS_AC_KERNEL_VFS_GENERIC_WRITE_CHECKS
210	ZFS_AC_KERNEL_VFS_IOV_ITER
211	ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
212	ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
213	ZFS_AC_KERNEL_MAKE_REQUEST_FN
214	ZFS_AC_KERNEL_GENERIC_IO_ACCT
215	ZFS_AC_KERNEL_FPU
216	ZFS_AC_KERNEL_FMODE_T
217	ZFS_AC_KERNEL_KUIDGID_T
218	ZFS_AC_KERNEL_KUID_HELPERS
219	ZFS_AC_KERNEL_MODULE_PARAM_CALL_CONST
220	ZFS_AC_KERNEL_RENAME
221	ZFS_AC_KERNEL_CURRENT_TIME
222	ZFS_AC_KERNEL_USERNS_CAPABILITIES
223	ZFS_AC_KERNEL_IN_COMPAT_SYSCALL
224	ZFS_AC_KERNEL_KTIME
225	ZFS_AC_KERNEL_TOTALRAM_PAGES_FUNC
226	ZFS_AC_KERNEL_TOTALHIGH_PAGES
227	ZFS_AC_KERNEL_KSTRTOUL
228	ZFS_AC_KERNEL_PERCPU
229	ZFS_AC_KERNEL_CPU_HOTPLUG
230	ZFS_AC_KERNEL_GENERIC_FILLATTR_USERNS
231	ZFS_AC_KERNEL_MKNOD
232	ZFS_AC_KERNEL_SYMLINK
233	ZFS_AC_KERNEL_BIO_MAX_SEGS
234])
235
236dnl #
237dnl # Detect name used for Module.symvers file in kernel
238dnl #
239AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
240	modpost=$LINUX/scripts/Makefile.modpost
241	AC_MSG_CHECKING([kernel file name for module symbols])
242	AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
243		AS_IF([grep -q Modules.symvers $modpost], [
244			LINUX_SYMBOLS=Modules.symvers
245		], [
246			LINUX_SYMBOLS=Module.symvers
247		])
248
249		AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
250			AC_MSG_ERROR([
251	*** Please make sure the kernel devel package for your distribution
252	*** is installed.  If you are building with a custom kernel, make sure
253	*** the kernel is configured, built, and the '--with-linux=PATH'
254	*** configure option refers to the location of the kernel source.
255			])
256		])
257	], [
258		LINUX_SYMBOLS=NONE
259	])
260	AC_MSG_RESULT($LINUX_SYMBOLS)
261	AC_SUBST(LINUX_SYMBOLS)
262])
263
264dnl #
265dnl # Detect the kernel to be built against
266dnl #
267AC_DEFUN([ZFS_AC_KERNEL], [
268	AC_ARG_WITH([linux],
269		AS_HELP_STRING([--with-linux=PATH],
270		[Path to kernel source]),
271		[kernelsrc="$withval"])
272
273	AC_ARG_WITH(linux-obj,
274		AS_HELP_STRING([--with-linux-obj=PATH],
275		[Path to kernel build objects]),
276		[kernelbuild="$withval"])
277
278	AC_MSG_CHECKING([kernel source directory])
279	AS_IF([test -z "$kernelsrc"], [
280		AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
281			headersdir="/lib/modules/$(uname -r)/source"
282			sourcelink=$(readlink -f "$headersdir")
283		], [test -e "/lib/modules/$(uname -r)/build"], [
284			headersdir="/lib/modules/$(uname -r)/build"
285			sourcelink=$(readlink -f "$headersdir")
286		], [
287			sourcelink=$(ls -1d /usr/src/kernels/* \
288			             /usr/src/linux-* \
289			             2>/dev/null | grep -v obj | tail -1)
290		])
291
292		AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
293			kernelsrc=`readlink -f ${sourcelink}`
294		], [
295			kernelsrc="[Not found]"
296		])
297	], [
298		AS_IF([test "$kernelsrc" = "NONE"], [
299			kernsrcver=NONE
300		])
301		withlinux=yes
302	])
303
304	AC_MSG_RESULT([$kernelsrc])
305	AS_IF([test ! -d "$kernelsrc"], [
306		AC_MSG_ERROR([
307	*** Please make sure the kernel devel package for your distribution
308	*** is installed and then try again.  If that fails, you can specify the
309	*** location of the kernel source with the '--with-linux=PATH' option.])
310	])
311
312	AC_MSG_CHECKING([kernel build directory])
313	AS_IF([test -z "$kernelbuild"], [
314		AS_IF([test x$withlinux != xyes -a -e "/lib/modules/$(uname -r)/build"], [
315			kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
316		], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
317			kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
318		], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
319			kernelbuild=${kernelsrc}-obj/${target_cpu}/default
320		], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
321			kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
322		], [
323			kernelbuild=${kernelsrc}
324		])
325	])
326	AC_MSG_RESULT([$kernelbuild])
327
328	AC_MSG_CHECKING([kernel source version])
329	utsrelease1=$kernelbuild/include/linux/version.h
330	utsrelease2=$kernelbuild/include/linux/utsrelease.h
331	utsrelease3=$kernelbuild/include/generated/utsrelease.h
332	AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
333		utsrelease=$utsrelease1
334	], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
335		utsrelease=$utsrelease2
336	], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
337		utsrelease=$utsrelease3
338	])
339
340	AS_IF([test -n "$utsrelease"], [
341		kernsrcver=$($AWK '/UTS_RELEASE/ { gsub(/"/, "", $[3]); print $[3] }' $utsrelease)
342		AS_IF([test -z "$kernsrcver"], [
343			AC_MSG_RESULT([Not found])
344			AC_MSG_ERROR([
345	*** Cannot determine kernel version.
346			])
347		])
348	], [
349		AC_MSG_RESULT([Not found])
350		if test "x$enable_linux_builtin" != xyes; then
351			AC_MSG_ERROR([
352	*** Cannot find UTS_RELEASE definition.
353			])
354		else
355			AC_MSG_ERROR([
356	*** Cannot find UTS_RELEASE definition.
357	*** Please run 'make prepare' inside the kernel source tree.])
358		fi
359	])
360
361	AC_MSG_RESULT([$kernsrcver])
362
363	AS_VERSION_COMPARE([$kernsrcver], [$ZFS_META_KVER_MIN], [
364		 AC_MSG_ERROR([
365	*** Cannot build against kernel version $kernsrcver.
366	*** The minimum supported kernel version is $ZFS_META_KVER_MIN.
367		])
368	])
369
370	LINUX=${kernelsrc}
371	LINUX_OBJ=${kernelbuild}
372	LINUX_VERSION=${kernsrcver}
373
374	AC_SUBST(LINUX)
375	AC_SUBST(LINUX_OBJ)
376	AC_SUBST(LINUX_VERSION)
377
378	ZFS_AC_MODULE_SYMVERS
379])
380
381dnl #
382dnl # Detect the QAT module to be built against, QAT provides hardware
383dnl # acceleration for data compression:
384dnl #
385dnl # https://01.org/intel-quickassist-technology
386dnl #
387dnl # 1) Download and install QAT driver from the above link
388dnl # 2) Start QAT driver in your system:
389dnl # 	 service qat_service start
390dnl # 3) Enable QAT in ZFS, e.g.:
391dnl # 	 ./configure --with-qat=<qat-driver-path>/QAT1.6
392dnl # 	 make
393dnl # 4) Set GZIP compression in ZFS dataset:
394dnl # 	 zfs set compression = gzip <dataset>
395dnl #
396dnl # Then the data written to this ZFS pool is compressed by QAT accelerator
397dnl # automatically, and de-compressed by QAT when read from the pool.
398dnl #
399dnl # 1) Get QAT hardware statistics with:
400dnl #	 cat /proc/icp_dh895xcc_dev/qat
401dnl # 2) To disable QAT:
402dnl # 	 insmod zfs.ko zfs_qat_disable=1
403dnl #
404AC_DEFUN([ZFS_AC_QAT], [
405	AC_ARG_WITH([qat],
406		AS_HELP_STRING([--with-qat=PATH],
407		[Path to qat source]),
408		AS_IF([test "$withval" = "yes"],
409			AC_MSG_ERROR([--with-qat=PATH requires a PATH]),
410			[qatsrc="$withval"]))
411
412	AC_ARG_WITH([qat-obj],
413		AS_HELP_STRING([--with-qat-obj=PATH],
414		[Path to qat build objects]),
415		[qatbuild="$withval"])
416
417	AS_IF([test ! -z "${qatsrc}"], [
418		AC_MSG_CHECKING([qat source directory])
419		AC_MSG_RESULT([$qatsrc])
420		QAT_SRC="${qatsrc}/quickassist"
421		AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [
422			AC_MSG_ERROR([
423	*** Please make sure the qat driver package is installed
424	*** and specify the location of the qat source with the
425	*** '--with-qat=PATH' option then try again. Failed to
426	*** find cpa.h in:
427	${QAT_SRC}/include])
428		])
429	])
430
431	AS_IF([test ! -z "${qatsrc}"], [
432		AC_MSG_CHECKING([qat build directory])
433		AS_IF([test -z "$qatbuild"], [
434			qatbuild="${qatsrc}/build"
435		])
436
437		AC_MSG_RESULT([$qatbuild])
438		QAT_OBJ=${qatbuild}
439		AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko" && ! test -e "$QAT_OBJ/qat_api.ko"], [
440			AC_MSG_ERROR([
441	*** Please make sure the qat driver is installed then try again.
442	*** Failed to find icp_qa_al.ko or qat_api.ko in:
443	$QAT_OBJ])
444		])
445
446		AC_SUBST(QAT_SRC)
447		AC_SUBST(QAT_OBJ)
448
449		AC_DEFINE(HAVE_QAT, 1,
450		[qat is enabled and existed])
451	])
452
453	dnl #
454	dnl # Detect the name used for the QAT Module.symvers file.
455	dnl #
456	AS_IF([test ! -z "${qatsrc}"], [
457		AC_MSG_CHECKING([qat file for module symbols])
458		QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers
459
460		AS_IF([test -r $QAT_SYMBOLS], [
461			AC_MSG_RESULT([$QAT_SYMBOLS])
462			AC_SUBST(QAT_SYMBOLS)
463		],[
464			AC_MSG_ERROR([
465	*** Please make sure the qat driver is installed then try again.
466	*** Failed to find Module.symvers in:
467	$QAT_SYMBOLS
468			])
469		])
470	])
471])
472
473dnl #
474dnl # Basic toolchain sanity check.
475dnl #
476AC_DEFUN([ZFS_AC_KERNEL_TEST_MODULE], [
477	AC_MSG_CHECKING([whether modules can be built])
478	ZFS_LINUX_TRY_COMPILE([], [], [
479		AC_MSG_RESULT([yes])
480	],[
481		AC_MSG_RESULT([no])
482		if test "x$enable_linux_builtin" != xyes; then
483			AC_MSG_ERROR([
484	*** Unable to build an empty module.
485			])
486		else
487			AC_MSG_ERROR([
488	*** Unable to build an empty module.
489	*** Please run 'make scripts' inside the kernel source tree.])
490		fi
491	])
492])
493
494dnl #
495dnl # ZFS_LINUX_CONFTEST_H
496dnl #
497AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
498test -d build/$2 || mkdir -p build/$2
499cat - <<_ACEOF >build/$2/$2.h
500$1
501_ACEOF
502])
503
504dnl #
505dnl # ZFS_LINUX_CONFTEST_C
506dnl #
507AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
508test -d build/$2 || mkdir -p build/$2
509cat confdefs.h - <<_ACEOF >build/$2/$2.c
510$1
511_ACEOF
512])
513
514dnl #
515dnl # ZFS_LINUX_CONFTEST_MAKEFILE
516dnl #
517dnl # $1 - test case name
518dnl # $2 - add to top-level Makefile
519dnl # $3 - additional build flags
520dnl #
521AC_DEFUN([ZFS_LINUX_CONFTEST_MAKEFILE], [
522	test -d build || mkdir -p build
523	test -d build/$1 || mkdir -p build/$1
524
525	file=build/$1/Makefile
526
527	dnl # Example command line to manually build source.
528	cat - <<_ACEOF >$file
529# Example command line to manually build source
530# make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1
531
532ccflags-y := -Werror $FRAME_LARGER_THAN
533_ACEOF
534
535	dnl # Additional custom CFLAGS as requested.
536	m4_ifval($3, [echo "ccflags-y += $3" >>$file], [])
537
538	dnl # Test case source
539	echo "obj-m := $1.o" >>$file
540
541	AS_IF([test "x$2" = "xyes"], [echo "obj-m += $1/" >>build/Makefile], [])
542])
543
544dnl #
545dnl # ZFS_LINUX_TEST_PROGRAM(C)([PROLOGUE], [BODY])
546dnl #
547m4_define([ZFS_LINUX_TEST_PROGRAM], [
548#include <linux/module.h>
549$1
550
551int
552main (void)
553{
554$2
555	;
556	return 0;
557}
558
559MODULE_DESCRIPTION("conftest");
560MODULE_AUTHOR(ZFS_META_AUTHOR);
561MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
562MODULE_LICENSE($3);
563])
564
565dnl #
566dnl # ZFS_LINUX_TEST_REMOVE
567dnl #
568dnl # Removes the specified test source and results.
569dnl #
570AC_DEFUN([ZFS_LINUX_TEST_REMOVE], [
571	test -d build/$1 && rm -Rf build/$1
572	test -f build/Makefile && sed '/$1/d' build/Makefile
573])
574
575dnl #
576dnl # ZFS_LINUX_COMPILE
577dnl #
578dnl # $1 - build dir
579dnl # $2 - test command
580dnl # $3 - pass command
581dnl # $4 - fail command
582dnl # $5 - set KBUILD_MODPOST_NOFINAL='yes'
583dnl # $6 - set KBUILD_MODPOST_WARN='yes'
584dnl #
585dnl # Used internally by ZFS_LINUX_TEST_{COMPILE,MODPOST}
586dnl #
587AC_DEFUN([ZFS_LINUX_COMPILE], [
588	AC_TRY_COMMAND([
589	    KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6"
590	    make modules -k -j$TEST_JOBS -C $LINUX_OBJ $ARCH_UM
591	    M=$PWD/$1 >$1/build.log 2>&1])
592	AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4])
593])
594
595dnl #
596dnl # ZFS_LINUX_TEST_COMPILE
597dnl #
598dnl # Perform a full compile excluding the final modpost phase.
599dnl #
600AC_DEFUN([ZFS_LINUX_TEST_COMPILE], [
601	ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
602		mv $2/Makefile $2/Makefile.compile.$1
603		mv $2/build.log $2/build.log.$1
604	],[
605	        AC_MSG_ERROR([
606        *** Unable to compile test source to determine kernel interfaces.])
607	], [yes], [])
608])
609
610dnl #
611dnl # ZFS_LINUX_TEST_MODPOST
612dnl #
613dnl # Perform a full compile including the modpost phase.  This may
614dnl # be an incremental build if the objects have already been built.
615dnl #
616AC_DEFUN([ZFS_LINUX_TEST_MODPOST], [
617	ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
618		mv $2/Makefile $2/Makefile.modpost.$1
619		cat $2/build.log >>build/build.log.$1
620	],[
621	        AC_MSG_ERROR([
622        *** Unable to modpost test source to determine kernel interfaces.])
623	], [], [yes])
624])
625
626dnl #
627dnl # Perform the compilation of the test cases in two phases.
628dnl #
629dnl # Phase 1) attempt to build the object files for all of the tests
630dnl #          defined by the ZFS_LINUX_TEST_SRC macro.  But do not
631dnl #          perform the final modpost stage.
632dnl #
633dnl # Phase 2) disable all tests which failed the initial compilation,
634dnl #          then invoke the final modpost step for the remaining tests.
635dnl #
636dnl # This allows us efficiently build the test cases in parallel while
637dnl # remaining resilient to build failures which are expected when
638dnl # detecting the available kernel interfaces.
639dnl #
640dnl # The maximum allowed parallelism can be controlled by setting the
641dnl # TEST_JOBS environment variable.  Otherwise, it default to $(nproc).
642dnl #
643AC_DEFUN([ZFS_LINUX_TEST_COMPILE_ALL], [
644	dnl # Phase 1 - Compilation only, final linking is skipped.
645	ZFS_LINUX_TEST_COMPILE([$1], [build])
646
647	dnl #
648	dnl # Phase 2 - When building external modules disable test cases
649	dnl # which failed to compile and invoke modpost to verify the
650	dnl # final linking.
651	dnl #
652	dnl # Test names suffixed with '_license' call modpost independently
653	dnl # to ensure that a single incompatibility does not result in the
654	dnl # modpost phase exiting early.  This check is not performed on
655	dnl # every symbol since the majority are compatible and doing so
656	dnl # would significantly slow down this phase.
657	dnl #
658	dnl # When configuring for builtin (--enable-linux-builtin)
659	dnl # fake the linking step artificially create the expected .ko
660	dnl # files for tests which did compile.  This is required for
661	dnl # kernels which do not have loadable module support or have
662	dnl # not yet been built.
663	dnl #
664	AS_IF([test "x$enable_linux_builtin" = "xno"], [
665		for dir in $(awk '/^obj-m/ { print [$]3 }' \
666		    build/Makefile.compile.$1); do
667			name=${dir%/}
668			AS_IF([test -f build/$name/$name.o], [
669				AS_IF([test "${name##*_}" = "license"], [
670					ZFS_LINUX_TEST_MODPOST([$1],
671					    [build/$name])
672					echo "obj-n += $dir" >>build/Makefile
673				], [
674					echo "obj-m += $dir" >>build/Makefile
675				])
676			], [
677				echo "obj-n += $dir" >>build/Makefile
678			])
679		done
680
681		ZFS_LINUX_TEST_MODPOST([$1], [build])
682	], [
683		for dir in $(awk '/^obj-m/ { print [$]3 }' \
684		    build/Makefile.compile.$1); do
685			name=${dir%/}
686			AS_IF([test -f build/$name/$name.o], [
687				touch build/$name/$name.ko
688			])
689		done
690	])
691])
692
693dnl #
694dnl # ZFS_LINUX_TEST_SRC
695dnl #
696dnl # $1 - name
697dnl # $2 - global
698dnl # $3 - source
699dnl # $4 - extra cflags
700dnl # $5 - check license-compatibility
701dnl #
702dnl # Check if the test source is buildable at all and then if it is
703dnl # license compatible.
704dnl #
705dnl # N.B because all of the test cases are compiled in parallel they
706dnl # must never depend on the results of previous tests.  Each test
707dnl # needs to be entirely independent.
708dnl #
709AC_DEFUN([ZFS_LINUX_TEST_SRC], [
710	ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
711	    [["Dual BSD/GPL"]])], [$1])
712	ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
713
714	AS_IF([ test -n "$5" ], [
715		ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM(
716		    [[$2]], [[$3]], [[$5]])], [$1_license])
717		ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
718	])
719])
720
721dnl #
722dnl # ZFS_LINUX_TEST_RESULT
723dnl #
724dnl # $1 - name of a test source (ZFS_LINUX_TEST_SRC)
725dnl # $2 - run on success (valid .ko generated)
726dnl # $3 - run on failure (unable to compile)
727dnl #
728AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
729	AS_IF([test -d build/$1], [
730		AS_IF([test -f build/$1/$1.ko], [$2], [$3])
731	], [
732		AC_MSG_ERROR([
733	*** No matching source for the "$1" test, check that
734	*** both the test source and result macros refer to the same name.
735		])
736	])
737])
738
739dnl #
740dnl # ZFS_LINUX_TEST_ERROR
741dnl #
742dnl # Generic error message which can be used when none of the expected
743dnl # kernel interfaces were detected.
744dnl #
745AC_DEFUN([ZFS_LINUX_TEST_ERROR], [
746	AC_MSG_ERROR([
747	*** None of the expected "$1" interfaces were detected.
748	*** This may be because your kernel version is newer than what is
749	*** supported, or you are using a patched custom kernel with
750	*** incompatible modifications.
751	***
752	*** ZFS Version: $ZFS_META_ALIAS
753	*** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
754	])
755])
756
757dnl #
758dnl # ZFS_LINUX_TEST_RESULT_SYMBOL
759dnl #
760dnl # Like ZFS_LINUX_TEST_RESULT except ZFS_CHECK_SYMBOL_EXPORT is called to
761dnl # verify symbol exports, unless --enable-linux-builtin was provided to
762dnl # configure.
763dnl #
764AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
765	AS_IF([ ! test -f build/$1/$1.ko], [
766		$5
767	], [
768		AS_IF([test "x$enable_linux_builtin" != "xyes"], [
769			ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5])
770		], [
771			$4
772		])
773	])
774])
775
776dnl #
777dnl # ZFS_LINUX_COMPILE_IFELSE
778dnl #
779AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
780	ZFS_LINUX_TEST_REMOVE([conftest])
781
782	m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1], [conftest])])
783	m4_ifvaln([$5], [ZFS_LINUX_CONFTEST_H([$5], [conftest])],
784	    [ZFS_LINUX_CONFTEST_H([], [conftest])])
785
786	ZFS_LINUX_CONFTEST_MAKEFILE([conftest], [no],
787	    [m4_ifvaln([$5], [-I$PWD/build/conftest], [])])
788	ZFS_LINUX_COMPILE([build/conftest], [$2], [$3], [$4], [], [])
789])
790
791dnl #
792dnl # ZFS_LINUX_TRY_COMPILE
793dnl #
794dnl # $1 - global
795dnl # $2 - source
796dnl # $3 - run on success (valid .ko generated)
797dnl # $4 - run on failure (unable to compile)
798dnl #
799dnl # When configuring as builtin (--enable-linux-builtin) for kernels
800dnl # without loadable module support (CONFIG_MODULES=n) only the object
801dnl # file is created.  See ZFS_LINUX_TEST_COMPILE_ALL for details.
802dnl #
803AC_DEFUN([ZFS_LINUX_TRY_COMPILE], [
804	AS_IF([test "x$enable_linux_builtin" = "xyes"], [
805		ZFS_LINUX_COMPILE_IFELSE(
806		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
807		    [[ZFS_META_LICENSE]])],
808		    [test -f build/conftest/conftest.o], [$3], [$4])
809	], [
810		ZFS_LINUX_COMPILE_IFELSE(
811		    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
812		    [[ZFS_META_LICENSE]])],
813		    [test -f build/conftest/conftest.ko], [$3], [$4])
814	])
815])
816
817dnl #
818dnl # ZFS_CHECK_SYMBOL_EXPORT
819dnl #
820dnl # Check if a symbol is exported on not by consulting the symbols
821dnl # file, or optionally the source code.
822dnl #
823AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
824	grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
825		$LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
826	rc=$?
827	if test $rc -ne 0; then
828		export=0
829		for file in $2; do
830			grep -q -E "EXPORT_SYMBOL.*($1)" \
831				"$LINUX/$file" 2>/dev/null
832			rc=$?
833			if test $rc -eq 0; then
834				export=1
835				break;
836			fi
837		done
838		if test $export -eq 0; then :
839			$4
840		else :
841			$3
842		fi
843	else :
844		$3
845	fi
846])
847
848dnl #
849dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
850dnl #
851dnl # Like ZFS_LINUX_TRY_COMPILER except ZFS_CHECK_SYMBOL_EXPORT is called
852dnl # to verify symbol exports, unless --enable-linux-builtin was provided
853dnl # to configure.
854dnl #
855AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
856	ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
857	if test $rc -ne 0; then :
858		$6
859	else
860		if test "x$enable_linux_builtin" != xyes; then
861			ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
862		fi
863		if test $rc -ne 0; then :
864			$6
865		else :
866			$5
867		fi
868	fi
869])
870
871dnl #
872dnl # ZFS_LINUX_TRY_COMPILE_HEADER
873dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
874dnl # provided via the fifth parameter
875dnl #
876AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER], [
877	ZFS_LINUX_COMPILE_IFELSE(
878	    [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]], [[ZFS_META_LICENSE]])],
879	    [test -f build/conftest/conftest.ko],
880	    [$3], [$4], [$5])
881])
882