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