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