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