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 <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
Kairui Song 2019-05-17 16:48:46 +08:00
parent 9529191d95
commit 75d9132417
6 changed files with 14 additions and 14 deletions

View File

@ -144,7 +144,6 @@ read_kdump_conf()
while read config_opt config_val; while read config_opt config_val;
do do
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
config_val=$(strip_comments $config_val)
case "$config_opt" in case "$config_opt" in
dracut_args) dracut_args)
config_val=$(get_dracut_args_target "$config_val") 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" add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val"
;; ;;
esac esac
done < $KDUMP_CONF done <<< "$(read_strip_comments $KDUMP_CONF)"
} }
fence_kdump_notify() fence_kdump_notify()

View File

@ -501,7 +501,6 @@ kdump_install_conf() {
while read _opt _val; while read _opt _val;
do do
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
_val=$(strip_comments $_val)
case "$_opt" in case "$_opt" in
raw) raw)
_pdev=$(persistent_policy="by-id" kdump_get_persistent_dev $_val) _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev $_val)
@ -529,7 +528,7 @@ kdump_install_conf() {
dracut_install "${_val%%[[:blank:]]*}" dracut_install "${_val%%[[:blank:]]*}"
;; ;;
esac esac
done < /etc/kdump.conf done <<< "$(read_strip_comments /etc/kdump.conf)"
default_dump_target_install_conf default_dump_target_install_conf

View File

@ -26,7 +26,6 @@ get_kdump_confs()
while read config_opt config_val; while read config_opt config_val;
do do
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
config_val=$(strip_comments $config_val)
case "$config_opt" in case "$config_opt" in
path) path)
KDUMP_PATH="$config_val" KDUMP_PATH="$config_val"
@ -84,7 +83,7 @@ get_kdump_confs()
esac esac
;; ;;
esac esac
done < $KDUMP_CONF done <<< "$(read_strip_comments $KDUMP_CONF)"
if [ -z "$CORE_COLLECTOR" ]; then if [ -z "$CORE_COLLECTOR" ]; then
CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR"

View File

@ -61,6 +61,14 @@ strip_comments()
echo $@ | sed -e 's/\(.*\)#.*/\1/' 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 # Check if fence kdump is configured in Pacemaker cluster
is_pcs_fence_kdump() is_pcs_fence_kdump()
{ {

View File

@ -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) 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. # remove inline comments after the end of a directive.
config_val=$(strip_comments $config_val)
[ -z "$config_val" ] && { [ -z "$config_val" ] && {
echo "Invalid kdump config value for option $config_opt." echo "Invalid kdump config value for option $config_opt."
return 1; return 1;
@ -260,7 +259,7 @@ check_config()
return 1; return 1;
;; ;;
esac esac
done < $KDUMP_CONFIG_FILE done <<< "$(read_strip_comments $KDUMP_CONFIG_FILE)"
check_failure_action_config || return 1 check_failure_action_config || return 1
check_final_action_config || return 1 check_final_action_config || return 1
@ -676,7 +675,6 @@ check_ssh_config()
case "$config_opt" in case "$config_opt" in
sshkey) sshkey)
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
config_val=$(strip_comments $config_val)
if [ -f "$config_val" ]; then if [ -f "$config_val" ]; then
# canonicalize the path # canonicalize the path
SSH_KEY_LOCATION=$(/usr/bin/readlink -m $config_val) SSH_KEY_LOCATION=$(/usr/bin/readlink -m $config_val)
@ -685,17 +683,15 @@ check_ssh_config()
fi fi
;; ;;
path) path)
config_val=$(strip_comments $config_val)
SAVE_PATH=$config_val SAVE_PATH=$config_val
;; ;;
ssh) ssh)
config_val=$(strip_comments $config_val)
DUMP_TARGET=$config_val DUMP_TARGET=$config_val
;; ;;
*) *)
;; ;;
esac esac
done < $KDUMP_CONFIG_FILE done <<< "$(read_strip_comments $KDUMP_CONFIG_FILE)"
#make sure they've configured kdump.conf for ssh dumps #make sure they've configured kdump.conf for ssh dumps
local SSH_TARGET=`echo -n $DUMP_TARGET | sed -n '/.*@/p'` local SSH_TARGET=`echo -n $DUMP_TARGET | sed -n '/.*@/p'`

View File

@ -392,7 +392,6 @@ fi
while read config_opt config_val; while read config_opt config_val;
do do
# remove inline comments after the end of a directive. # remove inline comments after the end of a directive.
config_val=$(strip_comments $config_val)
case "$config_opt" in case "$config_opt" in
extra_modules) extra_modules)
extra_modules="$extra_modules $config_val" extra_modules="$extra_modules $config_val"
@ -446,7 +445,7 @@ do
*) *)
;; ;;
esac esac
done <<< "$(grep -v -e "^#" -e "^$" $conf_file)" done <<< "$(read_strip_comments $conf_file)"
handle_default_dump_target handle_default_dump_target