Blame SOURCES/0437-watchdog-install-module-for-active-watchdog.patch

a0a3b4
From 0be17528e527c3e5081fc7e03ec51bb17d9b08cc Mon Sep 17 00:00:00 2001
a0a3b4
From: Pratyush Anand <panand@redhat.com>
a0a3b4
Date: Wed, 16 Mar 2016 09:09:10 +0530
a0a3b4
Subject: [PATCH] watchdog: install module for active watchdog
a0a3b4
a0a3b4
Recently following patches have been added in upstream Linux kernel, which
a0a3b4
(1) fixes parent of watchdog_device so that
a0a3b4
/sys/class/watchdog/watchdogn/device is populated. (2) adds some sysfs
a0a3b4
device attributes so that different watchdog status can be read.
a0a3b4
a0a3b4
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6551881c86c791237a3bebf11eb3bd70b60ea782
a0a3b4
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=906d7a5cfeda508e7361f021605579a00cd82815
a0a3b4
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=33b711269ade3f6bc9d9d15e4343e6fa922d999b
a0a3b4
a0a3b4
With the above support, now we can find out whether a watchdog is active or
a0a3b4
not. We can also find out the driver/module responsible for that watchdog
a0a3b4
device.
a0a3b4
a0a3b4
Proposed patch uses above support and then adds module of active watchdog
a0a3b4
in initramfs generated by dracut for hostonly mode. Kernel module for
a0a3b4
inactive watchdog will be added as well for none hostonly mode.
a0a3b4
a0a3b4
When an user does not want to add kernel module, then one should exclude
a0a3b4
complete dracut watchdog module with --omit.
a0a3b4
a0a3b4
Testing:
a0a3b4
-- When watchdog is active watchdog modules were added
a0a3b4
	# cat /sys/class/watchdog/watchdog0/identity
a0a3b4
	iTCO_wdt
a0a3b4
	# cat /sys/class/watchdog/watchdog0/state
a0a3b4
	active
a0a3b4
	# dracut --hostonly initramfs-test.img -a watchdog
a0a3b4
	# lsinitrd initramfs-test.img | grep iTCO
a0a3b4
	-rw-r--r--   1 root     root         9100 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_vendor_support.ko
a0a3b4
	-rw-r--r--   1 root     root        19252 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_wdt.ko
a0a3b4
a0a3b4
-- When watchdog is inactive then watchdog modules were not added
a0a3b4
	# cat /sys/class/watchdog/watchdog0/state
a0a3b4
	inactive
a0a3b4
	# dracut --hostonly initramfs-test.img -a watchdog
a0a3b4
	# lsinitrd initramfs-test.img | grep iTCO
a0a3b4
a0a3b4
-- When watchdog is inactive, but no hostonly mode, watchdog modules were added
a0a3b4
	# cat /sys/class/watchdog/watchdog0/state
a0a3b4
	inactive
a0a3b4
	# dracut --no-hostonly initramfs-test.img -a watchdog
a0a3b4
	# lsinitrd initramfs-test.img | grep iTCO
a0a3b4
	-rw-r--r--   1 root     root         9100 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_vendor_support.ko
a0a3b4
	-rw-r--r--   1 root     root        19252 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_wdt.ko
a0a3b4
a0a3b4
Signed-off-by: Pratyush Anand <panand@redhat.com>
a0a3b4
Cc: Dave Young <dyoung@redhat.com>
a0a3b4
Cc: Don Zickus <dzickus@redhat.com>
a0a3b4
Cc: Harald Hoyer <harald@redhat.com>
a0a3b4
---
a0a3b4
 modules.d/04watchdog/module-setup.sh | 28 ++++++++++++++++++++++++++++
a0a3b4
 1 file changed, 28 insertions(+)
a0a3b4
a0a3b4
diff --git a/modules.d/04watchdog/module-setup.sh b/modules.d/04watchdog/module-setup.sh
a0a3b4
index 7e32210..4680936 100755
a0a3b4
--- a/modules.d/04watchdog/module-setup.sh
a0a3b4
+++ b/modules.d/04watchdog/module-setup.sh
a0a3b4
@@ -31,3 +31,31 @@ install() {
a0a3b4
     inst_multiple -o wdctl
a0a3b4
 }
a0a3b4
 
a0a3b4
+installkernel() {
a0a3b4
+    [[ -d /sys/class/watchdog/ ]] || return
a0a3b4
+    for dir in /sys/class/watchdog/*; do
a0a3b4
+	    [[ -d "$dir" ]] || continue
a0a3b4
+	    [[ -f "$dir/state" ]] || continue
a0a3b4
+	    active=$(< "$dir/state")
a0a3b4
+	    ! [[ $hostonly ]] || [[ "$active" =  "active" ]] || continue
a0a3b4
+	    # device/modalias will return driver of this device
a0a3b4
+	    wdtdrv=$(< "$dir/device/modalias")
a0a3b4
+	    # There can be more than one module represented by same
a0a3b4
+	    # modalias. Currently load all of them.
a0a3b4
+	    # TODO: Need to find a way to avoid any unwanted module
a0a3b4
+	    # represented by modalias
a0a3b4
+	    wdtdrv=$(modprobe -R $wdtdrv)
a0a3b4
+	    instmods $wdtdrv
a0a3b4
+	    # however in some cases, we also need to check that if there is
a0a3b4
+	    # a specific driver for the parent bus/device.  In such cases
a0a3b4
+	    # we also need to enable driver for parent bus/device.
a0a3b4
+	    wdtppath=$(readlink -f "$dir/device/..")
a0a3b4
+	    while [ -f "$wdtppath/modalias" ]
a0a3b4
+	    do
a0a3b4
+		    wdtpdrv=$(< "$wdtppath/modalias")
a0a3b4
+		    wdtpdrv=$(modprobe -R $wdtpdrv)
a0a3b4
+		    instmods $wdtpdrv
a0a3b4
+		    wdtppath=$(readlink -f "$wdtppath/..")
a0a3b4
+	    done
a0a3b4
+    done
a0a3b4
+}