Blame SOURCES/0439-watchdog-module-setup.sh-rewrite.patch

712866
From 4c83fd10ab2a43272eab59719486064085beb2df Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Fri, 15 Apr 2016 11:27:20 +0200
712866
Subject: [PATCH] watchdog/module-setup.sh: rewrite
712866
712866
- use local variables with _
712866
- use associative array for the kernel modules
712866
- install emergency hook even in the systemd case
712866
- follow device path until /sys is reached
712866
- set kernel version for modprobe checking
712866
---
712866
 modules.d/04watchdog/module-setup.sh | 92 ++++++++++++++++++++----------------
712866
 1 file changed, 51 insertions(+), 41 deletions(-)
712866
712866
diff --git a/modules.d/04watchdog/module-setup.sh b/modules.d/04watchdog/module-setup.sh
5c6c2a
index 6b35f9f5..31102f4e 100755
712866
--- a/modules.d/04watchdog/module-setup.sh
712866
+++ b/modules.d/04watchdog/module-setup.sh
712866
@@ -13,54 +13,64 @@ depends() {
712866
 install() {
712866
     # Do not add watchdog hooks if systemd module is included
712866
     # In that case, systemd will manage watchdog kick
712866
-    if dracut_module_included "systemd"; then
712866
-	    return
712866
+    if ! dracut_module_included "systemd"; then
712866
+        inst_hook cmdline   00 "$moddir/watchdog.sh"
712866
+        inst_hook cmdline   50 "$moddir/watchdog.sh"
712866
+        inst_hook pre-trigger 00 "$moddir/watchdog.sh"
712866
+        inst_hook initqueue 00 "$moddir/watchdog.sh"
712866
+        inst_hook mount     00 "$moddir/watchdog.sh"
712866
+        inst_hook mount     50 "$moddir/watchdog.sh"
712866
+        inst_hook mount     99 "$moddir/watchdog.sh"
712866
+        inst_hook pre-pivot 00 "$moddir/watchdog.sh"
712866
+        inst_hook pre-pivot 99 "$moddir/watchdog.sh"
712866
+        inst_hook cleanup   00 "$moddir/watchdog.sh"
712866
+        inst_hook cleanup   99 "$moddir/watchdog.sh"
712866
     fi
712866
-    inst_hook cmdline   00 "$moddir/watchdog.sh"
712866
-    inst_hook cmdline   50 "$moddir/watchdog.sh"
712866
-    inst_hook pre-trigger 00 "$moddir/watchdog.sh"
712866
-    inst_hook initqueue 00 "$moddir/watchdog.sh"
712866
-    inst_hook mount     00 "$moddir/watchdog.sh"
712866
-    inst_hook mount     50 "$moddir/watchdog.sh"
712866
-    inst_hook mount     99 "$moddir/watchdog.sh"
712866
-    inst_hook pre-pivot 00 "$moddir/watchdog.sh"
712866
-    inst_hook pre-pivot 99 "$moddir/watchdog.sh"
712866
-    inst_hook cleanup   00 "$moddir/watchdog.sh"
712866
-    inst_hook cleanup   99 "$moddir/watchdog.sh"
712866
     inst_hook emergency 02 "$moddir/watchdog-stop.sh"
712866
     inst_multiple -o wdctl
712866
 }
712866
 
712866
 installkernel() {
712866
+    local -A _drivers
712866
+    local _alldrivers _active _wdtdrv _wdtppath _dir
712866
     [[ -d /sys/class/watchdog/ ]] || return
712866
-    wdtcmdline=""
712866
-    for dir in /sys/class/watchdog/*; do
712866
-	    [[ -d "$dir" ]] || continue
712866
-	    [[ -f "$dir/state" ]] || continue
712866
-	    active=$(< "$dir/state")
712866
-	    ! [[ $hostonly ]] || [[ "$active" =  "active" ]] || continue
712866
-	    # device/modalias will return driver of this device
712866
-	    wdtdrv=$(< "$dir/device/modalias")
712866
-	    # There can be more than one module represented by same
712866
-	    # modalias. Currently load all of them.
712866
-	    # TODO: Need to find a way to avoid any unwanted module
712866
-	    # represented by modalias
712866
-	    wdtdrv=$(modprobe -R $wdtdrv)
712866
-	    instmods $wdtdrv
712866
-	    wdtcmdline="$wdtcmdline$(echo $wdtdrv | tr " " ","),"
712866
-	    # however in some cases, we also need to check that if there is
712866
-	    # a specific driver for the parent bus/device.  In such cases
712866
-	    # we also need to enable driver for parent bus/device.
712866
-	    wdtppath=$(readlink -f "$dir/device/..")
712866
-	    while [ -f "$wdtppath/modalias" ]
712866
-	    do
712866
-		    wdtpdrv=$(< "$wdtppath/modalias")
712866
-		    wdtpdrv=$(modprobe -R $wdtpdrv)
712866
-		    instmods $wdtpdrv
712866
-		    wdtcmdline="$wdtcmdline$(echo $wdtpdrv | tr " " ","),"
712866
-		    wdtppath=$(readlink -f "$wdtppath/..")
712866
-	    done
712866
+    for _dir in /sys/class/watchdog/*; do
712866
+        [[ -d "$_dir" ]] || continue
712866
+        [[ -f "$_dir/state" ]] || continue
712866
+        _active=$(< "$_dir/state")
712866
+        ! [[ $hostonly ]] || [[ "$_active" =  "active" ]] || continue
712866
+        # device/modalias will return driver of this device
712866
+        _wdtdrv=$(< "$_dir/device/modalias")
712866
+        # There can be more than one module represented by same
712866
+        # modalias. Currently load all of them.
712866
+        # TODO: Need to find a way to avoid any unwanted module
712866
+        # represented by modalias
712866
+        _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
712866
+        if [[ $_wdtdrv ]]; then
712866
+            instmods $_wdtdrv
712866
+            for i in $_wdtdrv; do
712866
+                _drivers[$i]=1
712866
+            done
712866
+        fi
712866
+        # however in some cases, we also need to check that if there is
712866
+        # a specific driver for the parent bus/device.  In such cases
712866
+        # we also need to enable driver for parent bus/device.
712866
+        _wdtppath=$(readlink -f "$_dir/device/..")
712866
+        while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
712866
+            _wdtppath=$(readlink -f "$_wdtppath/..")
712866
+            [[ -f "$_wdtppath/modalias" ]] || continue
712866
+
712866
+            _wdtdrv=$(< "$_wdtppath/modalias")
712866
+            _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
712866
+            if [[ $_wdtdrv ]]; then
712866
+                instmods $_wdtdrv
712866
+                for i in $_wdtdrv; do
712866
+                    _drivers[$i]=1
712866
+                done
712866
+            fi
712866
+        done
712866
     done
712866
     # ensure that watchdog module is loaded as early as possible
712866
-    [[ $wdtcmdline = "" ]] || echo "rd.driver.pre=$wdtcmdline" > ${initdir}/etc/cmdline.d/00-watchdog.conf
712866
+    _alldrivers="${!_drivers[*]}"
712866
+    [[ $_alldrivers ]] && echo "rd.driver.pre=${_alldrivers// /,}" > ${initdir}/etc/cmdline.d/00-watchdog.conf
712866
 }