Petr Šabata f5bf49
#!/bin/sh
13a24c
#
050f80
# The main kdump routine in capture kernel, bash may not be the
050f80
# default shell. Any code added must be POSIX compliant.
Petr Šabata f5bf49
Petr Šabata f5bf49
. /lib/dracut-lib.sh
f9025c
. /lib/kdump-logger.sh
Petr Šabata f5bf49
. /lib/kdump-lib-initramfs.sh
Petr Šabata f5bf49
f9025c
#initiate the kdump logger
eb6eaf
if ! dlog_init; then
5e60aa
	echo "failed to initiate the kdump logger."
5e60aa
	exit 1
f9025c
fi
f9025c
f9025c
KDUMP_PATH="/var/crash"
f9025c
KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log"
f9025c
CORE_COLLECTOR=""
f9025c
DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31"
f9025c
DMESG_COLLECTOR="/sbin/vmcore-dmesg"
f9025c
FAILURE_ACTION="systemctl reboot -f"
eb6eaf
DATEDIR=$(date +%Y-%m-%d-%T)
f9025c
HOST_IP='127.0.0.1'
f9025c
DUMP_INSTRUCTION=""
f9025c
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
f9025c
DD_BLKSIZE=512
f9025c
FINAL_ACTION="systemctl reboot -f"
f9025c
KDUMP_PRE=""
f9025c
KDUMP_POST=""
f9025c
NEWROOT="/sysroot"
f9025c
OPALCORE="/sys/firmware/opal/mpipl/core"
eb6eaf
KDUMP_CONF_PARSED="/tmp/kdump.conf.$$"
f9025c
62d6f3
# POSIX doesn't have pipefail, only apply when using bash
62d6f3
# shellcheck disable=SC3040
62d6f3
[ -n "$BASH" ] && set -o pipefail
62d6f3
Petr Šabata f5bf49
DUMP_RETVAL=0
Petr Šabata f5bf49
eb6eaf
kdump_read_conf > $KDUMP_CONF_PARSED
eb6eaf
f9025c
get_kdump_confs()
f9025c
{
5e60aa
	while read -r config_opt config_val; do
5e60aa
		# remove inline comments after the end of a directive.
5e60aa
		case "$config_opt" in
5e60aa
		path)
5e60aa
			KDUMP_PATH="$config_val"
5e60aa
			;;
5e60aa
		core_collector)
5e60aa
			[ -n "$config_val" ] && CORE_COLLECTOR="$config_val"
5e60aa
			;;
5e60aa
		sshkey)
5e60aa
			if [ -f "$config_val" ]; then
5e60aa
				SSH_KEY_LOCATION=$config_val
5e60aa
			fi
5e60aa
			;;
5e60aa
		kdump_pre)
5e60aa
			KDUMP_PRE="$config_val"
5e60aa
			;;
5e60aa
		kdump_post)
5e60aa
			KDUMP_POST="$config_val"
5e60aa
			;;
5e60aa
		fence_kdump_args)
5e60aa
			FENCE_KDUMP_ARGS="$config_val"
5e60aa
			;;
5e60aa
		fence_kdump_nodes)
5e60aa
			FENCE_KDUMP_NODES="$config_val"
5e60aa
			;;
5e60aa
		failure_action | default)
5e60aa
			case $config_val in
5e60aa
			shell)
5e60aa
				FAILURE_ACTION="kdump_emergency_shell"
5e60aa
				;;
5e60aa
			reboot)
5e60aa
				FAILURE_ACTION="systemctl reboot -f && exit"
5e60aa
				;;
5e60aa
			halt)
5e60aa
				FAILURE_ACTION="halt && exit"
5e60aa
				;;
5e60aa
			poweroff)
5e60aa
				FAILURE_ACTION="systemctl poweroff -f && exit"
5e60aa
				;;
5e60aa
			dump_to_rootfs)
5e60aa
				FAILURE_ACTION="dump_to_rootfs"
5e60aa
				;;
5e60aa
			esac
5e60aa
			;;
5e60aa
		final_action)
5e60aa
			case $config_val in
5e60aa
			reboot)
5e60aa
				FINAL_ACTION="systemctl reboot -f"
5e60aa
				;;
5e60aa
			halt)
5e60aa
				FINAL_ACTION="halt"
5e60aa
				;;
5e60aa
			poweroff)
5e60aa
				FINAL_ACTION="systemctl poweroff -f"
5e60aa
				;;
5e60aa
			esac
5e60aa
			;;
5e60aa
		esac
5e60aa
	done < "$KDUMP_CONF_PARSED"
5e60aa
5e60aa
	if [ -z "$CORE_COLLECTOR" ]; then
5e60aa
		CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"
5e60aa
		if is_ssh_dump_target || is_raw_dump_target; then
5e60aa
			CORE_COLLECTOR="$CORE_COLLECTOR -F"
5e60aa
		fi
5e60aa
	fi
f9025c
}
f9025c
f9025c
# store the kexec kernel log to a file.
f9025c
save_log()
f9025c
{
5e60aa
	dmesg -T > $KDUMP_LOG_FILE
f9025c
5e60aa
	if command -v journalctl > /dev/null; then
5e60aa
		journalctl -ab >> $KDUMP_LOG_FILE
5e60aa
	fi
5e60aa
	chmod 600 $KDUMP_LOG_FILE
f9025c
}
f9025c
eb6eaf
# $1: dump path, must be a mount point
f9025c
dump_fs()
f9025c
{
5e60aa
	ddebug "dump_fs _mp=$1"
5e60aa
5e60aa
	if ! is_mounted "$1"; then
5e60aa
		dinfo "dump path '$1' is not mounted, trying to mount..."
5e60aa
		if ! mount --target "$1"; then
5e60aa
			derror "failed to dump to '$1', it's not a mount point!"
5e60aa
			return 1
5e60aa
		fi
5e60aa
	fi
5e60aa
5e60aa
	# Remove -F in makedumpfile case. We don't want a flat format dump here.
5e60aa
	case $CORE_COLLECTOR in
5e60aa
	*makedumpfile*)
5e60aa
		CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g")
5e60aa
		;;
5e60aa
	esac
5e60aa
5e60aa
	_dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)
5e60aa
	dinfo "saving to $_dump_fs_path"
5e60aa
5e60aa
	# Only remount to read-write mode if the dump target is mounted read-only.
5e60aa
	_dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f)
5e60aa
	case $_dump_mnt_op in
5e60aa
	ro*)
5e60aa
		dinfo "Remounting the dump target in rw mode."
5e60aa
		mount -o remount,rw "$1" || return 1
5e60aa
		;;
5e60aa
	esac
5e60aa
5e60aa
	mkdir -p "$_dump_fs_path" || return 1
5e60aa
5e60aa
	save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path"
5e60aa
	save_opalcore_fs "$_dump_fs_path"
5e60aa
5e60aa
	dinfo "saving vmcore"
5e60aa
	$CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete"
5e60aa
	_dump_exitcode=$?
5e60aa
	if [ $_dump_exitcode -eq 0 ]; then
5e60aa
		mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore"
5e60aa
		sync
5e60aa
		dinfo "saving vmcore complete"
5e60aa
	else
5e60aa
		derror "saving vmcore failed, exitcode:$_dump_exitcode"
5e60aa
	fi
5e60aa
5e60aa
	dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/"
5e60aa
	save_log
5e60aa
	mv "$KDUMP_LOG_FILE" "$_dump_fs_path/"
5e60aa
	if [ $_dump_exitcode -ne 0 ]; then
5e60aa
		return 1
5e60aa
	fi
5e60aa
5e60aa
	# improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure
5e60aa
	return 0
f9025c
}
f9025c
eb6eaf
# $1: dmesg collector
eb6eaf
# $2: dump path
5e60aa
save_vmcore_dmesg_fs()
5e60aa
{
5e60aa
	dinfo "saving vmcore-dmesg.txt to $2"
5e60aa
	if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then
5e60aa
		mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
5e60aa
		chmod 600 "$2/vmcore-dmesg.txt"
5e60aa
5e60aa
		# Make sure file is on disk. There have been instances where later
5e60aa
		# saving vmcore failed and system rebooted without sync and there
5e60aa
		# was no vmcore-dmesg.txt available.
5e60aa
		sync
5e60aa
		dinfo "saving vmcore-dmesg.txt complete"
5e60aa
	else
5e60aa
		if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then
5e60aa
			chmod 600 "$2/vmcore-dmesg-incomplete.txt"
5e60aa
		fi
5e60aa
		derror "saving vmcore-dmesg.txt failed"
5e60aa
	fi
f9025c
}
f9025c
eb6eaf
# $1: dump path
5e60aa
save_opalcore_fs()
5e60aa
{
5e60aa
	if [ ! -f $OPALCORE ]; then
5e60aa
		# Check if we are on an old kernel that uses a different path
5e60aa
		if [ -f /sys/firmware/opal/core ]; then
5e60aa
			OPALCORE="/sys/firmware/opal/core"
5e60aa
		else
5e60aa
			return 0
5e60aa
		fi
5e60aa
	fi
5e60aa
5e60aa
	dinfo "saving opalcore:$OPALCORE to $1/opalcore"
5e60aa
	if ! cp $OPALCORE "$1/opalcore"; then
5e60aa
		derror "saving opalcore failed"
5e60aa
		return 1
5e60aa
	fi
5e60aa
5e60aa
	sync
5e60aa
	dinfo "saving opalcore complete"
5e60aa
	return 0
f9025c
}
f9025c
f9025c
dump_to_rootfs()
f9025c
{
f9025c
5e60aa
	if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then
5e60aa
		dinfo "Trying to bring up initqueue for rootfs mount"
5e60aa
		systemctl start dracut-initqueue
5e60aa
	fi
5e60aa
5e60aa
	dinfo "Clean up dead systemd services"
5e60aa
	systemctl cancel
5e60aa
	dinfo "Waiting for rootfs mount, will timeout after 90 seconds"
5e60aa
	systemctl start --no-block sysroot.mount
5e60aa
5e60aa
	_loop=0
5e60aa
	while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do
5e60aa
		sleep 1
5e60aa
		_loop=$((_loop + 1))
5e60aa
	done
5e60aa
5e60aa
	if ! is_mounted /sysroot; then
5e60aa
		derror "Failed to mount rootfs"
5e60aa
		return
5e60aa
	fi
5e60aa
5e60aa
	ddebug "NEWROOT=$NEWROOT"
5e60aa
	dump_fs $NEWROOT
f9025c
}
f9025c
f9025c
kdump_emergency_shell()
f9025c
{
5e60aa
	ddebug "Switching to kdump emergency shell..."
5e60aa
5e60aa
	[ -f /etc/profile ] && . /etc/profile
5e60aa
	export PS1='kdump:${PWD}# '
5e60aa
5e60aa
	. /lib/dracut-lib.sh
5e60aa
	if [ -f /dracut-state.sh ]; then
5e60aa
		. /dracut-state.sh 2> /dev/null
5e60aa
	fi
5e60aa
5e60aa
	source_conf /etc/conf.d
5e60aa
5e60aa
	type plymouth > /dev/null 2>&1 && plymouth quit
5e60aa
5e60aa
	source_hook "emergency"
5e60aa
	while read -r _tty rest; do
5e60aa
		(
5e60aa
			echo
5e60aa
			echo
5e60aa
			echo 'Entering kdump emergency mode.'
5e60aa
			echo 'Type "journalctl" to view system logs.'
5e60aa
			echo 'Type "rdsosreport" to generate a sosreport, you can then'
5e60aa
			echo 'save it elsewhere and attach it to a bug report.'
5e60aa
			echo
5e60aa
			echo
5e60aa
		) > "/dev/$_tty"
5e60aa
	done < /proc/consoles
5e60aa
	sh -i -l
5e60aa
	/bin/rm -f -- /.console_lock
f9025c
}
f9025c
f9025c
do_failure_action()
f9025c
{
5e60aa
	dinfo "Executing failure action $FAILURE_ACTION"
5e60aa
	eval $FAILURE_ACTION
f9025c
}
f9025c
f9025c
do_final_action()
f9025c
{
5e60aa
	dinfo "Executing final action $FINAL_ACTION"
5e60aa
	eval $FINAL_ACTION
f9025c
}
eb6eaf
Petr Šabata f5bf49
do_dump()
Petr Šabata f5bf49
{
5e60aa
	eval $DUMP_INSTRUCTION
5e60aa
	_ret=$?
Petr Šabata f5bf49
5e60aa
	if [ $_ret -ne 0 ]; then
5e60aa
		derror "saving vmcore failed"
5e60aa
	fi
Petr Šabata f5bf49
5e60aa
	return $_ret
Petr Šabata f5bf49
}
Petr Šabata f5bf49
Petr Šabata f5bf49
do_kdump_pre()
Petr Šabata f5bf49
{
5e60aa
	if [ -n "$KDUMP_PRE" ]; then
5e60aa
		"$KDUMP_PRE"
5e60aa
		_ret=$?
5e60aa
		if [ $_ret -ne 0 ]; then
5e60aa
			derror "$KDUMP_PRE exited with $_ret status"
5e60aa
			return $_ret
5e60aa
		fi
5e60aa
	fi
5e60aa
5e60aa
	# if any script fails, it just raises warning and continues
5e60aa
	if [ -d /etc/kdump/pre.d ]; then
5e60aa
		for file in /etc/kdump/pre.d/*; do
5e60aa
			"$file"
5e60aa
			_ret=$?
5e60aa
			if [ $_ret -ne 0 ]; then
5e60aa
				derror "$file exited with $_ret status"
5e60aa
			fi
5e60aa
		done
5e60aa
	fi
5e60aa
	return 0
Petr Šabata f5bf49
}
Petr Šabata f5bf49
Petr Šabata f5bf49
do_kdump_post()
Petr Šabata f5bf49
{
5e60aa
	if [ -d /etc/kdump/post.d ]; then
5e60aa
		for file in /etc/kdump/post.d/*; do
5e60aa
			"$file" "$1"
5e60aa
			_ret=$?
5e60aa
			if [ $_ret -ne 0 ]; then
5e60aa
				derror "$file exited with $_ret status"
5e60aa
			fi
5e60aa
		done
5e60aa
	fi
5e60aa
5e60aa
	if [ -n "$KDUMP_POST" ]; then
5e60aa
		"$KDUMP_POST" "$1"
5e60aa
		_ret=$?
5e60aa
		if [ $_ret -ne 0 ]; then
5e60aa
			derror "$KDUMP_POST exited with $_ret status"
5e60aa
		fi
5e60aa
	fi
Petr Šabata f5bf49
}
Petr Šabata f5bf49
eb6eaf
# $1: block target, eg. /dev/sda
Petr Šabata f5bf49
dump_raw()
Petr Šabata f5bf49
{
5e60aa
	[ -b "$1" ] || return 1
Petr Šabata f5bf49
5e60aa
	dinfo "saving to raw disk $1"
Petr Šabata f5bf49
5e60aa
	if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then
5e60aa
		_src_size=$(stat --format %s /proc/vmcore)
5e60aa
		_src_size_mb=$((_src_size / 1048576))
5e60aa
		/kdumpscripts/monitor_dd_progress $_src_size_mb &
5e60aa
	fi
Petr Šabata f5bf49
5e60aa
	dinfo "saving vmcore"
5e60aa
	$CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1
5e60aa
	sync
Petr Šabata f5bf49
5e60aa
	dinfo "saving vmcore complete"
5e60aa
	return 0
Petr Šabata f5bf49
}
Petr Šabata f5bf49
eb6eaf
# $1: ssh key file
eb6eaf
# $2: ssh address in <user>@<host> format
Petr Šabata f5bf49
dump_ssh()
Petr Šabata f5bf49
{
5e60aa
	_ret=0
5e60aa
	_ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
5e60aa
	_ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
5e60aa
	if is_ipv6_address "$2"; then
5e60aa
		_scp_address=${2%@*}@"[${2#*@}]"
5e60aa
	else
5e60aa
		_scp_address=$2
5e60aa
	fi
5e60aa
5e60aa
	dinfo "saving to $2:$_ssh_dir"
5e60aa
5e60aa
	cat /var/lib/random-seed > /dev/urandom
5e60aa
	ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1
5e60aa
5e60aa
	save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2"
5e60aa
	dinfo "saving vmcore"
5e60aa
5e60aa
	save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address"
5e60aa
5e60aa
	if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
5e60aa
		scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
5e60aa
		_ret=$?
5e60aa
		_vmcore="vmcore"
5e60aa
	else
5e60aa
		$CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
5e60aa
		_ret=$?
5e60aa
		_vmcore="vmcore.flat"
5e60aa
	fi
5e60aa
5e60aa
	if [ $_ret -eq 0 ]; then
5e60aa
		ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
5e60aa
		_ret=$?
5e60aa
		if [ $_ret -ne 0 ]; then
5e60aa
			derror "moving vmcore failed, exitcode:$_ret"
5e60aa
		else
5e60aa
			dinfo "saving vmcore complete"
5e60aa
		fi
5e60aa
	else
5e60aa
		derror "saving vmcore failed, exitcode:$_ret"
5e60aa
	fi
5e60aa
5e60aa
	dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/"
5e60aa
	save_log
5e60aa
	if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then
5e60aa
		derror "saving log file failed, _exitcode:$_ret"
5e60aa
	fi
5e60aa
5e60aa
	return $_ret
Petr Šabata f5bf49
}
Petr Šabata f5bf49
eb6eaf
# $1: dump path
eb6eaf
# $2: ssh opts
eb6eaf
# $3: ssh address in <user>@<host> format
eb6eaf
# $4: scp address, similar with ssh address but IPv6 addresses are quoted
5e60aa
save_opalcore_ssh()
5e60aa
{
5e60aa
	if [ ! -f $OPALCORE ]; then
5e60aa
		# Check if we are on an old kernel that uses a different path
5e60aa
		if [ -f /sys/firmware/opal/core ]; then
5e60aa
			OPALCORE="/sys/firmware/opal/core"
5e60aa
		else
5e60aa
			return 0
5e60aa
		fi
5e60aa
	fi
5e60aa
5e60aa
	dinfo "saving opalcore:$OPALCORE to $3:$1"
5e60aa
5e60aa
	if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then
5e60aa
		derror "saving opalcore failed"
5e60aa
		return 1
5e60aa
	fi
5e60aa
5e60aa
	ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
5e60aa
	dinfo "saving opalcore complete"
5e60aa
	return 0
Petr Šabata f5bf49
}
Petr Šabata f5bf49
eb6eaf
# $1: dmesg collector
eb6eaf
# $2: dump path
eb6eaf
# $3: ssh opts
eb6eaf
# $4: ssh address in <user>@<host> format
5e60aa
save_vmcore_dmesg_ssh()
5e60aa
{
5e60aa
	dinfo "saving vmcore-dmesg.txt to $4:$2"
5e60aa
	if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then
5e60aa
		ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
5e60aa
		dinfo "saving vmcore-dmesg.txt complete"
5e60aa
	else
5e60aa
		derror "saving vmcore-dmesg.txt failed"
5e60aa
	fi
Petr Šabata f5bf49
}
Petr Šabata f5bf49
Petr Šabata f5bf49
get_host_ip()
Petr Šabata f5bf49
{
5e60aa
	if is_nfs_dump_target || is_ssh_dump_target; then
5e60aa
		kdumpnic=$(getarg kdumpnic=)
5e60aa
		if [ -z "$kdumpnic" ]; then
5e60aa
			derror "failed to get kdumpnic!"
5e60aa
			return 1
5e60aa
		fi
5e60aa
		if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then
5e60aa
			derror "wrong kdumpnic: $kdumpnic"
5e60aa
			return 1
5e60aa
		fi
5e60aa
		kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}')
5e60aa
		kdumphost="${kdumphost%%/*}"
5e60aa
		if [ -z "$kdumphost" ]; then
5e60aa
			derror "wrong kdumpnic: $kdumpnic"
5e60aa
			return 1
5e60aa
		fi
5e60aa
		HOST_IP=$kdumphost
5e60aa
	fi
5e60aa
	return 0
Petr Šabata f5bf49
}
Petr Šabata f5bf49
67b8dd
read_kdump_confs()
Petr Šabata f5bf49
{
5e60aa
	if [ ! -f "$KDUMP_CONFIG_FILE" ]; then
5e60aa
		derror "$KDUMP_CONFIG_FILE not found"
5e60aa
		return
5e60aa
	fi
5e60aa
5e60aa
	get_kdump_confs
5e60aa
5e60aa
	# rescan for add code for dump target
5e60aa
	while read -r config_opt config_val; do
5e60aa
		# remove inline comments after the end of a directive.
5e60aa
		case "$config_opt" in
5e60aa
		dracut_args)
5e60aa
			config_val=$(get_dracut_args_target "$config_val")
5e60aa
			if [ -n "$config_val" ]; then
5e60aa
				config_val=$(get_mntpoint_from_target "$config_val")
5e60aa
				DUMP_INSTRUCTION="dump_fs $config_val"
5e60aa
			fi
5e60aa
			;;
5e60aa
		ext[234] | xfs | btrfs | minix | nfs)
5e60aa
			config_val=$(get_mntpoint_from_target "$config_val")
5e60aa
			DUMP_INSTRUCTION="dump_fs $config_val"
5e60aa
			;;
5e60aa
		raw)
5e60aa
			DUMP_INSTRUCTION="dump_raw $config_val"
5e60aa
			;;
5e60aa
		ssh)
5e60aa
			DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val"
5e60aa
			;;
5e60aa
		esac
5e60aa
	done < "$KDUMP_CONF_PARSED"
Petr Šabata f5bf49
}
Petr Šabata f5bf49
Petr Šabata f5bf49
fence_kdump_notify()
Petr Šabata f5bf49
{
5e60aa
	if [ -n "$FENCE_KDUMP_NODES" ]; then
5e60aa
		# shellcheck disable=SC2086
5e60aa
		$FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES &
5e60aa
	fi
Petr Šabata f5bf49
}
Petr Šabata f5bf49
13a24c
if [ "$1" = "--error-handler" ]; then
5e60aa
	get_kdump_confs
5e60aa
	do_failure_action
5e60aa
	do_final_action
13a24c
5e60aa
	exit $?
13a24c
fi
13a24c
13a24c
# continue here only if we have to save dump.
13a24c
if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ] && [ ! -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then
5e60aa
	exit 0
13a24c
fi
13a24c
67b8dd
read_kdump_confs
Petr Šabata f5bf49
fence_kdump_notify
Petr Šabata f5bf49
eb6eaf
if ! get_host_ip; then
5e60aa
	derror "get_host_ip exited with non-zero status!"
5e60aa
	exit 1
Petr Šabata f5bf49
fi
Petr Šabata f5bf49
Petr Šabata f5bf49
if [ -z "$DUMP_INSTRUCTION" ]; then
5e60aa
	DUMP_INSTRUCTION="dump_fs $NEWROOT"
Petr Šabata f5bf49
fi
Petr Šabata f5bf49
eb6eaf
if ! do_kdump_pre; then
5e60aa
	derror "kdump_pre script exited with non-zero status!"
5e60aa
	do_final_action
5e60aa
	# During systemd service to reboot the machine, stop this shell script running
5e60aa
	exit 1
Petr Šabata f5bf49
fi
Petr Šabata f5bf49
make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab'
Petr Šabata f5bf49
do_dump
Petr Šabata f5bf49
DUMP_RETVAL=$?
Petr Šabata f5bf49
eb6eaf
if ! do_kdump_post $DUMP_RETVAL; then
5e60aa
	derror "kdump_post script exited with non-zero status!"
Petr Šabata f5bf49
fi
Petr Šabata f5bf49
Petr Šabata f5bf49
if [ $DUMP_RETVAL -ne 0 ]; then
5e60aa
	exit 1
Petr Šabata f5bf49
fi
Petr Šabata f5bf49
Petr Šabata f5bf49
do_final_action