From 75d9132417e00aca8498ef5d1d882f6b95091290 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 17 May 2019 16:48:46 +0800 Subject: [PATCH] Get rid of duplicated strip_comments when reading config 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 Acked-by: Dave Young --- dracut-kdump.sh | 3 +-- dracut-module-setup.sh | 3 +-- kdump-lib-initramfs.sh | 3 +-- kdump-lib.sh | 8 ++++++++ kdumpctl | 8 ++------ mkdumprd | 3 +-- 6 files changed, 14 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 36a1043..4feb7d0 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -61,6 +61,14 @@ strip_comments() echo $@ | sed -e 's/\(.*\)#.*/\1/' } +# Read from kdump config file stripping all comments +read_strip_comments() +{ + # strip heading spaces, and print any content starting with + # neither space or #, and strip everything after # + sed -n -e "s/^\s*\([^# \t][^#]\+\).*/\1/gp" $1 +} + # Check if fence kdump is configured in Pacemaker cluster is_pcs_fence_kdump() { diff --git a/kdumpctl b/kdumpctl index 72f9d7e..08c5667 100755 --- a/kdumpctl +++ b/kdumpctl @@ -245,7 +245,6 @@ check_config() ;; raw|ext2|ext3|ext4|minix|btrfs|xfs|nfs|ssh|sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|failure_action|default|final_action|force_rebuild|force_no_rebuild|dracut_args|fence_kdump_args|fence_kdump_nodes) # remove inline comments after the end of a directive. - config_val=$(strip_comments $config_val) [ -z "$config_val" ] && { echo "Invalid kdump config value for option $config_opt." return 1; @@ -260,7 +259,7 @@ check_config() return 1; ;; esac - done < $KDUMP_CONFIG_FILE + done <<< "$(read_strip_comments $KDUMP_CONFIG_FILE)" check_failure_action_config || return 1 check_final_action_config || return 1 @@ -676,7 +675,6 @@ check_ssh_config() case "$config_opt" in sshkey) # remove inline comments after the end of a directive. - config_val=$(strip_comments $config_val) if [ -f "$config_val" ]; then # canonicalize the path SSH_KEY_LOCATION=$(/usr/bin/readlink -m $config_val) @@ -685,17 +683,15 @@ check_ssh_config() fi ;; path) - config_val=$(strip_comments $config_val) SAVE_PATH=$config_val ;; ssh) - config_val=$(strip_comments $config_val) DUMP_TARGET=$config_val ;; *) ;; esac - done < $KDUMP_CONFIG_FILE + done <<< "$(read_strip_comments $KDUMP_CONFIG_FILE)" #make sure they've configured kdump.conf for ssh dumps local SSH_TARGET=`echo -n $DUMP_TARGET | sed -n '/.*@/p'` diff --git a/mkdumprd b/mkdumprd index a99d5f1..cf3533f 100644 --- a/mkdumprd +++ b/mkdumprd @@ -392,7 +392,6 @@ fi 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 extra_modules) extra_modules="$extra_modules $config_val" @@ -446,7 +445,7 @@ do *) ;; esac -done <<< "$(grep -v -e "^#" -e "^$" $conf_file)" +done <<< "$(read_strip_comments $conf_file)" handle_default_dump_target