From 2697669fa97dec3992b5f38e19ece3bc3fb447b8 Mon Sep 17 00:00:00 2001 From: Dave Young Date: Thu, 14 Jun 2012 09:56:10 +0800 Subject: [PATCH] ssh core_collector fix 1. add core_collector filter support to ssh dump 2. scp can be specified in kdump.conf 3. error out if no '-F' with makedumpfile 4. add proper explanation and examples to kdump.conf[.5] and kexec-kdump-howto.txt. v1->v2: add verify_core_collector function v2->v3: optimize the code, remove local variable for default core_collector Signed-off-by: Dave Young Acked-by: Vivek Goyal --- dracut-kdump.sh | 28 ++++++++++++++++++++++++---- kdump.conf | 3 ++- kdump.conf.5 | 36 ++++++++++++++++++++++++++++++++---- kexec-kdump-howto.txt | 36 +++++++++++++++++++++++++++++++++--- mkdumprd | 22 +++++++++++++++++++--- 5 files changed, 110 insertions(+), 15 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 0baa8cc..8d169c4 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -4,7 +4,8 @@ set -x KDUMP_PATH="/var/crash" -CORE_COLLECTOR="makedumpfile -c --message-level 1 -d 31" +CORE_COLLECTOR="" +DEFAULT_CORE_COLLECTOR="makedumpfile -c --message-level 1 -d 31" DEFAULT_ACTION="dump_rootfs" DATEDIR=`date +%d.%m.%y-%T` DUMP_INSTRUCTION="" @@ -118,9 +119,23 @@ dump_nfs() dump_ssh() { - ssh -q -i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes $2 mkdir -p $KDUMP_PATH/$DATEDIR || return 1 - scp -q -i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes /proc/vmcore "$2:$KDUMP_PATH/$DATEDIR" || return 1 - return 0 + local _opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes" + local _dir="$KDUMP_PATH/$DATEDIR" + + ssh -q $_opt $2 mkdir -p $_dir || return 1 + + if [ "${CORE_COLLECTOR%% *}" = "scp" ]; then + scp -q $_opt /proc/vmcore "$2:$_dir/vmcore-incomplete" || return 1 + ssh $_opt $2 "mv $_dir/vmcore-incomplete $_dir/vmcore" || return 1 + else + $CORE_COLLECTOR /proc/vmcore | ssh $_opt $2 "dd bs=512 of=$_dir/vmcore-incomplete" || return 1 + ssh $_opt $2 "mv $_dir/vmcore-incomplete $_dir/vmcore.flat" || return 1 + fi +} + +is_ssh_dump_target() +{ + grep -q "^net.*@" $conf_file } read_kdump_conf() @@ -188,6 +203,11 @@ read_kdump_conf() read_kdump_conf +if [ -z "$CORE_COLLECTOR" ];then + CORE_COLLECTOR=$DEFAULT_CORE_COLLECTOR + is_ssh_dump_target && CORE_COLLECTOR="$CORE_COLLECTOR -F" +fi + if [ -z "$DUMP_INSTRUCTION" ]; then add_dump_code "dump_rootfs" fi diff --git a/kdump.conf b/kdump.conf index 0846ecc..c3c613b 100644 --- a/kdump.conf +++ b/kdump.conf @@ -44,7 +44,7 @@ # options are not needed here, as the initrd will # automatically be populated with a config file # appropriate for the running kernel. -# Default core_collector for raw dump is: +# Default core_collector for raw/ssh dump is: # "makedumpfile -F -c --message-level 1 -d 31". # Default core_collector for other targets is: # "makedumpfile -c --message-level 1 -d 31". @@ -91,6 +91,7 @@ #sshkey /root/.ssh/kdump_id_rsa path /var/crash #core_collector makedumpfile -c --message-level 1 -d 31 +#core_collector scp #extra_bins /usr/bin/lftp #extra_modules gfs2 #default shell diff --git a/kdump.conf.5 b/kdump.conf.5 index a5824c0..854d794 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -72,7 +72,7 @@ will automatically be populated with a config file appropriate for the running kernel. .PP Note 1: About default core collector: -Default core_collector for raw dump is: +Default core_collector for raw/ssh dump is: "makedumpfile -F -c --message-level 1 -d 31". Default core_collector for other targets is: "makedumpfile -c --message-level 1 -d 31". @@ -141,10 +141,10 @@ Above will effectively be translated to: makedumpfile -c --message-level 1 -d 31 /proc/vmcore /vmcore .PP -For dump targets like raw, in general, core collector should expect +For dump targets like raw and ssh, in general, core collector should expect one argument (source file) and should output the processed core on standard -output. This standard output will be saved to destination using appropriate -commands. +output (There is one exception of "scp", discussed later). This standard +output will be saved to destination using appropriate commands. raw dumps examples: .TP @@ -161,6 +161,34 @@ core_collector "makedumpfile -F -c --message-level 1 -d 31" Above will effectively be translated to. makedumpfile -F -c --message-level 1 -d 31 | dd of= +.PP +ssh dumps examples +.TP +ex5. +core_collector "cat" + +Above will effectively be translated to. + +cat /proc/vmcore | ssh "dd of=path/vmcore" +.TP +ex6. +core_collector "makedumpfile -F -c --message-level 1 -d 31" + +Above will effectively be translated to. + +makedumpfile -F -c --message-level 1 -d 31 | ssh "dd of=path/vmcore" + +There is one exception to standard output rule for ssh dumps. And that is +scp. As scp can handle ssh destinations for file transfers, one can +specify "scp" as core collector for ssh targets (no output on stdout). +.TP +ex7. +core_collector "scp" + +Above will effectively be translated to. + +scp /proc/vmcore :path/vmcore + .PP examples for other options please see .I /etc/kdump.conf diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 4bab62a..3fa4b0a 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -467,10 +467,10 @@ Above will effectively be translated to: makedumpfile -c --message-level 1 -d 31 /proc/vmcore /vmcore -For dump targets like raw, in general, core collector should expect +For dump targets like raw and ssh, in general, core collector should expect one argument (source file) and should output the processed core on standard -output. This standard output will be saved to destination using appropriate -commands. +output (There is one exception of "scp", discussed later). This standard +output will be saved to destination using appropriate commands. raw dumps core_collector examples: --------- @@ -490,6 +490,36 @@ Above will effectively be translated to. makedumpfile -F -c --message-level 1 -d 31 | dd of= +ssh dumps core_collector examples: +--------- +ex5. +--- +core_collector "cat" + +Above will effectively be translated to. + +cat /proc/vmcore | ssh "dd of=path/vmcore" + +ex6. +--- +core_collector "makedumpfile -F -c --message-level 1 -d 31" + +Above will effectively be translated to. + +makedumpfile -F -c --message-level 1 -d 31 | ssh "dd of=path/vmcore" + +There is one exception to standard output rule for ssh dumps. And that is +scp. As scp can handle ssh destinations for file transfers, one can +specify "scp" as core collector for ssh targets (no output on stdout). + +ex7. +---- +core_collector "scp" + +Above will effectively be translated to. + +scp /proc/vmcore :path/vmcore + About default core collector ---------------------------- Default core_collector for ssh/raw dump is: diff --git a/mkdumprd b/mkdumprd index bff879e..f6ba6e1 100644 --- a/mkdumprd +++ b/mkdumprd @@ -91,6 +91,24 @@ check_remote() { return } +is_ssh_dump_target() +{ + grep -q "^net.*@" $conf_file +} + +# $1: core_collector config value +verify_core_collector() { + if grep -q "^raw" $conf_file && [ "${1%% *}" != "makedumpfile" ]; then + echo "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually." + fi + if is_ssh_dump_target && [ "${1%% *}" = "makedumpfile" ]; then + ! strstr "$1" "-F" && { + echo "The specified dump target needs makedumpfile \"-F\" option." + exit 1 + } + fi +} + add_mount() { local _dev=$(to_dev_name "$1") local _mnt=$(to_mount "$1") @@ -150,9 +168,7 @@ do fi ;; core_collector) - if grep -q "^raw" $conf_file && [ "${config_val%% *}" != "makedumpfile" ]; then - echo "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually." - fi + verify_core_collector "$config_val" add_dracut_arg "-I" "${config_val%% *}" ;; extra_bins)