From 01ea0171065270f1ebdc23e1abfbfc1b75104a25 Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Nov 15 2023 08:16:55 +0000 Subject: Allow _crashkernel_add to address larger memory ranges Resolves: https://issues.redhat.com/browse/RHEL-8727 Resolves: https://issues.redhat.com/browse/RHEL-8710 Upstream: Fedora Conflict: spec/kdump-lib_spec.sh doesn't exist in RHEL, so I remove the hunk directly. commit 3d253ab81134d9f68d230aeeceb3158026b597aa Author: Coiby Xu Date: Tue Oct 10 14:31:36 2023 +0800 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 Acked-by: Baoquan He Signed-off-by: Baoquan He --- diff --git a/kdump-lib.sh b/kdump-lib.sh index 5edb549..80b5dfb 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -993,7 +993,7 @@ has_aarch64_smmu() 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 # i.e. -[] @@ -1024,6 +1024,18 @@ to_bytes() _s=${_s::-1} _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 @@ -1032,7 +1044,7 @@ to_bytes() memsize_add() { - local -a units=("" "K" "M" "G") + local -a units=("" "K" "M" "G" "T" "P" "E") local i a b a=$(to_bytes "$1") || return 1