在 2019年01月10日 04:38, Kazuhito Hagio 写道:
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 to happen 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 <k-hagio(a)ab.jp.nec.com>
Cc: Dave Young <dyoung(a)redhat.com>
Cc: Lianbo Jiang <lijiang(a)redhat.com>
---
kdump-lib-initramfs.sh | 13 +++++++++++++
kdump.conf | 5 +++++
kdump.conf.5 | 6 ++++++
kdumpctl | 22 +++++++++++++++++++++-
4 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
index f5155a4..9f482cd 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
Thanks for your patch.
Once dumping fails, it will switch to the kdump-error-handler.sh, but this script always
calls
the do_default_action() first, and then executes the final action. Because the default is
always
'reboot' in case the 'default' is not set in '/etc/kdump.conf', so
the final action could have no
chance to execute. Unless we set 'default poweroff' and 'final_action
poweroff' together.
Not sure whether it would be more better like this:
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
index 7ba99b6..953b8bc 100755
--- a/kdump-lib-initramfs.sh
+++ b/kdump-lib-initramfs.sh
@@ -6,7 +6,7 @@ KDUMP_PATH="/var/crash"
CORE_COLLECTOR=""
DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
DMESG_COLLECTOR="/sbin/vmcore-dmesg"
-DEFAULT_ACTION="systemctl reboot -f"
+DEFAULT_ACTION=""
do_default_action()
{
- echo "Kdump: Executing default action $DEFAULT_ACTION"
- eval $DEFAULT_ACTION
+ if [ "$DEFAULT_ACTION" == "" ]; then
+ echo "Kdump: default action is not set."
+ else
+ echo "Kdump: Executing default action $DEFAULT_ACTION"
+ eval $DEFAULT_ACTION
+ fi
}
It makes sure that the final action can be called in case user doesn't set the
'default poweroff'
and dumping failure.
Thanks
Lianbo
> diff --git a/kdump.conf b/kdump.conf
> index 286ad27..6643e87 100644
> --- a/kdump.conf
> +++ b/kdump.conf
> @@ -110,6 +110,11 @@
> # reboot. Useful when non-root dump target is specified.
> # The default option is "reboot".
> #
> +# final_action <reboot | halt | poweroff>
> +# - Action to perform in case dumping succeeds.
> +# Each action is same as the "default" 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 990076e..72995c4 100644
> --- a/kdump.conf.5
> +++ b/kdump.conf.5
> @@ -160,6 +160,12 @@ target is specified, the default action can be set as
dump_to_rootfs. That mean
> dumping to target fails, dump vmcore to rootfs from initramfs context and reboot.
> .RE
>
> +.B final_action <reboot | halt | poweroff>
> +.RS
> +Action to perform in case dumping to the intended target succeeds. The default is
> +"reboot". Each action is same as the "default" directive above.
> +.RE
> +
> .B force_rebuild <0 | 1>
> .RS
> By default, kdump initrd will only be rebuilt when necessary.
> diff --git a/kdumpctl b/kdumpctl
> index ca47705..992aaa8 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|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|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_default_config || return 1
> + check_final_action_config || return 1
>
> check_fence_kdump_config || return 1
>
> @@ -954,6 +955,25 @@ check_default_config()
> fi
> }
>
> +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
>