From a8921f04aecb149b7dcdb7da2fcd80d198dc9cef Mon Sep 17 00:00:00 2001 From: WANG Chao Date: Tue, 24 Sep 2013 21:33:27 +0800 Subject: [PATCH] Introduce kdump-lib.sh for kdump shared functions Currently in the whole kdump framework, we have some common functions used across not only mkdumprd context and dracut context, but also 1st kernel and 2nd kernel. We defined these functions at each script, which is obviously not decent. So let's introduce kdump-lib.sh for the shared functions and put it to /lib/kdump/kdump-lib.sh. It starts small, as you can see, only 3 functions are extracted. But in the future more and more common functions can be added. Signed-off-by: WANG Chao Acked-by: Vivek Goyal --- dracut-kdump.sh | 16 +--------------- dracut-module-setup.sh | 7 ++----- kdump-lib.sh | 19 +++++++++++++++++++ kexec-tools.spec | 4 ++++ mkdumprd | 16 +--------------- 5 files changed, 27 insertions(+), 35 deletions(-) create mode 100755 kdump-lib.sh diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 7baa673..84dd72e 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -2,6 +2,7 @@ exec &> /dev/console . /lib/dracut-lib.sh +. /lib/kdump-lib.sh if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then rm -f -- $initdir/lib/dracut/no-emergency-shell @@ -198,21 +199,6 @@ save_vmcore_dmesg_ssh() { } -is_ssh_dump_target() -{ - grep -q "^ssh[[:blank:]].*@" $conf_file -} - -is_nfs_dump_target() -{ - grep -q "^nfs.*:" $conf_file -} - -is_raw_dump_target() -{ - grep -q "^raw" $conf_file -} - get_host_ip() { local _host diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index f49f7fe..10ecec6 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1,6 +1,7 @@ #!/bin/bash . $dracutfunctions +. /lib/kdump/kdump-lib.sh check() { [[ $debug ]] && set -x @@ -23,11 +24,6 @@ depends() { return 0 } -is_ssh_dump_target() -{ - grep -q "^ssh[[:blank:]].*@" /etc/kdump.conf -} - kdump_to_udev_name() { local dev="${1//\"/}" @@ -413,6 +409,7 @@ install() { inst "/sbin/makedumpfile" "/sbin/makedumpfile" inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg" inst_hook pre-pivot 9999 "$moddir/kdump.sh" + inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh" # Check for all the devices and if any device is iscsi, bring up iscsi # target. Ideally all this should be pushed into dracut iscsi module diff --git a/kdump-lib.sh b/kdump-lib.sh new file mode 100755 index 0000000..1d00f67 --- /dev/null +++ b/kdump-lib.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Kdump common functions +# + +is_ssh_dump_target() +{ + grep -q "^ssh[[:blank:]].*@" /etc/kdump.conf +} + +is_nfs_dump_target() +{ + grep -q "^nfs" /etc/kdump.conf +} + +is_raw_dump_target() +{ + grep -q "^raw" /etc/kdump.conf +} diff --git a/kexec-tools.spec b/kexec-tools.spec index b0775cd..7a43777 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -24,6 +24,7 @@ Source16: kdump.service Source17: rhcrashkernel-param Source18: kdump.sysconfig.s390x Source19: eppic_030413.tar.gz +Source20: kdump-lib.sh ####################################### # These are sources for mkdumpramfs @@ -156,6 +157,7 @@ mkdir -p -m755 $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d mkdir -p $RPM_BUILD_ROOT%{_unitdir} mkdir -p -m755 $RPM_BUILD_ROOT%{_bindir} mkdir -p -m755 $RPM_BUILD_ROOT%{_libdir} +mkdir -p -m755 $RPM_BUILD_ROOT%{_prefix}/lib/kdump install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/kdumpctl SYSCONFIG=$RPM_SOURCE_DIR/kdump.sysconfig.%{_target_cpu} @@ -168,6 +170,7 @@ install -m 644 %{SOURCE8} $RPM_BUILD_ROOT%{_sysconfdir}/kdump.conf install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8 install -m 755 %{SOURCE11} $RPM_BUILD_ROOT%{_datadir}/kdump/firstboot_kdump.py install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8 +install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh %ifnarch s390x # For s390x the ELF header is created in the kdump kernel and therefore kexec # udev rules are not required @@ -298,6 +301,7 @@ done /usr/sbin/* %{_bindir}/* %{_datadir}/kdump +%{_prefix}/lib/kdump %config(noreplace,missingok) %{_sysconfdir}/sysconfig/kdump %config(noreplace,missingok) %{_sysconfdir}/kdump.conf %ifnarch s390x diff --git a/mkdumprd b/mkdumprd index 26fe5af..ea84df5 100644 --- a/mkdumprd +++ b/mkdumprd @@ -6,6 +6,7 @@ # Written by Cong Wang # +. /lib/kdump/kdump-lib.sh export IN_KDUMP=1 conf_file="/etc/kdump.conf" @@ -243,21 +244,6 @@ check_size() { fi } -is_nfs_dump_target() -{ - grep -q "^nfs" $conf_file -} - -is_ssh_dump_target() -{ - grep -q "^ssh.*@" $conf_file -} - -is_raw_dump_target() -{ - grep -q "^raw" $conf_file -} - # $1: core_collector config value verify_core_collector() { if grep -q "^raw" $conf_file && [ "${1%% *}" != "makedumpfile" ]; then