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

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