In the later patch, the kdump error handler script can reuse some of the
code in kdump.sh. So introduce a new kdump library kdump-lib-2.sh and
put the common functions and variables there.
kdump-lib-2.sh is only used in 2nd kernel, and kdump-lib.sh will
automatically include it.
Signed-off-by: WANG Chao <chaowang(a)redhat.com>
---
dracut-kdump-lib-2.sh | 160 +++++++++++++++++++++++++++++++++++++++++++++++++
dracut-kdump.sh | 152 +---------------------------------------------
dracut-module-setup.sh | 1 +
kdump-lib.sh | 6 +-
kexec-tools.spec | 2 +
5 files changed, 170 insertions(+), 151 deletions(-)
create mode 100755 dracut-kdump-lib-2.sh
diff --git a/dracut-kdump-lib-2.sh b/dracut-kdump-lib-2.sh
new file mode 100755
index 0000000..cb2fdf7
--- /dev/null
+++ b/dracut-kdump-lib-2.sh
@@ -0,0 +1,160 @@
+# These variables and functions are useful in 2nd kernel
+
+KDUMP_PATH="/var/crash"
+CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
+DMESG_COLLECTOR="/sbin/vmcore-dmesg"
+DEFAULT_ACTION="reboot -f"
+SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
+KDUMP_PRE=""
+KDUMP_POST=""
+DATEDIR=`date +%Y.%m.%d-%T`
+HOST_IP='127.0.0.1'
+DUMP_INSTRUCTION=""
+KDUMP_SCRIPT_DIR="/kdumpscripts"
+DD_BLKSIZE=512
+KDUMP_CONF="/etc/kdump.conf"
+NEWROOT="/sysroot"
+
+get_kdump_confs()
+{
+ local config_opt config_val
+ local user_specified_cc
+
+ while read config_opt config_val;
+ do
+ # remove inline comments after the end of a directive.
+ config_val=$(strip_comments $config_val)
+ case "$config_opt" in
+ path)
+ KDUMP_PATH="$config_val"
+ ;;
+ core_collector)
+ CORE_COLLECTOR="$config_val"
+ user_specified_cc=yes
+ ;;
+ sshkey)
+ SSH_KEY_LOCATION=$config_val
+ ;;
+ kdump_pre)
+ KDUMP_PRE="$config_val"
+ ;;
+ kdump_post)
+ KDUMP_POST="$config_val"
+ ;;
+ fence_kdump_args)
+ FENCE_KDUMP_ARGS="$config_val"
+ ;;
+ fence_kdump_nodes)
+ FENCE_KDUMP_NODES="$config_val"
+ ;;
+ default)
+ case $config_val in
+ shell)
+ DEFAULT_ACTION="kdump_emergency_shell"
+ ;;
+ reboot)
+ DEFAULT_ACTION="do_umount; reboot -f"
+ ;;
+ halt)
+ DEFAULT_ACTION="do_umount; halt -f"
+ ;;
+ poweroff)
+ DEFAULT_ACTION="do_umount; poweroff -f"
+ ;;
+ dump_to_rootfs)
+ DEFAULT_ACTION="dump_to_rootfs"
+ ;;
+ esac
+ ;;
+ esac
+ done < $KDUMP_CONF
+
+ if is_ssh_dump_target || is_raw_dump_target; then
+ if [ -z "$user_specified_cc" ]; then
+ CORE_COLLECTOR="$CORE_COLLECTOR -F"
+ fi
+ fi
+}
+
+# dump_fs <mount point| device>
+dump_fs()
+{
+
+ local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
+ local _mp=$(findmnt -k -f -n -r -o TARGET $1)
+
+ echo "kdump: dump target is $_dev"
+
+ if [ -z "$_mp" ]; then
+ echo "kdump: error: Dump target $_dev is not mounted."
+ return 1
+ fi
+
+ # Remove -F in makedumpfile case. We don't want a flat format dump here.
+ [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo
$CORE_COLLECTOR | sed -e "s/-F//g"`
+
+ echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ mount -o remount,rw $_mp || return 1
+ mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
+
+ save_vmcore_dmesg_fs ${DMESG_COLLECTOR}
"$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
+
+ echo "kdump: saving vmcore"
+ $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete ||
return 1
+ mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete
$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
+ sync
+
+ echo "kdump: saving vmcore complete"
+}
+
+save_vmcore_dmesg_fs() {
+ local _dmesg_collector=$1
+ local _path=$2
+
+ echo "kdump: saving vmcore-dmesg.txt"
+ $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
+ _exitcode=$?
+ if [ $_exitcode -eq 0 ]; then
+ mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
+ echo "kdump: saving vmcore-dmesg.txt complete"
+ else
+ echo "kdump: saving vmcore-dmesg.txt failed"
+ fi
+}
+
+dump_to_rootfs()
+{
+
+ echo "Kdump: trying to bring up rootfs device"
+ systemctl start dracut-initqueue
+ echo "Kdump: waiting for rootfs mount, will timeout after 90 seconds"
+ systemctl start sysroot.mount
+
+ dump_fs $NEWROOT
+}
+
+kdump_emergency_shell()
+{
+ echo "PS1=\"kdump:\\\${PWD}# \"" >/etc/profile
+ /bin/dracut-emergency
+ rm -f /etc/profile
+}
+
+do_umount()
+{
+ umount -Rf /sysroot
+}
+
+do_default_action()
+{
+ echo "Kdump: Error Occured, doing default action"
+ eval $DEFAULT_ACTION
+}
+
+
+do_final_action()
+{
+ do_umount
+ reboot -f
+}
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index cb13d92..1960b7e 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
@@ -9,24 +9,6 @@ if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then
fi
set -o pipefail
-KDUMP_PATH="/var/crash"
-CORE_COLLECTOR=""
-DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"
-DMESG_COLLECTOR="/sbin/vmcore-dmesg"
-DEFAULT_ACTION="reboot -f"
-DATEDIR=`date +%Y.%m.%d-%T`
-HOST_IP='127.0.0.1'
-DUMP_INSTRUCTION=""
-SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
-KDUMP_SCRIPT_DIR="/kdumpscripts"
-DD_BLKSIZE=512
-FINAL_ACTION="reboot -f"
-DUMP_RETVAL=0
-conf_file="/etc/kdump.conf"
-KDUMP_PRE=""
-KDUMP_POST=""
-MOUNTS=""
-
export PATH=$PATH:$KDUMP_SCRIPT_DIR
do_dump()
@@ -43,27 +25,6 @@ do_dump()
return $_ret
}
-do_umount()
-{
- if [ -n "$MOUNTS" ]; then
- for mount in $MOUNTS; do
- ismounted $mount && umount -R $mount
- done
- fi
-}
-
-do_final_action()
-{
- do_umount
- eval $FINAL_ACTION
-}
-
-do_default_action()
-{
- wait_for_loginit
- eval $DEFAULT_ACTION
-}
-
do_kdump_pre()
{
if [ -n "$KDUMP_PRE" ]; then
@@ -83,39 +44,6 @@ add_dump_code()
DUMP_INSTRUCTION=$1
}
-# dump_fs <mount point| device>
-dump_fs()
-{
- local _dev=$(findmnt -k -f -n -r -o SOURCE $1)
- local _mp=$(findmnt -k -f -n -r -o TARGET $1)
-
- echo "kdump: dump target is $_dev"
-
- if [ -z "$_mp" ]; then
- echo "kdump: error: Dump target $_dev is not mounted."
- return 1
- fi
- MOUNTS="$MOUNTS $_mp"
-
- # Remove -F in makedumpfile case. We don't want a flat format dump here.
- [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo
$CORE_COLLECTOR | sed -e "s/-F//g"`
-
- echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- mount -o remount,rw $_mp || return 1
- mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
-
- save_vmcore_dmesg_fs ${DMESG_COLLECTOR}
"$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
-
- echo "kdump: saving vmcore"
- $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete ||
return 1
- mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete
$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
- sync
-
- echo "kdump: saving vmcore complete"
- return 0
-}
-
dump_raw()
{
local _raw=$1
@@ -165,21 +93,6 @@ dump_ssh()
return 0
}
-save_vmcore_dmesg_fs() {
- local _dmesg_collector=$1
- local _path=$2
-
- echo "kdump: saving vmcore-dmesg.txt"
- $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt
- _exitcode=$?
- if [ $_exitcode -eq 0 ]; then
- mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt
- echo "kdump: saving vmcore-dmesg.txt complete"
- else
- echo "kdump: saving vmcore-dmesg.txt failed"
- fi
-}
-
save_vmcore_dmesg_ssh() {
local _dmesg_collector=$1
local _path=$2
@@ -218,61 +131,7 @@ get_host_ip()
read_kdump_conf()
{
- if [ ! -f "$conf_file" ]; then
- echo "kdump: $conf_file not found"
- return
- fi
-
- # first get the necessary variables
- while read config_opt config_val;
- do
- # remove inline comments after the end of a directive.
- config_val=$(strip_comments $config_val)
- case "$config_opt" in
- path)
- KDUMP_PATH="$config_val"
- ;;
- core_collector)
- [ -n "$config_val" ] &&
CORE_COLLECTOR="$config_val"
- ;;
- sshkey)
- if [ -f "$config_val" ]; then
- SSH_KEY_LOCATION=$config_val
- fi
- ;;
- kdump_pre)
- KDUMP_PRE="$config_val"
- ;;
- kdump_post)
- KDUMP_POST="$config_val"
- ;;
- fence_kdump_args)
- FENCE_KDUMP_ARGS="$config_val"
- ;;
- fence_kdump_nodes)
- FENCE_KDUMP_NODES="$config_val"
- ;;
- default)
- case $config_val in
- shell)
- DEFAULT_ACTION="_emergency_shell kdump"
- ;;
- reboot)
- DEFAULT_ACTION="do_umount; reboot -f"
- ;;
- halt)
- DEFAULT_ACTION="do_umount; halt -f"
- ;;
- poweroff)
- DEFAULT_ACTION="do_umount; poweroff -f"
- ;;
- dump_to_rootfs)
- DEFAULT_ACTION="dump_fs $NEWROOT"
- ;;
- esac
- ;;
- esac
- done < $conf_file
+ get_kdump_confs
# rescan for add code for dump target
while read config_opt config_val;
@@ -290,7 +149,7 @@ read_kdump_conf()
add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val"
;;
esac
- done < $conf_file
+ done < $KDUMP_CONF
}
fence_kdump_notify()
@@ -303,13 +162,6 @@ fence_kdump_notify()
read_kdump_conf
fence_kdump_notify
-if [ -z "$CORE_COLLECTOR" ];then
- CORE_COLLECTOR=$DEFAULT_CORE_COLLECTOR
- if is_ssh_dump_target || is_raw_dump_target; then
- CORE_COLLECTOR="$CORE_COLLECTOR -F"
- fi
-fi
-
get_host_ip
if [ $? -ne 0 ]; then
echo "kdump: get_host_ip exited with non-zero status!"
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 87ad072..61f588a 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -555,6 +555,7 @@ install() {
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"
+ inst "$moddir/kdump-lib-2.sh" "/lib/kdump-lib-2.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
index a20c6e8..07fa50a 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -3,6 +3,11 @@
# Kdump common variables and functions
#
+# In 2nd kernel?
+if [ -f /usr/lib/kdump-lib-2.sh ]; then
+ . /usr/lib/kdump-lib-2.sh
+fi
+
DEFAULT_PATH="/var/crash/"
FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump"
FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send"
@@ -137,4 +142,3 @@ check_save_path_fs()
perror_exit "Dump path $_path does not exist."
fi
}
-
diff --git a/kexec-tools.spec b/kexec-tools.spec
index 9230ccf..5c8f60d 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -35,6 +35,7 @@ Source23: kdump-anaconda-addon-20140522.tar.gz
Source100: dracut-kdump.sh
Source101: dracut-module-setup.sh
Source102: dracut-monitor_dd_progress
+Source103: dracut-kdump-lib-2.sh
Requires(post): systemd-units
Requires(preun): systemd-units
@@ -198,6 +199,7 @@ mkdir -p -m755
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpba
cp %{SOURCE100}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE100}}
cp %{SOURCE101}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE101}}
cp %{SOURCE102}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE102}}
+cp %{SOURCE103}
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE103}}
chmod 755
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE100}}
chmod 755
$RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix
%{SOURCE101}}
--
1.9.3