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

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