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