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