On Mon, May 22, 2023 at 10:59 PM Philipp Rudo <prudo(a)redhat.com> wrote:
On Thu, 18 May 2023 13:26:40 +0800
Pingfan Liu <piliu(a)redhat.com> wrote:
> This help function can manipulate the crashkernel cmdline by adding an
> number for each item.
>
> Credit to Philipp Rudo, who brings up the original code.
>
> Signed-off-by: Pingfan Liu <piliu(a)redhat.com>
@Coiby, could you please take a look as I've provided the original code.
BTW, this function has one quirk I'm not sure if it is desired. In
particular by keeping the unit of an entry it will ignore any increase
smaller than 1024M to entries with size G. E.g.
_crashkernel_add 1G 1024 -> 2G
but
_crashkernel_add 1G 1023 -> 1G
Alternatively, we could convert everything to bytes first and then use
the best matching unit, e.g.
Since in practice, the delta is in the unit of MB, I suggest
converting it to MB if the unit is bigger than that.
Thanks,
Pingfan
_crashkernel_add 1G 1 -> 1025M
_crashkernel_add 1024K 1 -> 2M
But that will add more complexity and I'm not sure if it will over
engineered for our use case.
Thanks
Philipp
> ---
> kdump-lib.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 58 insertions(+)
>
> diff --git a/kdump-lib.sh b/kdump-lib.sh
> index 6b0a83d..f56a011 100755
> --- a/kdump-lib.sh
> +++ b/kdump-lib.sh
> @@ -906,6 +906,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 + (_add / 1024)))G"
> + ;;
> + *)
> + _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()