diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh index 23bb369..a4e14a4 100755 --- a/dracut-early-kdump.sh +++ b/dracut-early-kdump.sh @@ -53,6 +53,9 @@ early_kdump_load() EARLY_KEXEC_ARGS="$EARLY_KEXEC_ARGS -s" fi + # Here, only output the messages, but do not save these messages + # to a file because the target disk may not be mounted yet, the + # earlykdump is too early. ddebug "earlykdump: $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \ --command-line=$EARLY_KDUMP_CMDLINE --initrd=$EARLY_KDUMP_INITRD \ $EARLY_KDUMP_KERNEL" diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 911a8b8..1750c6c 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -20,6 +20,10 @@ check() { depends() { local _dep="base shutdown" + add_opt_module() { + [[ " $omit_dracutmodules " != *\ $1\ * ]] && _dep="$_dep $1" + } + is_squash_available() { for kmodule in squashfs overlay loop; do if [ -z "$KDUMP_KERNELVER" ]; then @@ -31,13 +35,25 @@ depends() { } if is_squash_available && ! is_fadump_capable; then - _dep="$_dep squash" + add_opt_module squash else dwarning "Required modules to build a squashed kdump image is missing!" fi + if is_wdt_active; then + add_opt_module watchdog + fi + + if is_ssh_dump_target; then + _dep="$_dep ssh-client" + fi + + if [ "$(uname -m)" = "s390x" ]; then + _dep="$_dep znet" + fi + if [ -n "$( find /sys/devices -name drm )" ] || [ -d /sys/module/hyperv_fb ]; then - _dep="$_dep drm" + add_opt_module drm fi if is_generic_fence_kdump || is_pcs_fence_kdump; then @@ -45,7 +61,6 @@ depends() { fi echo $_dep - return 0 } kdump_is_bridge() { @@ -819,7 +834,6 @@ install() { kdump_install_random_seed fi dracut_install -o /etc/adjtime /etc/localtime - inst_simple "/etc/sysconfig/kdump" inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress" chmod +x ${initdir}/kdumpscripts/monitor_dd_progress inst "/bin/dd" "/bin/dd" diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 14aac7b..d8d4893 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -1,6 +1,5 @@ # These variables and functions are useful in 2nd kernel -. /etc/sysconfig/kdump . /lib/kdump-lib.sh KDUMP_PATH="/var/crash" diff --git a/kdump-lib.sh b/kdump-lib.sh index b55d987..748419f 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -479,6 +479,18 @@ is_wdt_mod_omitted() { return $ret } +is_wdt_active() { + local active + + [ -d /sys/class/watchdog ] || return 1 + for dir in /sys/class/watchdog/*; do + [ -f "$dir/state" ] || continue + active=$(< "$dir/state") + [ "$active" = "active" ] && return 0 + done + return 1 +} + # If "dracut_args" contains "--mount" information, use it # directly without any check(users are expected to ensure # its correctness). diff --git a/kdump-logger.sh b/kdump-logger.sh index c7afa34..370e5e8 100755 --- a/kdump-logger.sh +++ b/kdump-logger.sh @@ -2,47 +2,115 @@ # # This comes from the dracut-logger.sh # -# The logger defined 6 logging levels: -# - dtrace() (6) -# The TRACE Level designates finer-grained informational events than the -# DEBUG. -# - ddebug (5) +# The logger defined 4 logging levels: +# - ddebug (4) # The DEBUG Level designates fine-grained informational events that are most # useful to debug an application. -# - dinfo (4) +# - dinfo (3) # The INFO level designates informational messages that highlight the # progress of the application at coarse-grained level. -# - dwarn (3) +# - dwarn (2) # The WARN level designates potentially harmful situations. -# - derror (2) +# - derror (1) # The ERROR level designates error events that might still allow the # application to continue running. -# - dfatal (1) -# The FATAL level designates very severe error events that will presumably -# lead the application to abort. # # Logging is controlled by following global variables: # - @var kdump_stdloglvl - logging level to standard error (console output) # - @var kdump_sysloglvl - logging level to syslog (by logger command) # - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) # -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl = 4 (info) -# - @var kdump_sysloglvl = 4 (info) -# - @var kdump_kmsgloglvl = 0 (no logging) +# If any of the variables is not set, the function dlog_init() sets it to default: +# - In the first kernel: +# - @var kdump_stdloglvl = 3 (info) +# - @var kdump_sysloglvl = 0 (no logging) +# - @var kdump_kmsgloglvl = 0 (no logging) +# +# -In the second kernel: +# - @var kdump_stdloglvl = 0 (no logging) +# - @var kdump_sysloglvl = 3 (info) +# - @var kdump_kmsgloglvl = 0 (no logging) # # First of all you have to start with dlog_init() function which initializes # required variables. Don't call any other logging function before that one! # + +# Define vairables for the log levels in this module. +kdump_stdloglvl="" +kdump_sysloglvl="" +kdump_kmsgloglvl="" + +# The dracut-lib.sh is only available in the second kernel, and it won't +# be used in the first kernel because the dracut-lib.sh is invisible in +# the first kernel. +if [ -f /lib/dracut-lib.sh ]; then + . /lib/dracut-lib.sh +fi + +# @brief Get the log level from kernel command line. +# @retval 1 if something has gone wrong +# @retval 0 on success. +# +get_kdump_loglvl() +{ + (type -p getarg) && kdump_sysloglvl=$(getarg rd.kdumploglvl) + [ -z "$kdump_sysloglvl" ] && return 1; + + (type -p isdigit) && isdigit $kdump_sysloglvl + [ $? -ne 0 ] && return 1; + + return 0 +} + +# @brief Check the log level. +# @retval 1 if something has gone wrong +# @retval 0 on success. +# +check_loglvl() +{ + case "$1" in + 0|1|2|3|4) + return 0 + ;; + *) + return 1 + ;; + esac +} + # @brief Initializes Logger. # @retval 1 if something has gone wrong # @retval 0 on success. # dlog_init() { local ret=0; local errmsg - [ -z "$kdump_stdloglvl" ] && kdump_stdloglvl=4 - [ -z "$kdump_sysloglvl" ] && kdump_sysloglvl=4 + + if [ -s /proc/vmcore ];then + get_kdump_loglvl + if [ $? -ne 0 ];then + logger -t "kdump[$$]" -p warn -- "Kdump is using the default log level(3)." + kdump_sysloglvl=3 + fi + kdump_stdloglvl=0 + kdump_kmsgloglvl=0 + else + kdump_stdloglvl=$KDUMP_STDLOGLVL + kdump_sysloglvl=$KDUMP_SYSLOGLVL + kdump_kmsgloglvl=$KDUMP_KMSGLOGLVL + fi + + [ -z "$kdump_stdloglvl" ] && kdump_stdloglvl=3 + [ -z "$kdump_sysloglvl" ] && kdump_sysloglvl=0 [ -z "$kdump_kmsgloglvl" ] && kdump_kmsgloglvl=0 + + for loglvl in "$kdump_stdloglvl" "$kdump_kmsgloglvl" "$kdump_sysloglvl"; do + check_loglvl "$loglvl" + if [ $? -ne 0 ]; then + echo "Illegal log level: $kdump_stdloglvl $kdump_kmsgloglvl $kdump_sysloglvl" + return 1 + fi + done + # Skip initialization if it's already done. [ -n "$kdump_maxloglvl" ] && return 0 @@ -76,83 +144,52 @@ dlog_init() { readonly kdump_maxloglvl=$maxloglvl_l export kdump_maxloglvl - - if [[ $kdump_stdloglvl -lt 6 ]] && [[ $kdump_kmsgloglvl -lt 6 ]] && [[ $kdump_sysloglvl -lt 6 ]]; then - unset dtrace - dtrace() { :; }; - fi - - if [[ $kdump_stdloglvl -lt 5 ]] && [[ $kdump_kmsgloglvl -lt 5 ]] && [[ $kdump_sysloglvl -lt 5 ]]; then + if [[ $kdump_stdloglvl -lt 4 ]] && [[ $kdump_kmsgloglvl -lt 4 ]] && [[ $kdump_sysloglvl -lt 4 ]]; then unset ddebug ddebug() { :; }; fi - if [[ $kdump_stdloglvl -lt 4 ]] && [[ $kdump_kmsgloglvl -lt 4 ]] && [[ $kdump_sysloglvl -lt 4 ]]; then + if [[ $kdump_stdloglvl -lt 3 ]] && [[ $kdump_kmsgloglvl -lt 3 ]] && [[ $kdump_sysloglvl -lt 3 ]]; then unset dinfo dinfo() { :; }; fi - if [[ $kdump_stdloglvl -lt 3 ]] && [[ $kdump_kmsgloglvl -lt 3 ]] && [[ $kdump_sysloglvl -lt 3 ]]; then + if [[ $kdump_stdloglvl -lt 2 ]] && [[ $kdump_kmsgloglvl -lt 2 ]] && [[ $kdump_sysloglvl -lt 2 ]]; then unset dwarn dwarn() { :; }; unset dwarning dwarning() { :; }; fi - if [[ $kdump_stdloglvl -lt 2 ]] && [[ $kdump_kmsgloglvl -lt 2 ]] && [[ $kdump_sysloglvl -lt 2 ]]; then + if [[ $kdump_stdloglvl -lt 1 ]] && [[ $kdump_kmsgloglvl -lt 1 ]] && [[ $kdump_sysloglvl -lt 1 ]]; then unset derror derror() { :; }; fi - if [[ $kdump_stdloglvl -lt 1 ]] && [[ $kdump_kmsgloglvl -lt 1 ]] && [[ $kdump_sysloglvl -lt 1 ]]; then - unset dfatal - dfatal() { :; }; - fi - [ -n "$errmsg" ] && derror "$errmsg" return $ret } -## @brief Converts numeric logging level to the first letter of level name. -# -# @param lvl Numeric logging level in range from 1 to 6. -# @retval 1 if @a lvl is out of range. -# @retval 0 if @a lvl is correct. -# @result Echoes first letter of level name. -_lvl2char() { - case "$1" in - 1) echo F;; - 2) echo E;; - 3) echo W;; - 4) echo I;; - 5) echo D;; - 6) echo T;; - *) return 1;; - esac -} - ## @brief Converts numeric level to logger priority defined by POSIX.2. # -# @param lvl Numeric logging level in range from 1 to 6. +# @param lvl Numeric logging level in range from 1 to 4. # @retval 1 if @a lvl is out of range. # @retval 0 if @a lvl is correct. # @result Echoes logger priority. _lvl2syspri() { case "$1" in - 1) echo crit;; - 2) echo error;; - 3) echo warning;; - 4) echo info;; - 5) echo debug;; - 6) echo debug;; + 1) echo error;; + 2) echo warning;; + 3) echo info;; + 4) echo debug;; *) return 1;; esac } ## @brief Converts logger numeric level to syslog log level # -# @param lvl Numeric logging level in range from 1 to 6. +# @param lvl Numeric logging level in range from 1 to 4. # @retval 1 if @a lvl is out of range. # @retval 0 if @a lvl is correct. # @result Echoes kernel console numeric log level @@ -162,13 +199,12 @@ _lvl2syspri() { # # none -> LOG_EMERG (0) # none -> LOG_ALERT (1) -# FATAL(1) -> LOG_CRIT (2) -# ERROR(2) -> LOG_ERR (3) -# WARN(3) -> LOG_WARNING (4) +# none -> LOG_CRIT (2) +# ERROR(1) -> LOG_ERR (3) +# WARN(2) -> LOG_WARNING (4) # none -> LOG_NOTICE (5) -# INFO(4) -> LOG_INFO (6) -# DEBUG(5) -> LOG_DEBUG (7) -# TRACE(6) / +# INFO(3) -> LOG_INFO (6) +# DEBUG(4) -> LOG_DEBUG (7) # # # @see /usr/include/sys/syslog.h @@ -176,29 +212,30 @@ _dlvl2syslvl() { local lvl case "$1" in - 1) lvl=2;; - 2) lvl=3;; - 3) lvl=4;; - 4) lvl=6;; - 5) lvl=7;; - 6) lvl=7;; + 1) lvl=3;; + 2) lvl=4;; + 3) lvl=6;; + 4) lvl=7;; *) return 1;; esac - [ -s /proc/vmcore ] && echo $((24+$lvl)) || echo $((8+$lvl)) + # The number is constructed by multiplying the facility by 8 and then + # adding the level. + # About The Syslog Protocol, please refer to the RFC5424 for more details. + echo $((24+$lvl)) } -## @brief Prints to stderr and/or writes to file, to syslog and/or /dev/kmsg -# given message with given level (priority). +## @brief Prints to stderr, to syslog and/or /dev/kmsg given message with +# given level (priority). # # @param lvl Numeric logging level. # @param msg Message. # @retval 0 It's always returned, even if logging failed. # # @note This function is not supposed to be called manually. Please use -# dtrace(), ddebug(), or others instead which wrap this one. +# dinfo(), ddebug(), or others instead which wrap this one. # -# This is core logging function which logs given message to standard error, file +# This is core logging function which logs given message to standard error # and/or syslog (with POSIX shell command logger) and/or to /dev/kmsg. # The format is following: # @@ -209,16 +246,13 @@ _dlvl2syslvl() { # # Message to syslog is sent with tag @c kdump. Priorities are mapped as # following: -# - @c FATAL to @c crit # - @c ERROR to @c error # - @c WARN to @c warning # - @c INFO to @c info -# - @c DEBUG and @c TRACE both to @c debug +# - @c DEBUG to @c debug _do_dlog() { local lvl="$1"; shift - local lvlc=$(_lvl2char "$lvl") || return 0 local msg="$*" - local lmsg="$lvlc: $*" [[ $lvl -le $kdump_stdloglvl ]] && printf -- 'kdump: %s\n' "$msg" >&2 @@ -241,7 +275,7 @@ _do_dlog() { # @retval 0 It's always returned, even if logging failed. # # @note This function is not supposed to be called manually. Please use -# dtrace(), ddebug(), or others instead which wrap this one. +# dinfo(), ddebug(), or others instead which wrap this one. # # This function calls _do_dlog() either with parameter msg, or if # none is given, it will read standard input and will use every line as @@ -263,43 +297,33 @@ dlog() { fi } -## @brief Logs message at TRACE level (6) -# -# @param msg Message. -# @retval 0 It's always returned, even if logging failed. -dtrace() { - set +x - dlog 6 "$@" - [ -n "$debug" ] && set -x || : -} - -## @brief Logs message at DEBUG level (5) +## @brief Logs message at DEBUG level (4) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. ddebug() { set +x - dlog 5 "$@" + dlog 4 "$@" [ -n "$debug" ] && set -x || : } -## @brief Logs message at INFO level (4) +## @brief Logs message at INFO level (3) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. dinfo() { set +x - dlog 4 "$@" + dlog 3 "$@" [ -n "$debug" ] && set -x || : } -## @brief Logs message at WARN level (3) +## @brief Logs message at WARN level (2) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. dwarn() { set +x - dlog 3 "$@" + dlog 2 "$@" [ -n "$debug" ] && set -x || : } @@ -313,22 +337,12 @@ dwarning() { [ -n "$debug" ] && set -x || : } -## @brief Logs message at ERROR level (2) +## @brief Logs message at ERROR level (1) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. derror() { set +x - dlog 2 "$@" - [ -n "$debug" ] && set -x || : -} - -## @brief Logs message at FATAL level (1) -# -# @param msg Message. -# @retval 0 It's always returned, even if logging failed. -dfatal() { - set +x dlog 1 "$@" [ -n "$debug" ] && set -x || : } diff --git a/kdump.sysconfig b/kdump.sysconfig index 52a0b92..30f0c63 100644 --- a/kdump.sysconfig +++ b/kdump.sysconfig @@ -36,18 +36,18 @@ KEXEC_ARGS="" #What is the image type used for kdump KDUMP_IMG="vmlinuz" -# Logging is controlled by following global variables: -# - @var kdump_stdloglvl - logging level to standard error (console output) -# - @var kdump_sysloglvl - logging level to syslog (by logger command) -# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl=4 (info) -# - @var kdump_sysloglvl=4 (info) -# - @var kdump_kmsgloglvl=0 (no logging) +# Logging is controlled by following variables in the first kernel: +# - @var KDUMP_STDLOGLVL - logging level to standard error (console output) +# - @var KDUMP_SYSLOGLVL - logging level to syslog (by logger command) +# - @var KDUMP_KMSGLOGLVL - logging level to /dev/kmsg (only for boot-time) # -# Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) +# In the second kernel, kdump will use the rd.kdumploglvl option to set the +# log level in the above KDUMP_COMMANDLINE_APPEND. +# - @var rd.kdumploglvl - logging level to syslog (by logger command) +# - for example: add the rd.kdumploglvl=3 option to KDUMP_COMMANDLINE_APPEND # -# For example: the following configurations indicate that kdump messages will be printed -# to console and journald for debugging case. -# kdump_sysloglvl=5 -# kdump_stdloglvl=5 +# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) +# +# KDUMP_STDLOGLVL=3 +# KDUMP_SYSLOGLVL=0 +# KDUMP_KMSGLOGLVL=0 diff --git a/kdump.sysconfig.aarch64 b/kdump.sysconfig.aarch64 index 1d75979..6f7830a 100644 --- a/kdump.sysconfig.aarch64 +++ b/kdump.sysconfig.aarch64 @@ -36,18 +36,18 @@ KEXEC_ARGS="" #What is the image type used for kdump KDUMP_IMG="vmlinuz" -# Logging is controlled by following global variables: -# - @var kdump_stdloglvl - logging level to standard error (console output) -# - @var kdump_sysloglvl - logging level to syslog (by logger command) -# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl=4 (info) -# - @var kdump_sysloglvl=4 (info) -# - @var kdump_kmsgloglvl=0 (no logging) +# Logging is controlled by following variables in the first kernel: +# - @var KDUMP_STDLOGLVL - logging level to standard error (console output) +# - @var KDUMP_SYSLOGLVL - logging level to syslog (by logger command) +# - @var KDUMP_KMSGLOGLVL - logging level to /dev/kmsg (only for boot-time) # -# Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) +# In the second kernel, kdump will use the rd.kdumploglvl option to set the +# log level in the above KDUMP_COMMANDLINE_APPEND. +# - @var rd.kdumploglvl - logging level to syslog (by logger command) +# - for example: add the rd.kdumploglvl=3 option to KDUMP_COMMANDLINE_APPEND # -# For example: the following configurations indicate that kdump messages will be printed -# to console and journald for debugging case. -# kdump_sysloglvl=5 -# kdump_stdloglvl=5 +# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) +# +# KDUMP_STDLOGLVL=3 +# KDUMP_SYSLOGLVL=0 +# KDUMP_KMSGLOGLVL=0 diff --git a/kdump.sysconfig.i386 b/kdump.sysconfig.i386 index 2eb9705..d2de7d6 100644 --- a/kdump.sysconfig.i386 +++ b/kdump.sysconfig.i386 @@ -39,18 +39,18 @@ KDUMP_IMG="vmlinuz" #What is the images extension. Relocatable kernels don't have one KDUMP_IMG_EXT="" -# Logging is controlled by following global variables: -# - @var kdump_stdloglvl - logging level to standard error (console output) -# - @var kdump_sysloglvl - logging level to syslog (by logger command) -# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl=4 (info) -# - @var kdump_sysloglvl=4 (info) -# - @var kdump_kmsgloglvl=0 (no logging) +# Logging is controlled by following variables in the first kernel: +# - @var KDUMP_STDLOGLVL - logging level to standard error (console output) +# - @var KDUMP_SYSLOGLVL - logging level to syslog (by logger command) +# - @var KDUMP_KMSGLOGLVL - logging level to /dev/kmsg (only for boot-time) # -# Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) +# In the second kernel, kdump will use the rd.kdumploglvl option to set the +# log level in the above KDUMP_COMMANDLINE_APPEND. +# - @var rd.kdumploglvl - logging level to syslog (by logger command) +# - for example: add the rd.kdumploglvl=3 option to KDUMP_COMMANDLINE_APPEND # -# For example: the following configurations indicate that kdump messages will be printed -# to console and journald for debugging case. -# kdump_sysloglvl=5 -# kdump_stdloglvl=5 +# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) +# +# KDUMP_STDLOGLVL=3 +# KDUMP_SYSLOGLVL=0 +# KDUMP_KMSGLOGLVL=0 diff --git a/kdump.sysconfig.ppc64 b/kdump.sysconfig.ppc64 index 24279ff..39b69bb 100644 --- a/kdump.sysconfig.ppc64 +++ b/kdump.sysconfig.ppc64 @@ -41,18 +41,18 @@ KDUMP_IMG_EXT="" #Specify the action after failure -# Logging is controlled by following global variables: -# - @var kdump_stdloglvl - logging level to standard error (console output) -# - @var kdump_sysloglvl - logging level to syslog (by logger command) -# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl=4 (info) -# - @var kdump_sysloglvl=4 (info) -# - @var kdump_kmsgloglvl=0 (no logging) +# Logging is controlled by following variables in the first kernel: +# - @var KDUMP_STDLOGLVL - logging level to standard error (console output) +# - @var KDUMP_SYSLOGLVL - logging level to syslog (by logger command) +# - @var KDUMP_KMSGLOGLVL - logging level to /dev/kmsg (only for boot-time) # -# Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) +# In the second kernel, kdump will use the rd.kdumploglvl option to set the +# log level in the above KDUMP_COMMANDLINE_APPEND. +# - @var rd.kdumploglvl - logging level to syslog (by logger command) +# - for example: add the rd.kdumploglvl=3 option to KDUMP_COMMANDLINE_APPEND # -# For example: the following configurations indicate that kdump messages will be printed -# to console and journald for debugging case. -# kdump_sysloglvl=5 -# kdump_stdloglvl=5 +# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) +# +# KDUMP_STDLOGLVL=3 +# KDUMP_SYSLOGLVL=0 +# KDUMP_KMSGLOGLVL=0 diff --git a/kdump.sysconfig.ppc64le b/kdump.sysconfig.ppc64le index 24279ff..39b69bb 100644 --- a/kdump.sysconfig.ppc64le +++ b/kdump.sysconfig.ppc64le @@ -41,18 +41,18 @@ KDUMP_IMG_EXT="" #Specify the action after failure -# Logging is controlled by following global variables: -# - @var kdump_stdloglvl - logging level to standard error (console output) -# - @var kdump_sysloglvl - logging level to syslog (by logger command) -# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl=4 (info) -# - @var kdump_sysloglvl=4 (info) -# - @var kdump_kmsgloglvl=0 (no logging) +# Logging is controlled by following variables in the first kernel: +# - @var KDUMP_STDLOGLVL - logging level to standard error (console output) +# - @var KDUMP_SYSLOGLVL - logging level to syslog (by logger command) +# - @var KDUMP_KMSGLOGLVL - logging level to /dev/kmsg (only for boot-time) # -# Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) +# In the second kernel, kdump will use the rd.kdumploglvl option to set the +# log level in the above KDUMP_COMMANDLINE_APPEND. +# - @var rd.kdumploglvl - logging level to syslog (by logger command) +# - for example: add the rd.kdumploglvl=3 option to KDUMP_COMMANDLINE_APPEND # -# For example: the following configurations indicate that kdump messages will be printed -# to console and journald for debugging case. -# kdump_sysloglvl=5 -# kdump_stdloglvl=5 +# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) +# +# KDUMP_STDLOGLVL=3 +# KDUMP_SYSLOGLVL=0 +# KDUMP_KMSGLOGLVL=0 diff --git a/kdump.sysconfig.s390x b/kdump.sysconfig.s390x index 5e1cb5a..f9218e5 100644 --- a/kdump.sysconfig.s390x +++ b/kdump.sysconfig.s390x @@ -42,18 +42,18 @@ KDUMP_IMG="vmlinuz" #What is the images extension. Relocatable kernels don't have one KDUMP_IMG_EXT="" -# Logging is controlled by following global variables: -# - @var kdump_stdloglvl - logging level to standard error (console output) -# - @var kdump_sysloglvl - logging level to syslog (by logger command) -# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl=4 (info) -# - @var kdump_sysloglvl=4 (info) -# - @var kdump_kmsgloglvl=0 (no logging) +# Logging is controlled by following variables in the first kernel: +# - @var KDUMP_STDLOGLVL - logging level to standard error (console output) +# - @var KDUMP_SYSLOGLVL - logging level to syslog (by logger command) +# - @var KDUMP_KMSGLOGLVL - logging level to /dev/kmsg (only for boot-time) # -# Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) +# In the second kernel, kdump will use the rd.kdumploglvl option to set the +# log level in the above KDUMP_COMMANDLINE_APPEND. +# - @var rd.kdumploglvl - logging level to syslog (by logger command) +# - for example: add the rd.kdumploglvl=3 option to KDUMP_COMMANDLINE_APPEND # -# For example: the following configurations indicate that kdump messages will be printed -# to console and journald for debugging case. -# kdump_sysloglvl=5 -# kdump_stdloglvl=5 +# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) +# +# KDUMP_STDLOGLVL=3 +# KDUMP_SYSLOGLVL=0 +# KDUMP_KMSGLOGLVL=0 diff --git a/kdump.sysconfig.x86_64 b/kdump.sysconfig.x86_64 index eb1c538..0521893 100644 --- a/kdump.sysconfig.x86_64 +++ b/kdump.sysconfig.x86_64 @@ -39,18 +39,18 @@ KDUMP_IMG="vmlinuz" #What is the images extension. Relocatable kernels don't have one KDUMP_IMG_EXT="" -# Logging is controlled by following global variables: -# - @var kdump_stdloglvl - logging level to standard error (console output) -# - @var kdump_sysloglvl - logging level to syslog (by logger command) -# - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) -# If any of the variables is not set, this function set it to default: -# - @var kdump_stdloglvl=4 (info) -# - @var kdump_sysloglvl=4 (info) -# - @var kdump_kmsgloglvl=0 (no logging) +# Logging is controlled by following variables in the first kernel: +# - @var KDUMP_STDLOGLVL - logging level to standard error (console output) +# - @var KDUMP_SYSLOGLVL - logging level to syslog (by logger command) +# - @var KDUMP_KMSGLOGLVL - logging level to /dev/kmsg (only for boot-time) # -# Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) +# In the second kernel, kdump will use the rd.kdumploglvl option to set the +# log level in the above KDUMP_COMMANDLINE_APPEND. +# - @var rd.kdumploglvl - logging level to syslog (by logger command) +# - for example: add the rd.kdumploglvl=3 option to KDUMP_COMMANDLINE_APPEND # -# For example: the following configurations indicate that kdump messages will be printed -# to console and journald for debugging case. -# kdump_sysloglvl=5 -# kdump_stdloglvl=5 +# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) +# +# KDUMP_STDLOGLVL=3 +# KDUMP_SYSLOGLVL=0 +# KDUMP_KMSGLOGLVL=0 diff --git a/kdumpctl b/kdumpctl index e816719..94e4f5a 100755 --- a/kdumpctl +++ b/kdumpctl @@ -719,6 +719,10 @@ load_kdump() ddebug "$KEXEC $KEXEC_ARGS $standard_kexec_args --command-line=$KDUMP_COMMANDLINE --initrd=$TARGET_INITRD $KDUMP_KERNEL" + # The '12' represents an intermediate temporary file descriptor + # to store the standard error file descriptor '2', and later + # restore the error file descriptor with the file descriptor '12' + # and release it. exec 12>&2 exec 2>> $KDUMP_LOG_PATH/kdump.log PS4='+ $(date "+%Y-%m-%d %H:%M:%S") ${BASH_SOURCE}@${LINENO}: ' diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 5f57a84..447bc54 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -888,35 +888,80 @@ Debugging Tips - Using the logger to output kdump log messages - Currently, kdump messages are printed with the 'echo' command or redirect - to console, and which does not support to output kdump messages according - to the log level. - - That is not convenient to debug kdump issues, we usually need to capture - additional debugging information via the modification of the options or the - scripts like kdumpctl, mkdumprd, etc. Because there is no complete debugging - messages, which could waste valuable time. - - To cope with this challenging, we introduce the logger to output the kdump - messages according to the log level, and provide a chance to save logs to - the journald if the journald service is available, and then dump all logs - to a file, otherwise dump the logs with the dmesg to a file. - - Logging is controlled by following global variables: - - @var kdump_stdloglvl - logging level to standard error (console output) - - @var kdump_sysloglvl - logging level to syslog (by logger command) - - @var kdump_kmsgloglvl - logging level to /dev/kmsg (only for boot-time) - If any of the variables is not set, this function set it to default: - - @var kdump_stdloglvl=4 (info) - - @var kdump_sysloglvl=4 (info) - - @var kdump_kmsgloglvl=0 (no logging) - - Logging levels: fatal(1),error(2),warn(3),info(4),debug(5),trace(6) - - We can easily configure the above variables in the /etc/sysconfig/kdump. For - example: - kdump_sysloglvl=5 - kdump_stdloglvl=5 - - The above configurations indicate that kdump messages will be printed to the - console and journald if the journald service is enabled. + You can configure the kdump log level for the first kernel in the + /etc/sysconfig/kdump. For example: + + KDUMP_STDLOGLVL=3 + KDUMP_SYSLOGLVL=0 + KDUMP_KMSGLOGLVL=0 + + The above configurations indicate that kdump messages will be printed + to the console, and the KDUMP_STDLOGLVL is set to 3(info), but the + KDUMP_SYSLOGLVL and KDUMP_KMSGLOGLVL are set to 0(no logging). This + is also the current default log levels in the first kernel. + + In the second kernel, you can add the 'rd.kdumploglvl=X' option to the + KDUMP_COMMANDLINE_APPEND in the /etc/sysconfig/kdump so that you can also + set the log levels for the second kernel. The 'X' represents the logging + levels, the default log level is 3(info) in the second kernel, for example: + + # cat /etc/sysconfig/kdump |grep rd.kdumploglvl + KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory mce=off numa=off udev.children-max=2 panic=10 acpi_no_memhotplug transparent_hugepage=never nokaslr hest_disable novmcoredd rd.kdumploglvl=3" + + Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) + + The ERROR level designates error events that might still allow the application + to continue running. + + The WARN level designates potentially harmful situations. + + The INFO level designates informational messages that highlight the progress + of the application at coarse-grained level. + + The DEBUG level designates fine-grained informational events that are most + useful to debug an application. + + Note: if you set the log level to 0, that will disable the logs at the + corresponding log level, which indicates that it has no log output. + + At present, the logger works in both the first kernel(kdump service debugging) + and the second kernel. + + In the first kernel, you can find the historical logs with the journalctl + command and check kdump service debugging information. In addition, the + 'kexec -d' debugging messages are also saved to /var/log/kdump.log in the + first kernel. For example: + + [root@ibm-z-109 ~]# ls -al /var/log/kdump.log + -rw-r--r--. 1 root root 63238 Oct 28 06:40 /var/log/kdump.log + + If you want to get the debugging information of building kdump initramfs, you + can enable the '--debug' option for the dracut_args in the /etc/kdump.conf, and + then rebuild the kdump initramfs as below: + + # systemctl restart kdump.service + + That will rebuild the kdump initramfs and gerenate some logs to journald, you + can find the dracut logs with the journalctl command. + + In the second kernel, kdump will automatically put the kexec-dmesg.log to a same + directory with the vmcore, the log file includes the debugging messages like dmesg + and journald logs. For example: + + [root@ibm-z-109 ~]# ls -al /var/crash/127.0.0.1-2020-10-28-02\:01\:23/ + drwxr-xr-x. 2 root root 67 Oct 28 02:02 . + drwxr-xr-x. 6 root root 154 Oct 28 02:01 .. + -rw-r--r--. 1 root root 21164 Oct 28 02:01 kexec-dmesg.log + -rw-------. 1 root root 74238698 Oct 28 02:01 vmcore + -rw-r--r--. 1 root root 17532 Oct 28 02:01 vmcore-dmesg.txt + + If you want to get more debugging information in the second kernel, you can add + the 'rd.debug' option to the KDUMP_COMMANDLINE_APPEND in the /etc/sysconfig/kdump, + and then reload them in order to make the changes take effect. + + In addition, you can also add the 'rd.memdebug=X' option to the KDUMP_COMMANDLINE_APPEND + in the /etc/sysconfig/kdump in order to output the additional information about + kernel module memory consumption during loading. + + For more details, please refer to the /etc/sysconfig/kdump, or the man page of + dracut.cmdline and kdump.conf. diff --git a/kexec-tools.spec b/kexec-tools.spec index 623274c..53d1ff1 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,7 +4,7 @@ Name: kexec-tools Version: 2.0.20 -Release: 19%{?dist} +Release: 20%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -362,6 +362,25 @@ done %endif %changelog +* Thu Nov 19 2020 Kairui Song - 2.0.20-20 +- selftest: Fix several test issue with Fedora 33 +- selftest: add more detailed log and fix a test failure issue +- selftest: Update test base image to Fedora 33 +- selftest: Fix qcow2 image format detect +- selftest: Always use the get_image_fmt helper +- Doc: improve the usage documentation of the logger +- Update the kdump sysconfig +- Capitalize the configuration name of log level +- Add the rd.kdumploglvl option to control log level in the second kernel +- Appropriately converts logger numeric level to syslog log level +- Remove unused log levels for kdump logger +- Add sanity checks for the log levels +- Move watchdog detect and install code to module-setup.sh +- Add a helper to omit non-mandatory dracut module +- Move some dracut module dependencies checks to module-setup.sh +- Add code comments to help better understanding + +* Thu Nov 05 2020 Kairui Song - 2.0.20-19 - Fix comment about ssh dump target - mkdumprd: Ensure kdumpbase is added - kdump.service: use ConditionKernelCommandLine=crashkernel diff --git a/mkdumprd b/mkdumprd index 1c361d6..0623940 100644 --- a/mkdumprd +++ b/mkdumprd @@ -44,28 +44,10 @@ trap ' # clean up after ourselves no matter how we die. trap 'exit 1;' SIGINT -is_wdt_addition_needed() { - local active - - is_wdt_mod_omitted - [[ $? -eq 0 ]] && return 1 - [[ -d /sys/class/watchdog/ ]] || return 1 - for dir in /sys/class/watchdog/*; do - [[ -f "$dir/state" ]] || continue - active=$(< "$dir/state") - [[ "$active" = "active" ]] && return 0 - done - return 1 -} - add_dracut_arg() { dracut_args="$dracut_args $@" } -add_dracut_module() { - add_dracut_arg "--add" "\"$1\"" -} - add_dracut_mount() { add_dracut_arg "--mount" "\"$1\"" } @@ -421,14 +403,6 @@ if [ -f "$keyfile" ]; then SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile) fi -if [ "$(uname -m)" = "s390x" ]; then - add_dracut_module "znet" -fi - -if is_wdt_addition_needed; then - add_dracut_arg "-a" "watchdog" -fi - while read config_opt config_val; do # remove inline comments after the end of a directive. @@ -457,7 +431,6 @@ do then mkdir_save_path_ssh $config_val check_size ssh $config_val - add_dracut_module "ssh-client" add_dracut_sshkey "$SSH_KEY_LOCATION" else perror_exit "Bad ssh dump target $config_val" diff --git a/tests/Makefile b/tests/Makefile index 6144809..71b329b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -11,9 +11,9 @@ DIST ?= fedora DIST_ABR ?= f DIST_ABRL ?= fc DIST_UNSET ?= rhel -RELEASE ?= 32 +RELEASE ?= 33 -DEFAULT_BASE_IMAGE_VER ?= 1.6 +DEFAULT_BASE_IMAGE_VER ?= 1.2 DEFAULT_BASE_IMAGE ?= Fedora-Cloud-Base-$(RELEASE)-$(DEFAULT_BASE_IMAGE_VER).$(ARCH).raw.xz DEFAULT_BASE_IMAGE_URL ?= https://dl.fedoraproject.org/pub/fedora/linux/releases/$(RELEASE)/Cloud/$(ARCH)/images/$(DEFAULT_BASE_IMAGE) diff --git a/tests/scripts/image-init-lib.sh b/tests/scripts/image-init-lib.sh index 7be55d1..0a1524b 100644 --- a/tests/scripts/image-init-lib.sh +++ b/tests/scripts/image-init-lib.sh @@ -61,6 +61,10 @@ get_image_fmt() { return 1 } +fmt_is_qcow2() { + [ "$1" == "qcow2" ] || [ "$1" == "qcow2 backing qcow2" ] +} + # If it's partitioned, return the mountable partition, else return the dev get_mountable_dev() { local dev=$1 parts @@ -143,7 +147,7 @@ mount_image() { dev="$($SUDO losetup --show -f $image)" [ $? -ne 0 ] || [ -z "$dev" ] && perror_exit "failed to setup loop device" - elif [ "$fmt" == "qcow2" ]; then + elif fmt_is_qcow2 "$fmt"; then prepare_nbd dev=$(mount_nbd $image) @@ -232,13 +236,13 @@ create_image_from_base_image() { image=$decompressed_image fi - local image_fmt=$(qemu-img info $image | sed -n "s/file format:\s*\(.*\)/\1/p") + local image_fmt=$(get_image_fmt $image) if [ "$image_fmt" != "raw" ]; then - if [ "$image_fmt" == "qcow2" ]; then + if fmt_is_qcow2 "$image_fmt"; then echo "Source image is qcow2, using snapshot..." qemu-img create -f qcow2 -b $image $output else - perror_exit "Unrecognized base image format $image_mnt" + perror_exit "Unrecognized base image format '$image_mnt'" fi else echo "Source image is raw, converting to qcow2..." diff --git a/tests/scripts/kexec-kdump-test/init.sh b/tests/scripts/kexec-kdump-test/init.sh index 5737810..f427905 100755 --- a/tests/scripts/kexec-kdump-test/init.sh +++ b/tests/scripts/kexec-kdump-test/init.sh @@ -73,25 +73,33 @@ has_valid_vmcore_dir() { local vmcore_dir=$path/$(ls -1 $path | tail -n 1) local vmcore="" + test_output "Found a vmcore dir \"$vmcore_dir\":" # Checking with `crash` is slow and consume a lot of memory/disk, # just do a sanity check by check if log are available. if [ -e $vmcore_dir/vmcore ]; then vmcore=$vmcore_dir/vmcore - makedumpfile --dump-dmesg $vmcore $vmcore_dir/vmcore-dmesg.txt.2 || return 1 + makedumpfile --dump-dmesg $vmcore $vmcore_dir/vmcore-dmesg.txt.2 || { + test_output "Failed to retrive dmesg from vmcore!" + return 1 + } elif [ -e $vmcore_dir/vmcore.flat ]; then vmcore=$vmcore_dir/vmcore.flat makedumpfile -R $vmcore_dir/vmcore < $vmcore || return 1 - makedumpfile --dump-dmesg $vmcore_dir/vmcore $vmcore_dir/vmcore-dmesg.txt.2 || return 1 + makedumpfile --dump-dmesg $vmcore_dir/vmcore $vmcore_dir/vmcore-dmesg.txt.2 || { + test_output "Failed to retrive dmesg from vmcore!" + return 1 + } rm $vmcore_dir/vmcore else + test_output "The vmcore dir is empty!" return 1 fi - if diff $vmcore_dir/vmcore-dmesg.txt.2 $vmcore_dir/vmcore-dmesg.txt; then + if ! diff $vmcore_dir/vmcore-dmesg.txt.2 $vmcore_dir/vmcore-dmesg.txt; then + test_output "Dmesg retrived from vmcore is different from dump version!" return 1 fi - test_output "Found a valid vmcore in \"$vmcore_dir\"" test_output "VMCORE: $vmcore" test_output "KERNEL VERSION: $(rpm -q kernel-core)" diff --git a/tests/scripts/run-test.sh b/tests/scripts/run-test.sh index ef628aa..a68504d 100755 --- a/tests/scripts/run-test.sh +++ b/tests/scripts/run-test.sh @@ -94,7 +94,7 @@ for test_case in $testcases; do $(run_test_sync $script > $(get_test_console_file $script)) & - sleep 3 + sleep 5 done script="$main_script" diff --git a/tests/scripts/testcases/local-kdump/0-local.sh b/tests/scripts/testcases/local-kdump/0-local.sh index 948cfa1..e5c1ff0 100755 --- a/tests/scripts/testcases/local-kdump/0-local.sh +++ b/tests/scripts/testcases/local-kdump/0-local.sh @@ -22,7 +22,7 @@ EOF if has_valid_vmcore_dir /var/crash; then test_passed else - test_failed + test_failed "Vmcore missing" fi shutdown -h 0 diff --git a/tests/scripts/testcases/nfs-kdump/0-server.sh b/tests/scripts/testcases/nfs-kdump/0-server.sh index 04f102e..41a0212 100755 --- a/tests/scripts/testcases/nfs-kdump/0-server.sh +++ b/tests/scripts/testcases/nfs-kdump/0-server.sh @@ -8,6 +8,9 @@ on_build() { img_run_cmd "echo /srv/nfs 192.168.77.1/24\(rw,async,insecure,no_root_squash\) > /etc/exports" img_run_cmd "systemctl enable nfs-server" + img_run_cmd "touch /etc/systemd/resolved.conf" + img_run_cmd "echo DNSStubListener=no >> /etc/systemd/resolved.conf" + img_run_cmd "echo interface=eth0 > /etc/dnsmasq.conf" img_run_cmd "echo dhcp-authoritative >> /etc/dnsmasq.conf" img_run_cmd "echo dhcp-range=192.168.77.50,192.168.77.100,255.255.255.0,12h >> /etc/dnsmasq.conf" diff --git a/tests/scripts/testcases/nfs-kdump/1-client.sh b/tests/scripts/testcases/nfs-kdump/1-client.sh index 4122bb8..184c795 100755 --- a/tests/scripts/testcases/nfs-kdump/1-client.sh +++ b/tests/scripts/testcases/nfs-kdump/1-client.sh @@ -15,7 +15,7 @@ core_collector makedumpfile -l --message-level 7 -d 31 EOF while ! ping -c 1 $nfs_server -W 1; do - : + sleep 1 done kdumpctl start || test_failed "Failed to start kdump" diff --git a/tests/scripts/testcases/ssh-kdump/0-server.sh b/tests/scripts/testcases/ssh-kdump/0-server.sh index f1e5073..6dfcc91 100755 --- a/tests/scripts/testcases/ssh-kdump/0-server.sh +++ b/tests/scripts/testcases/ssh-kdump/0-server.sh @@ -9,6 +9,9 @@ on_build() { img_run_cmd 'sed -i "s/^.*PermitRootLogin .*\$/PermitRootLogin yes/" /etc/ssh/sshd_config' img_run_cmd "systemctl enable sshd" + img_run_cmd "touch /etc/systemd/resolved.conf" + img_run_cmd "echo DNSStubListener=no >> /etc/systemd/resolved.conf" + img_run_cmd "echo interface=eth0 > /etc/dnsmasq.conf" img_run_cmd "echo dhcp-authoritative >> /etc/dnsmasq.conf" img_run_cmd "echo dhcp-range=192.168.77.50,192.168.77.100,255.255.255.0,12h >> /etc/dnsmasq.conf" diff --git a/tests/scripts/testcases/ssh-kdump/1-client.sh b/tests/scripts/testcases/ssh-kdump/1-client.sh index bd03eff..be549c3 100755 --- a/tests/scripts/testcases/ssh-kdump/1-client.sh +++ b/tests/scripts/testcases/ssh-kdump/1-client.sh @@ -14,7 +14,7 @@ ssh root@192.168.77.1 core_collector makedumpfile -l --message-level 7 -d 31 -F EOF - ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa <<< y &>/dev/ttyS1 + ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa <<< y while ! ping -c 1 $ssh_server -W 1; do sleep 1 @@ -24,9 +24,11 @@ EOF ssh-keyscan -H 192.168.77.1 > /root/.ssh/known_hosts done - sshpass -p fedora ssh-copy-id root@$ssh_server -f &>/dev/ttyS1 + sshpass -p fedora ssh $ssh_server "mkdir /root/.ssh" + cat /root/.ssh/id_rsa.pub | sshpass -p fedora ssh $ssh_server "cat >> /root/.ssh/authorized_keys" - sshpass -p fedora kdumpctl propagate &>/dev/ttyS1 + sshpass -p fedora kdumpctl propagate + cat /root/.ssh/kdump_id_rsa.pub | sshpass -p fedora ssh $ssh_server "cat >> /root/.ssh/authorized_keys" kdumpctl start || test_failed "Failed to start kdump"