Blame 0060-watchdog-module-setup.sh-rewrite.patch

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