fix kdump failure of saving vmcore with the scp + ipv6 method

Currently, kdump will fail to save vmcore when using the scp and ipv6.
The reason is that the scp requires IPv6 addresses to be enclosed in
square brackets, but ssh doesn’t require this.

Let's enclose the ipv6 address in square brackets for scp dump.

Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
Acked-by: Pingfan Liu <piliu@redhat.com>
This commit is contained in:
Lianbo Jiang 2021-01-14 11:42:01 +08:00 committed by Kairui Song
parent 550f1c4285
commit a571b0da9f
2 changed files with 30 additions and 3 deletions

View File

@ -111,6 +111,7 @@ dump_ssh()
local _dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" local _dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
local _host=$2 local _host=$2
local _vmcore="vmcore" local _vmcore="vmcore"
local _ipv6_addr="" _username=""
dinfo "saving to $_host:$_dir" dinfo "saving to $_host:$_dir"
@ -122,8 +123,17 @@ dump_ssh()
dinfo "saving vmcore" dinfo "saving vmcore"
if is_ipv6_address "$_host"; then
_username=${_host%@*}
_ipv6_addr="[${_host#*@}]"
fi
if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
if [ -n "$_username" ] && [ -n "$_ipv6_addr" ]; then
scp -q $_opt /proc/vmcore "$_username@$_ipv6_addr:$_dir/vmcore-incomplete"
else
scp -q $_opt /proc/vmcore "$_host:$_dir/vmcore-incomplete" scp -q $_opt /proc/vmcore "$_host:$_dir/vmcore-incomplete"
fi
_exitcode=$? _exitcode=$?
else else
$CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "dd bs=512 of=$_dir/vmcore-incomplete" $CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "dd bs=512 of=$_dir/vmcore-incomplete"
@ -143,8 +153,13 @@ dump_ssh()
derror "saving vmcore failed, _exitcode:$_exitcode" derror "saving vmcore failed, _exitcode:$_exitcode"
fi fi
dinfo "saving the $KDUMP_LOG_FILE to $_host:$_dir/"
save_log save_log
if [ -n "$_username" ] && [ -n "$_ipv6_addr" ]; then
scp -q $_opt $KDUMP_LOG_FILE "$_username@$_ipv6_addr:$_dir/"
else
scp -q $_opt $KDUMP_LOG_FILE "$_host:$_dir/" scp -q $_opt $KDUMP_LOG_FILE "$_host:$_dir/"
fi
_ret=$? _ret=$?
if [ $_ret -ne 0 ]; then if [ $_ret -ne 0 ]; then
derror "saving log file failed, _exitcode:$_ret" derror "saving log file failed, _exitcode:$_ret"
@ -161,6 +176,7 @@ save_opalcore_ssh() {
local _path=$1 local _path=$1
local _opts="$2" local _opts="$2"
local _location=$3 local _location=$3
local _user_name="" _ipv6addr=""
ddebug "_path=$_path _opts=$_opts _location=$_location" ddebug "_path=$_path _opts=$_opts _location=$_location"
@ -173,8 +189,18 @@ save_opalcore_ssh() {
fi fi
fi fi
if is_ipv6_address "$_host"; then
_user_name=${_location%@*}
_ipv6addr="[${_location#*@}]"
fi
dinfo "saving opalcore:$OPALCORE to $_location:$_path" dinfo "saving opalcore:$OPALCORE to $_location:$_path"
if [ -n "$_user_name" ] && [ -n "$_ipv6addr" ]; then
scp $_opts $OPALCORE $_user_name@$_ipv6addr:$_path/opalcore-incomplete
else
scp $_opts $OPALCORE $_location:$_path/opalcore-incomplete scp $_opts $OPALCORE $_location:$_path/opalcore-incomplete
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
derror "saving opalcore failed" derror "saving opalcore failed"
return 1 return 1

View File

@ -158,6 +158,7 @@ dump_fs()
derror "saving vmcore failed, _exitcode:$_exitcode" derror "saving vmcore failed, _exitcode:$_exitcode"
fi fi
dinfo "saving the $KDUMP_LOG_FILE to $_dump_path/"
save_log save_log
mv $KDUMP_LOG_FILE $_dump_path/ mv $KDUMP_LOG_FILE $_dump_path/
if [ $_exitcode -ne 0 ]; then if [ $_exitcode -ne 0 ]; then