bash scripts: reformat with shfmt

upstream: fedora
resolves: bz2003832
conflict:
    function load_kdump_kernel_key() not exist in rhel9,
    so related patch hunk is removed.

commit 0e4b66b1ab
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Sep 14 02:25:40 2021 +0800

    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>

Signed-off-by: Tao Liu <ltao@redhat.com>
This commit is contained in:
Tao Liu 2021-11-09 21:42:45 +08:00
parent 63308480fc
commit b494b7f193
5 changed files with 563 additions and 552 deletions

View File

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

View File

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

260
kdumpctl
View File

@ -46,7 +46,7 @@ single_instance_lock()
{ {
local rc timeout=5 local rc timeout=5
if ! exec 9>/var/lock/kdump; then if ! exec 9> /var/lock/kdump; then
derror "Create file lock failed" derror "Create file lock failed"
exit 1 exit 1
fi fi
@ -90,9 +90,9 @@ save_core()
# https://fedorahosted.org/abrt/ # https://fedorahosted.org/abrt/
if [[ -x /usr/bin/dumpoops ]]; then if [[ -x /usr/bin/dumpoops ]]; then
ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" 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" 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" dinfo "kernel oops has been collected by abrt tool"
fi fi
fi fi
@ -131,7 +131,7 @@ rebuild_kdump_initrd()
rebuild_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" derror "$(dirname "$TARGET_INITRD") does not have write permission. Cannot rebuild $TARGET_INITRD"
return 1 return 1
fi fi
@ -149,7 +149,7 @@ rebuild_initrd()
check_exist() check_exist()
{ {
for file in $1; do for file in $1; do
if [[ ! -e "$file" ]]; then if [[ ! -e $file ]]; then
derror "Error: $file not found." derror "Error: $file not found."
return 1 return 1
fi fi
@ -160,7 +160,7 @@ check_exist()
check_executable() check_executable()
{ {
for file in $1; do for file in $1; do
if [[ ! -x "$file" ]]; then if [[ ! -x $file ]]; then
derror "Error: $file is not executable." derror "Error: $file is not executable."
return 1 return 1
fi fi
@ -171,7 +171,7 @@ backup_default_initrd()
{ {
ddebug "backup default initrd: $DEFAULT_INITRD" ddebug "backup default initrd: $DEFAULT_INITRD"
if [[ ! -f "$DEFAULT_INITRD" ]]; then if [[ ! -f $DEFAULT_INITRD ]]; then
return return
fi fi
@ -190,7 +190,7 @@ restore_default_initrd()
{ {
ddebug "restore default initrd: $DEFAULT_INITRD" ddebug "restore default initrd: $DEFAULT_INITRD"
if [[ ! -f "$DEFAULT_INITRD" ]]; then if [[ ! -f $DEFAULT_INITRD ]]; then
return return
fi fi
@ -200,7 +200,7 @@ restore_default_initrd()
# verify checksum before restoring # verify checksum before restoring
backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }') backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }')
default_checksum=$(awk '{ print $1 }' "$INITRD_CHECKSUM_LOCATION") 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.." dwarn "WARNING: checksum mismatch! Can't restore original initrd.."
else else
rm -f $INITRD_CHECKSUM_LOCATION rm -f $INITRD_CHECKSUM_LOCATION
@ -220,7 +220,7 @@ check_config()
dracut_args) dracut_args)
if [[ $config_val == *--mount* ]]; then if [[ $config_val == *--mount* ]]; then
if [[ $(echo "$config_val" | grep -o "\-\-mount" | wc -l) -ne 1 ]]; 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 return 1
fi fi
config_opt=_target config_opt=_target
@ -232,12 +232,12 @@ check_config()
fi fi
config_opt=_target config_opt=_target
;; ;;
ext[234]|minix|btrfs|xfs|nfs|ssh) ext[234] | minix | btrfs | xfs | nfs | ssh)
config_opt=_target 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) 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) net | options | link_delay | disk_timeout | debug_mem_level | blacklist)
derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives."
return 1 return 1
;; ;;
@ -250,12 +250,12 @@ check_config()
;; ;;
esac esac
if [[ -z "$config_val" ]]; then if [[ -z $config_val ]]; then
derror "Invalid kdump config value for option '$config_opt'" derror "Invalid kdump config value for option '$config_opt'"
return 1 return 1
fi fi
if [[ -n "${_opt_rec[$config_opt]}" ]]; then if [[ -n ${_opt_rec[$config_opt]} ]]; then
if [[ $config_opt == _target ]]; then if [[ $config_opt == _target ]]; then
derror "More than one dump targets specified" derror "More than one dump targets specified"
else else
@ -291,7 +291,7 @@ get_pcs_cluster_modified_files()
if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then
time_stamp=$(stat -c "%Y" "$FENCE_KDUMP_CONFIG_FILE") 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" modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE"
fi fi
fi fi
@ -335,14 +335,14 @@ check_files_modified()
HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/"
if [[ -d /etc/kdump/post.d ]]; then if [[ -d /etc/kdump/post.d ]]; then
for file in /etc/kdump/post.d/*; do for file in /etc/kdump/post.d/*; do
if [[ -x "$file" ]]; then if [[ -x $file ]]; then
POST_FILES="$POST_FILES $file" POST_FILES="$POST_FILES $file"
fi fi
done done
fi fi
if [[ -d /etc/kdump/pre.d ]]; then if [[ -d /etc/kdump/pre.d ]]; then
for file in /etc/kdump/pre.d/*; do for file in /etc/kdump/pre.d/*; do
if [[ -x "$file" ]]; then if [[ -x $file ]]; then
PRE_FILES="$PRE_FILES $file" PRE_FILES="$PRE_FILES $file"
fi fi
done done
@ -359,19 +359,19 @@ check_files_modified()
# Check for any updated extra module # Check for any updated extra module
EXTRA_MODULES="$(kdump_get_conf_val extra_modules)" 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 if [[ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]]; then
files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep"
fi fi
for _module in $EXTRA_MODULES; do 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" files="$files $_module_file"
for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do 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 done
else else
# If it's not a module nor builtin, give an error # 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" dwarn "Module $_module not found"
fi fi
fi fi
@ -383,15 +383,15 @@ check_files_modified()
check_exist "$files" && check_executable "$EXTRA_BINS" || return 2 check_exist "$files" && check_executable "$EXTRA_BINS" || return 2
for file in $files; do for file in $files; do
if [[ -e "$file" ]]; then if [[ -e $file ]]; then
time_stamp=$(stat -c "%Y" "$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" modified_files="$modified_files $file"
fi fi
if [[ -L "$file" ]]; then if [[ -L $file ]]; then
file=$(readlink -m "$file") file=$(readlink -m "$file")
time_stamp=$(stat -c "%Y" "$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" modified_files="$modified_files $file"
fi fi
fi fi
@ -400,7 +400,7 @@ check_files_modified()
fi fi
done done
if [[ -n "$modified_files" ]]; then if [[ -n $modified_files ]]; then
dinfo "Detected change(s) in the following file(s): $modified_files" dinfo "Detected change(s) in the following file(s): $modified_files"
return 1 return 1
fi fi
@ -414,8 +414,9 @@ check_drivers_modified()
# If it's dump target is on block device, detect the block driver # If it's dump target is on block device, detect the block driver
_target=$(get_block_dump_target) _target=$(get_block_dump_target)
if [[ -n "$_target" ]]; then if [[ -n $_target ]]; then
_record_block_drivers() { _record_block_drivers()
{
local _drivers local _drivers
_drivers=$(udevadm info -a "/dev/block/$1" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p') _drivers=$(udevadm info -a "/dev/block/$1" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p')
for _driver in $_drivers; do for _driver in $_drivers; do
@ -431,7 +432,7 @@ check_drivers_modified()
# Include watchdog drivers if watchdog module is not omitted # Include watchdog drivers if watchdog module is not omitted
is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)" 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 if is_fadump_capable; then
_old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')" _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'" ddebug "Modules included in old initramfs: '$_old_drivers'"
for _driver in $_new_drivers; do for _driver in $_new_drivers; do
# Skip deprecated/invalid driver name or built-in module # Skip deprecated/invalid driver name or built-in module
_module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null) _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) _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2> /dev/null)
if [[ -z "$_module_name" ]] || [[ -z "$_module_filename" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then if [[ -z $_module_name ]] || [[ -z $_module_filename ]] || [[ $_module_filename == *"(builtin)"* ]]; then
continue continue
fi fi
if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then
@ -474,21 +475,21 @@ check_fs_modified()
_target=$(get_block_dump_target) _target=$(get_block_dump_target)
_new_fstype=$(get_fs_type_from_target "$_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" derror "Dump target is invalid"
return 2 return 2
fi fi
ddebug "_target=$_target _new_fstype=$_new_fstype" ddebug "_target=$_target _new_fstype=$_new_fstype"
_new_dev=$(kdump_get_persistent_dev "$_target") _new_dev=$(kdump_get_persistent_dev "$_target")
if [[ -z "$_new_dev" ]]; then if [[ -z $_new_dev ]]; then
perror "Get persistent device name failed" perror "Get persistent device name failed"
return 2 return 2
fi fi
_new_mntpoint="$(get_kdump_mntpoint_from_target "$_target")" _new_mntpoint="$(get_kdump_mntpoint_from_target "$_target")"
_dracut_args=$(lsinitrd "$TARGET_INITRD" -f usr/lib/dracut/build-parameter.txt) _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" dwarn "Warning: No dracut arguments found in initrd"
return 0 return 0
fi fi
@ -501,10 +502,10 @@ check_fs_modified()
_old_dev=$1 _old_dev=$1
_old_mntpoint=$2 _old_mntpoint=$2
_old_fstype=$3 _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 # otherwise rebuild if target device is not a root device
else else
[[ "$_target" = "$(get_root_fs_device)" ]] && return 0 [[ $_target == "$(get_root_fs_device)" ]] && return 0
fi fi
dinfo "Detected change in File System" 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=$(kdump_get_conf_val force_no_rebuild)
force_no_rebuild=${force_no_rebuild:-0} 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" derror "Error: force_no_rebuild value is invalid"
return 1 return 1
fi fi
force_rebuild=$(kdump_get_conf_val force_rebuild) force_rebuild=$(kdump_get_conf_val force_rebuild)
force_rebuild=${force_rebuild:-0} 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" derror "Error: force_rebuild value is invalid"
return 1 return 1
fi 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" derror "Error: force_rebuild and force_no_rebuild are enabled simultaneously in kdump.conf"
return 1 return 1
fi fi
# Will not rebuild kdump initrd # Will not rebuild kdump initrd
if [[ "$force_no_rebuild" == "1" ]]; then if [[ $force_no_rebuild == "1" ]]; then
return 0 return 0
fi fi
#check to see if dependent files has been modified #check to see if dependent files has been modified
#since last build of the image file #since last build of the image file
if [[ -f $TARGET_INITRD ]]; then 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 #in case of fadump mode, check whether the default/target
#initrd is already built with dump capture capability #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$) capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$)
fi fi
fi fi
@ -589,17 +590,17 @@ check_rebuild()
ret=$? ret=$?
if [[ $ret -eq 2 ]]; then if [[ $ret -eq 2 ]]; then
return 1 return 1
elif [[ $ret -eq 1 ]];then elif [[ $ret -eq 1 ]]; then
system_modified="1" system_modified="1"
fi fi
if [[ $image_time -eq 0 ]]; then if [[ $image_time -eq 0 ]]; then
dinfo "No kdump initial ramdisk found." 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" dinfo "Rebuild $TARGET_INITRD with dump capture support"
elif [[ "$force_rebuild" != "0" ]]; then elif [[ $force_rebuild != "0" ]]; then
dinfo "Force rebuild $TARGET_INITRD" dinfo "Force rebuild $TARGET_INITRD"
elif [[ "$system_modified" != "0" ]]; then elif [[ $system_modified != "0" ]]; then
: :
else else
return 0 return 0
@ -665,7 +666,7 @@ check_ssh_config()
case "$config_opt" in case "$config_opt" in
sshkey) sshkey)
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
if [[ -f "$config_val" ]]; then if [[ -f $config_val ]]; then
# canonicalize the path # canonicalize the path
SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val") SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val")
else else
@ -678,14 +679,14 @@ check_ssh_config()
ssh) ssh)
DUMP_TARGET=$config_val DUMP_TARGET=$config_val
;; ;;
*) *) ;;
;;
esac esac
done <<< "$(kdump_read_conf)" done <<< "$(kdump_read_conf)"
#make sure they've configured kdump.conf for ssh dumps #make sure they've configured kdump.conf for ssh dumps
SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p') SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p')
if [[ -z "$SSH_TARGET" ]]; then if [[ -z $SSH_TARGET ]]; then
return 1 return 1
fi fi
return 0 return 0
@ -732,7 +733,7 @@ check_and_wait_network_ready()
diff=$((cur - start_time)) diff=$((cur - start_time))
# 60s time out # 60s time out
if [[ $diff -gt 180 ]]; then if [[ $diff -gt 180 ]]; then
break; break
fi fi
sleep 1 sleep 1
done done
@ -783,19 +784,19 @@ propagate_ssh_key()
show_reserved_mem() show_reserved_mem()
{ {
local mem local mem
local mem_mb local mem_mb
mem=$(</sys/kernel/kexec_crash_size) mem=$(< /sys/kernel/kexec_crash_size)
mem_mb=$((mem / 1024 / 1024)) 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_current_fadump_status()
{ {
# Check if firmware-assisted dump has been registered. # Check if firmware-assisted dump has been registered.
rc=$(<$FADUMP_REGISTER_SYS_NODE) rc=$(< $FADUMP_REGISTER_SYS_NODE)
[[ $rc -eq 1 ]] && return 0 [[ $rc -eq 1 ]] && return 0
return 1 return 1
} }
@ -817,8 +818,8 @@ save_raw()
local raw_target local raw_target
raw_target=$(kdump_get_conf_val raw) raw_target=$(kdump_get_conf_val raw)
[[ -z "$raw_target" ]] && return 0 [[ -z $raw_target ]] && return 0
[[ -b "$raw_target" ]] || { [[ -b $raw_target ]] || {
derror "raw partition $raw_target not found" derror "raw partition $raw_target not found"
return 1 return 1
} }
@ -828,22 +829,22 @@ save_raw()
return 0 return 0
fi fi
kdump_dir=$(kdump_get_conf_val path) 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")" coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
else else
coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")" coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")"
fi fi
mkdir -p "$coredir" mkdir -p "$coredir"
[[ -d "$coredir" ]] || { [[ -d $coredir ]] || {
derror "failed to create $coredir" derror "failed to create $coredir"
return 1 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 # dump found
dinfo "Dump saved to $coredir/vmcore" dinfo "Dump saved to $coredir/vmcore"
# wipe makedumpfile header # 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 else
rm -rf "$coredir" rm -rf "$coredir"
fi fi
@ -866,11 +867,11 @@ path_to_be_relabeled()
if is_user_configured_dump_target; then if is_user_configured_dump_target; then
if is_mount_in_dracut_args; then if is_mount_in_dracut_args; then
return; return
fi fi
_target=$(local_fs_dump_target) _target=$(local_fs_dump_target)
if [[ -n "$_target" ]]; then if [[ -n $_target ]]; then
_mnt=$(get_mntpoint_from_target "$_target") _mnt=$(get_mntpoint_from_target "$_target")
if ! is_mounted "$_mnt"; then if ! is_mounted "$_mnt"; then
return return
@ -882,8 +883,8 @@ path_to_be_relabeled()
_path=$(get_save_path) _path=$(get_save_path)
# if $_path is masked by other mount, we will not relabel it. # if $_path is masked by other mount, we will not relabel it.
_rmnt=$(df "$_mnt/$_path" 2>/dev/null | tail -1 | awk '{ print $NF }') _rmnt=$(df "$_mnt/$_path" 2> /dev/null | tail -1 | awk '{ print $NF }')
if [[ "$_rmnt" == "$_mnt" ]]; then if [[ $_rmnt == "$_mnt" ]]; then
echo "$_mnt/$_path" echo "$_mnt/$_path"
fi fi
} }
@ -893,14 +894,14 @@ selinux_relabel()
local _path _i _attr local _path _i _attr
_path=$(path_to_be_relabeled) _path=$(path_to_be_relabeled)
if [[ -z "$_path" ]] || ! [[ -d "$_path" ]] ; then if [[ -z $_path ]] || ! [[ -d $_path ]]; then
return return
fi fi
while IFS= read -r -d '' _i; do while IFS= read -r -d '' _i; do
_attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null) _attr=$(getfattr -m "security.selinux" "$_i" 2> /dev/null)
if [[ -z "$_attr" ]]; then if [[ -z $_attr ]]; then
restorecon "$_i"; restorecon "$_i"
fi fi
done < <(find "$_path" -print0) done < <(find "$_path" -print0)
} }
@ -916,7 +917,7 @@ check_fence_kdump_config()
nodes=$(kdump_get_conf_val "fence_kdump_nodes") nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in $nodes; do for node in $nodes; do
if [[ "$node" = "$hostname" ]]; then if [[ $node == "$hostname" ]]; then
derror "Option fence_kdump_nodes cannot contain $hostname" derror "Option fence_kdump_nodes cannot contain $hostname"
return 1 return 1
fi fi
@ -972,25 +973,26 @@ check_failure_action_config()
default_option=$(kdump_get_conf_val default) default_option=$(kdump_get_conf_val default)
failure_action=$(kdump_get_conf_val failure_action) 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 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" derror "Cannot specify 'failure_action' and 'default' option together"
return 1 return 1
fi fi
if [[ -n "$default_option" ]]; then if [[ -n $default_option ]]; then
option="default" option="default"
failure_action="$default_option" failure_action="$default_option"
fi fi
case "$failure_action" in case "$failure_action" in
reboot|halt|poweroff|shell|dump_to_rootfs) reboot | halt | poweroff | shell | dump_to_rootfs)
return 0 return 0
;; ;;
*) *)
dinfo $"Usage kdump.conf: $option {reboot|halt|poweroff|shell|dump_to_rootfs}" dinfo $"Usage kdump.conf: $option {reboot|halt|poweroff|shell|dump_to_rootfs}"
return 1 return 1
;;
esac esac
} }
@ -999,16 +1001,17 @@ check_final_action_config()
local final_action local final_action
final_action=$(kdump_get_conf_val final_action) final_action=$(kdump_get_conf_val final_action)
if [[ -z "$final_action" ]]; then if [[ -z $final_action ]]; then
return 0 return 0
else else
case "$final_action" in case "$final_action" in
reboot|halt|poweroff) reboot | halt | poweroff)
return 0 return 0
;; ;;
*) *)
dinfo $"Usage kdump.conf: final_action {reboot|halt|poweroff}" dinfo $"Usage kdump.conf: final_action {reboot|halt|poweroff}"
return 1 return 1
;;
esac esac
fi fi
} }
@ -1025,7 +1028,7 @@ start()
return 1 return 1
fi 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 selinux_relabel
fi fi
@ -1156,7 +1159,8 @@ stop()
return 0 return 0
} }
rebuild() { rebuild()
{
check_config || return 1 check_config || return 1
if check_ssh_config; then if check_ssh_config; then
@ -1172,33 +1176,34 @@ rebuild() {
return $? return $?
} }
do_estimate() { do_estimate()
{
local kdump_mods local kdump_mods
local -A large_mods local -A large_mods
local baseline local baseline
local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommended_size 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 setup_initrd
if [[ ! -f "$TARGET_INITRD" ]]; then if [[ ! -f $TARGET_INITRD ]]; then
derror "kdumpctl estimate: kdump initramfs is not built yet." derror "kdumpctl estimate: kdump initramfs is not built yet."
exit 1 exit 1
fi fi
kdump_mods="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')" kdump_mods="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')"
baseline=$(kdump_get_arch_recommend_size) baseline=$(kdump_get_arch_recommend_size)
if [[ "${baseline: -1}" == "M" ]]; then if [[ ${baseline: -1} == "M" ]]; then
baseline=${baseline%M} baseline=${baseline%M}
elif [[ "${baseline: -1}" == "G" ]]; then elif [[ ${baseline: -1} == "G" ]]; then
baseline=$(( ${baseline%G} * 1024 )) baseline=$((${baseline%G} * 1024))
elif [[ "${baseline: -1}" == "T" ]]; then elif [[ ${baseline: -1} == "T" ]]; then
baseline=$(( ${baseline%Y} * 1048576 )) baseline=$((${baseline%Y} * 1048576))
fi fi
# The default pre-reserved crashkernel value # The default pre-reserved crashkernel value
baseline_size=$((baseline * size_mb)) baseline_size=$((baseline * size_mb))
# Current reserved crashkernel size # 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 # A pre-estimated value for userspace usage and kernel
# runtime allocation, 64M should good for most cases # runtime allocation, 64M should good for most cases
runtime_size=$((64 * size_mb)) runtime_size=$((64 * size_mb))
@ -1209,7 +1214,7 @@ do_estimate() {
# Kernel modules static size after loaded # Kernel modules static size after loaded
mod_size=0 mod_size=0
while read -r _name _size _; do while read -r _name _size _; do
if [[ ! " $kdump_mods " == *" $_name "* ]]; then if [[ " $kdump_mods " != *" $_name "* ]]; then
continue continue
fi fi
mod_size=$((mod_size + _size)) mod_size=$((mod_size + _size))
@ -1224,8 +1229,8 @@ do_estimate() {
crypt_size=0 crypt_size=0
for _dev in $(get_all_kdump_crypt_dev); do for _dev in $(get_all_kdump_crypt_dev); do
_crypt_info=$(cryptsetup luksDump "/dev/block/$_dev") _crypt_info=$(cryptsetup luksDump "/dev/block/$_dev")
[[ $(echo "$_crypt_info" | sed -n "s/^Version:\s*\(.*\)/\1/p" ) == "2" ]] || continue [[ $(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 for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n); do
crypt_size=$((crypt_size + _mem * 1024)) crypt_size=$((crypt_size + _mem * 1024))
break break
done done
@ -1246,10 +1251,10 @@ do_estimate() {
echo "Kernel modules size: $((mod_size / size_mb))M" echo "Kernel modules size: $((mod_size / size_mb))M"
echo "Initramfs size: $((initrd_size / size_mb))M" echo "Initramfs size: $((initrd_size / size_mb))M"
echo "Runtime reservation: $((runtime_size / size_mb))M" echo "Runtime reservation: $((runtime_size / size_mb))M"
[[ $crypt_size -ne 0 ]] && \ [[ $crypt_size -ne 0 ]] &&
echo "LUKS required size: $((crypt_size / size_mb))M" echo "LUKS required size: $((crypt_size / size_mb))M"
echo -n "Large modules:" echo -n "Large modules:"
if [[ "${#large_mods[@]}" -eq 0 ]]; then if [[ ${#large_mods[@]} -eq 0 ]]; then
echo " <none>" echo " <none>"
else else
echo "" echo ""
@ -1263,14 +1268,15 @@ do_estimate() {
fi fi
} }
reset_crashkernel() { reset_crashkernel()
{
local kernel=$1 entry crashkernel_default local kernel=$1 entry crashkernel_default
local grub_etc_default="/etc/default/grub" local grub_etc_default="/etc/default/grub"
[[ -z "$kernel" ]] && kernel=$(uname -r) [[ -z $kernel ]] && kernel=$(uname -r)
crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null) 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" derror "$kernel doesn't have a crashkernel.default"
exit 1 exit 1
fi fi
@ -1287,7 +1293,7 @@ reset_crashkernel() {
entry=${entry#\"} entry=${entry#\"}
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" sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$crashkernel_default\2/" "$grub_etc_default"
fi fi
@ -1297,18 +1303,18 @@ reset_crashkernel() {
fi fi
} }
if [[ ! -f "$KDUMP_CONFIG_FILE" ]]; then if [[ ! -f $KDUMP_CONFIG_FILE ]]; then
derror "Error: No kdump config file found!" derror "Error: No kdump config file found!"
exit 1 exit 1
fi fi
main () main()
{ {
# Determine if the dump mode is kdump or fadump # Determine if the dump mode is kdump or fadump
determine_dump_mode determine_dump_mode
case "$1" in case "$1" in
start) start)
if [[ -s /proc/vmcore ]]; then if [[ -s /proc/vmcore ]]; then
save_core save_core
reboot reboot
@ -1316,51 +1322,52 @@ main ()
start start
fi fi
;; ;;
stop) stop)
stop stop
;; ;;
status) status)
EXIT_CODE=0 EXIT_CODE=0
check_current_status check_current_status
case "$?" in case "$?" in
0) 0)
dinfo "Kdump is operational" dinfo "Kdump is operational"
EXIT_CODE=0 EXIT_CODE=0
;; ;;
1) 1)
dinfo "Kdump is not operational" dinfo "Kdump is not operational"
EXIT_CODE=3 EXIT_CODE=3
;; ;;
esac esac
exit $EXIT_CODE exit $EXIT_CODE
;; ;;
reload) reload)
reload reload
;; ;;
restart) restart)
stop stop
start start
;; ;;
rebuild) rebuild)
rebuild rebuild
;; ;;
condrestart) condrestart) ;;
;;
propagate) propagate)
propagate_ssh_key propagate_ssh_key
;; ;;
showmem) showmem)
show_reserved_mem show_reserved_mem
;; ;;
estimate) estimate)
do_estimate do_estimate
;; ;;
reset-crashkernel) reset-crashkernel)
reset_crashkernel "$2" reset_crashkernel "$2"
;; ;;
*) *)
dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}" dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}"
exit 1 exit 1
;;
esac esac
} }
@ -1369,6 +1376,9 @@ single_instance_lock
# To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call main. # 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. # So that fd isn't leaking when main is invoking a subshell.
(exec 9<&-; main "$@") (
exec 9<&-
main "$@"
)
exit $? exit $?

518
mkdumprd
View File

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

View File

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