There are multiple places getting the reserved memory size,
so make it a library function in kdump-lib.sh.
We will call it in the following patch as well.
Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
---
kdump-lib.sh | 12 ++++++++++++
kdumpctl | 3 +--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index e3b5a01..4022459 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -406,3 +406,15 @@ get_dracut_args_target()
{
echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut
-d' ' -f1
}
+
+get_reserved_memory_mb()
+{
+ local mem
+
+ if [ ! -f "/sys/kernel/kexec_crash_size" ]; then
+ echo -n "0"
+ else
+ mem=$(cat /sys/kernel/kexec_crash_size)
+ echo -n "$(($mem / 1024 / 1024))"
+ fi
+}
diff --git a/kdumpctl b/kdumpctl
index dbdfef6..ce71138 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -964,8 +964,7 @@ is_secure_boot_enforced()
check_crash_mem_reserved()
{
- MEM_RESERVED=$(cat /sys/kernel/kexec_crash_size)
- if [ $MEM_RESERVED -eq 0 ]
+ if [ "$(get_reserved_memory_mb)" -eq 0 ]
then
echo "No memory reserved for crash kernel." >&2
return 1
--
1.8.3.1