From 5859628dbdbf542ac65538c755dd37301afe7007 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Piccoli" Date: Wed, 18 Jan 2023 19:26:14 -0300 Subject: [PATCH] kdump-load: Parse the biggest RAM buffer for pstore The way kdump-load parses /proc/iomem currently expects it has only a single RAM buffer - but what if we have more, how to choose? This commit enables multi RAM buffers parsing, and the tool now copes with various available buffers, selecting the biggest one. Signed-off-by: Guilherme G. Piccoli --- kdump-load.sh.in | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/kdump-load.sh.in b/kdump-load.sh.in index b61df85..f343bba 100644 --- a/kdump-load.sh.in +++ b/kdump-load.sh.in @@ -74,6 +74,27 @@ clear_all_initrds() { rm -f "${MOUNT_FOLDER}"/kdump-initrd-* } +# Next routine parses /proc/iomem to obtain the biggest RAM buffer +# available. Saves the results in 2 global variables: MEM_{SIZE,START}. +parse_ram_buffers() { + BUFFERS="$(grep "RAM buffer" /proc/iomem)" + while read -r line + do + RANGE=$(echo "$line" | cut -f1 -d\ ) + + MEM_END=$(echo "$RANGE" | cut -f2 -d-) + MSTART=$(echo "$RANGE" | cut -f1 -d-) + MSIZE=$(( 16#${MEM_END} - 16#${MSTART} )) + + if [ ${MSIZE} -gt "${MEM_SIZE}" ]; then + MEM_SIZE="${MSIZE}" + MEM_START="${MSTART}" + fi + done <<< "${BUFFERS}" + # Trick to preserve global variables modifications inside loops + # using here-strings got from https://stackoverflow.com/a/16854326 . +} + # Function to display basic help about how to use this tool. usage() { cat <