On Wed, May 15, 2019 at 5:59 PM Dave Young <dyoung(a)redhat.com> wrote:
On 05/15/19 at 04:25pm, Kairui Song wrote:
> On Wed, May 15, 2019 at 3:10 PM Dave Young <dyoung(a)redhat.com> wrote:
> >
> > Hi,
> >
> > On 05/13/19 at 06:02pm, Kairui Song wrote:
> > > When reading kdump configs, a single parsing should be enough and this
> > > saves a lot of duplicated striping call which speed up the total load
> > > speed.
> > >
> > > Speed up about 2 second when building and 0.1 second for reload in my
> > > tests.
> > >
> > > Signed-off-by: Kairui Song <kasong(a)redhat.com>
> > > ---
> > > dracut-kdump.sh | 3 +--
> > > dracut-module-setup.sh | 3 +--
> > > kdump-lib-initramfs.sh | 3 +--
> > > kdump-lib.sh | 7 +++++++
> > > kdumpctl | 8 ++------
> > > mkdumprd | 3 +--
> > > 6 files changed, 13 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/dracut-kdump.sh b/dracut-kdump.sh
> > > index b75c2a5..2ae1c7c 100755
> > > --- a/dracut-kdump.sh
> > > +++ b/dracut-kdump.sh
> > > @@ -144,7 +144,6 @@ read_kdump_conf()
> > > while read config_opt config_val;
> > > do
> > > # remove inline comments after the end of a directive.
> > > - config_val=$(strip_comments $config_val)
> > > case "$config_opt" in
> > > dracut_args)
> > > config_val=$(get_dracut_args_target "$config_val")
> > > @@ -160,7 +159,7 @@ read_kdump_conf()
> > > add_dump_code "dump_ssh $SSH_KEY_LOCATION
$config_val"
> > > ;;
> > > esac
> > > - done < $KDUMP_CONF
> > > + done <<< "$(read_strip_comments $KDUMP_CONF)"
> > > }
> > >
> > > fence_kdump_notify()
> > > diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
> > > index db7cd23..2998c72 100755
> > > --- a/dracut-module-setup.sh
> > > +++ b/dracut-module-setup.sh
> > > @@ -501,7 +501,6 @@ kdump_install_conf() {
> > > while read _opt _val;
> > > do
> > > # remove inline comments after the end of a directive.
> > > - _val=$(strip_comments $_val)
> > > case "$_opt" in
> > > raw)
> > > _pdev=$(persistent_policy="by-id"
kdump_get_persistent_dev $_val)
> > > @@ -529,7 +528,7 @@ kdump_install_conf() {
> > > dracut_install "${_val%%[[:blank:]]*}"
> > > ;;
> > > esac
> > > - done < /etc/kdump.conf
> > > + done <<< "$(read_strip_comments /etc/kdump.conf)"
> > >
> > > default_dump_target_install_conf
> > >
> > > diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
> > > index d6c01d1..608dc6e 100755
> > > --- a/kdump-lib-initramfs.sh
> > > +++ b/kdump-lib-initramfs.sh
> > > @@ -26,7 +26,6 @@ get_kdump_confs()
> > > while read config_opt config_val;
> > > do
> > > # remove inline comments after the end of a directive.
> > > - config_val=$(strip_comments $config_val)
> > > case "$config_opt" in
> > > path)
> > > KDUMP_PATH="$config_val"
> > > @@ -84,7 +83,7 @@ get_kdump_confs()
> > > esac
> > > ;;
> > > esac
> > > - done < $KDUMP_CONF
> > > + done <<< "$(read_strip_comments $KDUMP_CONF)"
> > >
> > > if [ -z "$CORE_COLLECTOR" ]; then
> > > CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"
> > > diff --git a/kdump-lib.sh b/kdump-lib.sh
> > > index 3118a4b..95a8e3c 100755
> > > --- a/kdump-lib.sh
> > > +++ b/kdump-lib.sh
> > > @@ -61,6 +61,13 @@ strip_comments()
> > > echo $@ | sed -e 's/\(.*\)#.*/\1/'
> > > }
> > >
> > > +# Read from kdump config file stripping all comments
> > > +read_strip_comments()
> > > +{
> > > + # sed: print all non empty line and ignore any contain after a #
> > > + sed -n -e "s/^\([^#]\+\).*$/\1/gp" $1
> >
> > This patter does not remove the empty line with white spaces, can it be
> > improved?
> >
>
> Good catch, then use "s/^[ \t]*\([^# \t]\+[^#]\+\).*/\1/gp" should be
good.
> But it looks complex, and empty lines seems won't bring trouble for
> parsing not sure worth it.
Yes, it looks over complicated. Is '\s' better?
If no easy way to then probably we just leave with it.
This pattern looks better, \s inside [] won't work so only replaced one with \s:
s/^\s*\([^# \t][^#]\+\).*/\1/gp
--
Best Regards,
Kairui Song