Allow _crashkernel_add to address larger memory ranges

Currently _crashkernel_add can't deal with larger memory ranges like
terabyte. For example, '_crashkernel_add "128G-1T:4G" "0"' actually
returns empty result. This patch allows _crashkernel_add to address
terabyte, petabyte and exabyte memory ranges.

Fixes: 64f2827a ("kdump-lib: Harden _crashkernel_add")
Signed-off-by: Coiby Xu <coxu@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
This commit is contained in:
Coiby Xu 2023-10-10 14:31:36 +08:00
parent c9ac933cc2
commit 3d253ab811
2 changed files with 21 additions and 3 deletions

View File

@ -862,7 +862,7 @@ has_aarch64_smmu()
ls /sys/devices/platform/arm-smmu-* 1> /dev/null 2>&1 ls /sys/devices/platform/arm-smmu-* 1> /dev/null 2>&1
} }
is_memsize() { [[ "$1" =~ ^[+-]?[0-9]+[KkMmGg]?$ ]]; } is_memsize() { [[ "$1" =~ ^[+-]?[0-9]+[KkMmGgTtPbEe]?$ ]]; }
# range defined for crashkernel parameter # range defined for crashkernel parameter
# i.e. <start>-[<end>] # i.e. <start>-[<end>]
@ -893,6 +893,18 @@ to_bytes()
_s=${_s::-1} _s=${_s::-1}
_s="$((_s * 1024 * 1024 * 1024))" _s="$((_s * 1024 * 1024 * 1024))"
;; ;;
T|t)
_s=${_s::-1}
_s="$((_s * 1024 * 1024 * 1024 * 1024))"
;;
P|p)
_s=${_s::-1}
_s="$((_s * 1024 * 1024 * 1024 * 1024 * 1024))"
;;
E|e)
_s=${_s::-1}
_s="$((_s * 1024 * 1024 * 1024 * 1024 * 1024 * 1024))"
;;
*) *)
;; ;;
esac esac
@ -901,7 +913,7 @@ to_bytes()
memsize_add() memsize_add()
{ {
local -a units=("" "K" "M" "G") local -a units=("" "K" "M" "G" "T" "P" "E")
local i a b local i a b
a=$(to_bytes "$1") || return 1 a=$(to_bytes "$1") || return 1

View File

@ -52,14 +52,20 @@ Describe 'kdump-lib'
Context "For valid input values" Context "For valid input values"
Parameters Parameters
"1G-4G:256M,4G-64G:320M,64G-:576M" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M" "1G-4G:256M,4G-64G:320M,64G-:576M" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M"
"1G-4G:256M" "100" "1G-4G:268435556" # avoids any rounding when size % 1024 != 0
"1G-4G:256M,4G-64G:320M,64G-:576M@4G" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M@4G" "1G-4G:256M,4G-64G:320M,64G-:576M@4G" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M@4G"
"1G-4G:1G,4G-64G:2G,64G-:3G@4G" "100M" "1G-4G:1124M,4G-64G:2148M,64G-:3172M@4G" "1G-4G:1G,4G-64G:2G,64G-:3G@4G" "100M" "1G-4G:1124M,4G-64G:2148M,64G-:3172M@4G"
"1G-4G:10000K,4G-64G:20000K,64G-:40000K@4G" "100M" "1G-4G:112400K,4G-64G:122400K,64G-:142400K@4G" "1G-4G:10000K,4G-64G:20000K,64G-:40000K@4G" "100M" "1G-4G:112400K,4G-64G:122400K,64G-:142400K@4G"
"1,high" "1" "2,high" "1,high" "1" "2,high"
"1K,low" "1" "1025,low" "1K,low" "1" "1025,low"
"128G-1T:4G" "0" "128G-1T:4G"
"10T-100T:1T" "0" "10T-100T:1T"
"128G-1T:4G" "0M" "128G-1T:4G"
"128G-1P:4G" "0M" "128G-1P:4G"
"128G-1E:4G" "0M" "128G-1E:4G"
"1M@1G" "1k" "1025K@1G" "1M@1G" "1k" "1025K@1G"
"500M@1G" "-100m" "400M@1G" "500M@1G" "-100m" "400M@1G"
"1099511627776" "0" "1024G" "1099511627776" "0" "1T"
End End
It "should add delta to every value after ':'" It "should add delta to every value after ':'"
When call _crashkernel_add "$1" "$2" When call _crashkernel_add "$1" "$2"