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