On Thu, Feb 20, 2014 at 01:04:55PM +0530, Hari Bathini wrote:
This patch enables kdump script to check if firmware-assisted dump
is
enabled or not by reading value from '/sys/kernel/fadump_enabled'. The
determine_dump_mode() routine sets dump_mode to 'fadump', if fadump is
enabled. By default, dump_mode is set to 'kdump' mode.
Modify status routine to check if firmware assisted dump is registered
or not by reading value from '/sys/kernel/fadump_registered' file. If
it is set to '1' then return status=0 else return status=1.
0 <= Firmware assisted is enabled and running
1 <= Firmware assisted is enabled but not running
Signed-off-by: Mahesh Salgaonkar <mahesh(a)linux.vnet.ibm.com>
Signed-off-by: Hari Bathini <hbathini(a)linux.vnet.ibm.com>
---
kdumpctl | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 57 insertions(+), 6 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index f72020d..e624b91 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -9,6 +9,8 @@ MKDUMPRD="/sbin/mkdumprd -f"
SAVE_PATH=/var/crash
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
DUMP_TARGET=""
+FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled"
+FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered"
. /lib/kdump/kdump-lib.sh
@@ -24,6 +26,18 @@ single_instance_lock()
flock 9
}
+determine_dump_mode()
+{
+ # kdump shall be the default dump mode
+ dump_mode="kdump"
+
+ # Check if firmware-assisted dump is enabled
+ # if yes, set the dump mode as fadump
+ if is_fadump_capable; then
+ dump_mode="fadump"
+ fi
+}
+
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ...
[<paramN>]
# Remove a list of kernel parameters from a given kernel cmdline and print the result.
# For each "arg" in the removing params list, "arg" and
"arg=xxx" will be removed if exists.
@@ -384,6 +398,27 @@ function propagate_ssh_key()
}
+function is_fadump_capable()
I don't think "function" keyword is necessary. Just get rid of it from
all functions.
+{
+ # Check if firmware-assisted dump is enabled
+ # if yes, check fadump status Otherwise fallback to kdump check
+ if [ -f $FADUMP_ENABLED_SYS_NODE ] && \
+ [ -f $FADUMP_REGISTER_SYS_NODE ]
Why are we checking for presence of FADUMP_REGISTER_SYS_NODE file here?
+ then
+ rc=`cat $FADUMP_ENABLED_SYS_NODE`
+ [ $rc -eq 1 ] && return 0
+ fi
+ return 1
+}
+
+function check_current_fadump_status()
+{
+ # Check if firmware-assisted dump has been registered.
+ rc=`cat $FADUMP_REGISTER_SYS_NODE`
+ [ $rc -eq 1 ] && return 0
+ return 1
+}
+
function check_current_kdump_status()
{
rc=`cat /sys/kernel/kexec_crash_loaded`
@@ -394,6 +429,17 @@ function check_current_kdump_status()
fi
}
+function check_current_status()
+{
+ if [ $dump_mode == "fadump" ]; then
+ check_current_fadump_status
+ else
+ check_current_kdump_status
+ fi
+
+ return $?
+}
+
function save_raw()
{
local kdump_dir
@@ -555,13 +601,15 @@ function start()
return 1
fi
- check_kdump_feasibility
- if [ $? -ne 0 ]; then
- echo "Starting kdump: [FAILED]"
- return 1
+ if [ $dump_mode == "kdump" ]; then
+ check_kdump_feasibility
+ if [ $? -ne 0 ]; then
+ echo "Starting kdump: [FAILED]"
+ return 1
+ fi
Try to avoid too much conditional checks in higher level functions. Wrap
them with a function to keep code more readable.
So write a function check_dump_feasibility(). Following is pseudo code.
Also for scripting look at some of the existing code of dracut. You will
have good ideas on how to write if loops etc in more compact form.
check_dump_feasibility()
{
if (dump_mode != kdump)
return 0;
check_kdump_feasibility
}
fi
- check_current_kdump_status
+ check_current_status
if [ $? == 0 ]; then
echo "Kdump already running: [WARNING]"
return 0
@@ -623,7 +671,7 @@ main ()
;;
status)
EXIT_CODE=0
- check_current_kdump_status
+ check_current_status
case "$?" in
0)
echo "Kdump is operational"
@@ -654,6 +702,9 @@ main ()
# Other kdumpctl instances will block in queue, until this one exits
single_instance_lock
+# Determine if the dump mode is kdump or fadump
+determine_dump_mode
+
Keep it inside main(). There is no reason to keep it outside. Also it
might be a good idea to give a message on console which tells that
dump mode we are operating in. We can output this message only if
dump mode is fadump as kdump is default anyway.
echo "Using dump mode fadump" or something like that.
# To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call
main.
# So that fd isn't leaking when main is invoking a subshell.
(exec 9<&-; main $1)