kdump-lib: Introduce a help function _crashkernel_add()
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2160676
Upstream: Fedora rawhide
Conflict: Drop shellspec test case
commit 51efbcf83e
Author: Pingfan Liu <piliu@redhat.com>
Date: Tue Jun 13 17:43:20 2023 +0800
kdump-lib: Introduce a help function _crashkernel_add()
This help function can manipulate the crashkernel cmdline by adding an
number for each item. Also a basic test case for _crashkernel_add() is
provided in this patch.
Credit to Philipp, who contributes the original code.
Signed-off-by: Pingfan Liu <piliu@redhat.com>
Reviewed-by: Coiby Xu <coxu@redhat.com>
Reviewed-by: Philipp Rudo <prudo@redhat.com>
Signed-off-by: Pingfan Liu <piliu@redhat.com>
This commit is contained in:
parent
cb850aec26
commit
37de94d02a
58
kdump-lib.sh
58
kdump-lib.sh
@ -904,6 +904,64 @@ get_recommend_size()
|
||||
echo "0M"
|
||||
}
|
||||
|
||||
# $1 crashkernel=""
|
||||
# $2 delta in unit of MB
|
||||
_crashkernel_add()
|
||||
{
|
||||
local _ck _add _entry _ret
|
||||
local _range _size _offset
|
||||
|
||||
_ck="$1"
|
||||
_add="$2"
|
||||
_ret=""
|
||||
|
||||
if [[ "$_ck" == *@* ]]; then
|
||||
_offset="@${_ck##*@}"
|
||||
_ck=${_ck%@*}
|
||||
elif [[ "$_ck" == *,high ]] || [[ "$_ck" == *,low ]]; then
|
||||
_offset=",${_ck##*,}"
|
||||
_ck=${_ck%,*}
|
||||
else
|
||||
_offset=''
|
||||
fi
|
||||
|
||||
while read -d , -r _entry; do
|
||||
[[ -n "$_entry" ]] || continue
|
||||
if [[ "$_entry" == *:* ]]; then
|
||||
_range=${_entry%:*}
|
||||
_size=${_entry#*:}
|
||||
else
|
||||
_range=""
|
||||
_size=${_entry}
|
||||
fi
|
||||
|
||||
case "${_size: -1}" in
|
||||
K)
|
||||
_size=${_size::-1}
|
||||
_size="$((_size + (_add * 1024)))K"
|
||||
;;
|
||||
M)
|
||||
_size=${_size::-1}
|
||||
_size="$((_size + _add))M"
|
||||
;;
|
||||
G)
|
||||
_size=${_size::-1}
|
||||
_size="$((_size * 1024 + _add))M"
|
||||
;;
|
||||
*)
|
||||
_size="$((_size + (_add * 1024 * 1024)))"
|
||||
;;
|
||||
esac
|
||||
|
||||
[[ -n "$_range" ]] && _ret+="$_range:"
|
||||
_ret+="$_size,"
|
||||
done <<< "$_ck,"
|
||||
|
||||
_ret=${_ret%,}
|
||||
[[ -n "$_offset" ]] && _ret+=$_offset
|
||||
echo "$_ret"
|
||||
}
|
||||
|
||||
# get default crashkernel
|
||||
# $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable
|
||||
kdump_get_arch_recommend_crashkernel()
|
||||
|
Loading…
Reference in New Issue
Block a user