diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh index 45ee6dc..2a8652e 100755 --- a/dracut-early-kdump.sh +++ b/dracut-early-kdump.sh @@ -38,7 +38,7 @@ early_kdump_load() return 1 fi - if check_current_kdump_status; then + if is_kernel_loaded "kdump"; then return 1 fi diff --git a/kdump-lib.sh b/kdump-lib.sh index 27e2154..de74491 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -6,6 +6,7 @@ . /usr/lib/kdump/kdump-lib-initramfs.sh FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" +FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" is_uki() { @@ -501,19 +502,31 @@ check_kdump_feasibility() return $? } -check_current_kdump_status() +is_kernel_loaded() { - if [[ ! -f /sys/kernel/kexec_crash_loaded ]]; then - derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel" - return 1 - fi + local _sysfs _mode - rc=$(< /sys/kernel/kexec_crash_loaded) - if [[ $rc == 1 ]]; then - return 0 - else - return 1 - fi + _mode=$1 + + case "$_mode" in + kdump) + _sysfs="/sys/kernel/kexec_crash_loaded" + ;; + fadump) + _sysfs="$FADUMP_REGISTER_SYS_NODE" + ;; + *) + derror "Unknown dump mode '$_mode' provided" + return 1 + ;; + esac + + if [[ ! -f $_sysfs ]]; then + derror "$_mode is not supported on this kernel" + return 1 + fi + + [[ $(< $_sysfs) -eq 1 ]] } # diff --git a/kdumpctl b/kdumpctl index 98c72ef..8ded96e 100755 --- a/kdumpctl +++ b/kdumpctl @@ -17,7 +17,6 @@ DEFAULT_INITRD_BAK="" INITRD_CHECKSUM_LOCATION="" KDUMP_INITRD="" TARGET_INITRD="" -FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" #kdump shall be the default dump mode DEFAULT_DUMP_MODE="kdump" image_time=0 @@ -849,23 +848,6 @@ show_reserved_mem() dinfo "Reserved ${mem_mb}MB memory for crash kernel" } -check_current_fadump_status() -{ - # Check if firmware-assisted dump has been registered. - rc=$(< $FADUMP_REGISTER_SYS_NODE) - [[ $rc -eq 1 ]] && return 0 - return 1 -} - -check_current_status() -{ - if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then - check_current_fadump_status - else - check_current_kdump_status - fi -} - save_raw() { local kdump_dir @@ -996,8 +978,8 @@ check_dump_feasibility() start_fadump() { - echo 1 > $FADUMP_REGISTER_SYS_NODE - if ! check_current_fadump_status; then + echo 1 > "$FADUMP_REGISTER_SYS_NODE" + if ! is_kernel_loaded "fadump"; then derror "fadump: failed to register" return 1 fi @@ -1088,7 +1070,7 @@ start() return 1 fi - if [[ $DEFAULT_DUMP_MODE == "kdump" ]] && check_current_kdump_status; then + if [[ $DEFAULT_DUMP_MODE == "kdump" ]] && is_kernel_loaded "kdump"; then dwarn "Kdump already running: [WARNING]" return 0 fi @@ -1115,7 +1097,7 @@ start() reload() { - if ! check_current_status; then + if ! is_kernel_loaded "$DEFAULT_DUMP_MODE"; then dwarn "Kdump was not running: [WARNING]" fi @@ -1146,8 +1128,8 @@ reload() stop_fadump() { - echo 0 > $FADUMP_REGISTER_SYS_NODE - if check_current_fadump_status; then + echo 0 > "$FADUMP_REGISTER_SYS_NODE" + if is_kernel_loaded "fadump"; then derror "fadump: failed to unregister" return 1 fi @@ -1176,7 +1158,7 @@ stop_kdump() reload_fadump() { - if echo 1 > $FADUMP_REGISTER_SYS_NODE; then + if echo 1 > "$FADUMP_REGISTER_SYS_NODE"; then dinfo "fadump: re-registered successfully" return 0 else @@ -1830,7 +1812,7 @@ main() ;; status) EXIT_CODE=0 - check_current_status + is_kernel_loaded "$DEFAULT_DUMP_MODE" case "$?" in 0) dinfo "Kdump is operational"