Hi Coiby,
nice patch!
On Tue, 9 May 2023 15:01:39 +0800
Coiby Xu <coxu(a)redhat.com> wrote:
Currently, kexec-tools only updates the crashkernel to a new default
value only when both two conditions are met,
- auto_reset_crashkernel=yes in kdump.conf
- existing kernels or current running kernel should use the old default
value.
To address seen corner cases, the logic to tell if the second condition
is met becomes quite complex. Instead of making the logic more complex
to support aarch64-64k, this patch drops the second condition to
simplify the management of the crashkernel kernel parameter.
Note this patch also stop trying to update /etc/default/grub because
1) it only affects the static file /boot/grub2/grub.cfg
2) grubby is recommended to change the kernel command-line parameters
for both Fedora [1] and RHEL9 [2][3]
3) For the cases of aarch64 and POWER, different kernels could have
different default crashkernel value.
[1]
https://fedoraproject.org/wiki/GRUB_2
[2]
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/...
[3]
https://access.redhat.com/solutions/1136173
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kdump.conf.5 | 5 ++-
kdumpctl | 89 +++++++++++-------------------------------------
kexec-tools.spec | 21 ------------
3 files changed, 21 insertions(+), 94 deletions(-)
diff --git a/kdump.conf.5 b/kdump.conf.5
index e3e9900b..ec285524 100644
--- a/kdump.conf.5
+++ b/kdump.conf.5
@@ -28,9 +28,8 @@ understand how this configuration file affects the behavior of kdump.
.B auto_reset_crashkernel <yes|no>
.RS
-determine whether to reset kernel crashkernel to new default value
-or not when kexec-tools updates the default crashkernel value and
-existing kernels using the old default kernel crashkernel value
+determine whether to reset kernel crashkernel parameter to the default value
+or not when kexec-tools is updated or a new kernel is installed.
.B raw <partition>
.RS
diff --git a/kdumpctl b/kdumpctl
index edcf2caf..6e66e7bb 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1585,72 +1585,36 @@ _is_bootloader_installed()
fi
}
-# update the crashkernel value in GRUB_ETC_DEFAULT if necessary
-#
-# called by reset_crashkernel_after_update and inherit its array variable
-# _crashkernel_vals
-update_crashkernel_in_grub_etc_default_after_update()
-{
- local _crashkernel _fadump_val
- local _dump_mode _old_default_crashkernel _new_default_crashkernel
-
- if [[ $(uname -m) == s390x ]]; then
- return
- fi
-
- _crashkernel=$(_read_kernel_arg_in_grub_etc_default crashkernel)
I think with this patch there is no more user of
_read_kernel_arg_in_grub_etc_default. You can remove this as well.
-
- if [[ -z $_crashkernel ]]; then
- return
- fi
-
- _fadump_val=$(_read_kernel_arg_in_grub_etc_default fadump)
- _dump_mode=$(get_dump_mode_by_fadump_val "$_fadump_val")
-
- _old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]}
- _new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]}
-
- if [[ $_crashkernel == auto ]] ||
- [[ $_crashkernel == "$_old_default_crashkernel" &&
- $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then
- _update_kernel_arg_in_grub_etc_default crashkernel
"$_new_default_crashkernel"
+_update_crashkernel()
+{
+ local _kernel _dump_mode _old_default_crashkernel _new_default_crashkernel _fadump_val
+
+ _kernel=$1
+ _dump_mode=$(get_dump_mode_by_kernel "$_kernel")
+ _old_default_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel"
crashkernel)
+ _new_default_crashkernel=$(kdump_get_arch_recommend_crashkernel
"$_dump_mode")
+ if [[ $_old_default_crashkernel != "$_new_default_crashkernel" ]]; then
+ _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump)
+ if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel"
"$_dump_mode" "$_fadump_val"; then
+ echo -n "For kernel=$_kernel, crashkernel=$_new_default_crashkernel now. Please
reboot the system for the change to take effet."
+ echo " Note if you don't want kexec-tools to manage the crashkernel kernel
parameter, please set auto_reset_crashkernel=no in /etc/kdump.conf."
+ fi
fi
}
+
# shellcheck disable=SC2154 # false positive when dereferencing an array
^^^^^^^^^^^^^^^^^^^^^^^^^
Is this still needed with your change?
Thanks
Philipp
reset_crashkernel_after_update()
{
- local _kernel _crashkernel _dump_mode _fadump_val _old_default_crashkernel
_new_default_crashkernel
- declare -A _crashkernel_vals
+ local _kernel
if ! _is_bootloader_installed; then
return
fi
- _crashkernel_vals[old_kdump]=$(cat /tmp/old_default_crashkernel 2> /dev/null)
- _crashkernel_vals[old_fadump]=$(cat /tmp/old_default_crashkernel_fadump 2>
/dev/null)
- _crashkernel_vals[new_kdump]=$(get_default_crashkernel kdump)
- _crashkernel_vals[new_fadump]=$(get_default_crashkernel fadump)
-
for _kernel in $(_get_all_kernels_from_grubby ALL); do
- _crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel)
- if [[ $_crashkernel == auto ]]; then
- reset_crashkernel "--kernel=$_kernel"
- elif [[ -n $_crashkernel ]]; then
- _dump_mode=$(get_dump_mode_by_kernel "$_kernel")
- _old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]}
- _new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]}
- if [[ $_crashkernel == "$_old_default_crashkernel" ]] &&
- [[ $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then
- _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump)
- if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel"
"$_dump_mode" "$_fadump_val"; then
- echo "For kernel=$_kernel, crashkernel=$_new_default_crashkernel now."
- fi
- fi
- fi
+ _update_crashkernel "$_kernel"
done
-
- update_crashkernel_in_grub_etc_default_after_update
}
# read the value of an environ variable from given environ file path
@@ -1674,8 +1638,7 @@ _is_osbuild()
reset_crashkernel_for_installed_kernel()
{
- local _installed_kernel _running_kernel _crashkernel _crashkernel_running
- local _dump_mode_running _fadump_val_running
+ local _installed_kernel
# During package install, only try to reset crashkernel for osbuild
# thus to avoid calling grubby when installing os via anaconda
@@ -1694,21 +1657,7 @@ reset_crashkernel_for_installed_kernel()
return
fi
- if ! _running_kernel=$(_get_current_running_kernel_path); then
- ddebug "Couldn't find current running kernel"
- exit
- fi
-
- _crashkernel=$(get_grub_kernel_boot_parameter "$_installed_kernel"
crashkernel)
- _crashkernel_running=$(get_grub_kernel_boot_parameter "$_running_kernel"
crashkernel)
- _dump_mode_running=$(get_dump_mode_by_kernel "$_running_kernel")
- _fadump_val_running=$(get_grub_kernel_boot_parameter "$_kernel" fadump)
-
- if [[ $_crashkernel != "$_crashkernel_running" ]]; then
- if _update_kernel_cmdline "$_installed_kernel"
"$_crashkernel_running" "$_dump_mode_running"
"$_fadump_val_running"; then
- echo "kexec-tools has reset $_installed_kernel to use the new default
crashkernel value $_crashkernel_running"
- fi
- fi
+ _update_crashkernel "$_installed_kernel"
}
main()
diff --git a/kexec-tools.spec b/kexec-tools.spec
index d2a8aca9..06f87dd0 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -259,21 +259,6 @@ chmod 755
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpini
mkdir -p $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/
mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/*
$RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/
-%pre
-# Save the old default crashkernel values to /tmp/ when upgrading the package
-# so kdumpctl later can tell if it should update the kernel crashkernel
-# parameter in the posttrans scriptlet. Note this feauture of auto-updating
-# the kernel crashkernel parameter currently doesn't support ostree, so skip it
-# for ostree.
-if [ ! -f /run/ostree-booted ] && [ $1 == 2 ] && grep -q
get-default-crashkernel /usr/bin/kdumpctl; then
- kdumpctl get-default-crashkernel kdump > /tmp/old_default_crashkernel
2>/dev/null
-%ifarch ppc64 ppc64le
- kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump
2>/dev/null
-%endif
-fi
-# don't block package update
-:
-
%post
# Initial installation
%systemd_post kdump.service
@@ -349,12 +334,6 @@ done
# former case is used to set up crashkernel for osbuild
if [ ! -f /run/ostree-booted ] && [ $1 == 1 ]; then
kdumpctl _reset-crashkernel-after-update
- rm /tmp/old_default_crashkernel 2>/dev/null
-%ifarch ppc64 ppc64le
- rm /tmp/old_default_crashkernel_fadump 2>/dev/null
-%endif
- # dnf would complain about the exit code not being 0. To keep it happy,
- # always return 0
:
fi