kdumpctl: improve check_wdt_modified()

Use the logic of dracut 04watchdog/module-setup.sh to check,
then we only need to compare the content of 00-watchdog.conf,
so we can save one operation of lsinitrd.

Signed-off-by: Xunlei Pang <xlpang@redhat.com>
Acked-by: Pratyush Anand <panand@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
Xunlei Pang 2017-05-04 14:56:55 +08:00 committed by Dave Young
parent c63c0a1084
commit 2a5f362521

View File

@ -565,36 +565,58 @@ check_dump_fs_modified()
check_wdt_modified() check_wdt_modified()
{ {
local -A _drivers
local _alldrivers _active _wdtdrv _wdtppath _dir
local wd_old wd_new
is_wdt_mod_omitted is_wdt_mod_omitted
[[ $? -eq 0 ]] && return 0 [[ $? -eq 0 ]] && return 0
[[ -d /sys/class/watchdog/ ]] || return 0 [[ -d /sys/class/watchdog/ ]] || return 0
for dir in /sys/class/watchdog/*; do # Copied logic from dracut 04watchdog/module-setup.sh::installkernel()
[[ -d "$dir" ]] || continue for _dir in /sys/class/watchdog/*; do
[[ -f "$dir/state" ]] || continue [[ -d "$_dir" ]] || continue
wdtdrv=$(< "$dir/device/modalias") [[ -f "$_dir/state" ]] || continue
wdtdrv=$(modinfo $wdtdrv | grep filename | awk -F"kernel/" '{print $2}') _active=$(< "$_dir/state")
active=$(< "$dir/state") [[ "$_active" = "active" ]] || continue
# rebuild when: # device/modalias will return driver of this device
# module for this watchdog is not found and watchdog is active _wdtdrv=$(< "$_dir/device/modalias")
# module for this watchdog is found and watchdog is inactive # There can be more than one module represented by same
lsinitrd $TARGET_INITRD | grep $wdtdrv &> /dev/null # modalias. Currently load all of them.
if [ $? -ne 0 ]; then # TODO: Need to find a way to avoid any unwanted module
[[ "$active" = "active" ]] && return 1 # represented by modalias
else _wdtdrv=$(modprobe --set-version "$kdump_kver" -R $_wdtdrv 2>/dev/null)
[[ "$active" = "inactive" ]] && return 1 if [[ $_wdtdrv ]]; then
for i in $_wdtdrv; do
_drivers[$i]=1
done
fi fi
# however in some cases, we also need to check that if there is
# a specific driver for the parent bus/device. In such cases
# we also need to enable driver for parent bus/device.
_wdtppath=$(readlink -f "$_dir/device")
while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
_wdtppath=$(readlink -f "$_wdtppath/..")
[[ -f "$_wdtppath/modalias" ]] || continue
_wdtdrv=$(< "$_wdtppath/modalias")
_wdtdrv=$(modprobe --set-version "$kdump_kver" -R $_wdtdrv 2>/dev/null)
if [[ $_wdtdrv ]]; then
for i in $_wdtdrv; do
_drivers[$i]=1
done
fi
done
done done
# check if watchdog kernel module unloaded. # ensure that watchdog module is loaded as early as possible
loaded_mods=$(lsinitrd $TARGET_INITRD -f etc/cmdline.d/00-watchdog.conf) _alldrivers="${!_drivers[*]}"
[[ -n $loaded_mods ]] && loaded_mods=$(echo $loaded_mods | awk -F"rd.driver.pre=" '{print $2}' | sed "s/,/ /g") [[ $_alldrivers ]] && wd_new="rd.driver.pre=${_alldrivers// /,}"
for mod in $loaded_mods ; do wd_old=$(lsinitrd $TARGET_INITRD -f etc/cmdline.d/00-watchdog.conf)
lsmod | grep $mod &> /dev/null
[[ $? != 0 ]] && return 1
done
return 0 [[ "$wd_old" = "$wd_new" ]] && return 0
return 1
} }
# returns 0 if system is not modified # returns 0 if system is not modified