From 242da37c5829e6306fd71065918ea5ce47d57f9c Mon Sep 17 00:00:00 2001 From: Kazuhito Hagio Date: Thu, 17 Jan 2019 15:31:24 -0500 Subject: [PATCH] Add final_action option to kdump.conf If a crash occurs repeatedly after enabling kdump, the system goes into a crash loop and the dump target may get filled up by vmcores. This is likely especially with early kdump. This patch introduces 'final_action' option to kdump.conf, in order for users to be able to power off the system even after capturing a vmcore successfully. Signed-off-by: Kazuhito Hagio Cc: Dave Young Cc: Lianbo Jiang Cc: Bhupesh Sharma Acked-by: Bhupesh Sharma Acked-by: Dave Young Signed-off-by: Kairui Song --- fadump-howto.txt | 3 ++- kdump-lib-initramfs.sh | 13 +++++++++++++ kdump.conf | 12 ++++++++++-- kdump.conf.5 | 14 ++++++++++++-- kdumpctl | 22 +++++++++++++++++++++- 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/fadump-howto.txt b/fadump-howto.txt index 2730f4b..7061f02 100644 --- a/fadump-howto.txt +++ b/fadump-howto.txt @@ -73,7 +73,8 @@ The control flow of fadump works as follows: 10. Is dump capture successful (yes goto 12, no goto 11) 11. Perform the failure action specified in /etc/kdump.conf (The default failure action is reboot, if unspecified) -12. Reboot +12. Perform the final action specified in /etc/kdump.conf + (The default final action is reboot, if unspecified) How to configure fadump: diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 8df2b6c..d6c01d1 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -70,6 +70,19 @@ get_kdump_confs() ;; esac ;; + final_action) + case $config_val in + reboot) + FINAL_ACTION="systemctl reboot -f" + ;; + halt) + FINAL_ACTION="halt" + ;; + poweroff) + FINAL_ACTION="systemctl poweroff -f" + ;; + esac + ;; esac done < $KDUMP_CONF diff --git a/kdump.conf b/kdump.conf index 1c7408a..1f0fc2d 100644 --- a/kdump.conf +++ b/kdump.conf @@ -105,15 +105,23 @@ # halt: Halt the system. # poweroff: Power down the system. # shell: Drop to a bash shell. -# Exiting the shell reboots the system. +# Exiting the shell reboots the system by default, +# or perform "final_action". # dump_to_rootfs: Dump vmcore to rootfs from initramfs context and -# reboot. Useful when non-root dump target is specified. +# reboot by default or perform "final_action". +# Useful when non-root dump target is specified. # The default option is "reboot". # # default # - Same as the "failure_action" directive above, but this directive # is obsolete and will be removed in the future. # +# final_action +# - Action to perform in case dumping succeeds. Also performed +# when "shell" or "dump_to_rootfs" failure action finishes. +# Each action is same as the "failure_action" directive above. +# The default is "reboot". +# # force_rebuild <0 | 1> # - By default, kdump initrd will only be rebuilt when necessary. # Specify 1 to force rebuilding kdump initrd every time when kdump diff --git a/kdump.conf.5 b/kdump.conf.5 index c7098c9..5a0952b 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -155,9 +155,11 @@ reboot: Reboot the system (this is what most people will want, as it returns the to a normal state). halt: Halt the system and lose the vmcore. poweroff: The system will be powered down. shell: Drop to a shell session inside the initramfs, from which you can manually perform additional recovery actions. Exiting this shell reboots the -system. Note: kdump uses bash as the default shell. dump_to_rootfs: If non-root dump +system by default or performs "final_action". +Note: kdump uses bash as the default shell. dump_to_rootfs: If non-root dump target is specified, the failure action can be set as dump_to_rootfs. That means when -dumping to target fails, dump vmcore to rootfs from initramfs context and reboot. +dumping to target fails, dump vmcore to rootfs from initramfs context and reboot +by default or perform "final_action". .RE .B default @@ -166,6 +168,14 @@ Same as the "failure_action" directive above, but this directive is obsolete and will be removed in the future. .RE +.B final_action +.RS +Action to perform in case dumping to the intended target succeeds. +Also performed when "shell" or "dump_to_rootfs" failure action finishes. +Each action is same as the "failure_action" directive above. +The default is "reboot". +.RE + .B force_rebuild <0 | 1> .RS By default, kdump initrd will only be rebuilt when necessary. diff --git a/kdumpctl b/kdumpctl index 25d9c28..de6da39 100755 --- a/kdumpctl +++ b/kdumpctl @@ -228,7 +228,7 @@ check_config() case "$config_opt" in \#* | "") ;; - raw|ext2|ext3|ext4|minix|btrfs|xfs|nfs|ssh|sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|failure_action|default|force_rebuild|force_no_rebuild|dracut_args|fence_kdump_args|fence_kdump_nodes) + raw|ext2|ext3|ext4|minix|btrfs|xfs|nfs|ssh|sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|failure_action|default|final_action|force_rebuild|force_no_rebuild|dracut_args|fence_kdump_args|fence_kdump_nodes) # remove inline comments after the end of a directive. config_val=$(strip_comments $config_val) [ -z "$config_val" ] && { @@ -248,6 +248,7 @@ check_config() done < $KDUMP_CONFIG_FILE check_failure_action_config || return 1 + check_final_action_config || return 1 check_fence_kdump_config || return 1 @@ -966,6 +967,25 @@ check_failure_action_config() esac } +check_final_action_config() +{ + local final_action + + final_action=$(awk '$1 ~ /^final_action$/ {print $2;}' $KDUMP_CONFIG_FILE) + if [ -z "$final_action" ]; then + return 0 + else + case "$final_action" in + reboot|halt|poweroff) + return 0 + ;; + *) + echo $"Usage kdump.conf: final_action {reboot|halt|poweroff}" + return 1 + esac + fi +} + start() { check_dump_feasibility