bash scripts: reformat with shfmt

This is a batch update done with:
shfmt -s -w mkfadumprd mkdumprd kdumpctl *-module-setup.sh

Clean up code style and reduce code base size, no behaviour change.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Kairui Song 2021-09-14 02:25:40 +08:00
parent 4f75e16700
commit 0e4b66b1ab
5 changed files with 570 additions and 559 deletions

View File

@ -6,9 +6,8 @@ KDUMP_KERNEL=""
KDUMP_INITRD=""
check() {
if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]]\
|| [[ -n "${IN_KDUMP}" ]]
then
if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]] \
|| [[ -n ${IN_KDUMP} ]]; then
return 1
fi
return 255
@ -25,7 +24,7 @@ prepare_kernel_initrd() {
prepare_kdump_bootinfo
# $kernel is a variable from dracut
if [[ "$KDUMP_KERNELVER" != "$kernel" ]]; then
if [[ $KDUMP_KERNELVER != "$kernel" ]]; then
dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \
"but the initramfs is generated for kernel version '$kernel'"
fi
@ -33,12 +32,12 @@ prepare_kernel_initrd() {
install() {
prepare_kernel_initrd
if [[ ! -f "$KDUMP_KERNEL" ]]; then
if [[ ! -f $KDUMP_KERNEL ]]; then
derror "Could not find required kernel for earlykdump," \
"earlykdump will not work!"
return 1
fi
if [[ ! -f "$KDUMP_INITRD" ]]; then
if [[ ! -f $KDUMP_INITRD ]]; then
derror "Could not find required kdump initramfs for earlykdump," \
"please ensure kdump initramfs is generated first," \
"earlykdump will not work!"

View File

@ -11,8 +11,7 @@ kdump_module_init() {
check() {
[[ $debug ]] && set -x
#kdumpctl sets this explicitly
if [[ -z "$IN_KDUMP" ]] || [[ ! -f /etc/kdump.conf ]]
then
if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then
return 1
fi
return 0
@ -41,11 +40,11 @@ depends() {
_dep="$_dep ssh-client"
fi
if [[ "$(uname -m)" = "s390x" ]]; then
if [[ "$(uname -m)" == "s390x" ]]; then
_dep="$_dep znet"
fi
if [[ -n "$( ls -A /sys/class/drm 2>/dev/null )" ]] || [[ -d /sys/module/hyperv_fb ]]; then
if [[ -n "$(ls -A /sys/class/drm 2> /dev/null)" ]] || [[ -d /sys/module/hyperv_fb ]]; then
add_opt_module drm
fi
@ -57,19 +56,19 @@ depends() {
}
kdump_is_bridge() {
[[ -d /sys/class/net/"$1"/bridge ]]
[[ -d /sys/class/net/"$1"/bridge ]]
}
kdump_is_bond() {
[[ -d /sys/class/net/"$1"/bonding ]]
[[ -d /sys/class/net/"$1"/bonding ]]
}
kdump_is_team() {
[[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null
[[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null
}
kdump_is_vlan() {
[[ -f /proc/net/vlan/"$1" ]]
[[ -f /proc/net/vlan/"$1" ]]
}
# $1: netdev name
@ -78,7 +77,7 @@ source_ifcfg_file() {
dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager."
ifcfg_file=$(get_ifcfg_filename "$1")
if [[ -f "${ifcfg_file}" ]]; then
if [[ -f ${ifcfg_file} ]]; then
. "${ifcfg_file}"
else
dwarning "The ifcfg file of $1 is not found!"
@ -94,28 +93,26 @@ kdump_setup_dns() {
_tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS")
# shellcheck disable=SC2206
array=( ${_tmp//|/ } )
array=(${_tmp//|/ })
if [[ ${array[*]} ]]; then
for _dns in "${array[@]}"
do
for _dns in "${array[@]}"; do
echo "nameserver=$_dns" >> "$_dnsfile"
done
else
dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script"
source_ifcfg_file "$_netdev"
[[ -n "$DNS1" ]] && echo "nameserver=$DNS1" > "$_dnsfile"
[[ -n "$DNS2" ]] && echo "nameserver=$DNS2" >> "$_dnsfile"
[[ -n $DNS1 ]] && echo "nameserver=$DNS1" > "$_dnsfile"
[[ -n $DNS2 ]] && echo "nameserver=$DNS2" >> "$_dnsfile"
fi
while read -r content;
do
while read -r content; do
_nameserver=$(echo "$content" | grep ^nameserver)
[[ -z "$_nameserver" ]] && continue
[[ -z $_nameserver ]] && continue
_dns=$(echo "$_nameserver" | awk '{print $2}')
[[ -z "$_dns" ]] && continue
[[ -z $_dns ]] && continue
if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then
if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile"; then
echo "nameserver=$_dns" >> "$_dnsfile"
fi
done < "/etc/resolv.conf"
@ -130,7 +127,7 @@ repeatedly_join_str() {
local _separator="$3"
local i _res
if [[ "$_count" -le 0 ]]; then
if [[ $_count -le 0 ]]; then
echo -n ""
return
fi
@ -139,7 +136,7 @@ repeatedly_join_str() {
_res="$_str"
((_count--))
while [[ "$i" -lt "$_count" ]]; do
while [[ $i -lt $_count ]]; do
((i++))
_res="${_res}${_separator}${_str}"
done
@ -160,14 +157,14 @@ cal_netmask_by_prefix() {
local _count _res _octets_per_group _octets_total _seperator _total_groups
local _max_group_value _max_group_value_repr _bits_per_group _tmp _zero_bits
if [[ "$_ipv6_flag" == "-6" ]]; then
if [[ $_ipv6_flag == "-6" ]]; then
_ipv6=1
else
_ipv6=0
fi
if [[ "$_prefix" -lt 0 || "$_prefix" -gt 128 ]] || \
( ((!_ipv6)) && [[ "$_prefix" -gt 32 ]] ); then
if [[ $_prefix -lt 0 || $_prefix -gt 128 ]] \
|| ( ((!_ipv6)) && [[ $_prefix -gt 32 ]]); then
derror "Bad prefix:$_prefix for calculating netmask"
exit 1
fi
@ -182,7 +179,7 @@ cal_netmask_by_prefix() {
_seperator="."
fi
_total_groups=$((_octets_total/_octets_per_group))
_total_groups=$((_octets_total / _octets_per_group))
_bits_per_group=$((_octets_per_group * _bits_per_octet))
_max_group_value=$(((1 << _bits_per_group) - 1))
@ -192,39 +189,39 @@ cal_netmask_by_prefix() {
_max_group_value_repr="$_max_group_value"
fi
_count=$((_prefix/_octets_per_group/_bits_per_octet))
_count=$((_prefix / _octets_per_group / _bits_per_octet))
_first_part=$(repeatedly_join_str "$_count" "$_max_group_value_repr" "$_seperator")
_res="$_first_part"
_tmp=$((_octets_total*_bits_per_octet-_prefix))
_tmp=$((_octets_total * _bits_per_octet - _prefix))
_zero_bits=$((_tmp % _bits_per_group))
if [[ "$_zero_bits" -ne 0 ]]; then
if [[ $_zero_bits -ne 0 ]]; then
_second_part=$((_max_group_value >> _zero_bits << _zero_bits))
if ((_ipv6)); then
_second_part=$(printf "%x" $_second_part)
fi
((_count++))
if [[ -z "$_first_part" ]]; then
if [[ -z $_first_part ]]; then
_res="$_second_part"
else
_res="${_first_part}${_seperator}${_second_part}"
fi
fi
_count=$((_total_groups-_count))
if [[ "$_count" -eq 0 ]]; then
_count=$((_total_groups - _count))
if [[ $_count -eq 0 ]]; then
echo -n "$_res"
return
fi
if ((_ipv6)) && [[ "$_count" -gt 1 ]] ; then
if ((_ipv6)) && [[ $_count -gt 1 ]]; then
# use condensed notion for IPv6
_third_part=":"
else
_third_part=$(repeatedly_join_str "$_count" "0" "$_seperator")
fi
if [[ -z "$_res" ]] && ((!_ipv6)) ; then
if [[ -z $_res ]] && ((!_ipv6)); then
echo -n "${_third_part}"
else
echo -n "${_res}${_seperator}${_third_part}"
@ -244,11 +241,11 @@ kdump_static_ip() {
_ipv6_flag="-6"
fi
if [[ -n "$_ipaddr" ]]; then
_gateway=$(ip $_ipv6_flag route list dev "$_netdev" | \
awk '/^default /{print $3}' | head -n 1)
if [[ -n $_ipaddr ]]; then
_gateway=$(ip $_ipv6_flag route list dev "$_netdev" \
| awk '/^default /{print $3}' | head -n 1)
if [[ "x" != "x"$_ipv6_flag ]]; then
if [[ "x" != "x"$_ipv6_flag ]]; then
# _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/"
_netmask=${_ipaddr#*\/}
_srcaddr="[$_srcaddr]"
@ -263,17 +260,17 @@ kdump_static_ip() {
echo -n "${_srcaddr}::${_gateway}:${_netmask}::"
fi
/sbin/ip $_ipv6_flag route show | grep -v default |\
grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\
while read -r _route; do
_target=$(echo "$_route" | awk '{print $1}')
_nexthop=$(echo "$_route" | awk '{print $3}')
if [[ "x" != "x"$_ipv6_flag ]]; then
_target="[$_target]"
_nexthop="[$_nexthop]"
fi
echo "rd.route=$_target:$_nexthop:$kdumpnic"
done >> "${initdir}/etc/cmdline.d/45route-static.conf"
/sbin/ip $_ipv6_flag route show | grep -v default \
| grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" \
| while read -r _route; do
_target=$(echo "$_route" | awk '{print $1}')
_nexthop=$(echo "$_route" | awk '{print $3}')
if [[ "x" != "x"$_ipv6_flag ]]; then
_target="[$_target]"
_nexthop="[$_nexthop]"
fi
echo "rd.route=$_target:$_nexthop:$kdumpnic"
done >> "${initdir}/etc/cmdline.d/45route-static.conf"
kdump_handle_mulitpath_route "$_netdev" "$_srcaddr" "$kdumpnic"
}
@ -287,28 +284,28 @@ kdump_handle_mulitpath_route() {
fi
while IFS="" read -r _route; do
if [[ "$_route" =~ [[:space:]]+nexthop ]]; then
if [[ $_route =~ [[:space:]]+nexthop ]]; then
_route=${_route##[[:space:]]}
# Parse multipath route, using previous _target
[[ "$_target" == 'default' ]] && continue
[[ "$_route" =~ .*via.*\ $_netdev ]] || continue
[[ $_target == 'default' ]] && continue
[[ $_route =~ .*via.*\ $_netdev ]] || continue
_weight=$(echo "$_route" | cut -d ' ' -f7)
if [[ "$_weight" -gt "$_max_weight" ]]; then
if [[ $_weight -gt $_max_weight ]]; then
_nexthop=$(echo "$_route" | cut -d ' ' -f3)
_max_weight=$_weight
if [[ "x" != "x"$_ipv6_flag ]]; then
if [[ "x" != "x"$_ipv6_flag ]]; then
_rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic"
else
_rule="rd.route=$_target:$_nexthop:$kdumpnic"
fi
fi
else
[[ -n "$_rule" ]] && echo "$_rule"
[[ -n $_rule ]] && echo "$_rule"
_target=$(echo "$_route" | cut -d ' ' -f1)
_rule="" _max_weight=0 _weight=0
fi
done >> "${initdir}/etc/cmdline.d/45route-static.conf"\
done >> "${initdir}/etc/cmdline.d/45route-static.conf" \
<<< "$(/sbin/ip $_ipv6_flag route show)"
[[ -n $_rule ]] && echo "$_rule" >> "${initdir}/etc/cmdline.d/45route-static.conf"
@ -323,8 +320,7 @@ kdump_get_mac_addr() {
kdump_get_perm_addr() {
local addr
addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //')
if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]]
then
if [[ -z $addr ]] || [[ $addr == "00:00:00:00:00:00" ]]; then
derror "Can't get the permanent address of $1"
else
echo "$addr"
@ -391,13 +387,13 @@ kdump_setup_bond() {
_bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options")
if [[ -z "$_bondoptions" ]]; then
if [[ -z $_bondoptions ]]; then
dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script."
source_ifcfg_file "$_netdev"
_bondoptions="$(echo "$BONDING_OPTS" | xargs echo | tr " " ",")"
fi
if [[ -z "$_bondoptions" ]]; then
if [[ -z $_bondoptions ]]; then
derror "Get empty bond options"
exit 1
fi
@ -453,30 +449,27 @@ kdump_setup_vlan() {
# code reaped from the list_configured function of
# https://github.com/hreinecke/s390-tools/blob/master/zconf/znetconf
find_online_znet_device() {
local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices"
local NETWORK_DEVICES d ifname ONLINE
local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices"
local NETWORK_DEVICES d ifname ONLINE
[[ ! -d "$CCWGROUPBUS_DEVICEDIR" ]] && return
NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR)
for d in $NETWORK_DEVICES
do
[[ ! -f "$d/online" ]] && continue
read -r ONLINE < "$d/online"
if [[ $ONLINE -ne 1 ]]; then
continue
fi
# determine interface name, if there (only for qeth and if
# device is online)
if [[ -f $d/if_name ]]
then
read -r ifname < "$d/if_name"
elif [[ -d $d/net ]]
then
ifname=$(ls "$d/net/")
fi
[[ -n "$ifname" ]] && break
done
echo -n "$ifname"
[[ ! -d $CCWGROUPBUS_DEVICEDIR ]] && return
NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR)
for d in $NETWORK_DEVICES; do
[[ ! -f "$d/online" ]] && continue
read -r ONLINE < "$d/online"
if [[ $ONLINE -ne 1 ]]; then
continue
fi
# determine interface name, if there (only for qeth and if
# device is online)
if [[ -f $d/if_name ]]; then
read -r ifname < "$d/if_name"
elif [[ -d $d/net ]]; then
ifname=$(ls "$d/net/")
fi
[[ -n $ifname ]] && break
done
echo -n "$ifname"
}
# setup s390 znet cmdline
@ -494,7 +487,7 @@ kdump_setup_znet() {
SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels")
_options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options")
if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
if [[ -z $NETTYPE || -z $SUBCHANNELS || -z $_options ]]; then
dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script."
source_ifcfg_file "$_netdev"
for i in $OPTIONS; do
@ -502,15 +495,14 @@ kdump_setup_znet() {
done
fi
if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then
if [[ -z $NETTYPE || -z $SUBCHANNELS || -z $_options ]]; then
exit 1
fi
echo "rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS}" > "${initdir}/etc/cmdline.d/30znet.conf"
}
kdump_get_ip_route()
{
kdump_get_ip_route() {
local _route
if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then
derror "Bad kdump network destination: $1"
@ -519,18 +511,16 @@ kdump_get_ip_route()
echo "$_route"
}
kdump_get_ip_route_field()
{
kdump_get_ip_route_field() {
echo "$1" | sed -n -e "s/^.*\<$2\>\s\+\(\S\+\).*$/\1/p"
}
kdump_get_remote_ip()
{
kdump_get_remote_ip() {
local _remote _remote_temp
_remote=$(get_remote_host "$1")
if is_hostname "$_remote"; then
_remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1)
if [[ -z "$_remote_temp" ]]; then
if [[ -z $_remote_temp ]]; then
_remote_temp=$(getent ahosts "$_remote" | head -n 1)
fi
_remote=$(echo "$_remote_temp" | awk '{print $1}')
@ -555,7 +545,7 @@ kdump_install_net() {
kdumpnic=$(kdump_setup_ifname "$_netdev")
_znet_netdev=$(find_online_znet_device)
if [[ -n "$_znet_netdev" ]]; then
if [[ -n $_znet_netdev ]]; then
_nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev")
if ! (kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet"); then
derror "Failed to set up znet"
@ -564,7 +554,7 @@ kdump_install_net() {
fi
_static=$(kdump_static_ip "$_netdev" "$_srcaddr" "$kdumpnic")
if [[ -n "$_static" ]]; then
if [[ -n $_static ]]; then
_proto=none
elif is_ipv6_address "$_srcaddr"; then
_proto=auto6
@ -579,8 +569,8 @@ kdump_install_net() {
# so we have to avoid adding duplicates
# We should also check /proc/cmdline for existing ip=xx arg.
# For example, iscsi boot will specify ip=xxx arg in cmdline.
if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" &&\
! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then
if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" \
&& ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then
echo "$_ip_opts" >> "$_ip_conf"
fi
@ -611,8 +601,8 @@ kdump_install_net() {
# the default gate way for network dump, eth1 in the fence kdump path will
# call kdump_install_net again and we don't want eth1 to be the default
# gateway.
if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] &&
[[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then
if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] \
&& [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then
echo "kdumpnic=$kdumpnic" > "${initdir}/etc/cmdline.d/60kdumpnic.conf"
echo "bootdev=$kdumpnic" > "${initdir}/etc/cmdline.d/70bootdev.conf"
fi
@ -622,17 +612,17 @@ kdump_install_net() {
kdump_install_pre_post_conf() {
if [[ -d /etc/kdump/pre.d ]]; then
for file in /etc/kdump/pre.d/*; do
if [[ -x "$file" ]]; then
if [[ -x $file ]]; then
dracut_install "$file"
elif [[ $file != "/etc/kdump/pre.d/*" ]]; then
echo "$file is not executable"
echo "$file is not executable"
fi
done
fi
if [[ -d /etc/kdump/post.d ]]; then
for file in /etc/kdump/post.d/*; do
if [[ -x "$file" ]]; then
if [[ -x $file ]]; then
dracut_install "$file"
elif [[ $file != "/etc/kdump/post.d/*" ]]; then
echo "$file is not executable"
@ -641,8 +631,7 @@ kdump_install_pre_post_conf() {
fi
}
default_dump_target_install_conf()
{
default_dump_target_install_conf() {
local _target _fstype
local _mntpoint _save_path
@ -663,7 +652,7 @@ default_dump_target_install_conf()
echo "$_fstype $_target" >> "${initdir}/tmp/$$-kdump.conf"
# don't touch the path under root mount
if [[ "$_mntpoint" != "/" ]]; then
if [[ $_mntpoint != "/" ]]; then
_save_path=${_save_path##"$_mntpoint"}
fi
@ -678,32 +667,31 @@ kdump_install_conf() {
kdump_read_conf > "${initdir}/tmp/$$-kdump.conf"
while read -r _opt _val;
do
while read -r _opt _val; do
# remove inline comments after the end of a directive.
case "$_opt" in
raw)
_pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val")
sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf"
;;
ext[234]|xfs|btrfs|minix)
_pdev=$(kdump_get_persistent_dev "$_val")
sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf"
;;
ssh|nfs)
kdump_install_net "$_val"
;;
dracut_args)
if [[ $(get_dracut_args_fstype "$_val") = nfs* ]] ; then
kdump_install_net "$(get_dracut_args_target "$_val")"
fi
;;
kdump_pre|kdump_post|extra_bins)
dracut_install "$_val"
;;
core_collector)
dracut_install "${_val%%[[:blank:]]*}"
;;
raw)
_pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val")
sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf"
;;
ext[234] | xfs | btrfs | minix)
_pdev=$(kdump_get_persistent_dev "$_val")
sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf"
;;
ssh | nfs)
kdump_install_net "$_val"
;;
dracut_args)
if [[ $(get_dracut_args_fstype "$_val") == nfs* ]]; then
kdump_install_net "$(get_dracut_args_target "$_val")"
fi
;;
kdump_pre | kdump_post | extra_bins)
dracut_install "$_val"
;;
core_collector)
dracut_install "${_val%%[[:blank:]]*}"
;;
esac
done <<< "$(kdump_read_conf)"
@ -711,7 +699,7 @@ kdump_install_conf() {
default_dump_target_install_conf
kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf"
kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf"
inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf"
rm -f "${initdir}/tmp/$$-kdump.conf"
}
@ -744,16 +732,17 @@ kdump_get_iscsi_initiator() {
local _initiator
local initiator_conf="/etc/iscsi/initiatorname.iscsi"
[[ -f "$initiator_conf" ]] || return 1
[[ -f $initiator_conf ]] || return 1
while read -r _initiator; do
[[ -z "${_initiator%%#*}" ]] && continue # Skip comment lines
[[ -z ${_initiator%%#*} ]] && continue # Skip comment lines
case $_initiator in
InitiatorName=*)
initiator=${_initiator#InitiatorName=}
echo "rd.iscsi.initiator=${initiator}"
return 0;;
return 0
;;
*) ;;
esac
done < ${initiator_conf}
@ -763,15 +752,21 @@ kdump_get_iscsi_initiator() {
# Figure out iBFT session according to session type
is_ibft() {
[[ "$(kdump_iscsi_get_rec_val "$1" "node.discovery_type")" = fw ]]
[[ "$(kdump_iscsi_get_rec_val "$1" "node.discovery_type")" == fw ]]
}
kdump_setup_iscsi_device() {
local path=$1
local tgt_name; local tgt_ipaddr;
local username; local password; local userpwd_str;
local username_in; local password_in; local userpwd_in_str;
local netroot_str ; local initiator_str;
local tgt_name
local tgt_ipaddr
local username
local password
local userpwd_str
local username_in
local password_in
local userpwd_in_str
local netroot_str
local initiator_str
local netroot_conf="${initdir}/etc/cmdline.d/50iscsi.conf"
local initiator_conf="/etc/iscsi/initiatorname.iscsi"
@ -779,7 +774,7 @@ kdump_setup_iscsi_device() {
# Check once before getting explicit values, so we can bail out early,
# e.g. in case of pure-hardware(all-offload) iscsi.
if ! /sbin/iscsiadm -m session -r "$path" &>/dev/null ; then
if ! /sbin/iscsiadm -m session -r "$path" &> /dev/null; then
return 1
fi
@ -796,18 +791,18 @@ kdump_setup_iscsi_device() {
# get and set username and password details
username=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username")
[[ "$username" == "<empty>" ]] && username=""
[[ $username == "<empty>" ]] && username=""
password=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password")
[[ "$password" == "<empty>" ]] && password=""
[[ $password == "<empty>" ]] && password=""
username_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username_in")
[[ -n "$username" ]] && userpwd_str="$username:$password"
[[ -n $username ]] && userpwd_str="$username:$password"
# get and set incoming username and password details
[[ "$username_in" == "<empty>" ]] && username_in=""
[[ $username_in == "<empty>" ]] && username_in=""
password_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password_in")
[[ "$password_in" == "<empty>" ]] && password_in=""
[[ $password_in == "<empty>" ]] && password_in=""
[[ -n "$username_in" ]] && userpwd_in_str=":$username_in:$password_in"
[[ -n $username_in ]] && userpwd_in_str=":$username_in:$password_in"
kdump_install_net "$tgt_ipaddr"
@ -824,8 +819,8 @@ kdump_setup_iscsi_device() {
# If netroot target does not exist already, append.
if ! grep -q "$netroot_str" "$netroot_conf"; then
echo "$netroot_str" >> "$netroot_conf"
dinfo "Appended $netroot_str to $netroot_conf"
echo "$netroot_str" >> "$netroot_conf"
dinfo "Appended $netroot_str to $netroot_conf"
fi
# Setup initator
@ -836,14 +831,14 @@ kdump_setup_iscsi_device() {
# If initiator details do not exist already, append.
if ! grep -q "$initiator_str" "$netroot_conf"; then
echo "$initiator_str" >> "$netroot_conf"
dinfo "Appended $initiator_str to $netroot_conf"
echo "$initiator_str" >> "$netroot_conf"
dinfo "Appended $initiator_str to $netroot_conf"
fi
}
kdump_check_iscsi_targets () {
kdump_check_iscsi_targets() {
# If our prerequisites are not met, fail anyways.
type -P iscsistart >/dev/null || return 1
type -P iscsistart > /dev/null || return 1
kdump_check_setup_iscsi() (
local _dev
@ -869,12 +864,11 @@ get_alias() {
local alias_set
ips=$(hostname -I)
for ip in $ips
do
# in /etc/hosts, alias can come at the 2nd column
if entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }'); then
alias_set="$alias_set $entries"
fi
for ip in $ips; do
# in /etc/hosts, alias can come at the 2nd column
if entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }'); then
alias_set="$alias_set $entries"
fi
done
echo "$alias_set"
@ -892,7 +886,7 @@ is_localhost() {
hostnames="$hostnames $shortnames $aliasname"
for name in ${hostnames}; do
if [[ "$name" == "$nodename" ]]; then
if [[ $name == "$nodename" ]]; then
return 0
fi
done
@ -948,7 +942,7 @@ get_generic_fence_kdump_nodes() {
# setup fence_kdump in cluster
# setup proper network and install needed files
kdump_configure_fence_kdump () {
kdump_configure_fence_kdump() {
local kdump_cfg_file=$1
local nodes
local args
@ -963,7 +957,7 @@ kdump_configure_fence_kdump () {
echo "fence_kdump_nodes $nodes" >> "${kdump_cfg_file}"
args=$(get_pcs_fence_kdump_args)
if [[ -n "$args" ]]; then
if [[ -n $args ]]; then
echo "fence_kdump_args $args" >> "${kdump_cfg_file}"
fi
@ -987,14 +981,14 @@ kdump_configure_fence_kdump () {
kdump_install_random_seed() {
local poolsize
poolsize=$(</proc/sys/kernel/random/poolsize)
poolsize=$(< /proc/sys/kernel/random/poolsize)
if [[ ! -d "${initdir}/var/lib/" ]]; then
mkdir -p "${initdir}/var/lib/"
fi
dd if=/dev/urandom of="${initdir}/var/lib/random-seed" \
bs="$poolsize" count=1 2> /dev/null
bs="$poolsize" count=1 2> /dev/null
}
kdump_install_systemd_conf() {
@ -1071,8 +1065,8 @@ install() {
# it unconditionally here, if "/etc/lvm/lvm.conf" doesn't exist, it
# actually does nothing.
sed -i -e \
's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \
"${initdir}/etc/lvm/lvm.conf" &>/dev/null
's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \
"${initdir}/etc/lvm/lvm.conf" &> /dev/null
# Save more memory by dropping switch root capability
dracut_no_switch_root

274
kdumpctl
View File

@ -46,7 +46,7 @@ single_instance_lock()
{
local rc timeout=5
if ! exec 9>/var/lock/kdump; then
if ! exec 9> /var/lock/kdump; then
derror "Create file lock failed"
exit 1
fi
@ -90,9 +90,9 @@ save_core()
# https://fedorahosted.org/abrt/
if [[ -x /usr/bin/dumpoops ]]; then
ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg"
makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" >/dev/null 2>&1
makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" > /dev/null 2>&1
ddebug "dumpoops -d $coredir/dmesg"
if dumpoops -d "$coredir/dmesg" >/dev/null 2>&1; then
if dumpoops -d "$coredir/dmesg" > /dev/null 2>&1; then
dinfo "kernel oops has been collected by abrt tool"
fi
fi
@ -131,7 +131,7 @@ rebuild_kdump_initrd()
rebuild_initrd()
{
if [[ ! -w $(dirname "$TARGET_INITRD") ]];then
if [[ ! -w $(dirname "$TARGET_INITRD") ]]; then
derror "$(dirname "$TARGET_INITRD") does not have write permission. Cannot rebuild $TARGET_INITRD"
return 1
fi
@ -149,7 +149,7 @@ rebuild_initrd()
check_exist()
{
for file in $1; do
if [[ ! -e "$file" ]]; then
if [[ ! -e $file ]]; then
derror "Error: $file not found."
return 1
fi
@ -160,7 +160,7 @@ check_exist()
check_executable()
{
for file in $1; do
if [[ ! -x "$file" ]]; then
if [[ ! -x $file ]]; then
derror "Error: $file is not executable."
return 1
fi
@ -171,7 +171,7 @@ backup_default_initrd()
{
ddebug "backup default initrd: $DEFAULT_INITRD"
if [[ ! -f "$DEFAULT_INITRD" ]]; then
if [[ ! -f $DEFAULT_INITRD ]]; then
return
fi
@ -190,7 +190,7 @@ restore_default_initrd()
{
ddebug "restore default initrd: $DEFAULT_INITRD"
if [[ ! -f "$DEFAULT_INITRD" ]]; then
if [[ ! -f $DEFAULT_INITRD ]]; then
return
fi
@ -200,7 +200,7 @@ restore_default_initrd()
# verify checksum before restoring
backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }')
default_checksum=$(awk '{ print $1 }' "$INITRD_CHECKSUM_LOCATION")
if [[ "$default_checksum" != "$backup_checksum" ]]; then
if [[ $default_checksum != "$backup_checksum" ]]; then
dwarn "WARNING: checksum mismatch! Can't restore original initrd.."
else
rm -f $INITRD_CHECKSUM_LOCATION
@ -220,7 +220,7 @@ check_config()
dracut_args)
if [[ $config_val == *--mount* ]]; then
if [[ $(echo "$config_val" | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then
derror "Multiple mount targets specified in one \"dracut_args\"."
derror 'Multiple mount targets specified in one "dracut_args".'
return 1
fi
config_opt=_target
@ -232,12 +232,12 @@ check_config()
fi
config_opt=_target
;;
ext[234]|minix|btrfs|xfs|nfs|ssh)
ext[234] | minix | btrfs | xfs | nfs | ssh)
config_opt=_target
;;
sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|failure_action|default|final_action|force_rebuild|force_no_rebuild|fence_kdump_args|fence_kdump_nodes)
;;
net|options|link_delay|disk_timeout|debug_mem_level|blacklist)
sshkey | path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes) ;;
net | options | link_delay | disk_timeout | debug_mem_level | blacklist)
derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives."
return 1
;;
@ -250,12 +250,12 @@ check_config()
;;
esac
if [[ -z "$config_val" ]]; then
if [[ -z $config_val ]]; then
derror "Invalid kdump config value for option '$config_opt'"
return 1
fi
if [[ -n "${_opt_rec[$config_opt]}" ]]; then
if [[ -n ${_opt_rec[$config_opt]} ]]; then
if [[ $config_opt == _target ]]; then
derror "More than one dump targets specified"
else
@ -291,7 +291,7 @@ get_pcs_cluster_modified_files()
if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then
time_stamp=$(stat -c "%Y" "$FENCE_KDUMP_CONFIG_FILE")
if [[ "$time_stamp" -gt "$image_time" ]]; then
if [[ $time_stamp -gt $image_time ]]; then
modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE"
fi
fi
@ -335,14 +335,14 @@ check_files_modified()
HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/"
if [[ -d /etc/kdump/post.d ]]; then
for file in /etc/kdump/post.d/*; do
if [[ -x "$file" ]]; then
if [[ -x $file ]]; then
POST_FILES="$POST_FILES $file"
fi
done
fi
if [[ -d /etc/kdump/pre.d ]]; then
for file in /etc/kdump/pre.d/*; do
if [[ -x "$file" ]]; then
if [[ -x $file ]]; then
PRE_FILES="$PRE_FILES $file"
fi
done
@ -359,19 +359,19 @@ check_files_modified()
# Check for any updated extra module
EXTRA_MODULES="$(kdump_get_conf_val extra_modules)"
if [[ -n "$EXTRA_MODULES" ]]; then
if [[ -n $EXTRA_MODULES ]]; then
if [[ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]]; then
files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep"
fi
for _module in $EXTRA_MODULES; do
if _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)"; then
if _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2> /dev/null)"; then
files="$files $_module_file"
for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do
files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2>/dev/null)"
files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2> /dev/null)"
done
else
# If it's not a module nor builtin, give an error
if ! ( modprobe --set-version "$KDUMP_KERNELVER" --dry-run "$_module" &>/dev/null ); then
if ! (modprobe --set-version "$KDUMP_KERNELVER" --dry-run "$_module" &> /dev/null); then
dwarn "Module $_module not found"
fi
fi
@ -383,15 +383,15 @@ check_files_modified()
check_exist "$files" && check_executable "$EXTRA_BINS" || return 2
for file in $files; do
if [[ -e "$file" ]]; then
if [[ -e $file ]]; then
time_stamp=$(stat -c "%Y" "$file")
if [[ "$time_stamp" -gt "$image_time" ]]; then
if [[ $time_stamp -gt $image_time ]]; then
modified_files="$modified_files $file"
fi
if [[ -L "$file" ]]; then
if [[ -L $file ]]; then
file=$(readlink -m "$file")
time_stamp=$(stat -c "%Y" "$file")
if [[ "$time_stamp" -gt "$image_time" ]]; then
if [[ $time_stamp -gt $image_time ]]; then
modified_files="$modified_files $file"
fi
fi
@ -400,7 +400,7 @@ check_files_modified()
fi
done
if [[ -n "$modified_files" ]]; then
if [[ -n $modified_files ]]; then
dinfo "Detected change(s) in the following file(s): $modified_files"
return 1
fi
@ -414,8 +414,9 @@ check_drivers_modified()
# If it's dump target is on block device, detect the block driver
_target=$(get_block_dump_target)
if [[ -n "$_target" ]]; then
_record_block_drivers() {
if [[ -n $_target ]]; then
_record_block_drivers()
{
local _drivers
_drivers=$(udevadm info -a "/dev/block/$1" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p')
for _driver in $_drivers; do
@ -431,7 +432,7 @@ check_drivers_modified()
# Include watchdog drivers if watchdog module is not omitted
is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)"
[[ -z "$_new_drivers" ]] && return 0
[[ -z $_new_drivers ]] && return 0
if is_fadump_capable; then
_old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')"
@ -443,9 +444,9 @@ check_drivers_modified()
ddebug "Modules included in old initramfs: '$_old_drivers'"
for _driver in $_new_drivers; do
# Skip deprecated/invalid driver name or built-in module
_module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null)
_module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2>/dev/null)
if [[ -z "$_module_name" ]] || [[ -z "$_module_filename" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then
_module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2> /dev/null)
_module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2> /dev/null)
if [[ -z $_module_name ]] || [[ -z $_module_filename ]] || [[ $_module_filename == *"(builtin)"* ]]; then
continue
fi
if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then
@ -474,21 +475,21 @@ check_fs_modified()
_target=$(get_block_dump_target)
_new_fstype=$(get_fs_type_from_target "$_target")
if [[ -z "$_target" ]] || [[ -z "$_new_fstype" ]];then
if [[ -z $_target ]] || [[ -z $_new_fstype ]]; then
derror "Dump target is invalid"
return 2
fi
ddebug "_target=$_target _new_fstype=$_new_fstype"
_new_dev=$(kdump_get_persistent_dev "$_target")
if [[ -z "$_new_dev" ]]; then
if [[ -z $_new_dev ]]; then
perror "Get persistent device name failed"
return 2
fi
_new_mntpoint="$(get_kdump_mntpoint_from_target "$_target")"
_dracut_args=$(lsinitrd "$TARGET_INITRD" -f usr/lib/dracut/build-parameter.txt)
if [[ -z "$_dracut_args" ]];then
if [[ -z $_dracut_args ]]; then
dwarn "Warning: No dracut arguments found in initrd"
return 0
fi
@ -501,10 +502,10 @@ check_fs_modified()
_old_dev=$1
_old_mntpoint=$2
_old_fstype=$3
[[ $_new_dev = "$_old_dev" && $_new_mntpoint = "$_old_mntpoint" && $_new_fstype = "$_old_fstype" ]] && return 0
[[ $_new_dev == "$_old_dev" && $_new_mntpoint == "$_old_mntpoint" && $_new_fstype == "$_old_fstype" ]] && return 0
# otherwise rebuild if target device is not a root device
else
[[ "$_target" = "$(get_root_fs_device)" ]] && return 0
[[ $_target == "$(get_root_fs_device)" ]] && return 0
fi
dinfo "Detected change in File System"
@ -551,36 +552,36 @@ check_rebuild()
force_no_rebuild=$(kdump_get_conf_val force_no_rebuild)
force_no_rebuild=${force_no_rebuild:-0}
if [[ "$force_no_rebuild" != "0" ]] && [[ "$force_no_rebuild" != "1" ]];then
if [[ $force_no_rebuild != "0" ]] && [[ $force_no_rebuild != "1" ]]; then
derror "Error: force_no_rebuild value is invalid"
return 1
fi
force_rebuild=$(kdump_get_conf_val force_rebuild)
force_rebuild=${force_rebuild:-0}
if [[ "$force_rebuild" != "0" ]] && [[ "$force_rebuild" != "1" ]];then
if [[ $force_rebuild != "0" ]] && [[ $force_rebuild != "1" ]]; then
derror "Error: force_rebuild value is invalid"
return 1
fi
if [[ "$force_no_rebuild" == "1" && "$force_rebuild" == "1" ]]; then
if [[ $force_no_rebuild == "1" && $force_rebuild == "1" ]]; then
derror "Error: force_rebuild and force_no_rebuild are enabled simultaneously in kdump.conf"
return 1
fi
# Will not rebuild kdump initrd
if [[ "$force_no_rebuild" == "1" ]]; then
if [[ $force_no_rebuild == "1" ]]; then
return 0
fi
#check to see if dependent files has been modified
#since last build of the image file
if [[ -f $TARGET_INITRD ]]; then
image_time=$(stat -c "%Y" "$TARGET_INITRD" 2>/dev/null)
image_time=$(stat -c "%Y" "$TARGET_INITRD" 2> /dev/null)
#in case of fadump mode, check whether the default/target
#initrd is already built with dump capture capability
if [[ "$DEFAULT_DUMP_MODE" == "fadump" ]]; then
if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$)
fi
fi
@ -589,17 +590,17 @@ check_rebuild()
ret=$?
if [[ $ret -eq 2 ]]; then
return 1
elif [[ $ret -eq 1 ]];then
elif [[ $ret -eq 1 ]]; then
system_modified="1"
fi
if [[ $image_time -eq 0 ]]; then
dinfo "No kdump initial ramdisk found."
elif [[ "$capture_capable_initrd" == "0" ]]; then
elif [[ $capture_capable_initrd == "0" ]]; then
dinfo "Rebuild $TARGET_INITRD with dump capture support"
elif [[ "$force_rebuild" != "0" ]]; then
elif [[ $force_rebuild != "0" ]]; then
dinfo "Force rebuild $TARGET_INITRD"
elif [[ "$system_modified" != "0" ]]; then
elif [[ $system_modified != "0" ]]; then
:
else
return 0
@ -617,13 +618,13 @@ function load_kdump_kernel_key()
# this is only called inside is_secure_boot_enforced,
# no need to retest
# this is only required if DT /ibm,secure-boot is a file.
# if it is a dir, we are on OpenPower and don't need this.
if ! [[ -f /proc/device-tree/ibm,secure-boot ]]; then
return
fi
# this is only required if DT /ibm,secure-boot is a file.
# if it is a dir, we are on OpenPower and don't need this.
if ! [[ -f /proc/device-tree/ibm,secure-boot ]]; then
return
fi
KDUMP_KEY_ID=$(keyctl padd asymmetric kernelkey-$RANDOM %:.ima < "/usr/share/doc/kernel-keys/$KDUMP_KERNELVER/kernel-signing-ppc.cer")
KDUMP_KEY_ID=$(keyctl padd asymmetric kernelkey-$RANDOM %:.ima < "/usr/share/doc/kernel-keys/$KDUMP_KERNELVER/kernel-signing-ppc.cer")
}
# remove a previously loaded key. There's no real security implication
@ -631,7 +632,7 @@ function load_kdump_kernel_key()
# to be idempotent and so as to reduce the potential for confusion.
function remove_kdump_kernel_key()
{
if [[ -z "$KDUMP_KEY_ID" ]]; then
if [[ -z $KDUMP_KEY_ID ]]; then
return
fi
@ -696,7 +697,7 @@ check_ssh_config()
case "$config_opt" in
sshkey)
# remove inline comments after the end of a directive.
if [[ -f "$config_val" ]]; then
if [[ -f $config_val ]]; then
# canonicalize the path
SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val")
else
@ -709,14 +710,14 @@ check_ssh_config()
ssh)
DUMP_TARGET=$config_val
;;
*)
;;
*) ;;
esac
done <<< "$(kdump_read_conf)"
#make sure they've configured kdump.conf for ssh dumps
SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p')
if [[ -z "$SSH_TARGET" ]]; then
if [[ -z $SSH_TARGET ]]; then
return 1
fi
return 0
@ -763,7 +764,7 @@ check_and_wait_network_ready()
diff=$((cur - start_time))
# 60s time out
if [[ $diff -gt 180 ]]; then
break;
break
fi
sleep 1
done
@ -814,19 +815,19 @@ propagate_ssh_key()
show_reserved_mem()
{
local mem
local mem_mb
local mem
local mem_mb
mem=$(</sys/kernel/kexec_crash_size)
mem_mb=$((mem / 1024 / 1024))
mem=$(< /sys/kernel/kexec_crash_size)
mem_mb=$((mem / 1024 / 1024))
dinfo "Reserved ${mem_mb}MB memory for crash kernel"
dinfo "Reserved ${mem_mb}MB memory for crash kernel"
}
check_current_fadump_status()
{
# Check if firmware-assisted dump has been registered.
rc=$(<$FADUMP_REGISTER_SYS_NODE)
rc=$(< $FADUMP_REGISTER_SYS_NODE)
[[ $rc -eq 1 ]] && return 0
return 1
}
@ -848,8 +849,8 @@ save_raw()
local raw_target
raw_target=$(kdump_get_conf_val raw)
[[ -z "$raw_target" ]] && return 0
[[ -b "$raw_target" ]] || {
[[ -z $raw_target ]] && return 0
[[ -b $raw_target ]] || {
derror "raw partition $raw_target not found"
return 1
}
@ -859,22 +860,22 @@ save_raw()
return 0
fi
kdump_dir=$(kdump_get_conf_val path)
if [[ -z "${kdump_dir}" ]]; then
if [[ -z ${kdump_dir} ]]; then
coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
else
coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")"
fi
mkdir -p "$coredir"
[[ -d "$coredir" ]] || {
[[ -d $coredir ]] || {
derror "failed to create $coredir"
return 1
}
if makedumpfile -R "$coredir/vmcore" < "$raw_target" >/dev/null 2>&1; then
if makedumpfile -R "$coredir/vmcore" < "$raw_target" > /dev/null 2>&1; then
# dump found
dinfo "Dump saved to $coredir/vmcore"
# wipe makedumpfile header
dd if=/dev/zero of="$raw_target" bs=1b count=1 2>/dev/null
dd if=/dev/zero of="$raw_target" bs=1b count=1 2> /dev/null
else
rm -rf "$coredir"
fi
@ -897,11 +898,11 @@ path_to_be_relabeled()
if is_user_configured_dump_target; then
if is_mount_in_dracut_args; then
return;
return
fi
_target=$(local_fs_dump_target)
if [[ -n "$_target" ]]; then
if [[ -n $_target ]]; then
_mnt=$(get_mntpoint_from_target "$_target")
if ! is_mounted "$_mnt"; then
return
@ -913,8 +914,8 @@ path_to_be_relabeled()
_path=$(get_save_path)
# if $_path is masked by other mount, we will not relabel it.
_rmnt=$(df "$_mnt/$_path" 2>/dev/null | tail -1 | awk '{ print $NF }')
if [[ "$_rmnt" == "$_mnt" ]]; then
_rmnt=$(df "$_mnt/$_path" 2> /dev/null | tail -1 | awk '{ print $NF }')
if [[ $_rmnt == "$_mnt" ]]; then
echo "$_mnt/$_path"
fi
}
@ -924,14 +925,14 @@ selinux_relabel()
local _path _i _attr
_path=$(path_to_be_relabeled)
if [[ -z "$_path" ]] || ! [[ -d "$_path" ]] ; then
if [[ -z $_path ]] || ! [[ -d $_path ]]; then
return
fi
while IFS= read -r -d '' _i; do
_attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null)
if [[ -z "$_attr" ]]; then
restorecon "$_i";
_attr=$(getfattr -m "security.selinux" "$_i" 2> /dev/null)
if [[ -z $_attr ]]; then
restorecon "$_i"
fi
done < <(find "$_path" -print0)
}
@ -947,7 +948,7 @@ check_fence_kdump_config()
nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in $nodes; do
if [[ "$node" = "$hostname" ]]; then
if [[ $node == "$hostname" ]]; then
derror "Option fence_kdump_nodes cannot contain $hostname"
return 1
fi
@ -1003,25 +1004,26 @@ check_failure_action_config()
default_option=$(kdump_get_conf_val default)
failure_action=$(kdump_get_conf_val failure_action)
if [[ -z "$failure_action" ]] && [[ -z "$default_option" ]]; then
if [[ -z $failure_action ]] && [[ -z $default_option ]]; then
return 0
elif [[ -n "$failure_action" ]] && [[ -n "$default_option" ]]; then
elif [[ -n $failure_action ]] && [[ -n $default_option ]]; then
derror "Cannot specify 'failure_action' and 'default' option together"
return 1
fi
if [[ -n "$default_option" ]]; then
if [[ -n $default_option ]]; then
option="default"
failure_action="$default_option"
fi
case "$failure_action" in
reboot|halt|poweroff|shell|dump_to_rootfs)
reboot | halt | poweroff | shell | dump_to_rootfs)
return 0
;;
*)
;;
*)
dinfo $"Usage kdump.conf: $option {reboot|halt|poweroff|shell|dump_to_rootfs}"
return 1
;;
esac
}
@ -1030,16 +1032,17 @@ check_final_action_config()
local final_action
final_action=$(kdump_get_conf_val final_action)
if [[ -z "$final_action" ]]; then
if [[ -z $final_action ]]; then
return 0
else
case "$final_action" in
reboot|halt|poweroff)
reboot | halt | poweroff)
return 0
;;
*)
;;
*)
dinfo $"Usage kdump.conf: final_action {reboot|halt|poweroff}"
return 1
;;
esac
fi
}
@ -1056,7 +1059,7 @@ start()
return 1
fi
if sestatus 2>/dev/null | grep -q "SELinux status.*enabled"; then
if sestatus 2> /dev/null | grep -q "SELinux status.*enabled"; then
selinux_relabel
fi
@ -1187,7 +1190,8 @@ stop()
return 0
}
rebuild() {
rebuild()
{
check_config || return 1
if check_ssh_config; then
@ -1203,33 +1207,34 @@ rebuild() {
return $?
}
do_estimate() {
do_estimate()
{
local kdump_mods
local -A large_mods
local baseline
local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommended_size
local size_mb=$(( 1024 * 1024 ))
local size_mb=$((1024 * 1024))
setup_initrd
if [[ ! -f "$TARGET_INITRD" ]]; then
if [[ ! -f $TARGET_INITRD ]]; then
derror "kdumpctl estimate: kdump initramfs is not built yet."
exit 1
fi
kdump_mods="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')"
baseline=$(kdump_get_arch_recommend_size)
if [[ "${baseline: -1}" == "M" ]]; then
if [[ ${baseline: -1} == "M" ]]; then
baseline=${baseline%M}
elif [[ "${baseline: -1}" == "G" ]]; then
baseline=$(( ${baseline%G} * 1024 ))
elif [[ "${baseline: -1}" == "T" ]]; then
baseline=$(( ${baseline%Y} * 1048576 ))
elif [[ ${baseline: -1} == "G" ]]; then
baseline=$((${baseline%G} * 1024))
elif [[ ${baseline: -1} == "T" ]]; then
baseline=$((${baseline%Y} * 1048576))
fi
# The default pre-reserved crashkernel value
baseline_size=$((baseline * size_mb))
# Current reserved crashkernel size
reserved_size=$(</sys/kernel/kexec_crash_size)
reserved_size=$(< /sys/kernel/kexec_crash_size)
# A pre-estimated value for userspace usage and kernel
# runtime allocation, 64M should good for most cases
runtime_size=$((64 * size_mb))
@ -1240,7 +1245,7 @@ do_estimate() {
# Kernel modules static size after loaded
mod_size=0
while read -r _name _size _; do
if [[ ! " $kdump_mods " == *" $_name "* ]]; then
if [[ " $kdump_mods " != *" $_name "* ]]; then
continue
fi
mod_size=$((mod_size + _size))
@ -1255,8 +1260,8 @@ do_estimate() {
crypt_size=0
for _dev in $(get_all_kdump_crypt_dev); do
_crypt_info=$(cryptsetup luksDump "/dev/block/$_dev")
[[ $(echo "$_crypt_info" | sed -n "s/^Version:\s*\(.*\)/\1/p" ) == "2" ]] || continue
for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n ); do
[[ $(echo "$_crypt_info" | sed -n "s/^Version:\s*\(.*\)/\1/p") == "2" ]] || continue
for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n); do
crypt_size=$((crypt_size + _mem * 1024))
break
done
@ -1277,10 +1282,10 @@ do_estimate() {
echo "Kernel modules size: $((mod_size / size_mb))M"
echo "Initramfs size: $((initrd_size / size_mb))M"
echo "Runtime reservation: $((runtime_size / size_mb))M"
[[ $crypt_size -ne 0 ]] && \
echo "LUKS required size: $((crypt_size / size_mb))M"
[[ $crypt_size -ne 0 ]] &&
echo "LUKS required size: $((crypt_size / size_mb))M"
echo -n "Large modules:"
if [[ "${#large_mods[@]}" -eq 0 ]]; then
if [[ ${#large_mods[@]} -eq 0 ]]; then
echo " <none>"
else
echo ""
@ -1294,14 +1299,15 @@ do_estimate() {
fi
}
reset_crashkernel() {
reset_crashkernel()
{
local kernel=$1 entry crashkernel_default
local grub_etc_default="/etc/default/grub"
[[ -z "$kernel" ]] && kernel=$(uname -r)
crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null)
[[ -z $kernel ]] && kernel=$(uname -r)
crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2> /dev/null)
if [[ -z "$crashkernel_default" ]]; then
if [[ -z $crashkernel_default ]]; then
derror "$kernel doesn't have a crashkernel.default"
exit 1
fi
@ -1318,7 +1324,7 @@ reset_crashkernel() {
entry=${entry#\"}
entry=${entry%\"}
if [[ -f "$grub_etc_default" ]]; then
if [[ -f $grub_etc_default ]]; then
sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$crashkernel_default\2/" "$grub_etc_default"
fi
@ -1328,18 +1334,18 @@ reset_crashkernel() {
fi
}
if [[ ! -f "$KDUMP_CONFIG_FILE" ]]; then
if [[ ! -f $KDUMP_CONFIG_FILE ]]; then
derror "Error: No kdump config file found!"
exit 1
fi
main ()
main()
{
# Determine if the dump mode is kdump or fadump
determine_dump_mode
case "$1" in
start)
start)
if [[ -s /proc/vmcore ]]; then
save_core
reboot
@ -1347,51 +1353,52 @@ main ()
start
fi
;;
stop)
stop)
stop
;;
status)
status)
EXIT_CODE=0
check_current_status
case "$?" in
0)
0)
dinfo "Kdump is operational"
EXIT_CODE=0
;;
1)
1)
dinfo "Kdump is not operational"
EXIT_CODE=3
;;
esac
exit $EXIT_CODE
;;
reload)
reload)
reload
;;
restart)
restart)
stop
start
;;
rebuild)
rebuild)
rebuild
;;
condrestart)
;;
propagate)
condrestart) ;;
propagate)
propagate_ssh_key
;;
showmem)
showmem)
show_reserved_mem
;;
estimate)
estimate)
do_estimate
;;
reset-crashkernel)
reset-crashkernel)
reset_crashkernel "$2"
;;
*)
*)
dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}"
exit 1
;;
esac
}
@ -1400,6 +1407,9 @@ single_instance_lock
# To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call main.
# So that fd isn't leaking when main is invoking a subshell.
(exec 9<&-; main "$@")
(
exec 9<&-
main "$@"
)
exit $?

518
mkdumprd
View File

@ -27,7 +27,7 @@ SAVE_PATH=$(get_save_path)
OVERRIDE_RESETTABLE=0
extra_modules=""
dracut_args=( --add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump" )
dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump")
MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)"
[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed."
@ -43,66 +43,71 @@ trap '
# clean up after ourselves no matter how we die.
trap 'exit 1;' SIGINT
add_dracut_arg() {
dracut_args+=( "$@" )
add_dracut_arg()
{
dracut_args+=("$@")
}
add_dracut_mount() {
add_dracut_arg "--mount" "$1"
add_dracut_mount()
{
add_dracut_arg "--mount" "$1"
}
add_dracut_sshkey() {
add_dracut_arg "--sshkey" "$1"
add_dracut_sshkey()
{
add_dracut_arg "--sshkey" "$1"
}
# caller should ensure $1 is valid and mounted in 1st kernel
to_mount() {
local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev
to_mount()
{
local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev
_new_mntpoint=$(get_kdump_mntpoint_from_target "$_target")
_fstype="${_fstype:-$(get_fs_type_from_target "$_target")}"
_options="${_options:-$(get_mntopt_from_target "$_target")}"
_options="${_options:-defaults}"
_new_mntpoint=$(get_kdump_mntpoint_from_target "$_target")
_fstype="${_fstype:-$(get_fs_type_from_target "$_target")}"
_options="${_options:-$(get_mntopt_from_target "$_target")}"
_options="${_options:-defaults}"
if [[ "$_fstype" == "nfs"* ]]; then
_pdev=$_target
_sed_cmd+='s/,addr=[^,]*//;'
_sed_cmd+='s/,proto=[^,]*//;'
_sed_cmd+='s/,clientaddr=[^,]*//;'
else
# for non-nfs _target converting to use udev persistent name
_pdev="$(kdump_get_persistent_dev "$_target")"
if [[ -z $_pdev ]]; then
return 1
fi
fi
if [[ $_fstype == "nfs"* ]]; then
_pdev=$_target
_sed_cmd+='s/,addr=[^,]*//;'
_sed_cmd+='s/,proto=[^,]*//;'
_sed_cmd+='s/,clientaddr=[^,]*//;'
else
# for non-nfs _target converting to use udev persistent name
_pdev="$(kdump_get_persistent_dev "$_target")"
if [[ -z $_pdev ]]; then
return 1
fi
fi
# mount fs target as rw in 2nd kernel
_sed_cmd+='s/\(^\|,\)ro\($\|,\)/\1rw\2/g;'
# with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd
# kernel, filter it out here.
_sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;'
# drop nofail or nobootwait
_sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;'
_sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;'
# mount fs target as rw in 2nd kernel
_sed_cmd+='s/\(^\|,\)ro\($\|,\)/\1rw\2/g;'
# with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd
# kernel, filter it out here.
_sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;'
# drop nofail or nobootwait
_sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;'
_sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;'
_options=$(echo "$_options" | sed "$_sed_cmd")
_options=$(echo "$_options" | sed "$_sed_cmd")
echo "$_pdev $_new_mntpoint $_fstype $_options"
echo "$_pdev $_new_mntpoint $_fstype $_options"
}
#Function: get_ssh_size
#$1=dump target
#called from while loop and shouldn't read from stdin, so we're using "ssh -n"
get_ssh_size() {
local _out
local _opt=("-i" "$SSH_KEY_LOCATION" "-o" "BatchMode=yes" "-o" "StrictHostKeyChecking=yes")
get_ssh_size()
{
local _out
local _opt=("-i" "$SSH_KEY_LOCATION" "-o" "BatchMode=yes" "-o" "StrictHostKeyChecking=yes")
if ! _out=$(ssh -q -n "${_opt[@]}" "$1" "df" "--output=avail" "$SAVE_PATH"); then
perror_exit "checking remote ssh server available size failed."
fi
if ! _out=$(ssh -q -n "${_opt[@]}" "$1" "df" "--output=avail" "$SAVE_PATH"); then
perror_exit "checking remote ssh server available size failed."
fi
echo -n "$_out" | tail -1
echo -n "$_out" | tail -1
}
#mkdir if save path does not exist on ssh dump target
@ -111,320 +116,323 @@ get_ssh_size() {
#called from while loop and shouldn't read from stdin, so we're using "ssh -n"
mkdir_save_path_ssh()
{
local _opt _dir
_opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes)
ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" &>/dev/null || \
perror_exit "mkdir failed on $1:$SAVE_PATH"
local _opt _dir
_opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes)
ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" &> /dev/null ||
perror_exit "mkdir failed on $1:$SAVE_PATH"
# check whether user has write permission on $1:$SAVE_PATH
_dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null) || \
perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination"
ssh -qn "${_opt[@]}" "$1" rmdir "$_dir"
# check whether user has write permission on $1:$SAVE_PATH
_dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2> /dev/null) ||
perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination"
ssh -qn "${_opt[@]}" "$1" rmdir "$_dir"
return 0
return 0
}
#Function: get_fs_size
#$1=dump target
get_fs_size() {
df --output=avail "$(get_mntpoint_from_target "$1")/$SAVE_PATH" | tail -1
get_fs_size()
{
df --output=avail "$(get_mntpoint_from_target "$1")/$SAVE_PATH" | tail -1
}
#Function: get_raw_size
#$1=dump target
get_raw_size() {
fdisk -s "$1"
get_raw_size()
{
fdisk -s "$1"
}
#Function: check_size
#$1: dump type string ('raw', 'fs', 'ssh')
#$2: dump target
check_size() {
local avail memtotal
check_size()
{
local avail memtotal
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
case "$1" in
raw)
avail=$(get_raw_size "$2")
;;
ssh)
avail=$(get_ssh_size "$2")
;;
fs)
avail=$(get_fs_size "$2")
;;
*)
return
esac || perror_exit "Check dump target size failed"
memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo)
case "$1" in
raw)
avail=$(get_raw_size "$2")
;;
ssh)
avail=$(get_ssh_size "$2")
;;
fs)
avail=$(get_fs_size "$2")
;;
*)
return
;;
esac || perror_exit "Check dump target size failed"
if [[ "$avail" -lt "$memtotal" ]]; then
dwarn "Warning: There might not be enough space to save a vmcore."
dwarn " The size of $2 should be greater than $memtotal kilo bytes."
fi
if [[ $avail -lt $memtotal ]]; then
dwarn "Warning: There might not be enough space to save a vmcore."
dwarn " The size of $2 should be greater than $memtotal kilo bytes."
fi
}
check_save_path_fs()
{
local _path=$1
local _path=$1
if [[ ! -d $_path ]]; then
perror_exit "Dump path $_path does not exist."
fi
if [[ ! -d $_path ]]; then
perror_exit "Dump path $_path does not exist."
fi
}
mount_failure()
{
local _target=$1
local _mnt=$2
local _fstype=$3
local msg="Failed to mount $_target"
local _target=$1
local _mnt=$2
local _fstype=$3
local msg="Failed to mount $_target"
if [[ -n "$_mnt" ]]; then
msg="$msg on $_mnt"
fi
if [[ -n $_mnt ]]; then
msg="$msg on $_mnt"
fi
msg="$msg for kdump preflight check."
msg="$msg for kdump preflight check."
if [[ $_fstype = "nfs" ]]; then
msg="$msg Please make sure nfs-utils has been installed."
fi
if [[ $_fstype == "nfs" ]]; then
msg="$msg Please make sure nfs-utils has been installed."
fi
perror_exit "$msg"
perror_exit "$msg"
}
check_user_configured_target()
{
local _target=$1 _cfg_fs_type=$2 _mounted
local _mnt _opt _fstype
local _target=$1 _cfg_fs_type=$2 _mounted
local _mnt _opt _fstype
_mnt=$(get_mntpoint_from_target "$_target")
_opt=$(get_mntopt_from_target "$_target")
_fstype=$(get_fs_type_from_target "$_target")
_mnt=$(get_mntpoint_from_target "$_target")
_opt=$(get_mntopt_from_target "$_target")
_fstype=$(get_fs_type_from_target "$_target")
if [[ -n "$_fstype" ]]; then
# In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf
[[ $_fstype = "nfs"* ]] && _fstype=nfs
if [[ -n $_fstype ]]; then
# In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf
[[ $_fstype == "nfs"* ]] && _fstype=nfs
if [[ -n "$_cfg_fs_type" ]] && [[ "$_fstype" != "$_cfg_fs_type" ]]; then
perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\""
fi
else
_fstype="$_cfg_fs_type"
_fstype="$_cfg_fs_type"
fi
if [[ -n $_cfg_fs_type ]] && [[ $_fstype != "$_cfg_fs_type" ]]; then
perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\""
fi
else
_fstype="$_cfg_fs_type"
_fstype="$_cfg_fs_type"
fi
# For noauto mount, mount it inplace with default value.
# Else use the temporary target directory
if [[ -n "$_mnt" ]]; then
if ! is_mounted "$_mnt"; then
if [[ $_opt = *",noauto"* ]]; then
mount "$_mnt" || mount_failure "$_target" "$_mnt" "$_fstype"
_mounted=$_mnt
else
perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\""
fi
fi
else
_mnt=$MKDUMPRD_TMPMNT
mkdir -p "$_mnt"
mount "$_target" "$_mnt" -t "$_fstype" -o defaults || mount_failure "$_target" "" "$_fstype"
_mounted=$_mnt
fi
# For noauto mount, mount it inplace with default value.
# Else use the temporary target directory
if [[ -n $_mnt ]]; then
if ! is_mounted "$_mnt"; then
if [[ $_opt == *",noauto"* ]]; then
mount "$_mnt" || mount_failure "$_target" "$_mnt" "$_fstype"
_mounted=$_mnt
else
perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\""
fi
fi
else
_mnt=$MKDUMPRD_TMPMNT
mkdir -p "$_mnt"
mount "$_target" "$_mnt" -t "$_fstype" -o defaults || mount_failure "$_target" "" "$_fstype"
_mounted=$_mnt
fi
# For user configured target, use $SAVE_PATH as the dump path within the target
if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then
perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\""
fi
# For user configured target, use $SAVE_PATH as the dump path within the target
if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then
perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\""
fi
check_size fs "$_target"
check_size fs "$_target"
# Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway
if [[ -n "$_mounted" ]]; then
umount -f -- "$_mounted"
fi
# Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway
if [[ -n $_mounted ]]; then
umount -f -- "$_mounted"
fi
}
# $1: core_collector config value
verify_core_collector() {
local _cmd="${1%% *}"
local _params="${1#* }"
verify_core_collector()
{
local _cmd="${1%% *}"
local _params="${1#* }"
if [[ "$_cmd" != "makedumpfile" ]]; then
if is_raw_dump_target; then
dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually."
fi
return
fi
if [[ $_cmd != "makedumpfile" ]]; then
if is_raw_dump_target; then
dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually."
fi
return
fi
if is_ssh_dump_target || is_raw_dump_target; then
if ! strstr "$_params" "-F"; then
perror_exit "The specified dump target needs makedumpfile \"-F\" option."
fi
_params="$_params vmcore"
else
_params="$_params vmcore dumpfile"
fi
if is_ssh_dump_target || is_raw_dump_target; then
if ! strstr "$_params" "-F"; then
perror_exit 'The specified dump target needs makedumpfile "-F" option.'
fi
_params="$_params vmcore"
else
_params="$_params vmcore dumpfile"
fi
# shellcheck disable=SC2086
if ! $_cmd --check-params $_params; then
perror_exit "makedumpfile parameter check failed."
fi
# shellcheck disable=SC2086
if ! $_cmd --check-params $_params; then
perror_exit "makedumpfile parameter check failed."
fi
}
add_mount() {
local _mnt
add_mount()
{
local _mnt
_mnt=$(to_mount "$@") || exit 1
_mnt=$(to_mount "$@") || exit 1
add_dracut_mount "$_mnt"
add_dracut_mount "$_mnt"
}
#handle the case user does not specify the dump target explicitly
handle_default_dump_target()
{
local _target
local _mntpoint
local _target
local _mntpoint
is_user_configured_dump_target && return
is_user_configured_dump_target && return
check_save_path_fs "$SAVE_PATH"
check_save_path_fs "$SAVE_PATH"
_save_path=$(get_bind_mount_source "$SAVE_PATH")
_target=$(get_target_from_path "$_save_path")
_mntpoint=$(get_mntpoint_from_target "$_target")
_save_path=$(get_bind_mount_source "$SAVE_PATH")
_target=$(get_target_from_path "$_save_path")
_mntpoint=$(get_mntpoint_from_target "$_target")
SAVE_PATH=${_save_path##"$_mntpoint"}
add_mount "$_target"
check_size fs "$_target"
SAVE_PATH=${_save_path##"$_mntpoint"}
add_mount "$_target"
check_size fs "$_target"
}
# $1: function name
for_each_block_target()
{
local dev majmin
local dev majmin
for dev in $(get_kdump_targets); do
[[ -b "$dev" ]] || continue
majmin=$(get_maj_min "$dev")
check_block_and_slaves "$1" "$majmin" && return 1
done
for dev in $(get_kdump_targets); do
[[ -b $dev ]] || continue
majmin=$(get_maj_min "$dev")
check_block_and_slaves "$1" "$majmin" && return 1
done
return 0
return 0
}
#judge if a specific device with $1 is unresettable
#return false if unresettable.
is_unresettable()
{
local path device resettable=1
local path device resettable=1
path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable"
if [[ -f "$path" ]]; then
resettable="$(<"$path")"
[[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && {
device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}')
derror "Error: Can not save vmcore because device $device is unresettable"
return 0
}
fi
path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable"
if [[ -f $path ]]; then
resettable="$(< "$path")"
[[ $resettable -eq 0 ]] && [[ $OVERRIDE_RESETTABLE -eq 0 ]] && {
device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}')
derror "Error: Can not save vmcore because device $device is unresettable"
return 0
}
fi
return 1
return 1
}
#check if machine is resettable.
#return true if resettable
check_resettable()
{
local _target _override_resettable
local _target _override_resettable
_override_resettable=$(kdump_get_conf_val override_resettable)
OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE}
if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then
perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid"
fi
_override_resettable=$(kdump_get_conf_val override_resettable)
OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE}
if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ]; then
perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid"
fi
for_each_block_target is_unresettable && return
for_each_block_target is_unresettable && return
return 1
return 1
}
check_crypt()
{
local _dev
local _dev
for _dev in $(get_kdump_targets); do
if [[ -n $(get_luks_crypt_dev "$(get_maj_min "$_dev")") ]]; then
derror "Device $_dev is encrypted." && return 1
fi
done
for _dev in $(get_kdump_targets); do
if [[ -n $(get_luks_crypt_dev "$(get_maj_min "$_dev")") ]]; then
derror "Device $_dev is encrypted." && return 1
fi
done
}
if ! check_resettable; then
exit 1
exit 1
fi
if ! check_crypt; then
dwarn "Warning: Encrypted device is in dump path, which is not recommended, see kexec-kdump-howto.txt for more details."
dwarn "Warning: Encrypted device is in dump path, which is not recommended, see kexec-kdump-howto.txt for more details."
fi
# firstly get right SSH_KEY_LOCATION
keyfile=$(kdump_get_conf_val sshkey)
if [[ -f "$keyfile" ]]; then
# canonicalize the path
SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$keyfile")
if [[ -f $keyfile ]]; then
# canonicalize the path
SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$keyfile")
fi
while read -r config_opt config_val;
do
# remove inline comments after the end of a directive.
case "$config_opt" in
extra_modules)
extra_modules="$extra_modules $config_val"
;;
ext[234]|xfs|btrfs|minix|nfs)
check_user_configured_target "$config_val" "$config_opt"
add_mount "$config_val" "$config_opt"
;;
raw)
# checking raw disk writable
dd if="$config_val" count=1 of=/dev/null > /dev/null 2>&1 || {
perror_exit "Bad raw disk $config_val"
}
_praw=$(persistent_policy="by-id" kdump_get_persistent_dev "$config_val")
if [[ -z $_praw ]]; then
exit 1
fi
add_dracut_arg "--device" "$_praw"
check_size raw "$config_val"
;;
ssh)
if strstr "$config_val" "@";
then
mkdir_save_path_ssh "$config_val"
check_size ssh "$config_val"
add_dracut_sshkey "$SSH_KEY_LOCATION"
else
perror_exit "Bad ssh dump target $config_val"
fi
;;
core_collector)
verify_core_collector "$config_val"
;;
dracut_args)
while read -r dracut_arg; do
add_dracut_arg "$dracut_arg"
done <<< "$(echo "$config_val" | xargs -n 1 echo)"
;;
*)
;;
esac
while read -r config_opt config_val; do
# remove inline comments after the end of a directive.
case "$config_opt" in
extra_modules)
extra_modules="$extra_modules $config_val"
;;
ext[234] | xfs | btrfs | minix | nfs)
check_user_configured_target "$config_val" "$config_opt"
add_mount "$config_val" "$config_opt"
;;
raw)
# checking raw disk writable
dd if="$config_val" count=1 of=/dev/null > /dev/null 2>&1 || {
perror_exit "Bad raw disk $config_val"
}
_praw=$(persistent_policy="by-id" kdump_get_persistent_dev "$config_val")
if [[ -z $_praw ]]; then
exit 1
fi
add_dracut_arg "--device" "$_praw"
check_size raw "$config_val"
;;
ssh)
if strstr "$config_val" "@"; then
mkdir_save_path_ssh "$config_val"
check_size ssh "$config_val"
add_dracut_sshkey "$SSH_KEY_LOCATION"
else
perror_exit "Bad ssh dump target $config_val"
fi
;;
core_collector)
verify_core_collector "$config_val"
;;
dracut_args)
while read -r dracut_arg; do
add_dracut_arg "$dracut_arg"
done <<< "$(echo "$config_val" | xargs -n 1 echo)"
;;
*) ;;
esac
done <<< "$(kdump_read_conf)"
handle_default_dump_target
if [[ -n "$extra_modules" ]]
then
add_dracut_arg "--add-drivers" "$extra_modules"
if [[ -n $extra_modules ]]; then
add_dracut_arg "--add-drivers" "$extra_modules"
fi
# TODO: The below check is not needed anymore with the introduction of
@ -433,11 +441,11 @@ fi
# parameter available in fadump case. So, find a way to fix that first
# before removing this check.
if ! is_fadump_capable; then
# The 2nd rootfs mount stays behind the normal dump target mount,
# so it doesn't affect the logic of check_dump_fs_modified().
is_dump_to_rootfs && add_mount "$(to_dev_name "$(get_root_fs_device)")"
# The 2nd rootfs mount stays behind the normal dump target mount,
# so it doesn't affect the logic of check_dump_fs_modified().
is_dump_to_rootfs && add_mount "$(to_dev_name "$(get_root_fs_device)")"
add_dracut_arg "--no-hostonly-default-device"
add_dracut_arg "--no-hostonly-default-device"
fi
dracut "${dracut_args[@]}" "$@"

View File

@ -44,22 +44,22 @@ fi
### Unpack the initramfs having dump capture capability
mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot"
if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" && \
if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" &&
popd > /dev/null); then
derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'"
exit 1
fi
### Pack it into the normal boot initramfs with zz-fadumpinit module
_dracut_isolate_args=(\
--rebuild "$REBUILD_INITRD" --add zz-fadumpinit \
_dracut_isolate_args=(
--rebuild "$REBUILD_INITRD" --add zz-fadumpinit
-i "$MKFADUMPRD_TMPDIR/fadumproot" /fadumproot
-i "$MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt"
/usr/lib/dracut/fadump-kernel-modules.txt
)
if is_squash_available; then
_dracut_isolate_args+=( --add squash )
_dracut_isolate_args+=(--add squash)
fi
if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then