config: cache results of kernel checks (#17106)

Kernel checks are the heaviest part of the configure checks. This allows
the results to be cached through the normal autoconf cache.

Since we don't want to reuse cached values for different kernels, but
don't want to discard the entire cache on every kernel, we instead add a
short checksum to kernel config cache keys, based on the version and
path, so the cache can hold results for multiple different kernels.

Sponsored-by: https://despairlabs.com/sponsor/

Signed-off-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
This commit is contained in:
Rob Norris 2025-03-28 10:44:54 +11:00 committed by Tony Hutter
parent e6f8c1f612
commit 76bd2ae5c8

View File

@ -465,6 +465,11 @@ AC_DEFUN([ZFS_AC_KERNEL], [
AC_SUBST(LINUX)
AC_SUBST(LINUX_OBJ)
AC_SUBST(LINUX_VERSION)
dnl # create a relatively unique numeric checksum based on the kernel
dnl # version and path. this is included in the cache key below,
dnl # allowing different cached values for different kernels
_zfs_linux_cache_checksum=$(echo ${kernelsrc} {$kernelbuild} ${kernsrcver} | cksum | cut -f1 -d' ')
])
AC_DEFUN([ZFS_AC_KERNEL_VERSION_WARNING], [
@ -812,6 +817,9 @@ dnl # must never depend on the results of previous tests. Each test
dnl # needs to be entirely independent.
dnl #
AC_DEFUN([ZFS_LINUX_TEST_SRC], [
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
eval "cacheval=\$$cachevar"
AS_IF([test "x$cacheval" = "x"], [
ZFS_LINUX_CONFTEST_C([ZFS_LINUX_TEST_PROGRAM([[$2]], [[$3]],
[["Dual BSD/GPL"]])], [$1])
ZFS_LINUX_CONFTEST_MAKEFILE([$1], [yes], [$4])
@ -822,6 +830,7 @@ AC_DEFUN([ZFS_LINUX_TEST_SRC], [
ZFS_LINUX_CONFTEST_MAKEFILE([$1_license], [yes], [$4])
])
])
])
dnl #
dnl # ZFS_LINUX_TEST_RESULT
@ -831,8 +840,14 @@ dnl # $2 - run on success (valid .ko generated)
dnl # $3 - run on failure (unable to compile)
dnl #
AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
AC_CACHE_VAL([$cachevar], [
AS_IF([test -d build/$1], [
AS_IF([test -f build/$1/$1.ko], [$2], [$3])
AS_IF([test -f build/$1/$1.ko], [
eval "$cachevar=yes"
], [
eval "$cachevar=no"
])
], [
AC_MSG_ERROR([
*** No matching source for the "$1" test, check that
@ -840,6 +855,9 @@ AC_DEFUN([ZFS_LINUX_TEST_RESULT], [
])
])
])
eval "cacheval=\$$cachevar"
AS_IF([test "x$cacheval" = "xyes"], [$2], [$3])
])
dnl #
dnl # ZFS_LINUX_TEST_ERROR
@ -867,16 +885,25 @@ dnl # verify symbol exports, unless --enable-linux-builtin was provided to
dnl # configure.
dnl #
AC_DEFUN([ZFS_LINUX_TEST_RESULT_SYMBOL], [
cachevar="zfs_cv_kernel_[$1]_$_zfs_linux_cache_checksum"
AC_CACHE_VAL([$cachevar], [
AS_IF([ ! test -f build/$1/$1.ko], [
$5
eval "$cachevar=no"
], [
AS_IF([test "x$enable_linux_builtin" != "xyes"], [
ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [$4], [$5])
ZFS_CHECK_SYMBOL_EXPORT([$2], [$3], [
eval "$cachevar=yes"
], [
$4
eval "$cachevar=no"
])
], [
eval "$cacheval=yes"
])
])
])
eval "cacheval=\$$cachevar"
AS_IF([test "x$cacheval" = "xyes"], [$4], [$5])
])
dnl #
dnl # ZFS_LINUX_COMPILE_IFELSE