From: Bernhard Walle Subject: [PATCH] Add udev rule to reload kdump References: bnc#389658 This patch - implements "try-restart" in the init script - adds a udev rule that uses "try-restart" to reload the kdump kernel in case of a memory or CPU hot plug event Signed-off-by: Bernhard Walle --- Makefile | 1 + init/kdump | 46 ++++++++++++++++++++++++++++++++++------------ udev/70-kdump.rules | 12 ++++++++++++ udev/Makefile | 9 +++++++++ 4 files changed, 56 insertions(+), 12 deletions(-) --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ install: make -C init install make -C gdb install make -C config install + make -C udev install clean: make -C src clean --- a/init/kdump +++ b/init/kdump @@ -1,4 +1,4 @@ -#! /bin/sh +#!/bin/bash # # Copyright 2005 Red Hat, Inc. # Author: Jeff Moyer @@ -36,6 +36,25 @@ KDUMP_IDENTIFY_KERNEL=/usr/sbin/kdump-id BOOTDIR="/boot" +# +# Checks if currently a kdump kernel is loaded. +# +# Returns: 0 (true) if a kdump kernel is loaded, +# 1 (false) if the kdump kernel is not loaded and +# -1 (false) if the feature is not implemented (too old kernel) +kdump_kernel_loaded() +{ + if [ -r /sys/kernel/kexec_crash_loaded ]; then + if [ "$(cat /sys/kernel/kexec_crash_loaded)" = "1" ]; then + return 0 + else + return 1 + fi + else + return -1 + fi +} + # The default dumper # # Clean up old stuff if necessary, check the free size @@ -303,24 +322,27 @@ case "$1" in fi ;; status) - if [ -r /sys/kernel/kexec_crash_loaded ]; then - if [ "$(cat /sys/kernel/kexec_crash_loaded)" = "1" ]; then - echo "kdump kernel loaded" - else - echo "kdump kernel not loaded" - fi - else - echo "not implemented" - fi + kdump_kernel_loaded + case $? in + 0) echo "kdump kernel loaded" ;; + 1) echo "kdump kernel not loaded" ;; + -1) echo "not implemented" ;; + esac ;; restart|reload) $0 stop $0 start ;; - condrestart) + condrestart|try-restart) + if kdump_kernel_loaded ; then + $0 start + else + rc_reset + fi + rc_status ;; *) - echo $"Usage: $0 {start|stop|status|restart|reload}" + echo $"Usage: $0 {start|stop|status|restart|reload|try-reload}" exit 1 esac --- /dev/null +++ b/udev/70-kdump.rules @@ -0,0 +1,12 @@ +# +# Kdump core headers needs to be regnerated if the CPUs or memory changes. +# For this, reload kdump. +# +# Novell Bug #389658 +# + +SUBSYSTEM=="cpu", ACTION=="online", PROGRAM="/etc/init.d/kdump try-restart" +SUBSYSTEM=="cpu", ACTION=="offline", PROGRAM="/etc/init.d/kdump try-restart" +SUBSYSTEM=="memory", ACTION=="add", PROGRAM="/etc/init.d/kdump try-restart" +SUBSYSTEM=="memory", ACTION=="remove", PROGRAM="/etc/init.d/kdump try-restart" + --- /dev/null +++ b/udev/Makefile @@ -0,0 +1,9 @@ +# Simple makefile to build kdump-helper +# +# (c) 2008, Bernhard Walle , SUSE LINUX Products GmbH + + +install: + mkdir -p $(DESTDIR)$(SYSCONFDIR)/udev/rules.d + install -m 0644 70-kdump.rules $(DESTDIR)$(SYSCONFDIR)/udev/rules.d +