Blame 0037-watchdog-install-module-for-active-watchdog.patch

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