kdumpctl: Move get_kernel_size to kdumpctl
The function is only used in do_estimate. Move it to kdumpctl to prevent confusion. Signed-off-by: Philipp Rudo <prudo@redhat.com> Reviewed-by: Pingfan Liu <piliu@redhat.com> Reviewed-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
parent
0ff44ca6e8
commit
81d89c885f
72
kdump-lib.sh
72
kdump-lib.sh
@ -853,75 +853,3 @@ get_all_kdump_crypt_dev()
|
||||
get_luks_crypt_dev "$(kdump_get_maj_min "$_dev")"
|
||||
done
|
||||
}
|
||||
|
||||
check_vmlinux()
|
||||
{
|
||||
# Use readelf to check if it's a valid ELF
|
||||
readelf -h "$1" &> /dev/null || return 1
|
||||
}
|
||||
|
||||
get_vmlinux_size()
|
||||
{
|
||||
local size=0 _msize
|
||||
|
||||
while read -r _msize; do
|
||||
size=$((size + _msize))
|
||||
done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2> /dev/stderr)"
|
||||
|
||||
echo $size
|
||||
}
|
||||
|
||||
try_decompress()
|
||||
{
|
||||
# The obscure use of the "tr" filter is to work around older versions of
|
||||
# "grep" that report the byte offset of the line instead of the pattern.
|
||||
|
||||
# Try to find the header ($1) and decompress from here
|
||||
for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"); do
|
||||
if ! type -P "$3" > /dev/null; then
|
||||
ddebug "Signiature detected but '$3' is missing, skip this decompressor"
|
||||
break
|
||||
fi
|
||||
|
||||
pos=${pos%%:*}
|
||||
tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null
|
||||
if check_vmlinux "$5"; then
|
||||
ddebug "Kernel is extracted with '$3'"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Borrowed from linux/scripts/extract-vmlinux
|
||||
get_kernel_size()
|
||||
{
|
||||
# Prepare temp files:
|
||||
local tmp img=$1
|
||||
|
||||
tmp=$(mktemp /tmp/vmlinux-XXX)
|
||||
trap 'rm -f "$tmp"' 0
|
||||
|
||||
# Try to check if it's a vmlinux already
|
||||
check_vmlinux "$img" && get_vmlinux_size "$img" && return 0
|
||||
|
||||
# That didn't work, so retry after decompression.
|
||||
try_decompress '\037\213\010' xy gunzip "$img" "$tmp" ||
|
||||
try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" ||
|
||||
try_decompress 'BZh' xy bunzip2 "$img" "$tmp" ||
|
||||
try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" ||
|
||||
try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" ||
|
||||
try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" ||
|
||||
try_decompress '(\265/\375' xxx unzstd "$img" "$tmp"
|
||||
|
||||
# Finally check for uncompressed images or objects:
|
||||
[[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0
|
||||
|
||||
# Fallback to use iomem
|
||||
local _size=0 _seg
|
||||
while read -r _seg; do
|
||||
_size=$((_size + 0x${_seg#*-} - 0x${_seg%-*}))
|
||||
done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)"
|
||||
echo $_size
|
||||
}
|
||||
|
72
kdumpctl
72
kdumpctl
@ -1147,6 +1147,78 @@ rebuild()
|
||||
rebuild_initrd
|
||||
}
|
||||
|
||||
check_vmlinux()
|
||||
{
|
||||
# Use readelf to check if it's a valid ELF
|
||||
readelf -h "$1" &> /dev/null || return 1
|
||||
}
|
||||
|
||||
get_vmlinux_size()
|
||||
{
|
||||
local size=0 _msize
|
||||
|
||||
while read -r _msize; do
|
||||
size=$((size + _msize))
|
||||
done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2> /dev/stderr)"
|
||||
|
||||
echo $size
|
||||
}
|
||||
|
||||
try_decompress()
|
||||
{
|
||||
# The obscure use of the "tr" filter is to work around older versions of
|
||||
# "grep" that report the byte offset of the line instead of the pattern.
|
||||
|
||||
# Try to find the header ($1) and decompress from here
|
||||
for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"); do
|
||||
if ! type -P "$3" > /dev/null; then
|
||||
ddebug "Signiature detected but '$3' is missing, skip this decompressor"
|
||||
break
|
||||
fi
|
||||
|
||||
pos=${pos%%:*}
|
||||
tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null
|
||||
if check_vmlinux "$5"; then
|
||||
ddebug "Kernel is extracted with '$3'"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Borrowed from linux/scripts/extract-vmlinux
|
||||
get_kernel_size()
|
||||
{
|
||||
# Prepare temp files:
|
||||
local tmp img=$1
|
||||
|
||||
tmp=$(mktemp /tmp/vmlinux-XXX)
|
||||
trap 'rm -f "$tmp"' 0
|
||||
|
||||
# Try to check if it's a vmlinux already
|
||||
check_vmlinux "$img" && get_vmlinux_size "$img" && return 0
|
||||
|
||||
# That didn't work, so retry after decompression.
|
||||
try_decompress '\037\213\010' xy gunzip "$img" "$tmp" ||
|
||||
try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" ||
|
||||
try_decompress 'BZh' xy bunzip2 "$img" "$tmp" ||
|
||||
try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" ||
|
||||
try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" ||
|
||||
try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" ||
|
||||
try_decompress '(\265/\375' xxx unzstd "$img" "$tmp"
|
||||
|
||||
# Finally check for uncompressed images or objects:
|
||||
[[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0
|
||||
|
||||
# Fallback to use iomem
|
||||
local _size=0 _seg
|
||||
while read -r _seg; do
|
||||
_size=$((_size + 0x${_seg#*-} - 0x${_seg%-*}))
|
||||
done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)"
|
||||
echo $_size
|
||||
}
|
||||
|
||||
do_estimate()
|
||||
{
|
||||
local kdump_mods
|
||||
|
Loading…
Reference in New Issue
Block a user