[PATCH RFC dracut] watchdog: install module for active watchdog

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Recently following patches have been added in upstream Linux kernel, which
(1) fixes parent of watchdog_device so that
/sys/class/watchdog/watchdogn/device is populated. (2) adds some sysfs
device attributes so that different watchdog status can be read.

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6551881c86c791237a3bebf11eb3bd70b60ea782
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=906d7a5cfeda508e7361f021605579a00cd82815
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=33b711269ade3f6bc9d9d15e4343e6fa922d999b

With the above support, now we can find out whether a watchdog is active or
not. If it is active, we can also find out the driver/module responsible
for that watchdog device.

Proposed patch uses above support and then adds module of active watchdog
in initramfs generated by dracut for --hostonly mode.

If an user does not want to add this support then he/she may pass --nowdt
with dracut command.

Testing:
-- When watchdog is active and --nowdt was passed, watchdog modules were not
added
	# cat /sys/class/watchdog/watchdog0/identity
	iTCO_wdt
	# cat /sys/class/watchdog/watchdog0/state
	active
	# dracut --hostonly --nowdt --hostonly-cmdline initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	# lsinitrd -f usr/lib/dracut/active-watchdogs  initramfs-test.img

-- When watchdog is active and --nowdt was not passed, watchdog modules were
added

	# dracut --hostonly --hostonly-cmdline initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	-rw-r--r--   1 root     root         9100 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_vendor_support.ko
	-rw-r--r--   1 root     root        19252 Feb 24 09:19 usr/lib/modules/.../kernel/drivers/watchdog/iTCO_wdt.ko
	# lsinitrd -f usr/lib/dracut/active-watchdogs  initramfs-test.img
	iTCO_wdt

-- When watchdog is inactive then watchdog modules were not added
	# cat /sys/class/watchdog/watchdog0/state
	inactive
	# dracut --hostonly --nowdt --hostonly-cmdline initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	# lsinitrd -f usr/lib/dracut/active-watchdogs  initramfs-test.img

	# dracut --hostonly --hostonly-cmdline initramfs-test.img -a watchdog
	# lsinitrd initramfs-test.img | grep iTCO
	# lsinitrd -f usr/lib/dracut/active-watchdogs  initramfs-test.img

Signed-off-by: Pratyush Anand <panand@xxxxxxxxxx>
Cc: Dave Young <dyoung@xxxxxxxxxx>
Cc: Don Zickus <dzickus@xxxxxxxxxx>
Cc: Harald Hoyer <harald@xxxxxxxxxx>
---
Hi Harald,

I am not subscribed to initramfs mailing list, so kindly keep me in CC for
replies.

~Pratyush

 dracut-bash-completion.sh            |  2 +-
 dracut.8.asc                         |  3 +++
 dracut.conf.5.asc                    |  3 +++
 dracut.sh                            |  6 +++++-
 modules.d/04watchdog/module-setup.sh | 37 ++++++++++++++++++++++++++++++++++++
 5 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/dracut-bash-completion.sh b/dracut-bash-completion.sh
index 09330a673230..3d6519a71cd4 100644
--- a/dracut-bash-completion.sh
+++ b/dracut-bash-completion.sh
@@ -40,7 +40,7 @@ _dracut() {
                               --fwdir --libdirs --fscks --add-fstab --mount --device --nofscks
                               --kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix
                               --kernel-cmdline --sshkey --persistent-policy --install-optional
-                              --loginstall --uefi-stub --kernel-image
+                              --loginstall --uefi-stub --kernel-image --nowdt
                               '
         )
 
diff --git a/dracut.8.asc b/dracut.8.asc
index aee84c45a1c5..65519154af6d 100644
--- a/dracut.8.asc
+++ b/dracut.8.asc
@@ -237,6 +237,9 @@ example:
 **--nofscks**::
     inhibit installation of any fsck tools
 
+**--nowdt**::
+    inhibit installation of module for any active watchdog
+
 **--strip**::
     strip binaries in the initramfs (default)
 
diff --git a/dracut.conf.5.asc b/dracut.conf.5.asc
index 0460d4fff8d4..755b90bbbe14 100644
--- a/dracut.conf.5.asc
+++ b/dracut.conf.5.asc
@@ -139,6 +139,9 @@ provide a valid _/etc/fstab_.
 *nofscks=*"__{yes|no}__"::
     If specified, inhibit installation of any fsck tools.
 
+*nowdt=*"__{yes|no}__"::
+    If specified, inhibit installation of module for any active watchdog.
+
 *ro_mnt=*"__{yes|no}__"::
     Mount _/_ and _/usr_ read-only by default.
 
diff --git a/dracut.sh b/dracut.sh
index 98dbe0bcc259..6acd48e9ced2 100755
--- a/dracut.sh
+++ b/dracut.sh
@@ -120,6 +120,7 @@ Creates initial ramdisk images for preloading modules
   --nolvmconf           Do not include local /etc/lvm/lvm.conf
   --fscks [LIST]        Add a space-separated list of fsck helpers.
   --nofscks             Inhibit installation of any fsck helpers.
+  --nowdt		Inhibit installation of module for any active watchdog
   --ro-mnt              Mount / and /usr read-only by default.
   -h, --help            This message
   --debug               Output debug information of the build process
@@ -304,6 +305,7 @@ rearrange_params()
         --long device: \
         --long add-device: \
         --long nofscks: \
+        --long nowdt: \
         --long ro-mnt \
         --long kmoddir: \
         --long conf: \
@@ -478,6 +480,7 @@ while :; do
         --add-device|--device) add_device_l+=("$2");          PARMS_TO_STORE+=" '$2'"; shift;;
         --kernel-cmdline) kernel_cmdline_l+=("$2");           PARMS_TO_STORE+=" '$2'"; shift;;
         --nofscks)     nofscks_l="yes";;
+        --nowdt)       nowdt_l="yes";;
         --ro-mnt)      ro_mnt_l="yes";;
         -k|--kmoddir)  drivers_dir_l="$2";             PARMS_TO_STORE+=" '$2'"; shift;;
         -c|--conf)     conffile="$2";                  PARMS_TO_STORE+=" '$2'"; shift;;
@@ -740,6 +743,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
 [[ $compress_l ]] && compress=$compress_l
 [[ $show_modules_l ]] && show_modules=$show_modules_l
 [[ $nofscks_l ]] && nofscks="yes"
+[[ $nowdt_l ]] && nowdt="yes"
 [[ $ro_mnt_l ]] && ro_mnt="yes"
 [[ $early_microcode_l ]] && early_microcode=$early_microcode_l
 [[ $early_microcode ]] || early_microcode=no
@@ -1276,7 +1280,7 @@ export initdir dracutbasedir \
     mods_to_load \
     fw_dir drivers_dir debug no_kernel kernel_only \
     omit_drivers mdadmconf lvmconf root_dev \
-    use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
+    use_fstab fstab_lines libdirs fscks nofscks nowdt ro_mnt \
     stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
     debug host_fs_types host_devs swap_devs sshkey add_fstab \
     DRACUT_VERSION udevdir prefix filesystems drivers \
diff --git a/modules.d/04watchdog/module-setup.sh b/modules.d/04watchdog/module-setup.sh
index 576c589c198d..b6443dd60c94 100755
--- a/modules.d/04watchdog/module-setup.sh
+++ b/modules.d/04watchdog/module-setup.sh
@@ -27,3 +27,40 @@ install() {
     inst_multiple -o wdctl
 }
 
+installkernel() {
+    if [[ $hostonly ]] && [[ $nowdt != "yes" ]]; then
+	wdtcls=/sys/class/watchdog
+	cd $wdtcls
+	for dir in */; do
+		cd $dir
+		active=`[ -f state ] && cat state`
+		if [ "$active" =  "active" ]; then
+			# applications like kdump need to know that
+			# which watchdog modules have been added
+			# into initramfs
+			echo `cat identity` >> "$initdir/lib/dracut/active-watchdogs"
+			# device/modalias will return driver of this device
+			wdtdrv=`cat device/modalias`
+			# There can be more than one module represented by same
+			# modalias. Currently load all of them.
+			# TODO: Need to find a way to avoid any unwanted module
+			# represented by modalias
+			wdtdrv=`modprobe -R $wdtdrv | tr "\n" "," | sed 's/.$//'`
+			instmods $wdtdrv
+			# however in some cases, we also need to check that if
+			# there is a specific driver for the parent bus/device.
+			# In such cases we also need to enable driver for parent
+			# bus/device.
+			wdtppath="device/..";
+			while [ -f "$wdtppath/modalias" ]
+			do
+				wdtpdrv=`cat $wdtppath/modalias`
+				wdtpdrv=`modprobe -R $wdtpdrv | tr "\n" "," | sed 's/.$//'`
+				instmods $wdtpdrv
+				wdtppath="$wdtppath/.."
+			done
+		fi
+		cd ..
+	done
+    fi
+}
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe initramfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux