|
|
9abf8c |
From 4e1d7a423253d4e3476b003fc2e17c2ac44bd8ca Mon Sep 17 00:00:00 2001
|
|
|
9abf8c |
From: Kairui Song <kasong@redhat.com>
|
|
|
9abf8c |
Date: Thu, 10 Sep 2020 02:18:02 +0800
|
|
|
9abf8c |
Subject: [PATCH] 04watchdog: split the watchdog module install
|
|
|
9abf8c |
|
|
|
9abf8c |
In some cases, user only want to include the watchdog module, not the
|
|
|
9abf8c |
wdctl or any other userspace helper. For example, systemd have a
|
|
|
9abf8c |
RebootWatchdogSec option that use watchdog to prevent reboot hangs. And
|
|
|
9abf8c |
it can help prevent machines hangs when reboot directly within the
|
|
|
9abf8c |
initramfs stage. So split the module installation to a standlone module.
|
|
|
9abf8c |
|
|
|
9abf8c |
Also when watchdog-module get included, install driver for all loaded
|
|
|
9abf8c |
watchdog instaed of only install driver for active watchdog. Both
|
|
|
9abf8c |
watchdog and watchdog-module return 255 in check(), so it's enabled only
|
|
|
9abf8c |
when manually included, the watchdog may get configured/activated later.
|
|
|
9abf8c |
|
|
|
9abf8c |
Signed-off-by: Kairui Song <kasong@redhat.com>
|
|
|
9abf8c |
(cherry picked from commit 39d90012a652fa4d9d2534d0168ddad8cacec248)
|
|
|
9abf8c |
|
|
|
9abf8c |
Resolves: #1890039
|
|
|
9abf8c |
---
|
|
|
9abf8c |
modules.d/04watchdog-modules/module-setup.sh | 61 ++++++++++++++++++++++++++++
|
|
|
9abf8c |
modules.d/04watchdog/module-setup.sh | 50 +----------------------
|
|
|
9abf8c |
2 files changed, 63 insertions(+), 48 deletions(-)
|
|
|
9abf8c |
|
|
|
9abf8c |
diff --git a/modules.d/04watchdog-modules/module-setup.sh b/modules.d/04watchdog-modules/module-setup.sh
|
|
|
9abf8c |
new file mode 100755
|
|
|
9abf8c |
index 00000000..5fbd769b
|
|
|
9abf8c |
--- /dev/null
|
|
|
9abf8c |
+++ b/modules.d/04watchdog-modules/module-setup.sh
|
|
|
9abf8c |
@@ -0,0 +1,61 @@
|
|
|
9abf8c |
+#!/bin/bash
|
|
|
9abf8c |
+
|
|
|
9abf8c |
+# called by dracut
|
|
|
9abf8c |
+check() {
|
|
|
9abf8c |
+ return 255
|
|
|
9abf8c |
+}
|
|
|
9abf8c |
+
|
|
|
9abf8c |
+# called by dracut
|
|
|
9abf8c |
+depends() {
|
|
|
9abf8c |
+ return 0
|
|
|
9abf8c |
+}
|
|
|
9abf8c |
+
|
|
|
9abf8c |
+# called by dracut
|
|
|
9abf8c |
+install() {
|
|
|
9abf8c |
+ return 0
|
|
|
9abf8c |
+}
|
|
|
9abf8c |
+
|
|
|
9abf8c |
+installkernel() {
|
|
|
9abf8c |
+ local -A _drivers
|
|
|
9abf8c |
+ local _alldrivers _wdtdrv _wdtppath _dir
|
|
|
9abf8c |
+ [[ -d /sys/class/watchdog/ ]] || return
|
|
|
9abf8c |
+ for _dir in /sys/class/watchdog/*; do
|
|
|
9abf8c |
+ [[ -d "$_dir" ]] || continue
|
|
|
9abf8c |
+ [[ -f "$_dir/state" ]] || continue
|
|
|
9abf8c |
+ # device/modalias will return driver of this device
|
|
|
9abf8c |
+ _wdtdrv=$(< "$_dir/device/modalias")
|
|
|
9abf8c |
+ # There can be more than one module represented by same
|
|
|
9abf8c |
+ # modalias. Currently load all of them.
|
|
|
9abf8c |
+ # TODO: Need to find a way to avoid any unwanted module
|
|
|
9abf8c |
+ # represented by modalias
|
|
|
9abf8c |
+ _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
|
|
|
9abf8c |
+ if [[ $_wdtdrv ]]; then
|
|
|
9abf8c |
+ instmods $_wdtdrv
|
|
|
9abf8c |
+ for i in $_wdtdrv; do
|
|
|
9abf8c |
+ _drivers[$i]=1
|
|
|
9abf8c |
+ done
|
|
|
9abf8c |
+ fi
|
|
|
9abf8c |
+ # however in some cases, we also need to check that if there is
|
|
|
9abf8c |
+ # a specific driver for the parent bus/device. In such cases
|
|
|
9abf8c |
+ # we also need to enable driver for parent bus/device.
|
|
|
9abf8c |
+ _wdtppath=$(readlink -f "$_dir/device")
|
|
|
9abf8c |
+ while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
|
|
|
9abf8c |
+ _wdtppath=$(readlink -f "$_wdtppath/..")
|
|
|
9abf8c |
+ [[ -f "$_wdtppath/modalias" ]] || continue
|
|
|
9abf8c |
+
|
|
|
9abf8c |
+ _wdtdrv=$(< "$_wdtppath/modalias")
|
|
|
9abf8c |
+ _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
|
|
|
9abf8c |
+ if [[ $_wdtdrv ]]; then
|
|
|
9abf8c |
+ instmods $_wdtdrv
|
|
|
9abf8c |
+ for i in $_wdtdrv; do
|
|
|
9abf8c |
+ _drivers[$i]=1
|
|
|
9abf8c |
+ done
|
|
|
9abf8c |
+ fi
|
|
|
9abf8c |
+ done
|
|
|
9abf8c |
+ done
|
|
|
9abf8c |
+ # ensure that watchdog module is loaded as early as possible
|
|
|
9abf8c |
+ _alldrivers="${!_drivers[*]}"
|
|
|
9abf8c |
+ [[ $_alldrivers ]] && echo "rd.driver.pre=${_alldrivers// /,}" > ${initdir}/etc/cmdline.d/00-watchdog.conf
|
|
|
9abf8c |
+
|
|
|
9abf8c |
+ return 0
|
|
|
9abf8c |
+}
|
|
|
9abf8c |
diff --git a/modules.d/04watchdog/module-setup.sh b/modules.d/04watchdog/module-setup.sh
|
|
|
9abf8c |
index 7566d651..15bcd897 100755
|
|
|
9abf8c |
--- a/modules.d/04watchdog/module-setup.sh
|
|
|
9abf8c |
+++ b/modules.d/04watchdog/module-setup.sh
|
|
|
9abf8c |
@@ -7,7 +7,7 @@ check() {
|
|
|
9abf8c |
|
|
|
9abf8c |
# called by dracut
|
|
|
9abf8c |
depends() {
|
|
|
9abf8c |
- return 0
|
|
|
9abf8c |
+ return "watchdog-modules"
|
|
|
9abf8c |
}
|
|
|
9abf8c |
|
|
|
9abf8c |
# called by dracut
|
|
|
9abf8c |
@@ -27,53 +27,7 @@ install() {
|
|
|
9abf8c |
inst_hook cleanup 00 "$moddir/watchdog.sh"
|
|
|
9abf8c |
inst_hook cleanup 99 "$moddir/watchdog.sh"
|
|
|
9abf8c |
fi
|
|
|
9abf8c |
+
|
|
|
9abf8c |
inst_hook emergency 02 "$moddir/watchdog-stop.sh"
|
|
|
9abf8c |
inst_multiple -o wdctl
|
|
|
9abf8c |
}
|
|
|
9abf8c |
-
|
|
|
9abf8c |
-installkernel() {
|
|
|
9abf8c |
- local -A _drivers
|
|
|
9abf8c |
- local _alldrivers _active _wdtdrv _wdtppath _dir
|
|
|
9abf8c |
- [[ -d /sys/class/watchdog/ ]] || return
|
|
|
9abf8c |
- for _dir in /sys/class/watchdog/*; do
|
|
|
9abf8c |
- [[ -d "$_dir" ]] || continue
|
|
|
9abf8c |
- [[ -f "$_dir/state" ]] || continue
|
|
|
9abf8c |
- _active=$(< "$_dir/state")
|
|
|
9abf8c |
- ! [[ $hostonly ]] || [[ "$_active" = "active" ]] || continue
|
|
|
9abf8c |
- # device/modalias will return driver of this device
|
|
|
9abf8c |
- _wdtdrv=$(< "$_dir/device/modalias")
|
|
|
9abf8c |
- # There can be more than one module represented by same
|
|
|
9abf8c |
- # modalias. Currently load all of them.
|
|
|
9abf8c |
- # TODO: Need to find a way to avoid any unwanted module
|
|
|
9abf8c |
- # represented by modalias
|
|
|
9abf8c |
- _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
|
|
|
9abf8c |
- if [[ $_wdtdrv ]]; then
|
|
|
9abf8c |
- instmods $_wdtdrv
|
|
|
9abf8c |
- for i in $_wdtdrv; do
|
|
|
9abf8c |
- _drivers[$i]=1
|
|
|
9abf8c |
- done
|
|
|
9abf8c |
- fi
|
|
|
9abf8c |
- # however in some cases, we also need to check that if there is
|
|
|
9abf8c |
- # a specific driver for the parent bus/device. In such cases
|
|
|
9abf8c |
- # we also need to enable driver for parent bus/device.
|
|
|
9abf8c |
- _wdtppath=$(readlink -f "$_dir/device")
|
|
|
9abf8c |
- while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do
|
|
|
9abf8c |
- _wdtppath=$(readlink -f "$_wdtppath/..")
|
|
|
9abf8c |
- [[ -f "$_wdtppath/modalias" ]] || continue
|
|
|
9abf8c |
-
|
|
|
9abf8c |
- _wdtdrv=$(< "$_wdtppath/modalias")
|
|
|
9abf8c |
- _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null)
|
|
|
9abf8c |
- if [[ $_wdtdrv ]]; then
|
|
|
9abf8c |
- instmods $_wdtdrv
|
|
|
9abf8c |
- for i in $_wdtdrv; do
|
|
|
9abf8c |
- _drivers[$i]=1
|
|
|
9abf8c |
- done
|
|
|
9abf8c |
- fi
|
|
|
9abf8c |
- done
|
|
|
9abf8c |
- done
|
|
|
9abf8c |
- # ensure that watchdog module is loaded as early as possible
|
|
|
9abf8c |
- _alldrivers="${!_drivers[*]}"
|
|
|
9abf8c |
- [[ $_alldrivers ]] && echo "rd.driver.pre=${_alldrivers// /,}" > ${initdir}/etc/cmdline.d/00-watchdog.conf
|
|
|
9abf8c |
-
|
|
|
9abf8c |
- return 0
|
|
|
9abf8c |
-}
|
|
|
9abf8c |
|