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