This is a pretty big refactor in the logic / goals of this kdump implementation. * WHY? We want to decouple completely the log submission mechanism from the kdump tooling, for mainly two reasons: reuse this submission API/mechanism in other log collection tools, and to allow upstreaming the kdump tooling for Arch Linux generically, not embedding SteamOS particulars to it. * HOW: First of all, we dropped the log submission bits from this codebase. We also deleted the particulars of SteamOS/Deck in the log naming, like collecting the serial of the device if "Jupiter" model is found in the DMI info or getting the Steam user account via the VDF file. All of that will happen in a later stage of the log processing, done by *another tool* that shall rename the logs and transmit them to the Valve servers. While at it, we've done other small changes in the logic to make this kdump tool more generic and reliable, like allowing the collection of kdump *AND* pstore logs (not choosing one of them). * CAVEATS / TODO: More to come in this front, we still definitely need to remove more references to SteamOS and clear a bit the code from its particulars. Important also is to update the README to reflect the changes made by the upstreaming effort. Mea culpa: these changes are invasive, switch some logic and expectations around the package, so making them fully bisectable would be way harder than not. Hence, please take that into account: this series should be tested/merged as a whole, it's not guaranteed that individual patches work correctly in a standalone fashion. Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
140 lines
4.1 KiB
Bash
140 lines
4.1 KiB
Bash
#!/bin/sh
|
|
#
|
|
# SPDX-License-Identifier: LGPL-2.1+
|
|
#
|
|
# Copyright (c) 2021 Valve.
|
|
# Maintainer: Guilherme G. Piccoli <gpiccoli@igalia.com>
|
|
#
|
|
# This is the SteamOS kdump/pstore log collector; this script prepares the
|
|
# pstore/kdump collected data and save it in the local disk, in the next
|
|
# successful boot.
|
|
#
|
|
|
|
# We do some validation to be sure KDUMP_MNT pointed path is valid...
|
|
# That and having a valid /usr/share/kdump/kdump.conf are essential conditions.
|
|
if [ ! -s "/usr/share/kdump/kdump.conf" ]; then
|
|
logger "kdump-steamos: /usr/share/kdump/kdump.conf is missing, aborting."
|
|
exit 0
|
|
fi
|
|
|
|
. /usr/share/kdump/kdump.conf
|
|
|
|
KDUMP_MAIN_FOLDER="$(cat "${KDUMP_MNT}")"
|
|
rm -f "${KDUMP_MNT}"
|
|
|
|
if [ ! -d "${KDUMP_MAIN_FOLDER}" ]; then
|
|
logger "kdump-steamos: invalid folder (${KDUMP_MAIN_FOLDER}) - aborting..."
|
|
exit 0
|
|
fi
|
|
|
|
LOGS_FOUND=0
|
|
KDUMP_TMP_FOLDER="${KDUMP_MAIN_FOLDER}/.tmp"
|
|
|
|
# Use UTC timezone to match kdump collection
|
|
CURRENT_TSTAMP=$(date -u +"%Y%m%d%H%M")
|
|
|
|
# By default, pstore is mounted in this location; if it isn't, we bail-out.
|
|
# Notice we currently only support the logs generated by the ramoops backend.
|
|
PSTORE_CNT=$(find /sys/fs/pstore/* 2>/dev/null | grep -c ramoops)
|
|
if [ "${PSTORE_CNT}" -ne 0 ]; then
|
|
|
|
PSTORE_FOLDER="${KDUMP_TMP_FOLDER}/pstore"
|
|
mkdir -p "${PSTORE_FOLDER}"
|
|
|
|
LOOP_CNT=0
|
|
while [ "${PSTORE_CNT}" -gt 0 ]; do
|
|
PSTORE_FILE="$(find /sys/fs/pstore/* | grep ramoops | sort | head -n1)"
|
|
SAVED_FILE="${PSTORE_FOLDER}/dmesg-pstore.${CURRENT_TSTAMP}-${LOOP_CNT}"
|
|
|
|
cat "${PSTORE_FILE}" > "${SAVED_FILE}"
|
|
sync "${SAVED_FILE}"
|
|
rm -f "${PSTORE_FILE}"
|
|
|
|
PSTORE_CNT=$((PSTORE_CNT - 1))
|
|
LOOP_CNT=$((LOOP_CNT + 1))
|
|
done
|
|
LOGS_FOUND=${LOOP_CNT}
|
|
|
|
# Logs should live on <...>/.tmp folder, due to the zip compression.
|
|
mv "${PSTORE_FOLDER}"/* "${KDUMP_TMP_FOLDER}/" 2>/dev/null
|
|
rm -rf "${PSTORE_FOLDER}"
|
|
fi
|
|
|
|
# Now, we proceed the same way if there are kdump data.
|
|
KDUMP_CRASH_FOLDER="${KDUMP_MAIN_FOLDER}/crash"
|
|
|
|
KDUMP_CNT=$(find "${KDUMP_CRASH_FOLDER}"/* -type d 2>/dev/null | wc -l)
|
|
if [ "${KDUMP_CNT}" -ne 0 ]; then
|
|
KD_FOLDER="${KDUMP_TMP_FOLDER}/kdump"
|
|
mkdir -p "${KD_FOLDER}"
|
|
|
|
LOOP_CNT=0
|
|
while [ "${KDUMP_CNT}" -gt 0 ]; do
|
|
CRASH_CURRENT=$(find "${KDUMP_CRASH_FOLDER}"/* -type d 2>/dev/null | head -n1)
|
|
|
|
# When collecting the vmcore/dmesg during kdump, folder is
|
|
# saved with its name == the timestamp of the collection.
|
|
CRASH_TSTAMP=$(basename "${CRASH_CURRENT}")
|
|
|
|
if [ -s "${CRASH_CURRENT}/dmesg.txt" ]; then
|
|
SAVED_FILE="${KD_FOLDER}/dmesg-kdump.${CRASH_TSTAMP}"
|
|
mv "${CRASH_CURRENT}/dmesg.txt" "${SAVED_FILE}"
|
|
sync "${SAVED_FILE}"
|
|
|
|
fi
|
|
|
|
# We won't pack vmcores in the zip blob, but let's save
|
|
# it in case it was collected as well.
|
|
if [ -s "${CRASH_CURRENT}/vmcore.compressed" ]; then
|
|
SAVED_FILE="${KDUMP_CRASH_FOLDER}/vmcore.${CRASH_TSTAMP}"
|
|
mv "${CRASH_CURRENT}/vmcore.compressed" "${SAVED_FILE}"
|
|
sync "${SAVED_FILE}"
|
|
|
|
fi
|
|
|
|
rm -rf "${CRASH_CURRENT}"
|
|
KDUMP_CNT=$((KDUMP_CNT - 1))
|
|
LOOP_CNT=$((LOOP_CNT + 1))
|
|
done
|
|
|
|
LOGS_FOUND=$((LOGS_FOUND + LOOP_CNT))
|
|
|
|
# Logs should live on .tmp folder, due to the zip compression.
|
|
mv "${KD_FOLDER}"/* "${KDUMP_TMP_FOLDER}/" 2>/dev/null
|
|
rm -rf "${KD_FOLDER}"
|
|
fi
|
|
|
|
|
|
# If we have pstore and/or kdump logs, let's process them...
|
|
KDUMP_LOGS_FOLDER="${KDUMP_MAIN_FOLDER}/logs"
|
|
|
|
if [ ${LOGS_FOUND} -ne 0 ]; then
|
|
mkdir -p "${KDUMP_LOGS_FOLDER}"
|
|
|
|
# First we collect some more info, like DMI data, os-release, etc;
|
|
DMI_FNAME="${KDUMP_TMP_FOLDER}/dmidecode.${CURRENT_TSTAMP}"
|
|
dmidecode > "${DMI_FNAME}"
|
|
|
|
BUILD_FNAME="${KDUMP_TMP_FOLDER}/build.${CURRENT_TSTAMP}"
|
|
cp "/etc/os-release" "${BUILD_FNAME}"
|
|
|
|
VERSION_FNAME="${KDUMP_TMP_FOLDER}/version.${CURRENT_TSTAMP}"
|
|
uname -r > "${VERSION_FNAME}"
|
|
|
|
sync "${DMI_FNAME}" "${BUILD_FNAME}" "${VERSION_FNAME}"
|
|
|
|
# Create the dump compressed pack.
|
|
LOG_FNAME="kdump-${CURRENT_TSTAMP}.zip"
|
|
LOG_FNAME="${KDUMP_LOGS_FOLDER}/${LOG_FNAME}"
|
|
zip -9 -jq "${LOG_FNAME}" "${KDUMP_TMP_FOLDER}"/* 1>/dev/null
|
|
|
|
sync "${LOG_FNAME}" 2>/dev/null
|
|
if [ ! -s "${LOG_FNAME}" ]; then
|
|
logger "kdump-steamos: couldn't create the log archive, aborting..."
|
|
else
|
|
logger "kdump-steamos: logs saved locally (check ${KDUMP_LOGS_FOLDER})"
|
|
fi
|
|
fi
|
|
|
|
rm -rf "${KDUMP_TMP_FOLDER}"
|