config: remove HAVE_SUPER_SETUP_BDI_NAME
[zfs.git] / config / kernel.m4
blob1c34daea5d70f748658e6c849f693e47826f38c6
1 dnl #
2 dnl # Default ZFS kernel configuration
3 dnl #
4 AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
5         AM_COND_IF([BUILD_LINUX], [
6                 dnl # Setup the kernel build environment.
7                 ZFS_AC_KERNEL
8                 ZFS_AC_QAT
10                 dnl # Sanity checks for module building and CONFIG_* defines
11                 ZFS_AC_KERNEL_CONFIG_DEFINED
12                 ZFS_AC_MODULE_SYMVERS
14                 dnl # Sequential ZFS_LINUX_TRY_COMPILE tests
15                 ZFS_AC_KERNEL_FPU_HEADER
16                 ZFS_AC_KERNEL_OBJTOOL_HEADER
17                 ZFS_AC_KERNEL_WAIT_QUEUE_ENTRY_T
18                 ZFS_AC_KERNEL_MISC_MINOR
19                 ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
21                 dnl # Parallel ZFS_LINUX_TEST_SRC / ZFS_LINUX_TEST_RESULT tests
22                 ZFS_AC_KERNEL_TEST_SRC
23                 ZFS_AC_KERNEL_TEST_RESULT
25                 AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
26                         KERNEL_MAKE="$KERNEL_MAKE O=$LINUX_OBJ"
27                 ])
29                 AC_SUBST(KERNEL_MAKE)
30         ])
33 dnl #
34 dnl # Generate and compile all of the kernel API test cases to determine
35 dnl # which interfaces are available.  By invoking the kernel build system
36 dnl # only once the compilation can be done in parallel significantly
37 dnl # speeding up the process.
38 dnl #
39 AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
40         ZFS_AC_KERNEL_SRC_TYPES
41         ZFS_AC_KERNEL_SRC_OBJTOOL
42         ZFS_AC_KERNEL_SRC_GLOBAL_PAGE_STATE
43         ZFS_AC_KERNEL_SRC_ACCESS_OK_TYPE
44         ZFS_AC_KERNEL_SRC_PDE_DATA
45         ZFS_AC_KERNEL_SRC_GENERIC_FADVISE
46         ZFS_AC_KERNEL_SRC_SCHED
47         ZFS_AC_KERNEL_SRC_USLEEP_RANGE
48         ZFS_AC_KERNEL_SRC_VMALLOC_PAGE_KERNEL
49         ZFS_AC_KERNEL_SRC_WAIT
50         ZFS_AC_KERNEL_SRC_INODE_TIMES
51         ZFS_AC_KERNEL_SRC_PROC_OPERATIONS
52         ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS
53         ZFS_AC_KERNEL_SRC_BIO
54         ZFS_AC_KERNEL_SRC_BLKDEV
55         ZFS_AC_KERNEL_SRC_BLK_QUEUE
56         ZFS_AC_KERNEL_SRC_GENHD_FLAGS
57         ZFS_AC_KERNEL_SRC_REVALIDATE_DISK
58         ZFS_AC_KERNEL_SRC_GET_DISK_RO
59         ZFS_AC_KERNEL_SRC_GENERIC_READLINK_GLOBAL
60         ZFS_AC_KERNEL_SRC_DISCARD_GRANULARITY
61         ZFS_AC_KERNEL_SRC_INODE_OWNER_OR_CAPABLE
62         ZFS_AC_KERNEL_SRC_XATTR
63         ZFS_AC_KERNEL_SRC_ACL
64         ZFS_AC_KERNEL_SRC_INODE_SETATTR
65         ZFS_AC_KERNEL_SRC_INODE_GETATTR
66         ZFS_AC_KERNEL_SRC_SHOW_OPTIONS
67         ZFS_AC_KERNEL_SRC_SHRINKER
68         ZFS_AC_KERNEL_SRC_MKDIR
69         ZFS_AC_KERNEL_SRC_LOOKUP_FLAGS
70         ZFS_AC_KERNEL_SRC_CREATE
71         ZFS_AC_KERNEL_SRC_PERMISSION
72         ZFS_AC_KERNEL_SRC_TMPFILE
73         ZFS_AC_KERNEL_SRC_AUTOMOUNT
74         ZFS_AC_KERNEL_SRC_COMMIT_METADATA
75         ZFS_AC_KERNEL_SRC_SETATTR_PREPARE
76         ZFS_AC_KERNEL_SRC_INSERT_INODE_LOCKED
77         ZFS_AC_KERNEL_SRC_TRUNCATE_SETSIZE
78         ZFS_AC_KERNEL_SRC_SECURITY_INODE
79         ZFS_AC_KERNEL_SRC_FST_MOUNT
80         ZFS_AC_KERNEL_SRC_SET_NLINK
81         ZFS_AC_KERNEL_SRC_SGET
82         ZFS_AC_KERNEL_SRC_VFS_FILEMAP_DIRTY_FOLIO
83         ZFS_AC_KERNEL_SRC_VFS_READ_FOLIO
84         ZFS_AC_KERNEL_SRC_VFS_FSYNC_2ARGS
85         ZFS_AC_KERNEL_SRC_GET_USER_PAGES
86         ZFS_AC_KERNEL_SRC_VFS_DIRECT_IO
87         ZFS_AC_KERNEL_SRC_VFS_READPAGES
88         ZFS_AC_KERNEL_SRC_VFS_SET_PAGE_DIRTY_NOBUFFERS
89         ZFS_AC_KERNEL_SRC_VFS_IOV_ITER
90         ZFS_AC_KERNEL_SRC_VFS_GENERIC_COPY_FILE_RANGE
91         ZFS_AC_KERNEL_SRC_VFS_SPLICE_COPY_FILE_RANGE
92         ZFS_AC_KERNEL_SRC_VFS_REMAP_FILE_RANGE
93         ZFS_AC_KERNEL_SRC_VFS_CLONE_FILE_RANGE
94         ZFS_AC_KERNEL_SRC_VFS_DEDUPE_FILE_RANGE
95         ZFS_AC_KERNEL_SRC_KMAP_ATOMIC_ARGS
96         ZFS_AC_KERNEL_SRC_KMAP_LOCAL_PAGE
97         ZFS_AC_KERNEL_SRC_FOLLOW_DOWN_ONE
98         ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN
99         ZFS_AC_KERNEL_SRC_GENERIC_IO_ACCT
100         ZFS_AC_KERNEL_SRC_FPU
101         ZFS_AC_KERNEL_SRC_FMODE_T
102         ZFS_AC_KERNEL_SRC_KUIDGID_T
103         ZFS_AC_KERNEL_SRC_KUID_HELPERS
104         ZFS_AC_KERNEL_SRC_RENAME
105         ZFS_AC_KERNEL_SRC_USERNS_CAPABILITIES
106         ZFS_AC_KERNEL_SRC_TOTALRAM_PAGES_FUNC
107         ZFS_AC_KERNEL_SRC_TOTALHIGH_PAGES
108         ZFS_AC_KERNEL_SRC_PERCPU
109         ZFS_AC_KERNEL_SRC_GENERIC_FILLATTR
110         ZFS_AC_KERNEL_SRC_MKNOD
111         ZFS_AC_KERNEL_SRC_SYMLINK
112         ZFS_AC_KERNEL_SRC_BIO_MAX_SEGS
113         ZFS_AC_KERNEL_SRC_SIGINFO
114         ZFS_AC_KERNEL_SRC_SYSFS
115         ZFS_AC_KERNEL_SRC_STANDALONE_LINUX_STDARG
116         ZFS_AC_KERNEL_SRC_STRLCPY
117         ZFS_AC_KERNEL_SRC_PAGEMAP_FOLIO_WAIT_BIT
118         ZFS_AC_KERNEL_SRC_ADD_DISK
119         ZFS_AC_KERNEL_SRC_KTHREAD
120         ZFS_AC_KERNEL_SRC_ZERO_PAGE
121         ZFS_AC_KERNEL_SRC___COPY_FROM_USER_INATOMIC
122         ZFS_AC_KERNEL_SRC_IDMAP_MNT_API
123         ZFS_AC_KERNEL_SRC_IDMAP_NO_USERNS
124         ZFS_AC_KERNEL_SRC_IATTR_VFSID
125         ZFS_AC_KERNEL_SRC_WRITEPAGE_T
126         ZFS_AC_KERNEL_SRC_RECLAIMED
127         ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_TABLE
128         ZFS_AC_KERNEL_SRC_REGISTER_SYSCTL_SZ
129         ZFS_AC_KERNEL_SRC_PROC_HANDLER_CTL_TABLE_CONST
130         ZFS_AC_KERNEL_SRC_COPY_SPLICE_READ
131         ZFS_AC_KERNEL_SRC_SYNC_BDEV
132         ZFS_AC_KERNEL_SRC_MM_PAGE_SIZE
133         ZFS_AC_KERNEL_SRC_MM_PAGE_MAPPING
134         case "$host_cpu" in
135                 powerpc*)
136                         ZFS_AC_KERNEL_SRC_CPU_HAS_FEATURE
137                         ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
138                         ;;
139                 riscv*)
140                         ZFS_AC_KERNEL_SRC_FLUSH_DCACHE_PAGE
141                         ;;
142         esac
144         AC_MSG_CHECKING([for available kernel interfaces])
145         ZFS_LINUX_TEST_COMPILE_ALL([kabi])
146         AC_MSG_RESULT([done])
149 dnl #
150 dnl # Check results of kernel interface tests.
151 dnl #
152 AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
153         ZFS_AC_KERNEL_TYPES
154         ZFS_AC_KERNEL_ACCESS_OK_TYPE
155         ZFS_AC_KERNEL_GLOBAL_PAGE_STATE
156         ZFS_AC_KERNEL_OBJTOOL
157         ZFS_AC_KERNEL_PDE_DATA
158         ZFS_AC_KERNEL_GENERIC_FADVISE
159         ZFS_AC_KERNEL_SCHED
160         ZFS_AC_KERNEL_USLEEP_RANGE
161         ZFS_AC_KERNEL_VMALLOC_PAGE_KERNEL
162         ZFS_AC_KERNEL_WAIT
163         ZFS_AC_KERNEL_INODE_TIMES
164         ZFS_AC_KERNEL_PROC_OPERATIONS
165         ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS
166         ZFS_AC_KERNEL_BIO
167         ZFS_AC_KERNEL_BLKDEV
168         ZFS_AC_KERNEL_BLK_QUEUE
169         ZFS_AC_KERNEL_GENHD_FLAGS
170         ZFS_AC_KERNEL_REVALIDATE_DISK
171         ZFS_AC_KERNEL_GET_DISK_RO
172         ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL
173         ZFS_AC_KERNEL_DISCARD_GRANULARITY
174         ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE
175         ZFS_AC_KERNEL_XATTR
176         ZFS_AC_KERNEL_ACL
177         ZFS_AC_KERNEL_INODE_SETATTR
178         ZFS_AC_KERNEL_INODE_GETATTR
179         ZFS_AC_KERNEL_SHOW_OPTIONS
180         ZFS_AC_KERNEL_SHRINKER
181         ZFS_AC_KERNEL_MKDIR
182         ZFS_AC_KERNEL_LOOKUP_FLAGS
183         ZFS_AC_KERNEL_CREATE
184         ZFS_AC_KERNEL_PERMISSION
185         ZFS_AC_KERNEL_TMPFILE
186         ZFS_AC_KERNEL_AUTOMOUNT
187         ZFS_AC_KERNEL_COMMIT_METADATA
188         ZFS_AC_KERNEL_SETATTR_PREPARE
189         ZFS_AC_KERNEL_INSERT_INODE_LOCKED
190         ZFS_AC_KERNEL_TRUNCATE_SETSIZE
191         ZFS_AC_KERNEL_SECURITY_INODE
192         ZFS_AC_KERNEL_FST_MOUNT
193         ZFS_AC_KERNEL_SET_NLINK
194         ZFS_AC_KERNEL_SGET
195         ZFS_AC_KERNEL_VFS_FILEMAP_DIRTY_FOLIO
196         ZFS_AC_KERNEL_VFS_READ_FOLIO
197         ZFS_AC_KERNEL_VFS_FSYNC_2ARGS
198         ZFS_AC_KERNEL_GET_USER_PAGES
199         ZFS_AC_KERNEL_VFS_DIRECT_IO
200         ZFS_AC_KERNEL_VFS_READPAGES
201         ZFS_AC_KERNEL_VFS_SET_PAGE_DIRTY_NOBUFFERS
202         ZFS_AC_KERNEL_VFS_IOV_ITER
203         ZFS_AC_KERNEL_VFS_GENERIC_COPY_FILE_RANGE
204         ZFS_AC_KERNEL_VFS_SPLICE_COPY_FILE_RANGE
205         ZFS_AC_KERNEL_VFS_REMAP_FILE_RANGE
206         ZFS_AC_KERNEL_VFS_CLONE_FILE_RANGE
207         ZFS_AC_KERNEL_VFS_DEDUPE_FILE_RANGE
208         ZFS_AC_KERNEL_KMAP_ATOMIC_ARGS
209         ZFS_AC_KERNEL_KMAP_LOCAL_PAGE
210         ZFS_AC_KERNEL_FOLLOW_DOWN_ONE
211         ZFS_AC_KERNEL_MAKE_REQUEST_FN
212         ZFS_AC_KERNEL_GENERIC_IO_ACCT
213         ZFS_AC_KERNEL_FPU
214         ZFS_AC_KERNEL_FMODE_T
215         ZFS_AC_KERNEL_KUIDGID_T
216         ZFS_AC_KERNEL_KUID_HELPERS
217         ZFS_AC_KERNEL_RENAME
218         ZFS_AC_KERNEL_USERNS_CAPABILITIES
219         ZFS_AC_KERNEL_TOTALRAM_PAGES_FUNC
220         ZFS_AC_KERNEL_TOTALHIGH_PAGES
221         ZFS_AC_KERNEL_PERCPU
222         ZFS_AC_KERNEL_GENERIC_FILLATTR
223         ZFS_AC_KERNEL_MKNOD
224         ZFS_AC_KERNEL_SYMLINK
225         ZFS_AC_KERNEL_BIO_MAX_SEGS
226         ZFS_AC_KERNEL_SIGINFO
227         ZFS_AC_KERNEL_SYSFS
228         ZFS_AC_KERNEL_STANDALONE_LINUX_STDARG
229         ZFS_AC_KERNEL_STRLCPY
230         ZFS_AC_KERNEL_PAGEMAP_FOLIO_WAIT_BIT
231         ZFS_AC_KERNEL_ADD_DISK
232         ZFS_AC_KERNEL_KTHREAD
233         ZFS_AC_KERNEL_ZERO_PAGE
234         ZFS_AC_KERNEL___COPY_FROM_USER_INATOMIC
235         ZFS_AC_KERNEL_IDMAP_MNT_API
236         ZFS_AC_KERNEL_IDMAP_NO_USERNS
237         ZFS_AC_KERNEL_IATTR_VFSID
238         ZFS_AC_KERNEL_WRITEPAGE_T
239         ZFS_AC_KERNEL_RECLAIMED
240         ZFS_AC_KERNEL_REGISTER_SYSCTL_TABLE
241         ZFS_AC_KERNEL_REGISTER_SYSCTL_SZ
242         ZFS_AC_KERNEL_PROC_HANDLER_CTL_TABLE_CONST
243         ZFS_AC_KERNEL_COPY_SPLICE_READ
244         ZFS_AC_KERNEL_SYNC_BDEV
245         ZFS_AC_KERNEL_MM_PAGE_SIZE
246         ZFS_AC_KERNEL_MM_PAGE_MAPPING
247         ZFS_AC_KERNEL_1ARG_ASSIGN_STR
248         case "$host_cpu" in
249                 powerpc*)
250                         ZFS_AC_KERNEL_CPU_HAS_FEATURE
251                         ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
252                         ;;
253                 riscv*)
254                         ZFS_AC_KERNEL_FLUSH_DCACHE_PAGE
255                         ;;
256         esac
259 dnl #
260 dnl # Detect name used for Module.symvers file in kernel
261 dnl #
262 AC_DEFUN([ZFS_AC_MODULE_SYMVERS], [
263         modpost=$LINUX/scripts/Makefile.modpost
264         AC_MSG_CHECKING([kernel file name for module symbols])
265         AS_IF([test "x$enable_linux_builtin" != xyes -a -f "$modpost"], [
266                 AS_IF([grep -q Modules.symvers $modpost], [
267                         LINUX_SYMBOLS=Modules.symvers
268                 ], [
269                         LINUX_SYMBOLS=Module.symvers
270                 ])
272                 AS_IF([test ! -f "$LINUX_OBJ/$LINUX_SYMBOLS"], [
273                         AC_MSG_ERROR([
274         *** Please make sure the kernel devel package for your distribution
275         *** is installed.  If you are building with a custom kernel, make sure
276         *** the kernel is configured, built, and the '--with-linux=PATH'
277         *** configure option refers to the location of the kernel source.
278                         ])
279                 ])
280         ], [
281                 LINUX_SYMBOLS=NONE
282         ])
283         AC_MSG_RESULT($LINUX_SYMBOLS)
284         AC_SUBST(LINUX_SYMBOLS)
287 dnl #
288 dnl # Detect the kernel to be built against
289 dnl #
290 dnl # Most modern Linux distributions have separate locations for bare
291 dnl # source (source) and prebuilt (build) files. Additionally, there are
292 dnl # `source` and `build` symlinks in `/lib/modules/$(KERNEL_VERSION)`
293 dnl # pointing to them. The directory search order is now:
294 dnl # 
295 dnl # - `configure` command line values if both `--with-linux` and
296 dnl #   `--with-linux-obj` were defined
297 dnl # 
298 dnl # - If only `--with-linux` was defined, `--with-linux-obj` is assumed
299 dnl #   to have the same value as `--with-linux`
300 dnl # 
301 dnl # - If neither `--with-linux` nor `--with-linux-obj` were defined
302 dnl #   autodetection is used:
303 dnl # 
304 dnl #   - `/lib/modules/$(uname -r)/{source,build}` respectively, if exist.
305 dnl # 
306 dnl #   - If only `/lib/modules/$(uname -r)/build` exists, it is assumed
307 dnl #     to be both source and build directory.
308 dnl # 
309 dnl #   - The first directory in `/lib/modules` with the highest version
310 dnl #     number according to `sort -V` which contains both `source` and
311 dnl #     `build` symlinks/directories. If module directory contains only
312 dnl #     `build` component, it is assumed to be both source and build
313 dnl #     directory.
314 dnl # 
315 dnl #   - Last resort: the first directory matching `/usr/src/kernels/*`
316 dnl #     and `/usr/src/linux-*` with the highest version number according
317 dnl #     to `sort -V` is assumed to be both source and build directory.
318 dnl #
319 AC_DEFUN([ZFS_AC_KERNEL], [
320         AC_ARG_WITH([linux],
321                 AS_HELP_STRING([--with-linux=PATH],
322                 [Path to kernel source]),
323                 [kernelsrc="$withval"])
325         AC_ARG_WITH(linux-obj,
326                 AS_HELP_STRING([--with-linux-obj=PATH],
327                 [Path to kernel build objects]),
328                 [kernelbuild="$withval"])
330         AC_MSG_CHECKING([kernel source and build directories])
331         AS_IF([test -n "$kernelsrc" && test -z "$kernelbuild"], [
332                 kernelbuild="$kernelsrc"
333         ], [test -z "$kernelsrc"], [
334                 AS_IF([test -e "/lib/modules/$(uname -r)/source" && \
335                        test -e "/lib/modules/$(uname -r)/build"], [
336                         src="/lib/modules/$(uname -r)/source"
337                         build="/lib/modules/$(uname -r)/build"
338                 ], [test -e "/lib/modules/$(uname -r)/build"], [
339                         build="/lib/modules/$(uname -r)/build"
340                         src="$build"
341                 ], [
342                         src=
344                         for d in $(ls -1d /lib/modules/* 2>/dev/null | sort -Vr); do
345                                 if test -e "$d/source" && test -e "$d/build"; then
346                                         src="$d/source"
347                                         build="$d/build"
348                                         break
349                                 fi
351                                 if test -e "$d/build"; then
352                                         src="$d/build"
353                                         build="$d/build"
354                                         break
355                                 fi
356                         done
358                         # the least reliable method
359                         if test -z "$src"; then
360                                 src=$(ls -1d /usr/src/kernels/* /usr/src/linux-* \
361                                       2>/dev/null | grep -v obj | sort -Vr | head -1)
362                                 build="$src"
363                         fi
364                 ])
366                 AS_IF([test -n "$src" && test -e "$src"], [
367                         kernelsrc=$(readlink -e "$src")
368                 ], [
369                         kernelsrc="[Not found]"
370                 ])
371                 AS_IF([test -n "$build" && test -e "$build"], [
372                         kernelbuild=$(readlink -e "$build")
373                 ], [
374                         kernelbuild="[Not found]"
375                 ])
376         ], [
377                 AS_IF([test "$kernelsrc" = "NONE"], [
378                         kernsrcver=NONE
379                 ])
380                 withlinux=yes
381         ])
383         AC_MSG_RESULT([done])
384         AC_MSG_CHECKING([kernel source directory])
385         AC_MSG_RESULT([$kernelsrc])
386         AC_MSG_CHECKING([kernel build directory])
387         AC_MSG_RESULT([$kernelbuild])
388         AS_IF([test ! -d "$kernelsrc" || test ! -d "$kernelbuild"], [
389                 AC_MSG_ERROR([
390         *** Please make sure the kernel devel package for your distribution
391         *** is installed and then try again.  If that fails, you can specify the
392         *** location of the kernel source and build with the '--with-linux=PATH' and
393         *** '--with-linux-obj=PATH' options respectively.])
394         ])
396         AC_MSG_CHECKING([kernel source version])
397         utsrelease1=$kernelbuild/include/linux/version.h
398         utsrelease2=$kernelbuild/include/linux/utsrelease.h
399         utsrelease3=$kernelbuild/include/generated/utsrelease.h
400         AS_IF([test -r $utsrelease1 && grep -qF UTS_RELEASE $utsrelease1], [
401                 utsrelease=$utsrelease1
402         ], [test -r $utsrelease2 && grep -qF UTS_RELEASE $utsrelease2], [
403                 utsrelease=$utsrelease2
404         ], [test -r $utsrelease3 && grep -qF UTS_RELEASE $utsrelease3], [
405                 utsrelease=$utsrelease3
406         ])
408         AS_IF([test -n "$utsrelease"], [
409                 kernsrcver=$($AWK '/UTS_RELEASE/ { gsub(/"/, "", $[3]); print $[3] }' $utsrelease)
410                 AS_IF([test -z "$kernsrcver"], [
411                         AC_MSG_RESULT([Not found])
412                         AC_MSG_ERROR([
413         *** Cannot determine kernel version.
414                         ])
415                 ])
416         ], [
417                 AC_MSG_RESULT([Not found])
418                 if test "x$enable_linux_builtin" != xyes; then
419                         AC_MSG_ERROR([
420         *** Cannot find UTS_RELEASE definition.
421                         ])
422                 else
423                         AC_MSG_ERROR([
424         *** Cannot find UTS_RELEASE definition.
425         *** Please run 'make prepare' inside the kernel source tree.])
426                 fi
427         ])
429         AC_MSG_RESULT([$kernsrcver])
431         AS_VERSION_COMPARE([$kernsrcver], [$ZFS_META_KVER_MIN], [
432                  AC_MSG_ERROR([
433         *** Cannot build against kernel version $kernsrcver.
434         *** The minimum supported kernel version is $ZFS_META_KVER_MIN.
435                 ])
436         ])
438         LINUX=${kernelsrc}
439         LINUX_OBJ=${kernelbuild}
440         LINUX_VERSION=${kernsrcver}
442         AC_SUBST(LINUX)
443         AC_SUBST(LINUX_OBJ)
444         AC_SUBST(LINUX_VERSION)
447 dnl #
448 dnl # Detect the QAT module to be built against, QAT provides hardware
449 dnl # acceleration for data compression:
450 dnl #
451 dnl # https://01.org/intel-quickassist-technology
452 dnl #
453 dnl # 1) Download and install QAT driver from the above link
454 dnl # 2) Start QAT driver in your system:
455 dnl #    service qat_service start
456 dnl # 3) Enable QAT in ZFS, e.g.:
457 dnl #    ./configure --with-qat=<qat-driver-path>/QAT1.6
458 dnl #    make
459 dnl # 4) Set GZIP compression in ZFS dataset:
460 dnl #    zfs set compression = gzip <dataset>
461 dnl #
462 dnl # Then the data written to this ZFS pool is compressed by QAT accelerator
463 dnl # automatically, and de-compressed by QAT when read from the pool.
464 dnl #
465 dnl # 1) Get QAT hardware statistics with:
466 dnl #    cat /proc/icp_dh895xcc_dev/qat
467 dnl # 2) To disable QAT:
468 dnl #    insmod zfs.ko zfs_qat_disable=1
469 dnl #
470 AC_DEFUN([ZFS_AC_QAT], [
471         AC_ARG_WITH([qat],
472                 AS_HELP_STRING([--with-qat=PATH],
473                 [Path to qat source]),
474                 AS_IF([test "$withval" = "yes"],
475                         AC_MSG_ERROR([--with-qat=PATH requires a PATH]),
476                         [qatsrc="$withval"]))
478         AC_ARG_WITH([qat-obj],
479                 AS_HELP_STRING([--with-qat-obj=PATH],
480                 [Path to qat build objects]),
481                 [qatbuild="$withval"])
483         AS_IF([test ! -z "${qatsrc}"], [
484                 AC_MSG_CHECKING([qat source directory])
485                 AC_MSG_RESULT([$qatsrc])
486                 QAT_SRC="${qatsrc}/quickassist"
487                 AS_IF([ test ! -e "$QAT_SRC/include/cpa.h"], [
488                         AC_MSG_ERROR([
489         *** Please make sure the qat driver package is installed
490         *** and specify the location of the qat source with the
491         *** '--with-qat=PATH' option then try again. Failed to
492         *** find cpa.h in:
493         ${QAT_SRC}/include])
494                 ])
495         ])
497         AS_IF([test ! -z "${qatsrc}"], [
498                 AC_MSG_CHECKING([qat build directory])
499                 AS_IF([test -z "$qatbuild"], [
500                         qatbuild="${qatsrc}/build"
501                 ])
503                 AC_MSG_RESULT([$qatbuild])
504                 QAT_OBJ=${qatbuild}
505                 AS_IF([ ! test -e "$QAT_OBJ/icp_qa_al.ko" && ! test -e "$QAT_OBJ/qat_api.ko"], [
506                         AC_MSG_ERROR([
507         *** Please make sure the qat driver is installed then try again.
508         *** Failed to find icp_qa_al.ko or qat_api.ko in:
509         $QAT_OBJ])
510                 ])
512                 AC_SUBST(QAT_SRC)
513                 AC_SUBST(QAT_OBJ)
515                 AC_DEFINE(HAVE_QAT, 1,
516                 [qat is enabled and existed])
517         ])
519         dnl #
520         dnl # Detect the name used for the QAT Module.symvers file.
521         dnl #
522         AS_IF([test ! -z "${qatsrc}"], [
523                 AC_MSG_CHECKING([qat file for module symbols])
524                 QAT_SYMBOLS=$QAT_SRC/lookaside/access_layer/src/Module.symvers
526                 AS_IF([test -r $QAT_SYMBOLS], [
527                         AC_MSG_RESULT([$QAT_SYMBOLS])
528                         AC_SUBST(QAT_SYMBOLS)
529                 ],[
530                         AC_MSG_ERROR([
531         *** Please make sure the qat driver is installed then try again.
532         *** Failed to find Module.symvers in:
533         $QAT_SYMBOLS
534                         ])
535                 ])
536         ])
539 dnl #
540 dnl # ZFS_LINUX_CONFTEST_H
541 dnl #
542 AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
543 test -d build/$2 || mkdir -p build/$2
544 cat - <<_ACEOF >build/$2/$2.h
546 _ACEOF
549 dnl #
550 dnl # ZFS_LINUX_CONFTEST_C
551 dnl #
552 AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
553 test -d build/$2 || mkdir -p build/$2
554 cat confdefs.h - <<_ACEOF >build/$2/$2.c
556 _ACEOF
559 dnl #
560 dnl # ZFS_LINUX_CONFTEST_MAKEFILE
561 dnl #
562 dnl # $1 - test case name
563 dnl # $2 - add to top-level Makefile
564 dnl # $3 - additional build flags
565 dnl #
566 AC_DEFUN([ZFS_LINUX_CONFTEST_MAKEFILE], [
567         test -d build || mkdir -p build
568         test -d build/$1 || mkdir -p build/$1
570         file=build/$1/Makefile
572         dnl # Example command line to manually build source.
573         cat - <<_ACEOF >$file
574 # Example command line to manually build source
575 # make modules -C $LINUX_OBJ $ARCH_UM M=$PWD/build/$1
577 ccflags-y := -Werror $FRAME_LARGER_THAN
578 _ACEOF
580         dnl # Additional custom CFLAGS as requested.
581         m4_ifval($3, [echo "ccflags-y += $3" >>$file], [])
583         dnl # Test case source
584         echo "obj-m := $1.o" >>$file
586         AS_IF([test "x$2" = "xyes"], [echo "obj-m += $1/" >>build/Makefile], [])
589 dnl #
590 dnl # ZFS_LINUX_TEST_PROGRAM(C)([PROLOGUE], [BODY])
591 dnl #
592 m4_define([ZFS_LINUX_TEST_PROGRAM], [
593 #include <linux/module.h>
597 main (void)
600         ;
601         return 0;
604 MODULE_DESCRIPTION("conftest");
605 MODULE_AUTHOR(ZFS_META_AUTHOR);
606 MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
607 MODULE_LICENSE($3);
610 dnl #
611 dnl # ZFS_LINUX_TEST_REMOVE
612 dnl #
613 dnl # Removes the specified test source and results.
614 dnl #
615 AC_DEFUN([ZFS_LINUX_TEST_REMOVE], [
616         test -d build/$1 && rm -Rf build/$1
617         test -f build/Makefile && sed '/$1/d' build/Makefile
620 dnl #
621 dnl # ZFS_LINUX_COMPILE
622 dnl #
623 dnl # $1 - build dir
624 dnl # $2 - test command
625 dnl # $3 - pass command
626 dnl # $4 - fail command
627 dnl # $5 - set KBUILD_MODPOST_NOFINAL='yes'
628 dnl # $6 - set KBUILD_MODPOST_WARN='yes'
629 dnl #
630 dnl # Used internally by ZFS_LINUX_TEST_{COMPILE,MODPOST}
631 dnl #
632 AC_DEFUN([ZFS_LINUX_COMPILE], [
633         AC_ARG_VAR([KERNEL_CC], [C compiler for
634                 building kernel modules])
635         AC_ARG_VAR([KERNEL_LD], [Linker for
636                 building kernel modules])
637         AC_ARG_VAR([KERNEL_LLVM], [Binary option to
638                 build kernel modules with LLVM/CLANG toolchain])
639         AC_TRY_COMMAND([
640             KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6"
641             make modules -k -j$TEST_JOBS ${KERNEL_CC:+CC=$KERNEL_CC}
642             ${KERNEL_LD:+LD=$KERNEL_LD} ${KERNEL_LLVM:+LLVM=$KERNEL_LLVM}
643             CONFIG_MODULES=y CFLAGS_MODULE=-DCONFIG_MODULES
644             -C $LINUX_OBJ $ARCH_UM M=$PWD/$1 >$1/build.log 2>&1])
645         AS_IF([AC_TRY_COMMAND([$2])], [$3], [$4])
648 dnl #
649 dnl # ZFS_LINUX_TEST_COMPILE
650 dnl #
651 dnl # Perform a full compile excluding the final modpost phase.
652 dnl #
653 AC_DEFUN([ZFS_LINUX_TEST_COMPILE], [
654         ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
655                 mv $2/Makefile $2/Makefile.compile.$1
656                 mv $2/build.log $2/build.log.$1
657         ],[
658                 AC_MSG_ERROR([
659         *** Unable to compile test source to determine kernel interfaces.])
660         ], [yes], [])
663 dnl #
664 dnl # ZFS_LINUX_TEST_MODPOST
665 dnl #
666 dnl # Perform a full compile including the modpost phase.  This may
667 dnl # be an incremental build if the objects have already been built.
668 dnl #
669 AC_DEFUN([ZFS_LINUX_TEST_MODPOST], [
670         ZFS_LINUX_COMPILE([$2], [test -f $2/build.log], [
671                 mv $2/Makefile $2/Makefile.modpost.$1
672                 cat $2/build.log >>build/build.log.$1
673         ],[
674                 AC_MSG_ERROR([
675         *** Unable to modpost test source to determine kernel interfaces.])
676         ], [], [yes])
679 dnl #
680 dnl # Perform the compilation of the test cases in two phases.
681 dnl #
682 dnl # Phase 1) attempt to build the object files for all of the tests
683 dnl #          defined by the ZFS_LINUX_TEST_SRC macro.  But do not
684 dnl #          perform the final modpost stage.
685 dnl #
686 dnl # Phase 2) disable all tests which failed the initial compilation,
687 dnl #          then invoke the final modpost step for the remaining tests.
688 dnl #
689 dnl # This allows us efficiently build the test cases in parallel while
690 dnl # remaining resilient to build failures which are expected when
691 dnl # detecting the available kernel interfaces.
692 dnl #
693 dnl # The maximum allowed parallelism can be controlled by setting the
694 dnl # TEST_JOBS environment variable.  Otherwise, it default to $(nproc).
695 dnl #
696 AC_DEFUN([ZFS_LINUX_TEST_COMPILE_ALL], [
697         dnl # Phase 1 - Compilation only, final linking is skipped.
698         ZFS_LINUX_TEST_COMPILE([$1], [build])
700         dnl #
701         dnl # Phase 2 - When building external modules disable test cases
702         dnl # which failed to compile and invoke modpost to verify the
703         dnl # final linking.
704         dnl #
705         dnl # Test names suffixed with '_license' call modpost independently
706         dnl # to ensure that a single incompatibility does not result in the
707         dnl # modpost phase exiting early.  This check is not performed on
708         dnl # every symbol since the majority are compatible and doing so
709         dnl # would significantly slow down this phase.
710         dnl #
711         dnl # When configuring for builtin (--enable-linux-builtin)
712         dnl # fake the linking step artificially create the expected .ko
713         dnl # files for tests which did compile.  This is required for
714         dnl # kernels which do not have loadable module support or have
715         dnl # not yet been built.
716         dnl #
717         AS_IF([test "x$enable_linux_builtin" = "xno"], [
718                 for dir in $(awk '/^obj-m/ { print [$]3 }' \
719                     build/Makefile.compile.$1); do
720                         name=${dir%/}
721                         AS_IF([test -f build/$name/$name.o], [
722                                 AS_IF([test "${name##*_}" = "license"], [
723                                         ZFS_LINUX_TEST_MODPOST([$1],
724                                             [build/$name])
725                                         echo "obj-n += $dir" >>build/Makefile
726                                 ], [
727                                         echo "obj-m += $dir" >>build/Makefile
728                                 ])
729                         ], [
730                                 echo "obj-n += $dir" >>build/Makefile
731                         ])
732                 done
734                 ZFS_LINUX_TEST_MODPOST([$1], [build])
735         ], [
736                 for dir in $(awk '/^obj-m/ { print [$]3 }' \
737                     build/Makefile.compile.$1); do
738                         name=${dir%/}
739                         AS_IF([test -f build/$name/$name.o], [
740                                 touch build/$name/$name.ko
741                         ])
742                 done
743         ])
746 dnl #
747 dnl # ZFS_LINUX_TEST_SRC
748 dnl #
749 dnl # $1 - name
750 dnl # $2 - global
751 dnl # $3 - source
752 dnl # $4 - extra cflags
753 dnl # $5 - check license-compatibility
754 dnl #
755 dnl # Check if the test source is buildable at all and then if it is
756 dnl # license compatible.
757 dnl #
758 dnl # N.B because all of the test cases are compiled in parallel they
759 dnl # must never depend on the results of previous tests.  Each test
760 dnl # needs to be entirely independent.
761 dnl #
762 AC_DEFUN([ZFS_LINUX_TEST_SRC], [
763         ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
764             [["Dual BSD/GPL"]])], [$1])
765         ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
767         AS_IF([ test -n "$5" ], [
768                 ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM(
769                     [[$2]], [[$3]], [[$5]])], [$1_license])
770                 ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
771         ])
774 dnl #
775 dnl # ZFS_LINUX_TEST_RESULT
776 dnl #
777 dnl # $1 - name of a test source (ZFS_LINUX_TEST_SRC)
778 dnl # $2 - run on success (valid .ko generated)
779 dnl # $3 - run on failure (unable to compile)
780 dnl #
781 AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
782         AS_IF([test -d build/$1], [
783                 AS_IF([test -f build/$1/$1.ko], [$2], [$3])
784         ], [
785                 AC_MSG_ERROR([
786         *** No matching source for the "$1" test, check that
787         *** both the test source and result macros refer to the same name.
788                 ])
789         ])
792 dnl #
793 dnl # ZFS_LINUX_TEST_ERROR
794 dnl #
795 dnl # Generic error message which can be used when none of the expected
796 dnl # kernel interfaces were detected.
797 dnl #
798 AC_DEFUN([ZFS_LINUX_TEST_ERROR], [
799         AC_MSG_ERROR([
800         *** None of the expected "$1" interfaces were detected.
801         *** This may be because your kernel version is newer than what is
802         *** supported, or you are using a patched custom kernel with
803         *** incompatible modifications.
804         ***
805         *** ZFS Version: $ZFS_META_ALIAS
806         *** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
807         ])
810 dnl #
811 dnl # ZFS_LINUX_TEST_RESULT_SYMBOL
812 dnl #
813 dnl # Like ZFS_LINUX_TEST_RESULT except ZFS_CHECK_SYMBOL_EXPORT is called to
814 dnl # verify symbol exports, unless --enable-linux-builtin was provided to
815 dnl # configure.
816 dnl #
817 AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
818         AS_IF([ ! test -f build/$1/$1.ko], [
819                 $5
820         ], [
821                 AS_IF([test "x$enable_linux_builtin" != "xyes"], [
822                         ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5])
823                 ], [
824                         $4
825                 ])
826         ])
829 dnl #
830 dnl # ZFS_LINUX_COMPILE_IFELSE
831 dnl #
832 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
833         ZFS_LINUX_TEST_REMOVE([conftest])
835         m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1], [conftest])])
836         m4_ifvaln([$5], [ZFS_LINUX_CONFTEST_H([$5], [conftest])],
837             [ZFS_LINUX_CONFTEST_H([], [conftest])])
839         ZFS_LINUX_CONFTEST_MAKEFILE([conftest], [no],
840             [m4_ifvaln([$5], [-I$PWD/build/conftest], [])])
841         ZFS_LINUX_COMPILE([build/conftest], [$2], [$3], [$4], [], [])
844 dnl #
845 dnl # ZFS_LINUX_TRY_COMPILE
846 dnl #
847 dnl # $1 - global
848 dnl # $2 - source
849 dnl # $3 - run on success (valid .ko generated)
850 dnl # $4 - run on failure (unable to compile)
851 dnl #
852 dnl # When configuring as builtin (--enable-linux-builtin) for kernels
853 dnl # without loadable module support (CONFIG_MODULES=n) only the object
854 dnl # file is created.  See ZFS_LINUX_TEST_COMPILE_ALL for details.
855 dnl #
856 AC_DEFUN([ZFS_LINUX_TRY_COMPILE], [
857         AS_IF([test "x$enable_linux_builtin" = "xyes"], [
858                 ZFS_LINUX_COMPILE_IFELSE(
859                     [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
860                     [[ZFS_META_LICENSE]])],
861                     [test -f build/conftest/conftest.o], [$3], [$4])
862         ], [
863                 ZFS_LINUX_COMPILE_IFELSE(
864                     [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
865                     [[ZFS_META_LICENSE]])],
866                     [test -f build/conftest/conftest.ko], [$3], [$4])
867         ])
870 dnl #
871 dnl # ZFS_CHECK_SYMBOL_EXPORT
872 dnl #
873 dnl # Check if a symbol is exported on not by consulting the symbols
874 dnl # file, or optionally the source code.
875 dnl #
876 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT], [
877         grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
878                 $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null
879         rc=$?
880         if test $rc -ne 0; then
881                 export=0
882                 for file in $2; do
883                         grep -q -E "EXPORT_SYMBOL.*($1)" \
884                                 "$LINUX/$file" 2>/dev/null
885                         rc=$?
886                         if test $rc -eq 0; then
887                                 export=1
888                                 break;
889                         fi
890                 done
891                 if test $export -eq 0; then :
892                         $4
893                 else :
894                         $3
895                 fi
896         else :
897                 $3
898         fi
901 dnl #
902 dnl # ZFS_LINUX_TRY_COMPILE_SYMBOL
903 dnl #
904 dnl # Like ZFS_LINUX_TRY_COMPILER except ZFS_CHECK_SYMBOL_EXPORT is called
905 dnl # to verify symbol exports, unless --enable-linux-builtin was provided
906 dnl # to configure.
907 dnl #
908 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
909         ZFS_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
910         if test $rc -ne 0; then :
911                 $6
912         else
913                 if test "x$enable_linux_builtin" != xyes; then
914                         ZFS_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
915                 fi
916                 if test $rc -ne 0; then :
917                         $6
918                 else :
919                         $5
920                 fi
921         fi
924 dnl #
925 dnl # ZFS_LINUX_TRY_COMPILE_HEADER
926 dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
927 dnl # provided via the fifth parameter
928 dnl #
929 AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER], [
930         AS_IF([test "x$enable_linux_builtin" = "xyes"], [
931                 ZFS_LINUX_COMPILE_IFELSE(
932                     [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
933                     [[ZFS_META_LICENSE]])],
934                     [test -f build/conftest/conftest.o], [$3], [$4], [$5])
935         ], [
936                 ZFS_LINUX_COMPILE_IFELSE(
937                     [ZFS_LINUX_TEST_PROGRAM([[$1]], [[$2]],
938                     [[ZFS_META_LICENSE]])],
939                     [test -f build/conftest/conftest.ko], [$3], [$4], [$5])
940         ])
943 dnl #
944 dnl # AS_VERSION_COMPARE_LE
945 dnl # like AS_VERSION_COMPARE_LE, but runs $3 if (and only if) $1 <= $2
946 dnl # AS_VERSION_COMPARE_LE (version-1, version-2, [action-if-less-or-equal], [action-if-greater])
947 dnl #
948 AC_DEFUN([AS_VERSION_COMPARE_LE], [
949         AS_VERSION_COMPARE([$1], [$2], [$3], [$3], [$4])
952 dnl #
953 dnl # ZFS_LINUX_REQUIRE_API
954 dnl # like ZFS_LINUX_TEST_ERROR, except only fails if the kernel is
955 dnl # at least some specified version.
956 dnl #
957 AC_DEFUN([ZFS_LINUX_REQUIRE_API], [
958         AS_VERSION_COMPARE_LE([$2], [$kernsrcver], [
959                 AC_MSG_ERROR([
960                 *** None of the expected "$1" interfaces were detected. This
961                 *** interface is expected for kernels version "$2" and above.
962                 *** This may be because your kernel version is newer than what is
963                 *** supported, or you are using a patched custom kernel with
964                 *** incompatible modifications.  Newer kernels may have incompatible
965                 *** APIs.
966                 ***
967                 *** ZFS Version: $ZFS_META_ALIAS
968                 *** Compatible Kernels: $ZFS_META_KVER_MIN - $ZFS_META_KVER_MAX
969                 ])
970         ], [
971                 AC_MSG_RESULT(no)
972         ])