From 78e9625b62fee387e65f6b5a79d5a18f36046259 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 13 Jun 2023 17:43:21 +0800 Subject: [PATCH] kdump-lib: Introduce parse_kver_from_path() to get kernel version from its path name Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2160676 Upstream: Fedora rawhide Conflict: None commit d8b961be37de09289a2ffff8c9c51cca4d153a92 Author: Pingfan Liu Date: Tue Jun 13 17:43:21 2023 +0800 kdump-lib: Introduce parse_kver_from_path() to get kernel version from its path name kdump_get_arch_recommend_crashkernel() expects the kernel version info, while _update_kernel() provides the absolute path, which contains the kernel version info. This patch introduce a dedicated function parse_kver_from_path() to extract the kernel info from the path Credit to Philipp, who contributes the original code. Signed-off-by: Pingfan Liu Reviewed-by: Coiby Xu Reviewed-by: Philipp Rudo Signed-off-by: Pingfan Liu --- kdump-lib.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 6009360..e15ec22 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -648,6 +648,49 @@ prepare_kdump_kernel() echo "$kdump_kernel" } +_is_valid_kver() +{ + [[ -f /usr/lib/modules/$1/modules.dep ]] +} + +# This function is introduced since 64k variant may be installed on 4k or vice versa +# $1 the kernel path name. +parse_kver_from_path() +{ + local _img _kver + + [[ -z "$1" ]] && return + + _img=$1 + BLS_ENTRY_TOKEN=$( + _kver=${_img##*/vmlinuz-} + _kver=${_kver%"$KDUMP_IMG_EXT"} + if _is_valid_kver "$_kver"; then + echo "$_kver" + return + fi + + # BLS recommended image names, i.e. $BOOT///linux + _kver=${_img##*/"$BLS_ENTRY_TOKEN"/} + _kver=${_kver%%/*} + if _is_valid_kver "$_kver"; then + echo "$_kver" + return + fi + + # Fedora UKI installation, i.e. $BOOT/efi/EFI/Linux/-.efi + _kver=${_img##*/"$BLS_ENTRY_TOKEN"-} + _kver=${_kver%.efi} + if _is_valid_kver "$_kver"; then + echo "$_kver" + return + fi + + ddebug "Could not parse version from $_img" +} + _get_kdump_kernel_version() { local _version _version_nondebug