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