]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - config/kernel.m4
Add kernel module auto-loading
[FreeBSD/FreeBSD.git] / config / kernel.m4
1 dnl #
2 dnl # Default ZFS kernel configuration
3 dnl #
4 AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5         ZFS_AC_KERNEL
6         ZFS_AC_SPL
7         ZFS_AC_QAT
8         ZFS_AC_TEST_MODULE
9         ZFS_AC_KERNEL_MISC_MINOR
10         ZFS_AC_KERNEL_OBJTOOL
11         ZFS_AC_KERNEL_CONFIG
12         ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
13         ZFS_AC_KERNEL_CURRENT_BIO_TAIL
14         ZFS_AC_KERNEL_SUPER_USER_NS
15         ZFS_AC_KERNEL_SUBMIT_BIO
16         ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
17         ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
18         ZFS_AC_KERNEL_TYPE_FMODE_T
19         ZFS_AC_KERNEL_3ARG_BLKDEV_GET
20         ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
21         ZFS_AC_KERNEL_OPEN_BDEV_EXCLUSIVE
22         ZFS_AC_KERNEL_LOOKUP_BDEV
23         ZFS_AC_KERNEL_INVALIDATE_BDEV_ARGS
24         ZFS_AC_KERNEL_BDEV_LOGICAL_BLOCK_SIZE
25         ZFS_AC_KERNEL_BDEV_PHYSICAL_BLOCK_SIZE
26         ZFS_AC_KERNEL_BIO_BVEC_ITER
27         ZFS_AC_KERNEL_BIO_FAILFAST_DTD
28         ZFS_AC_KERNEL_BIO_SET_DEV
29         ZFS_AC_KERNEL_REQ_FAILFAST_MASK
30         ZFS_AC_KERNEL_REQ_OP_DISCARD
31         ZFS_AC_KERNEL_REQ_OP_SECURE_ERASE
32         ZFS_AC_KERNEL_REQ_OP_FLUSH
33         ZFS_AC_KERNEL_BIO_BI_OPF
34         ZFS_AC_KERNEL_BIO_END_IO_T_ARGS
35         ZFS_AC_KERNEL_BIO_BI_STATUS
36         ZFS_AC_KERNEL_BIO_RW_BARRIER
37         ZFS_AC_KERNEL_BIO_RW_DISCARD
38         ZFS_AC_KERNEL_BLK_QUEUE_BDI
39         ZFS_AC_KERNEL_BLK_QUEUE_FLUSH
40         ZFS_AC_KERNEL_BLK_QUEUE_MAX_HW_SECTORS
41         ZFS_AC_KERNEL_BLK_QUEUE_MAX_SEGMENTS
42         ZFS_AC_KERNEL_BLK_QUEUE_HAVE_BIO_RW_UNPLUG
43         ZFS_AC_KERNEL_BLK_QUEUE_HAVE_BLK_PLUG
44         ZFS_AC_KERNEL_GET_DISK_AND_MODULE
45         ZFS_AC_KERNEL_GET_DISK_RO
46         ZFS_AC_KERNEL_GET_GENDISK
47         ZFS_AC_KERNEL_HAVE_BIO_SET_OP_ATTRS
48         ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL
49         ZFS_AC_KERNEL_DISCARD_GRANULARITY
50         ZFS_AC_KERNEL_CONST_XATTR_HANDLER
51         ZFS_AC_KERNEL_XATTR_HANDLER_NAME
52         ZFS_AC_KERNEL_XATTR_HANDLER_GET
53         ZFS_AC_KERNEL_XATTR_HANDLER_SET
54         ZFS_AC_KERNEL_XATTR_HANDLER_LIST
55         ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
56         ZFS_AC_KERNEL_POSIX_ACL_FROM_XATTR_USERNS
57         ZFS_AC_KERNEL_POSIX_ACL_RELEASE
58         ZFS_AC_KERNEL_SET_CACHED_ACL_USABLE
59         ZFS_AC_KERNEL_POSIX_ACL_CHMOD
60         ZFS_AC_KERNEL_POSIX_ACL_EQUIV_MODE_WANTS_UMODE_T
61         ZFS_AC_KERNEL_POSIX_ACL_VALID_WITH_NS
62         ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION
63         ZFS_AC_KERNEL_INODE_OPERATIONS_PERMISSION_WITH_NAMEIDATA
64         ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL
65         ZFS_AC_KERNEL_INODE_OPERATIONS_CHECK_ACL_WITH_FLAGS
66         ZFS_AC_KERNEL_INODE_OPERATIONS_GET_ACL
67         ZFS_AC_KERNEL_INODE_OPERATIONS_SET_ACL
68         ZFS_AC_KERNEL_INODE_OPERATIONS_GETATTR
69         ZFS_AC_KERNEL_INODE_SET_FLAGS
70         ZFS_AC_KERNEL_INODE_SET_IVERSION
71         ZFS_AC_KERNEL_GET_ACL_HANDLE_CACHE
72         ZFS_AC_KERNEL_SHOW_OPTIONS
73         ZFS_AC_KERNEL_FILE_INODE
74         ZFS_AC_KERNEL_FILE_DENTRY
75         ZFS_AC_KERNEL_FSYNC
76         ZFS_AC_KERNEL_EVICT_INODE
77         ZFS_AC_KERNEL_DIRTY_INODE_WITH_FLAGS
78         ZFS_AC_KERNEL_NR_CACHED_OBJECTS
79         ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
80         ZFS_AC_KERNEL_FALLOCATE
81         ZFS_AC_KERNEL_AIO_FSYNC
82         ZFS_AC_KERNEL_MKDIR_UMODE_T
83         ZFS_AC_KERNEL_LOOKUP_NAMEIDATA
84         ZFS_AC_KERNEL_CREATE_NAMEIDATA
85         ZFS_AC_KERNEL_GET_LINK
86         ZFS_AC_KERNEL_PUT_LINK
87         ZFS_AC_KERNEL_TMPFILE
88         ZFS_AC_KERNEL_TRUNCATE_RANGE
89         ZFS_AC_KERNEL_AUTOMOUNT
90         ZFS_AC_KERNEL_ENCODE_FH_WITH_INODE
91         ZFS_AC_KERNEL_COMMIT_METADATA
92         ZFS_AC_KERNEL_CLEAR_INODE
93         ZFS_AC_KERNEL_SETATTR_PREPARE
94         ZFS_AC_KERNEL_INSERT_INODE_LOCKED
95         ZFS_AC_KERNEL_D_MAKE_ROOT
96         ZFS_AC_KERNEL_D_OBTAIN_ALIAS
97         ZFS_AC_KERNEL_D_PRUNE_ALIASES
98         ZFS_AC_KERNEL_D_SET_D_OP
99         ZFS_AC_KERNEL_D_REVALIDATE_NAMEIDATA
100         ZFS_AC_KERNEL_CONST_DENTRY_OPERATIONS
101         ZFS_AC_KERNEL_TRUNCATE_SETSIZE
102         ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY
103         ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY
104         ZFS_AC_KERNEL_MOUNT_NODEV
105         ZFS_AC_KERNEL_SHRINK
106         ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
107         ZFS_AC_KERNEL_S_INSTANCES_LIST_HEAD
108         ZFS_AC_KERNEL_S_D_OP
109         ZFS_AC_KERNEL_BDI
110         ZFS_AC_KERNEL_SET_NLINK
111         ZFS_AC_KERNEL_ELEVATOR_CHANGE
112         ZFS_AC_KERNEL_5ARG_SGET
113         ZFS_AC_KERNEL_LSEEK_EXECUTE
114         ZFS_AC_KERNEL_VFS_ITERATE
115         ZFS_AC_KERNEL_VFS_RW_ITERATE
116         ZFS_AC_KERNEL_GENERIC_WRITE_CHECKS
117         ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
118         ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
119         ZFS_AC_KERNEL_MAKE_REQUEST_FN
120         ZFS_AC_KERNEL_GENERIC_IO_ACCT_3ARG
121         ZFS_AC_KERNEL_GENERIC_IO_ACCT_4ARG
122         ZFS_AC_KERNEL_FPU
123         ZFS_AC_KERNEL_KUID_HELPERS
124         ZFS_AC_KERNEL_MODULE_PARAM_CALL_CONST
125         ZFS_AC_KERNEL_RENAME_WANTS_FLAGS
126         ZFS_AC_KERNEL_HAVE_GENERIC_SETXATTR
127         ZFS_AC_KERNEL_CURRENT_TIME
128         ZFS_AC_KERNEL_GLOBAL_PAGE_STATE
129         ZFS_AC_KERNEL_ACL_HAS_REFCOUNT
130         ZFS_AC_KERNEL_USERNS_CAPABILITIES
131
132         AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
133                 KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ"
134         ])
135
136         AC_SUBST(KERNEL_MAKE)
137 ])
138
139 dnl #
140 dnl # Detect name used for Module.symvers file in kernel
141 dnl #
142 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
143         modpost=$LINUX/scripts/Makefile.modpost
144         AC_MSG_CHECKING([kernel file name for module symbols])
145         AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
146                 AS_IF([grep -q Modules.symvers $modpost], [
147                         LINUX_SYMBOLS=Modules.symvers
148                 ], [
149                         LINUX_SYMBOLS=Module.symvers
150                 ])
151
152                 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
153                         AC_MSG_ERROR([
154         *** Please make sure the kernel devel package for your distribution
155         *** is installed.  If you are building with a custom kernel, make sure the
156         *** kernel is configured, built, and the '--with-linux=PATH' configure
157         *** option refers to the location of the kernel source.])
158                 ])
159         ], [
160                 LINUX_SYMBOLS=NONE
161         ])
162         AC_MSG_RESULT($LINUX_SYMBOLS)
163         AC_SUBST(LINUX_SYMBOLS)
164 ])
165
166 dnl #
167 dnl # Detect the kernel to be built against
168 dnl #
169 AC_DEFUN([ZFS_AC_KERNEL], [
170         AC_ARG_WITH([linux],
171                 AS_HELP_STRING([--with-linux=PATH],
172                 [Path to kernel source]),
173                 [kernelsrc="$withval"])
174
175         AC_ARG_WITH(linux-obj,
176                 AS_HELP_STRING([--with-linux-obj=PATH],
177                 [Path to kernel build objects]),
178                 [kernelbuild="$withval"])
179
180         AC_MSG_CHECKING([kernel source directory])
181         AS_IF([test -z "$kernelsrc"], [
182                 AS_IF([test -e "/lib/modules/$(uname -r)/source"], [
183                         headersdir="/lib/modules/$(uname -r)/source"
184                         sourcelink=$(readlink -f "$headersdir")
185                 ], [test -e "/lib/modules/$(uname -r)/build"], [
186                         headersdir="/lib/modules/$(uname -r)/build"
187                         sourcelink=$(readlink -f "$headersdir")
188                 ], [
189                         sourcelink=$(ls -1d /usr/src/kernels/* \
190                                      /usr/src/linux-* \
191                                      2>/dev/null | grep -v obj | tail -1)
192                 ])
193
194                 AS_IF([test -n "$sourcelink" && test -e ${sourcelink}], [
195                         kernelsrc=`readlink -f ${sourcelink}`
196                 ], [
197                         kernelsrc="[Not found]"
198                 ])
199         ], [
200                 AS_IF([test "$kernelsrc" = "NONE"], [
201                         kernsrcver=NONE
202                 ])
203                 withlinux=yes
204         ])
205
206         AC_MSG_RESULT([$kernelsrc])
207         AS_IF([test ! -d "$kernelsrc"], [
208                 AC_MSG_ERROR([
209         *** Please make sure the kernel devel package for your distribution
210         *** is installed and then try again.  If that fails, you can specify the
211         *** location of the kernel source with the '--with-linux=PATH' option.])
212         ])
213
214         AC_MSG_CHECKING([kernel build directory])
215         AS_IF([test -z "$kernelbuild"], [
216                 AS_IF([test x$withlinux != xyes -a -e "/lib/modules/$(uname -r)/build"], [
217                         kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
218                 ], [test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}], [
219                         kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
220                 ], [test -d ${kernelsrc}-obj/${target_cpu}/default], [
221                         kernelbuild=${kernelsrc}-obj/${target_cpu}/default
222                 ], [test -d `dirname ${kernelsrc}`/build-${target_cpu}], [
223                         kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
224                 ], [
225                         kernelbuild=${kernelsrc}
226                 ])
227         ])
228         AC_MSG_RESULT([$kernelbuild])
229
230         AC_MSG_CHECKING([kernel source version])
231         utsrelease1=$kernelbuild/include/linux/version.h
232         utsrelease2=$kernelbuild/include/linux/utsrelease.h
233         utsrelease3=$kernelbuild/include/generated/utsrelease.h
234         AS_IF([test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1], [
235                 utsrelease=linux/version.h
236         ], [test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2], [
237                 utsrelease=linux/utsrelease.h
238         ], [test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3], [
239                 utsrelease=generated/utsrelease.h
240         ])
241
242         AS_IF([test "$utsrelease"], [
243                 kernsrcver=`(echo "#include <$utsrelease>";
244                              echo "kernsrcver=UTS_RELEASE") |
245                              cpp -I $kernelbuild/include |
246                              grep "^kernsrcver=" | cut -d \" -f 2`
247
248                 AS_IF([test -z "$kernsrcver"], [
249                         AC_MSG_RESULT([Not found])
250                         AC_MSG_ERROR([*** Cannot determine kernel version.])
251                 ])
252         ], [
253                 AC_MSG_RESULT([Not found])
254                 if test "x$enable_linux_builtin" != xyes; then
255                         AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
256                 else
257                         AC_MSG_ERROR([
258         *** Cannot find UTS_RELEASE definition.
259         *** Please run 'make prepare' inside the kernel source tree.])
260                 fi
261         ])
262
263         AC_MSG_RESULT([$kernsrcver])
264
265         LINUX=${kernelsrc}
266         LINUX_OBJ=${kernelbuild}
267         LINUX_VERSION=${kernsrcver}
268
269         AC_SUBST(LINUX)
270         AC_SUBST(LINUX_OBJ)
271         AC_SUBST(LINUX_VERSION)
272
273         ZFS_AC_MODULE_SYMVERS
274 ])
275
276
277 dnl #
278 dnl # Detect the SPL module to be built against
279 dnl #
280 AC_DEFUN([ZFS_AC_SPL], [
281         AC_ARG_WITH([spl],
282                 AS_HELP_STRING([--with-spl=PATH],
283                 [Path to spl source]),
284                 AS_IF([test "$withval" = "yes"],
285                         AC_MSG_ERROR([--with-spl=PATH requires a PATH]),
286                         [splsrc="$withval"]))
287
288         AC_ARG_WITH([spl-obj],
289                 AS_HELP_STRING([--with-spl-obj=PATH],
290                 [Path to spl build objects]),
291                 [splbuild="$withval"])
292
293         AC_ARG_WITH([spl-timeout],
294                 AS_HELP_STRING([--with-spl-timeout=SECS],
295                 [Wait SECS for SPL header and symver file @<:@default=0@:>@]),
296                 [timeout="$withval"], [timeout=0])
297
298         dnl #
299         dnl # The existence of spl.release.in is used to identify a valid
300         dnl # source directory.  In order of preference:
301         dnl #
302         splsrc0="/var/lib/dkms/spl/${VERSION}/build"
303         splsrc1="/usr/local/src/spl-${VERSION}/${LINUX_VERSION}"
304         splsrc2="/usr/local/src/spl-${VERSION}"
305         splsrc3="/usr/src/spl-${VERSION}/${LINUX_VERSION}"
306         splsrc4="/usr/src/spl-${VERSION}"
307         splsrc5="../spl/"
308         splsrc6="$LINUX"
309
310         AC_MSG_CHECKING([spl source directory])
311         AS_IF([test -z "${splsrc}"], [
312                 [all_spl_sources="
313                 ${splsrc0}
314                 ${splsrc1}
315                 ${splsrc2}
316                 ${splsrc3}
317                 ${splsrc4}
318                 ${splsrc5}
319                 ${splsrc6}"],
320                 AS_IF([ test -e "${splsrc0}/spl.release.in"], [
321                         splsrc=${splsrc0}
322                 ], [ test -e "${splsrc1}/spl.release.in"], [
323                         splsrc=${splsrc1}
324                 ], [ test -e "${splsrc2}/spl.release.in"], [
325                         splsrc=${splsrc2}
326                 ], [ test -e "${splsrc3}/spl.release.in"], [
327                         splsrc=$(readlink -f "${splsrc3}")
328                 ], [ test -e "${splsrc4}/spl.release.in" ], [
329                         splsrc=${splsrc4}
330                 ], [ test -e "${splsrc5}/spl.release.in"], [
331                         splsrc=$(readlink -f "${splsrc5}")
332                 ], [ test -e "${splsrc6}/spl.release.in" ], [
333                         splsrc=${splsrc6}
334                 ], [
335                         splsrc="[Not found]"
336                 ])
337         ], [
338                 [all_spl_sources="$withval"],
339                 AS_IF([test "$splsrc" = "NONE"], [
340                         splbuild=NONE
341                         splsrcver=NONE
342                 ])
343         ])
344
345         AC_MSG_RESULT([$splsrc])
346         AS_IF([ test ! -e "$splsrc/spl.release.in"], [
347                 AC_MSG_ERROR([
348         *** Please make sure the kmod spl devel package for your distribution
349         *** is installed then try again.  If that fails you can specify the
350         *** location of the spl source with the '--with-spl=PATH' option.
351         *** The spl version must match the version of ZFS you are building,
352         *** ${VERSION}.  Failed to find spl.release.in in the following:
353         $all_spl_sources])
354         ])
355
356         dnl #
357         dnl # The existence of the spl_config.h is used to identify a valid
358         dnl # spl object directory.  In many cases the object and source
359         dnl # directory are the same, however the objects may also reside
360         dnl # is a subdirectory named after the kernel version.
361         dnl #
362         dnl # This file is supposed to be available after DKMS finishes
363         dnl # building the SPL kernel module for the target kernel.  The
364         dnl # '--with-spl-timeout' option can be passed to pause here,
365         dnl # waiting for the file to appear from a concurrently building
366         dnl # SPL package.
367         dnl #
368         AC_MSG_CHECKING([spl build directory])
369
370         all_spl_config_locs="${splsrc}/${LINUX_VERSION}
371         ${splsrc}"
372
373         while true; do
374                 AS_IF([test -z "$splbuild"], [
375                         AS_IF([ test -e "${splsrc}/${LINUX_VERSION}/spl_config.h" ], [
376                                 splbuild="${splsrc}/${LINUX_VERSION}"
377                         ], [ test -e "${splsrc}/spl_config.h" ], [
378                                 splbuild="${splsrc}"
379                         ], [ find -L "${splsrc}" -name spl_config.h 2> /dev/null | grep -wq spl_config.h ], [
380                                 splbuild=$(find -L "${splsrc}" -name spl_config.h | sed 's,/spl_config.h,,')
381                         ], [
382                                 splbuild="[Not found]"
383                         ])
384                 ])
385                 AS_IF([test -e "$splbuild/spl_config.h" -o $timeout -le 0], [
386                         break;
387                 ], [
388                         sleep 1
389                         timeout=$((timeout-1))
390                 ])
391         done
392
393         AC_MSG_RESULT([$splbuild])
394         AS_IF([ ! test -e "$splbuild/spl_config.h"], [
395                 AC_MSG_ERROR([
396         *** Please make sure the kmod spl devel <kernel> package for your
397         *** distribution is installed then try again.  If that fails you
398         *** can specify the location of the spl objects with the
399         *** '--with-spl-obj=PATH' option.  Failed to find spl_config.h in
400         *** any of the following:
401         $all_spl_config_locs])
402         ])
403
404         AC_MSG_CHECKING([spl source version])
405         AS_IF([test -r $splbuild/spl_config.h &&
406                 fgrep -q SPL_META_VERSION $splbuild/spl_config.h], [
407
408                 splsrcver=`(echo "#include <spl_config.h>";
409                             echo "splsrcver=SPL_META_VERSION-SPL_META_RELEASE") |
410                             cpp -I $splbuild |
411                             grep "^splsrcver=" | tr -d \" | cut -d= -f2`
412         ])
413
414         AS_IF([test -z "$splsrcver"], [
415                 AC_MSG_RESULT([Not found])
416                 AC_MSG_ERROR([
417         *** Cannot determine the version of the spl source.
418         *** Please prepare the spl source before running this script])
419         ])
420
421         AC_MSG_RESULT([$splsrcver])
422
423         SPL=${splsrc}
424         SPL_OBJ=${splbuild}
425         SPL_VERSION=${splsrcver}
426
427         AC_SUBST(SPL)
428         AC_SUBST(SPL_OBJ)
429         AC_SUBST(SPL_VERSION)
430
431         dnl #
432         dnl # Detect the name used for the SPL Module.symvers file.  If one
433         dnl # does not exist this is likely because the SPL has been configured
434         dnl # but not built.  The '--with-spl-timeout' option can be passed
435         dnl # to pause here, waiting for the file to appear from a concurrently
436         dnl # building SPL package.  If the file does not appear in time, a good
437         dnl # guess is made as to what this file will be named based on what it
438         dnl # is named in the kernel build products.  This file will first be
439         dnl # used at link time so if the guess is wrong the build will fail
440         dnl # then.  This unfortunately means the ZFS package does not contain a
441         dnl # reliable mechanism to detect symbols exported by the SPL at
442         dnl # configure time.
443         dnl #
444         AC_MSG_CHECKING([spl file name for module symbols])
445         SPL_SYMBOLS=NONE
446
447         while true; do
448                 AS_IF([test -r $SPL_OBJ/Module.symvers], [
449                         SPL_SYMBOLS=Module.symvers
450                 ], [test -r $SPL_OBJ/Modules.symvers], [
451                         SPL_SYMBOLS=Modules.symvers
452                 ], [test -r $SPL_OBJ/module/Module.symvers], [
453                         SPL_SYMBOLS=Module.symvers
454                 ], [test -r $SPL_OBJ/module/Modules.symvers], [
455                         SPL_SYMBOLS=Modules.symvers
456                 ])
457
458                 AS_IF([test $SPL_SYMBOLS != NONE -o $timeout -le 0], [
459                         break;
460                 ], [
461                         sleep 1
462                         timeout=$((timeout-1))
463                 ])
464         done
465
466         AS_IF([test "$SPL_SYMBOLS" = NONE], [
467                 SPL_SYMBOLS=$LINUX_SYMBOLS
468         ])
469
470         AC_MSG_RESULT([$SPL_SYMBOLS])
471         AC_SUBST(SPL_SYMBOLS)
472 ])
473
474 dnl #
475 dnl # Detect the QAT module to be built against
476 dnl # QAT provides hardware acceleration for data compression:
477 dnl #   https://01.org/intel-quickassist-technology
478 dnl # * Download and install QAT driver from the above link
479 dnl # * Start QAT driver in your system:
480 dnl #   service qat_service start
481 dnl # * Enable QAT in ZFS, e.g.:
482 dnl #   ./configure --with-qat=<qat-driver-path>/QAT1.6
483 dnl #   make
484 dnl # * Set GZIP compression in ZFS dataset:
485 dnl #   zfs set compression = gzip <dataset>
486 dnl # Then the data written to this ZFS pool is compressed
487 dnl # by QAT accelerator automatically, and de-compressed by
488 dnl # QAT when read from the pool.
489 dnl # * Get QAT hardware statistics by:
490 dnl #   cat /proc/icp_dh895xcc_dev/qat
491 dnl # * To disable QAT:
492 dnl #   insmod zfs.ko zfs_qat_disable=1
493 dnl #
494 AC_DEFUN([ZFS_AC_QAT], [
495         AC_ARG_WITH([qat],
496                 AS_HELP_STRING([--with-qat=PATH],
497                 [Path to qat source]),
498                 AS_IF([test "$withval" = "yes"],
499                         AC_MSG_ERROR([--with-qat=PATH requires a PATH]),
500                         [qatsrc="$withval"]))
501
502         AC_ARG_WITH([qat-obj],
503                 AS_HELP_STRING([--with-qat-obj=PATH],
504                 [Path to qat build objects]),
505                 [qatbuild="$withval"])
506
507         AS_IF([test ! -z "${qatsrc}"], [
508                 AC_MSG_CHECKING([qat source directory])
509                 AC_MSG_RESULT([$qatsrc])
510                 QAT_SRC="${qatsrc}/quickassist"
511                 AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [
512                         AC_MSG_ERROR([
513                 *** Please make sure the qat driver package is installed
514                 *** and specify the location of the qat source with the
515                 *** '--with-qat=PATH' option then try again. Failed to
516                 *** find cpa.h in:
517                 ${QAT_SRC}/include])
518                 ])
519         ])
520
521         AS_IF([test ! -z "${qatsrc}"], [
522                 AC_MSG_CHECKING([qat build directory])
523                 AS_IF([test -z "$qatbuild"], [
524                         qatbuild="${qatsrc}/build"
525                 ])
526
527                 AC_MSG_RESULT([$qatbuild])
528                 QAT_OBJ=${qatbuild}
529                 AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko" && ! test -e "$QAT_OBJ/qat_api.ko"], [
530                         AC_MSG_ERROR([
531                 *** Please make sure the qat driver is installed then try again.
532                 *** Failed to find icp_qa_al.ko or qat_api.ko in:
533                 $QAT_OBJ])
534                 ])
535
536                 AC_SUBST(QAT_SRC)
537                 AC_SUBST(QAT_OBJ)
538
539                 AC_DEFINE(HAVE_QAT, 1,
540                 [qat is enabled and existed])
541         ])
542
543         dnl #
544         dnl # Detect the name used for the QAT Module.symvers file.
545         dnl #
546         AS_IF([test ! -z "${qatsrc}"], [
547                 AC_MSG_CHECKING([qat file for module symbols])
548                 QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers
549
550                 AS_IF([test -r $QAT_SYMBOLS], [
551                         AC_MSG_RESULT([$QAT_SYMBOLS])
552                         AC_SUBST(QAT_SYMBOLS)
553                 ],[
554                        AC_MSG_ERROR([
555                         *** Please make sure the qat driver is installed then try again.
556                         *** Failed to find Module.symvers in:
557                         $QAT_SYMBOLS])
558                         ])
559                 ])
560         ])
561 ])
562
563 dnl #
564 dnl # Basic toolchain sanity check.
565 dnl #
566 AC_DEFUN([ZFS_AC_TEST_MODULE], [
567         AC_MSG_CHECKING([whether modules can be built])
568         ZFS_LINUX_TRY_COMPILE([],[],[
569                 AC_MSG_RESULT([yes])
570         ],[
571                 AC_MSG_RESULT([no])
572                 if test "x$enable_linux_builtin" != xyes; then
573                         AC_MSG_ERROR([*** Unable to build an empty module.])
574                 else
575                         AC_MSG_ERROR([
576         *** Unable to build an empty module.
577         *** Please run 'make scripts' inside the kernel source tree.])
578                 fi
579         ])
580 ])
581
582 dnl #
583 dnl # Certain kernel build options are not supported.  These must be
584 dnl # detected at configure time and cause a build failure.  Otherwise
585 dnl # modules may be successfully built that behave incorrectly.
586 dnl #
587 AC_DEFUN([ZFS_AC_KERNEL_CONFIG], [
588         AS_IF([test "x$cross_compiling" != xyes], [
589                 AC_RUN_IFELSE([
590                         AC_LANG_PROGRAM([
591                                 #include "$LINUX/include/linux/license.h"
592                         ], [
593                                 return !license_is_gpl_compatible("$ZFS_META_LICENSE");
594                         ])
595                 ], [
596                         AC_DEFINE([ZFS_IS_GPL_COMPATIBLE], [1],
597                             [Define to 1 if GPL-only symbols can be used])
598                 ], [
599                 ])
600         ])
601
602         ZFS_AC_KERNEL_CONFIG_THREAD_SIZE
603         ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC
604 ])
605
606 dnl #
607 dnl # Check configured THREAD_SIZE
608 dnl #
609 dnl # The stack size will vary by architecture, but as of Linux 3.15 on x86_64
610 dnl # the default thread stack size was increased to 16K from 8K.  Therefore,
611 dnl # on newer kernels and some architectures stack usage optimizations can be
612 dnl # conditionally applied to improve performance without negatively impacting
613 dnl # stability.
614 dnl #
615 AC_DEFUN([ZFS_AC_KERNEL_CONFIG_THREAD_SIZE], [
616         AC_MSG_CHECKING([whether kernel was built with 16K or larger stacks])
617         ZFS_LINUX_TRY_COMPILE([
618                 #include <linux/module.h>
619         ],[
620                 #if (THREAD_SIZE < 16384)
621                 #error "THREAD_SIZE is less than 16K"
622                 #endif
623         ],[
624                 AC_MSG_RESULT([yes])
625                 AC_DEFINE(HAVE_LARGE_STACKS, 1, [kernel has large stacks])
626         ],[
627                 AC_MSG_RESULT([no])
628         ])
629 ])
630
631 dnl #
632 dnl # Check CONFIG_DEBUG_LOCK_ALLOC
633 dnl #
634 dnl # This is typically only set for debug kernels because it comes with
635 dnl # a performance penalty.  However, when it is set it maps the non-GPL
636 dnl # symbol mutex_lock() to the GPL-only mutex_lock_nested() symbol.
637 dnl # This will cause a failure at link time which we'd rather know about
638 dnl # at compile time.
639 dnl #
640 dnl # Since we plan to pursue making mutex_lock_nested() a non-GPL symbol
641 dnl # with the upstream community we add a check to detect this case.
642 dnl #
643 AC_DEFUN([ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC], [
644
645         ZFS_LINUX_CONFIG([DEBUG_LOCK_ALLOC], [
646                 AC_MSG_CHECKING([whether mutex_lock() is GPL-only])
647                 tmp_flags="$EXTRA_KCFLAGS"
648                 ZFS_LINUX_TRY_COMPILE([
649                         #include <linux/module.h>
650                         #include <linux/mutex.h>
651
652                         MODULE_LICENSE("$ZFS_META_LICENSE");
653                 ],[
654                         struct mutex lock;
655
656                         mutex_init(&lock);
657                         mutex_lock(&lock);
658                         mutex_unlock(&lock);
659                 ],[
660                         AC_MSG_RESULT(no)
661                 ],[
662                         AC_MSG_RESULT(yes)
663                         AC_MSG_ERROR([
664         *** Kernel built with CONFIG_DEBUG_LOCK_ALLOC which is incompatible
665         *** with the CDDL license and will prevent the module linking stage
666         *** from succeeding.  You must rebuild your kernel without this
667         *** option enabled.])
668                 ])
669                 EXTRA_KCFLAGS="$tmp_flags"
670         ], [])
671 ])
672
673 dnl #
674 dnl # ZFS_LINUX_CONFTEST_H
675 dnl #
676 AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
677 cat - <<_ACEOF >conftest.h
678 $1
679 _ACEOF
680 ])
681
682 dnl #
683 dnl # ZFS_LINUX_CONFTEST_C
684 dnl #
685 AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
686 cat confdefs.h - <<_ACEOF >conftest.c
687 $1
688 _ACEOF
689 ])
690
691 dnl #
692 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
693 dnl #
694 m4_define([ZFS_LANG_PROGRAM], [
695 $1
696 int
697 main (void)
698 {
699 dnl Do *not* indent the following line: there may be CPP directives.
700 dnl Don't move the `;' right after for the same reason.
701 $2
702   ;
703   return 0;
704 }
705 ])
706
707 dnl #
708 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
709 dnl #
710 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
711         m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1])])
712         m4_ifvaln([$6], [ZFS_LINUX_CONFTEST_H([$6])], [ZFS_LINUX_CONFTEST_H([])])
713         rm -Rf build && mkdir -p build && touch build/conftest.mod.c
714         echo "obj-m := conftest.o" >build/Makefile
715         modpost_flag=''
716         test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
717         AS_IF(
718                 [AC_TRY_COMMAND(cp conftest.c conftest.h build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror $FRAME_LARGER_THAN $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
719                 [$4],
720                 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
721         )
722         rm -Rf build
723 ])
724
725 dnl #
726 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
727 dnl #
728 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
729         [ZFS_LINUX_COMPILE_IFELSE(
730         [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
731         [modules],
732         [test -s build/conftest.o],
733         [$3], [$4])
734 ])
735
736 dnl #
737 dnl # ZFS_LINUX_CONFIG
738 dnl #
739 AC_DEFUN([ZFS_LINUX_CONFIG],
740         [AC_MSG_CHECKING([whether kernel was built with CONFIG_$1])
741         ZFS_LINUX_TRY_COMPILE([
742                 #include <linux/module.h>
743         ],[
744                 #ifndef CONFIG_$1
745                 #error CONFIG_$1 not #defined
746                 #endif
747         ],[
748                 AC_MSG_RESULT([yes])
749                 $2
750         ],[
751                 AC_MSG_RESULT([no])
752                 $3
753         ])
754 ])
755
756 dnl #
757 dnl # ZFS_CHECK_SYMBOL_EXPORT
758 dnl # check symbol exported or not
759 dnl #
760 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
761         grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
762                 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
763         rc=$?
764         if test $rc -ne 0; then
765                 export=0
766                 for file in $2; do
767                         grep -q -E "EXPORT_SYMBOL.*($1)" \
768                                 "$LINUX/$file" 2>/dev/null
769                         rc=$?
770                         if test $rc -eq 0; then
771                                 export=1
772                                 break;
773                         fi
774                 done
775                 if test $export -eq 0; then :
776                         $4
777                 else :
778                         $3
779                 fi
780         else :
781                 $3
782         fi
783 ])
784
785 dnl #
786 dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
787 dnl # like ZFS_LINUX_TRY_COMPILE, except ZFS_CHECK_SYMBOL_EXPORT
788 dnl # is called if not compiling for builtin
789 dnl #
790 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
791         ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
792         if test $rc -ne 0; then :
793                 $6
794         else
795                 if test "x$enable_linux_builtin" != xyes; then
796                         ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
797                 fi
798                 if test $rc -ne 0; then :
799                         $6
800                 else :
801                         $5
802                 fi
803         fi
804 ])
805
806 dnl #
807 dnl # ZFS_LINUX_TRY_COMPILE_HEADER
808 dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
809 dnl # provided via the fifth parameter
810 dnl #
811 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER],
812         [ZFS_LINUX_COMPILE_IFELSE(
813         [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
814         [modules],
815         [test -s build/conftest.o],
816         [$3], [$4], [$5])
817 ])