All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harald Hoyer <harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Pratyush Anand <panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	dzickus-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH V2 dracut 2/2] watchdog: install module for active watchdog
Date: Mon, 7 Mar 2016 14:49:08 +0100	[thread overview]
Message-ID: <56DD86D4.8040800@redhat.com> (raw)
In-Reply-To: <0d7adcfdf08f4eb753a0e65e7e65d5fe0ef22f70.1456919929.git.panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

On 02.03.2016 13:06, Pratyush Anand wrote:
> 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. 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.
> 
> It is reasonable to always add kernel watchdog module if dracut watchdog
> module has been added. When an user does not want to add kernel module,
> then he/she should exclude complete dracut watchdog module with --omit.
> 
> Testing:
> -- When watchdog is active watchdog modules were added
> 	# cat /sys/class/watchdog/watchdog0/identity
> 	iTCO_wdt
> 	# cat /sys/class/watchdog/watchdog0/state
> 	active
> 	# dracut 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 tmp/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 initramfs-test.img -a watchdog
> 	# lsinitrd initramfs-test.img | grep iTCO
> 	# lsinitrd -f tmp/active-watchdogs  initramfs-test.img
> 
> Signed-off-by: Pratyush Anand <panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Don Zickus <dzickus-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Cc: Harald Hoyer <harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
>  modules.d/04watchdog/module-setup.sh | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/modules.d/04watchdog/module-setup.sh b/modules.d/04watchdog/module-setup.sh
> index 7ec757aec032..6232afb0d9ca 100755
> --- a/modules.d/04watchdog/module-setup.sh
> +++ b/modules.d/04watchdog/module-setup.sh
> @@ -32,3 +32,36 @@ install() {
>      inst_multiple -o wdctl
>  }
>  
> +installkernel() {
> +    cd /sys/class/watchdog
> +    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/tmp/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
> +}
> 


This part should only matter/execute in the "hostonly" case. Please use $()
instead of backticks. $() can be nested.

$(cat file) can be expressed as $(< file)

you have to catch the case:
a) there is no /sys/class/watchdog
b) there is no subdir in /sys/class/watchdog

cd $dir and cd .. is not ideal
you might want to use subshells with () or use pushd/popd


something like this:

installkernel() {
  [[ $hostonly ]] || return
  for dir in /sys/class/watchdog/*; do
 	[[ -d "$dir" ]] || continue
        [[ -f "$dir/state" ]] || continue
        active=$(< "$dir/state")
	[[ "$active" ==  "active" ]] || continue
        (
		cd $dir
	   	echo $(< identity) >> "$initdir/tmp/active-watchdogs"
[…]
	        # no need for "cd .."
	)
}

Also I don't know, if the ".." method works for the wdtppath with the symlinks.
You might want:
wdtppath=$(readlink -f device/..)
instead of:
wdtppath="device/.."


why do you use tr "\n" "," | sed 's/.$//' to construct the instmods string?


  parent reply	other threads:[~2016-03-07 13:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-02 12:06 [PATCH V2 dracut 0/2] Install kernel module for active watchdog Pratyush Anand
     [not found] ` <cover.1456919929.git.panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-02 12:06   ` [PATCH V2 dracut 1/2] watchdog: Do not add hooks if systemd module is included Pratyush Anand
2016-03-02 12:06   ` [PATCH V2 dracut 2/2] watchdog: install module for active watchdog Pratyush Anand
     [not found]     ` <0d7adcfdf08f4eb753a0e65e7e65d5fe0ef22f70.1456919929.git.panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-02 15:04       ` Dracut GitHub Import Bot
2016-03-04  3:13       ` Dave Young
     [not found]         ` <20160304031334.GA3592-0VdLhd/A9Pl+NNSt+8eSiB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2016-03-04  4:15           ` Pratyush Anand
     [not found]             ` <20160304041550.GC7467-AB7H14ik7lQf7BdofF/totBPR1lH4CV8@public.gmane.org>
2016-03-04  4:53               ` Dave Young
2016-03-04  6:22               ` Pratyush Anand
2016-03-04  4:56       ` Dave Young
     [not found]         ` <20160304045610.GD3592-0VdLhd/A9Pl+NNSt+8eSiB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2016-03-04  5:09           ` Pratyush Anand
     [not found]             ` <20160304050914.GD7467-AB7H14ik7lQf7BdofF/totBPR1lH4CV8@public.gmane.org>
2016-03-04  7:30               ` Dave Young
     [not found]                 ` <20160304073007.GB2909-0VdLhd/A9Pl+NNSt+8eSiB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2016-03-04  7:44                   ` Pratyush Anand
     [not found]                     ` <20160304074422.GG7467-AB7H14ik7lQf7BdofF/totBPR1lH4CV8@public.gmane.org>
2016-03-04  8:18                       ` Dave Young
2016-03-07 13:49       ` Harald Hoyer [this message]
     [not found]         ` <56DD86D4.8040800-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-07 16:28           ` Pratyush Anand
     [not found]             ` <20160307162813.GC20953-AB7H14ik7lQf7BdofF/totBPR1lH4CV8@public.gmane.org>
2016-03-07 16:52               ` Harald Hoyer
     [not found]                 ` <56DDB1DF.7050500-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-08  2:15                   ` Pratyush Anand
2016-03-04  3:16   ` [PATCH V2 dracut 0/2] Install kernel " Dave Young
     [not found]     ` <20160304031633.GB3592-0VdLhd/A9Pl+NNSt+8eSiB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2016-03-04  3:34       ` Pratyush Anand
     [not found]         ` <20160304033443.GB7467-AB7H14ik7lQf7BdofF/totBPR1lH4CV8@public.gmane.org>
2016-03-04  7:26           ` Dave Young

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56DD86D4.8040800@redhat.com \
    --to=harald-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=dzickus-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=panand-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.