From 4454163cb4c56a7d90e96438b1c523c137192382 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Wed, 7 Jun 2023 11:59:24 +0800 Subject: [PATCH] kdump-lib: always specify version in is_squash_available Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2165839 Upstream: Fedora Conflict: None commit 88919b73f01ed630843893b0fcf4fec57b91ac22 Author: Philipp Rudo Date: Thu Jan 12 16:31:04 2023 +0100 kdump-lib: always specify version in is_squash_available is_squash_available is only used in dracut-module-setup.sh and mkdumprd. Neither of the two scripts calls prepare_kdump_bootinfo which determines and sets KDUMP_KERNELVER. Thus KDUMP_KERNELVER is only non-zero if it explicitly specified by the user in /etc/sysconfig/kdump (and the file gets sourced, which is not the case for drachu-module-setup.sh). In theory this can even lead to bugs. For example consider the case when a debug kernel is running. In that case kdumpctl will try to use the non-debug version of the kernel while is_squash_available will make its decision based on the debug version. So in case the debug kernel has squash available but the non-debug kernel doesn't mkdumprd will try to add it nevertheless. Thus factor out the kernel version detection from prepare_kdump_bootinfo and make use of the new function when checking for the availability of those kernel modules. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu Signed-off-by: Pingfan Liu --- kdump-lib.sh | 64 +++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 5b58953..6fcf9fa 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -31,12 +31,11 @@ is_fadump_capable() is_squash_available() { + local _version kmodule + + _version=$(_get_kdump_kernel_version) for kmodule in squashfs overlay loop; do - if [[ -z $KDUMP_KERNELVER ]]; then - modprobe --dry-run $kmodule &> /dev/null || return 1 - else - modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &> /dev/null || return 1 - fi + modprobe -S "$_version" --dry-run $kmodule &> /dev/null || return 1 done } @@ -649,6 +648,31 @@ prepare_kdump_kernel() echo "$kdump_kernel" } +_get_kdump_kernel_version() +{ + local _version _version_nondebug + + if [[ -n "$KDUMP_KERNELVER" ]]; then + echo "$KDUMP_KERNELVER" + return + fi + + _version=$(uname -r) + if [[ ! "$_version" =~ \+debug$ ]]; then + echo "$_version" + return + fi + + _version_nondebug=${_version%+debug} + if [[ -f "$(prepare_kdump_kernel "$_version_nondebug")" ]]; then + dinfo "Use of debug kernel detected. Trying to use $_version_nondebug" + echo "$_version_nondebug" + else + dinfo "Use of debug kernel detected but cannot find $_version_nondebug. Falling back to $_version" + echo "$_version" + fi +} + # # Detect initrd and kernel location, results are stored in global environmental variables: # KDUMP_BOOTDIR, KDUMP_KERNELVER, KDUMP_KERNEL, DEFAULT_INITRD, and KDUMP_INITRD @@ -658,37 +682,11 @@ prepare_kdump_kernel() # prepare_kdump_bootinfo() { - local boot_initrdlist nondebug_kernelver debug_kernelver - local default_initrd_base var_target_initrd_dir - - if [[ -z $KDUMP_KERNELVER ]]; then - KDUMP_KERNELVER=$(uname -r) - - # Fadump uses the regular bootloader, unlike kdump. So, use the same version - # for default kernel and capture kernel unless specified explicitly with - # KDUMP_KERNELVER option. - if ! is_fadump_capable; then - nondebug_kernelver=$(sed -n -e 's/\(.*\)+debug$/\1/p' <<< "$KDUMP_KERNELVER") - fi - fi - - # Use nondebug kernel if possible, because debug kernel will consume more memory and may oom. - if [[ -n $nondebug_kernelver ]]; then - dinfo "Trying to use $nondebug_kernelver." - debug_kernelver=$KDUMP_KERNELVER - KDUMP_KERNELVER=$nondebug_kernelver - fi + local boot_initrdlist default_initrd_base var_target_initrd_dir + KDUMP_KERNELVER=$(_get_kdump_kernel_version) KDUMP_KERNEL=$(prepare_kdump_kernel "$KDUMP_KERNELVER") - if ! [[ -e $KDUMP_KERNEL ]]; then - if [[ -n $debug_kernelver ]]; then - dinfo "Fallback to using debug kernel" - KDUMP_KERNELVER=$debug_kernelver - KDUMP_KERNEL=$(prepare_kdump_kernel "$KDUMP_KERNELVER") - fi - fi - if ! [[ -e $KDUMP_KERNEL ]]; then derror "Failed to detect kdump kernel location" return 1