kdumpctl: merge check_current_{kdump,fadump}_status
Both functions are almost identical. The only differences are (1) the sysfs node the status is read from and (2) the fact the fadump version doesn't verify if the file it's trying to read actually exists. Thus merge the two functions and get rid of the check_current_status wrapper. While at it rename the function to is_kernel_loaded which explains better what the function does. Finally, after moving FADUMP_REGISTER_SYS_NODE shellcheck can no longer access the definition and starts complaining about it not being quoted. Thus quote all uses of FADUMP_REGISTER_SYS_NODE. Signed-off-by: Philipp Rudo <prudo@redhat.com> Reviewed-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
parent
ed6936f9fc
commit
b9fd7a4076
@ -37,7 +37,7 @@ early_kdump_load()
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if check_current_kdump_status; then
|
if is_kernel_loaded "kdump"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
31
kdump-lib.sh
31
kdump-lib.sh
@ -9,6 +9,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled"
|
FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled"
|
||||||
|
FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered"
|
||||||
|
|
||||||
is_fadump_capable()
|
is_fadump_capable()
|
||||||
{
|
{
|
||||||
@ -494,19 +495,31 @@ check_kdump_feasibility()
|
|||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
check_current_kdump_status()
|
is_kernel_loaded()
|
||||||
{
|
{
|
||||||
if [[ ! -f /sys/kernel/kexec_crash_loaded ]]; then
|
local _sysfs _mode
|
||||||
derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel"
|
|
||||||
|
_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
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rc=$(< /sys/kernel/kexec_crash_loaded)
|
[[ $(< $_sysfs) -eq 1 ]]
|
||||||
if [[ $rc == 1 ]]; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>]
|
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>]
|
||||||
|
34
kdumpctl
34
kdumpctl
@ -14,7 +14,6 @@ DEFAULT_INITRD_BAK=""
|
|||||||
INITRD_CHECKSUM_LOCATION=""
|
INITRD_CHECKSUM_LOCATION=""
|
||||||
KDUMP_INITRD=""
|
KDUMP_INITRD=""
|
||||||
TARGET_INITRD=""
|
TARGET_INITRD=""
|
||||||
FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered"
|
|
||||||
#kdump shall be the default dump mode
|
#kdump shall be the default dump mode
|
||||||
DEFAULT_DUMP_MODE="kdump"
|
DEFAULT_DUMP_MODE="kdump"
|
||||||
image_time=0
|
image_time=0
|
||||||
@ -837,23 +836,6 @@ show_reserved_mem()
|
|||||||
dinfo "Reserved ${mem_mb}MB memory for crash kernel"
|
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()
|
save_raw()
|
||||||
{
|
{
|
||||||
local raw_target
|
local raw_target
|
||||||
@ -974,8 +956,8 @@ check_dump_feasibility()
|
|||||||
|
|
||||||
start_fadump()
|
start_fadump()
|
||||||
{
|
{
|
||||||
echo 1 > $FADUMP_REGISTER_SYS_NODE
|
echo 1 > "$FADUMP_REGISTER_SYS_NODE"
|
||||||
if ! check_current_fadump_status; then
|
if ! is_kernel_loaded "fadump"; then
|
||||||
derror "fadump: failed to register"
|
derror "fadump: failed to register"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -1040,7 +1022,7 @@ start()
|
|||||||
return 1
|
return 1
|
||||||
fi
|
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]"
|
dwarn "Kdump already running: [WARNING]"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@ -1065,7 +1047,7 @@ start()
|
|||||||
|
|
||||||
reload()
|
reload()
|
||||||
{
|
{
|
||||||
if ! check_current_status; then
|
if ! is_kernel_loaded "$DEFAULT_DUMP_MODE"; then
|
||||||
dwarn "Kdump was not running: [WARNING]"
|
dwarn "Kdump was not running: [WARNING]"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -1096,8 +1078,8 @@ reload()
|
|||||||
|
|
||||||
stop_fadump()
|
stop_fadump()
|
||||||
{
|
{
|
||||||
echo 0 > $FADUMP_REGISTER_SYS_NODE
|
echo 0 > "$FADUMP_REGISTER_SYS_NODE"
|
||||||
if check_current_fadump_status; then
|
if is_kernel_loaded "fadump"; then
|
||||||
derror "fadump: failed to unregister"
|
derror "fadump: failed to unregister"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -1126,7 +1108,7 @@ stop_kdump()
|
|||||||
|
|
||||||
reload_fadump()
|
reload_fadump()
|
||||||
{
|
{
|
||||||
if echo 1 > $FADUMP_REGISTER_SYS_NODE; then
|
if echo 1 > "$FADUMP_REGISTER_SYS_NODE"; then
|
||||||
dinfo "fadump: re-registered successfully"
|
dinfo "fadump: re-registered successfully"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -1739,7 +1721,7 @@ main()
|
|||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
EXIT_CODE=0
|
EXIT_CODE=0
|
||||||
check_current_status
|
is_kernel_loaded "$DEFAULT_DUMP_MODE"
|
||||||
case "$?" in
|
case "$?" in
|
||||||
0)
|
0)
|
||||||
dinfo "Kdump is operational"
|
dinfo "Kdump is operational"
|
||||||
|
Loading…
Reference in New Issue
Block a user