kdump-lib.sh: fix a few ambiguous or redundant code

Fix a few ambiguous syntax issues and remove some unused variables.
Also refactor some code to make it more robust.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Kairui Song 2021-09-13 01:17:23 +08:00
parent c0edb80b8f
commit 319219d23b
1 changed files with 14 additions and 17 deletions

View File

@ -176,7 +176,7 @@ get_bind_mount_source()
echo $_mnt$_path && return echo $_mnt$_path && return
fi fi
local _fsroot=${_src#$_src_nofsroot[} local _fsroot=${_src#${_src_nofsroot}[}
_fsroot=${_fsroot%]} _fsroot=${_fsroot%]}
_mnt=$(get_mount_info TARGET source $_src_nofsroot -f) _mnt=$(get_mount_info TARGET source $_src_nofsroot -f)
@ -621,14 +621,14 @@ prepare_kexec_args()
# #
prepare_kdump_bootinfo() prepare_kdump_bootinfo()
{ {
local boot_imglist boot_dirlist boot_initrdlist curr_kver="$(uname -r)" local boot_imglist boot_dirlist boot_initrdlist
local machine_id local machine_id
if [[ -z "$KDUMP_KERNELVER" ]]; then if [[ -z "$KDUMP_KERNELVER" ]]; then
KDUMP_KERNELVER="$(uname -r)" KDUMP_KERNELVER="$(uname -r)"
fi fi
read machine_id < /etc/machine-id read -r machine_id < /etc/machine-id
boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"} boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"}
boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG" boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG"
@ -743,8 +743,8 @@ prepare_cmdline()
cmdline="${cmdline} $3" cmdline="${cmdline} $3"
id=$(get_bootcpu_apicid) id=$(get_bootcpu_apicid)
if [[ ! -z ${id} ]] ; then if [[ -n ${id} ]] ; then
cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id}) cmdline=$(append_cmdline "$cmdline" disable_cpu_apicid "$id")
fi fi
# If any watchdog is used, set it's pretimeout to 0. pretimeout let # If any watchdog is used, set it's pretimeout to 0. pretimeout let
@ -775,7 +775,7 @@ get_system_size()
result=$(grep "System RAM" /proc/iomem | awk -F ":" '{ print $1 }' | tr [:lower:] [:upper:] | paste -sd+) result=$(grep "System RAM" /proc/iomem | awk -F ":" '{ print $1 }' | tr [:lower:] [:upper:] | paste -sd+)
result="+$result" result="+$result"
# replace '-' with '+0x' and '+' with '-0x' # replace '-' with '+0x' and '+' with '-0x'
sum=$( echo $result | sed -e 's/-/K0x/g' | sed -e 's/+/-0x/g' | sed -e 's/K/+/g' ) sum=$(echo "$result" | sed -e 's/-/K0x/g' -e 's/+/-0x/g' -e 's/K/+/g')
size=$(printf "%d\n" $(($sum))) size=$(printf "%d\n" $(($sum)))
size=$((size / 1024 / 1024 / 1024)) size=$((size / 1024 / 1024 / 1024))
@ -788,9 +788,6 @@ get_recommend_size()
local _ck_cmdline=$2 local _ck_cmdline=$2
local OLDIFS="$IFS" local OLDIFS="$IFS"
last_sz=""
last_unit=""
start=${_ck_cmdline: :1} start=${_ck_cmdline: :1}
if [[ $mem_size -lt $start ]]; then if [[ $mem_size -lt $start ]]; then
echo "0M" echo "0M"
@ -845,7 +842,7 @@ kdump_get_arch_recommend_size()
fi fi
fi fi
ck_cmdline=$(echo $ck_cmdline | sed -e 's/-:/-102400T:/g') ck_cmdline=${ck_cmdline//-:/-102400T:}
sys_mem=$(get_system_size) sys_mem=$(get_system_size)
get_recommend_size "$sys_mem" "$ck_cmdline" get_recommend_size "$sys_mem" "$ck_cmdline"
@ -896,11 +893,11 @@ check_vmlinux()
get_vmlinux_size() get_vmlinux_size()
{ {
local size=0 local size=0 _msize
while read _type _offset _virtaddr _physaddr _fsize _msize _flg _aln; do while read -r _msize; do
size=$(( size + _msize )) size=$(( size + _msize ))
done <<< $(readelf -l -W $1 | grep "^ LOAD" 2>/dev/stderr) done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2>/dev/stderr)"
echo $size echo $size
} }
@ -952,9 +949,9 @@ get_kernel_size()
[[ $? -eq 0 ]] && get_vmlinux_size $tmp && return 0 [[ $? -eq 0 ]] && get_vmlinux_size $tmp && return 0
# Fallback to use iomem # Fallback to use iomem
local _size=0 local _size=0 _seg
for _seg in $(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1); do while read -r _seg; do
_size=$(( _size + 0x${_seg#*-} - 0x${_seg%-*} )) _size=$(( _size + 0x${_seg#*-} - 0x${_seg%-*} ))
done done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)"
echo $_size echo $_size
} }