From a571b0da9ff06d75eb0bb99d38b75a648941de7d Mon Sep 17 00:00:00 2001 From: Lianbo Jiang Date: Thu, 14 Jan 2021 11:42:01 +0800 Subject: [PATCH] fix kdump failure of saving vmcore with the scp + ipv6 method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Acked-by: Pingfan Liu --- dracut-kdump.sh | 32 +++++++++++++++++++++++++++++--- kdump-lib-initramfs.sh | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 370d217..3367bc5 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -111,6 +111,7 @@ dump_ssh() local _dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" local _host=$2 local _vmcore="vmcore" + local _ipv6_addr="" _username="" dinfo "saving to $_host:$_dir" @@ -122,8 +123,17 @@ dump_ssh() dinfo "saving vmcore" + if is_ipv6_address "$_host"; then + _username=${_host%@*} + _ipv6_addr="[${_host#*@}]" + fi + if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then - scp -q $_opt /proc/vmcore "$_host:$_dir/vmcore-incomplete" + 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" + fi _exitcode=$? else $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" fi + dinfo "saving the $KDUMP_LOG_FILE to $_host:$_dir/" save_log - scp -q $_opt $KDUMP_LOG_FILE "$_host:$_dir/" + 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/" + fi _ret=$? if [ $_ret -ne 0 ]; then derror "saving log file failed, _exitcode:$_ret" @@ -161,6 +176,7 @@ save_opalcore_ssh() { local _path=$1 local _opts="$2" local _location=$3 + local _user_name="" _ipv6addr="" ddebug "_path=$_path _opts=$_opts _location=$_location" @@ -173,8 +189,18 @@ save_opalcore_ssh() { fi fi + if is_ipv6_address "$_host"; then + _user_name=${_location%@*} + _ipv6addr="[${_location#*@}]" + fi + dinfo "saving opalcore:$OPALCORE to $_location:$_path" - scp $_opts $OPALCORE $_location:$_path/opalcore-incomplete + + if [ -n "$_user_name" ] && [ -n "$_ipv6addr" ]; then + scp $_opts $OPALCORE $_user_name@$_ipv6addr:$_path/opalcore-incomplete + else + scp $_opts $OPALCORE $_location:$_path/opalcore-incomplete + fi if [ $? -ne 0 ]; then derror "saving opalcore failed" return 1 diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 059ff20..86065be 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -158,6 +158,7 @@ dump_fs() derror "saving vmcore failed, _exitcode:$_exitcode" fi + dinfo "saving the $KDUMP_LOG_FILE to $_dump_path/" save_log mv $KDUMP_LOG_FILE $_dump_path/ if [ $_exitcode -ne 0 ]; then