From 8ebf2874a202a2d7116a27c69816b8621ace5224 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 1 Jun 2023 17:04:13 +0200 Subject: [PATCH 3/7] kdumpctl: Simplify fadump handling in reset_crashkernel When handling fadump there are three cases we need to consider 1) When running on non-ppc64le systems In this case _dump_mode=kdump and _new_fadump='' always. In other words we don't need to care updating the fadump parameter on the kernel command line. We could always remove it like the code did so far. But should we remove it when we never set it? In particular as that might overwrite a change explicitly made by the user (for whatever reason) 2) When running on ppc64le and the user provided --fadump option In this case _new_fadump and _dump_mode are set accordingly to what the user provided. Thus we need to update both the crashkernel (in case fadump was turned on/off) and the fadump (in case the fadump mode changed) parameters. 3) When running on ppc64le but the user did not provide --fadump option In this case both _new_fadump='' and _dump_mode=''. In this case we take over the previously set fadump parameter. Which means that we don't need to update the fadump parameter at all. We do need to check whether the _new_dump_mode is fadump or kdump though so we use the correct (new) default crashkernel value. In the three cases only the second one needs to update the fadump parameter. Reflect this discussion in code. This also fixes a bug that always prints kdump: Updated fadump= for kernel=$kernel. Please reboot the system for the change to take effect. when the crashkernel= parameter is unchanged as well as reboots the system, if --reboot is provided. Even for non-ppc architectures. Fixes: 140da74 ("rewrite reset_crashkernel to support fadump and to used by RPM scriptlet") Signed-off-by: Philipp Rudo --- kdumpctl | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/kdumpctl b/kdumpctl index 8dc56e5..8ec638b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1467,10 +1467,10 @@ _get_all_kernels_from_grubby() reset_crashkernel() { local _opt _val _reboot _grubby_kernel_path _kernel _kernels - local _dump_mode _new_dump_mode + local _dump_mode local _has_changed _needs_reboot local _old_ck _new_ck - local _old_fadump _new_fadump + local _old_fadump _new_fadump _opt_fadump for _opt in "$@"; do case "$_opt" in @@ -1479,12 +1479,11 @@ reset_crashkernel() derror "Option --fadump only valid on PPC" exit 1 fi - _new_fadump=${_opt#*=} - if ! _dump_mode=$(get_dump_mode_by_fadump_val $_new_fadump); then + _opt_fadump=${_opt#*=} + if ! _dump_mode=$(get_dump_mode_by_fadump_val $_opt_fadump); then derror "failed to determine dump mode" exit fi - [[ "$_new_fadump" == off ]] && _new_fadump="" ;; --kernel=*) _val=${_opt#*=} @@ -1519,8 +1518,6 @@ reset_crashkernel() return fi - [[ $(uname -m) != ppc64le ]] && _dump_mode=kdump - # If kernel-path not specified, either # - use KDUMP_KERNELVER if it's defined # - use current running kernel @@ -1536,19 +1533,28 @@ reset_crashkernel() for _kernel in $_kernels; do _has_changed="" - if [[ -z $_dump_mode ]]; then - _new_dump_mode=$(get_dump_mode_by_kernel "$_kernel") - _new_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + if [[ $(uname -m) == ppc64le ]]; then + if [[ -n "$_opt_fadump" ]]; then + _new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode") + _old_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + _new_fadump="$_opt_fadump" + [[ "$_new_fadump" == off ]] && _new_fadump="" + if _update_kernel_cmdline "$_kernel" fadump "$_old_fadump" "$_new_fadump"; then + if [[ -n "$_new_fadump" ]]; then + _has_changed="Updated fadump=$_new_fadump" + else + _has_changed="Removed fadump" + fi + fi + else + _dump_mode="$(get_dump_mode_by_kernel "$_kernel")" + _new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode") + fi else - _new_dump_mode=$_dump_mode + _new_ck=$(kdump_get_arch_recommend_crashkernel kdump) fi _old_ck=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) - _new_ck=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") - _old_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump) - if _update_kernel_cmdline "$_kernel" fadump "$_old_fadump" "$_new_fadump"; then - _has_changed="Updated fadump=$_new_fadump" - fi if _update_kernel_cmdline "$_kernel" crashkernel "$_old_ck" "$_new_ck"; then _has_changed="Updated crashkernel=$_new_ck" fi -- 2.45.2