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