Currently, if saving vmcore failed, the final failure information won't
be saved to the kexec-dmesg.log, because the action of saving the log
occurs before the final log is printed, it has no chance to save the
log(marked it with the '^^^' below) to the log file(kexec-dmesg.log).
For example:
[1] console log:
[ 3.589967] kdump[453]: saving vmcore-dmesg.txt to
/sysroot//var/crash/127.0.0.1-2020-11-26-14:19:17/
[ 3.627261] kdump[458]: saving vmcore-dmesg.txt complete
[ 3.633923] kdump[460]: saving vmcore
[ 3.661020] kdump[465]: saving vmcore failed
^^^^^^^^^^^^^^^^^^^^
[2] kexec-dmesg.log:
Nov 26 14:19:17
kvm-06-guest25.hv2.lab.eng.bos.redhat.com kdump[453]: saving
vmcore-dmesg.txt to /sysroot//var/crash/127.0.0.1-2020-11-26-14:19:17/
Nov 26 14:19:17
kvm-06-guest25.hv2.lab.eng.bos.redhat.com kdump[458]: saving
vmcore-dmesg.txt complete
Nov 26 14:19:17
kvm-06-guest25.hv2.lab.eng.bos.redhat.com kdump[460]: saving vmcore
Let's improve it in order to avoid the loss of important information.
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
dracut-kdump.sh | 43 +++++++++++++++++++++++++++---------------
kdump-lib-initramfs.sh | 20 ++++++++++++--------
2 files changed, 40 insertions(+), 23 deletions(-)
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index c2627c296040..370d217cea52 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
@@ -105,10 +105,12 @@ dump_raw()
dump_ssh()
{
- local ret
+ local _ret=0
+ local _exitcode=0 _exitcode2=0
local _opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
local _dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
local _host=$2
+ local _vmcore="vmcore"
dinfo "saving to $_host:$_dir"
@@ -122,25 +124,36 @@ dump_ssh()
if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
scp -q $_opt /proc/vmcore "$_host:$_dir/vmcore-incomplete"
- ret=$?
- save_log
- scp -q $_opt $KDUMP_LOG_FILE "$_host:$_dir/"
- if [ $ret -ne 0 ]; then
- return 1
- fi
- ssh $_opt $_host "mv $_dir/vmcore-incomplete $_dir/vmcore" || return 1
+ _exitcode=$?
else
$CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "dd bs=512
of=$_dir/vmcore-incomplete"
- ret=$?
- save_log
- scp -q $_opt $KDUMP_LOG_FILE "$_host:$_dir/"
- if [ $ret -ne 0 ]; then
- return 1
+ _exitcode=$?
+ _vmcore="vmcore.flat"
+ fi
+
+ if [ $_exitcode -eq 0 ]; then
+ ssh $_opt $_host "mv $_dir/vmcore-incomplete $_dir/$_vmcore"
+ _exitcode2=$?
+ if [ $_exitcode2 -ne 0 ]; then
+ derror "moving vmcore failed, _exitcode:$_exitcode2"
+ else
+ dinfo "saving vmcore complete"
fi
- ssh $_opt $_host "mv $_dir/vmcore-incomplete $_dir/vmcore.flat" ||
return 1
+ else
+ derror "saving vmcore failed, _exitcode:$_exitcode"
+ fi
+
+ save_log
+ scp -q $_opt $KDUMP_LOG_FILE "$_host:$_dir/"
+ _ret=$?
+ if [ $_ret -ne 0 ]; then
+ derror "saving log file failed, _exitcode:$_ret"
+ fi
+
+ if [ $_exitcode -ne 0 ] || [ $_exitcode2 -ne 0 ];then
+ return 1
fi
- dinfo "saving vmcore complete"
return 0
}
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
index 791d141aa00a..e766f95c7d6a 100755
--- a/kdump-lib-initramfs.sh
+++ b/kdump-lib-initramfs.sh
@@ -115,7 +115,7 @@ save_log()
# dump_fs <mount point>
dump_fs()
{
- local ret
+ local _exitcode
local _mp=$1
local _dev=$(get_mount_info SOURCE target $_mp -f)
local _op=$(get_mount_info OPTIONS target $_mp -f)
@@ -159,16 +159,20 @@ dump_fs()
dinfo "saving vmcore"
$CORE_COLLECTOR /proc/vmcore $_dump_path/vmcore-incomplete
- ret=$?
+ _exitcode=$?
+ if [ $_exitcode -eq 0 ]; then
+ mv $_dump_path/vmcore-incomplete $_dump_path/vmcore
+ sync
+ dinfo "saving vmcore complete"
+ else
+ derror "saving vmcore failed, _exitcode:$_exitcode"
+ fi
+
save_log
mv $KDUMP_LOG_FILE $_dump_path/
- if [ $ret -ne 0 ]; then
- return 1
+ if [ $_exitcode -ne 0 ]; then
+ return 1
fi
- mv $_dump_path/vmcore-incomplete $_dump_path/vmcore
- sync
-
- dinfo "saving vmcore complete"
# improper kernel cmdline can cause the failure of echo, we can ignore this kind of
failure
return 0
--
2.17.1